This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Counting number of address books

Tags: None
(comma "," separated)
goocreations
Registered Member
Posts
2
Karma
0
OS

Counting number of address books

Mon Jun 28, 2010 9:55 pm
I want to get the number of address books a user has.
The following code returns 0 (even with more than 0 address books):

Code: Select all
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();


Does anyone have an clue what I'm doing wrong, or is the another/easier way of getting the number of address books?

Thanks for any suggestions.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
If you do not get a reply here, I would recommend asking on the KDE PIM development mailing list: kde-pim@kde.org


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
goocreations
Registered Member
Posts
2
Karma
0
OS
thank you
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS
For those not reading the mailing list:

Code: Select all
  using namespace Akonadi;
  CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive );
  job->fetchScope().setContentMimeTypes( QStringList() << Addressee::mimeType() );

  connect( job, SIGNAL( result( KJob* ) ), SLOT( collectionsFetched( KJob* ) ) );


and the result slot like this
Code: Select all
  void MyClass::collectionsFetched( KJob *job )
  {
    if ( job->error() ) {
      // error handling
      return;
    }

    const CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );

    const addressBookCount = fetchJob->collections().count();
  }


Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]