diff options
Diffstat (limited to 'framework/src/notifications')
-rw-r--r-- | framework/src/notifications/notificationhandler.cpp | 80 | ||||
-rw-r--r-- | framework/src/notifications/notificationhandler.h | 80 |
2 files changed, 0 insertions, 160 deletions
diff --git a/framework/src/notifications/notificationhandler.cpp b/framework/src/notifications/notificationhandler.cpp deleted file mode 100644 index 093d638a..00000000 --- a/framework/src/notifications/notificationhandler.cpp +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
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 | |||
20 | #include "notificationhandler.h" | ||
21 | |||
22 | #include <QDebug> | ||
23 | |||
24 | #include <sink/notifier.h> | ||
25 | #include <sink/notification.h> | ||
26 | #include <sink/query.h> | ||
27 | |||
28 | using namespace Kube; | ||
29 | |||
30 | NotificationHandler::NotificationHandler(QObject *parent) | ||
31 | : QObject(parent) | ||
32 | { | ||
33 | Sink::Query query{Sink::Query::LiveQuery}; | ||
34 | mNotifier.reset(new Sink::Notifier{query}); | ||
35 | mNotifier->registerHandler([this] (const Sink::Notification ¬ification) { | ||
36 | notify(notification); | ||
37 | }); | ||
38 | |||
39 | } | ||
40 | |||
41 | void NotificationHandler::notify(const Sink::Notification ¬ification) | ||
42 | { | ||
43 | Notification n; | ||
44 | qWarning() << "Received notification: " << notification; | ||
45 | if (notification.type == Sink::Notification::Warning) { | ||
46 | n.mType = Notification::Warning; | ||
47 | if (notification.code == Sink::ApplicationDomain::TransmissionError) { | ||
48 | n.mMessage = "Failed to send message."; | ||
49 | } else { | ||
50 | return; | ||
51 | } | ||
52 | } else if (notification.type == Sink::Notification::Status) { | ||
53 | if (notification.code == Sink::ApplicationDomain::ErrorStatus) { | ||
54 | //A resource entered error status | ||
55 | n.mType = Notification::Warning; | ||
56 | n.mMessage = "A resource experienced an error."; | ||
57 | } else { | ||
58 | return; | ||
59 | } | ||
60 | } else if (notification.type == Sink::Notification::Error) { | ||
61 | if (notification.code == Sink::ApplicationDomain::ConnectionError) { | ||
62 | n.mType = Notification::Warning; | ||
63 | n.mMessage = "Failed to connect to server."; | ||
64 | } else { | ||
65 | return; | ||
66 | } | ||
67 | } else if (notification.type == Sink::Notification::Info) { | ||
68 | n.mType = Notification::Info; | ||
69 | if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { | ||
70 | n.mMessage = "A message has been sent."; | ||
71 | } else { | ||
72 | return; | ||
73 | } | ||
74 | } else { | ||
75 | return; | ||
76 | } | ||
77 | //The base implementation to call the handler in QML | ||
78 | QMetaObject::invokeMethod(this, "handler", Q_ARG(QVariant, QVariant::fromValue(&n))); | ||
79 | } | ||
80 | |||
diff --git a/framework/src/notifications/notificationhandler.h b/framework/src/notifications/notificationhandler.h deleted file mode 100644 index fa992e87..00000000 --- a/framework/src/notifications/notificationhandler.h +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
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*); | ||