diff options
Diffstat (limited to 'framework/src/notifications/notificationhandler.h')
-rw-r--r-- | framework/src/notifications/notificationhandler.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/framework/src/notifications/notificationhandler.h b/framework/src/notifications/notificationhandler.h new file mode 100644 index 00000000..fa992e87 --- /dev/null +++ b/framework/src/notifications/notificationhandler.h | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QVariant> | ||
23 | #include <functional> | ||
24 | #include <sink/notifier.h> | ||
25 | |||
26 | namespace Sink { | ||
27 | class Notification; | ||
28 | } | ||
29 | |||
30 | namespace Kube { | ||
31 | |||
32 | class Notification : public QObject | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | |||
36 | public: | ||
37 | enum Type { | ||
38 | Info, | ||
39 | Warning | ||
40 | }; | ||
41 | Q_ENUMS(Type) | ||
42 | |||
43 | Q_PROPERTY(Type type MEMBER mType CONSTANT) | ||
44 | Q_PROPERTY(QString message MEMBER mMessage CONSTANT) | ||
45 | |||
46 | Notification() = default; | ||
47 | ~Notification() = default; | ||
48 | |||
49 | Type mType; | ||
50 | QString mMessage; | ||
51 | }; | ||
52 | |||
53 | /** | ||
54 | * A notification handler. | ||
55 | * | ||
56 | * Can beinstantiated from QML like so: | ||
57 | * NotificationHandler { | ||
58 | * function handler(notification) { | ||
59 | * ...do something | ||
60 | * } | ||
61 | * } | ||
62 | * | ||
63 | * The handler will listen for all notifications by default. | ||
64 | */ | ||
65 | class NotificationHandler : public QObject | ||
66 | { | ||
67 | Q_OBJECT | ||
68 | |||
69 | public: | ||
70 | NotificationHandler(QObject *parent = 0); | ||
71 | |||
72 | virtual void notify(const Sink::Notification ¬ification); | ||
73 | |||
74 | private: | ||
75 | QScopedPointer<Sink::Notifier> mNotifier; | ||
76 | }; | ||
77 | |||
78 | } | ||
79 | |||
80 | Q_DECLARE_METATYPE(Kube::Notification*); | ||