Branch 'c++/master' - c++/lib c++/tests
Christian Mollekopf
mollekopf at kolabsys.com
Tue Feb 7 11:29:45 CET 2012
c++/lib/genericxcalconverions.h | 563 ------------------------
c++/lib/kcalconversions.h | 682 -----------------------------
c++/lib/kcalkolabformat.cpp | 5
c++/lib/kolabevent.cpp | 18
c++/lib/kolabevent.h | 4
c++/lib/kolabformat.cpp | 14
c++/lib/xcalconversions.h | 906 ++++++++++++++++++++++++++-------------
c++/lib/xcardconversions.h | 11
c++/tests/CMakeLists.txt | 8
c++/tests/conversiontest.cpp | 11
c++/tests/kcalconversiontest.cpp | 2
11 files changed, 657 insertions(+), 1567 deletions(-)
New commits:
commit cabcfc5d8cec3e04a2f869a098cd3fa166f793e8
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Tue Feb 7 11:27:06 2012 +0100
Refactoring to get rid of all the unnecessary templates.
All xcal code is now in a single file and the kcalconversion are no longer.
+some general code cleanups
diff --git a/c++/lib/genericxcalconverions.h b/c++/lib/genericxcalconverions.h
deleted file mode 100644
index 6c879d5..0000000
--- a/c++/lib/genericxcalconverions.h
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * Copyright (C) 2011 Christian Mollekopf <mollekopf at kolabsys.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef KOLAB_CONVERSIONS_H
-#define KOLAB_CONVERSIONS_H
-
-#include "global_definitions.h"
-
-#include <bindings/kolabformat-xcal.hxx>
-#include <bindings/iCalendar-props.hxx>
-#include <compiled/XMLParserWrapper.h>
-
-#include <boost/shared_ptr.hpp>
-#include <boost/numeric/conversion/converter_policies.hpp>
-#include <boost/numeric/conversion/cast.hpp>
-#include <boost/foreach.hpp>
-
-#include <fstream>
-#include <iostream>
-#include "kolabcontainers.h"
-
-const char* const XCAL_VERSION = "2.0";
-const char* const XCAL_NAMESPACE = "urn:ietf:params:xml:ns:icalendar-2.0";
-
-const char* const TZ_PREFIX = "/kolab.org/";
-
-const char* const THISANDFUTURE = "THISANDFUTURE";
-
-const char* const BASE64 = "BASE64";
-
-const char* const NEEDSACTION = "NEEDS-ACTION";
-const char* const COMPLETED = "OPAQUE";
-const char* const INPROCESS = "IN-PROCESS";
-const char* const CANCELLED = "CANCELLED";
-const char* const TENTATIVE = "TENTATIVE";
-const char* const CONFIRMED = "CONFIRMED";
-const char* const DRAFT = "DRAFT";
-const char* const FINAL = "FINAL";
-
-const char* const CONFIDENTIAL = "CONFIDENTIAL";
-const char* const PRIVATE = "PRIVATE";
-const char* const PUBLIC = "PUBLIC";
-
-const char* const PARTACCEPTED = "ACCEPTED";
-const char* const PARTDECLINED = "DECLINED";
-const char* const PARTDELEGATED = "DELEGATED";
-const char* const PARTNEEDSACTION = "NEEDS-ACTION";
-const char* const PARTTENTATIVE = "TENTATIVE";
-
-const char* const CHAIR = "CHAIR";
-const char* const NONPARTICIPANT = "NON-PARTICIPANT";
-const char* const OPTIONAL = "OPT-PARTICIPANT";
-const char* const REQUIRED = "REQ-PARTICIPANT";
-
-
-namespace Kolab {
-
-
-//=== Generic ===
-
-template <typename T>
-int convertToInt(T integer)
-{
- try {
- int i = boost::numeric_cast<int>(integer);
- return i;
- } catch(boost::numeric::negative_overflow& e) {
- std::cerr << e.what();
- } catch(boost::numeric::positive_overflow& e) {
- std::cerr << e.what();
- } catch(boost::numeric::bad_numeric_cast& e) {
- std::cerr << e.what();
- }
- return 0;
-}
-
-template <typename T>
-T fromInt(int integer)
-{
- try {
- T i = boost::numeric_cast<T>(integer);
- return i;
- } catch(boost::numeric::negative_overflow& e) {
- std::cerr << e.what();
- } catch(boost::numeric::positive_overflow& e) {
- std::cerr << e.what();
- } catch(boost::numeric::bad_numeric_cast& e) {
- std::cerr << e.what();
- }
- return 0;
-}
-
-int toInt(const icalendar_2_0::IntegerPropertyType &prop)
-{
- return convertToInt<icalendar_2_0::IntegerPropertyType::integer_type>(prop.integer());
-}
-
-//----------------
-
-//=== Attendee ===
-
-std::string mapPartStat(PartStatus status)
-{
- switch (status) {
- case PartAccepted:
- return PARTACCEPTED;
- case PartDeclined:
- return PARTDECLINED;
- case PartDelegated:
- return PARTDELEGATED;
- case PartNeedsAction:
- return PARTNEEDSACTION;
- case PartTentative:
- return PARTTENTATIVE;
- }
- std::cout << "PartStat not handled: " << status;
- return std::string();
-}
-
-PartStatus mapPartStat(const std::string &status)
-{
- if (status == PARTACCEPTED) {
- return PartAccepted;
- } else if (status == PARTDECLINED) {
- return PartDeclined;
- } else if (status == PARTDELEGATED) {
- return PartDelegated;
- } else if (status == PARTNEEDSACTION) {
- return PartNeedsAction;
- } else if (status == PARTTENTATIVE) {
- return PartTentative;
- }
- std::cout << "Unhandled partstatus" << status;
- return PartNeedsAction;
-}
-
-std::string mapRole(Role status)
-{
- switch (status) {
- case Chair:
- return std::string(CHAIR);
- case NonParticipant:
- return NONPARTICIPANT;
- case Optional:
- return OPTIONAL;
- case Required:
- return REQUIRED;
- }
- std::cout << "PartStat not handled: " << status;
- return std::string();
-}
-
-Role mapRole(const std::string &status)
-{
- if (status == CHAIR) {
- return Chair;
- } else if (status == NONPARTICIPANT) {
- return NonParticipant;
- } else if (status == OPTIONAL) {
- return Optional;
- } else if (status == REQUIRED) {
- return Required;
- }
- std::cout << "Unhandled Role" << status;
- return Required;
-}
-
-
-
-
-
-//----------------
-
-///trait to convert date-time values
-template <typename T>
-struct DateTimeConverter;
-
-std::string getTimezone(const icalendar_2_0::ArrayOfParameters ¶meters) {
- for (icalendar_2_0::DateDatetimePropertyType::parameters_type::baseParameter_const_iterator it(parameters.baseParameter().begin()); it != parameters.baseParameter().end(); it++) {
- if (const icalendar_2_0::TzidParamType* tz = dynamic_cast<const icalendar_2_0::TzidParamType*> (&*it)) {
- std::string tzid = tz->text();
- if (tzid.find(TZ_PREFIX) != std::string::npos) {
- tzid.erase(0, strlen(TZ_PREFIX));
- } else {
- std::cout << "/kolab.org/ timezone prefix is missing";
- }
- return tzid;
- }
- }
- return std::string();
-}
-
-template <typename T>
-typename T::DatePtr toDate(const icalendar_2_0::DateDatetimePropertyType &dtProperty)
-{
- typedef DateTimeConverter<typename T::DateType> DC;
- typename T::DatePtr date;
- if (dtProperty.date_time()) {
- date = DC::toDate(*dtProperty.date_time());
- } else if (dtProperty.date()) {
- date = DC::toDate(*dtProperty.date());
- }
-
- if (dtProperty.parameters()) {
- const std::string &tzid = getTimezone(*dtProperty.parameters());
- if (tzid.size()) {
- DC::setTimezone(date, tzid);
- }
- }
- return date;
-}
-
-
-// template <typename T, typename I>
-// typename T::DatePtr toDate(const I &dtProperty)
-// {
-// typedef DateTimeConverter<typename T::DateType> DC;
-// typename T::DatePtr date;
-// if (dtProperty.date_time()) {
-// date = DC::toDate(*dtProperty.date_time());
-// } else if (dtProperty.date()) {
-// date = DC::toDate(*dtProperty.date());
-// }
-//
-// if (dtProperty.parameters()) {
-// const std::string &tzid = getTimezone(*dtProperty.parameters());
-// if (tzid.size()) {
-// DC::setTimezone(date, tzid);
-// }
-// }
-// return date;
-// }
-
-template <typename T> typename T::DatePtr toDate(const icalendar_2_0::UtcDatetimePropertyType &dtProperty)
-{
- typedef typename T::DateType DateType;
- typedef typename T::DatePtr DatePtr;
- typedef DateTimeConverter<DateType> DC;
-
- typename T::DatePtr date;
- if (dtProperty.date_time()) {
- date = DC::toDate(*dtProperty.date_time());
- } else { //The utc-date-time element shouldn't even exist
- date = DatePtr(new DateType());
- std::cerr << "This element shouldn't even be existing";
- //TODO Implement anyways?
- return date;
- }
- DC::setUTC(date);
- return date;
-}
-
-template <typename T, typename I>
-std::auto_ptr<I> fromDate(const typename T::DateType &dt)
-{
- typedef typename T::DateType DateType;
- typedef typename T::DatePtr DatePtr;
- typedef DateTimeConverter<DateType> DC;
-
- std::auto_ptr<I> ptr(new I);
-
- if (DC::isDateOnly(dt)) {
- ptr->date(DC::fromDate(dt));
- } else {
- ptr->date_time(DC::fromDateTime(dt));
-
- const std::string &timezone = DC::getTimezone(dt);
- if (timezone.size() != 0) {
- std::string tz(TZ_PREFIX);
- tz.append(timezone);
- icalendar_2_0::TzidParamType tzidParam(tz);
- icalendar_2_0::ArrayOfParameters parameters;
- parameters.baseParameter().push_back(tzidParam);
- ptr->parameters(parameters);
- }
- }
- return ptr;
-}
-
-template <typename T>
-void setDateTimeProperty(icalendar_2_0::DateDatetimePropertyType &date, const typename T::DateType &dt)
-{
- typedef typename T::DateType DateType;
- typedef typename T::DatePtr DatePtr;
- typedef DateTimeConverter<DateType> DC;
-
- if (DC::isDateOnly(dt)) {
- date.date(DC::fromDate(dt));
- } else {
- date.date_time(DC::fromDateTime(dt));
-
- const std::string &timezone = DC::getTimezone(dt);
- if (timezone.size() != 0) {
- std::string tz(TZ_PREFIX);
- tz.append(timezone);
- icalendar_2_0::TzidParamType tzidParam(tz);
- icalendar_2_0::ArrayOfParameters parameters;
- parameters.baseParameter().push_back(tzidParam);
- date.parameters(parameters);
- }
- }
-}
-
-template <typename T, typename I>
-std::vector<typename T::DateType> toDateTimeList(I datelistProperty)
-{
- typedef typename T::DateType DateType;
- typedef DateTimeConverter<DateType> DC;
-
- std::vector<DateType> list;
-
- std::string tzid;
- if (datelistProperty.parameters()) {
- tzid = getTimezone(*datelistProperty.parameters());
- }
- if (!datelistProperty.date().empty()) {
- BOOST_FOREACH(const xml_schema::date &d, datelistProperty.date()) {
- list.push_back(*DC::toDate(d));
- }
- } else if (!datelistProperty.date_time().empty()) {
- BOOST_FOREACH(const xml_schema::date_time &d, datelistProperty.date_time()) {
- typename DC::Ptr date = DC::toDate(d);
- if (tzid.size()) {
- date->setTimezone(tzid);
- }
- list.push_back(*date);
- }
- }
- return list;
-}
-
-template <typename T, typename I>
-std::auto_ptr<I> fromDateTimeList(const std::vector<typename T::DateType> &dtlist)
-{
- typedef typename T::DateType DateType;
- typedef typename T::DatePtr DatePtr;
- typedef DateTimeConverter<DateType> DC;
-
- std::auto_ptr<I> ptr(new I);
- BOOST_FOREACH(const DateType &dt, dtlist) {
- if (DC::isDateOnly(dt)) {
- ptr->date().push_back(DC::fromDate(dt));
- } else {
- ptr->date_time().push_back(DC::fromDateTime(dt));
- }
- //TODO handle utc
- //TODO check for equality of timezones?
- }
-
- if (!dtlist.empty() && !DC::getTimezone(dtlist.at(0)).empty()) {
- const std::string &timezone = DC::getTimezone(dtlist.at(0));
- if (timezone.size() != 0) {
- std::string tz(TZ_PREFIX);
- tz.append(timezone);
- icalendar_2_0::TzidParamType tzidParam(tz);
- icalendar_2_0::ArrayOfParameters parameters;
- parameters.baseParameter().push_back(tzidParam);
- ptr->parameters(parameters);
- }
- }
-
- return ptr;
-}
-
-
-
-///trait to convert recurrence properties
-template <typename T>
-struct RecurrenceConverter;
-
-template <typename T>
-typename T::RecurrencePtr toRRule(const icalendar_2_0::RecurType &rrule)
-{
- using namespace icalendar_2_0;
-
- typedef RecurrenceConverter< typename T::RecurrenceType> RC;
- typedef DateTimeConverter< typename T::DateType> DC;
- typedef typename T::DatePtr DatePtr;
- typedef typename T::RecurrencePtr RecurrencePtr;
- typedef typename T::RecurrenceType RecurrenceType;
-
- RecurrencePtr r(new RecurrenceType());
- RC::setType(r, rrule.freq());
- if (rrule.until()) {
- DatePtr date;
- if ((*rrule.until()).date_time()) {
- date = DC::toDate(*(*rrule.until()).date_time());
- } else if ((*rrule.until()).date()) {
- date = DC::toDate(*(*rrule.until()).date());
- }
- RC::setEndDt(r, date);
- } else if (rrule.count()) {
- RC::setCount(r, toInt(*rrule.count()));
- }
- if (rrule.interval()) {
- RC::setInterval(r, toInt(*rrule.interval()));
- } else {
- RC::setInterval(r, 1); //FIXME should be initialized to 1 in KCalCore::RecurrenceRule class (default value of interval per RFC).
- }
- RC::setBysecond(r, rrule.bysecond());
- RC::setByminute(r, rrule.byminute());
- RC::setByhour(r, rrule.byhour());
- RC::setByday(r, rrule.byday());
- RC::setBymonthday(r, rrule.bymonthday());
- RC::setByyearday(r, rrule.byyearday());
- RC::setByweekno(r, rrule.byweekno());
- RC::setBymonth(r, rrule.bymonth());
- if (rrule.wkst()) {
- RC::setWeekStart(r, *rrule.wkst());
- }
-
- return r;
-}
-
-///Trait for Incidence object
-template <typename T, typename I>
-struct IncidenceConverter;
-
-///Trait for incidence properties specialized for Event/Todo/Journal
-template <typename T> struct IncidenceTrait;
-
-
-
-
-template <typename T>
-typename T::IncidencePtr deserializeIncidence(const std::string& s, bool isUrl)
-{
- typedef typename T::IncidencePtr IncidencePtr;
- typedef typename T::IncidenceType IncidenceType;
- typedef typename T::KolabType KolabType;
-
- try {
-// xml_schema::properties props;
- std::auto_ptr<icalendar_2_0::IcalendarType> icalendar;
- if (isUrl) {
- xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseFile(s);
- if (doc.get()) {
- icalendar = icalendar_2_0::icalendar(doc);
- }
-// props.schema_location ("urn:ietf:params:xml:ns:icalendar-2.0", "../../../schemas/ical/kolabformat-xcal.xsd"); //Force schema
-// icalendar = icalendar_2_0::icalendar(s, 0, props);
- } else {
-// props.schema_location ("urn:ietf:params:xml:ns:icalendar-2.0", "/home/chrigi/work/kolab/xmlformat/libkolabxml/schemas/ical/kolabformat-xcal.xsd"); //Force schema
- xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseString(s);
- if (doc.get()) {
- icalendar = icalendar_2_0::icalendar(doc);
- }
-// icalendar = readCompiledIncidence(is, "string");
-// icalendar = icalendar_2_0::icalendar(is, 0, props);
- }
-
- if (!icalendar.get()) {
- std::cerr << "failed to parse calendar!" << std::endl;
- return IncidencePtr();
- }
-
- const icalendar_2_0::VcalendarType &vcalendar = icalendar->vcalendar();
-
- std::vector < IncidencePtr > incidences;
- for (typename xsd::cxx::tree::sequence< KolabType >::const_iterator it(T::begin(vcalendar.components())); it != T::end(vcalendar.components()); it++) {
- IncidencePtr e = IncidencePtr(new IncidenceType);
- const KolabType &event = *it;
- T::readIncidence(*e, event);
- incidences.push_back(e);
- }
-
- //TODO x_kolab_version
-
- //TODO resolve events, exceptions can be identified based on the recurrence-id attribute
-// foreach (KCalCore::Event * event, events) {
-// if (!event->hasRecurrenceId()) {
-// return event;
-// }
-// }
-
- return *incidences.begin();
- } catch (const xml_schema::exception& e) {
- std::cerr << e << std::endl;
- std::cerr << "Failed to read incidence!" << std::endl;
- }
-
- return IncidencePtr();
-
-}
-
-
-const char* const DISPLAYALARM = "DISPLAY";
-const char* const EMAILALARM = "EMAIL";
-const char* const AUDIOALARM = "AUDIO";
-
-
-template <typename T>
-std::string serializeIncidence(const typename T::IncidenceType &incidence, const std::string productid = std::string()) {
-
- using namespace icalendar_2_0;
- typedef IncidenceConverter< typename T::Incidence, typename T::IncidenceType > IC;
- typedef typename T::KolabType KolabType;
-
- try {
-
- typename KolabType::components_type eventComponents;
- T::setComponents(eventComponents, incidence);
-
- typename KolabType::properties_type::uid_type uid(IC::uid(incidence));
- typename KolabType::properties_type::dtstamp_type dtstamp;
- dtstamp.date_time(IC::dtstamp());
- typename KolabType::properties_type::created_type created;
- created.date_time(IC::created(incidence));
- typename KolabType::properties_type eventProps(uid, created, dtstamp);
-
- KolabType inc(eventProps);
- if (!eventComponents.valarm().empty()) {
- inc.components(eventComponents);
- }
- T::writeIncidence(inc, incidence);
-
-
- VcalendarType::components_type components;
- T::addIncidence(components, inc);
-
- VcalendarType::properties_type::prodid_type prodid(productid+KOLAB_LIBNAME+KOLAB_LIB_VERSION); //FIXME own version field for lib version
- VcalendarType::properties_type::version_type version(XCAL_VERSION);
- VcalendarType::properties_type::x_kolab_version_type x_kolab_version(KOLAB_FORMAT_VERSION);
-
- VcalendarType::properties_type properties(prodid, version, x_kolab_version);
-
- VcalendarType vcalendar(properties, components);
-
- IcalendarType icalendar(vcalendar);
-
- xml_schema::namespace_infomap map;
- map[""].name = XCAL_NAMESPACE;
-
- std::ostringstream ostringstream;
- icalendar_2_0::icalendar(ostringstream, icalendar, map);
- return ostringstream.str();
- } catch (const xml_schema::exception& e) {
- std::cout << "failed to write Incidence";
- return std::string();
- }
-}
-
-
-
-
-
-}
-
-#endif
\ No newline at end of file
diff --git a/c++/lib/kcalconversions.h b/c++/lib/kcalconversions.h
deleted file mode 100644
index d805194..0000000
--- a/c++/lib/kcalconversions.h
+++ /dev/null
@@ -1,682 +0,0 @@
-/*
- * Copyright (C) 2011 Christian Mollekopf <mollekopf at kolabsys.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef KOLAB_KCALCONVERSIONS_H
-#define KOLAB_KCALCONVERSIONS_H
-
-#include "genericxcalconverions.h"
-#include <KDE/KDateTime>
-#include <KDE/KDebug>
-#include <kcalcore/recurrencerule.h>
-#include <kcalcore/recurrence.h>
-#include <kcalcore/incidence.h>
-#include <KDE/KCalCore/Event>
-#include <KDE/KCalCore/Todo>
-#include <kcalcore/person.h>
-
-namespace Kolab {
-
-struct KCalCoreTypes
-{
- typedef KDateTime DateType;
- typedef boost::shared_ptr<KDateTime> DatePtr;
- typedef KCalCore::RecurrenceRule RecurrenceType;
- typedef std::auto_ptr<KCalCore::RecurrenceRule> RecurrencePtr;
- typedef QString StringType;
- typedef KCalCore::Incidence IncidenceType;
-};
-
-
-QStringList toStringList(const icalendar_2_0::TextListPropertyType &s)
-{
- QStringList d;
- const icalendar_2_0::TextListPropertyType::text_sequence &list = s.text();
- for (::xsd::cxx::tree::sequence< xml_schema::string >::const_iterator it = list.begin(); it != list.end(); it++) {
- d.append(QString::fromStdString(*it));
- }
- return d;
-}
-
-QString toString(const icalendar_2_0::TextPropertyType &s)
-{
- return QString::fromStdString(s.text());
-}
-
-void setString(icalendar_2_0::TextPropertyType &p, const QString &s)
-{
- p.text(s.toStdString());
-}
-
-// std::auto_ptr<icalendar_2_0::TextPropertyType> fromString(const QString &s)
-// {
-// return std::auto_ptr<icalendar_2_0::TextPropertyType>(new icalendar_2_0::TextPropertyType(s.toStdString()));
-// }
-
-
-typedef KCalCoreTypes::RecurrencePtr RecurrencePtr;
-
-template <> struct DateTimeConverter<KDateTime>
-{
- typedef KDateTime Type;
- typedef boost::shared_ptr<KDateTime> Ptr;
-
- static Ptr toDate(const xml_schema::date &dt)
- {
- Ptr date(new KDateTime());
- date->setDateOnly(true);
- date->setDate(QDate(dt.year(), dt.month(), dt.day()));
- return date;
- }
-
- static Ptr toDate(const xml_schema::date_time &dt)
- {
- Ptr date(new KDateTime());
- date->setDate(QDate(dt.year(), dt.month(), dt.day()));
- date->setTime(QTime(dt.hours(), dt.minutes(), dt.seconds()));
- if (dt.zone_present()) {
- date->setTimeSpec(KDateTime::Spec(KDateTime::UTC));
- }
- return date;
- }
-
- static xml_schema::date_time fromDateTime(const KDateTime &dt)
- {
- const QDate &d = dt.date();
- const QTime &t = dt.time();
- xml_schema::date_time date(d.year(), d.month(), d.day(), t.hour(), t.minute(), t.second());
- if (dt.timeType() == KDateTime::UTC) {
- //Setting both zone hours/and zone minutes to zero results in a Z being appended to indicate UTC
- date.zone_hours(0);
- date.zone_minutes(0);
- }
- return date;
- }
-
- static xml_schema::date fromDate(const KDateTime &dt)
- {
- const QDate &d = dt.date();
- xml_schema::date date(d.year(), d.month(), d.day());
- return date;
- }
-
- static void setTimezone(Ptr date, const std::string &tzid)
- {
- KTimeZone timezone(QString::fromStdString(tzid));
- KDateTime::Spec spec(timezone);
- date->setTimeSpec(spec);
- }
-
- static std::string getTimezone(const KDateTime &dt)
- {
- return dt.timeZone().name().toStdString();
- }
-
- static void setUTC(Ptr date)
- {
- if (date->timeSpec().type() != KDateTime::UTC) {
- kWarning() << "utc date wrong formatting, corrected to utc";
- date->setTimeSpec(KDateTime::Spec(KDateTime::UTC));
- }
- }
-
- static bool isDateOnly(Type date)
- {
- return date.isDateOnly();
- }
-
-};
-
-
-
-template <> struct RecurrenceConverter < KCalCore::RecurrenceRule >
-{
- typedef KCalCoreTypes::RecurrenceType Type;
- typedef KCalCoreTypes::RecurrencePtr& Ptr; //Pass by reference, otherwise auto_ptr deletes the pointer after the first pass to a function (unlike shared_ptr)
-
- static void setType(Ptr r, const icalendar_2_0::RecurType::freq_type &freq)
- {
- using namespace icalendar_2_0;
- using namespace KCalCore;
-
- switch (freq) {
- case FreqRecurType::YEARLY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rYearly);
- break;
- case FreqRecurType::MONTHLY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rMonthly);
- break;
- case FreqRecurType::WEEKLY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rWeekly);
- break;
- case FreqRecurType::DAILY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rDaily);
- break;
- case FreqRecurType::HOURLY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rHourly);
- break;
- case FreqRecurType::MINUTELY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rMinutely);
- break;
- case FreqRecurType::SECONDLY:
- r->setRecurrenceType(KCalCore::RecurrenceRule::rSecondly);
- break;
- default:
- kWarning() << "invalid unhandled recurrenc type" << freq;
- }
- }
-
- static icalendar_2_0::RecurType::freq_type type(const Type &t)
- {
- using namespace icalendar_2_0;
- using namespace KCalCore;
-
- switch (t.recurrenceType()) {
- case KCalCore::RecurrenceRule::rYearly:
- return FreqRecurType::YEARLY;
- case KCalCore::RecurrenceRule::rMonthly:
- return FreqRecurType::MONTHLY;
- case KCalCore::RecurrenceRule::rWeekly:
- return FreqRecurType::WEEKLY;
- case KCalCore::RecurrenceRule::rDaily:
- return FreqRecurType::DAILY;
- case KCalCore::RecurrenceRule::rHourly:
- return FreqRecurType::HOURLY;
- case KCalCore::RecurrenceRule::rMinutely:
- return FreqRecurType::MINUTELY;
- case KCalCore::RecurrenceRule::rSecondly:
- return FreqRecurType::SECONDLY;
- default:
- kWarning() << "invalid unhandled recurrenc type";
- }
- return 0;
- }
-
- static void setWeekStart(Ptr r, const icalendar_2_0::RecurType::wkst_type &wkst)
- {
- using namespace icalendar_2_0;
-
- switch (wkst) {
- case WeekdayRecurType::MO:
- r->setWeekStart(1);
- break;
- case WeekdayRecurType::TU:
- r->setWeekStart(2);
- break;
- case WeekdayRecurType::WE:
- r->setWeekStart(3);
- break;
- case WeekdayRecurType::TH:
- r->setWeekStart(4);
- break;
- case WeekdayRecurType::FR:
- r->setWeekStart(5);
- break;
- case WeekdayRecurType::SA:
- r->setWeekStart(6);
- break;
- case WeekdayRecurType::SU:
- r->setWeekStart(7);
- break;
- default:
- kWarning() << "invalid unhandled weekday" << wkst;
- }
- }
-
- static void setEndDt(Ptr r, KCalCoreTypes::DatePtr date )
- {
- r->setEndDt(*date);
- }
-
- static void setCount(Ptr r, int count )
- {
- r->setDuration(count);
- }
-
- static void setInterval(Ptr r, int interval )
- {
- r->setFrequency(interval);
- }
-
- static void setBysecond(Ptr r, const icalendar_2_0::RecurType::bysecond_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::bysecond_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setBySeconds(by);
- }
- }
-
- static void setByminute(Ptr r, const icalendar_2_0::RecurType::byminute_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::byminute_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByMinutes(by);
- }
- }
-
- static void setByhour(Ptr r, const icalendar_2_0::RecurType::byhour_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::byhour_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByHours(by);
- }
- }
-
- static void setByday(Ptr r, const icalendar_2_0::RecurType::byday_sequence &list)
- {
- QList<KCalCore::RecurrenceRule::WDayPos> by;
- for (icalendar_2_0::RecurType::byday_const_iterator it(list.begin()); it != list.end(); it++) {
- KCalCore::RecurrenceRule::WDayPos pos;
- //TODO implement parser for format
-// switch () {
-//
-// }
- //by.append(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByDays(by);
- }
- }
-
- static void setBymonthday(Ptr r, const icalendar_2_0::RecurType::bymonthday_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::bymonth_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByMonthDays(by);
- }
- }
-
- static void setByyearday(Ptr r, const icalendar_2_0::RecurType::byyearday_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::byyearday_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByYearDays(by);
- }
- }
-
- static void setByweekno(Ptr r, const icalendar_2_0::RecurType::byweekno_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::byweekno_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByWeekNumbers(by);
- }
- }
-
- static void setBymonth(Ptr r, const icalendar_2_0::RecurType::bymonth_sequence &list)
- {
- QList<int> by;
- for (icalendar_2_0::RecurType::bymonth_const_iterator it(list.begin()); it != list.end(); it++) {
- by.append(convertToInt<xml_schema::integer>(*it));
- }
- if (!by.isEmpty()) {
- r->setByMonths(by);
- }
- }
-};
-
-// template <typename T, typename I>
-// QList <int> &toList(QList<int> &list, const xsd::cxx::tree::sequence <T> &input) {
-// for (icalendar_2_0::RecurType::bysecond_const_iterator it(list.begin()); it != list.end(); it++) {
-// bysec.append(convertToInt<I>(*it));
-// }
-// Q_FOREACH (I i, list) {
-// list.push_back(fromInt<I>(i));
-// }
-// return list;
-// }
-
-template <typename T, typename I>
-xsd::cxx::tree::sequence <T> &toList(xsd::cxx::tree::sequence <T> &list, const QList<int> &input) {
- Q_FOREACH (int i, list) {
- list.push_back(convertToInt<I>(i));
- }
- return list;
-}
-
-
-std::auto_ptr< icalendar_2_0::RrulePropType > recurrenceProperty(const typename KCalCore::RecurrenceRule &r)
-{
- using namespace icalendar_2_0;
-
- typedef RecurrenceConverter< KCalCore::RecurrenceRule > RC;
- typedef DateTimeConverter< KDateTime> DC;
-
- std::auto_ptr< RrulePropType > rruleProp(new RrulePropType(RC::type(r)));
-
- RecurPropertyType::recur_type &recur = rruleProp->recur();
- bool ok;
- const KDateTime &endDate = r.endDt(&ok);
- if (ok) {
- RecurPropertyType::recur_type::until_type until;
- if (endDate.isDateOnly()) {
- until.date(DC::fromDate(endDate));
- } else {
- until.date_time(DC::fromDateTime(endDate));
- }
- recur.until(until);
- } else if (r.duration() > 0) {
- recur.count(fromInt<RecurType::count_type>(r.duration()));
- }
-
- if (r.frequency() > 1) {
- recur.interval(fromInt<RecurType::interval_type>(r.frequency()));
- }
-
- if (!r.bySeconds().isEmpty()) {
- RecurType::bysecond_sequence bysecond;
- recur.bysecond(toList<RecurType::bysecond_type, xml_schema::non_negative_integer>(bysecond, r.bySeconds()));
- }
- return rruleProp;
-}
-
-template <typename T>
-void setIncidenceProperties(KCalCore::Incidence &inc, const T &prop)
-{
- using namespace KCalCore;
- typedef DateTimeConverter<KDateTime> DC;
-
- inc.setUid(toString(prop.uid()));
- inc.setCreated(*toDate<KCalCoreTypes>(prop.created()));
- inc.setLastModified(*toDate<KCalCoreTypes>(prop.dtstamp()));
-
- if (prop.sequence()) {
- inc.setRevision(toInt(*prop.sequence()));
- }
-
- if (prop.class_()) {
- QString string(toString(*prop.class_()));
- KCalCore::Incidence::Secrecy sec;
- if (string == "PRIVATE") {
- sec = KCalCore::Incidence::SecrecyPrivate;
- } else if (string == "CONFIDENTIAL") {
- sec = KCalCore::Incidence::SecrecyConfidential;
- } else {
- sec = KCalCore::Incidence::SecrecyPublic;
- }
- inc.setSecrecy(sec);
- }
-
- if (prop.categories()) {
- inc.setCategories(toStringList(*prop.categories()));
- }
-
- if (prop.dtstart()) {
- const KCalCoreTypes::DatePtr date = toDate<KCalCoreTypes>(*prop.dtstart());
- inc.setDtStart(*date);
- inc.setAllDay(date->isDateOnly()); //TODO add to specification that allday depends on start date format
- }
-
- KCalCore::Recurrence *recurrence = inc.recurrence();
- if (prop.rrule()) {
- RecurrencePtr rrule = toRRule<KCalCoreTypes>(prop.rrule()->recur());
- rrule->setStartDt(recurrence->startDateTime());
- recurrence->addRRule(rrule.release());
- }
-
- if (prop.rdate()) {
- const icalendar_2_0::KolabEvent::properties_type::rdate_type &rdate = *prop.rdate();
- std::string tzid;
- if (rdate.parameters()) {
- tzid = getTimezone(*rdate.parameters());
- }
- if (rdate.date().size()) {
- Q_FOREACH(const xml_schema::date &d, rdate.date()) {
- recurrence->addRDate(DC::toDate(d)->date());
- }
- } else if (rdate.date_time().size()) {
- Q_FOREACH(const xml_schema::date_time &d, rdate.date_time()) {
- DC::Ptr date = DC::toDate(d);
- if (tzid.size()) {
- DC::setTimezone(date, tzid);
- }
- recurrence->addRDateTime(*date);
- }
- } else if (rdate.period().size()) {
- kDebug() << "the period element must not be used, ignored.";
- }
- }
-
- if (prop.exdate()) {
- //TODO
-// recurrence->addExDate();
-// recurrence->addExDateTime();
- }
-
- if (prop.recurrence_id()) {
- //TODO THISANDFUTURE range
- inc.setRecurrenceId(*toDate<KCalCoreTypes>(*prop.recurrence_id()));
- }
-
- if (prop.summary()) {
- inc.setSummary(toString(*prop.summary())); //TODO detect richtext and set flag accordingly
- }
-
- if (prop.description()) {
- inc.setDescription(toString(*prop.description())); //TODO detect richtext and set flag accordingly
- }
-
- if (prop.priority()) {
- inc.setPriority(toInt(*prop.priority()));
- }
-
- if (prop.status()) {
- const QString &status = toString(*prop.status());
- if (status == "NEEDS-ACTION") {
- inc.setStatus(Incidence::StatusNeedsAction);
- } else if (status == "COMPLETED") {
- inc.setStatus(Incidence::StatusCompleted);
- } else if (status == "IN-PROCESS") {
- inc.setStatus(Incidence::StatusInProcess);
- } else if (status == "CANCELLED") {
- inc.setStatus(Incidence::StatusCanceled);
- } else if (status == "TENTATIVE") {
- inc.setStatus(Incidence::StatusTentative);
- } else if (status == "CONFIRMED") {
- inc.setStatus(Incidence::StatusConfirmed);
- } else if (status == "DRAFT") {
- inc.setStatus(Incidence::StatusDraft);
- } else if (status == "FINAL") {
- inc.setStatus(Incidence::StatusFinal);
- }
- }
-
- if (prop.location()) {
- inc.setLocation(toString(*prop.location()));
- }
-
- if (prop.organizer()) {
-// icalendar_2_0::KolabEvent::properties_type::organizer();
-// inc.
-// KCalCore::Person person;
- }
-
- if (prop.attendee().size()) {
-
- }
-
- if (prop.attach().size()) {
-
- }
-
- if (prop.x_custom().size()) {
-
- }
-
-}
-
-template <typename T>
-void getIncidenceProperties(T &prop, const KCalCore::Incidence &inc)
-{
- using namespace KCalCore;
- using namespace icalendar_2_0;
-
- prop.sequence(fromInt<xml_schema::integer>(inc.revision()));
-
- switch (inc.secrecy()) {
- case Incidence::SecrecyConfidential:
- prop.class_(typename T::class_type("CONFIDENTIAL"));
- break;
- case Incidence::SecrecyPrivate:
- prop.class_(typename T::class_type("PRIVATE"));
- break;
- default:
- prop.class_(typename T::class_type("PUBLIC"));
- break;
- }
-
- if (inc.dtStart().isValid()) {
- typename T::dtstart_type dtstart;
- setDateTimeProperty<KCalCoreTypes>(dtstart, inc.dtStart());
- prop.dtstart(dtstart);
- }
-
- if (inc.recurs()) {
- KCalCore::Recurrence *r = inc.recurrence();
- if (r->rRules().size() >= 1) {
- if (r->rRules().size() != 1) {
- kWarning() << "too many recurrences: " << r->rRules().size();
- }
- KCalCore::RecurrenceRule *rule = r->rRules().first();
- //TODO check if startdate is allDay if recurrence is allDay
- //TODO check if startdate matches the one of the event (it MUST)
- prop.rrule(recurrenceProperty(*rule));
- }
- }
-
-}
-
-template <> struct IncidenceConverter < KCalCore::Incidence, KCalCore::Incidence >
-{
- typedef DateTimeConverter< KDateTime> DC;
- static std::string uid(const KCalCore::Incidence &inc) { //FIXME thats possibly the kontact internal uid?
- return inc.uid().toStdString();
- }
-
- static xml_schema::date_time dtstamp(const KCalCore::Incidence &inc) {
- return DC::fromDateTime(inc.lastModified());
- }
-
- static xml_schema::date_time created(const KCalCore::Incidence &inc) {
- return DC::fromDateTime(inc.created());
- }
-
-};
-
-template < > struct IncidenceTrait <KCalCore::Event>
-{
- typedef icalendar_2_0::KolabEvent KolabType;
- typedef KCalCore::Event IncidenceType;
- typedef KCalCore::Event::Ptr IncidencePtr;
- typedef KCalCore::Incidence Incidence;
-
- static void writeIncidence(icalendar_2_0::KolabEvent& vevent, const KCalCore::Event &event)
- {
- icalendar_2_0::KolabEvent::properties_type &prop = vevent.properties();
-
- getIncidenceProperties<icalendar_2_0::KolabEvent::properties_type>(prop, event);
-
- if (event.hasEndDate() && event.dtEnd().isValid()) {
- icalendar_2_0::KolabEvent::properties_type::dtend_type dtend;
- setDateTimeProperty<KCalCoreTypes>(dtend, event.dtEnd());
- prop.dtend(dtend);
- } else if (event.hasDuration()) {
-
- }
- }
-
- static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, KolabType inc)
- {
- components.vevent().push_back(inc);
- }
-
- static void readIncidence(KCalCore::Event &event, const icalendar_2_0::KolabEvent& vevent)
- {
- const icalendar_2_0::KolabEvent::properties_type &prop = vevent.properties();
-
- setIncidenceProperties<icalendar_2_0::KolabEvent::properties_type>(event, prop);
-
- if (prop.dtend()) {
- event.setDtEnd(*toDate<KCalCoreTypes>(*prop.dtend()));
- if (event.dtEnd().timeType() != event.dtStart().timeType()) {
- kWarning() << "dtEnd has wrong timespec";
- }
- } else if (prop.duration()) {
- //TODO implement
- // KCalCore::Duration duration.;
- // event.setDuration(duration << prop.duration());
- }
- //TODO check for equality of timespecs
-
- if (prop.transp()) {
- //TODO implement
- }
- }
-
- static icalendar_2_0::components2::vevent_const_iterator begin(const icalendar_2_0::VcalendarType::components_type &components)
- {
- return components.vevent().begin();
- }
-
- static icalendar_2_0::components2::vevent_const_iterator end(const icalendar_2_0::VcalendarType::components_type &components)
- {
- return components.vevent().end();
- }
-
-};
-
-template < > struct IncidenceTrait <KCalCore::Todo>
-{
- typedef icalendar_2_0::KolabTodo KolabType;
- typedef KCalCore::Todo IncidenceType;
- typedef KCalCore::Incidence Incidence;
-
- static void writeIncidence(icalendar_2_0::KolabTodo& vtodo, const KCalCore::Todo &todo)
- {
- icalendar_2_0::KolabTodo::properties_type &prop = vtodo.properties();
- getIncidenceProperties<icalendar_2_0::KolabTodo::properties_type>(prop, todo);
- //TODO implement remaining todo properties
-
- }
-
- static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, KolabType inc)
- {
- components.vtodo().push_back(inc);
- }
-
- //TODO implement reading
-};
-
-} //Namespace
-
-#endif
\ No newline at end of file
diff --git a/c++/lib/kcalkolabformat.cpp b/c++/lib/kcalkolabformat.cpp
index 1922fa4..12eaba2 100644
--- a/c++/lib/kcalkolabformat.cpp
+++ b/c++/lib/kcalkolabformat.cpp
@@ -20,7 +20,7 @@
#include <kcalcore/event.h>
#include <KDE/KCalCore/Todo>
-#include "kcalconversions.h"
+// #include "kcalconversions.h"
namespace Kolab {
@@ -28,7 +28,8 @@ namespace KCal {
KCalCore::Event::Ptr readEvent(const std::string& s, bool isUrl)
{
- return deserializeIncidence< IncidenceTrait<KCalCore::Event> >(s, isUrl);
+// return deserializeIncidence< IncidenceTrait<KCalCore::Event> >(s, isUrl);
+ return KCalCore::Event::Ptr();
}
KCalCore::Todo::Ptr readTodo(const std::string& s, bool isUrl)
diff --git a/c++/lib/kolabevent.cpp b/c++/lib/kolabevent.cpp
index 821b819..43caaad 100644
--- a/c++/lib/kolabevent.cpp
+++ b/c++/lib/kolabevent.cpp
@@ -318,15 +318,15 @@ std::vector< CustomProperty > Event::customProperties() const
return d->customProperties;
}
-void Event::setExceptions(const std::vector< Event > &exceptions)
-{
- d->exceptions = exceptions;
-}
-
-std::vector< Event > Event::exceptions() const
-{
- return d->exceptions;
-}
+// void Event::setExceptions(const std::vector< Event > &exceptions)
+// {
+// d->exceptions = exceptions;
+// }
+//
+// std::vector< Event > Event::exceptions() const
+// {
+// return d->exceptions;
+// }
void Event::setAlarms(const std::vector< Alarm > &alarms)
{
diff --git a/c++/lib/kolabevent.h b/c++/lib/kolabevent.h
index 866bf27..668e254 100644
--- a/c++/lib/kolabevent.h
+++ b/c++/lib/kolabevent.h
@@ -106,9 +106,9 @@ public:
void setCustomProperties(const std::vector<CustomProperty> &);
std::vector<CustomProperty> customProperties() const;
-
+/* TODO what is this?
void setExceptions(const std::vector<Event> &);
- std::vector<Event> exceptions() const;
+ std::vector<Event> exceptions() const;*/
void setAlarms(const std::vector<Alarm> &);
std::vector<Alarm> alarms() const;
diff --git a/c++/lib/kolabformat.cpp b/c++/lib/kolabformat.cpp
index 16eb19e..f199be9 100644
--- a/c++/lib/kolabformat.cpp
+++ b/c++/lib/kolabformat.cpp
@@ -26,7 +26,7 @@ namespace Kolab {
Kolab::Event readEvent(const std::string& s, bool isUrl)
{
- Kolab::IncidenceTrait <Kolab::Event >::IncidencePtr ptr = deserializeIncidence< IncidenceTrait<Kolab::Event> >(s, isUrl);
+ Kolab::XCAL::IncidenceTrait <Kolab::Event >::IncidencePtr ptr = XCAL::deserializeIncidence< XCAL::IncidenceTrait<Kolab::Event> >(s, isUrl);
if (!ptr.get()) {
return Kolab::Event();
}
@@ -35,12 +35,12 @@ Kolab::Event readEvent(const std::string& s, bool isUrl)
std::string writeEvent(const Kolab::Event &event)
{
- return serializeIncidence< IncidenceTrait<Kolab::Event> >(event);
+ return XCAL::serializeIncidence< XCAL::IncidenceTrait<Kolab::Event> >(event);
}
Kolab::Todo readTodo(const std::string& s, bool isUrl)
{
- Kolab::IncidenceTrait<Kolab::Todo>::IncidencePtr ptr = deserializeIncidence< IncidenceTrait<Kolab::Todo> >(s, isUrl);
+ XCAL::IncidenceTrait<Kolab::Todo>::IncidencePtr ptr = XCAL::deserializeIncidence< XCAL::IncidenceTrait<Kolab::Todo> >(s, isUrl);
if (!ptr.get()) {
return Kolab::Todo();
}
@@ -49,7 +49,7 @@ Kolab::Todo readTodo(const std::string& s, bool isUrl)
std::string writeTodo(const Kolab::Todo &event)
{
- return serializeIncidence< IncidenceTrait<Kolab::Todo> >(event);
+ return XCAL::serializeIncidence< XCAL::IncidenceTrait<Kolab::Todo> >(event);
}
Journal readJournal(const std::string& s, bool isUrl)
@@ -71,7 +71,7 @@ std::string writeJournal(const Kolab::Journal &j)
Kolab::Contact readContact(const std::string& s, bool isUrl)
{
- boost::shared_ptr <Kolab::Contact > ptr = deserializeCard<Kolab::Contact>(s, isUrl);
+ boost::shared_ptr <Kolab::Contact > ptr = XCARD::deserializeCard<Kolab::Contact>(s, isUrl);
if (!ptr.get()) {
return Kolab::Contact();
}
@@ -80,12 +80,12 @@ Kolab::Contact readContact(const std::string& s, bool isUrl)
std::string writeContact(const Contact &contact)
{
- return serializeCard(contact);
+ return XCARD::serializeCard(contact);
}
DistList readDistlist(const std::string& s, bool isUrl)
{
- boost::shared_ptr <Kolab::DistList> ptr = deserializeCard<Kolab::DistList>(s, isUrl);
+ boost::shared_ptr <Kolab::DistList> ptr = XCARD::deserializeCard<Kolab::DistList>(s, isUrl);
if (!ptr.get()) {
return Kolab::DistList();
}
diff --git a/c++/lib/xcalconversions.h b/c++/lib/xcalconversions.h
index 752c162..b0bfd8d 100644
--- a/c++/lib/xcalconversions.h
+++ b/c++/lib/xcalconversions.h
@@ -18,9 +18,20 @@
#ifndef XCALCONVERSIONS_H
#define XCALCONVERSIONS_H
-#include "genericxcalconverions.h"
+#include "global_definitions.h"
+#include <bindings/kolabformat-xcal.hxx>
+#include <bindings/iCalendar-props.hxx>
+#include <compiled/XMLParserWrapper.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/numeric/conversion/converter_policies.hpp>
+#include <boost/numeric/conversion/cast.hpp>
#include <boost/foreach.hpp>
+
+#include <fstream>
+#include <iostream>
+
#include <boost/lexical_cast.hpp>
#include "kolabcontainers.h"
@@ -30,20 +41,100 @@
#include "base64.h"
namespace Kolab {
+ namespace XCAL {
-class Incidence;
-//TODO we can get rid of this construct (was used for the kcalcore/kolab in parallel masterplan)
-struct KolabTypes
-{
- typedef DateTime DateType;
- typedef boost::shared_ptr<DateTime> DatePtr;
- typedef RecurrenceRule RecurrenceType;
- typedef std::auto_ptr<RecurrenceRule> RecurrencePtr;
- typedef std::string StringType;
- typedef Incidence IncidenceType;
-};
+const char* const XCAL_VERSION = "2.0";
+const char* const XCAL_NAMESPACE = "urn:ietf:params:xml:ns:icalendar-2.0";
+
+const char* const TZ_PREFIX = "/kolab.org/";
+
+const char* const THISANDFUTURE = "THISANDFUTURE";
+
+const char* const BASE64 = "BASE64";
+
+const char* const NEEDSACTION = "NEEDS-ACTION";
+const char* const COMPLETED = "OPAQUE";
+const char* const INPROCESS = "IN-PROCESS";
+const char* const CANCELLED = "CANCELLED";
+const char* const TENTATIVE = "TENTATIVE";
+const char* const CONFIRMED = "CONFIRMED";
+const char* const DRAFT = "DRAFT";
+const char* const FINAL = "FINAL";
+
+const char* const CONFIDENTIAL = "CONFIDENTIAL";
+const char* const PRIVATE = "PRIVATE";
+const char* const PUBLIC = "PUBLIC";
+
+const char* const PARTACCEPTED = "ACCEPTED";
+const char* const PARTDECLINED = "DECLINED";
+const char* const PARTDELEGATED = "DELEGATED";
+const char* const PARTNEEDSACTION = "NEEDS-ACTION";
+const char* const PARTTENTATIVE = "TENTATIVE";
+
+const char* const CHAIR = "CHAIR";
+const char* const NONPARTICIPANT = "NON-PARTICIPANT";
+const char* const OPTIONAL = "OPT-PARTICIPANT";
+const char* const REQUIRED = "REQ-PARTICIPANT";
+
+const char* const DISPLAYALARM = "DISPLAY";
+const char* const EMAILALARM = "EMAIL";
+const char* const AUDIOALARM = "AUDIO";
+
+const char* const TRANSPARENT = "TRANSPARENT";
+const char* const OPAQUE = "OPAQUE";
+
+const char* const MO = "MO";
+const char* const TU = "TU";
+const char* const WE = "WE";
+const char* const TH = "TH";
+const char* const FR = "FR";
+const char* const SA = "SA";
+const char* const SU = "SU";
+
+//Alarms
+const char* const START = "START";
+const char* const END = "END";
+
+//=== Generic Conversions ===
+template <typename T>
+int convertToInt(T integer)
+{
+ try {
+ int i = boost::numeric_cast<int>(integer);
+ return i;
+ } catch(boost::numeric::negative_overflow& e) {
+ std::cerr << e.what();
+ } catch(boost::numeric::positive_overflow& e) {
+ std::cerr << e.what();
+ } catch(boost::numeric::bad_numeric_cast& e) {
+ std::cerr << e.what();
+ }
+ return 0;
+}
+
+template <typename T>
+T fromInt(int integer)
+{
+ try {
+ T i = boost::numeric_cast<T>(integer);
+ return i;
+ } catch(boost::numeric::negative_overflow& e) {
+ std::cerr << e.what();
+ } catch(boost::numeric::positive_overflow& e) {
+ std::cerr << e.what();
+ } catch(boost::numeric::bad_numeric_cast& e) {
+ std::cerr << e.what();
+ }
+ return 0;
+}
+
+int toInt(const icalendar_2_0::IntegerPropertyType &prop)
+{
+ return convertToInt<icalendar_2_0::IntegerPropertyType::integer_type>(prop.integer());
+}
+
std::vector<std::string> toStringList(const icalendar_2_0::TextListPropertyType &s)
{
std::vector<std::string> d;
@@ -66,13 +157,7 @@ std::string toString(const icalendar_2_0::TextPropertyType &s)
}
-const char* const MO = "MO";
-const char* const TU = "TU";
-const char* const WE = "WE";
-const char* const TH = "TH";
-const char* const FR = "FR";
-const char* const SA = "SA";
-const char* const SU = "SU";
+
std::string fromDayPos(const Kolab::DayPos &d)
{
@@ -287,29 +372,94 @@ Kolab::Duration toDuration(const icalendar_2_0::DurationValueType &d)
}
return Duration(days, hours, minutes, seconds, negative);
}
-// template <typename T>
-// std::auto_ptr<T> fromString(const std::string &s)
-// {
-// std::auto_ptr<T> ptr(new T());
-// p.text(s);
-// return ptr;
-// }
-
-template <> struct DateTimeConverter<DateTime>
+
+
+
+void setCalAddress(const icalendar_2_0::CalAddressPropertyType &cal, std::string &email, std::string &name)
{
- typedef DateTime Type;
- typedef boost::shared_ptr<DateTime> Ptr;
+ if (cal.parameters()) {
+ for (icalendar_2_0::ArrayOfParameters::baseParameter_const_iterator it((*cal.parameters()).baseParameter().begin()); it != (*cal.parameters()).baseParameter().end(); it++) {
+ if (const icalendar_2_0::CnParamType * tz = dynamic_cast<const icalendar_2_0::CnParamType*> (&*it)) {
+ name = tz->text();
+ }
+ }
+ }
+ email = cal.cal_address();
+}
- static Ptr toDate(const xml_schema::date &dt)
+
+template <typename T>
+Kolab::Attachment toAttachment(T aProp)
+{
+ Kolab::Attachment a;
+ std::string mimetype;
+ if (aProp.parameters()) {
+ const icalendar_2_0::AttachPropType ::parameters_type ¶meters = *aProp.parameters();
+ for (icalendar_2_0::AttachPropType::parameters_type::baseParameter_const_iterator it(parameters.baseParameter().begin()); it != parameters.baseParameter().end(); it++) {
+ if (const icalendar_2_0::FmttypeParamType *p = dynamic_cast<const icalendar_2_0::FmttypeParamType*> (&*it)) {
+ mimetype = p->text();
+ }
+ if (const icalendar_2_0::EncodingParamType *p = dynamic_cast<const icalendar_2_0::EncodingParamType*> (&*it)) {
+ if (p->text() != BASE64) {
+ std::cerr << "wrong encoding";
+ return Kolab::Attachment();
+ }
+ }
+ if (const icalendar_2_0::XlabelParamType *p = dynamic_cast<const icalendar_2_0::XlabelParamType*> (&*it)) {
+ a.setLabel(p->text());
+ }
+ }
+ }
+ if (mimetype.empty()) {
+ std::cerr << "no mimetype" << std::endl;
+ }
+
+ if (aProp.uri()) {
+ a.setUri(*aProp.uri(), mimetype);
+ } else if (aProp.binary()) {
+ a.setData(base64_decode(*aProp.binary()), mimetype);
+ } else {
+ std::cerr << "not uri and no data available" << std::endl;
+ }
+ return a;
+}
+
+icalendar_2_0::AttachPropType fromAttachment(const Kolab::Attachment &a)
+{
+ icalendar_2_0::AttachPropType attachment;
+ icalendar_2_0::AttachPropType::parameters_type p;
+ p.baseParameter().push_back(icalendar_2_0::FmttypeParamType(a.mimetype()));
+ if (!a.label().empty()) {
+ p.baseParameter().push_back(icalendar_2_0::XlabelParamType(a.label()));
+ }
+
+ if (!a.uri().empty()) {
+ attachment.uri(a.uri());
+ } else if (!a.data().empty()) {
+ attachment.binary(base64_encode(reinterpret_cast<const unsigned char*>(a.data().c_str()), a.data().length()));
+ p.baseParameter().push_back(icalendar_2_0::EncodingParamType(BASE64));
+ } else {
+ std::cerr << "no uri and no data" << std::endl;
+ }
+
+ attachment.parameters(p);
+ return attachment;
+}
+
+//==== DateTime ====
+
+typedef boost::shared_ptr<DateTime> DateTimePtr;
+
+ static DateTimePtr toDate(const xml_schema::date &dt)
{
- Ptr date(new DateTime());
+ DateTimePtr date(new DateTime());
date->setDate(dt.year(), dt.month(), dt.day());
return date;
}
- static Ptr toDate(const xml_schema::date_time &dt)
+ static DateTimePtr toDate(const xml_schema::date_time &dt)
{
- Ptr date(new DateTime());
+ DateTimePtr date(new DateTime());
date->setDate(dt.year(), dt.month(), dt.day());
date->setTime(dt.hours(), dt.minutes(), dt.seconds());
if (dt.zone_present()) {
@@ -335,71 +485,250 @@ template <> struct DateTimeConverter<DateTime>
return date;
}
- static void setTimezone(Ptr date, const std::string &tzid)
- {
- date->setTimezone(tzid);
+ std::string getTimezone(const icalendar_2_0::ArrayOfParameters ¶meters) {
+ for (icalendar_2_0::DateDatetimePropertyType::parameters_type::baseParameter_const_iterator it(parameters.baseParameter().begin()); it != parameters.baseParameter().end(); it++) {
+ if (const icalendar_2_0::TzidParamType* tz = dynamic_cast<const icalendar_2_0::TzidParamType*> (&*it)) {
+ std::string tzid = tz->text();
+ if (tzid.find(TZ_PREFIX) != std::string::npos) {
+ tzid.erase(0, strlen(TZ_PREFIX));
+ } else {
+ std::cerr << "/kolab.org/ timezone prefix is missing";
+ }
+ return tzid;
+ }
}
+ return std::string();
+}
- static std::string getTimezone(const DateTime &dt)
- {
- return dt.timezone();
+DateTimePtr toDate(const icalendar_2_0::DateDatetimePropertyType &dtProperty)
+{
+ DateTimePtr date;
+ if (dtProperty.date_time()) {
+ date = toDate(*dtProperty.date_time());
+ } else if (dtProperty.date()) {
+ date = toDate(*dtProperty.date());
}
- static void setUTC(Ptr date)
- {
- date->setUTC(true);
+ if (dtProperty.parameters()) {
+ const std::string &tzid = getTimezone(*dtProperty.parameters());
+ if (tzid.size()) {
+ date->setTimezone(tzid);
+ }
}
+ return date;
+}
- static bool isDateOnly(Type date)
- {
- return date.isDateOnly();
+
+DateTimePtr toDate(const icalendar_2_0::UtcDatetimePropertyType &dtProperty)
+{
+ DateTimePtr date;
+ if (dtProperty.date_time()) {
+ date = toDate(*dtProperty.date_time());
+ } else { //The utc-date-time element shouldn't even exist
+ date = DateTimePtr(new DateTime());
+ std::cerr << "This element shouldn't even be existing";
+ //TODO Implement anyways?
+ return date;
}
+ date->setUTC(true);
+ return date;
+}
-};
+template <typename I>
+std::auto_ptr<I> fromDate(const DateTime &dt)
+{
+ std::auto_ptr<I> ptr(new I);
+ if (dt.isDateOnly()) {
+ ptr->date(fromDate(dt));
+ } else {
+ ptr->date_time(fromDateTime(dt));
+ const std::string &timezone = dt.timezone();
+ if (timezone.size() != 0) {
+ std::string tz(TZ_PREFIX);
+ tz.append(timezone);
+ icalendar_2_0::TzidParamType tzidParam(tz);
+ icalendar_2_0::ArrayOfParameters parameters;
+ parameters.baseParameter().push_back(tzidParam);
+ ptr->parameters(parameters);
+ }
+ }
+ return ptr;
+}
+
+
+template <typename I>
+std::vector<DateTime> toDateTimeList(I datelistProperty)
+{
+ std::vector<DateTime> list;
+
+ std::string tzid;
+ if (datelistProperty.parameters()) {
+ tzid = getTimezone(*datelistProperty.parameters());
+ }
+ if (!datelistProperty.date().empty()) {
+ BOOST_FOREACH(const xml_schema::date &d, datelistProperty.date()) {
+ list.push_back(*toDate(d));
+ }
+ } else if (!datelistProperty.date_time().empty()) {
+ BOOST_FOREACH(const xml_schema::date_time &d, datelistProperty.date_time()) {
+ DateTimePtr date = toDate(d);
+ if (tzid.size()) {
+ date->setTimezone(tzid);
+ }
+ list.push_back(*date);
+ }
+ }
+ return list;
+}
+
+template <typename I>
+std::auto_ptr<I> fromDateTimeList(const std::vector<DateTime> &dtlist)
+{
+
+ std::auto_ptr<I> ptr(new I);
+ BOOST_FOREACH(const DateTime &dt, dtlist) {
+ if (dt.isDateOnly()) {
+ ptr->date().push_back(fromDate(dt));
+ } else {
+ ptr->date_time().push_back(fromDateTime(dt));
+ }
+ //TODO handle utc
+ //TODO check for equality of timezones?
+ }
+
+ if (!dtlist.empty() && !dtlist.at(0).timezone().empty()) {
+ const std::string &timezone = dtlist.at(0).timezone();
+ if (timezone.size() != 0) {
+ std::string tz(TZ_PREFIX);
+ tz.append(timezone);
+ icalendar_2_0::TzidParamType tzidParam(tz);
+ icalendar_2_0::ArrayOfParameters parameters;
+ parameters.baseParameter().push_back(tzidParam);
+ ptr->parameters(parameters);
+ }
+ }
+
+ return ptr;
+}
+
+
+
+//---- DateTime ----
+
+
+
+//----------------
-template <> struct RecurrenceConverter < RecurrenceRule >
+//=== Attendee ===
+
+std::string mapPartStat(PartStatus status)
+{
+ switch (status) {
+ case PartAccepted:
+ return PARTACCEPTED;
+ case PartDeclined:
+ return PARTDECLINED;
+ case PartDelegated:
+ return PARTDELEGATED;
+ case PartNeedsAction:
+ return PARTNEEDSACTION;
+ case PartTentative:
+ return PARTTENTATIVE;
+ }
+ std::cout << "PartStat not handled: " << status;
+ return std::string();
+}
+
+PartStatus mapPartStat(const std::string &status)
{
+ if (status == PARTACCEPTED) {
+ return PartAccepted;
+ } else if (status == PARTDECLINED) {
+ return PartDeclined;
+ } else if (status == PARTDELEGATED) {
+ return PartDelegated;
+ } else if (status == PARTNEEDSACTION) {
+ return PartNeedsAction;
+ } else if (status == PARTTENTATIVE) {
+ return PartTentative;
+ }
+ std::cout << "Unhandled partstatus" << status;
+ return PartNeedsAction;
+}
+
+std::string mapRole(Role status)
+{
+ switch (status) {
+ case Chair:
+ return std::string(CHAIR);
+ case NonParticipant:
+ return NONPARTICIPANT;
+ case Optional:
+ return OPTIONAL;
+ case Required:
+ return REQUIRED;
+ }
+ std::cout << "PartStat not handled: " << status;
+ return std::string();
+}
+
+Role mapRole(const std::string &status)
+{
+ if (status == CHAIR) {
+ return Chair;
+ } else if (status == NONPARTICIPANT) {
+ return NonParticipant;
+ } else if (status == OPTIONAL) {
+ return Optional;
+ } else if (status == REQUIRED) {
+ return Required;
+ }
+ std::cout << "Unhandled Role" << status;
+ return Required;
+}
- typedef KolabTypes::RecurrenceType Type;
- typedef KolabTypes::RecurrencePtr& Ptr; //Pass by reference, otherwise auto_ptr deletes the pointer after the first pass to a function (unlike shared_ptr)
- static void setType(Ptr r, const icalendar_2_0::RecurType::freq_type &freq)
+
+
+
+//----------------
+
+//=== Recurrence Rule ===
+
+ typedef std::auto_ptr<RecurrenceRule> RecurrencePtr;
+
+
+ RecurrenceRule::Frequency mapRecurrenceFrequency(const icalendar_2_0::RecurType::freq_type &freq)
{
using namespace icalendar_2_0;
switch (freq) {
case FreqRecurType::YEARLY:
- r->setFrequency(RecurrenceRule::Yearly);
- break;
+ return RecurrenceRule::Yearly;
case FreqRecurType::MONTHLY:
- r->setFrequency(RecurrenceRule::Monthly);
- break;
+ return RecurrenceRule::Monthly;
case FreqRecurType::WEEKLY:
- r->setFrequency(RecurrenceRule::Weekly);
- break;
+ return RecurrenceRule::Weekly;
case FreqRecurType::DAILY:
- r->setFrequency(RecurrenceRule::Daily);
- break;
+ return RecurrenceRule::Daily;
case FreqRecurType::HOURLY:
- r->setFrequency(RecurrenceRule::Hourly);
- break;
+ return RecurrenceRule::Hourly;
case FreqRecurType::MINUTELY:
- r->setFrequency(RecurrenceRule::Minutely);
- break;
+ return RecurrenceRule::Minutely;
case FreqRecurType::SECONDLY:
- r->setFrequency(RecurrenceRule::Secondly);
- break;
+ return RecurrenceRule::Secondly;
default:
std::cout << "invalid unhandled recurrenc type" << freq;
}
+ return RecurrenceRule::None;
}
- static icalendar_2_0::RecurType::freq_type type(const Type &t)
+ icalendar_2_0::RecurType::freq_type mapRecurrenceFrequency(RecurrenceRule::Frequency freq)
{
using namespace icalendar_2_0;
- switch (t.frequency()) {
+ switch (freq) {
case RecurrenceRule::Yearly:
return FreqRecurType::YEARLY;
case RecurrenceRule::Monthly:
@@ -420,7 +749,7 @@ template <> struct RecurrenceConverter < RecurrenceRule >
return 0;
}
- static void setWeekStart(Ptr r, const icalendar_2_0::RecurType::wkst_type &wkst)
+ static void setWeekStart(RecurrencePtr &r, const icalendar_2_0::RecurType::wkst_type &wkst)
{
using namespace icalendar_2_0;
@@ -451,49 +780,8 @@ template <> struct RecurrenceConverter < RecurrenceRule >
}
}
- static void setEndDt(Ptr r, KolabTypes::DatePtr date )
- {
- r->setEnd(*date);
- }
-
- static void setCount(Ptr r, int count )
- {
- r->setCount(count);
- }
- static void setInterval(Ptr r, int interval )
- {
- r->setInterval(interval);
- }
-
- static void setBysecond(Ptr r, const icalendar_2_0::RecurType::bysecond_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::bysecond_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- r->setBysecond(by);
- }
-
- static void setByminute(Ptr r, const icalendar_2_0::RecurType::byminute_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::byminute_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- r->setByminute(by);
- }
-
- static void setByhour(Ptr r, const icalendar_2_0::RecurType::byhour_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::byhour_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::non_negative_integer>(*it));
- }
- r->setByhour(by);
- }
-
- static void setByday(Ptr r, const icalendar_2_0::RecurType::byday_sequence &list)
+ static void setByday(RecurrencePtr &r, const icalendar_2_0::RecurType::byday_sequence &list)
{
std::vector<DayPos> by;
for (icalendar_2_0::RecurType::byday_const_iterator it(list.begin()); it != list.end(); it++) {
@@ -501,109 +789,63 @@ template <> struct RecurrenceConverter < RecurrenceRule >
}
r->setByday(by);
}
-
- static void setBymonthday(Ptr r, const icalendar_2_0::RecurType::bymonthday_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::bymonth_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::integer>(*it));
- }
- r->setBymonthday(by);
- }
-
- static void setByyearday(Ptr r, const icalendar_2_0::RecurType::byyearday_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::byyearday_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::integer>(*it));
- }
- r->setByyearday(by);
- }
-
- static void setByweekno(Ptr r, const icalendar_2_0::RecurType::byweekno_sequence &list)
- {
+
+ template <typename T, typename I>
+ std::vector<int> bylist(const xsd::cxx::tree::sequence <T> &list)
+ {
std::vector<int> by;
- for (icalendar_2_0::RecurType::byweekno_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::integer>(*it));
+ BOOST_FOREACH(const T i, list) {
+ by.push_back(convertToInt<I>(i));
}
- r->setByweekno(by);
+ return by;
}
- static void setBymonth(Ptr r, const icalendar_2_0::RecurType::bymonth_sequence &list)
- {
- std::vector<int> by;
- for (icalendar_2_0::RecurType::bymonth_const_iterator it(list.begin()); it != list.end(); it++) {
- by.push_back(convertToInt<xml_schema::integer>(*it));
- }
- r->setBymonth(by);
- }
-};
-
-
-void setCalAddress(const icalendar_2_0::CalAddressPropertyType &cal, std::string &email, std::string &name)
+RecurrencePtr toRRule(const icalendar_2_0::RecurType &rrule)
{
- if (cal.parameters()) {
- for (icalendar_2_0::ArrayOfParameters::baseParameter_const_iterator it((*cal.parameters()).baseParameter().begin()); it != (*cal.parameters()).baseParameter().end(); it++) {
- if (const icalendar_2_0::CnParamType * tz = dynamic_cast<const icalendar_2_0::CnParamType*> (&*it)) {
- name = tz->text();
- }
- }
- }
- email = cal.cal_address();
-}
-
-// template <typename T> setProperty(T::parameters_type::baseParameter_const_iterator it, void (*set)(std::string))
-// {
-// if (const T * p = dynamic_cast<const T*> (&*it)) {
-// set(p->text());
-// }
-// }
+ using namespace icalendar_2_0;
-template <typename T>
-Kolab::Attachment toAttachment(T aProp)
-{
- Kolab::Attachment a;
- std::string mimetype;
- if (aProp.parameters()) {
- const icalendar_2_0::AttachPropType ::parameters_type ¶meters = *aProp.parameters();
- for (icalendar_2_0::AttachPropType::parameters_type::baseParameter_const_iterator it(parameters.baseParameter().begin()); it != parameters.baseParameter().end(); it++) {
- if (const icalendar_2_0::FmttypeParamType *p = dynamic_cast<const icalendar_2_0::FmttypeParamType*> (&*it)) {
- mimetype = p->text();
- }
- if (const icalendar_2_0::EncodingParamType *p = dynamic_cast<const icalendar_2_0::EncodingParamType*> (&*it)) {
- if (p->text() != BASE64) {
- std::cerr << "wrong encoding";
- return Kolab::Attachment();
- }
- }
- if (const icalendar_2_0::XlabelParamType *p = dynamic_cast<const icalendar_2_0::XlabelParamType*> (&*it)) {
- a.setLabel(p->text());
- }
+ RecurrencePtr r(new RecurrenceRule());
+ r->setFrequency(mapRecurrenceFrequency(rrule.freq()));
+ if (rrule.until()) {
+ DateTimePtr date;
+ if ((*rrule.until()).date_time()) {
+ date = toDate(*(*rrule.until()).date_time());
+ } else if ((*rrule.until()).date()) {
+ date = toDate(*(*rrule.until()).date());
}
+ r->setEnd(*date);
+ } else if (rrule.count()) {
+ r->setCount(toInt(*rrule.count()));
}
- if (mimetype.empty()) {
- std::cerr << "no mimetype" << std::endl;
- }
-
- if (aProp.uri()) {
- a.setUri(*aProp.uri(), mimetype);
- } else if (aProp.binary()) {
- a.setData(base64_decode(*aProp.binary()), mimetype);
+ if (rrule.interval()) {
+ r->setInterval(toInt(*rrule.interval()));
} else {
- std::cerr << "not uri and no data available" << std::endl;
- }
- return a;
+ r->setInterval(1);
+ }
+ r->setBysecond(bylist<RecurType::bysecond_type, xml_schema::non_negative_integer>(rrule.bysecond()));
+ r->setByminute(bylist<RecurType::byminute_type, xml_schema::non_negative_integer>(rrule.byminute()));
+ r->setByhour(bylist<RecurType::byhour_type, xml_schema::non_negative_integer>(rrule.byhour()));
+ setByday(r, rrule.byday());
+ r->setBymonthday(bylist<RecurType::bymonthday_type, xml_schema::integer>(rrule.bymonthday()));
+ r->setByyearday(bylist<RecurType::byyearday_type, xml_schema::integer>(rrule.byyearday()));
+ r->setByweekno(bylist<RecurType::byweekno_type, xml_schema::integer>(rrule.byweekno()));
+ r->setBymonth(bylist<RecurType::bymonth_type, xml_schema::integer>(rrule.bymonth()));
+ if (rrule.wkst()) {
+ setWeekStart(r, *rrule.wkst());
+ }
+ return r;
}
+
+//--- Recurrence Rule ---
+
template <typename I, typename T>
void setIncidenceProperties(I &inc, const T &prop)
-{
- typedef DateTimeConverter<Kolab::DateTime> DC;
-
+{
inc.setUid(toString(prop.uid()));
- inc.setCreated(*toDate<KolabTypes>(prop.created()));
- inc.setLastModified(*toDate<KolabTypes>(prop.dtstamp()));
+ inc.setCreated(*toDate(prop.created()));
+ inc.setLastModified(*toDate(prop.dtstamp()));
if (prop.sequence()) {
inc.setSequence(toInt(*prop.sequence()));
@@ -625,24 +867,24 @@ void setIncidenceProperties(I &inc, const T &prop)
}
if (prop.dtstart()) {
- const KolabTypes::DatePtr date = toDate<KolabTypes>(*prop.dtstart());
- inc.setStart(*date); //TODO add to specification that allday depends on start date format
+ const DateTimePtr date = toDate(*prop.dtstart());
+ inc.setStart(*date);
}
if (prop.rrule()) {
- KolabTypes::RecurrencePtr rrule = toRRule<KolabTypes>(prop.rrule()->recur());
+ RecurrencePtr rrule = toRRule(prop.rrule()->recur());
inc.setRecurrenceRule(*rrule);
}
if (prop.rdate()) {
- inc.setRecurrenceDates(toDateTimeList<KolabTypes, icalendar_2_0::KolabEvent::properties_type::rdate_type>(*prop.rdate()));
+ inc.setRecurrenceDates(toDateTimeList<icalendar_2_0::KolabEvent::properties_type::rdate_type>(*prop.rdate()));
if (!prop.rdate()->period().empty()) {
std::cout << "the period element must not be used, ignored." << std::endl;
}
}
if (prop.exdate()) {
- inc.setExceptionDates(toDateTimeList<KolabTypes, icalendar_2_0::KolabEvent::properties_type::exdate_type>(*prop.exdate()));
+ inc.setExceptionDates(toDateTimeList<icalendar_2_0::KolabEvent::properties_type::exdate_type>(*prop.exdate()));
}
if (prop.recurrence_id()) {
@@ -655,7 +897,7 @@ void setIncidenceProperties(I &inc, const T &prop)
}
}
}
- inc.setRecurrenceID(*toDate<KolabTypes>(*prop.recurrence_id()), thisandfuture);
+ inc.setRecurrenceID(*toDate(*prop.recurrence_id()), thisandfuture);
}
if (prop.summary()) {
@@ -774,20 +1016,17 @@ T fromList(const std::vector<int> &input) {
std::auto_ptr< icalendar_2_0::RrulePropType > recurrenceProperty(const RecurrenceRule &r)
{
using namespace icalendar_2_0;
-
- typedef RecurrenceConverter< RecurrenceRule > RC;
- typedef DateTimeConverter< DateTime> DC;
-
- std::auto_ptr< RrulePropType > rruleProp(new RrulePropType(RC::type(r)));
+
+ std::auto_ptr< RrulePropType > rruleProp(new RrulePropType(mapRecurrenceFrequency(r.frequency())));
RecurPropertyType::recur_type &recur = rruleProp->recur();
const DateTime &endDate = r.end();
if (endDate.isValid()) {
RecurPropertyType::recur_type::until_type until;
if (endDate.isDateOnly()) {
- until.date(DC::fromDate(endDate));
+ until.date(fromDate(endDate));
} else {
- until.date_time(DC::fromDateTime(endDate));
+ until.date_time(fromDateTime(endDate));
}
recur.until(until);
} else if (r.count() > 0) {
@@ -837,27 +1076,7 @@ std::auto_ptr< icalendar_2_0::RrulePropType > recurrenceProperty(const Recurrenc
return rruleProp;
}
-icalendar_2_0::AttachPropType fromAttachment(const Kolab::Attachment &a)
-{
- icalendar_2_0::AttachPropType attachment;
- icalendar_2_0::AttachPropType::parameters_type p;
- p.baseParameter().push_back(icalendar_2_0::FmttypeParamType(a.mimetype()));
- if (!a.label().empty()) {
- p.baseParameter().push_back(icalendar_2_0::XlabelParamType(a.label()));
- }
-
- if (!a.uri().empty()) {
- attachment.uri(a.uri());
- } else if (!a.data().empty()) {
- attachment.binary(base64_encode(reinterpret_cast<const unsigned char*>(a.data().c_str()), a.data().length()));
- p.baseParameter().push_back(icalendar_2_0::EncodingParamType(BASE64));
- } else {
- std::cerr << "no uri and no data" << std::endl;
- }
-
- attachment.parameters(p);
- return attachment;
-}
+
template <typename T, typename I>
@@ -866,7 +1085,6 @@ void getIncidenceProperties(T &prop, const I &inc)
using namespace icalendar_2_0;
typedef T properties;
- typedef DateTimeConverter< DateTime> DC;
prop.sequence(fromInt<xml_schema::integer>(inc.sequence()));
@@ -887,7 +1105,7 @@ void getIncidenceProperties(T &prop, const I &inc)
}
if (inc.start().isValid()) {
- prop.dtstart(fromDate<KolabTypes, typename properties::dtstart_type>(inc.start()));
+ prop.dtstart(fromDate<typename properties::dtstart_type>(inc.start()));
}
if (inc.recurrenceRule().isValid()) {
@@ -898,15 +1116,15 @@ void getIncidenceProperties(T &prop, const I &inc)
}
if (!inc.recurrenceDates().empty()) {
- prop.rdate(fromDateTimeList<KolabTypes, typename properties::rdate_type>(inc.recurrenceDates()));
+ prop.rdate(fromDateTimeList<typename properties::rdate_type>(inc.recurrenceDates()));
}
if (!inc.exceptionDates().empty()) {
- prop.exdate(fromDateTimeList<KolabTypes, typename properties::exdate_type>(inc.exceptionDates()));
+ prop.exdate(fromDateTimeList<typename properties::exdate_type>(inc.exceptionDates()));
}
if (inc.recurrenceID().isValid()) {
- std::auto_ptr<typename properties::recurrence_id_type> recurrenceId = fromDate<KolabTypes, typename properties::recurrence_id_type>(inc.recurrenceID());
+ std::auto_ptr<typename properties::recurrence_id_type> recurrenceId = fromDate<typename properties::recurrence_id_type>(inc.recurrenceID());
if (inc.thisAndFuture()) {
if (!recurrenceId->parameters()) {
recurrenceId->parameters(typename properties::recurrence_id_type::parameters_type());
@@ -1027,20 +1245,18 @@ void getIncidenceProperties(T &prop, const I &inc)
}
-const char* const START = "START";
-const char* const END = "END";
+//=== Alarms ===
template <typename KolabType, typename IncidenceType>
void setAlarms(typename KolabType::components_type& components, const IncidenceType &incidence)
{
- typedef DateTimeConverter< DateTime> DC;
BOOST_FOREACH(const Kolab::Alarm &alarm, incidence.alarms()) {
typedef icalendar_2_0::ValarmType::properties_type PropType;
PropType::trigger_type trigger;
if (alarm.start().isValid()) {
- trigger.date_time(DC::fromDateTime(alarm.start()));
+ trigger.date_time(fromDateTime(alarm.start()));
} else {
if (!alarm.relativeStart().isValid()) {
std::cerr << "no start and no relativeStart" << std::endl;
@@ -1088,15 +1304,6 @@ void setAlarms(typename KolabType::components_type& components, const IncidenceT
}
}
-// typename KolabTypes::DatePtr toDate(const icalendar_2_0::DateTimeType &dtProperty)
-// {
-// typedef DateTimeConverter<Kolab::DateTime> DC;
-// typename KolabTypes::DatePtr date;
-// if (dtProperty.date_time()) {
-// date = DC::toDate(dtProperty.date_time());
-// }
-// return date;
-// }
template <typename IncidenceType, typename KolabType>
@@ -1141,7 +1348,7 @@ void getAlarms(IncidenceType &incidence, const typename KolabType::components_ty
}
if (prop.trigger().date_time()) {
- alarm.setStart(*DateTimeConverter<Kolab::DateTime>::toDate(*prop.trigger().date_time()));
+ alarm.setStart(*toDate(*prop.trigger().date_time()));
if (!alarm.start().isUTC()) {
std::cerr << "The start date time must be in UTC "<< std::endl;
continue;
@@ -1179,9 +1386,16 @@ void getAlarms(IncidenceType &incidence, const typename KolabType::components_ty
incidence.setAlarms(alarms);
}
+//--- Alarms ---
+
+class Incidence; //Just for Trait
+
+///Trait for Incidence object
+template <typename T, typename I>
+struct IncidenceConverter;
+
template <typename T> struct IncidenceConverter < Incidence, T >
{
- typedef DateTimeConverter< DateTime> DC;
static std::string uid(const T &inc) {
if (inc.uid().empty()) { //generate new UID
return getUID();
@@ -1190,58 +1404,58 @@ template <typename T> struct IncidenceConverter < Incidence, T >
}
static xml_schema::date_time dtstamp() {
- return DC::fromDateTime(getCurrentTime());
+ return fromDateTime(getCurrentTime());
}
static xml_schema::date_time created(const T &inc) {
if (inc.created().isValid()) {
- return DC::fromDateTime(inc.created());
+ return fromDateTime(inc.created());
}
- return DC::fromDateTime(getCurrentTime());
+ return fromDateTime(getCurrentTime());
}
};
-const char* const TRANSPARENT = "TRANSPARENT";
-const char* const OPAQUE = "OPAQUE";
+
+///Trait for incidence properties specialized for Event/Todo/Journal
+template <typename T> struct IncidenceTrait;
template < > struct IncidenceTrait <Kolab::Event>
{
typedef icalendar_2_0::KolabEvent KolabType;
typedef Kolab::Event IncidenceType;
typedef boost::shared_ptr<Kolab::Event> IncidencePtr;
- typedef Kolab::Incidence Incidence;
-
+
static void writeIncidence(icalendar_2_0::KolabEvent& vevent, const Kolab::Event &event)
{
- KolabType::properties_type &prop = vevent.properties();
-
- getIncidenceProperties<KolabType::properties_type>(prop, event);
+ icalendar_2_0::KolabEvent::properties_type &prop = vevent.properties();
+
+ getIncidenceProperties<icalendar_2_0::KolabEvent::properties_type>(prop, event);
if (event.end().isValid()) {
- prop.dtend(fromDate<KolabTypes, KolabType::properties_type::dtend_type>(event.end()));
+ prop.dtend(fromDate<icalendar_2_0::KolabEvent::properties_type::dtend_type>(event.end()));
} else if (event.duration().isValid()) {
- prop.duration(KolabType::properties_type::duration_type(fromDuration(event.duration())));
+ prop.duration(icalendar_2_0::KolabEvent::properties_type::duration_type(fromDuration(event.duration())));
}
if (event.transparency()) {
- prop.transp( KolabType::properties_type::transp_type(TRANSPARENT));
+ prop.transp( icalendar_2_0::KolabEvent::properties_type::transp_type(TRANSPARENT));
}
}
- static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, KolabType inc) //TODO to base trait
+ static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, icalendar_2_0::KolabEvent inc) //TODO to base trait
{
components.vevent().push_back(inc);
}
static void readIncidence(Kolab::Event &event, const icalendar_2_0::KolabEvent& vevent)
{
- const KolabType::properties_type &prop = vevent.properties();
+ const icalendar_2_0::KolabEvent::properties_type &prop = vevent.properties();
- setIncidenceProperties<Kolab::Event, KolabType::properties_type>(event, prop);
+ setIncidenceProperties<Kolab::Event, icalendar_2_0::KolabEvent::properties_type>(event, prop);
if (prop.dtend()) {
- event.setEnd(*toDate<KolabTypes>(*prop.dtend()));
+ event.setEnd(*toDate(*prop.dtend()));
if (event.end().isUTC() != event.end().isUTC() &&
event.end().timezone() != event.end().timezone() &&
event.end().isDateOnly() != event.end().isDateOnly()) {
@@ -1262,13 +1476,13 @@ template < > struct IncidenceTrait <Kolab::Event>
}
}
if (vevent.components()) {
- getAlarms<IncidenceType, KolabType>(event, *vevent.components());
+ getAlarms<Kolab::Event, icalendar_2_0::KolabEvent>(event, *vevent.components());
}
}
- static void setComponents(KolabType::components_type& components, const Kolab::Event &incidence)
+ static void setComponents(icalendar_2_0::KolabEvent::components_type& components, const Kolab::Event &incidence)
{
- setAlarms<KolabType, IncidenceType>(components, incidence);
+ setAlarms<icalendar_2_0::KolabEvent, Kolab::Event>(components, incidence);
}
static icalendar_2_0::VcalendarType::components_type::vevent_const_iterator begin(const icalendar_2_0::VcalendarType::components_type &components)
@@ -1288,59 +1502,58 @@ template < > struct IncidenceTrait <Kolab::Todo>
typedef icalendar_2_0::KolabTodo KolabType;
typedef Kolab::Todo IncidenceType;
typedef boost::shared_ptr<Kolab::Todo> IncidencePtr;
- typedef Kolab::Incidence Incidence;
-
- static void writeIncidence(KolabType& vevent, const Kolab::Todo &todo)
+
+ static void writeIncidence(icalendar_2_0::KolabTodo& vevent, const Kolab::Todo &todo)
{
- KolabType::properties_type &prop = vevent.properties();
+ icalendar_2_0::KolabTodo::properties_type &prop = vevent.properties();
- getIncidenceProperties<KolabType::properties_type>(prop, todo);
+ getIncidenceProperties<icalendar_2_0::KolabTodo::properties_type>(prop, todo);
if (!todo.relatedTo().empty()) {
- KolabType::properties_type::related_to_sequence list;
+ icalendar_2_0::KolabTodo::properties_type::related_to_sequence list;
BOOST_FOREACH(std::string relatedTo, todo.relatedTo()) {
- list.push_back(KolabType::properties_type::related_to_type(relatedTo));
+ list.push_back(icalendar_2_0::KolabTodo::properties_type::related_to_type(relatedTo));
}
prop.related_to(list);
}
if (todo.due().isValid()) {
- prop.due(fromDate<KolabTypes, KolabType::properties_type::due_type>(todo.due()));
+ prop.due(fromDate<icalendar_2_0::KolabTodo::properties_type::due_type>(todo.due()));
}
if (todo.percentComplete() > 0) {
- prop.percent_complete(KolabType::properties_type::percent_complete_type(fromInt<icalendar_2_0::IntegerPropertyType::integer_type>(todo.percentComplete())));
+ prop.percent_complete(icalendar_2_0::KolabTodo::properties_type::percent_complete_type(fromInt<icalendar_2_0::IntegerPropertyType::integer_type>(todo.percentComplete())));
}
}
- static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, KolabType inc) //TODO to base trait
+ static void addIncidence(icalendar_2_0::VcalendarType::components_type &components, icalendar_2_0::KolabTodo inc) //TODO to base trait
{
components.vtodo().push_back(inc);
}
static void readIncidence(Kolab::Todo &todo, const icalendar_2_0::KolabTodo& vevent)
{
- const KolabType::properties_type &prop = vevent.properties();
+ const icalendar_2_0::KolabTodo::properties_type &prop = vevent.properties();
- setIncidenceProperties<Kolab::Todo, KolabType::properties_type>(todo, prop);
+ setIncidenceProperties<Kolab::Todo, icalendar_2_0::KolabTodo::properties_type>(todo, prop);
if (!prop.related_to().empty()) {
- BOOST_FOREACH(KolabType::properties_type::related_to_type p, prop.related_to()) {
+ BOOST_FOREACH(icalendar_2_0::KolabTodo::properties_type::related_to_type p, prop.related_to()) {
todo.addRelatedTo(p.text());
}
}
if (prop.due()) {
- todo.setDue(*toDate<KolabTypes>(*prop.due()));
+ todo.setDue(*toDate(*prop.due()));
}
if (prop.percent_complete()) {
todo.setPercentComplete(toInt(*prop.percent_complete()));
}
if (vevent.components()) {
- getAlarms<IncidenceType, KolabType>(todo, *vevent.components());
+ getAlarms<Kolab::Todo, icalendar_2_0::KolabTodo>(todo, *vevent.components());
}
}
- static void setComponents(KolabType::components_type& components, const Kolab::Todo &incidence)
+ static void setComponents(icalendar_2_0::KolabTodo::components_type& components, const Kolab::Todo &incidence)
{
- setAlarms<KolabType, IncidenceType>(components, incidence);
+ setAlarms<icalendar_2_0::KolabTodo, IncidenceType>(components, incidence);
}
static icalendar_2_0::VcalendarType::components_type::vevent_const_iterator begin(const icalendar_2_0::VcalendarType::components_type &components)
@@ -1356,6 +1569,121 @@ template < > struct IncidenceTrait <Kolab::Todo>
};
+//////////////////////////////////=========================================
+
+
+template <typename T>
+std::string serializeIncidence(const typename T::IncidenceType &incidence, const std::string productid = std::string()) {
+
+ using namespace icalendar_2_0;
+ typedef IncidenceConverter< Incidence, typename T::IncidenceType > IC;
+ typedef typename T::KolabType KolabType;
+
+ try {
+
+ typename KolabType::components_type eventComponents;
+ T::setComponents(eventComponents, incidence);
+
+ typename KolabType::properties_type::uid_type uid(IC::uid(incidence));
+ typename KolabType::properties_type::dtstamp_type dtstamp;
+ dtstamp.date_time(IC::dtstamp());
+ typename KolabType::properties_type::created_type created;
+ created.date_time(IC::created(incidence));
+ typename KolabType::properties_type eventProps(uid, created, dtstamp);
+
+ KolabType inc(eventProps);
+ if (!eventComponents.valarm().empty()) {
+ inc.components(eventComponents);
+ }
+ T::writeIncidence(inc, incidence);
+
+
+ VcalendarType::components_type components;
+ T::addIncidence(components, inc);
+
+ VcalendarType::properties_type::prodid_type prodid(productid+KOLAB_LIBNAME+KOLAB_LIB_VERSION); //FIXME own version field for lib version
+ VcalendarType::properties_type::version_type version(XCAL_VERSION);
+ VcalendarType::properties_type::x_kolab_version_type x_kolab_version(KOLAB_FORMAT_VERSION);
+
+ VcalendarType::properties_type properties(prodid, version, x_kolab_version);
+
+ VcalendarType vcalendar(properties, components);
+
+ IcalendarType icalendar(vcalendar);
+
+ xml_schema::namespace_infomap map;
+ map[""].name = XCAL_NAMESPACE;
+
+ std::ostringstream ostringstream;
+ icalendar_2_0::icalendar(ostringstream, icalendar, map);
+ return ostringstream.str();
+ } catch (const xml_schema::exception& e) {
+ std::cout << "failed to write Incidence" << std::endl;
+ } catch (...) {
+ std::cerr << "Unhandled exception" << std::endl;
+ }
+ return std::string();
+}
+
+
+template <typename T>
+typename T::IncidencePtr deserializeIncidence(const std::string& s, bool isUrl)
+{
+ typedef typename T::IncidencePtr IncidencePtr;
+ typedef typename T::IncidenceType IncidenceType;
+ typedef typename T::KolabType KolabType;
+
+ try {
+ std::auto_ptr<icalendar_2_0::IcalendarType> icalendar;
+ if (isUrl) {
+ xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseFile(s);
+ if (doc.get()) {
+ icalendar = icalendar_2_0::icalendar(doc);
+ }
+ } else {
+ xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseString(s);
+ if (doc.get()) {
+ icalendar = icalendar_2_0::icalendar(doc);
+ }
+ }
+
+ if (!icalendar.get()) {
+ std::cerr << "failed to parse calendar!" << std::endl;
+ return IncidencePtr();
+ }
+
+ const icalendar_2_0::VcalendarType &vcalendar = icalendar->vcalendar();
+
+ std::vector < IncidencePtr > incidences;
+ for (typename xsd::cxx::tree::sequence< KolabType >::const_iterator it(T::begin(vcalendar.components())); it != T::end(vcalendar.components()); it++) {
+ IncidencePtr e = IncidencePtr(new IncidenceType);
+ const KolabType &event = *it;
+ T::readIncidence(*e, event);
+ incidences.push_back(e);
+ }
+
+ //TODO x_kolab_version
+
+ //TODO resolve events, exceptions can be identified based on the recurrence-id attribute
+// foreach (KCalCore::Event * event, events) {
+// if (!event->hasRecurrenceId()) {
+// return event;
+// }
+// }
+ if (incidences.size() != 1) {
+ std::cerr << "wrong number of incidences: " << incidences.size() << std::endl;
+ }
+ return *incidences.begin();
+ } catch (const xml_schema::exception& e) {
+ std::cerr << e << std::endl;
+ std::cerr << "Failed to read incidence!" << std::endl;
+ } catch (...) {
+ std::cerr << "Unhandled exception" << std::endl;
+ }
+ return IncidencePtr();
+}
+
+ }
}//Namespace
#endif
\ No newline at end of file
diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index 9a89863..d9443ed 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -25,11 +25,12 @@
#include "global_definitions.h"
#include "utils.h"
-const char* const XCARD_NAMESPACE = "urn:ietf:params:xml:ns:vcard-4.0";
-const char* const INDIVIDUAL = "individual";
-const char* const GROUP = "group";
-
namespace Kolab {
+ namespace XCARD {
+
+ const char* const XCARD_NAMESPACE = "urn:ietf:params:xml:ns:vcard-4.0";
+ const char* const INDIVIDUAL = "individual";
+ const char* const GROUP = "group";
template <typename T>
std::string getType();
@@ -151,6 +152,8 @@ boost::shared_ptr<T> deserializeCard(const std::string& s, bool isUrl)
return boost::shared_ptr<T>();
}
+
+ }
} //Namespace
diff --git a/c++/tests/CMakeLists.txt b/c++/tests/CMakeLists.txt
index 9a78104..a3b7899 100644
--- a/c++/tests/CMakeLists.txt
+++ b/c++/tests/CMakeLists.txt
@@ -8,10 +8,10 @@ if (QT4_FOUND AND KDECORE_FOUND AND KCALCORE_FOUND)
QT4_AUTOMOC(bindingstest.cpp)
add_executable(bindingstest bindingstest.cpp ${CMAKE_CURRENT_BINARY_DIR}/${BINDINGSTEST_MOC})
target_link_libraries(bindingstest ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} kolabxml kolabkcal ${XERCES_C})
-
- QT4_AUTOMOC(kcalconversiontest.cpp)
- add_executable(kcalconversiontest kcalconversiontest.cpp ${CMAKE_CURRENT_BINARY_DIR}/${KCALCONVERSIONTEST_MOC})
- target_link_libraries(kcalconversiontest ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} kolabxmlkcal ${XERCES_C})
+#
+# QT4_AUTOMOC(kcalconversiontest.cpp)
+# add_executable(kcalconversiontest kcalconversiontest.cpp ${CMAKE_CURRENT_BINARY_DIR}/${KCALCONVERSIONTEST_MOC})
+# target_link_libraries(kcalconversiontest ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} kolabxmlkcal ${XERCES_C})
QT4_AUTOMOC(conversiontest.cpp)
add_executable(conversiontest conversiontest.cpp ${CMAKE_CURRENT_BINARY_DIR}/${CONVERSIONTEST_MOC})
diff --git a/c++/tests/conversiontest.cpp b/c++/tests/conversiontest.cpp
index cb9367c..5fe8f5e 100644
--- a/c++/tests/conversiontest.cpp
+++ b/c++/tests/conversiontest.cpp
@@ -7,6 +7,8 @@
Q_DECLARE_METATYPE(Kolab::Duration);
Q_DECLARE_METATYPE(Kolab::DayPos);
+
+using namespace Kolab::XCAL;
void ConversionTest::durationParserTest_data()
{
@@ -23,7 +25,7 @@ void ConversionTest::durationParserTest()
{
QFETCH(QString, string);
QFETCH(Kolab::Duration, expected);
- const Kolab::Duration result = Kolab::toDuration(string.toStdString());
+ const Kolab::Duration result = toDuration(string.toStdString());
QCOMPARE(result, expected);
}
@@ -35,6 +37,7 @@ void ConversionTest::durationSerializerTest_data()
QTest::newRow("Time") << "PT2H3M4S" << Kolab::Duration(0,2,3,4, false);
QTest::newRow("Day") << "P1DT2H3M4S" << Kolab::Duration(1,2,3,4, false);
QTest::newRow("Week") << "P1W" << Kolab::Duration(1, false);
+ QTest::newRow("Week") << "-P3W" << Kolab::Duration(3, false);
QTest::newRow("Week Multidigit, negative") << "-P23W" << Kolab::Duration(23, true);
}
@@ -42,7 +45,7 @@ void ConversionTest::durationSerializerTest()
{
QFETCH(Kolab::Duration, duration);
QFETCH(QString, expected);
- const std::string result = Kolab::fromDuration(duration);
+ const std::string result = fromDuration(duration);
QCOMPARE(QString::fromStdString(result), expected);
}
@@ -63,7 +66,7 @@ void ConversionTest::dayPosParserTest()
{
QFETCH(QString, string);
QFETCH(Kolab::DayPos, expected);
- const Kolab::DayPos result = Kolab::toDayPos(string.toStdString());
+ const Kolab::DayPos result = toDayPos(string.toStdString());
QCOMPARE(result, expected);
}
@@ -82,7 +85,7 @@ void ConversionTest::dayPosSerializerTest()
{
QFETCH(Kolab::DayPos, daypos);
QFETCH(QString, expected);
- const std::string result = Kolab::fromDayPos(daypos);
+ const std::string result = fromDayPos(daypos);
QCOMPARE(QString::fromStdString(result), expected);
}
diff --git a/c++/tests/kcalconversiontest.cpp b/c++/tests/kcalconversiontest.cpp
index 4a01e7b..ee5061d 100644
--- a/c++/tests/kcalconversiontest.cpp
+++ b/c++/tests/kcalconversiontest.cpp
@@ -4,7 +4,7 @@
#include <QtTest/QtTest>
#include <kcalcore/recurrence.h>
-#include <lib/kcalconversions.h>
+// #include <lib/kcalconversions.h>
#include <lib/kcalkolabformat.h>
More information about the commits
mailing list