PlasmaActivities

info.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_INFO_H
8#define ACTIVITIES_INFO_H
9
10#include <QFuture>
11#include <QObject>
12#include <QString>
13
14#include "plasma_activities_export.h"
15
16#include <memory>
17
18namespace KActivities
19{
20class InfoPrivate;
21
22/**
23 * This class provides info about an activity. Most methods in it require a
24 * semantic backend running to function properly.
25 *
26 * This class is not thread-safe.
27 *
28 * @see Consumer for info about activities
29 *
30 * The API of the class is synchronous, but the most used properties
31 * are pre-fetched and cached. This means that, in order to get the least
32 * amount of d-bus related locks, you should declare long-lived instances
33 * of this class.
34 *
35 * Before relying on the values retrieved by the class, make sure that the
36 * state is not Info::Unknown. You can get invalid data either because the
37 * service is not functioning properly (or at all) or because the class did
38 * not have enough time to synchronize the data with it.
39 *
40 * For example, if this is the only existing instance of the Info class, the
41 * name method will return an empty string.
42 *
43 * For example, this is wrong (works, but blocks):
44 * @code
45 * void someMethod(const QString & activity) {
46 * // Do not copy. This approach is not a good one!
47 * Info info(activity);
48 * doSomethingWith(info.name());
49 * }
50 * @endcode
51 *
52 * Instances of the Info class should be long-lived. For example, members
53 * of the classes that use them, and you should listen for the changes in the
54 * provided properties.
55 *
56 * @since 4.5
57 */
58class PLASMA_ACTIVITIES_EXPORT Info : public QObject
59{
61
62 Q_PROPERTY(QString id READ id)
63 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
64 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
65 Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
66 Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY isCurrentChanged)
67 Q_PROPERTY(Info::State state READ state NOTIFY stateChanged)
68
69public:
70 explicit Info(const QString &activity, QObject *parent = nullptr);
71 ~Info() override;
72
73 /**
74 * @return true if the activity represented by this object exists and is valid
75 */
76 bool isValid() const;
77
78 /**
79 * Specifies which parts of this class are functional
80 */
82 Nothing = 0, ///< No activity info provided (isValid is false)
83 BasicInfo = 1, ///< Basic info is provided
84 Everything = 2, ///< Everything is available
85 };
86
87 /**
88 * State of the activity
89 */
90 enum State {
91 Invalid = 0, ///< This activity does not exist
92 Unknown = 1, ///< Information is not yet retrieved from the service
93 Running = 2, ///< Activity is running
94 Starting = 3, ///< Activity is begin started
95 Stopped = 4, ///< Activity is stopped
96 Stopping = 5, ///< Activity is begin started
97 };
98
99 /**
100 * @returns what info is provided by this instance of Info
101 */
102 Availability availability() const;
103
104 /**
105 * @returns the URI of this activity. The same URI is used by activities
106 * KIO worker.
107 */
108 QString uri() const;
109
110 /**
111 * @returns the id of the activity
112 */
113 QString id() const;
114
115 /**
116 * @returns whether this activity is the current one
117 */
118 bool isCurrent() const;
119
120 /**
121 * @returns the name of the activity
122 */
123 QString name() const;
124
125 /**
126 * @returns the description of the activity
127 */
129
130 /**
131 * @returns the icon of the activity. Icon can be a freedesktop.org name or
132 * a file path. Or empty if no icon is set.
133 */
134 QString icon() const;
135
136 /**
137 * @returns the state of the activity
138 */
139 State state() const;
140
141 /**
142 * Links the specified resource to the activity
143 * @param resourceUri resource URI
144 * @note This method is <b>asynchronous</b>. It will return before the
145 * resource is actually linked to the activity.
146 */
147 // QFuture<void> linkResource(const QString &resourceUri);
148
149 /**
150 * Unlinks the specified resource from the activity
151 * @param resourceUri resource URI
152 * @note This method is <b>asynchronous</b>. It will return before the
153 * resource is actually unlinked from the activity.
154 */
155 // QFuture<void> unlinkResource(const QString &resourceUri);
156
157 /**
158 * @returns whether a resource is linked to this activity
159 * @note This QFuture is not thread-based, you can not call synchronous
160 * methods like waitForFinished, cancel, pause on it.
161 * @since 5.0
162 */
163 // QFuture<bool> isResourceLinked(const QString &resourceUri);
164
166 /**
167 * Emitted when the activity's name, icon or some custom property is changed
168 */
170
171 /**
172 * Emitted when the name is changed
173 */
174 void nameChanged(const QString &name);
175
176 /**
177 * Emitted when the activity becomes the current one, or when it stops
178 * being the current one
179 */
180 void isCurrentChanged(bool current);
181
182 /**
183 * Emitted when the description is changed
184 */
185 void descriptionChanged(const QString &description);
186
187 /**
188 * Emitted when the icon was changed
189 */
190 void iconChanged(const QString &icon);
191
192 /**
193 * Emitted when the activity is added
194 */
195 void added();
196
197 /**
198 * Emitted when the activity is removed
199 */
200 void removed();
201
202 /**
203 * Emitted when the activity is started
204 */
205 void started();
206
207 /**
208 * Emitted when the activity is stopped
209 */
210 void stopped();
211
212 /**
213 * Emitted when the activity changes state
214 * @param state new state of the activity
215 */
217
218private:
219 const std::unique_ptr<InfoPrivate> d;
220
221 Q_PRIVATE_SLOT(d, void activityStateChanged(const QString &, int))
222 Q_PRIVATE_SLOT(d, void added(const QString &))
223 Q_PRIVATE_SLOT(d, void removed(const QString &))
224 Q_PRIVATE_SLOT(d, void started(const QString &))
225 Q_PRIVATE_SLOT(d, void stopped(const QString &))
226 Q_PRIVATE_SLOT(d, void infoChanged(const QString &))
227 Q_PRIVATE_SLOT(d, void nameChanged(const QString &, const QString &))
228 Q_PRIVATE_SLOT(d, void descriptionChanged(const QString &, const QString &))
229 Q_PRIVATE_SLOT(d, void iconChanged(const QString &, const QString &))
230 Q_PRIVATE_SLOT(d, void setServiceStatus(Consumer::ServiceStatus))
231 Q_PRIVATE_SLOT(d, void setCurrentActivity(const QString &))
232
233 friend class InfoPrivate;
234};
235
236} // namespace KActivities
237
238#endif // ACTIVITIES_INFO_H
ServiceStatus
Different states of the activities service.
Definition consumer.h:76
void infoChanged()
Links the specified resource to the activity.
bool isValid() const
Definition info.cpp:124
void stopped()
Emitted when the activity is stopped.
void added()
Emitted when the activity is added.
QString icon() const
State
State of the activity.
Definition info.h:90
@ Starting
Activity is begin started.
Definition info.h:94
@ Unknown
Information is not yet retrieved from the service.
Definition info.h:92
@ Running
Activity is running.
Definition info.h:93
@ Invalid
This activity does not exist.
Definition info.h:91
@ Stopped
Activity is stopped.
Definition info.h:95
@ Stopping
Activity is begin started.
Definition info.h:96
void descriptionChanged(const QString &description)
Emitted when the description is changed.
void isCurrentChanged(bool current)
Emitted when the activity becomes the current one, or when it stops being the current one.
void started()
Emitted when the activity is started.
void nameChanged(const QString &name)
Emitted when the name is changed.
Availability
Specifies which parts of this class are functional.
Definition info.h:81
@ Everything
Everything is available.
Definition info.h:84
@ Nothing
No activity info provided (isValid is false)
Definition info.h:82
@ BasicInfo
Basic info is provided.
Definition info.h:83
void removed()
Emitted when the activity is removed.
void stateChanged(KActivities::Info::State state)
Emitted when the activity changes state.
void iconChanged(const QString &icon)
Emitted when the icon was changed.
QString description() const
QString name() const
Namespace for everything in libkactivities.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
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.