Branch 'libkolab-0.4' - 3 commits - CMakeLists.txt conversion/kabcconversion.cpp conversion/kcalconversion.cpp tests/kcalconversiontest.cpp

Christian Mollekopf mollekopf at kolabsys.com
Mon Apr 15 17:04:15 CEST 2013


 CMakeLists.txt                |    4 +-
 conversion/kabcconversion.cpp |   57 ++++++++++++++++++++++++++++++++++--------
 conversion/kcalconversion.cpp |   10 ++++++-
 tests/kcalconversiontest.cpp  |   12 +++++++-
 4 files changed, 68 insertions(+), 15 deletions(-)

New commits:
commit 460ca4d68f00b5306fcca3d51fd9a3171a064f00
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Mon Apr 15 16:59:31 2013 +0200

    Preserve email types.
    
    Requires libkolabxml 0.8.5

diff --git a/conversion/kabcconversion.cpp b/conversion/kabcconversion.cpp
index 0278643..851b45a 100644
--- a/conversion/kabcconversion.cpp
+++ b/conversion/kabcconversion.cpp
@@ -433,11 +433,25 @@ KABC::Addressee toKABC(const Kolab::Contact &contact)
   QString preferredEmail;
   
   if (!contact.emailAddresses().empty()) {
-      addressee.setEmails(toStringList(contact.emailAddresses()));
+      QStringList emails;
+      foreach (const Email &mail, contact.emailAddressesWithType()) {
+          emails << fromStdString(mail.address());
+          if (mail.types() != Email::NoType) {
+              QStringList types;
+              if (mail.types() & Email::Home) {
+                  types.append(QLatin1String("home"));
+              }
+              if (mail.types() & Email::Work) {
+                  types.append(QLatin1String("work"));
+              }
+              addressee.insertCustom(QLatin1String("KOLAB"), QString("EmailTypes%1").arg(fromStdString(mail.address())), types.join(","));
+          }
+      }
+      addressee.setEmails(emails);
       if ((contact.emailAddressPreferredIndex() >= 0) && (contact.emailAddressPreferredIndex() < static_cast<int>(contact.emailAddresses().size()))) {
-          preferredEmail = fromStdString(contact.emailAddresses().at(contact.emailAddressPreferredIndex()));
+          preferredEmail = fromStdString(contact.emailAddressesWithType().at(contact.emailAddressPreferredIndex()).address());
       } else {
-          preferredEmail = fromStdString(contact.emailAddresses().at(0));
+          preferredEmail = fromStdString(contact.emailAddressesWithType().at(0).address());
       }
       addressee.insertEmail(preferredEmail, true);
   }
@@ -709,14 +723,26 @@ Kolab::Contact fromKABC(const KABC::Addressee &addressee)
         c.setIMaddresses(std::vector<std::string>() << toStdString(imAddress), 0);
     }
     
-    int prefEmail = -1;
+    int counter = -1;
+    int prefEmail = 0;
+    std::vector<Email> emails;
     foreach(const QString &e, addressee.emails()) {
-        prefEmail++;
+        counter++;
         if (e == addressee.preferredEmail()) {
-            break;
+            prefEmail = counter;
         }
+        const QStringList types = addressee.custom(QLatin1String("KOLAB"), QString("EmailTypes%1").arg(e)).split(',', QString::SkipEmptyParts);
+        int t = Email::NoType;
+        if (types.contains("work")) {
+           t |= Email::Work;
+        }
+        if (types.contains("home")) {
+           t |= Email::Home;
+        }
+        emails << Email(toStdString(e), t);
     }
-    c.setEmailAddresses(fromStringList(addressee.emails()), prefEmail);
+    c.setEmailAddressesWithType(emails, prefEmail);
+    
     if (addressee.geo().isValid()) {
         c.setGPSpos(std::vector<Kolab::Geo>() << Kolab::Geo(addressee.geo().latitude(), addressee.geo().longitude()));
     }


commit 717bdf28ec2c128e8145207564818894b9b7b975
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Apr 10 01:38:24 2013 +0200

    Deal with corrupted images better.
    
    * Try to set the mimetype if available, otherwise fallback to autodetection.
    * Don't set an error if we fail to load the image.
    
    By degrading image problems to a warning, we still get the contact displayed in Kontact even if we fail to load the image.
    
    The proper fix would be to classify the error and let the application decide what to do.
    (cherry picked from commit a268479ab1fba7dba13117a54dde692f61d7010a)

diff --git a/conversion/kabcconversion.cpp b/conversion/kabcconversion.cpp
index 1be0df8..0278643 100644
--- a/conversion/kabcconversion.cpp
+++ b/conversion/kabcconversion.cpp
@@ -21,6 +21,7 @@
 #include <kcalcore/freebusyurlstore.h>
 #include <kdebug.h>
 #include <qbuffer.h>
+#include <qimagereader.h>
 #include "kolabformat/errorhandler.h"
 
 
@@ -357,13 +358,23 @@ std::string fromPicture(const KABC::Picture &pic, std::string &mimetype)
 
 KABC::Picture toPicture(const std::string &data, const std::string &mimetype) {
     QImage img;
-    if (!img.loadFromData( QByteArray::fromRawData(data.data(), data.size()) )) {
-        Error() << "failed to load picture";
+    bool ret = false;
+    QByteArray type(mimetype.data(), mimetype.size());
+    type = type.split('/').last(); // extract "jpeg" from "image/jpeg"
+    if (QImageReader::supportedImageFormats().contains(type)) {
+        ret = img.loadFromData(QByteArray::fromRawData(data.data(), data.size()), type.constData());
+    } else {
+        ret = img.loadFromData(QByteArray::fromRawData(data.data(), data.size()));
+    }
+    if (!ret) {
+        Warning() << "failed to load picture";
+        return KABC::Picture();
     }
     
     KABC::Picture logo(img);
     if (logo.isEmpty()) {
-        Error() << "failed to read picture";
+        Warning() << "failed to read picture";
+        return KABC::Picture();
     }
     logo.setType(fromStdString(mimetype));
     return logo;


commit 414f10f02aadb0be0735f2dc646cbfd031ed083d
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Mon Apr 15 14:51:46 2013 +0200

    Preserve the url. Requires libkolabxml 0.9
    (cherry picked from commit 851e8c74e1aedb87bfd4810aa60078e616f2add9)
    
    Conflicts:
    	CMakeLists.txt
    
    Adjusted to require libkolabxml 0.8.5

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 944d346..fb22747 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,8 +47,8 @@ set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolab )
 include(MacroLogFeature)
 
 # Do the building
-find_package(Libkolabxml 0.7 REQUIRED)
-macro_log_feature(Libkolabxml_FOUND "Libkolabxml" "Kolab XML Format 3 serializing library" "http://git.kolab.org/libkolabxml/" TRUE "0.7" "Required for reading/writing Kolab XML Objects")
+find_package(Libkolabxml 0.8 REQUIRED)
+macro_log_feature(Libkolabxml_FOUND "Libkolabxml" "Kolab XML Format 3 serializing library" "http://git.kolab.org/libkolabxml/" TRUE "0.8.5" "Required for reading/writing Kolab XML Objects")
 
 find_package(Qt4 4.6.0 REQUIRED)
 
diff --git a/conversion/kcalconversion.cpp b/conversion/kcalconversion.cpp
index 1ba81f3..a82b6a2 100644
--- a/conversion/kcalconversion.cpp
+++ b/conversion/kcalconversion.cpp
@@ -33,6 +33,7 @@ namespace Kolab {
 //The uid of a contact which refers to the uuid of a contact in the addressbook
 #define CUSTOM_KOLAB_CONTACT_UUID "X_KOLAB_CONTACT_UUID"
 #define CUSTOM_KOLAB_CONTACT_CUTYPE "X_KOLAB_CONTACT_CUTYPE"
+#define CUSTOM_KOLAB_URL "X-KOLAB-URL"
 
 KCalCore::Duration toDuration(const Kolab::Duration &d)
 {
@@ -391,7 +392,10 @@ void getIncidence(T &i, const I &e)
     std::vector<Kolab::CustomProperty> customProperties;
     const QMap<QByteArray, QString> &props = e.customProperties();
     for (QMap<QByteArray, QString>::const_iterator it = props.begin(); it != props.end(); it++) {
-        QString key = QString(it.key());
+        QString key(it.key());
+        if (key == QLatin1String(CUSTOM_KOLAB_URL)) {
+            continue;
+        }
         customProperties.push_back(Kolab::CustomProperty(toStdString(key.remove("X-KOLAB-")), toStdString(it.value())));
     }
     i.setCustomProperties(customProperties);
@@ -653,6 +657,9 @@ void setTodoEvent(KCalCore::Incidence &i, const T &e)
     if (e.organizer().isValid()) {
         i.setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person(fromStdString(e.organizer().name()), fromStdString(e.organizer().email())))); //TODO handle uid too
     }
+    if (!e.url().empty()) {
+        i.setNonKDECustomProperty(CUSTOM_KOLAB_URL, fromStdString(e.url()));
+    }
     if (e.recurrenceID().isValid()) {
         i.setRecurrenceId(toDate(e.recurrenceID())); //TODO THISANDFUTURE
     }
@@ -704,6 +711,7 @@ void getTodoEvent(T &i, const I &e)
     if (e.organizer() && !e.organizer()->email().isEmpty()) {
         i.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference, toStdString(e.organizer()->email()), toStdString(e.organizer()->name()))); //TODO handle uid too
     }
+    i.setUrl(toStdString(e.nonKDECustomProperty(CUSTOM_KOLAB_URL)));
     i.setRecurrenceID(fromDate(e.recurrenceId()), false); //TODO THISANDFUTURE
     getRecurrence(i, e);
     std::vector <Kolab::Alarm> alarms;
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 23698dd..477af3b 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -183,6 +183,8 @@ void KCalConversionTest::testConversion_data()
         kcal.setStatus(KCalCore::Incidence::StatusConfirmed);
         kcal.setLocation("location");
         kcal.setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person("organizer", "organizer at email")));
+        //Url
+        kcal.setNonKDECustomProperty("X-KOLAB-URL", "http://test.org");
         KCalCore::Attendee::Ptr att(new KCalCore::Attendee("attendee", "attendee at email", false, KCalCore::Attendee::NeedsAction, KCalCore::Attendee::ReqParticipant));
         att->setDelegate("mailto:delegatee<delegatee at email>");
         att->setDelegator("mailto:delegator<delegator at email>");
@@ -235,6 +237,7 @@ void KCalConversionTest::testConversion_data()
         kolab.setStatus(Kolab::StatusConfirmed);
         kolab.setLocation("location");
         kolab.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference,"organizer at email", "organizer")); //TODO uid
+        kolab.setUrl("http://test.org");
         
         Kolab::Attendee a(Kolab::ContactReference(Kolab::ContactReference::EmailReference,"attendee at email", "attendee"));//TODO uid
         a.setDelegatedTo(std::vector<Kolab::ContactReference>() << Kolab::ContactReference(Kolab::ContactReference::EmailReference,"delegatee at email", "delegatee"));
@@ -339,7 +342,8 @@ void KCalConversionTest::testConversion()
     QFETCH(KCalCore::Event, kcal);
     QFETCH(Kolab::Event, kolab);
     
-    const KCalCore::Event::Ptr e = toKCalCore(kolab);
+    KCalCore::Event::Ptr e = toKCalCore(kolab);
+    const Kolab::Event &b = fromKCalCore(kcal);
     
     QCOMPARE(e->uid(), kcal.uid());
     QCOMPARE(e->created(), kcal.created());
@@ -361,6 +365,10 @@ void KCalConversionTest::testConversion()
     QCOMPARE(e->location(), kcal.location());
     QCOMPARE(e->organizer()->name(), kcal.organizer()->name());
     QCOMPARE(e->organizer()->email(), kcal.organizer()->email());
+    QCOMPARE(e->nonKDECustomProperty("X-KOLAB-URL"), kcal.nonKDECustomProperty("X-KOLAB-URL"));
+    //otherwise we'd break the customProperties comparison
+    e->removeNonKDECustomProperty("X-KOLAB-URL");
+    kcal.removeNonKDECustomProperty("X-KOLAB-URL");
     compareAttendeesVectors(e->attendees(), kcal.attendees());
     comparePointerVectors(e->attachments(), kcal.attachments());
     
@@ -371,7 +379,6 @@ void KCalConversionTest::testConversion()
 //         toKCalCore(kolab);
 //     }
     
-    const Kolab::Event &b = fromKCalCore(kcal);
     QCOMPARE(b.uid(), kolab.uid());
     QCOMPARE(b.created(), kolab.created());
     QCOMPARE(b.lastModified(), kolab.lastModified());
@@ -393,6 +400,7 @@ void KCalConversionTest::testConversion()
     QCOMPARE(b.status(), kolab.status());
     QCOMPARE(b.location(), kolab.location());
     QCOMPARE(b.organizer(), kolab.organizer());
+    QCOMPARE(b.url(), kolab.url());
     QCOMPARE(b.attendees(), kolab.attendees());
     QCOMPARE(b.attachments(), kolab.attachments());
     QCOMPARE(b.customProperties(), kolab.customProperties());





More information about the commits mailing list