Skip to content

Commit

Permalink
Add mnemonics for better experience
Browse files Browse the repository at this point in the history
Fixes #643
  • Loading branch information
gastoner committed Oct 9, 2023
1 parent e713a46 commit c7af1e9
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 113 deletions.
12 changes: 12 additions & 0 deletions src/app/qml/AboutDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ApplicationWindow {
anchors.fill: parent
anchors.margins: units.gridUnit
spacing: units.gridUnit
focus: true

Column {
leftPadding: units.gridUnit
Expand Down Expand Up @@ -95,5 +96,16 @@ ApplicationWindow {
text: qsTr("Close")
}
}

Keys.onPressed: (event)=> {
switch (event.key) {
case (Qt.Key_Escape):
case (Qt.Key_Enter):
case (Qt.Key_Return):
case (Qt.Key_I):
aboutDialog.close()
break
}
}
}
}
49 changes: 33 additions & 16 deletions src/app/qml/CancelDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ApplicationWindow {
anchors.fill: parent
anchors.margins: units.gridUnit
spacing: units.gridUnit
focus: true

Column {
leftPadding: units.gridUnit
Expand Down Expand Up @@ -90,22 +91,7 @@ ApplicationWindow {

Button {
id: cancelButton
onClicked: {
cancelDialog.close()
// Store release state locally as drives.selected.cancel() makes
// it go to failed state if we cancel the writing process
var releaseState = releases.variant.status
if (drives.selected)
drives.selected.cancel()
if (mainWindow.selectedPage == Units.Page.DownloadPage &&
(releaseState === Units.DownloadStatus.Writing || releaseState === Units.DownloadStatus.Write_Verifying || releaseState === Units.DownloadStatus.Writing_Not_Possible)) {
drives.lastRestoreable = drivesSelected
drives.lastRestoreable.setRestoreStatus(Units.RestoreStatus.Contains_Live)
}
releases.variant.resetStatus()
downloadManager.cancel()
selectedPage = Units.Page.MainPage
}
onClicked: cancelWrite()
text: {
if (releases.variant.status == Units.DownloadStatus.Downloading || releases.variant.status === Units.DownloadStatus.Download_Verifying)
qsTr("Cancel Download")
Expand All @@ -118,6 +104,37 @@ ApplicationWindow {
}
}
}
Keys.onPressed: (event)=> {
switch (event.key) {
case (Qt.Key_Escape):
cancelDialog.close()
break
case (Qt.Key_Return):
case (Qt.Key_Enter):
if (cancelDialog.visible)
cancelWrite()
else
cancelDialog.show()
break
}
}
}

function cancelWrite() {
cancelDialog.close()
// Store release state locally as drives.selected.cancel() makes
// it go to failed state if we cancel the writing process
var releaseState = releases.variant.status
if (drives.selected)
drives.selected.cancel()
if (mainWindow.selectedPage == Units.Page.DownloadPage &&
(releaseState === Units.DownloadStatus.Writing || releaseState === Units.DownloadStatus.Write_Verifying || releaseState === Units.DownloadStatus.Writing_Not_Possible)) {
drives.lastRestoreable = drivesSelected
drives.lastRestoreable.setRestoreStatus(Units.RestoreStatus.Contains_Live)
}
releases.variant.resetStatus()
downloadManager.cancel()
selectedPage = Units.Page.MainPage
}
}

37 changes: 37 additions & 0 deletions src/app/qml/DownloadPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ Page {
}
}

StackView.onActivated: {
prevButton.text = qsTr("Cancel")
if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Downloading || releases.variant.status === Units.DownloadStatus.Download_Verifying)
nextButton.text = qsTr("Cancel")
else if (releases.variant.status == Units.DownloadStatus.Ready)
nextButton.text = qsTr("Write")
else if (releases.variant.status === Units.DownloadStatus.Finished)
nextButton.text = qsTr("Finish")
else
nextButton.text = qsTr("Retry")
}

function getPrevButtonState() {
// There will be only [Finish] button on the right side so [Cancel] button
// is not necessary
Expand All @@ -357,5 +369,30 @@ Page {

return false
}

function setNextPage() {
if (releases.variant.status === Units.DownloadStatus.Finished) {
drives.lastRestoreable = drives.selected
drives.lastRestoreable.setRestoreStatus(Units.RestoreStatus.Contains_Live)
releases.variant.resetStatus()
downloadManager.cancel()
selectedPage = Units.Page.MainPage
} else if ((releases.variant.status === Units.DownloadStatus.Failed && drives.length) || releases.variant.status === Units.DownloadStatus.Failed_Download || (releases.variant.status === Units.DownloadStatus.Failed_Verification && drives.length) || releases.variant.status === Units.DownloadStatus.Ready) {
if (selectedOption != Units.MainSelect.Write)
releases.variant.download()
drives.selected.setImage(releases.variant)
drives.selected.write(releases.variant)
}
}

function setPreviousPage() {
if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Downloading || releases.variant.status === Units.DownloadStatus.Download_Verifying) {
cancelDialog.show()
} else {
releases.variant.resetStatus()
downloadManager.cancel()
mainWindow.selectedPage = Units.Page.MainPage
}
}
}

94 changes: 94 additions & 0 deletions src/app/qml/DrivePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Page {
}

CheckBox {
id: deleteCheck
text: qsTr("Delete download after writing")
onCheckedChanged: mainWindow.eraseVariant = !mainWindow.eraseVariant
}
Expand All @@ -181,4 +182,97 @@ Page {
PropertyChanges { target: nextButton; enabled: driveCombo.enabled && releases.localFile.iso }
}
]

Keys.onPressed: (event)=> {
if (drivePage.state == "Downloading") {
switch (event.key) {
case (Qt.Key_1):
closePopups()
if (!versionCombo.down)
versionCombo.popup.open()
break
case (Qt.Key_2):
closePopups()
if (!hwArchCombo.down)
hwArchCombo.popup.open()
break
case (Qt.Key_3):
closePopups()
if (!driveCombo.down && driveCombo.count)
driveCombo.popup.open()
break
case (Qt.Key_D):
case (Qt.Key_4):
deleteCheck.checked = !deleteCheck.checked
break
case (Qt.Key_Return):
case (Qt.Key_Enter):
closePopups()
break
case (Qt.Key_Up):
if (versionCombo.down && versionCombo.currentIndex > 0)
versionCombo.currentIndex -= 1
else if (hwArchCombo.down && hwArchCombo.currentIndex > 0)
hwArchCombo.currentIndex -= 1
else if (driveCombo.down && driveCombo.currentIndex > 0)
driveCombo.currentIndex -= 1
break
case (Qt.Key_Down):
if (versionCombo.down && versionCombo.currentIndex < versionCombo.count - 1)
versionCombo.currentIndex += 1
else if (hwArchCombo.down && hwArchCombo.currentIndex < hwArchCombo.count - 1)
hwArchCombo.currentIndex += 1
else if (driveCombo.down && driveCombo.currentIndex < driveCombo.count - 1)
driveCombo.currentIndex += 1
break
}
} else {
switch (event.key) {
case (Qt.Key_1):
if (portalFileDialog.isAvailable)
portalFileDialog.open()
else
fileDialog.open()
break
case (Qt.Key_2):
driveCombo.focus = true
break
}
}
}

StackView.onActivated: {
prevButton.text = qsTr("Previous")
if (selectedOption == Units.MainSelect.Write || downloadManager.isDownloaded(releases.selected.version.variant.url))
nextButton.text = qsTr("Write")
else if (Qt.platform.os === "windows" || Qt.platform.os === "osx")
nextButton.text = qsTr("Download && Write")
else
nextButton.text = qsTr("Download & Write")
}

function setNextPage() {
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)
}
}

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

function closePopups() {
versionCombo.popup.close()
hwArchCombo.popup.close()
driveCombo.popup.close()
}
}
37 changes: 37 additions & 0 deletions src/app/qml/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Page {
}

RadioButton {
checked: mainWindow.selectedOption == Units.MainSelect.Write
text: qsTr("Select .iso file")
onClicked: {
selectedOption = Units.MainSelect.Write
Expand All @@ -73,6 +74,7 @@ Page {
RadioButton {
id: restoreRadio
visible: drives.lastRestoreable
checked: mainWindow.selectedOption == Units.MainSelect.Restore
text: drives.lastRestoreable ? qsTr("Restore <b>%1</b>").arg(drives.lastRestoreable.name) : ""
onClicked: {
selectedOption = Units.MainSelect.Restore
Expand All @@ -91,4 +93,39 @@ Page {
}
}
}

StackView.onActivated: {
prevButton.text = qsTr("About")
nextButton.text = qsTr("Next")
}

function setNextPage() {
if (mainWindow.selectedOption == Units.MainSelect.Write) {
if (releases.localFile.iso)
releases.selectLocalFile()
mainWindow.selectedPage = Units.Page.DrivePage
} else if (selectedOption == Units.MainSelect.Restore)
mainWindow.selectedPage = Units.Page.RestorePage
else
mainWindow.selectedPage = Units.Page.VersionPage
}

function setPreviousPage() {
aboutDialog.show()
}

Keys.onPressed: (event)=> {
switch (event.key) {
case (Qt.Key_1):
mainWindow.selectedOption = Units.MainSelect.Download
break
case (Qt.Key_2):
mainWindow.selectedOption = Units.MainSelect.Write
break
case (Qt.Key_3):
if (restoreRadio.visible)
mainWindow.selectedOption = Units.MainSelect.Restore
break
}
}
}
19 changes: 19 additions & 0 deletions src/app/qml/RestorePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,23 @@ Page {
}
}
]

StackView.onActivated: {
prevButton.text = qsTr("Previous")
if (lastRestoreable && lastRestoreable.restoreStatus == Units.RestoreStatus.Restored)
nextButton.text = qsTr("Finish")
else
nextButton.text = qsTr("Restore")
}

function setNextPage() {
if (lastRestoreable && lastRestoreable.restoreStatus == Units.RestoreStatus.Restored)
selectedPage = Units.Page.MainPage
else
drives.lastRestoreable.restore()
}

function setPreviousPage() {
selectedPage = Units.Page.MainPage
}
}
Loading

0 comments on commit c7af1e9

Please sign in to comment.