[Kde-pim] KDE - Counting Number of Address Books

GOO Creations goocreations at gmail.com
Tue Jun 29 11:35:30 BST 2010


The second option you provided works fine, but the first one (the 
recommended one) doesn't.
After I did some debugging, I've noticed that the signal result( KJob* ) 
is never emitted, hence

void MyClass::collectionsFetched( KJob *job )

was never called.

Any idea why?




On 2010/06/29 10:37 AM, Tobias Koenig wrote:
> On Tue, Jun 29, 2010 at 09:56:50AM +0200, GOO Creations wrote:
>
>    
>> Dear KDEPIM Developers
>>      
> Hej Christoph,
>
>    
>>   Akonadi::ChangeRecorder *changeRecorder = new
>>   Akonadi::ChangeRecorder();
>>   changeRecorder->setCollectionMonitored( Akonadi::Collection::root() );
>>   changeRecorder->setMimeTypeMonitored( KABC::Addressee::mimeType() );
>>   changeRecorder->fetchCollection( true );
>>
>>   Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel(
>>   changeRecorder);
>>   model->setItemPopulationStrategy(
>>   Akonadi::EntityTreeModel::NoItemPopulation );
>>
>>   QMessageBox msgBox;
>>   msgBox.setText(QString::number(model->rowCount()));
>>   msgBox.exec();
>>      
> EntityTreeModel uses asynchronous loading of the content, so at the point where
> you ask for the rowCount(), the data might have not been loaded yet.
> If you only want to know the number of collections using the EntityTreeModel is
> overkill. You can use the following code instead:
>
>    using namespace Akonadi;
>    CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive );
>    connect( job, SIGNAL( result( KJob* ) ), SLOT( collectionsFetched( KJob* ) ) );
>
>    ...
>
>    void MyClass::collectionsFetched( KJob *job )
>    {
>      if ( job->error() ) {
>        // error handling
>        return;
>      }
>
>      const CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
>
>      int addressBookCounter = 0;
>      foreach ( const Collection&collection, fetchJob->collections() ) {
>        if ( collection.contentMimeTypes().contains( KABC::Addressee::mimeType() ) ||
>             collection.contentMimeTypes().contains( KABC::ContactGroup::mimeType() ) )
>          addressBookCounter++;
>      }
>    }
>
> alternatively you can use the synchronous way (however that is not recommended):
>
>    CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive );
>    if ( job->exec() ) {
>      int addressBookCounter = 0;
>      foreach ( const Collection&collection, job->collections() ) {
>        if ( collection.contentMimeTypes().contains( KABC::Addressee::mimeType() ) ||
>             collection.contentMimeTypes().contains( KABC::ContactGroup::mimeType() ) )
>          addressBookCounter++;
>      }
>    }
>
> Ciao,
> Tobias
>    
>
>
> _______________________________________________
> KDE PIM mailing list kde-pim at kde.org
> https://mail.kde.org/mailman/listinfo/kde-pim
> KDE PIM home page at http://pim.kde.org/

_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list