• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.1 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
collectionrightsattribute.cpp
1 /*
2  Copyright (c) 2007 Tobias Koenig <tokoe@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 "collectionrightsattribute_p.h"
21 
22 using namespace Akonadi;
23 
24 static const char* s_accessRightsIdentifier = "AccessRights";
25 
26 static Collection::Rights dataToRights( const QByteArray &data )
27 {
28  Collection::Rights rights = Collection::ReadOnly;
29 
30  if ( data.isEmpty() )
31  return Collection::ReadOnly;
32 
33  if ( data.at( 0 ) == 'a' )
34  return Collection::AllRights;
35 
36  for ( int i = 0; i < data.count(); ++i ) {
37  switch ( data.at( i ) ) {
38  case 'w': rights |= Collection::CanChangeItem; break;
39  case 'c': rights |= Collection::CanCreateItem; break;
40  case 'd': rights |= Collection::CanDeleteItem; break;
41  case 'l': rights |= Collection::CanLinkItem; break;
42  case 'u': rights |= Collection::CanUnlinkItem; break;
43  case 'W': rights |= Collection::CanChangeCollection; break;
44  case 'C': rights |= Collection::CanCreateCollection; break;
45  case 'D': rights |= Collection::CanDeleteCollection; break;
46  }
47  }
48 
49  return rights;
50 }
51 
52 static QByteArray rightsToData( Collection::Rights &rights )
53 {
54  if ( rights == Collection::AllRights )
55  return QByteArray( "a" );
56 
57  QByteArray data;
58  if ( rights & Collection::CanChangeItem )
59  data.append( 'w' );
60  if ( rights & Collection::CanCreateItem )
61  data.append( 'c' );
62  if ( rights & Collection::CanDeleteItem )
63  data.append( 'd' );
64  if ( rights & Collection::CanChangeCollection )
65  data.append( 'W' );
66  if ( rights & Collection::CanCreateCollection )
67  data.append( 'C' );
68  if ( rights & Collection::CanDeleteCollection )
69  data.append( 'D' );
70  if ( rights & Collection::CanLinkItem )
71  data.append( 'l' );
72  if ( rights & Collection::CanUnlinkItem )
73  data.append( 'u' );
74 
75  return data;
76 }
77 
81 class CollectionRightsAttribute::Private
82 {
83  public:
84  QByteArray mData;
85 };
86 
87 CollectionRightsAttribute::CollectionRightsAttribute()
88  : Attribute(), d( new Private )
89 {
90 }
91 
92 CollectionRightsAttribute::~CollectionRightsAttribute()
93 {
94  delete d;
95 }
96 
97 void CollectionRightsAttribute::setRights( Collection::Rights rights )
98 {
99  d->mData = rightsToData( rights );
100 }
101 
102 Collection::Rights CollectionRightsAttribute::rights() const
103 {
104  return dataToRights( d->mData );
105 }
106 
107 CollectionRightsAttribute* CollectionRightsAttribute::clone() const
108 {
109  CollectionRightsAttribute *attr = new CollectionRightsAttribute();
110  attr->d->mData = d->mData;
111 
112  return attr;
113 }
114 
115 QByteArray CollectionRightsAttribute::type() const
116 {
117  return s_accessRightsIdentifier;
118 }
119 
120 QByteArray CollectionRightsAttribute::serialized() const
121 {
122  return d->mData;
123 }
124 
125 void CollectionRightsAttribute::deserialize( const QByteArray &data )
126 {
127  d->mData = data;
128 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:06:25 by doxygen 1.8.1.1 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.1 API Reference

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