[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasma-workspace/Plasma/5.14] dataengines/hotplug: [Hotplug Engine] Update actions at runtime and l
From: Kai Uwe Broulik <null () kde ! org>
Date: 2018-09-21 9:40:36
Message-ID: E1g3HvQ-0005B3-Ip () code ! kde ! org
[Download RAW message or body]
Git commit 522d2cfce8ec09ea26d1949d5920f604a132180b by Kai Uwe Broulik.
Committed on 21/09/2018 at 09:39.
Pushed by broulik into branch 'Plasma/5.14'.
[Hotplug Engine] Update actions at runtime and listen for added/removed
It would only detect changes to existing device actions but not adding or removing \
them. Moreover, the list of actions was never updated at runtime, only the list of \
predicates for the device. This causes Device Notifier to pick up added, removed, or \
modified device actions only on startup.
Differential Revision: https://phabricator.kde.org/D15613
M +24 -15 dataengines/hotplug/hotplugengine.cpp
M +1 -0 dataengines/hotplug/hotplugengine.h
https://commits.kde.org/plasma-workspace/522d2cfce8ec09ea26d1949d5920f604a132180b
diff --git a/dataengines/hotplug/hotplugengine.cpp \
b/dataengines/hotplug/hotplugengine.cpp index f851499e..f2177cea 100644
--- a/dataengines/hotplug/hotplugengine.cpp
+++ b/dataengines/hotplug/hotplugengine.cpp
@@ -51,6 +51,8 @@ HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& \
args) foreach (const QString &folder, folders) {
m_dirWatch->addDir(folder, KDirWatch::WatchFiles);
}
+ connect(m_dirWatch, &KDirWatch::created, this, \
&HotplugEngine::updatePredicates); + connect(m_dirWatch, &KDirWatch::deleted, \
this, &HotplugEngine::updatePredicates);
connect(m_dirWatch, &KDirWatch::dirty, this, &HotplugEngine::updatePredicates);
init();
}
@@ -148,6 +150,7 @@ void HotplugEngine::updatePredicates(const QString &path)
if (sources().contains(udi)) {
Plasma::DataEngine::Data data;
data.insert(QStringLiteral("predicateFiles"), predicates);
+ data.insert(QStringLiteral("actions"), \
actionsForPredicates(predicates)); setData(udi, data);
} else {
onDeviceAdded(device, false);
@@ -175,6 +178,26 @@ QStringList HotplugEngine::predicatesForDevice(Solid::Device \
&device) const return interestingDesktopFiles;
}
+QVariantList HotplugEngine::actionsForPredicates(const QStringList &predicates) \
const +{
+ QVariantList actions;
+ actions.reserve(predicates.count());
+
+ for (const QString &desktop : predicates) {
+ const QString actionUrl = \
QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/" + \
desktop); + QList<KServiceAction> services = \
KDesktopFileActions::userDefinedServices(actionUrl, true); + if \
(!services.isEmpty()) { + Plasma::DataEngine::Data action;
+ action.insert(QStringLiteral("predicate"), desktop);
+ action.insert(QStringLiteral("text"), services[0].text());
+ action.insert(QStringLiteral("icon"), services[0].icon());
+ actions << action;
+ }
+ }
+
+ return actions;
+}
+
void HotplugEngine::onDeviceAdded(const QString &udi)
{
Solid::Device device(udi);
@@ -234,21 +257,7 @@ void HotplugEngine::onDeviceAdded(Solid::Device &device, bool \
added) data.insert(QStringLiteral("icon"), device.icon());
data.insert(QStringLiteral("emblems"), device.emblems());
data.insert(QStringLiteral("predicateFiles"), interestingDesktopFiles);
-
- QVariantList actions;
- foreach(const QString& desktop, interestingDesktopFiles) {
- const QString actionUrl = \
QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/" + \
desktop);
- //qDebug() << actionUrl;
- QList<KServiceAction> services = \
KDesktopFileActions::userDefinedServices(actionUrl, true);
- if (!services.isEmpty()) {
- Plasma::DataEngine::Data action;
- action.insert(QStringLiteral("predicate"), desktop);
- action.insert(QStringLiteral("text"), services[0].text());
- action.insert(QStringLiteral("icon"), services[0].icon());
- actions << action;
- }
- }
- data.insert(QStringLiteral("actions"), actions);
+ data.insert(QStringLiteral("actions"), \
actionsForPredicates(interestingDesktopFiles));
data.insert(QStringLiteral("isEncryptedContainer"), isEncryptedContainer);
diff --git a/dataengines/hotplug/hotplugengine.h \
b/dataengines/hotplug/hotplugengine.h index 585d3655..ea6413dc 100644
--- a/dataengines/hotplug/hotplugengine.h
+++ b/dataengines/hotplug/hotplugengine.h
@@ -51,6 +51,7 @@ class HotplugEngine : public Plasma::DataEngine
void onDeviceAdded(Solid::Device &dev, bool added = true);
void findPredicates();
QStringList predicatesForDevice(Solid::Device &device) const;
+ QVariantList actionsForPredicates(const QStringList &predicates) const;
private Q_SLOTS:
void processNextStartupDevice();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic