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

akonadi

  • 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 
29 #include <QtCore/QDebug>
30 #include <QtCore/QHash>
31 #include <QtCore/QString>
32 #include <QtCore/QStringList>
33 
34 #include <KUrl>
35 #include <KGlobal>
36 
37 using namespace Akonadi;
38 
39 class CollectionRoot : public Collection
40 {
41  public:
42  CollectionRoot()
43  : Collection( 0 )
44  {
45  QStringList types;
46  types << Collection::mimeType();
47  setContentMimeTypes( types );
48 
49  // The root collection is read-only for the users
50  Collection::Rights rights;
51  rights |= Collection::ReadOnly;
52  setRights( rights );
53  }
54 };
55 
56 K_GLOBAL_STATIC( CollectionRoot, s_root )
57 
58 Collection::Collection() :
59  Entity( new CollectionPrivate )
60 {
61  Q_D( Collection );
62  static int lastId = -1;
63  d->mId = lastId--;
64 }
65 
66 Collection::Collection( Id id ) :
67  Entity( new CollectionPrivate( id ) )
68 {
69 }
70 
71 Collection::Collection(const Collection & other) :
72  Entity( other )
73 {
74 }
75 
76 Collection::~Collection()
77 {
78 }
79 
80 QString Collection::name( ) const
81 {
82  return d_func()->name;
83 }
84 
85 void Collection::setName( const QString & name )
86 {
87  Q_D( Collection );
88  d->name = name;
89 }
90 
91 Collection::Rights Collection::rights() const
92 {
93  CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>();
94  if ( attr ) {
95  return attr->rights();
96  } else {
97  return AllRights;
98  }
99 }
100 
101 void Collection::setRights( Rights rights )
102 {
103  CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>( AddIfMissing );
104  attr->setRights( rights );
105 }
106 
107 QStringList Collection::contentMimeTypes() const
108 {
109  return d_func()->contentTypes;
110 }
111 
112 void Collection::setContentMimeTypes( const QStringList & types )
113 {
114  Q_D( Collection );
115  if ( d->contentTypes != types ) {
116  d->contentTypes = types;
117  d->contentTypesChanged = true;
118  }
119 }
120 
121 Collection::Id Collection::parent() const
122 {
123  return parentCollection().id();
124 }
125 
126 void Collection::setParent( Id parent )
127 {
128  parentCollection().setId( parent );
129 }
130 
131 void Collection::setParent(const Collection & collection)
132 {
133  setParentCollection( collection );
134 }
135 
136 QString Collection::parentRemoteId() const
137 {
138  return parentCollection().remoteId();
139 }
140 
141 void Collection::setParentRemoteId(const QString & remoteParent)
142 {
143  parentCollection().setRemoteId( remoteParent );
144 }
145 
146 KUrl Collection::url() const
147 {
148  return url( UrlShort );
149 }
150 
151 KUrl Collection::url( UrlType type ) const
152 {
153  KUrl url;
154  url.setProtocol( QString::fromLatin1( "akonadi" ) );
155  url.addQueryItem( QLatin1String( "collection" ), QString::number( id() ) );
156 
157  if ( type == UrlWithName ) {
158  url.addQueryItem( QLatin1String( "name" ), name() );
159  }
160 
161  return url;
162 }
163 
164 Collection Collection::fromUrl( const KUrl &url )
165 {
166  if ( url.protocol() != QLatin1String( "akonadi" ) ) {
167  return Collection();
168  }
169 
170  const QString colStr = url.queryItem( QLatin1String( "collection" ) );
171  bool ok = false;
172  Collection::Id colId = colStr.toLongLong( &ok );
173  if ( !ok ) {
174  return Collection();
175  }
176 
177  if ( colId == 0 ) {
178  return Collection::root();
179  }
180 
181  return Collection( colId );
182 }
183 
184 Collection Collection::root()
185 {
186  return *s_root;
187 }
188 
189 QString Collection::mimeType( )
190 {
191  return QString::fromLatin1( "inode/directory" );
192 }
193 
194 QString Collection::resource() const
195 {
196  return d_func()->resource;
197 }
198 
199 void Collection::setResource(const QString & resource)
200 {
201  Q_D( Collection );
202  d->resource = resource;
203 }
204 
205 uint qHash( const Akonadi::Collection &collection )
206 {
207  return qHash( collection.id() );
208 }
209 
210 QDebug operator <<( QDebug d, const Akonadi::Collection &collection )
211 {
212  return d << "Collection ID:" << collection.id()
213  << " remote ID:" << collection.remoteId() << endl
214  << " name:" << collection.name() << endl
215  << " url:" << collection.url() << endl
216  << " parent:" << collection.parentCollection().id() << collection.parentCollection().remoteId() << endl
217  << " resource:" << collection.resource() << endl
218  << " rights:" << collection.rights() << endl
219  << " contents mime type:" << collection.contentMimeTypes() << endl
220  << " isVirtual:" << collection.isVirtual() << endl
221  << " " << collection.cachePolicy() << endl
222  << " " << collection.statistics();
223 }
224 
225 CollectionStatistics Collection::statistics() const
226 {
227  return d_func()->statistics;
228 }
229 
230 void Collection::setStatistics(const CollectionStatistics & statistics)
231 {
232  Q_D( Collection );
233  d->statistics = statistics;
234 }
235 
236 CachePolicy Collection::cachePolicy() const
237 {
238  return d_func()->cachePolicy;
239 }
240 
241 void Collection::setCachePolicy(const CachePolicy & cachePolicy)
242 {
243  Q_D( Collection );
244  d->cachePolicy = cachePolicy;
245  d->cachePolicyChanged = true;
246 }
247 
248 bool Collection::isVirtual() const
249 {
250  return d_func()->isVirtual;
251 }
252 
253 void Akonadi::Collection::setVirtual(bool isVirtual)
254 {
255  Q_D( Collection );
256 
257  d->isVirtual = isVirtual;
258 }
259 
260 
261 AKONADI_DEFINE_PRIVATE( Akonadi::Collection )
Akonadi::Collection::parentRemoteId
QString parentRemoteId() const
Returns the parent remote identifier.
Definition: collection.cpp:136
Akonadi::Collection::name
QString name() const
Returns the i18n&#39;ed name of the collection.
Definition: collection.cpp:80
Akonadi::CollectionStatistics
Provides statistics information of a Collection.
Definition: collectionstatistics.h:69
Akonadi::Collection::url
KUrl url() const
Returns the url of the collection.
Definition: collection.cpp:146
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:78
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:64
Akonadi::Collection::mimeType
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:189
Akonadi::Entity::setId
void setId(Id identifier)
Sets the unique identifier of the entity.
Definition: entity.cpp:68
Akonadi::Entity::setParentCollection
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: entity.cpp:196
Akonadi::Collection::setParent
void setParent(Id parent)
Sets the identifier of the parent collection.
Definition: collection.cpp:126
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n&#39;ed name of the collection.
Definition: collection.cpp:85
Akonadi::Collection::setRights
void setRights(Rights rights)
Sets the rights the user has on the collection.
Definition: collection.cpp:101
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:253
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:187
Akonadi::Collection::UrlWithName
A url with identifier and name.
Definition: collection.h:247
Akonadi::Collection::setStatistics
void setStatistics(const CollectionStatistics &statistics)
Sets the collection statistics for the collection.
Definition: collection.cpp:230
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:83
Akonadi::Collection::UrlType
UrlType
Describes the type of url which is returned in url().
Definition: collection.h:245
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:184
Akonadi::CollectionRightsAttribute::setRights
void setRights(Collection::Rights rights)
Sets the rights of the collection.
Definition: collectionrightsattribute.cpp:108
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:241
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:73
Akonadi::CollectionRightsAttribute
Attribute that stores the rights of a collection.
Definition: collectionrightsattribute_p.h:44
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:91
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:58
Akonadi::Collection::UrlShort
A short url which contains the identifier only (equivalent to url())
Definition: collection.h:246
Akonadi::Collection::contentMimeTypes
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:107
Akonadi::Collection::cachePolicy
CachePolicy cachePolicy() const
Returns the cache policy of the collection.
Definition: collection.cpp:236
Akonadi::Entity::AddIfMissing
Creates the attribute if it is missing.
Definition: entity.h:203
Akonadi::Collection::~Collection
~Collection()
Destroys the collection.
Definition: collection.cpp:76
Akonadi::Collection::resource
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:194
Akonadi::CollectionRightsAttribute::rights
Collection::Rights rights() const
Returns the rights of the collection.
Definition: collectionrightsattribute.cpp:113
Akonadi::Collection::parent
Id parent() const
Returns the identifier of the parent collection.
Definition: collection.cpp:121
Akonadi::Collection::setParentRemoteId
void setParentRemoteId(const QString &identifier)
Sets the parent&#39;s remote identifier.
Definition: collection.cpp:141
Akonadi::Collection::Collection
Collection()
Creates an invalid collection.
Definition: collection.cpp:58
Akonadi::Collection::fromUrl
static Collection fromUrl(const KUrl &url)
Creates a collection from the given url.
Definition: collection.cpp:164
Akonadi::Collection::statistics
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:225
Akonadi::Collection::setResource
void setResource(const QString &identifier)
Sets the identifier of the resource owning the collection.
Definition: collection.cpp:199
Akonadi::Collection::setContentMimeTypes
void setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
Definition: collection.cpp:112
Akonadi::Collection::isVirtual
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:248
Akonadi::CollectionPrivate
Definition: collection_p.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2017 The KDE developers.
Generated on Sat Feb 25 2017 07:46:39 by doxygen 1.8.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.10.5 API Reference

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