Plasma-workspace

activityinfo.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 "activityinfo.h"
8
9#include <PlasmaActivities/ActivitiesModel>
10#include <PlasmaActivities/Consumer>
11
12namespace TaskManager
13{
14class Q_DECL_HIDDEN ActivityInfo::Private
15{
16public:
17 Private(ActivityInfo *q);
18 ~Private();
19
20 static int instanceCount;
21 static KActivities::Consumer *activityConsumer;
22 static KActivities::ActivitiesModel *activitiesModel;
23};
24
25int ActivityInfo::Private::instanceCount = 0;
26KActivities::Consumer *ActivityInfo::Private::activityConsumer = nullptr;
27KActivities::ActivitiesModel *ActivityInfo::Private::activitiesModel = nullptr;
28
29ActivityInfo::Private::Private(ActivityInfo *)
30{
31 ++instanceCount;
32}
33
34ActivityInfo::Private::~Private()
35{
36 --instanceCount;
37
38 if (!instanceCount) {
39 delete activityConsumer;
40 activityConsumer = nullptr;
41 delete activitiesModel;
42 activitiesModel = nullptr;
43 }
44}
45
46ActivityInfo::ActivityInfo(QObject *parent)
48 , d(new Private(this))
49{
50 if (!d->activityConsumer) {
51 d->activityConsumer = new KActivities::Consumer();
52 }
53
54 connect(d->activityConsumer, &KActivities::Consumer::currentActivityChanged, this, &ActivityInfo::currentActivityChanged);
55 connect(d->activityConsumer, &KActivities::Consumer::runningActivitiesChanged, this, &ActivityInfo::numberOfRunningActivitiesChanged);
56 connect(d->activityConsumer, &KActivities::Consumer::runningActivitiesChanged, this, &ActivityInfo::namesOfRunningActivitiesChanged);
57
58 if (!d->activitiesModel) {
59 d->activitiesModel = new KActivities::ActivitiesModel();
60 d->activitiesModel->setShownStates(QList<KActivities::Info::State>{KActivities::Info::Running});
61 }
62
63 connect(d->activitiesModel, &KActivities::ActivitiesModel::modelReset, this, &ActivityInfo::namesOfRunningActivitiesChanged);
64
65 connect(d->activitiesModel,
66 &KActivities::ActivitiesModel::dataChanged,
67 this,
68 [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
69 Q_UNUSED(topLeft)
70 Q_UNUSED(bottomRight)
71
72 if (roles.isEmpty() || roles.contains(Qt::DisplayRole)) {
73 Q_EMIT namesOfRunningActivitiesChanged();
74 }
75 });
76}
77
78ActivityInfo::~ActivityInfo()
79{
80}
81
82QString ActivityInfo::currentActivity() const
83{
84 return d->activityConsumer->currentActivity();
85}
86
87int ActivityInfo::numberOfRunningActivities() const
88{
89 return d->activityConsumer->activities(KActivities::Info::State::Running).count();
90}
91
92QStringList ActivityInfo::runningActivities() const
93{
94 return d->activityConsumer->activities(KActivities::Info::State::Running);
95}
96
97QString ActivityInfo::activityName(const QString &id)
98{
99 KActivities::Info info(id);
100
101 if (info.state() != KActivities::Info::Invalid) {
102 return info.name();
103 }
104
105 return QString();
106}
107
108QString ActivityInfo::activityIcon(const QString &id)
109{
110 KActivities::Info info(id);
111
112 if (info.state() != KActivities::Info::Invalid) {
113 return info.icon();
114 }
115
116 return QString();
117}
118}
119
120#include "moc_activityinfo.cpp"
QObject * parent() const const
qsizetype count() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 12:00:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.