• 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
protocolhelper_p.h
1 /*
2  Copyright (c) 2008 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 #ifndef AKONADI_PROTOCOLHELPER_P_H
21 #define AKONADI_PROTOCOLHELPER_P_H
22 
23 #include <akonadi/cachepolicy.h>
24 #include <akonadi/collection.h>
25 #include <akonadi/collectionutils_p.h>
26 #include <akonadi/item.h>
27 #include <akonadi/itemfetchscope.h>
28 #include <akonadi/sharedvaluepool_p.h>
29 
30 #include <akonadi/private/imapparser_p.h>
31 #include <akonadi/private/protocol_p.h>
32 
33 #include <boost/bind.hpp>
34 #include <algorithm>
35 
36 namespace Akonadi {
37 
38 struct ProtocolHelperValuePool
39 {
40  typedef Internal::SharedValuePool<QByteArray, QVector> FlagPool;
41  typedef Internal::SharedValuePool<QString, QVector> MimeTypePool;
42 
43  FlagPool flagPool;
44  MimeTypePool mimeTypePool;
45  QHash<Collection::Id, Collection> ancestorCollections;
46 };
47 
56 class ProtocolHelper
57 {
58  public:
60  enum PartNamespace {
61  PartGlobal,
62  PartPayload,
63  PartAttribute
64  };
65 
73  static int parseCachePolicy( const QByteArray &data, CachePolicy &policy, int start = 0 );
74 
78  static QByteArray cachePolicyToByteArray( const CachePolicy &policy );
79 
83  static void parseAncestors( const QByteArray &data, Entity *entity, int start = 0 );
84 
91  static void parseAncestorsCached( const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0, int start = 0 );
92 
100  static int parseCollection( const QByteArray &data, Collection &collection, int start = 0 );
101 
105  static QByteArray attributesToByteArray( const Entity &entity, bool ns = false );
106 
110  static QByteArray encodePartIdentifier( PartNamespace ns, const QByteArray &label, int version = 0 );
111 
115  static QByteArray decodePartIdentifier( const QByteArray &data, PartNamespace &ns );
116 
121  template <typename T>
122  static QByteArray entitySetToByteArray( const QList<T> &_objects, const QByteArray &command )
123  {
124  if ( _objects.isEmpty() )
125  throw Exception( "No objects specified" );
126 
127  typename T::List objects( _objects );
128 
129  QByteArray rv;
130  std::sort( objects.begin(), objects.end(), boost::bind( &T::id, _1 ) < boost::bind( &T::id, _2 ) );
131  if ( objects.first().isValid() ) {
132  // all items have a uid set
133  rv += " " AKONADI_CMD_UID " ";
134  if ( !command.isEmpty() ) {
135  rv += command;
136  rv += ' ';
137  }
138  QVector<typename T::Id> uids;
139  foreach ( const T &object, objects )
140  uids << object.id();
141  ImapSet set;
142  set.add( uids );
143  rv += set.toImapSequenceSet();
144  return rv;
145  }
146 
147  // check if all items have a remote id
148  if ( std::find_if( objects.constBegin(), objects.constEnd(),
149  boost::bind( &QString::isEmpty, boost::bind( &T::remoteId, _1 ) ) )
150  != objects.constEnd() )
151  {
152  throw Exception( "No remote identifier specified" );
153  }
154 
155  // check if we have RIDs or HRIDs
156  if ( std::find_if( objects.constBegin(), objects.constEnd(),
157  !boost::bind( static_cast<bool (*)(const T&)>( &CollectionUtils::hasValidHierarchicalRID ), _1 ) )
158  == objects.constEnd() && objects.size() == 1 ) // ### HRID sets are not yet specified
159  {
160  // HRIDs
161  rv += " " AKONADI_CMD_HRID " ";
162  if ( !command.isEmpty() ) {
163  rv += command;
164  rv += ' ';
165  }
166  rv += '(' + hierarchicalRidToByteArray( objects.first() ) + ')';
167  return rv;
168  }
169 
170  // RIDs
171  QList<QByteArray> rids;
172  foreach ( const T &object, objects ) {
173  rids << ImapParser::quote( object.remoteId().toUtf8() );
174  }
175 
176  rv += " " AKONADI_CMD_RID " ";
177  if ( !command.isEmpty() ) {
178  rv += command;
179  rv += ' ';
180  }
181  rv += '(';
182  rv += ImapParser::join( rids, " " );
183  rv += ')';
184  return rv;
185  }
186 
187  static QByteArray entitySetToByteArray( const QList<Akonadi::Item> &_objects, const QByteArray &command );
188 
193  template <typename T>
194  static QByteArray entityIdToByteArray( const T &object, const QByteArray &command )
195  {
196  return entitySetToByteArray( typename T::List() << object, command );
197  }
198 
203  static QByteArray hierarchicalRidToByteArray( const Collection &col );
204 
209  static QByteArray hierarchicalRidToByteArray( const Item &item );
210 
214  static QByteArray itemFetchScopeToByteArray( const ItemFetchScope &fetchScope );
215 
219  static void parseItemFetchResult( const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0 );
220 };
221 
222 }
223 
224 #endif
Akonadi::ProtocolHelper::parseCachePolicy
static int parseCachePolicy(const QByteArray &data, CachePolicy &policy, int start=0)
Parse a cache policy definition.
Definition: protocolhelper.cpp:38
Akonadi::ProtocolHelper::itemFetchScopeToByteArray
static QByteArray itemFetchScopeToByteArray(const ItemFetchScope &fetchScope)
Converts a given ItemFetchScope object into a protocol representation.
Definition: protocolhelper.cpp:298
Akonadi::ProtocolHelper::entitySetToByteArray
static QByteArray entitySetToByteArray(const QList< T > &_objects, const QByteArray &command)
Converts the given set of items into a protocol representation.
Definition: protocolhelper_p.h:122
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:206
Akonadi::ProtocolHelper
Definition: protocolhelper_p.h:56
Akonadi::ProtocolHelper::parseCollection
static int parseCollection(const QByteArray &data, Collection &collection, int start=0)
Parse a collection description.
Definition: protocolhelper.cpp:129
Akonadi::ProtocolHelper::hierarchicalRidToByteArray
static QByteArray hierarchicalRidToByteArray(const Collection &col)
Converts the given collection's hierarchical RID into a protocol representation.
Definition: protocolhelper.cpp:282
Akonadi::ProtocolHelper::encodePartIdentifier
static QByteArray encodePartIdentifier(PartNamespace ns, const QByteArray &label, int version=0)
Encodes part label and namespace.
Definition: protocolhelper.cpp:216
Akonadi::ProtocolHelper::PartNamespace
PartNamespace
Part namespaces.
Definition: protocolhelper_p.h:60
Akonadi::CachePolicy
Represents the caching policy for a collection.
Definition: cachepolicy.h:71
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:68
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:59
Akonadi::ProtocolHelper::parseAncestors
static void parseAncestors(const QByteArray &data, Entity *entity, int start=0)
Convert a ancestor chain from its protocol representation into an Entity object.
Definition: protocolhelper.cpp:101
Akonadi::Exception
Base class for exceptions used by the Akonadi library.
Definition: exception.h:35
Akonadi::ProtocolHelper::decodePartIdentifier
static QByteArray decodePartIdentifier(const QByteArray &data, PartNamespace &ns)
Decode part label and namespace.
Definition: protocolhelper.cpp:232
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::parseAncestorsCached
static void parseAncestorsCached(const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool=0, int start=0)
Convert a ancestor chain from its protocol representation into an Entity object.
Definition: protocolhelper.cpp:82
Akonadi::ProtocolHelper::parseItemFetchResult
static void parseItemFetchResult(const QList< QByteArray > &lineTokens, Item &item, ProtocolHelperValuePool *valuePool=0)
Parses a single line from an item fetch job result into an Item object.
Definition: protocolhelper.cpp:347
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:27 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