summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-12 21:32:15 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-12 21:32:37 (GMT)
commitdbf0c0cfc46e373b66f6f52705d436b668a52b0f (patch)
treead609a87bff38cf6aabc64103634d6d81e7c4ba2
parent8e4e4f4dbe96bebd545202482d7cd491ccecf8cf (diff)
Fix button text. Allow to unable/disable button
-rw-r--r--src/ksieveui/sievescriptdebugger/autotests/sievescriptdebuggerdialogtest.cpp5
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.cpp24
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.h4
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.cpp7
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.h3
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.cpp4
-rw-r--r--src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.h4
7 files changed, 39 insertions, 12 deletions
diff --git a/src/ksieveui/sievescriptdebugger/autotests/sievescriptdebuggerdialogtest.cpp b/src/ksieveui/sievescriptdebugger/autotests/sievescriptdebuggerdialogtest.cpp
index 9089d5a..d82f80b 100644
--- a/src/ksieveui/sievescriptdebugger/autotests/sievescriptdebuggerdialogtest.cpp
+++ b/src/ksieveui/sievescriptdebugger/autotests/sievescriptdebuggerdialogtest.cpp
@@ -21,6 +21,7 @@
#include "../sievescriptdebuggerdialog.h"
#include "../sievescriptdebuggerwidget.h"
#include <QDialogButtonBox>
+#include <QPushButton>
#include <QTest>
SieveScriptDebuggerDialogTest::SieveScriptDebuggerDialogTest(QObject *parent)
@@ -44,6 +45,10 @@ void SieveScriptDebuggerDialogTest::shouldHaveDefaultValue()
QVERIFY(widget);
QVERIFY(dlg.script().isEmpty());
+
+ QPushButton *mOkButton = dlg.findChild<QPushButton *>(QStringLiteral("okbutton"));
+ QVERIFY(mOkButton);
+ QVERIFY(!mOkButton->isEnabled());
}
QTEST_MAIN(SieveScriptDebuggerDialogTest)
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.cpp b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.cpp
index cb60980..de91a3d 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.cpp
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.cpp
@@ -33,31 +33,39 @@ using namespace KSieveUi;
SieveScriptDebuggerDialog::SieveScriptDebuggerDialog(QWidget *parent)
: QDialog(parent)
{
- QVBoxLayout *mainLayout = new QVBoxLayout;
- setLayout(mainLayout);
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
setWindowTitle(i18n("Debug Sieve Script"));
mSieveScriptDebuggerWidget = new SieveScriptDebuggerWidget(this);
mSieveScriptDebuggerWidget->setObjectName(QStringLiteral("sievescriptdebuggerwidget"));
mainLayout->addWidget(mSieveScriptDebuggerWidget);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mainLayout->addWidget(buttonBox);
buttonBox->setObjectName(QStringLiteral("buttonbox"));
- QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
- okButton->setDefault(true);
- okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
+ mOkButton = buttonBox->button(QDialogButtonBox::Ok);
+ mOkButton->setObjectName(QStringLiteral("okbutton"));
+ mOkButton->setText(i18n("Apply Changes"));
+ mOkButton->setDefault(true);
+ mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
+ mOkButton->setEnabled(false);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SieveScriptDebuggerDialog::slotAccepted);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptDebuggerDialog::reject);
-
+ connect(mSieveScriptDebuggerWidget, &SieveScriptDebuggerWidget::scriptTextChanged, this, &SieveScriptDebuggerDialog::slotScriptTextChanged);
readConfig();
}
SieveScriptDebuggerDialog::~SieveScriptDebuggerDialog()
{
+ disconnect(mSieveScriptDebuggerWidget, &SieveScriptDebuggerWidget::scriptTextChanged, this, &SieveScriptDebuggerDialog::slotScriptTextChanged);
writeConfig();
}
+void SieveScriptDebuggerDialog::slotScriptTextChanged()
+{
+ mOkButton->setEnabled(mOriginScript != mSieveScriptDebuggerWidget->script());
+}
+
void SieveScriptDebuggerDialog::slotAccepted()
{
if (mSieveScriptDebuggerWidget->canAccept()) {
@@ -67,7 +75,9 @@ void SieveScriptDebuggerDialog::slotAccepted()
void SieveScriptDebuggerDialog::setScript(const QString &script)
{
+ mOriginScript = script;
mSieveScriptDebuggerWidget->setScript(script);
+ mOkButton->setEnabled(false);
}
QString SieveScriptDebuggerDialog::script() const
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.h b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.h
index 3d99365..20e3db6 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.h
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerdialog.h
@@ -23,6 +23,7 @@
#include <QDialog>
#include "ksieveui_export.h"
+class QPushButton;
namespace KSieveUi
{
class SieveScriptDebuggerWidget;
@@ -37,10 +38,13 @@ public:
QString script() const;
private:
+ void slotScriptTextChanged();
void slotAccepted();
void writeConfig();
void readConfig();
+ QString mOriginScript;
SieveScriptDebuggerWidget *mSieveScriptDebuggerWidget;
+ QPushButton *mOkButton;
};
}
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.cpp b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.cpp
index 247719a..29cd554 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.cpp
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.cpp
@@ -45,9 +45,8 @@ SieveScriptDebuggerFrontEndWidget::SieveScriptDebuggerFrontEndWidget(QWidget *pa
: QWidget(parent),
mProcess(Q_NULLPTR)
{
- QVBoxLayout *mainLayout = new QVBoxLayout;
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
- setLayout(mainLayout);
QFormLayout *formLayout = new QFormLayout;
mainLayout->addLayout(formLayout);
@@ -90,7 +89,9 @@ SieveScriptDebuggerFrontEndWidget::SieveScriptDebuggerFrontEndWidget(QWidget *pa
textToSpeechWidget->setObjectName(QStringLiteral("texttospeechwidget"));
vboxSieveEditorLayout->addWidget(textToSpeechWidget);
- mSieveTextEditWidget = new KSieveUi::SieveTextEditWidget(new KSieveUi::SieveScriptDebuggerTextEdit(this), this);
+ KSieveUi::SieveScriptDebuggerTextEdit *textEdit = new KSieveUi::SieveScriptDebuggerTextEdit(this);
+ connect(textEdit, &KSieveUi::SieveScriptDebuggerTextEdit::textChanged, this, &SieveScriptDebuggerFrontEndWidget::scriptTextChanged);
+ mSieveTextEditWidget = new KSieveUi::SieveTextEditWidget(textEdit, this);
mSieveTextEditWidget->setObjectName(QStringLiteral("sievetexteditwidget"));
vboxSieveEditorLayout->addWidget(mSieveTextEditWidget);
connect(mSieveTextEditWidget->textEdit(), &SieveTextEdit::say, textToSpeechWidget, &KPIMTextEdit::TextToSpeechWidget::say);
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.h b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.h
index 33c922e..c871893 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.h
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerfrontendwidget.h
@@ -50,6 +50,9 @@ public:
QList<int> splitterSizes() const;
void setSplitterSizes(const QList<int> &sizes);
+Q_SIGNALS:
+ void scriptTextChanged();
+
private Q_SLOTS:
void slotDebugScript();
void slotEmailChanged(const QString &text);
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.cpp b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.cpp
index bdb0b02..af8bf84 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.cpp
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.cpp
@@ -31,8 +31,7 @@ using namespace KSieveUi;
SieveScriptDebuggerWidget::SieveScriptDebuggerWidget(QWidget *parent)
: QWidget(parent)
{
- QHBoxLayout *mainLayout = new QHBoxLayout;
- setLayout(mainLayout);
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setMargin(0);
mStackedWidget = new QStackedWidget(this);
mStackedWidget->setObjectName(QStringLiteral("stackedwidget"));
@@ -41,6 +40,7 @@ SieveScriptDebuggerWidget::SieveScriptDebuggerWidget(QWidget *parent)
mSieveScriptFrontEnd = new SieveScriptDebuggerFrontEndWidget;
mSieveScriptFrontEnd->setObjectName(QStringLiteral("sievescriptfrontend"));
mStackedWidget->addWidget(mSieveScriptFrontEnd);
+ connect(mSieveScriptFrontEnd, &SieveScriptDebuggerFrontEndWidget::scriptTextChanged, this, &SieveScriptDebuggerWidget::scriptTextChanged);
mSieveNoExistingFrontEnd = new QLabel(i18n("\"sieve-test\" was not found on system. Please install it. (See in Dovecot package)"));
mSieveNoExistingFrontEnd->setAlignment(Qt::AlignHCenter);
diff --git a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.h b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.h
index 274d002..33a4feb 100644
--- a/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.h
+++ b/src/ksieveui/sievescriptdebugger/sievescriptdebuggerwidget.h
@@ -41,6 +41,10 @@ public:
QList<int> splitterSizes() const;
void setSplitterSizes(const QList<int> &sizes);
+
+Q_SIGNALS:
+ void scriptTextChanged();
+
private:
void checkSieveTestApplication();
QStackedWidget *mStackedWidget;