• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
38namespace Akonadi {
39
40struct 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
58class ProtocolHelper
59{
60public:
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
131 typename T::List objects(_objects);
132
133 QByteArray rv;
134 std::sort(objects.begin(), objects.end(), boost::bind(&T::id, _1) < boost::bind(&T::id, _2));
135 if (objects.first().isValid()) {
136 // all items have a uid set
137 rv += " " AKONADI_CMD_UID " ";
138 if (!command.isEmpty()) {
139 rv += command;
140 rv += ' ';
141 }
142 QVector<typename T::Id> uids;
143 foreach (const T &object, objects) {
144 uids << object.id();
145 }
146 ImapSet set;
147 set.add(uids);
148 rv += set.toImapSequenceSet();
149 return rv;
150 }
151
152 // check if all items have a remote id
153 if (std::find_if(objects.constBegin(), objects.constEnd(),
154 boost::bind(&QString::isEmpty, boost::bind(&T::remoteId, _1)))
155 != objects.constEnd()) {
156 throw Exception("No remote identifier specified");
157 }
158
159 // check if we have RIDs or HRIDs
160 if (std::find_if(objects.constBegin(), objects.constEnd(),
161 !boost::bind(static_cast<bool (*)(const T &)>(&CollectionUtils::hasValidHierarchicalRID), _1))
162 == objects.constEnd() && objects.size() == 1) { // ### HRID sets are not yet specified
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
195
196 static QByteArray commandContextToByteArray(const Akonadi::Collection &collection, const Akonadi::Tag &tag,
197 const Item::List &requestedItems, const QByteArray &command);
198
203 template <typename T>
204 static QByteArray entityIdToByteArray(const T &object, const QByteArray &command)
205 {
206 return entitySetToByteArray(typename T::List() << object, command);
207 }
208
213 static QByteArray hierarchicalRidToByteArray(const Collection &col);
214
219 static QByteArray hierarchicalRidToByteArray(const Item &item);
220
224 static QByteArray itemFetchScopeToByteArray(const ItemFetchScope &fetchScope);
225
229 static QByteArray tagFetchScopeToByteArray( const TagFetchScope &fetchScope );
230
234 static void parseItemFetchResult(const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0);
235 static void parseTagFetchResult(const QList<QByteArray> &lineTokens, Tag &tag);
236
237 static QString akonadiStoragePath();
238 static QString absolutePayloadFilePath(const QString &fileName);
239
240 static bool streamPayloadToFile(const QByteArray &command, const QByteArray &data, QByteArray &error);
241
242 static QByteArray listPreference(Collection::ListPurpose purpose, Collection::ListPreference preference);
243 static QByteArray enabled(bool);
244 static QByteArray referenced(bool);
245};
246
247}
248
249#endif
Akonadi::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
Akonadi::CachePolicy
Represents the caching policy for a collection.
Definition: cachepolicy.h:72
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::ListPurpose
ListPurpose
Describes the purpose of the listing.
Definition: collection.h:335
Akonadi::Collection::ListPreference
ListPreference
Describes the list preference value.
Definition: collection.h:324
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:60
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::Exception
Base class for exceptions used by the Akonadi library.
Definition: exception.h:36
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:70
Akonadi::ProtocolHelper
Definition: protocolhelper_p.h:59
Akonadi::ProtocolHelper::itemFetchScopeToByteArray
static QByteArray itemFetchScopeToByteArray(const ItemFetchScope &fetchScope)
Converts a given ItemFetchScope object into a protocol representation.
Definition: protocolhelper.cpp:411
Akonadi::ProtocolHelper::parseCachePolicy
static int parseCachePolicy(const QByteArray &data, CachePolicy &policy, int start=0)
Parse a cache policy definition.
Definition: protocolhelper.cpp:43
Akonadi::ProtocolHelper::hierarchicalRidToByteArray
static QByteArray hierarchicalRidToByteArray(const Collection &col)
Converts the given collection's hierarchical RID into a protocol representation.
Definition: protocolhelper.cpp:395
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:204
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:106
Akonadi::ProtocolHelper::tagFetchScopeToByteArray
static QByteArray tagFetchScopeToByteArray(const TagFetchScope &fetchScope)
Converts a given TagFetchScope object into a protocol representation.
Definition: protocolhelper.cpp:468
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:232
Akonadi::ProtocolHelper::PartNamespace
PartNamespace
Part namespaces.
Definition: protocolhelper_p.h:62
Akonadi::ProtocolHelper::parseCollection
static int parseCollection(const QByteArray &data, Collection &collection, int start=0)
Parse a collection description.
Definition: protocolhelper.cpp:145
Akonadi::ProtocolHelper::decodePartIdentifier
static QByteArray decodePartIdentifier(const QByteArray &data, PartNamespace &ns)
Decode part label and namespace.
Definition: protocolhelper.cpp:268
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:503
Akonadi::ProtocolHelper::cachePolicyToByteArray
static QByteArray cachePolicyToByteArray(const CachePolicy &policy)
Convert a cache policy object into its protocol representation.
Definition: protocolhelper.cpp:71
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:87
Akonadi::ProtocolHelper::encodePartIdentifier
static QByteArray encodePartIdentifier(PartNamespace ns, const QByteArray &label, int version=0)
Encodes part label and namespace.
Definition: protocolhelper.cpp:252
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::TagFetchScope
Specifies which parts of a tag should be fetched from the Akonadi storage.
Definition: tagfetchscope.h:34
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:44
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

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