• 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 )
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:32 by doxygen 1.8.3.1 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