akonadi
collectionrightsattribute.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "collectionrightsattribute.h"
00021
00022 using namespace Akonadi;
00023
00024 static const char* s_accessRightsIdentifier = "AccessRights";
00025
00026 static Collection::Rights dataToRights( const QByteArray &data )
00027 {
00028 Collection::Rights rights = Collection::ReadOnly;
00029
00030 if ( data.isEmpty() || data.at( 0 ) == 'a' )
00031 return Collection::AllRights;
00032
00033 for ( int i = 0; i < data.count(); ++i ) {
00034 switch ( data.at( i ) ) {
00035 case 'w': rights |= Collection::CanChangeItem; break;
00036 case 'c': rights |= Collection::CanCreateItem; break;
00037 case 'd': rights |= Collection::CanDeleteItem; break;
00038 case 'W': rights |= Collection::CanChangeCollection; break;
00039 case 'C': rights |= Collection::CanCreateCollection; break;
00040 case 'D': rights |= Collection::CanDeleteCollection; break;
00041 }
00042 }
00043
00044 return rights;
00045 }
00046
00047 static QByteArray rightsToData( Collection::Rights &rights )
00048 {
00049 if ( rights == Collection::AllRights )
00050 return QByteArray( "a" );
00051
00052 QByteArray data;
00053 if ( rights & Collection::CanChangeItem )
00054 data.append( 'w' );
00055 if ( rights & Collection::CanCreateItem )
00056 data.append( 'c' );
00057 if ( rights & Collection::CanDeleteItem )
00058 data.append( 'd' );
00059 if ( rights & Collection::CanChangeCollection )
00060 data.append( 'W' );
00061 if ( rights & Collection::CanCreateCollection )
00062 data.append( 'C' );
00063 if ( rights & Collection::CanDeleteCollection )
00064 data.append( 'D' );
00065
00066 return data;
00067 }
00068
00072 class CollectionRightsAttribute::Private
00073 {
00074 public:
00075 QByteArray mData;
00076 };
00077
00078 CollectionRightsAttribute::CollectionRightsAttribute()
00079 : Attribute(), d( new Private )
00080 {
00081 }
00082
00083 CollectionRightsAttribute::~CollectionRightsAttribute()
00084 {
00085 delete d;
00086 }
00087
00088 void CollectionRightsAttribute::setRights( Collection::Rights rights )
00089 {
00090 d->mData = rightsToData( rights );
00091 }
00092
00093 Collection::Rights CollectionRightsAttribute::rights() const
00094 {
00095 return dataToRights( d->mData );
00096 }
00097
00098 CollectionRightsAttribute* CollectionRightsAttribute::clone() const
00099 {
00100 CollectionRightsAttribute *attr = new CollectionRightsAttribute();
00101 attr->d->mData = d->mData;
00102
00103 return attr;
00104 }
00105
00106 QByteArray CollectionRightsAttribute::type() const
00107 {
00108 return s_accessRightsIdentifier;
00109 }
00110
00111 QByteArray CollectionRightsAttribute::serialized() const
00112 {
00113 return d->mData;
00114 }
00115
00116 void CollectionRightsAttribute::deserialize( const QByteArray &data )
00117 {
00118 d->mData = data;
00119 }