diff --git a/applets/taskmanager/CMakeLists.txt b/applets/taskmanager/CMakeLists.txt --- a/applets/taskmanager/CMakeLists.txt +++ b/applets/taskmanager/CMakeLists.txt @@ -27,6 +27,7 @@ KF5::KIOCore KF5::KIOWidgets KF5::KIOFileWidgets # KFilePlacesModel + KF5::Notifications # KNotificationJobUiDelegate KF5::Plasma KF5::ProcessCore KF5::Service diff --git a/applets/taskmanager/plugin/backend.h b/applets/taskmanager/plugin/backend.h --- a/applets/taskmanager/plugin/backend.h +++ b/applets/taskmanager/plugin/backend.h @@ -108,7 +108,6 @@ private Q_SLOTS: void toolTipWindowChanged(QQuickWindow *window); - void handleJumpListAction() const; void handleRecentDocumentAction() const; private: diff --git a/applets/taskmanager/plugin/backend.cpp b/applets/taskmanager/plugin/backend.cpp --- a/applets/taskmanager/plugin/backend.cpp +++ b/applets/taskmanager/plugin/backend.cpp @@ -24,11 +24,14 @@ #include #include #include -#include +#include #include +#include #include #include +#include + #include #include #include @@ -139,55 +142,45 @@ QVariantList Backend::jumpListActions(const QUrl &launcherUrl, QObject *parent) { + QVariantList actions; + if (!parent) { - return QVariantList(); + return actions; } QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { - return QVariantList(); + return actions; } - QVariantList actions; - KDesktopFile desktopFile(desktopEntryUrl.toLocalFile()); - - const QStringList &jumpListActions = desktopFile.readActions(); - - const QLatin1String kde("KDE"); - - foreach (const QString &actionName, jumpListActions) { - const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); + const KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile()); + if (!service) { + return actions; + } - if (!actionGroup.isValid() || !actionGroup.exists()) { - continue; - } + const auto jumpListActions = service->actions(); - const QStringList ¬ShowIn = actionGroup.readXdgListEntry(QStringLiteral("NotShowIn")); - if (notShowIn.contains(kde)) { + for (const KServiceAction &serviceAction : jumpListActions) { + if (serviceAction.noDisplay()) { continue; } - const QStringList &onlyShowIn = actionGroup.readXdgListEntry(QStringLiteral("OnlyShowIn")); - if (!onlyShowIn.isEmpty() && !onlyShowIn.contains(kde)) { - continue; - } - - const QString &name = actionGroup.readEntry(QStringLiteral("Name")); - const QString &exec = actionGroup.readEntry(QStringLiteral("Exec")); - if (name.isEmpty() || exec.isEmpty()) { - continue; + QAction *action = new QAction(parent); + action->setText(serviceAction.text()); + action->setIcon(QIcon::fromTheme(serviceAction.icon())); + if (serviceAction.isSeparator()) { + action->setSeparator(true); } - QAction *action = new QAction(parent); - action->setText(name); - action->setIcon(QIcon::fromTheme(actionGroup.readEntry("Icon"))); - action->setProperty("exec", exec); - // so we can show the proper application name and icon when it launches - action->setProperty("applicationName", desktopFile.readName()); - action->setProperty("applicationIcon", desktopFile.readIcon()); - connect(action, &QAction::triggered, this, &Backend::handleJumpListAction); + connect(action, &QAction::triggered, this, [this, service, serviceAction]() { + auto *job = new KIO::ApplicationLauncherJob(service, serviceAction); + auto *delegate = new KNotificationJobUiDelegate; + delegate->setAutoErrorHandlingEnabled(true); + job->setUiDelegate(delegate); + job->start(); + }); actions << QVariant::fromValue(action); } @@ -240,7 +233,13 @@ return; } - KRun::runService(*service, {url}, QApplication::activeWindow()); + auto *job = new KIO::ApplicationLauncherJob(service); + auto *delegate = new KNotificationJobUiDelegate; + delegate->setAutoErrorHandlingEnabled(true); + job->setUiDelegate(delegate); + + job->setUrls({url}); + job->start(); }); const QString &groupName = idx.data(KFilePlacesModel::GroupRole).toString(); @@ -369,19 +368,6 @@ updateWindowHighlight(); } -void Backend::handleJumpListAction() const -{ - const QAction *action = qobject_cast(sender()); - - if (!action) { - return; - } - - KRun::run(action->property("exec").toString(), {}, nullptr, - action->property("applicationName").toString(), - action->property("applicationIcon").toString()); -} - void Backend::handleRecentDocumentAction() const { const QAction *action = qobject_cast(sender()); @@ -419,7 +405,13 @@ return; } - KRun::runService(*service, QList() << QUrl(resource), QApplication::activeWindow()); + auto *job = new KIO::ApplicationLauncherJob(service); + auto *delegate = new KNotificationJobUiDelegate; + delegate->setAutoErrorHandlingEnabled(true); + job->setUiDelegate(delegate); + + job->setUrls({QUrl(resource)}); + job->start(); } void Backend::setActionGroup(QAction *action) const