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 "changemediator_p.h"
9 #include "job_p.h"
10 #include "protocolhelper_p.h"
11 #include "tag.h"
12 #include "tag_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 QString Akonadi::TagModifyJobPrivate::jobDebuggingString() const
29 {
30  return QStringLiteral("Modify Tag: %1").arg(mTag.name());
31 }
32 
34  : Job(new TagModifyJobPrivate(this), parent)
35 {
37  d->mTag = tag;
38 }
39 
41 {
43 
44  auto cmd = Protocol::ModifyTagCommandPtr::create(d->mTag.id());
45  if (!d->mTag.remoteId().isNull()) {
46  cmd->setRemoteId(d->mTag.remoteId());
47  }
48  if (!d->mTag.type().isEmpty()) {
49  cmd->setType(d->mTag.type());
50  }
51  if (d->mTag.parent().isValid() && !d->mTag.isImmutable()) {
52  cmd->setParentId(d->mTag.parent().id());
53  }
54  if (!d->mTag.d_ptr->mAttributeStorage.deletedAttributes().isEmpty()) {
55  cmd->setRemovedAttributes(d->mTag.d_ptr->mAttributeStorage.deletedAttributes());
56  }
57  if (d->mTag.d_ptr->mAttributeStorage.hasModifiedAttributes()) {
58  cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mTag.d_ptr->mAttributeStorage.modifiedAttributes()));
59  }
60 
61  d->sendCommand(cmd);
62 }
63 
64 bool TagModifyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
65 {
67 
68  if (response->isResponse()) {
69  if (response->type() == Protocol::Command::FetchTags || response->type() == Protocol::Command::DeleteTag) {
70  // Tag was modified, deleted or merged, we ignore the response for now
71  return false;
72  } else if (response->type() == Protocol::Command::ModifyTag) {
73  // Done.
74  d->mTag.d_ptr->resetChangeLog();
75  return true;
76  }
77  }
78 
79  return Job::doHandleResponse(tag, response);
80 }
An Akonadi Tag.
Definition: tag.h:25
TagModifyJob(const Tag &tag, QObject *parent=nullptr)
Creates a new tag modify job.
Base class for all actions in the Akonadi storage.
Definition: job.h:80
Tag tag() const
Returns the modified tag.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
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
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.
Q_D(Todo)
Helper integration between Akonadi and Qt.
Job that modifies a tag in the Akonadi storage.
Definition: tagmodifyjob.h:21
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.