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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
collection.cpp
1 /*
2  Copyright (c) 2006 - 2007 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 "collection.h"
21 #include "collection_p.h"
22 
23 #include "attributefactory.h"
24 #include "cachepolicy.h"
25 #include "collectionrightsattribute_p.h"
26 #include "collectionstatistics.h"
27 #include "entity_p.h"
28 #include "entitydisplayattribute.h"
29 
30 #include <QtCore/QDebug>
31 #include <QtCore/QHash>
32 #include <QtCore/QString>
33 #include <QtCore/QStringList>
34 
35 #include <KUrl>
36 #include <KGlobal>
37 
38 using namespace Akonadi;
39 
40 class CollectionRoot : public Collection
41 {
42 public:
43  CollectionRoot()
44  : Collection(0)
45  {
46  QStringList types;
47  types << Collection::mimeType();
48  setContentMimeTypes(types);
49 
50  // The root collection is read-only for the users
51  Collection::Rights rights;
52  rights |= Collection::ReadOnly;
53  setRights(rights);
54  }
55 };
56 
57 K_GLOBAL_STATIC(CollectionRoot, s_root)
58 
59 Collection::Collection()
60  : Entity(new CollectionPrivate)
61 {
62  Q_D(Collection);
63  static int lastId = -1;
64  d->mId = lastId--;
65 }
66 
67 Collection::Collection(Id id)
68  : Entity(new CollectionPrivate(id))
69 {
70 }
71 
72 Collection::Collection(const Collection &other)
73  : Entity(other)
74 {
75 }
76 
77 Collection::~Collection()
78 {
79 }
80 
81 QString Collection::name() const
82 {
83  return d_func()->name;
84 }
85 
86 QString Collection::displayName() const
87 {
88  const EntityDisplayAttribute *const attr = attribute<EntityDisplayAttribute>();
89  const QString displayName = attr ? attr->displayName() : QString();
90  return !displayName.isEmpty() ? displayName : d_func()->name;
91 }
92 
93 void Collection::setName(const QString &name)
94 {
95  Q_D(Collection);
96  d->name = name;
97 }
98 
99 Collection::Rights Collection::rights() const
100 {
101  CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>();
102  if (attr) {
103  return attr->rights();
104  } else {
105  return AllRights;
106  }
107 }
108 
109 void Collection::setRights(Rights rights)
110 {
111  CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>(AddIfMissing);
112  attr->setRights(rights);
113 }
114 
115 QStringList Collection::contentMimeTypes() const
116 {
117  return d_func()->contentTypes;
118 }
119 
120 void Collection::setContentMimeTypes(const QStringList &types)
121 {
122  Q_D(Collection);
123  if (d->contentTypes != types) {
124  d->contentTypes = types;
125  d->contentTypesChanged = true;
126  }
127 }
128 
129 Collection::Id Collection::parent() const
130 {
131  return parentCollection().id();
132 }
133 
134 void Collection::setParent(Id parent)
135 {
136  parentCollection().setId(parent);
137 }
138 
139 void Collection::setParent(const Collection &collection)
140 {
141  setParentCollection(collection);
142 }
143 
144 QString Collection::parentRemoteId() const
145 {
146  return parentCollection().remoteId();
147 }
148 
149 void Collection::setParentRemoteId(const QString &remoteParent)
150 {
151  parentCollection().setRemoteId(remoteParent);
152 }
153 
154 KUrl Collection::url() const
155 {
156  return url(UrlShort);
157 }
158 
159 KUrl Collection::url(UrlType type) const
160 {
161  KUrl url;
162  url.setProtocol(QString::fromLatin1("akonadi"));
163  url.addQueryItem(QLatin1String("collection"), QString::number(id()));
164 
165  if (type == UrlWithName) {
166  url.addQueryItem(QLatin1String("name"), name());
167  }
168 
169  return url;
170 }
171 
172 Collection Collection::fromUrl(const KUrl &url)
173 {
174  if (url.protocol() != QLatin1String("akonadi")) {
175  return Collection();
176  }
177 
178  const QString colStr = url.queryItem(QLatin1String("collection"));
179  bool ok = false;
180  Collection::Id colId = colStr.toLongLong(&ok);
181  if (!ok) {
182  return Collection();
183  }
184 
185  if (colId == 0) {
186  return Collection::root();
187  }
188 
189  return Collection(colId);
190 }
191 
192 Collection Collection::root()
193 {
194  return *s_root;
195 }
196 
197 QString Collection::mimeType()
198 {
199  return QString::fromLatin1("inode/directory");
200 }
201 
202 QString Akonadi::Collection::virtualMimeType()
203 {
204  return QString::fromLatin1("application/x-vnd.akonadi.collection.virtual");
205 }
206 
207 QString Collection::resource() const
208 {
209  return d_func()->resource;
210 }
211 
212 void Collection::setResource(const QString &resource)
213 {
214  Q_D(Collection);
215  d->resource = resource;
216 }
217 
218 uint qHash(const Akonadi::Collection &collection)
219 {
220  return qHash(collection.id());
221 }
222 
223 QDebug operator <<(QDebug d, const Akonadi::Collection &collection)
224 {
225  return d << "Collection ID:" << collection.id()
226  << " remote ID:" << collection.remoteId() << endl
227  << " name:" << collection.name() << endl
228  << " url:" << collection.url() << endl
229  << " parent:" << collection.parentCollection().id() << collection.parentCollection().remoteId() << endl
230  << " resource:" << collection.resource() << endl
231  << " rights:" << collection.rights() << endl
232  << " contents mime type:" << collection.contentMimeTypes() << endl
233  << " isVirtual:" << collection.isVirtual() << endl
234  << " " << collection.cachePolicy() << endl
235  << " " << collection.statistics();
236 }
237 
238 CollectionStatistics Collection::statistics() const
239 {
240  return d_func()->statistics;
241 }
242 
243 void Collection::setStatistics(const CollectionStatistics &statistics)
244 {
245  Q_D(Collection);
246  d->statistics = statistics;
247 }
248 
249 CachePolicy Collection::cachePolicy() const
250 {
251  return d_func()->cachePolicy;
252 }
253 
254 void Collection::setCachePolicy(const CachePolicy &cachePolicy)
255 {
256  Q_D(Collection);
257  d->cachePolicy = cachePolicy;
258  d->cachePolicyChanged = true;
259 }
260 
261 bool Collection::isVirtual() const
262 {
263  return d_func()->isVirtual;
264 }
265 
266 void Akonadi::Collection::setVirtual(bool isVirtual)
267 {
268  Q_D(Collection);
269 
270  d->isVirtual = isVirtual;
271 }
272 
273 void Collection::setEnabled(bool enabled)
274 {
275  Q_D(Collection);
276 
277  d->enabledChanged = true;
278  d->enabled = enabled;
279 }
280 
281 bool Collection::enabled() const
282 {
283  Q_D(const Collection);
284 
285  return d->enabled;
286 }
287 
288 void Collection::setLocalListPreference(Collection::ListPurpose purpose, Collection::ListPreference preference)
289 {
290  Q_D(Collection);
291 
292  switch(purpose) {
293  case ListDisplay:
294  d->displayPreference = preference;
295  break;
296  case ListSync:
297  d->syncPreference = preference;
298  break;
299  case ListIndex:
300  d->indexPreference = preference;
301  break;
302  }
303  d->listPreferenceChanged = true;
304 }
305 
306 Collection::ListPreference Collection::localListPreference(Collection::ListPurpose purpose) const
307 {
308  Q_D(const Collection);
309 
310  switch(purpose) {
311  case ListDisplay:
312  return d->displayPreference;
313  case ListSync:
314  return d->syncPreference;
315  case ListIndex:
316  return d->indexPreference;
317  }
318  return ListDefault;
319 }
320 
321 bool Collection::shouldList(Collection::ListPurpose purpose) const
322 {
323  if (localListPreference(purpose) == ListDefault) {
324  return enabled();
325  }
326  return (localListPreference(purpose) == ListEnabled);
327 }
328 
329 void Collection::setShouldList(ListPurpose purpose, bool list)
330 {
331  if (localListPreference(purpose) == ListDefault) {
332  setEnabled(list);
333  } else {
334  setLocalListPreference(purpose, list ? ListEnabled : ListDisabled);
335  }
336 }
337 
338 void Collection::setReferenced(bool referenced)
339 {
340  Q_D(Collection);
341 
342  d->referencedChanged = true;
343  d->referenced = referenced;
344 }
345 
346 bool Collection::referenced() const
347 {
348  Q_D(const Collection);
349 
350  return d->referenced;
351 }
352 
353 AKONADI_DEFINE_PRIVATE(Akonadi::Collection)
Akonadi::Collection::ListPreference
ListPreference
Describes the list preference value.
Definition: collection.h:324
Akonadi::Collection::parentRemoteId
AKONADI_DEPRECATED QString parentRemoteId() const
Returns the parent remote identifier.
Definition: collection.cpp:144
Akonadi::Collection::name
QString name() const
Returns the i18n'ed name of the collection.
Definition: collection.cpp:81
Akonadi::Collection::displayName
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
Definition: collection.cpp:86
Akonadi::CollectionStatistics
Provides statistics information of a Collection.
Definition: collectionstatistics.h:69
Akonadi::Collection::shouldList
bool shouldList(ListPurpose purpose) const
Returns whether the collection should be listed or not for the specified purpose Takes enabled state ...
Definition: collection.cpp:321
Akonadi::Collection::url
KUrl url() const
Returns the url of the collection.
Definition: collection.cpp:154
Akonadi::EntityDisplayAttribute::displayName
QString displayName() const
Returns the name that should be used for display.
Definition: entitydisplayattribute.cpp:52
Akonadi::Collection::AllRights
Has all rights on this storage collection.
Definition: collection.h:96
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::Collection::virtualMimeType
static QString virtualMimeType()
Returns the mimetype used for virtual collections.
Definition: collection.cpp:202
Akonadi::Collection::ListDisplay
Listing for display to the user.
Definition: collection.h:337
Akonadi::Collection::mimeType
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:197
Akonadi::Collection::ListIndex
Listing for indexing the content.
Definition: collection.h:338
Akonadi::Entity::setId
void setId(Id identifier)
Sets the unique identifier of the entity.
Definition: entity.cpp:67
Akonadi::Entity::setParentCollection
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: entity.cpp:194
Akonadi::Collection::setParent
AKONADI_DEPRECATED void setParent(Id parent)
Sets the identifier of the parent collection.
Definition: collection.cpp:134
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
Akonadi::Collection::setRights
void setRights(Rights rights)
Sets the rights the user has on the collection.
Definition: collection.cpp:109
Akonadi::Collection::setEnabled
void setEnabled(bool enabled)
Sets the collection's enabled state.
Definition: collection.cpp:273
Akonadi::Collection::referenced
bool referenced() const
Returns the referenced state of the collection.
Definition: collection.cpp:346
Akonadi::Collection::ReadOnly
Can only read items or subcollection of this collection.
Definition: collection.h:87
Akonadi::Collection::setVirtual
void setVirtual(bool isVirtual)
Sets whether the collection is virtual or not.
Definition: collection.cpp:266
Akonadi::Collection::ListDisabled
Disable collectoin for specified purpose.
Definition: collection.h:326
QString::number
QString number(int n, int base)
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:185
Akonadi::Collection::UrlWithName
A url with identifier and name.
Definition: collection.h:266
Akonadi::Collection::setStatistics
void setStatistics(const CollectionStatistics &statistics)
Sets the collection statistics for the collection.
Definition: collection.cpp:243
Akonadi::Collection::ListEnabled
Enable collection for specified purpose.
Definition: collection.h:325
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:82
Akonadi::Collection::ListPurpose
ListPurpose
Describes the purpose of the listing.
Definition: collection.h:335
Akonadi::Collection::UrlType
UrlType
Describes the type of url which is returned in url().
Definition: collection.h:264
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
QString
Akonadi::CollectionRightsAttribute::setRights
void setRights(Collection::Rights rights)
Sets the rights of the collection.
Definition: collectionrightsattribute.cpp:123
Akonadi::CachePolicy
Represents the caching policy for a collection.
Definition: cachepolicy.h:71
Akonadi::Collection::setCachePolicy
void setCachePolicy(const CachePolicy &policy)
Sets the cache policy of the collection.
Definition: collection.cpp:254
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::CollectionRightsAttribute
Attribute that stores the rights of a collection.
Definition: collectionrightsattribute_p.h:44
QStringList
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::Collection::ListDefault
Fallback to enabled state.
Definition: collection.h:327
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:59
Akonadi::Collection::setLocalListPreference
void setLocalListPreference(ListPurpose purpose, ListPreference preference)
Sets the local list preference for the specified purpose.
Definition: collection.cpp:288
QDebug
Akonadi::Collection::setShouldList
void setShouldList(ListPurpose purpose, bool shouldList)
Sets wether the collection should be listed or not for the specified purpose.
Definition: collection.cpp:329
QLatin1String
Akonadi::Collection::UrlShort
A short url which contains the identifier only (equivalent to url())
Definition: collection.h:265
Akonadi::Collection::contentMimeTypes
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:115
Akonadi::Collection::cachePolicy
CachePolicy cachePolicy() const
Returns the cache policy of the collection.
Definition: collection.cpp:249
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Akonadi::Entity::AddIfMissing
Creates the attribute if it is missing.
Definition: entity.h:205
Akonadi::Collection::~Collection
~Collection()
Destroys the collection.
Definition: collection.cpp:77
Akonadi::Collection::enabled
bool enabled() const
Returns the collection's enabled state.
Definition: collection.cpp:281
Akonadi::Collection::resource
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:207
Akonadi::Collection::localListPreference
ListPreference localListPreference(ListPurpose purpose) const
Returns the local list preference for the specified purpose.
Definition: collection.cpp:306
Akonadi::CollectionRightsAttribute::rights
Collection::Rights rights() const
Returns the rights of the collection.
Definition: collectionrightsattribute.cpp:128
Akonadi::Collection::parent
AKONADI_DEPRECATED Id parent() const
Returns the identifier of the parent collection.
Definition: collection.cpp:129
Akonadi::Collection::setParentRemoteId
AKONADI_DEPRECATED void setParentRemoteId(const QString &identifier)
Sets the parent's remote identifier.
Definition: collection.cpp:149
Akonadi::Collection::Collection
Collection()
Creates an invalid collection.
Definition: collection.cpp:59
Akonadi::Collection::fromUrl
static Collection fromUrl(const KUrl &url)
Creates a collection from the given url.
Definition: collection.cpp:172
Akonadi::Collection::setReferenced
void setReferenced(bool referenced)
Sets a collection to be referenced.
Definition: collection.cpp:338
Akonadi::Collection::statistics
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:238
Akonadi::Collection::ListSync
Listing for synchronization.
Definition: collection.h:336
QString::toLongLong
qlonglong toLongLong(bool *ok, int base) const
Akonadi::Collection::setResource
void setResource(const QString &identifier)
Sets the identifier of the resource owning the collection.
Definition: collection.cpp:212
Akonadi::EntityDisplayAttribute
Attribute that stores the properties that are used to display an entity.
Definition: entitydisplayattribute.h:39
Akonadi::Collection::setContentMimeTypes
void setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
Definition: collection.cpp:120
Akonadi::Collection::isVirtual
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:261
Akonadi::CollectionPrivate
Definition: collection_p.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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