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

KDE's Doxygen guidelines are available online.