diff --git a/src/drive_mount_row/imp.rs b/src/drive_mount_row/imp.rs index 6521363..4646559 100644 --- a/src/drive_mount_row/imp.rs +++ b/src/drive_mount_row/imp.rs @@ -1,4 +1,4 @@ -use std::{cell::{RefCell}, rc::Rc, sync::OnceLock}; +use std::{cell::RefCell, rc::Rc, sync::OnceLock}; use adw::{prelude::*, subclass::prelude::*, *}; use glib::{clone, subclass::Signal, Properties}; diff --git a/src/drive_mount_row/mod.rs b/src/drive_mount_row/mod.rs index 2d06456..089fe18 100644 --- a/src/drive_mount_row/mod.rs +++ b/src/drive_mount_row/mod.rs @@ -26,6 +26,7 @@ impl DriveMountRow { partition: create_parition_struct(&self.partition()), mountpoint: self.mountpoint(), mountopts: self.mountopts(), + used_by: self.id(), } } } diff --git a/src/manual_partitioning_page/func.rs b/src/manual_partitioning_page/func.rs index 9461c62..e1113c4 100644 --- a/src/manual_partitioning_page/func.rs +++ b/src/manual_partitioning_page/func.rs @@ -216,9 +216,10 @@ pub fn create_efi_row( } else { (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); } - partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ))); } )); @@ -241,8 +242,11 @@ pub fn create_efi_row( (*used_partition_array_refcell.borrow_mut()) .retain(|x| &x.partition.part_name != &row.partition()); partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + &glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ), + )); } ), ); @@ -282,7 +286,6 @@ pub fn create_boot_row( let null_checkbutton = gtk::CheckButton::builder().build(); - for partition in partition_array { let part_name = &partition.part_name.to_owned(); let partition_button = gtk::CheckButton::builder() @@ -445,9 +448,10 @@ pub fn create_boot_row( } else { (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); } - partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ))); } )); @@ -470,8 +474,11 @@ pub fn create_boot_row( (*used_partition_array_refcell.borrow_mut()) .retain(|x| &x.partition.part_name != &row.partition()); partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + &glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ), + )); } ), ); @@ -511,7 +518,6 @@ pub fn create_root_row( let null_checkbutton = gtk::CheckButton::builder().build(); - for partition in partition_array { let part_name = &partition.part_name.to_owned(); let partition_button = gtk::CheckButton::builder() @@ -679,9 +685,10 @@ pub fn create_root_row( } else { (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); } - partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ))); } )); @@ -704,8 +711,11 @@ pub fn create_root_row( (*used_partition_array_refcell.borrow_mut()) .retain(|x| &x.partition.part_name != &row.partition()); partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + &glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ), + )); } ), ); @@ -746,7 +756,6 @@ pub fn create_mount_row( let null_checkbutton = gtk::CheckButton::builder().build(); - for partition in partition_array { let part_name = &partition.part_name.to_owned(); let partition_button = gtk::CheckButton::builder() @@ -877,9 +886,10 @@ pub fn create_mount_row( } else { (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); } - partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ))); } )); @@ -902,8 +912,11 @@ pub fn create_mount_row( (*used_partition_array_refcell.borrow_mut()) .retain(|x| &x.partition.part_name != &row.partition()); partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) - )); + &glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ), + )); } ), ); @@ -966,14 +979,23 @@ fn post_check_drive_mount( if partition_button.is_active() == true { let part_name = &partition.part_name; row.set_partition(part_name.to_string()); - (*used_partition_array_refcell.borrow_mut()) - .push(DriveMountRow::get_fstab_entry(&row)); + if !used_partition_array_refcell + .borrow() + .iter() + .any(|e| part_name == &e.partition.part_name) + { + (*used_partition_array_refcell.borrow_mut()) + .push(DriveMountRow::get_fstab_entry(&row)); + } } else { (*used_partition_array_refcell.borrow_mut()) .retain(|x| &x.partition.part_name != &row.partition()); } partition_changed_action.activate(Some( - &glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING) + &glib::variant::Variant::from_data_with_type( + row.id().to_string(), + glib::VariantTy::STRING, + ), )); } } @@ -1035,10 +1057,14 @@ fn post_check_drive_mount( let used_partition_array = used_partition_array_refcell.borrow(); let subvol_partition_array = subvol_partition_array_refcell.borrow(); - let action_id = String::from_utf8_lossy(varient.unwrap().data()).parse::().unwrap(); + //dbg!(&used_partition_array); + + let action_id = String::from_utf8_lossy(varient.unwrap().data()) + .parse::() + .unwrap(); if used_partition_array.iter().any(|e| { - (part_name == &e.partition.part_name) + (part_name == &e.partition.part_name && part_name != &row.partition()) && (subvol_partition_array.iter().any(|e| part_name == e)) }) { if *partition_row_struct.never.borrow() == false @@ -1050,21 +1076,22 @@ fn post_check_drive_mount( (*partition_row_struct.used.borrow_mut()) = 2; } else if used_partition_array .iter() - .any(|e| part_name == &e.partition.part_name) + .any(|e| part_name == &e.partition.part_name && e.used_by != row.id() && !subvol_partition_array.iter().any(|e| part_name == e)) { - if action_id != row.id() { + if &row.partition() == part_name { null_checkbutton.set_active(true); - partition_row_struct.widget.set_sensitive(false); + row.set_partition(""); } + partition_row_struct.widget.set_sensitive(false); (*partition_row_struct.used.borrow_mut()) = 1; } else { - if *partition_row_struct.never.borrow() == false - && *partition_row_struct.swap_fs_error.borrow() == false - && *partition_row_struct.hardcode_fs_error.borrow() == false - { - partition_row_struct.widget.set_sensitive(true); - } - (*partition_row_struct.used.borrow_mut()) = 0; + if *partition_row_struct.never.borrow() == false + && *partition_row_struct.swap_fs_error.borrow() == false + && *partition_row_struct.hardcode_fs_error.borrow() == false + { + partition_row_struct.widget.set_sensitive(true); + } + (*partition_row_struct.used.borrow_mut()) = 0; } } )); diff --git a/src/manual_partitioning_page/mod.rs b/src/manual_partitioning_page/mod.rs index ec38ab4..592447a 100644 --- a/src/manual_partitioning_page/mod.rs +++ b/src/manual_partitioning_page/mod.rs @@ -32,11 +32,12 @@ pub fn manual_partitioning_page( let partition_array_refcell = Rc::new(RefCell::new(get_partitions())); let used_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); let subvol_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); - let extra_mount_id_refcell: Rc> = Rc::new(RefCell::default()); + let extra_mount_id_refcell: Rc> = Rc::new(RefCell::new(3)); // - let partition_changed_action = gio::SimpleAction::new("partition-changed", Some(glib::VariantTy::STRING)); + let partition_changed_action = + gio::SimpleAction::new("partition-changed", Some(glib::VariantTy::STRING)); // @@ -73,7 +74,7 @@ pub fn manual_partitioning_page( &language_changed_action, &used_partition_array_refcell, &subvol_partition_array_refcell, - &extra_mount_id_refcell + &extra_mount_id_refcell, ); let open_disk_utility_button = gtk::Button::builder() @@ -167,6 +168,7 @@ pub fn manual_partitioning_page( (*partition_method_manual_crypttab_entry_array_refcell.borrow_mut()) = Vec::new(); (*used_partition_array_refcell.borrow_mut()) = Vec::new(); (*subvol_partition_array_refcell.borrow_mut()) = Vec::new(); + (*extra_mount_id_refcell.borrow_mut()) = 3; create_hardcoded_rows( &drive_mounts_adw_listbox, &drive_rows_size_group, @@ -175,7 +177,7 @@ pub fn manual_partitioning_page( &language_changed_action, &used_partition_array_refcell, &subvol_partition_array_refcell, - &extra_mount_id_refcell + &extra_mount_id_refcell, ); } )); @@ -498,7 +500,7 @@ fn create_hardcoded_rows( &language_changed_action, &used_partition_array_refcell, &subvol_partition_array_refcell, - &extra_mount_id_refcell + &extra_mount_id_refcell, ); } )); diff --git a/src/partitioning_page/mod.rs b/src/partitioning_page/mod.rs index 0486650..2724c6b 100644 --- a/src/partitioning_page/mod.rs +++ b/src/partitioning_page/mod.rs @@ -191,6 +191,7 @@ pub struct FstabEntry { pub partition: Partition, pub mountpoint: String, pub mountopts: String, + pub used_by: i32, } #[derive(Default, Clone, Debug)]