KUserFeedback

feedbackconfiguicontroller.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "feedbackconfiguicontroller.h"
8#include "abstractdatasource.h"
9
10#include <QGuiApplication>
11#include <QSet>
12#include <QVector>
13
14#include <algorithm>
15#include <vector>
16
17using namespace KUserFeedback;
18
19namespace KUserFeedback {
20class FeedbackConfigUiControllerPrivate {
21public:
22 FeedbackConfigUiControllerPrivate();
23
24 Provider *provider;
25 std::vector<Provider::TelemetryMode> telemetryModeMap;
26 QString m_appName;
27};
28}
29
30FeedbackConfigUiControllerPrivate::FeedbackConfigUiControllerPrivate() :
31 provider(nullptr),
32 m_appName(QGuiApplication::applicationDisplayName())
33{
34}
35
36FeedbackConfigUiController::FeedbackConfigUiController(QObject* parent)
37 : QObject(parent)
38 , d(new FeedbackConfigUiControllerPrivate)
39{
40}
41
42FeedbackConfigUiController::~FeedbackConfigUiController()
43{
44}
45
47{
48 return d->provider;
49}
50
52{
53 if (d->provider == provider)
54 return;
55 d->provider = provider;
56
57 d->telemetryModeMap.clear();
58 d->telemetryModeMap.reserve(5);
59 d->telemetryModeMap.push_back(Provider::NoTelemetry);
60 d->telemetryModeMap.push_back(Provider::BasicSystemInformation);
61 d->telemetryModeMap.push_back(Provider::BasicUsageStatistics);
62 d->telemetryModeMap.push_back(Provider::DetailedSystemInformation);
63 d->telemetryModeMap.push_back(Provider::DetailedUsageStatistics);
64
65 QSet<Provider::TelemetryMode> supportedModes;
66 supportedModes.reserve(d->telemetryModeMap.size());
67 supportedModes.insert(Provider::NoTelemetry);
68 foreach (const auto &src, provider->dataSources())
69 supportedModes.insert(src->telemetryMode());
70 for (auto it = d->telemetryModeMap.begin(); it != d->telemetryModeMap.end();) {
71 if (!supportedModes.contains(*it))
72 it = d->telemetryModeMap.erase(it);
73 else
74 ++it;
75 }
76
78}
79
81{
82 return d->telemetryModeMap.size();
83}
84
86{
87 return 3;
88}
89
91{
92 if (index < 0 || index >= telemetryModeCount())
94 return d->telemetryModeMap[index];
95}
96
98{
99 const auto it = std::lower_bound(d->telemetryModeMap.begin(), d->telemetryModeMap.end(), mode);
100 if (it == d->telemetryModeMap.end())
101 return 0;
102 return std::distance(d->telemetryModeMap.begin(), it);
103}
104
106{
107 return telemetryName(telemetryIndexToMode(telemetryIndex));
108}
109
111{
112 return telemetryDescription(telemetryIndexToMode(telemetryIndex));
113}
114
116{
117 switch (mode) {
119 return tr("Disabled");
121 return tr("Basic system information");
123 return tr("Basic system information and usage statistics");
125 return tr("Detailed system information and basic usage statistics");
127 return tr("Detailed system information and usage statistics");
128 }
129
130 return {};
131}
132
134{
135 const auto name = applicationName();
136 if (name.isEmpty()) {
137 switch (mode) {
139 return tr(
140 "Don't share anything"
141 );
143 return tr(
144 "Share basic system information such as the version of the application and the operating system"
145 );
147 return tr(
148 "Share basic system information and basic statistics on how often you use the application"
149 );
151 return tr(
152 "Share basic statistics on how often you use the application, as well as more detailed information about your system"
153 );
155 return tr(
156 "Share detailed system information and statistics on how often individual features of the application are used."
157 );
158 }
159 } else {
160 switch (mode) {
162 return tr(
163 "Don't share anything"
164 );
166 return tr(
167 "Share basic system information such as the version of %1 and and the operating system"
168 ).arg(name);
170 return tr(
171 "Share basic system information and basic statistics on how often you use %1"
172 ).arg(name);
174 return tr(
175 "Share basic statistics on how often you use %1, as well as more detailed information about your system"
176 ).arg(name);
178 return tr(
179 "Share detailed system information and statistics on how often individual features of %1 are used."
180 ).arg(name);
181 }
182 }
183
184 return QString();
185}
186
188{
189 if (telemetryIndex <= 0 || telemetryIndex >= telemetryModeCount())
190 return QString();
191
192 auto srcs = d->provider->dataSources();
193 std::stable_sort(srcs.begin(), srcs.end(), [](AbstractDataSource *lhs, AbstractDataSource *rhs) {
194 return lhs->telemetryMode() < rhs->telemetryMode();
195 });
196
197 auto detailsStr = QStringLiteral("<ul>");
198 foreach (const auto *src, srcs) {
199 if (telemetryIndex >= telemetryModeToIndex(src->telemetryMode()) && !src->description().isEmpty())
200 detailsStr += QStringLiteral("<li>") + src->description() + QStringLiteral("</li>");
201 }
202 return detailsStr + QStringLiteral("</ul>");
203}
204
206{
207 switch (index) {
208 case 0: return -1;
209 case 1: return 90;
210 case 2: return 0;
211 }
212 return -1;
213}
214
216{
217 if (interval < 0)
218 return 0;
219 else if (interval >= 90)
220 return 1;
221 else
222 return 2;
223}
224
226{
227 const auto name = applicationName();
228 if (name.isEmpty()) {
229 switch (surveyIndex) {
230 case 0:
231 return tr(
232 "Don't participate in usability surveys"
233 );
234 case 1:
235 return tr(
236 "Participate in surveys about the application not more than four times a year"
237 );
238 case 2:
239 return tr(
240 "Participate in surveys about the application whenever one is available (they can be deferred or skipped)"
241 );
242 }
243 } else {
244 switch (surveyIndex) {
245 case 0:
246 return tr(
247 "Don't participate in usability surveys about %1"
248 ).arg(name);
249 case 1:
250 return tr(
251 "Participate in surveys about %1 not more than four times a year"
252 ).arg(name);
253 case 2:
254 return tr(
255 "Participate in surveys about %1 whenever one is available (they can be deferred or skipped)"
256 ).arg(name);
257 }
258 }
259
260 return QString();
261}
262
264{
265 return d->m_appName;
266}
267
268void FeedbackConfigUiController::setApplicationName(const QString& appName)
269{
270 if (appName == d->m_appName)
271 return;
272
273 d->m_appName = appName;
274 Q_EMIT applicationNameChanged(appName);
275}
276
277#include "moc_feedbackconfiguicontroller.cpp"
Base class for data sources for telemetry data.
KUserFeedback::Provider * feedbackProvider
The Provider instance we are configuring.
Q_INVOKABLE QString telemetryDescription(KUserFeedback::Provider::TelemetryMode mode) const
Telemetry mode explanation text.
void providerChanged()
A provider-related setting has changed.
void setFeedbackProvider(Provider *provider)
Set the feedback provider to configure.
Q_INVOKABLE QString telemetryModeDescription(int telemetryIndex) const
Telemetry mode explanation text.
Q_INVOKABLE int surveyIntervalToIndex(int interval) const
Convert survey interval to slider index.
Q_INVOKABLE int surveyIndexToInterval(int index) const
Convert slider index to survey interval.
Q_INVOKABLE QString surveyModeDescription(int surveyIndex) const
Survey mode explanation text.
Q_INVOKABLE QString telemetryModeDetails(int telemetryIndex) const
Detailed information about the data sources of the given telemetry mode index.
int telemetryModeCount
Amount of telemetry modes supported by the provider.
QString applicationName
Name of the application that will appear on descriptions.
Q_INVOKABLE int telemetryModeToIndex(KUserFeedback::Provider::TelemetryMode mode) const
Convert telemetry mode to slider index.
Q_INVOKABLE KUserFeedback::Provider::TelemetryMode telemetryIndexToMode(int index) const
Convert slider index to telemetry mode.
Q_INVOKABLE QString telemetryModeName(int telemetryIndex) const
Telemetry mode short name.
int surveyModeCount
Amount of supported survey modes.
Q_INVOKABLE QString telemetryName(KUserFeedback::Provider::TelemetryMode mode) const
Telemetry mode short name.
The central object managing data sources and transmitting feedback to the server.
Definition provider.h:32
TelemetryMode
Telemetry collection modes.
Definition provider.h:102
@ BasicSystemInformation
Transmit basic information about the system.
Definition provider.h:104
@ DetailedSystemInformation
Transmit detailed system information.
Definition provider.h:106
@ DetailedUsageStatistics
Transmit detailed usage statistics.
Definition provider.h:107
@ BasicUsageStatistics
Transmit basic usage statistics.
Definition provider.h:105
@ NoTelemetry
Transmit no data at all.
Definition provider.h:103
QVector< AbstractDataSource * > dataSources() const
Returns all data sources that have been added to this provider.
Definition provider.cpp:526
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
void reserve(qsizetype size)
QString arg(Args &&... args) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.