Commit b1f555ab authored by Laurent Montel's avatar Laurent Montel 😁

Split code

parent d1c570a5
......@@ -37,6 +37,7 @@ set( messagecomposer_job_src
job/aliasesexpandjob.cpp
job/emailaddressresolvejob.cpp
job/attachmentfrompublickeyjob.cpp
job/distributionlistexpandjob.cpp
)
set( messagecomposer_composer_src
......
......@@ -21,10 +21,8 @@
*/
#include "aliasesexpandjob.h"
#include "aliasesexpandjob_p.h"
#include "distributionlistexpandjob.h"
#include <akonadi/contact/contactgroupexpandjob.h>
#include <akonadi/contact/contactgroupsearchjob.h>
#include <akonadi/contact/contactsearchjob.h>
#include <KPIMUtils/Email>
......@@ -33,75 +31,6 @@
using namespace MessageComposer;
DistributionListExpandJob::DistributionListExpandJob( const QString &name, QObject *parent )
: KJob( parent ), mListName( name ), mIsEmpty( false )
{
}
DistributionListExpandJob::~DistributionListExpandJob()
{
}
void DistributionListExpandJob::start()
{
Akonadi::ContactGroupSearchJob *job = new Akonadi::ContactGroupSearchJob( this );
job->setQuery( Akonadi::ContactGroupSearchJob::Name, mListName );
connect( job, SIGNAL(result(KJob*)), SLOT(slotSearchDone(KJob*)) );
}
QString DistributionListExpandJob::addresses() const
{
return mEmailAddresses.join( QLatin1String( ", " ) );
}
bool DistributionListExpandJob::isEmpty() const
{
return mIsEmpty;
}
void DistributionListExpandJob::slotSearchDone( KJob *job )
{
if ( job->error() ) {
setError( job->error() );
setErrorText( job->errorText() );
emitResult();
return;
}
const Akonadi::ContactGroupSearchJob *searchJob = qobject_cast<Akonadi::ContactGroupSearchJob*>( job );
const KABC::ContactGroup::List groups = searchJob->contactGroups();
if ( groups.isEmpty() ) {
emitResult();
return;
}
Akonadi::ContactGroupExpandJob *expandJob = new Akonadi::ContactGroupExpandJob( groups.first() );
connect( expandJob, SIGNAL(result(KJob*)), SLOT(slotExpansionDone(KJob*)) );
expandJob->start();
}
void DistributionListExpandJob::slotExpansionDone( KJob *job )
{
if ( job->error() ) {
setError( job->error() );
setErrorText( job->errorText() );
emitResult();
return;
}
const Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob*>( job );
const KABC::Addressee::List contacts = expandJob->contacts();
foreach ( const KABC::Addressee &contact, contacts )
mEmailAddresses << contact.fullEmail();
mIsEmpty = mEmailAddresses.isEmpty();
emitResult();
}
AliasesExpandJob::AliasesExpandJob( const QString &recipients, const QString &defaultDomain, QObject *parent )
: KJob( parent ),
......@@ -249,5 +178,3 @@ void AliasesExpandJob::finishExpansion()
emitResult();
}
#include "moc_aliasesexpandjob_p.cpp"
/*
* This file is part of KMail.
*
* Copyright (c) 2010 KDAB
*
* Author: Tobias Koenig <tokoe@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; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "distributionlistexpandjob.h"
#include <akonadi/contact/contactgroupexpandjob.h>
#include <akonadi/contact/contactgroupsearchjob.h>
using namespace MessageComposer;
DistributionListExpandJob::DistributionListExpandJob( const QString &name, QObject *parent )
: KJob( parent ), mListName( name ), mIsEmpty( false )
{
}
DistributionListExpandJob::~DistributionListExpandJob()
{
}
void DistributionListExpandJob::start()
{
Akonadi::ContactGroupSearchJob *job = new Akonadi::ContactGroupSearchJob( this );
job->setQuery( Akonadi::ContactGroupSearchJob::Name, mListName );
connect( job, SIGNAL(result(KJob*)), SLOT(slotSearchDone(KJob*)) );
}
QString DistributionListExpandJob::addresses() const
{
return mEmailAddresses.join( QLatin1String( ", " ) );
}
bool DistributionListExpandJob::isEmpty() const
{
return mIsEmpty;
}
void DistributionListExpandJob::slotSearchDone( KJob *job )
{
if ( job->error() ) {
setError( job->error() );
setErrorText( job->errorText() );
emitResult();
return;
}
const Akonadi::ContactGroupSearchJob *searchJob = qobject_cast<Akonadi::ContactGroupSearchJob*>( job );
const KABC::ContactGroup::List groups = searchJob->contactGroups();
if ( groups.isEmpty() ) {
emitResult();
return;
}
Akonadi::ContactGroupExpandJob *expandJob = new Akonadi::ContactGroupExpandJob( groups.first() );
connect( expandJob, SIGNAL(result(KJob*)), SLOT(slotExpansionDone(KJob*)) );
expandJob->start();
}
void DistributionListExpandJob::slotExpansionDone( KJob *job )
{
if ( job->error() ) {
setError( job->error() );
setErrorText( job->errorText() );
emitResult();
return;
}
const Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob*>( job );
const KABC::Addressee::List contacts = expandJob->contacts();
foreach ( const KABC::Addressee &contact, contacts )
mEmailAddresses << contact.fullEmail();
mIsEmpty = mEmailAddresses.isEmpty();
emitResult();
}
......@@ -24,7 +24,8 @@
#define ALIASESEXPANDJOB_P_H
#include <kjob.h>
#include <QStringList>
namespace MessageComposer {
/**
* @short A job to expand a distribution list to its member email addresses.
*/
......@@ -70,5 +71,5 @@ class DistributionListExpandJob : public KJob
QStringList mEmailAddresses;
bool mIsEmpty;
};
}
#endif
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