Page MenuHomePhorge

kolabconversion.cpp
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

kolabconversion.cpp

/*
* 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 "kolabconversion.h"
#include "commonconversion.h"
#include <akonadi/notes/noteutils.h>
namespace Kolab {
namespace Conversion {
Note fromNote(const KMime::Message::Ptr &m)
{
Akonadi::NoteUtils::NoteMessageWrapper note(m);
Note n;
n.setSummary(note.title().toStdString());
n.setDescription(note.text().toStdString());
KDateTime created = note.creationDate();
created.setTimeSpec(KDateTime::UTC);
n.setCreated(fromDate(created));
// #if KDEPIMLIBS_VERSION >= 0x040840
#ifdef KDEPIMLIBS_VERSION_DEVEL
n.setUid(note.uid().toStdString());
KDateTime lastModified = note.lastModifiedDate();
lastModified.setTimeSpec(KDateTime::UTC);
n.setLastModified(fromDate(lastModified));
switch (note.classification()) {
case Akonadi::NoteUtils::NoteMessageWrapper::Confidential:
n.setClassification(Kolab::ClassConfidential);
break;
case Akonadi::NoteUtils::NoteMessageWrapper::Private:
n.setClassification(Kolab::ClassPrivate);
break;
default:
n.setClassification(Kolab::ClassPublic);
}
std::vector<Kolab::CustomProperty> customs;
for (QMap <QString, QString >::const_iterator it = note.custom().begin(); it != note.custom().end(); it ++) {
customs.push_back(Kolab::CustomProperty(it.key().toStdString(), it.value().toStdString()));
}
n.setCustomProperties(customs);
std::vector<Kolab::Attachment> attachments;
foreach(const Akonadi::NoteUtils::Attachment &a, note.attachments()) {
Kolab::Attachment attachment;
if (a.url().isValid()) {
attachment.setUri(a.url().toString().toStdString(), a.mimetype().toStdString());
} else {
attachment.setData(QString(a.data()).toStdString(), a.mimetype().toStdString());
}
attachment.setLabel(a.label().toStdString());
attachments.push_back(attachment);
}
n.setAttachments(attachments);
#endif
return n;
}
KMime::Message::Ptr toNote(const Note &n)
{
Akonadi::NoteUtils::NoteMessageWrapper note;
note.setTitle(QString::fromStdString(n.summary()));
note.setText(QString::fromStdString(n.description()));
note.setFrom("kolab@kde4");
note.setCreationDate(toDate(n.created()));
#ifdef KDEPIMLIBS_VERSION_DEVEL
note.setUid(QString::fromStdString(n.uid()));
note.setLastModifiedDate(toDate(n.lastModified()));
switch (n.classification()) {
case Kolab::ClassPrivate:
note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Private);
break;
case Kolab::ClassConfidential:
note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Confidential);
break;
default:
note.setClassification(Akonadi::NoteUtils::NoteMessageWrapper::Public);
}
foreach (const Kolab::Attachment &a, n.attachments()) {
if (!a.uri().empty()) {
Akonadi::NoteUtils::Attachment attachment(QUrl(QString::fromStdString(a.uri())), QString::fromStdString(a.mimetype()));
attachment.setLabel(QString::fromStdString(a.label()));
note.attachments().append(attachment);
} else {
Akonadi::NoteUtils::Attachment attachment(QString::fromStdString(a.data()).toLatin1(), QString::fromStdString(a.mimetype()));
attachment.setLabel(QString::fromStdString(a.label()));
note.attachments().append(attachment);
}
}
foreach (const Kolab::CustomProperty &a, n.customProperties()) {
note.custom().insert(QString::fromStdString(a.identifier), QString::fromStdString(a.value));
}
#endif
return note.message();
}
}
}

File Metadata

Mime Type
text/x-c++
Expires
Sat, Apr 4, 2:41 AM (4 d, 23 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0f/dd/58d9ce834222aabb13aa1b9986b4
Default Alt Text
kolabconversion.cpp (4 KB)

Event Timeline