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

akonadi

collectionrightsattribute.cpp

00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@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 "collectionrightsattribute_p.h"
00021 
00022 using namespace Akonadi;
00023 
00024 static const char* s_accessRightsIdentifier = "AccessRights";
00025 
00026 static Collection::Rights dataToRights( const QByteArray &data )
00027 {
00028   Collection::Rights rights = Collection::ReadOnly;
00029 
00030   if ( data.isEmpty() )
00031     return Collection::ReadOnly;
00032 
00033   if ( data.at( 0 ) == 'a' )
00034     return Collection::AllRights;
00035 
00036   for ( int i = 0; i < data.count(); ++i ) {
00037     switch ( data.at( i ) ) {
00038       case 'w': rights |= Collection::CanChangeItem; break;
00039       case 'c': rights |= Collection::CanCreateItem; break;
00040       case 'd': rights |= Collection::CanDeleteItem; break;
00041       case 'W': rights |= Collection::CanChangeCollection; break;
00042       case 'C': rights |= Collection::CanCreateCollection; break;
00043       case 'D': rights |= Collection::CanDeleteCollection; break;
00044     }
00045   }
00046 
00047   return rights;
00048 }
00049 
00050 static QByteArray rightsToData( Collection::Rights &rights )
00051 {
00052   if ( rights == Collection::AllRights )
00053     return QByteArray( "a" );
00054 
00055   QByteArray data;
00056   if ( rights & Collection::CanChangeItem )
00057     data.append( 'w' );
00058   if ( rights & Collection::CanCreateItem )
00059     data.append( 'c' );
00060   if ( rights & Collection::CanDeleteItem )
00061     data.append( 'd' );
00062   if ( rights & Collection::CanChangeCollection )
00063     data.append( 'W' );
00064   if ( rights & Collection::CanCreateCollection )
00065     data.append( 'C' );
00066   if ( rights & Collection::CanDeleteCollection )
00067     data.append( 'D' );
00068 
00069   return data;
00070 }
00071 
00075 class CollectionRightsAttribute::Private
00076 {
00077   public:
00078     QByteArray mData;
00079 };
00080 
00081 CollectionRightsAttribute::CollectionRightsAttribute()
00082   : Attribute(), d( new Private )
00083 {
00084 }
00085 
00086 CollectionRightsAttribute::~CollectionRightsAttribute()
00087 {
00088   delete d;
00089 }
00090 
00091 void CollectionRightsAttribute::setRights( Collection::Rights rights )
00092 {
00093   d->mData = rightsToData( rights );
00094 }
00095 
00096 Collection::Rights CollectionRightsAttribute::rights() const
00097 {
00098   return dataToRights( d->mData );
00099 }
00100 
00101 CollectionRightsAttribute* CollectionRightsAttribute::clone() const
00102 {
00103   CollectionRightsAttribute *attr = new CollectionRightsAttribute();
00104   attr->d->mData = d->mData;
00105 
00106   return attr;
00107 }
00108 
00109 QByteArray CollectionRightsAttribute::type() const
00110 {
00111   return s_accessRightsIdentifier;
00112 }
00113 
00114 QByteArray CollectionRightsAttribute::serialized() const
00115 {
00116   return d->mData;
00117 }
00118 
00119 void CollectionRightsAttribute::deserialize( const QByteArray &data )
00120 {
00121   d->mData = data;
00122 }

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
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.9
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