Akonadi

akonadicontrol/agentinstance.h
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
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
23class AgentManager;
24class 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 */
34class AgentInstance : public QObject
35{
37public:
39
40 explicit AgentInstance(AgentManager &manager);
41 ~AgentInstance() override;
42
43 /** Set/get the unique identifier of this AgentInstance */
45 {
46 return mIdentifier;
47 }
48
49 void setIdentifier(const QString &identifier)
50 {
51 mIdentifier = identifier;
52 }
53
54 [[nodiscard]] QString agentType() const
55 {
56 return mType;
57 }
58
59 [[nodiscard]] int status() const
60 {
61 return mStatus;
62 }
63
64 [[nodiscard]] QString statusMessage() const
65 {
66 return mStatusMessage;
67 }
68
69 [[nodiscard]] int progress() const
70 {
71 return mPercent;
72 }
73
74 [[nodiscard]] bool isOnline() const
75 {
76 return mOnline;
77 }
78
79 [[nodiscard]] 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 [[nodiscard]] bool hasResourceInterface() const
91 {
92 return mResourceInterface != nullptr;
93 }
94
95 [[nodiscard]] bool hasAgentInterface() const
96 {
97 return mAgentControlInterface != nullptr && mAgentStatusInterface != nullptr;
98 }
99
100 [[nodiscard]] 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
134protected 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
150private:
151 template<typename T>
152 std::unique_ptr<T> findInterface(Akonadi::DBus::AgentType agentType, const char *path = nullptr);
153
154protected:
155 void setAgentType(const QString &agentType)
156 {
157 mType = agentType;
158 }
159
160private:
161 QString mIdentifier;
162 QString mType;
163 AgentManager &mManager;
164 std::unique_ptr<org::freedesktop::Akonadi::Agent::Control> mAgentControlInterface;
165 std::unique_ptr<org::freedesktop::Akonadi::Agent::Status> mAgentStatusInterface;
166 std::unique_ptr<org::freedesktop::Akonadi::Agent::Search> mSearchInterface;
167 std::unique_ptr<org::freedesktop::Akonadi::Resource> mResourceInterface;
168 std::unique_ptr<org::freedesktop::Akonadi::Preprocessor> mPreprocessorInterface;
169
170 QString mResourceName;
171 QString mStatusMessage;
172 int mStatus = 0;
173 int mPercent = 0;
174 bool mOnline = false;
175 bool mPendingQuit = false;
176};
Represents one agent instance and takes care of communication with it.
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_SCRIPTABLE Q_NOREPLY void start()
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:58:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.