• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kalarmcal
compatibilityattribute.cpp
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 class CompatibilityAttribute::Private
31 {
32  public:
33  Private()
34  : mCompatibility(KACalendar::Incompatible),
35  mVersion(KACalendar::IncompatibleFormat)
36  {}
37 
38  KACalendar::Compat mCompatibility; // calendar compatibility with current KAlarm format
39  int mVersion; // KAlarm calendar format version
40 };
41 
42 CompatibilityAttribute::CompatibilityAttribute()
43  : d(new Private)
44 {
45 }
46 
47 CompatibilityAttribute::CompatibilityAttribute(const CompatibilityAttribute& rhs)
48  : Akonadi::Attribute(rhs),
49  d(new Private(*rhs.d))
50 {
51 }
52 
53 CompatibilityAttribute::~CompatibilityAttribute()
54 {
55  delete d;
56 }
57 
58 CompatibilityAttribute& CompatibilityAttribute::operator=(const CompatibilityAttribute& other)
59 {
60  if (&other != this)
61  {
62  Attribute::operator=(other);
63  *d = *other.d;
64  }
65  return *this;
66 }
67 
68 CompatibilityAttribute* CompatibilityAttribute::clone() const
69 {
70  return new CompatibilityAttribute(*this);
71 }
72 
73 KACalendar::Compat CompatibilityAttribute::compatibility() const
74 {
75  return d->mCompatibility;
76 }
77 
78 void CompatibilityAttribute::setCompatibility(KACalendar::Compat c)
79 {
80  d->mCompatibility = c;
81 }
82 
83 int CompatibilityAttribute::version() const
84 {
85  return d->mVersion;
86 }
87 
88 void CompatibilityAttribute::setVersion(int v)
89 {
90  d->mVersion = v;
91 }
92 
93 QByteArray CompatibilityAttribute::type() const
94 {
95  return name();
96 }
97 
98 QByteArray CompatibilityAttribute::name()
99 {
100  return "KAlarmCompatibility";
101 }
102 
103 QByteArray CompatibilityAttribute::serialized() const
104 {
105  QByteArray v = QByteArray::number(d->mCompatibility) + ' '
106  + QByteArray::number(d->mVersion);
107  kDebug() << v;
108  return v;
109 }
110 
111 void CompatibilityAttribute::deserialize(const QByteArray& data)
112 {
113  kDebug() << data;
114 
115  // Set default values
116  d->mCompatibility = KACalendar::Incompatible;
117  d->mVersion = KACalendar::IncompatibleFormat;
118 
119  bool ok;
120  const QList<QByteArray> items = data.simplified().split(' ');
121  int count = items.count();
122  int index = 0;
123  if (count > index)
124  {
125  // 0: calendar format compatibility
126  int c = items[index++].toInt(&ok);
127  KACalendar::Compat AllCompat(KACalendar::Current | KACalendar::Converted | KACalendar::Convertible | KACalendar::Incompatible | KACalendar::Unknown);
128  if (!ok || (c & AllCompat) != c)
129  {
130  kError() << "Invalid compatibility:" << c;
131  return;
132  }
133  d->mCompatibility = static_cast<KACalendar::Compat>(c);
134  }
135  if (count > index)
136  {
137  // 1: KAlarm calendar version number
138  int c = items[index++].toInt(&ok);
139  if (!ok)
140  {
141  kError() << "Invalid version:" << c;
142  return;
143  }
144  d->mVersion = c;
145  }
146 }
147 
148 } // namespace KAlarmCal
149 
150 // vim: et sw=4:
KAlarmCal::CompatibilityAttribute::CompatibilityAttribute
CompatibilityAttribute()
Default constructor.
Definition: compatibilityattribute.cpp:42
KAlarmCal::KACalendar::IncompatibleFormat
not written by KAlarm, or a newer KAlarm version
Definition: kacalendar.h:101
KAlarmCal::KACalendar::Incompatible
not written by KAlarm, or in a newer KAlarm version
Definition: kacalendar.h:77
KAlarmCal::CompatibilityAttribute::serialized
virtual QByteArray serialized() const
Reimplemented from Attribute.
Definition: compatibilityattribute.cpp:103
KAlarmCal::CompatibilityAttribute::setCompatibility
void setCompatibility(KACalendar::Compat c)
Set the compatibility status for the entity.
Definition: compatibilityattribute.cpp:78
KAlarmCal::KACalendar::Convertible
in an older KAlarm format
Definition: kacalendar.h:76
KAlarmCal::KACalendar::Converted
in current KAlarm format, but not yet saved
Definition: kacalendar.h:75
KAlarmCal::KACalendar::Unknown
format not determined
Definition: kacalendar.h:73
KAlarmCal::CompatibilityAttribute::setVersion
void setVersion(int v)
Set the KAlarm version of the backend calendar format.
Definition: compatibilityattribute.cpp:88
KAlarmCal::CompatibilityAttribute::compatibility
KACalendar::Compat compatibility() const
Return the compatibility status for the entity.
Definition: compatibilityattribute.cpp:73
KAlarmCal::CompatibilityAttribute::deserialize
virtual void deserialize(const QByteArray &data)
Reimplemented from Attribute.
Definition: compatibilityattribute.cpp:111
KAlarmCal::CompatibilityAttribute::version
int version() const
Return the KAlarm version of the backend calendar format.
Definition: compatibilityattribute.cpp:83
KAlarmCal::CompatibilityAttribute::name
static QByteArray name()
Return the attribute name.
Definition: compatibilityattribute.cpp:98
KAlarmCal::CompatibilityAttribute::clone
virtual CompatibilityAttribute * clone() const
Reimplemented from Attribute.
Definition: compatibilityattribute.cpp:68
KAlarmCal::CompatibilityAttribute::operator=
CompatibilityAttribute & operator=(const CompatibilityAttribute &other)
Assignment operator.
Definition: compatibilityattribute.cpp:58
KAlarmCal::KACalendar::Current
in current KAlarm format
Definition: kacalendar.h:74
KAlarmCal::CompatibilityAttribute::type
virtual QByteArray type() const
Reimplemented from Attribute.
Definition: compatibilityattribute.cpp:93
KAlarmCal::CompatibilityAttribute
An Attribute for a KAlarm Collection containing compatibility information.
Definition: compatibilityattribute.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KAlarm Library

Skip menu "KAlarm Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal