Skip to content

Commit

Permalink
EncryptView: use single view
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Oct 22, 2024
1 parent 9e23e75 commit f86ddb4
Showing 1 changed file with 20 additions and 65 deletions.
85 changes: 20 additions & 65 deletions src/Views/EncryptView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class EncryptView : AbstractInstallerView {
private ErrorRevealer confirm_entry_revealer;
private ErrorRevealer pw_error_revealer;
private Gtk.Button next_button;
private Gtk.Button encrypt_button;
private Granite.ValidatedEntry confirm_entry;
private ValidatedEntry pw_entry;
private Gtk.LevelBar pw_levelbar;
Expand Down Expand Up @@ -51,20 +52,14 @@ public class EncryptView : AbstractInstallerView {

var title_label = new Gtk.Label (title);

var details_label = new Gtk.Label (_("Encrypt this device's drive if required for added protection, but be sure you understand:")) {
wrap = true,
xalign = 0
};
details_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

var protect_row = new DescriptionRow (
_("Data will only be protected from others with physical access to this device when it is shut down."),
"security-high-symbolic",
"green"
);

var restart_row = new DescriptionRow (
_("The encryption password will be required each time this device is turned on. Store it somewhere safe."),
_("The encryption password will be required each time this device is turned on. If you forget the encryption password, <b>you will not be able to recover data.</b>"),
"system-reboot-symbolic",
"blue"
);
Expand All @@ -75,30 +70,14 @@ public class EncryptView : AbstractInstallerView {
"slate"
);

var description_box = new Gtk.Box (VERTICAL, 32) {
valign = CENTER
var pw_label = new Granite.HeaderLabel (_("Choose Encryption Password")) {
secondary_text = _("This is a unique password for this device, not the password for your user account.")
};
description_box.append (details_label);
description_box.append (protect_row);
description_box.append (restart_row);
description_box.append (keyboard_row);

var description = new Gtk.Label (
_("If you forget the encryption password, <b>you will not be able to recover data.</b> This is a unique password for this device, not the password for your user account.")
) {
margin_bottom = 12,
use_markup = true,
wrap = true,
xalign = 0
};

var pw_label = new Granite.HeaderLabel (_("Choose Encryption Password"));

pw_error_revealer = new ErrorRevealer (".");
pw_error_revealer.label_widget.add_css_class (Granite.STYLE_CLASS_WARNING);

pw_entry = new ValidatedEntry ();
pw_entry.visibility = false;

pw_levelbar = new Gtk.LevelBar.for_interval (0.0, 100.0);
pw_levelbar.set_mode (Gtk.LevelBarMode.CONTINUOUS);
Expand All @@ -116,10 +95,7 @@ public class EncryptView : AbstractInstallerView {
confirm_entry_revealer = new ErrorRevealer (".");
confirm_entry_revealer.label_widget.add_css_class (Granite.STYLE_CLASS_ERROR);

var password_box = new Gtk.Box (VERTICAL, 3) {
valign = CENTER
};
password_box.append (description);
var password_box = new Gtk.Box (VERTICAL, 3);
password_box.append (pw_label);
password_box.append (pw_entry);
password_box.append (pw_levelbar);
Expand All @@ -128,56 +104,37 @@ public class EncryptView : AbstractInstallerView {
password_box.append (confirm_entry);
password_box.append (confirm_entry_revealer);

var stack = new Gtk.Stack () {
transition_type = SLIDE_LEFT_RIGHT,
vexpand = true
};
stack.add_child (description_box);
stack.add_child (password_box);

title_area.append (overlay);
title_area.append (title_label);

content_area.append (stack);

var back_button = new Gtk.Button.with_label (_("Back"));
content_area.valign = CENTER;
content_area.append (protect_row);
content_area.append (restart_row);
content_area.append (keyboard_row);
content_area.append (password_box);

var encrypt_button = new Gtk.Button.with_label (_("Choose Password"));
encrypt_button = new Gtk.Button.with_label (_("Set Password")) {
sensitive = false
};

next_button = new Gtk.Button.with_label (_(SKIP_STRING)) {
receives_default = true
};
next_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

action_box_end.append (back_button);
action_box_end.append (encrypt_button);
action_box_end.append (next_button);

next_button.grab_focus ();

back_button.clicked.connect (() => {
stack.visible_child = description_box;
next_button.label = _(SKIP_STRING);
next_button.sensitive = true;
back_button.hide ();
encrypt_button.show ();
shown.connect (() => {
((Gtk.Window) get_root ()).default_widget = encrypt_button;
});

encrypt_button.clicked.connect (() => {
stack.visible_child = password_box;
next_button.label = _("Set Encryption Password");
update_next_button ();
back_button.show ();
encrypt_button.hide ();

pw_entry.grab_focus ();
Configuration.get_default ().encryption_password = pw_entry.text;
next_step ();
});

next_button.clicked.connect (() => {
if (stack.visible_child == password_box) {
Configuration.get_default ().encryption_password = pw_entry.text;
}

next_step ();
});

Expand All @@ -191,8 +148,6 @@ public class EncryptView : AbstractInstallerView {
confirm_entry.is_valid = confirm_password ();
update_next_button ();
});

back_button.hide ();
}

private bool check_password () {
Expand Down Expand Up @@ -248,10 +203,9 @@ public class EncryptView : AbstractInstallerView {

private void update_next_button () {
if (pw_entry.is_valid && confirm_entry.is_valid) {
next_button.sensitive = true;
((Gtk.Window) get_root ()).default_widget = next_button;
encrypt_button.sensitive = true;
} else {
next_button.sensitive = false;
encrypt_button.sensitive = false;
}
}

Expand All @@ -260,6 +214,7 @@ public class EncryptView : AbstractInstallerView {

construct {
activates_default = true;
visibility = false;
}
}

Expand Down

0 comments on commit f86ddb4

Please sign in to comment.