Commit ee79239a authored by Eike Hein's avatar Eike Hein

Use KRun::runApplication when possible; split out and share more code.

Summary:
Also better sanity-checking of found services being app services
all around.

I'm not particularly happy about adding more X11 code outside of
XWindowTasksModel, but it means greater code reuse (in something that
has experienced unwelcome drift before) and there's a precedent in
LauncherTasksModel.

Reviewers: #plasma, broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D6358
parent d1b5447f
......@@ -21,6 +21,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "tasktools.h"
#include "abstracttasksmodel.h"
#include <KActivities/ResourceInstance>
#include <KConfigGroup>
#include <KDesktopFile>
#include <kemailsettings.h>
......@@ -28,10 +29,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KMimeTypeTrader>
#include <KRun>
#include <KSharedConfig>
#include <KStartupInfo>
#include <KWindowSystem>
#include <config-X11.h>
#include <QDir>
#include <QGuiApplication>
#include <QScreen>
#if HAVE_X11
#include <QX11Info>
#endif
namespace TaskManager
{
......@@ -310,4 +318,34 @@ QRect screenGeometry(const QPoint &pos)
return screenGeometry;
}
void runApp(const AppData &appData, const QList<QUrl> &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"));
}
}
}
}
}
......@@ -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<QUrl> &urls = QList<QUrl>());
}
#endif
......@@ -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<QUrl> &urls)
......@@ -388,15 +377,7 @@ void WaylandTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QU
return;
}
const QUrl &url = d->appData(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)
......
......@@ -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<QUrl> &urls)
......@@ -1035,15 +1026,7 @@ void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QU
return;
}
const QUrl &url = d->appData(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)
......
Markdown is supported
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