mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-24 19:02:51 +00:00
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
/*
|
|
Copyright (c) 2013, 2014 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 <libkdepim/misc/broadcaststatus.h>
|
|
|
|
|
|
#include <Akonadi/ItemModifyJob>
|
|
|
|
#include <KABC/Addressee>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
AddEmailToExistingContactJob::AddEmailToExistingContactJob(const Akonadi::Item &item, const QString &email, QObject *parent)
|
|
: KJob(parent),
|
|
mItem(item)
|
|
{
|
|
QString name;
|
|
KABC::Addressee::parseEmailAddress( email, name, mEmail );
|
|
}
|
|
|
|
AddEmailToExistingContactJob::~AddEmailToExistingContactJob()
|
|
{
|
|
|
|
}
|
|
|
|
void AddEmailToExistingContactJob::start()
|
|
{
|
|
if (mItem.hasPayload<KABC::Addressee>()) {
|
|
KABC::Addressee address = mItem.payload<KABC::Addressee>();
|
|
QStringList emails = address.emails();
|
|
if (emails.contains(mEmail)) {
|
|
Q_EMIT emitResult();
|
|
} else {
|
|
emails.append(mEmail);
|
|
address.setEmails(emails);
|
|
mItem.setPayload<KABC::Addressee>(address);
|
|
Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob( mItem );
|
|
connect( job, SIGNAL(result(KJob*)), SLOT(slotAddEmailDone(KJob*)) );
|
|
}
|
|
} else {
|
|
qDebug()<<" not a KABC::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();
|
|
}
|
|
|
|
#include "moc_addemailtoexistingcontactjob.cpp"
|