Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasktools.cpp
Show All 35 Lines | |||||
36 | #include <KStartupInfo> | 36 | #include <KStartupInfo> | ||
37 | #include <KWindowSystem> | 37 | #include <KWindowSystem> | ||
38 | 38 | | |||
39 | #include <processcore/processes.h> | 39 | #include <processcore/processes.h> | ||
40 | #include <processcore/process.h> | 40 | #include <processcore/process.h> | ||
41 | 41 | | |||
42 | #include <config-X11.h> | 42 | #include <config-X11.h> | ||
43 | 43 | | |||
44 | #include <QDir> | 44 | #include <QDir> | ||
broulik: Unused | |||||
45 | #include <QGuiApplication> | 45 | #include <QGuiApplication> | ||
46 | #include <QRegularExpression> | 46 | #include <QRegularExpression> | ||
47 | #include <QScreen> | 47 | #include <QScreen> | ||
48 | #if HAVE_X11 | 48 | #if HAVE_X11 | ||
49 | #include <QX11Info> | 49 | #include <QX11Info> | ||
50 | #endif | 50 | #endif | ||
51 | 51 | | |||
52 | namespace TaskManager | 52 | namespace TaskManager | ||
Show All 11 Lines | 63 | if (uQuery.hasQueryItem(QLatin1String("iconData"))) { | |||
64 | QString iconData(uQuery.queryItemValue(QLatin1String("iconData"))); | 64 | QString iconData(uQuery.queryItemValue(QLatin1String("iconData"))); | ||
65 | QPixmap pixmap; | 65 | QPixmap pixmap; | ||
66 | QByteArray bytes = QByteArray::fromBase64(iconData.toLocal8Bit(), QByteArray::Base64UrlEncoding); | 66 | QByteArray bytes = QByteArray::fromBase64(iconData.toLocal8Bit(), QByteArray::Base64UrlEncoding); | ||
67 | pixmap.loadFromData(bytes); | 67 | pixmap.loadFromData(bytes); | ||
68 | data.icon.addPixmap(pixmap); | 68 | data.icon.addPixmap(pixmap); | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | // applications: URLs are used to refer to applications by their KService::menuId | ||||
73 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | ||||
74 | if (url.scheme() == QStringLiteral("applications")) { | ||||
broulik: compare with `QLatin1String` | |||||
75 | const KService::Ptr service = KService::serviceByMenuId(url.path()); | ||||
76 | | ||||
77 | if (service && url.path() == service->menuId()) { | ||||
78 | data.name = service->name(); | ||||
79 | data.genericName = service->genericName(); | ||||
80 | data.id = service->storageId(); | ||||
81 | | ||||
82 | if (data.icon.isNull()) { | ||||
83 | data.icon = QIcon::fromTheme(service->icon()); | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | | ||||
72 | if (url.isLocalFile() && KDesktopFile::isDesktopFile(url.toLocalFile())) { | 88 | if (url.isLocalFile() && KDesktopFile::isDesktopFile(url.toLocalFile())) { | ||
73 | KDesktopFile f(url.toLocalFile()); | 89 | KDesktopFile f(url.toLocalFile()); | ||
74 | 90 | | |||
75 | const KService::Ptr service = KService::serviceByStorageId(f.fileName()); | 91 | const KService::Ptr service = KService::serviceByStorageId(f.fileName()); | ||
76 | 92 | | |||
93 | // Resolve to non-absolute menuId-based URL if possible. | ||||
94 | if (service) { | ||||
95 | const QString &menuId = service->menuId(); | ||||
96 | | ||||
97 | if (!menuId.isEmpty()) { | ||||
98 | data.url = QUrl(QStringLiteral("applications:") + menuId); | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
77 | if (service && QUrl::fromLocalFile(service->entryPath()) == url) { | 102 | if (service && QUrl::fromLocalFile(service->entryPath()) == url) { | ||
78 | data.name = service->name(); | 103 | data.name = service->name(); | ||
79 | data.genericName = service->genericName(); | 104 | data.genericName = service->genericName(); | ||
80 | data.id = service->storageId(); | 105 | data.id = service->storageId(); | ||
81 | 106 | | |||
82 | if (data.icon.isNull()) { | 107 | if (data.icon.isNull()) { | ||
83 | data.icon = QIcon::fromTheme(service->icon()); | 108 | data.icon = QIcon::fromTheme(service->icon()); | ||
84 | } | 109 | } | ||
Show All 11 Lines | 120 | if (data.id.endsWith(".desktop")) { | |||
96 | data.id = data.id.left(data.id.length() - 8); | 121 | data.id = data.id.left(data.id.length() - 8); | ||
97 | } | 122 | } | ||
98 | } else if (url.scheme() == QLatin1String("preferred")) { | 123 | } else if (url.scheme() == QLatin1String("preferred")) { | ||
99 | data.id = defaultApplication(url); | 124 | data.id = defaultApplication(url); | ||
100 | 125 | | |||
101 | const KService::Ptr service = KService::serviceByStorageId(data.id); | 126 | const KService::Ptr service = KService::serviceByStorageId(data.id); | ||
102 | 127 | | |||
103 | if (service) { | 128 | if (service) { | ||
104 | QString desktopFile = service->entryPath(); | 129 | const QString &menuId = service->menuId(); | ||
130 | const QString &desktopFile = service->entryPath(); | ||||
105 | 131 | | |||
106 | // Update with resolved URL. | 132 | data.name = service->name(); | ||
107 | data.url = QUrl::fromLocalFile(desktopFile); | 133 | data.genericName = service->genericName(); | ||
108 | 134 | data.id = service->storageId(); | |||
109 | KDesktopFile f(desktopFile); | | |||
110 | KConfigGroup cg(&f, "Desktop Entry"); | | |||
111 | | ||||
112 | data.icon = QIcon::fromTheme(f.readIcon()); | | |||
113 | const QString exec = cg.readEntry("Exec", QString()); | | |||
114 | data.name = cg.readEntry("Name", QString()); | | |||
115 | 135 | | |||
116 | if (data.name.isEmpty() && !exec.isEmpty()) { | 136 | if (data.icon.isNull()) { | ||
117 | data.name = exec.split(' ').at(0); | 137 | data.icon = QIcon::fromTheme(service->icon()); | ||
118 | } | 138 | } | ||
119 | 139 | | |||
120 | data.genericName = f.readGenericName(); | 140 | // Update with resolved URL. | ||
141 | if (!menuId.isEmpty()) { | ||||
142 | data.url = QUrl(QStringLiteral("applications:") + menuId); | ||||
143 | } else { | ||||
144 | data.url = QUrl::fromLocalFile(desktopFile); | ||||
145 | } | ||||
121 | } | 146 | } | ||
122 | } | 147 | } | ||
123 | 148 | | |||
124 | if (data.name.isEmpty()) { | 149 | if (data.name.isEmpty()) { | ||
125 | data.name = url.fileName(); | 150 | data.name = url.fileName(); | ||
126 | } | 151 | } | ||
127 | 152 | | |||
128 | if (data.icon.isNull()) { | 153 | if (data.icon.isNull()) { | ||
129 | data.icon = fallbackIcon; | 154 | data.icon = fallbackIcon; | ||
130 | } | 155 | } | ||
131 | 156 | | |||
132 | return data; | 157 | return data; | ||
133 | } | 158 | } | ||
134 | 159 | | |||
135 | AppData appDataFromAppId(const QString &appId) | 160 | AppData appDataFromAppId(const QString &appId) | ||
136 | { | 161 | { | ||
137 | AppData data; | 162 | AppData data; | ||
138 | 163 | | |||
139 | KService::Ptr service = KService::serviceByStorageId(appId); | 164 | KService::Ptr service = KService::serviceByStorageId(appId); | ||
140 | 165 | | |||
141 | if (service) { | 166 | if (service) { | ||
142 | data.id = service->storageId(); | 167 | data.id = service->storageId(); | ||
143 | data.name = service->name(); | 168 | data.name = service->name(); | ||
144 | data.genericName = service->genericName(); | 169 | data.genericName = service->genericName(); | ||
170 | | ||||
171 | const QString &menuId = service->menuId(); | ||||
172 | | ||||
173 | // applications: URLs are used to refer to applications by their KService::menuId | ||||
174 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | ||||
175 | if (!menuId.isEmpty()) { | ||||
176 | data.url = QUrl(QStringLiteral("applications:") + menuId); | ||||
177 | } else { | ||||
145 | data.url = QUrl::fromLocalFile(service->entryPath()); | 178 | data.url = QUrl::fromLocalFile(service->entryPath()); | ||
179 | } | ||||
146 | 180 | | |||
147 | return data; | 181 | return data; | ||
148 | } | 182 | } | ||
149 | 183 | | |||
150 | QString desktopFile = appId; | 184 | QString desktopFile = appId; | ||
151 | 185 | | |||
152 | if (!desktopFile.endsWith(QLatin1String(".desktop"))) { | 186 | if (!desktopFile.endsWith(QLatin1String(".desktop"))) { | ||
153 | desktopFile.append(QLatin1String(".desktop")); | 187 | desktopFile.append(QLatin1String(".desktop")); | ||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Line(s) | 392 | if (services.empty() || services.at(0)->desktopEntryName().isEmpty()) { | |||
370 | // uniqueness that RDN is meant to bring to the table we could potentially end | 404 | // uniqueness that RDN is meant to bring to the table we could potentially end | ||
371 | // up with more than one match here. | 405 | // up with more than one match here. | ||
372 | if (matchingServices.length() == 1) { | 406 | if (matchingServices.length() == 1) { | ||
373 | services = matchingServices; | 407 | services = matchingServices; | ||
374 | } | 408 | } | ||
375 | } | 409 | } | ||
376 | 410 | | |||
377 | if (!services.empty()) { | 411 | if (!services.empty()) { | ||
378 | QString path = services[0]->entryPath(); | 412 | const QString &menuId = services.at(0)->menuId(); | ||
413 | | ||||
414 | // applications: URLs are used to refer to applications by their KService::menuId | ||||
415 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | ||||
416 | if (!menuId.isEmpty()) { | ||||
417 | return QUrl(QStringLiteral("applications:") + menuId); | ||||
418 | } | ||||
419 | | ||||
420 | QString path = services.at(0)->entryPath(); | ||||
421 | | ||||
379 | if (path.isEmpty()) { | 422 | if (path.isEmpty()) { | ||
380 | path = services[0]->exec(); | 423 | path = services.at(0)->exec(); | ||
381 | } | 424 | } | ||
382 | 425 | | |||
383 | if (!path.isEmpty()) { | 426 | if (!path.isEmpty()) { | ||
384 | url = QUrl::fromLocalFile(path); | 427 | url = QUrl::fromLocalFile(path); | ||
385 | } | 428 | } | ||
386 | } | 429 | } | ||
387 | 430 | | |||
388 | return url; | 431 | return url; | ||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Line(s) | 677 | if (appData.url.isValid()) { | |||
635 | quint32 timeStamp = 0; | 678 | quint32 timeStamp = 0; | ||
636 | 679 | | |||
637 | #if HAVE_X11 | 680 | #if HAVE_X11 | ||
638 | if (KWindowSystem::isPlatformX11()) { | 681 | if (KWindowSystem::isPlatformX11()) { | ||
639 | timeStamp = QX11Info::appUserTime(); | 682 | timeStamp = QX11Info::appUserTime(); | ||
640 | } | 683 | } | ||
641 | #endif | 684 | #endif | ||
642 | 685 | | |||
643 | const KService::Ptr service = KService::serviceByDesktopPath(appData.url.toLocalFile()); | 686 | KService::Ptr service; | ||
687 | | ||||
688 | // applications: URLs are used to refer to applications by their KService::menuId | ||||
689 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | ||||
690 | if (appData.url.scheme() == QStringLiteral("applications")) { | ||||
691 | service = KService::serviceByMenuId(appData.url.path()); | ||||
692 | } else if (appData.url.scheme() == QLatin1String("preferred")) { | ||||
693 | const KService::Ptr service = KService::serviceByStorageId(defaultApplication(appData.url)); | ||||
694 | } else { | ||||
695 | service = KService::serviceByDesktopPath(appData.url.toLocalFile()); | ||||
696 | } | ||||
644 | 697 | | |||
645 | if (service && service->isApplication()) { | 698 | if (service && service->isApplication()) { | ||
646 | KRun::runApplication(*service, urls, nullptr, 0, {}, | 699 | KRun::runApplication(*service, urls, nullptr, 0, {}, | ||
647 | KStartupInfo::createNewStartupIdForTimestamp(timeStamp)); | 700 | KStartupInfo::createNewStartupIdForTimestamp(timeStamp)); | ||
648 | 701 | | |||
649 | KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()), | 702 | KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()), | ||
650 | QStringLiteral("org.kde.libtaskmanager")); | 703 | QStringLiteral("org.kde.libtaskmanager")); | ||
651 | } else { | 704 | } else { | ||
Show All 11 Lines |
Unused