Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncryptView: use single view #847

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 it, <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 (_("Encryption Password")) {
secondary_text = _("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, 6);
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 Encryption 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