diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-15 18:42:51 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-15 18:42:51 +0100 |
commit | 64cfb8daa16a49cd5cd4b2d2344d85db31739c0e (patch) | |
tree | d1a62e495b70bf3e97cd00b7339e019a47217ab9 | |
parent | cd82ff9946b82266c65777e141ad58916f05f4ca (diff) | |
download | kube-64cfb8daa16a49cd5cd4b2d2344d85db31739c0e.tar.gz kube-64cfb8daa16a49cd5cd4b2d2344d85db31739c0e.zip |
Start of a notifications framework
-rw-r--r-- | components/mail/contents/ui/Mail.qml | 11 | ||||
-rw-r--r-- | framework/CMakeLists.txt | 2 | ||||
-rw-r--r-- | framework/notifications/CMakeLists.txt | 12 | ||||
-rw-r--r-- | framework/notifications/notificationhandler.cpp | 63 | ||||
-rw-r--r-- | framework/notifications/notificationhandler.h | 80 | ||||
-rw-r--r-- | framework/notifications/notificationplugin.cpp | 30 | ||||
-rw-r--r-- | framework/notifications/notificationplugin.h | 31 | ||||
-rw-r--r-- | framework/notifications/qmldir | 3 |
8 files changed, 232 insertions, 0 deletions
diff --git a/components/mail/contents/ui/Mail.qml b/components/mail/contents/ui/Mail.qml index ff0e8c5c..334e5a96 100644 --- a/components/mail/contents/ui/Mail.qml +++ b/components/mail/contents/ui/Mail.qml | |||
@@ -27,6 +27,7 @@ import org.kde.kirigami 1.0 as Kirigami | |||
27 | import org.kube.framework.actions 1.0 as KubeAction | 27 | import org.kube.framework.actions 1.0 as KubeAction |
28 | import org.kube.framework.settings 1.0 as KubeSettings | 28 | import org.kube.framework.settings 1.0 as KubeSettings |
29 | import org.kube.framework.domain 1.0 as KubeFramework | 29 | import org.kube.framework.domain 1.0 as KubeFramework |
30 | import org.kube.framework.notifications 1.0 as KubeNotifications | ||
30 | import org.kube.components 1.0 as KubeComponents | 31 | import org.kube.components 1.0 as KubeComponents |
31 | import org.kube.components.accounts 1.0 as KubeAccounts | 32 | import org.kube.components.accounts 1.0 as KubeAccounts |
32 | 33 | ||
@@ -40,6 +41,16 @@ Controls2.ApplicationWindow { | |||
40 | 41 | ||
41 | visible: true | 42 | visible: true |
42 | 43 | ||
44 | KubeNotifications.NotificationHandler { | ||
45 | id: notificationHandler | ||
46 | function handler(n) { | ||
47 | console.warn("We got a notification: ", n.message) | ||
48 | if (n.type == KubeNotifications.Notification.Warning) { | ||
49 | console.warn("And it's a warning!", n.type) | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
43 | //BEGIN Actions | 54 | //BEGIN Actions |
44 | KubeAction.Context { | 55 | KubeAction.Context { |
45 | id: maillistcontext | 56 | id: maillistcontext |
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) | |||
41 | add_subdirectory(domain) | 41 | add_subdirectory(domain) |
42 | # The accounts framework | 42 | # The accounts framework |
43 | add_subdirectory(accounts) | 43 | add_subdirectory(accounts) |
44 | # The notifications framework | ||
45 | add_subdirectory(notifications) | ||
44 | 46 | ||
45 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 47 | feature_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 @@ | |||
1 | set(SRCS | ||
2 | notificationplugin.cpp | ||
3 | notificationhandler.cpp | ||
4 | ) | ||
5 | |||
6 | add_library(notificationplugin SHARED ${SRCS}) | ||
7 | |||
8 | target_link_libraries(notificationplugin sink) | ||
9 | qt5_use_modules(notificationplugin Core Quick Qml) | ||
10 | |||
11 | install(TARGETS notificationplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/notifications) | ||
12 | install(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 | |||
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 | 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 | |||
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*); | ||
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 | |||
25 | void 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 | |||
24 | class NotificationPlugin : public QQmlExtensionPlugin | ||
25 | { | ||
26 | Q_OBJECT | ||
27 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") | ||
28 | |||
29 | public: | ||
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 @@ | |||
1 | module org.kube.framework.notifications | ||
2 | |||
3 | plugin notificationplugin | ||