File indexing completed on 2024-11-10 04:40:27
0001 /* 0002 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collectionrightsattribute_p.h" 0008 0009 using namespace Akonadi; 0010 0011 static Collection::Rights dataToRights(const QByteArray &data) 0012 { 0013 Collection::Rights rights = Collection::ReadOnly; 0014 0015 if (data.isEmpty()) { 0016 return Collection::ReadOnly; 0017 } 0018 0019 if (data.at(0) == 'a') { 0020 return Collection::AllRights; 0021 } 0022 0023 for (int i = 0; i < data.count(); ++i) { 0024 switch (data.at(i)) { 0025 case 'w': 0026 rights |= Collection::CanChangeItem; 0027 break; 0028 case 'c': 0029 rights |= Collection::CanCreateItem; 0030 break; 0031 case 'd': 0032 rights |= Collection::CanDeleteItem; 0033 break; 0034 case 'l': 0035 rights |= Collection::CanLinkItem; 0036 break; 0037 case 'u': 0038 rights |= Collection::CanUnlinkItem; 0039 break; 0040 case 'W': 0041 rights |= Collection::CanChangeCollection; 0042 break; 0043 case 'C': 0044 rights |= Collection::CanCreateCollection; 0045 break; 0046 case 'D': 0047 rights |= Collection::CanDeleteCollection; 0048 break; 0049 } 0050 } 0051 0052 return rights; 0053 } 0054 0055 static QByteArray rightsToData(Collection::Rights &rights) 0056 { 0057 if (rights == Collection::AllRights) { 0058 return QByteArray("a"); 0059 } 0060 0061 QByteArray data; 0062 if (rights & Collection::CanChangeItem) { 0063 data.append('w'); 0064 } 0065 if (rights & Collection::CanCreateItem) { 0066 data.append('c'); 0067 } 0068 if (rights & Collection::CanDeleteItem) { 0069 data.append('d'); 0070 } 0071 if (rights & Collection::CanChangeCollection) { 0072 data.append('W'); 0073 } 0074 if (rights & Collection::CanCreateCollection) { 0075 data.append('C'); 0076 } 0077 if (rights & Collection::CanDeleteCollection) { 0078 data.append('D'); 0079 } 0080 if (rights & Collection::CanLinkItem) { 0081 data.append('l'); 0082 } 0083 if (rights & Collection::CanUnlinkItem) { 0084 data.append('u'); 0085 } 0086 0087 return data; 0088 } 0089 0090 /** 0091 * @internal 0092 */ 0093 class Akonadi::CollectionRightsAttributePrivate 0094 { 0095 public: 0096 QByteArray mData; 0097 }; 0098 0099 CollectionRightsAttribute::CollectionRightsAttribute() 0100 : d(new CollectionRightsAttributePrivate()) 0101 { 0102 } 0103 0104 CollectionRightsAttribute::~CollectionRightsAttribute() = default; 0105 0106 void CollectionRightsAttribute::setRights(Collection::Rights rights) 0107 { 0108 d->mData = rightsToData(rights); 0109 } 0110 0111 Collection::Rights CollectionRightsAttribute::rights() const 0112 { 0113 return dataToRights(d->mData); 0114 } 0115 0116 CollectionRightsAttribute *CollectionRightsAttribute::clone() const 0117 { 0118 auto attr = new CollectionRightsAttribute(); 0119 attr->d->mData = d->mData; 0120 0121 return attr; 0122 } 0123 0124 QByteArray CollectionRightsAttribute::type() const 0125 { 0126 static const QByteArray s_accessRightsIdentifier("AccessRights"); 0127 return s_accessRightsIdentifier; 0128 } 0129 0130 QByteArray CollectionRightsAttribute::serialized() const 0131 { 0132 return d->mData; 0133 } 0134 0135 void CollectionRightsAttribute::deserialize(const QByteArray &data) 0136 { 0137 d->mData = data; 0138 }