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

KAlarm Library

compatibilityattribute.cpp
00001 /*
00002  *  compatibilityattribute.cpp  -  Akonadi attribute holding Collection compatibility
00003  *  This file is part of kalarmcal library, which provides access to KAlarm
00004  *  calendar data.
00005  *  Copyright © 2011 by David Jarvie <djarvie@kde.org>
00006  *
00007  *  This library is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU Library General Public License as published
00009  *  by the Free Software Foundation; either version 2 of the License, or (at
00010  *  your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful, but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015  *  License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public License
00018  *  along with this library; see the file COPYING.LIB.  If not, write to the
00019  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  *  MA 02110-1301, USA.
00021  */
00022 
00023 #include "compatibilityattribute.h"
00024 
00025 #include <kdebug.h>
00026 
00027 namespace KAlarmCal
00028 {
00029 
00030 
00031 class CompatibilityAttribute::Private
00032 {
00033     public:
00034         Private()
00035             : mCompatibility(KACalendar::Incompatible),
00036               mVersion(KACalendar::IncompatibleFormat)
00037             {}
00038 
00039         KACalendar::Compat mCompatibility;    // calendar compatibility with current KAlarm format
00040         int                mVersion;          // KAlarm calendar format version
00041 };
00042  
00043     
00044 CompatibilityAttribute::CompatibilityAttribute()
00045     : d(new Private)
00046 {
00047 }
00048 
00049 CompatibilityAttribute::CompatibilityAttribute(const CompatibilityAttribute& rhs)
00050     : Akonadi::Attribute(rhs),
00051       d(new Private(*rhs.d))
00052 {
00053 }
00054 
00055 CompatibilityAttribute::~CompatibilityAttribute()
00056 {
00057     delete d;
00058 }
00059 
00060 CompatibilityAttribute& CompatibilityAttribute::operator=(const CompatibilityAttribute& other)
00061 {
00062     if (&other != this)
00063     {
00064         Attribute::operator=(other);
00065         *d = *other.d;
00066     }
00067     return *this;
00068 }
00069 
00070 CompatibilityAttribute* CompatibilityAttribute::clone() const
00071 {
00072     return new CompatibilityAttribute(*this);
00073 }
00074 
00075 KACalendar::Compat CompatibilityAttribute::compatibility() const
00076 {
00077     return d->mCompatibility;
00078 }
00079 
00080 void CompatibilityAttribute::setCompatibility(KACalendar::Compat c)
00081 {
00082     d->mCompatibility = c;
00083 }
00084 
00085 int CompatibilityAttribute::version() const
00086 {
00087     return d->mVersion;
00088 }
00089 
00090 void CompatibilityAttribute::setVersion(int v)
00091 {
00092     d->mVersion = v;
00093 }
00094 
00095 QByteArray CompatibilityAttribute::type() const
00096 {
00097     return name();
00098 }
00099 
00100 QByteArray CompatibilityAttribute::name()
00101 {
00102     return "KAlarmCompatibility";
00103 }
00104 
00105 QByteArray CompatibilityAttribute::serialized() const
00106 {
00107     QByteArray v = QByteArray::number(d->mCompatibility) + ' '
00108                  + QByteArray::number(d->mVersion);
00109     kDebug() << v;
00110     return v;
00111 }
00112 
00113 void CompatibilityAttribute::deserialize(const QByteArray& data)
00114 {
00115     kDebug() << data;
00116 
00117     // Set default values
00118     d->mCompatibility = KACalendar::Incompatible;
00119     d->mVersion       = KACalendar::IncompatibleFormat;
00120 
00121     bool ok;
00122     const QList<QByteArray> items = data.simplified().split(' ');
00123     int count = items.count();
00124     int index = 0;
00125     if (count > index)
00126     {
00127         // 0: calendar format compatibility
00128         int c = items[index++].toInt(&ok);
00129         KACalendar::Compat AllCompat(KACalendar::Current | KACalendar::Converted | KACalendar::Convertible | KACalendar::Incompatible | KACalendar::Unknown);
00130         if (!ok  ||  (c & AllCompat) != c)
00131         {
00132             kError() << "Invalid compatibility:" << c;
00133             return;
00134         }
00135         d->mCompatibility = static_cast<KACalendar::Compat>(c);
00136     }
00137     if (count > index)
00138     {
00139         // 1: KAlarm calendar version number
00140         int c = items[index++].toInt(&ok);
00141         if (!ok)
00142         {
00143             kError() << "Invalid version:" << c;
00144             return;
00145         }
00146         d->mVersion = c;
00147     }
00148 }
00149 
00150 } // namespace KAlarmCal
00151 
00152 // vim: et sw=4:
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:10:38 by doxygen 1.7.5 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-4.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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