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