File indexing completed on 2024-11-10 04:40:31
0001 /* 0002 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "relationcreatejob.h" 0008 #include "akonadicore_debug.h" 0009 #include "job_p.h" 0010 #include "private/protocol_p.h" 0011 #include "protocolhelper_p.h" 0012 #include "relation.h" 0013 #include <KLocalizedString> 0014 0015 using namespace Akonadi; 0016 0017 class Akonadi::RelationCreateJobPrivate : public JobPrivate 0018 { 0019 public: 0020 explicit RelationCreateJobPrivate(RelationCreateJob *parent) 0021 : JobPrivate(parent) 0022 { 0023 } 0024 0025 Relation mRelation; 0026 }; 0027 0028 RelationCreateJob::RelationCreateJob(const Akonadi::Relation &relation, QObject *parent) 0029 : Job(new RelationCreateJobPrivate(this), parent) 0030 { 0031 Q_D(RelationCreateJob); 0032 d->mRelation = relation; 0033 } 0034 0035 void RelationCreateJob::doStart() 0036 { 0037 Q_D(RelationCreateJob); 0038 0039 if (!d->mRelation.isValid()) { 0040 qCWarning(AKONADICORE_LOG) << "The relation is invalid"; 0041 setError(Job::Unknown); 0042 setErrorText(i18n("Failed to create relation.")); 0043 emitResult(); 0044 return; 0045 } 0046 0047 d->sendCommand( 0048 Protocol::ModifyRelationCommandPtr::create(d->mRelation.left().id(), d->mRelation.right().id(), d->mRelation.type(), d->mRelation.remoteId())); 0049 } 0050 0051 bool RelationCreateJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) 0052 { 0053 if (!response->isResponse() || response->type() != Protocol::Command::ModifyRelation) { 0054 return Job::doHandleResponse(tag, response); 0055 } 0056 0057 return true; 0058 } 0059 0060 Relation RelationCreateJob::relation() const 0061 { 0062 Q_D(const RelationCreateJob); 0063 return d->mRelation; 0064 } 0065 0066 #include "moc_relationcreatejob.cpp"