Commit 104516e0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix enable/disable button. Emit signal when necessary

parent 79bbebc4
......@@ -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());
......
......@@ -50,7 +50,7 @@ void ConfirmAddressDialogTest::shouldHaveDefaultValue()
QPushButton *whiteListEmailsButton = dlg.findChild<QPushButton *>(QStringLiteral("whiteListEmailsButton"));
QVERIFY(whiteListEmailsButton);
QVERIFY(!whiteListEmailsButton->isEnabled());
}
QTEST_MAIN(ConfirmAddressDialogTest)
......@@ -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);
}
}
......@@ -42,6 +42,7 @@ private:
void readConfig();
uint mCurrentIdentity;
ConfirmAddressWidget *mConfirmWidget;
QPushButton *mWhiteListEmailsButton;
};
#endif // CONFIRMADDRESSDIALOG_H
......@@ -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);
}
......@@ -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;
};
......
Supports Markdown
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