checkduplicateemailsjob.cpp 1.81 KB
Newer Older
Laurent Montel's avatar
Add job  
Laurent Montel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
   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"
Laurent Montel's avatar
Laurent Montel committed
20 21
#include <KEmailAddress>
#include <QDebug>
Laurent Montel's avatar
Add job  
Laurent Montel committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

CheckDuplicateEmailsJob::CheckDuplicateEmailsJob()
{

}

CheckDuplicateEmailsJob::~CheckDuplicateEmailsJob()
{

}

void CheckDuplicateEmailsJob::start()
{
    mResult.clear();
    if (mEmails.isEmpty()) {
        return;
    }
Laurent Montel's avatar
Laurent Montel committed
39 40
    QMap<QString, int> results;
    Q_FOREACH(const QString &email, mEmails) {
Laurent Montel's avatar
Laurent Montel committed
41 42 43 44
        QString tname, temail;
        KEmailAddress::extractEmailAddressAndName(email, temail, tname);    // ignore return value

        int val = results.value(temail, 0);
Laurent Montel's avatar
Laurent Montel committed
45
        if (val == 0) {
Laurent Montel's avatar
Laurent Montel committed
46
            results.insert(temail, val+1);
Laurent Montel's avatar
Laurent Montel committed
47
        } else {
Laurent Montel's avatar
Laurent Montel committed
48
            results[temail] = val+1;
Laurent Montel's avatar
Laurent Montel committed
49 50 51 52 53 54 55 56 57 58
        }
    }
    QMapIterator<QString, int> i(results);
    while (i.hasNext()) {
        i.next();
        if (i.value() > 1) {
            mResult.insert(i.key(), i.value());
        }
    }

Laurent Montel's avatar
Add job  
Laurent Montel committed
59 60 61 62 63 64 65 66 67 68 69
}

void CheckDuplicateEmailsJob::setEmails(const QStringList &list)
{
    mEmails = list;
}

QMap<QString, int> CheckDuplicateEmailsJob::result() const
{
    return mResult;
}