Plasma-workspace

windowtasksmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "windowtasksmodel.h"
8
9#include <config-X11.h>
10
11#include "waylandtasksmodel.h"
12#if HAVE_X11
13#include "xwindowtasksmodel.h"
14#endif
15
16#include <KWindowSystem>
17
18namespace TaskManager
19{
20class Q_DECL_HIDDEN WindowTasksModel::Private
21{
22public:
23 Private(WindowTasksModel *q);
24 ~Private();
25
26 static int instanceCount;
27 static AbstractTasksModel *sourceTasksModel;
28
29 void initSourceTasksModel();
30
31private:
32 WindowTasksModel *const q;
33};
34
35int WindowTasksModel::Private::instanceCount = 0;
36AbstractTasksModel *WindowTasksModel::Private::sourceTasksModel = nullptr;
37
38WindowTasksModel::Private::Private(WindowTasksModel *q)
39 : q(q)
40{
41 ++instanceCount;
42}
43
44WindowTasksModel::Private::~Private()
45{
46 --instanceCount;
47
48 if (!instanceCount) {
49 delete sourceTasksModel;
50 sourceTasksModel = nullptr;
51 }
52}
53
54void WindowTasksModel::Private::initSourceTasksModel()
55{
56 if (!sourceTasksModel && KWindowSystem::isPlatformWayland()) {
57 sourceTasksModel = new WaylandTasksModel();
58 }
59
60#if HAVE_X11
61 if (!sourceTasksModel && KWindowSystem::isPlatformX11()) {
62 sourceTasksModel = new XWindowTasksModel();
63 }
64#endif
65
66 q->setSourceModel(sourceTasksModel);
67}
68
69WindowTasksModel::WindowTasksModel(QObject *parent)
70 : QIdentityProxyModel(parent)
71 , d(new Private(this))
72{
73 d->initSourceTasksModel();
74}
75
76WindowTasksModel::~WindowTasksModel()
77{
78}
79
80QHash<int, QByteArray> WindowTasksModel::roleNames() const
81{
82 if (d->sourceTasksModel) {
83 return d->sourceTasksModel->roleNames();
84 }
85
87}
88
89QModelIndex WindowTasksModel::mapIfaceToSource(const QModelIndex &index) const
90{
91 return mapToSource(index);
92}
93
94}
95
96#include "moc_windowtasksmodel.cpp"
static bool isPlatformX11()
static bool isPlatformWayland()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.