• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
collectioncreatejob.cpp
1 /*
2  Copyright (c) 2006 Volker Krause <vkrause@kde.org>
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 "collectioncreatejob.h"
21 #include "imapparser_p.h"
22 #include "protocolhelper_p.h"
23 
24 #include "job_p.h"
25 
26 #include <kdebug.h>
27 #include <KLocalizedString>
28 using namespace Akonadi;
29 
30 class Akonadi::CollectionCreateJobPrivate : public JobPrivate
31 {
32 public:
33  CollectionCreateJobPrivate(CollectionCreateJob *parent)
34  : JobPrivate(parent)
35  {
36  }
37 
38  Collection mCollection;
39 };
40 
41 CollectionCreateJob::CollectionCreateJob(const Collection &collection, QObject *parent)
42  : Job(new CollectionCreateJobPrivate(this), parent)
43 {
44  Q_D(CollectionCreateJob);
45 
46  d->mCollection = collection;
47 }
48 
49 CollectionCreateJob::~CollectionCreateJob()
50 {
51 }
52 
53 void CollectionCreateJob::doStart()
54 {
55  Q_D(CollectionCreateJob);
56  if (d->mCollection.parentCollection().id() < 0 && d->mCollection.parentCollection().remoteId().isEmpty()) {
57  setError(Unknown);
58  setErrorText(i18n("Invalid parent"));
59  emitResult();
60  return;
61  }
62 
63  QByteArray command = d->newTag();
64  if (d->mCollection.parentCollection().id() < 0) {
65  command += " RID";
66  }
67  command += " CREATE " + ImapParser::quote(d->mCollection.name().toUtf8()) + ' ';
68  if (d->mCollection.parentCollection().id() >= 0) {
69  command += QByteArray::number(d->mCollection.parentCollection().id());
70  } else {
71  command += ImapParser::quote(d->mCollection.parentCollection().remoteId().toUtf8());
72  }
73  command += " (";
74  if (!d->mCollection.contentMimeTypes().isEmpty()) {
75  QList<QByteArray> cList;
76  foreach (const QString &s, d->mCollection.contentMimeTypes()) {
77  cList << s.toLatin1();
78  }
79  command += "MIMETYPE (" + ImapParser::join(cList, QByteArray(" ")) + ')';
80  }
81  command += " REMOTEID " + ImapParser::quote(d->mCollection.remoteId().toUtf8());
82  command += " REMOTEREVISION " + ImapParser::quote(d->mCollection.remoteRevision().toUtf8());
83  command += " VIRTUAL " + QByteArray::number(d->mCollection.isVirtual());
84  command += ' ' + ProtocolHelper::enabled(d->mCollection.enabled());
85  command += ' ' + ProtocolHelper::listPreference(Collection::ListDisplay, d->mCollection.localListPreference(Collection::ListDisplay));
86  command += ' ' + ProtocolHelper::listPreference(Collection::ListSync, d->mCollection.localListPreference(Collection::ListSync));
87  command += ' ' + ProtocolHelper::listPreference(Collection::ListIndex, d->mCollection.localListPreference(Collection::ListIndex));
88  foreach (Attribute *attr, d->mCollection.attributes()) {
89  command += ' ' + attr->type() + ' ' + ImapParser::quote(attr->serialized());
90  }
91  command += ' ' + ProtocolHelper::cachePolicyToByteArray(d->mCollection.cachePolicy());
92  command += ")\n";
93  d->writeData(command);
94  emitWriteFinished();
95 }
96 
97 Collection CollectionCreateJob::collection() const
98 {
99  Q_D(const CollectionCreateJob);
100 
101  return d->mCollection;
102 }
103 
104 void CollectionCreateJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
105 {
106  Q_D(CollectionCreateJob);
107 
108  if (tag == "*") {
109  Collection col;
110  ProtocolHelper::parseCollection(data, col);
111  if (!col.isValid()) {
112  return;
113  }
114 
115  col.setParentCollection(d->mCollection.parentCollection());
116  col.setName(d->mCollection.name());
117  col.setRemoteId(d->mCollection.remoteId());
118  col.setRemoteRevision(d->mCollection.remoteRevision());
119  col.setVirtual(d->mCollection.isVirtual());
120  d->mCollection = col;
121  } else {
122  Job::doHandleResponse(tag, data);
123  }
124 }
Akonadi::CollectionCreateJob::doHandleResponse
virtual void doHandleResponse(const QByteArray &tag, const QByteArray &data)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data...
Definition: collectioncreatejob.cpp:104
QByteArray
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:108
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
Akonadi::Collection::ListDisplay
Listing for display to the user.
Definition: collection.h:337
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
Akonadi::Collection::ListIndex
Listing for indexing the content.
Definition: collection.h:338
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::Entity::setParentCollection
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: entity.cpp:194
Akonadi::ProtocolHelper::parseCollection
static int parseCollection(const QByteArray &data, Collection &collection, int start=0)
Parse a collection description.
Definition: protocolhelper.cpp:145
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
Akonadi::Collection::setVirtual
void setVirtual(bool isVirtual)
Sets whether the collection is virtual or not.
Definition: collection.cpp:266
Akonadi::CollectionCreateJob::CollectionCreateJob
CollectionCreateJob(const Collection &collection, QObject *parent=0)
Creates a new collection create job.
Definition: collectioncreatejob.cpp:41
Akonadi::Entity::setRemoteRevision
void setRemoteRevision(const QString &revision)
Sets the remote revision of the entity.
Definition: entity.cpp:87
QObject
QByteArray::number
QByteArray number(int n, int base)
Akonadi::CollectionCreateJob::~CollectionCreateJob
virtual ~CollectionCreateJob()
Destroys the collection create job.
Definition: collectioncreatejob.cpp:49
Akonadi::Job::emitWriteFinished
void emitWriteFinished()
Call this method to indicate that this job will not call writeData() again.
Definition: job.cpp:370
QString
QList< QByteArray >
Akonadi::Job::doHandleResponse
virtual void doHandleResponse(const QByteArray &tag, const QByteArray &data)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data...
Definition: job.cpp:348
QString::toLatin1
QByteArray toLatin1() const
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::Attribute::serialized
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
Akonadi::CollectionCreateJob
Job that creates a new collection in the Akonadi storage.
Definition: collectioncreatejob.h:52
Akonadi::CollectionCreateJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: collectioncreatejob.cpp:53
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
Akonadi::Collection::ListSync
Listing for synchronization.
Definition: collection.h:336
Akonadi::ProtocolHelper::cachePolicyToByteArray
static QByteArray cachePolicyToByteArray(const CachePolicy &policy)
Convert a cache policy object into its protocol representation.
Definition: protocolhelper.cpp:71
Akonadi::CollectionCreateJob::collection
Collection collection() const
Returns the created collection if the job was executed successfully.
Definition: collectioncreatejob.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal