From c17795c48eeed597b9e62e11ddc74a5557b8384b Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sun, 23 Jan 2022 19:30:16 +0100 Subject: [PATCH] Allow nested subitems Fixes "Can't assign to existing role 'subitems' of different type" or hang (depending on Qt version) on using nested subitems. Keep nested subitems flattenend as json string in memory while not being used, to simplify dealing with ListElement expectation that all elements have the same data type, as well as QML/Ecmascript's memory management. --- debian/changelog | 7 ++++++- main.qml | 51 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1892f96..abde6e1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,12 +5,17 @@ rpi-imager (1.6.3) unstable; urgency=medium repository. Some heuristics are used with custom images from disk. * Advanced settings: add support for cloudinit format * Advanced settings: add support for specifying username + * Advanced settings: allow setting username and password + * Advanced settings: allow hidden wifi SSID + * Advanced settings: allow multi-line authorized_keys + * Retry on GnuTLS Recv errors * Some fixes to deal better with Linux distributions auto-mounting drives * Add Slovenija translation * Adds support for zstd + * Allow nested subitems entries - -- Floris Bos Thu, 09 Dec 2021 11:13:12 +0100 + -- Floris Bos Sun, 23 Jan 2022 16:39:46 +0100 rpi-imager (1.6.2) unstable; urgency=medium diff --git a/main.qml b/main.qml index 6ea3945..6b4fd20 100644 --- a/main.qml +++ b/main.qml @@ -478,7 +478,7 @@ ApplicationWindow { contains_multiple_files: false release_date: "" subitems_url: "internal://back" - subitems: [] + subitems_json: "" name: qsTr("Back") description: qsTr("Go back to main menu") tooltip: "" @@ -520,7 +520,7 @@ ApplicationWindow { contains_multiple_files: false release_date: "" subitems_url: "" - subitems: [] + subitems_json: "" name: qsTr("Erase") description: qsTr("Format card as FAT32") tooltip: "" @@ -632,7 +632,7 @@ ApplicationWindow { Column { Image { source: "icons/ic_chevron_right_40px.svg" - visible: (typeof(subitems) == "object" && subitems.count) || (typeof(subitems_url) == "string" && subitems_url != "" && subitems_url != "internal://back") + visible: (typeof(subitems_json) == "string" && subitems_json != "") || (typeof(subitems_url) == "string" && subitems_url != "" && subitems_url != "internal://back") height: parent.parent.parent.height fillMode: Image.Pad } @@ -1084,24 +1084,38 @@ ApplicationWindow { } function oslistFromJson(o) { + var oslist = false var lang_country = Qt.locale().name if ("os_list_"+lang_country in o) { - return o["os_list_"+lang_country] + oslist = o["os_list_"+lang_country] } - if (lang_country.includes("_")) { + else if (lang_country.includes("_")) { var lang = lang_country.substr(0, lang_country.indexOf("_")) if ("os_list_"+lang in o) { - return o["os_list_"+lang] + oslist = o["os_list_"+lang] } } - if (!"os_list" in o) { - onError(qsTr("Error parsing os_list.json")) - return false + if (!oslist) { + if (!"os_list" in o) { + onError(qsTr("Error parsing os_list.json")) + return false + } + + oslist = o["os_list"] } - var oslist = o["os_list"] checkForRandom(oslist) + + /* Flatten subitems to subitems_json */ + for (var i in oslist) { + var entry = oslist[i]; + if ("subitems" in entry) { + entry["subitems_json"] = JSON.stringify(entry["subitems"]) + delete entry["subitems"] + } + } + return oslist } @@ -1110,8 +1124,8 @@ ApplicationWindow { for (var i = 0; i < collection.count; i++) { var os = collection.get(i) - if (typeof(os.subitems) !== "undefined") { - selectNamedOS(name, os.subitems) + if (typeof(os.subitems_json) == "string" && os.subitems_json != "") { + selectNamedOS(name, os.subitems_json) } else if (typeof(os.url) !== "undefined" && name === os.name) { selectOSitem(os, false) @@ -1197,12 +1211,19 @@ ApplicationWindow { function selectOSitem(d, selectFirstSubitem) { - if (typeof(d.subitems) == "object" && d.subitems.count) { + if (typeof(d.subitems_json) == "string" && d.subitems_json !== "") { var m = newSublist() + var subitems = JSON.parse(d.subitems_json) - for (var i=0; i