Commit 45205946 authored by Eike Hein's avatar Eike Hein

Merge branch 'Plasma/5.10'

parents dc07b332 ee79239a
......@@ -21,6 +21,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "tasktools.h"
#include "abstracttasksmodel.h"
#include "tasktools.h"
#include "abstracttasksmodel.h"
#include <KActivities/ResourceInstance>
#include <KConfigGroup>
#include <KDesktopFile>
#include <kemailsettings.h>
......@@ -28,13 +32,22 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KMimeTypeTrader>
#include <KRun>
#include <KServiceTypeTrader>
#include <KSharedConfig>
#include <KStartupInfo>
#include <KWindowSystem>
#include <processcore/processes.h>
#include <processcore/process.h>
#include <config-X11.h>
#include <QDir>
#include <QGuiApplication>
#include <QRegularExpression>
#include <QScreen>
#if HAVE_X11
#include <QX11Info>
#endif
namespace TaskManager
{
......@@ -616,4 +629,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"));
}
}
}
}
}
......@@ -180,6 +180,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
......@@ -442,18 +442,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)
......@@ -464,15 +453,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)
......
......@@ -676,16 +676,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)
......@@ -696,15 +687,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