Akonadi

resourcebase.h
1 /*
2  This file is part of akonadiresources.
3 
4  Copyright (c) 2006 Till Adam <[email protected]>
5  Copyright (c) 2007 Volker Krause <[email protected]>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #ifndef AKONADI_RESOURCEBASE_H
24 #define AKONADI_RESOURCEBASE_H
25 
26 #include "akonadiagentbase_export.h"
27 #include "agentbase.h"
28 #include "collection.h"
29 #include "item.h"
30 #include "itemsync.h"
31 
32 class KJob;
33 class Akonadi__ResourceAdaptor;
34 class ResourceState;
35 
36 namespace Akonadi
37 {
38 
39 class ResourceBasePrivate;
40 
147 // FIXME_API: API dox need to be updated for Observer approach (kevin)
148 class AKONADIAGENTBASE_EXPORT ResourceBase : public AgentBase
149 {
150  Q_OBJECT
151 
152 public:
180  template <typename T>
181  static int init(int argc, char **argv)
182  {
183 
184  // Disable session management
185  qunsetenv("SESSION_MANAGER");
186 
187  QApplication app(argc, argv);
188  debugAgent(argc, argv);
189  const QString id = parseArguments(argc, argv);
190  T r(id);
191 
192  // check if T also inherits AgentBase::Observer and
193  // if it does, automatically register it on itself
194  Observer *observer = dynamic_cast<Observer *>(&r);
195  if (observer != nullptr) {
196  r.registerObserver(observer);
197  }
198 
199  return init(r);
200  }
201 
205  void setName(const QString &name);
206 
210  Q_REQUIRED_RESULT QString name() const;
211 
224  void setAutomaticProgressReporting(bool enabled);
225 
226 Q_SIGNALS:
232  void nameChanged(const QString &name);
233 
237  void synchronized();
238 
245  void attributesSynchronized(qlonglong collectionId);
246 
252  void collectionTreeSynchronized();
253 
269  void retrieveNextItemSyncBatch(int remainingBatchSize);
270 
271 protected Q_SLOTS:
277  virtual void retrieveCollections() = 0;
278 
283  virtual void retrieveTags();
284 
289  virtual void retrieveRelations();
290 
301  virtual void retrieveCollectionAttributes(const Akonadi::Collection &collection);
302 
316  virtual void retrieveItems(const Akonadi::Collection &collection) = 0;
317 
326  int itemSyncBatchSize() const;
327 
335  void setItemSyncBatchSize(int batchSize);
336 
343  void setScheduleAttributeSyncBeforeItemSync(bool);
344 
355  AKONADIAGENTBASE_DEPRECATED virtual bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts);
356 
372  virtual bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts);
373 
379  virtual void abortActivity();
380 
386  {
387  return QString();
388  }
389 
390 protected:
396  ResourceBase(const QString &id);
397 
401  ~ResourceBase() override;
402 
408  void itemRetrieved(const Item &item);
409 
416  void collectionAttributesRetrieved(const Collection &collection);
417 
425  void changeCommitted(const Item &item);
426 
436  void changesCommitted(const Item::List &items);
437 
447  void changeCommitted(const Tag &tag);
448 
458  void changeCommitted(const Collection &collection);
459 
466  void collectionsRetrieved(const Collection::List &collections);
467 
468  void tagsRetrieved(const Tag::List &tags, const QHash<QString, Item::List> &tagMembers);
469  void relationsRetrieved(const Relation::List &relations);
470 
478  void collectionsRetrievedIncremental(const Collection::List &changedCollections,
479  const Collection::List &removedCollections);
480 
488  void setCollectionStreamingEnabled(bool enable);
489 
498  void collectionsRetrievalDone();
499 
513  void setKeepLocalCollectionChanges(const QSet<QByteArray> &parts);
514 
524  void itemsRetrieved(const Item::List &items);
525 
551  void setTotalItems(int amount);
552 
566  void setDisableAutomaticItemDeliveryDone(bool disable);
567 
576  void setItemStreamingEnabled(bool enable);
577 
584  void setItemTransactionMode(ItemSync::TransactionMode mode);
585 
598  void setItemMergingMode(ItemSync::MergeMode mode);
599 
611  void setItemSynchronizationFetchScope(const ItemFetchScope &fetchScope);
612 
619  void itemsRetrievedIncremental(const Item::List &changedItems,
620  const Item::List &removedItems);
621 
631  void itemsRetrievalDone();
632 
642  void clearCache();
643 
653  void invalidateCache(const Collection &collection);
654 
660  Collection currentCollection() const;
661 
667  AKONADIAGENTBASE_DEPRECATED Item currentItem() const;
668 
674  Item::List currentItems() const;
675 
679  void synchronize();
680 
685  void synchronizeCollection(qint64 id);
686 
692  void synchronizeCollection(qint64 id, bool recursive);
693 
701  void synchronizeCollectionAttributes(qint64 id);
702 
709  void synchronizeCollectionAttributes(const Akonadi::Collection &col);
710 
714  void synchronizeCollectionTree();
715 
719  void synchronizeTags();
720 
724  void synchronizeRelations();
725 
729  void cancelTask();
730 
736  void cancelTask(const QString &error);
737 
749  void deferTask();
750 
757  void doSetOnline(bool online) override;
758 
770  void setHierarchicalRemoteIdentifiersEnabled(bool enable);
771 
772  friend class ResourceScheduler;
773  friend class ::ResourceState;
774 
785  Append
786  };
787 
803  void scheduleCustomTask(QObject *receiver, const char *method, const QVariant &argument, SchedulePriority priority = Append);
804 
811  void taskDone();
812 
817  QString dumpNotificationListToString() const;
818 
827  void dumpMemoryInfo() const;
828 
835  QString dumpMemoryInfoToString() const;
836 
841  QString dumpSchedulerToString() const;
842 
843 private:
844  static QString parseArguments(int argc, char **argv);
845  static int init(ResourceBase &r);
846 
847  // dbus resource interface
848  friend class ::Akonadi__ResourceAdaptor;
849 
850  void requestItemDelivery(const QVector<qint64> &uids, const QByteArrayList &parts);
851 
852 private:
853  Q_DECLARE_PRIVATE(ResourceBase)
854 
855  Q_PRIVATE_SLOT(d_func(), void slotAbortRequested())
856  Q_PRIVATE_SLOT(d_func(), void slotDeliveryDone(KJob *))
857  Q_PRIVATE_SLOT(d_func(), void slotCollectionSyncDone(KJob *))
858  Q_PRIVATE_SLOT(d_func(), void slotDeleteResourceCollection())
859  Q_PRIVATE_SLOT(d_func(), void slotDeleteResourceCollectionDone(KJob *))
860  Q_PRIVATE_SLOT(d_func(), void slotCollectionDeletionDone(KJob *))
861  Q_PRIVATE_SLOT(d_func(), void slotInvalidateCache(const Akonadi::Collection &))
862  Q_PRIVATE_SLOT(d_func(), void slotLocalListDone(KJob *))
863  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeCollection(const Akonadi::Collection &))
864  Q_PRIVATE_SLOT(d_func(), void slotCollectionListDone(KJob *))
865  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeCollectionAttributes(const Akonadi::Collection &))
866  Q_PRIVATE_SLOT(d_func(), void slotCollectionListForAttributesDone(KJob *))
867  Q_PRIVATE_SLOT(d_func(), void slotCollectionAttributesSyncDone(KJob *))
868  Q_PRIVATE_SLOT(d_func(), void slotItemSyncDone(KJob *))
869  Q_PRIVATE_SLOT(d_func(), void slotPercent(KJob *, unsigned long))
870  Q_PRIVATE_SLOT(d_func(), void slotDelayedEmitProgress())
871  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemRetrieval(const Akonadi::Item &items))
872  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemRetrievalResult(KJob *))
873  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemsRetrieval(const QVector<Akonadi::Item> &items))
874  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemsRetrievalResult(KJob *))
875  Q_PRIVATE_SLOT(d_func(), void changeCommittedResult(KJob *))
876  Q_PRIVATE_SLOT(d_func(), void slotSessionReconnected())
877  Q_PRIVATE_SLOT(d_func(), void slotRecursiveMoveReplay(RecursiveMover *))
878  Q_PRIVATE_SLOT(d_func(), void slotRecursiveMoveReplayResult(KJob *))
879  Q_PRIVATE_SLOT(d_func(), void slotTagSyncDone(KJob *))
880  Q_PRIVATE_SLOT(d_func(), void slotRelationSyncDone(KJob *job))
881  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeTags())
882  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeRelations())
883  Q_PRIVATE_SLOT(d_func(), void slotItemRetrievalCollectionFetchDone(KJob *))
884  Q_PRIVATE_SLOT(d_func(), void slotAttributeRetrievalCollectionFetchDone(KJob *))
885 };
886 
887 }
888 
889 #ifndef AKONADI_RESOURCE_MAIN
890 
893 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
894  int main( int argc, char **argv ) \
895  { \
896  return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
897  }
898 #endif
899 
900 #endif
virtual QString dumpResourceToString() const
Dump resource internals, for debugging.
Definition: resourcebase.h:385
Represents a collection of PIM items.
Definition: collection.h:76
The interface for reacting on monitored or replayed changes.
Definition: agentbase.h:190
The base class for all Akonadi agents and resources.
Definition: agentbase.h:84
SchedulePriority
Describes the scheduling priority of a task that has been queued for execution.
Definition: resourcebase.h:782
The task is scheduled after the last ChangeReplay task in the queue.
Definition: resourcebase.h:784
Specifies which parts of an item should be fetched from the Akonadi storage.
TransactionMode
Transaction mode used by ItemSync.
Definition: itemsync.h:169
Helper integration between Akonadi and Qt.
An Akonadi Tag.
Definition: tag.h:39
static int init(int argc, char **argv)
Use this method in the main function of your resource application to initialize your resource subclas...
Definition: resourcebase.h:181
The task will be executed as soon as the current task has finished.
Definition: resourcebase.h:783
The base class for all Akonadi resources.
Definition: resourcebase.h:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:46:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.