Rework OS Customization

In the new flow, it doesn't make sense to _not_ save the OS
customization parameters, so remove the ComboBox.

Additionally, our data model was failing to notify the UI of changes to
the saved settings state. Due to time constraints, I'm not able to
resolve the binding in the 'correct' manner, but I can introduce a
makeshift status signalling mechanism to prevent UI inconsistency.
This commit is contained in:
Tom Dewey tom.dewey@raspberrypi.com 2023-10-17 15:21:49 +01:00
parent 50449158bc
commit ecf992cb62
4 changed files with 76 additions and 44 deletions

View file

@ -29,6 +29,8 @@ Window {
property string cloudinitwrite
property string cloudinitnetwork
signal saveSettingsSignal(var settings)
ColumnLayout {
id: cl
spacing: 10
@ -51,16 +53,6 @@ Window {
Label {
text: qsTr("OS customization options")
}
ComboBox {
id: comboSaveSettings
model: {
[qsTr("for this session only"),
qsTr("to always use")]
}
Layout.minimumWidth: 250
Layout.maximumHeight: 40
enabled: !imageWriter.isEmbeddedMode()
}
}
TabBar {
@ -453,7 +445,6 @@ Window {
fieldKeyboardLayout.model = imageWriter.getKeymapLayoutList()
if (Object.keys(settings).length) {
comboSaveSettings.currentIndex = 1
hasSavedSettings = true
}
if ('hostname' in settings) {
@ -807,8 +798,6 @@ Window {
function saveSettings()
{
if (comboSaveSettings.currentIndex == 1) {
hasSavedSettings = true
var settings = { };
if (chkHostname.checked && fieldHostname.length) {
settings.hostname = fieldHostname.text
@ -835,15 +824,35 @@ Window {
settings.keyboardLayout = fieldKeyboardLayout.editText
}
imageWriter.setSavedCustomizationSettings(settings)
} else if (hasSavedSettings) {
imageWriter.clearSavedCustomizationSettings()
hasSavedSettings = false
}
imageWriter.setSetting("beep", chkBeep.checked)
imageWriter.setSetting("eject", chkEject.checked)
imageWriter.setSetting("telemetry", chkTelemtry.checked)
if (chkHostname.checked || chkSetUser.checked || chkSSH.checked || chkWifi.checked || chkLocale.checked) {
/* OS customization to be applied. */
hasSavedSettings = true
saveSettingsSignal(settings)
}
}
function clearCustomizationFields()
{
fieldHostname.clear()
fieldUserName.clear()
fieldUserPassword.clear()
radioPubKeyAuthentication.checked = false
radioPasswordAuthentication.checked = false
fieldPublicKey.clear()
fieldWifiSSID.clear()
fieldWifiCountry.currentIndex = -1
fieldWifiPassword.clear()
fieldTimezone.currentIndex = -1
fieldKeyboardLayout.currentIndex = -1
chkSetUser.checked = false
chkSSH.checked = false
chkLocale.checked = false
chkWifi.checked = false
chkWifiSSIDHidden.checked = false
chkHostname.checked = false
}
}

View file

@ -18,6 +18,8 @@ Popup {
padding: 0
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
property bool hasSavedSettings: false
signal yes()
signal no()
signal noClearSettings()
@ -105,6 +107,7 @@ Popup {
}
ImButton {
id: noAndClearButton
text: qsTr("NO, CLEAR SETTINGS")
onClicked: {
msgpopup.close()
@ -112,10 +115,11 @@ Popup {
}
Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff"
Material.background: "#c51a4a"
enabled: imageWriter.hasSavedCustomizationSettings() ? true : false
enabled: false
}
ImButton {
id: yesButton
text: qsTr("YES")
onClicked: {
msgpopup.close()
@ -123,7 +127,7 @@ Popup {
}
Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff"
Material.background: "#c51a4a"
enabled: imageWriter.hasSavedCustomizationSettings() ? true : false
enabled: false
}
ImButton {
@ -142,6 +146,16 @@ Popup {
function openPopup() {
open()
if (hasSavedSettings) {
/* HACK: Bizarrely, the button enabled characteristics are not re-evaluated on open.
* So, let's manually _force_ these buttons to be enabled */
yesButton.enabled = true
noAndClearButton.enabled = true
} else {
yesButton.enabled = false
noAndClearButton.enabled = false
}
// trigger screen reader to speak out message
msgpopupbody.forceActiveFocus()
}

View file

@ -1039,6 +1039,7 @@ void ImageWriter::setSavedCustomizationSettings(const QVariantMap &map)
_settings.setValue(key, map.value(key));
}
_settings.endGroup();
_settings.sync();
}
QVariantMap ImageWriter::getSavedCustomizationSettings()
@ -1060,10 +1061,12 @@ void ImageWriter::clearSavedCustomizationSettings()
_settings.beginGroup("imagecustomization");
_settings.remove("");
_settings.endGroup();
_settings.sync();
}
bool ImageWriter::hasSavedCustomizationSettings()
{
_settings.sync();
_settings.beginGroup("imagecustomization");
bool result = !_settings.childKeys().isEmpty();
_settings.endGroup();

View file

@ -1183,6 +1183,10 @@ ApplicationWindow {
OptionsPopup {
id: optionspopup
onSaveSettingsSignal: {
imageWriter.setSavedCustomizationSettings(settings)
usesavedsettingspopup.hasSavedSettings = true
}
}
UseSavedSettingsPopup {
@ -1196,6 +1200,8 @@ ApplicationWindow {
confirmwritepopup.askForConfirmation()
}
onNoClearSettings: {
hasSavedSettings = false
optionspopup.clearCustomizationFields()
imageWriter.clearSavedCustomizationSettings()
confirmwritepopup.askForConfirmation()
}