From e0716187bd0a67e4443d1dc4f7ee75617045457a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 23 Sep 2024 10:48:35 -0700 Subject: [PATCH 1/2] PartitionMenu: closer to GObject-style --- src/Widgets/PartitionBar.vala | 2 +- src/Widgets/PartitionMenu.vala | 96 ++++++++++++++++------------------ 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/Widgets/PartitionBar.vala b/src/Widgets/PartitionBar.vala index 0ae7c8743..c154f498c 100644 --- a/src/Widgets/PartitionBar.vala +++ b/src/Widgets/PartitionBar.vala @@ -36,7 +36,7 @@ public class Installer.PartitionBar : Gtk.Box { 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 = new PartitionMenu (partition, parent_path, lvm, set_mount, unset_mount, mount_set, this); } menu.set_parent (this); diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 4fa4b446d..ee94488c1 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -1,18 +1,6 @@ -/*- - * Copyright 2018-2021 elementary, inc. (https://elementary.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2018-2024 elementary, Inc. (https://elementary.io) * * Authored by: Michael Aaron Murphy */ @@ -24,46 +12,52 @@ public delegate void UnsetMount (string partition); public delegate bool MountSetFn (string mount_point); public class Installer.PartitionMenu : Gtk.Popover { + public InstallerDaemon.Partition partition { get; construct; } + public string parent_disk { get; construct; } + public bool is_lvm { get; construct; } + // A reference to the parent which owns this menu. + public PartitionBar partition_bar { get; construct; } + private bool disable_signals; - private bool is_lvm; - private string parent_disk; - private string partition_path; - private InstallerDaemon.FileSystem original_filesystem; private Granite.SwitchModelButton format_partition; private Granite.SwitchModelButton use_partition; private Gtk.ComboBoxText type; private Gtk.ComboBoxText use_as; private Gtk.Entry custom; - private Gtk.Label custom_label; - private Gtk.Label type_label; - // A reference to the parent which owns this menu. - private PartitionBar partition_bar; - - public PartitionMenu (string path, string parent, InstallerDaemon.FileSystem fs, - bool lvm, SetMount set_mount, UnsetMount unset_mount, - MountSetFn mount_set, PartitionBar partition_bar) { - this.partition_bar = partition_bar; - original_filesystem = fs; - is_lvm = lvm; - partition_path = path; - parent_disk = parent; - - string boot_partition = (Daemon.get_default ().bootloader_detect () == Distinst.PartitionTable.GPT) + + public PartitionMenu ( + InstallerDaemon.Partition partition, + string parent, + bool lvm, + SetMount set_mount, + UnsetMount unset_mount, + MountSetFn mount_set, + PartitionBar partition_bar + ) { + Object ( + partition: partition, + parent_disk: parent, + is_lvm: lvm, + partition_bar: partition_bar + ); + + var boot_partition = (Daemon.get_default ().bootloader_detect () == GPT) ? "/boot/efi" : "/boot"; use_partition = new Granite.SwitchModelButton (_("Use Partition")); - var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); + var separator = new Gtk.Separator (HORIZONTAL); format_partition = new Granite.SwitchModelButton (_("Format")) { description = _("Delete all data and set up a new file system") }; - var use_as_label = new Gtk.Label (_("Use as:")); - use_as_label.halign = Gtk.Align.END; - use_as_label.xalign = 1; + var use_as_label = new Gtk.Label (_("Use as:")) { + halign = END, + xalign = 1 + }; use_as = new Gtk.ComboBoxText () { hexpand = true @@ -76,18 +70,20 @@ public class Installer.PartitionMenu : Gtk.Popover { use_as.active = 0; use_as.bind_property ("visible", use_as_label, "visible"); - custom_label = new Gtk.Label (_("Custom:")); - custom_label.halign = Gtk.Align.END; - custom_label.xalign = 1; + var custom_label = new Gtk.Label (_("Custom:")) { + halign = END, + xalign = 1 + }; custom = new Gtk.Entry (); custom.bind_property ("visible", custom_label, "visible"); - type_label = new Gtk.Label (_("Filesystem:")); - type_label.halign = Gtk.Align.END; - type_label.xalign = 1; + var type_label = new Gtk.Label (_("Filesystem:")) { + halign = END, + xalign = 1 + }; - var label_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL); + var label_size_group = new Gtk.SizeGroup (HORIZONTAL); label_size_group.add_widget (use_as_label); label_size_group.add_widget (custom_label); label_size_group.add_widget (type_label); @@ -205,13 +201,13 @@ public class Installer.PartitionMenu : Gtk.Popover { disable_signals = false; int select = 0; - if (fs == InstallerDaemon.FileSystem.FAT16 || fs == InstallerDaemon.FileSystem.FAT32) { + if (partition.filesystem == FAT16 || partition.filesystem == FAT32) { if (mount_set (boot_partition)) { select = 4; } else { select = 2; } - } else if (fs == InstallerDaemon.FileSystem.SWAP) { + } else if (partition.filesystem == SWAP) { select = 3; } else if (mount_set ("/")) { if (mount_set ("/home" )) { @@ -223,7 +219,7 @@ public class Installer.PartitionMenu : Gtk.Popover { use_as.set_active (select); update_values (set_mount); } else { - unset_mount (partition_path); + unset_mount (partition.device_path); partition_bar.icon = null; } @@ -264,7 +260,7 @@ public class Installer.PartitionMenu : Gtk.Popover { string? error = null; try { set_mount (new Installer.Mount ( - partition_path, + partition.device_path, parent_disk, mount, partition_bar.get_partition_size (), @@ -287,7 +283,7 @@ public class Installer.PartitionMenu : Gtk.Popover { } private bool has_same_filesystem () { - return original_filesystem == get_file_system (); + return partition.filesystem == get_file_system (); } private InstallerDaemon.FileSystem get_file_system () { From 3f44b723018e6984ed965fc4902c825c971fdc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 10:13:35 -0700 Subject: [PATCH 2/2] get partition size from partition directly --- src/Widgets/PartitionMenu.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 57cc2a31d..a345e9bf0 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -263,7 +263,7 @@ public class Installer.PartitionMenu : Gtk.Popover { partition.device_path, parent_disk, mount, - partition_block.get_partition_size (), + partition.end_sector - partition.start_sector, (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), filesystem,