akonadi
resourcebase.h
00001 /* 00002 This file is part of akonadiresources. 00003 00004 Copyright (c) 2006 Till Adam <adam@kde.org> 00005 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00006 00007 This library is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU Library General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or (at your 00010 option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to the 00019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 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 #include <akonadi/itemsync.h> 00032 00033 class KJob; 00034 class Akonadi__ResourceAdaptor; 00035 00036 namespace Akonadi { 00037 00038 class ResourceBasePrivate; 00039 00145 // FIXME_API: API dox need to be updated for Observer approach (kevin) 00146 class AKONADI_EXPORT ResourceBase : public AgentBase 00147 { 00148 Q_OBJECT 00149 00150 public: 00175 template <typename T> 00176 static int init( int argc, char **argv ) 00177 { 00178 const QString id = parseArguments( argc, argv ); 00179 KApplication app; 00180 T* r = new T( id ); 00181 00182 // check if T also inherits AgentBase::Observer and 00183 // if it does, automatically register it on itself 00184 Observer *observer = dynamic_cast<Observer*>( r ); 00185 if ( observer != 0 ) 00186 r->registerObserver( observer ); 00187 00188 return init( r ); 00189 } 00190 00194 void setName( const QString &name ); 00195 00199 QString name() const; 00200 00201 Q_SIGNALS: 00207 void nameChanged( const QString &name ); 00208 00212 void synchronized(); 00213 00220 void attributesSynchronized( qlonglong collectionId ); 00221 00222 protected Q_SLOTS: 00228 virtual void retrieveCollections() = 0; 00229 00240 // KDE5: Make it pure virtual, for now can be called only by invokeMethod() 00241 // in order to simulate polymorphism 00242 void retrieveCollectionAttributes( const Akonadi::Collection &collection ); 00243 00257 virtual void retrieveItems( const Akonadi::Collection &collection ) = 0; 00258 00268 virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts ) = 0; 00269 00275 // KDE5: Make it pure virtual, for now can be called only by invokeMethod() 00276 // in order to simulate polymorphism 00277 void abortActivity(); 00278 00279 protected: 00285 ResourceBase( const QString & id ); 00286 00290 ~ResourceBase(); 00291 00297 void itemRetrieved( const Item &item ); 00298 00305 void collectionAttributesRetrieved( const Collection &collection ); 00306 00314 void changeCommitted( const Item &item ); 00315 00325 void changeCommitted( const Collection &collection ); 00326 00333 void collectionsRetrieved( const Collection::List &collections ); 00334 00342 void collectionsRetrievedIncremental( const Collection::List &changedCollections, 00343 const Collection::List &removedCollections ); 00344 00352 void setCollectionStreamingEnabled( bool enable ); 00353 00362 void collectionsRetrievalDone(); 00363 00372 void itemsRetrieved( const Item::List &items ); 00373 00381 void setTotalItems( int amount ); 00382 00388 void setItemStreamingEnabled( bool enable ); 00389 00395 void setItemTransactionMode( ItemSync::TransactionMode mode ); 00396 00408 void setItemSynchronizationFetchScope( const ItemFetchScope &fetchScope ); 00409 00416 void itemsRetrievedIncremental( const Item::List &changedItems, 00417 const Item::List &removedItems ); 00418 00428 void itemsRetrievalDone(); 00429 00439 void clearCache(); 00440 00444 Collection currentCollection() const; 00445 00449 Item currentItem() const; 00450 00454 void synchronize(); 00455 00460 void synchronizeCollection( qint64 id ); 00461 00467 void synchronizeCollection( qint64 id, bool recursive ); 00468 00476 void synchronizeCollectionAttributes( qint64 id ); 00477 00481 void synchronizeCollectionTree(); 00482 00486 void cancelTask(); 00487 00492 void cancelTask( const QString &error ); 00493 00506 void deferTask(); 00507 00511 void doSetOnline( bool online ); 00512 00523 void setHierarchicalRemoteIdentifiersEnabled( bool enable ); 00524 00525 friend class ResourceScheduler; 00526 friend class ResourceState; 00527 00535 enum SchedulePriority { 00536 Prepend, 00537 AfterChangeReplay, 00538 Append 00539 }; 00540 00556 void scheduleCustomTask( QObject* receiver, const char* method, const QVariant &argument, SchedulePriority priority = Append ); 00557 00564 void taskDone(); 00565 00566 private: 00567 static QString parseArguments( int, char** ); 00568 static int init( ResourceBase *r ); 00569 00570 // dbus resource interface 00571 friend class ::Akonadi__ResourceAdaptor; 00572 00573 bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts ); 00574 00575 private: 00576 Q_DECLARE_PRIVATE( ResourceBase ) 00577 00578 Q_PRIVATE_SLOT( d_func(), void slotAbortRequested() ) 00579 Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) ) 00580 Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) ) 00581 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollection() ) 00582 Q_PRIVATE_SLOT( d_func(), void slotDeleteResourceCollectionDone( KJob* ) ) 00583 Q_PRIVATE_SLOT( d_func(), void slotCollectionDeletionDone( KJob* ) ) 00584 Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) ) 00585 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) ) 00586 Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) ) 00587 Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollectionAttributes( const Akonadi::Collection& ) ) 00588 Q_PRIVATE_SLOT( d_func(), void slotCollectionListForAttributesDone( KJob* ) ) 00589 Q_PRIVATE_SLOT( d_func(), void slotCollectionAttributesSyncDone( KJob* ) ) 00590 Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) ) 00591 Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) ) 00592 Q_PRIVATE_SLOT( d_func(), void slotDelayedEmitProgress() ) 00593 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrieval( const Akonadi::Item& item ) ) 00594 Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrievalResult( KJob* ) ) 00595 Q_PRIVATE_SLOT( d_func(), void changeCommittedResult( KJob* ) ) 00596 Q_PRIVATE_SLOT( d_func(), void slotSessionReconnected() ) 00597 }; 00598 00599 } 00600 00601 #ifndef AKONADI_RESOURCE_MAIN 00602 00605 #define AKONADI_RESOURCE_MAIN( resourceClass ) \ 00606 int main( int argc, char **argv ) \ 00607 { \ 00608 return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \ 00609 } 00610 #endif 00611 00612 #endif