Debian Codegraph @

Dekko/components/LogRecorder.h

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef LOGRECORDER_H
19 #define LOGRECORDER_H
20
21 #include <QObject>
22 #include <QmlObjectListModel.h>
23 //#include <QQmlAutoPropertyHelpers.h>
24 #include <QtQuick>
25 #include <QQmlEngine>
26 #include <QJSEngine>
27
28 class LogMessage : public QObject
29 {
30 Q_OBJECT
31 Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
32 QString m_message;
33
34 public:
35 explicit LogMessage(QObject *parent = 0) : QObject(parent){}
36 QString message() const
37 {
38 return m_message;
39 }
40 public slots:
41 void setMessage(QString message)
42 {
43 if (m_message == message)
44 return;
45
46 m_message = message;
47 emit messageChanged(message);
48 }
49 signals:
50 void messageChanged(QString message);
51 };
52
53 class LogRecorder : public QObject
54 {
55 Q_OBJECT
56 Q_PROPERTY(QObject *model READ model NOTIFY modelChanged)
57 Q_ENUMS(Type)
58 public:
59 explicit LogRecorder(QObject *parent = 0);
60 enum Type {
61 INFO,
62 STATUS,
63 WARNING,
64 ERROR
65 };
66 QObject *model() { return m_model; }
67 static QObject *factory(QQmlEngine *engine, QJSEngine *scriptEngine);
68
69 signals:
70 void modelChanged();
71
72 public slots:
73 void logMessage(const QString &location, const int &type, const QString &message);
74
75 private:
76 QString formatMessage(const QString &location, const int &type, const QString &message);
77 QQmlObjectListModel<LogMessage> *m_model;
78 };
79
80 #endif // LOGRECORDER_H