Commit 64cdd9d5 authored by Volker Krause's avatar Volker Krause
Browse files

Add automatic submission.

parent 81abfe95
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
#include <QTime> #include <QTime>
#include <QTimer>
#include <QUrl> #include <QUrl>
#include <algorithm> #include <algorithm>
...@@ -60,6 +61,7 @@ public: ...@@ -60,6 +61,7 @@ public:
QNetworkAccessManager *networkAccessManager; QNetworkAccessManager *networkAccessManager;
QUrl serverUrl; QUrl serverUrl;
QDateTime lastSubmitTime; QDateTime lastSubmitTime;
int submissionInterval;
QStringList completedSurveys; QStringList completedSurveys;
...@@ -72,6 +74,7 @@ public: ...@@ -72,6 +74,7 @@ public:
ProviderPrivate::ProviderPrivate(Provider *qq) ProviderPrivate::ProviderPrivate(Provider *qq)
: q(qq) : q(qq)
, networkAccessManager(Q_NULLPTR) , networkAccessManager(Q_NULLPTR)
, submissionInterval(-1)
, startCount(0) , startCount(0)
, usageTime(0) , usageTime(0)
{ {
...@@ -153,6 +156,9 @@ void ProviderPrivate::submitFinished() ...@@ -153,6 +156,9 @@ void ProviderPrivate::submitFinished()
return; return;
emit q->surveyAvailable(survey); emit q->surveyAvailable(survey);
} }
if (submissionInterval > 0)
QTimer::singleShot(submissionInterval * 24 * 60 * 60 * 1000, q, SLOT(submit()));
} }
...@@ -182,6 +188,20 @@ void Provider::setFeedbackServer(const QUrl &url) ...@@ -182,6 +188,20 @@ void Provider::setFeedbackServer(const QUrl &url)
d->serverUrl = url; d->serverUrl = url;
} }
void Provider::setSubmissionInterval(int days)
{
d->submissionInterval = days;
if (d->submissionInterval <= 0)
return;
const auto nextSubmission = d->lastSubmitTime.addDays(days);
const auto now = QDateTime::currentDateTime();
if (nextSubmission <= now)
submit();
else
QTimer::singleShot(now.msecsTo(nextSubmission), this, SLOT(submit()));
}
void Provider::setSurveyCompleted(const SurveyInfo &info) void Provider::setSurveyCompleted(const SurveyInfo &info)
{ {
d->completedSurveys.push_back(QString::number(info.id())); d->completedSurveys.push_back(QString::number(info.id()));
......
...@@ -45,6 +45,9 @@ public: ...@@ -45,6 +45,9 @@ public:
/** Set the feedback server URL. */ /** Set the feedback server URL. */
void setFeedbackServer(const QUrl &url); void setFeedbackServer(const QUrl &url);
/** Set the automatic submission interval. */
void setSubmissionInterval(int days);
/** Marks the given survey as completed. This avoids getting further notification /** Marks the given survey as completed. This avoids getting further notification
* about the same survey. * about the same survey.
*/ */
......
...@@ -85,6 +85,7 @@ int main(int argc, char** argv) ...@@ -85,6 +85,7 @@ int main(int argc, char** argv)
provider.reset(new UserFeedback::Provider); provider.reset(new UserFeedback::Provider);
provider->setFeedbackServer(QUrl(QStringLiteral("https://feedback.volkerkrause.eu"))); provider->setFeedbackServer(QUrl(QStringLiteral("https://feedback.volkerkrause.eu")));
provider->setSubmissionInterval(1);
Orwell mainWindow; Orwell mainWindow;
mainWindow.show(); mainWindow.show();
......
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