5 commits - calendaring/event.cpp CMakeLists.txt conversion/kabcconversion.cpp freebusy/freebusy.cpp kolabformat/formathelpers.cpp kolabformat/formathelpers.h kolabformat/kolabdefinitions.h kolabformat/kolabobject.cpp kolabformatV2/distributionlist.cpp kolabformat/v2helpers.h
Christian Mollekopf
mollekopf at kolabsys.com
Wed Jul 18 18:03:20 CEST 2012
CMakeLists.txt | 2
calendaring/event.cpp | 2
conversion/kabcconversion.cpp | 30 +--
freebusy/freebusy.cpp | 6
kolabformat/formathelpers.cpp | 79 ++++++++++
kolabformat/formathelpers.h | 42 +++++
kolabformat/kolabdefinitions.h | 30 +--
kolabformat/kolabobject.cpp | 278 ++++++++++++++++++++-----------------
kolabformat/v2helpers.h | 10 -
kolabformatV2/distributionlist.cpp | 38 -----
10 files changed, 322 insertions(+), 195 deletions(-)
New commits:
commit a6d822077b3bfe262e0c1b6d7d65ccde0f55bd3b
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Jul 18 18:03:07 2012 +0200
A couple of helper functions for default names etc.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d33e1c8..4c40fb3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -114,6 +114,7 @@ QT4_WRAP_CPP(CALENDARING_MOC calendaring/event.h)
set(KOLAB_SRCS
kolabformat/kolabobject.cpp
+ kolabformat/formathelpers.cpp
kolabformat/errorhandler.cpp
mime/mimeutils.cpp
${CONVERSION_SRCS}
@@ -153,6 +154,7 @@ install(TARGETS kolab EXPORT LibkolabExport
install(FILES
kolab_export.h
kolabformat/kolabdefinitions.h
+ kolabformat/formathelpers.h
kolabformat/kolabobject.h
kolabformat/errorhandler.h
conversion/kcalconversion.h
diff --git a/kolabformat/formathelpers.cpp b/kolabformat/formathelpers.cpp
new file mode 100644
index 0000000..1badcf6
--- /dev/null
+++ b/kolabformat/formathelpers.cpp
@@ -0,0 +1,79 @@
+#include "formathelpers.h"
+#include <klocalizedstring.h>
+#include "kolabdefinitions.h"
+
+namespace Kolab {
+
+static const struct {
+ const char *name;
+ const char *label;
+} folderTypeData[] = {
+ { KOLAB_FOLDER_TYPE_MAIL, "" },
+ { KOLAB_FOLDER_TYPE_CONTACT, I18N_NOOP( "Contacts" ) },
+ { KOLAB_FOLDER_TYPE_EVENT, I18N_NOOP( "Calendar" ) },
+ { KOLAB_FOLDER_TYPE_TASK, I18N_NOOP( "Tasks" ) },
+ { KOLAB_FOLDER_TYPE_JOURNAL, I18N_NOOP( "Journal" ) },
+ { KOLAB_FOLDER_TYPE_NOTE, I18N_NOOP( "Notes" ) },
+ { KOLAB_FOLDER_TYPE_CONFIGURATION, I18N_NOOP( "Configuration" ) },
+ { KOLAB_FOLDER_TYPE_FREEBUSY, I18N_NOOP( "Freebusy" ) }
+};
+static const int numFolderTypeData = sizeof folderTypeData / sizeof *folderTypeData;
+
+std::string folderAnnotation(FolderType type, bool isDefault)
+{
+ Q_ASSERT( type >= 0 && type < LastType );
+ std::string result = folderTypeData[ type ].name;
+ if ( isDefault ) {
+ result += KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX;
+ }
+ return result;
+}
+
+FolderType folderTypeFromString(const std::string& folderTypeName)
+{
+ if ( folderTypeName == KOLAB_FOLDER_TYPE_CONTACT ||
+ folderTypeName == KOLAB_FOLDER_TYPE_CONTACT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
+ return ContactType;
+ }
+
+ if ( folderTypeName == KOLAB_FOLDER_TYPE_EVENT ||
+ folderTypeName == KOLAB_FOLDER_TYPE_EVENT KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
+ return EventType;
+ }
+
+ if ( folderTypeName == KOLAB_FOLDER_TYPE_TASK ||
+ folderTypeName == KOLAB_FOLDER_TYPE_TASK KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
+ return TaskType;
+ }
+
+ if ( folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL ||
+ folderTypeName == KOLAB_FOLDER_TYPE_JOURNAL KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
+ return JournalType;
+ }
+
+ if ( folderTypeName == KOLAB_FOLDER_TYPE_NOTE ||
+ folderTypeName == KOLAB_FOLDER_TYPE_NOTE KOLAB_FOLDER_TYPE_DEFAULT_SUFFIX ) {
+ return NoteType;
+ }
+
+ return MailType;
+}
+
+FolderType guessFolderTypeFromName(const std::string& name)
+{
+ for ( int i = 0; i < numFolderTypeData; ++i ) {
+ if ( name == i18n( folderTypeData[ i ].label ).toStdString() ||
+ name == folderTypeData[ i ].label ) {
+ return static_cast<FolderType>( i );
+ }
+ }
+ return MailType;
+}
+
+std::string nameForFolderType(FolderType type)
+{
+ Q_ASSERT( type >= 0 && type < LastType );
+ return i18n( folderTypeData[ type ].label ).toStdString();
+}
+
+}
diff --git a/kolabformat/formathelpers.h b/kolabformat/formathelpers.h
new file mode 100644
index 0000000..9334927
--- /dev/null
+++ b/kolabformat/formathelpers.h
@@ -0,0 +1,42 @@
+
+#ifndef FORMATHELPERS_H
+#define FORMATHELPERS_H
+
+#include <kolab_export.h>
+#include <string>
+
+namespace Kolab {
+
+enum FolderType {
+ MailType = 0,
+ ContactType,
+ EventType,
+ TaskType,
+ JournalType,
+ NoteType,
+ ConfigurationType,
+ FreebusyType,
+ LastType
+};
+
+/**
+ * Returns the FolderType from a KOLAB_FOLDER_TYPE_* folder type string
+ */
+KOLAB_EXPORT FolderType folderTypeFromString( const std::string &folderTypeName );
+/**
+ * Returns the annotation string for a folder
+ */
+KOLAB_EXPORT std::string folderAnnotation( FolderType type, bool isDefault = false );
+/**
+ * Guesses the folder type from a user visible string
+ */
+KOLAB_EXPORT FolderType guessFolderTypeFromName( const std::string &name );
+
+/**
+ * Returns a folder name for a type
+ */
+KOLAB_EXPORT std::string nameForFolderType( FolderType type );
+
+}
+
+#endif
diff --git a/kolabformat/kolabdefinitions.h b/kolabformat/kolabdefinitions.h
index 0d53c8e..a9537c4 100644
--- a/kolabformat/kolabdefinitions.h
+++ b/kolabformat/kolabdefinitions.h
@@ -18,8 +18,6 @@
#ifndef KOLABDEFINITIONS_H
#define KOLABDEFINITIONS_H
-#include <QString>
-
namespace Kolab {
#define KOLAB_FOLDER_TYPE_MAIL "mail"
@@ -42,20 +40,20 @@ namespace Kolab {
#define KOLAB_OBJECT_FILENAME "kolab.xml"
-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 distlistKolabTypeCompat() { return QString::fromLatin1("application/x-vnd.kolab.distribution-list"); }
-static QString noteKolabType() { return QString::fromLatin1("application/x-vnd.kolab.note"); }
-static QString configurationKolabType() { return QString::fromLatin1("application/x-vnd.kolab.configuration"); }
-static QString dictKolabType() { return QString::fromLatin1("application/x-vnd.kolab.configuration.dictionary"); }
-static QString freebusyKolabType() { return QString::fromLatin1("application/x-vnd.kolab.freebusy"); }
-
-static QString xCalMimeType() { return QString::fromLatin1("application/calendar+xml"); };
-static QString xCardMimeType() { return QString::fromLatin1("application/vcard+xml"); };
-static QString kolabMimeType() { return QString::fromLatin1("application/vnd.kolab+xml"); };
+#define MIME_TYPE_XCAL "application/calendar+xml"
+#define MIME_TYPE_XCARD "application/vcard+xml"
+#define MIME_TYPE_KOLAB "application/vnd.kolab+xml"
+
+#define KOLAB_TYPE_EVENT "application/x-vnd.kolab.event"
+#define KOLAB_TYPE_TASK "application/x-vnd.kolab.task"
+#define KOLAB_TYPE_JOURNAL "application/x-vnd.kolab.journal"
+#define KOLAB_TYPE_CONTACT "application/x-vnd.kolab.contact"
+#define KOLAB_TYPE_DISTLIST "application/x-vnd.kolab.contact.distlist"
+#define KOLAB_TYPE_DISTLIST_COMPAT "application/x-vnd.kolab.event"
+#define KOLAB_TYPE_NOTE "application/x-vnd.kolab.distribution-list"
+#define KOLAB_TYPE_CONFIGURATION "application/x-vnd.kolab.configuration"
+#define KOLAB_TYPE_DICT "application/x-vnd.kolab.configuration.dictionary"
+#define KOLAB_TYPE_FREEBUSY "application/x-vnd.kolab.freebusy"
}
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index c26f336..9190b94 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -39,6 +39,22 @@
namespace Kolab {
+
+static QString eventKolabType() { return QString::fromLatin1(KOLAB_TYPE_EVENT); };
+static QString todoKolabType() { return QString::fromLatin1(KOLAB_TYPE_TASK); };
+static QString journalKolabType() { return QString::fromLatin1(KOLAB_TYPE_JOURNAL); };
+static QString contactKolabType() { return QString::fromLatin1(KOLAB_TYPE_CONTACT); };
+static QString distlistKolabType() { return QString::fromLatin1(KOLAB_TYPE_DISTLIST); }
+static QString distlistKolabTypeCompat() { return QString::fromLatin1(KOLAB_TYPE_DISTLIST_COMPAT); }
+static QString noteKolabType() { return QString::fromLatin1(KOLAB_TYPE_NOTE); }
+static QString configurationKolabType() { return QString::fromLatin1(KOLAB_TYPE_CONFIGURATION); }
+static QString dictKolabType() { return QString::fromLatin1(KOLAB_TYPE_DICT); }
+static QString freebusyKolabType() { return QString::fromLatin1(KOLAB_TYPE_FREEBUSY); }
+
+static QString xCalMimeType() { return QString::fromLatin1(MIME_TYPE_XCAL); };
+static QString xCardMimeType() { return QString::fromLatin1(MIME_TYPE_XCARD); };
+static QString kolabMimeType() { return QString::fromLatin1(MIME_TYPE_KOLAB); };
+
KCalCore::Event::Ptr readV2EventXML(const QByteArray& xmlData, QStringList& attachments)
{
return fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
@@ -116,13 +132,13 @@ QByteArray getMimeType(Kolab::ObjectType type)
case TodoObject:
case JournalObject:
case FreebusyObject:
- return xCalMimeType().toLocal8Bit();
+ return MIME_TYPE_XCAL;
case ContactObject:
case DistlistObject:
- return xCardMimeType().toLocal8Bit();
+ return MIME_TYPE_XCARD;
case NoteObject:
case DictionaryConfigurationObject:
- return kolabMimeType().toLocal8Bit();
+ return MIME_TYPE_KOLAB;
default:
Critical() << "unknown type "<< type;
}
diff --git a/kolabformat/v2helpers.h b/kolabformat/v2helpers.h
index 3700f37..f93f9a1 100644
--- a/kolabformat/v2helpers.h
+++ b/kolabformat/v2helpers.h
@@ -161,11 +161,11 @@ QByteArray createPicture(const QImage &img, const QString &format, QString &type
KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact& contact, const QString &productId)
{
- KMime::Message::Ptr message = Mime::createMessage( contactKolabType(), false, 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( contactKolabType(), contact.saveXML().toUtf8() );
+ KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_CONTACT, contact.saveXML().toUtf8() );
message->addContent( content );
if ( !contact.picture().isNull() ) {
@@ -202,11 +202,11 @@ KABC::ContactGroup contactGroupFromKolab(const QByteArray &xmlData)
KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList& distList, const QString &productId)
{
- KMime::Message::Ptr message = Mime::createMessage( distlistKolabType(), false, 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( distlistKolabType(), distList.saveXML().toUtf8() );
+ KMime::Content* content = Mime::createMainPart( KOLAB_TYPE_DISTLIST, distList.saveXML().toUtf8() );
message->addContent( content );
message->assemble();
@@ -236,7 +236,7 @@ KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr& msg, const QString &p
j.setSummary( note.title() );
j.setBody( note.text() );
- return Mime::createMessage(j.summary(), noteKolabType(), noteKolabType(), j.saveXML().toUtf8(), false, productId);
+ return Mime::createMessage(j.summary(), KOLAB_TYPE_NOTE, KOLAB_TYPE_NOTE, j.saveXML().toUtf8(), false, productId);
}
QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language)
commit efbc13c3955b53016c0562a03a815c5c701ad209
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Jul 18 18:02:01 2012 +0200
User the organizer as "from" address of an iMip message.
diff --git a/calendaring/event.cpp b/calendaring/event.cpp
index b09ceeb..f3bdce6 100644
--- a/calendaring/event.cpp
+++ b/calendaring/event.cpp
@@ -110,7 +110,7 @@ std::string Event::toIMip(ITipMethod method) const
{
std::vector<Kolab::Event> list;
list.push_back(*this);
- return mITipHandler.toIMip(*this, static_cast<ITipHandler::ITipMethod>(method), "from");
+ return mITipHandler.toIMip(*this, static_cast<ITipHandler::ITipMethod>(method), organizer().email());
}
Calendaring::Event::ITipMethod Event::getSchedulingMethod() const
commit fbccfcdda2935eef0b7defebe8ec12f47e2a0a2b
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Jul 18 15:50:03 2012 +0200
refactoring
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 286785b..c26f336 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -55,6 +55,9 @@ public:
{
mAddressee = KABC::Addressee();
}
+
+ ObjectType readKolabV2(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType, const QString &kolabType);
+ ObjectType readKolabV3(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType);
KCalCore::Incidence::Ptr mIncidence;
KABC::Addressee mAddressee;
@@ -76,7 +79,7 @@ KolabObjectReader::KolabObjectReader()
KolabObjectReader::KolabObjectReader(const KMime::Message::Ptr& msg)
: d( new KolabObjectReader::Private )
{
- parseMimeMessage(msg);
+ d->mObjectType = parseMimeMessage(msg);
}
KolabObjectReader::~KolabObjectReader()
@@ -134,6 +137,133 @@ void printMessageDebugInfo(const KMime::Message::Ptr &msg)
// Debug() << msg->encodedContent();
}
+ObjectType KolabObjectReader::Private::readKolabV2(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType, const QString &kolabType)
+{
+ if (objectType == DictionaryConfigurationObject) {
+ KMime::Content *xmlContent = Mime::findContentByType( msg, "application/xml" );
+ if ( !xmlContent ) {
+ Critical() << "no application/xml part found";
+ printMessageDebugInfo(msg);
+ return InvalidObject;
+ }
+ const QByteArray &xmlData = xmlContent->decodedContent();
+ mDictionary = readLegacyDictionaryConfiguration(xmlData, mDictionaryLanguage);
+ ErrorHandler::handleLibkolabxmlErrors();
+ mObjectType = objectType;
+ return mObjectType;
+ }
+ KMime::Content *xmlContent = Mime::findContentByType( msg, kolabType.toLocal8Bit() );
+ if ( !xmlContent ) {
+ Critical() << "no part with type" << kolabType.toLocal8Bit() << " found";
+ printMessageDebugInfo(msg);
+ return InvalidObject;
+ }
+ const QByteArray &xmlData = xmlContent->decodedContent();
+ Q_ASSERT(!xmlData.isEmpty());
+ QStringList attachments;
+
+ switch (objectType) {
+ case EventObject:
+ mIncidence = fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
+ break;
+ case TodoObject:
+ mIncidence = fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(xmlData, attachments);
+ break;
+ case JournalObject:
+ mIncidence = fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(xmlData, attachments);
+ break;
+ case ContactObject:
+ mAddressee = addresseeFromKolab(xmlData, msg);
+ break;
+ case DistlistObject:
+ mContactGroup = contactGroupFromKolab(xmlData);
+ break;
+ case NoteObject:
+ mNote = noteFromKolab(xmlData, msg);
+ break;
+ default:
+ CRITICAL("no kolab object found ");
+ break;
+ }
+ if (!mIncidence.isNull()) {
+// kDebug() << "v2 attachments " << attachments.size() << d->mIncidence->attachments().size();
+ mIncidence->clearAttachments();
+ Mime::getAttachments(mIncidence, attachments, msg);
+ Q_ASSERT(mIncidence->attachments().size() == attachments.size());
+ }
+ mObjectType = objectType;
+ return objectType;
+}
+
+ObjectType KolabObjectReader::Private::readKolabV3(const KMime::Message::Ptr &msg, Kolab::ObjectType objectType)
+{
+ KMime::Content *xmlContent = Mime::findContentByType( msg, getMimeType(objectType) );
+ if ( !xmlContent ) {
+ Critical() << "no " << getMimeType(objectType) << " part found";
+ printMessageDebugInfo(msg);
+ return InvalidObject;
+ }
+ switch (objectType) {
+ case EventObject: {
+ const Kolab::Event & event = Kolab::readEvent(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mIncidence = Kolab::Conversion::toKCalCore(event);
+ }
+ break;
+ case TodoObject: {
+ const Kolab::Todo & event = Kolab::readTodo(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mIncidence = Kolab::Conversion::toKCalCore(event);
+ }
+ break;
+ case JournalObject: {
+ const Kolab::Journal & event = Kolab::readJournal(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mIncidence = Kolab::Conversion::toKCalCore(event);
+ }
+ break;
+ case ContactObject: {
+ const Kolab::Contact &contact = Kolab::readContact(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mAddressee = Kolab::Conversion::toKABC(contact); //TODO extract attachments
+ }
+ break;
+ case DistlistObject: {
+ const Kolab::DistList &distlist = Kolab::readDistlist(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mContactGroup = Kolab::Conversion::toKABC(distlist);
+ }
+ break;
+ case NoteObject: {
+ const Kolab::Note ¬e = Kolab::readNote(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mNote = Kolab::Conversion::toNote(note);
+ }
+ break;
+ case DictionaryConfigurationObject: {
+ const Kolab::Configuration &configuration = Kolab::readConfiguration(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ const Kolab::Dictionary &dictionary = configuration.dictionary();
+ mDictionary.clear();
+ foreach (const std::string &entry, dictionary.entries()) {
+ mDictionary.append(QString::fromStdString(entry));
+ }
+ mDictionaryLanguage = QString::fromStdString(dictionary.language());
+ }
+ break;
+ case FreebusyObject: {
+ const Kolab::Freebusy &fb = Kolab::readFreebusy(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
+ mFreebusy = fb;
+ }
+ break;
+ default:
+ Critical() << "no kolab object found ";
+ printMessageDebugInfo(msg);
+ break;
+ }
+
+ if (!mIncidence.isNull()) {
+// kDebug() << "getting attachments";
+ Mime::getAttachmentsById(mIncidence, msg);
+ }
+ ErrorHandler::handleLibkolabxmlErrors();
+ mObjectType = objectType;
+ return objectType;
+}
+
ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
{
ErrorHandler::clearErrors();
@@ -159,127 +289,13 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
}
d->mVersion = KolabV3;
}
- d->mObjectType = getObjectType(kolabType);
+ Kolab::ObjectType objectType = getObjectType(kolabType);
if (d->mVersion == KolabV2) {
- if (d->mObjectType == DictionaryConfigurationObject) {
- KMime::Content *xmlContent = Mime::findContentByType( msg, "application/xml" );
- if ( !xmlContent ) {
- Critical() << "no application/xml part found";
- printMessageDebugInfo(msg);
- return InvalidObject;
- }
- const QByteArray &xmlData = xmlContent->decodedContent();
- d->mDictionary = readLegacyDictionaryConfiguration(xmlData, d->mDictionaryLanguage);
- ErrorHandler::handleLibkolabxmlErrors();
- return d->mObjectType;
- }
- KMime::Content *xmlContent = Mime::findContentByType( msg, kolabType.toLocal8Bit() );
- if ( !xmlContent ) {
- Critical() << "no part with type" << kolabType.toLocal8Bit() << " found";
- printMessageDebugInfo(msg);
- return InvalidObject;
- }
- const QByteArray &xmlData = xmlContent->decodedContent();
- Q_ASSERT(!xmlData.isEmpty());
- QStringList attachments;
-
- switch (d->mObjectType) {
- case EventObject:
- d->mIncidence = fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
- break;
- case TodoObject:
- d->mIncidence = fromXML<KCalCore::Todo::Ptr, KolabV2::Task>(xmlData, attachments);
- break;
- case JournalObject:
- d->mIncidence = fromXML<KCalCore::Journal::Ptr, KolabV2::Journal>(xmlData, attachments);
- break;
- case ContactObject:
- d->mAddressee = addresseeFromKolab(xmlData, msg);
- break;
- case DistlistObject:
- d->mContactGroup = contactGroupFromKolab(xmlData);
- break;
- case NoteObject:
- d->mNote = noteFromKolab(xmlData, msg);
- break;
- default:
- CRITICAL("no kolab object found "+kolabType);
- break;
- }
- if (!d->mIncidence.isNull()) {
-// kDebug() << "v2 attachments " << attachments.size() << d->mIncidence->attachments().size();
- d->mIncidence->clearAttachments();
- Mime::getAttachments(d->mIncidence, attachments, msg);
- Q_ASSERT(d->mIncidence->attachments().size() == attachments.size());
- }
- } else { //V3
- KMime::Content *xmlContent = Mime::findContentByType( msg, getMimeType(d->mObjectType) );
- if ( !xmlContent ) {
- Critical() << "no " << getMimeType(d->mObjectType) << " part found";
- printMessageDebugInfo(msg);
- d->mObjectType = InvalidObject;
- return InvalidObject;
- }
- switch (d->mObjectType) {
- case EventObject: {
- const Kolab::Event & event = Kolab::readEvent(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mIncidence = Kolab::Conversion::toKCalCore(event);
- }
- break;
- case TodoObject: {
- const Kolab::Todo & event = Kolab::readTodo(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mIncidence = Kolab::Conversion::toKCalCore(event);
- }
- break;
- case JournalObject: {
- const Kolab::Journal & event = Kolab::readJournal(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mIncidence = Kolab::Conversion::toKCalCore(event);
- }
- break;
- case ContactObject: {
- const Kolab::Contact &contact = Kolab::readContact(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mAddressee = Kolab::Conversion::toKABC(contact); //TODO extract attachments
- }
- break;
- case DistlistObject: {
- const Kolab::DistList &distlist = Kolab::readDistlist(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mContactGroup = Kolab::Conversion::toKABC(distlist);
- }
- break;
- case NoteObject: {
- const Kolab::Note ¬e = Kolab::readNote(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mNote = Kolab::Conversion::toNote(note);
- }
- break;
- case DictionaryConfigurationObject: {
- const Kolab::Configuration &configuration = Kolab::readConfiguration(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- const Kolab::Dictionary &dictionary = configuration.dictionary();
- d->mDictionary.clear();
- foreach (const std::string &entry, dictionary.entries()) {
- d->mDictionary.append(QString::fromStdString(entry));
- }
- d->mDictionaryLanguage = QString::fromStdString(dictionary.language());
- }
- break;
- case FreebusyObject: {
- const Kolab::Freebusy &fb = Kolab::readFreebusy(std::string(xmlContent->decodedContent().data(), xmlContent->decodedContent().size()), false);
- d->mFreebusy = fb;
- }
- break;
- default:
- Critical() << "no kolab object found " << kolabType;
- printMessageDebugInfo(msg);
- d->mObjectType = InvalidObject;
- break;
- }
-
- if (!d->mIncidence.isNull()) {
-// kDebug() << "getting attachments";
- Mime::getAttachmentsById(d->mIncidence, msg);
- }
- ErrorHandler::handleLibkolabxmlErrors();
+ return d->readKolabV2(msg, objectType, kolabType);
+ } else {
+ return d->readKolabV3(msg, objectType);
}
- return d->mObjectType;
+ return InvalidObject;
}
Version KolabObjectReader::getVersion() const
commit 495e2cb3e6d4910336a1884d217c32c90d4cc115
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Tue Jul 17 19:16:57 2012 +0200
Only set the organizer if available.
diff --git a/freebusy/freebusy.cpp b/freebusy/freebusy.cpp
index 465946f..91f2055 100644
--- a/freebusy/freebusy.cpp
+++ b/freebusy/freebusy.cpp
@@ -148,7 +148,7 @@ Kolab::Period addLocalPeriod( const KDateTime &eventStart, const KDateTime &eve
tmpStart = eventStart;
}
- qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString();
+// qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString();
if ( eventEnd > mDtEnd ) { //event end is after dtEnd
tmpEnd = mDtEnd;
} else {
@@ -239,7 +239,9 @@ Freebusy generateFreeBusy(const QList<KCalCore::Event::Ptr>& events, const KDate
freebusy.setPeriods(freebusyPeriods);
freebusy.setUid(QUuid::createUuid().toString().toStdString());
freebusy.setTimestamp(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime()));
- freebusy.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, organizer->email().toStdString(), organizer->name().toStdString()));
+ if (organizer) {
+ freebusy.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, organizer->email().toStdString(), organizer->name().toStdString()));
+ }
return freebusy;
}
commit 0bad296869a07f7615a31b9162df0b39890e30f0
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Tue Jul 17 19:16:38 2012 +0200
Fix distlist conversions.
diff --git a/conversion/kabcconversion.cpp b/conversion/kabcconversion.cpp
index a418333..b7afce7 100644
--- a/conversion/kabcconversion.cpp
+++ b/conversion/kabcconversion.cpp
@@ -808,20 +808,20 @@ DistList fromKABC(const KABC::ContactGroup &cg)
dl.setUid(cg.id().toStdString());
std::vector <Kolab::ContactReference > members;
+ for (int i = 0; i < cg.dataCount(); i++) {
+ const KABC::ContactGroup::Data &data = cg.data(i);
+ members.push_back(Kolab::ContactReference(Kolab::ContactReference::EmailReference, data.email().toStdString(), data.name().toStdString()));
+ }
for (int i = 0; i < cg.contactReferenceCount(); i++) {
const KABC::ContactGroup::ContactReference &ref = cg.contactReference(i);
- if (!ref.preferredEmail().isEmpty()) {
- members.push_back(Kolab::ContactReference(Kolab::ContactReference::EmailReference, ref.preferredEmail().toStdString())); //TODO name?
- } else if (!ref.uid().isEmpty()) {
- //TODO find uid of referenced contact (akonadi item id)
- Warning() << "uid reference not yet supported";
- } else {
- Error() << "invalid contact reference";
- }
+ members.push_back(Kolab::ContactReference(Kolab::ContactReference::UidReference, ref.uid().toStdString()));
}
- dl.setMembers(members);
+ if (cg.contactGroupReferenceCount() > 0) {
+ kWarning() << "Tried to save contact group references, which should have been resolved already";
+ }
+ dl.setMembers(members);
return dl;
}
@@ -831,19 +831,17 @@ KABC::ContactGroup toKABC(const DistList &dl)
KABC::ContactGroup cg(QString::fromStdString(dl.name()));
cg.setId(QString::fromStdString(dl.uid()));
foreach(const Kolab::ContactReference &m, dl.members()) {
- KABC::ContactGroup::ContactReference ref;
+ KABC::ContactGroup::Data data;
switch (m.type()) {
case Kolab::ContactReference::EmailReference:
- ref.setPreferredEmail(QString::fromStdString(m.email()));
+ cg.append(KABC::ContactGroup::Data(QString::fromStdString(m.name()), QString::fromStdString(m.email())));
+ break;
case Kolab::ContactReference::UidReference:
- //TODO find contact based on uid, and then set the corresponding akonadi item id as uid
- //m.uid() //TODO
- //ref.setUid(//akonadi item id of referenced contact);
- Warning() << "uid reference not yet supported";
+ cg.append(KABC::ContactGroup::ContactReference(QString::fromStdString(m.uid())));
+ break;
default:
Error() << "invalid contact reference";
}
- cg.append(ref);
}
return cg;
diff --git a/kolabformatV2/distributionlist.cpp b/kolabformatV2/distributionlist.cpp
index 61605c6..34379ef 100644
--- a/kolabformatV2/distributionlist.cpp
+++ b/kolabformatV2/distributionlist.cpp
@@ -31,8 +31,6 @@
#include "distributionlist.h"
-// #include <akonadi/itemfetchjob.h>
-// #include <akonadi/itemfetchscope.h>
#include <kabc/addressee.h>
#include <kabc/contactgroup.h>
#include <kdebug.h>
@@ -194,36 +192,12 @@ void DistributionList::setFields( const KABC::ContactGroup* contactGroup )
mDistrListMembers.append( m );
}
-
- // Hopefully all resources are available during saving, so we can look up
- // in the addressbook to get name+email from the UID.
- // TODO proxy should at least know the addressees it created
-// for ( uint index = 0; index < contactGroup->contactReferenceCount(); ++index ) {
-// const KABC::ContactGroup::ContactReference& reference = contactGroup->contactReference( index );
-//
-// //FIXME this won't work on the server (wihtout akonadi), move this part to the akonadi resource
-// const Akonadi::Item item( reference.uid().toLongLong() );
-// Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( item );
-// job->fetchScope().fetchFullPayload();
-// if ( !job->exec() )
-// continue;
-//
-// const Akonadi::Item::List items = job->items();
-// if ( items.count() != 1 )
-// continue;
-//
-// const KABC::Addressee addressee = job->items().first().payload<KABC::Addressee>();
-//
-// if ( !addressee.isEmpty() ) {
-// Member m;
-// m.displayName = addressee.formattedName();
-// m.email = reference.preferredEmail();
-// if ( m.email.isEmpty() )
-// m.email = addressee.preferredEmail();
-//
-// mDistrListMembers.append( m );
-// }
-// }
+ if (contactGroup->contactReferenceCount() > 0) {
+ kWarning() << "Tried to save contact references, which should have been resolved already";
+ }
+ if (contactGroup->contactGroupReferenceCount() > 0) {
+ kWarning() << "Tried to save contact group references, which should have been resolved already";
+ }
}
// The loading is: xml -> DistributionList -> contactgroup, this is the second part
More information about the commits
mailing list