2 commits - src/CMakeLists.txt src/kolabevent.cpp src/kolabevent.h src/kolabevent_p.h src/kolabformat.cpp src/kolabformat.h src/shared_conversions.h src/xcalconversions.h src/xcardconversions.h tests/conversiontest.cpp tests/conversiontest.h

Christian Mollekopf mollekopf at kolabsys.com
Thu May 24 16:06:04 CEST 2012


 src/CMakeLists.txt       |    2 ++
 src/kolabevent.cpp       |   14 +-------------
 src/kolabevent.h         |    2 +-
 src/kolabevent_p.h       |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/kolabformat.cpp      |    5 +++++
 src/kolabformat.h        |    5 +++++
 src/shared_conversions.h |   20 --------------------
 src/xcalconversions.h    |    4 ++--
 src/xcardconversions.h   |    6 +++++-
 tests/conversiontest.cpp |   20 ++++++++++++++++++--
 tests/conversiontest.h   |    1 +
 11 files changed, 82 insertions(+), 39 deletions(-)

New commits:
commit 8edcf270de58d8fdc827335ab6ace49832f76f16
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Thu May 24 16:06:00 2012 +0200

    Give subclasses direct access to the values.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6bbed10..2f635d6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -31,6 +31,8 @@ install(TARGETS kolabxml EXPORT LibkolabxmlExport
 install( FILES
     kolabformat.h
     kolabevent.h
+    kolabevent_p.h
+    incidence_p.h
     kolabtodo.h
     kolabjournal.h
     kolabcontact.h
diff --git a/src/kolabevent.cpp b/src/kolabevent.cpp
index 1ac4f71..56295e6 100644
--- a/src/kolabevent.cpp
+++ b/src/kolabevent.cpp
@@ -16,22 +16,10 @@
 */
 
 #include "kolabevent.h"
-#include "incidence_p.h"
+#include "kolabevent_p.h"
 
 namespace Kolab {
 
-struct Event::Private: public PrivateIncidence
-{
-    Private()
-    : PrivateIncidence(), 
-    isTransparent(false){}
-
-    cDateTime end;
-    bool isTransparent;
-    Duration duration;
-    std::vector< Event > exceptions;
-};
-
 Event::Event()
 : d(new Event::Private())
 {
diff --git a/src/kolabevent.h b/src/kolabevent.h
index c203ace..424fafd 100644
--- a/src/kolabevent.h
+++ b/src/kolabevent.h
@@ -115,7 +115,7 @@ public:
     void setAlarms(const std::vector<Alarm> &);
     std::vector<Alarm> alarms() const;
 
-private:
+protected:
     struct Private;
     boost::scoped_ptr<Private> d;
 };
diff --git a/src/kolabevent_p.h b/src/kolabevent_p.h
new file mode 100644
index 0000000..66054d3
--- /dev/null
+++ b/src/kolabevent_p.h
@@ -0,0 +1,42 @@
+/*
+ * 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 KOLABEVENT_P
+#define KOLABEVENT_P
+
+#include "kolabcontainers.h"
+#include "incidence_p.h"
+
+namespace Kolab {
+
+class Event;
+
+struct Event::Private: public PrivateIncidence
+{
+    Private()
+    : PrivateIncidence(),
+    isTransparent(false){}
+
+    cDateTime end;
+    bool isTransparent;
+    Duration duration;
+    std::vector< Event > exceptions;
+};
+
+}
+
+#endif


commit b6f7242706824889de025c61725593e05815856c
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Thu May 24 14:04:15 2012 +0200

    Some cleanup, make generateUID available.

diff --git a/src/kolabformat.cpp b/src/kolabformat.cpp
index e2b69cc..13d282b 100644
--- a/src/kolabformat.cpp
+++ b/src/kolabformat.cpp
@@ -56,6 +56,11 @@ std::string getSerializedUID()
     return Utils::createdUid();
 }
 
+std::string generateUID()
+{
+    return Utils::getUID();
+}
+
 void overrideTimestamp(const cDateTime& dt)
 {
     Utils::setOverrideTimestamp(dt);
diff --git a/src/kolabformat.h b/src/kolabformat.h
index 221b7fd..57e4940 100644
--- a/src/kolabformat.h
+++ b/src/kolabformat.h
@@ -59,6 +59,11 @@ std::string xCalVersion();
 std::string getSerializedUID();
 
 /**
+ * Returns a generated uid.
+ */
+std::string generateUID();
+
+/**
  * Use this function to override the timestamp which is normally generated upon serialization from the system time.
  * To override the timestamp call this function once. You will need to clear the timestamp manually by setting a default constructed cDateTime().
  * 
diff --git a/src/shared_conversions.h b/src/shared_conversions.h
index a19cd88..119c5e8 100644
--- a/src/shared_conversions.h
+++ b/src/shared_conversions.h
@@ -96,26 +96,6 @@ Kolab::ContactReference toContactReference(const std::string &uri) {
     return Kolab::ContactReference(Kolab::ContactReference::EmailReference, email, name);
 }
 
-std::string fromContactReference(const Kolab::ContactReference &c, bool embeddName = true) {
-    switch (c.type()) {
-        case ContactReference::UidReference:
-            return toURN(c.uid());
-        case ContactReference::EmailReference:
-        case ContactReference::EmailAndUidReference:
-            if (embeddName) {
-                return toMailto(c.email(), c.name());
-            }
-            return toMailto(c.email());
-        case ContactReference::Invalid:
-        default:
-            WARNING("Tried serializing invalid ContactReference");
-    }
-    return std::string();
-}
-
-
-
-
     } //Namespace
 } //Namespace
 
diff --git a/src/xcalconversions.h b/src/xcalconversions.h
index 68947ee..ced0b27 100644
--- a/src/xcalconversions.h
+++ b/src/xcalconversions.h
@@ -1183,7 +1183,7 @@ void getIncidenceProperties(T &prop, const I &inc)
             if (!a.delegatedTo().empty()) {
                 icalendar_2_0::DelegatedToParamType delegatedTo;
                 BOOST_FOREACH(const Kolab::ContactReference &ref, a.delegatedTo()) {
-                    delegatedTo.cal_address().push_back(CalAddressListParamType::cal_address_type(Shared::fromContactReference(ref, true)));
+                    delegatedTo.cal_address().push_back(CalAddressListParamType::cal_address_type(toMailto(ref.email(), ref.name())));
                 }
                 p.baseParameter().push_back(delegatedTo);
             }
@@ -1191,7 +1191,7 @@ void getIncidenceProperties(T &prop, const I &inc)
             if (!a.delegatedFrom().empty()) {
                 icalendar_2_0::DelegatedFromParamType delegatedFrom;
                 BOOST_FOREACH(const Kolab::ContactReference &ref, a.delegatedFrom()) {
-                    delegatedFrom.cal_address().push_back(CalAddressListParamType::cal_address_type(Shared::fromContactReference(ref, true)));
+                    delegatedFrom.cal_address().push_back(CalAddressListParamType::cal_address_type(toMailto(ref.email(), ref.name())));
                 }
                 p.baseParameter().push_back(delegatedFrom);
             }
diff --git a/src/xcardconversions.h b/src/xcardconversions.h
index ae6a2f5..70ac33a 100644
--- a/src/xcardconversions.h
+++ b/src/xcardconversions.h
@@ -741,7 +741,11 @@ void writeCard<Kolab::DistList>(vcard_4_0::vcard &vcard, const Kolab::DistList &
         vcard_4_0::vcard::member_sequence members;
         const std::vector<ContactReference> &l = distlist.members();
         BOOST_FOREACH (const Kolab::ContactReference &m, l) {
-            members.push_back(vcard_4_0::vcard::member_type(Shared::fromContactReference(m)));
+            if (!m.uid().empty()) {
+                members.push_back(vcard_4_0::vcard::member_type(Shared::toURN(m.uid())));
+            } else {
+                members.push_back(vcard_4_0::vcard::member_type(Shared::toMailto(m.email(), m.name())));
+            }
         }
         vcard.member(members);
     } else {
diff --git a/tests/conversiontest.cpp b/tests/conversiontest.cpp
index 60cbe43..7144fb4 100644
--- a/tests/conversiontest.cpp
+++ b/tests/conversiontest.cpp
@@ -226,9 +226,9 @@ void ConversionTest::geoUriTest()
 void ConversionTest::contactReferenceTest()
 {
     Kolab::ContactReference email(Kolab::ContactReference::EmailReference, "mail", "name");
-    QCOMPARE(Kolab::Shared::fromContactReference(email), std::string("mailto:name%3Cmail%3E"));
+    QCOMPARE(Kolab::Shared::toMailto(email.email(), email.name()), std::string("mailto:name%3Cmail%3E"));
     Kolab::ContactReference urn(Kolab::ContactReference::UidReference, "urn");
-    QCOMPARE(Kolab::Shared::fromContactReference(urn), std::string("urn:uuid:urn"));
+    QCOMPARE(Kolab::Shared::toURN(urn.uid()), std::string("urn:uuid:urn"));
     
     QCOMPARE(Kolab::Shared::toContactReference("urn:uuid:urn"), urn);
     QCOMPARE(Kolab::Shared::toContactReference("mailto:name%3Cmail%3E"), email);
@@ -266,6 +266,22 @@ void ConversionTest::uuidGeneratorTest()
     QCOMPARE(s.size(), (std::size_t)36ul);
 }
 
+void ConversionTest::uuidGeneratorTest2()
+{
+    Kolab::Event event;
+    event.setStart(Kolab::cDateTime(2001, 01, 02, 03, 04 ,05, false));
+    QVERIFY(Kolab::getSerializedUID().empty());
+    Kolab::writeEvent(event);
+    std::string uid1 = Kolab::getSerializedUID();
+    QVERIFY(!uid1.empty());
+    Kolab::writeEvent(event);
+    std::string uid2 = Kolab::getSerializedUID();
+    std::cout << uid1 << uid2;
+    QVERIFY(!uid2.empty());
+    QVERIFY(uid1 != uid2);
+}
+
+
 
 
 QTEST_MAIN( ConversionTest )
diff --git a/tests/conversiontest.h b/tests/conversiontest.h
index b586ed6..7ccd110 100644
--- a/tests/conversiontest.h
+++ b/tests/conversiontest.h
@@ -42,6 +42,7 @@ class ConversionTest : public QObject
     void threadLocalTest();
     
     void uuidGeneratorTest();
+    void uuidGeneratorTest2();
 };
 
 #endif // CONVERSIONTEST_H





More information about the commits mailing list