diff --git a/libtaskmanager/tasktools.cpp b/libtaskmanager/tasktools.cpp
index 5ebbb733c..1ca5a9411 100644
--- a/libtaskmanager/tasktools.cpp
+++ b/libtaskmanager/tasktools.cpp
@@ -21,6 +21,7 @@ License along with this library. If not, see .
#include "tasktools.h"
#include "abstracttasksmodel.h"
+#include
#include
#include
#include
@@ -28,10 +29,17 @@ License along with this library. If not, see .
#include
#include
#include
+#include
+#include
+
+#include
#include
#include
#include
+#if HAVE_X11
+#include
+#endif
namespace TaskManager
{
@@ -310,4 +318,34 @@ QRect screenGeometry(const QPoint &pos)
return screenGeometry;
}
+void runApp(const AppData &appData, const QList &urls)
+{
+ if (appData.url.isValid()) {
+ quint32 timeStamp = 0;
+
+#if HAVE_X11
+ if (KWindowSystem::isPlatformX11()) {
+ timeStamp = QX11Info::appUserTime();
+ }
+#endif
+
+ const KService::Ptr service = KService::serviceByDesktopPath(appData.url.toLocalFile());
+
+ if (service && service->isApplication()) {
+ KRun::runApplication(*service, urls, nullptr, 0, {},
+ KStartupInfo::createNewStartupIdForTimestamp(timeStamp));
+
+ KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()),
+ QStringLiteral("org.kde.libtaskmanager"));
+ } else {
+ new KRun(appData.url, 0, false, KStartupInfo::createNewStartupIdForTimestamp(timeStamp));
+
+ if (!appData.id.isEmpty()) {
+ KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + appData.id),
+ QStringLiteral("org.kde.libtaskmanager"));
+ }
+ }
+ }
+}
+
}
diff --git a/libtaskmanager/tasktools.h b/libtaskmanager/tasktools.h
index f577eda80..dd1374325 100644
--- a/libtaskmanager/tasktools.h
+++ b/libtaskmanager/tasktools.h
@@ -126,6 +126,17 @@ TASKMANAGER_EXPORT bool appsMatch(const QModelIndex &a, const QModelIndex &b);
* @return The geometry of the screen containing pos or closest to pos.
*/
TASKMANAGER_EXPORT QRect screenGeometry(const QPoint &pos);
+
+/**
+ * Attempts to run the application described by the AppData struct that
+ * is passed in, optionally also handing the application a list of URLs
+ * to open.
+ *
+ * @param appData An application data struct.
+ * @param urls A list of URLs for the application to open.
+ */
+TASKMANAGER_EXPORT void runApp(const AppData &appData,
+ const QList &urls = QList());
}
#endif
diff --git a/libtaskmanager/waylandtasksmodel.cpp b/libtaskmanager/waylandtasksmodel.cpp
index 1308f538a..8341c65bd 100644
--- a/libtaskmanager/waylandtasksmodel.cpp
+++ b/libtaskmanager/waylandtasksmodel.cpp
@@ -366,18 +366,7 @@ void WaylandTasksModel::requestNewInstance(const QModelIndex &index)
return;
}
- KWayland::Client::PlasmaWindow* window = d->windows.at(index.row());
-
- if (d->appDataCache.contains(window)) {
- const AppData &data = d->appData(window);
-
- new KRun(data.url, 0, false);
-
- if (!data.id.isEmpty()) {
- KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + data.id),
- QStringLiteral("org.kde.libtaskmanager"));
- }
- }
+ runApp(d->appData(d->windows.at(index.row())));
}
void WaylandTasksModel::requestOpenUrls(const QModelIndex &index, const QList &urls)
@@ -388,15 +377,7 @@ void WaylandTasksModel::requestOpenUrls(const QModelIndex &index, const QListappData(d->windows.at(index.row())).url;
- const KService::Ptr service = KService::serviceByDesktopPath(url.toLocalFile());
-
- if (service) {
- KRun::runApplication(*service, urls, nullptr, 0);
-
- KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()),
- QStringLiteral("org.kde.libtaskmanager"));
- }
+ runApp(d->appData(d->windows.at(index.row())), urls);
}
void WaylandTasksModel::requestClose(const QModelIndex &index)
diff --git a/libtaskmanager/xwindowtasksmodel.cpp b/libtaskmanager/xwindowtasksmodel.cpp
index 47a64bdba..5e0278df2 100644
--- a/libtaskmanager/xwindowtasksmodel.cpp
+++ b/libtaskmanager/xwindowtasksmodel.cpp
@@ -1015,16 +1015,7 @@ void XWindowTasksModel::requestNewInstance(const QModelIndex &index)
return;
}
- const AppData &data = d->appData(d->windows.at(index.row()));
-
- if (data.url.isValid()) {
- new KRun(data.url, 0, false, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime()));
-
- if (!data.id.isEmpty()) {
- KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + data.id),
- QStringLiteral("org.kde.libtaskmanager"));
- }
- }
+ runApp(d->appData(d->windows.at(index.row())));
}
void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList &urls)
@@ -1035,15 +1026,7 @@ void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QListappData(d->windows.at(index.row())).url;
- const KService::Ptr service = KService::serviceByDesktopPath(url.toLocalFile());
-
- if (service) {
- KRun::runApplication(*service, urls, nullptr, 0, {}, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime()));
-
- KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()),
- QStringLiteral("org.kde.libtaskmanager"));
- }
+ runApp(d->appData(d->windows.at(index.row())), urls);
}
void XWindowTasksModel::requestClose(const QModelIndex &index)