From 8d2e4bd4720d5f161109b034de0d76606f00f0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 09:21:58 -0700 Subject: [PATCH 1/4] DRY DiskBar construction, PartitionBlock: GObject --- src/Views/PartitioningView.vala | 30 ++++++++++----------- src/Widgets/PartitionBlock.vala | 48 ++++++++++++++------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index a8d4880df..7bfe6a782 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -171,19 +171,11 @@ public class Installer.PartitioningView : AbstractInstallerView { } foreach (unowned InstallerDaemon.Disk disk in disks.physical_disks) { - var partitions = new Gee.ArrayList (); - foreach (unowned InstallerDaemon.Partition part in disk.partitions) { - var partition = new PartitionBlock (part, disk.device_path, disk.sector_size, false, this.set_mount, this.unset_mount, this.mount_is_set); - partition.decrypted.connect (on_partition_decrypted); - partitions.add (partition); - } - - var disk_bar = new DiskBar (disk, (owned) partitions); - disk_list.append (disk_bar); + disk_list.append (get_disk_bar (disk, false)); } foreach (unowned InstallerDaemon.Disk disk in disks.logical_disks) { - add_logical_disk (disk); + disk_list.append (get_disk_bar (disk, true)); } load_stack.set_visible_child_name ("disk"); @@ -218,16 +210,22 @@ public class Installer.PartitioningView : AbstractInstallerView { load_disks.begin (); } - private void add_logical_disk (InstallerDaemon.Disk disk) { + private DiskBar get_disk_bar (InstallerDaemon.Disk disk, bool lvm) { var partitions = new Gee.ArrayList (); foreach (unowned InstallerDaemon.Partition part in disk.partitions) { - var partition = new PartitionBlock (part, disk.device_path, disk.sector_size, true, this.set_mount, this.unset_mount, this.mount_is_set); - partition.decrypted.connect (on_partition_decrypted); + var partition = new PartitionBlock (part, disk.device_path, disk.sector_size); + + if (part.filesystem == LUKS) { + partition.menu = new DecryptMenu (part.device_path); + ((DecryptMenu) partition.menu).decrypted.connect (on_partition_decrypted); + } else { + partition.menu = new PartitionMenu (part.device_path, disk.device_path, part.filesystem, lvm, this.set_mount, this.unset_mount, this.mount_is_set, partition); + } + partitions.add (partition); } - var disk_bar = new DiskBar (disk, (owned) partitions); - disk_list.append (disk_bar); + return new DiskBar (disk, (owned) partitions); } private void validate_status () { @@ -269,7 +267,7 @@ public class Installer.PartitioningView : AbstractInstallerView { Daemon.get_default ().get_logical_device.begin (credentials.pv, (obj, res) => { try { var disk = ((Daemon)obj).get_logical_device.end (res); - add_logical_disk (disk); + disk_list.append (get_disk_bar (disk, true)); } catch (Error e) { critical ("Unable to get logical device: %s", e.message); } diff --git a/src/Widgets/PartitionBlock.vala b/src/Widgets/PartitionBlock.vala index 24ac56531..f3aeed35c 100644 --- a/src/Widgets/PartitionBlock.vala +++ b/src/Widgets/PartitionBlock.vala @@ -10,42 +10,34 @@ public class Installer.PartitionBlock : Adw.Bin { public Icon? icon { get; set; default = null; } - public bool lvm { get; construct; } + private Gtk.Popover _menu; + public Gtk.Popover menu { + get { + return _menu; + } + + set { + _menu = value; + _menu.set_parent (this); + _menu.position = BOTTOM; + + var click_gesture = new Gtk.GestureClick (); + click_gesture.released.connect (_menu.popup); + + add_controller (click_gesture); + } + } + public InstallerDaemon.Partition partition { get; construct; } public string parent_path { get; construct; } public string? volume_group { get; private set; } - public Gtk.Popover menu { get; private set; } - - public PartitionBlock ( - InstallerDaemon.Partition partition, - string parent_path, - uint64 sector_size, - bool lvm, - SetMount set_mount, - UnsetMount unset_mount, - MountSetFn mount_set - ) { + + public PartitionBlock (InstallerDaemon.Partition partition, string parent_path, uint64 sector_size) { Object ( - lvm: lvm, parent_path: parent_path, partition: partition ); - - if (partition.filesystem == LUKS) { - menu = new DecryptMenu (partition.device_path); - ((DecryptMenu)menu).decrypted.connect ((creds) => decrypted (creds)); - } else { - menu = new PartitionMenu (partition.device_path, parent_path, partition.filesystem, lvm, set_mount, unset_mount, mount_set, this); - } - - menu.set_parent (this); - menu.position = BOTTOM; - - var click_gesture = new Gtk.GestureClick (); - click_gesture.released.connect (menu.popup); - - add_controller (click_gesture); } class construct { From 37459cb2762fc8882d7c10578df7e4597ebf4a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 09:23:31 -0700 Subject: [PATCH 2/4] Simplify PartitionBlock even further --- src/Views/PartitioningView.vala | 2 +- src/Widgets/PartitionBlock.vala | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 7bfe6a782..d5903ab67 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -213,7 +213,7 @@ public class Installer.PartitioningView : AbstractInstallerView { private DiskBar get_disk_bar (InstallerDaemon.Disk disk, bool lvm) { var partitions = new Gee.ArrayList (); foreach (unowned InstallerDaemon.Partition part in disk.partitions) { - var partition = new PartitionBlock (part, disk.device_path, disk.sector_size); + var partition = new PartitionBlock (part); if (part.filesystem == LUKS) { partition.menu = new DecryptMenu (part.device_path); diff --git a/src/Widgets/PartitionBlock.vala b/src/Widgets/PartitionBlock.vala index f3aeed35c..390a121fc 100644 --- a/src/Widgets/PartitionBlock.vala +++ b/src/Widgets/PartitionBlock.vala @@ -29,15 +29,11 @@ public class Installer.PartitionBlock : Adw.Bin { } public InstallerDaemon.Partition partition { get; construct; } - public string parent_path { get; construct; } public string? volume_group { get; private set; } - public PartitionBlock (InstallerDaemon.Partition partition, string parent_path, uint64 sector_size) { - Object ( - parent_path: parent_path, - partition: partition - ); + public PartitionBlock (InstallerDaemon.Partition partition) { + Object (partition: partition); } class construct { From 91ce9c3b5945af1597adb5eadad077149db281f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 09:58:10 -0700 Subject: [PATCH 3/4] Even smaller --- src/Widgets/DiskBar.vala | 2 +- src/Widgets/PartitionBlock.vala | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index 807bb905d..9d7c84e0f 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -40,7 +40,7 @@ public class Installer.DiskBar: Gtk.Box { p.partition.device_path, p.get_partition_size () * 512, p.partition.filesystem.to_string (), - p.volume_group, + p.partition.filesystem == LVM ? p.partition.current_lvm_volume_group : null, p.menu ); } diff --git a/src/Widgets/PartitionBlock.vala b/src/Widgets/PartitionBlock.vala index 390a121fc..e9bc46449 100644 --- a/src/Widgets/PartitionBlock.vala +++ b/src/Widgets/PartitionBlock.vala @@ -30,8 +30,6 @@ public class Installer.PartitionBlock : Adw.Bin { public InstallerDaemon.Partition partition { get; construct; } - public string? volume_group { get; private set; } - public PartitionBlock (InstallerDaemon.Partition partition) { Object (partition: partition); } @@ -41,8 +39,6 @@ public class Installer.PartitionBlock : Adw.Bin { } construct { - volume_group = (partition.filesystem == LVM) ? partition.current_lvm_volume_group : null; - var image = new Gtk.Image () { halign = END, valign = END From 7a51f46dbe0d6de713cda4e5816722d68d148c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 30 Sep 2024 16:18:01 -0700 Subject: [PATCH 4/4] Remove unused signal --- src/Widgets/PartitionBlock.vala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Widgets/PartitionBlock.vala b/src/Widgets/PartitionBlock.vala index e9bc46449..a3e977287 100644 --- a/src/Widgets/PartitionBlock.vala +++ b/src/Widgets/PartitionBlock.vala @@ -6,8 +6,6 @@ */ public class Installer.PartitionBlock : Adw.Bin { - public signal void decrypted (InstallerDaemon.LuksCredentials credential); - public Icon? icon { get; set; default = null; } private Gtk.Popover _menu;