File indexing completed on 2024-11-10 04:40:31
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 0011 #include <KJob> 0012 0013 #include <memory> 0014 0015 namespace Akonadi 0016 { 0017 class AgentInstance; 0018 class ResourceSynchronizationJobPrivate; 0019 0020 /** 0021 * @short Job that synchronizes a resource. 0022 * 0023 * This job will trigger a resource to synchronize the backend it is 0024 * responsible for (e.g. a local file or a groupware server) with the 0025 * Akonadi storage. 0026 * 0027 * If you only want to trigger the synchronization without being 0028 * interested in the result, using Akonadi::AgentInstance::synchronize() is enough. 0029 * If you want to wait until it's finished, use this class. 0030 * 0031 * Example: 0032 * 0033 * @code 0034 * using namespace Akonadi; 0035 * 0036 * const AgentInstance resource = AgentManager::self()->instance( "myresourceidentifier" ); 0037 * 0038 * ResourceSynchronizationJob *job = new ResourceSynchronizationJob( resource ); 0039 * connect( job, SIGNAL(result(KJob*)), SLOT(synchronizationFinished(KJob*)) ); 0040 * job->start(); 0041 * 0042 * @endcode 0043 * 0044 * @note This is a KJob, not an Akonadi::Job, so it won't auto-start! 0045 * 0046 * @author Volker Krause <vkrause@kde.org> 0047 * @since 4.4 0048 */ 0049 class AKONADICORE_EXPORT ResourceSynchronizationJob : public KJob 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 /** 0055 * Creates a new synchronization job for the given resource. 0056 * 0057 * @param instance The resource instance to synchronize. 0058 */ 0059 explicit ResourceSynchronizationJob(const AgentInstance &instance, QObject *parent = nullptr); 0060 0061 /** 0062 * Destroys the synchronization job. 0063 */ 0064 ~ResourceSynchronizationJob() override; 0065 0066 /** 0067 * Returns whether a full synchronization will be done, or just the collection tree (without items). 0068 * The default is @c false, i.e. a full sync will be requested. 0069 * 0070 * @since 4.8 0071 */ 0072 [[nodiscard]] bool collectionTreeOnly() const; 0073 0074 /** 0075 * Sets the collectionTreeOnly property. 0076 * 0077 * @param collectionTreeOnly If set, only the collection tree will be synchronized. 0078 * @since 4.8 0079 */ 0080 void setCollectionTreeOnly(bool collectionTreeOnly); 0081 0082 /** 0083 * Returns the resource that has been synchronized. 0084 */ 0085 [[nodiscard]] AgentInstance resource() const; 0086 0087 /* reimpl */ 0088 void start() override; 0089 0090 /* 0091 * @since 5.1 0092 */ 0093 void setTimeoutCountLimit(int count); 0094 [[nodiscard]] int timeoutCountLimit() const; 0095 0096 private: 0097 /// @cond PRIVATE 0098 friend class ResourceSynchronizationJobPrivate; 0099 std::unique_ptr<ResourceSynchronizationJobPrivate> const d; 0100 /// @endcond 0101 }; 0102 0103 }