Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/plugin/backend.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "backend.h" | 20 | #include "backend.h" | ||
21 | 21 | | |||
22 | #include <KConfigGroup> | 22 | #include <KConfigGroup> | ||
23 | #include <KDesktopFile> | 23 | #include <KDesktopFile> | ||
24 | #include <KFileItem> | 24 | #include <KFileItem> | ||
25 | #include <KFilePlacesModel> | 25 | #include <KFilePlacesModel> | ||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <KRun> | 27 | #include <KNotificationJobUiDelegate> | ||
28 | #include <KService> | 28 | #include <KService> | ||
29 | #include <KServiceAction> | ||||
29 | #include <kwindoweffects.h> | 30 | #include <kwindoweffects.h> | ||
30 | #include <KWindowSystem> | 31 | #include <KWindowSystem> | ||
31 | 32 | | |||
33 | #include <KIO/ApplicationLauncherJob> | ||||
34 | | ||||
32 | #include <QAction> | 35 | #include <QAction> | ||
33 | #include <QActionGroup> | 36 | #include <QActionGroup> | ||
34 | #include <QApplication> | 37 | #include <QApplication> | ||
35 | #include <QJsonArray> | 38 | #include <QJsonArray> | ||
36 | #include <QMenu> | 39 | #include <QMenu> | ||
37 | #include <QScopedPointer> | 40 | #include <QScopedPointer> | ||
38 | #include <QQuickItem> | 41 | #include <QQuickItem> | ||
39 | #include <QQuickWindow> | 42 | #include <QQuickWindow> | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 132 | if (launcherUrl.isValid() && launcherUrl.scheme() == QLatin1String("applications")) { | |||
134 | } | 137 | } | ||
135 | } | 138 | } | ||
136 | 139 | | |||
137 | return launcherUrl; | 140 | return launcherUrl; | ||
138 | } | 141 | } | ||
139 | 142 | | |||
140 | QVariantList Backend::jumpListActions(const QUrl &launcherUrl, QObject *parent) | 143 | QVariantList Backend::jumpListActions(const QUrl &launcherUrl, QObject *parent) | ||
141 | { | 144 | { | ||
145 | QVariantList actions; | ||||
146 | | ||||
142 | if (!parent) { | 147 | if (!parent) { | ||
143 | return QVariantList(); | 148 | return actions; | ||
144 | } | 149 | } | ||
145 | 150 | | |||
146 | QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); | 151 | QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); | ||
147 | 152 | | |||
148 | if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() | 153 | if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() | ||
149 | || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { | 154 | || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { | ||
150 | return QVariantList(); | 155 | return actions; | ||
151 | } | 156 | } | ||
152 | 157 | | |||
153 | QVariantList actions; | 158 | const KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile()); | ||
154 | KDesktopFile desktopFile(desktopEntryUrl.toLocalFile()); | 159 | if (!service) { | ||
155 | 160 | return actions; | |||
156 | const QStringList &jumpListActions = desktopFile.readActions(); | | |||
157 | | ||||
158 | const QLatin1String kde("KDE"); | | |||
159 | | ||||
160 | foreach (const QString &actionName, jumpListActions) { | | |||
161 | const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); | | |||
162 | | ||||
163 | if (!actionGroup.isValid() || !actionGroup.exists()) { | | |||
164 | continue; | | |||
165 | } | 161 | } | ||
166 | 162 | | |||
167 | const QStringList ¬ShowIn = actionGroup.readXdgListEntry(QStringLiteral("NotShowIn")); | 163 | const auto jumpListActions = service->actions(); | ||
168 | if (notShowIn.contains(kde)) { | | |||
169 | continue; | | |||
170 | } | | |||
171 | 164 | | |||
172 | const QStringList &onlyShowIn = actionGroup.readXdgListEntry(QStringLiteral("OnlyShowIn")); | 165 | for (const KServiceAction &serviceAction : jumpListActions) { | ||
173 | if (!onlyShowIn.isEmpty() && !onlyShowIn.contains(kde)) { | 166 | if (serviceAction.noDisplay()) { | ||
174 | continue; | 167 | continue; | ||
175 | } | 168 | } | ||
176 | 169 | | |||
177 | const QString &name = actionGroup.readEntry(QStringLiteral("Name")); | 170 | QAction *action = new QAction(parent); | ||
178 | const QString &exec = actionGroup.readEntry(QStringLiteral("Exec")); | 171 | action->setText(serviceAction.text()); | ||
179 | if (name.isEmpty() || exec.isEmpty()) { | 172 | action->setIcon(QIcon::fromTheme(serviceAction.icon())); | ||
180 | continue; | 173 | if (serviceAction.isSeparator()) { | ||
174 | action->setSeparator(true); | ||||
181 | } | 175 | } | ||
182 | 176 | | |||
183 | QAction *action = new QAction(parent); | 177 | connect(action, &QAction::triggered, this, [this, service, serviceAction]() { | ||
184 | action->setText(name); | 178 | auto *job = new KIO::ApplicationLauncherJob(service, serviceAction); | ||
185 | action->setIcon(QIcon::fromTheme(actionGroup.readEntry("Icon"))); | 179 | auto *delegate = new KNotificationJobUiDelegate; | ||
dfaure: Only if you like messageboxes.
Plasma code might prefer something else? A notification maybe? | |||||
186 | action->setProperty("exec", exec); | 180 | delegate->setAutoErrorHandlingEnabled(true); | ||
187 | // so we can show the proper application name and icon when it launches | 181 | job->setUiDelegate(delegate); | ||
188 | action->setProperty("applicationName", desktopFile.readName()); | 182 | job->start(); | ||
189 | action->setProperty("applicationIcon", desktopFile.readIcon()); | 183 | }); | ||
190 | connect(action, &QAction::triggered, this, &Backend::handleJumpListAction); | | |||
191 | 184 | | |||
192 | actions << QVariant::fromValue<QAction *>(action); | 185 | actions << QVariant::fromValue<QAction *>(action); | ||
193 | } | 186 | } | ||
194 | 187 | | |||
195 | return actions; | 188 | return actions; | ||
196 | } | 189 | } | ||
197 | 190 | | |||
198 | QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent) | 191 | QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent) | ||
Show All 36 Lines | 217 | for (int i = 0; i < placesModel->rowCount(); ++i) { | |||
235 | QAction *placeAction = new QAction(icon, title, parent); | 228 | QAction *placeAction = new QAction(icon, title, parent); | ||
236 | 229 | | |||
237 | connect(placeAction, &QAction::triggered, this, [url, desktopEntryUrl] { | 230 | connect(placeAction, &QAction::triggered, this, [url, desktopEntryUrl] { | ||
238 | KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile()); | 231 | KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile()); | ||
239 | if (!service) { | 232 | if (!service) { | ||
240 | return; | 233 | return; | ||
241 | } | 234 | } | ||
242 | 235 | | |||
243 | KRun::runService(*service, {url}, QApplication::activeWindow()); | 236 | auto *job = new KIO::ApplicationLauncherJob(service); | ||
237 | auto *delegate = new KNotificationJobUiDelegate; | ||||
238 | delegate->setAutoErrorHandlingEnabled(true); | ||||
239 | job->setUiDelegate(delegate); | ||||
I see that redundant code in many places can you wrap it in function KJob* createApplicationNotificationLauncherJob or something similar. anthonyfieroni: I see that redundant code in many places can you wrap it in function
```
KJob*… | |||||
240 | | ||||
241 | job->setUrls({url}); | ||||
242 | job->start(); | ||||
244 | }); | 243 | }); | ||
245 | 244 | | |||
246 | const QString &groupName = idx.data(KFilePlacesModel::GroupRole).toString(); | 245 | const QString &groupName = idx.data(KFilePlacesModel::GroupRole).toString(); | ||
247 | if (previousGroup.isEmpty()) { // Skip first group heading. | 246 | if (previousGroup.isEmpty()) { // Skip first group heading. | ||
248 | previousGroup = groupName; | 247 | previousGroup = groupName; | ||
249 | } | 248 | } | ||
250 | 249 | | |||
251 | // Put all subsequent categories into a submenu. | 250 | // Put all subsequent categories into a submenu. | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
364 | 363 | | |||
365 | void Backend::toolTipWindowChanged(QQuickWindow *window) | 364 | void Backend::toolTipWindowChanged(QQuickWindow *window) | ||
366 | { | 365 | { | ||
367 | Q_UNUSED(window) | 366 | Q_UNUSED(window) | ||
368 | 367 | | |||
369 | updateWindowHighlight(); | 368 | updateWindowHighlight(); | ||
370 | } | 369 | } | ||
371 | 370 | | |||
372 | void Backend::handleJumpListAction() const | | |||
373 | { | | |||
374 | const QAction *action = qobject_cast<QAction* >(sender()); | | |||
375 | | ||||
376 | if (!action) { | | |||
377 | return; | | |||
378 | } | | |||
379 | | ||||
380 | KRun::run(action->property("exec").toString(), {}, nullptr, | | |||
381 | action->property("applicationName").toString(), | | |||
382 | action->property("applicationIcon").toString()); | | |||
383 | } | | |||
384 | | ||||
385 | void Backend::handleRecentDocumentAction() const | 371 | void Backend::handleRecentDocumentAction() const | ||
386 | { | 372 | { | ||
387 | const QAction *action = qobject_cast<QAction* >(sender()); | 373 | const QAction *action = qobject_cast<QAction* >(sender()); | ||
388 | 374 | | |||
389 | if (!action) { | 375 | if (!action) { | ||
390 | return; | 376 | return; | ||
391 | } | 377 | } | ||
392 | 378 | | |||
Show All 21 Lines | |||||
414 | KService::Ptr service = KService::serviceByDesktopPath(desktopPath); | 400 | KService::Ptr service = KService::serviceByDesktopPath(desktopPath); | ||
415 | 401 | | |||
416 | qDebug() << service; | 402 | qDebug() << service; | ||
417 | 403 | | |||
418 | if (!service) { | 404 | if (!service) { | ||
419 | return; | 405 | return; | ||
420 | } | 406 | } | ||
421 | 407 | | |||
422 | KRun::runService(*service, QList<QUrl>() << QUrl(resource), QApplication::activeWindow()); | 408 | auto *job = new KIO::ApplicationLauncherJob(service); | ||
409 | auto *delegate = new KNotificationJobUiDelegate; | ||||
410 | delegate->setAutoErrorHandlingEnabled(true); | ||||
411 | job->setUiDelegate(delegate); | ||||
412 | | ||||
413 | job->setUrls({QUrl(resource)}); | ||||
414 | job->start(); | ||||
423 | } | 415 | } | ||
424 | 416 | | |||
425 | void Backend::setActionGroup(QAction *action) const | 417 | void Backend::setActionGroup(QAction *action) const | ||
426 | { | 418 | { | ||
427 | if (action) { | 419 | if (action) { | ||
428 | action->setActionGroup(m_actionGroup); | 420 | action->setActionGroup(m_actionGroup); | ||
429 | } | 421 | } | ||
430 | } | 422 | } | ||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
Only if you like messageboxes.
Plasma code might prefer something else? A notification maybe? I think we both know a guy who likes them very much ;)