Skip to content

Commit

Permalink
DRY DiskBar construction, PartitionBlock: GObject
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Sep 24, 2024
1 parent fe60a17 commit 8d2e4bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 44 deletions.
30 changes: 14 additions & 16 deletions src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,11 @@ public class Installer.PartitioningView : AbstractInstallerView {
}

foreach (unowned InstallerDaemon.Disk disk in disks.physical_disks) {
var partitions = new Gee.ArrayList<PartitionBlock> ();
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");
Expand Down Expand Up @@ -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<PartitionBlock> ();
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 () {
Expand Down Expand Up @@ -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);
}
Expand Down
48 changes: 20 additions & 28 deletions src/Widgets/PartitionBlock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8d2e4bd

Please sign in to comment.