akonadi/clients
listcommand.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "listcommand.h"
00023
00024 #include "out.h"
00025
00026 #include <akonadi/collectionfetchjob.h>
00027 #include <akonadi/private/collectionpathresolver_p.h>
00028 #include <akonadi/itemfetchjob.h>
00029
00030 using namespace Akonadi;
00031
00032 ListCommand::ListCommand( const QString &path )
00033 : mPath( path )
00034 {
00035 if ( mPath.isEmpty() ) mPath = "/";
00036 }
00037
00038 void ListCommand::exec()
00039 {
00040 CollectionPathResolver *resolver = new CollectionPathResolver( mPath );
00041 if ( !resolver->exec() ) {
00042 err() << "Error resolving path '" << mPath << "': " << resolver->errorString() << endl;
00043 return;
00044 }
00045 Collection::Id currentColId = resolver->collection();
00046
00047 CollectionFetchJob* collectionJob = new CollectionFetchJob( Collection( currentColId ) );
00048 if ( !collectionJob->exec() ) {
00049 err() << "Error listing collection '" << mPath << "': "
00050 << collectionJob->errorString()
00051 << endl;
00052 return;
00053 } else {
00054 foreach( const Akonadi::Collection &collection, collectionJob->collections() ) {
00055 out() << collection.name() << endl;
00056 }
00057 }
00058
00059 ItemFetchJob* itemFetchJob = new ItemFetchJob( Collection( currentColId ) );
00060 if ( !itemFetchJob->exec() ) {
00061 err() << "Error listing items at '" << mPath << "': "
00062 << itemFetchJob->errorString()
00063 << endl;
00064 } else {
00065 foreach( const Akonadi::Item &item, itemFetchJob->items() ) {
00066 QString str;
00067 str = QLatin1String("Item: ") + QString::number( item.id() );
00068 if ( !item.remoteId().isEmpty() ) {
00069 str += QLatin1String(" [") + item.remoteId() + QLatin1Char(']');
00070 }
00071 if ( !item.flags().isEmpty() ) {
00072 str += QLatin1String(" ( ");
00073 foreach( const QByteArray &flag, item.flags() ) {
00074 str += flag + QLatin1Char(' ');
00075 }
00076 str += QLatin1Char(')');
00077 }
00078 str += QLatin1String(" [") + item.mimeType() + QLatin1Char(']');
00079 out() << str << endl;
00080 }
00081 }
00082 }