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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 
34  if ( data.at( 0 ) == 'a' ) {
35  return Collection::AllRights;
36  }
37 
38  for ( int i = 0; i < data.count(); ++i ) {
39  switch ( data.at( i ) ) {
40  case 'w': rights |= Collection::CanChangeItem; break;
41  case 'c': rights |= Collection::CanCreateItem; break;
42  case 'd': rights |= Collection::CanDeleteItem; break;
43  case 'l': rights |= Collection::CanLinkItem; break;
44  case 'u': rights |= Collection::CanUnlinkItem; break;
45  case 'W': rights |= Collection::CanChangeCollection; break;
46  case 'C': rights |= Collection::CanCreateCollection; break;
47  case 'D': rights |= Collection::CanDeleteCollection; break;
48  }
49  }
50 
51  return rights;
52 }
53 
54 static QByteArray rightsToData( Collection::Rights &rights )
55 {
56  if ( rights == Collection::AllRights ) {
57  return QByteArray( "a" );
58  }
59 
60  QByteArray data;
61  if ( rights & Collection::CanChangeItem ) {
62  data.append( 'w' );
63  }
64  if ( rights & Collection::CanCreateItem ) {
65  data.append( 'c' );
66  }
67  if ( rights & Collection::CanDeleteItem ) {
68  data.append( 'd' );
69  }
70  if ( rights & Collection::CanChangeCollection ) {
71  data.append( 'W' );
72  }
73  if ( rights & Collection::CanCreateCollection ) {
74  data.append( 'C' );
75  }
76  if ( rights & Collection::CanDeleteCollection ) {
77  data.append( 'D' );
78  }
79  if ( rights & Collection::CanLinkItem ) {
80  data.append( 'l' );
81  }
82  if ( rights & Collection::CanUnlinkItem ) {
83  data.append( 'u' );
84  }
85 
86  return data;
87 }
88 
92 class CollectionRightsAttribute::Private
93 {
94  public:
95  QByteArray mData;
96 };
97 
98 CollectionRightsAttribute::CollectionRightsAttribute()
99  : Attribute(), d( new Private )
100 {
101 }
102 
103 CollectionRightsAttribute::~CollectionRightsAttribute()
104 {
105  delete d;
106 }
107 
108 void CollectionRightsAttribute::setRights( Collection::Rights rights )
109 {
110  d->mData = rightsToData( rights );
111 }
112 
113 Collection::Rights CollectionRightsAttribute::rights() const
114 {
115  return dataToRights( d->mData );
116 }
117 
118 CollectionRightsAttribute* CollectionRightsAttribute::clone() const
119 {
120  CollectionRightsAttribute *attr = new CollectionRightsAttribute();
121  attr->d->mData = d->mData;
122 
123  return attr;
124 }
125 
126 QByteArray CollectionRightsAttribute::type() const
127 {
128  return s_accessRightsIdentifier;
129 }
130 
131 QByteArray CollectionRightsAttribute::serialized() const
132 {
133  return d->mData;
134 }
135 
136 void CollectionRightsAttribute::deserialize( const QByteArray &data )
137 {
138  d->mData = data;
139 }
Akonadi::CollectionRightsAttribute::type
virtual QByteArray type() const
Returns the type of the attribute.
Definition: collectionrightsattribute.cpp:126
Akonadi::Collection::AllRights
Has all rights on this storage collection.
Definition: collection.h:96
Akonadi::Collection::CanCreateCollection
Can create new subcollections in this collection.
Definition: collection.h:92
Akonadi::Collection::CanChangeItem
Can change items in this collection.
Definition: collection.h:88
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::Collection::CanUnlinkItem
Can remove links to items in this virtual collection.
Definition: collection.h:95
Akonadi::Collection::ReadOnly
Can only read items or subcollection of this collection.
Definition: collection.h:87
Akonadi::Collection::CanLinkItem
Can create links to existing items in this virtual collection.
Definition: collection.h:94
Akonadi::Collection::CanDeleteItem
Can delete items in this collection.
Definition: collection.h:90
Akonadi::CollectionRightsAttribute::clone
virtual CollectionRightsAttribute * clone() const
Creates a copy of this attribute.
Definition: collectionrightsattribute.cpp:118
Akonadi::Collection::CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::Collection::CanDeleteCollection
Can delete this collection.
Definition: collection.h:93
Akonadi::CollectionRightsAttribute::setRights
void setRights(Collection::Rights rights)
Sets the rights of the collection.
Definition: collectionrightsattribute.cpp:108
Akonadi::CollectionRightsAttribute
Attribute that stores the rights of a collection.
Definition: collectionrightsattribute_p.h:44
Akonadi::CollectionRightsAttribute::CollectionRightsAttribute
CollectionRightsAttribute()
Creates a new collection rights attribute.
Definition: collectionrightsattribute.cpp:98
Akonadi::CollectionRightsAttribute::serialized
virtual QByteArray serialized() const
Returns a QByteArray representation of the attribute which will be storaged.
Definition: collectionrightsattribute.cpp:131
Akonadi::CollectionRightsAttribute::~CollectionRightsAttribute
~CollectionRightsAttribute()
Destroys the collection rights attribute.
Definition: collectionrightsattribute.cpp:103
Akonadi::CollectionRightsAttribute::deserialize
virtual void deserialize(const QByteArray &)
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Definition: collectionrightsattribute.cpp:136
Akonadi::CollectionRightsAttribute::rights
Collection::Rights rights() const
Returns the rights of the collection.
Definition: collectionrightsattribute.cpp:113
Akonadi::Collection::CanChangeCollection
Can change this collection.
Definition: collection.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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