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

Return item changed

parent 59fe54ac
......@@ -44,6 +44,57 @@ void BlackListBalooEmailListTest::shouldFillListEmail()
KPIM::BlackListBalooEmailList blackList;
blackList.slotEmailFound(QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli"));
QCOMPARE(blackList.count(), 3);
for (int i = 0; i < blackList.count(); ++i) {
QListWidgetItem *item = blackList.item(i);
QVERIFY(item);
KPIM::BlackListBalooEmailListItem *blackListItem = static_cast<KPIM::BlackListBalooEmailListItem *>(item);
QVERIFY(!blackListItem->initializeStatus());
QCOMPARE(blackListItem->checkState(), Qt::Unchecked);
}
QVERIFY(blackList.blackListItemChanged().isEmpty());
}
void BlackListBalooEmailListTest::shouldFillListWithAlreadyBlackListedEmail()
{
KPIM::BlackListBalooEmailList blackList;
QStringList emails = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli");
blackList.setEmailBlackList(emails);
blackList.slotEmailFound(emails);
QCOMPARE(blackList.count(), 3);
for (int i = 0; i < blackList.count(); ++i) {
QListWidgetItem *item = blackList.item(i);
QVERIFY(item);
KPIM::BlackListBalooEmailListItem *blackListItem = static_cast<KPIM::BlackListBalooEmailListItem *>(item);
QVERIFY(blackListItem->initializeStatus());
QCOMPARE(blackListItem->checkState(), Qt::Checked);
}
QVERIFY(blackList.blackListItemChanged().isEmpty());
}
void BlackListBalooEmailListTest::shouldReturnChangedItems()
{
KPIM::BlackListBalooEmailList blackList;
QStringList emails = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli");
blackList.setEmailBlackList(emails);
blackList.slotEmailFound(emails);
QListWidgetItem *item = blackList.item(1);
QVERIFY(item);
item->setCheckState(Qt::Unchecked);
QVERIFY(!blackList.blackListItemChanged().isEmpty());
}
void BlackListBalooEmailListTest::shouldNotAddDuplicateEmails()
{
KPIM::BlackListBalooEmailList blackList;
QStringList emails = QStringList() << QLatin1String("foo") << QLatin1String("bli") << QLatin1String("bli");
blackList.setEmailBlackList(emails);
blackList.slotEmailFound(emails);
QCOMPARE(blackList.count(), 2);
}
QTEST_KDEMAIN(BlackListBalooEmailListTest, GUI)
......@@ -32,6 +32,9 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldFillListEmail();
void shouldFillListWithAlreadyBlackListedEmail();
void shouldReturnChangedItems();
void shouldNotAddDuplicateEmails();
};
#endif // BLACKLISTBALOOEMAILLISTTEST_H
......@@ -101,7 +101,11 @@ void BlackListBalooEmailCompletionDialog::writeConfig()
void BlackListBalooEmailCompletionDialog::slotSave()
{
//TODO
const QHash<QString, bool> result = mEmailList->blackListItemChanged();
if (result.isEmpty()) {
}
accept();
}
void BlackListBalooEmailCompletionDialog::slotSearch()
......
......@@ -40,12 +40,34 @@ void BlackListBalooEmailList::setEmailBlackList(const QStringList &list)
mEmailBlackList = list;
}
QHash<QString, bool> BlackListBalooEmailList::blackListItemChanged() const
{
QHash<QString, bool> result;
for (int i = 0; i < count(); ++i) {
QListWidgetItem *element = item(i);
KPIM::BlackListBalooEmailListItem *blackListItem = static_cast<KPIM::BlackListBalooEmailListItem *>(element);
bool currentStatus = (blackListItem->checkState() == Qt::Checked);
if (blackListItem->initializeStatus() != currentStatus) {
result.insert(blackListItem->text(), currentStatus);
}
}
return result;
}
void BlackListBalooEmailList::slotEmailFound(const QStringList &list)
{
clear();
QStringList emailsAdded;
Q_FOREACH(const QString & mail, list) {
BlackListBalooEmailListItem *item = new BlackListBalooEmailListItem(this);
item->setText(mail);
if (!emailsAdded.contains(mail)) {
BlackListBalooEmailListItem *item = new BlackListBalooEmailListItem(this);
if (mEmailBlackList.contains(mail)) {
item->setCheckState(Qt::Checked);
item->setInitializeStatus(true);
}
item->setText(mail);
emailsAdded << mail;
}
}
}
......
......@@ -23,6 +23,7 @@
#include <QListWidget>
#include <QListWidgetItem>
#include <QHash>
#include "kdepim_export.h"
namespace KPIM {
......@@ -49,6 +50,8 @@ public:
void setEmailBlackList(const QStringList &list);
QHash<QString, bool> blackListItemChanged() const;
public Q_SLOTS:
void slotEmailFound(const QStringList &);
......
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