knoteprintobject.cpp 2.61 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  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
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "knoteprintobject.h"
Laurent Montel's avatar
Laurent Montel committed
19
#include "attributes/notealarmattribute.h"
Laurent Montel's avatar
Laurent Montel committed
20
21
#include "attributes/notelockattribute.h"
#include "attributes/notelockattribute.h"
22

23
#include <KMime/KMimeMessage>
24

Laurent Montel's avatar
Laurent Montel committed
25
#include <QLocale>
26

Laurent Montel's avatar
Laurent Montel committed
27
28
#include <attributes/notedisplayattribute.h>

29
KNotePrintObject::KNotePrintObject(const Akonadi::Item &item, QObject *parent)
30
    : QObject(parent),
31
      mItem(item)
32
33
34
35
36
37
38
39
40
41
{
}

KNotePrintObject::~KNotePrintObject()
{

}

QString KNotePrintObject::description() const
{
42
    KMime::Message::Ptr noteMessage = mItem.payload<KMime::Message::Ptr>();
Laurent Montel's avatar
Laurent Montel committed
43
    if (noteMessage->contentType()->isHTMLText()) {
44
        return noteMessage->mainBodyPart()->decodedText();
45
    } else {
Laurent Montel's avatar
Laurent Montel committed
46
        return noteMessage->mainBodyPart()->decodedText().replace(QLatin1Char('\n'), QStringLiteral("<br>"));
47
    }
48
49
50
51
}

QString KNotePrintObject::name() const
{
52
    KMime::Message::Ptr noteMessage = mItem.payload<KMime::Message::Ptr>();
Laurent Montel's avatar
Laurent Montel committed
53
    const KMime::Headers::Subject *const subject = noteMessage ? noteMessage->subject(false) : Q_NULLPTR;
54
    return subject ? subject->asUnicodeString() : QString();
55
56
}

57
58
59
QString KNotePrintObject::currentDateTime() const
{
    const QDateTime now = QDateTime::currentDateTime();
Laurent Montel's avatar
Laurent Montel committed
60
    return QLocale().toString((now), QLocale::ShortFormat);
61
}
Laurent Montel's avatar
Laurent Montel committed
62
63
64
65
66
67
68
69
70
71

bool KNotePrintObject::hasAlarm() const
{
    return mItem.hasAttribute<NoteShared::NoteAlarmAttribute>();
}

QString KNotePrintObject::alarm() const
{
    NoteShared::NoteAlarmAttribute *attr = mItem.attribute<NoteShared::NoteAlarmAttribute>();
    if (attr) {
Laurent Montel's avatar
Laurent Montel committed
72
        return QLocale().toString(attr->dateTime(), QLocale::LongFormat);
Laurent Montel's avatar
Laurent Montel committed
73
74
75
    }
    return QString();
}
76
77
78
79
80

bool KNotePrintObject::isLock() const
{
    return mItem.hasAttribute<NoteShared::NoteLockAttribute>();
}
Laurent Montel's avatar
Laurent Montel committed
81
82
83
84
85
86
87
88

QString KNotePrintObject::backgroundColorName() const
{
    if (mItem.hasAttribute<NoteShared::NoteDisplayAttribute>()) {
        return mItem.attribute<NoteShared::NoteDisplayAttribute>()->backgroundColor().name();
    }
    return QString();
}