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;
void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::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->basicSurveys->setChecked(m_provider->surveyInterval() >= 90);
updateButtonState();
......@@ -59,7 +62,12 @@ void FeedbackConfigDialog::setFeedbackProvider(UserFeedback::Provider* provider)
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()) {
m_provider->setSurveyInterval(-1);
} else {
......
......@@ -64,6 +64,7 @@ public:
QUrl serverUrl;
QDateTime lastSubmitTime;
int submissionInterval;
Provider::StatisticsCollectionMode statisticsMode;
int surveyInterval;
QDateTime lastSurveyTime;
......@@ -79,6 +80,7 @@ ProviderPrivate::ProviderPrivate(Provider *qq)
: q(qq)
, networkAccessManager(Q_NULLPTR)
, submissionInterval(-1)
, statisticsMode(Provider::NoStatistics)
, surveyInterval(-1)
, startCount(0)
, usageTime(0)
......@@ -107,11 +109,15 @@ void ProviderPrivate::load()
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
lastSubmitTime = settings.value(QStringLiteral("LastSubmission")).toDateTime();
startCount = std::max(settings.value(QStringLiteral("ApplicationStartCount"), 0).toInt() + 1, 1);
usageTime = std::max(settings.value(QStringLiteral("ApplicationTime"), 0).toInt(), 0);
// TODO store as string via QMetaEnum
statisticsMode = static_cast<Provider::StatisticsCollectionMode>(settings.value(QStringLiteral("StatisticsCollectionMode"), Provider::NoStatistics).toInt());
surveyInterval = settings.value(QStringLiteral("SurveyInterval"), -1).toInt();
lastSurveyTime = settings.value(QStringLiteral("LastSurvey")).toDateTime();
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()
......@@ -119,11 +125,14 @@ void ProviderPrivate::store()
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
settings.setValue(QStringLiteral("LastSubmission"), lastSubmitTime);
settings.setValue(QStringLiteral("ApplicationStartCount"), startCount);
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
settings.setValue(QStringLiteral("StatisticsCollectionMode"), statisticsMode);
settings.setValue(QStringLiteral("SurveyInterval"), surveyInterval);
settings.setValue(QStringLiteral("LastSurvey"), lastSurveyTime);
settings.setValue(QStringLiteral("CompletedSurveys"), completedSurveys);
settings.setValue(QStringLiteral("ApplicationStartCount"), startCount);
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
}
void ProviderPrivate::aboutToQuit()
......@@ -136,9 +145,12 @@ QByteArray ProviderPrivate::jsonData() const
{
QJsonObject obj;
obj.insert(QStringLiteral("productId"), productId);
if (statisticsMode != Provider::NoStatistics) {
obj.insert(QStringLiteral("startCount"), startCount);
obj.insert(QStringLiteral("usageTime"), currentApplicationTime());
obj.insert(QStringLiteral("version"), QCoreApplication::applicationVersion());
}
QJsonDocument doc(obj);
return doc.toJson();
......@@ -223,6 +235,16 @@ void Provider::setSubmissionInterval(int days)
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
{
return d->surveyInterval;
......
......@@ -34,6 +34,13 @@ class USERFEEDBACKCORE_EXPORT Provider : public QObject
{
Q_OBJECT
public:
enum StatisticsCollectionMode {
NoStatistics,
BasicStatistics,
AllStatistics
};
Q_ENUMS(StatisticsCollectionMode);
explicit Provider(QObject *parent = Q_NULLPTR);
~Provider();
......@@ -48,6 +55,12 @@ public:
/** Set the automatic submission interval. */
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. */
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