File: kolabconversion.cpp

package info (click to toggle)
libkolab 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,484 kB
  • ctags: 1,199
  • sloc: cpp: 10,856; php: 180; sh: 132; makefile: 27; xml: 20; ansic: 15
file content (120 lines) | stat: -rw-r--r-- 4,434 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * 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(toStdString(note.title()));
    n.setDescription(toStdString(note.text()));
    KDateTime created = note.creationDate();
    created.setTimeSpec(KDateTime::UTC);
    n.setCreated(fromDate(created));

// #if KDEPIMLIBS_VERSION >= 0x040840
#ifdef KDEPIMLIBS_VERSION_DEVEL
    n.setUid(toStdString(note.uid()));
    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;
    QMap<QString, QString> &customsMap = note.custom();
    for (QMap <QString, QString >::const_iterator it = customsMap.constBegin(); it != customsMap.constEnd(); it ++) {
        customs.push_back(Kolab::CustomProperty(toStdString(it.key()), toStdString(it.value())));
    }
    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(toStdString(a.url().toString()), toStdString(a.mimetype()));
        } else {
            attachment.setData(toStdString(QString(a.data())), toStdString(a.mimetype()));
        }
        attachment.setLabel(toStdString(a.label()));
        attachments.push_back(attachment);
    }
    n.setAttachments(attachments);

#endif
    return n;
}

KMime::Message::Ptr toNote(const Note &n)
{
    Akonadi::NoteUtils::NoteMessageWrapper note;
    note.setTitle(fromStdString(n.summary()));
    note.setText(fromStdString(n.description()));
    note.setFrom("kolab@kde4");
    note.setCreationDate(toDate(n.created()));
#ifdef KDEPIMLIBS_VERSION_DEVEL
    note.setUid(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(fromStdString(a.uri())), fromStdString(a.mimetype()));
            attachment.setLabel(fromStdString(a.label()));
            note.attachments().append(attachment);
        } else {
            Akonadi::NoteUtils::Attachment attachment(fromStdString(a.data()).toLatin1(), fromStdString(a.mimetype()));
            attachment.setLabel(fromStdString(a.label()));
            note.attachments().append(attachment);
        }
    }
    foreach (const Kolab::CustomProperty &a, n.customProperties()) {
        note.custom().insert(fromStdString(a.identifier), fromStdString(a.value));
    }
#endif
    return note.message();
}

        
    }
}