summaryrefslogtreecommitdiffstats
path: root/framework/src/notifications/notificationhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/notifications/notificationhandler.cpp')
-rw-r--r--framework/src/notifications/notificationhandler.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/framework/src/notifications/notificationhandler.cpp b/framework/src/notifications/notificationhandler.cpp
new file mode 100644
index 00000000..093d638a
--- /dev/null
+++ b/framework/src/notifications/notificationhandler.cpp
@@ -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
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
28using namespace Kube;
29
30NotificationHandler::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 &notification) {
36 notify(notification);
37 });
38
39}
40
41void NotificationHandler::notify(const Sink::Notification &notification)
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