summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-11 20:50:38 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-11 20:51:59 (GMT)
commit104516e0ed797e39f1b5b91bdaf45edfde83e9c6 (patch)
treecb7e624099b479594d8464e1b894328cb135f338
parent79bbebc4a1796798e58b7be0ee5d348e53673742 (diff)
Fix enable/disable button. Emit signal when necessary
-rw-r--r--kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp2
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressdialogtest.cpp2
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.cpp14
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.h1
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.cpp15
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.h6
6 files changed, 33 insertions, 7 deletions
diff --git a/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp b/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp
index 02b0eab..8358491 100644
--- a/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp
+++ b/kmail/editorsendcheckplugins/automaticaddcontacts/automaticaddcontactstabwidget.cpp
@@ -55,7 +55,7 @@ AutomaticAddContactsTabWidget::AutomaticAddContactsTabWidget(QWidget *parent, QA
lab->setObjectName(QStringLiteral("labelfolder"));
hlay->addWidget(lab);
- mCollectionCombobox = new Akonadi::CollectionComboBox(model);
+ mCollectionCombobox = new Akonadi::CollectionComboBox(model, this);
mCollectionCombobox->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
mCollectionCombobox->setMinimumWidth(250);
mCollectionCombobox->setMimeTypeFilter(QStringList() << KContacts::Addressee::mimeType());
diff --git a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressdialogtest.cpp b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressdialogtest.cpp
index 2ac45b6..59081e4 100644
--- a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressdialogtest.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressdialogtest.cpp
@@ -50,7 +50,7 @@ void ConfirmAddressDialogTest::shouldHaveDefaultValue()
QPushButton *whiteListEmailsButton = dlg.findChild<QPushButton *>(QStringLiteral("whiteListEmailsButton"));
QVERIFY(whiteListEmailsButton);
-
+ QVERIFY(!whiteListEmailsButton->isEnabled());
}
QTEST_MAIN(ConfirmAddressDialogTest)
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.cpp b/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.cpp
index 70963d0..6c273c2 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.cpp
@@ -43,10 +43,12 @@ ConfirmAddressDialog::ConfirmAddressDialog(QWidget *parent)
connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfirmAddressDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfirmAddressDialog::reject);
- QPushButton *whiteListEmailsButton = new QPushButton(i18n("Add Selected Emails to WhiteList"));
- whiteListEmailsButton->setObjectName(QStringLiteral("whiteListEmailsButton"));
- buttonBox->addButton(whiteListEmailsButton, QDialogButtonBox::ActionRole);
- connect(whiteListEmailsButton, &QPushButton::clicked, this, &ConfirmAddressDialog::slotWhiteListSelectedEmails);
+ mWhiteListEmailsButton = new QPushButton(i18n("Add Selected Emails to WhiteList"));
+ mWhiteListEmailsButton->setObjectName(QStringLiteral("whiteListEmailsButton"));
+ mWhiteListEmailsButton->setEnabled(false);
+ buttonBox->addButton(mWhiteListEmailsButton, QDialogButtonBox::ActionRole);
+ connect(mWhiteListEmailsButton, &QPushButton::clicked, this, &ConfirmAddressDialog::slotWhiteListSelectedEmails);
+ connect(mConfirmWidget, &ConfirmAddressWidget::updateButtonStatus, mWhiteListEmailsButton, &QPushButton::setEnabled);
mainLayout->addWidget(buttonBox);
readConfig();
@@ -90,5 +92,7 @@ void ConfirmAddressDialog::setCurrentIdentity(uint identity)
void ConfirmAddressDialog::slotWhiteListSelectedEmails()
{
const QStringList whiteListEmails = mConfirmWidget->whiteListSelectedEmails();
- Q_EMIT addWhileListEmails(whiteListEmails, mCurrentIdentity);
+ if (!whiteListEmails.isEmpty()) {
+ Q_EMIT addWhileListEmails(whiteListEmails, mCurrentIdentity);
+ }
}
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.h b/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.h
index be36ce5..dfec2d1 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.h
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressdialog.h
@@ -42,6 +42,7 @@ private:
void readConfig();
uint mCurrentIdentity;
ConfirmAddressWidget *mConfirmWidget;
+ QPushButton *mWhiteListEmailsButton;
};
#endif // CONFIRMADDRESSDIALOG_H
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.cpp b/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.cpp
index eb59859..ac25b7a 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.cpp
@@ -37,6 +37,7 @@ ConfirmAddressWidget::ConfirmAddressWidget(QWidget *parent)
mListEmails = new QListWidget(this);
mListEmails->setObjectName(QStringLiteral("listemails"));
+ connect(mListEmails, &QListWidget::itemChanged, this, &ConfirmAddressWidget::slotItemChanged);
mainLayout->addWidget(mListEmails);
}
@@ -83,3 +84,17 @@ QStringList ConfirmAddressWidget::whiteListSelectedEmails() const
}
return lst;
}
+
+void ConfirmAddressWidget::slotItemChanged(QListWidgetItem *)
+{
+ bool hasElementChecked = false;
+ const int nbItems(mListEmails->count());
+ for (int i = 0; i < nbItems; ++i) {
+ QListWidgetItem *item = mListEmails->item(i);
+ if (item->checkState() == Qt::Checked) {
+ hasElementChecked = true;
+ break;
+ }
+ }
+ Q_EMIT updateButtonStatus(hasElementChecked);
+}
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.h b/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.h
index dc6d59f..0b3d589 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.h
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddresswidget.h
@@ -22,6 +22,7 @@
#include <QWidget>
class QListWidget;
+class QListWidgetItem;
class ConfirmAddressWidget : public QWidget
{
Q_OBJECT
@@ -32,8 +33,13 @@ public:
void setValidAddresses(const QStringList &addresses);
void setInvalidAddresses(const QStringList &addresses);
QStringList whiteListSelectedEmails() const;
+
+Q_SIGNALS:
+ void updateButtonStatus(bool hasElementChecked);
+
private:
void createAddressItems(const QStringList &address, bool valid);
+ void slotItemChanged(QListWidgetItem *item);
QListWidget *mListEmails;
};