Commit 018270c1 authored by Laurent Montel's avatar Laurent Montel 😁

Add job

parent d575a1db
......@@ -3,6 +3,7 @@ set(kmail_checkbeforesendeditorplugin_SRCS
checkbeforesendinterface.cpp
checkbeforesendconfigurewidget.cpp
checkduplicateemailsdialog.cpp
checkduplicateemailsjob.cpp
)
ecm_qt_declare_logging_category(kmail_checkbeforesendeditorplugin_SRCS HEADER checkbeforesendplugin_debug.h IDENTIFIER KMAIL_EDITOR_checkbeforesend_PLUGIN_LOG CATEGORY_NAME log_kmail_checkbeforesendplugin)
......
......@@ -12,7 +12,8 @@ macro(add_kmail_checkbeforesend_unittest _source _additional)
endmacro ()
add_kmail_checkbeforesend_unittest(checkbeforesendplugintest.cpp "../checkbeforesendplugin.cpp;../checkbeforesendinterface.cpp;../checkbeforesendconfigurewidget.cpp")
add_kmail_checkbeforesend_unittest(checkbeforesendinterfacetest.cpp "../checkbeforesendinterface.cpp")
add_kmail_checkbeforesend_unittest(checkbeforesendplugintest.cpp "../checkduplicateemailsjob.cpp;../checkduplicateemailsdialog.cpp;../checkbeforesendplugin.cpp;../checkbeforesendinterface.cpp;../checkbeforesendconfigurewidget.cpp")
add_kmail_checkbeforesend_unittest(checkbeforesendinterfacetest.cpp "../checkduplicateemailsjob.cpp;../checkduplicateemailsdialog.cpp;../checkbeforesendinterface.cpp")
add_kmail_checkbeforesend_unittest(checkbeforesendconfigurewidgettest.cpp "../checkbeforesendconfigurewidget.cpp")
add_kmail_checkbeforesend_unittest(checkduplicateemailsdialogtest.cpp "../checkduplicateemailsdialog.cpp")
add_kmail_checkbeforesend_unittest(checkduplicateemailsjobtest.cpp "../checkduplicateemailsjob.cpp")
/*
Copyright (C) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "checkduplicateemailsjobtest.h"
#include "../checkduplicateemailsjob.h"
#include <QTest>
#include <QStringList>
CheckDuplicateEmailsJobTest::CheckDuplicateEmailsJobTest(QObject *parent)
: QObject(parent)
{
}
CheckDuplicateEmailsJobTest::~CheckDuplicateEmailsJobTest()
{
}
void CheckDuplicateEmailsJobTest::shouldHaveDefaultValue()
{
CheckDuplicateEmailsJob job;
QVERIFY(job.result().isEmpty());
}
void CheckDuplicateEmailsJobTest::shouldReturnEmptyListWhenEmailsListIsEmpty()
{
CheckDuplicateEmailsJob job;
QStringList listEmails;
job.setEmails(listEmails);
job.start();
QVERIFY(job.result().isEmpty());
}
void CheckDuplicateEmailsJobTest::shouldReturnEmails_data()
{
QTest::addColumn<QStringList>("emails");
QTest::addColumn<QMap<QString, int> >("result");
QTest::newRow("empty") << QStringList() << QMap<QString, int>();
}
void CheckDuplicateEmailsJobTest::shouldReturnEmails()
{
QFETCH(QStringList, emails);
typedef QMap<QString, int> mapEmails;
QFETCH(mapEmails, result);
CheckDuplicateEmailsJob job;
job.setEmails(emails);
job.start();
QCOMPARE(job.result(), result);
}
QTEST_MAIN(CheckDuplicateEmailsJobTest)
/*
Copyright (C) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CHECKDUPLICATEEMAILSJOBTEST_H
#define CHECKDUPLICATEEMAILSJOBTEST_H
#include <QObject>
class CheckDuplicateEmailsJobTest : public QObject
{
Q_OBJECT
public:
explicit CheckDuplicateEmailsJobTest(QObject *parent = Q_NULLPTR);
~CheckDuplicateEmailsJobTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldReturnEmptyListWhenEmailsListIsEmpty();
void shouldReturnEmails_data();
void shouldReturnEmails();
};
#endif // CHECKDUPLICATEEMAILSJOBTEST_H
......@@ -18,6 +18,8 @@
*/
#include "checkbeforesendinterface.h"
#include "checkduplicateemailsjob.h"
#include "checkduplicateemailsdialog.h"
#include <KMessageBox>
#include <KConfigGroup>
......@@ -26,6 +28,8 @@
#include <KIdentityManagement/Identity>
#include <KIdentityManagement/IdentityManager>
#include <QPointer>
CheckBeforeSendInterface::CheckBeforeSendInterface(QObject *parent)
: MessageComposer::PluginEditorCheckBeforeSendInterface(parent),
mIdentityManager(Q_NULLPTR),
......@@ -66,7 +70,23 @@ bool CheckBeforeSendInterface::exec(const MessageComposer::PluginEditorCheckBefo
}
}
if (mCheckDuplicateEmails) {
//TODO
const QStringList lst{ params.bccAddresses(), params.toAddresses(), params.ccAddresses() };
if (!lst.isEmpty()) {
CheckDuplicateEmailsJob job;
job.setEmails(lst);
job.start();
const QMap<QString, int> results = job.result();
if (!results.isEmpty()) {
QPointer<CheckDuplicateEmailsDialog> dlg = new CheckDuplicateEmailsDialog(parentWidget());
if (dlg->exec()) {
delete dlg;
return true;
} else {
delete dlg;
return false;
}
}
}
}
return true;
}
......
/*
Copyright (C) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "checkduplicateemailsjob.h"
CheckDuplicateEmailsJob::CheckDuplicateEmailsJob()
{
}
CheckDuplicateEmailsJob::~CheckDuplicateEmailsJob()
{
}
void CheckDuplicateEmailsJob::start()
{
mResult.clear();
if (mEmails.isEmpty()) {
return;
}
}
void CheckDuplicateEmailsJob::setEmails(const QStringList &list)
{
mEmails = list;
}
QMap<QString, int> CheckDuplicateEmailsJob::result() const
{
return mResult;
}
/*
Copyright (C) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CHECKDUPLICATEEMAILSJOB_H
#define CHECKDUPLICATEEMAILSJOB_H
#include <QMap>
#include <QStringList>
class CheckDuplicateEmailsJob
{
public:
CheckDuplicateEmailsJob();
~CheckDuplicateEmailsJob();
void start();
void setEmails(const QStringList &list);
QMap<QString, int> result() const;
private:
QStringList mEmails;
QMap<QString, int> mResult;
};
#endif // CHECKDUPLICATEEMAILSJOB_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