File indexing completed on 2024-12-15 03:45:05

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "feedbackconfigdialog.h"
0008 #include "ui_feedbackconfigdialog.h"
0009 
0010 #include <provider.h>
0011 
0012 #include <QDebug>
0013 #include <QPushButton>
0014 
0015 using namespace KUserFeedback;
0016 
0017 namespace KUserFeedback {
0018 class FeedbackConfigDialogPrivate {
0019 public:
0020     void updateButtonState();
0021 
0022     std::unique_ptr<Ui::FeedbackConfigDialog> ui;
0023 };
0024 }
0025 
0026 FeedbackConfigDialog::FeedbackConfigDialog(QWidget *parent) :
0027     QDialog(parent),
0028     d(new FeedbackConfigDialogPrivate)
0029 {
0030     d->ui.reset(new Ui::FeedbackConfigDialog);
0031     d->ui->setupUi(this);
0032     d->ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Contribute!"));
0033     d->ui->buttonBox->button(QDialogButtonBox::Close)->setText(tr("No, I do not want to contribute."));
0034 }
0035 
0036 FeedbackConfigDialog::~FeedbackConfigDialog()
0037 {
0038 }
0039 
0040 void FeedbackConfigDialog::setFeedbackProvider(Provider* provider)
0041 {
0042     d->ui->configWidget->setFeedbackProvider(provider);
0043     connect(d->ui->configWidget, &FeedbackConfigWidget::configurationChanged, this, [this]() { d->updateButtonState(); });
0044     d->updateButtonState();
0045 }
0046 
0047 void FeedbackConfigDialog::accept()
0048 {
0049     auto p = d->ui->configWidget->feedbackProvider();
0050     p->setTelemetryMode(d->ui->configWidget->telemetryMode());
0051     p->setSurveyInterval(d->ui->configWidget->surveyInterval());
0052     QDialog::accept();
0053 }
0054 
0055 void FeedbackConfigDialogPrivate::updateButtonState()
0056 {
0057     const auto any = ui->configWidget->surveyInterval() >= 0
0058         || ui->configWidget->telemetryMode() != Provider::NoTelemetry;
0059 
0060     ui->buttonBox->button(QDialogButtonBox::Ok)->setVisible(any);
0061     ui->buttonBox->button(QDialogButtonBox::Close)->setVisible(!any);
0062 }
0063 
0064 #include "moc_feedbackconfigdialog.cpp"