Commit d575a1db authored by Laurent Montel's avatar Laurent Montel 😁

improve it

parent a1e42160
......@@ -20,6 +20,7 @@
#include "checkduplicateemailsdialogtest.h"
#include "../checkduplicateemailsdialog.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QListWidget>
#include <QTest>
......@@ -43,6 +44,26 @@ void CheckDuplicateEmailsDialogTest::shouldHaveDefaultValue()
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
QLabel *lab = dlg.findChild<QLabel* >(QStringLiteral("label"));
QVERIFY(lab);
QVERIFY(!lab->text().isEmpty());
}
void CheckDuplicateEmailsDialogTest::shouldAddEmails()
{
CheckDuplicateEmailsDialog dlg;
QListWidget *mListWidget = dlg.findChild<QListWidget *>(QStringLiteral("listwidget"));
QMap<QString, int> map;
map.insert(QStringLiteral("foo"), 5);
map.insert(QStringLiteral("bla"), 5);
map.insert(QStringLiteral("kde.org"), 7);
map.insert(QStringLiteral("linux.fr"), 2);
dlg.setDuplicatedEmails(map);
QCOMPARE(mListWidget->count(), map.count());
}
QTEST_MAIN(CheckDuplicateEmailsDialogTest)
......@@ -31,6 +31,7 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddEmails();
};
#endif // CHECKDUPLICATEEMAILSDIALOGTEST_H
......@@ -23,13 +23,18 @@
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QListWidget>
#include <QLabel>
#include <KConfigGroup>
#include <KSharedConfig>
CheckDuplicateEmailsDialog::CheckDuplicateEmailsDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18n("Duplicated Emails"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QLabel *lab = new QLabel(i18n("Theses emails are duplicated:"), this);
lab->setObjectName(QStringLiteral("label"));
mainLayout->addWidget(lab);
mListWidget = new QListWidget(this);
mListWidget->setObjectName(QStringLiteral("listwidget"));
......@@ -48,6 +53,15 @@ CheckDuplicateEmailsDialog::~CheckDuplicateEmailsDialog()
writeConfig();
}
void CheckDuplicateEmailsDialog::setDuplicatedEmails(const QMap<QString, int> &emails)
{
QMapIterator<QString, int> i(emails);
while (i.hasNext()) {
i.next();
mListWidget->addItem(i18nc("emails (number of emails)", "%1 (%2)", i.key(), i.value()));
}
}
void CheckDuplicateEmailsDialog::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "CheckDuplicateEmailsDialog");
......
......@@ -30,6 +30,7 @@ public:
explicit CheckDuplicateEmailsDialog(QWidget *parent = Q_NULLPTR);
~CheckDuplicateEmailsDialog();
void setDuplicatedEmails(const QMap<QString, int> &emails);
private:
void readConfig();
void writeConfig();
......
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