Akonadi

collectionrightsattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "collectionrightsattribute_p.h"
8 
9 using namespace Akonadi;
10 
11 static Collection::Rights dataToRights(const QByteArray &data)
12 {
14 
15  if (data.isEmpty()) {
16  return Collection::ReadOnly;
17  }
18 
19  if (data.at(0) == 'a') {
20  return Collection::AllRights;
21  }
22 
23  for (int i = 0; i < data.count(); ++i) {
24  switch (data.at(i)) {
25  case 'w':
26  rights |= Collection::CanChangeItem;
27  break;
28  case 'c':
29  rights |= Collection::CanCreateItem;
30  break;
31  case 'd':
32  rights |= Collection::CanDeleteItem;
33  break;
34  case 'l':
35  rights |= Collection::CanLinkItem;
36  break;
37  case 'u':
38  rights |= Collection::CanUnlinkItem;
39  break;
40  case 'W':
42  break;
43  case 'C':
45  break;
46  case 'D':
48  break;
49  }
50  }
51 
52  return rights;
53 }
54 
55 static QByteArray rightsToData(Collection::Rights &rights)
56 {
57  if (rights == Collection::AllRights) {
58  return QByteArray("a");
59  }
60 
61  QByteArray data;
62  if (rights & Collection::CanChangeItem) {
63  data.append('w');
64  }
65  if (rights & Collection::CanCreateItem) {
66  data.append('c');
67  }
68  if (rights & Collection::CanDeleteItem) {
69  data.append('d');
70  }
71  if (rights & Collection::CanChangeCollection) {
72  data.append('W');
73  }
74  if (rights & Collection::CanCreateCollection) {
75  data.append('C');
76  }
77  if (rights & Collection::CanDeleteCollection) {
78  data.append('D');
79  }
80  if (rights & Collection::CanLinkItem) {
81  data.append('l');
82  }
83  if (rights & Collection::CanUnlinkItem) {
84  data.append('u');
85  }
86 
87  return data;
88 }
89 
90 /**
91  * @internal
92  */
93 class Akonadi::CollectionRightsAttributePrivate
94 {
95 public:
96  QByteArray mData;
97 };
98 
99 CollectionRightsAttribute::CollectionRightsAttribute()
100  : d(new CollectionRightsAttributePrivate())
101 {
102 }
103 
104 CollectionRightsAttribute::~CollectionRightsAttribute() = default;
105 
106 void CollectionRightsAttribute::setRights(Collection::Rights rights)
107 {
108  d->mData = rightsToData(rights);
109 }
110 
111 Collection::Rights CollectionRightsAttribute::rights() const
112 {
113  return dataToRights(d->mData);
114 }
115 
116 CollectionRightsAttribute *CollectionRightsAttribute::clone() const
117 {
118  auto attr = new CollectionRightsAttribute();
119  attr->d->mData = d->mData;
120 
121  return attr;
122 }
123 
124 QByteArray CollectionRightsAttribute::type() const
125 {
126  static const QByteArray s_accessRightsIdentifier("AccessRights");
127  return s_accessRightsIdentifier;
128 }
129 
130 QByteArray CollectionRightsAttribute::serialized() const
131 {
132  return d->mData;
133 }
134 
135 void CollectionRightsAttribute::deserialize(const QByteArray &data)
136 {
137  d->mData = data;
138 }
@ CanCreateCollection
Can create new subcollections in this collection.
Definition: collection.h:95
@ CanChangeItem
Can change items in this collection.
Definition: collection.h:91
QByteArray & append(char ch)
@ CanCreateItem
Can create new items in this collection.
Definition: collection.h:92
@ ReadOnly
Can only read items or subcollection of this collection.
Definition: collection.h:90
char at(int i) const const
@ CanChangeCollection
Can change this collection.
Definition: collection.h:94
@ AllRights
Has all rights on this storage collection.
Definition: collection.h:99
int count(char ch) const const
@ CanDeleteCollection
Can delete this collection.
Definition: collection.h:96
bool isEmpty() const const
@ CanUnlinkItem
Can remove links to items in this virtual collection.
Definition: collection.h:98
@ CanDeleteItem
Can delete items in this collection.
Definition: collection.h:93
@ CanLinkItem
Can create links to existing items in this virtual collection.
Definition: collection.h:97
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.