Akonadi

akonadicontrol/agentinstance.h
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef AKONADICONTROL_AGENTINSTANCE_H
8 #define AKONADICONTROL_AGENTINSTANCE_H
9 
10 #include "controlinterface.h"
11 #include "statusinterface.h"
12 #include "resourceinterface.h"
13 #include "preprocessorinterface.h"
14 #include "searchinterface.h"
15 
16 #include <private/dbus_p.h>
17 
18 #include <QDBusError>
19 #include <QSharedPointer>
20 #include <QString>
21 
22 #include <memory>
23 
24 class AgentManager;
25 class AgentType;
26 
35 class AgentInstance : public QObject
36 {
37  Q_OBJECT
38 public:
40 
41  explicit AgentInstance(AgentManager &manager);
42  ~AgentInstance() override;
43 
45  Q_REQUIRED_RESULT QString identifier() const
46  {
47  return mIdentifier;
48  }
49 
50  void setIdentifier(const QString &identifier)
51  {
52  mIdentifier = identifier;
53  }
54 
55  Q_REQUIRED_RESULT QString agentType() const
56  {
57  return mType;
58  }
59 
60  Q_REQUIRED_RESULT int status() const
61  {
62  return mStatus;
63  }
64 
65  Q_REQUIRED_RESULT QString statusMessage() const
66  {
67  return mStatusMessage;
68  }
69 
70  Q_REQUIRED_RESULT int progress() const
71  {
72  return mPercent;
73  }
74 
75  Q_REQUIRED_RESULT bool isOnline() const
76  {
77  return mOnline;
78  }
79 
80  Q_REQUIRED_RESULT QString resourceName() const
81  {
82  return mResourceName;
83  }
84 
85  virtual bool start(const AgentType &agentInfo) = 0;
86  virtual void quit();
87  virtual void cleanup();
88  virtual void restartWhenIdle() = 0;
89  virtual void configure(qlonglong windowId) = 0;
90 
91  Q_REQUIRED_RESULT bool hasResourceInterface() const
92  {
93  return mResourceInterface != nullptr;
94  }
95 
96  Q_REQUIRED_RESULT bool hasAgentInterface() const
97  {
98  return mAgentControlInterface != nullptr && mAgentStatusInterface != nullptr;
99  }
100 
101  Q_REQUIRED_RESULT bool hasPreprocessorInterface() const
102  {
103  return mPreprocessorInterface != nullptr;
104  }
105 
106  org::freedesktop::Akonadi::Agent::Control *controlInterface() const
107  {
108  return mAgentControlInterface.get();
109  }
110 
111  org::freedesktop::Akonadi::Agent::Status *statusInterface() const
112  {
113  return mAgentStatusInterface.get();
114  }
115 
116  org::freedesktop::Akonadi::Agent::Search *searchInterface() const
117  {
118  return mSearchInterface.get();
119  }
120 
121  org::freedesktop::Akonadi::Resource *resourceInterface() const
122  {
123  return mResourceInterface.get();
124  }
125 
126  org::freedesktop::Akonadi::Preprocessor *preProcessorInterface() const
127  {
128  return mPreprocessorInterface.get();
129  }
130 
131  bool obtainAgentInterface();
132  bool obtainResourceInterface();
133  bool obtainPreprocessorInterface();
134 
135 protected Q_SLOTS:
136  void statusChanged(int status, const QString &statusMsg);
137  void advancedStatusChanged(const QVariantMap &status);
138  void statusStateChanged(int status);
139  void statusMessageChanged(const QString &msg);
140  void percentChanged(int percent);
141  void warning(const QString &msg);
142  void error(const QString &msg);
143  void onlineChanged(bool state);
144  void resourceNameChanged(const QString &name);
145 
146  void refreshAgentStatus();
147  void refreshResourceStatus();
148 
149  void errorHandler(const QDBusError &error);
150 
151 private:
152  template <typename T>
153  std::unique_ptr<T> findInterface(Akonadi::DBus::AgentType agentType, const char *path = nullptr);
154 
155 protected:
156  void setAgentType(const QString &agentType)
157  {
158  mType = agentType;
159  }
160 
161 private:
162  QString mIdentifier;
163  QString mType;
164  AgentManager &mManager;
165  std::unique_ptr<org::freedesktop::Akonadi::Agent::Control> mAgentControlInterface;
166  std::unique_ptr<org::freedesktop::Akonadi::Agent::Status> mAgentStatusInterface;
167  std::unique_ptr<org::freedesktop::Akonadi::Agent::Search> mSearchInterface;
168  std::unique_ptr<org::freedesktop::Akonadi::Resource> mResourceInterface;
169  std::unique_ptr<org::freedesktop::Akonadi::Preprocessor> mPreprocessorInterface;
170 
171  QString mResourceName;
172  QString mStatusMessage;
173  int mStatus = 0;
174  int mPercent = 0;
175  bool mOnline = false;
176  bool mPendingQuit = false;
177 
178 };
179 
180 #endif
Represents one agent instance and takes care of communication with it.
Q_OBJECTQ_OBJECT
QString identifier() const
Set/get the unique identifier of this AgentInstance.
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 23:16:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.