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

Add automatic submission.

parent 81abfe95
......@@ -29,6 +29,7 @@
#include <QSettings>
#include <QStringList>
#include <QTime>
#include <QTimer>
#include <QUrl>
#include <algorithm>
......@@ -60,6 +61,7 @@ public:
QNetworkAccessManager *networkAccessManager;
QUrl serverUrl;
QDateTime lastSubmitTime;
int submissionInterval;
QStringList completedSurveys;
......@@ -72,6 +74,7 @@ public:
ProviderPrivate::ProviderPrivate(Provider *qq)
: q(qq)
, networkAccessManager(Q_NULLPTR)
, submissionInterval(-1)
, startCount(0)
, usageTime(0)
{
......@@ -153,6 +156,9 @@ void ProviderPrivate::submitFinished()
return;
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)
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)
{
d->completedSurveys.push_back(QString::number(info.id()));
......
......@@ -45,6 +45,9 @@ public:
/** Set the feedback server 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
* about the same survey.
*/
......
......@@ -85,6 +85,7 @@ int main(int argc, char** argv)
provider.reset(new UserFeedback::Provider);
provider->setFeedbackServer(QUrl(QStringLiteral("https://feedback.volkerkrause.eu")));
provider->setSubmissionInterval(1);
Orwell mainWindow;
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