Akonadi

collectioncreatejob.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "collectioncreatejob.h"
8#include "job_p.h"
9#include "private/protocol_p.h"
10#include "protocolhelper_p.h"
11
12#include <KLocalizedString>
13
14using namespace Akonadi;
15
16class Akonadi::CollectionCreateJobPrivate : public JobPrivate
17{
18public:
19 explicit CollectionCreateJobPrivate(CollectionCreateJob *parent)
20 : JobPrivate(parent)
21 {
22 }
23
24 QString jobDebuggingString() const override;
25 Collection mCollection;
26};
27
28QString Akonadi::CollectionCreateJobPrivate::jobDebuggingString() const
29{
30 return QStringLiteral("Create collection: %1").arg(mCollection.id());
31}
32
34 : Job(new CollectionCreateJobPrivate(this), parent)
35{
37
38 d->mCollection = collection;
39}
40
44
46{
48 if (d->mCollection.parentCollection().id() < 0 && d->mCollection.parentCollection().remoteId().isEmpty()) {
50 setErrorText(i18n("Invalid parent"));
51 emitResult();
52 return;
53 }
54
55 auto cmd = Protocol::CreateCollectionCommandPtr::create();
56 cmd->setName(d->mCollection.name());
57 cmd->setParent(ProtocolHelper::entityToScope(d->mCollection.parentCollection()));
58 cmd->setMimeTypes(d->mCollection.contentMimeTypes());
59 cmd->setRemoteId(d->mCollection.remoteId());
60 cmd->setRemoteRevision(d->mCollection.remoteRevision());
61 cmd->setIsVirtual(d->mCollection.isVirtual());
62 cmd->setEnabled(d->mCollection.enabled());
63 cmd->setDisplayPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListDisplay)));
64 cmd->setSyncPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListSync)));
65 cmd->setIndexPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListIndex)));
66 cmd->setCachePolicy(ProtocolHelper::cachePolicyToProtocol(d->mCollection.cachePolicy()));
67 Protocol::Attributes attrs;
68 const Akonadi::Attribute::List attrList = d->mCollection.attributes();
69 for (Attribute *attr : attrList) {
70 attrs.insert(attr->type(), attr->serialized());
71 }
72 cmd->setAttributes(attrs);
73
74 d->sendCommand(cmd);
76}
77
79{
81
82 return d->mCollection;
83}
84
86{
88
89 if (!response->isResponse()) {
90 return Job::doHandleResponse(tag, response);
91 }
92
93 if (response->type() == Protocol::Command::FetchCollections) {
94 const auto &resp = Protocol::cmdCast<Protocol::FetchCollectionsResponse>(response);
95 Collection col = ProtocolHelper::parseCollection(resp);
96 if (!col.isValid()) {
98 setErrorText(i18n("Failed to parse Collection from response"));
99 return true;
100 }
101 col.setParentCollection(d->mCollection.parentCollection());
102 col.setName(d->mCollection.name());
103 col.setRemoteId(d->mCollection.remoteId());
104 col.setRemoteRevision(d->mCollection.remoteRevision());
105 col.setVirtual(d->mCollection.isVirtual());
106 d->mCollection = col;
107 return false;
108 }
109
110 if (response->type() == Protocol::Command::CreateCollection) {
111 return true;
112 }
113
114 return Job::doHandleResponse(tag, response);
115}
116
117#include "moc_collectioncreatejob.cpp"
Provides interface for custom attributes for Entity.
Definition attribute.h:132
Job that creates a new collection in the Akonadi storage.
Collection collection() const
Returns the created collection if the job was executed successfully.
CollectionCreateJob(const Collection &collection, QObject *parent=nullptr)
Creates a new collection create job.
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.
~CollectionCreateJob() override
Destroys the collection create job.
void doStart() override
This method must be reimplemented in the concrete jobs.
Represents a collection of PIM items.
Definition collection.h:62
void setVirtual(bool isVirtual)
Sets whether the collection is virtual or not.
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
@ ListSync
Listing for synchronization.
Definition collection.h:480
@ ListIndex
Listing for indexing the content.
Definition collection.h:482
@ ListDisplay
Listing for display to the user.
Definition collection.h:481
void setName(const QString &name)
Sets the i18n'ed name of the collection.
void setRemoteId(const QString &id)
Sets the remote id of the collection.
void setRemoteRevision(const QString &revision)
Sets the remote revision of the collection.
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
void emitWriteFinished()
Call this method to indicate that this job will not call writeData() again.
Definition job.cpp:409
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.
QString arg(Args &&... args) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.