Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/xwindowtasksmodel.cpp
Show All 16 Lines | |||||
17 | 17 | | |||
18 | You should have received a copy of the GNU Lesser General Public | 18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | 20 | *********************************************************************/ | ||
21 | 21 | | |||
22 | #include "xwindowtasksmodel.h" | 22 | #include "xwindowtasksmodel.h" | ||
23 | #include "tasktools.h" | 23 | #include "tasktools.h" | ||
24 | 24 | | |||
25 | #include <KActivities/ResourceInstance> | ||||
25 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
26 | #include <KDesktopFile> | 27 | #include <KDesktopFile> | ||
27 | #include <KDirWatch> | 28 | #include <KDirWatch> | ||
28 | #include <KIconLoader> | 29 | #include <KIconLoader> | ||
29 | #include <KRun> | 30 | #include <KRun> | ||
30 | #include <KService> | 31 | #include <KService> | ||
31 | #include <KServiceTypeTrader> | 32 | #include <KServiceTypeTrader> | ||
32 | #include <KSharedConfig> | 33 | #include <KSharedConfig> | ||
▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Line(s) | 405 | { | |||
409 | } | 410 | } | ||
410 | 411 | | |||
411 | QModelIndex idx = q->index(i); | 412 | QModelIndex idx = q->index(i); | ||
412 | emit q->dataChanged(idx, idx, roles); | 413 | emit q->dataChanged(idx, idx, roles); | ||
413 | } | 414 | } | ||
414 | 415 | | |||
415 | KWindowInfo* XWindowTasksModel::Private::windowInfo(WId window) | 416 | KWindowInfo* XWindowTasksModel::Private::windowInfo(WId window) | ||
416 | { | 417 | { | ||
417 | if (!windowInfoCache.contains(window)) { | 418 | const auto &it = windowInfoCache.constFind(window); | ||
419 | | ||||
420 | if (it != windowInfoCache.constEnd()) { | ||||
421 | return *it; | ||||
422 | } | ||||
423 | | ||||
418 | KWindowInfo *info = new KWindowInfo(window, windowInfoFlags, windowInfoFlags2); | 424 | KWindowInfo *info = new KWindowInfo(window, windowInfoFlags, windowInfoFlags2); | ||
419 | windowInfoCache.insert(window, info); | 425 | windowInfoCache.insert(window, info); | ||
420 | 426 | | |||
421 | return info; | 427 | return info; | ||
422 | } | 428 | } | ||
423 | 429 | | |||
424 | return windowInfoCache.value(window); | | |||
425 | } | | |||
426 | | ||||
427 | AppData XWindowTasksModel::Private::appData(WId window) | 430 | AppData XWindowTasksModel::Private::appData(WId window) | ||
428 | { | 431 | { | ||
429 | if (!appDataCache.contains(window)) { | 432 | const auto &it = appDataCache.constFind(window); | ||
433 | | ||||
434 | if (it != appDataCache.constEnd()) { | ||||
435 | return *it; | ||||
436 | } | ||||
437 | | ||||
430 | const AppData &data = appDataFromUrl(windowUrl(window)); | 438 | const AppData &data = appDataFromUrl(windowUrl(window)); | ||
431 | 439 | | |||
432 | // If we weren't able to derive a launcher URL from the window meta data, | 440 | // If we weren't able to derive a launcher URL from the window meta data, | ||
433 | // fall back to WM_CLASS Class string as app id. This helps with apps we | 441 | // fall back to WM_CLASS Class string as app id. This helps with apps we | ||
434 | // can't map to an URL due to existing outside the regular system | 442 | // can't map to an URL due to existing outside the regular system | ||
435 | // environment, e.g. wine clients. | 443 | // environment, e.g. wine clients. | ||
436 | if (data.id.isEmpty() && data.url.isEmpty()) { | 444 | if (data.id.isEmpty() && data.url.isEmpty()) { | ||
437 | AppData dataCopy = data; | 445 | AppData dataCopy = data; | ||
438 | 446 | | |||
439 | dataCopy.id = windowInfo(window)->windowClassClass(); | 447 | dataCopy.id = windowInfo(window)->windowClassClass(); | ||
440 | 448 | | |||
441 | appDataCache.insert(window, dataCopy); | 449 | appDataCache.insert(window, dataCopy); | ||
442 | 450 | | |||
443 | return dataCopy; | 451 | return dataCopy; | ||
444 | } | 452 | } | ||
445 | 453 | | |||
446 | appDataCache.insert(window, data); | 454 | appDataCache.insert(window, data); | ||
447 | 455 | | |||
448 | return data; | 456 | return data; | ||
449 | } | 457 | } | ||
450 | 458 | | |||
451 | return appDataCache.value(window); | | |||
452 | } | | |||
453 | | ||||
454 | QIcon XWindowTasksModel::Private::icon(WId window) | 459 | QIcon XWindowTasksModel::Private::icon(WId window) | ||
455 | { | 460 | { | ||
456 | const AppData &app = appData(window); | 461 | const AppData &app = appData(window); | ||
457 | 462 | | |||
458 | if (!app.icon.isNull()) { | 463 | if (!app.icon.isNull()) { | ||
459 | return app.icon; | 464 | return app.icon; | ||
460 | } | 465 | } | ||
461 | 466 | | |||
▲ Show 20 Lines • Show All 503 Lines • ▼ Show 20 Line(s) | |||||
965 | } | 970 | } | ||
966 | 971 | | |||
967 | void XWindowTasksModel::requestNewInstance(const QModelIndex &index) | 972 | void XWindowTasksModel::requestNewInstance(const QModelIndex &index) | ||
968 | { | 973 | { | ||
969 | if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { | 974 | if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { | ||
970 | return; | 975 | return; | ||
971 | } | 976 | } | ||
972 | 977 | | |||
973 | const QUrl &url = d->appData(d->windows.at(index.row())).url; | 978 | const AppData &data = d->appData(d->windows.at(index.row())); | ||
979 | | ||||
980 | if (data.url.isValid()) { | ||||
981 | new KRun(data.url, 0, false, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime())); | ||||
974 | 982 | | |||
975 | if (url.isValid()) { | 983 | if (!data.id.isEmpty()) { | ||
976 | new KRun(url, 0, false, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime())); | 984 | KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + data.id), | ||
graesslin: this looks like an unrelated change? | |||||
hein: It's documented in the change description though. | |||||
graesslin: and here | |||||
985 | QStringLiteral("org.kde.libtaskmanager")); | ||||
graesslin: QStringLiteral("...") | |||||
hein: Done. | |||||
986 | } | ||||
977 | } | 987 | } | ||
978 | } | 988 | } | ||
979 | 989 | | |||
980 | void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) | 990 | void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) | ||
981 | { | 991 | { | ||
982 | if (!index.isValid() || index.model() != this || index.row() < 0 | 992 | if (!index.isValid() || index.model() != this || index.row() < 0 | ||
983 | || index.row() >= d->windows.count() | 993 | || index.row() >= d->windows.count() | ||
984 | || urls.isEmpty()) { | 994 | || urls.isEmpty()) { | ||
985 | return; | 995 | return; | ||
986 | } | 996 | } | ||
987 | 997 | | |||
988 | const QUrl &url = d->appData(d->windows.at(index.row())).url; | 998 | const QUrl &url = d->appData(d->windows.at(index.row())).url; | ||
989 | const KService::Ptr service = KService::serviceByDesktopPath(url.toLocalFile()); | 999 | const KService::Ptr service = KService::serviceByDesktopPath(url.toLocalFile()); | ||
1000 | | ||||
990 | if (service) { | 1001 | if (service) { | ||
991 | KRun::runApplication(*service, urls, nullptr, 0, {}, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime())); | 1002 | KRun::runApplication(*service, urls, nullptr, 0, {}, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime())); | ||
1003 | | ||||
1004 | KActivities::ResourceInstance::notifyAccessed(QUrl(QStringLiteral("applications:") + service->storageId()), | ||||
graesslin: and here | |||||
1005 | QStringLiteral("org.kde.libtaskmanager")); | ||||
graesslin: QStringLiteral | |||||
hein: Done. | |||||
992 | } | 1006 | } | ||
993 | } | 1007 | } | ||
994 | 1008 | | |||
995 | void XWindowTasksModel::requestClose(const QModelIndex &index) | 1009 | void XWindowTasksModel::requestClose(const QModelIndex &index) | ||
996 | { | 1010 | { | ||
997 | if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { | 1011 | if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { | ||
998 | return; | 1012 | return; | ||
999 | } | 1013 | } | ||
▲ Show 20 Lines • Show All 348 Lines • Show Last 20 Lines |
this looks like an unrelated change?