Plasma-workspace

startuptasksmodel.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 "startuptasksmodel.h"
8#include "abstracttasksmodel.h"
9
10#include <config-X11.h>
11
12#include "waylandstartuptasksmodel.h"
13#if HAVE_X11
14#include "xstartuptasksmodel.h"
15#endif
16
17#include <KWindowSystem>
18
19namespace TaskManager
20{
21class Q_DECL_HIDDEN StartupTasksModel::Private
22{
23public:
24 Private(StartupTasksModel *q);
25 ~Private();
26
27 static int instanceCount;
28 static AbstractTasksModel *sourceTasksModel;
29
30 void initSourceTasksModel();
31
32private:
33 StartupTasksModel *const q;
34};
35
36int StartupTasksModel::Private::instanceCount = 0;
37AbstractTasksModel *StartupTasksModel::Private::sourceTasksModel = nullptr;
38
39StartupTasksModel::Private::Private(StartupTasksModel *q)
40 : q(q)
41{
42 ++instanceCount;
43}
44
45StartupTasksModel::Private::~Private()
46{
47 --instanceCount;
48
49 if (!instanceCount) {
50 delete sourceTasksModel;
51 sourceTasksModel = nullptr;
52 }
53}
54
55void StartupTasksModel::Private::initSourceTasksModel()
56{
57 if (!sourceTasksModel && KWindowSystem::isPlatformWayland()) {
58 sourceTasksModel = new WaylandStartupTasksModel();
59 }
60
61#if HAVE_X11
62 if (!sourceTasksModel && KWindowSystem::isPlatformX11()) {
63 sourceTasksModel = new XStartupTasksModel();
64 }
65#endif
66
67 q->setSourceModel(sourceTasksModel);
68}
69
70StartupTasksModel::StartupTasksModel(QObject *parent)
71 : QIdentityProxyModel(parent)
72 , d(new Private(this))
73{
74 d->initSourceTasksModel();
75}
76
77StartupTasksModel::~StartupTasksModel()
78{
79}
80
81QHash<int, QByteArray> StartupTasksModel::roleNames() const
82{
83 if (d->sourceTasksModel) {
84 return d->sourceTasksModel->roleNames();
85 }
86
88}
89
90QModelIndex StartupTasksModel::mapIfaceToSource(const QModelIndex &index) const
91{
92 return mapToSource(index);
93}
94
95}
96
97#include "moc_startuptasksmodel.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.