Akonadi

collectionrightsattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "collectionrightsattribute_p.h"
8
9using namespace Akonadi;
10
11static Collection::Rights dataToRights(const QByteArray &data)
12{
14
15 if (data.isEmpty()) {
17 }
18
19 if (data.at(0) == 'a') {
21 }
22
23 for (int i = 0; i < data.size(); ++i) {
24 switch (data.at(i)) {
25 case 'w':
27 break;
28 case 'c':
30 break;
31 case 'd':
33 break;
34 case 'l':
36 break;
37 case 'u':
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
55static 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 }
72 data.append('W');
73 }
75 data.append('C');
76 }
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 */
93class Akonadi::CollectionRightsAttributePrivate
94{
95public:
96 QByteArray mData;
97};
98
99CollectionRightsAttribute::CollectionRightsAttribute()
100 : d(new CollectionRightsAttributePrivate())
101{
102}
103
104CollectionRightsAttribute::~CollectionRightsAttribute() = default;
105
106void CollectionRightsAttribute::setRights(Collection::Rights rights)
107{
108 d->mData = rightsToData(rights);
109}
110
111Collection::Rights CollectionRightsAttribute::rights() const
112{
113 return dataToRights(d->mData);
114}
115
116CollectionRightsAttribute *CollectionRightsAttribute::clone() const
117{
118 auto attr = new CollectionRightsAttribute();
119 attr->d->mData = d->mData;
120
121 return attr;
122}
123
124QByteArray CollectionRightsAttribute::type() const
125{
126 static const QByteArray s_accessRightsIdentifier("AccessRights");
127 return s_accessRightsIdentifier;
128}
129
130QByteArray CollectionRightsAttribute::serialized() const
131{
132 return d->mData;
133}
134
135void CollectionRightsAttribute::deserialize(const QByteArray &data)
136{
137 d->mData = data;
138}
@ CanDeleteItem
Can delete items in this collection.
Definition collection.h:93
@ ReadOnly
Can only read items or subcollection of this collection.
Definition collection.h:90
@ CanDeleteCollection
Can delete this collection.
Definition collection.h:96
@ CanChangeCollection
Can change this collection.
Definition collection.h:94
@ CanCreateItem
Can create new items in this collection.
Definition collection.h:92
@ CanLinkItem
Can create links to existing items in this virtual collection.
Definition collection.h:97
@ CanCreateCollection
Can create new subcollections in this collection.
Definition collection.h:95
@ CanUnlinkItem
Can remove links to items in this virtual collection.
Definition collection.h:98
@ AllRights
Has all rights on this storage collection.
Definition collection.h:99
@ CanChangeItem
Can change items in this collection.
Definition collection.h:91
Helper integration between Akonadi and Qt.
QByteArray & append(QByteArrayView data)
char at(qsizetype i) const const
bool isEmpty() const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.