2 commits - CMakeLists.txt kolabformat/kolabdefinitions.h kolabformat/kolabobject.h kolabformat/kolabobject.i kolabformat/php kolabformat/v2helpers.cpp kolabformat/v2helpers.h kolabformat/xmlobject.cpp kolabformat/xmlobject.h
Christian Mollekopf
mollekopf at kolabsys.com
Wed Oct 31 16:30:35 CET 2012
CMakeLists.txt | 3
kolabformat/kolabdefinitions.h | 17 ++
kolabformat/kolabobject.h | 18 ---
kolabformat/kolabobject.i | 16 ++
kolabformat/php/CMakeLists.txt | 4
kolabformat/php/test.php | 16 ++
kolabformat/v2helpers.cpp | 236 +++++++++++++++++++++++++++++++++++++++++
kolabformat/v2helpers.h | 200 +---------------------------------
kolabformat/xmlobject.cpp | 66 +++++++++++
kolabformat/xmlobject.h | 72 ++++++++++++
10 files changed, 443 insertions(+), 205 deletions(-)
New commits:
commit f561543e9a8f5db3bab275f52e27d991c411ff81
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Oct 31 16:28:01 2012 +0100
XMLObject interface for events, including php bindings
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ee5f4c..5a459d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -119,6 +119,7 @@ QT4_WRAP_CPP(CALENDARING_MOC calendaring/event.h)
set(KOLAB_SRCS
kolabformat/kolabobject.cpp
+ kolabformat/xmlobject.cpp
kolabformat/formathelpers.cpp
kolabformat/errorhandler.cpp
kolabformat/v2helpers.cpp
@@ -189,4 +190,5 @@ endif(PYTHON_BINDINGS)
if(PHP_BINDINGS)
generatePHPBindings(kolabshared shared.i)
+ add_subdirectory(kolabformat/php)
endif(PHP_BINDINGS)
diff --git a/kolabformat/kolabdefinitions.h b/kolabformat/kolabdefinitions.h
index 9a14306..0fc8307 100644
--- a/kolabformat/kolabdefinitions.h
+++ b/kolabformat/kolabdefinitions.h
@@ -61,6 +61,23 @@ namespace Kolab {
#define KOLAB_TYPE_DICT "application/x-vnd.kolab.configuration.dictionary"
#define KOLAB_TYPE_FREEBUSY "application/x-vnd.kolab.freebusy"
+enum Version {
+ KolabV2,
+ KolabV3
+};
+
+enum ObjectType {
+ InvalidObject,
+ EventObject,
+ TodoObject,
+ JournalObject,
+ ContactObject,
+ DistlistObject,
+ NoteObject,
+ DictionaryConfigurationObject,
+ FreebusyObject
+};
+
}
#endif
diff --git a/kolabformat/kolabobject.h b/kolabformat/kolabobject.h
index a17b235..23836e6 100644
--- a/kolabformat/kolabobject.h
+++ b/kolabformat/kolabobject.h
@@ -28,26 +28,12 @@
#include <kcalcore/todo.h>
#include <kmime/kmime_message.h>
+#include "kolabdefinitions.h"
+
namespace Kolab {
class Freebusy;
-enum Version {
- KolabV2,
- KolabV3
-};
-
-enum ObjectType {
- InvalidObject,
- EventObject,
- TodoObject,
- JournalObject,
- ContactObject,
- DistlistObject,
- NoteObject,
- DictionaryConfigurationObject,
- FreebusyObject
-};
KOLAB_EXPORT KCalCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStringList &attachments);
diff --git a/kolabformat/kolabobject.i b/kolabformat/kolabobject.i
new file mode 100644
index 0000000..73c19be
--- /dev/null
+++ b/kolabformat/kolabobject.i
@@ -0,0 +1,16 @@
+%{
+ /* This macro ensures that return vectors remain a vector also in python and are not converted to tuples */
+ #define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
+
+ #include "../kolabformat/xmlobject.h"
+ #include "../kolabformat/kolabdefinitions.h"
+%}
+
+%include "std_string.i"
+%include "std_vector.i"
+
+%import(module="kolabformat") <kolabevent.h>
+%import "../shared.i"
+
+%include "../kolabformat/xmlobject.h"
+%include "../kolabformat/kolabdefinitions.h"
diff --git a/kolabformat/php/CMakeLists.txt b/kolabformat/php/CMakeLists.txt
new file mode 100644
index 0000000..2d18e19
--- /dev/null
+++ b/kolabformat/php/CMakeLists.txt
@@ -0,0 +1,4 @@
+#Generate PHP wrapper
+include_directories(../)
+include(SWIGUtils)
+generatePHPBindings(kolabobject ../kolabobject.i)
diff --git a/kolabformat/php/test.php b/kolabformat/php/test.php
new file mode 100644
index 0000000..5c669c5
--- /dev/null
+++ b/kolabformat/php/test.php
@@ -0,0 +1,16 @@
+<?php
+//run using:
+// php -d enable_dl=On -dextension=/usr/local/lib/php/modules/kolabshared.so -dextension=/usr/local/lib/php/modules/kolabformat.so -dextension=/usr/local/lib/php/modules/kolabobject.so test.php
+
+include("/usr/local/lib/php/modules/kolabformat.php");
+include("/usr/local/lib/php/modules/kolabobject.php");
+
+/////// Test Event
+$e = new Event();
+$e->setCreated(new cDateTime(2012,3,14, 9,5,30, true));
+$e->setStart(new cDateTime(2012,7,31));
+$e->setUid("uid");
+print XMLObject::writeEvent($e, kolabobject::KolabV2, "roundcube");
+print XMLObject::writeEvent($e, kolabobject::KolabV3, "roundcube");
+
+?>
diff --git a/kolabformat/xmlobject.cpp b/kolabformat/xmlobject.cpp
new file mode 100644
index 0000000..9e60a75
--- /dev/null
+++ b/kolabformat/xmlobject.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2012 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "xmlobject.h"
+#include "v2helpers.h"
+#include "kolabformatV2/event.h"
+#include <conversion/kcalconversion.h>
+#include <kolabformat.h>
+
+namespace Kolab {
+
+XMLObject::XMLObject()
+{
+
+}
+
+std::vector< std::string > XMLObject::getAttachments() const
+{
+ return mAttachments;
+}
+
+
+std::string XMLObject::writeEvent(const Event &event, Version version, const std::string& productId)
+{
+ if (version == KolabV2) {
+ KCalCore::Event::Ptr i = Conversion::toKCalCore(event);
+ //The timezone is used for created and last modified dates
+ const QString &xml = KolabV2::Event::eventToXML(i, QLatin1String("UTC"));
+ return xml.toStdString();
+ }
+ return Kolab::writeEvent(event, productId);
+}
+
+Event XMLObject::readEvent(const std::string& s, Version version)
+{
+ if (version == KolabV2) {
+ QStringList attachments;
+ KCalCore::Event::Ptr event = Kolab::fromXML<KCalCore::Event::Ptr, KolabV2::Event>(QString::fromUtf8(s.c_str()).toUtf8(), attachments);
+ mAttachments.clear();
+ foreach (const QString &attachment, attachments) {
+ mAttachments.push_back(std::string(attachment.toUtf8().constData()));
+ }
+ return Conversion::fromKCalCore(*event);
+ }
+ return Kolab::readEvent(s, false);
+}
+
+
+
+
+
+};
\ No newline at end of file
diff --git a/kolabformat/xmlobject.h b/kolabformat/xmlobject.h
new file mode 100644
index 0000000..0e06f3f
--- /dev/null
+++ b/kolabformat/xmlobject.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KOLABXMLOBJECT_H
+#define KOLABXMLOBJECT_H
+
+#ifndef SWIG
+#include "kolab_export.h"
+#else
+/* No export/import SWIG interface files */
+#define KOLAB_EXPORT
+#endif
+
+#include <kolabxml/kolabformat.h>
+
+#include "kolabdefinitions.h"
+
+namespace Kolab {
+
+class KOLAB_EXPORT XMLObject
+{
+public:
+ explicit XMLObject();
+ ///List of attachment names to be retrieved from the mime message (only when reading v2, for v3 attachments containing the cid: of the attachment are created )
+ std::vector<std::string> getAttachments() const;
+
+ Kolab::Event readEvent(const std::string& s, Kolab::Version version);
+ static std::string writeEvent(const Kolab::Event &, Kolab::Version version, const std::string& productId = std::string());
+/*
+ Kolab::Todo readTodo(const std::string& s, Version version);
+ static std::string writeTodo(const Kolab::Todo &, Version version, const std::string& productId = std::string());
+
+ Kolab::Journal readJournal(const std::string& s, Version version);
+ static std::string writeJournal(const Kolab::Journal &, Version version, const std::string& productId = std::string());
+
+ Kolab::Freebusy readFreebusy(const std::string& s, Version version);
+ static std::string writeFreebusy(const Kolab::Freebusy &, Version version, const std::string& productId = std::string());
+
+ Kolab::Contact readContact(const std::string& s, Version version);
+ static std::string writeContact(const Kolab::Contact &, Version version, const std::string& productId = std::string());
+
+ Kolab::DistList readDistlist(const std::string& s, Version version);
+ static std::string writeDistlist(const Kolab::DistList &, Version version, const std::string& productId = std::string());
+
+ Kolab::Note readNote(const std::string& s, Version version);
+ static std::string writeNote(const Kolab::Note &, Version version, const std::string& productId = std::string());
+
+ Kolab::Configuration readConfiguration(const std::string& s, Version version);
+ static std::string writeConfiguration(const Kolab::Configuration &, Version version, const std::string& productId = std::string());
+
+ Kolab::File readFile(const std::string& s, Version version);
+ static std::string writeFile(const Kolab::File &, Version version, const std::string& productId = std::string()); */
+private:
+ std::vector<std::string> mAttachments;
+};
+
+}
+#endif // KOLABXMLOBJECT_H
commit 95d71a2058695f85dc9d50d5cdeb75330b1bc3c5
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Oct 31 15:37:25 2012 +0100
Moved v2helpers implementation to it's own cpp file so it's reusable.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3c303f0..7ee5f4c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,6 +121,7 @@ set(KOLAB_SRCS
kolabformat/kolabobject.cpp
kolabformat/formathelpers.cpp
kolabformat/errorhandler.cpp
+ kolabformat/v2helpers.cpp
mime/mimeutils.cpp
${CONVERSION_SRCS}
${kolabformatv2_SRCS}
diff --git a/kolabformat/v2helpers.cpp b/kolabformat/v2helpers.cpp
new file mode 100644
index 0000000..2d88359
--- /dev/null
+++ b/kolabformat/v2helpers.cpp
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2012 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/>.
+ */
+
+#include "v2helpers.h"
+
+#include "kolabdefinitions.h"
+
+#include "kolabformatV2/kolabbase.h"
+#include "kolabformatV2/journal.h"
+#include "kolabformatV2/task.h"
+#include "kolabformatV2/event.h"
+#include "kolabformatV2/contact.h"
+#include "kolabformatV2/distributionlist.h"
+#include "kolabformatV2/note.h"
+#include "mime/mimeutils.h"
+#include "kolabformat/errorhandler.h"
+
+#include <kabc/contactgroup.h>
+
+#include <qdom.h>
+#include <kdebug.h>
+#include <qbuffer.h>
+#include <akonadi/notes/noteutils.h>
+
+namespace Kolab {
+
+QImage getPicture(const QString &pictureAttachmentName, const KMime::Message::Ptr &data, QByteArray &type)
+{
+ KMime::Content *imgContent = Mime::findContentByName(data, pictureAttachmentName/*"kolab-picture.png"*/, type);
+ if (!imgContent) {
+ Warning() << "could not find picture: " << pictureAttachmentName;
+ return QImage();
+ }
+ QByteArray imgData = imgContent->decodedContent();
+ QBuffer buffer(&imgData);
+ buffer.open(QIODevice::ReadOnly);
+ QImage image;
+ bool success = false;
+ if (type == "image/jpeg") {
+ success = image.load(&buffer, "JPEG");
+ //FIXME I tried getting the code to interpret the picture as PNG, but the VCard implementation writes it as JPEG anyways...
+// if (success) {
+// QByteArray pic;
+// QBuffer b(&pic);
+// b.open(QIODevice::ReadWrite);
+// Q_ASSERT(image.save(&b, "PNG"));
+// b.close();
+// Debug() << pic.toBase64();
+// QBuffer b2(&pic);
+// b2.open(QIODevice::ReadOnly);
+// success = image.load(&b2, "PNG");
+// b2.close();
+// Q_ASSERT(success);
+// }
+ } else {
+ type = "image/png";
+ success = image.load(&buffer, "PNG");
+ }
+ buffer.close();
+ if (!success) {
+ Warning() << "failed to load picture";
+ }
+ return image;
+}
+
+KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data)
+{
+ KABC::Addressee addressee;
+// Debug() << "xmlData " << xmlData;
+ KolabV2::Contact contact(QString::fromUtf8(xmlData));
+ QByteArray type;
+ const QString &pictureAttachmentName = contact.pictureAttachmentName();
+ if (!pictureAttachmentName.isEmpty()) {
+ const QImage &img = getPicture(pictureAttachmentName, data, type);
+ contact.setPicture(img, type);
+ }
+
+ const QString &logoAttachmentName = contact.logoAttachmentName();
+ if (!logoAttachmentName.isEmpty()) {
+ contact.setLogo(getPicture(logoAttachmentName, data, type), type);
+ }
+
+ const QString &soundAttachmentName = contact.soundAttachmentName();
+ if (!soundAttachmentName.isEmpty()) {
+ QByteArray type;
+ KMime::Content *content = Mime::findContentByName(data, soundAttachmentName/*"sound"*/, type);
+ if (content) {
+ const QByteArray &sData = content->decodedContent();
+ contact.setSound(sData);
+ } else {
+ Warning() << "could not find sound: " << soundAttachmentName;
+ }
+ }
+ contact.saveTo(&addressee);
+ return addressee;
+}
+
+QByteArray createPicture(const QImage &img, const QString &format, QString &type)
+{
+ QByteArray pic;
+ QBuffer buffer(&pic);
+ buffer.open(QIODevice::WriteOnly);
+ type = "image/png";
+ //FIXME it's not possible to save jpegs lossless, so we always use png. otherwise we would compress the image on every write.
+// if (format == "image/jpeg") {
+// type = "image/jpeg";
+// img.save(&buffer, "JPEG");
+// } else {
+ img.save(&buffer, "PNG");
+// }
+ buffer.close();
+ return pic;
+}
+
+KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId)
+{
+ KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_CONTACT, false, productId );
+ message->subject()->fromUnicodeString( contact.uid(), "utf-8" );
+ message->from()->fromUnicodeString( contact.fullEmail(), "utf-8" );
+
+ KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_CONTACT, contact.saveXML().toUtf8() );
+ message->addContent( content );
+
+ if ( !contact.picture().isNull() ) {
+ QString type;
+ const QByteArray &pic = createPicture(contact.picture(), contact.pictureFormat(), type);
+ content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-picture.png"*/contact.pictureAttachmentName(), pic );
+ message->addContent(content);
+ }
+
+ if ( !contact.logo().isNull() ) {
+ QString type;
+ const QByteArray &pic = createPicture(contact.logo(), contact.logoFormat(), type);
+ content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-logo.png"*/contact.logoAttachmentName(), pic );
+ message->addContent(content);
+ }
+
+ if ( !contact.sound().isEmpty() ) {
+ content = Mime::createAttachmentPart(QByteArray(), "audio/unknown", /*"sound"*/contact.soundAttachmentName(), contact.sound() );
+ message->addContent(content);
+ }
+
+ message->assemble();
+ return message;
+}
+
+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 distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId)
+{
+ KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_DISTLIST, false, productId );
+ message->subject()->fromUnicodeString( distList.uid(), "utf-8" );
+ message->from()->fromUnicodeString( distList.uid(), "utf-8" );
+
+ KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_DISTLIST, distList.saveXML().toUtf8() );
+ message->addContent( content );
+
+ message->assemble();
+ return message;
+}
+
+KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const KMime::Message::Ptr &data)
+{
+ KolabV2::Note j;
+ if ( !j.load( xmlData ) ) {
+ Warning() << "failed to read note";
+ return KMime::Message::Ptr();
+ }
+
+ Akonadi::NoteUtils::NoteMessageWrapper note;
+ note.setTitle(j.summary());
+ note.setText(j.body().toUtf8());
+ note.setFrom("kolab at kde4");
+ note.setCreationDate(data->date()->dateTime());
+ return note.message();
+}
+
+KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &productId)
+{
+ Akonadi::NoteUtils::NoteMessageWrapper note(msg);
+ KolabV2::Note j;
+ j.setSummary( note.title() );
+ j.setBody( note.text() );
+
+ return Mime::createMessage(j.summary(), KOLAB_TYPE_NOTE, KOLAB_TYPE_NOTE, j.saveXML().toUtf8(), false, productId);
+}
+
+QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language)
+{
+ QStringList dictionary;
+ const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument( QString::fromUtf8(xmlData) ); //TODO extract function from V2 format
+ Q_ASSERT ( !xmlDoc.isNull() );
+
+ QDomElement top = xmlDoc.documentElement();
+
+ if ( top.tagName() != "configuration" ) {
+ qWarning( "XML error: Top tag was %s instead of the expected configuration",
+ top.tagName().toAscii().data() );
+ return QStringList();
+ }
+
+ for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
+ if ( n.isComment() || !n.isElement() )
+ continue;
+ QDomElement e = n.toElement();
+ if (e.tagName() == "language") {
+ language = e.text();
+ } else if (e.tagName() == "e") {
+ dictionary.append(e.text());
+ }
+ }
+ return dictionary;
+}
+
+}
\ No newline at end of file
diff --git a/kolabformat/v2helpers.h b/kolabformat/v2helpers.h
index 29a23c3..367f0ac 100644
--- a/kolabformat/v2helpers.h
+++ b/kolabformat/v2helpers.h
@@ -30,8 +30,9 @@
#include "mime/mimeutils.h"
#include "kolabformat/errorhandler.h"
+#include <kabc/contactgroup.h>
+
#include <qdom.h>
-#include <kdebug.h>
#include <qbuffer.h>
#include <akonadi/notes/noteutils.h>
@@ -72,200 +73,21 @@ static inline IncidencePtr incidenceFromKolabImpl( const KMime::Message::Ptr &da
return ptr;
}
-QImage getPicture(const QString &pictureAttachmentName, const KMime::Message::Ptr &data, QByteArray &type)
-{
- KMime::Content *imgContent = Mime::findContentByName(data, pictureAttachmentName/*"kolab-picture.png"*/, type);
- if (!imgContent) {
- Warning() << "could not find picture: " << pictureAttachmentName;
- return QImage();
- }
- QByteArray imgData = imgContent->decodedContent();
- QBuffer buffer(&imgData);
- buffer.open(QIODevice::ReadOnly);
- QImage image;
- bool success = false;
- if (type == "image/jpeg") {
- success = image.load(&buffer, "JPEG");
- //FIXME I tried getting the code to interpret the picture as PNG, but the VCard implementation writes it as JPEG anyways...
-// if (success) {
-// QByteArray pic;
-// QBuffer b(&pic);
-// b.open(QIODevice::ReadWrite);
-// Q_ASSERT(image.save(&b, "PNG"));
-// b.close();
-// Debug() << pic.toBase64();
-// QBuffer b2(&pic);
-// b2.open(QIODevice::ReadOnly);
-// success = image.load(&b2, "PNG");
-// b2.close();
-// Q_ASSERT(success);
-// }
- } else {
- type = "image/png";
- success = image.load(&buffer, "PNG");
- }
- buffer.close();
- if (!success) {
- Warning() << "failed to load picture";
- }
- return image;
-}
-
-KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data)
-{
- KABC::Addressee addressee;
-// Debug() << "xmlData " << xmlData;
- KolabV2::Contact contact(QString::fromUtf8(xmlData));
- QByteArray type;
- const QString &pictureAttachmentName = contact.pictureAttachmentName();
- if (!pictureAttachmentName.isEmpty()) {
- const QImage &img = getPicture(pictureAttachmentName, data, type);
- contact.setPicture(img, type);
- }
-
- const QString &logoAttachmentName = contact.logoAttachmentName();
- if (!logoAttachmentName.isEmpty()) {
- contact.setLogo(getPicture(logoAttachmentName, data, type), type);
- }
-
- const QString &soundAttachmentName = contact.soundAttachmentName();
- if (!soundAttachmentName.isEmpty()) {
- QByteArray type;
- KMime::Content *content = Mime::findContentByName(data, soundAttachmentName/*"sound"*/, type);
- if (content) {
- const QByteArray &sData = content->decodedContent();
- contact.setSound(sData);
- } else {
- Warning() << "could not find sound: " << soundAttachmentName;
- }
- }
- contact.saveTo(&addressee);
- return addressee;
-}
-
-QByteArray createPicture(const QImage &img, const QString &format, QString &type)
-{
- QByteArray pic;
- QBuffer buffer(&pic);
- buffer.open(QIODevice::WriteOnly);
- type = "image/png";
- //FIXME it's not possible to save jpegs lossless, so we always use png. otherwise we would compress the image on every write.
-// if (format == "image/jpeg") {
-// type = "image/jpeg";
-// img.save(&buffer, "JPEG");
-// } else {
- img.save(&buffer, "PNG");
-// }
- buffer.close();
- return pic;
-}
-
-KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId)
-{
- KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_CONTACT, false, productId );
- message->subject()->fromUnicodeString( contact.uid(), "utf-8" );
- message->from()->fromUnicodeString( contact.fullEmail(), "utf-8" );
-
- KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_CONTACT, contact.saveXML().toUtf8() );
- message->addContent( content );
-
- if ( !contact.picture().isNull() ) {
- QString type;
- const QByteArray &pic = createPicture(contact.picture(), contact.pictureFormat(), type);
- content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-picture.png"*/contact.pictureAttachmentName(), pic );
- message->addContent(content);
- }
-
- if ( !contact.logo().isNull() ) {
- QString type;
- const QByteArray &pic = createPicture(contact.logo(), contact.logoFormat(), type);
- content = Mime::createAttachmentPart(QByteArray(), type, /*"kolab-logo.png"*/contact.logoAttachmentName(), pic );
- message->addContent(content);
- }
-
- if ( !contact.sound().isEmpty() ) {
- content = Mime::createAttachmentPart(QByteArray(), "audio/unknown", /*"sound"*/contact.soundAttachmentName(), contact.sound() );
- message->addContent(content);
- }
-
- message->assemble();
- return message;
-}
-
-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 distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId)
-{
- KMime::Message::Ptr message = Mime::createMessage( KOLAB_TYPE_DISTLIST, false, productId );
- message->subject()->fromUnicodeString( distList.uid(), "utf-8" );
- message->from()->fromUnicodeString( distList.uid(), "utf-8" );
-
- KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_DISTLIST, distList.saveXML().toUtf8() );
- message->addContent( content );
-
- message->assemble();
- return message;
-}
+QImage getPicture(const QString &pictureAttachmentName, const KMime::Message::Ptr &data, QByteArray &type);
+KABC::Addressee addresseeFromKolab( const QByteArray &xmlData, const KMime::Message::Ptr &data);
-KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const KMime::Message::Ptr &data)
-{
- KolabV2::Note j;
- if ( !j.load( xmlData ) ) {
- Warning() << "failed to read note";
- return KMime::Message::Ptr();
- }
-
- Akonadi::NoteUtils::NoteMessageWrapper note;
- note.setTitle(j.summary());
- note.setText(j.body().toUtf8());
- note.setFrom("kolab at kde4");
- note.setCreationDate(data->date()->dateTime());
- return note.message();
-}
+QByteArray createPicture(const QImage &img, const QString &format, QString &type);
-KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &productId)
-{
- Akonadi::NoteUtils::NoteMessageWrapper note(msg);
- KolabV2::Note j;
- j.setSummary( note.title() );
- j.setBody( note.text() );
-
- return Mime::createMessage(j.summary(), KOLAB_TYPE_NOTE, KOLAB_TYPE_NOTE, j.saveXML().toUtf8(), false, productId);
-}
+KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId);
-QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language)
-{
- QStringList dictionary;
- const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument( QString::fromUtf8(xmlData) ); //TODO extract function from V2 format
- Q_ASSERT ( !xmlDoc.isNull() );
+KABC::ContactGroup contactGroupFromKolab(const QByteArray &xmlData);
- QDomElement top = xmlDoc.documentElement();
+KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId);
+KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const KMime::Message::Ptr &data);
- if ( top.tagName() != "configuration" ) {
- qWarning( "XML error: Top tag was %s instead of the expected configuration",
- top.tagName().toAscii().data() );
- return QStringList();
- }
+KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &productId);
- for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
- if ( n.isComment() || !n.isElement() )
- continue;
- QDomElement e = n.toElement();
- if (e.tagName() == "language") {
- language = e.text();
- } else if (e.tagName() == "e") {
- dictionary.append(e.text());
- }
- }
- return dictionary;
-}
+QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language);
}
More information about the commits
mailing list