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

Refactor survey interval configuration for QML reuse too

parent 93362beb
......@@ -91,6 +91,11 @@ int FeedbackConfigUiController::telemetryModeCount() const
return d->telemetryModeMap.size();
}
int FeedbackConfigUiController::surveyModeCount() const
{
return 3;
}
Provider::StatisticsCollectionMode FeedbackConfigUiController::telemetryIndexToMode(int index) const
{
if (index < 0 || index >= telemetryModeCount())
......@@ -153,3 +158,44 @@ QString FeedbackConfigUiController::telemetryModeDetails(int telemetryIndex) con
}
return detailsStr + QStringLiteral("</ul>");
}
int FeedbackConfigUiController::surveyIndexToInterval(int index) const
{
switch (index) {
case 0: return -1;
case 1: return 90;
case 2: return 0;
}
return -1;
}
int FeedbackConfigUiController::surveyIntervalToIndex(int interval) const
{
if (interval < 0)
return 0;
else if (interval >= 90)
return 1;
else
return 2;
}
QString FeedbackConfigUiController::surveyModeDescription(int surveyIndex) const
{
switch (surveyIndex) {
case 0:
return tr(
"We make this application for you. In order to ensure it actually does what you need it to do we "
"would like to ask you about your use cases and your feedback, in the form of a web survey."
);
case 1:
return tr(
"I will occasionally participate in web surveys about the application, not more than four times a year though."
);
case 2:
return tr(
"I will participate in web surveys whenever one is available. Surveys can of course be defered or skipped."
);
}
return QString();
}
......@@ -41,6 +41,8 @@ class USERFEEDBACKCORE_EXPORT FeedbackConfigUiController : public QObject
Q_PROPERTY(UserFeedback::Provider* feedbackProvider READ feedbackProvider WRITE setFeedbackProvider NOTIFY providerChanged)
/*! Amount of telemetry modes supported by the provider. */
Q_PROPERTY(int telemetryModeCount READ telemetryModeCount NOTIFY providerChanged)
/*! Amount of supported survey modes. */
Q_PROPERTY(int surveyModeCount READ surveyModeCount CONSTANT)
public:
FeedbackConfigUiController(QObject *parent = nullptr);
~FeedbackConfigUiController();
......@@ -54,6 +56,8 @@ public:
* This depends on what type of sources the provider actually has.
*/
int telemetryModeCount() const;
/*! Amount of supported survey modes. */
int surveyModeCount() const;
/*! Convert slider index to telemetry mode. */
Q_INVOKABLE UserFeedback::Provider::StatisticsCollectionMode telemetryIndexToMode(int index) const;
......@@ -65,6 +69,14 @@ public:
/*! Detailed information about the data sources of the given telemetry mode index. */
Q_INVOKABLE QString telemetryModeDetails(int telemetryIndex) const;
/*! Convert slider index to survey interval. */
Q_INVOKABLE int surveyIndexToInterval(int index) const;
/*! Convert survey interval to slider index. */
Q_INVOKABLE int surveyIntervalToIndex(int interval) const;
/*! Survey mode explanation text. */
Q_INVOKABLE QString surveyModeDescription(int surveyIndex) const;
Q_SIGNALS:
/*! A provider-related setting has changed. */
void providerChanged();
......
......@@ -72,25 +72,7 @@ void FeedbackConfigWidgetPrivate::surveySliderChanged()
if (!controller->feedbackProvider())
return;
switch (ui->surveySlider->value()) {
case 0:
ui->surveyLabel->setText(FeedbackConfigWidget::tr(
"We make this application for you. In order to ensure it actually does what you need it to do we "
"would like to ask you about your use cases and your feedback, in the form of a web survey."
));
break;
case 1:
ui->surveyLabel->setText(FeedbackConfigWidget::tr(
"I will occasionally participate in web surveys about the application, not more than four times a year though."
));
break;
case 2:
ui->surveyLabel->setText(FeedbackConfigWidget::tr(
"I will participate in web surveys whenever one is available. Surveys can of course be defered or skipped."
));
break;
}
ui->surveyLabel->setText(controller->surveyModeDescription(ui->surveySlider->value()));
applyPalette(ui->surveySlider);
}
......@@ -158,13 +140,7 @@ void FeedbackConfigWidget::setFeedbackProvider(Provider* provider)
d->ui->telemetrySlider->setMaximum(d->controller->telemetryModeCount() - 1);
d->ui->telemetrySlider->setValue(d->controller->telemetryModeToIndex(provider->statisticsCollectionMode()));
if (provider->surveyInterval() < 0)
d->ui->surveySlider->setValue(0);
else if (provider->surveyInterval() >= 90)
d->ui->surveySlider->setValue(1);
else
d->ui->surveySlider->setValue(2);
d->ui->surveySlider->setValue(d->controller->surveyIntervalToIndex(provider->surveyInterval()));
d->surveySliderChanged(); // update the description even if nothing changed initially
setEnabled(provider);
......@@ -193,12 +169,7 @@ Provider::StatisticsCollectionMode FeedbackConfigWidget::statisticsCollectionMod
int FeedbackConfigWidget::surveyInterval() const
{
switch (d->ui->surveySlider->value()) {
case 0: return -1;
case 1: return 90;
case 2: return 0;
}
return -1;
return d->controller->surveyIndexToInterval(d->ui->surveySlider->value());
}
#include "moc_feedbackconfigwidget.cpp"
......@@ -44,9 +44,6 @@ ApplicationWindow {
applicationStartsUntilEncouragement: 5
encouragementDelay: 10
encouragementInterval: 1
// TODO make configurable
statisticsCollectionMode: UserFeedback.Provider.DetailedUsageStatistics
surveyInterval: 0
onSurveyAvailable: {
console.log(survey);
......@@ -55,7 +52,8 @@ ApplicationWindow {
}
onShowEncouragementMessage: {
console.log("showing encouragement");
encouragementPopup.open();
if (stackView.depth == 1)
encouragementPopup.open();
}
UserFeedback.ApplicationVersionSource { mode: UserFeedback.Provider.BasicSystemInformation }
......@@ -204,14 +202,15 @@ ApplicationWindow {
Slider {
id: surveySlider
value: controller.surveyIntervalToIndex(provider.surveyInterval)
stepSize: 1
to: 2
to: controller.surveyModeCount - 1
Layout.fillWidth: true
snapMode: Slider.SnapAlways
}
Label {
id: surveyLabel
text: "TODO"
text: controller.surveyModeDescription(surveySlider.value)
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
......@@ -219,10 +218,11 @@ ApplicationWindow {
Button {
Layout.alignment: Qt.AlignHCenter
text: telemetrySlider.value + surveySlider.value === 0 ?
qsTr("I don't contriute.") :
qsTr("I don't contribute.") :
qsTr("Contribute!");
onClicked: {
// TODO
provider.statisticsCollectionMode = controller.telemetryIndexToMode(telemetrySlider.value);
provider.surveyInterval = controller.surveyIndexToInterval(surveySlider.value);
stackView.pop();
}
}
......@@ -288,8 +288,7 @@ ApplicationWindow {
text: qsTr("Contribute...")
onClicked: {
encouragementPopup.close();
if (stackView.depth == 1)
stackView.push(contributePage);
stackView.push(contributePage);
}
}
}
......
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