Akonadi

collectionmodifyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
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 "protocolhelper_p.h"
14 #include "private/protocol_p.h"
15 #include "persistentsearchattribute.h"
16 
17 using namespace Akonadi;
18 
19 class Akonadi::CollectionModifyJobPrivate : public JobPrivate
20 {
21 public:
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 
43 {
44 }
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 {
112  Q_D(CollectionModifyJob);
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 {
124  const Q_D(CollectionModifyJob);
125  return d->mCollection;
126 }
Job that modifies a collection in the Akonadi storage.
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:372
void emitResult()
void doStart() override
This method must be reimplemented in the concrete jobs.
Unknown error.
Definition: job.h:102
Represents a collection of PIM items.
Definition: collection.h:63
void setError(int errorCode)
Listing for display to the user.
Definition: collection.h:470
Base class for all actions in the Akonadi storage.
Definition: job.h:80
Listing for indexing the content.
Definition: collection.h:471
An attribute to store query properties of persistent search collections.
void setErrorText(const QString &errorText)
QString fromUtf8(const char *str, int size)
Collection collection() const
Returns the modified collection.
bool isEmpty() const const
CollectionModifyJob(const Collection &collection, QObject *parent=nullptr)
Creates a new collection modify job for the given collection.
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...
~CollectionModifyJob() override
Destroys the collection modify job.
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Listing for synchronization.
Definition: collection.h:469
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 23:16:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.