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

akonadi

  • 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 #include <akonadi/attributeentity.h>
30 #include <akonadi/tag.h>
31 
32 #include <akonadi/private/imapparser_p.h>
33 #include <akonadi/private/protocol_p.h>
34 
35 #include <boost/bind.hpp>
36 #include <algorithm>
37 
38 namespace Akonadi {
39 
40 struct ProtocolHelperValuePool
41 {
42  typedef Internal::SharedValuePool<QByteArray, QVector> FlagPool;
43  typedef Internal::SharedValuePool<QString, QVector> MimeTypePool;
44 
45  FlagPool flagPool;
46  MimeTypePool mimeTypePool;
47  QHash<Collection::Id, Collection> ancestorCollections;
48 };
49 
58 class ProtocolHelper
59 {
60  public:
62  enum PartNamespace {
63  PartGlobal,
64  PartPayload,
65  PartAttribute
66  };
67 
75  static int parseCachePolicy( const QByteArray &data, CachePolicy &policy, int start = 0 );
76 
80  static QByteArray cachePolicyToByteArray( const CachePolicy &policy );
81 
85  static void parseAncestors( const QByteArray &data, Entity *entity, int start = 0 );
86 
93  static void parseAncestorsCached( const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0, int start = 0 );
94 
102  static int parseCollection( const QByteArray &data, Collection &collection, int start = 0 );
103 
107  static QByteArray attributesToByteArray( const Entity &entity, bool ns = false );
108  static QByteArray attributesToByteArray( const AttributeEntity &entity, bool ns = false );
109 
113  static QByteArray encodePartIdentifier( PartNamespace ns, const QByteArray &label, int version = 0 );
114 
118  static QByteArray decodePartIdentifier( const QByteArray &data, PartNamespace &ns );
119 
124  template <typename T>
125  static QByteArray entitySetToByteArray( const QList<T> &_objects, const QByteArray &command )
126  {
127  if ( _objects.isEmpty() )
128  throw Exception( "No objects specified" );
129 
130  typename T::List objects( _objects );
131 
132  QByteArray rv;
133  std::sort( objects.begin(), objects.end(), boost::bind( &T::id, _1 ) < boost::bind( &T::id, _2 ) );
134  if ( objects.first().isValid() ) {
135  // all items have a uid set
136  rv += " " AKONADI_CMD_UID " ";
137  if ( !command.isEmpty() ) {
138  rv += command;
139  rv += ' ';
140  }
141  QVector<typename T::Id> uids;
142  foreach ( const T &object, objects )
143  uids << object.id();
144  ImapSet set;
145  set.add( uids );
146  rv += set.toImapSequenceSet();
147  return rv;
148  }
149 
150  // check if all items have a remote id
151  if ( std::find_if( objects.constBegin(), objects.constEnd(),
152  boost::bind( &QString::isEmpty, boost::bind( &T::remoteId, _1 ) ) )
153  != objects.constEnd() )
154  {
155  throw Exception( "No remote identifier specified" );
156  }
157 
158  // check if we have RIDs or HRIDs
159  if ( std::find_if( objects.constBegin(), objects.constEnd(),
160  !boost::bind( static_cast<bool (*)(const T&)>( &CollectionUtils::hasValidHierarchicalRID ), _1 ) )
161  == objects.constEnd() && objects.size() == 1 ) // ### HRID sets are not yet specified
162  {
163  // HRIDs
164  rv += " " AKONADI_CMD_HRID " ";
165  if ( !command.isEmpty() ) {
166  rv += command;
167  rv += ' ';
168  }
169  rv += '(' + hierarchicalRidToByteArray( objects.first() ) + ')';
170  return rv;
171  }
172 
173  // RIDs
174  QList<QByteArray> rids;
175  foreach ( const T &object, objects ) {
176  rids << ImapParser::quote( object.remoteId().toUtf8() );
177  }
178 
179  rv += " " AKONADI_CMD_RID " ";
180  if ( !command.isEmpty() ) {
181  rv += command;
182  rv += ' ';
183  }
184  rv += '(';
185  rv += ImapParser::join( rids, " " );
186  rv += ')';
187  return rv;
188  }
189 
190  static QByteArray entitySetToByteArray( const QList<Akonadi::Item> &_objects, const QByteArray &command );
191 
192  static QByteArray tagSetToImapSequenceSet( const Akonadi::Tag::List &_objects );
193  static QByteArray tagSetToByteArray( const Akonadi::Tag::List &_objects, const QByteArray &command );
194 
199  template <typename T>
200  static QByteArray entityIdToByteArray( const T &object, const QByteArray &command )
201  {
202  return entitySetToByteArray( typename T::List() << object, command );
203  }
204 
209  static QByteArray hierarchicalRidToByteArray( const Collection &col );
210 
215  static QByteArray hierarchicalRidToByteArray( const Item &item );
216 
220  static QByteArray itemFetchScopeToByteArray( const ItemFetchScope &fetchScope );
221 
225  static void parseItemFetchResult( const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0 );
226  static void parseTagFetchResult( const QList<QByteArray> &lineTokens, Tag &tag );
227 
228 };
229 
230 }
231 
232 #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:355
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:125
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::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
Akonadi::ProtocolHelper
Definition: protocolhelper_p.h:58
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:339
Akonadi::ProtocolHelper::encodePartIdentifier
static QByteArray encodePartIdentifier(PartNamespace ns, const QByteArray &label, int version=0)
Encodes part label and namespace.
Definition: protocolhelper.cpp:226
Akonadi::ProtocolHelper::PartNamespace
PartNamespace
Part namespaces.
Definition: protocolhelper_p.h:62
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::Tag
An Akonadi Tag.
Definition: tag.h:44
Akonadi::ProtocolHelper::decodePartIdentifier
static QByteArray decodePartIdentifier(const QByteArray &data, PartNamespace &ns)
Decode part label and namespace.
Definition: protocolhelper.cpp:242
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::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:406
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:54 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