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

Implement system/user-wide way to disable the entire feedback system

Fixes T6602
parent a0f3a37e
......@@ -50,6 +50,7 @@ private slots:
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.remove(QLatin1String("LastEncouragement"));
s.remove(QLatin1String("Enabled"));
}
void testProductId()
......@@ -329,6 +330,38 @@ private slots:
}
}
void testGlobalKillSwitch()
{
{
Provider p1;
QVERIFY(p1.isEnabled());
p1.setEnabled(false);
QVERIFY(!p1.isEnabled());
}
Provider p2;
QVERIFY(!p2.isEnabled());
// check encouragements are disabled
{
QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));;
s.beginGroup(QLatin1String("UserFeedback"));
s.remove(QLatin1String("LastEncouragement"));
}
{
Provider p;
p.setSurveyInterval(-1);
p.setTelemetryMode(Provider::NoTelemetry);
QSignalSpy spy(&p, SIGNAL(showEncouragementMessage()));
QVERIFY(spy.isValid());
p.setEncouragementDelay(0);
p.setApplicationStartsUntilEncouragement(0);
p.setEncouragementInterval(1);
QVERIFY(!spy.wait(100));
}
}
};
QTEST_MAIN(ProviderTest)
......
......@@ -70,7 +70,14 @@ private slots:
QSignalSpy spy(&p, SIGNAL(surveyAvailable(KUserFeedback::SurveyInfo)));
QVERIFY(spy.isValid());
// global kill switch prevents survey
bool rv = false;
p.setEnabled(false);
QMetaObject::invokeMethod(&p, "selectSurvey", Q_RETURN_ARG(bool, rv), Q_ARG(KUserFeedback::SurveyInfo, s1));
QVERIFY(!rv);
QVERIFY(spy.isEmpty());
p.setEnabled(true);
QMetaObject::invokeMethod(&p, "selectSurvey", Q_RETURN_ARG(bool, rv), Q_ARG(KUserFeedback::SurveyInfo, s1));
QVERIFY(rv);
QCOMPARE(spy.size(), 1);
......
......@@ -130,6 +130,7 @@ MainWindow::MainWindow() :
connect(ui->actionUserManual, &QAction::triggered, this, []() {
HelpController::openContents();
});
ui->actionContribute->setVisible(m_feedbackProvider->isEnabled());
connect(ui->actionContribute, &QAction::triggered, this, [this]() {
FeedbackConfigDialog dlg(this);
dlg.setFeedbackProvider(m_feedbackProvider);
......
......@@ -302,6 +302,8 @@ QByteArray ProviderPrivate::jsonData(Provider::TelemetryMode mode) const
void ProviderPrivate::scheduleNextSubmission()
{
submissionTimer.stop();
if (!q->isEnabled())
return;
if (submissionInterval <= 0 || (telemetryMode == Provider::NoTelemetry && surveyInterval < 0))
return;
......@@ -375,7 +377,7 @@ QVariant ProviderPrivate::sourceData(const QString& sourceName) const
bool ProviderPrivate::selectSurvey(const SurveyInfo &survey) const
{
qCDebug(Log) << "got survey:" << survey.url() << survey.target();
if (!survey.isValid() || completedSurveys.contains(survey.uuid().toString()))
if (!q->isEnabled() || !survey.isValid() || completedSurveys.contains(survey.uuid().toString()))
return false;
if (lastSurveyTime.addDays(surveyInterval) > QDateTime::currentDateTime())
......@@ -410,6 +412,8 @@ Provider::TelemetryMode ProviderPrivate::highestTelemetryMode() const
void ProviderPrivate::scheduleEncouragement()
{
encouragementTimer.stop();
if (!q->isEnabled())
return;
// already done, not repetition
if (lastEncouragementTime.isValid() && encouragementInterval <= 0)
......@@ -470,6 +474,21 @@ Provider::~Provider()
delete d;
}
bool Provider::isEnabled() const
{
auto s = d->makeGlobalSettings();
s->beginGroup(QStringLiteral("UserFeedback"));
return s->value(QStringLiteral("Enabled"), true).toBool();
}
void Provider::setEnabled(bool enabled)
{
if (enabled == isEnabled())
return;
d->storeOneGlobal(QStringLiteral("Enabled"), enabled);
emit enabledChanged();
}
QString Provider::productIdentifier() const
{
return d->productId;
......@@ -645,6 +664,10 @@ void Provider::surveyCompleted(const SurveyInfo &info)
void Provider::submit()
{
if (!isEnabled()) {
qCWarning(Log) << "Global kill switch is enabled";
return;
}
if (d->productId.isEmpty()) {
qCWarning(Log) << "No productId specified!";
return;
......
......@@ -42,6 +42,11 @@ class SurveyInfo;
class KUSERFEEDBACKCORE_EXPORT Provider : public QObject
{
Q_OBJECT
/*! The global enabled state of the feedback functionality.
* If this is @c false, all feedback functionality has to be disabled completely.
*/
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
/*! The interval in which the user accepts surveys.
* This should be configurable for the user.
* @c -1 indicates surveys are disabled.
......@@ -124,6 +129,17 @@ public:
explicit Provider(QObject *parent = nullptr);
~Provider();
/*! Returns whether feedback functionality is enabled on this system.
* This should be checked everywhere showing feedback UI to the user
* to respect the global "kill switch" for this. Provider does check
* this internally for encouragements, surveys and telemetry submission.
*/
bool isEnabled() const;
/*! Set the global (user-wide) activation state for feedback functionality.
* @see isEnabled
*/
void setEnabled(bool enabled);
/*! Returns the current product identifier. */
QString productIdentifier() const;
/*! Set the product identifier.
......@@ -247,6 +263,9 @@ Q_SIGNALS:
/*! Emitted when any provider setting changed. */
void providerSettingsChanged();
/*! Emitted when the global enabled state changed. */
void enabledChanged();
private:
friend class ProviderPrivate;
ProviderPrivate * const d;
......
......@@ -62,6 +62,7 @@ Orwell::Orwell(QWidget* parent) :
provider->setSurveyInterval(value);
});
ui->actionContribute->setVisible(provider->isEnabled());
connect(ui->actionContribute, &QAction::triggered, this, [this]() {
KUserFeedback::FeedbackConfigDialog dlg(this);
dlg.setFeedbackProvider(provider.get());
......
......@@ -62,6 +62,7 @@ ApplicationWindow {
y: menuButton.height
MenuItem {
text: "Contribute..."
visible: provider.enabled
onTriggered: {
stackView.push(contributePage);
stackView.currentItem.provider = provider;
......
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