You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
72 lines
2.3 KiB
/* |
|
Copyright (c) 2013-2015 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, version 2, as |
|
published by the Free Software Foundation. |
|
|
|
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; if not, write to the Free Software Foundation, Inc., |
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
*/ |
|
|
|
#include "addemailtoexistingcontactjob.h" |
|
#include "kmail_debug.h" |
|
#include <Libkdepim/BroadcastStatus> |
|
|
|
#include <AkonadiCore/ItemModifyJob> |
|
|
|
#include <KContacts/Addressee> |
|
|
|
#include <KLocalizedString> |
|
|
|
AddEmailToExistingContactJob::AddEmailToExistingContactJob(const Akonadi::Item &item, const QString &email, QObject *parent) |
|
: KJob(parent), |
|
mItem(item) |
|
{ |
|
QString name; |
|
KContacts::Addressee::parseEmailAddress(email, name, mEmail); |
|
} |
|
|
|
AddEmailToExistingContactJob::~AddEmailToExistingContactJob() |
|
{ |
|
|
|
} |
|
|
|
void AddEmailToExistingContactJob::start() |
|
{ |
|
if (mItem.hasPayload<KContacts::Addressee>()) { |
|
KContacts::Addressee address = mItem.payload<KContacts::Addressee>(); |
|
QStringList emails = address.emails(); |
|
if (emails.contains(mEmail)) { |
|
Q_EMIT emitResult(); |
|
} else { |
|
emails.append(mEmail); |
|
address.setEmails(emails); |
|
mItem.setPayload<KContacts::Addressee>(address); |
|
Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem); |
|
connect(job, &Akonadi::ItemModifyJob::result, this, &AddEmailToExistingContactJob::slotAddEmailDone); |
|
} |
|
} else { |
|
qCDebug(KMAIL_LOG) << " not a KContacts::Addressee item "; |
|
//TODO add error |
|
Q_EMIT emitResult(); |
|
} |
|
} |
|
|
|
void AddEmailToExistingContactJob::slotAddEmailDone(KJob *job) |
|
{ |
|
if (job->error()) { |
|
setError(job->error()); |
|
setErrorText(job->errorText()); |
|
} else { |
|
KPIM::BroadcastStatus::instance()->setStatusMsg(i18n("Email added successfully.")); |
|
} |
|
Q_EMIT emitResult(); |
|
} |
|
|
|
|