• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

collection.cpp

00001 /*
00002     Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "collection.h"
00021 #include "collection_p.h"
00022 
00023 #include "attributefactory.h"
00024 #include "cachepolicy.h"
00025 #include "collectionrightsattribute_p.h"
00026 #include "collectionstatistics.h"
00027 #include "entity_p.h"
00028 
00029 #include <QtCore/QDebug>
00030 #include <QtCore/QHash>
00031 #include <QtCore/QString>
00032 #include <QtCore/QStringList>
00033 
00034 #include <KUrl>
00035 #include <KGlobal>
00036 
00037 using namespace Akonadi;
00038 
00039 class CollectionRoot : public Collection
00040 {
00041   public:
00042     CollectionRoot()
00043       : Collection( 0 )
00044     {
00045       QStringList types;
00046       types << Collection::mimeType();
00047       setContentMimeTypes( types );
00048 
00049       // The root collection is read-only for the users
00050       Collection::Rights rights;
00051       rights |= Collection::ReadOnly;
00052       setRights( rights );
00053     }
00054 };
00055 
00056 K_GLOBAL_STATIC( CollectionRoot, s_root )
00057 
00058 Collection::Collection() :
00059     Entity( new CollectionPrivate )
00060 {
00061   Q_D( Collection );
00062   static int lastId = -1;
00063   d->mId = lastId--;
00064 }
00065 
00066 Collection::Collection( Id id ) :
00067     Entity( new CollectionPrivate( id ) )
00068 {
00069 }
00070 
00071 Collection::Collection(const Collection & other) :
00072     Entity( other )
00073 {
00074 }
00075 
00076 Collection::~Collection()
00077 {
00078 }
00079 
00080 QString Collection::name( ) const
00081 {
00082   return d_func()->name;
00083 }
00084 
00085 void Collection::setName( const QString & name )
00086 {
00087   Q_D( Collection );
00088   d->name = name;
00089 }
00090 
00091 Collection::Rights Collection::rights() const
00092 {
00093   CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>();
00094   if ( attr )
00095     return attr->rights();
00096   else
00097     return AllRights;
00098 }
00099 
00100 void Collection::setRights( Rights rights )
00101 {
00102   CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>( AddIfMissing );
00103   attr->setRights( rights );
00104 }
00105 
00106 QStringList Collection::contentMimeTypes() const
00107 {
00108   return d_func()->contentTypes;
00109 }
00110 
00111 void Collection::setContentMimeTypes( const QStringList & types )
00112 {
00113   Q_D( Collection );
00114   d->contentTypes = types;
00115   d->contentTypesChanged = true;
00116 }
00117 
00118 Collection::Id Collection::parent() const
00119 {
00120   return parentCollection().id();
00121 }
00122 
00123 void Collection::setParent( Id parent )
00124 {
00125   parentCollection().setId( parent );
00126 }
00127 
00128 void Collection::setParent(const Collection & collection)
00129 {
00130   setParentCollection( collection );
00131 }
00132 
00133 QString Collection::parentRemoteId() const
00134 {
00135   return parentCollection().remoteId();
00136 }
00137 
00138 void Collection::setParentRemoteId(const QString & remoteParent)
00139 {
00140   parentCollection().setRemoteId( remoteParent );
00141 }
00142 
00143 KUrl Collection::url() const
00144 {
00145   KUrl url;
00146   url.setProtocol( QString::fromLatin1("akonadi") );
00147   url.addQueryItem( QLatin1String("collection"), QString::number( id() ) );
00148   return url;
00149 }
00150 
00151 Collection Collection::fromUrl( const KUrl &url )
00152 {
00153   if ( url.protocol() != QLatin1String( "akonadi" ) )
00154     return Collection();
00155 
00156   const QString colStr = url.queryItem( QLatin1String( "collection" ) );
00157   bool ok = false;
00158   Collection::Id colId = colStr.toLongLong( &ok );
00159   if ( !ok )
00160     return Collection();
00161 
00162   if ( colId == 0 )
00163     return Collection::root();
00164 
00165   return Collection( colId );
00166 }
00167 
00168 Collection Collection::root()
00169 {
00170   return *s_root;
00171 }
00172 
00173 QString Collection::mimeType( )
00174 {
00175   return QString::fromLatin1("inode/directory");
00176 }
00177 
00178 QString Collection::resource() const
00179 {
00180   return d_func()->resource;
00181 }
00182 
00183 void Collection::setResource(const QString & resource)
00184 {
00185   Q_D( Collection );
00186   d->resource = resource;
00187 }
00188 
00189 uint qHash( const Akonadi::Collection &collection )
00190 {
00191   return qHash( collection.id() );
00192 }
00193 
00194 QDebug operator <<( QDebug d, const Akonadi::Collection &collection )
00195 {
00196     return d << "Collection ID:" << collection.id()
00197              << "   remote ID:" << collection.remoteId() << endl
00198              << "   name:" << collection.name() << endl
00199              << "   url:" << collection.url() << endl
00200              << "   parent:" << collection.parentCollection().id() << collection.parentCollection().remoteId() << endl
00201              << "   resource:" << collection.resource() << endl
00202              << "   rights:" << collection.rights() << endl
00203              << "   contents mime type:" << collection.contentMimeTypes() << endl
00204              << "   " << collection.cachePolicy() << endl
00205              << "   " << collection.statistics();
00206 }
00207 
00208 CollectionStatistics Collection::statistics() const
00209 {
00210   return d_func()->statistics;
00211 }
00212 
00213 void Collection::setStatistics(const CollectionStatistics & statistics)
00214 {
00215   Q_D( Collection );
00216   d->statistics = statistics;
00217 }
00218 
00219 CachePolicy Collection::cachePolicy() const
00220 {
00221   return d_func()->cachePolicy;
00222 }
00223 
00224 void Collection::setCachePolicy(const CachePolicy & cachePolicy)
00225 {
00226   Q_D( Collection );
00227   d->cachePolicy = cachePolicy;
00228   d->cachePolicyChanged = true;
00229 }
00230 
00231 AKONADI_DEFINE_PRIVATE( Akonadi::Collection )

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal