Akonadi

agentbase.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  SPDX-FileCopyrightText: 2008 Kevin Krammer <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 
11 #ifndef AKONADI_AGENTBASE_H
12 #define AKONADI_AGENTBASE_H
13 
14 #include "akonadiagentbase_export.h"
15 #include "item.h"
16 
17 #include <QApplication>
18 
19 #include <KSharedConfig>
20 
21 #include <QDBusConnection>
22 #include <QDBusContext>
23 
24 class Akonadi__ControlAdaptor;
25 class Akonadi__StatusAdaptor;
26 
27 class KAboutData;
28 
29 namespace Akonadi
30 {
31 
32 class AgentBasePrivate;
33 class ChangeRecorder;
34 class Collection;
35 class Item;
36 
71 class AKONADIAGENTBASE_EXPORT AgentBase : public QObject, protected QDBusContext
72 {
73  Q_OBJECT
74 
75 public:
177  class AKONADIAGENTBASE_DEPRECATED AKONADIAGENTBASE_EXPORT Observer // krazy:exclude=dpointer
178  {
179  public:
183  Observer();
184 
188  virtual ~Observer();
189 
195  virtual void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection);
196 
202  virtual void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers);
203 
208  virtual void itemRemoved(const Akonadi::Item &item);
209 
215  virtual void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent);
216 
221  virtual void collectionChanged(const Akonadi::Collection &collection);
222 
227  virtual void collectionRemoved(const Akonadi::Collection &collection);
228  };
229 
236  class AKONADIAGENTBASE_EXPORT ObserverV2 : public Observer // krazy:exclude=dpointer
237  {
238  public:
239  using Observer::collectionChanged;
240 
251  virtual void itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource,
252  const Akonadi::Collection &collectionDestination);
253 
260  virtual void itemLinked(const Akonadi::Item &item, const Akonadi::Collection &collection);
261 
268  virtual void itemUnlinked(const Akonadi::Item &item, const Akonadi::Collection &collection);
269 
280  virtual void collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &collectionSource,
281  const Akonadi::Collection &collectionDestination);
282 
288  virtual void collectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &changedAttributes);
289  };
290 
301  class AKONADIAGENTBASE_EXPORT ObserverV3 : public ObserverV2 // krazy:exclude=dpointer
302  {
303  public:
315  virtual void itemsFlagsChanged(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags, const QSet<QByteArray> &removedFlags);
316 
322  virtual void itemsRemoved(const Akonadi::Item::List &items);
323 
331  virtual void itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &sourceCollection,
332  const Akonadi::Collection &destinationCollection);
333 
340  virtual void itemsLinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection);
341 
348  virtual void itemsUnlinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection);
349  };
350 
360  class AKONADIAGENTBASE_EXPORT ObserverV4 : public ObserverV3 // krazy:exclude=dpointer
361  {
362  public:
368  virtual void tagAdded(const Akonadi::Tag &tag);
369 
375  virtual void tagChanged(const Akonadi::Tag &tag);
376 
386  virtual void tagRemoved(const Akonadi::Tag &tag);
387 
395  virtual void itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags, const QSet<Akonadi::Tag> &removedTags);
396 
400  virtual void relationAdded(const Akonadi::Relation &relation);
401 
405  virtual void relationRemoved(const Akonadi::Relation &relation);
406 
413  virtual void itemsRelationsChanged(const Akonadi::Item::List &items,
414  const Akonadi::Relation::List &addedRelations,
415  const Akonadi::Relation::List &removedRelations);
416  };
417 
422  enum Status {
423  Idle = 0,
426  NotConfigured
427  };
428 
453  template <typename T>
454  static int init(int argc, char **argv)
455  {
456 
457  // Disable session management
458  qunsetenv("SESSION_MANAGER");
459 
460  QApplication app(argc, argv);
461  debugAgent(argc, argv);
462  const QString id = parseArguments(argc, argv);
463  T r(id);
464 
465  // check if T also inherits AgentBase::Observer and
466  // if it does, automatically register it on itself
467  Observer *observer = dynamic_cast<Observer *>(&r);
468  if (observer != nullptr) {
469  r.registerObserver(observer);
470  }
471  return init(r);
472  }
473 
484  Q_REQUIRED_RESULT virtual int status() const;
485 
489  Q_REQUIRED_RESULT virtual QString statusMessage() const;
490 
494  Q_REQUIRED_RESULT virtual int progress() const;
495 
499  Q_REQUIRED_RESULT virtual QString progressMessage() const;
500 
501 public Q_SLOTS:
512  virtual void configure(WId windowId);
513 
514 public:
518  Q_REQUIRED_RESULT WId winIdForDialogs() const;
519 
520 #ifdef Q_OS_WIN
521 
525  void configure(qlonglong windowId);
526 #endif
527 
531  Q_REQUIRED_RESULT QString identifier() const;
532 
540  virtual void cleanup();
541 
549  void registerObserver(Observer *observer);
550 
557  //FIXME_API: make sure location is renamed to this by agentbase
558  void setAgentName(const QString &name);
559 
565  Q_REQUIRED_RESULT QString agentName() const;
566 
567 Q_SIGNALS:
575  void agentNameChanged(const QString &name);
576 
582  void status(int status, const QString &message = QString());
583 
590  void percent(int progress);
591 
597  void warning(const QString &message);
598 
604  void error(const QString &message);
605 
612  void advancedStatus(const QVariantMap &status);
613 
622  void abortRequested();
623 
630  void reloadConfiguration();
631 
637  void onlineChanged(bool online);
638 
647  void configurationDialogAccepted();
648 
657  void configurationDialogRejected();
658 
659 protected:
665  AgentBase(const QString &id);
666 
670  ~AgentBase();
671 
679  virtual void aboutToQuit();
680 
685  ChangeRecorder *changeRecorder() const;
686 
690  KSharedConfigPtr config();
691 
699  void changeProcessed();
700 
704  bool isOnline() const;
705 
714  void setNeedsNetwork(bool needsNetwork);
715 
719  void setOnline(bool state);
720 
721 protected:
745  void setTemporaryOffline(int makeOnlineInSeconds = 300);
746 
747  //@cond PRIVATE
748  static void debugAgent(int argc, char **argv);
749 
750  AgentBasePrivate *d_ptr;
751  explicit AgentBase(AgentBasePrivate *d, const QString &id);
752  friend class ObserverV2;
753  //@endcond
754 
760  virtual void doSetOnline(bool online);
761 
762  virtual KAboutData aboutData() const;
763 
764 private:
765  //@cond PRIVATE
766  static QString parseArguments(int argc, char **argv);
767  static int init(AgentBase &r);
768  void setOnlineInternal(bool state);
769 
770  // D-Bus interface stuff
771  void abort();
772  void reconfigure();
773  void quit();
774 
775  // dbus agent interface
776  friend class ::Akonadi__StatusAdaptor;
777  friend class ::Akonadi__ControlAdaptor;
778 
779  Q_DECLARE_PRIVATE(AgentBase)
780  Q_PRIVATE_SLOT(d_func(), void delayedInit())
781  Q_PRIVATE_SLOT(d_func(), void slotStatus(int, const QString &))
782  Q_PRIVATE_SLOT(d_func(), void slotPercent(int))
783  Q_PRIVATE_SLOT(d_func(), void slotWarning(const QString &))
784  Q_PRIVATE_SLOT(d_func(), void slotError(const QString &))
785  Q_PRIVATE_SLOT(d_func(), void slotNetworkStatusChange(bool))
786  Q_PRIVATE_SLOT(d_func(), void slotResumedFromSuspend())
787  Q_PRIVATE_SLOT(d_func(), void slotTemporaryOfflineTimeout())
788 
789  //@endcond
790 };
791 
792 }
793 
794 #ifndef AKONADI_AGENT_MAIN
795 
798 #define AKONADI_AGENT_MAIN( agentClass ) \
799  int main( int argc, char **argv ) \
800  { \
801  return Akonadi::AgentBase::init<agentClass>( argc, argv ); \
802  }
803 #endif
804 
805 #endif
An Akonadi Relation.
Definition: relation.h:39
Status
This enum describes the different states the agent can be in.
Definition: agentbase.h:422
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
BC extension of Observer with support for monitoring item and collection moves.
Definition: agentbase.h:236
BC extension of ObserverV2 with support for batch operations.
Definition: agentbase.h:301
QCA_EXPORT void init()
The agent encountered an error state.
Definition: agentbase.h:425
Helper integration between Akonadi and Qt.
Observer that adds support for item tagging.
Definition: agentbase.h:360
An Akonadi Tag.
Definition: tag.h:26
static int init(int argc, char **argv)
Use this method in the main function of your agent application to initialize your agent subclass...
Definition: agentbase.h:454
The agent is working on something.
Definition: agentbase.h:424
Records and replays change notification.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 7 2020 23:14:29 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.