Akonadi

core/agentinstance.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Tobias Koenig <[email protected]>
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 
16 using namespace Akonadi;
17 
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 
83 {
84  return d->mIsOnline;
85 }
86 
87 void AgentInstance::setIsOnline(bool online)
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  AgentManager::self()->d->synchronizeRelations(*this);
115 }
116 
118 {
119  if (this != &other) {
120  d = other.d;
121  }
122 
123  return *this;
124 }
125 
126 bool AgentInstance::operator==(const AgentInstance &other) const
127 {
128  return (d->mIdentifier == other.d->mIdentifier);
129 }
130 
132 {
133  QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
134  QStringLiteral("/"),
135  QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
136  if (iface.isValid()) {
137  QDBusReply<void> reply = iface.call(QStringLiteral("abort"));
138  if (!reply.isValid()) {
139  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
140  }
141  } else {
142  qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
143  }
144 }
145 
147 {
148  QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
149  QStringLiteral("/"),
150  QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
151  if (iface.isValid()) {
152  QDBusReply<void> reply = iface.call(QStringLiteral("reconfigure"));
153  if (!reply.isValid()) {
154  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
155  }
156  } else {
157  qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
158  }
159 }
160 
162 {
163  QDBusInterface iface(ServerManager::serviceName(Akonadi::ServerManager::Control),
164  QStringLiteral("/AgentManager"),
165  QStringLiteral("org.freedesktop.Akonadi.AgentManager"));
166  if (iface.isValid()) {
167  QDBusReply<void> reply = iface.call(QStringLiteral("restartAgentInstance"), identifier());
168  if (!reply.isValid()) {
169  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
170  }
171  } else {
172  qCWarning(AKONADICORE_LOG) << "Unable to obtain control interface" << iface.lastError().message();
173  }
174 }
QString identifier() const
Returns the unique identifier of the agent instance.
AgentInstance()
Creates a new agent instance object.
@ Running
The agent instance is working on something.
@ Broken
The agent instance encountered an error state.
void setIsOnline(bool online)
Sets online status of the agent instance.
Status status() const
Returns the status of the agent instance.
AgentType type() const
Returns the agent type of this instance.
A representation of an agent type.
QString message() const const
bool isValid() const const
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
@ NotConfigured
The agent is lacking required configuration.
QDBusMessage call(const QString &method, Args &&... args)
Status
Describes the status of the agent instance.
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...
void restart() const
Restart the agent process.
void reconfigure() const
Tell the agent that its configuration has been changed remotely via D-Bus.
bool operator==(const AgentInstance &other) const
void synchronize()
Triggers the agent instance to start synchronization.
void setName(const QString &name)
Sets the user visible name of the agent instance.
void synchronizeRelations()
Triggers a synchronization of relations by the given agent instance.
QString name() const
Returns the user visible name of the agent instance.
void synchronizeCollectionTree()
Triggers a synchronization of the collection tree by the given agent instance.
bool isValid() const const
bool isOnline() const
Returns whether the agent instance is online currently.
void abortCurrentTask() const
Tell the agent to abort its current operation.
AgentInstance & operator=(const AgentInstance &other)
void synchronizeTags()
Triggers a synchronization of tags by the given agent instance.
static AgentManager * self()
Returns the global instance of the agent manager.
QDBusError lastError() const const
int progress() const
Returns the progress of the agent instance in percent, or -1 if no progress information are available...
@ Idle
The agent instance does currently nothing.
bool isValid() const
Returns whether the agent instance object is valid.
QString statusMessage() const
Returns a textual presentation of the status of the agent instance.
A representation of an agent instance.
~AgentInstance()
Destroys the agent instance object.
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.