Akonadi

collectionrightsattribute.cpp
1 /*
2  Copyright (c) 2007 Tobias Koenig <[email protected]>
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 Collection::Rights dataToRights(const QByteArray &data)
25 {
27 
28  if (data.isEmpty()) {
29  return Collection::ReadOnly;
30  }
31 
32  if (data.at(0) == 'a') {
33  return Collection::AllRights;
34  }
35 
36  for (int i = 0; i < data.count(); ++i) {
37  switch (data.at(i)) {
38  case 'w':
39  rights |= Collection::CanChangeItem;
40  break;
41  case 'c':
42  rights |= Collection::CanCreateItem;
43  break;
44  case 'd':
45  rights |= Collection::CanDeleteItem;
46  break;
47  case 'l':
48  rights |= Collection::CanLinkItem;
49  break;
50  case 'u':
51  rights |= Collection::CanUnlinkItem;
52  break;
53  case 'W':
55  break;
56  case 'C':
58  break;
59  case 'D':
61  break;
62  }
63  }
64 
65  return rights;
66 }
67 
68 static QByteArray rightsToData(Collection::Rights &rights)
69 {
70  if (rights == Collection::AllRights) {
71  return QByteArray("a");
72  }
73 
74  QByteArray data;
75  if (rights & Collection::CanChangeItem) {
76  data.append('w');
77  }
78  if (rights & Collection::CanCreateItem) {
79  data.append('c');
80  }
81  if (rights & Collection::CanDeleteItem) {
82  data.append('d');
83  }
84  if (rights & Collection::CanChangeCollection) {
85  data.append('W');
86  }
87  if (rights & Collection::CanCreateCollection) {
88  data.append('C');
89  }
90  if (rights & Collection::CanDeleteCollection) {
91  data.append('D');
92  }
93  if (rights & Collection::CanLinkItem) {
94  data.append('l');
95  }
96  if (rights & Collection::CanUnlinkItem) {
97  data.append('u');
98  }
99 
100  return data;
101 }
102 
106 class CollectionRightsAttribute::Private
107 {
108 public:
109  QByteArray mData;
110 };
111 
112 CollectionRightsAttribute::CollectionRightsAttribute()
113  : Attribute()
114  , d(new Private)
115 {
116 }
117 
118 CollectionRightsAttribute::~CollectionRightsAttribute()
119 {
120  delete d;
121 }
122 
123 void CollectionRightsAttribute::setRights(Collection::Rights rights)
124 {
125  d->mData = rightsToData(rights);
126 }
127 
128 Collection::Rights CollectionRightsAttribute::rights() const
129 {
130  return dataToRights(d->mData);
131 }
132 
133 CollectionRightsAttribute *CollectionRightsAttribute::clone() const
134 {
136  attr->d->mData = d->mData;
137 
138  return attr;
139 }
140 
141 QByteArray CollectionRightsAttribute::type() const
142 {
143  static const QByteArray s_accessRightsIdentifier("AccessRights");
144  return s_accessRightsIdentifier;
145 }
146 
147 QByteArray CollectionRightsAttribute::serialized() const
148 {
149  return d->mData;
150 }
151 
152 void CollectionRightsAttribute::deserialize(const QByteArray &data)
153 {
154  d->mData = data;
155 }
char at(int i) const const
Has all rights on this storage collection.
Definition: collection.h:102
bool isEmpty() const const
Can create new subcollections in this collection.
Definition: collection.h:98
Can change items in this collection.
Definition: collection.h:94
Provides interface for custom attributes for Entity.
Definition: attribute.h:139
Can remove links to items in this virtual collection.
Definition: collection.h:101
Can only read items or subcollection of this collection.
Definition: collection.h:93
Can create links to existing items in this virtual collection.
Definition: collection.h:100
Can delete items in this collection.
Definition: collection.h:96
Can create new items in this collection.
Definition: collection.h:95
int count(char ch) const const
Can delete this collection.
Definition: collection.h:99
QByteArray & append(char ch)
Helper integration between Akonadi and Qt.
Can change this collection.
Definition: collection.h:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.