• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 void Collection::setRights( Rights rights )
101 {
102  CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>( AddIfMissing );
103  attr->setRights( rights );
104 }
105 
106 QStringList Collection::contentMimeTypes() const
107 {
108  return d_func()->contentTypes;
109 }
110 
111 void Collection::setContentMimeTypes( const QStringList & types )
112 {
113  Q_D( Collection );
114  if ( d->contentTypes != types ) {
115  d->contentTypes = types;
116  d->contentTypesChanged = true;
117  }
118 }
119 
120 Collection::Id Collection::parent() const
121 {
122  return parentCollection().id();
123 }
124 
125 void Collection::setParent( Id parent )
126 {
127  parentCollection().setId( parent );
128 }
129 
130 void Collection::setParent(const Collection & collection)
131 {
132  setParentCollection( collection );
133 }
134 
135 QString Collection::parentRemoteId() const
136 {
137  return parentCollection().remoteId();
138 }
139 
140 void Collection::setParentRemoteId(const QString & remoteParent)
141 {
142  parentCollection().setRemoteId( remoteParent );
143 }
144 
145 KUrl Collection::url() const
146 {
147  return url( UrlShort );
148 }
149 
150 KUrl Collection::url( UrlType type ) const
151 {
152  KUrl url;
153  url.setProtocol( QString::fromLatin1( "akonadi" ) );
154  url.addQueryItem( QLatin1String( "collection" ), QString::number( id() ) );
155 
156  if ( type == UrlWithName )
157  url.addQueryItem( QLatin1String( "name" ), name() );
158 
159  return url;
160 }
161 
162 Collection Collection::fromUrl( const KUrl &url )
163 {
164  if ( url.protocol() != QLatin1String( "akonadi" ) )
165  return Collection();
166 
167  const QString colStr = url.queryItem( QLatin1String( "collection" ) );
168  bool ok = false;
169  Collection::Id colId = colStr.toLongLong( &ok );
170  if ( !ok )
171  return Collection();
172 
173  if ( colId == 0 )
174  return Collection::root();
175 
176  return Collection( colId );
177 }
178 
179 Collection Collection::root()
180 {
181  return *s_root;
182 }
183 
184 QString Collection::mimeType( )
185 {
186  return QString::fromLatin1( "inode/directory" );
187 }
188 
189 QString Collection::resource() const
190 {
191  return d_func()->resource;
192 }
193 
194 void Collection::setResource(const QString & resource)
195 {
196  Q_D( Collection );
197  d->resource = resource;
198 }
199 
200 uint qHash( const Akonadi::Collection &collection )
201 {
202  return qHash( collection.id() );
203 }
204 
205 QDebug operator <<( QDebug d, const Akonadi::Collection &collection )
206 {
207  return d << "Collection ID:" << collection.id()
208  << " remote ID:" << collection.remoteId() << endl
209  << " name:" << collection.name() << endl
210  << " url:" << collection.url() << endl
211  << " parent:" << collection.parentCollection().id() << collection.parentCollection().remoteId() << endl
212  << " resource:" << collection.resource() << endl
213  << " rights:" << collection.rights() << endl
214  << " contents mime type:" << collection.contentMimeTypes() << endl
215  << " " << collection.cachePolicy() << endl
216  << " " << collection.statistics();
217 }
218 
219 CollectionStatistics Collection::statistics() const
220 {
221  return d_func()->statistics;
222 }
223 
224 void Collection::setStatistics(const CollectionStatistics & statistics)
225 {
226  Q_D( Collection );
227  d->statistics = statistics;
228 }
229 
230 CachePolicy Collection::cachePolicy() const
231 {
232  return d_func()->cachePolicy;
233 }
234 
235 void Collection::setCachePolicy(const CachePolicy & cachePolicy)
236 {
237  Q_D( Collection );
238  d->cachePolicy = cachePolicy;
239  d->cachePolicyChanged = true;
240 }
241 
242 bool Collection::isVirtual() const
243 {
244  // TODO make this a proper flag
245  return ( (resource() == QLatin1String( "akonadi_search_resource" ) || resource() == QLatin1String( "akonadi_nepomuktag_resource" ) ) );
246 }
247 
248 AKONADI_DEFINE_PRIVATE( Akonadi::Collection )
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Dec 10 2012 13:48:07 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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