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 "job_p.h"
9 #include "tag.h"
10 #include "protocolhelper_p.h"
11 #include "akonadicore_debug.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 {
32  Q_D(TagCreateJob);
33  d->mTag = tag;
34 }
35 
37 {
38  Q_D(TagCreateJob);
39  d->mMerge = merge;
40 }
41 
43 {
44  Q_D(TagCreateJob);
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 
65 {
66  Q_D(TagCreateJob);
67 
68  if (response->isResponse() && response->type() == Protocol::Command::FetchTags) {
69  d->mResultTag = ProtocolHelper::parseTagFetchResult(
70  Protocol::cmdCast<Protocol::FetchTagsResponse>(response));
71  return false;
72  }
73 
74  if (response->isResponse() && response->type() == Protocol::Command::CreateTag) {
75  return true;
76  }
77 
78  return Job::doHandleResponse(tag, response);
79 }
80 
82 {
83  Q_D(const TagCreateJob);
84  return d->mResultTag;
85 }
Tag tag() const
Returns the created tag with the new unique id, or an invalid tag if the job failed.
TagCreateJob(const Tag &tag, QObject *parent=nullptr)
Creates a new tag create job.
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()
Unknown error.
Definition: job.h:102
void setError(int errorCode)
Base class for all actions in the Akonadi storage.
Definition: job.h:80
void setErrorText(const QString &errorText)
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.
QString i18n(const char *text, const TYPE &arg...)
void doStart() override
This method must be reimplemented in the concrete jobs.
Helper integration between Akonadi and Qt.
Job that creates a new tag in the Akonadi storage.
Definition: tagcreatejob.h:23
An Akonadi Tag.
Definition: tag.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Sep 20 2020 23:16:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.