Akonadi

collectioncreatejob.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Volker Krause <[email protected]>
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 
14 using namespace Akonadi;
15 
16 class Akonadi::CollectionCreateJobPrivate : public JobPrivate
17 {
18 public:
19  explicit CollectionCreateJobPrivate(CollectionCreateJob *parent)
20  : JobPrivate(parent)
21  {
22  }
23 
24  QString jobDebuggingString() const override;
25  Collection mCollection;
26 };
27 
28 QString 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 
42 {
43 }
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 {
80  Q_D(const CollectionCreateJob);
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 }
void emitWriteFinished()
Call this method to indicate that this job will not call writeData() again.
Definition: job.cpp:409
@ Unknown
Unknown error.
Definition: job.h:102
void setErrorText(const QString &errorText)
Represents a collection of PIM items.
Definition: collection.h:61
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.
Provides interface for custom attributes for Entity.
Definition: attribute.h:124
Definition: item.h:32
CollectionCreateJob(const Collection &collection, QObject *parent=nullptr)
Creates a new collection create job.
Collection collection() const
Returns the created collection if the job was executed successfully.
QString i18n(const char *text, const TYPE &arg...)
@ ListDisplay
Listing for display to the user.
Definition: collection.h:477
void setRemoteId(const QString &id)
Sets the remote id of the collection.
Definition: collection.cpp:101
void doStart() override
This method must be reimplemented in the concrete jobs.
Base class for all actions in the Akonadi storage.
Definition: job.h:80
@ ListSync
Listing for synchronization.
Definition: collection.h:476
void insert(int i, const T &value)
void setVirtual(bool isVirtual)
Sets whether the collection is virtual or not.
Definition: collection.cpp:352
~CollectionCreateJob() override
Destroys the collection create job.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
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
@ ListIndex
Listing for indexing the content.
Definition: collection.h:478
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: collection.cpp:204
Job that creates a new collection in the Akonadi storage.
void emitResult()
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:221
void setError(int errorCode)
void setRemoteRevision(const QString &revision)
Sets the remote revision of the collection.
Definition: collection.cpp:111
Q_D(Todo)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.