20 #ifndef AKONADI_PROTOCOLHELPER_P_H
21 #define AKONADI_PROTOCOLHELPER_P_H
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>
30 #include <akonadi/private/imapparser_p.h>
31 #include <akonadi/private/protocol_p.h>
33 #include <boost/bind.hpp>
38 struct ProtocolHelperValuePool
40 typedef Internal::SharedValuePool<QByteArray, QVector> FlagPool;
41 typedef Internal::SharedValuePool<QString, QVector> MimeTypePool;
44 MimeTypePool mimeTypePool;
45 QHash<Collection::Id, Collection> ancestorCollections;
73 static int parseCachePolicy(
const QByteArray &data, CachePolicy &policy,
int start = 0 );
78 static QByteArray cachePolicyToByteArray(
const CachePolicy &policy );
83 static void parseAncestors(
const QByteArray &data,
Entity *entity,
int start = 0 );
91 static void parseAncestorsCached(
const QByteArray &data,
Entity *entity,
Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0,
int start = 0 );
100 static int parseCollection(
const QByteArray &data, Collection &collection,
int start = 0 );
105 static QByteArray attributesToByteArray(
const Entity &entity,
bool ns =
false );
110 static QByteArray encodePartIdentifier( PartNamespace ns,
const QByteArray &label,
int version = 0 );
115 static QByteArray decodePartIdentifier(
const QByteArray &data, PartNamespace &ns );
121 template <
typename T>
124 if ( _objects.isEmpty() )
125 throw Exception(
"No objects specified" );
127 typename T::List objects( _objects );
130 std::sort( objects.begin(), objects.end(), boost::bind( &T::id, _1 ) < boost::bind( &T::id, _2 ) );
131 if ( objects.first().isValid() ) {
133 rv +=
" " AKONADI_CMD_UID
" ";
134 if ( !command.isEmpty() ) {
138 QVector<typename T::Id> uids;
139 foreach (
const T &
object, objects )
143 rv +=
set.toImapSequenceSet();
148 if ( std::find_if( objects.constBegin(), objects.constEnd(),
149 boost::bind( &QString::isEmpty, boost::bind( &T::remoteId, _1 ) ) )
150 != objects.constEnd() )
152 throw Exception(
"No remote identifier specified" );
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 )
161 rv +=
" " AKONADI_CMD_HRID
" ";
162 if ( !command.isEmpty() ) {
171 QList<QByteArray> rids;
172 foreach (
const T &
object, objects ) {
173 rids << ImapParser::quote(
object.remoteId().toUtf8() );
176 rv +=
" " AKONADI_CMD_RID
" ";
177 if ( !command.isEmpty() ) {
182 rv += ImapParser::join( rids,
" " );
191 template <
typename T>
201 static QByteArray hierarchicalRidToByteArray(
const Collection &col );
207 static QByteArray hierarchicalRidToByteArray(
const Item &item );
212 static QByteArray itemFetchScopeToByteArray(
const ItemFetchScope &fetchScope );
217 static void parseItemFetchResult(
const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0 );