File indexing completed on 2024-12-15 03:45:03
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KUSERFEEDBACK_ABSTRACTDATASOURCE_H 0008 #define KUSERFEEDBACK_ABSTRACTDATASOURCE_H 0009 0010 #include "kuserfeedbackcore_export.h" 0011 #include "provider.h" 0012 0013 #include <QCoreApplication> 0014 0015 QT_BEGIN_NAMESPACE 0016 class QSettings; 0017 QT_END_NAMESPACE 0018 0019 namespace KUserFeedback { 0020 0021 class AbstractDataSourcePrivate; 0022 0023 /*! Base class for data sources for telemetry data. */ 0024 class KUSERFEEDBACKCORE_EXPORT AbstractDataSource 0025 { 0026 public: 0027 virtual ~AbstractDataSource(); 0028 0029 /*! Returns the ID of this data source. 0030 * This is used as identifier towards the server and should 0031 * not be shown to the user. 0032 * @see description() 0033 * @returns The data source identifier configured on the feedback server. 0034 */ 0035 QString id() const; 0036 0037 /*! Returns a short name of this data source. 0038 * Can be empty if short name is meaningless for this data source. 0039 * @returns A translated, human-readable string. 0040 */ 0041 virtual QString name() const; 0042 0043 /*! Returns a human-readable, translated description of what 0044 * this source provides. 0045 * @see id() 0046 * @returns A translated, human-readable string. 0047 */ 0048 virtual QString description() const = 0; 0049 0050 /*! 0051 * Returns the data gathered by this source. 0052 * 0053 * Implement this to return the data provided by this source. 0054 * One of the three following formats are expected: 0055 * - scalar entries: QAssociativeIterable 0056 * - list entries: QSequentialIterable containing QAssociativeIterable 0057 * - map entries: QAssociativeIterable containing QAssociativeIterable 0058 * 0059 * The innermost QAssociativeIterable must only contain one of the following 0060 * base types (which has to match the corresponding schema entry element): 0061 * - QString 0062 * - int 0063 * - double 0064 * - bool 0065 * 0066 * All keys must be strings. 0067 * 0068 * @returns A variant complying with the above requirements. 0069 */ 0070 virtual QVariant data() = 0; 0071 0072 /*! Load persistent state for this data source. 0073 * @param settings A QSettings object opened in a dedicated group for loading 0074 * persistent data. 0075 */ 0076 void load(QSettings *settings); 0077 0078 /*! Store persistent state for this data source. 0079 * @param settings A QSettings object opened in a dedicated group for storing 0080 * persistent data. 0081 */ 0082 void store(QSettings *settings); 0083 0084 /*! Reset the persistent state of this data source. 0085 * This is called after a successful submission of data, and can be used 0086 * by sources that track differential rather than absolute data to reset 0087 * their counters. 0088 * @param settings A QSettings object opened in the dedicated group of this 0089 * data source. 0090 */ 0091 void reset(QSettings *settings); 0092 0093 /*! Returns which telemetry colleciton mode this data source belongs to. 0094 * @return The telemetry collection category this source belongs to. 0095 */ 0096 Provider::TelemetryMode telemetryMode() const; 0097 0098 /*! Sets which telemetry colleciton mode this data source belongs to. 0099 * @param mode The data collection mode of this source. 0100 * Provider::NoTelemetry is not allowed here. 0101 */ 0102 void setTelemetryMode(Provider::TelemetryMode mode); 0103 0104 /*! Checks whether this data source is active or not 0105 * If the data source is not active, then collected 0106 * data neither will be sent to a server nor appeared 0107 * in the audit log. 0108 * Data source is active by default. 0109 * @return true if active, false otherwise 0110 */ 0111 bool isActive() const; 0112 0113 /*! Changes active state of the data source 0114 * @param active The new active state for this data source 0115 */ 0116 void setActive(bool active); 0117 0118 protected: 0119 /*! Create a new data source named @p name. 0120 * The name of the data source must match the corresponding 0121 * product schema entry. 0122 * @param id Must not be empty. 0123 * @param mode The default telemetry mode. 0124 */ 0125 explicit AbstractDataSource(const QString &id, 0126 Provider::TelemetryMode mode = Provider::DetailedUsageStatistics); 0127 0128 ///@cond internal 0129 explicit AbstractDataSource(const QString &id, 0130 Provider::TelemetryMode mode, 0131 AbstractDataSourcePrivate *dd); 0132 ///@endcond 0133 0134 /*! Set the ID of this data source. 0135 * The ID should not change at runtime, this is only provided 0136 * for enabling QML API for generic sources. 0137 * @see id() 0138 */ 0139 void setId(const QString &id); 0140 0141 /*! Invoked by @p load() in order to load individual settings of this data source. 0142 * @see load() description for further details. 0143 * @param settings A QSettings object opened in a dedicated group for loading 0144 * persistent data. 0145 */ 0146 virtual void loadImpl(QSettings *settings); 0147 0148 /*! Invoked by @p store() in order to store individual settings of this data source. 0149 * @see store() description for further details. 0150 * @param settings A QSettings object opened in a dedicated group for loading 0151 * persistent data. 0152 */ 0153 virtual void storeImpl(QSettings *settings); 0154 0155 /*! Invoked by @p reset() in order to reset individual settings of this data source. 0156 * @see reset() description for further details. 0157 * @param settings A QSettings object opened in a dedicated group for loading 0158 * persistent data. 0159 */ 0160 virtual void resetImpl(QSettings *settings); 0161 0162 ///@cond internal 0163 class AbstractDataSourcePrivate* const d_ptr; 0164 ///@endcond 0165 0166 private: 0167 Q_DECLARE_PRIVATE(AbstractDataSource) 0168 Q_DISABLE_COPY(AbstractDataSource) 0169 }; 0170 } 0171 0172 #endif // KUSERFEEDBACK_ABSTRACTDATASOURCE_H