akonadi
resourcebase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AKONADI_RESOURCEBASE_H
00024 #define AKONADI_RESOURCEBASE_H
00025
00026 #include "akonadi_export.h"
00027
00028 #include <akonadi/agentbase.h>
00029 #include <akonadi/collection.h>
00030 #include <akonadi/item.h>
00031
00032 class KJob;
00033 class ResourceAdaptor;
00034
00035 namespace Akonadi {
00036
00037 class ResourceBasePrivate;
00038
00140
00141 class AKONADI_EXPORT ResourceBase : public AgentBase
00142 {
00143 Q_OBJECT
00144
00145 public:
00170 template <typename T>
00171 static int init( int argc, char **argv )
00172 {
00173 const QString id = parseArguments( argc, argv );
00174 KApplication app;
00175 T* r = new T( id );
00176
00177
00178
00179 Observer *observer = dynamic_cast<Observer*>( r );
00180 if ( observer != 0 )
00181 r->registerObserver( observer );
00182 return init( r );
00183 }
00184
00188
00189 void setName( const QString &name );
00190
00194 QString name() const;
00195
00196 Q_SIGNALS:
00202 void nameChanged( const QString &name );
00203
00204 protected Q_SLOTS:
00210 virtual void retrieveCollections() = 0;
00211
00225 virtual void retrieveItems( const Akonadi::Collection &collection ) = 0;
00226
00236 virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
00237
00238 protected:
00244 ResourceBase( const QString & id );
00245
00249 ~ResourceBase();
00250
00256 void itemRetrieved( const Item &item );
00257
00265 void changeCommitted( const Item &item );
00266
00276 void changeCommitted( const Collection &collection );
00277
00284 void collectionsRetrieved( const Collection::List &collections );
00285
00293 void collectionsRetrievedIncremental( const Collection::List &changedCollections,
00294 const Collection::List &removedCollections );
00295
00304 void itemsRetrieved( const Item::List &items );
00305
00313 void setTotalItems( int amount );
00314
00320 void setItemStreamingEnabled( bool enable );
00321
00328 void itemsRetrievedIncremental( const Item::List &changedItems,
00329 const Item::List &removedItems );
00330
00340 void itemsRetrievalDone();
00341
00345 Collection currentCollection() const;
00346
00350 Item currentItem() const;
00351
00355 void synchronize();
00356
00361 void synchronizeCollection( qint64 id );
00362
00366 void synchronizeCollectionTree();
00367
00371 void cancelTask();
00372
00377 void cancelTask( const QString &error );
00378
00382 void doSetOnline( bool online );
00383
00384 private:
00385 static QString parseArguments( int, char** );
00386 static int init( ResourceBase *r );
00387
00388
00389 friend class ::ResourceAdaptor;
00390
00391 bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts );
00392
00393 private:
00394 Q_DECLARE_PRIVATE( ResourceBase )
00395
00396 Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) )
00397 Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) )
00398 Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) )
00399 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) )
00400 Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) )
00401 Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) )
00402 Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) )
00403 };
00404
00405 }
00406
00407 #ifndef AKONADI_RESOURCE_MAIN
00408
00411 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
00412 int main( int argc, char **argv ) \
00413 { \
00414 return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
00415 }
00416 #endif
00417
00418 #endif