Commit 34832649 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Sources: Move the InlineMessage out of the section delegate

It looks a bit out of place but at least it doesn't trigger all the bad
notes in ListView.
parent 5af64380
import QtQuick 2.4
import QtQuick 2.15
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
import org.kde.discover 2.0
......@@ -25,6 +25,27 @@ DiscoverPage {
contextualActions: feedbackLoader.item ? feedbackLoader.item.actions : [configureUpdatesAction]
header: ColumnLayout {
Repeater {
id: rep
model: SourcesModel.sources
delegate: Kirigami.InlineMessage {
Layout.fillWidth: true
Layout.margins: Kirigami.Units.smallSpacing
text: modelData.inlineAction.toolTip
visible: modelData.inlineAction && modelData.inlineAction.visible
actions: [
Kirigami.Action {
icon.name: modelData.inlineAction.iconName
text: modelData.inlineAction.text
onTriggered: modelData.inlineAction.trigger()
}
]
}
}
}
mainItem: ListView {
id: sourcesView
model: SourcesModel
......@@ -52,91 +73,75 @@ DiscoverPage {
}
}
contentItem: ColumnLayout {
RowLayout {
Kirigami.Heading {
text: resourcesBackend.displayName
level: 3
font.weight: backendItem.isDefault ? Font.Bold : Font.Normal
}
contentItem: RowLayout {
Kirigami.Heading {
text: resourcesBackend.displayName
level: 3
font.weight: backendItem.isDefault ? Font.Bold : Font.Normal
}
Kirigami.ActionToolBar {
id: actionBar
Kirigami.ActionToolBar {
id: actionBar
alignment: Qt.AlignRight
alignment: Qt.AlignRight
Kirigami.Action {
id: isDefaultbackendLabelAction
Kirigami.Action {
id: isDefaultbackendLabelAction
visible: backendItem.isDefault
displayHint: Kirigami.DisplayHint.KeepVisible
displayComponent: Kirigami.Heading {
text: i18n("Default source")
level: 3
font.weight: Font.Bold
}
visible: backendItem.isDefault
displayHint: Kirigami.DisplayHint.KeepVisible
displayComponent: Kirigami.Heading {
text: i18n("Default source")
level: 3
font.weight: Font.Bold
}
Kirigami.Action {
id: addSourceAction
text: i18n("Add Source…")
icon.name: "list-add"
visible: backendItem.backend && backendItem.backend.supportsAdding
}
Kirigami.Action {
id: addSourceAction
text: i18n("Add Source…")
icon.name: "list-add"
visible: backendItem.backend && backendItem.backend.supportsAdding
readonly property Component p0: Component {
id: dialogComponent
AddSourceDialog {
source: backendItem.backend
readonly property Component p0: Component {
id: dialogComponent
AddSourceDialog {
source: backendItem.backend
onSheetOpenChanged: if(!sheetOpen) {
destroy(1000)
}
onSheetOpenChanged: if(!sheetOpen) {
destroy(1000)
}
}
onTriggered: {
var addSourceDialog = dialogComponent.createObject(window, {displayName: backendItem.backend.resourcesBackend.displayName })
addSourceDialog.open()
}
}
Kirigami.Action {
id: makeDefaultAction
visible: resourcesBackend && resourcesBackend.hasApplications && !backendItem.isDefault
text: i18n("Make default")
icon.name: "favorite"
onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
}
Component {
id: kirigamiAction
ConvertDiscoverAction {}
onTriggered: {
var addSourceDialog = dialogComponent.createObject(window, {displayName: backendItem.backend.resourcesBackend.displayName })
addSourceDialog.open()
}
}
Kirigami.Action {
id: makeDefaultAction
visible: resourcesBackend && resourcesBackend.hasApplications && !backendItem.isDefault
function mergeActions(moreActions) {
var actions = [isDefaultbackendLabelAction,
makeDefaultAction,
addSourceAction]
for(var i in moreActions) {
actions.push(kirigamiAction.createObject(actionBar, {action: moreActions[i]}))
}
return actions;
}
actions: mergeActions(backendItem.backend.actions)
text: i18n("Make default")
icon.name: "favorite"
onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
}
}
Kirigami.InlineMessage {
Layout.fillWidth: true
text: backendItem.backend.inlineAction.toolTip
visible: backendItem.backend.inlineAction && backendItem.backend.inlineAction.visible
Component {
id: kirigamiAction
ConvertDiscoverAction {}
}
actions: [
Kirigami.Action {
icon.name: backendItem.backend.inlineAction.iconName
text: backendItem.backend.inlineAction.text
onTriggered: backendItem.backend.inlineAction.trigger()
function mergeActions(moreActions) {
var actions = [isDefaultbackendLabelAction,
makeDefaultAction,
addSourceAction]
for(var i in moreActions) {
actions.push(kirigamiAction.createObject(actionBar, {action: moreActions[i]}))
}
]
return actions;
}
actions: mergeActions(backendItem.backend.actions)
}
}
}
......
......@@ -90,7 +90,7 @@ FlatpakSourcesBackend::FlatpakSourcesBackend(const QVector<FlatpakInstallation *
, m_noSourcesItem(new QStandardItem(QStringLiteral("-")))
{
m_saveAction->setVisible(false);
m_saveAction->setToolTip(i18n("Changes to the priority of these sources must be applied before they will take effect."));
m_saveAction->setToolTip(i18n("Changes to the priority of Flatpak sources must be applied before they will take effect."));
connect(m_saveAction, &DiscoverAction::triggered, this, &FlatpakSourcesBackend::save);
m_flathubAction->setObjectName(QStringLiteral("flathub"));
......
......@@ -57,11 +57,13 @@ void SourcesModel::addSourcesBackend(AbstractSourcesBackend *sources)
auto action = new OneTimeAction(
[this, m] {
addSourceModel(m);
sourcesChanged();
},
this);
connect(m, &QAbstractItemModel::rowsInserted, action, &OneTimeAction::trigger);
} else {
addSourceModel(m);
sourcesChanged();
}
}
......@@ -96,3 +98,16 @@ AbstractSourcesBackend *SourcesModel::sourcesBackendByName(const QString &id) co
}
return nullptr;
}
QVector<AbstractSourcesBackend *> SourcesModel::sources() const
{
QVector<AbstractSourcesBackend *> sources;
for (int i = 0, c = rowCount(); i < c; ++i) {
const auto idx = index(i, 0);
auto source = qobject_cast<AbstractSourcesBackend *>(modelAt(idx)->property(SourcesBackendId).value<QObject *>());
if (!sources.contains(source)) {
sources += source;
}
}
return sources;
}
......@@ -16,6 +16,7 @@
class DISCOVERCOMMON_EXPORT SourcesModel : public QConcatenateTablesProxyModel
{
Q_OBJECT
Q_PROPERTY(QVector<AbstractSourcesBackend *> sources READ sources NOTIFY sourcesChanged)
public:
enum Roles {
SourceNameRole = AbstractSourcesBackend::LastRole,
......@@ -35,8 +36,9 @@ public:
void addSourcesBackend(AbstractSourcesBackend *sources);
Q_SCRIPTABLE AbstractSourcesBackend *sourcesBackendByName(const QString &name) const;
QVector<AbstractSourcesBackend *> sources() const;
Q_SIGNALS:
void sourcesChanged();
void showingNow();
private:
......
Supports Markdown
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