1 | /* |
2 | Copyright (C) 2009 Kevin Ottens <ervin@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "collectionquotaattribute.h" |
21 | |
22 | #include <QtCore/QByteArray> |
23 | |
24 | using namespace Akonadi; |
25 | |
26 | class CollectionQuotaAttribute::Private |
27 | { |
28 | public: |
29 | Private(qint64 currentValue, qint64 maxValue) |
30 | : mCurrentValue(currentValue) |
31 | , mMaximumValue(maxValue) |
32 | { |
33 | } |
34 | |
35 | qint64 mCurrentValue; |
36 | qint64 mMaximumValue; |
37 | }; |
38 | |
39 | CollectionQuotaAttribute::CollectionQuotaAttribute() |
40 | : d(new Private(-1, -1)) |
41 | { |
42 | } |
43 | |
44 | CollectionQuotaAttribute::CollectionQuotaAttribute(qint64 currentValue, qint64 maxValue) |
45 | : d(new Private(currentValue, maxValue)) |
46 | { |
47 | } |
48 | |
49 | CollectionQuotaAttribute::~CollectionQuotaAttribute() |
50 | { |
51 | delete d; |
52 | } |
53 | |
54 | void CollectionQuotaAttribute::setCurrentValue(qint64 value) |
55 | { |
56 | d->mCurrentValue = value; |
57 | } |
58 | |
59 | void CollectionQuotaAttribute::setMaximumValue(qint64 value) |
60 | { |
61 | d->mMaximumValue = value; |
62 | } |
63 | |
64 | qint64 CollectionQuotaAttribute::currentValue() const |
65 | { |
66 | return d->mCurrentValue; |
67 | } |
68 | |
69 | qint64 CollectionQuotaAttribute::maximumValue() const |
70 | { |
71 | return d->mMaximumValue; |
72 | } |
73 | |
74 | QByteArray CollectionQuotaAttribute::type() const |
75 | { |
76 | return "collectionquota" ; |
77 | } |
78 | |
79 | Akonadi::Attribute *CollectionQuotaAttribute::clone() const |
80 | { |
81 | return new CollectionQuotaAttribute(d->mCurrentValue, d->mMaximumValue); |
82 | } |
83 | |
84 | QByteArray CollectionQuotaAttribute::serialized() const |
85 | { |
86 | return QByteArray::number(d->mCurrentValue) |
87 | + ' ' |
88 | + QByteArray::number(d->mMaximumValue); |
89 | } |
90 | |
91 | void CollectionQuotaAttribute::deserialize(const QByteArray &data) |
92 | { |
93 | d->mCurrentValue = -1; |
94 | d->mMaximumValue = -1; |
95 | |
96 | const QList<QByteArray> items = data.simplified().split(' '); |
97 | |
98 | if (items.isEmpty()) { |
99 | return; |
100 | } |
101 | |
102 | d->mCurrentValue = items[0].toLongLong(); |
103 | |
104 | if (items.size() < 2) { |
105 | return; |
106 | } |
107 | |
108 | d->mMaximumValue = items[1].toLongLong(); |
109 | } |
110 | |