try to add IDs
This commit is contained in:
parent
65030405d0
commit
6f81fda8d1
@ -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 adw::{prelude::*, subclass::prelude::*, *};
|
||||||
use glib::{clone, subclass::Signal, Properties};
|
use glib::{clone, subclass::Signal, Properties};
|
||||||
@ -25,6 +25,8 @@ pub struct DriveMountRow {
|
|||||||
sizegroup: RefCell<Option<gtk::SizeGroup>>,
|
sizegroup: RefCell<Option<gtk::SizeGroup>>,
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
langaction: RefCell<Option<gio::SimpleAction>>,
|
langaction: RefCell<Option<gio::SimpleAction>>,
|
||||||
|
#[property(get, set)]
|
||||||
|
id: RefCell<i32>,
|
||||||
}
|
}
|
||||||
// ANCHOR_END: custom_button
|
// ANCHOR_END: custom_button
|
||||||
|
|
||||||
|
@ -5,13 +5,14 @@ use adw::gio;
|
|||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use glib::{clone, closure_local, ffi::gboolean};
|
use glib::{clone, closure_local, ffi::gboolean};
|
||||||
use gtk::{glib, prelude::*};
|
use gtk::{glib, prelude::*};
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::borrow::Borrow;
|
||||||
|
use std::{cell::{RefCell}, rc::Rc};
|
||||||
|
|
||||||
const MINIMUM_EFI_BYTE_SIZE: f64 = 500000000.0;
|
const MINIMUM_EFI_BYTE_SIZE: f64 = 500000000.0;
|
||||||
const MINIMUM_BOOT_BYTE_SIZE: f64 = 1000000000.0;
|
const MINIMUM_BOOT_BYTE_SIZE: f64 = 1000000000.0;
|
||||||
const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0;
|
const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct PartitionRow {
|
struct PartitionRow {
|
||||||
widget: adw::ActionRow,
|
widget: adw::ActionRow,
|
||||||
swap_fs_error: Rc<std::cell::RefCell<bool>>,
|
swap_fs_error: Rc<std::cell::RefCell<bool>>,
|
||||||
@ -50,6 +51,8 @@ pub fn create_efi_row(
|
|||||||
|
|
||||||
row.set_mountpoint("/boot/efi");
|
row.set_mountpoint("/boot/efi");
|
||||||
|
|
||||||
|
row.set_id(0);
|
||||||
|
|
||||||
let null_checkbutton = gtk::CheckButton::builder().build();
|
let null_checkbutton = gtk::CheckButton::builder().build();
|
||||||
|
|
||||||
for partition in partition_array {
|
for partition in partition_array {
|
||||||
@ -191,6 +194,7 @@ pub fn create_efi_row(
|
|||||||
post_check_drive_mount(
|
post_check_drive_mount(
|
||||||
&row,
|
&row,
|
||||||
&partition_row_struct,
|
&partition_row_struct,
|
||||||
|
&null_checkbutton,
|
||||||
&partition_button,
|
&partition_button,
|
||||||
&partition_changed_action,
|
&partition_changed_action,
|
||||||
&partition,
|
&partition,
|
||||||
@ -213,7 +217,9 @@ pub fn create_efi_row(
|
|||||||
} else {
|
} else {
|
||||||
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
||||||
}
|
}
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -235,7 +241,9 @@ pub fn create_efi_row(
|
|||||||
listbox.remove(&row);
|
listbox.remove(&row);
|
||||||
(*used_partition_array_refcell.borrow_mut())
|
(*used_partition_array_refcell.borrow_mut())
|
||||||
.retain(|x| &x.partition.part_name != &row.partition());
|
.retain(|x| &x.partition.part_name != &row.partition());
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -271,8 +279,11 @@ pub fn create_boot_row(
|
|||||||
|
|
||||||
row.set_mountpoint("/boot");
|
row.set_mountpoint("/boot");
|
||||||
|
|
||||||
|
row.set_id(1);
|
||||||
|
|
||||||
let null_checkbutton = gtk::CheckButton::builder().build();
|
let null_checkbutton = gtk::CheckButton::builder().build();
|
||||||
|
|
||||||
|
|
||||||
for partition in partition_array {
|
for partition in partition_array {
|
||||||
let part_name = &partition.part_name.to_owned();
|
let part_name = &partition.part_name.to_owned();
|
||||||
let partition_button = gtk::CheckButton::builder()
|
let partition_button = gtk::CheckButton::builder()
|
||||||
@ -412,6 +423,7 @@ pub fn create_boot_row(
|
|||||||
post_check_drive_mount(
|
post_check_drive_mount(
|
||||||
&row,
|
&row,
|
||||||
&partition_row_struct,
|
&partition_row_struct,
|
||||||
|
&null_checkbutton,
|
||||||
&partition_button,
|
&partition_button,
|
||||||
&partition_changed_action,
|
&partition_changed_action,
|
||||||
&partition,
|
&partition,
|
||||||
@ -434,7 +446,9 @@ pub fn create_boot_row(
|
|||||||
} else {
|
} else {
|
||||||
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
||||||
}
|
}
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -456,7 +470,9 @@ pub fn create_boot_row(
|
|||||||
listbox.remove(&row);
|
listbox.remove(&row);
|
||||||
(*used_partition_array_refcell.borrow_mut())
|
(*used_partition_array_refcell.borrow_mut())
|
||||||
.retain(|x| &x.partition.part_name != &row.partition());
|
.retain(|x| &x.partition.part_name != &row.partition());
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -492,8 +508,11 @@ pub fn create_root_row(
|
|||||||
|
|
||||||
row.set_mountpoint("/");
|
row.set_mountpoint("/");
|
||||||
|
|
||||||
|
row.set_id(2);
|
||||||
|
|
||||||
let null_checkbutton = gtk::CheckButton::builder().build();
|
let null_checkbutton = gtk::CheckButton::builder().build();
|
||||||
|
|
||||||
|
|
||||||
for partition in partition_array {
|
for partition in partition_array {
|
||||||
let part_name = &partition.part_name.to_owned();
|
let part_name = &partition.part_name.to_owned();
|
||||||
let partition_button = gtk::CheckButton::builder()
|
let partition_button = gtk::CheckButton::builder()
|
||||||
@ -638,6 +657,7 @@ pub fn create_root_row(
|
|||||||
post_check_drive_mount(
|
post_check_drive_mount(
|
||||||
&row,
|
&row,
|
||||||
&partition_row_struct,
|
&partition_row_struct,
|
||||||
|
&null_checkbutton,
|
||||||
&partition_button,
|
&partition_button,
|
||||||
&partition_changed_action,
|
&partition_changed_action,
|
||||||
&partition,
|
&partition,
|
||||||
@ -660,7 +680,9 @@ pub fn create_root_row(
|
|||||||
} else {
|
} else {
|
||||||
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
||||||
}
|
}
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -682,7 +704,9 @@ pub fn create_root_row(
|
|||||||
listbox.remove(&row);
|
listbox.remove(&row);
|
||||||
(*used_partition_array_refcell.borrow_mut())
|
(*used_partition_array_refcell.borrow_mut())
|
||||||
.retain(|x| &x.partition.part_name != &row.partition());
|
.retain(|x| &x.partition.part_name != &row.partition());
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -696,6 +720,7 @@ pub fn create_mount_row(
|
|||||||
language_changed_action: &gio::SimpleAction,
|
language_changed_action: &gio::SimpleAction,
|
||||||
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
|
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
|
||||||
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
|
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
|
||||||
|
extra_mount_id_refcell: &Rc<RefCell<i32>>,
|
||||||
) {
|
) {
|
||||||
let partition_scroll_child = gtk::ListBox::builder()
|
let partition_scroll_child = gtk::ListBox::builder()
|
||||||
.selection_mode(gtk::SelectionMode::None)
|
.selection_mode(gtk::SelectionMode::None)
|
||||||
@ -716,8 +741,11 @@ pub fn create_mount_row(
|
|||||||
|
|
||||||
row.set_langaction(language_changed_action);
|
row.set_langaction(language_changed_action);
|
||||||
|
|
||||||
|
row.set_id(extra_mount_id_refcell.borrow());
|
||||||
|
|
||||||
let null_checkbutton = gtk::CheckButton::builder().build();
|
let null_checkbutton = gtk::CheckButton::builder().build();
|
||||||
|
|
||||||
|
|
||||||
for partition in partition_array {
|
for partition in partition_array {
|
||||||
let part_name = &partition.part_name.to_owned();
|
let part_name = &partition.part_name.to_owned();
|
||||||
let partition_button = gtk::CheckButton::builder()
|
let partition_button = gtk::CheckButton::builder()
|
||||||
@ -825,6 +853,7 @@ pub fn create_mount_row(
|
|||||||
post_check_drive_mount(
|
post_check_drive_mount(
|
||||||
&row,
|
&row,
|
||||||
&partition_row_struct,
|
&partition_row_struct,
|
||||||
|
&null_checkbutton,
|
||||||
&partition_button,
|
&partition_button,
|
||||||
&partition_changed_action,
|
&partition_changed_action,
|
||||||
&partition,
|
&partition,
|
||||||
@ -847,7 +876,9 @@ pub fn create_mount_row(
|
|||||||
} else {
|
} else {
|
||||||
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
|
||||||
}
|
}
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -869,7 +900,9 @@ pub fn create_mount_row(
|
|||||||
listbox.remove(&row);
|
listbox.remove(&row);
|
||||||
(*used_partition_array_refcell.borrow_mut())
|
(*used_partition_array_refcell.borrow_mut())
|
||||||
.retain(|x| &x.partition.part_name != &row.partition());
|
.retain(|x| &x.partition.part_name != &row.partition());
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -878,6 +911,7 @@ pub fn create_mount_row(
|
|||||||
fn post_check_drive_mount(
|
fn post_check_drive_mount(
|
||||||
row: &DriveMountRow,
|
row: &DriveMountRow,
|
||||||
partition_row_struct: &PartitionRow,
|
partition_row_struct: &PartitionRow,
|
||||||
|
null_checkbutton: >k::CheckButton,
|
||||||
partition_button: >k::CheckButton,
|
partition_button: >k::CheckButton,
|
||||||
partition_changed_action: &gio::SimpleAction,
|
partition_changed_action: &gio::SimpleAction,
|
||||||
partition: &Partition,
|
partition: &Partition,
|
||||||
@ -888,6 +922,10 @@ fn post_check_drive_mount(
|
|||||||
partition_button.connect_toggled(clone!(
|
partition_button.connect_toggled(clone!(
|
||||||
#[weak]
|
#[weak]
|
||||||
row,
|
row,
|
||||||
|
#[strong]
|
||||||
|
null_checkbutton,
|
||||||
|
#[strong]
|
||||||
|
partition_row_struct,
|
||||||
#[weak]
|
#[weak]
|
||||||
partition_button,
|
partition_button,
|
||||||
#[strong]
|
#[strong]
|
||||||
@ -897,6 +935,33 @@ fn post_check_drive_mount(
|
|||||||
#[strong]
|
#[strong]
|
||||||
partition,
|
partition,
|
||||||
move |_| {
|
move |_| {
|
||||||
|
let (check_delay_sender, check_delay_receiver) = async_channel::unbounded::<bool>();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
check_delay_sender
|
||||||
|
.send_blocking(true)
|
||||||
|
.expect("The channel needs to be open.");
|
||||||
|
});
|
||||||
|
|
||||||
|
let check_delay_main_context = glib::MainContext::default();
|
||||||
|
check_delay_main_context.spawn_local(clone!(
|
||||||
|
#[weak]
|
||||||
|
row,
|
||||||
|
#[strong]
|
||||||
|
null_checkbutton,
|
||||||
|
#[strong]
|
||||||
|
partition_row_struct,
|
||||||
|
#[weak]
|
||||||
|
partition_button,
|
||||||
|
#[strong]
|
||||||
|
partition_changed_action,
|
||||||
|
#[strong]
|
||||||
|
used_partition_array_refcell,
|
||||||
|
#[strong]
|
||||||
|
partition,
|
||||||
|
async move {
|
||||||
|
while let Ok(_state) = check_delay_receiver.recv().await {
|
||||||
|
if !null_checkbutton.is_active() {
|
||||||
if partition_button.is_active() == true {
|
if partition_button.is_active() == true {
|
||||||
let part_name = &partition.part_name;
|
let part_name = &partition.part_name;
|
||||||
row.set_partition(part_name.to_string());
|
row.set_partition(part_name.to_string());
|
||||||
@ -906,13 +971,21 @@ fn post_check_drive_mount(
|
|||||||
(*used_partition_array_refcell.borrow_mut())
|
(*used_partition_array_refcell.borrow_mut())
|
||||||
.retain(|x| &x.partition.part_name != &row.partition());
|
.retain(|x| &x.partition.part_name != &row.partition());
|
||||||
}
|
}
|
||||||
partition_changed_action.activate(None);
|
partition_changed_action.activate(Some(
|
||||||
|
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
row.connect_mountpoint_notify(clone!(
|
row.connect_mountpoint_notify(clone!(
|
||||||
#[strong]
|
#[strong]
|
||||||
partition_row_struct,
|
partition_row_struct,
|
||||||
#[strong]
|
#[strong]
|
||||||
|
null_checkbutton,
|
||||||
|
#[strong]
|
||||||
partition,
|
partition,
|
||||||
#[strong]
|
#[strong]
|
||||||
row,
|
row,
|
||||||
@ -928,9 +1001,11 @@ fn post_check_drive_mount(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(*partition_row_struct.swap_fs_error.borrow_mut()) = true;
|
(*partition_row_struct.swap_fs_error.borrow_mut()) = true;
|
||||||
|
null_checkbutton.set_active(true);
|
||||||
partition_row_struct.widget.set_sensitive(false);
|
partition_row_struct.widget.set_sensitive(false);
|
||||||
}
|
}
|
||||||
} else if *partition_row_struct.used.borrow() != 1
|
} else {
|
||||||
|
if *partition_row_struct.used.borrow() != 1
|
||||||
&& *partition_row_struct.never.borrow() == false
|
&& *partition_row_struct.never.borrow() == false
|
||||||
&& *partition_row_struct.hardcode_fs_error.borrow() == false
|
&& *partition_row_struct.hardcode_fs_error.borrow() == false
|
||||||
{
|
{
|
||||||
@ -938,12 +1013,15 @@ fn post_check_drive_mount(
|
|||||||
partition_row_struct.widget.set_sensitive(true);
|
partition_row_struct.widget.set_sensitive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
partition_changed_action.connect_activate(clone!(
|
partition_changed_action.connect_activate(clone!(
|
||||||
#[strong]
|
#[strong]
|
||||||
partition_row_struct,
|
partition_row_struct,
|
||||||
#[strong]
|
#[strong]
|
||||||
|
null_checkbutton,
|
||||||
|
#[strong]
|
||||||
row,
|
row,
|
||||||
#[strong]
|
#[strong]
|
||||||
partition,
|
partition,
|
||||||
@ -951,13 +1029,15 @@ fn post_check_drive_mount(
|
|||||||
used_partition_array_refcell,
|
used_partition_array_refcell,
|
||||||
#[strong]
|
#[strong]
|
||||||
subvol_partition_array_refcell,
|
subvol_partition_array_refcell,
|
||||||
move |_, _| {
|
move |_, varient| {
|
||||||
let part_name = &partition.part_name;
|
let part_name = &partition.part_name;
|
||||||
let used_partition_array = used_partition_array_refcell.borrow();
|
let used_partition_array = used_partition_array_refcell.borrow();
|
||||||
let subvol_partition_array = subvol_partition_array_refcell.borrow();
|
let subvol_partition_array = subvol_partition_array_refcell.borrow();
|
||||||
|
|
||||||
|
let action_id = String::from_utf8_lossy(varient.unwrap().data()).parse::<i32>().unwrap();
|
||||||
|
|
||||||
if used_partition_array.iter().any(|e| {
|
if used_partition_array.iter().any(|e| {
|
||||||
(part_name == &e.partition.part_name && part_name != &row.partition())
|
(part_name == &e.partition.part_name)
|
||||||
&& (subvol_partition_array.iter().any(|e| part_name == e))
|
&& (subvol_partition_array.iter().any(|e| part_name == e))
|
||||||
}) {
|
}) {
|
||||||
if *partition_row_struct.never.borrow() == false
|
if *partition_row_struct.never.borrow() == false
|
||||||
@ -969,9 +1049,12 @@ fn post_check_drive_mount(
|
|||||||
(*partition_row_struct.used.borrow_mut()) = 2;
|
(*partition_row_struct.used.borrow_mut()) = 2;
|
||||||
} else if used_partition_array
|
} else if used_partition_array
|
||||||
.iter()
|
.iter()
|
||||||
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
|
.any(|e| part_name == &e.partition.part_name)
|
||||||
{
|
{
|
||||||
|
if action_id != row.id() {
|
||||||
|
null_checkbutton.set_active(true);
|
||||||
partition_row_struct.widget.set_sensitive(false);
|
partition_row_struct.widget.set_sensitive(false);
|
||||||
|
}
|
||||||
(*partition_row_struct.used.borrow_mut()) = 1;
|
(*partition_row_struct.used.borrow_mut()) = 1;
|
||||||
} else {
|
} else {
|
||||||
if *partition_row_struct.never.borrow() == false
|
if *partition_row_struct.never.borrow() == false
|
||||||
|
@ -6,6 +6,7 @@ use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partit
|
|||||||
use adw::gio;
|
use adw::gio;
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use glib::{clone, closure_local, ffi::gboolean};
|
use glib::{clone, closure_local, ffi::gboolean};
|
||||||
|
use gtk::glib::Variant;
|
||||||
use gtk::{glib, prelude::*, Orientation};
|
use gtk::{glib, prelude::*, Orientation};
|
||||||
use std::{cell::RefCell, collections::HashSet, rc::Rc};
|
use std::{cell::RefCell, collections::HashSet, rc::Rc};
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ pub fn manual_partitioning_page(
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
let partition_changed_action = gio::SimpleAction::new("partition-changed", None);
|
let partition_changed_action = gio::SimpleAction::new("partition-changed", Some(glib::VariantTy::STRING));
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user