Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
36 KB
Referenced Files
None
Subscribers
None
diff --git a/freebusy/freebusy.cpp b/freebusy/freebusy.cpp
index 91f2055..cd090bd 100644
--- a/freebusy/freebusy.cpp
+++ b/freebusy/freebusy.cpp
@@ -1,313 +1,313 @@
/*
* Copyright (C) 2012 Christian Mollekopf <mollekopf@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 "freebusy.h"
#include "conversion/kcalconversion.h"
#include <kcalcore/freebusy.h>
#include <kcalcore/icalformat.h>
#include <kdebug.h>
#include <quuid.h>
// namespace KCalCore {
// struct KCalFreebusy
// {
//
// void init( const Event::List &eventList, const KDateTime &start, const KDateTime &end )
// {
// mDtStart = start.toUtc();
// mDtEnd = end.toUtc();
//
// // Loops through every event in the calendar
// Event::List::ConstIterator it;
// for ( it = eventList.constBegin(); it != eventList.constEnd(); ++it ) {
// Event::Ptr event = *it;
//
// // If this event is transparent it shouldn't be in the freebusy list.
// if ( event->transparency() == Event::Transparent ) {
// continue;
// }
//
// if ( event->hasRecurrenceId() ) {
// continue; //TODO apply special period exception (duration could be different)
// }
//
// const KDateTime eventStart = event->dtStart().toUtc();
// const KDateTime eventEnd = event->dtEnd().toUtc();
//
// if ( event->recurs() ) {
// const KCalCore::Duration duration( eventStart, eventEnd );
// const KCalCore::DateTimeList list = event->recurrence()->timesInInterval(start, end);
// foreach (const KDateTime &dt, list) {
// const KDateTime utc = dt.toUtc();
// addLocalPeriod(utc, duration.end(utc) );
// }
// } else {
// addLocalPeriod( eventStart, eventEnd );
// }
// }
//
// // q->sortList();
// }
//
// bool addLocalPeriod(
// const KDateTime &eventStart,
// const KDateTime &eventEnd )
// {
// KDateTime tmpStart;
// KDateTime tmpEnd;
//
// //Check to see if the start *or* end of the event is
// //between the start and end of the freebusy dates.
// if ( !( ( ( mDtStart.secsTo( eventStart ) >= 0 ) &&
// ( eventStart.secsTo( mDtEnd ) >= 0 ) ) ||
// ( ( mDtStart.secsTo( eventEnd ) >= 0 ) &&
// ( eventEnd.secsTo( mDtEnd ) >= 0 ) ) ) ) {
// qDebug() << "out of scope";
// return false;
// }
//
// // qDebug() << eventStart.date().toString() << eventStart.time().toString() << mDtStart.toString();
// if ( eventStart < mDtStart ) { //eventStart is before start
// // qDebug() << "use start";
// tmpStart = mDtStart;
// } else {
// tmpStart = eventStart;
// }
//
// qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString();
// if ( eventEnd > mDtEnd ) { //event end is after dtEnd
// // qDebug() << "use end";
// tmpEnd = mDtEnd;
// } else {
// tmpEnd = eventEnd;
// }
//
// // qDebug() << "########## " << tmpStart.isValid();
// Q_ASSERT(tmpStart.isValid());
// Q_ASSERT(tmpEnd.isValid());
// // qDebug() << tmpStart.date().toString() << tmpStart.time().toString() << tmpStart.toString();
//
// FreeBusyPeriod p( tmpStart, tmpEnd );
// mBusyPeriods.append( p );
//
// return true;
// }
//
// KDateTime mDtStart;
// KDateTime mDtEnd; // end datetime
// FreeBusyPeriod::List mBusyPeriods; // list of periods
//
// };
//
// } // Namespace
namespace Kolab {
namespace FreebusyUtils {
Kolab::Period addLocalPeriod( const KDateTime &eventStart, const KDateTime &eventEnd, const KDateTime &mDtStart, const KDateTime &mDtEnd)
{
KDateTime tmpStart;
KDateTime tmpEnd;
//Check to see if the start *or* end of the event is
//between the start and end of the freebusy dates.
if ( !( ( ( mDtStart <= eventStart) &&
( eventStart <= mDtEnd ) ) ||
( ( mDtStart <= eventEnd ) &&
( eventEnd <= mDtEnd ) ) ) ) {
- qDebug() << "out of scope";
+ qDebug() << "event is not within the fb range, skipping";
return Kolab::Period();
}
if ( eventStart < mDtStart ) { //eventStart is before start
tmpStart = mDtStart;
} else {
tmpStart = eventStart;
}
// qDebug() << eventEnd.date().toString() << eventEnd.time().toString() << mDtEnd.toString();
if ( eventEnd > mDtEnd ) { //event end is after dtEnd
tmpEnd = mDtEnd;
} else {
tmpEnd = eventEnd;
}
Q_ASSERT(tmpStart.isValid());
Q_ASSERT(tmpEnd.isValid());
if (tmpStart.isDateOnly()) {
tmpStart.setTime(QTime(0,0,0,0));
}
if (tmpEnd.isDateOnly()) {
tmpEnd.setTime(QTime(23,59,59,999)); //The window is inclusive
}
return Kolab::Period(Kolab::Conversion::fromDate(tmpStart), Kolab::Conversion::fromDate(tmpEnd));
}
Freebusy generateFreeBusy(const std::vector< Event >& events, const cDateTime& startDate, const cDateTime& endDate)
{
QList<KCalCore::Event::Ptr> list;
foreach (const Kolab::Event &e, events) {
list.append(Kolab::Conversion::toKCalCore(e));
}
KCalCore::Person::Ptr person(new KCalCore::Person("dummyname", "dummyemail"));
return generateFreeBusy(list, Kolab::Conversion::toDate(startDate), Kolab::Conversion::toDate(endDate), person);
}
Freebusy generateFreeBusy(const QList<KCalCore::Event::Ptr>& events, const KDateTime& startDate, const KDateTime& endDate, const KCalCore::Person::Ptr &organizer)
{
/*
* TODO the conversion of date-only values to date-time is only necessary because xCal doesn't allow date only. iCalendar doesn't seem to make this restriction so it looks like a bug.
*/
KDateTime start = startDate.toUtc();
if (start.isDateOnly()) {
start.setTime(QTime(0,0,0,0));
}
KDateTime end = endDate.toUtc();
if (end.isDateOnly()) {
end.addDays(1);
end.setTime(QTime(0,0,0,0)); //The window is inclusive
}
//TODO try to merge that with KCalCore::Freebusy
std::vector<Kolab::FreebusyPeriod> freebusyPeriods;
Q_FOREACH (KCalCore::Event::Ptr event, events) {
// If this event is transparent it shouldn't be in the freebusy list.
if ( event->transparency() == KCalCore::Event::Transparent ) {
continue;
}
if ( event->hasRecurrenceId() ) {
continue; //TODO apply special period exception (duration could be different)
}
const KDateTime eventStart = event->dtStart().toUtc();
const KDateTime eventEnd = event->dtEnd().toUtc();
std::vector <Kolab::Period> periods;
if ( event->recurs() ) {
const KCalCore::Duration duration( eventStart, eventEnd );
const KCalCore::DateTimeList list = event->recurrence()->timesInInterval(start, end);
Q_FOREACH (const KDateTime &dt, list) {
const KDateTime utc = dt.toUtc();
const Kolab::Period &period = addLocalPeriod(utc, duration.end(utc), start, end);
if (period.isValid()) {
periods.push_back(period);
}
}
} else {
const Kolab::Period &period = addLocalPeriod(eventStart, eventEnd, start, end);
if (period.isValid()) {
periods.push_back(period);
}
}
if (!periods.empty()) {
Kolab::FreebusyPeriod period;
period.setPeriods(periods);
//TODO get busy type from event (out-of-office, tentative)
period.setType(Kolab::FreebusyPeriod::Busy);
period.setEvent(event->uid().toStdString(), event->summary().toStdString(), event->location().toStdString());
freebusyPeriods.push_back(period);
}
}
Kolab::Freebusy freebusy;
freebusy.setStart(Kolab::Conversion::fromDate(start));
freebusy.setEnd(Kolab::Conversion::fromDate(end));
freebusy.setPeriods(freebusyPeriods);
freebusy.setUid(QUuid::createUuid().toString().toStdString());
freebusy.setTimestamp(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime()));
if (organizer) {
freebusy.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, organizer->email().toStdString(), organizer->name().toStdString()));
}
return freebusy;
}
Freebusy aggregateFreeBusy(const std::vector< Freebusy >& fbList, const std::string &organizerEmail, const std::string &organizerName, bool simple)
{
std::vector <Kolab::FreebusyPeriod > periods;
KDateTime start;
KDateTime end;
Q_FOREACH (const Freebusy &fb, fbList) {
const KDateTime &tmpStart = Kolab::Conversion::toDate(fb.start());
if (!start.isValid() || tmpStart < start) {
start = tmpStart;
}
const KDateTime &tmpEnd = Kolab::Conversion::toDate(fb.end());
if (!end.isValid() || tmpEnd > end) {
end = tmpEnd;
}
Q_FOREACH (const Kolab::FreebusyPeriod &period, fb.periods()) {
Kolab::FreebusyPeriod simplifiedPeriod;
simplifiedPeriod.setPeriods(period.periods());
simplifiedPeriod.setType(period.type());
if (!simple) { //Don't copy and reset to avoid unintentional information leaking into simple lists
simplifiedPeriod.setEvent(period.eventSummary(), period.eventUid(), period.eventLocation());
}
periods.push_back(simplifiedPeriod);
}
}
Freebusy aggregateFB;
aggregateFB.setStart(Kolab::Conversion::fromDate(start));
aggregateFB.setEnd(Kolab::Conversion::fromDate(end));
aggregateFB.setPeriods(periods);
aggregateFB.setUid(QUuid::createUuid().toString().toStdString());
aggregateFB.setTimestamp(Kolab::Conversion::fromDate(KDateTime::currentUtcDateTime()));
aggregateFB.setOrganizer(ContactReference(Kolab::ContactReference::EmailReference, organizerEmail, organizerName));
return aggregateFB;
}
std::string toIFB(const Kolab::Freebusy &freebusy)
{
KCalCore::FreeBusy::Ptr fb(new KCalCore::FreeBusy(Kolab::Conversion::toDate(freebusy.start()), Kolab::Conversion::toDate(freebusy.end())));
KCalCore::FreeBusyPeriod::List list;
Q_FOREACH (const Kolab::FreebusyPeriod &fbPeriod, freebusy.periods()) {
Q_FOREACH (const Kolab::Period &p, fbPeriod.periods()) {
KCalCore::FreeBusyPeriod period(Kolab::Conversion::toDate(p.start), Kolab::Conversion::toDate(p.end));
// period.setSummary("summary"); Doesn't even work. X-SUMMARY is read though (just not written out)
//TODO
list.append(period);
}
}
fb->addPeriods(list);
fb->setUid(QString::fromStdString(freebusy.uid()));
fb->setOrganizer(KCalCore::Person::Ptr(new KCalCore::Person(QString::fromStdString(freebusy.organizer().name()), QString::fromStdString(freebusy.organizer().email()))));
fb->setLastModified(Kolab::Conversion::toDate(freebusy.timestamp()));
KCalCore::ICalFormat format;
QString data = format.createScheduleMessage( fb, KCalCore::iTIPPublish );
return data.toStdString();
}
}
}
diff --git a/kolabformat/errorhandler.cpp b/kolabformat/errorhandler.cpp
index 3b2f98a..630135a 100644
--- a/kolabformat/errorhandler.cpp
+++ b/kolabformat/errorhandler.cpp
@@ -1,88 +1,94 @@
/*
* Copyright (C) 2012 Christian Mollekopf <mollekopf@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 "errorhandler.h"
#include <qdebug.h>
+#include <QTime>
+#include <QStringList>
+#include <iostream>
#include <kolabformat.h>
namespace Kolab {
void logMessage(const QString &message, const QString &file, int line, ErrorHandler::Severity s)
{
ErrorHandler::instance().addError(s, message, file+" "+QString::number(line));
}
void ErrorHandler::addError(ErrorHandler::Severity s, const QString& message, const QString &location)
{
+ QString filename = location;
+ if (!filename.split(QLatin1Char('/')).isEmpty()) {
+ filename = filename.split(QLatin1Char('/')).last();
+ }
+ const QString output = filename + QTime::currentTime().toString(QLatin1String("(hh:mm:ss)")) + QLatin1String(": ") + message;
+ std::cout << output.toStdString() << std::endl;
if (s == Debug) {
- qDebug() << location << ": " << message;
return;
- } else {
- qWarning() << location << ": " << message;
}
if (s > m_worstError) {
m_worstError = s;
m_worstErrorMessage = message;
}
m_errorQueue.append(Err(s, message, location));
}
ErrorHandler::Severity ErrorHandler::error() const
{
return m_worstError;
}
QString ErrorHandler::errorMessage() const
{
return m_worstErrorMessage;
}
const QList< ErrorHandler::Err >& ErrorHandler::getErrors() const
{
return m_errorQueue;
}
void ErrorHandler::clear()
{
m_errorQueue.clear();
m_worstError = Debug;
}
void ErrorHandler::handleLibkolabxmlErrors()
{
switch (Kolab::error()) {
case Kolab::Warning:
instance().addError(ErrorHandler::Warning, QString::fromStdString(Kolab::errorMessage()), "libkolabxml");
break;
case Kolab::Error:
instance().addError(ErrorHandler::Error, QString::fromStdString(Kolab::errorMessage()), "libkolabxml");
break;
case Kolab::Critical:
instance().addError(ErrorHandler::Critical, QString::fromStdString(Kolab::errorMessage()), "libkolabxml");
break;
default:
//Do nothing, there is no message available in this case
break;
}
}
}
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 9190b94..0b25ac5 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -1,537 +1,542 @@
/*
* Copyright (C) 2012 Christian Mollekopf <mollekopf@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 "kolabobject.h"
#include "v2helpers.h"
#include "kolabdefinitions.h"
#include "errorhandler.h"
#include "libkolab-version.h"
#include <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 <conversion/kcalconversion.h>
#include <conversion/kabcconversion.h>
#include <conversion/kolabconversion.h>
#include <akonadi/notes/noteutils.h>
#include <kolabformat.h>
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);
}
//@cond PRIVATE
class KolabObjectReader::Private
{
public:
Private()
: mObjectType( InvalidObject ),
mVersion( KolabV3 )
{
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;
KABC::ContactGroup mContactGroup;
KMime::Message::Ptr mNote;
QStringList mDictionary;
QString mDictionaryLanguage;
ObjectType mObjectType;
Version mVersion;
Kolab::Freebusy mFreebusy;
};
//@endcond
KolabObjectReader::KolabObjectReader()
: d( new KolabObjectReader::Private )
{
}
KolabObjectReader::KolabObjectReader(const KMime::Message::Ptr& msg)
: d( new KolabObjectReader::Private )
{
d->mObjectType = parseMimeMessage(msg);
}
KolabObjectReader::~KolabObjectReader()
{
delete d;
}
Kolab::ObjectType getObjectType(const QString &type)
{
if (type == eventKolabType()) {
return EventObject;
} else if (type == todoKolabType()) {
return TodoObject;
} else if (type == journalKolabType()) {
return JournalObject;
} else if (type == contactKolabType()) {
return ContactObject;
} else if (type == distlistKolabType() || type == distlistKolabTypeCompat()) {
return DistlistObject;
} else if (type == noteKolabType()) {
return NoteObject;
} else if (type == freebusyKolabType()) {
return FreebusyObject;
} else if (type.contains(dictKolabType())) { //Previous versions appended the language to the type
return DictionaryConfigurationObject;
}
return Kolab::InvalidObject;
}
QByteArray getMimeType(Kolab::ObjectType type)
{
switch (type) {
case EventObject:
case TodoObject:
case JournalObject:
case FreebusyObject:
return MIME_TYPE_XCAL;
case ContactObject:
case DistlistObject:
return MIME_TYPE_XCARD;
case NoteObject:
case DictionaryConfigurationObject:
return MIME_TYPE_KOLAB;
default:
Critical() << "unknown type "<< type;
}
return QByteArray();
}
void printMessageDebugInfo(const KMime::Message::Ptr &msg)
{
//TODO replace by Debug stream for Mimemessage
Debug() << "MessageId: " << msg->messageID()->asUnicodeString();
Debug() << "Subject: " << msg->subject()->asUnicodeString();
// 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 &note = 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();
d->mObjectType = InvalidObject;
KMime::Headers::Base *xKolabHeader = msg->getHeaderByType(X_KOLAB_TYPE_HEADER);
if (!xKolabHeader) {
CRITICAL("could not find the X-Kolab-Type Header");
printMessageDebugInfo(msg);
return InvalidObject;
}
const QString &kolabType = xKolabHeader->asUnicodeString(); //TODO we probably shouldn't use unicodeString
KMime::Headers::Base *xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER);
if (!xKolabVersion) {
//For backwards compatibility to development versions, can be removed in future versions
xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER_COMPAT);
}
if (!xKolabVersion) {
d->mVersion = KolabV2;
} else {
if (xKolabVersion->asUnicodeString() != KOLAB_VERSION_V3) { //TODO version compatibility check?
Warning() << "Kolab Version Header available but not on the same version as the implementation: " << xKolabVersion->asUnicodeString();
}
d->mVersion = KolabV3;
}
Kolab::ObjectType objectType = getObjectType(kolabType);
+ if (objectType == InvalidObject) {
+ Warning() << "invalid object type";
+ printMessageDebugInfo(msg);
+ return InvalidObject;
+ }
if (d->mVersion == KolabV2) {
return d->readKolabV2(msg, objectType, kolabType);
} else {
return d->readKolabV3(msg, objectType);
}
return InvalidObject;
}
Version KolabObjectReader::getVersion() const
{
return d->mVersion;
}
ObjectType KolabObjectReader::getType() const
{
return d->mObjectType;
}
KCalCore::Event::Ptr KolabObjectReader::getEvent() const
{
return d->mIncidence.dynamicCast<KCalCore::Event>();
}
KCalCore::Todo::Ptr KolabObjectReader::getTodo() const
{
return d->mIncidence.dynamicCast<KCalCore::Todo>();
}
KCalCore::Journal::Ptr KolabObjectReader::getJournal() const
{
return d->mIncidence.dynamicCast<KCalCore::Journal>();
}
KCalCore::Incidence::Ptr KolabObjectReader::getIncidence() const
{
return d->mIncidence;
}
KABC::Addressee KolabObjectReader::getContact() const
{
return d->mAddressee;
}
KABC::ContactGroup KolabObjectReader::getDistlist() const
{
return d->mContactGroup;
}
KMime::Message::Ptr KolabObjectReader::getNote() const
{
return d->mNote;
}
QStringList KolabObjectReader::getDictionary(QString& lang) const
{
lang = d->mDictionaryLanguage;
return d->mDictionary;
}
Freebusy KolabObjectReader::getFreebusy() const
{
return d->mFreebusy;
}
//Normalize incidences before serializing them
KCalCore::Incidence::Ptr normalizeIncidence(KCalCore::Incidence::Ptr original)
{
KCalCore::Incidence::Ptr i = KCalCore::Incidence::Ptr(original->clone()); //We copy to avoid destructive writing
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
}
return i;
}
/*
KABC::Addressee normalizeContact(const KABC::Addressee &a)
{
KABC::Addressee addresee = a;
Q_FOREACH (KCalCore::Attachment::Ptr attachment, addresee.photo()) {
attachment->setUri(QString::fromLatin1("cid:")+QString::fromLatin1(KMime::uniqueString() + '@' + "kolab.resource.akonadi")); //Serialize the attachment as attachment with uri, referencing the created mime-part
}
return i;
}*/
QString getProductId(const QString &pId)
{
if (pId.isEmpty()) {
return LIBKOLAB_LIB_VERSION_STRING;
}
return pId+" "+LIBKOLAB_LIB_VERSION_STRING;
}
KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Event::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Event>();
const Kolab::Event &incidence = Kolab::Conversion::fromKCalCore(*ic);
const std::string &v3String = Kolab::writeEvent(incidence, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(ic, xCalMimeType(), eventKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
const QString &xml = KolabV2::Event::eventToXML(i, tz);
return Mime::createMessage(i, eventKolabType(), eventKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Todo::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Todo>();
const Kolab::Todo &incidence = Kolab::Conversion::fromKCalCore(*ic);
const std::string &v3String = Kolab::writeTodo(incidence, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(ic, xCalMimeType(), todoKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
const QString &xml = KolabV2::Task::taskToXML(i, tz);
return Mime::createMessage(i, todoKolabType(), todoKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Journal::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Journal>();
const Kolab::Journal &incidence = Kolab::Conversion::fromKCalCore(*ic);
const std::string &v3String = Kolab::writeJournal(incidence, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(ic, xCalMimeType(), journalKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
const QString &xml = KolabV2::Journal::journalToXML(i, tz);
return Mime::createMessage(i, journalKolabType(), journalKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeIncidence(const KCalCore::Incidence::Ptr &i, Version v, const QString& productId, const QString& tz)
{
switch (i->type()) {
case KCalCore::IncidenceBase::TypeEvent:
return writeEvent(i.dynamicCast<KCalCore::Event>(),v,productId,tz);
case KCalCore::IncidenceBase::TypeTodo:
return writeTodo(i.dynamicCast<KCalCore::Todo>(),v,productId,tz);
case KCalCore::IncidenceBase::TypeJournal:
return writeJournal(i.dynamicCast<KCalCore::Journal>(),v,productId,tz);
default:
Critical() << "unknown incidence type";
}
return KMime::Message::Ptr();
}
KMime::Message::Ptr KolabObjectWriter::writeContact(const KABC::Addressee &addressee, Version v, const QString &productId)
{
ErrorHandler::clearErrors();
if (v == KolabV3) {
const Kolab::Contact &contact = Kolab::Conversion::fromKABC(addressee);
const std::string &v3String = Kolab::writeContact(contact, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(addressee, xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
KolabV2::Contact contact(&addressee);
return contactToKolabFormat(contact, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeDistlist(const KABC::ContactGroup &distlist, Version v, const QString &productId)
{
ErrorHandler::clearErrors();
if (v == KolabV3) {
const Kolab::DistList &dist = Kolab::Conversion::fromKABC(distlist);
const std::string &v3String = Kolab::writeDistlist(dist, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(QString::fromStdString(dist.uid()), xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
KolabV2::DistributionList d(&distlist);
return distListToKolabFormat(d, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeNote(const KMime::Message::Ptr &note, Version v, const QString &productId)
{
ErrorHandler::clearErrors();
Q_ASSERT(note.get());
if (v == KolabV3) {
const Kolab::Note &n = Kolab::Conversion::fromNote(note);
const std::string &v3String = Kolab::writeNote(n, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(QString::fromStdString(n.uid()), kolabMimeType(), noteKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
return noteToKolab(note, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeDictionary(const QStringList &entries, const QString& lang, Version v, const QString& productId)
{
ErrorHandler::clearErrors();
if (v != KolabV3) {
Critical() << "only v3 implementation available";
}
Kolab::Dictionary dictionary(lang.toStdString());
std::vector <std::string> ent;
foreach (const QString &e, entries) {
ent.push_back(e.toStdString());
}
dictionary.setEntries(ent);
Kolab::Configuration configuration(dictionary); //TODO preserve creation/lastModified date
const std::string &v3String = Kolab::writeConfiguration(configuration, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(QString::fromStdString(configuration.uid()), kolabMimeType(), dictKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, Version v, const QString& productId)
{
ErrorHandler::clearErrors();
if (v != KolabV3) {
Critical() << "only v3 implementation available";
}
const std::string &v3String = Kolab::writeFreebusy(freebusy, getProductId(productId).toStdString());
ErrorHandler::handleLibkolabxmlErrors();
return Mime::createMessage(QString::fromStdString(freebusy.uid()), xCalMimeType(), freebusyKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
}
}; //Namespace

File Metadata

Mime Type
text/x-diff
Expires
Mon, Apr 6, 1:07 AM (3 d, 40 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831801
Default Alt Text
(36 KB)

Event Timeline