22 #include "contactgroupexpandjob.h"
24 #include <akonadi/contact/contactgroupsearchjob.h>
25 #include <akonadi/itemfetchjob.h>
26 #include <akonadi/itemfetchscope.h>
27 #include <akonadi/itemsearchjob.h>
29 using namespace Akonadi;
31 class ContactGroupExpandJob::Private
35 : mParent( parent ), mGroup( group ), mFetchCount( 0 )
40 : mParent( parent ), mName( name ), mFetchCount( 0 )
46 for (
unsigned int i = 0; i < mGroup.dataCount(); ++i ) {
47 const KABC::ContactGroup::Data data = mGroup.data( i );
49 KABC::Addressee contact;
50 contact.setNameFromString( data.name() );
51 contact.insertEmail( data.email(), true );
53 mContacts.append( contact );
56 for (
unsigned int i = 0; i < mGroup.contactReferenceCount(); ++i ) {
57 const KABC::ContactGroup::ContactReference reference = mGroup.contactReference( i );
61 job->setProperty(
"preferredEmail", reference.preferredEmail() );
63 mParent->connect( job, SIGNAL(result(KJob*)), mParent, SLOT(fetchResult(KJob*)) );
68 if ( mFetchCount == 0 ) {
69 mParent->emitResult();
73 void searchResult( KJob *job )
76 mParent->setError( job->error() );
77 mParent->setErrorText( job->errorText() );
78 mParent->emitResult();
85 mParent->emitResult();
93 void fetchResult( KJob *job )
98 if ( !items.isEmpty() ) {
99 const QString email = fetchJob->property(
"preferredEmail" ).toString();
101 const Item item = items.first();
103 KABC::Addressee contact = item.
payload<KABC::Addressee>();
104 if ( !email.isEmpty() ) {
105 contact.insertEmail( email,
true );
108 mContacts.append( contact );
110 kWarning() <<
"Contact for Akonadi item" << item.
id() <<
"does not exist anymore!";
115 if ( mFetchCount == 0 ) {
116 mParent->emitResult();
121 KABC::ContactGroup mGroup;
123 KABC::Addressee::List mContacts;
129 : KJob( parent ), d( new Private( group, this ) )
134 : KJob( parent ), d( new Private( name, this ) )
145 if ( !d->mName.isEmpty() && !d->mName.contains( QLatin1Char(
'@' ) ) ) {
150 connect( searchJob, SIGNAL(result(KJob*)),
this, SLOT(searchResult(KJob*)) );
161 #include "moc_contactgroupexpandjob.cpp"