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 cloudinitwrite
property string cloudinitnetwork property string cloudinitnetwork
signal saveSettingsSignal(var settings)
ColumnLayout { ColumnLayout {
id: cl id: cl
spacing: 10 spacing: 10
@ -51,16 +53,6 @@ Window {
Label { Label {
text: qsTr("OS customization options") 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 { TabBar {
@ -453,7 +445,6 @@ Window {
fieldKeyboardLayout.model = imageWriter.getKeymapLayoutList() fieldKeyboardLayout.model = imageWriter.getKeymapLayoutList()
if (Object.keys(settings).length) { if (Object.keys(settings).length) {
comboSaveSettings.currentIndex = 1
hasSavedSettings = true hasSavedSettings = true
} }
if ('hostname' in settings) { if ('hostname' in settings) {
@ -807,43 +798,61 @@ Window {
function saveSettings() function saveSettings()
{ {
if (comboSaveSettings.currentIndex == 1) { var settings = { };
hasSavedSettings = true if (chkHostname.checked && fieldHostname.length) {
var settings = { }; settings.hostname = fieldHostname.text
if (chkHostname.checked && fieldHostname.length) { }
settings.hostname = fieldHostname.text if (chkSetUser.checked) {
} settings.sshUserName = fieldUserName.text
if (chkSetUser.checked) { settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
settings.sshUserName = fieldUserName.text }
settings.sshUserPassword = fieldUserPassword.alreadyCrypted ? fieldUserPassword.text : imageWriter.crypt(fieldUserPassword.text)
}
settings.sshEnabled = chkSSH.checked settings.sshEnabled = chkSSH.checked
if (chkSSH.checked && radioPubKeyAuthentication.checked) { if (chkSSH.checked && radioPubKeyAuthentication.checked) {
settings.sshAuthorizedKeys = fieldPublicKey.text settings.sshAuthorizedKeys = fieldPublicKey.text
}
if (chkWifi.checked) {
settings.wifiSSID = fieldWifiSSID.text
if (chkWifiSSIDHidden.checked) {
settings.wifiSSIDHidden = true
} }
if (chkWifi.checked) { settings.wifiPassword = fieldWifiPassword.text.length == 64 ? fieldWifiPassword.text : imageWriter.pbkdf2(fieldWifiPassword.text, fieldWifiSSID.text)
settings.wifiSSID = fieldWifiSSID.text settings.wifiCountry = fieldWifiCountry.editText
if (chkWifiSSIDHidden.checked) { }
settings.wifiSSIDHidden = true if (chkLocale.checked) {
} settings.timezone = fieldTimezone.editText
settings.wifiPassword = fieldWifiPassword.text.length == 64 ? fieldWifiPassword.text : imageWriter.pbkdf2(fieldWifiPassword.text, fieldWifiSSID.text) settings.keyboardLayout = fieldKeyboardLayout.editText
settings.wifiCountry = fieldWifiCountry.editText
}
if (chkLocale.checked) {
settings.timezone = fieldTimezone.editText
settings.keyboardLayout = fieldKeyboardLayout.editText
}
imageWriter.setSavedCustomizationSettings(settings)
} else if (hasSavedSettings) {
imageWriter.clearSavedCustomizationSettings()
hasSavedSettings = false
} }
imageWriter.setSetting("beep", chkBeep.checked) imageWriter.setSetting("beep", chkBeep.checked)
imageWriter.setSetting("eject", chkEject.checked) imageWriter.setSetting("eject", chkEject.checked)
imageWriter.setSetting("telemetry", chkTelemtry.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 padding: 0
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
property bool hasSavedSettings: false
signal yes() signal yes()
signal no() signal no()
signal noClearSettings() signal noClearSettings()
@ -105,6 +107,7 @@ Popup {
} }
ImButton { ImButton {
id: noAndClearButton
text: qsTr("NO, CLEAR SETTINGS") text: qsTr("NO, CLEAR SETTINGS")
onClicked: { onClicked: {
msgpopup.close() msgpopup.close()
@ -112,10 +115,11 @@ Popup {
} }
Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff" Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff"
Material.background: "#c51a4a" Material.background: "#c51a4a"
enabled: imageWriter.hasSavedCustomizationSettings() ? true : false enabled: false
} }
ImButton { ImButton {
id: yesButton
text: qsTr("YES") text: qsTr("YES")
onClicked: { onClicked: {
msgpopup.close() msgpopup.close()
@ -123,7 +127,7 @@ Popup {
} }
Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff" Material.foreground: activeFocus ? "#d1dcfb" : "#ffffff"
Material.background: "#c51a4a" Material.background: "#c51a4a"
enabled: imageWriter.hasSavedCustomizationSettings() ? true : false enabled: false
} }
ImButton { ImButton {
@ -142,6 +146,16 @@ Popup {
function openPopup() { function openPopup() {
open() 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 // trigger screen reader to speak out message
msgpopupbody.forceActiveFocus() msgpopupbody.forceActiveFocus()
} }

View file

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

View file

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