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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 #include <KLocalizedString>
32 
33 using namespace Akonadi;
34 
35 class Akonadi::CollectionModifyJobPrivate : public JobPrivate
36 {
37  public:
38  CollectionModifyJobPrivate( CollectionModifyJob *parent )
39  : JobPrivate( parent )
40  {
41  }
42 
43  virtual QString jobDebuggingString() const
44  {
45  return QString::fromLatin1( "Collection Id %1" ).arg( mCollection.id() );
46  }
47 
48  Collection mCollection;
49 };
50 
51 CollectionModifyJob::CollectionModifyJob( const Collection &collection, QObject * parent )
52  : Job( new CollectionModifyJobPrivate( this ), parent )
53 {
54  Q_D( CollectionModifyJob );
55  d->mCollection = collection;
56 }
57 
58 CollectionModifyJob::~CollectionModifyJob()
59 {
60 }
61 
62 void CollectionModifyJob::doStart()
63 {
64  Q_D( CollectionModifyJob );
65  QByteArray command = d->newTag();
66  try {
67  command += ProtocolHelper::entityIdToByteArray( d->mCollection, AKONADI_CMD_COLLECTIONMODIFY );
68  } catch ( const std::exception &e ) {
69  setError( Job::Unknown );
70  setErrorText( QString::fromUtf8( e.what() ) );
71  emitResult();
72  return;
73  }
74 
75  QByteArray changes;
76  if ( d->mCollection.d_func()->contentTypesChanged ) {
77  QList<QByteArray> bList;
78  foreach ( const QString &s, d->mCollection.contentMimeTypes() ) {
79  bList << s.toLatin1();
80  }
81  changes += " MIMETYPE (" + ImapParser::join( bList, " " ) + ')';
82  }
83  if ( d->mCollection.parentCollection().id() >= 0 ) {
84  changes += " PARENT " + QByteArray::number( d->mCollection.parentCollection().id() );
85  }
86  if ( !d->mCollection.name().isEmpty() ) {
87  changes += " NAME " + ImapParser::quote( d->mCollection.name().toUtf8() );
88  }
89  if ( !d->mCollection.remoteId().isNull() ) {
90  changes += " REMOTEID " + ImapParser::quote( d->mCollection.remoteId().toUtf8() );
91  }
92  if ( !d->mCollection.remoteRevision().isNull() ) {
93  changes += " REMOTEREVISION " + ImapParser::quote( d->mCollection.remoteRevision().toUtf8() );
94  }
95  if ( d->mCollection.d_func()->cachePolicyChanged ) {
96  changes += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() );
97  }
98  if ( d->mCollection.attributes().count() > 0 ) {
99  changes += ' ' + ProtocolHelper::attributesToByteArray( d->mCollection );
100  }
101  foreach ( const QByteArray &b, d->mCollection.d_func()->mDeletedAttributes ) {
102  changes += " -" + b;
103  }
104  if ( changes.isEmpty() ) {
105  emitResult();
106  return;
107  }
108  command += changes + '\n';
109  d->writeData( command );
110 
111  ChangeMediator::invalidateCollection( d->mCollection );
112 }
113 
114 Collection CollectionModifyJob::collection() const
115 {
116  const Q_D( CollectionModifyJob );
117  return d->mCollection;
118 }
119 
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:51
Akonadi::CollectionModifyJob::collection
Collection collection() const
Returns the modified collection.
Definition: collectionmodifyjob.cpp:114
Akonadi::CollectionModifyJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: collectionmodifyjob.cpp:62
Akonadi::CollectionModifyJob::~CollectionModifyJob
~CollectionModifyJob()
Destroys the collection modify job.
Definition: collectionmodifyjob.cpp:58
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:194
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 Tue Oct 14 2014 23:00:26 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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