Branch 'libkolabxml-0.8' - src/containers src/xcalconversions.h tests/bindingstest.cpp tests/bindingstest.h

Christian Mollekopf mollekopf at kolabsys.com
Tue Jan 15 14:23:03 CET 2013


 src/containers/kolabevent.cpp |   18 +++++-----
 src/containers/kolabevent.h   |    4 +-
 src/containers/kolabtodo.cpp  |   11 ++++++
 src/containers/kolabtodo.h    |    3 +
 src/xcalconversions.h         |   74 ++++++++++++++++++++++++++++++++++++------
 tests/bindingstest.cpp        |   31 +++++++++++++++++
 tests/bindingstest.h          |    1 
 7 files changed, 121 insertions(+), 21 deletions(-)

New commits:
commit 79b52d27b9d211d9387493dbfd45192bb82358bb
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Mon Jan 14 17:01:25 2013 +0100

    Support for recurrence exceptions.
    (cherry picked from commit 933250ca15b39b5ac78dd6812c0f65391c773df4)

diff --git a/src/containers/kolabevent.cpp b/src/containers/kolabevent.cpp
index f70346a..0fd4d2b 100644
--- a/src/containers/kolabevent.cpp
+++ b/src/containers/kolabevent.cpp
@@ -300,15 +300,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/src/containers/kolabevent.h b/src/containers/kolabevent.h
index abec9a9..8973d1a 100644
--- a/src/containers/kolabevent.h
+++ b/src/containers/kolabevent.h
@@ -105,9 +105,9 @@ public:
     
     void setCustomProperties(const std::vector<CustomProperty> &);
     std::vector<CustomProperty> customProperties() const;
-/*    TODO what is this? Exceptions it is
+    
     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/src/containers/kolabtodo.cpp b/src/containers/kolabtodo.cpp
index ceefcf9..2286d25 100644
--- a/src/containers/kolabtodo.cpp
+++ b/src/containers/kolabtodo.cpp
@@ -29,6 +29,7 @@ struct Todo::Private: public PrivateIncidence
     
     cDateTime due;
     int percentComplete;
+    std::vector< Todo > exceptions;
 };
 
 Todo::Todo()
@@ -314,6 +315,16 @@ std::vector< CustomProperty > Todo::customProperties() const
     return d->customProperties;
 }
 
+void Todo::setExceptions(const std::vector< Todo > &exceptions)
+{
+    d->exceptions = exceptions;
+}
+
+std::vector< Todo > Todo::exceptions() const
+{
+    return d->exceptions;
+}
+
 void Todo::setAlarms(const std::vector< Alarm > &alarms)
 {
     d->alarms = alarms;
diff --git a/src/containers/kolabtodo.h b/src/containers/kolabtodo.h
index ce547e3..1ab8024 100644
--- a/src/containers/kolabtodo.h
+++ b/src/containers/kolabtodo.h
@@ -108,6 +108,9 @@ public:
     void setCustomProperties(const std::vector<CustomProperty> &);
     std::vector<CustomProperty> customProperties() const;
     
+    void setExceptions(const std::vector<Todo> &);
+    std::vector<Todo> exceptions() const;
+    
     void setAlarms(const std::vector<Alarm> &);
     std::vector<Alarm> alarms() const;
     
diff --git a/src/xcalconversions.h b/src/xcalconversions.h
index 0a419b9..d11536c 100644
--- a/src/xcalconversions.h
+++ b/src/xcalconversions.h
@@ -1527,6 +1527,26 @@ template < > struct IncidenceTrait <Kolab::Event>
     {
         return components.vevent().end();
     }
+
+    static IncidencePtr resolveExceptions(const std::vector<IncidencePtr> &list)
+    {
+        IncidencePtr incidence = *list.begin();
+        std::vector<IncidenceType> exceptions;
+        for (std::vector < IncidencePtr >::const_iterator it = list.begin()+1; it != list.end(); it++) {
+            exceptions.push_back(**it);
+        }
+        incidence->setExceptions(exceptions);
+        return incidence;
+    }
+    
+    static void addExceptions(icalendar_2_0::VcalendarType::components_type &components, const Kolab::Event &event, KolabType::properties_type props)
+    {
+        BOOST_FOREACH(const Kolab::Event &exception, event.exceptions()) {
+            KolabType ex(props);
+            writeIncidence(ex, exception);
+            addIncidence(components, ex);
+        }
+    }
     
 };
 
@@ -1603,6 +1623,26 @@ template < > struct IncidenceTrait <Kolab::Todo>
         return components.vtodo().end();
     }
     
+    static IncidencePtr resolveExceptions(const std::vector<IncidencePtr> &list)
+    {
+        IncidencePtr incidence = *list.begin();
+        std::vector<IncidenceType> exceptions;
+        for (std::vector < IncidencePtr >::const_iterator it = list.begin()+1; it != list.end(); it++) {
+            exceptions.push_back(**it);
+        }
+        incidence->setExceptions(exceptions);
+        return incidence;
+    }
+    
+    static void addExceptions(icalendar_2_0::VcalendarType::components_type &components, const Kolab::Todo &event, KolabType::properties_type props)
+    {
+        BOOST_FOREACH(const Kolab::Todo &exception, event.exceptions()) {
+            KolabType ex(props);
+            writeIncidence(ex, exception);
+            addIncidence(components, ex);
+        }
+    }
+    
 };
 
 template < > struct IncidenceTrait <Kolab::Journal>
@@ -1638,6 +1678,15 @@ template < > struct IncidenceTrait <Kolab::Journal>
         return components.vjournal().end();
     }
     
+    static IncidencePtr resolveExceptions(const std::vector<IncidencePtr> &list)
+    {
+        return *list.begin();
+    }
+    
+    static void addExceptions(icalendar_2_0::VcalendarType::components_type &, const Kolab::Journal &, KolabType::properties_type)
+    {
+    }
+    
 };
 
 template < > struct IncidenceTrait <Kolab::Freebusy>
@@ -1785,6 +1834,15 @@ template < > struct IncidenceTrait <Kolab::Freebusy>
     {
         return components.vfreebusy().end();
     }
+    
+    static IncidencePtr resolveExceptions(const std::vector<IncidencePtr> &list)
+    {
+        return *list.begin();
+    }
+    
+    static void addExceptions(icalendar_2_0::VcalendarType::components_type &, const Kolab::Freebusy &, KolabType::properties_type)
+    {
+    }
 
 };
 
@@ -1825,6 +1883,8 @@ std::string serializeIncidence(const typename T::IncidenceType &incidence, const
 
         VcalendarType::components_type components;
         T::addIncidence(components, inc);
+
+        T::addExceptions(components, incidence, eventProps);
         
         VcalendarType::properties_type::prodid_type prodid(getProductId(productid));
         VcalendarType::properties_type::version_type version(XCAL_VERSION);
@@ -1893,17 +1953,11 @@ typename T::IncidencePtr deserializeIncidence(const std::string& s, bool isUrl)
         global_xCalVersion = vcalendar.properties().version().text();
         setKolabVersion( vcalendar.properties().x_kolab_version().text() );
 
-
-        //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) {
-            WARNING("wrong number of incidences: "+ incidences.size());
+        if (incidences.empty()) {
+            CRITICAL("no incidence in object");
+            return IncidencePtr();
         }
-        return *incidences.begin();
+        return T::resolveExceptions(incidences);
     } catch  (const xml_schema::exception& e) {
         std::cerr <<  e << std::endl;
     } catch (...) {
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 912e5c6..edfb680 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -310,6 +310,37 @@ void BindingsTest::eventDuration()
     QCOMPARE(ev.duration(), e.duration());
 }
 
+void BindingsTest::eventExceptions()
+{
+    Kolab::Event ev;
+    ev.setUid("uid1");
+    ev.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
+    std::vector<Kolab::Event> exceptions;
+    Kolab::Event ex1;
+    ex1.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
+    ex1.setUid("uid1");
+    ex1.setRecurrenceID(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0), true);
+    exceptions.push_back(ex1);
+    Kolab::Event ex2;
+    ex2.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
+    ex2.setUid("uid1");
+    ex2.setRecurrenceID(Kolab::cDateTime("Europe/Zurich", 2007,1,8,12,0,0), false);
+    exceptions.push_back(ex2);
+    ev.setExceptions(exceptions);
+
+    const std::string result = Kolab::writeEvent(ev);
+    QVERIFY(Kolab::error() == Kolab::NoError);
+//     std::cout << result << endl;
+    const Kolab::Event e = Kolab::readEvent(result, false);
+    QVERIFY(Kolab::error() == Kolab::NoError);
+    QCOMPARE(e.exceptions().size(), std::size_t(2));
+    QCOMPARE(ev.exceptions().at(0).uid(), e.exceptions().at(0).uid());
+    QCOMPARE(ev.exceptions().at(0).recurrenceID(), e.exceptions().at(0).recurrenceID());
+    QCOMPARE(ev.exceptions().at(1).uid(), e.exceptions().at(1).uid());
+    QCOMPARE(ev.exceptions().at(1).recurrenceID(), e.exceptions().at(1).recurrenceID());
+
+}
+
 void BindingsTest::todoCompletness()
 {
     Kolab::Todo ev;
diff --git a/tests/bindingstest.h b/tests/bindingstest.h
index 86fd7d7..dbd2c76 100644
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@ -27,6 +27,7 @@ class BindingsTest : public QObject
     void noteCompletness();
     void eventCompletness();
     void eventDuration();
+    void eventExceptions();
     void todoCompletness();
     void dueDateDateOnly();
     void journalCompletness();





More information about the commits mailing list