Commit c8d5c23d authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Concentrate sources information by the source section header

Summary:
Instead of having a huge unbearable toolbar on top.
Still help is left there, I'd move it away in a different iteration of the
patch.

Reviewers: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9517
parent 01deaa8c
......@@ -35,7 +35,7 @@
#include <UpdateModel/UpdateModel.h>
#include <ScreenshotsModel.h>
#include <ApplicationAddonsModel.h>
#include <MessageActionsModel.h>
#include <ActionsModel.h>
#include <qqml.h>
#include <QQmlEngine>
#include <QQmlContext>
......@@ -60,7 +60,7 @@ void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
qmlRegisterType<ReviewsModel>("org.kde.discover", 2, 0, "ReviewsModel");
qmlRegisterType<ApplicationAddonsModel>("org.kde.discover", 2, 0, "ApplicationAddonsModel");
qmlRegisterType<ScreenshotsModel>("org.kde.discover", 2, 0, "ScreenshotsModel");
qmlRegisterType<MessageActionsModel>("org.kde.discover", 2, 0, "MessageActionsModel");
qmlRegisterType<ActionsModel>("org.kde.discover", 2, 0, "ActionsModel");
qmlRegisterType<UpdateModel>("org.kde.discover", 2, 0, "UpdateModel");
qmlRegisterUncreatableType<QAction>("org.kde.discover", 2, 0, "QAction", QStringLiteral("Use QQC Action"));
......@@ -73,4 +73,5 @@ void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
qmlRegisterType<Category>();
qmlRegisterType<ResourcesModel>();
qmlProtectModule("org.kde.discover", 2);
qRegisterMetaType<QList<QAction*>>();
}
......@@ -23,27 +23,6 @@ DiscoverPage {
target: sourceBackend
onPassiveMessage: window.showPassiveNotification(message)
}
readonly property var b: AddSourceDialog {
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 +42,84 @@ DiscoverPage {
}
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: settingsButton.isDefault ? i18n("%1 (Default)", section) : section
}
ToolButton {
id: settingsButton
iconName: "preferences-other"
readonly property QtObject backend: SourcesModel.backendForSection(section)
readonly property bool isDefault: ResourcesModel.currentApplicationBackend == settingsButton.backend.resourcesBackend
visible: backend
AddSourceDialog {
id: addSourceDialog
source: settingsButton.backend
}
menu: Menu {
id: settingsMenu
MenuItem {
enabled: !settingsButton.isDefault
text: i18n("Make default")
onTriggered: ResourcesModel.currentApplicationBackend = settingsButton.backend.resourcesBackend
}
MenuItem {
text: i18n("Add Source")
onTriggered: addSourceDialog.open()
}
MenuSeparator {
visible: messageActionsInst.count>0
}
Instantiator {
id: messageActionsInst
model: ActionsModel {
actions: settingsButton.backend ? settingsButton.backend.resourcesBackend.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 +140,6 @@ DiscoverPage {
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 +161,6 @@ DiscoverPage {
}
}
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 {
......
......@@ -18,41 +18,52 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "MessageActionsModel.h"
#include "ActionsModel.h"
#include "resources/ResourcesModel.h"
#include "utils.h"
#include <QAction>
MessageActionsModel::MessageActionsModel(QObject* parent)
ActionsModel::ActionsModel(QObject* parent)
: QAbstractListModel(parent)
, m_priority(-1)
{
connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &MessageActionsModel::reload);
connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &ActionsModel::reload);
}
QHash< int, QByteArray > MessageActionsModel::roleNames() const
QHash< int, QByteArray > ActionsModel::roleNames() const
{
return { { Qt::UserRole, "action" }};
}
QVariant MessageActionsModel::data(const QModelIndex& index, int role) const
QVariant ActionsModel::data(const QModelIndex& index, int role) const
{
if(!index.isValid() || role!=Qt::UserRole)
return QVariant();
return QVariant::fromValue<QObject*>(m_actions[index.row()]);
}
int MessageActionsModel::rowCount(const QModelIndex& parent) const
int ActionsModel::rowCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : m_actions.count();
}
void MessageActionsModel::reload()
void ActionsModel::setActions(const QList<QAction *>& actions)
{
auto actions = ResourcesModel::global()->messageActions();
if (m_actions == actions) {
return;
}
reload();
Q_EMIT actionsChanged(m_actions);
}
void ActionsModel::reload()
{
auto actions = m_filteredActions;
if (m_priority>=0) {
actions = kFilter<QList<QAction*>>(actions, [this](QAction* action){ return action->priority() == m_priority; });
}
actions = kFilter<QList<QAction*>>(actions, [](QAction* action){ return action->isVisible(); });
if (actions == m_actions)
return;
......@@ -61,20 +72,15 @@ void MessageActionsModel::reload()
endResetModel();
}
int MessageActionsModel::filterPriority() const
int ActionsModel::filterPriority() const
{
return m_priority;
}
void MessageActionsModel::setFilterPriority(int p)
void ActionsModel::setFilterPriority(int p)
{
if (m_priority != p) {
m_priority = p;
reload();
}
}
void MessageActionsModel::componentComplete()
{
reload();
}
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef MESSAGEACTIONSMODEL_H
#define MESSAGEACTIONSMODEL_H
#ifndef ACTIONSMODEL_H
#define ACTIONSMODEL_H
#include <QAbstractListModel>
#include <QQmlParserStatus>
......@@ -27,13 +27,13 @@
class QAction;
class DISCOVERCOMMON_EXPORT MessageActionsModel : public QAbstractListModel, public QQmlParserStatus
class DISCOVERCOMMON_EXPORT ActionsModel : public QAbstractListModel
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QList<QAction*> actions READ actions WRITE setActions NOTIFY actionsChanged)
Q_PROPERTY(int filterPriority READ filterPriority WRITE setFilterPriority)
public:
explicit MessageActionsModel(QObject* parent = nullptr);
explicit ActionsModel(QObject* parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex& index, int role) const override;
......@@ -42,13 +42,17 @@ class DISCOVERCOMMON_EXPORT MessageActionsModel : public QAbstractListModel, pub
void setFilterPriority(int p);
int filterPriority() const;
void classBegin() override {}
void componentComplete() override;
void setActions(const QList<QAction*>& actions);
QList<QAction*> actions() const { return m_actions; }
Q_SIGNALS:
void actionsChanged(const QList<QAction*>& actions);
private:
void reload();
QList<QAction*> m_actions;
QList<QAction*> m_filteredActions;
int m_priority;
};
......
......@@ -30,7 +30,7 @@ set(discovercommon_SRCS
resources/AbstractSourcesBackend.cpp
resources/StoredResultsStream.cpp
CachedNetworkAccessManager.cpp
MessageActionsModel
ActionsModel.cpp
DiscoverBackendsFactory.cpp
ScreenshotsModel.cpp
ApplicationAddonsModel.cpp
......
......@@ -22,7 +22,7 @@
#include <QDebug>
#include <QAction>
DummySourcesBackend::DummySourcesBackend(QObject* parent)
DummySourcesBackend::DummySourcesBackend(AbstractResourcesBackend * parent)
: AbstractSourcesBackend(parent)
, m_sources(new QStandardItemModel(this))
, m_testAction(new QAction(QIcon::fromTheme(QStringLiteral("kalgebra")), QStringLiteral("DummyAction"), this))
......
......@@ -27,7 +27,7 @@
class DummySourcesBackend : public AbstractSourcesBackend
{
public:
explicit DummySourcesBackend(QObject* parent);
explicit DummySourcesBackend(AbstractResourcesBackend * parent);
QAbstractItemModel* sources() override;
bool addSource(const QString& id) override;
......
......@@ -44,7 +44,7 @@ private:
FlatpakInstallation *m_installation;
};
FlatpakSourcesBackend::FlatpakSourcesBackend(const QVector<FlatpakInstallation *> &installations, QObject* parent)
FlatpakSourcesBackend::FlatpakSourcesBackend(const QVector<FlatpakInstallation *> &installations, AbstractResourcesBackend * parent)
: AbstractSourcesBackend(parent)
, m_preferredInstallation(installations.constFirst())
, m_sources(new QStandardItemModel(this))
......
......@@ -33,7 +33,7 @@ class FlatpakResource;
class FlatpakSourcesBackend : public AbstractSourcesBackend
{
public:
explicit FlatpakSourcesBackend(const QVector<FlatpakInstallation *>& installations, QObject *parent);
explicit FlatpakSourcesBackend(const QVector<FlatpakInstallation *>& installations, AbstractResourcesBackend *parent);
QAbstractItemModel* sources() override;
bool addSource(const QString &id) override;
......
......@@ -24,6 +24,7 @@
#include <PackageKit/Transaction>
#include <PackageKit/Daemon>
#include <QDebug>
#include <resources/AbstractResourcesBackend.h>
class PKSourcesModel : public QStandardItemModel
{
......@@ -67,7 +68,7 @@ private:
PackageKitSourcesBackend* m_backend;
};
PackageKitSourcesBackend::PackageKitSourcesBackend(QObject* parent)
PackageKitSourcesBackend::PackageKitSourcesBackend(AbstractResourcesBackend* parent)
: AbstractSourcesBackend(parent)
, m_sources(new PKSourcesModel(this))
{
......@@ -77,7 +78,7 @@ PackageKitSourcesBackend::PackageKitSourcesBackend(QObject* parent)
QString PackageKitSourcesBackend::name() const
{
return i18n("Software Management");
return resourcesBackend()->displayName();
}
QString PackageKitSourcesBackend::idDescription()
......
......@@ -31,7 +31,7 @@ class PackageKitSourcesBackend : public AbstractSourcesBackend
{
Q_OBJECT
public:
PackageKitSourcesBackend(QObject* parent);
PackageKitSourcesBackend(AbstractResourcesBackend* parent);
QString name() const override;
QString idDescription() override;
......
......@@ -77,6 +77,7 @@ class DISCOVERCOMMON_EXPORT AbstractResourcesBackend : public QObject
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<QAction*> messageActions READ messageActions CONSTANT)
public:
/**
* Constructs an AbstractResourcesBackend
......
......@@ -19,9 +19,16 @@
***************************************************************************/
#include "AbstractSourcesBackend.h"
#include "AbstractResourcesBackend.h"
AbstractSourcesBackend::AbstractSourcesBackend(QObject* parent)
AbstractSourcesBackend::AbstractSourcesBackend(AbstractResourcesBackend* parent)
: QObject(parent)
{}
AbstractSourcesBackend::~AbstractSourcesBackend() = default;
AbstractResourcesBackend * AbstractSourcesBackend::resourcesBackend() const
{
return dynamic_cast<AbstractResourcesBackend*>(parent());
}
......@@ -26,14 +26,18 @@
class QAction;
class QAbstractItemModel;
class AbstractResourcesBackend;
class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
{
Q_OBJECT
Q_PROPERTY(AbstractResourcesBackend* resourcesBackend READ resourcesBackend CONSTANT)
Q_PROPERTY(QAbstractItemModel* sources READ sources CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString idDescription READ idDescription CONSTANT)
Q_PROPERTY(QList<QAction*> actions READ actions CONSTANT)
public:
explicit AbstractSourcesBackend(QObject* parent);
explicit AbstractSourcesBackend(AbstractResourcesBackend* parent);
~AbstractSourcesBackend() override;
enum Roles {
......@@ -51,6 +55,8 @@ class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
virtual QAbstractItemModel* sources() = 0;
virtual QList<QAction*> actions() const = 0;
AbstractResourcesBackend* resourcesBackend() const;
Q_SIGNALS:
void passiveMessage(const QString &message);
};
......
......@@ -83,12 +83,14 @@ int SourcesModel::rowCount(const QModelIndex& parent) const
return parent.isValid() ? 0 : m_sources.count();
}
QList<QObject*> SourcesModel::actions() const
QObject * SourcesModel::backendForSection(const QString& status) const
{
QList<QObject*> 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;
}
......@@ -32,7 +32,6 @@ class DISCOVERCOMMON_EXPORT SourcesModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY sourcesChanged)
Q_PROPERTY(QList<QObject*> actions READ actions NOTIFY sourcesChanged)
public:
enum Roles {
SourceBackend = Qt::UserRole+1
......@@ -47,7 +46,8 @@ class DISCOVERCOMMON_EXPORT SourcesModel : public QAbstractListModel
void addSourcesBackend(AbstractSourcesBackend* sources);
QHash<int, QByteArray> roleNames() const override;
QList<QObject*> actions() const;
public Q_SLOTS:
QObject* backendForSection(const QString &status) const;
Q_SIGNALS:
void sourcesChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment