• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi/contact

contactgroupexpandjob.cpp

00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "contactgroupexpandjob.h"
00023 
00024 #include <akonadi/itemfetchjob.h>
00025 #include <akonadi/itemfetchscope.h>
00026 #include <akonadi/itemsearchjob.h>
00027 
00028 using namespace Akonadi;
00029 
00030 class ContactGroupExpandJob::Private
00031 {
00032   public:
00033     Private( const KABC::ContactGroup &group, ContactGroupExpandJob *parent )
00034       : mParent( parent ), mGroup( group ), mFetchCount( 0 )
00035     {
00036     }
00037 
00038     void fetchResult( KJob *job )
00039     {
00040       const ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job );
00041 
00042       const Item::List items = fetchJob->items();
00043       if ( !items.isEmpty() ) {
00044         const QString email = fetchJob->property( "preferredEmail" ).toString();
00045 
00046         const Item item = items.first();
00047         if ( item.hasPayload<KABC::Addressee>() ) {
00048           KABC::Addressee contact = item.payload<KABC::Addressee>();
00049           if ( !email.isEmpty() )
00050             contact.insertEmail( email, true );
00051 
00052           mContacts.append( contact );
00053         } else
00054           kWarning() << "Contact for Akonadi item" << item.id() << "does not exist anymore!";
00055       }
00056 
00057       mFetchCount--;
00058 
00059       if ( mFetchCount == 0 )
00060         mParent->emitResult();
00061     }
00062 
00063     ContactGroupExpandJob *mParent;
00064     KABC::ContactGroup mGroup;
00065     KABC::Addressee::List mContacts;
00066 
00067     int mFetchCount;
00068 };
00069 
00070 ContactGroupExpandJob::ContactGroupExpandJob( const KABC::ContactGroup &group, QObject * parent )
00071   : KJob( parent ), d( new Private( group, this ) )
00072 {
00073 }
00074 
00075 ContactGroupExpandJob::~ContactGroupExpandJob()
00076 {
00077   delete d;
00078 }
00079 
00080 void ContactGroupExpandJob::start()
00081 {
00082   for ( unsigned int i = 0; i < d->mGroup.dataCount(); ++i ) {
00083     const KABC::ContactGroup::Data data = d->mGroup.data( i );
00084 
00085     KABC::Addressee contact;
00086     contact.setNameFromString( data.name() );
00087     contact.insertEmail( data.email(), true );
00088 
00089     d->mContacts.append( contact );
00090   }
00091 
00092   for ( unsigned int i = 0; i < d->mGroup.contactReferenceCount(); ++i ) {
00093     const KABC::ContactGroup::ContactReference reference = d->mGroup.contactReference( i );
00094 
00095     ItemFetchJob *job = new ItemFetchJob( Item( reference.uid().toLongLong() ) );
00096     job->fetchScope().fetchFullPayload();
00097     job->setProperty( "preferredEmail", reference.preferredEmail() );
00098 
00099     connect( job, SIGNAL( result( KJob* ) ), this, SLOT( fetchResult( KJob* ) ) );
00100 
00101     d->mFetchCount++;
00102   }
00103 
00104   if ( d->mFetchCount == 0 ) // nothing to fetch, so we can return immediately
00105     emitResult();
00106 }
00107 
00108 KABC::Addressee::List ContactGroupExpandJob::contacts() const
00109 {
00110   return d->mContacts;
00111 }
00112 
00113 #include "contactgroupexpandjob.moc"

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal