mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 07:55:21 +01:00
Fix back button and forward swipe on multi-level os_list
This commit is contained in:
parent
f5b36b6dd0
commit
cb0a3dd954
1 changed files with 100 additions and 87 deletions
187
main.qml
187
main.qml
|
@ -109,10 +109,7 @@ ApplicationWindow {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
onClicked: {
|
onClicked: {
|
||||||
ospopup.open()
|
ospopup.open()
|
||||||
if (osswipeview.currentIndex == 0)
|
osswipeview.currentItem.forceActiveFocus()
|
||||||
oslist.forceActiveFocus()
|
|
||||||
else
|
|
||||||
suboslist.forceActiveFocus()
|
|
||||||
}
|
}
|
||||||
Material.background: "#ffffff"
|
Material.background: "#ffffff"
|
||||||
Material.foreground: "#c51a4a"
|
Material.foreground: "#c51a4a"
|
||||||
|
@ -341,34 +338,53 @@ ApplicationWindow {
|
||||||
selectOSitem(model.get(currentIndex), true)
|
selectOSitem(model.get(currentIndex), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
|
||||||
id: suboslist
|
|
||||||
model: subosmodel
|
|
||||||
currentIndex: -1
|
|
||||||
delegate: osdelegate
|
|
||||||
width: window.width-100
|
|
||||||
height: window.height-100
|
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
|
||||||
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
|
|
||||||
ScrollBar.vertical: ScrollBar {
|
|
||||||
width: 10
|
|
||||||
policy: suboslist.contentHeight > suboslist.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
|
|
||||||
}
|
|
||||||
Keys.onSpacePressed: {
|
|
||||||
if (currentIndex != -1)
|
|
||||||
selectOSitem(model.get(currentIndex))
|
|
||||||
}
|
|
||||||
Accessible.onPressAction: {
|
|
||||||
if (currentIndex != -1)
|
|
||||||
selectOSitem(model.get(currentIndex))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: suboslist
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
model: ListModel {
|
||||||
|
ListElement {
|
||||||
|
url: ""
|
||||||
|
icon: "icons/ic_chevron_left_40px.svg"
|
||||||
|
extract_size: 0
|
||||||
|
image_download_size: 0
|
||||||
|
extract_sha256: ""
|
||||||
|
contains_multiple_files: false
|
||||||
|
release_date: ""
|
||||||
|
subitems_url: "internal://back"
|
||||||
|
subitems: []
|
||||||
|
name: qsTr("Back")
|
||||||
|
description: qsTr("Go back to main menu")
|
||||||
|
tooltip: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIndex: -1
|
||||||
|
delegate: osdelegate
|
||||||
|
width: window.width-100
|
||||||
|
height: window.height-100
|
||||||
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
|
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
|
||||||
|
ScrollBar.vertical: ScrollBar {
|
||||||
|
width: 10
|
||||||
|
policy: parent.contentHeight > parent.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
|
||||||
|
}
|
||||||
|
Keys.onSpacePressed: {
|
||||||
|
if (currentIndex != -1)
|
||||||
|
selectOSitem(model.get(currentIndex))
|
||||||
|
}
|
||||||
|
Accessible.onPressAction: {
|
||||||
|
if (currentIndex != -1)
|
||||||
|
selectOSitem(model.get(currentIndex))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: osmodel
|
id: osmodel
|
||||||
|
|
||||||
|
@ -401,25 +417,6 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
|
||||||
id: subosmodel
|
|
||||||
|
|
||||||
ListElement {
|
|
||||||
url: ""
|
|
||||||
icon: "icons/ic_chevron_left_40px.svg"
|
|
||||||
extract_size: 0
|
|
||||||
image_download_size: 0
|
|
||||||
extract_sha256: ""
|
|
||||||
contains_multiple_files: false
|
|
||||||
release_date: ""
|
|
||||||
subitems_url: "internal://back"
|
|
||||||
subitems: []
|
|
||||||
name: qsTr("Back")
|
|
||||||
description: qsTr("Go back to main menu")
|
|
||||||
tooltip: ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: osdelegate
|
id: osdelegate
|
||||||
|
|
||||||
|
@ -896,14 +893,32 @@ ApplicationWindow {
|
||||||
progressText.text = qsTr("Finalizing...")
|
progressText.text = qsTr("Finalizing...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function oslistFromJson(o) {
|
||||||
|
var lang_country = Qt.locale().name
|
||||||
|
if ("os_list_"+lang_country in o) {
|
||||||
|
return o["os_list_"+lang_country]
|
||||||
|
}
|
||||||
|
if (lang_country.includes("_")) {
|
||||||
|
var lang = lang_country.substr(0, lang_country.indexOf("_"))
|
||||||
|
if ("os_list_"+lang in o) {
|
||||||
|
return o["os_list_"+lang]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"os_list" in o) {
|
||||||
|
onError(qsTr("Error parsing os_list.json"))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return o["os_list"]
|
||||||
|
}
|
||||||
|
|
||||||
function fetchOSlist() {
|
function fetchOSlist() {
|
||||||
httpRequest(imageWriter.constantOsListUrl(), function (x) {
|
httpRequest(imageWriter.constantOsListUrl(), function (x) {
|
||||||
var o = JSON.parse(x.responseText)
|
var o = JSON.parse(x.responseText)
|
||||||
if (!"os_list" in o) {
|
var oslist = oslistFromJson(o)
|
||||||
onError(qsTr("Error parsing os_list.json"))
|
if (oslist === false)
|
||||||
return;
|
return
|
||||||
}
|
|
||||||
var oslist = o["os_list"]
|
|
||||||
for (var i in oslist) {
|
for (var i in oslist) {
|
||||||
osmodel.insert(osmodel.count-2, oslist[i])
|
osmodel.insert(osmodel.count-2, oslist[i])
|
||||||
}
|
}
|
||||||
|
@ -920,56 +935,60 @@ ApplicationWindow {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newSublist() {
|
||||||
|
if (osswipeview.currentIndex == (osswipeview.count-1))
|
||||||
|
{
|
||||||
|
var newlist = suboslist.createObject(osswipeview)
|
||||||
|
osswipeview.addItem(newlist)
|
||||||
|
}
|
||||||
|
|
||||||
|
var m = osswipeview.itemAt(osswipeview.currentIndex+1).model
|
||||||
|
|
||||||
|
if (m.count>1)
|
||||||
|
{
|
||||||
|
m.remove(1, m.count-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
function selectOSitem(d, selectFirstSubitem)
|
function selectOSitem(d, selectFirstSubitem)
|
||||||
{
|
{
|
||||||
if (typeof(d.subitems) == "object" && d.subitems.count) {
|
if (typeof(d.subitems) == "object" && d.subitems.count) {
|
||||||
if (subosmodel.count>1)
|
var m = newSublist()
|
||||||
{
|
|
||||||
subosmodel.remove(1, subosmodel.count-1)
|
|
||||||
}
|
|
||||||
for (var i=0; i<d.subitems.count; i++)
|
for (var i=0; i<d.subitems.count; i++)
|
||||||
{
|
{
|
||||||
subosmodel.append(d.subitems.get(i))
|
m.append(d.subitems.get(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectFirstSubitem === true)
|
osswipeview.itemAt(osswipeview.currentIndex+1).currentIndex = (selectFirstSubitem === true) ? 0 : -1
|
||||||
suboslist.currentIndex = 0
|
osswipeview.incrementCurrentIndex()
|
||||||
else
|
|
||||||
suboslist.currentIndex = -1
|
|
||||||
osswipeview.setCurrentIndex(1)
|
|
||||||
ospopup.categorySelected = d.name
|
ospopup.categorySelected = d.name
|
||||||
} else if (typeof(d.subitems_url) == "string" && d.subitems_url !== "") {
|
} else if (typeof(d.subitems_url) == "string" && d.subitems_url !== "") {
|
||||||
if (d.subitems_url === "internal://back")
|
if (d.subitems_url === "internal://back")
|
||||||
{
|
{
|
||||||
osswipeview.setCurrentIndex(0)
|
osswipeview.decrementCurrentIndex()
|
||||||
ospopup.categorySelected = ""
|
ospopup.categorySelected = ""
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ospopup.categorySelected = d.name
|
ospopup.categorySelected = d.name
|
||||||
var suburl = d.subitems_url
|
var suburl = d.subitems_url
|
||||||
if (subosmodel.count>1)
|
var m = newSublist()
|
||||||
{
|
|
||||||
subosmodel.remove(1, subosmodel.count-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
httpRequest(suburl, function (x) {
|
httpRequest(suburl, function (x) {
|
||||||
var o = JSON.parse(x.responseText)
|
var o = JSON.parse(x.responseText)
|
||||||
if (!"os_list" in o) {
|
var oslist = oslistFromJson(o)
|
||||||
onError(qsTr("Error parsing os_list.json"))
|
if (oslist === false)
|
||||||
return;
|
return
|
||||||
}
|
|
||||||
var oslist = o["os_list"]
|
|
||||||
for (var i in oslist) {
|
for (var i in oslist) {
|
||||||
subosmodel.append(oslist[i])
|
m.append(oslist[i])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (selectFirstSubitem === true)
|
osswipeview.itemAt(osswipeview.currentIndex+1).currentIndex = (selectFirstSubitem === true) ? 0 : -1
|
||||||
suboslist.currentIndex = 0
|
osswipeview.incrementCurrentIndex()
|
||||||
else
|
|
||||||
suboslist.currentIndex = -1
|
|
||||||
osswipeview.setCurrentIndex(1)
|
|
||||||
}
|
}
|
||||||
} else if (d.url === "") {
|
} else if (d.url === "") {
|
||||||
if (!imageWriter.isEmbeddedMode()) {
|
if (!imageWriter.isEmbeddedMode()) {
|
||||||
|
@ -977,20 +996,14 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (imageWriter.mountUsbSourceMedia()) {
|
if (imageWriter.mountUsbSourceMedia()) {
|
||||||
if (subosmodel.count>1)
|
var m = newSublist()
|
||||||
{
|
|
||||||
subosmodel.remove(1, subosmodel.count-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var oslist = JSON.parse(imageWriter.getUsbSourceOSlist())
|
var oslist = JSON.parse(imageWriter.getUsbSourceOSlist())
|
||||||
for (var i in oslist) {
|
for (var i in oslist) {
|
||||||
subosmodel.append(oslist[i])
|
m.append(oslist[i])
|
||||||
}
|
}
|
||||||
if (selectFirstSubitem === true)
|
osswipeview.itemAt(osswipeview.currentIndex+1).currentIndex = (selectFirstSubitem === true) ? 0 : -1
|
||||||
suboslist.currentIndex = 0
|
osswipeview.incrementCurrentIndex()
|
||||||
else
|
|
||||||
suboslist.currentIndex = -1
|
|
||||||
osswipeview.setCurrentIndex(1)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue