Skip to content

Commit

Permalink
QML rewrite: use a reusable base "Page" component for each UI page
Browse files Browse the repository at this point in the history
This "Page" component also now includes buttons, which originally were
part of the main UI, where we also had the complete logic for what text
and actions should be used for both buttons at different state. Moving
this to per page component makes things simpler, easier to understand
and less error prone. It also removes quite a lot of code.
  • Loading branch information
grulja committed Oct 2, 2024
1 parent 662756d commit 697a8b1
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 833 deletions.
13 changes: 7 additions & 6 deletions src/app/qml.qrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<RCC>
<qresource prefix="/">
<file>qml/main.qml</file>
<file>qml/VersionPage.qml</file>
<file>qml/DrivePage.qml</file>
<file>qml/AboutDialog.qml</file>
<file>qml/CancelDialog.qml</file>
<file>qml/DownloadPage.qml</file>
<file>qml/Units.qml</file>
<file>qml/DrivePage.qml</file>
<file>qml/Heading.qml</file>
<file>qml/MainPage.qml</file>
<file>qml/AboutDialog.qml</file>
<file>qml/CancelDialog.qml</file>
<file>qml/Page.qml</file>
<file>qml/RestorePage.qml</file>
<file>qml/Units.qml</file>
<file>qml/VersionPage.qml</file>
<file>qml/main.qml</file>
</qresource>
</RCC>
1 change: 0 additions & 1 deletion src/app/qml/AboutDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import QtQuick 6.6
import QtQuick.Controls 6.6
import QtQuick.Window 6.6
import QtQuick.Layouts 6.6
import QtQml 6.6

ApplicationWindow {
id: aboutDialog
Expand Down
1 change: 0 additions & 1 deletion src/app/qml/CancelDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import QtQuick 6.6
import QtQuick.Controls 6.6
import QtQuick.Window 6.6
import QtQuick.Layouts 6.6
import QtQml 6.6

ApplicationWindow {
id: cancelDialog
Expand Down
427 changes: 178 additions & 249 deletions src/app/qml/DownloadPage.qml

Large diffs are not rendered by default.

267 changes: 138 additions & 129 deletions src/app/qml/DrivePage.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Fedora Media Writer
* Copyright (C) 2024 Jan Grulich <[email protected]>
* Copyright (C) 2021-2022 Evžen Gasta <[email protected]>
*
* This program is free software; you can redistribute it and/or
Expand All @@ -18,167 +19,175 @@
*/

import QtQuick 6.6
import QtQuick.Controls 6.6
import QtQuick.Window 6.6
import QtQuick.Layouts 6.6
import QtQml 6.6
import QtQuick.Controls 6.6 as QQC2
import QtQuick.Dialogs 6.6
import QtQuick.Layouts 6.6

Page {
id: drivePage

ColumnLayout {
anchors.fill: parent
spacing: units.gridUnit
layoutSpacing: units.gridUnit
text: qsTr("Write Options")

ColumnLayout {
id: versionCol
visible: selectedOption != Units.MainSelect.Write

Heading {
Layout.alignment: Qt.AlignHCenter
text: qsTr("Write Options")
level: 5
text: qsTr("Version")
}

ColumnLayout {
id: versionCol
visible: selectedOption != Units.MainSelect.Write

Heading {
text: qsTr("Version")
}

ComboBox {
id: versionCombo
Layout.fillWidth: true
model: releases.selected.versions
textRole: "name"
onCurrentIndexChanged: releases.selected.versionIndex = currentIndex
Component.onCompleted: {
if (releases.selected.version.status != Units.Status.FINAL && releases.selected.versions.length > 1) {
currentIndex++
}

QQC2.ComboBox {
id: versionCombo
Layout.fillWidth: true
model: releases.selected.versions
textRole: "name"
onCurrentIndexChanged: releases.selected.versionIndex = currentIndex
Component.onCompleted: {
if (releases.selected.version.status != Units.Status.FINAL && releases.selected.versions.length > 1) {
currentIndex++
}
}
}

ColumnLayout {
id: architectureCol
visible: selectedOption != Units.MainSelect.Write

Heading {
text: qsTr("Hardware Architecture")
}

ComboBox {
id: hwArchCombo
Layout.fillWidth: true
model: releases.selected.version.variants
textRole: "name"
onCurrentIndexChanged: releases.selected.version.variantIndex = currentIndex
}
}

ColumnLayout {
id: architectureCol
visible: selectedOption != Units.MainSelect.Write

Heading {
text: qsTr("Hardware Architecture")
}

ColumnLayout {
id: selectFileColumn
visible: selectedOption == Units.MainSelect.Write

Heading {
text: qsTr("Selected file")

QQC2.ComboBox {
id: hwArchCombo
Layout.fillWidth: true
model: releases.selected.version.variants
textRole: "name"
onCurrentIndexChanged: releases.selected.version.variantIndex = currentIndex
}
}

ColumnLayout {
id: selectFileColumn
visible: selectedOption == Units.MainSelect.Write

Heading {
text: qsTr("Selected file")
}

RowLayout {
id: fileCol

QQC2.Label {
text: releases.localFile.iso ? (String)(releases.localFile.iso).split("/").slice(-1)[0] : ("<font color=\"gray\">" + qsTr("None") + "</font>")
Layout.fillWidth: true
elide: QQC2.Label.ElideRight
}

RowLayout {
id: fileCol

Label {
text: releases.localFile.iso ? (String)(releases.localFile.iso).split("/").slice(-1)[0] : ("<font color=\"gray\">" + qsTr("None") + "</font>")
Layout.fillWidth: true
elide: Label.ElideRight

QQC2.Button {
id: selectFileButton
Layout.alignment: Qt.AlignRight
text: qsTr("Select...")
onClicked: {
if (portalFileDialog.isAvailable)
portalFileDialog.open()
else
fileDialog.open()
}

Button {
id: selectFileButton
Layout.alignment: Qt.AlignRight
text: qsTr("Select...")
onClicked: {
if (portalFileDialog.isAvailable)
portalFileDialog.open()
else
fileDialog.open()
}

Connections {
target: portalFileDialog
function onFileSelected(fileName) {
releases.selectLocalFile(fileName)
}
Connections {
target: portalFileDialog
function onFileSelected(fileName) {
releases.selectLocalFile(fileName)
}
FileDialog {
id: fileDialog
nameFilters: [ qsTr("Image files") + " (*.iso *.raw *.xz)", qsTr("All files (*)")]
onAccepted: {
releases.selectLocalFile(currentFile)
}
}

FileDialog {
id: fileDialog
nameFilters: [ qsTr("Image files") + " (*.iso *.raw *.xz)", qsTr("All files (*)")]
onAccepted: {
releases.selectLocalFile(currentFile)
}
}
}
}

ColumnLayout {
Heading {
text: qsTr("USB Drive")
}

ComboBox {
id: driveCombo
Layout.fillWidth: true
model: drives
enabled: !(currentIndex === -1 || !currentText)
displayText: currentIndex === -1 || !currentText ? qsTr("There are no portable drives connected") : currentText
textRole: "display"

Binding on currentIndex {
when: drives
value: drives.selectedIndex
}
Binding {
target: drives
property: "selectedIndex"
value: driveCombo.currentIndex
}
}
}

ColumnLayout {
Heading {
text: qsTr("USB Drive")
}

ColumnLayout {
visible: selectedOption != Units.MainSelect.Write
Layout.bottomMargin: units.gridUnit * 5

Heading {
text: qsTr("Download")
level: 1

QQC2.ComboBox {
id: driveCombo
Layout.fillWidth: true
model: drives
enabled: !(currentIndex === -1 || !currentText)
displayText: currentIndex === -1 || !currentText ? qsTr("There are no portable drives connected") : currentText
textRole: "display"

Binding on currentIndex {
when: drives
value: drives.selectedIndex
}

CheckBox {
text: qsTr("Delete download after writing")
onCheckedChanged: mainWindow.eraseVariant = !mainWindow.eraseVariant
Binding {
target: drives
property: "selectedIndex"
value: driveCombo.currentIndex
}
}

Item {
visible: selectedOption == Units.MainSelect.Write
Layout.fillHeight: true
}

ColumnLayout {
visible: selectedOption != Units.MainSelect.Write

Heading {
text: qsTr("Download")
level: 1
}

QQC2.CheckBox {
text: qsTr("Delete download after writing")
onCheckedChanged: mainWindow.eraseVariant = !mainWindow.eraseVariant
}
}

states: [
State {
name: "Downloading"
when: selectedOption != Units.MainSelect.Write && selectedPage == Units.Page.DrivePage
PropertyChanges { target: nextButton; enabled: true }
StateChangeScript { script: releases.setSelectedVariantIndex = 0 }
},
State {
name: "WritingISO"
when: selectedOption == Units.MainSelect.Write && selectedPage == Units.Page.DrivePage
PropertyChanges { target: nextButton; enabled: driveCombo.enabled && releases.localFile.iso }
}
]

nextButtonEnabled: (selectedOption != Units.MainSelect.Write && selectedPage == Units.Page.DrivePage) ||
(selectedOption == Units.MainSelect.Write && selectedPage == Units.Page.DrivePage)

nextButtonText: {
if (selectedOption == Units.MainSelect.Write || downloadManager.isDownloaded(releases.selected.version.variant.url))
return qsTr("Write")
if (Qt.platform.os === "windows" || Qt.platform.os === "osx")
return qsTr("Download && Write")
return qsTr("Download & Write")
}

onPreviousButtonClicked: {
if (selectedOption == Units.MainSelect.Write)
selectedPage = Units.Page.MainPage
else {
selectedPage -= 1
stackView.pop()
}
}

onNextButtonClicked: {
selectedPage = Units.Page.DownloadPage
if (selectedOption != Units.MainSelect.Write)
releases.variant.download()
if (drives.length) {
drives.selected.setImage(releases.variant)
drives.selected.write(releases.variant)
}
}
}
Loading

0 comments on commit 697a8b1

Please sign in to comment.