diff --git a/akonadi/contact/contactgroupexpandjob.cpp b/akonadi/contact/contactgroupexpandjob.cpp index f51d66fd6..556cd3e3c 100644 --- a/akonadi/contact/contactgroupexpandjob.cpp +++ b/akonadi/contact/contactgroupexpandjob.cpp @@ -1,107 +1,117 @@ /* Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contactgroupexpandjob.h" #include #include #include using namespace Akonadi; class ContactGroupExpandJob::Private { public: Private( const KABC::ContactGroup &group, ContactGroupExpandJob *parent ) : mParent( parent ), mGroup( group ), mFetchCount( 0 ) { } void fetchResult( KJob *job ) { const ItemFetchJob *fetchJob = qobject_cast( job ); const Item::List items = fetchJob->items(); if ( !items.isEmpty() ) { const QString email = fetchJob->property( "preferredEmail" ).toString(); KABC::Addressee contact = items.first().payload(); if ( !email.isEmpty() ) contact.insertEmail( email, true ); mContacts.append( contact ); } mFetchCount--; if ( mFetchCount == 0 ) mParent->emitResult(); } ContactGroupExpandJob *mParent; KABC::ContactGroup mGroup; KABC::Addressee::List mContacts; int mFetchCount; }; ContactGroupExpandJob::ContactGroupExpandJob( const KABC::ContactGroup &group, QObject * parent ) : KJob( parent ), d( new Private( group, this ) ) { } ContactGroupExpandJob::~ContactGroupExpandJob() { delete d; } void ContactGroupExpandJob::start() { for ( unsigned int i = 0; i < d->mGroup.dataCount(); ++i ) { const KABC::ContactGroup::Data data = d->mGroup.data( i ); KABC::Addressee contact; contact.setNameFromString( data.name() ); contact.insertEmail( data.email(), true ); d->mContacts.append( contact ); } for ( unsigned int i = 0; i < d->mGroup.contactReferenceCount(); ++i ) { const KABC::ContactGroup::ContactReference reference = d->mGroup.contactReference( i ); ItemFetchJob *job = new ItemFetchJob( Item( reference.uid().toLongLong() ) ); job->fetchScope().fetchFullPayload(); job->setProperty( "preferredEmail", reference.preferredEmail() ); connect( job, SIGNAL( result( KJob* ) ), this, SLOT( fetchResult( KJob* ) ) ); d->mFetchCount++; } if ( d->mFetchCount == 0 ) // nothing to fetch, so we can return immediately emitResult(); } KABC::Addressee::List ContactGroupExpandJob::contacts() const { return d->mContacts; } +QStringList ContactGroupExpandJob::emailAddresses() const +{ + QStringList emails; + + foreach ( const KABC::Addressee &contact, d->mContacts ) + emails.append( contact.fullEmail() ); + + return emails; +} + #include "contactgroupexpandjob.moc" diff --git a/akonadi/contact/contactgroupexpandjob.h b/akonadi/contact/contactgroupexpandjob.h index 90c487e35..c37f9f896 100644 --- a/akonadi/contact/contactgroupexpandjob.h +++ b/akonadi/contact/contactgroupexpandjob.h @@ -1,100 +1,107 @@ /* Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_CONTACTGROUPEXPANDJOB_H #define AKONADI_CONTACTGROUPEXPANDJOB_H #include "akonadi-contact_export.h" #include #include #include namespace Akonadi { /** * @short Job that expands a ContactGroup to a list of contacts. * * This job takes a KABC::ContactGroup object and expands it to a list * of KABC::Addressee objects by creating temporary KABC::Addressee objects * for the KABC::ContactGroup::Data objects of the group and fetching the * complete contacts from the Akonadi storage for the * KABC::ContactGroup::ContactReferences of the group. * * @code * * const KABC::ContactGroup group = ...; * * Akonadi::ContactGroupExpandJob *job = new Akonadi::ContactGroupExpandJob( group ); * job->start(); * connect( job, SIGNAL( result( KJob* ) ), this, SLOT( expandResult( KJob* ) ) ); * * ... * * MyClass::expandResult( KJob *job ) * { * Akonadi::ContactGroupExpandJob *expandJob = qobject_cast( job ); * const KABC::Addressee::List contacts = expandJob->contacts(); * // do something with the contacts * } * * @endcode * * @author Tobias Koenig */ class AKONADI_CONTACT_EXPORT ContactGroupExpandJob : public KJob { Q_OBJECT public: /** * Creates a new contact group expand job. * * @param group The contact group to expand. * @param parent The parent object. */ explicit ContactGroupExpandJob( const KABC::ContactGroup &group, QObject *parent = 0 ); /** * Destroys the contact group expand job. */ ~ContactGroupExpandJob(); /** * Returns the list of contacts. */ KABC::Addressee::List contacts() const; + /** + * Returns the list of email addresses of the contacts. + * + * Each entry of the list is in the form: FullName + */ + QStringList emailAddresses() const; + /** * Starts the expand job. */ virtual void start(); private: //@cond PRIVATE class Private; Private* const d; Q_PRIVATE_SLOT( d, void fetchResult( KJob* ) ) //@endcond }; } #endif