Akonadi

tagcreatejob.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
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
14using namespace Akonadi;
15
16class Akonadi::TagCreateJobPrivate : public JobPrivate
17{
18public:
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
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}
85
86#include "moc_tagcreatejob.cpp"
Base class for all actions in the Akonadi storage.
Definition job.h:81
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
@ Unknown
Unknown error.
Definition job.h:102
Job that creates a new tag in the Akonadi storage.
TagCreateJob(const Tag &tag, QObject *parent=nullptr)
Creates a new tag create job.
void setMergeIfExisting(bool merge)
Merges the tag by GID if it is already existing, and returns the merged version.
Tag tag() const
Returns the created tag with the new unique id, or an invalid tag if the job failed.
void doStart() override
This method must be reimplemented in the concrete jobs.
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.
An Akonadi Tag.
Definition tag.h:26
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.