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 "protocolhelper_p.h"
10 #include "tag.h"
11 #include "tag_p.h"
12 
13 using namespace Akonadi;
14 
15 class Akonadi::TagModifyJobPrivate : public JobPrivate
16 {
17 public:
18  explicit TagModifyJobPrivate(TagModifyJob *parent)
19  : JobPrivate(parent)
20  {
21  }
22 
23  QString jobDebuggingString() const override;
24  Tag mTag;
25 };
26 
27 QString Akonadi::TagModifyJobPrivate::jobDebuggingString() const
28 {
29  return QStringLiteral("Modify Tag: %1").arg(mTag.name());
30 }
31 
33  : Job(new TagModifyJobPrivate(this), parent)
34 {
36  d->mTag = tag;
37 }
38 
40 {
42 
43  auto cmd = Protocol::ModifyTagCommandPtr::create(d->mTag.id());
44  if (!d->mTag.remoteId().isNull()) {
45  cmd->setRemoteId(d->mTag.remoteId());
46  }
47  if (!d->mTag.type().isEmpty()) {
48  cmd->setType(d->mTag.type());
49  }
50  if (d->mTag.parent().isValid() && !d->mTag.isImmutable()) {
51  cmd->setParentId(d->mTag.parent().id());
52  }
53  if (!d->mTag.d_ptr->mAttributeStorage.deletedAttributes().isEmpty()) {
54  cmd->setRemovedAttributes(d->mTag.d_ptr->mAttributeStorage.deletedAttributes());
55  }
56  if (d->mTag.d_ptr->mAttributeStorage.hasModifiedAttributes()) {
57  cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mTag.d_ptr->mAttributeStorage.modifiedAttributes()));
58  }
59 
60  d->sendCommand(cmd);
61 }
62 
63 bool TagModifyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
64 {
66 
67  if (response->isResponse()) {
68  if (response->type() == Protocol::Command::FetchTags || response->type() == Protocol::Command::DeleteTag) {
69  // Tag was modified, deleted or merged, we ignore the response for now
70  return false;
71  } else if (response->type() == Protocol::Command::ModifyTag) {
72  // Done.
73  d->mTag.d_ptr->resetChangeLog();
74  return true;
75  }
76  }
77 
78  return Job::doHandleResponse(tag, response);
79 }
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-2023 The KDE developers.
Generated on Sun Jun 4 2023 03:52:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.