summaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/CMakeLists.txt2
-rw-r--r--framework/notifications/CMakeLists.txt12
-rw-r--r--framework/notifications/notificationhandler.cpp63
-rw-r--r--framework/notifications/notificationhandler.h80
-rw-r--r--framework/notifications/notificationplugin.cpp30
-rw-r--r--framework/notifications/notificationplugin.h31
-rw-r--r--framework/notifications/qmldir3
7 files changed, 221 insertions, 0 deletions
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index aa2362f1..d14360b4 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -41,5 +41,7 @@ add_subdirectory(settings)
41add_subdirectory(domain) 41add_subdirectory(domain)
42# The accounts framework 42# The accounts framework
43add_subdirectory(accounts) 43add_subdirectory(accounts)
44# The notifications framework
45add_subdirectory(notifications)
44 46
45feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 47feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/framework/notifications/CMakeLists.txt b/framework/notifications/CMakeLists.txt
new file mode 100644
index 00000000..ec2f52c2
--- /dev/null
+++ b/framework/notifications/CMakeLists.txt
@@ -0,0 +1,12 @@
1set(SRCS
2 notificationplugin.cpp
3 notificationhandler.cpp
4)
5
6add_library(notificationplugin SHARED ${SRCS})
7
8target_link_libraries(notificationplugin sink)
9qt5_use_modules(notificationplugin Core Quick Qml)
10
11install(TARGETS notificationplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/notifications)
12install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/notifications)
diff --git a/framework/notifications/notificationhandler.cpp b/framework/notifications/notificationhandler.cpp
new file mode 100644
index 00000000..23aa3da1
--- /dev/null
+++ b/framework/notifications/notificationhandler.cpp
@@ -0,0 +1,63 @@
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 n.mMessage = notification.message;
48 } else if (notification.type == Sink::Notification::Status) {
49 if (notification.code == Sink::ApplicationDomain::ErrorStatus) {
50 //A resource entered error status
51 n.mType = Notification::Warning;
52 n.mMessage = notification.message;
53 }
54 } else if (notification.type == Sink::Notification::Info) {
55 n.mType = Notification::Info;
56 n.mMessage = notification.message;
57 } else {
58 return;
59 }
60 //The base implementation to call the handler in QML
61 QMetaObject::invokeMethod(this, "handler", Q_ARG(QVariant, QVariant::fromValue(&n)));
62}
63
diff --git a/framework/notifications/notificationhandler.h b/framework/notifications/notificationhandler.h
new file mode 100644
index 00000000..fa992e87
--- /dev/null
+++ b/framework/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
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*);
diff --git a/framework/notifications/notificationplugin.cpp b/framework/notifications/notificationplugin.cpp
new file mode 100644
index 00000000..a7a9aa5b
--- /dev/null
+++ b/framework/notifications/notificationplugin.cpp
@@ -0,0 +1,30 @@
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#include "notificationplugin.h"
20
21#include "notificationhandler.h"
22
23#include <QtQml>
24
25void NotificationPlugin::registerTypes (const char *uri)
26{
27 Q_ASSERT(uri == QLatin1String("org.kube.framework.notifications"));
28 qmlRegisterType<Kube::NotificationHandler>(uri, 1, 0, "NotificationHandler");
29 qmlRegisterType<Kube::Notification>(uri, 1, 0, "Notification");
30}
diff --git a/framework/notifications/notificationplugin.h b/framework/notifications/notificationplugin.h
new file mode 100644
index 00000000..9aa0e033
--- /dev/null
+++ b/framework/notifications/notificationplugin.h
@@ -0,0 +1,31 @@
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 <QQmlEngine>
22#include <QQmlExtensionPlugin>
23
24class NotificationPlugin : public QQmlExtensionPlugin
25{
26 Q_OBJECT
27 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28
29public:
30 virtual void registerTypes(const char *uri);
31};
diff --git a/framework/notifications/qmldir b/framework/notifications/qmldir
new file mode 100644
index 00000000..4eaad10c
--- /dev/null
+++ b/framework/notifications/qmldir
@@ -0,0 +1,3 @@
1module org.kube.framework.notifications
2
3plugin notificationplugin