1 /*
2     This file is part of the kolab resource - the implementation of the
3     Kolab storage format. See www.kolab.org for documentation on this.
4 
5     SPDX-FileCopyrightText: 2004 Bo Thorsen <bo@sonofthor.dk>
6 
7     SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include <KCalendarCore/Journal>
13 
14 #include "kolabbase.h"
15 
16 class QDomElement;
17 
18 namespace KolabV2
19 {
20 /**
21  * This class represents a note, and knows how to load/save it
22  * from/to XML, and from/to a KCalendarCore::Journal.
23  * The instances of this class are temporary, only used to convert
24  * one to the other.
25  */
26 class Note : public KolabBase
27 {
28 public:
29     /// Use this to parse an xml string to a journal entry
30     /// The caller is responsible for deleting the returned journal
31     static KCalendarCore::Journal::Ptr xmlToJournal(const QString &xml);
32 
33     /// Use this to get an xml string describing this journal entry
34     static QString journalToXML(const KCalendarCore::Journal::Ptr &);
35 
36     /// Create a note object and
37     explicit Note(const KCalendarCore::Journal::Ptr &journal = KCalendarCore::Journal::Ptr());
38     ~Note() override;
39 
40     void saveTo(const KCalendarCore::Journal::Ptr &journal) const;
41 
type()42     QString type() const override
43     {
44         return QStringLiteral("Note");
45     }
46 
47     virtual void setSummary(const QString &summary);
48     virtual QString summary() const;
49 
50     virtual void setBackgroundColor(const QColor &bgColor);
51     virtual QColor backgroundColor() const;
52 
53     virtual void setForegroundColor(const QColor &fgColor);
54     virtual QColor foregroundColor() const;
55 
56     virtual void setRichText(bool richText);
57     virtual bool richText() const;
58 
59     // Load the attributes of this class
60     bool loadAttribute(QDomElement &) override;
61 
62     // Save the attributes of this class
63     bool saveAttributes(QDomElement &) const override;
64 
65     // Load this note by reading the XML file
66     bool loadXML(const QDomDocument &xml) override;
67 
68     // Serialize this note to an XML string
69     QString saveXML() const override;
70 
71 protected:
72     // Read all known fields from this ical incidence
73     void setFields(const KCalendarCore::Journal::Ptr &);
74 
75     // Save all known fields into this ical incidence
76     void saveTo(const KCalendarCore::Incidence::Ptr &) const;
77 
78     QString productID() const override;
79 
80     QString mSummary;
81     QColor mBackgroundColor;
82     QColor mForegroundColor;
83     bool mRichText;
84 };
85 }
86 
87