1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef V2HELPERS_H
#define 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 <kcontacts/contactgroup.h>
#include <kcontacts/addressee.h>
#include <KCalendarCore/Incidence>
#include <kcalendarcore/event.h>
#include <kmime/kmime_message.h>
#include <qdom.h>
#include <akonadi/notes/noteutils.h>
namespace Kolab {
/*
* Parse XML, create KCalendarCore container and extract attachments
*/
template<typename KCalPtr, typename Container>
static KCalPtr fromXML(const QByteArray &xmlData, QStringList &attachments)
{
const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument(QString::fromUtf8(xmlData)); //TODO extract function from V2 format
if (xmlDoc.isNull()) {
Critical() << "Failed to read the xml document";
return KCalPtr();
}
const KCalPtr i = Container::fromXml(xmlDoc, QString()); //For parsing we don't need the timezone, so we don't set one
Q_ASSERT(i);
const QDomNodeList nodes = xmlDoc.elementsByTagName(QStringLiteral("inline-attachment"));
for (int i = 0; i < nodes.size(); i++) {
attachments.append(nodes.at(i).toElement().text());
}
return i;
}
void getAttachments(KCalendarCore::Incidence::Ptr incidence, const QStringList &attachments, const KMime::Message::Ptr &mimeData);
template<typename IncidencePtr, typename Converter>
static inline IncidencePtr incidenceFromKolabImpl(const KMime::Message::Ptr &data, const QByteArray &mimetype, const QString &timezoneId)
{
KMime::Content *xmlContent = Mime::findContentByType(data, mimetype);
if (!xmlContent) {
Critical() << "couldn't find part";
return IncidencePtr();
}
const QByteArray &xmlData = xmlContent->decodedContent();
QStringList attachments;
IncidencePtr ptr = fromXML<IncidencePtr, Converter>(xmlData, attachments); //TODO do we care about timezone?
getAttachments(ptr, attachments, data);
return ptr;
}
KContacts::Addressee addresseeFromKolab(const QByteArray &xmlData, const KMime::Message::Ptr &data);
KContacts::Addressee addresseeFromKolab(const QByteArray &xmlData, QString &pictureAttachmentName, QString &logoAttachmentName, QString &soundAttachmentName);
KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact &contact, const QString &productId);
KContacts::ContactGroup contactGroupFromKolab(const QByteArray &xmlData);
KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList &distList, const QString &productId);
KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const QDateTime &creationDate);
KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr &msg, const QString &productId);
QByteArray noteToKolabXML(const KMime::Message::Ptr &msg);
QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language);
}
#endif
|