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

Make the survey API work from QML

parent 751e94af
......@@ -300,6 +300,7 @@ void ProviderPrivate::submitFinished()
const auto it = obj.find(QLatin1String("surveys"));
if (it != obj.end() && surveyInterval >= 0) {
const auto a = it.value().toArray();
qCDebug(Log) << "received" << a.size() << "surveys";
foreach(const auto &s, a) {
const auto survey = SurveyInfo::fromJson(s.toObject());
if (selectSurvey(survey))
......@@ -342,6 +343,7 @@ bool ProviderPrivate::selectSurvey(const SurveyInfo &survey) const
return false;
}
qCDebug(Log) << "picked survey:" << survey.url();
emit q->surveyAvailable(survey);
return true;
}
......@@ -589,7 +591,7 @@ void Provider::setEncouragementInterval(int days)
d->scheduleEncouragement();
}
void Provider::setSurveyCompleted(const SurveyInfo &info)
void Provider::surveyCompleted(const SurveyInfo &info)
{
d->completedSurveys.push_back(info.uuid().toString());
d->lastSurveyTime = QDateTime::currentDateTime();
......
......@@ -183,11 +183,6 @@ public:
*/
void setSurveyInterval(int days);
/*! Marks the given survey as completed. This avoids getting further notification
* about the same survey.
*/
void setSurveyCompleted(const SurveyInfo &info);
/*! Returns the amount of application starts before an encouragement message is shown. */
int applicationStartsUntilEncouragement() const;
/*! Set the amount of application starts until the encouragement message should be shown.
......@@ -232,6 +227,11 @@ public Q_SLOTS:
/*! Manually submit currently recorded data. */
void submit();
/*! Marks the given survey as completed. This avoids getting further notification
* about the same survey.
*/
void surveyCompleted(const UserFeedback::SurveyInfo &info);
Q_SIGNALS:
/*! Emitted whenever there is a new survey available that can be presented
* to the user.
......
......@@ -20,6 +20,7 @@
#include "userfeedbackcore_export.h"
#include <QMetaType>
#include <QSharedDataPointer>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qobjectdefs.h>
......@@ -85,4 +86,6 @@ private:
}
Q_DECLARE_METATYPE(UserFeedback::SurveyInfo)
#endif // USERFEEDBACK_SURVEYINFO_H
......@@ -20,6 +20,7 @@
#include "qmlproviderextension.h"
#include <Provider>
#include <SurveyInfo>
#include <QQmlEngine>
......@@ -40,4 +41,6 @@ void QmlPlugin::registerTypes(const char* uri)
qmlRegisterType<QmlScreenInfoSource>(uri, 1, 0, "ScreenInfoSource");
qmlRegisterType<QmlStartCountSource>(uri, 1, 0, "StartCountSource");
qmlRegisterType<QmlUsageTimeSource>(uri, 1, 0, "UsageTimeSource");
qRegisterMetaType<SurveyInfo>();
}
......@@ -118,7 +118,7 @@ void NotificationPopupPrivate::action()
{
if (survey.isValid()) {
QDesktopServices::openUrl(survey.url());
provider->setSurveyCompleted(survey);
provider->surveyCompleted(survey);
} else {
FeedbackConfigDialog dlg(q);
dlg.setFeedbackProvider(provider);
......
......@@ -16,6 +16,7 @@
*/
import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import org.kde.userfeedback 1.0 as UserFeedback
......@@ -29,7 +30,15 @@ ApplicationWindow {
submissionInterval: 1
productIdentifier: "org.kde.orwell"
feedbackServer: "https://feedback.volkerkrause.eu/"
// TODO make configurable
statisticsCollectionMode: UserFeedback.Provider.DetailedUsageStatistics
surveyInterval: 0
onSurveyAvailable: {
console.log(survey);
surveyPopup.surveyInfo = survey;
surveyPopup.open();
}
UserFeedback.ApplicationVersionSource { mode: UserFeedback.Provider.BasicSystemInformation }
UserFeedback.CompilerInfoSource { mode: UserFeedback.Provider.BasicSystemInformation }
......@@ -49,4 +58,37 @@ ApplicationWindow {
anchors.centerIn: parent
onClicked: provider.submit()
}
Popup {
id: surveyPopup
property var surveyInfo;
x: 0
y: 0
width: parent.width
height: parent.height
ColumnLayout {
anchors.fill: parent
Label {
Layout.fillWidth: true
horizontalAlignment: Qt.AlignHCenter;
text: qsTr("We are looking for your feedback!")
font.bold: true
}
Label {
Layout.fillWidth: true
text: qsTr("We would like a few minutes of your time to provide feedback about this application in a survey.")
wrapMode: Text.WordWrap
}
Button {
Layout.alignment: Qt.AlignHCenter;
text: qsTr("Participate!")
onClicked: {
if (Qt.openUrlExternally(surveyPopup.surveyInfo.url))
provider.surveyCompleted(surveyPopup.surveyInfo);
surveyPopup.close()
}
}
}
}
}
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