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 Akonadi__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 void setName( const QString &name );
00193
00197 QString name() const;
00198
00199 Q_SIGNALS:
00205 void nameChanged( const QString &name );
00206
00210 void synchronized();
00211
00212 protected Q_SLOTS:
00218 virtual void retrieveCollections() = 0;
00219
00233 virtual void retrieveItems( const Akonadi::Collection &collection ) = 0;
00234
00244 virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0;
00245
00246 protected:
00252 ResourceBase( const QString & id );
00253
00257 ~ResourceBase();
00258
00264 void itemRetrieved( const Item &item );
00265
00273 void changeCommitted( const Item &item );
00274
00284 void changeCommitted( const Collection &collection );
00285
00292 void collectionsRetrieved( const Collection::List &collections );
00293
00301 void collectionsRetrievedIncremental( const Collection::List &changedCollections,
00302 const Collection::List &removedCollections );
00303
00311 void setCollectionStreamingEnabled( bool enable );
00312
00321 void collectionsRetrievalDone();
00322
00331 void itemsRetrieved( const Item::List &items );
00332
00340 void setTotalItems( int amount );
00341
00347 void setItemStreamingEnabled( bool enable );
00348
00355 void itemsRetrievedIncremental( const Item::List &changedItems,
00356 const Item::List &removedItems );
00357
00367 void itemsRetrievalDone();
00368
00378 void clearCache();
00379
00383 Collection currentCollection() const;
00384
00388 Item currentItem() const;
00389
00393 void synchronize();
00394
00399 void synchronizeCollection( qint64 id );
00400
00404 void synchronizeCollectionTree();
00405
00409 void cancelTask();
00410
00415 void cancelTask( const QString &error );
00416
00423 void deferTask();
00424
00428 void doSetOnline( bool online );
00429
00440 void setHierarchicalRemoteIdentifiersEnabled( bool enable );
00441
00442 friend class ResourceScheduler;
00443
00451 enum SchedulePriority {
00452 Prepend,
00453 AfterChangeReplay,
00454 Append
00455 };
00456
00472 void scheduleCustomTask( QObject* receiver, const char* method, const QVariant &argument, SchedulePriority priority = Append );
00473
00480 void taskDone();
00481
00482 private:
00483 static QString parseArguments( int, char** );
00484 static int init( ResourceBase *r );
00485
00486
00487 friend class ::Akonadi__ResourceAdaptor;
00488
00489 bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts );
00490
00491 private:
00492 Q_DECLARE_PRIVATE( ResourceBase )
00493
00494 Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) )
00495 Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) )
00496 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollection() )
00497 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollectionDone( KJob* ) )
00498 Q_PRIVATE_SLOT( d_func(), void slotCollectionDeletionDone( KJob* ) )
00499 Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) )
00500 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) )
00501 Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) )
00502 Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) )
00503 Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) )
00504 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrieval( const Akonadi::Item& item ) )
00505 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrievalResult( KJob* ) )
00506 Q_PRIVATE_SLOT( d_func(), void changeCommittedResult( KJob* ) )
00507 };
00508
00509 }
00510
00511 #ifndef AKONADI_RESOURCE_MAIN
00512
00515 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
00516 int main( int argc, char **argv ) \
00517 { \
00518 return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
00519 }
00520 #endif
00521
00522 #endif