Commit 48e569b9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Disable ok button when we can't create a valid rule

parent 773e0897
......@@ -20,6 +20,7 @@
#include "dkimmanagerulescombobox.h"
#include "dkimmanageruleswidget.h"
#include "dkimruledialog.h"
#include "messageviewer_dkimcheckerdebug.h"
#include <MessageViewer/DKIMManagerRules>
#include <QVBoxLayout>
#include <QHeaderView>
......@@ -137,6 +138,8 @@ void DKIMManageRulesWidget::addRule()
if (rule.isValid()) {
DKIMManageRulesWidgetItem *item = new DKIMManageRulesWidgetItem(mTreeWidget);
item->setRule(rule);
} else {
qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Rule is not valid";
}
}
delete dlg;
......
......@@ -47,6 +47,13 @@ DKIMRuleDialog::DKIMRuleDialog(QWidget *parent)
buttonBox->setObjectName(QStringLiteral("buttonBox"));
mainLayout->addWidget(buttonBox);
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setEnabled(false);
connect(mRuleWidget, &DKIMRuleWidget::updateOkButtonRequested, this, [this](bool enabled) {
mOkButton->setEnabled(enabled);
});
connect(buttonBox, &QDialogButtonBox::accepted, this, &DKIMRuleDialog::slotAccepted);
connect(buttonBox, &QDialogButtonBox::rejected, this, &DKIMRuleDialog::reject);
readConfig();
......
......@@ -23,6 +23,7 @@
#include "messageviewer_private_export.h"
#include <QDialog>
#include <MessageViewer/DKIMRule>
class QPushButton;
namespace MessageViewer {
class DKIMRuleWidget;
class MESSAGEVIEWER_TESTS_EXPORT DKIMRuleDialog : public QDialog
......@@ -39,6 +40,7 @@ private:
void writeConfig();
void readConfig();
DKIMRuleWidget *mRuleWidget = nullptr;
QPushButton *mOkButton = nullptr;
};
}
......
......@@ -42,6 +42,7 @@ DKIMRuleWidget::DKIMRuleWidget(QWidget *parent)
mDomain->setObjectName(QStringLiteral("domain"));
mDomain->setClearButtonEnabled(true);
layout->addRow(i18n("Domain:"), mDomain);
connect(mDomain, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
mListId = new QLineEdit(this);
mListId->setObjectName(QStringLiteral("listid"));
......@@ -53,6 +54,7 @@ DKIMRuleWidget::DKIMRuleWidget(QWidget *parent)
mFrom->setClearButtonEnabled(true);
layout->addRow(i18n("From:"), mFrom);
mFrom->setPlaceholderText(i18n("Use '*' to specify all emails from domain"));
connect(mFrom, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
mSignatureDomainIdentifier = new QLineEdit(this);
mSignatureDomainIdentifier->setObjectName(QStringLiteral("signaturedomainidentifier"));
......@@ -76,6 +78,11 @@ DKIMRuleWidget::~DKIMRuleWidget()
{
}
void DKIMRuleWidget::updateOkButton()
{
Q_EMIT updateOkButtonRequested(!mFrom->text().trimmed().isEmpty() && !mDomain->text().trimmed().isEmpty());
}
void DKIMRuleWidget::loadRule(const MessageViewer::DKIMRule &rule)
{
mEnabled->setChecked(rule.enabled());
......
......@@ -34,7 +34,12 @@ public:
~DKIMRuleWidget();
void loadRule(const MessageViewer::DKIMRule &rule);
Q_REQUIRED_RESULT MessageViewer::DKIMRule rule() const;
Q_SIGNALS:
void updateOkButtonRequested(bool enabled);
private:
void updateOkButton();
QCheckBox *mEnabled = nullptr;
QLineEdit *mDomain = nullptr;
QLineEdit *mSignatureDomainIdentifier = nullptr;
......
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