• Skip to content
  • Skip to link menu
KDE 4.2 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.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() : Collection( 0 ) {
00043       QStringList types;
00044       types << Collection::mimeType();
00045       setContentMimeTypes( types );
00046     }
00047 };
00048 
00049 K_GLOBAL_STATIC( CollectionRoot, s_root )
00050 
00051 Collection::Collection() :
00052     Entity( new CollectionPrivate )
00053 {
00054   Q_D( Collection );
00055   static int lastId = -1;
00056   d->mId = lastId--;
00057 }
00058 
00059 Collection::Collection( Id id ) :
00060     Entity( new CollectionPrivate( id ) )
00061 {
00062 }
00063 
00064 Collection::Collection(const Collection & other) :
00065     Entity( other )
00066 {
00067 }
00068 
00069 Collection::~Collection()
00070 {
00071 }
00072 
00073 QString Collection::name( ) const
00074 {
00075   return d_func()->name;
00076 }
00077 
00078 void Collection::setName( const QString & name )
00079 {
00080   Q_D( Collection );
00081   d->name = name;
00082 }
00083 
00084 Collection::Rights Collection::rights() const
00085 {
00086   CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>();
00087   if ( attr )
00088     return attr->rights();
00089   else
00090     return AllRights;
00091 }
00092 
00093 void Collection::setRights( Rights rights )
00094 {
00095   CollectionRightsAttribute *attr = attribute<CollectionRightsAttribute>( AddIfMissing );
00096   attr->setRights( rights );
00097 }
00098 
00099 QStringList Collection::contentMimeTypes() const
00100 {
00101   return d_func()->contentTypes;
00102 }
00103 
00104 void Collection::setContentMimeTypes( const QStringList & types )
00105 {
00106   Q_D( Collection );
00107   d->contentTypes = types;
00108   d->contentTypesChanged = true;
00109 }
00110 
00111 Collection::Id Collection::parent() const
00112 {
00113   return d_func()->parentId;
00114 }
00115 
00116 void Collection::setParent( Id parent )
00117 {
00118   Q_D( Collection );
00119   d->parentId = parent;
00120 }
00121 
00122 void Collection::setParent(const Collection & collection)
00123 {
00124   Q_D( Collection );
00125   d->parentId = collection.id();
00126   d->parentRemoteId = collection.remoteId();
00127 }
00128 
00129 QString Collection::parentRemoteId() const
00130 {
00131   return d_func()->parentRemoteId;
00132 }
00133 
00134 void Collection::setParentRemoteId(const QString & remoteParent)
00135 {
00136   Q_D( Collection );
00137   d->parentRemoteId = remoteParent;
00138 }
00139 
00140 KUrl Collection::url() const
00141 {
00142   KUrl url;
00143   url.setProtocol( QString::fromLatin1("akonadi") );
00144   url.addQueryItem( QLatin1String("collection"), QString::number( id() ) );
00145   return url;
00146 }
00147 
00148 Collection Collection::fromUrl( const KUrl &url )
00149 {
00150   if ( url.protocol() != QLatin1String( "akonadi" ) )
00151     return Collection();
00152 
00153   const QString colStr = url.queryItem( QLatin1String( "collection" ) );
00154   bool ok = false;
00155   Collection::Id colId = colStr.toLongLong( &ok );
00156   if ( !ok )
00157     return Collection();
00158 
00159   if ( colId == 0 )
00160     return Collection::root();
00161 
00162   return Collection( colId );
00163 }
00164 
00165 Collection Collection::root()
00166 {
00167   return *s_root;
00168 }
00169 
00170 QString Collection::mimeType( )
00171 {
00172   return QString::fromLatin1("inode/directory");
00173 }
00174 
00175 QString Collection::resource() const
00176 {
00177   return d_func()->resource;
00178 }
00179 
00180 void Collection::setResource(const QString & resource)
00181 {
00182   Q_D( Collection );
00183   d->resource = resource;
00184 }
00185 
00186 uint qHash( const Akonadi::Collection &collection )
00187 {
00188   return qHash( collection.id() );
00189 }
00190 
00191 CollectionStatistics Collection::statistics() const
00192 {
00193   return d_func()->statistics;
00194 }
00195 
00196 void Collection::setStatistics(const CollectionStatistics & statistics)
00197 {
00198   Q_D( Collection );
00199   d->statistics = statistics;
00200 }
00201 
00202 CachePolicy Collection::cachePolicy() const
00203 {
00204   return d_func()->cachePolicy;
00205 }
00206 
00207 void Collection::setCachePolicy(const CachePolicy & cachePolicy)
00208 {
00209   Q_D( Collection );
00210   d->cachePolicy = cachePolicy;
00211   d->cachePolicyChanged = true;
00212 }
00213 
00214 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
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7.1
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