summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 15:34:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 15:34:31 +0200
commit74703d12ef6f72a057f11957181b6cf6f4730e2d (patch)
treea9126fd02863243e26fdc2881b3910b163d59c87
parent68ed477e34756beb5b152f8077c2e2527bba4708 (diff)
downloadkube-74703d12ef6f72a057f11957181b6cf6f4730e2d.tar.gz
kube-74703d12ef6f72a057f11957181b6cf6f4730e2d.zip
Added the Fabric as an in application message bus
-rw-r--r--components/kube/contents/ui/Kube.qml14
-rw-r--r--framework/qml/ConversationView.qml16
-rw-r--r--framework/qml/FolderListView.qml16
-rw-r--r--framework/qml/InlineAccountSwitcher.qml6
-rw-r--r--framework/qml/MailListView.qml32
-rw-r--r--framework/qml/Messages.qml31
-rw-r--r--framework/qmldir1
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/fabric.cpp83
-rw-r--r--framework/src/fabric.h70
-rw-r--r--framework/src/frameworkplugin.cpp11
11 files changed, 246 insertions, 35 deletions
diff --git a/components/kube/contents/ui/Kube.qml b/components/kube/contents/ui/Kube.qml
index 8537dba2..cc149e66 100644
--- a/components/kube/contents/ui/Kube.qml
+++ b/components/kube/contents/ui/Kube.qml
@@ -91,10 +91,12 @@ Controls2.ApplicationWindow {
91 //Controller 91 //Controller
92 Kube.FolderController { 92 Kube.FolderController {
93 id: folderController 93 id: folderController
94 Binding on folder { 94 }
95 //!! checks for the availability of the type 95 Kube.Listener {
96 when: !!folderListView.currentFolder 96 id: controllerListener
97 value: folderListView.currentFolder 97 filter: Kube.Messages.folderSelection
98 onMessageReceived: {
99 folderController.folder = message.folder
98 } 100 }
99 } 101 }
100 102
@@ -266,7 +268,6 @@ Controls2.ApplicationWindow {
266 268
267 Kube.MailListView { 269 Kube.MailListView {
268 id: mailListView 270 id: mailListView
269 parentFolder: accountFolderview.currentFolder
270 width: Kube.Units.gridUnit * 20 271 width: Kube.Units.gridUnit * 20
271 height: parent.height 272 height: parent.height
272 Layout.maximumWidth: app.width * 0.4 273 Layout.maximumWidth: app.width * 0.4
@@ -276,10 +277,7 @@ Controls2.ApplicationWindow {
276 277
277 Kube.ConversationView { 278 Kube.ConversationView {
278 id: mailView 279 id: mailView
279 mail: mailListView.currentMail
280 Layout.fillWidth: true 280 Layout.fillWidth: true
281 hideTrash: !accountFolderview.isTrashFolder
282 hideNonTrash: accountFolderview.isTrashFolder
283 } 281 }
284 } 282 }
285 } 283 }
diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml
index bdcd0aa0..85712a5a 100644
--- a/framework/qml/ConversationView.qml
+++ b/framework/qml/ConversationView.qml
@@ -37,6 +37,22 @@ Rectangle {
37 property bool hideTrash: true; 37 property bool hideTrash: true;
38 property bool hideNonTrash: false; 38 property bool hideNonTrash: false;
39 39
40
41 Kube.Listener {
42 filter: Kube.Messages.mailSelection
43 onMessageReceived: {
44 root.mail = message.mail
45 }
46 }
47
48 Kube.Listener {
49 filter: Kube.Messages.folderSelection
50 onMessageReceived: {
51 root.hideTrash = !message.trash
52 root.hideNonTrash = message.trash
53 }
54 }
55
40 onCurrentIndexChanged: { 56 onCurrentIndexChanged: {
41 markAsReadTimer.restart(); 57 markAsReadTimer.restart();
42 } 58 }
diff --git a/framework/qml/FolderListView.qml b/framework/qml/FolderListView.qml
index 4082e08d..78d3c5d0 100644
--- a/framework/qml/FolderListView.qml
+++ b/framework/qml/FolderListView.qml
@@ -26,18 +26,18 @@ import org.kube.framework 1.0 as Kube
26Rectangle { 26Rectangle {
27 id: root 27 id: root
28 28
29 property variant currentFolder: null
30 property variant accountId 29 property variant accountId
31 property bool isTrashFolder: false
32 30
33 color: Kube.Colors.textColor 31 color: Kube.Colors.textColor
34 32
35 Kube.FolderController { 33 Kube.FolderController {
36 id: folderController 34 id: folderController
37 Binding on folder { 35 }
38 //!! checks for the availability of the type 36 Kube.Listener {
39 when: !!root.currentFolder 37 id: controllerListener
40 value: root.currentFolder 38 filter: Kube.Messages.folderSelection
39 onMessageReceived: {
40 folderController.folder = message.folder
41 } 41 }
42 } 42 }
43 43
@@ -64,8 +64,8 @@ Rectangle {
64 64
65 onCurrentIndexChanged: { 65 onCurrentIndexChanged: {
66 model.fetchMore(currentIndex) 66 model.fetchMore(currentIndex)
67 root.currentFolder = model.data(currentIndex, Kube.FolderListModel.DomainObject) 67 Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder":model.data(currentIndex, Kube.FolderListModel.DomainObject),
68 root.isTrashFolder = model.data(currentIndex, Kube.FolderListModel.Trash) 68 "trash":model.data(currentIndex, Kube.FolderListModel.Trash)})
69 folderController.synchronizeAction.execute() 69 folderController.synchronizeAction.execute()
70 console.error(model.data) 70 console.error(model.data)
71 } 71 }
diff --git a/framework/qml/InlineAccountSwitcher.qml b/framework/qml/InlineAccountSwitcher.qml
index b7e70746..b5b4bb9f 100644
--- a/framework/qml/InlineAccountSwitcher.qml
+++ b/framework/qml/InlineAccountSwitcher.qml
@@ -24,8 +24,6 @@ Rectangle {
24 id: root 24 id: root
25 25
26 property string currentAccount: null 26 property string currentAccount: null
27 property var currentFolder: null
28 property bool isTrashFolder: false
29 27
30 Kube.AccountsModel { 28 Kube.AccountsModel {
31 id: accountsModel 29 id: accountsModel
@@ -109,10 +107,6 @@ Rectangle {
109 accountId: model.accountId 107 accountId: model.accountId
110 visible: model.accountId == root.currentAccount 108 visible: model.accountId == root.currentAccount
111 109
112 onCurrentFolderChanged: {
113 root.currentFolder = currentFolder
114 root.isTrashFolder = isTrashFolder
115 }
116 } 110 }
117 } 111 }
118 } 112 }
diff --git a/framework/qml/MailListView.qml b/framework/qml/MailListView.qml
index 96e266bb..5adc3f98 100644
--- a/framework/qml/MailListView.qml
+++ b/framework/qml/MailListView.qml
@@ -25,26 +25,25 @@ import org.kube.framework 1.0 as Kube
25 25
26Item { 26Item {
27 id: root 27 id: root
28 property variant parentFolder 28 //InterfaceProperties
29 property variant currentMail: null 29 property string filterString
30 //Private properties
31 property variant parentFolder: null
30 property bool isDraft : false 32 property bool isDraft : false
31 property bool isImportant : false 33 property bool isImportant : false
32 property bool isTrash : false 34 property bool isTrash : false
33 property bool isUnread : false 35 property bool isUnread : false
34 property int currentIndex
35 property string filterString
36 36
37 onParentFolderChanged: { 37 Kube.Listener {
38 currentMail = null 38 filter: Kube.Messages.folderSelection
39 onMessageReceived: {
40 parentFolder = message.folder
41 Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail":null})
42 }
39 } 43 }
40 44
41 Kube.MailController { 45 Kube.MailController {
42 id: mailController 46 id: mailController
43 Binding on mail {
44 //!! checks for the availability of the type
45 when: !!root.currentMail
46 value: root.currentMail
47 }
48 unread: root.isUnread 47 unread: root.isUnread
49 trash: root.isTrash 48 trash: root.isTrash
50 important: root.isImportant 49 important: root.isImportant
@@ -52,6 +51,14 @@ Item {
52 operateOnThreads: mailListModel.isThreaded 51 operateOnThreads: mailListModel.isThreaded
53 } 52 }
54 53
54 Kube.Listener {
55 id: controllerListener
56 filter: Kube.Messages.mailSelection
57 onMessageReceived: {
58 mailController.mail = message.mail
59 }
60 }
61
55 Shortcut { 62 Shortcut {
56 sequence: StandardKey.Delete 63 sequence: StandardKey.Delete
57 onActivated: mailController.moveToTrashAction.execute() 64 onActivated: mailController.moveToTrashAction.execute()
@@ -93,9 +100,8 @@ Item {
93 } 100 }
94 //END keyboard nav 101 //END keyboard nav
95 102
96 currentIndex: root.currentIndex
97 onCurrentItemChanged: { 103 onCurrentItemChanged: {
98 root.currentMail = currentItem.currentData.domainObject; 104 Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail":currentItem.currentData.mail})
99 root.isDraft = currentItem.currentData.draft; 105 root.isDraft = currentItem.currentData.draft;
100 root.isTrash = currentItem.currentData.trash; 106 root.isTrash = currentItem.currentData.trash;
101 root.isImportant = currentItem.currentData.important; 107 root.isImportant = currentItem.currentData.important;
diff --git a/framework/qml/Messages.qml b/framework/qml/Messages.qml
new file mode 100644
index 00000000..3241af0b
--- /dev/null
+++ b/framework/qml/Messages.qml
@@ -0,0 +1,31 @@
1/*
2 Copyright (C) 2017 Michael Bohlender, <bohlender@kolabsys.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19pragma Singleton
20
21import QtQuick 2.7
22
23Item {
24 //Selections
25 property string folderSelection: "currentFolder"
26 property string mailSelection: "currentMail"
27
28 //Actions
29 property string moveToTrash: "moveToTrash"
30}
31
diff --git a/framework/qmldir b/framework/qmldir
index 35d1cb62..8e969c96 100644
--- a/framework/qmldir
+++ b/framework/qmldir
@@ -20,6 +20,7 @@ ComboBox 1.0 ComboBox.qml
20PositiveButton 1.0 PositiveButton.qml 20PositiveButton 1.0 PositiveButton.qml
21TextField 1.0 TextField.qml 21TextField 1.0 TextField.qml
22Label 1.0 Label.qml 22Label 1.0 Label.qml
23singleton Messages 1.0 Messages.qml
23singleton Colors 1.0 Colors.qml 24singleton Colors 1.0 Colors.qml
24singleton Icons 1.0 Icons.qml 25singleton Icons 1.0 Icons.qml
25singleton Units 1.0 Units.qml 26singleton Units 1.0 Units.qml
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index b773748b..39f17c32 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -49,6 +49,7 @@ set(SRCS
49 accounts/accountfactory.cpp 49 accounts/accountfactory.cpp
50 accounts/accountsmodel.cpp 50 accounts/accountsmodel.cpp
51 notifications/notificationhandler.cpp 51 notifications/notificationhandler.cpp
52 fabric.cpp
52) 53)
53 54
54add_library(frameworkplugin SHARED ${SRCS}) 55add_library(frameworkplugin SHARED ${SRCS})
diff --git a/framework/src/fabric.cpp b/framework/src/fabric.cpp
new file mode 100644
index 00000000..b14ed55d
--- /dev/null
+++ b/framework/src/fabric.cpp
@@ -0,0 +1,83 @@
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 "fabric.h"
21
22#include <QDebug>
23
24namespace Kube {
25namespace Fabric {
26
27class Bus {
28public:
29 Bus() = default;
30 ~Bus() = default;
31
32 static Bus &instance()
33 {
34 static Bus bus;
35 return bus;
36 }
37
38 void registerListener(Listener *listener)
39 {
40 mListener << listener;
41 }
42
43 void unregisterListener(Listener *listener)
44 {
45 mListener.removeAll(listener);
46 }
47
48 void postMessage(const QString &id, const QVariantMap &message)
49 {
50 for (const auto &l : mListener) {
51 l->notify(id, message);
52 }
53 }
54
55private:
56 QVector<Listener*> mListener;
57};
58
59void Fabric::postMessage(const QString &id, const QVariantMap &msg)
60{
61 Bus::instance().postMessage(id, msg);
62}
63
64Listener::Listener(QObject *parent)
65 : QObject(parent)
66{
67 Bus::instance().registerListener(this);
68}
69
70Listener::~Listener()
71{
72 Bus::instance().unregisterListener(this);
73}
74
75void Listener::notify(const QString &messageId, const QVariantMap &msg)
76{
77 if (messageId == mFilter) {
78 emit messageReceived(msg);
79 }
80}
81
82}
83}
diff --git a/framework/src/fabric.h b/framework/src/fabric.h
new file mode 100644
index 00000000..764c42b1
--- /dev/null
+++ b/framework/src/fabric.h
@@ -0,0 +1,70 @@
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 <QVector>
24
25namespace Kube {
26/**
27 * The Fabric is a publish/subscribe message bus to interconnect components in kube.
28 *
29 * It provides a background mesh ("the fabric"), that interconnects various parts of kube.
30 * This is useful as it allows us to decouple functionality from the UI components, and keeps us from writing unnecessary API
31 * for visual components to pass through all necessary information for interaction.
32 */
33namespace Fabric {
34
35class Fabric : public QObject {
36 Q_OBJECT
37public:
38 Q_INVOKABLE void postMessage(const QString &id, const QVariantMap &);
39};
40
41/**
42 * A message handler.
43 *
44 * Can beinstantiated from QML like so:
45 * Listener {
46 * function onMessageReceived(msg) {
47 * ...do something
48 * }
49 * }
50 */
51class Listener : public QObject
52{
53 Q_OBJECT
54 Q_PROPERTY(QString filter MEMBER mFilter)
55
56public:
57 Listener(QObject *parent = 0);
58 virtual ~Listener();
59
60 virtual void notify(const QString &id, const QVariantMap &notification);
61
62signals:
63 void messageReceived(const QVariantMap &message);
64
65private:
66 QString mFilter;
67};
68
69}
70}
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index f491bae7..4c17242f 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -40,9 +40,17 @@
40#include "actions/context.h" 40#include "actions/context.h"
41#include "actions/actionhandler.h" 41#include "actions/actionhandler.h"
42#include "actions/actionresult.h" 42#include "actions/actionresult.h"
43#include "fabric.h"
43 44
44#include <QtQml> 45#include <QtQml>
45 46
47static QObject *example_qobject_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
48{
49 Q_UNUSED(engine)
50 Q_UNUSED(scriptEngine)
51 return new Kube::Fabric::Fabric;
52}
53
46void FrameworkPlugin::registerTypes (const char *uri) 54void FrameworkPlugin::registerTypes (const char *uri)
47{ 55{
48 qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); 56 qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel");
@@ -69,4 +77,7 @@ void FrameworkPlugin::registerTypes (const char *uri)
69 qmlRegisterType<Kube::Action>(uri, 1, 0, "Action"); 77 qmlRegisterType<Kube::Action>(uri, 1, 0, "Action");
70 qmlRegisterType<Kube::ActionHandler>(uri, 1, 0, "ActionHandler"); 78 qmlRegisterType<Kube::ActionHandler>(uri, 1, 0, "ActionHandler");
71 qmlRegisterType<Kube::ActionResult>(uri, 1, 0, "ActionResult"); 79 qmlRegisterType<Kube::ActionResult>(uri, 1, 0, "ActionResult");
80
81 qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener");
82 qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", example_qobject_singletontype_provider);
72} 83}