~ubuntu-branches/ubuntu/quantal/kdepimlibs/quantal-proposed

« back to all changes in this revision

Viewing changes to kalarmcal/compatibilityattribute.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-14 14:37:07 UTC
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: package-import@ubuntu.com-20111214143707-m0qplh3hsd957ukv
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  compatibilityattribute.cpp  -  Akonadi attribute holding Collection compatibility
 
3
 *  This file is part of kalarmcal library, which provides access to KAlarm
 
4
 *  calendar data.
 
5
 *  Copyright © 2011 by David Jarvie <djarvie@kde.org>
 
6
 *
 
7
 *  This library is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU Library General Public License as published
 
9
 *  by the Free Software Foundation; either version 2 of the License, or (at
 
10
 *  your option) any later version.
 
11
 *
 
12
 *  This library is distributed in the hope that it will be useful, but WITHOUT
 
13
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
15
 *  License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU Library General Public License
 
18
 *  along with this library; see the file COPYING.LIB.  If not, write to the
 
19
 *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
 *  MA 02110-1301, USA.
 
21
 */
 
22
 
 
23
#include "compatibilityattribute.h"
 
24
 
 
25
#include <kdebug.h>
 
26
 
 
27
namespace KAlarmCal
 
28
{
 
29
 
 
30
 
 
31
class CompatibilityAttribute::Private
 
32
{
 
33
    public:
 
34
        Private()
 
35
            : mCompatibility(KACalendar::Incompatible),
 
36
              mVersion(KACalendar::IncompatibleFormat)
 
37
            {}
 
38
 
 
39
        KACalendar::Compat mCompatibility;    // calendar compatibility with current KAlarm format
 
40
        int                mVersion;          // KAlarm calendar format version
 
41
};
 
42
 
 
43
    
 
44
CompatibilityAttribute::CompatibilityAttribute()
 
45
    : d(new Private)
 
46
{
 
47
}
 
48
 
 
49
CompatibilityAttribute::CompatibilityAttribute(const CompatibilityAttribute& rhs)
 
50
    : Akonadi::Attribute(rhs),
 
51
      d(new Private(*rhs.d))
 
52
{
 
53
}
 
54
 
 
55
CompatibilityAttribute::~CompatibilityAttribute()
 
56
{
 
57
    delete d;
 
58
}
 
59
 
 
60
CompatibilityAttribute& CompatibilityAttribute::operator=(const CompatibilityAttribute& other)
 
61
{
 
62
    if (&other != this)
 
63
    {
 
64
        Attribute::operator=(other);
 
65
        *d = *other.d;
 
66
    }
 
67
    return *this;
 
68
}
 
69
 
 
70
CompatibilityAttribute* CompatibilityAttribute::clone() const
 
71
{
 
72
    return new CompatibilityAttribute(*this);
 
73
}
 
74
 
 
75
KACalendar::Compat CompatibilityAttribute::compatibility() const
 
76
{
 
77
    return d->mCompatibility;
 
78
}
 
79
 
 
80
void CompatibilityAttribute::setCompatibility(KACalendar::Compat c)
 
81
{
 
82
    d->mCompatibility = c;
 
83
}
 
84
 
 
85
int CompatibilityAttribute::version() const
 
86
{
 
87
    return d->mVersion;
 
88
}
 
89
 
 
90
void CompatibilityAttribute::setVersion(int v)
 
91
{
 
92
    d->mVersion = v;
 
93
}
 
94
 
 
95
QByteArray CompatibilityAttribute::type() const
 
96
{
 
97
    return name();
 
98
}
 
99
 
 
100
QByteArray CompatibilityAttribute::name()
 
101
{
 
102
    return "KAlarmCompatibility";
 
103
}
 
104
 
 
105
QByteArray CompatibilityAttribute::serialized() const
 
106
{
 
107
    QByteArray v = QByteArray::number(d->mCompatibility) + ' '
 
108
                 + QByteArray::number(d->mVersion);
 
109
    kDebug() << v;
 
110
    return v;
 
111
}
 
112
 
 
113
void CompatibilityAttribute::deserialize(const QByteArray& data)
 
114
{
 
115
    kDebug() << data;
 
116
 
 
117
    // Set default values
 
118
    d->mCompatibility = KACalendar::Incompatible;
 
119
    d->mVersion       = KACalendar::IncompatibleFormat;
 
120
 
 
121
    bool ok;
 
122
    const QList<QByteArray> items = data.simplified().split(' ');
 
123
    int count = items.count();
 
124
    int index = 0;
 
125
    if (count > index)
 
126
    {
 
127
        // 0: calendar format compatibility
 
128
        int c = items[index++].toInt(&ok);
 
129
        KACalendar::Compat AllCompat(KACalendar::Current | KACalendar::Converted | KACalendar::Convertible | KACalendar::Incompatible | KACalendar::Unknown);
 
130
        if (!ok  ||  (c & AllCompat) != c)
 
131
        {
 
132
            kError() << "Invalid compatibility:" << c;
 
133
            return;
 
134
        }
 
135
        d->mCompatibility = static_cast<KACalendar::Compat>(c);
 
136
    }
 
137
    if (count > index)
 
138
    {
 
139
        // 1: KAlarm calendar version number
 
140
        int c = items[index++].toInt(&ok);
 
141
        if (!ok)
 
142
        {
 
143
            kError() << "Invalid version:" << c;
 
144
            return;
 
145
        }
 
146
        d->mVersion = c;
 
147
    }
 
148
}
 
149
 
 
150
} // namespace KAlarmCal
 
151
 
 
152
// vim: et sw=4: