Akonadi

collectionmodifyjob.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "collectionmodifyjob.h"
8
9#include "changemediator_p.h"
10#include "collection_p.h"
11#include "collectionstatistics.h"
12#include "job_p.h"
13#include "persistentsearchattribute.h"
14#include "private/protocol_p.h"
15#include "protocolhelper_p.h"
16
17using namespace Akonadi;
18
19class Akonadi::CollectionModifyJobPrivate : public JobPrivate
20{
21public:
22 explicit CollectionModifyJobPrivate(CollectionModifyJob *parent)
23 : JobPrivate(parent)
24 {
25 }
26
27 QString jobDebuggingString() const override
28 {
29 return QStringLiteral("Collection Id %1").arg(mCollection.id());
30 }
31
32 Collection mCollection;
33};
34
36 : Job(new CollectionModifyJobPrivate(this), parent)
37{
39 d->mCollection = collection;
40}
41
45
47{
49
50 Protocol::ModifyCollectionCommandPtr cmd;
51 try {
52 cmd = Protocol::ModifyCollectionCommandPtr::create(ProtocolHelper::entityToScope(d->mCollection));
53 } catch (const std::exception &e) {
56 emitResult();
57 return;
58 }
59
60 if (d->mCollection.d_ptr->contentTypesChanged) {
61 cmd->setMimeTypes(d->mCollection.contentMimeTypes());
62 }
63 if (d->mCollection.parentCollection().id() >= 0) {
64 cmd->setParentId(d->mCollection.parentCollection().id());
65 }
66 const QString &collectionName = d->mCollection.name();
67 if (!collectionName.isEmpty()) {
68 cmd->setName(collectionName);
69 }
70 if (!d->mCollection.remoteId().isNull()) {
71 cmd->setRemoteId(d->mCollection.remoteId());
72 }
73 if (!d->mCollection.remoteRevision().isNull()) {
74 cmd->setRemoteRevision(d->mCollection.remoteRevision());
75 }
76 if (d->mCollection.d_ptr->cachePolicyChanged) {
77 cmd->setCachePolicy(ProtocolHelper::cachePolicyToProtocol(d->mCollection.cachePolicy()));
78 }
79 if (d->mCollection.d_ptr->enabledChanged) {
80 cmd->setEnabled(d->mCollection.enabled());
81 }
82 if (d->mCollection.d_ptr->listPreferenceChanged) {
83 cmd->setDisplayPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListDisplay)));
84 cmd->setSyncPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListSync)));
85 cmd->setIndexPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListIndex)));
86 }
87 if (d->mCollection.d_ptr->mAttributeStorage.hasModifiedAttributes()) {
88 cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mCollection.d_ptr->mAttributeStorage.modifiedAttributes()));
89 }
90 if (auto attr = d->mCollection.attribute<Akonadi::PersistentSearchAttribute>()) {
91 cmd->setPersistentSearchCollections(attr->queryCollections());
92 cmd->setPersistentSearchQuery(attr->queryString());
93 cmd->setPersistentSearchRecursive(attr->isRecursive());
94 cmd->setPersistentSearchRemote(attr->isRemoteSearchEnabled());
95 }
96 if (!d->mCollection.d_ptr->mAttributeStorage.deletedAttributes().empty()) {
97 cmd->setRemovedAttributes(d->mCollection.d_ptr->mAttributeStorage.deletedAttributes());
98 }
99
100 if (cmd->modifiedParts() == Protocol::ModifyCollectionCommand::None) {
101 emitResult();
102 return;
103 }
104
105 d->sendCommand(cmd);
106
107 ChangeMediator::invalidateCollection(d->mCollection);
108}
109
111{
113
114 if (!response->isResponse() || response->type() != Protocol::Command::ModifyCollection) {
115 return Job::doHandleResponse(tag, response);
116 }
117
118 d->mCollection.d_ptr->resetChangeLog();
119 return true;
120}
121
123{
125 return d->mCollection;
126}
127
128#include "moc_collectionmodifyjob.cpp"
Job that modifies a collection in the Akonadi storage.
Collection collection() const
Returns the modified collection.
~CollectionModifyJob() override
Destroys the collection modify job.
CollectionModifyJob(const Collection &collection, QObject *parent=nullptr)
Creates a new collection modify job for the given collection.
void doStart() override
This method must be reimplemented in the concrete jobs.
bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override
This method should be reimplemented in the concrete jobs in case you want to handle incoming data.
Represents a collection of PIM items.
Definition collection.h:62
@ ListSync
Listing for synchronization.
Definition collection.h:480
@ ListIndex
Listing for indexing the content.
Definition collection.h:482
@ ListDisplay
Listing for display to the user.
Definition collection.h:481
Base class for all actions in the Akonadi storage.
Definition job.h:81
virtual bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data.
Definition job.cpp:381
@ Unknown
Unknown error.
Definition job.h:102
An attribute to store query properties of persistent search collections.
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
Helper integration between Akonadi and Qt.
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.