Commit 66a2e9ae authored by Volker Krause's avatar Volker Krause
Browse files

Store telemetry mode as stringified enum rather than numeric value

parent 85720754
......@@ -138,6 +138,29 @@ private slots:
b.replace('\n', "");
QCOMPARE(b.constData(), "{}");
}
void testLoadStore()
{
{
Provider p;
p.setStatisticsCollectionMode(Provider::NoStatistics);
p.setSurveyInterval(-1);
}
{
Provider p;
QCOMPARE(p.statisticsCollectionMode(), Provider::NoStatistics);
QCOMPARE(p.surveyInterval(), -1);
p.setStatisticsCollectionMode(Provider::DetailedSystemInformation);
p.setSurveyInterval(90);
}
{
Provider p;
QCOMPARE(p.statisticsCollectionMode(), Provider::DetailedSystemInformation);
QCOMPARE(p.surveyInterval(), 90);
}
}
};
QTEST_MAIN(ProviderTest)
......
......@@ -31,6 +31,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#endif
#include <QMetaEnum>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
......@@ -85,13 +86,21 @@ int ProviderPrivate::currentApplicationTime() const
return usageTime + (startTime.elapsed() / 1000);
}
static QMetaEnum statisticsCollectionModeEnum()
{
const auto idx = Provider::staticMetaObject.indexOfEnumerator("StatisticsCollectionMode");
Q_ASSERT(idx >= 0);
return Provider::staticMetaObject.enumerator(idx);
}
void ProviderPrivate::load()
{
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
lastSubmitTime = settings.value(QStringLiteral("LastSubmission")).toDateTime();
// TODO store as string via QMetaEnum
statisticsMode = static_cast<Provider::StatisticsCollectionMode>(settings.value(QStringLiteral("StatisticsCollectionMode"), Provider::NoStatistics).toInt());
const auto modeStr = settings.value(QStringLiteral("StatisticsCollectionMode")).toByteArray();
statisticsMode = static_cast<Provider::StatisticsCollectionMode>(std::max(statisticsCollectionModeEnum().keyToValue(modeStr), 0));
surveyInterval = settings.value(QStringLiteral("SurveyInterval"), -1).toInt();
lastSurveyTime = settings.value(QStringLiteral("LastSurvey")).toDateTime();
......@@ -108,7 +117,7 @@ void ProviderPrivate::store()
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
settings.setValue(QStringLiteral("LastSubmission"), lastSubmitTime);
settings.setValue(QStringLiteral("StatisticsCollectionMode"), statisticsMode);
settings.setValue(QStringLiteral("StatisticsCollectionMode"), QString::fromLatin1(statisticsCollectionModeEnum().valueToKey(statisticsMode)));
settings.setValue(QStringLiteral("SurveyInterval"), surveyInterval);
settings.setValue(QStringLiteral("LastSurvey"), lastSurveyTime);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment