diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 19:34:26 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 19:34:26 +0100 |
commit | 2d9944bd0b5cd1dd202d9dc6318d612e1aca4241 (patch) | |
tree | d9fbc3d48937f18c35cbb1000b4310a9d6162800 | |
parent | d3e1aa3fa1d64360c9dc31edb17072f456ddfba4 (diff) | |
download | kube-2d9944bd0b5cd1dd202d9dc6318d612e1aca4241.tar.gz kube-2d9944bd0b5cd1dd202d9dc6318d612e1aca4241.zip |
Load extensions with a model
-rw-r--r-- | components/kube/qml/Kube.qml | 14 | ||||
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/extensionmodel.cpp | 74 | ||||
-rw-r--r-- | framework/src/extensionmodel.h | 52 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 2 |
5 files changed, 143 insertions, 0 deletions
diff --git a/components/kube/qml/Kube.qml b/components/kube/qml/Kube.qml index e7c4f70e..9a31ba58 100644 --- a/components/kube/qml/Kube.qml +++ b/components/kube/qml/Kube.qml | |||
@@ -204,6 +204,20 @@ Controls2.ApplicationWindow { | |||
204 | Controls2.ButtonGroup.group: viewButtonGroup | 204 | Controls2.ButtonGroup.group: viewButtonGroup |
205 | tooltip: qsTr("people") | 205 | tooltip: qsTr("people") |
206 | } | 206 | } |
207 | Repeater { | ||
208 | model: Kube.ExtensionModel {} | ||
209 | Kube.IconButton { | ||
210 | iconName: model.icon | ||
211 | onClicked: { | ||
212 | var component = Qt.createComponent(model.source) | ||
213 | kubeViews.pushView(component, {}) | ||
214 | } | ||
215 | activeFocusOnTab: true | ||
216 | checkable: true | ||
217 | Controls2.ButtonGroup.group: viewButtonGroup | ||
218 | tooltip: model.tooltip | ||
219 | } | ||
220 | } | ||
207 | } | 221 | } |
208 | Column { | 222 | Column { |
209 | anchors { | 223 | anchors { |
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 526fbefe..97cb453b 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -47,6 +47,7 @@ add_library(kubeframework SHARED | |||
47 | startupcheck.cpp | 47 | startupcheck.cpp |
48 | keyring.cpp | 48 | keyring.cpp |
49 | domainobjectcontroller.cpp | 49 | domainobjectcontroller.cpp |
50 | extensionmodel.cpp | ||
50 | ) | 51 | ) |
51 | target_link_libraries(kubeframework | 52 | target_link_libraries(kubeframework |
52 | sink | 53 | sink |
diff --git a/framework/src/extensionmodel.cpp b/framework/src/extensionmodel.cpp new file mode 100644 index 00000000..f64a0e17 --- /dev/null +++ b/framework/src/extensionmodel.cpp | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 "extensionmodel.h" | ||
20 | #include <QStandardItemModel> | ||
21 | #include <QQmlEngine> | ||
22 | #include <QDir> | ||
23 | #include <QDebug> | ||
24 | #include <QTimer> | ||
25 | |||
26 | using namespace Kube; | ||
27 | |||
28 | ExtensionModel::ExtensionModel(QObject *parent) | ||
29 | : QSortFilterProxyModel(parent) | ||
30 | { | ||
31 | QTimer::singleShot(0, this, &ExtensionModel::load); | ||
32 | } | ||
33 | |||
34 | QHash<int, QByteArray> ExtensionModel::roleNames() const | ||
35 | { | ||
36 | return { | ||
37 | {Name, "name"}, | ||
38 | {Tooltip, "tooltip"}, | ||
39 | {Icon, "icon"}, | ||
40 | {Source, "source"} | ||
41 | }; | ||
42 | } | ||
43 | |||
44 | void ExtensionModel::load() | ||
45 | { | ||
46 | auto model = new QStandardItemModel(this); | ||
47 | |||
48 | auto engine = qmlEngine(this); | ||
49 | Q_ASSERT(engine); | ||
50 | for (const auto &path : engine->importPathList()) { | ||
51 | QDir dir{path + "/org/kube/viewextensions"}; | ||
52 | for (const auto &pluginName : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { | ||
53 | auto viewPath = dir.path() + pluginName + "/View.qml"; | ||
54 | qWarning() << "Plugin path: " << dir.path() + pluginName + "/View.qml"; | ||
55 | auto item = new QStandardItem; | ||
56 | item->setData(viewPath, Source); | ||
57 | item->setData(pluginName, Name); | ||
58 | item->setData(pluginName, Tooltip); | ||
59 | item->setData("document-decrypt", Icon); | ||
60 | model->appendRow(item); | ||
61 | } | ||
62 | } | ||
63 | setSourceModel(model); | ||
64 | } | ||
65 | |||
66 | QVariant ExtensionModel::data(const QModelIndex &idx, int role) const | ||
67 | { | ||
68 | return QSortFilterProxyModel::data(idx, role); | ||
69 | } | ||
70 | |||
71 | bool ExtensionModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||
72 | { | ||
73 | return QSortFilterProxyModel::lessThan(left, right); | ||
74 | } | ||
diff --git a/framework/src/extensionmodel.h b/framework/src/extensionmodel.h new file mode 100644 index 00000000..6e984005 --- /dev/null +++ b/framework/src/extensionmodel.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 | #pragma once | ||
21 | |||
22 | #include <QSortFilterProxyModel> | ||
23 | #include <QSharedPointer> | ||
24 | |||
25 | namespace Kube { | ||
26 | |||
27 | class ExtensionModel : public QSortFilterProxyModel | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | |||
32 | ExtensionModel(QObject *parent = Q_NULLPTR); | ||
33 | ~ExtensionModel() = default; | ||
34 | |||
35 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | ||
36 | |||
37 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; | ||
38 | |||
39 | enum Roles { | ||
40 | Name = Qt::UserRole + 1, | ||
41 | Tooltip, | ||
42 | Icon, | ||
43 | Source | ||
44 | }; | ||
45 | |||
46 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | ||
47 | |||
48 | private slots: | ||
49 | void load(); | ||
50 | }; | ||
51 | |||
52 | } | ||
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index f768be1b..b0e2f9c9 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -41,6 +41,7 @@ | |||
41 | #include "keyring.h" | 41 | #include "keyring.h" |
42 | #include "controller.h" | 42 | #include "controller.h" |
43 | #include "domainobjectcontroller.h" | 43 | #include "domainobjectcontroller.h" |
44 | #include "extensionmodel.h" | ||
44 | 45 | ||
45 | #include <QtQml> | 46 | #include <QtQml> |
46 | #include <QQuickImageProvider> | 47 | #include <QQuickImageProvider> |
@@ -130,6 +131,7 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
130 | 131 | ||
131 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); | 132 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); |
132 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); | 133 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); |
134 | qmlRegisterType<Kube::ExtensionModel>(uri, 1, 0, "ExtensionModel"); | ||
133 | 135 | ||
134 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); | 136 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); |
135 | 137 | ||