File indexing completed on 2024-11-10 04:40:36

0001 /*
0002     SPDX-FileCopyrightText: 2008 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "agentinstance.h"
0008 #include "agentinstance_p.h"
0009 
0010 #include "agentmanager.h"
0011 #include "agentmanager_p.h"
0012 #include "servermanager.h"
0013 
0014 #include "akonadicore_debug.h"
0015 
0016 using namespace Akonadi;
0017 
0018 AgentInstance::AgentInstance()
0019     : d(new AgentInstancePrivate)
0020 {
0021 }
0022 
0023 AgentInstance::AgentInstance(const AgentInstance &other)
0024     : d(other.d)
0025 {
0026 }
0027 
0028 AgentInstance::~AgentInstance()
0029 {
0030 }
0031 
0032 bool AgentInstance::isValid() const
0033 {
0034     return !d->mIdentifier.isEmpty();
0035 }
0036 
0037 AgentType AgentInstance::type() const
0038 {
0039     return d->mType;
0040 }
0041 
0042 QString AgentInstance::identifier() const
0043 {
0044     return d->mIdentifier;
0045 }
0046 
0047 void AgentInstance::setName(const QString &name)
0048 {
0049     AgentManager::self()->d->setName(*this, name);
0050 }
0051 
0052 QString AgentInstance::name() const
0053 {
0054     return d->mName;
0055 }
0056 
0057 AgentInstance::Status AgentInstance::status() const
0058 {
0059     switch (d->mStatus) {
0060     case 0:
0061         return Idle;
0062     case 1:
0063         return Running;
0064     case 3:
0065         return NotConfigured;
0066     case 2:
0067     default:
0068         return Broken;
0069     }
0070 }
0071 
0072 QString AgentInstance::statusMessage() const
0073 {
0074     return d->mStatusMessage;
0075 }
0076 
0077 int AgentInstance::progress() const
0078 {
0079     return d->mProgress;
0080 }
0081 
0082 bool AgentInstance::isOnline() const
0083 {
0084     return d->mIsOnline;
0085 }
0086 
0087 void AgentInstance::setIsOnline(bool online)
0088 {
0089     AgentManager::self()->d->setOnline(*this, online);
0090 }
0091 
0092 void AgentInstance::configure(QWidget *parent)
0093 {
0094     AgentManager::self()->d->configure(*this, parent);
0095 }
0096 
0097 void AgentInstance::synchronize()
0098 {
0099     AgentManager::self()->d->synchronize(*this);
0100 }
0101 
0102 void AgentInstance::synchronizeCollectionTree()
0103 {
0104     AgentManager::self()->d->synchronizeCollectionTree(*this);
0105 }
0106 
0107 void AgentInstance::synchronizeTags()
0108 {
0109     AgentManager::self()->d->synchronizeTags(*this);
0110 }
0111 
0112 void AgentInstance::synchronizeRelations()
0113 {
0114     AgentManager::self()->d->synchronizeRelations(*this);
0115 }
0116 
0117 AgentInstance &AgentInstance::operator=(const AgentInstance &other)
0118 {
0119     if (this != &other) {
0120         d = other.d;
0121     }
0122 
0123     return *this;
0124 }
0125 
0126 bool AgentInstance::operator==(const AgentInstance &other) const
0127 {
0128     return (d->mIdentifier == other.d->mIdentifier);
0129 }
0130 
0131 void AgentInstance::abortCurrentTask() const
0132 {
0133     QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
0134                          QStringLiteral("/"),
0135                          QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
0136     if (iface.isValid()) {
0137         QDBusReply<void> reply = iface.call(QStringLiteral("abort"));
0138         if (!reply.isValid()) {
0139             qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
0140         }
0141     } else {
0142         qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
0143     }
0144 }
0145 
0146 void AgentInstance::reconfigure() const
0147 {
0148     QDBusInterface iface(ServerManager::agentServiceName(ServerManager::Agent, identifier()),
0149                          QStringLiteral("/"),
0150                          QStringLiteral("org.freedesktop.Akonadi.Agent.Control"));
0151     if (iface.isValid()) {
0152         QDBusReply<void> reply = iface.call(QStringLiteral("reconfigure"));
0153         if (!reply.isValid()) {
0154             qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
0155         }
0156     } else {
0157         qCWarning(AKONADICORE_LOG) << "Unable to obtain agent interface";
0158     }
0159 }
0160 
0161 void Akonadi::AgentInstance::restart() const
0162 {
0163     QDBusInterface iface(ServerManager::serviceName(Akonadi::ServerManager::Control),
0164                          QStringLiteral("/AgentManager"),
0165                          QStringLiteral("org.freedesktop.Akonadi.AgentManager"));
0166     if (iface.isValid()) {
0167         QDBusReply<void> reply = iface.call(QStringLiteral("restartAgentInstance"), identifier());
0168         if (!reply.isValid()) {
0169             qCWarning(AKONADICORE_LOG) << "Failed to place D-Bus call.";
0170         }
0171     } else {
0172         qCWarning(AKONADICORE_LOG) << "Unable to obtain control interface" << iface.lastError().message();
0173     }
0174 }