KUserFeedback

provider.h
1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KUSERFEEDBACK_PROVIDER_H
8#define KUSERFEEDBACK_PROVIDER_H
9
10#include "kuserfeedbackcore_export.h"
11
12#include <QMetaType>
13#include <QObject>
14#include <QUrl>
15
16namespace KUserFeedback {
17
18class AbstractDataSource;
19class ProviderPrivate;
20class SurveyInfo;
21
22/*! The central object managing data sources and transmitting feedback to the server.
23 *
24 * The defaults for this class are very defensive, so in order to make it actually
25 * operational and submit data, there is a number of settings you need to set in
26 * code, namely submission intervals, encouragement settings and adding data sources.
27 * The settings about what data to submit (telemetryMode) and how often
28 * to bother the user with surveys (surveyInterval) should not be set to hardcoded
29 * values in code, but left as choices to the user.
30 */
31class KUSERFEEDBACKCORE_EXPORT Provider : public QObject
32{
33 Q_OBJECT
34 /*! The global enabled state of the feedback functionality.
35 * If this is @c false, all feedback functionality has to be disabled completely.
36 */
37 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
38
39 /*! The interval in which the user accepts surveys.
40 * This should be configurable for the user.
41 * @c -1 indicates surveys are disabled.
42 * @see surveyInterval(), setSurveyInterval()
43 */
44 Q_PROPERTY(int surveyInterval READ surveyInterval WRITE setSurveyInterval NOTIFY surveyIntervalChanged)
45
46 /*! The telemetry mode the user has configured.
47 * This should be configurable for the user.
48 * @see telemetryMode(), setTelemetryMode()
49 */
50 Q_PROPERTY(TelemetryMode telemetryMode READ telemetryMode WRITE setTelemetryMode NOTIFY telemetryModeChanged)
51
52 /*! Unique product id as set on the feedback server.
53 * @see setProductIdentifier
54 */
55 Q_PROPERTY(QString productIdentifier READ productIdentifier WRITE setProductIdentifier NOTIFY providerSettingsChanged)
56
57 /*! URL of the feedback server.
58 * @see setFeedbackServer
59 */
60 Q_PROPERTY(QUrl feedbackServer READ feedbackServer WRITE setFeedbackServer NOTIFY providerSettingsChanged)
61
62 /*! Submission interval in days.
63 * @see setSubmissionInterval
64 */
65 Q_PROPERTY(int submissionInterval READ submissionInterval WRITE setSubmissionInterval NOTIFY providerSettingsChanged)
66
67 /*! Times the application has to be started before an encouragement message is shown.
68 * @see setApplicationStartsUntilEncouragement
69 */
70 Q_PROPERTY(int applicationStartsUntilEncouragement
71 READ applicationStartsUntilEncouragement
72 WRITE setApplicationStartsUntilEncouragement
73 NOTIFY providerSettingsChanged)
74
75 /*! Application usage time in seconds before an encouragement message is shown.
76 * @see setApplicationUsageTimeUntilEncouragement
77 */
78 Q_PROPERTY(int applicationUsageTimeUntilEncouragement
79 READ applicationUsageTimeUntilEncouragement
80 WRITE setApplicationUsageTimeUntilEncouragement
81 NOTIFY providerSettingsChanged)
82
83 /*! Encouragement delay after application start in seconds.
84 * @see setEncouragementDelay
85 */
86 Q_PROPERTY(int encouragementDelay READ encouragementDelay WRITE setEncouragementDelay NOTIFY providerSettingsChanged)
87
88 /*! Encouragement interval.
89 * @see setEncouragementInterval
90 */
91 Q_PROPERTY(int encouragementInterval READ encouragementInterval WRITE setEncouragementInterval NOTIFY providerSettingsChanged)
92
93 /*!
94 */
95 Q_PROPERTY(QString describeDataSources READ describeDataSources NOTIFY dataSourcesChanged)
96
97public:
98 /*! Telemetry collection modes.
99 * Collection modes are inclusive, ie. higher modes always imply data from
100 * lower modes too.
101 */
103 NoTelemetry, ///< Transmit no data at all.
104 BasicSystemInformation = 0x10, ///< Transmit basic information about the system.
105 BasicUsageStatistics = 0x20, ///< Transmit basic usage statistics.
106 DetailedSystemInformation = 0x30, ///< Transmit detailed system information.
107 DetailedUsageStatistics = 0x40, ///< Transmit detailed usage statistics.
108 };
109 Q_ENUM(TelemetryMode)
110
111 /*! Create a new feedback provider.
112 * @param parent The parent object.
113 */
114 explicit Provider(QObject *parent = nullptr);
115 ~Provider() override;
116
117 /*! Returns whether feedback functionality is enabled on this system.
118 * This should be checked everywhere showing feedback UI to the user
119 * to respect the global "kill switch" for this. Provider does check
120 * this internally for encouragements, surveys and telemetry submission.
121 */
122 bool isEnabled() const;
123 /*! Set the global (user-wide) activation state for feedback functionality.
124 * @see isEnabled
125 */
126 void setEnabled(bool enabled);
127
128 /*! Set the telemetry mode and the survey interval back to their default values.
129 * @see telemetryMode(), surveyInterval()
130 * @since 1.1.0
131 */
132 void restoreDefaults();
133
134 /*! Returns the current product identifier. */
135 QString productIdentifier() const;
136 /*! Set the product identifier.
137 * This is used to distinguish independent products on the same server.
138 * If this is not specified, the product identifier is derived from the application name
139 * organisation domain specified in QCoreApplication.
140 * @param productId Unique product identifier, as configured on the feedback server.
141 */
142 void setProductIdentifier(const QString &productId);
143
144 /*! Returns the current feedback server URL. */
145 QUrl feedbackServer() const;
146 /*! Set the feedback server URL.
147 * This must be called with an appropriate URL for this class to be operational.
148 * @param url The URL of the feedback server.
149 */
150 void setFeedbackServer(const QUrl &url);
151
152 /*! Returns the current submission interval.
153 * @return Days between telemetry submissions, or -1 if submission is off.
154 */
155 int submissionInterval() const;
156 /*! Set the automatic submission interval in days.
157 * This must be called with a positive number for this class to be operational,
158 * as the default is -1 (no submission ever).
159 */
160 void setSubmissionInterval(int days);
161
162 /*! Returns the current telemetry collection mode.
163 * The default is NoTelemetry.
164 */
165 TelemetryMode telemetryMode() const;
166
167 /*! Set which telemetry data should be submitted. */
168 void setTelemetryMode(TelemetryMode mode);
169
170 /*! Adds a data source for telemetry data collection.
171 * @param source The data source to add. The Provider takes ownership of @p source.
172 */
173 void addDataSource(AbstractDataSource *source);
174
175 /*! Returns all data sources that have been added to this provider.
176 * @see addDataSource
177 */
178 QVector<AbstractDataSource*> dataSources() const;
179
180 /*! Returns a data source with matched @p id
181 * @param id data source unique identifier
182 * @return pointer to found data source or nullptr if data source is not found
183 */
184 AbstractDataSource *dataSource(const QString &id) const;
185
186 /*! Returns the minimum time between two surveys in days.
187 * The default is -1 (no surveys enabled).
188 */
189 int surveyInterval() const;
190
191 /*! Sets the minimum time in days between two surveys.
192 * @c -1 indicates no surveys should be requested.
193 * @c 0 indicates no minimum time between surveys at all (i.e. bother the user as often as you want).
194 */
195 void setSurveyInterval(int days);
196
197 /*! Returns the amount of application starts before an encouragement message is shown. */
198 int applicationStartsUntilEncouragement() const;
199 /*! Set the amount of application starts until the encouragement message should be shown.
200 * The default is -1, ie. no encouragement based on application starts.
201 * @param starts The amount of application starts after which an encouragement
202 * message should be displayed.
203 */
204 void setApplicationStartsUntilEncouragement(int starts);
205
206 /*! Returns the amount of application usage time before an encouragement message is shown. */
207 int applicationUsageTimeUntilEncouragement() const;
208 /*! Set the amount of usage time until the encouragement message should be shown.
209 * The default is -1, ie. no encouragement based on application usage time.
210 * @param secs Amount of seconds until the encouragement should be shown.
211 */
212 void setApplicationUsageTimeUntilEncouragement(int secs);
213
214 /*! Returns the current encouragement delay in seconds. */
215 int encouragementDelay() const;
216 /*! Set the delay after application start for the earliest display of the encouragement message.
217 * The default is 300, ie. 5 minutes after the application start.
218 * @note This only adds an additional constraint on usage time and startup count based
219 * encouragement messages, it does not actually trigger encouragement messages itself.
220 *
221 * @param secs Amount of seconds after the application start for the earliest display
222 * of an encouragement message.
223 *
224 * @see setApplicationStartsUntilEncouragement, setApplicationUsageTimeUntilEncouragement
225 */
226 void setEncouragementDelay(int secs);
227
228 /*! Returns the current encouragement interval. */
229 int encouragementInterval() const;
230 /*! Sets the interval after the encouragement should be repeated.
231 * Encouragement messages are only repeated if no feedback options have been enabled.
232 * The default is -1, that is no repeated encouragement at all.
233 * @param days Days between encouragement messages, 0 disables repeated encouragements.
234 */
235 void setEncouragementInterval(int days);
236
237 /*! Returns a string with each source and its enable mode. */
238 QString describeDataSources() const;
239
240public Q_SLOTS:
241 /*! Manually submit currently recorded data. */
242 void submit();
243
244 /*! Marks the given survey as completed. This avoids getting further notification
245 * about the same survey.
246 */
247 void surveyCompleted(const KUserFeedback::SurveyInfo &info);
248
249 /*! Manually load settings of the provider and all added data sources.
250 * Automatically invoked after object construction and changing product ID.
251 * @note Potentially long operation.
252 */
253 void load();
254
255 /*! Manually store settings of the provider and all added data sources.
256 * Will be automatically invoked upon @p QCoreApplication::aboutToQuit signal.
257 * @note Potentially long operation.
258 */
259 void store();
260
261Q_SIGNALS:
262 /*! Emitted whenever there is a new survey available that can be presented
263 * to the user.
264 */
266
267 /*! Indicate that the encouragement notice should be shown. */
269
270 /*! Emitted when the survey interval changed. */
272
273 /*! Emitted when the telemetry collection mode has changed. */
275
276 /*! Emitted when any provider setting changed. */
278
279 /*! Emitted when the global enabled state changed. */
281
282 /*! Emitted when a data source is added or removed. */
284
285private:
286 friend class ProviderPrivate;
287 ProviderPrivate * const d;
288 // for UI
289 Q_PRIVATE_SLOT(d, QByteArray jsonData(KUserFeedback::Provider::TelemetryMode))
290 // for testing
291 Q_PRIVATE_SLOT(d, bool selectSurvey(const KUserFeedback::SurveyInfo&))
292};
293
294}
295
297
298#endif // KUSERFEEDBACK_PROVIDER_H
Base class for data sources for telemetry data.
The central object managing data sources and transmitting feedback to the server.
Definition provider.h:32
void providerSettingsChanged()
Emitted when any provider setting changed.
void telemetryModeChanged()
Emitted when the telemetry collection mode has changed.
void enabledChanged()
Emitted when the global enabled state changed.
void showEncouragementMessage()
Indicate that the encouragement notice should be shown.
void surveyIntervalChanged()
Emitted when the survey interval changed.
void surveyAvailable(const KUserFeedback::SurveyInfo &survey)
Emitted whenever there is a new survey available that can be presented to the user.
TelemetryMode
Telemetry collection modes.
Definition provider.h:102
@ NoTelemetry
Transmit no data at all.
Definition provider.h:103
void dataSourcesChanged()
Emitted when a data source is added or removed.
Information about a survey request.
Definition surveyinfo.h:31
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.