Akonadi

tagmodifyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Christian Mollekopf <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "tagmodifyjob.h"
8 #include "job_p.h"
9 #include "tag.h"
10 #include "tag_p.h"
11 #include "protocolhelper_p.h"
12 #include "changemediator_p.h"
13 
14 using namespace Akonadi;
15 
16 class Akonadi::TagModifyJobPrivate : public JobPrivate
17 {
18 public:
19  explicit TagModifyJobPrivate(TagModifyJob *parent)
20  : JobPrivate(parent)
21  {
22  }
23 
24  QString jobDebuggingString() const override;
25  Tag mTag;
26 
27 };
28 
29 QString Akonadi::TagModifyJobPrivate::jobDebuggingString() const
30 {
31  return QStringLiteral("Modify Tag: %1").arg(mTag.name());
32 }
33 
35  : Job(new TagModifyJobPrivate(this), parent)
36 {
37  Q_D(TagModifyJob);
38  d->mTag = tag;
39 }
40 
42 {
43  Q_D(TagModifyJob);
44 
45  auto cmd = Protocol::ModifyTagCommandPtr::create(d->mTag.id());
46  if (!d->mTag.remoteId().isNull()) {
47  cmd->setRemoteId(d->mTag.remoteId());
48  }
49  if (!d->mTag.type().isEmpty()) {
50  cmd->setType(d->mTag.type());
51  }
52  if (d->mTag.parent().isValid() && !d->mTag.isImmutable()) {
53  cmd->setParentId(d->mTag.parent().id());
54  }
55  if (!d->mTag.d_ptr->mAttributeStorage.deletedAttributes().isEmpty()) {
56  cmd->setRemovedAttributes(d->mTag.d_ptr->mAttributeStorage.deletedAttributes());
57  }
58  if (d->mTag.d_ptr->mAttributeStorage.hasModifiedAttributes()) {
59  cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mTag.d_ptr->mAttributeStorage.modifiedAttributes()));
60  }
61 
62  d->sendCommand(cmd);
63 }
64 
66 {
67  Q_D(TagModifyJob);
68 
69  if (response->isResponse()) {
70  if (response->type() == Protocol::Command::FetchTags || response->type() == Protocol::Command::DeleteTag) {
71  // Tag was modified, deleted or merged, we ignore the response for now
72  return false;
73  } else if (response->type() == Protocol::Command::ModifyTag) {
74  // Done.
75  d->mTag.d_ptr->resetChangeLog();
76  return true;
77  }
78  }
79 
80  return Job::doHandleResponse(tag, response);
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:372
Base class for all actions in the Akonadi storage.
Definition: job.h:80
TagModifyJob(const Tag &tag, QObject *parent=nullptr)
Creates a new tag modify job.
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Job that modifies a tag in the Akonadi storage.
Definition: tagmodifyjob.h:23
An Akonadi Tag.
Definition: tag.h:26
Tag tag() const
Returns the modified tag.
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...
void doStart() override
This method must be reimplemented in the concrete jobs.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 23:16:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.