summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 21:22:39 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 21:22:39 +0200
commit4ba8c5b72fd7a3db6e593853c4669750dc6dd2a2 (patch)
tree5d4f590ccd0993a1cc1cc225e93b3ddc82eca644
parent1d0717f90712c298e93d61dd7312498303b5db0f (diff)
downloadkube-4ba8c5b72fd7a3db6e593853c4669750dc6dd2a2.tar.gz
kube-4ba8c5b72fd7a3db6e593853c4669750dc6dd2a2.zip
Removed notification plugin
...which is replaced by the fabric
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/frameworkplugin.cpp3
-rw-r--r--framework/src/notifications/notificationhandler.cpp80
-rw-r--r--framework/src/notifications/notificationhandler.h80
4 files changed, 0 insertions, 164 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index cf971497..73e489b1 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -48,7 +48,6 @@ set(SRCS
48 domain/peoplemodel.cpp 48 domain/peoplemodel.cpp
49 accounts/accountfactory.cpp 49 accounts/accountfactory.cpp
50 accounts/accountsmodel.cpp 50 accounts/accountsmodel.cpp
51 notifications/notificationhandler.cpp
52 fabric.cpp 51 fabric.cpp
53 sinkfabric.cpp 52 sinkfabric.cpp
54) 53)
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index 4c17242f..2f77bef4 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -35,7 +35,6 @@
35#include "accounts/accountsmodel.h" 35#include "accounts/accountsmodel.h"
36#include "accounts/accountfactory.h" 36#include "accounts/accountfactory.h"
37#include "settings/settings.h" 37#include "settings/settings.h"
38#include "notifications/notificationhandler.h"
39#include "actions/action.h" 38#include "actions/action.h"
40#include "actions/context.h" 39#include "actions/context.h"
41#include "actions/actionhandler.h" 40#include "actions/actionhandler.h"
@@ -70,8 +69,6 @@ void FrameworkPlugin::registerTypes (const char *uri)
70 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); 69 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel");
71 70
72 qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); 71 qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings");
73 qmlRegisterType<Kube::NotificationHandler>(uri, 1, 0, "NotificationHandler");
74 qmlRegisterType<Kube::Notification>(uri, 1, 0, "Notification");
75 72
76 qmlRegisterType<Kube::Context>(uri, 1, 0, "Context"); 73 qmlRegisterType<Kube::Context>(uri, 1, 0, "Context");
77 qmlRegisterType<Kube::Action>(uri, 1, 0, "Action"); 74 qmlRegisterType<Kube::Action>(uri, 1, 0, "Action");
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
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
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
26namespace Sink {
27 class Notification;
28}
29
30namespace Kube {
31
32class Notification : public QObject
33{
34 Q_OBJECT
35
36public:
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 */
65class NotificationHandler : public QObject
66{
67 Q_OBJECT
68
69public:
70 NotificationHandler(QObject *parent = 0);
71
72 virtual void notify(const Sink::Notification &notification);
73
74private:
75 QScopedPointer<Sink::Notifier> mNotifier;
76};
77
78}
79
80Q_DECLARE_METATYPE(Kube::Notification*);