diff --git a/discover/DiscoverDeclarativePlugin.cpp b/discover/DiscoverDeclarativePlugin.cpp --- a/discover/DiscoverDeclarativePlugin.cpp +++ b/discover/DiscoverDeclarativePlugin.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -60,7 +60,7 @@ qmlRegisterType("org.kde.discover", 2, 0, "ReviewsModel"); qmlRegisterType("org.kde.discover", 2, 0, "ApplicationAddonsModel"); qmlRegisterType("org.kde.discover", 2, 0, "ScreenshotsModel"); - qmlRegisterType("org.kde.discover", 2, 0, "MessageActionsModel"); + qmlRegisterType("org.kde.discover", 2, 0, "ActionsModel"); qmlRegisterType("org.kde.discover", 2, 0, "UpdateModel"); qmlRegisterUncreatableType("org.kde.discover", 2, 0, "QAction", QStringLiteral("Use QQC Action")); @@ -73,4 +73,5 @@ qmlRegisterType(); qmlRegisterType(); qmlProtectModule("org.kde.discover", 2); + qRegisterMetaType>(); } diff --git a/discover/qml/SourcesPage.qml b/discover/qml/SourcesPage.qml --- a/discover/qml/SourcesPage.qml +++ b/discover/qml/SourcesPage.qml @@ -27,23 +27,6 @@ id: addSourceDialog source: sourceBackend } - - readonly property var c: MenuItem { - id: menuItem - text: sourceBackend.name - onTriggered: { - try { - addSourceDialog.open() - addSourceDialog.visible = true - } catch (e) { - console.log("error loading dialog:", e) - } - } - } - - Component.onCompleted: { - sourcesMenu.insertItem(0, menuItem) - } } onObjectAdded: { everySourceModel.addSourceModel(object.sourcesModel) @@ -63,13 +46,72 @@ } currentIndex: -1 - Menu { id: sourcesMenu } - section { property: "statusTip" - delegate: Kirigami.Heading { - leftPadding: Kirigami.Units.largeSpacing - text: section + delegate: RowLayout { + anchors { + right: parent.right + left: parent.left + } + Kirigami.Heading { + Layout.fillWidth: true + leftPadding: Kirigami.Units.largeSpacing + text: section + } + ToolButton { + id: settingsButton + iconName: "preferences-other" + readonly property QtObject backend: SourcesModel.backendForSection(section) + visible: backend + menu: Menu { + id: settingsMenu + MenuItem { + enabled: ResourcesModel.currentApplicationBackend != settingsButton.backend + text: i18n("Make default") + onTriggered: ResourcesModel.currentApplicationBackend = settingsButton.backend + } + + MenuSeparator { + visible: messageActionsInst.count>0 + } + + Instantiator { + id: messageActionsInst + model: ActionsModel { + actions: settingsButton.backend ? settingsButton.backend.parent.messageActions : null + } + delegate: MenuItem { + action: ActionBridge { action: model.action } + } + onObjectAdded: { + settingsMenu.insertItem(index, object) + } + onObjectRemoved: { + object.destroy() + } + } + + MenuSeparator { + visible: backendActionsInst.count>0 + } + + Instantiator { + id: backendActionsInst + model: ActionsModel { + actions: settingsButton.backend ? settingsButton.backend.actions : null + } + delegate: MenuItem { + action: ActionBridge { action: model.action } + } + onObjectAdded: { + settingsMenu.insertItem(index, object) + } + onObjectRemoved: { + object.destroy() + } + } + } + } } } @@ -90,43 +132,6 @@ Layout.fillWidth: true } - ToolButton { - text: i18n("Application Sources") - tooltip: i18n("Allows to choose the source that will be used for browsing applications") - menu: Menu { - id: backendsMenu - } - enabled: menu.items.length>0 - - ExclusiveGroup { - id: select - } - - Instantiator { - model: ResourcesModel.applicationBackends - delegate: MenuItem { - text: modelData.displayName - checkable: true - checked: ResourcesModel.currentApplicationBackend == modelData - onTriggered: ResourcesModel.currentApplicationBackend = modelData - exclusiveGroup: select - } - onObjectAdded: { - backendsMenu.insertItem(index, object) - } - onObjectRemoved: { - object.destroy() - } - } - } - - ToolButton { -// iconName: "list-add" - text: i18n("Add Source") - - tooltip: text - menu: sourcesMenu - } Repeater { model: SourcesModel.actions @@ -148,27 +153,6 @@ } } - ToolButton { - text: i18n("More...") - menu: Menu { - id: actionsMenu - } - enabled: menu.items.length>0 - - Instantiator { - model: MessageActionsModel {} - delegate: MenuItem { - action: ActionBridge { action: model.action } - } - onObjectAdded: { - actionsMenu.insertItem(index, object) - } - onObjectRemoved: { - object.destroy() - } - } - } - ToolButton { text: i18n("Help...") menu: Menu { diff --git a/libdiscover/CMakeLists.txt b/libdiscover/CMakeLists.txt --- a/libdiscover/CMakeLists.txt +++ b/libdiscover/CMakeLists.txt @@ -30,7 +30,7 @@ resources/AbstractSourcesBackend.cpp resources/StoredResultsStream.cpp CachedNetworkAccessManager.cpp - MessageActionsModel + ActionsModel.cpp DiscoverBackendsFactory.cpp ScreenshotsModel.cpp ApplicationAddonsModel.cpp diff --git a/libdiscover/MessageActionsModel.h b/libdiscover/MessageActionsModel.h deleted file mode 100644 --- a/libdiscover/MessageActionsModel.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright © 2014 Aleix Pol Gonzalez * - * * - * 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) version 3 or any later version * - * accepted by the membership of KDE e.V. (or its successor approved * - * by the membership of KDE e.V.), which shall act as a proxy * - * defined in Section 14 of version 3 of the license. * - * * - * 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, see . * - ***************************************************************************/ - -#ifndef MESSAGEACTIONSMODEL_H -#define MESSAGEACTIONSMODEL_H - -#include -#include -#include "discovercommon_export.h" - -class QAction; - -class DISCOVERCOMMON_EXPORT MessageActionsModel : public QAbstractListModel, public QQmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QQmlParserStatus) - Q_PROPERTY(int filterPriority READ filterPriority WRITE setFilterPriority) - public: - explicit MessageActionsModel(QObject* parent = nullptr); - - QHash roleNames() const override; - QVariant data(const QModelIndex& index, int role) const override; - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - - void setFilterPriority(int p); - int filterPriority() const; - - void classBegin() override {} - void componentComplete() override; - - private: - void reload(); - - QList m_actions; - int m_priority; -}; - -#endif diff --git a/libdiscover/MessageActionsModel.cpp b/libdiscover/MessageActionsModel.cpp deleted file mode 100644 --- a/libdiscover/MessageActionsModel.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * Copyright © 2014 Aleix Pol Gonzalez * - * * - * 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) version 3 or any later version * - * accepted by the membership of KDE e.V. (or its successor approved * - * by the membership of KDE e.V.), which shall act as a proxy * - * defined in Section 14 of version 3 of the license. * - * * - * 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, see . * - ***************************************************************************/ - -#include "MessageActionsModel.h" -#include "resources/ResourcesModel.h" -#include "utils.h" -#include - -MessageActionsModel::MessageActionsModel(QObject* parent) - : QAbstractListModel(parent) - , m_priority(-1) -{ - connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &MessageActionsModel::reload); -} - -QHash< int, QByteArray > MessageActionsModel::roleNames() const -{ - return { { Qt::UserRole, "action" }}; -} - -QVariant MessageActionsModel::data(const QModelIndex& index, int role) const -{ - if(!index.isValid() || role!=Qt::UserRole) - return QVariant(); - return QVariant::fromValue(m_actions[index.row()]); -} - -int MessageActionsModel::rowCount(const QModelIndex& parent) const -{ - return parent.isValid() ? 0 : m_actions.count(); -} - -void MessageActionsModel::reload() -{ - auto actions = ResourcesModel::global()->messageActions(); - if (m_priority>=0) { - actions = kFilter>(actions, [this](QAction* action){ return action->priority() == m_priority; }); - } - if (actions == m_actions) - return; - - beginResetModel(); - m_actions = actions; - endResetModel(); -} - -int MessageActionsModel::filterPriority() const -{ - return m_priority; -} - -void MessageActionsModel::setFilterPriority(int p) -{ - if (m_priority != p) { - m_priority = p; - reload(); - } -} - -void MessageActionsModel::componentComplete() -{ - reload(); -} diff --git a/libdiscover/resources/AbstractResourcesBackend.h b/libdiscover/resources/AbstractResourcesBackend.h --- a/libdiscover/resources/AbstractResourcesBackend.h +++ b/libdiscover/resources/AbstractResourcesBackend.h @@ -77,6 +77,7 @@ Q_PROPERTY(AbstractReviewsBackend* reviewsBackend READ reviewsBackend CONSTANT) Q_PROPERTY(int updatesCount READ updatesCount NOTIFY updatesCountChanged) Q_PROPERTY(bool isFetching READ isFetching NOTIFY fetchingChanged) + Q_PROPERTY(QList messageActions READ messageActions CONSTANT) public: /** * Constructs an AbstractResourcesBackend diff --git a/libdiscover/resources/AbstractSourcesBackend.h b/libdiscover/resources/AbstractSourcesBackend.h --- a/libdiscover/resources/AbstractSourcesBackend.h +++ b/libdiscover/resources/AbstractSourcesBackend.h @@ -32,6 +32,7 @@ Q_PROPERTY(QAbstractItemModel* sources READ sources CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString idDescription READ idDescription CONSTANT) + Q_PROPERTY(QList actions READ actions CONSTANT) public: explicit AbstractSourcesBackend(QObject* parent); ~AbstractSourcesBackend() override; diff --git a/libdiscover/resources/SourcesModel.h b/libdiscover/resources/SourcesModel.h --- a/libdiscover/resources/SourcesModel.h +++ b/libdiscover/resources/SourcesModel.h @@ -32,7 +32,6 @@ { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY sourcesChanged) - Q_PROPERTY(QList actions READ actions NOTIFY sourcesChanged) public: enum Roles { SourceBackend = Qt::UserRole+1 @@ -47,7 +46,8 @@ void addSourcesBackend(AbstractSourcesBackend* sources); QHash roleNames() const override; - QList actions() const; + public Q_SLOTS: + QObject* backendForSection(const QString &status) const; Q_SIGNALS: void sourcesChanged(); diff --git a/libdiscover/resources/SourcesModel.cpp b/libdiscover/resources/SourcesModel.cpp --- a/libdiscover/resources/SourcesModel.cpp +++ b/libdiscover/resources/SourcesModel.cpp @@ -83,12 +83,15 @@ return parent.isValid() ? 0 : m_sources.count(); } -QList SourcesModel::actions() const +QObject * SourcesModel::backendForSection(const QString& status) const { - QList ret; + AbstractSourcesBackend* ret = nullptr; for(AbstractSourcesBackend* b: m_sources) { - foreach(QAction* action, b->actions()) - ret.append(action); + if (b->name() == status) { + ret = b; + break; + } } return ret; } +