KUserFeedback

abstractdatasource.h
1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KUSERFEEDBACK_ABSTRACTDATASOURCE_H
8#define KUSERFEEDBACK_ABSTRACTDATASOURCE_H
9
10#include "kuserfeedbackcore_export.h"
11#include "provider.h"
12
13#include <QCoreApplication>
14
15QT_BEGIN_NAMESPACE
16class QSettings;
17QT_END_NAMESPACE
18
19namespace KUserFeedback {
20
21class AbstractDataSourcePrivate;
22
23/*! Base class for data sources for telemetry data. */
24class KUSERFEEDBACKCORE_EXPORT AbstractDataSource
25{
26public:
27 virtual ~AbstractDataSource();
28
29 /*! Returns the ID of this data source.
30 * This is used as identifier towards the server and should
31 * not be shown to the user.
32 * @see description()
33 * @returns The data source identifier configured on the feedback server.
34 */
35 QString id() const;
36
37 /*! Returns a short name of this data source.
38 * Can be empty if short name is meaningless for this data source.
39 * @returns A translated, human-readable string.
40 */
41 virtual QString name() const;
42
43 /*! Returns a human-readable, translated description of what
44 * this source provides.
45 * @see id()
46 * @returns A translated, human-readable string.
47 */
48 virtual QString description() const = 0;
49
50 /*!
51 * Returns the data gathered by this source.
52 *
53 * Implement this to return the data provided by this source.
54 * One of the three following formats are expected:
55 * - scalar entries: QAssociativeIterable
56 * - list entries: QSequentialIterable containing QAssociativeIterable
57 * - map entries: QAssociativeIterable containing QAssociativeIterable
58 *
59 * The innermost QAssociativeIterable must only contain one of the following
60 * base types (which has to match the corresponding schema entry element):
61 * - QString
62 * - int
63 * - double
64 * - bool
65 *
66 * All keys must be strings.
67 *
68 * @returns A variant complying with the above requirements.
69 */
70 virtual QVariant data() = 0;
71
72 /*! Load persistent state for this data source.
73 * @param settings A QSettings object opened in a dedicated group for loading
74 * persistent data.
75 */
76 void load(QSettings *settings);
77
78 /*! Store persistent state for this data source.
79 * @param settings A QSettings object opened in a dedicated group for storing
80 * persistent data.
81 */
82 void store(QSettings *settings);
83
84 /*! Reset the persistent state of this data source.
85 * This is called after a successful submission of data, and can be used
86 * by sources that track differential rather than absolute data to reset
87 * their counters.
88 * @param settings A QSettings object opened in the dedicated group of this
89 * data source.
90 */
91 void reset(QSettings *settings);
92
93 /*! Returns which telemetry colleciton mode this data source belongs to.
94 * @return The telemetry collection category this source belongs to.
95 */
96 Provider::TelemetryMode telemetryMode() const;
97
98 /*! Sets which telemetry colleciton mode this data source belongs to.
99 * @param mode The data collection mode of this source.
100 * Provider::NoTelemetry is not allowed here.
101 */
102 void setTelemetryMode(Provider::TelemetryMode mode);
103
104 /*! Checks whether this data source is active or not
105 * If the data source is not active, then collected
106 * data neither will be sent to a server nor appeared
107 * in the audit log.
108 * Data source is active by default.
109 * @return true if active, false otherwise
110 */
111 bool isActive() const;
112
113 /*! Changes active state of the data source
114 * @param active The new active state for this data source
115 */
116 void setActive(bool active);
117
118protected:
119 /*! Create a new data source named @p name.
120 * The name of the data source must match the corresponding
121 * product schema entry.
122 * @param id Must not be empty.
123 * @param mode The default telemetry mode.
124 */
125 explicit AbstractDataSource(const QString &id,
126 Provider::TelemetryMode mode = Provider::DetailedUsageStatistics);
127
128 ///@cond internal
129 explicit AbstractDataSource(const QString &id,
131 AbstractDataSourcePrivate *dd);
132 ///@endcond
133
134 /*! Set the ID of this data source.
135 * The ID should not change at runtime, this is only provided
136 * for enabling QML API for generic sources.
137 * @see id()
138 */
139 void setId(const QString &id);
140
141 /*! Invoked by @p load() in order to load individual settings of this data source.
142 * @see load() description for further details.
143 * @param settings A QSettings object opened in a dedicated group for loading
144 * persistent data.
145 */
146 virtual void loadImpl(QSettings *settings);
147
148 /*! Invoked by @p store() in order to store individual settings of this data source.
149 * @see store() description for further details.
150 * @param settings A QSettings object opened in a dedicated group for loading
151 * persistent data.
152 */
153 virtual void storeImpl(QSettings *settings);
154
155 /*! Invoked by @p reset() in order to reset individual settings of this data source.
156 * @see reset() description for further details.
157 * @param settings A QSettings object opened in a dedicated group for loading
158 * persistent data.
159 */
160 virtual void resetImpl(QSettings *settings);
161
162 ///@cond internal
163 class AbstractDataSourcePrivate* const d_ptr;
164 ///@endcond
165
166private:
167 Q_DECLARE_PRIVATE(AbstractDataSource)
168 Q_DISABLE_COPY(AbstractDataSource)
169};
170}
171
172#endif // KUSERFEEDBACK_ABSTRACTDATASOURCE_H
Base class for data sources for telemetry data.
virtual QVariant data()=0
Returns the data gathered by this source.
virtual QString description() const =0
Returns a human-readable, translated description of what this source provides.
TelemetryMode
Telemetry collection modes.
Definition provider.h:102
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.