Akonadi

core/agentinstance.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "agentinstance.h"
8#include "agentinstance_p.h"
9
10#include "agentmanager.h"
11#include "agentmanager_p.h"
12#include "servermanager.h"
13
14#include "akonadicore_debug.h"
15
16using namespace Akonadi;
17
18AgentInstance::AgentInstance()
19 : d(new AgentInstancePrivate)
20{
21}
22
24 : d(other.d)
25{
26}
27
29{
30}
31
33{
34 return !d->mIdentifier.isEmpty();
35}
36
38{
39 return d->mType;
40}
41
43{
44 return d->mIdentifier;
45}
46
48{
49 AgentManager::self()->d->setName(*this, name);
50}
51
53{
54 return d->mName;
55}
56
58{
59 switch (d->mStatus) {
60 case 0:
61 return Idle;
62 case 1:
63 return Running;
64 case 3:
65 return NotConfigured;
66 case 2:
67 default:
68 return Broken;
69 }
70}
71
73{
74 return d->mStatusMessage;
75}
76
78{
79 return d->mProgress;
80}
81
82bool AgentInstance::isOnline() const
83{
84 return d->mIsOnline;
85}
86
88{
89 AgentManager::self()->d->setOnline(*this, online);
90}
91
93{
94 AgentManager::self()->d->configure(*this, parent);
95}
96
98{
99 AgentManager::self()->d->synchronize(*this);
100}
101
103{
104 AgentManager::self()->d->synchronizeCollectionTree(*this);
105}
106
108{
109 AgentManager::self()->d->synchronizeTags(*this);
110}
111
113{
114 if (this != &other) {
115 d = other.d;
116 }
117
118 return *this;
119}
120
122{
123 return (d->mIdentifier == other.d->mIdentifier);
124}
125
127{
128 QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
129 QStringLiteral("/"),
130 QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
131 if (iface.isValid()) {
132 QDBusReply<void> reply = iface.call(QStringLiteral("abort"));
133 if (!reply.isValid()) {
134 qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
135 }
136 } else {
137 qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
138 }
139}
140
142{
143 QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
144 QStringLiteral("/"),
145 QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
146 if (iface.isValid()) {
147 QDBusReply<void> reply = iface.call(QStringLiteral("reconfigure"));
148 if (!reply.isValid()) {
149 qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
150 }
151 } else {
152 qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
153 }
154}
155
157{
158 QDBusInterface iface(ServerManager::serviceName(Akonadi::ServerManager::Control),
159 QStringLiteral("/AgentManager"),
160 QStringLiteral("org.freedesktop.Akonadi.AgentManager"));
161 if (iface.isValid()) {
162 QDBusReply<void> reply = iface.call(QStringLiteral("restartAgentInstance"), identifier());
163 if (!reply.isValid()) {
164 qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
165 }
166 } else {
167 qCWarning(AKONADICORE_LOG) << "Unable to obtain control interface" << iface.lastError().message();
168 }
169}
170
172{
173 return d->mActivities;
174}
175
177{
178 AgentManager::self()->d->setActivities(*this, activities);
179}
180
182{
183 return d->mActivitiesEnabled;
184}
185
187{
188 AgentManager::self()->d->setActivitiesEnabled(*this, enabled);
189}
A representation of an agent instance.
void restart() const
Restart the agent process.
Status status() const
Returns the status of the agent instance.
void abortCurrentTask() const
Tell the agent to abort its current operation.
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
void synchronize()
Triggers the agent instance to start synchronization.
AgentInstance()
Creates a new agent instance object.
bool isValid() const
Returns whether the agent instance object is valid.
QString identifier() const
Returns the unique identifier of the agent instance.
void setIsOnline(bool online)
Sets online status of the agent instance.
AgentType type() const
Returns the agent type of this instance.
QStringList activities() const
Returns a list of activities of the agent instance.
void synchronizeCollectionTree()
Triggers a synchronization of the collection tree by the given agent instance.
AgentInstance & operator=(const AgentInstance &other)
void setActivities(const QStringList &online)
Sets list of activities of the agent instance.
void setName(const QString &name)
Sets the user visible name of the agent instance.
~AgentInstance()
Destroys the agent instance object.
Status
Describes the status of the agent instance.
@ NotConfigured
The agent is lacking required configuration.
@ Running
The agent instance is working on something.
@ Idle
The agent instance does currently nothing.
@ Broken
The agent instance encountered an error state.
QString statusMessage() const
Returns a textual presentation of the status of the agent instance.
bool operator==(const AgentInstance &other) const
void synchronizeTags()
Triggers a synchronization of tags by the given agent instance.
void setActivitiesEnabled(bool enabled)
Sets activities support enabled.
void reconfigure() const
Tell the agent that its configuration has been changed remotely via D-Bus.
bool isOnline() const
Returns whether the agent instance is online currently.
int progress() const
Returns the progress of the agent instance in percent, or -1 if no progress information are available...
bool activitiesEnabled() const
Returns true if agent instance has activities support enabled.
QString name() const
Returns the user visible name of the agent instance.
static AgentManager * self()
Returns the global instance of the agent manager.
A representation of an agent type.
static QString agentServiceName(ServiceAgentType agentType, const QString &identifier)
Returns the namespaced D-Bus service name for an agent of type agentType with agent identifier identi...
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
Helper integration between Akonadi and Qt.
QDBusMessage call(QDBus::CallMode mode, const QString &method, Args &&... args)
bool isValid() const const
QDBusError lastError() const const
QString message() const const
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.