File indexing completed on 2024-12-22 05:13:39
0001 /* 0002 SPDX-FileCopyrightText: 2010-2016 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef ACTIVITIES_CONSUMER_H 0008 #define ACTIVITIES_CONSUMER_H 0009 0010 #include <QObject> 0011 #include <QString> 0012 #include <QStringList> 0013 0014 #include "info.h" 0015 0016 #include "plasma_activities_export.h" 0017 0018 #include <memory> 0019 0020 namespace KActivities 0021 { 0022 class ConsumerPrivate; 0023 0024 /** 0025 * Contextual information can be, from the user's point of view, divided 0026 * into three aspects - "who am I?", "where am I?" (what are my surroundings?) 0027 * and "what am I doing?". 0028 * 0029 * Activities deal with the last one - "what am I doing?". The current activity 0030 * refers to what the user is doing at the moment, while the other activities 0031 * represent things that he/she was doing before, and probably will be doing 0032 * again. 0033 * 0034 * Activity is an abstract concept whose meaning can differ from one user to 0035 * another. Typical examples of activities are "developing a KDE project", 0036 * "studying the 19th century art", "composing music", "lazing on a Sunday 0037 * afternoon" etc. 0038 * 0039 * Consumer provides read-only information about activities. 0040 * 0041 * Before relying on the values retrieved by the class, make sure that the 0042 * serviceStatus is set to Running. Otherwise, you can get invalid data either 0043 * because the service is not functioning properly (or at all) or because 0044 * the class did not have enough time to synchronize the data with it. 0045 * 0046 * For example, if this is the only existing instance of the Consumer class, 0047 * the listActivities method will return an empty list. 0048 * 0049 * @code 0050 * void someMethod() { 0051 * // Do not copy. This approach is not a good one! 0052 * Consumer c; 0053 * doSomethingWith(c.listActivities()); 0054 * } 0055 * @endcode 0056 * 0057 * Instances of the Consumer class should be long-lived. For example, members 0058 * of the classes that use them, and you should listen for the changes in the 0059 * provided properties. 0060 * 0061 * @since 4.5 0062 */ 0063 class PLASMA_ACTIVITIES_EXPORT Consumer : public QObject 0064 { 0065 Q_OBJECT 0066 0067 Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged) 0068 Q_PROPERTY(QStringList activities READ activities NOTIFY activitiesChanged) 0069 Q_PROPERTY(QStringList runningActivities READ runningActivities NOTIFY runningActivitiesChanged) 0070 Q_PROPERTY(ServiceStatus serviceStatus READ serviceStatus NOTIFY serviceStatusChanged) 0071 0072 public: 0073 /** 0074 * Different states of the activities service 0075 */ 0076 enum ServiceStatus { 0077 NotRunning, ///< Service is not running 0078 Unknown, ///< Unable to determine the status of the service 0079 Running, ///< Service is running properly 0080 }; 0081 0082 explicit Consumer(QObject *parent = nullptr); 0083 0084 ~Consumer() override; 0085 0086 /** 0087 * @returns the id of the current activity 0088 * @note Activity ID is a UUID-formatted string. If the serviceStatus 0089 * is not Running, a null UUID is returned. The ID can also be an empty 0090 * string in the case there is no current activity. 0091 */ 0092 QString currentActivity() const; 0093 0094 /** 0095 * @returns the list of activities filtered by state 0096 * @param state state of the activity 0097 * @note If the serviceStatus is not Running, only a null activity will be 0098 * returned. 0099 */ 0100 QStringList activities(Info::State state) const; 0101 0102 /** 0103 * @returns a list of running activities 0104 * This is a convenience method that returns Running and Stopping activities 0105 */ 0106 QStringList runningActivities() const; 0107 0108 /** 0109 * @returns the list of all existing activities 0110 * @note If the serviceStatus is not Running, only a null activity will be 0111 * returned. 0112 */ 0113 QStringList activities() const; 0114 0115 /** 0116 * @returns status of the activities service 0117 */ 0118 ServiceStatus serviceStatus(); 0119 0120 Q_SIGNALS: 0121 /** 0122 * This signal is emitted when the current activity is changed 0123 * @param id id of the new current activity 0124 */ 0125 void currentActivityChanged(const QString &id); 0126 0127 /** 0128 * This signal is emitted when the activity service goes online or offline, 0129 * or when the class manages to synchronize the data with the service. 0130 * @param status new status of the service 0131 */ 0132 void serviceStatusChanged(Consumer::ServiceStatus status); 0133 0134 /** 0135 * This signal is emitted when a new activity is added 0136 * @param id id of the new activity 0137 */ 0138 void activityAdded(const QString &id); 0139 0140 /** 0141 * This signal is emitted when an activity has been removed 0142 * @param id id of the removed activity 0143 */ 0144 void activityRemoved(const QString &id); 0145 0146 /** 0147 * This signal is emitted when the activity list changes 0148 * @param activities list of activities 0149 */ 0150 void activitiesChanged(const QStringList &activities); 0151 0152 /** 0153 * This signal is emitted when the list of running activities changes 0154 * @param runningActivities list of running activities 0155 */ 0156 void runningActivitiesChanged(const QStringList &runningActivities); 0157 0158 private: 0159 const std::unique_ptr<ConsumerPrivate> d; 0160 }; 0161 0162 } // namespace KActivities 0163 0164 #endif // ACTIVITIES_CONSUMER_H