Akonadi

collectionmodifyjob.h
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadicore_export.h"
10#include "job.h"
11
12namespace Akonadi
13{
14class CachePolicy;
15class Collection;
16class CollectionModifyJobPrivate;
17
18/**
19 * @short Job that modifies a collection in the Akonadi storage.
20 *
21 * This job modifies the properties of an existing collection.
22 *
23 * @code
24 * Akonadi::Collection collection = ...
25 *
26 * auto job = new Akonadi::CollectionModifyJob(collection);
27 * connect(job, &KJob::result, this, &MyClass::modifyResult);
28 * @endcode
29 *
30 * If the collection has attributes, it is recommended only to supply values for
31 * any attributes whose values are to be updated. This will help to avoid
32 * potential clashes with other resources or applications which may happen to
33 * update the collection simultaneously. To avoid supplying attribute values which
34 * are not needed, create a new instance of the collection and explicitly set
35 * attributes to be updated, e.g.
36 *
37 * @code
38 * // Update the 'MyAttribute' attribute of 'collection'.
39 * Akonadi::Collection c(collection.id());
40 * auto attribute = c.attribute<MyAttribute>(Collection::AddIfMissing);
41 * if (collection.hasAttribute<MyAttribute>()) {
42 * *attribute = *collection.attribute<MyAttribute>();
43 * }
44 * // Update the value of 'attribute' ...
45 * auto job = new Akonadi::CollectionModifyJob(c);
46 * connect(job, &KJob::result, this, &MyClass::modifyResult);
47 * @endcode
48 *
49 * To update only the collection, and not change any attributes:
50 *
51 * @code
52 * // Update the cache policy for 'collection' to 'newPolicy'.
53 * Akonadi::Collection c(collection.id());
54 * c.setCachePolicy(newPolicy);
55 * auto job = new Akonadi::CollectionModifyJob(c);
56 * connect(job, &KJob::result, this, &MyClass::modifyResult);
57 * @endcode
58 *
59 * @author Volker Krause <vkrause@kde.org>
60 */
61class AKONADICORE_EXPORT CollectionModifyJob : public Job
62{
63 Q_OBJECT
64
65public:
66 /**
67 * Creates a new collection modify job for the given collection. The collection can be
68 * identified either by its unique identifier or its remote identifier. Since the remote
69 * identifier is not necessarily globally unique, identification by remote identifier only
70 * works inside a resource context (that is from within ResourceBase) and is therefore
71 * limited to one resource.
72 *
73 * @param collection The collection to modify.
74 * @param parent The parent object.
75 */
76 explicit CollectionModifyJob(const Collection &collection, QObject *parent = nullptr);
77
78 /**
79 * Destroys the collection modify job.
80 */
81 ~CollectionModifyJob() override;
82
83 /**
84 * Returns the modified collection.
85 *
86 * @since 4.4
87 */
88 [[nodiscard]] Collection collection() const;
89
90protected:
91 void doStart() override;
92 bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override;
93
94private:
95 Q_DECLARE_PRIVATE(CollectionModifyJob)
96};
97
98}
Job that modifies a collection in the Akonadi storage.
Represents a collection of PIM items.
Definition collection.h:62
Base class for all actions in the Akonadi storage.
Definition job.h:81
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:49:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.