Akonadi

core/agentinstance.cpp
1 /*
2  Copyright (c) 2008 Tobias Koenig <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "agentinstance.h"
21 #include "agentinstance_p.h"
22 
23 #include "agentmanager.h"
24 #include "agentmanager_p.h"
25 #include "servermanager.h"
26 
27 #include "akonadicore_debug.h"
28 
29 using namespace Akonadi;
30 
32  : d(new Private)
33 {
34 }
35 
37  : d(other.d)
38 {
39 }
40 
42 {
43 }
44 
46 {
47  return !d->mIdentifier.isEmpty();
48 }
49 
51 {
52  return d->mType;
53 }
54 
56 {
57  return d->mIdentifier;
58 }
59 
61 {
62  AgentManager::self()->d->setName(*this, name);
63 }
64 
66 {
67  return d->mName;
68 }
69 
71 {
72  switch (d->mStatus) {
73  case 0:
74  return Idle;
75  case 1:
76  return Running;
77  case 3:
78  return NotConfigured;
79  case 2:
80  default:
81  return Broken;
82  }
83 }
84 
86 {
87  return d->mStatusMessage;
88 }
89 
91 {
92  return d->mProgress;
93 }
94 
96 {
97  return d->mIsOnline;
98 }
99 
100 void AgentInstance::setIsOnline(bool online)
101 {
102  AgentManager::self()->d->setOnline(*this, online);
103 }
104 
106 {
107  AgentManager::self()->d->configure(*this, parent);
108 }
109 
111 {
112  AgentManager::self()->d->synchronize(*this);
113 }
114 
116 {
117  AgentManager::self()->d->synchronizeCollectionTree(*this);
118 }
119 
121 {
122  AgentManager::self()->d->synchronizeTags(*this);
123 }
124 
126 {
127  AgentManager::self()->d->synchronizeRelations(*this);
128 }
129 
131 {
132  if (this != &other) {
133  d = other.d;
134  }
135 
136  return *this;
137 }
138 
139 bool AgentInstance::operator==(const AgentInstance &other) const
140 {
141  return (d->mIdentifier == other.d->mIdentifier);
142 }
143 
145 {
146  QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
147  QStringLiteral("/"),
148  QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
149  if (iface.isValid()) {
150  QDBusReply<void> reply = iface.call(QStringLiteral("abort"));
151  if (!reply.isValid()) {
152  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
153  }
154  } else {
155  qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
156  }
157 }
158 
160 {
161  QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
162  QStringLiteral("/"),
163  QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
164  if (iface.isValid()) {
165  QDBusReply<void> reply = iface.call(QStringLiteral("reconfigure"));
166  if (!reply.isValid()) {
167  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
168  }
169  } else {
170  qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
171  }
172 }
173 
175 {
176  QDBusInterface iface(ServerManager::serviceName(Akonadi::ServerManager::Control),
177  QStringLiteral("/AgentManager"),
178  QStringLiteral("org.freedesktop.Akonadi.AgentManager"));
179  if (iface.isValid()) {
180  QDBusReply<void> reply = iface.call(QStringLiteral("restartAgentInstance"), identifier());
181  if (!reply.isValid()) {
182  qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
183  }
184  } else {
185  qCWarning(AKONADICORE_LOG) << "Unable to obtain control interface" << iface.lastError().message();
186  }
187 }
bool isValid() const const
void synchronizeTags()
Triggers a synchronization of tags by the given agent instance.
The agent instance does currently nothing.
void synchronizeCollectionTree()
Triggers a synchronization of the collection tree by the given agent instance.
void synchronize()
Triggers the agent instance to start synchronization.
void restart() const
Restart the agent process.
AgentType type() const
Returns the agent type of this instance.
QString message() const const
bool isValid() const const
The agent instance is working on something.
The agent is lacking required configuration.
QString identifier() const
Returns the unique identifier of the agent instance.
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
A representation of an agent type.
int progress() const
Returns the progress of the agent instance in percent, or -1 if no progress information are available...
~AgentInstance()
Destroys the agent instance object.
void setIsOnline(bool online)
Sets online status of the agent instance.
void synchronizeRelations()
Triggers a synchronization of relations by the given agent instance.
AgentInstance & operator=(const AgentInstance &other)
AgentInstance()
Creates a new agent instance object.
bool isValid() const
Returns whether the agent instance object is valid.
bool isOnline() const
Returns whether the agent instance is online currently.
AKONADICORE_DEPRECATED void configure(QWidget *parent=nullptr)
Triggers the agent instance to show its configuration dialog.
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 setName(const QString &name)
Sets the user visible name of the agent instance.
QString name() const
Returns the user visible name of the agent instance.
Helper integration between Akonadi and Qt.
Status
Describes the status of the agent instance.
static AgentManager * self()
Returns the global instance of the agent manager.
Status status() const
Returns the status of the agent instance.
A representation of an agent instance.
QDBusError lastError() const const
bool operator==(const AgentInstance &other) const
QString statusMessage() const
Returns a textual presentation of the status of the agent instance.
The agent instance encountered an error state.
void abortCurrentTask() const
Tell the agent to abort its current operation.
void reconfigure() const
Tell the agent that its configuration has been changed remotely via D-Bus.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.