Commit a16dd560 authored by Volker Krause's avatar Volker Krause
Browse files

Separate user feedback settings from application settings

This matters when collecting feedback on components that can be
embedded elsewhere (e.g. KMail vs Kontact).
parent 2cb613ec
......@@ -36,6 +36,9 @@ class ProviderTest : public QObject
private slots:
void initTestCase()
{
QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
QCoreApplication::setApplicationName(QStringLiteral("providertest"));
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QStandardPaths::setTestModeEnabled(true);
#endif
......@@ -81,7 +84,7 @@ private slots:
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
{
QSettings s;
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.remove(QLatin1String("LastEncouragement"));
}
......@@ -114,7 +117,7 @@ private slots:
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
{
QSettings s;
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.remove(QLatin1String("LastEncouragement"));
}
......@@ -137,7 +140,7 @@ private slots:
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
{
QSettings s;
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.remove(QLatin1String("LastEncouragement"));
}
......@@ -162,7 +165,7 @@ private slots:
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
{
QSettings s;
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.setValue(QLatin1String("LastEncouragement"), QDateTime::currentDateTime().addSecs(-24 * 60 * 60 + 1));
}
......@@ -181,7 +184,7 @@ private slots:
}
{
QSettings s;
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.setValue(QLatin1String("LastEncouragement"), QDateTime::currentDateTime().addSecs(-24 * 60 * 60 - 1));
}
......
......@@ -108,43 +108,49 @@ static QMetaEnum statisticsCollectionModeEnum()
return Provider::staticMetaObject.enumerator(idx);
}
std::unique_ptr<QSettings> ProviderPrivate::makeSettings() const
{
std::unique_ptr<QSettings> s(new QSettings(QStringLiteral("KDE"), QStringLiteral("UserFeedback.") + productId));
return s;
}
void ProviderPrivate::load()
{
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
lastSubmitTime = settings.value(QStringLiteral("LastSubmission")).toDateTime();
auto s = makeSettings();
s->beginGroup(QStringLiteral("UserFeedback"));
lastSubmitTime = s->value(QStringLiteral("LastSubmission")).toDateTime();
const auto modeStr = settings.value(QStringLiteral("StatisticsCollectionMode")).toByteArray();
const auto modeStr = s->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();
completedSurveys = settings.value(QStringLiteral("CompletedSurveys"), QStringList()).toStringList();
surveyInterval = s->value(QStringLiteral("SurveyInterval"), -1).toInt();
lastSurveyTime = s->value(QStringLiteral("LastSurvey")).toDateTime();
completedSurveys = s->value(QStringLiteral("CompletedSurveys"), QStringList()).toStringList();
startCount = std::max(settings.value(QStringLiteral("ApplicationStartCount"), 0).toInt() + 1, 1);
usageTime = std::max(settings.value(QStringLiteral("ApplicationTime"), 0).toInt(), 0);
startCount = std::max(s->value(QStringLiteral("ApplicationStartCount"), 0).toInt() + 1, 1);
usageTime = std::max(s->value(QStringLiteral("ApplicationTime"), 0).toInt(), 0);
lastEncouragementTime = settings.value(QStringLiteral("LastEncouragement")).toDateTime();
lastEncouragementTime = s->value(QStringLiteral("LastEncouragement")).toDateTime();
}
void ProviderPrivate::store()
{
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
settings.setValue(QStringLiteral("LastSubmission"), lastSubmitTime);
settings.setValue(QStringLiteral("StatisticsCollectionMode"), QString::fromLatin1(statisticsCollectionModeEnum().valueToKey(statisticsMode)));
auto s = makeSettings();
s->beginGroup(QStringLiteral("UserFeedback"));
s->setValue(QStringLiteral("LastSubmission"), lastSubmitTime);
s->setValue(QStringLiteral("StatisticsCollectionMode"), QString::fromLatin1(statisticsCollectionModeEnum().valueToKey(statisticsMode)));
settings.setValue(QStringLiteral("SurveyInterval"), surveyInterval);
settings.setValue(QStringLiteral("LastSurvey"), lastSurveyTime);
settings.setValue(QStringLiteral("CompletedSurveys"), completedSurveys);
s->setValue(QStringLiteral("SurveyInterval"), surveyInterval);
s->setValue(QStringLiteral("LastSurvey"), lastSurveyTime);
s->setValue(QStringLiteral("CompletedSurveys"), completedSurveys);
settings.setValue(QStringLiteral("ApplicationStartCount"), startCount);
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
s->setValue(QStringLiteral("ApplicationStartCount"), startCount);
s->setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
settings.setValue(QStringLiteral("LastEncouragement"), lastEncouragementTime);
s->setValue(QStringLiteral("LastEncouragement"), lastEncouragementTime);
foreach (auto source, dataSources)
source->store(&settings);
source->store(s.get());
}
void ProviderPrivate::aboutToQuit()
......@@ -429,9 +435,9 @@ void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMod
d->dataSources.push_back(source);
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
source->load(&settings);
auto s = d->makeSettings();
s->beginGroup(QStringLiteral("UserFeedback"));
source->load(s.get());
}
QVector<AbstractDataSource*> Provider::dataSources() const
......
......@@ -28,8 +28,11 @@
#include <QTimer>
#include <QVector>
#include <memory>
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QSettings;
QT_END_NAMESPACE
namespace UserFeedback {
......@@ -42,6 +45,7 @@ public:
void reset();
int currentApplicationTime() const;
std::unique_ptr<QSettings> makeSettings() const;
void load();
void store();
......
......@@ -81,7 +81,7 @@ void Orwell::loadStats()
{
ui->version->setText(QCoreApplication::applicationVersion());
QSettings settings;
QSettings settings(QStringLiteral("KDE"), QStringLiteral("UserFeedback.org.kde.orwell"));
ui->startCount->setValue(settings.value(QStringLiteral("UserFeedback/ApplicationStartCount")).toInt());
ui->runtime->setValue(settings.value(QStringLiteral("UserFeedback/ApplicationTime")).toInt());
ui->surveys->setText(settings.value(QStringLiteral("UserFeedback/CompletedSurveys")).toStringList().join(QStringLiteral(", ")));
......@@ -90,7 +90,7 @@ void Orwell::loadStats()
void Orwell::writeStats()
{
QSettings settings;
QSettings settings(QStringLiteral("KDE"), QStringLiteral("UserFeedback.org.kde.orwell"));
settings.setValue(QStringLiteral("UserFeedback/ApplicationStartCount"), ui->startCount->value());
settings.setValue(QStringLiteral("UserFeedback/ApplicationTime"), ui->runtime->value());
settings.setValue(QStringLiteral("UserFeedback/CompletedSurveys"), ui->surveys->text().split(QStringLiteral(", ")));
......
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