Akonadi

tagcreatejob.cpp
1 /*
2  Copyright (c) 2014 Christian Mollekopf <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "tagcreatejob.h"
21 #include "job_p.h"
22 #include "tag.h"
23 #include "protocolhelper_p.h"
24 #include "akonadicore_debug.h"
25 #include <KLocalizedString>
26 
27 using namespace Akonadi;
28 
29 class Akonadi::TagCreateJobPrivate : public JobPrivate
30 {
31 public:
32  TagCreateJobPrivate(TagCreateJob *parent)
33  : JobPrivate(parent)
34  {
35  }
36 
37  Tag mTag;
38  Tag mResultTag;
39  bool mMerge = false;
40 };
41 
43  : Job(new TagCreateJobPrivate(this), parent)
44 {
45  Q_D(TagCreateJob);
46  d->mTag = tag;
47 }
48 
50 {
51  Q_D(TagCreateJob);
52  d->mMerge = merge;
53 }
54 
56 {
57  Q_D(TagCreateJob);
58 
59  if (d->mTag.gid().isEmpty()) {
60  qCWarning(AKONADICORE_LOG) << "The gid of a new tag must not be empty";
62  setErrorText(i18n("Failed to create tag."));
63  emitResult();
64  return;
65  }
66 
67  auto cmd = Protocol::CreateTagCommandPtr::create();
68  cmd->setGid(d->mTag.gid());
69  cmd->setMerge(d->mMerge);
70  cmd->setType(d->mTag.type());
71  cmd->setRemoteId(d->mTag.remoteId());
72  cmd->setParentId(d->mTag.parent().id());
73  cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mTag));
74  d->sendCommand(cmd);
75 }
76 
78 {
79  Q_D(TagCreateJob);
80 
81  if (response->isResponse() && response->type() == Protocol::Command::FetchTags) {
82  d->mResultTag = ProtocolHelper::parseTagFetchResult(
83  Protocol::cmdCast<Protocol::FetchTagsResponse>(response));
84  return false;
85  }
86 
87  if (response->isResponse() && response->type() == Protocol::Command::CreateTag) {
88  return true;
89  }
90 
91  return Job::doHandleResponse(tag, response);
92 }
93 
95 {
96  Q_D(const TagCreateJob);
97  return d->mResultTag;
98 }
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:385
void emitResult()
Unknown error.
Definition: job.h:115
void setError(int errorCode)
Base class for all actions in the Akonadi storage.
Definition: job.h:93
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:36
An Akonadi Tag.
Definition: tag.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.