collectionquotaattribute.cpp
00001 /* 00002 Copyright (C) 2009 Kevin Ottens <ervin@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "collectionquotaattribute.h" 00021 00022 #include <QtCore/QByteArray> 00023 00024 using namespace Akonadi; 00025 00026 class CollectionQuotaAttribute::Private 00027 { 00028 public: 00029 Private( qint64 currentValue, qint64 maxValue ) 00030 : mCurrentValue( currentValue ), mMaximumValue( maxValue ) 00031 { 00032 } 00033 00034 qint64 mCurrentValue; 00035 qint64 mMaximumValue; 00036 }; 00037 00038 CollectionQuotaAttribute::CollectionQuotaAttribute() 00039 : d( new Private( -1, -1 ) ) 00040 { 00041 } 00042 00043 CollectionQuotaAttribute::CollectionQuotaAttribute( qint64 currentValue, qint64 maxValue ) 00044 : d( new Private( currentValue, maxValue ) ) 00045 { 00046 } 00047 00048 CollectionQuotaAttribute::~CollectionQuotaAttribute() 00049 { 00050 delete d; 00051 } 00052 00053 void CollectionQuotaAttribute::setCurrentValue( qint64 value ) 00054 { 00055 d->mCurrentValue = value; 00056 } 00057 00058 void CollectionQuotaAttribute::setMaximumValue( qint64 value ) 00059 { 00060 d->mMaximumValue = value; 00061 } 00062 00063 qint64 CollectionQuotaAttribute::currentValue() const 00064 { 00065 return d->mCurrentValue; 00066 } 00067 00068 qint64 CollectionQuotaAttribute::maximumValue() const 00069 { 00070 return d->mMaximumValue; 00071 } 00072 00073 QByteArray CollectionQuotaAttribute::type() const 00074 { 00075 return "collectionquota"; 00076 } 00077 00078 Akonadi::Attribute* CollectionQuotaAttribute::clone() const 00079 { 00080 return new CollectionQuotaAttribute( d->mCurrentValue, d->mMaximumValue ); 00081 } 00082 00083 QByteArray CollectionQuotaAttribute::serialized() const 00084 { 00085 return QByteArray::number( d->mCurrentValue ) 00086 + ' ' 00087 + QByteArray::number( d->mMaximumValue ); 00088 } 00089 00090 void CollectionQuotaAttribute::deserialize( const QByteArray &data ) 00091 { 00092 d->mCurrentValue = -1; 00093 d->mMaximumValue = -1; 00094 00095 const QList<QByteArray> items = data.simplified().split( ' ' ); 00096 00097 if ( items.isEmpty() ) 00098 return; 00099 00100 d->mCurrentValue = items[0].toLongLong(); 00101 00102 if ( items.size() < 2 ) 00103 return; 00104 00105 d->mMaximumValue = items[1].toLongLong(); 00106 }