Summary: - hasn't been installed for years and no one missed it - not actually ported - using tech we want to get rid of (soliduiserver) Test Plan: workspace still builds Reviewers: broulik Reviewed By: broulik Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D21747wilder-5.17
parent
9efe2b4596
commit
ec9709fdd2
8 changed files with 0 additions and 824 deletions
@ -1,13 +0,0 @@ |
|||||||
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_runner_solid\") |
|
||||||
|
|
||||||
set(krunner_solid_SRCS |
|
||||||
solidrunner.cpp |
|
||||||
devicewrapper.cpp |
|
||||||
) |
|
||||||
|
|
||||||
add_library(krunner_solid MODULE ${krunner_solid_SRCS}) |
|
||||||
target_link_libraries(krunner_solid KF5::Plasma KF5::Solid KIOCore) |
|
||||||
|
|
||||||
install(TARGETS krunner_solid DESTINATION ${KDE_INSTALL_PLUGINDIR} ) |
|
||||||
|
|
||||||
install(FILES plasma-runner-solid.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) |
|
||||||
@ -1,3 +0,0 @@ |
|||||||
#! /usr/bin/env bash |
|
||||||
$XGETTEXT *.cpp -o $podir/plasma_runner_solid.pot |
|
||||||
|
|
||||||
@ -1,209 +0,0 @@ |
|||||||
/**************************************************************************
|
|
||||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> * |
|
||||||
* This program is free software; you can redistribute it and/or modify * |
|
||||||
* it under the terms of the GNU General Public License as published by * |
|
||||||
* the Free Software Foundation; either version 2 of the License, or * |
|
||||||
* (at your option) any later version. * |
|
||||||
* * |
|
||||||
* This program is distributed in the hope that it will be useful, * |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
||||||
* GNU General Public License for more details. * |
|
||||||
* * |
|
||||||
* You should have received a copy of the GNU General Public License * |
|
||||||
* along with this program; if not, write to the * |
|
||||||
* Free Software Foundation, Inc., * |
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * |
|
||||||
***************************************************************************/ |
|
||||||
|
|
||||||
//own
|
|
||||||
#include "devicewrapper.h" |
|
||||||
|
|
||||||
//Qt
|
|
||||||
#include <QAction> |
|
||||||
#include <QTimer> |
|
||||||
#include <QDBusInterface> |
|
||||||
#include <QDBusReply> |
|
||||||
|
|
||||||
//Solid
|
|
||||||
#include <Solid/Device> |
|
||||||
#include <Solid/StorageVolume> |
|
||||||
#include <Solid/StorageAccess> |
|
||||||
#include <Solid/OpticalDrive> |
|
||||||
#include <Solid/OpticalDisc> |
|
||||||
|
|
||||||
//KDE
|
|
||||||
#include <KIcon> |
|
||||||
#include <KMessageBox> |
|
||||||
#include <KStandardDirs> |
|
||||||
#include <kdesktopfileactions.h> |
|
||||||
|
|
||||||
//Plasma
|
|
||||||
#include <Plasma/DataEngine> |
|
||||||
|
|
||||||
DeviceWrapper::DeviceWrapper(const QString& udi) |
|
||||||
: m_device(udi), |
|
||||||
m_isStorageAccess(false), |
|
||||||
m_isAccessible(false), |
|
||||||
m_isEncryptedContainer(false) |
|
||||||
{ |
|
||||||
m_udi = m_device.udi(); |
|
||||||
} |
|
||||||
|
|
||||||
DeviceWrapper::~DeviceWrapper() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
void DeviceWrapper::dataUpdated(const QString &source, Plasma::DataEngine::Data data) |
|
||||||
{ |
|
||||||
Q_UNUSED(source) |
|
||||||
|
|
||||||
if (data.isEmpty()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
if (data["text"].isValid()) { |
|
||||||
m_actionIds.clear(); |
|
||||||
foreach (const QString &desktop, data["predicateFiles"].toStringList()) { |
|
||||||
QString filePath = KStandardDirs::locate("data", "solid/actions/" + desktop); |
|
||||||
QList<KServiceAction> services = KDesktopFileActions::userDefinedServices(filePath, true); |
|
||||||
|
|
||||||
foreach (KServiceAction serviceAction, services) { |
|
||||||
QString actionId = id()+'_'+desktop+'_'+serviceAction.name(); |
|
||||||
m_actionIds << actionId; |
|
||||||
emit registerAction(actionId, serviceAction.icon(), serviceAction.text(), desktop); |
|
||||||
} |
|
||||||
} |
|
||||||
m_isEncryptedContainer = data["isEncryptedContainer"].toBool(); |
|
||||||
} else { |
|
||||||
if (data["Device Types"].toStringList().contains("Storage Access")) { |
|
||||||
m_isStorageAccess = true; |
|
||||||
if (data["Accessible"].toBool() == true) { |
|
||||||
m_isAccessible = true; |
|
||||||
} else { |
|
||||||
m_isAccessible = false; |
|
||||||
} |
|
||||||
} else { |
|
||||||
m_isStorageAccess = false; |
|
||||||
} |
|
||||||
if (data["Device Types"].toStringList().contains("OpticalDisc")) { |
|
||||||
m_isOpticalDisc = true; |
|
||||||
} else { |
|
||||||
m_isOpticalDisc = false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
m_emblems = m_device.emblems(); |
|
||||||
m_description = m_device.description(); |
|
||||||
m_iconName = m_device.icon(); |
|
||||||
|
|
||||||
emit refreshMatch(m_udi); |
|
||||||
} |
|
||||||
|
|
||||||
QString DeviceWrapper::id() const { |
|
||||||
return m_udi; |
|
||||||
} |
|
||||||
|
|
||||||
Solid::Device DeviceWrapper::device() const { |
|
||||||
return m_device; |
|
||||||
} |
|
||||||
|
|
||||||
KIcon DeviceWrapper::icon() const { |
|
||||||
return KIcon(m_iconName, nullptr, m_emblems); |
|
||||||
} |
|
||||||
|
|
||||||
bool DeviceWrapper::isStorageAccess() const { |
|
||||||
return m_isStorageAccess; |
|
||||||
} |
|
||||||
|
|
||||||
bool DeviceWrapper::isAccessible() const { |
|
||||||
return m_isAccessible; |
|
||||||
} |
|
||||||
|
|
||||||
bool DeviceWrapper::isEncryptedContainer() const { |
|
||||||
return m_isEncryptedContainer; |
|
||||||
} |
|
||||||
|
|
||||||
bool DeviceWrapper::isOpticalDisc() const { |
|
||||||
return m_isOpticalDisc; |
|
||||||
} |
|
||||||
|
|
||||||
QString DeviceWrapper::description() const { |
|
||||||
return m_description; |
|
||||||
} |
|
||||||
|
|
||||||
void DeviceWrapper::setForceEject(bool force) |
|
||||||
{ |
|
||||||
m_forceEject = force; |
|
||||||
} |
|
||||||
|
|
||||||
QString DeviceWrapper::defaultAction() const { |
|
||||||
|
|
||||||
QString actionString; |
|
||||||
|
|
||||||
if (m_isOpticalDisc && m_forceEject) { |
|
||||||
actionString = i18n("Eject medium"); |
|
||||||
} else if (m_isStorageAccess) { |
|
||||||
if (!m_isEncryptedContainer) { |
|
||||||
if (!m_isAccessible) { |
|
||||||
actionString = i18n("Mount the device"); |
|
||||||
} else { |
|
||||||
actionString = i18n("Unmount the device"); |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (!m_isAccessible) { |
|
||||||
actionString = i18nc("Unlock the encrypted container; will ask for a password; partitions inside will appear as they had been plugged in","Unlock the container"); |
|
||||||
} else { |
|
||||||
actionString = i18nc("Close the encrypted container; partitions inside will disappear as they had been unplugged", "Lock the container"); |
|
||||||
} |
|
||||||
} |
|
||||||
} else { |
|
||||||
actionString = i18n("Eject medium"); |
|
||||||
} |
|
||||||
return actionString; |
|
||||||
} |
|
||||||
|
|
||||||
void DeviceWrapper::runAction(QAction * action) |
|
||||||
{ |
|
||||||
if (action) { |
|
||||||
QString desktopAction = action->data().toString(); |
|
||||||
if (!desktopAction.isEmpty()) { |
|
||||||
QStringList desktopFiles; |
|
||||||
desktopFiles.append(desktopAction); |
|
||||||
QDBusInterface soliduiserver("org.kde.kded5", "/modules/soliduiserver", "org.kde.SolidUiServer"); |
|
||||||
soliduiserver.asyncCall("showActionsDialog", id(), desktopFiles); |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (isOpticalDisc() && m_forceEject) { |
|
||||||
Solid::OpticalDrive *drive = m_device.parent().as<Solid::OpticalDrive>(); |
|
||||||
if (drive) { |
|
||||||
drive->eject(); |
|
||||||
} |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (m_device.is<Solid::StorageVolume>()) { |
|
||||||
Solid::StorageAccess *access = m_device.as<Solid::StorageAccess>(); |
|
||||||
if (access) { |
|
||||||
if (access->isAccessible()) { |
|
||||||
access->teardown(); |
|
||||||
} else { |
|
||||||
access->setup(); |
|
||||||
} |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (isOpticalDisc()) { |
|
||||||
Solid::OpticalDrive *drive = m_device.parent().as<Solid::OpticalDrive>(); |
|
||||||
if (drive) { |
|
||||||
drive->eject(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QStringList DeviceWrapper::actionIds() const |
|
||||||
{ |
|
||||||
return m_actionIds; |
|
||||||
} |
|
||||||
|
|
||||||
@ -1,89 +0,0 @@ |
|||||||
/**************************************************************************
|
|
||||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> * |
|
||||||
* This program is free software; you can redistribute it and/or modify * |
|
||||||
* it under the terms of the GNU General Public License as published by * |
|
||||||
* the Free Software Foundation; either version 2 of the License, or * |
|
||||||
* (at your option) any later version. * |
|
||||||
* * |
|
||||||
* This program is distributed in the hope that it will be useful, * |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
||||||
* GNU General Public License for more details. * |
|
||||||
* * |
|
||||||
* You should have received a copy of the GNU General Public License * |
|
||||||
* along with this program; if not, write to the * |
|
||||||
* Free Software Foundation, Inc., * |
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * |
|
||||||
***************************************************************************/ |
|
||||||
|
|
||||||
#ifndef DEVICEWRAPPER_H |
|
||||||
#define DEVICEWRAPPER_H |
|
||||||
|
|
||||||
#include <QString> |
|
||||||
|
|
||||||
#include <KIcon> |
|
||||||
|
|
||||||
#include <Plasma/DataEngine> |
|
||||||
|
|
||||||
#include <Solid/Device> |
|
||||||
|
|
||||||
|
|
||||||
#include <solid/solidnamespace.h> |
|
||||||
|
|
||||||
class DeviceWrapper : public QObject |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit DeviceWrapper(const QString& udi); |
|
||||||
~DeviceWrapper(); |
|
||||||
|
|
||||||
QString id() const; |
|
||||||
Solid::Device device() const; |
|
||||||
KIcon icon() const; |
|
||||||
bool isStorageAccess() const; |
|
||||||
bool isAccessible() const; |
|
||||||
bool isOpticalDisc() const; |
|
||||||
bool isEncryptedContainer() const; |
|
||||||
QString description() const; |
|
||||||
QString defaultAction() const; |
|
||||||
void runAction(QAction *) ; |
|
||||||
QStringList actionIds() const; |
|
||||||
void setForceEject(bool force); |
|
||||||
|
|
||||||
Q_SIGNALS: |
|
||||||
void registerAction(QString &id, QString icon, QString text, QString desktop); |
|
||||||
void refreshMatch(QString &id); |
|
||||||
|
|
||||||
protected Q_SLOTS: |
|
||||||
|
|
||||||
/**
|
|
||||||
* slot called when a source of the hotplug engine is updated |
|
||||||
* @param source the name of the source |
|
||||||
* @param data the data of the source |
|
||||||
* |
|
||||||
* @internal |
|
||||||
**/ |
|
||||||
void dataUpdated(const QString &source, Plasma::DataEngine::Data data); |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
Solid::Device m_device; |
|
||||||
QString m_iconName; |
|
||||||
bool m_isStorageAccess; |
|
||||||
bool m_isAccessible; |
|
||||||
bool m_isEncryptedContainer; |
|
||||||
bool m_isOpticalDisc; |
|
||||||
bool m_forceEject; |
|
||||||
QString m_description; |
|
||||||
QStringList m_actionIds; |
|
||||||
// Solid doesn't like multithreading that much
|
|
||||||
// We cache the information we need locally so that
|
|
||||||
// 1) nothing possibly goes wrong when processing a query
|
|
||||||
// 2) performance++
|
|
||||||
|
|
||||||
QString m_udi; |
|
||||||
QStringList m_emblems; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif //DEVICEWRAPPER_H
|
|
||||||
@ -1,285 +0,0 @@ |
|||||||
/***************************************************************************
|
|
||||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> * |
|
||||||
* This program is free software; you can redistribute it and/or modify * |
|
||||||
* it under the terms of the GNU General Public License as published by * |
|
||||||
* the Free Software Foundation; either version 2 of the License, or * |
|
||||||
* (at your option) any later version. * |
|
||||||
* * |
|
||||||
* This program is distributed in the hope that it will be useful, * |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
||||||
* GNU General Public License for more details. * |
|
||||||
* * |
|
||||||
* You should have received a copy of the GNU General Public License * |
|
||||||
* along with this program; if not, write to the * |
|
||||||
* Free Software Foundation, Inc., * |
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * |
|
||||||
***************************************************************************/ |
|
||||||
|
|
||||||
//own
|
|
||||||
#include "solidrunner.h" |
|
||||||
#include "devicewrapper.h" |
|
||||||
|
|
||||||
//Qt
|
|
||||||
#include <QAction> |
|
||||||
|
|
||||||
//KDE
|
|
||||||
#include <KIcon> |
|
||||||
|
|
||||||
//Plasma
|
|
||||||
#include <Plasma/Plasma> |
|
||||||
#include <Plasma/DataEngineManager> |
|
||||||
|
|
||||||
//Solid
|
|
||||||
#include <Solid/Device> |
|
||||||
|
|
||||||
using namespace Plasma; |
|
||||||
|
|
||||||
SolidRunner::SolidRunner(QObject* parent, const QVariantList& args) |
|
||||||
: AbstractRunner(parent, args), |
|
||||||
m_deviceList() |
|
||||||
{ |
|
||||||
Q_UNUSED(args) |
|
||||||
setObjectName( QLatin1String("Solid" )); |
|
||||||
|
|
||||||
m_engineManager = Plasma::DataEngineManager::self(); |
|
||||||
|
|
||||||
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Finds devices whose name match :q:"))); |
|
||||||
|
|
||||||
setDefaultSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "device"), |
|
||||||
i18n("Lists all devices and allows them to be mounted, unmounted or ejected."))); |
|
||||||
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "mount"), |
|
||||||
i18n("Lists all devices which can be mounted, and allows them to be mounted."))); |
|
||||||
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "unlock"), |
|
||||||
i18n("Lists all encrypted devices which can be unlocked, and allows them to be unlocked."))); |
|
||||||
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "unmount"), |
|
||||||
i18n("Lists all devices which can be unmounted, and allows them to be unmounted."))); |
|
||||||
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "lock"), |
|
||||||
i18n("Lists all encrypted devices which can be locked, and allows them to be locked."))); |
|
||||||
|
|
||||||
addSyntax(Plasma::RunnerSyntax(i18nc("Note this is a KRunner keyword", "eject"), |
|
||||||
i18n("Lists all devices which can be ejected, and allows them to be ejected."))); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
SolidRunner::~SolidRunner() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::init() |
|
||||||
{ |
|
||||||
|
|
||||||
m_hotplugEngine = dataEngine("hotplug"); |
|
||||||
m_solidDeviceEngine = dataEngine("soliddevice"); |
|
||||||
|
|
||||||
//connect to engine when a device is plugged
|
|
||||||
connect(m_hotplugEngine, SIGNAL(sourceAdded(QString)), |
|
||||||
this, SLOT(onSourceAdded(QString))); |
|
||||||
connect(m_hotplugEngine, SIGNAL(sourceRemoved(QString)), |
|
||||||
this, SLOT(onSourceRemoved(QString))); |
|
||||||
fillPreviousDevices(); |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::cleanActionsForDevice(DeviceWrapper * dev) |
|
||||||
{ |
|
||||||
const QStringList actionIds = dev->actionIds(); |
|
||||||
if (!actionIds.isEmpty()) { |
|
||||||
foreach (const QString& id, actionIds) { |
|
||||||
removeAction(id); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QList<QAction*> SolidRunner::actionsForMatch(const Plasma::QueryMatch &match) |
|
||||||
{ |
|
||||||
QList<QAction*> actions; |
|
||||||
|
|
||||||
DeviceWrapper* dev = m_deviceList.value(match.data().toString()); |
|
||||||
if (dev) { |
|
||||||
QStringList actionIds = dev->actionIds(); |
|
||||||
if (!actionIds.isEmpty()) { |
|
||||||
foreach (const QString& id, actionIds) { |
|
||||||
actions << action(id); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return actions; |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::match(Plasma::RunnerContext& context) |
|
||||||
{ |
|
||||||
m_currentContext = context; |
|
||||||
createOrUpdateMatches(m_deviceList.keys()); |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::createOrUpdateMatches(const QStringList &udiList) |
|
||||||
{ |
|
||||||
const QString term = m_currentContext.query(); |
|
||||||
|
|
||||||
if (!m_currentContext.isValid()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (!m_currentContext.singleRunnerQueryMode() && (term.length() < 3)) { |
|
||||||
return; |
|
||||||
} |
|
||||||
QList<Plasma::QueryMatch> matches; |
|
||||||
|
|
||||||
// keyword match: when term starts with "device" we list all devices
|
|
||||||
QStringList keywords = term.split(" "); |
|
||||||
QString deviceDescription; |
|
||||||
bool onlyMounted = false; |
|
||||||
bool onlyMountable = false; |
|
||||||
bool onlyEncrypted = false; |
|
||||||
bool onlyOptical = false; |
|
||||||
bool forceEject = false; |
|
||||||
bool showDevices = false; |
|
||||||
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "device") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} |
|
||||||
|
|
||||||
if (!keywords.isEmpty()) { |
|
||||||
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "mount") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
onlyMountable = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unmount") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
onlyMounted = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "eject") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
onlyOptical = true; |
|
||||||
forceEject = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unlock") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
onlyMountable = true; |
|
||||||
onlyEncrypted = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "lock") , Qt::CaseInsensitive)) { |
|
||||||
showDevices = true; |
|
||||||
onlyMounted = true; |
|
||||||
onlyEncrypted = true; |
|
||||||
keywords.removeFirst(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (!keywords.isEmpty()) { |
|
||||||
deviceDescription = keywords[0]; |
|
||||||
} |
|
||||||
|
|
||||||
foreach (const QString& udi, udiList) { |
|
||||||
DeviceWrapper * dev = m_deviceList.value(udi); |
|
||||||
if ((deviceDescription.isEmpty() && showDevices) || dev->description().contains(deviceDescription, Qt::CaseInsensitive)) { |
|
||||||
// This is getting quite messy indeed
|
|
||||||
if (((!onlyEncrypted) || (onlyEncrypted && dev->isEncryptedContainer())) && |
|
||||||
((!onlyOptical) || (onlyOptical && dev->isOpticalDisc())) && |
|
||||||
((onlyMounted && dev->isAccessible()) || |
|
||||||
(onlyMountable && dev->isStorageAccess() && !dev->isAccessible()) || |
|
||||||
(!onlyMounted && !onlyMountable))) { |
|
||||||
dev->setForceEject(forceEject); |
|
||||||
Plasma::QueryMatch match = deviceMatch(dev); |
|
||||||
if (dev->description().compare(deviceDescription, Qt::CaseInsensitive)) { |
|
||||||
match.setType(Plasma::QueryMatch::ExactMatch); |
|
||||||
} else if (deviceDescription.isEmpty()) { |
|
||||||
match.setType(Plasma::QueryMatch::PossibleMatch); |
|
||||||
} else { |
|
||||||
match.setType(Plasma::QueryMatch::CompletionMatch); |
|
||||||
} |
|
||||||
matches << match; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (!matches.isEmpty()) { |
|
||||||
m_currentContext.addMatches(term, matches); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Plasma::QueryMatch SolidRunner::deviceMatch(DeviceWrapper * device) |
|
||||||
{ |
|
||||||
Plasma::QueryMatch match(this); |
|
||||||
match.setId(device->id()); |
|
||||||
match.setData(device->id()); |
|
||||||
match.setIcon(device->icon()); |
|
||||||
match.setText(device->description()); |
|
||||||
|
|
||||||
match.setSubtext(device->defaultAction()); |
|
||||||
|
|
||||||
//Put them in order such that the last added device is on top.
|
|
||||||
match.setRelevance(0.5+0.1*qreal(m_udiOrderedList.indexOf(device->id()))/qreal(m_udiOrderedList.count())); |
|
||||||
|
|
||||||
return match; |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match) |
|
||||||
{ |
|
||||||
Q_UNUSED(context) |
|
||||||
|
|
||||||
DeviceWrapper *device = m_deviceList.value(match.data().toString()); |
|
||||||
if (device) { |
|
||||||
device->runAction(match.selectedAction()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::registerAction(QString &id, QString icon, QString text, QString desktop) |
|
||||||
{ |
|
||||||
QAction* action = addAction(id, KIcon(icon), text); |
|
||||||
action->setData(desktop); |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::refreshMatch(QString &id) |
|
||||||
{ |
|
||||||
if (!m_currentContext.isValid()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
QueryMatch match(this); |
|
||||||
match.setId(id); |
|
||||||
m_currentContext.removeMatch(match.id()); |
|
||||||
QStringList deviceList; |
|
||||||
deviceList << id; |
|
||||||
createOrUpdateMatches(deviceList); |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::onSourceAdded(const QString &name) |
|
||||||
{ |
|
||||||
DeviceWrapper * device = new DeviceWrapper(name); |
|
||||||
connect(device, SIGNAL(registerAction(QString&,QString,QString,QString)), |
|
||||||
this, SLOT(registerAction(QString&,QString,QString,QString))); |
|
||||||
connect(device, SIGNAL(refreshMatch(QString&)), this, SLOT(refreshMatch(QString&))); |
|
||||||
|
|
||||||
m_deviceList.insert(name, device); |
|
||||||
m_udiOrderedList << name; |
|
||||||
m_hotplugEngine->connectSource(name, device); |
|
||||||
m_solidDeviceEngine->connectSource(name, device); |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::onSourceRemoved(const QString &name) |
|
||||||
{ |
|
||||||
DeviceWrapper * device = m_deviceList.value(name); |
|
||||||
if (device) { |
|
||||||
m_hotplugEngine->disconnectSource(name, device); |
|
||||||
m_solidDeviceEngine->disconnectSource(name, device); |
|
||||||
disconnect(device, 0, this, 0); |
|
||||||
cleanActionsForDevice(device); |
|
||||||
m_deviceList.remove(name); |
|
||||||
m_udiOrderedList.removeAll(name); |
|
||||||
if (m_currentContext.isValid()) { |
|
||||||
QueryMatch match(this); |
|
||||||
match.setId(device->id()); |
|
||||||
m_currentContext.removeMatch(match.id()); |
|
||||||
} |
|
||||||
delete device; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SolidRunner::fillPreviousDevices() |
|
||||||
{ |
|
||||||
foreach (const QString &source, m_hotplugEngine->sources()) { |
|
||||||
onSourceAdded(source); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@ -1,76 +0,0 @@ |
|||||||
/***************************************************************************
|
|
||||||
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> * |
|
||||||
* * |
|
||||||
* This program is free software; you can redistribute it and/or modify * |
|
||||||
* it under the terms of the GNU General Public License as published by * |
|
||||||
* the Free Software Foundation; either version 2 of the License, or * |
|
||||||
* (at your option) any later version. * |
|
||||||
* * |
|
||||||
* This program is distributed in the hope that it will be useful, * |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
||||||
* GNU General Public License for more details. * |
|
||||||
* * |
|
||||||
* You should have received a copy of the GNU General Public License * |
|
||||||
* along with this program; if not, write to the * |
|
||||||
* Free Software Foundation, Inc., * |
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * |
|
||||||
***************************************************************************/ |
|
||||||
#ifndef SOLIDRUNNER_H |
|
||||||
#define SOLIDRUNNER_H |
|
||||||
|
|
||||||
#include <Plasma/AbstractRunner> |
|
||||||
|
|
||||||
namespace Plasma { |
|
||||||
class DataEngine; |
|
||||||
class DataEngineManager; |
|
||||||
class RunnerContext; |
|
||||||
} |
|
||||||
|
|
||||||
class DeviceWrapper; |
|
||||||
|
|
||||||
class SolidRunner : public Plasma::AbstractRunner |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
SolidRunner(QObject* parent, const QVariantList &args); |
|
||||||
~SolidRunner(); |
|
||||||
|
|
||||||
virtual void match(Plasma::RunnerContext& context); |
|
||||||
virtual void run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match); |
|
||||||
|
|
||||||
|
|
||||||
protected: |
|
||||||
QList<QAction*> actionsForMatch(const Plasma::QueryMatch &match); |
|
||||||
|
|
||||||
protected Q_SLOTS: |
|
||||||
|
|
||||||
void init(); |
|
||||||
void onSourceAdded(const QString &name); |
|
||||||
void onSourceRemoved(const QString &name); |
|
||||||
|
|
||||||
private Q_SLOTS: |
|
||||||
void registerAction(QString &id, QString icon, QString text, QString desktop); |
|
||||||
void refreshMatch(QString &id); |
|
||||||
|
|
||||||
private: |
|
||||||
|
|
||||||
void fillPreviousDevices(); |
|
||||||
void cleanActionsForDevice(DeviceWrapper *); |
|
||||||
void createOrUpdateMatches(const QStringList &udiList); |
|
||||||
|
|
||||||
Plasma::QueryMatch deviceMatch(DeviceWrapper * device); |
|
||||||
|
|
||||||
Plasma::DataEngine *m_hotplugEngine; |
|
||||||
Plasma::DataEngine *m_solidDeviceEngine; |
|
||||||
|
|
||||||
QHash<QString, DeviceWrapper*> m_deviceList; |
|
||||||
QStringList m_udiOrderedList; |
|
||||||
Plasma::DataEngineManager* m_engineManager; |
|
||||||
Plasma::RunnerContext m_currentContext; |
|
||||||
}; |
|
||||||
|
|
||||||
K_EXPORT_PLASMA_RUNNER(solid, SolidRunner) |
|
||||||
|
|
||||||
#endif // SOLIDRUNNER_H
|
|
||||||
Loading…
Reference in new issue