Akonadi

relationcreatejob.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 "relationcreatejob.h"
21 #include "job_p.h"
22 #include "relation.h"
23 #include "protocolhelper_p.h"
24 #include "private/protocol_p.h"
25 #include "akonadicore_debug.h"
26 #include <KLocalizedString>
27 
28 using namespace Akonadi;
29 
30 class Akonadi::RelationCreateJobPrivate : public JobPrivate
31 {
32 public:
33  RelationCreateJobPrivate(RelationCreateJob *parent)
34  : JobPrivate(parent)
35  {
36  }
37 
38  Relation mRelation;
39 };
40 
42  : Job(new RelationCreateJobPrivate(this), parent)
43 {
44  Q_D(RelationCreateJob);
45  d->mRelation = relation;
46 }
47 
49 {
50  Q_D(RelationCreateJob);
51 
52  if (!d->mRelation.isValid()) {
53  qCWarning(AKONADICORE_LOG) << "The relation is invalid";
55  setErrorText(i18n("Failed to create relation."));
56  emitResult();
57  return;
58  }
59 
60  d->sendCommand(Protocol::ModifyRelationCommandPtr::create(d->mRelation.left().id(),
61  d->mRelation.right().id(),
62  d->mRelation.type(),
63  d->mRelation.remoteId()));
64 }
65 
67 {
68  if (!response->isResponse() || response->type() != Protocol::Command::ModifyRelation) {
69  return Job::doHandleResponse(tag, response);
70  }
71 
72  return true;
73 }
74 
76 {
77  Q_D(const RelationCreateJob);
78  return d->mRelation;
79 }
An Akonadi Relation.
Definition: relation.h:52
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
Relation relation() const
Returns the relation.
void setError(int errorCode)
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...
Base class for all actions in the Akonadi storage.
Definition: job.h:93
void setErrorText(const QString &errorText)
RelationCreateJob(const Relation &relation, QObject *parent=nullptr)
Creates a new relation create job.
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
Job that creates a new relation in the Akonadi storage.
void doStart() override
This method must be reimplemented in the concrete jobs.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.