From 0c881f0c1b77cf8876094e3647d1732210b954d1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Mar 2018 17:34:05 +0100 Subject: An extension mechanism load qml files at generic extension points. and forward the email via an extension api. --- framework/qml/ExtensionPoint.qml | 37 +++++++++++++++++++++++++++++++++++++ framework/qml/MailViewer.qml | 11 +++++++++-- framework/qmldir | 1 + framework/src/extensionmodel.cpp | 24 ++++++++++++++++++++---- framework/src/extensionmodel.h | 5 +++++ 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 framework/qml/ExtensionPoint.qml (limited to 'framework') diff --git a/framework/qml/ExtensionPoint.qml b/framework/qml/ExtensionPoint.qml new file mode 100644 index 00000000..4f66b20e --- /dev/null +++ b/framework/qml/ExtensionPoint.qml @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 + +import org.kube.framework 1.0 as Kube + +Repeater { + id: root + property alias extensionPoint: extensionModel.extensionPoint + property variant context: {} + + model: Kube.ExtensionModel { + id: extensionModel + } + Loader { + source: root.model.findSource(model.name, "main.qml") + onLoaded: { + item.context = root.context + } + } +} diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml index 2a1af3a6..e9759d72 100644 --- a/framework/qml/MailViewer.qml +++ b/framework/qml/MailViewer.qml @@ -348,6 +348,8 @@ Rectangle { } Item { id: footer + property var mail: model.mail + property string subject: model.subject anchors.bottom: parent.bottom @@ -373,13 +375,12 @@ Rectangle { } } - Grid { + Row { anchors { verticalCenter: parent.verticalCenter right: parent.right rightMargin: Kube.Units.largeSpacing } - columns: 2 spacing: Kube.Units.smallSpacing Kube.Button { @@ -405,6 +406,12 @@ Rectangle { } } } + Row { + Kube.ExtensionPoint { + extensionPoint: "extensions/mailview" + context: {"mail": footer.mail, "subject": footer.subject, "accountId": currentAccount} + } + } } } diff --git a/framework/qmldir b/framework/qmldir index 80146b8e..4a6f40ef 100644 --- a/framework/qmldir +++ b/framework/qmldir @@ -45,6 +45,7 @@ TreeView 1.0 TreeView.qml GridView 1.0 GridView.qml ScrollHelper 1.0 ScrollHelper.qml ModelIndexRetriever 1.0 ModelIndexRetriever.qml +ExtensionPoint 1.0 ExtensionPoint.qml singleton Messages 1.0 Messages.qml singleton Notifications 1.0 Notifications.qml singleton Colors 1.0 Colors.qml diff --git a/framework/src/extensionmodel.cpp b/framework/src/extensionmodel.cpp index e3fab7d8..5f42aa7a 100644 --- a/framework/src/extensionmodel.cpp +++ b/framework/src/extensionmodel.cpp @@ -47,12 +47,17 @@ QHash ExtensionModel::roleNames() const void ExtensionModel::load() { - auto model = new QStandardItemModel(this); - + if (auto m = sourceModel()) { + setSourceModel(nullptr); + delete m; + } auto engine = qmlEngine(this); - Q_ASSERT(engine); + if (!engine) { + return; + } + auto model = new QStandardItemModel(this); for (const auto &path : engine->importPathList()) { - QDir dir{path + "/org/kube/views"}; + QDir dir{path + "/org/kube/" + mExtensionPoint}; for (const auto &pluginName : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { const auto pluginPath = dir.path() + "/" + pluginName; mPaths.insert(pluginName, pluginPath); @@ -101,6 +106,17 @@ QVariantList ExtensionModel::sortOrder() const return {}; } +void ExtensionModel::setExtensionPoint(const QString &extensionPoint) +{ + mExtensionPoint = extensionPoint; + QTimer::singleShot(0, this, &ExtensionModel::load); +} + +QString ExtensionModel::extensionPoint() const +{ + return mExtensionPoint; +} + QVariant ExtensionModel::data(const QModelIndex &idx, int role) const { return QSortFilterProxyModel::data(idx, role); diff --git a/framework/src/extensionmodel.h b/framework/src/extensionmodel.h index 5360cc2f..07601e57 100644 --- a/framework/src/extensionmodel.h +++ b/framework/src/extensionmodel.h @@ -29,6 +29,7 @@ class ExtensionModel : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY(QVariantList sortOrder WRITE setSortOrder READ sortOrder) + Q_PROPERTY(QString extensionPoint WRITE setExtensionPoint READ extensionPoint) public: ExtensionModel(QObject *parent = Q_NULLPTR); @@ -49,6 +50,9 @@ public: void setSortOrder(const QVariantList &order); QVariantList sortOrder() const; + void setExtensionPoint(const QString &order); + QString extensionPoint() const; + Q_INVOKABLE QString findSource(const QString &extensionName, const QString &sourceName); private slots: @@ -57,6 +61,7 @@ private slots: private: QStringList mSortOrder; QHash mPaths; + QString mExtensionPoint; }; } -- cgit v1.2.3