Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 237c90b7 authored by Laurent Montel's avatar Laurent Montel 😁

Create balooemailutil to generate new list.

parent 4dbade0a
......@@ -77,6 +77,7 @@ set(kdepim_addressline_blacklist_baloo_LIB_SRCS
addressline/blacklistbaloocompletion/blacklistbalooemailcompletiondialog.cpp
addressline/blacklistbaloocompletion/blacklistbalooemaillist.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailsearchjob.cpp
addressline/blacklistbaloocompletion/blacklistbalooemailutil.cpp
)
set(kdepim_LIB_SRCS
......
......@@ -387,7 +387,9 @@ void AddresseeLineEdit::Private::searchInBaloo()
Baloo::PIM::ContactCompleter com(trimmedString, 20);
const QStringList listEmail = cleanupBalooContact(com.complete());
Q_FOREACH (const QString& email, listEmail) {
addCompletionItem(email, 1, s_static->balooCompletionSource);
if (!m_balooBlackList.contains(email)) {
addCompletionItem(email, 1, s_static->balooCompletionSource);
}
}
doCompletion( m_lastSearchMode );
// if ( q->hasFocus() || q->completionBox()->hasFocus() ) {
......@@ -1029,7 +1031,7 @@ void AddresseeLineEdit::Private::slotConfigureBalooBlackList()
void AddresseeLineEdit::Private::loadBalooBlackList()
{
KConfigGroup group( KGlobal::config(), "AddressLineEdit" );
m_balooBlackList = group.readEntry( "Baloo Back List", QStringList() );
m_balooBlackList = group.readEntry( "BalooBackList", QStringList() );
}
AddresseeLineEdit::AddresseeLineEdit( QWidget *parent, bool enableCompletion )
......@@ -1391,7 +1393,7 @@ QMenu *AddresseeLineEdit::createStandardContextMenu()
//Add i18n in kf5
QAction *configureBalooBlackList = new QAction(QLatin1String( "Configure Email Blacklist" ),menu);
connect(configureBalooBlackList, SIGNAL(triggered(bool)), this, SLOT(slotConfigureBalooBlackList(bool)));
connect(configureBalooBlackList, SIGNAL(triggered(bool)), this, SLOT(slotConfigureBalooBlackList()));
menu->addAction(configureBalooBlackList);
return menu;
......
......@@ -17,4 +17,7 @@ set( libkdepim_blacklistbalooemailsearchjobtest_SRCS blacklistbalooemailsearchjo
kde4_add_unit_test( libkdepim_blacklistbalooemailsearchjobtest ${libkdepim_blacklistbalooemailsearchjobtest_SRCS})
target_link_libraries( libkdepim_blacklistbalooemailsearchjobtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} kdepim)
set( libkdepim_blacklistbalooemailutiltest_SRCS blacklistbalooemailutiltest.cpp )
kde4_add_unit_test( libkdepim_blacklistbalooemailutiltest ${libkdepim_blacklistbalooemailutiltest_SRCS})
target_link_libraries( libkdepim_blacklistbalooemailutiltest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} kdepim)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "blacklistbalooemailutiltest.h"
#include "../blacklistbalooemailutil.h"
#include <qtest_kde.h>
BlackListBalooEmailUtilTest::BlackListBalooEmailUtilTest(QObject *parent)
: QObject(parent)
{
}
BlackListBalooEmailUtilTest::~BlackListBalooEmailUtilTest()
{
}
void BlackListBalooEmailUtilTest::shouldReturnEmptyResult()
{
KPIM::BlackListBalooEmailUtil util;
QVERIFY(util.createNewBlackList().isEmpty());
}
void BlackListBalooEmailUtilTest::shouldDontChangeWhenNotChanged()
{
KPIM::BlackListBalooEmailUtil util;
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("foo1") << QLatin1String("foo2");
util.initialBlackList(lst);
QCOMPARE(util.createNewBlackList(), lst);
}
void BlackListBalooEmailUtilTest::shouldCreateNewList()
{
KPIM::BlackListBalooEmailUtil util;
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("foo1") << QLatin1String("foo2");
util.initialBlackList(lst);
QHash<QString, bool> newList;
newList.insert(QLatin1String("foo"), false);
util.newBlackList(newList);
QCOMPARE(util.createNewBlackList(), QStringList() << QLatin1String("foo1") << QLatin1String("foo2"));
}
void BlackListBalooEmailUtilTest::shouldAddNewElements()
{
KPIM::BlackListBalooEmailUtil util;
QHash<QString, bool> newList;
newList.insert(QLatin1String("foo"), false);
newList.insert(QLatin1String("foo1"), false);
newList.insert(QLatin1String("foo2"), false);
util.newBlackList(newList);
QCOMPARE(util.createNewBlackList().count(), 0);
newList.clear();
newList.insert(QLatin1String("foo"), true);
newList.insert(QLatin1String("foo1"), true);
newList.insert(QLatin1String("foo2"), true);
util.newBlackList(newList);
QCOMPARE(util.createNewBlackList().count(), 3);
}
QTEST_KDEMAIN(BlackListBalooEmailUtilTest, NoGUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef BLACKLISTBALOOEMAILUTILTEST_H
#define BLACKLISTBALOOEMAILUTILTEST_H
#include <QObject>
class BlackListBalooEmailUtilTest : public QObject
{
Q_OBJECT
public:
explicit BlackListBalooEmailUtilTest(QObject *parent = 0);
~BlackListBalooEmailUtilTest();
private Q_SLOTS:
void shouldReturnEmptyResult();
void shouldDontChangeWhenNotChanged();
void shouldCreateNewList();
void shouldAddNewElements();
};
#endif // BLACKLISTBALOOEMAILUTILTEST_H
......@@ -21,6 +21,7 @@
#include "blacklistbalooemailcompletiondialog.h"
#include "blacklistbalooemailsearchjob.h"
#include "blacklistbalooemaillist.h"
#include "blacklistbalooemailutil.h"
#include <KLocalizedString>
#include <QHBoxLayout>
#include <QVBoxLayout>
......@@ -57,11 +58,13 @@ BlackListBalooEmailCompletionDialog::BlackListBalooEmailCompletionDialog(QWidget
mSearchLineEdit->setClearButtonShown(true);
mSearchLineEdit->setTrapReturnKey(true);
mSearchLineEdit->setObjectName(QLatin1String("search_lineedit"));
connect(mSearchLineEdit, SIGNAL(returnPressed()), this, SLOT(slotSearch()));
searchLayout->addWidget(mSearchLineEdit);
//Add i18n in kf5
mSearchButton = new KPushButton(QLatin1String("Search"));
mSearchButton->setObjectName(QLatin1String("search_button"));
connect(mSearchButton, SIGNAL(clicked()), this, SLOT(slotSearch()));
mSearchButton->setEnabled(false);
searchLayout->addWidget(mSearchButton);
......@@ -107,8 +110,15 @@ void BlackListBalooEmailCompletionDialog::writeConfig()
void BlackListBalooEmailCompletionDialog::slotSave()
{
const QHash<QString, bool> result = mEmailList->blackListItemChanged();
if (result.isEmpty()) {
if (!result.isEmpty()) {
KConfigGroup group( KGlobal::config(), "AddressLineEdit" );
QStringList blackList = group.readEntry( "BalooBackList", QStringList() );
KPIM::BlackListBalooEmailUtil util;
util.initialBlackList(blackList);
util.newBlackList(result);
blackList = util.createNewBlackList();
group.writeEntry( "Baloo Back List", blackList );
group.sync();
}
accept();
}
......@@ -116,7 +126,11 @@ void BlackListBalooEmailCompletionDialog::slotSave()
void BlackListBalooEmailCompletionDialog::slotSearch()
{
const QString searchEmail = mSearchLineEdit->text().trimmed();
KPIM::BlackListBalooEmailSearchJob *job = new KPIM::BlackListBalooEmailSearchJob(this);
connect(job, SIGNAL(emailsFound(QStringList)), mEmailList, SLOT(slotEmailFound(QStringList)));
if (searchEmail.length() > 2 ) {
KPIM::BlackListBalooEmailSearchJob *job = new KPIM::BlackListBalooEmailSearchJob(this);
job->setSearchEmail(searchEmail);
connect(job, SIGNAL(emailsFound(QStringList)), mEmailList, SLOT(slotEmailFound(QStringList)));
job->start();
}
}
......@@ -27,7 +27,7 @@ using namespace KPIM;
BlackListBalooEmailList::BlackListBalooEmailList(QWidget *parent)
: QListWidget(parent)
{
setSelectionMode(QAbstractItemView::ExtendedSelection);
}
BlackListBalooEmailList::~BlackListBalooEmailList()
......@@ -64,6 +64,8 @@ void BlackListBalooEmailList::slotEmailFound(const QStringList &list)
if (mEmailBlackList.contains(mail)) {
item->setCheckState(Qt::Checked);
item->setInitializeStatus(true);
} else {
item->setCheckState(Qt::Unchecked);
}
item->setText(mail);
emailsAdded << mail;
......
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "blacklistbalooemailutil.h"
using namespace KPIM;
BlackListBalooEmailUtil::BlackListBalooEmailUtil()
{
}
BlackListBalooEmailUtil::~BlackListBalooEmailUtil()
{
}
void BlackListBalooEmailUtil::initialBlackList(const QStringList &blackList)
{
mInitialList = blackList;
}
void BlackListBalooEmailUtil::newBlackList(const QHash<QString, bool> &list)
{
mNewBlackList = list;
}
QStringList BlackListBalooEmailUtil::createNewBlackList()
{
if (mNewBlackList.isEmpty()) {
return mInitialList;
}
QHashIterator<QString, bool> i(mNewBlackList);
while (i.hasNext()) {
i.next();
const QString newEmail(i.key());
if (i.value()) {
if (!mInitialList.contains(newEmail)) {
mInitialList.append(newEmail);
}
} else {
if (mInitialList.contains(newEmail)) {
mInitialList.removeAll(newEmail);
}
}
}
return mInitialList;
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef BLACKLISTBALOOEMAILUTIL_H
#define BLACKLISTBALOOEMAILUTIL_H
#include "kdepim_export.h"
#include <QStringList>
#include <QHash>
namespace KPIM {
class KDEPIM_EXPORT BlackListBalooEmailUtil
{
public:
BlackListBalooEmailUtil();
~BlackListBalooEmailUtil();
void initialBlackList(const QStringList &blackList);
void newBlackList(const QHash<QString, bool> & );
QStringList createNewBlackList();
private:
QStringList mInitialList;
QHash<QString, bool> mNewBlackList;
};
}
#endif // BLACKLISTBALOOEMAILUTIL_H
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