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
00143
00144 class AKONADI_EXPORT ResourceBase : public AgentBase
00145 {
00146 Q_OBJECT
00147
00148 public:
00173 template <typename T>
00174 static int init( int argc, char **argv )
00175 {
00176 const QString id = parseArguments( argc, argv );
00177 KApplication app;
00178 T* r = new T( id );
00179
00180
00181
00182 Observer *observer = dynamic_cast<Observer*>( r );
00183 if ( observer != 0 )
00184 r->registerObserver( observer );
00185 return init( r );
00186 }
00187
00191
00192 void setName( const QString &name );
00193
00197 QString name() const;
00198
00199 Q_SIGNALS:
00205 void nameChanged( const QString &name );
00206
00207 protected Q_SLOTS:
00213 virtual void retrieveCollections() = 0;
00214
00228 virtual void retrieveItems( const Akonadi::Collection &collection ) = 0;
00229
00239 virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
00240
00241 protected:
00247 ResourceBase( const QString & id );
00248
00252 ~ResourceBase();
00253
00259 void itemRetrieved( const Item &item );
00260
00268 void changeCommitted( const Item &item );
00269
00279 void changeCommitted( const Collection &collection );
00280
00287 void collectionsRetrieved( const Collection::List &collections );
00288
00296 void collectionsRetrievedIncremental( const Collection::List &changedCollections,
00297 const Collection::List &removedCollections );
00298
00307 void itemsRetrieved( const Item::List &items );
00308
00316 void setTotalItems( int amount );
00317
00323 void setItemStreamingEnabled( bool enable );
00324
00331 void itemsRetrievedIncremental( const Item::List &changedItems,
00332 const Item::List &removedItems );
00333
00343 void itemsRetrievalDone();
00344
00354 void clearCache();
00355
00359 Collection currentCollection() const;
00360
00364 Item currentItem() const;
00365
00369 void synchronize();
00370
00375 void synchronizeCollection( qint64 id );
00376
00380 void synchronizeCollectionTree();
00381
00385 void cancelTask();
00386
00391 void cancelTask( const QString &error );
00392
00396 void doSetOnline( bool online );
00397
00398 private:
00399 static QString parseArguments( int, char** );
00400 static int init( ResourceBase *r );
00401
00402
00403 friend class ::ResourceAdaptor;
00404
00405 bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts );
00406
00407 private:
00408 Q_DECLARE_PRIVATE( ResourceBase )
00409
00410 Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) )
00411 Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) )
00412 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollection() )
00413 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollectionDone( KJob* ) )
00414 Q_PRIVATE_SLOT( d_func(), void slotCollectionDeletionDone( KJob* ) )
00415 Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) )
00416 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) )
00417 Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) )
00418 Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) )
00419 Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) )
00420 };
00421
00422 }
00423
00424 #ifndef AKONADI_RESOURCE_MAIN
00425
00428 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
00429 int main( int argc, char **argv ) \
00430 { \
00431 return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
00432 }
00433 #endif
00434
00435 #endif