Commit 522d2cfc authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[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
parent 3f332a52
......@@ -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);
......
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment