File indexing completed on 2024-11-10 04:40:29
0001 /* 0002 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 #include "job.h" 0011 0012 namespace Akonadi 0013 { 0014 class CachePolicy; 0015 class Collection; 0016 class CollectionModifyJobPrivate; 0017 0018 /** 0019 * @short Job that modifies a collection in the Akonadi storage. 0020 * 0021 * This job modifies the properties of an existing collection. 0022 * 0023 * @code 0024 * 0025 * Akonadi::Collection collection = ... 0026 * 0027 * Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( collection ); 0028 * connect( job, SIGNAL(result(KJob*)), this, SLOT(modifyResult(KJob*)) ); 0029 * 0030 * @endcode 0031 * 0032 * If the collection has attributes, it is recommended only to supply values for 0033 * any attributes whose values are to be updated. This will help to avoid 0034 * potential clashes with other resources or applications which may happen to 0035 * update the collection simultaneously. To avoid supplying attribute values which 0036 * are not needed, create a new instance of the collection and explicitly set 0037 * attributes to be updated, e.g. 0038 * 0039 * @code 0040 * 0041 * // Update the 'MyAttribute' attribute of 'collection'. 0042 * Akonadi::Collection c( collection.id() ); 0043 * MyAttribute *attribute = c.attribute<MyAttribute>( Collection::AddIfMissing ); 0044 * if ( collection.hasAttribute<MyAttribute>() ) { 0045 * *attribute = *collection.attribute<MyAttribute>(); 0046 * } 0047 * // Update the value of 'attribute' ... 0048 * Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( c ); 0049 * connect( job, SIGNAL(result(KJob*)), this, SLOT(modifyResult(KJob*)) ); 0050 * 0051 * @endcode 0052 * 0053 * To update only the collection, and not change any attributes: 0054 * 0055 * @code 0056 * 0057 * // Update the cache policy for 'collection' to 'newPolicy'. 0058 * Akonadi::Collection c( collection.id() ); 0059 * c.setCachePolicy( newPolicy ); 0060 * Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( c ); 0061 * connect( job, SIGNAL(result(KJob*)), this, SLOT(modifyResult(KJob*)) ); 0062 * 0063 * @endcode 0064 * 0065 * @author Volker Krause <vkrause@kde.org> 0066 */ 0067 class AKONADICORE_EXPORT CollectionModifyJob : public Job 0068 { 0069 Q_OBJECT 0070 0071 public: 0072 /** 0073 * Creates a new collection modify job for the given collection. The collection can be 0074 * identified either by its unique identifier or its remote identifier. Since the remote 0075 * identifier is not necessarily globally unique, identification by remote identifier only 0076 * works inside a resource context (that is from within ResourceBase) and is therefore 0077 * limited to one resource. 0078 * 0079 * @param collection The collection to modify. 0080 * @param parent The parent object. 0081 */ 0082 explicit CollectionModifyJob(const Collection &collection, QObject *parent = nullptr); 0083 0084 /** 0085 * Destroys the collection modify job. 0086 */ 0087 ~CollectionModifyJob() override; 0088 0089 /** 0090 * Returns the modified collection. 0091 * 0092 * @since 4.4 0093 */ 0094 [[nodiscard]] Collection collection() const; 0095 0096 protected: 0097 void doStart() override; 0098 bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override; 0099 0100 private: 0101 Q_DECLARE_PRIVATE(CollectionModifyJob) 0102 }; 0103 0104 }