akonadi
resourcescheduler_p.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AKONADI_RESOURCESCHEDULER_P_H
00021 #define AKONADI_RESOURCESCHEDULER_P_H
00022
00023 #include <akonadi/agentbase.h>
00024 #include <akonadi/collection.h>
00025 #include <akonadi/item.h>
00026 #include <akonadi/resourcebase.h>
00027
00028 #include <QtCore/QObject>
00029 #include <QtCore/QStringList>
00030 #include <QtDBus/QDBusMessage>
00031
00032 namespace Akonadi {
00033
00034
00035
00043 class ResourceScheduler : public QObject
00044 {
00045 Q_OBJECT
00046
00047 public:
00048 enum TaskType {
00049 Invalid,
00050 SyncAll,
00051 SyncCollectionTree,
00052 SyncCollection,
00053 FetchItem,
00054 ChangeReplay,
00055 DeleteResourceCollection,
00056 SyncAllDone,
00057 Custom
00058 };
00059
00060 class Task {
00061 static qint64 latestSerial;
00062
00063 public:
00064 Task() : serial( ++latestSerial ), type( Invalid ), receiver( 0 ) {}
00065 qint64 serial;
00066 TaskType type;
00067 Collection collection;
00068 Item item;
00069 QSet<QByteArray> itemParts;
00070 QDBusMessage dbusMsg;
00071 QObject *receiver;
00072 QByteArray methodName;
00073 QVariant argument;
00074
00075 bool operator==( const Task &other ) const
00076 {
00077 return type == other.type
00078 && (collection == other.collection || (!collection.isValid() && !other.collection.isValid()))
00079 && (item == other.item || (!item.isValid() && !other.item.isValid()))
00080 && itemParts == other.itemParts
00081 && receiver == other.receiver
00082 && methodName == other.methodName
00083 && argument == other.argument;
00084 }
00085 };
00086
00087 ResourceScheduler( QObject *parent = 0 );
00088
00092 void scheduleFullSync();
00093
00097 void scheduleCollectionTreeSync();
00098
00103 void scheduleSync( const Collection &col );
00104
00111 void scheduleItemFetch( const Item &item, const QSet<QByteArray> &parts, const QDBusMessage &msg );
00112
00117 void scheduleResourceCollectionDeletion();
00118
00122 void scheduleFullSyncCompletion();
00123
00128 void scheduleCustomTask( QObject *receiver, const char *methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = ResourceBase::Append );
00129
00133 bool isEmpty();
00134
00138 Task currentTask() const;
00139
00143 void setOnline( bool state );
00144
00145 public Q_SLOTS:
00149 void scheduleChangeReplay();
00150
00154 void taskDone();
00155
00159 void deferTask();
00160
00164 void collectionRemoved( const Akonadi::Collection &collection );
00165
00166 Q_SIGNALS:
00167 void executeFullSync();
00168 void executeCollectionSync( const Akonadi::Collection &col );
00169 void executeCollectionTreeSync();
00170 void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts );
00171 void executeResourceCollectionDeletion();
00172 void executeChangeReplay();
00173 void fullSyncComplete();
00174 void status( int status, const QString &message = QString() );
00175
00176 private slots:
00177 void scheduleNext();
00178 void executeNext();
00179
00180 private:
00181 void signalTaskToTracker( const Task &task, const QByteArray &taskType );
00182
00183 QList<Task> mTaskList;
00184 Task mCurrentTask;
00185 bool mOnline;
00186 };
00187
00188
00189
00190 }
00191
00192 #endif