encrypt: Add confirmation row

Part of https://gitlab.gnome.org/p3732/os-installer/-/issues/36
This commit is contained in:
Peter Eisenmann
2024-10-16 13:00:54 -04:00
parent b9c4f5795d
commit e1b866cdb8
4 changed files with 40 additions and 3 deletions

View File

@@ -24,6 +24,17 @@ template $EncryptPage : Box {
/* Translators: Disk encryption pin confirmation entry field */
title: _("Encryption PIN");
changed => $pin_changed();
entry-activated => $pin_activated();
}
Adw.PasswordEntryRow pin_confirm_row {
activates-default: true;
use-underline: true;
width-chars: 10;
max-width-chars: 16;
/* Translators: Disk encryption pin confirmation entry field */
title: _("Confirm PIN");
changed => $pin_confirm_changed();
entry-activated => $continue();
}
}

View File

@@ -55,11 +55,12 @@ welcome_page:
minimum_disk_size: 5
# Disk encryption PIN setup.
# Default: offered: yes, forced: no, min_length: 1
# Default: offered: yes, forced: no, min_length: 1, confirmation: no
disk_encryption:
offered: yes
forced: no
min_length: 1
confirmation: yes
# Provide multiple desktop environments to choose from
#

View File

@@ -21,7 +21,7 @@ default_config = {
'welcome_page': {'usage': True, 'logo': None, 'text': None},
# disk
'minimum_disk_size': 5,
'disk_encryption': {'offered': True, 'forced': False, 'min_length': 1},
'disk_encryption': {'offered': True, 'forced': False, 'min_length': 1, 'confirmation': False},
# desktop
'desktop': [],
# user
@@ -106,6 +106,7 @@ def _validate(variables):
_match(variables['disk_encryption'], 'offered', bool) and
_match(variables['disk_encryption'], 'forced', bool) and
_match(variables['disk_encryption'], 'min_length', int) and
_match(variables['disk_encryption'], 'confirmation', bool) and
_match(variables, 'user', dict) and
_match(variables['user'], 'min_password_length', int) and
_match(variables['user'], 'request_username', bool) and

View File

@@ -12,6 +12,7 @@ class EncryptPage(Gtk.Box):
switch_row = Gtk.Template.Child()
pin_row = Gtk.Template.Child()
pin_confirm_row = Gtk.Template.Child()
info_revealer = Gtk.Template.Child()
continue_button = Gtk.Template.Child()
@@ -21,6 +22,7 @@ class EncryptPage(Gtk.Box):
encryption_setting = config.get('disk_encryption')
self.min_pin_length = max(1, encryption_setting['min_length'])
self.use_confirmation = encryption_setting['confirmation']
if encryption_setting['forced']:
self.switch_row.set_visible(False)
@@ -34,13 +36,22 @@ class EncryptPage(Gtk.Box):
self.pin_row, lambda text: len(text) > self.min_pin_length)
self.pin_row.set_text(config.get('encryption_pin'))
self.pin_confirm_row.set_visible(self.use_confirmation)
if self.use_confirmation:
self.confirmation = EntryErrorEnhancer(
self.pin_confirm_row, lambda text: text == self.pin_row.get_text())
self.pin_confirm_row.set_text(config.get('encryption_pin'))
else:
self.confirmation = True
def _adjust_pin_state(self):
self.pin_row.set_sensitive(self.active)
self.pin_confirm_row.set_sensitive(self.active)
self.info_revealer.set_reveal_child(self.active)
self._set_continue_button()
def _set_continue_button(self):
self.continue_button.set_sensitive(not self.active or self.pin)
self.continue_button.set_sensitive(not self.active or (self.pin and self.confirmation))
### callbacks ###
@@ -60,8 +71,21 @@ class EncryptPage(Gtk.Box):
pin = editable.get_text()
if self.pin.update_row(pin):
config.set('encryption_pin', pin)
self._pin_confirm_changed(self.pin_confirm_row)
@Gtk.Template.Callback('pin_confirm_changed')
def _pin_confirm_changed(self, editable):
pin = editable.get_text()
self.confirmation.update_row(pin)
self._set_continue_button()
@Gtk.Template.Callback('pin_activated')
def _pin_activated(self, object):
if self.use_confirmation:
self.pin_confirm_row.grab_focus()
else:
self._continue(None)
@Gtk.Template.Callback('continue')
def _continue(self, object):
if self.continue_button.is_sensitive():