Branch 'dev/libkolab' - 10 commits - c++/lib c++/tests libkolab/kolabformat libkolab/mime upgradetool/upgradetooltests.cpp

Christian Mollekopf mollekopf at kolabsys.com
Thu Mar 22 00:09:05 CET 2012


 c++/lib/CMakeLists.txt               |    4 
 c++/lib/kolabformat.cpp              |    4 
 c++/lib/php/test.php                 |   28 ++--
 c++/lib/xcardconversions.h           |   12 +
 c++/tests/bindingstest.cpp           |    1 
 libkolab/kolabformat/kolabobject.cpp |  243 ++++++++++++++++++++++++++++-------
 libkolab/kolabformat/kolabobject.h   |   24 ++-
 libkolab/mime/mimeutils.cpp          |   24 +--
 upgradetool/upgradetooltests.cpp     |    4 
 9 files changed, 261 insertions(+), 83 deletions(-)

New commits:
commit aa9dcc565fe64f265a1017c3fc7d81fb35f31076
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 23:31:48 2012 +0100

    V2 implementation for contacts and distlists.

diff --git a/libkolab/kolabformat/kolabobject.cpp b/libkolab/kolabformat/kolabobject.cpp
index 0a5059d..0a0cbc2 100644
--- a/libkolab/kolabformat/kolabobject.cpp
+++ b/libkolab/kolabformat/kolabobject.cpp
@@ -21,11 +21,15 @@
 #include <kolabformatV2/journal.h>
 #include <kolabformatV2/task.h>
 #include <kolabformatV2/event.h>
+#include <kolabformatV2/contact.h>
+#include <kolabformatV2/distributionlist.h>
 #include <mime/mimeutils.h>
 #include <conversion/kcalconversion.h>
 #include <qdom.h>
 #include <kcalcore/journal.h>
 #include <kdebug.h>
+#include <kabc/addressee.h>
+#include <qbuffer.h>
 #include <kolab/kolabformat.h>
 
 
@@ -34,6 +38,8 @@ namespace Kolab {
 static QString eventKolabType() { return QString::fromLatin1("application/x-vnd.kolab.event"); };
 static QString todoKolabType() { return QString::fromLatin1("application/x-vnd.kolab.task"); };
 static QString journalKolabType() { return QString::fromLatin1("application/x-vnd.kolab.journal"); };
+static QString contactKolabType() { return QString::fromLatin1("application/x-vnd.kolab.contact"); };
+static QString distlistKolabType() { return QString::fromLatin1("application/x-vnd.kolab.contact.distlist"); }
 static QString xCalMimeType() { return QString::fromLatin1("application/calendar+xml"); };
 
 /*
@@ -72,6 +78,105 @@ static inline IncidencePtr incidenceFromKolabImpl( const KMime::Message::Ptr &da
     return ptr;
 }
 
+
+KABC::Addressee addresseFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data)
+{
+    KABC::Addressee addressee;
+//     kDebug() << "xmlData " << xmlData;
+    KolabV2::Contact contact(QString::fromUtf8(xmlData));
+    const QString pictureAttachmentName = contact.pictureAttachmentName();
+    if (!pictureAttachmentName.isEmpty()) {
+      QByteArray type;
+      KMime::Content *imgContent = Mime::findContentByName(data, "kolab-picture.png", type);
+      if (imgContent) {
+        QByteArray imgData = imgContent->decodedContent();
+        QBuffer buffer(&imgData);
+        buffer.open(QIODevice::ReadOnly);
+        QImage image;
+        image.load(&buffer, "PNG");
+        contact.setPicture(image);
+      }
+    }
+
+    QString logoAttachmentName = contact.logoAttachmentName();
+    if (!logoAttachmentName.isEmpty()) {
+      QByteArray type;
+      KMime::Content *imgContent = Mime::findContentByName(data, "kolab-logo.png", type);
+      if (imgContent) {
+        QByteArray imgData = imgContent->decodedContent();
+        QBuffer buffer(&imgData);
+        buffer.open(QIODevice::ReadOnly);
+        QImage image;
+        image.load(&buffer, "PNG");
+        contact.setLogo(image);
+      }
+    }
+
+    QString soundAttachmentName = contact.soundAttachmentName();
+    if (!soundAttachmentName.isEmpty()) {
+      QByteArray type;
+      KMime::Content *content = Mime::findContentByName(data, "sound", type);
+      if (content) {
+        QByteArray sData = content->decodedContent();
+        contact.setSound(sData);
+      }
+    }
+    contact.saveTo(&addressee);
+    return addressee;
+}
+
+KABC::ContactGroup contactGroupFromKolab(const QByteArray &xmlData)
+{
+    KABC::ContactGroup contactGroup;
+    //     kDebug() << "xmlData " << xmlData;
+    KolabV2::DistributionList distList(QString::fromUtf8(xmlData));
+    distList.saveTo(&contactGroup);
+    return contactGroup;
+}
+
+
+KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact)
+{
+    KMime::Message::Ptr message = Mime::createMessage( contactKolabType() ); //TODO v3 mimetype
+    message->subject()->fromUnicodeString( contact.uid(), "utf-8" );
+    message->from()->fromUnicodeString( contact.fullEmail(), "utf-8" );
+    
+    KMime::Content* content = Mime::createMainPart( contactKolabType(), contact.saveXML().toUtf8() ); //TODO v3 mimetype
+    message->addContent( content );
+    
+    if ( !contact.picture().isNull() ) {
+        QByteArray pic;
+        QBuffer buffer(&pic);
+        buffer.open(QIODevice::WriteOnly);
+        contact.picture().save(&buffer, "PNG");
+        buffer.close();
+        
+        content = Mime::createAttachmentPart(QByteArray(), "image/png", "kolab-picture.png", pic );
+        message->addContent(content);
+    }
+    
+    if ( !contact.logo().isNull() ) {
+        QByteArray pic;
+        QBuffer buffer(&pic);
+        buffer.open(QIODevice::WriteOnly);
+        contact.logo().save(&buffer, "PNG");
+        buffer.close();
+        
+        content = Mime::createAttachmentPart(QByteArray(), "image/png", "kolab-logo.png", pic );
+        message->addContent(content);
+    }
+    
+    
+    if ( !contact.sound().isEmpty() ) {
+        content = Mime::createAttachmentPart(QByteArray(), "audio/unknown", "sound", contact.sound() );
+        message->addContent(content);
+    }
+    
+    message->assemble();
+    return message;
+}
+
+
 //Normalize incidences before serializing them
 void normalizeIncidence(KCalCore::Incidence::Ptr i)
 {
@@ -117,7 +222,7 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
         qWarning() << "no part found";
         return InvalidObject;
     }
-    const QByteArray xmlData = xmlContent->decodedContent();
+    const QByteArray &xmlData = xmlContent->decodedContent();
     QStringList attachments;
     KCalCore::Incidence::Ptr i;
     kDebug() << kolabType;
@@ -125,18 +230,23 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
     if (kolabType == eventKolabType()) { //Event
         kDebug() << "event";
         mIncidence = fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
-        Q_ASSERT(mIncidence);
         mObjectType = EventObject;
     } else if (kolabType == todoKolabType()) { //Todo 
         kDebug() << "todo";
         mIncidence = fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(xmlData, attachments);
-        Q_ASSERT(mIncidence);
         mObjectType = TodoObject;
     } else if (kolabType == journalKolabType()) { //Journal
         kDebug() << "journal";
         mIncidence = fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(xmlData, attachments);
-        Q_ASSERT(mIncidence);
         mObjectType = JournalObject;
+    } else if (kolabType == contactKolabType()) { //Contact
+        kDebug() << "contact";
+        mAddressee = addresseFromKolab(xmlData, msg);
+        mObjectType = ContactObject;
+    }  else if (kolabType == distlistKolabType()) { //Distlist
+        kDebug() << "distlist";
+        mContactGroup = contactGroupFromKolab(xmlData);
+        mObjectType = DistlistObject;
     } else {
         kWarning() << "no kolab object found " << kolabType;
     }
@@ -176,6 +286,16 @@ KCalCore::Incidence::Ptr KolabObjectReader::getIncidence() const
     return mIncidence;
 }
 
+KABC::Addressee KolabObjectReader::getContact() const
+{
+    return mAddressee;
+}
+
+KABC::ContactGroup KolabObjectReader::getDistlist() const
+{
+    return mContactGroup;
+}
+
 
 
 KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v, const QString &tz)
@@ -214,6 +334,37 @@ KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr
     return Mime::createMessage(i, xCalMimeType(), journalKolabType(), xml.toLocal8Bit());
 }
 
+KMime::Message::Ptr KolabObjectWriter::writeContact(const KABC::Addressee &addressee, Version v)
+{
+    if (v == KolabV3) {
+        //TODO
+    }
+    KolabV2::Contact contact(&addressee);
+    return contactToKolabFormat(contact);
+}
+
+KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList& distList)
+{    
+    KMime::Message::Ptr message = Mime::createMessage( distlistKolabType() );
+    message->subject()->fromUnicodeString( distList.uid(), "utf-8" );
+    message->from()->fromUnicodeString( distList.uid(), "utf-8" );
+    
+    KMime::Content* content = Mime::createMainPart( distlistKolabType(), distList.saveXML().toUtf8() );
+    message->addContent( content );
+    
+    message->assemble();
+    return message;
+}
+
+KMime::Message::Ptr KolabObjectWriter::writeDistlist(const KABC::ContactGroup &distlist, Version v)
+{
+    if (v == KolabV3) {
+        //TODO
+    }
+    KolabV2::DistributionList d(&distlist);
+    return distListToKolabFormat(d);
+}
+
 
 }; //Namespace
 
diff --git a/libkolab/kolabformat/kolabobject.h b/libkolab/kolabformat/kolabobject.h
index a6f2dbd..672c72c 100644
--- a/libkolab/kolabformat/kolabobject.h
+++ b/libkolab/kolabformat/kolabobject.h
@@ -25,6 +25,12 @@
 #include <kcalcore/journal.h>
 #include <kcalcore/todo.h>
 #include <kmime/kmime_message.h>
+#include <kabc/addressee.h>
+#include <kabc/contactgroup.h>
+
+namespace KABC {
+class Addressee;
+}
 
 namespace Kolab {
 
@@ -38,6 +44,8 @@ enum ObjectType {
     EventObject,
     TodoObject,
     JournalObject,
+    ContactObject,
+    DistlistObject
 };
 
 
@@ -62,8 +70,12 @@ public:
     KCalCore::Todo::Ptr getTodo() const;
     KCalCore::Journal::Ptr getJournal() const;
     KCalCore::Incidence::Ptr getIncidence() const;
+    KABC::Addressee getContact() const;
+    KABC::ContactGroup getDistlist() const;
 private:
     KCalCore::Incidence::Ptr mIncidence;
+    KABC::Addressee mAddressee;
+    KABC::ContactGroup mContactGroup;
     ObjectType mObjectType;
     Version mVersion;
 };
@@ -73,6 +85,8 @@ public:
     static KMime::Message::Ptr writeEvent(const KCalCore::Event::Ptr &, Version v = KolabV3, const QString &tz = QString());
     static KMime::Message::Ptr writeTodo(const KCalCore::Todo::Ptr &, Version v = KolabV3, const QString &tz = QString());
     static KMime::Message::Ptr writeJournal(const KCalCore::Journal::Ptr &, Version v = KolabV3, const QString &tz = QString());
+    static KMime::Message::Ptr writeContact(const KABC::Addressee &, Version v = KolabV3);
+    static KMime::Message::Ptr writeDistlist(const KABC::ContactGroup &, Version v = KolabV3);
 };
 
 }; //Namespace


commit aa93ab267df1f414d834c189431efef6c6c8805f
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 19:24:54 2012 +0100

    Incidence code works for kolabresource v2 and for upgrade code.

diff --git a/libkolab/kolabformat/kolabobject.cpp b/libkolab/kolabformat/kolabobject.cpp
index 77c77fa..0a5059d 100644
--- a/libkolab/kolabformat/kolabobject.cpp
+++ b/libkolab/kolabformat/kolabobject.cpp
@@ -63,34 +63,22 @@ static inline IncidencePtr incidenceFromKolabImpl( const KMime::Message::Ptr &da
         qWarning() << "couldn't find part";
         return IncidencePtr();
     }
-    const QByteArray xmlData = xmlContent->decodedContent();
+    const QByteArray &xmlData = xmlContent->decodedContent();
     
     QStringList attachments;
     IncidencePtr ptr = fromXML<IncidencePtr, Converter>(xmlData, attachments); //TODO do we care about timezone?
     Mime::getAttachments(ptr, attachments, data);
     
     return ptr;
-    //             KMime::Content *xmlContent = findContentByType( data, mimetype );
-    //             if ( xmlContent ) {
-        //                 const QByteArray xmlData = xmlContent->decodedContent();
-    // //                 qDebug() << xmlData;
-    //                 const QDomDocument xmlDoc = Converter::loadDocument( QString::fromUtf8(xmlData) );
-    //                 if ( !xmlDoc.isNull() ) {
-        //                     IncidencePtr i = Converter::fromXml( xmlDoc, timezoneId );
-    //                     attachmentsFromKolab( data, xmlDoc, i );
-    //                     return i;
-    //                 }
-    //             }
-    // //             qDebug() << "empty";
-    //             return IncidencePtr();
 }
 
+//Normalize incidences before serializing them
 void normalizeIncidence(KCalCore::Incidence::Ptr i)
 {
     Q_FOREACH (KCalCore::Attendee::Ptr a, i->attendees()) {
         a->setUid(QString()); //KCalCore sets the pointer as uid, we don't want that (if we wanted one, we'd want a real, globally unique one), so we clear the uid
     }
-    
+    //TODO Do we really not need the attachment uri for something else?
     Q_FOREACH (KCalCore::Attachment::Ptr attachment, i->attachments()) {
         attachment->setUri(QString::fromLatin1("cid:")+QString::fromLatin1(KMime::uniqueString() + '@' + "kolab.resource.akonadi")); //Serialize the attachment as attachment with uri, referencing the created mime-part
     }
@@ -108,6 +96,12 @@ KolabObjectReader::KolabObjectReader()
     
 }
 
+KolabObjectReader::KolabObjectReader(const KMime::Message::Ptr& msg)
+{
+    parseMimeMessage(msg);
+}
+
+
 ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
 {
     mObjectType = InvalidObject;
@@ -132,26 +126,23 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
         kDebug() << "event";
         mIncidence = fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
         Q_ASSERT(mIncidence);
-        Mime::getAttachments(mIncidence, attachments, msg);
-        normalizeIncidence(mIncidence);
         mObjectType = EventObject;
     } else if (kolabType == todoKolabType()) { //Todo 
         kDebug() << "todo";
         mIncidence = fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(xmlData, attachments);
         Q_ASSERT(mIncidence);
-        Mime::getAttachments(mIncidence, attachments, msg);
-        normalizeIncidence(mIncidence);
         mObjectType = TodoObject;
     } else if (kolabType == journalKolabType()) { //Journal
         kDebug() << "journal";
         mIncidence = fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(xmlData, attachments);
         Q_ASSERT(mIncidence);
-        Mime::getAttachments(mIncidence, attachments, msg);
-        normalizeIncidence(mIncidence);
         mObjectType = JournalObject;
     } else {
         kWarning() << "no kolab object found " << kolabType;
     }
+    if (mIncidence) {
+        Mime::getAttachments(mIncidence, attachments, msg);
+    }
     return mObjectType;
 }
 
@@ -167,43 +158,60 @@ ObjectType KolabObjectReader::getType() const
 
 KCalCore::Event::Ptr KolabObjectReader::getEvent() const
 {
-    return qSharedPointerDynamicCast<KCalCore::Event>(mIncidence);
+    return mIncidence.dynamicCast<KCalCore::Event>();
 }
 
 KCalCore::Todo::Ptr KolabObjectReader::getTodo() const
 {
-    return qSharedPointerDynamicCast<KCalCore::Todo>(mIncidence);
+    return mIncidence.dynamicCast<KCalCore::Todo>();
 }
 
 KCalCore::Journal::Ptr KolabObjectReader::getJournal() const
 {
-    return qSharedPointerDynamicCast<KCalCore::Journal>(mIncidence);
+    return mIncidence.dynamicCast<KCalCore::Journal>();
+}
+
+KCalCore::Incidence::Ptr KolabObjectReader::getIncidence() const
+{
+    return mIncidence;
 }
 
 
 
-KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v)
+KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v, const QString &tz)
 {
-    const Kolab::Event &incidence = Kolab::Conversion::fromKCalCore(*i);
-    const std::string &v3String = Kolab::writeEvent(incidence);
-    KMime::Message::Ptr message = Mime::createMessage(i, xCalMimeType(), eventKolabType(), QString::fromStdString(v3String).toLocal8Bit());
-    return message;
+    if (v == KolabV3) {
+        normalizeIncidence(i);
+        const Kolab::Event &incidence = Kolab::Conversion::fromKCalCore(*i);
+        const std::string &v3String = Kolab::writeEvent(incidence);
+        return Mime::createMessage(i, xCalMimeType(), eventKolabType(), QString::fromStdString(v3String).toLocal8Bit());
+    }
+    const QString &xml = KolabV2::Event::eventToXML(i, tz);
+    return Mime::createMessage(i, xCalMimeType(), eventKolabType(), xml.toLocal8Bit());
 }
 
-KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v)
+KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v, const QString &tz)
 {
-    const Kolab::Todo &incidence = Kolab::Conversion::fromKCalCore(*i);
-    const std::string &v3String = Kolab::writeTodo(incidence);
-    KMime::Message::Ptr message = Mime::createMessage(i, xCalMimeType(), todoKolabType(), QString::fromStdString(v3String).toLocal8Bit());
-    return message;
+    if (v == KolabV3) {
+        normalizeIncidence(i);
+        const Kolab::Todo &incidence = Kolab::Conversion::fromKCalCore(*i);
+        const std::string &v3String = Kolab::writeTodo(incidence);
+        return Mime::createMessage(i, xCalMimeType(), todoKolabType(), QString::fromStdString(v3String).toLocal8Bit());
+    }
+    const QString &xml = KolabV2::Task::taskToXML(i, tz);
+    return Mime::createMessage(i, xCalMimeType(), todoKolabType(), xml.toLocal8Bit());
 }
 
-KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v)
+KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v, const QString &tz)
 {
-    const Kolab::Journal &incidence = Kolab::Conversion::fromKCalCore(*i);
-    const std::string &v3String = Kolab::writeJournal(incidence);
-    KMime::Message::Ptr message = Mime::createMessage(i, xCalMimeType(), journalKolabType(), QString::fromStdString(v3String).toLocal8Bit());
-    return message;
+    if (v == KolabV3) {
+        normalizeIncidence(i);
+        const Kolab::Journal &incidence = Kolab::Conversion::fromKCalCore(*i);
+        const std::string &v3String = Kolab::writeJournal(incidence);
+        return  Mime::createMessage(i, xCalMimeType(), journalKolabType(), QString::fromStdString(v3String).toLocal8Bit());
+    }
+    const QString &xml = KolabV2::Journal::journalToXML(i, tz);
+    return Mime::createMessage(i, xCalMimeType(), journalKolabType(), xml.toLocal8Bit());
 }
 
 
diff --git a/libkolab/kolabformat/kolabobject.h b/libkolab/kolabformat/kolabobject.h
index 7be2326..a6f2dbd 100644
--- a/libkolab/kolabformat/kolabobject.h
+++ b/libkolab/kolabformat/kolabobject.h
@@ -41,8 +41,6 @@ enum ObjectType {
 };
 
 
-
-
 KOLAB_EXPORT KCalCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStringList &attachments);
 
 /**
@@ -54,6 +52,7 @@ KOLAB_EXPORT KCalCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStr
 class KOLAB_EXPORT KolabObjectReader {
 public:
     KolabObjectReader();
+    KolabObjectReader(const KMime::Message::Ptr &msg);
     ObjectType parseMimeMessage(const KMime::Message::Ptr &msg);
     
     ObjectType getType() const;
@@ -62,6 +61,7 @@ public:
     KCalCore::Event::Ptr getEvent() const;
     KCalCore::Todo::Ptr getTodo() const;
     KCalCore::Journal::Ptr getJournal() const;
+    KCalCore::Incidence::Ptr getIncidence() const;
 private:
     KCalCore::Incidence::Ptr mIncidence;
     ObjectType mObjectType;
@@ -70,9 +70,9 @@ private:
 
 class KOLAB_EXPORT KolabObjectWriter {
 public:
-    static KMime::Message::Ptr writeEvent(const KCalCore::Event::Ptr &, Version v = KolabV3);
-    static KMime::Message::Ptr writeTodo(const KCalCore::Todo::Ptr &, Version v = KolabV3);
-    static KMime::Message::Ptr writeJournal(const KCalCore::Journal::Ptr &, Version v = KolabV3);
+    static KMime::Message::Ptr writeEvent(const KCalCore::Event::Ptr &, Version v = KolabV3, const QString &tz = QString());
+    static KMime::Message::Ptr writeTodo(const KCalCore::Todo::Ptr &, Version v = KolabV3, const QString &tz = QString());
+    static KMime::Message::Ptr writeJournal(const KCalCore::Journal::Ptr &, Version v = KolabV3, const QString &tz = QString());
 };
 
 }; //Namespace
diff --git a/libkolab/mime/mimeutils.cpp b/libkolab/mime/mimeutils.cpp
index e9587fd..1e58df6 100644
--- a/libkolab/mime/mimeutils.cpp
+++ b/libkolab/mime/mimeutils.cpp
@@ -63,13 +63,11 @@ KMime::Content* findContentByName(const KMime::Message::Ptr &data, const QString
         }
     }
     return 0;
-    
 }
 
 
-//TODO repalce
-void attachmentsFromKolab(const KMime::Message::Ptr& data, const QDomDocument &xmlDoc,
-                                            const KCalCore::Incidence::Ptr &incidence)
+//TODO replace with getAttachments
+void attachmentsFromKolab(const KMime::Message::Ptr& data, const QDomDocument &xmlDoc, const KCalCore::Incidence::Ptr &incidence)
 {
     QDomNodeList nodes = xmlDoc.elementsByTagName("inline-attachment");
     for (int i = 0; i < nodes.size(); i++ ) {
@@ -77,12 +75,12 @@ void attachmentsFromKolab(const KMime::Message::Ptr& data, const QDomDocument &x
         QByteArray type;
         KMime::Content *content = findContentByName(data, name, type);
         if (!content) // guard against malformed events with non-existent attachments
-    continue;
-    const QByteArray c = content->decodedContent().toBase64();
-    KCalCore::Attachment::Ptr attachment( new KCalCore::Attachment( c, QString::fromLatin1( type ) ) );
-    attachment->setLabel( name );
-    incidence->addAttachment(attachment);
-    kDebug() << "ATTACHEMENT NAME" << name << type;
+            continue;
+        const QByteArray c = content->decodedContent().toBase64();
+        KCalCore::Attachment::Ptr attachment( new KCalCore::Attachment( c, QString::fromLatin1( type ) ) );
+        attachment->setLabel( name );
+        incidence->addAttachment(attachment);
+        kDebug() << "ATTACHEMENT NAME" << name << type;
     }
 }
 
@@ -97,8 +95,6 @@ QByteArray getXmlDocument(const KMime::Message::Ptr &data, const QByteArray &mim
 }
 
 
-
-    
 QByteArray fromCid(const QString &cid)
 {
     if (cid.left(4) != QString::fromLatin1("cid:")) { //Don't set if not a cid, happens when serializing format v2
@@ -187,8 +183,8 @@ void getAttachments(KCalCore::Incidence::Ptr incidence, const QStringList &attac
         QByteArray type;
         KMime::Content *content = findContentByName(mimeData, name, type);
         if (!content) { // guard against malformed events with non-existent attachments
-                    qWarning() << "could not find attachment: "<< name;
-                    continue;
+            qWarning() << "could not find attachment: "<< name;
+            continue;
         }
         const QByteArray c = content->decodedContent().toBase64();
         KCalCore::Attachment::Ptr attachment( new KCalCore::Attachment( c, QString::fromLatin1( type ) ) );
diff --git a/upgradetool/upgradetooltests.cpp b/upgradetool/upgradetooltests.cpp
index a470e76..4782795 100644
--- a/upgradetool/upgradetooltests.cpp
+++ b/upgradetool/upgradetooltests.cpp
@@ -5,10 +5,10 @@
 
 void UpgradeToolTests::testConvertEvent()
 {
-    QFile file( "complex.ics.mime" );
+    QFile file( "../../testfiles/v2/event/complex.ics.mime" );
     file.open( QFile::ReadOnly );
     const QByteArray data = file.readAll();
-    Q_ASSERT( !data.isEmpty() );
+    QVERIFY( !data.isEmpty() );
     kDebug() << Kolab::Upgrade::upgradeMime(data);
 }
 


commit 6fcb88426d7403b3407a562a903f7f6898c0a44a
Merge: 9f1f0a0 8a9fe78
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 17:01:56 2012 +0100

    Merge branch 'master' into dev/libkolab



commit 8a9fe781e4f7ed99fcf72fc731130b6419c3c458
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 17:01:34 2012 +0100

    cleanup

diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index ebcde7c..310d444 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -798,7 +798,6 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
                 const std::string &logo = uriInlineDecoding((*group.logo()).uri(), mimetype);
                 aff.setLogo(logo, mimetype);
             }
-//             aff.setTitles(toTextList<vcard::group_type::title_type>(group.title()));
             aff.setRoles(toTextList<vcard::group_type::role_type>(group.role()));
             std::vector<Related> relateds;
             BOOST_FOREACH(const vcard::group_type::related_type &rel, group.related()) {


commit abc3460cfe18d1153323ad84e52a2101e5b15b43
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 16:58:24 2012 +0100

    Checked and implemented titles.

diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index eeaa3b8..ebcde7c 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -471,6 +471,10 @@ void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &co
         vcard.fburl(vcard::fburl_type(contact.freeBusyUrl()));
     }
     
+    if (!contact.titles().empty()) {
+        vcard.title(fromList<vcard::title_type>(contact.titles()));
+    }
+    
     if (!contact.affiliations().empty()) {
         vcard::group_sequence affiliations;
         BOOST_FOREACH(const Affiliation &a, contact.affiliations()) {
@@ -483,7 +487,6 @@ void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &co
             if (!a.logo().empty()) {
                 group.logo(affiliationPropType::logo_type(uriInlineEncoding(a.logo(), a.logoMimetype())));
             }
-//             group.title(fromList<affiliationPropType::title_type >(a.titles()));
             group.role(fromList<affiliationPropType::role_type>(a.roles()));
             BOOST_FOREACH(const Related &rel, a.relateds()) {
                 group.related().push_back(fromRelated(rel));
@@ -773,6 +776,9 @@ boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::Vc
     if (vcard.fburl()) {
         contact->setFreeBusyUrl((*vcard.fburl()).uri());
     }
+    if (!vcard.title().empty()) {
+        contact->setTitles(toTextList<vcard::title_type >(vcard.title()));
+    }
     if (!vcard.group().empty()) {
         std::vector<Kolab::Affiliation> list;
         BOOST_FOREACH (const vcard::group_type &group, vcard.group()) {
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index 5bd327a..1945615 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -449,6 +449,7 @@ void BindingsTest::contactCompletness()
     QCOMPARE(e.nameComponents(), c.nameComponents());
     QCOMPARE(e.note(), c.note());
     QCOMPARE(e.freeBusyUrl(), c.freeBusyUrl());
+    QCOMPARE(e.titles(), c.titles());
     QCOMPARE(e.affiliations(), c.affiliations());
     QCOMPARE(e.urls(), c.urls());
     QCOMPARE(e.addresses(), c.addresses());


commit f258c78401941bb7bf30720e1bfb72def20d154a
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 16:44:36 2012 +0100

    More checking by the compiler, enable optimization for optimization and error-checking (otherwise not all errors are detected properly).

diff --git a/c++/lib/CMakeLists.txt b/c++/lib/CMakeLists.txt
index 44caba9..d970be3 100644
--- a/c++/lib/CMakeLists.txt
+++ b/c++/lib/CMakeLists.txt
@@ -1,7 +1,7 @@
 
 SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1)
 
-set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC " ) #always generate shared libraries with -fPIC
+set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wp,-D_FORTIFY_SOURCE=2 -O2" ) #always generate shared libraries with -fPIC, -D_FORTIFY_SOURCE=2 enables some extra checking
 
 #Library with serialization/deserialization code and kolab-containers
 add_library(kolabxml SHARED kolabformat.cpp kolabcontainers.cpp kolabnote.cpp kolabevent.cpp kolabtodo.cpp kolabjournal.cpp kolabcontact.cpp utils.cpp base64.cpp ../compiled/XMLParserWrapper.cpp ../compiled/grammar-input-stream.cxx ${SCHEMA_SOURCEFILES})


commit 4d22a0e2c137b1d9ae02cd11f1291fd139c4c1f2
Merge: b94b1ac c2f4ccf
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 16:05:22 2012 +0100

    Merge branch 'master' of ssh://git.kolabsys.com/git/libkolabxml



commit b94b1acd370b007cc49ce2ec7799743360074e9f
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Mar 21 16:05:03 2012 +0100

    Stricter compiling options, and complying to them.

diff --git a/c++/lib/CMakeLists.txt b/c++/lib/CMakeLists.txt
index ac961a8..44caba9 100644
--- a/c++/lib/CMakeLists.txt
+++ b/c++/lib/CMakeLists.txt
@@ -9,7 +9,7 @@ add_library(kolabxml SHARED kolabformat.cpp kolabcontainers.cpp kolabnote.cpp ko
 target_link_libraries(kolabxml ${XERCES_C} ${Boost_LIBRARIES})
 
 #For the core library we can be stricter when compiling. This doesn't work with the auto generated code though.
-set_target_properties(kolabxml PROPERTIES COMPILE_FLAGS "-Wl,--no-undefined -Werror ")
+set_target_properties(kolabxml PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wl,--no-undefined")
 set_target_properties(kolabxml PROPERTIES VERSION 3.0.0 SOVERSION 0)
 install(TARGETS kolabxml LIBRARY DESTINATION lib)
 
diff --git a/c++/lib/kolabformat.cpp b/c++/lib/kolabformat.cpp
index d7ac396..98a42a2 100644
--- a/c++/lib/kolabformat.cpp
+++ b/c++/lib/kolabformat.cpp
@@ -142,7 +142,7 @@ std::string writeNote(const Note &note)
     return Kolab::KolabObjects::serializeObject<Kolab::Note>(note);
 }
 
-Configuration readConfiguration(const std::string& s, bool isUrl)
+Configuration readConfiguration(const std::string& /*s*/, bool /*isUrl*/)
 {
 //     boost::shared_ptr <Kolab::Configuration> ptr = deserializeConfiguration(s, isUrl);
 //     if (!ptr.get()) {
@@ -152,7 +152,7 @@ Configuration readConfiguration(const std::string& s, bool isUrl)
     return Configuration();
 }
 
-std::string writeConfiguration(const Configuration &config)
+std::string writeConfiguration(const Configuration &/*config*/)
 {
 //     return serializeConfiguration(config);
 return std::string();
diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index 226e07d..eeaa3b8 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -302,7 +302,7 @@ vcard_4_0::relatedPropType fromRelated(const Kolab::Related &r)
 
 Kolab::Related toRelated(const vcard_4_0::relatedPropType &r)
 {
-    Kolab::Related::DescriptionType type;
+    Kolab::Related::DescriptionType type = Kolab::Related::Invalid;
     std::string textOrUri;
     if (r.uri()) {
         type = Kolab::Related::Uid;
@@ -312,6 +312,7 @@ Kolab::Related toRelated(const vcard_4_0::relatedPropType &r)
         textOrUri = *r.text();
     } else {
         ERROR("no text and no uri");
+        return Kolab::Related();
     }
     Kolab::Related related(type, textOrUri);
     if (r.parameters()) {


commit c2f4ccf74d699fc562518e3c27c47d6c9fd9d9da
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Mar 21 15:13:09 2012 +0100

    Add (yet failing) test for Contact::setTitles()

diff --git a/c++/lib/php/test.php b/c++/lib/php/test.php
old mode 100644
new mode 100755
index be1ef59..48c3304
--- a/c++/lib/php/test.php
+++ b/c++/lib/php/test.php
@@ -17,8 +17,9 @@ function assertequal($got, $expect, $name) {
 
 function assertcontains($haystack, $needle, $name) {
 	// remove whitespace
-	$haystack = preg_replace('/\s/ims', '', $haystack);
-	$needle = preg_replace('/\s/ims', '', $needle);
+	$haystack = preg_replace('/\n\s*/ims', '', $haystack);
+	$needle = preg_replace('/\n\s*/ims', '', $needle);
+
 	return assertequal(substr(strstr($haystack, $needle), 0, strlen($needle)), $needle, $name);
 }
 
@@ -97,6 +98,7 @@ assertcontains($nc->prefixes()->size(),    1, "NameComponents::setPrefixes()");
 assertcontains($nc->suffixes()->size(),    0, "NameComponents::suffixes()");
 
 $c->setNameComponents($nc);
+$c->setTitles(array2vector("MyProfession"));
 
 $pic = "R0lGODlhEgASAIAAAMDAwAAAACH5BAEAAAAALAAAAAASABIAQAIPhI+py+0Po5y02ouz3pwXADs=";
 $c->setPhoto(base64_decode($pic), 'image/gif');
@@ -113,6 +115,7 @@ $xml = kolabformat::writeContact($c);
 #print $xml;
 assertcontains($xml, "<uid><uri>urn:uuid:", "Generate Contact UID as urn::uuid");
 assertcontains($xml, "<n><surname>Surname</surname><given>Given</given><additional>Middle1</additional><additional>Middle2</additional><prefix>Prefix</prefix></n>", "Contact::setNameComponents()");
+assertcontains($xml, "<title><text>MyProfession</text></title>", "Contact::setTitles()");
 assertcontains($xml, "<photo><uri>data:image/gif;base64,$pic</uri></photo>", "Contact::setPhoto()");
 assertcontains($xml, "<bday><date>19800801</date></bday>", "Contact::setBDay()");
 assertcontains($xml, "<geo><uri>geo:46.952585,7.43766</uri></geo>", "Contact::setGPSpos()");


commit c0ae520b20452a4ab17212c4115c39a1351f9d53
Author: Thomas B <roundcube at gmail.com>
Date:   Wed Mar 21 08:52:01 2012 +0100

    Adapt php binding tests to recent changes in the library implementation

diff --git a/c++/lib/php/test.php b/c++/lib/php/test.php
index 916bc5a..be1ef59 100644
--- a/c++/lib/php/test.php
+++ b/c++/lib/php/test.php
@@ -132,27 +132,26 @@ assertfalse(strpos($xml, '<bday><date>'), "Unset BDay with empty cDateTime");
 $dl = new DistList;
 $dl->setName("DalistÄÖŸ");
 
-$m = new vectormember;
-$a = new Member;
-$a->setName("Member-A");
-$a->setEmail("a at localhost");
-$a->setUid("x-mem-a");
+$m = new vectorcontactref;
+$a = new ContactReference(ContactReference::EmailReference, "a at localhost", "Member-A");
 $m->push($a);
 
-$b = new Member;
+$b = new ContactReference(ContactReference::UidReference, "x-member-b-fff");
 $b->setName("Member-B");
-$b->setEmail("b at localhost");
-$b->setUid("x-mem-b");
 $m->push($b);
 
-assertequal($m->size(), 2, "vectormember::size()");
+#$c = new ContactReference(ContactReference::EmailAndUidReference, "c at localhost", "dddaab06-0000-0000-eeb5-cc64ff7f0000");
+#$c->setName("Member-C");
+#$m->push($c);
+
+assertequal($m->size(), 2, "vectorcontactref::size()");
 $dl->setMembers($m);
 
 $xml = kolabformat::writeDistlist($dl);
 #print $xml;
 assertcontains($xml, '<fn><text>DalistÄÖŸ</text></fn>', "kolabformat::writeDistlist(): FN (UTF-8)");
-assertcontains($xml, '<uri>mailto:Member%2DB%3Cb%40localhost%3E</uri>', "kolabformat::writeDistlist(): mailto uri");
-assertcontains($xml, '<member><parameters><x-uid><uri>x-mem-b</uri></x-uid></parameters>', "kolabformat::writeDistlist(): member x-uid");
+assertcontains($xml, '<uri>mailto:Member%2DA%3Ca%40localhost%3E</uri>', "kolabformat::writeDistlist(): mailto uri");
+assertcontains($xml, '<member><uri>urn:uuid:x-member-b-fff</uri>', "kolabformat::writeDistlist(): member urn::uuid");
 
 ?>
 





More information about the commits mailing list