PlasmaActivities

consumer.h
1/*
2 SPDX-FileCopyrightText: 2010-2016 Ivan Cukic <ivan.cukic(at)kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef ACTIVITIES_CONSUMER_H
8#define ACTIVITIES_CONSUMER_H
9
10#include <QObject>
11#include <QString>
12#include <QStringList>
13
14#include "info.h"
15
16#include "plasma_activities_export.h"
17
18#include <memory>
19
20namespace KActivities
21{
22class ConsumerPrivate;
23
24/**
25 * Contextual information can be, from the user's point of view, divided
26 * into three aspects - "who am I?", "where am I?" (what are my surroundings?)
27 * and "what am I doing?".
28 *
29 * Activities deal with the last one - "what am I doing?". The current activity
30 * refers to what the user is doing at the moment, while the other activities
31 * represent things that he/she was doing before, and probably will be doing
32 * again.
33 *
34 * Activity is an abstract concept whose meaning can differ from one user to
35 * another. Typical examples of activities are "developing a KDE project",
36 * "studying the 19th century art", "composing music", "lazing on a Sunday
37 * afternoon" etc.
38 *
39 * Consumer provides read-only information about activities.
40 *
41 * Before relying on the values retrieved by the class, make sure that the
42 * serviceStatus is set to Running. Otherwise, you can get invalid data either
43 * because the service is not functioning properly (or at all) or because
44 * the class did not have enough time to synchronize the data with it.
45 *
46 * For example, if this is the only existing instance of the Consumer class,
47 * the listActivities method will return an empty list.
48 *
49 * @code
50 * void someMethod() {
51 * // Do not copy. This approach is not a good one!
52 * Consumer c;
53 * doSomethingWith(c.listActivities());
54 * }
55 * @endcode
56 *
57 * Instances of the Consumer class should be long-lived. For example, members
58 * of the classes that use them, and you should listen for the changes in the
59 * provided properties.
60 *
61 * @since 4.5
62 */
63class PLASMA_ACTIVITIES_EXPORT Consumer : public QObject
64{
66
67 Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged)
68 Q_PROPERTY(QStringList activities READ activities NOTIFY activitiesChanged)
69 Q_PROPERTY(QStringList runningActivities READ runningActivities NOTIFY runningActivitiesChanged)
70 Q_PROPERTY(ServiceStatus serviceStatus READ serviceStatus NOTIFY serviceStatusChanged)
71
72public:
73 /**
74 * Different states of the activities service
75 */
77 NotRunning, ///< Service is not running
78 Unknown, ///< Unable to determine the status of the service
79 Running, ///< Service is running properly
80 };
81
82 explicit Consumer(QObject *parent = nullptr);
83
84 ~Consumer() override;
85
86 /**
87 * @returns the id of the current activity
88 * @note Activity ID is a UUID-formatted string. If the serviceStatus
89 * is not Running, a null UUID is returned. The ID can also be an empty
90 * string in the case there is no current activity.
91 */
92 QString currentActivity() const;
93
94 /**
95 * @returns the list of activities filtered by state
96 * @param state state of the activity
97 * @note If the serviceStatus is not Running, only a null activity will be
98 * returned.
99 */
100 QStringList activities(Info::State state) const;
101
102 /**
103 * @returns a list of running activities
104 * This is a convenience method that returns Running and Stopping activities
105 */
106 QStringList runningActivities() const;
107
108 /**
109 * @returns the list of all existing activities
110 * @note If the serviceStatus is not Running, only a null activity will be
111 * returned.
112 */
113 QStringList activities() const;
114
115 /**
116 * @returns status of the activities service
117 */
119
121 /**
122 * This signal is emitted when the current activity is changed
123 * @param id id of the new current activity
124 */
126
127 /**
128 * This signal is emitted when the activity service goes online or offline,
129 * or when the class manages to synchronize the data with the service.
130 * @param status new status of the service
131 */
133
134 /**
135 * This signal is emitted when a new activity is added
136 * @param id id of the new activity
137 */
138 void activityAdded(const QString &id);
139
140 /**
141 * This signal is emitted when an activity has been removed
142 * @param id id of the removed activity
143 */
144 void activityRemoved(const QString &id);
145
146 /**
147 * This signal is emitted when the activity list changes
148 * @param activities list of activities
149 */
150 void activitiesChanged(const QStringList &activities);
151
152 /**
153 * This signal is emitted when the list of running activities changes
154 * @param runningActivities list of running activities
155 */
156 void runningActivitiesChanged(const QStringList &runningActivities);
157
158private:
159 const std::unique_ptr<ConsumerPrivate> d;
160};
161
162} // namespace KActivities
163
164#endif // ACTIVITIES_CONSUMER_H
Contextual information can be, from the user's point of view, divided into three aspects - "who am I?...
Definition consumer.h:64
ServiceStatus
Different states of the activities service.
Definition consumer.h:76
@ Running
Service is running properly.
Definition consumer.h:79
@ Unknown
Unable to determine the status of the service.
Definition consumer.h:78
@ NotRunning
Service is not running.
Definition consumer.h:77
ServiceStatus serviceStatus()
void activityAdded(const QString &id)
This signal is emitted when a new activity is added.
void currentActivityChanged(const QString &id)
This signal is emitted when the current activity is changed.
void runningActivitiesChanged(const QStringList &runningActivities)
This signal is emitted when the list of running activities changes.
void activityRemoved(const QString &id)
This signal is emitted when an activity has been removed.
void serviceStatusChanged(Consumer::ServiceStatus status)
This signal is emitted when the activity service goes online or offline, or when the class manages to...
void activitiesChanged(const QStringList &activities)
This signal is emitted when the activity list changes.
State
State of the activity.
Definition info.h:90
Q_SCRIPTABLE CaptureState status()
Namespace for everything in libkactivities.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:06 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.