Commit 68e9090d authored by Volker Krause's avatar Volker Krause
Browse files

Make statistics collection configurable.

parent 21160a98
...@@ -52,6 +52,9 @@ FeedbackConfigDialog::~FeedbackConfigDialog() = default; ...@@ -52,6 +52,9 @@ FeedbackConfigDialog::~FeedbackConfigDialog() = default;
void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::Provider* provider) void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::Provider* provider)
{ {
m_provider = provider; m_provider = provider;
ui->advancedStats->setChecked(m_provider->statisticsCollectionMode() == Provider::AllStatistics);
ui->basicStats->setChecked(m_provider->statisticsCollectionMode() != Provider::NoStatistics);
ui->allSurveys->setChecked(m_provider->surveyInterval() >= 0 && m_provider->surveyInterval() < 90); ui->allSurveys->setChecked(m_provider->surveyInterval() >= 0 && m_provider->surveyInterval() < 90);
ui->basicSurveys->setChecked(m_provider->surveyInterval() >= 90); ui->basicSurveys->setChecked(m_provider->surveyInterval() >= 90);
updateButtonState(); updateButtonState();
...@@ -59,7 +62,12 @@ void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::Provider* provider) ...@@ -59,7 +62,12 @@ void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::Provider* provider)
void FeedbackConfigDialog::accept() void FeedbackConfigDialog::accept()
{ {
qDebug(); if (!ui->basicStats->isChecked()) {
m_provider->setStatisticsCollectionMode(Provider::NoStatistics);
} else {
m_provider->setStatisticsCollectionMode(ui->advancedStats->isChecked() ? Provider::AllStatistics : Provider::BasicStatistics);
}
if (!ui->basicSurveys->isChecked()) { if (!ui->basicSurveys->isChecked()) {
m_provider->setSurveyInterval(-1); m_provider->setSurveyInterval(-1);
} else { } else {
......
...@@ -64,6 +64,7 @@ public: ...@@ -64,6 +64,7 @@ public:
QUrl serverUrl; QUrl serverUrl;
QDateTime lastSubmitTime; QDateTime lastSubmitTime;
int submissionInterval; int submissionInterval;
Provider::StatisticsCollectionMode statisticsMode;
int surveyInterval; int surveyInterval;
QDateTime lastSurveyTime; QDateTime lastSurveyTime;
...@@ -79,6 +80,7 @@ ProviderPrivate::ProviderPrivate(Provider *qq) ...@@ -79,6 +80,7 @@ ProviderPrivate::ProviderPrivate(Provider *qq)
: q(qq) : q(qq)
, networkAccessManager(Q_NULLPTR) , networkAccessManager(Q_NULLPTR)
, submissionInterval(-1) , submissionInterval(-1)
, statisticsMode(Provider::NoStatistics)
, surveyInterval(-1) , surveyInterval(-1)
, startCount(0) , startCount(0)
, usageTime(0) , usageTime(0)
...@@ -107,11 +109,15 @@ void ProviderPrivate::load() ...@@ -107,11 +109,15 @@ void ProviderPrivate::load()
QSettings settings; QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback")); settings.beginGroup(QStringLiteral("UserFeedback"));
lastSubmitTime = settings.value(QStringLiteral("LastSubmission")).toDateTime(); lastSubmitTime = settings.value(QStringLiteral("LastSubmission")).toDateTime();
startCount = std::max(settings.value(QStringLiteral("ApplicationStartCount"), 0).toInt() + 1, 1); // TODO store as string via QMetaEnum
usageTime = std::max(settings.value(QStringLiteral("ApplicationTime"), 0).toInt(), 0); statisticsMode = static_cast<Provider::StatisticsCollectionMode>(settings.value(QStringLiteral("StatisticsCollectionMode"), Provider::NoStatistics).toInt());
surveyInterval = settings.value(QStringLiteral("SurveyInterval"), -1).toInt(); surveyInterval = settings.value(QStringLiteral("SurveyInterval"), -1).toInt();
lastSurveyTime = settings.value(QStringLiteral("LastSurvey")).toDateTime(); lastSurveyTime = settings.value(QStringLiteral("LastSurvey")).toDateTime();
completedSurveys = settings.value(QStringLiteral("CompletedSurveys"), QStringList()).toStringList(); completedSurveys = settings.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);
} }
void ProviderPrivate::store() void ProviderPrivate::store()
...@@ -119,11 +125,14 @@ void ProviderPrivate::store() ...@@ -119,11 +125,14 @@ void ProviderPrivate::store()
QSettings settings; QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback")); settings.beginGroup(QStringLiteral("UserFeedback"));
settings.setValue(QStringLiteral("LastSubmission"), lastSubmitTime); settings.setValue(QStringLiteral("LastSubmission"), lastSubmitTime);
settings.setValue(QStringLiteral("ApplicationStartCount"), startCount); settings.setValue(QStringLiteral("StatisticsCollectionMode"), statisticsMode);
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
settings.setValue(QStringLiteral("SurveyInterval"), surveyInterval); settings.setValue(QStringLiteral("SurveyInterval"), surveyInterval);
settings.setValue(QStringLiteral("LastSurvey"), lastSurveyTime); settings.setValue(QStringLiteral("LastSurvey"), lastSurveyTime);
settings.setValue(QStringLiteral("CompletedSurveys"), completedSurveys); settings.setValue(QStringLiteral("CompletedSurveys"), completedSurveys);
settings.setValue(QStringLiteral("ApplicationStartCount"), startCount);
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
} }
void ProviderPrivate::aboutToQuit() void ProviderPrivate::aboutToQuit()
...@@ -136,9 +145,12 @@ QByteArray ProviderPrivate::jsonData() const ...@@ -136,9 +145,12 @@ QByteArray ProviderPrivate::jsonData() const
{ {
QJsonObject obj; QJsonObject obj;
obj.insert(QStringLiteral("productId"), productId); obj.insert(QStringLiteral("productId"), productId);
obj.insert(QStringLiteral("startCount"), startCount);
obj.insert(QStringLiteral("usageTime"), currentApplicationTime()); if (statisticsMode != Provider::NoStatistics) {
obj.insert(QStringLiteral("version"), QCoreApplication::applicationVersion()); obj.insert(QStringLiteral("startCount"), startCount);
obj.insert(QStringLiteral("usageTime"), currentApplicationTime());
obj.insert(QStringLiteral("version"), QCoreApplication::applicationVersion());
}
QJsonDocument doc(obj); QJsonDocument doc(obj);
return doc.toJson(); return doc.toJson();
...@@ -223,6 +235,16 @@ void Provider::setSubmissionInterval(int days) ...@@ -223,6 +235,16 @@ void Provider::setSubmissionInterval(int days)
QTimer::singleShot(now.msecsTo(nextSubmission), this, SLOT(submit())); QTimer::singleShot(now.msecsTo(nextSubmission), this, SLOT(submit()));
} }
Provider::StatisticsCollectionMode Provider::statisticsCollectionMode() const
{
return d->statisticsMode;
}
void Provider::setStatisticsCollectionMode(StatisticsCollectionMode mode)
{
d->statisticsMode = mode;
}
int Provider::surveyInterval() const int Provider::surveyInterval() const
{ {
return d->surveyInterval; return d->surveyInterval;
......
...@@ -34,6 +34,13 @@ class USERFEEDBACKCORE_EXPORT Provider : public QObject ...@@ -34,6 +34,13 @@ class USERFEEDBACKCORE_EXPORT Provider : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum StatisticsCollectionMode {
NoStatistics,
BasicStatistics,
AllStatistics
};
Q_ENUMS(StatisticsCollectionMode);
explicit Provider(QObject *parent = Q_NULLPTR); explicit Provider(QObject *parent = Q_NULLPTR);
~Provider(); ~Provider();
...@@ -48,6 +55,12 @@ public: ...@@ -48,6 +55,12 @@ public:
/** Set the automatic submission interval. */ /** Set the automatic submission interval. */
void setSubmissionInterval(int days); void setSubmissionInterval(int days);
/** Returns the current statistics collection mode. */
StatisticsCollectionMode statisticsCollectionMode() const;
/** Set which statistics should be submitted. */
void setStatisticsCollectionMode(StatisticsCollectionMode mode);
/** Returns the minimum time between two surveys in days. */ /** Returns the minimum time between two surveys in days. */
int surveyInterval() const; int surveyInterval() const;
......
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