Akonadi

resourcebase.h
1 /*
2  This file is part of akonadiresources.
3 
4  SPDX-FileCopyrightText: 2006 Till Adam <[email protected]>
5  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef AKONADI_RESOURCEBASE_H
11 #define AKONADI_RESOURCEBASE_H
12 
13 #include "akonadiagentbase_export.h"
14 #include "agentbase.h"
15 #include "collection.h"
16 #include "item.h"
17 #include "itemsync.h"
18 
19 class KJob;
20 class Akonadi__ResourceAdaptor;
21 class ResourceState;
22 
23 namespace Akonadi
24 {
25 
26 class ResourceBasePrivate;
27 
134 // FIXME_API: API dox need to be updated for Observer approach (kevin)
135 class AKONADIAGENTBASE_EXPORT ResourceBase : public AgentBase
136 {
137  Q_OBJECT
138 
139 public:
167  template <typename T>
168  static int init(int argc, char **argv)
169  {
170 
171  // Disable session management
172  qunsetenv("SESSION_MANAGER");
173 
174  QApplication app(argc, argv);
175  debugAgent(argc, argv);
176  const QString id = parseArguments(argc, argv);
177  T r(id);
178 
179  // check if T also inherits AgentBase::Observer and
180  // if it does, automatically register it on itself
181  Observer *observer = dynamic_cast<Observer *>(&r);
182  if (observer != nullptr) {
183  r.registerObserver(observer);
184  }
185 
186  return init(r);
187  }
188 
192  void setName(const QString &name);
193 
197  Q_REQUIRED_RESULT QString name() const;
198 
211  void setAutomaticProgressReporting(bool enabled);
212 
213 Q_SIGNALS:
219  void nameChanged(const QString &name);
220 
224  void synchronized();
225 
232  void attributesSynchronized(qlonglong collectionId);
233 
239  void collectionTreeSynchronized();
240 
256  void retrieveNextItemSyncBatch(int remainingBatchSize);
257 
258 protected Q_SLOTS:
264  virtual void retrieveCollections() = 0;
265 
270  virtual void retrieveTags();
271 
276  virtual void retrieveRelations();
277 
288  virtual void retrieveCollectionAttributes(const Akonadi::Collection &collection);
289 
303  virtual void retrieveItems(const Akonadi::Collection &collection) = 0;
304 
313  int itemSyncBatchSize() const;
314 
322  void setItemSyncBatchSize(int batchSize);
323 
330  void setScheduleAttributeSyncBeforeItemSync(bool);
331 
342  AKONADIAGENTBASE_DEPRECATED virtual bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts);
343 
359  virtual bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts);
360 
366  virtual void abortActivity();
367 
373  {
374  return QString();
375  }
376 
377 protected:
383  ResourceBase(const QString &id);
384 
388  ~ResourceBase() override;
389 
395  void itemRetrieved(const Item &item);
396 
403  void collectionAttributesRetrieved(const Collection &collection);
404 
412  void changeCommitted(const Item &item);
413 
423  void changesCommitted(const Item::List &items);
424 
434  void changeCommitted(const Tag &tag);
435 
445  void changeCommitted(const Collection &collection);
446 
453  void collectionsRetrieved(const Collection::List &collections);
454 
455  void tagsRetrieved(const Tag::List &tags, const QHash<QString, Item::List> &tagMembers);
456  void relationsRetrieved(const Relation::List &relations);
457 
465  void collectionsRetrievedIncremental(const Collection::List &changedCollections,
466  const Collection::List &removedCollections);
467 
475  void setCollectionStreamingEnabled(bool enable);
476 
485  void collectionsRetrievalDone();
486 
500  void setKeepLocalCollectionChanges(const QSet<QByteArray> &parts);
501 
511  void itemsRetrieved(const Item::List &items);
512 
538  void setTotalItems(int amount);
539 
553  void setDisableAutomaticItemDeliveryDone(bool disable);
554 
563  void setItemStreamingEnabled(bool enable);
564 
571  void setItemTransactionMode(ItemSync::TransactionMode mode);
572 
585  void setItemMergingMode(ItemSync::MergeMode mode);
586 
598  void setItemSynchronizationFetchScope(const ItemFetchScope &fetchScope);
599 
606  void itemsRetrievedIncremental(const Item::List &changedItems,
607  const Item::List &removedItems);
608 
618  void itemsRetrievalDone();
619 
629  void clearCache();
630 
640  void invalidateCache(const Collection &collection);
641 
647  Collection currentCollection() const;
648 
654  AKONADIAGENTBASE_DEPRECATED Item currentItem() const;
655 
661  Item::List currentItems() const;
662 
666  void synchronize();
667 
672  void synchronizeCollection(qint64 id);
673 
679  void synchronizeCollection(qint64 id, bool recursive);
680 
688  void synchronizeCollectionAttributes(qint64 id);
689 
696  void synchronizeCollectionAttributes(const Akonadi::Collection &col);
697 
701  void synchronizeCollectionTree();
702 
706  void synchronizeTags();
707 
711  void synchronizeRelations();
712 
716  void cancelTask();
717 
723  void cancelTask(const QString &error);
724 
736  void deferTask();
737 
744  void doSetOnline(bool online) override;
745 
757  void setHierarchicalRemoteIdentifiersEnabled(bool enable);
758 
759  friend class ResourceScheduler;
760  friend class ::ResourceState;
761 
772  Append
773  };
774 
790  void scheduleCustomTask(QObject *receiver, const char *method, const QVariant &argument, SchedulePriority priority = Append);
791 
798  void taskDone();
799 
804  QString dumpNotificationListToString() const;
805 
814  void dumpMemoryInfo() const;
815 
822  QString dumpMemoryInfoToString() const;
823 
828  QString dumpSchedulerToString() const;
829 
830 private:
831  static QString parseArguments(int argc, char **argv);
832  static int init(ResourceBase &r);
833 
834  // dbus resource interface
835  friend class ::Akonadi__ResourceAdaptor;
836 
837  void requestItemDelivery(const QVector<qint64> &uids, const QByteArrayList &parts);
838 
839 private:
840  Q_DECLARE_PRIVATE(ResourceBase)
841 
842  Q_PRIVATE_SLOT(d_func(), void slotAbortRequested())
843  Q_PRIVATE_SLOT(d_func(), void slotDeliveryDone(KJob *))
844  Q_PRIVATE_SLOT(d_func(), void slotCollectionSyncDone(KJob *))
845  Q_PRIVATE_SLOT(d_func(), void slotDeleteResourceCollection())
846  Q_PRIVATE_SLOT(d_func(), void slotDeleteResourceCollectionDone(KJob *))
847  Q_PRIVATE_SLOT(d_func(), void slotCollectionDeletionDone(KJob *))
848  Q_PRIVATE_SLOT(d_func(), void slotInvalidateCache(const Akonadi::Collection &))
849  Q_PRIVATE_SLOT(d_func(), void slotLocalListDone(KJob *))
850  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeCollection(const Akonadi::Collection &))
851  Q_PRIVATE_SLOT(d_func(), void slotCollectionListDone(KJob *))
852  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeCollectionAttributes(const Akonadi::Collection &))
853  Q_PRIVATE_SLOT(d_func(), void slotCollectionListForAttributesDone(KJob *))
854  Q_PRIVATE_SLOT(d_func(), void slotCollectionAttributesSyncDone(KJob *))
855  Q_PRIVATE_SLOT(d_func(), void slotItemSyncDone(KJob *))
856  Q_PRIVATE_SLOT(d_func(), void slotPercent(KJob *, quint64))
857  Q_PRIVATE_SLOT(d_func(), void slotDelayedEmitProgress())
858  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemRetrieval(const Akonadi::Item &items))
859  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemRetrievalResult(KJob *))
860  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemsRetrieval(const QVector<Akonadi::Item> &items))
861  Q_PRIVATE_SLOT(d_func(), void slotPrepareItemsRetrievalResult(KJob *))
862  Q_PRIVATE_SLOT(d_func(), void changeCommittedResult(KJob *))
863  Q_PRIVATE_SLOT(d_func(), void slotSessionReconnected())
864  Q_PRIVATE_SLOT(d_func(), void slotRecursiveMoveReplay(RecursiveMover *))
865  Q_PRIVATE_SLOT(d_func(), void slotRecursiveMoveReplayResult(KJob *))
866  Q_PRIVATE_SLOT(d_func(), void slotTagSyncDone(KJob *))
867  Q_PRIVATE_SLOT(d_func(), void slotRelationSyncDone(KJob *job))
868  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeTags())
869  Q_PRIVATE_SLOT(d_func(), void slotSynchronizeRelations())
870  Q_PRIVATE_SLOT(d_func(), void slotItemRetrievalCollectionFetchDone(KJob *))
871  Q_PRIVATE_SLOT(d_func(), void slotAttributeRetrievalCollectionFetchDone(KJob *))
872 };
873 
874 }
875 
876 #ifndef AKONADI_RESOURCE_MAIN
877 
880 #define AKONADI_RESOURCE_MAIN( resourceClass ) \
881  int main( int argc, char **argv ) \
882  { \
883  return Akonadi::ResourceBase::init<resourceClass>( argc, argv ); \
884  }
885 #endif
886 
887 #endif
virtual QString dumpResourceToString() const
Dump resource internals, for debugging.
Definition: resourcebase.h:372
Represents a collection of PIM items.
Definition: collection.h:63
The interface for reacting on monitored or replayed changes.
Definition: agentbase.h:177
The base class for all Akonadi agents and resources.
Definition: agentbase.h:71
SchedulePriority
Describes the scheduling priority of a task that has been queued for execution.
Definition: resourcebase.h:769
The task is scheduled after the last ChangeReplay task in the queue.
Definition: resourcebase.h:771
Specifies which parts of an item should be fetched from the Akonadi storage.
QCA_EXPORT void init()
TransactionMode
Transaction mode used by ItemSync.
Definition: itemsync.h:156
Helper integration between Akonadi and Qt.
An Akonadi Tag.
Definition: tag.h:26
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:168
The task will be executed as soon as the current task has finished.
Definition: resourcebase.h:770
The base class for all Akonadi resources.
Definition: resourcebase.h:135
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 23:15:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.