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
00186 return init( r );
00187 }
00188
00192
00193 void setName( const QString &name );
00194
00198 QString name() const;
00199
00200 Q_SIGNALS:
00206 void nameChanged( const QString &name );
00207
00211 void synchronized();
00212
00213 protected Q_SLOTS:
00219 virtual void retrieveCollections() = 0;
00220
00234 virtual void retrieveItems( const Akonadi::Collection &collection ) = 0;
00235
00245 virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
00246
00247 protected:
00253 ResourceBase( const QString & id );
00254
00258 ~ResourceBase();
00259
00265 void itemRetrieved( const Item &item );
00266
00274 void changeCommitted( const Item &item );
00275
00285 void changeCommitted( const Collection &collection );
00286
00293 void collectionsRetrieved( const Collection::List &collections );
00294
00302 void collectionsRetrievedIncremental( const Collection::List &changedCollections,
00303 const Collection::List &removedCollections );
00304
00312 void setCollectionStreamingEnabled( bool enable );
00313
00322 void collectionsRetrievalDone();
00323
00332 void itemsRetrieved( const Item::List &items );
00333
00341 void setTotalItems( int amount );
00342
00348 void setItemStreamingEnabled( bool enable );
00349
00356 void itemsRetrievedIncremental( const Item::List &changedItems,
00357 const Item::List &removedItems );
00358
00368 void itemsRetrievalDone();
00369
00379 void clearCache();
00380
00384 Collection currentCollection() const;
00385
00389 Item currentItem() const;
00390
00394 void synchronize();
00395
00400 void synchronizeCollection( qint64 id );
00401
00405 void synchronizeCollectionTree();
00406
00410 void cancelTask();
00411
00416 void cancelTask( const QString &error );
00417
00424 void deferTask();
00425
00429 void doSetOnline( bool online );
00430
00441 void setHierarchicalRemoteIdentifiersEnabled( bool enable );
00442
00443 friend class ResourceScheduler;
00444
00452 enum SchedulePriority {
00453 Prepend,
00454 AfterChangeReplay,
00455 Append
00456 };
00457
00473 void scheduleCustomTask( QObject* receiver, const char* method, const QVariant &argument, SchedulePriority priority = Append );
00474
00481 void taskDone();
00482
00483 private:
00484 static QString parseArguments( int, char** );
00485 static int init( ResourceBase *r );
00486
00487
00488 friend class ::ResourceAdaptor;
00489
00490 bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts );
00491
00492 private:
00493 Q_DECLARE_PRIVATE( ResourceBase )
00494
00495 Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) )
00496 Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) )
00497 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollection() )
00498 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollectionDone( KJob* ) )
00499 Q_PRIVATE_SLOT( d_func(), void slotCollectionDeletionDone( KJob* ) )
00500 Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) )
00501 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) )
00502 Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) )
00503 Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) )
00504 Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) )
00505 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrieval( const Akonadi::Item& item ) )
00506 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrievalResult( KJob* ) )
00507 Q_PRIVATE_SLOT( d_func(), void changeCommittedResult( KJob* ) )
00508 };
00509
00510 }
00511
00512 #ifndef AKONADI_RESOURCE_MAIN
00513
00516 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
00517 int main( int argc, char **argv ) \
00518 { \
00519 return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
00520 }
00521 #endif
00522
00523 #endif