File indexing completed on 2024-06-23 05:06:45
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 0011 #include "agentinstance.h" 0012 #include "agenttype.h" 0013 0014 #include <QObject> 0015 0016 #include <memory> 0017 0018 namespace Akonadi 0019 { 0020 class AgentManagerPrivate; 0021 class Collection; 0022 0023 /** 0024 * @short Provides an interface to retrieve agent types and manage agent instances. 0025 * 0026 * This singleton class can be used to create or remove agent instances or trigger 0027 * synchronization of collections. Furthermore it provides information about status 0028 * changes of the agents. 0029 * 0030 * @code 0031 * 0032 * Akonadi::AgentManager *manager = Akonadi::AgentManager::self(); 0033 * 0034 * Akonadi::AgentType::List types = manager->types(); 0035 * for ( const Akonadi::AgentType& type : types ) { 0036 * qDebug() << "Type:" << type.name() << type.description(); 0037 * } 0038 * 0039 * @endcode 0040 * 0041 * @author Tobias Koenig <tokoe@kde.org> 0042 */ 0043 class AKONADICORE_EXPORT AgentManager : public QObject 0044 { 0045 friend class AgentInstance; 0046 friend class AgentInstanceCreateJobPrivate; 0047 friend class AgentManagerPrivate; 0048 0049 Q_OBJECT 0050 0051 public: 0052 /** 0053 * Returns the global instance of the agent manager. 0054 */ 0055 static AgentManager *self(); 0056 0057 /** 0058 * Destroys the agent manager. 0059 */ 0060 ~AgentManager() override; 0061 0062 /** 0063 * Returns the list of all available agent types. 0064 */ 0065 [[nodiscard]] AgentType::List types() const; 0066 0067 /** 0068 * Returns the agent type with the given @p identifier or 0069 * an invalid agent type if the identifier does not exist. 0070 */ 0071 [[nodiscard]] AgentType type(const QString &identifier) const; 0072 0073 /** 0074 * Returns the list of all available agent instances. 0075 */ 0076 [[nodiscard]] AgentInstance::List instances() const; 0077 0078 /** 0079 * Returns the agent instance with the given @p identifier or 0080 * an invalid agent instance if the identifier does not exist. 0081 * 0082 * Note that because a resource is a special case of an agent, the 0083 * identifier of a resource is the same as that of its agent instance. 0084 * @param identifier identifier to choose the agent instance 0085 */ 0086 [[nodiscard]] AgentInstance instance(const QString &identifier) const; 0087 0088 /** 0089 * Removes the given agent @p instance. 0090 */ 0091 void removeInstance(const AgentInstance &instance); 0092 0093 /** 0094 * Trigger a synchronization of the given collection by its owning resource agent. 0095 * 0096 * @param collection The collection to synchronize. 0097 */ 0098 void synchronizeCollection(const Collection &collection); 0099 0100 /** 0101 * Trigger a synchronization of the given collection by its owning resource agent. 0102 * 0103 * @param collection The collection to synchronize. 0104 * @param recursive If true, the sub-collections are also synchronized 0105 * 0106 * @since 4.6 0107 */ 0108 void synchronizeCollection(const Collection &collection, bool recursive); 0109 0110 Q_SIGNALS: 0111 /** 0112 * This signal is emitted whenever a new agent type was installed on the system. 0113 * 0114 * @param type The new agent type. 0115 */ 0116 void typeAdded(const Akonadi::AgentType &type); 0117 0118 /** 0119 * This signal is emitted whenever an agent type was removed from the system. 0120 * 0121 * @param type The removed agent type. 0122 */ 0123 void typeRemoved(const Akonadi::AgentType &type); 0124 0125 /** 0126 * This signal is emitted whenever a new agent instance was created. 0127 * 0128 * @param instance The new agent instance. 0129 */ 0130 void instanceAdded(const Akonadi::AgentInstance &instance); 0131 0132 /** 0133 * This signal is emitted whenever an agent instance was removed. 0134 * 0135 * @param instance The removed agent instance. 0136 */ 0137 void instanceRemoved(const Akonadi::AgentInstance &instance); 0138 0139 /** 0140 * This signal is emitted whenever the status of an agent instance has 0141 * changed. 0142 * 0143 * @param instance The agent instance that status has changed. 0144 */ 0145 void instanceStatusChanged(const Akonadi::AgentInstance &instance); 0146 0147 /** 0148 * This signal is emitted whenever the progress of an agent instance has 0149 * changed. 0150 * 0151 * @param instance The agent instance that progress has changed. 0152 */ 0153 void instanceProgressChanged(const Akonadi::AgentInstance &instance); 0154 0155 /** 0156 * This signal is emitted whenever the name of the agent instance has changed. 0157 * 0158 * @param instance The agent instance that name has changed. 0159 */ 0160 void instanceNameChanged(const Akonadi::AgentInstance &instance); 0161 0162 /** 0163 * This signal is emitted whenever the agent instance raised an error. 0164 * 0165 * @param instance The agent instance that raised the error. 0166 * @param message The i18n'ed error message. 0167 */ 0168 void instanceError(const Akonadi::AgentInstance &instance, const QString &message); 0169 0170 /** 0171 * This signal is emitted whenever the agent instance raised a warning. 0172 * 0173 * @param instance The agent instance that raised the warning. 0174 * @param message The i18n'ed warning message. 0175 */ 0176 void instanceWarning(const Akonadi::AgentInstance &instance, const QString &message); 0177 0178 /** 0179 * This signal is emitted whenever the online state of an agent changed. 0180 * 0181 * @param instance The agent instance that changed its online state. 0182 * @param online The new online state. 0183 * @since 4.2 0184 */ 0185 void instanceOnline(const Akonadi::AgentInstance &instance, bool online); 0186 0187 private: 0188 /// @cond PRIVATE 0189 explicit AgentManager(); 0190 0191 std::unique_ptr<AgentManagerPrivate> const d; 0192 /// @endcond 0193 }; 0194 0195 }