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 | #include "xwindowsystemeventbatcher.h" | 24 | #include "xwindowsystemeventbatcher.h" | ||
25 | 25 | | |||
broulik: Unused | |||||
26 | #include <KActivities/ResourceInstance> | 26 | #include <KActivities/ResourceInstance> | ||
27 | #include <KDesktopFile> | 27 | #include <KDesktopFile> | ||
28 | #include <KDirWatch> | 28 | #include <KDirWatch> | ||
29 | #include <KIconLoader> | 29 | #include <KIconLoader> | ||
30 | #include <KRun> | 30 | #include <KRun> | ||
31 | #include <KService> | 31 | #include <KService> | ||
32 | #include <KSharedConfig> | 32 | #include <KSharedConfig> | ||
33 | #include <KStartupInfo> | 33 | #include <KStartupInfo> | ||
34 | #include <KSycoca> | 34 | #include <KSycoca> | ||
35 | #include <KWindowInfo> | 35 | #include <KWindowInfo> | ||
36 | #include <KWindowSystem> | 36 | #include <KWindowSystem> | ||
37 | 37 | | |||
38 | #include <QBuffer> | 38 | #include <QBuffer> | ||
39 | #include <QDir> | 39 | #include <QDir> | ||
40 | #include <QIcon> | 40 | #include <QIcon> | ||
41 | #include <QFile> | 41 | #include <QFile> | ||
42 | #include <QSet> | 42 | #include <QSet> | ||
43 | #include <QTimer> | 43 | #include <QTimer> | ||
44 | #include <QUrlQuery> | 44 | #include <QUrlQuery> | ||
45 | #include <QX11Info> | 45 | #include <QX11Info> | ||
46 | 46 | | |||
47 | namespace TaskManager | 47 | namespace TaskManager | ||
broulik: Unused | |||||
48 | { | 48 | { | ||
49 | 49 | | |||
50 | static const NET::Properties windowInfoFlags = NET::WMState | NET::XAWMState | NET::WMDesktop | | 50 | static const NET::Properties windowInfoFlags = NET::WMState | NET::XAWMState | NET::WMDesktop | | ||
51 | NET::WMVisibleName | NET::WMGeometry | NET::WMFrameExtents | NET::WMWindowType | NET::WMPid; | 51 | NET::WMVisibleName | NET::WMGeometry | NET::WMFrameExtents | NET::WMWindowType | NET::WMPid; | ||
52 | static const NET::Properties2 windowInfoFlags2 = NET::WM2DesktopFileName | NET::WM2Activities | | 52 | static const NET::Properties2 windowInfoFlags2 = NET::WM2DesktopFileName | NET::WM2Activities | | ||
53 | NET::WM2WindowClass | NET::WM2AllowedActions; | 53 | NET::WM2WindowClass | NET::WM2AllowedActions; | ||
54 | 54 | | |||
55 | class Q_DECL_HIDDEN XWindowTasksModel::Private | 55 | class Q_DECL_HIDDEN XWindowTasksModel::Private | ||
Show All 20 Lines | 57 | public: | |||
76 | void addWindow(WId window); | 76 | void addWindow(WId window); | ||
77 | void removeWindow(WId window); | 77 | void removeWindow(WId window); | ||
78 | void windowChanged(WId window, NET::Properties properties, NET::Properties2 properties2); | 78 | void windowChanged(WId window, NET::Properties properties, NET::Properties2 properties2); | ||
79 | void transientChanged(WId window, NET::Properties properties, NET::Properties2 properties2); | 79 | void transientChanged(WId window, NET::Properties properties, NET::Properties2 properties2); | ||
80 | void dataChanged(WId window, const QVector<int> &roles); | 80 | void dataChanged(WId window, const QVector<int> &roles); | ||
81 | 81 | | |||
82 | KWindowInfo* windowInfo(WId window); | 82 | KWindowInfo* windowInfo(WId window); | ||
83 | AppData appData(WId window); | 83 | AppData appData(WId window); | ||
84 | QString appMenuServiceName(WId window); | ||||
85 | QString appMenuObjectPath(WId window); | ||||
84 | 86 | | |||
85 | QIcon icon(WId window); | 87 | QIcon icon(WId window); | ||
86 | static QString mimeType(); | 88 | static QString mimeType(); | ||
87 | static QString groupMimeType(); | 89 | static QString groupMimeType(); | ||
88 | QUrl windowUrl(WId window); | 90 | QUrl windowUrl(WId window); | ||
89 | QUrl launcherUrl(WId window, bool encodeFallbackIcon = true); | 91 | QUrl launcherUrl(WId window, bool encodeFallbackIcon = true); | ||
90 | bool demandsAttention(WId window); | 92 | bool demandsAttention(WId window); | ||
91 | 93 | | |||
▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Line(s) | 455 | if (data.id.isEmpty() && data.url.isEmpty()) { | |||
460 | return dataCopy; | 462 | return dataCopy; | ||
461 | } | 463 | } | ||
462 | 464 | | |||
463 | appDataCache.insert(window, data); | 465 | appDataCache.insert(window, data); | ||
464 | 466 | | |||
465 | return data; | 467 | return data; | ||
466 | } | 468 | } | ||
467 | 469 | | |||
470 | QString XWindowTasksModel::Private::appMenuServiceName(WId window) | ||||
We generally want to avoid global statics in library code. In the applet it's fine because it's a plugin that is loaded on demand broulik: We generally want to avoid global statics in library code. In the applet it's fine because it's… | |||||
471 | { | ||||
broulik: I think this should be split into two dedicated methods to match the rest | |||||
472 | const KWindowInfo *info = windowInfo(window); | ||||
broulik: `const KWindowInfo *` to match the rest of the code | |||||
473 | return QString::fromUtf8(info->applicationMenuServiceName()); | ||||
Is this check needed? I would think xwindowtasksmodel is guarded in its entirety both compile-time and run-time. broulik: Is this check needed? I would think `xwindowtasksmodel` is guarded in its entirety both compile… | |||||
474 | } | ||||
475 | | ||||
476 | QString XWindowTasksModel::Private::appMenuObjectPath(WId window) | ||||
477 | { | ||||
478 | const KWindowInfo *info = windowInfo(window); | ||||
479 | return QString::fromUtf8(info->applicationMenuServiceName()); | ||||
480 | } | ||||
481 | | ||||
468 | QIcon XWindowTasksModel::Private::icon(WId window) | 482 | QIcon XWindowTasksModel::Private::icon(WId window) | ||
469 | { | 483 | { | ||
470 | const AppData &app = appData(window); | 484 | const AppData &app = appData(window); | ||
broulik: Avoid double look-up, use iterator | |||||
471 | 485 | | |||
472 | if (!app.icon.isNull()) { | 486 | if (!app.icon.isNull()) { | ||
473 | return app.icon; | 487 | return app.icon; | ||
474 | } | 488 | } | ||
475 | 489 | | |||
476 | QIcon icon; | 490 | QIcon icon; | ||
477 | 491 | | |||
478 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeSmall, KIconLoader::SizeSmall, false)); | 492 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeSmall, KIconLoader::SizeSmall, false)); | ||
broulik: Avoid double hash look-up. Store atom in variable and check it | |||||
479 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium, false)); | 493 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium, false)); | ||
480 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeMedium, KIconLoader::SizeMedium, false)); | 494 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeMedium, KIconLoader::SizeMedium, false)); | ||
481 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeLarge, KIconLoader::SizeLarge, false)); | 495 | icon.addPixmap(KWindowSystem::icon(window, KIconLoader::SizeLarge, KIconLoader::SizeLarge, false)); | ||
482 | 496 | | |||
483 | appDataCache[window].icon = icon; | 497 | appDataCache[window].icon = icon; | ||
484 | usingFallbackIcon.insert(window); | 498 | usingFallbackIcon.insert(window); | ||
485 | 499 | | |||
486 | return icon; | 500 | return icon; | ||
Show All 12 Lines | |||||
499 | QUrl XWindowTasksModel::Private::windowUrl(WId window) | 513 | QUrl XWindowTasksModel::Private::windowUrl(WId window) | ||
500 | { | 514 | { | ||
501 | const KWindowInfo *info = windowInfo(window); | 515 | const KWindowInfo *info = windowInfo(window); | ||
502 | 516 | | |||
503 | QString desktopFile = QString::fromUtf8(info->desktopFileName()); | 517 | QString desktopFile = QString::fromUtf8(info->desktopFileName()); | ||
504 | 518 | | |||
505 | if (!desktopFile.isEmpty()) { | 519 | if (!desktopFile.isEmpty()) { | ||
506 | KService::Ptr service = KService::serviceByStorageId(desktopFile); | 520 | KService::Ptr service = KService::serviceByStorageId(desktopFile); | ||
507 | 521 | | |||
broulik: Use null `QString()` | |||||
508 | if (service) { | 522 | if (service) { | ||
509 | const QString &menuId = service->menuId(); | 523 | const QString &menuId = service->menuId(); | ||
510 | 524 | | |||
511 | // applications: URLs are used to refer to applications by their KService::menuId | 525 | // applications: URLs are used to refer to applications by their KService::menuId | ||
512 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | 526 | // (i.e. .desktop file name) rather than the absolute path to a .desktop file. | ||
513 | if (!menuId.isEmpty()) { | 527 | if (!menuId.isEmpty()) { | ||
514 | return QUrl(QStringLiteral("applications:") + menuId); | 528 | return QUrl(QStringLiteral("applications:") + menuId); | ||
515 | } | 529 | } | ||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Line(s) | 618 | { | |||
685 | } else if (role == AppPid) { | 699 | } else if (role == AppPid) { | ||
686 | return d->windowInfo(window)->pid(); | 700 | return d->windowInfo(window)->pid(); | ||
687 | } else if (role == StackingOrder) { | 701 | } else if (role == StackingOrder) { | ||
688 | return d->cachedStackingOrder.indexOf(window); | 702 | return d->cachedStackingOrder.indexOf(window); | ||
689 | } else if (role == LastActivated) { | 703 | } else if (role == LastActivated) { | ||
690 | if (d->lastActivated.contains(window)) { | 704 | if (d->lastActivated.contains(window)) { | ||
691 | return d->lastActivated.value(window); | 705 | return d->lastActivated.value(window); | ||
692 | } | 706 | } | ||
707 | } else if (role == ApplicationMenuObjectPath) { | ||||
708 | return d->appMenuObjectPath(window); | ||||
709 | } else if (role == ApplicationMenuServiceName) { | ||||
710 | return d->appMenuServiceName(window); | ||||
693 | } | 711 | } | ||
694 | 712 | | |||
695 | return QVariant(); | 713 | return QVariant(); | ||
696 | } | 714 | } | ||
697 | 715 | | |||
698 | int XWindowTasksModel::rowCount(const QModelIndex &parent) const | 716 | int XWindowTasksModel::rowCount(const QModelIndex &parent) const | ||
699 | { | 717 | { | ||
700 | return parent.isValid() ? 0 : d->windows.count(); | 718 | return parent.isValid() ? 0 : d->windows.count(); | ||
▲ Show 20 Lines • Show All 433 Lines • Show Last 20 Lines |
Unused