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

PartitionMenu: write check_values as single function with early returns #815

Merged
merged 9 commits into from
Oct 1, 2024
47 changes: 16 additions & 31 deletions src/Widgets/PartitionMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
}
}
use_as.set_active (select);
update_values (set_mount);
check_values (set_mount);
} else {
unset_mount (partition_path);
partition_bar.icon = null;
Expand Down Expand Up @@ -250,39 +250,36 @@ public class Installer.PartitionMenu : Gtk.Popover {
}

private void check_values (SetMount set_mount) {
if (values_ready ()) {
update_values (set_mount);
if (!use_partition.active) {
partition_bar.icon = null;
return;
}

if (use_as.active == 4 && !custom.text.has_prefix ("/")) {
partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic");
partition_bar.tooltip_text = _("Custom value must begin with /");
return;
}
}

private void update_values (SetMount set_mount) {
var mount = get_mount ();
var filesystem = mount == "swap"
? InstallerDaemon.FileSystem.SWAP
: get_file_system ();
var filesystem = mount == "swap" ? InstallerDaemon.FileSystem.SWAP : get_file_system ();

string? error = null;
try {
set_mount (new Installer.Mount (
partition_path,
parent_disk,
mount,
partition_bar.get_partition_size (),
(format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0)
+ (is_lvm ? InstallerDaemon.MountFlags.LVM : 0),
+ (is_lvm ? InstallerDaemon.MountFlags.LVM : 0),
danirabbit marked this conversation as resolved.
Show resolved Hide resolved
filesystem,
this
));
} catch (GLib.Error why) {
error = why.message;
}

partition_bar.icon = new ThemedIcon (
error == null ? "process-completed-symbolic" : "dialog-warning-symbolic"
);

if (error != null) {
partition_bar.tooltip_text = error;
partition_bar.icon = new ThemedIcon ("process-completed-symbolic");
} catch (GLib.Error e) {
partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic");
partition_bar.tooltip_text = e.message;
danirabbit marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -327,16 +324,4 @@ public class Installer.PartitionMenu : Gtk.Popover {
return custom.get_text ();
}
}

private bool values_ready () {
return use_partition.active && (!custom_set () || custom_valid ());
}

private bool custom_set () {
return use_as.get_active () == 4;
}

private bool custom_valid () {
return custom.get_text ().has_prefix ("/");
}
}