KUserFeedback

abstractdatasource.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include <QtCore/QSettings>
8
9#include "abstractdatasource.h"
10#include "abstractdatasource_p.h"
11
12using namespace KUserFeedback;
13
14static bool defaultActiveState() { return true; }
15static QString activeStateKey() { return QStringLiteral("activeState"); }
16
17static QString commonSettingsGroupName() { return QStringLiteral("dataSourceCommonSettings"); }
18
19AbstractDataSourcePrivate::AbstractDataSourcePrivate()
20 : mode(Provider::DetailedUsageStatistics)
21 , active(defaultActiveState())
22{
23}
24
25AbstractDataSourcePrivate::~AbstractDataSourcePrivate()
26{
27}
28
29void AbstractDataSourcePrivate::storeCommonSettings(QSettings *settings)
30{
31 settings->beginGroup(commonSettingsGroupName());
32
33 settings->setValue(activeStateKey(), active);
34
35 settings->endGroup();
36}
37
38void AbstractDataSourcePrivate::loadCommonSettings(QSettings *settings)
39{
40 settings->beginGroup(commonSettingsGroupName());
41
42 active = settings->value(activeStateKey(), defaultActiveState()).toBool();
43
44 settings->endGroup();
45}
46
47// Please note that this function is supposed to be invoked in between
48// data submissions, so be careful to don't reset flags that might be
49// changed by a user via UI (e.g., active state)
50void AbstractDataSourcePrivate::resetCommonSettings(QSettings *settings)
51{
52 Q_UNUSED(settings);
53}
54
59
61 AbstractDataSourcePrivate* dd)
62 : d_ptr(dd ? dd : new AbstractDataSourcePrivate)
63{
64 d_ptr->id = id;
65 d_ptr->mode = mode;
66}
67
68AbstractDataSource::~AbstractDataSource()
69{
70 delete d_ptr;
71}
72
74{
75 return d_ptr->id;
76}
77
79{
80 return {};
81}
82
84{
85 d_ptr->id = id;
86}
87
89{
90 Q_UNUSED(settings);
91}
92
94{
95 Q_UNUSED(settings);
96}
97
99{
100 Q_UNUSED(settings);
101}
102
104{
106 d->loadCommonSettings(settings);
107
108 loadImpl(settings);
109}
110
112{
114 d->storeCommonSettings(settings);
115
116 storeImpl(settings);
117}
118
120{
122 d->resetCommonSettings(settings);
123
124 resetImpl(settings);
125}
126
128{
129 Q_D(const AbstractDataSource);
130
131 Q_ASSERT(d->mode != Provider::NoTelemetry);
132 if (d->mode == Provider::NoTelemetry)
134 return d->mode;
135}
136
138{
140 Q_ASSERT(mode != Provider::NoTelemetry);
141 d->mode = mode;
142}
143
145{
146 Q_D(const AbstractDataSource);
147 return d->active;
148}
149
151{
153 d->active = active;
154}
Base class for data sources for telemetry data.
void load(QSettings *settings)
Load persistent state for this data source.
AbstractDataSource(const QString &id, Provider::TelemetryMode mode=Provider::DetailedUsageStatistics)
Create a new data source named name.
void setActive(bool active)
Changes active state of the data source.
QString id() const
Returns the ID of this data source.
virtual void resetImpl(QSettings *settings)
Invoked by reset() in order to reset individual settings of this data source.
void reset(QSettings *settings)
Reset the persistent state of this data source.
virtual void storeImpl(QSettings *settings)
Invoked by store() in order to store individual settings of this data source.
virtual QString name() const
Returns a short name of this data source.
void setTelemetryMode(Provider::TelemetryMode mode)
Sets which telemetry colleciton mode this data source belongs to.
void setId(const QString &id)
Set the ID of this data source.
Provider::TelemetryMode telemetryMode() const
Returns which telemetry colleciton mode this data source belongs to.
bool isActive() const
Checks whether this data source is active or not If the data source is not active,...
virtual void loadImpl(QSettings *settings)
Invoked by load() in order to load individual settings of this data source.
void store(QSettings *settings)
Store persistent state for this data source.
The central object managing data sources and transmitting feedback to the server.
Definition provider.h:32
TelemetryMode
Telemetry collection modes.
Definition provider.h:102
@ DetailedUsageStatistics
Transmit detailed usage statistics.
Definition provider.h:107
@ NoTelemetry
Transmit no data at all.
Definition provider.h:103
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
void beginGroup(QAnyStringView prefix)
void endGroup()
void setValue(QAnyStringView key, const QVariant &value)
QVariant value(QAnyStringView key) const const
bool toBool() const const
Q_D(Todo)
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.