• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.5 API Reference
  • KDE Home
  • 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 'l': rights |= Collection::CanLinkItem; break;
00042       case 'u': rights |= Collection::CanUnlinkItem; break;
00043       case 'W': rights |= Collection::CanChangeCollection; break;
00044       case 'C': rights |= Collection::CanCreateCollection; break;
00045       case 'D': rights |= Collection::CanDeleteCollection; break;
00046     }
00047   }
00048 
00049   return rights;
00050 }
00051 
00052 static QByteArray rightsToData( Collection::Rights &rights )
00053 {
00054   if ( rights == Collection::AllRights )
00055     return QByteArray( "a" );
00056 
00057   QByteArray data;
00058   if ( rights & Collection::CanChangeItem )
00059     data.append( 'w' );
00060   if ( rights & Collection::CanCreateItem )
00061     data.append( 'c' );
00062   if ( rights & Collection::CanDeleteItem )
00063     data.append( 'd' );
00064   if ( rights & Collection::CanChangeCollection )
00065     data.append( 'W' );
00066   if ( rights & Collection::CanCreateCollection )
00067     data.append( 'C' );
00068   if ( rights & Collection::CanDeleteCollection )
00069     data.append( 'D' );
00070   if ( rights & Collection::CanLinkItem )
00071     data.append( 'l' );
00072   if ( rights & Collection::CanUnlinkItem )
00073     data.append( 'u' );
00074 
00075   return data;
00076 }
00077 
00081 class CollectionRightsAttribute::Private
00082 {
00083   public:
00084     QByteArray mData;
00085 };
00086 
00087 CollectionRightsAttribute::CollectionRightsAttribute()
00088   : Attribute(), d( new Private )
00089 {
00090 }
00091 
00092 CollectionRightsAttribute::~CollectionRightsAttribute()
00093 {
00094   delete d;
00095 }
00096 
00097 void CollectionRightsAttribute::setRights( Collection::Rights rights )
00098 {
00099   d->mData = rightsToData( rights );
00100 }
00101 
00102 Collection::Rights CollectionRightsAttribute::rights() const
00103 {
00104   return dataToRights( d->mData );
00105 }
00106 
00107 CollectionRightsAttribute* CollectionRightsAttribute::clone() const
00108 {
00109   CollectionRightsAttribute *attr = new CollectionRightsAttribute();
00110   attr->d->mData = d->mData;
00111 
00112   return attr;
00113 }
00114 
00115 QByteArray CollectionRightsAttribute::type() const
00116 {
00117   return s_accessRightsIdentifier;
00118 }
00119 
00120 QByteArray CollectionRightsAttribute::serialized() const
00121 {
00122   return d->mData;
00123 }
00124 
00125 void CollectionRightsAttribute::deserialize( const QByteArray &data )
00126 {
00127   d->mData = data;
00128 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:21 by doxygen 1.7.5 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.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 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