Akonadi

tagcreatejob.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Christian Mollekopf <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "tagcreatejob.h"
8 #include "akonadicore_debug.h"
9 #include "job_p.h"
10 #include "protocolhelper_p.h"
11 #include "tag.h"
12 #include <KLocalizedString>
13 
14 using namespace Akonadi;
15 
16 class Akonadi::TagCreateJobPrivate : public JobPrivate
17 {
18 public:
19  explicit TagCreateJobPrivate(TagCreateJob *parent)
20  : JobPrivate(parent)
21  {
22  }
23 
24  Tag mTag;
25  Tag mResultTag;
26  bool mMerge = false;
27 };
28 
30  : Job(new TagCreateJobPrivate(this), parent)
31 {
33  d->mTag = tag;
34 }
35 
37 {
39  d->mMerge = merge;
40 }
41 
43 {
45 
46  if (d->mTag.gid().isEmpty()) {
47  qCWarning(AKONADICORE_LOG) << "The gid of a new tag must not be empty";
49  setErrorText(i18n("Failed to create tag."));
50  emitResult();
51  return;
52  }
53 
54  auto cmd = Protocol::CreateTagCommandPtr::create();
55  cmd->setGid(d->mTag.gid());
56  cmd->setMerge(d->mMerge);
57  cmd->setType(d->mTag.type());
58  cmd->setRemoteId(d->mTag.remoteId());
59  cmd->setParentId(d->mTag.parent().id());
60  cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mTag));
61  d->sendCommand(cmd);
62 }
63 
64 bool TagCreateJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
65 {
67 
68  if (response->isResponse() && response->type() == Protocol::Command::FetchTags) {
69  d->mResultTag = ProtocolHelper::parseTagFetchResult(Protocol::cmdCast<Protocol::FetchTagsResponse>(response));
70  return false;
71  }
72 
73  if (response->isResponse() && response->type() == Protocol::Command::CreateTag) {
74  return true;
75  }
76 
77  return Job::doHandleResponse(tag, response);
78 }
79 
81 {
82  Q_D(const TagCreateJob);
83  return d->mResultTag;
84 }
@ Unknown
Unknown error.
Definition: job.h:102
TagCreateJob(const Tag &tag, QObject *parent=nullptr)
Creates a new tag create job.
void setErrorText(const QString &errorText)
An Akonadi Tag.
Definition: tag.h:25
Tag tag() const
Returns the created tag with the new unique id, or an invalid tag if the job failed.
QString i18n(const char *text, const TYPE &arg...)
Base class for all actions in the Akonadi storage.
Definition: job.h:80
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 setMergeIfExisting(bool merge)
Merges the tag by GID if it is already existing, and returns the merged version.
void doStart() override
This method must be reimplemented in the concrete jobs.
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
void emitResult()
void setError(int errorCode)
Q_D(Todo)
Helper integration between Akonadi and Qt.
Job that creates a new tag in the Akonadi storage.
Definition: tagcreatejob.h:21
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Jul 1 2022 05:22:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.