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

akonadi

  • akonadi
collectionmodifyjob.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 "collectionmodifyjob.h"
21 
22 #include "changemediator_p.h"
23 #include "collection_p.h"
24 #include "collectionstatistics.h"
25 #include "imapparser_p.h"
26 #include "job_p.h"
27 #include "protocolhelper_p.h"
28 
29 #include <akonadi/private/protocol_p.h>
30 
31 
32 using namespace Akonadi;
33 
34 class Akonadi::CollectionModifyJobPrivate : public JobPrivate
35 {
36  public:
37  CollectionModifyJobPrivate( CollectionModifyJob *parent )
38  : JobPrivate( parent )
39  {
40  }
41 
42  virtual QString jobDebuggingString() const
43  {
44  return QString::fromLatin1( "Collection Id %1" ).arg( mCollection.id() );
45  }
46 
47  Collection mCollection;
48 };
49 
50 CollectionModifyJob::CollectionModifyJob( const Collection &collection, QObject * parent )
51  : Job( new CollectionModifyJobPrivate( this ), parent )
52 {
53  Q_D( CollectionModifyJob );
54  d->mCollection = collection;
55 }
56 
57 CollectionModifyJob::~CollectionModifyJob()
58 {
59 }
60 
61 void CollectionModifyJob::doStart()
62 {
63  Q_D( CollectionModifyJob );
64  QByteArray command = d->newTag();
65  try {
66  command += ProtocolHelper::entityIdToByteArray( d->mCollection, AKONADI_CMD_COLLECTIONMODIFY );
67  } catch ( const std::exception &e ) {
68  setError( Job::Unknown );
69  setErrorText( QString::fromUtf8( e.what() ) );
70  emitResult();
71  return;
72  }
73 
74  QByteArray changes;
75  if ( d->mCollection.d_func()->contentTypesChanged ) {
76  QList<QByteArray> bList;
77  foreach ( const QString &s, d->mCollection.contentMimeTypes() ) {
78  bList << s.toLatin1();
79  }
80  changes += " MIMETYPE (" + ImapParser::join( bList, " " ) + ')';
81  }
82  if ( d->mCollection.parentCollection().id() >= 0 ) {
83  changes += " PARENT " + QByteArray::number( d->mCollection.parentCollection().id() );
84  }
85  if ( !d->mCollection.name().isEmpty() ) {
86  changes += " NAME " + ImapParser::quote( d->mCollection.name().toUtf8() );
87  }
88  if ( !d->mCollection.remoteId().isNull() ) {
89  changes += " REMOTEID " + ImapParser::quote( d->mCollection.remoteId().toUtf8() );
90  }
91  if ( !d->mCollection.remoteRevision().isNull() ) {
92  changes += " REMOTEREVISION " + ImapParser::quote( d->mCollection.remoteRevision().toUtf8() );
93  }
94  if ( d->mCollection.d_func()->cachePolicyChanged ) {
95  changes += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() );
96  }
97  if ( d->mCollection.attributes().count() > 0 ) {
98  changes += ' ' + ProtocolHelper::attributesToByteArray( d->mCollection );
99  }
100  foreach ( const QByteArray &b, d->mCollection.d_func()->mDeletedAttributes ) {
101  changes += " -" + b;
102  }
103  if ( changes.isEmpty() ) {
104  emitResult();
105  return;
106  }
107  command += changes + '\n';
108  d->writeData( command );
109 
110  ChangeMediator::invalidateCollection( d->mCollection );
111 }
112 
113 Collection CollectionModifyJob::collection() const
114 {
115  const Q_D( CollectionModifyJob );
116  return d->mCollection;
117 }
118 
Akonadi::CollectionModifyJob
Job that modifies a collection in the Akonadi storage.
Definition: collectionmodifyjob.h:82
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:109
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:206
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
Akonadi::CollectionModifyJob::CollectionModifyJob
CollectionModifyJob(const Collection &collection, QObject *parent=0)
Creates a new collection modify job for the given collection.
Definition: collectionmodifyjob.cpp:50
Akonadi::CollectionModifyJob::collection
Collection collection() const
Returns the modified collection.
Definition: collectionmodifyjob.cpp:113
Akonadi::CollectionModifyJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: collectionmodifyjob.cpp:61
Akonadi::CollectionModifyJob::~CollectionModifyJob
~CollectionModifyJob()
Destroys the collection modify job.
Definition: collectionmodifyjob.cpp:57
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::ProtocolHelper::entityIdToByteArray
static QByteArray entityIdToByteArray(const T &object, const QByteArray &command)
Converts the given object identifier into a protocol representation.
Definition: protocolhelper_p.h:200
Akonadi::ProtocolHelper::cachePolicyToByteArray
static QByteArray cachePolicyToByteArray(const CachePolicy &policy)
Convert a cache policy object into its protocol representation.
Definition: protocolhelper.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:51 by doxygen 1.8.6 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-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 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
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