From d152501356d05cd2deea55b40d7697a836873449 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 19 Aug 2024 02:12:35 +0300 Subject: [PATCH] Fix Swap support --- locales/en_US.json | 16 +- src/automatic_partitioning_page/mod.rs | 605 +++++++------ src/build_ui.rs | 79 +- src/drive_mount_row/imp.rs | 95 +-- src/drive_mount_row/mod.rs | 4 +- src/efi_error_page/mod.rs | 6 +- src/eula_page/mod.rs | 91 +- src/installer_stack_page/imp.rs | 17 +- src/keyboard_page/mod.rs | 129 ++- src/language_page/mod.rs | 237 ++---- src/main.rs | 29 +- src/manual_partitioning/mod.rs | 99 --- src/manual_partitioning_page/mod.rs | 1084 ++++++++++++++---------- src/partitioning_page/mod.rs | 223 +++-- src/timezone_page/mod.rs | 132 +-- src/welcome_page/mod.rs | 37 +- 16 files changed, 1448 insertions(+), 1435 deletions(-) delete mode 100644 src/manual_partitioning/mod.rs diff --git a/locales/en_US.json b/locales/en_US.json index 10de611..0e3b320 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -26,15 +26,13 @@ "fstab_no_mountpoint_err": "Filesystem Table Error: One or more partitions don't have a mountpoint configured!", "fstab_no_partition_err": "Filesystem Table Error: One or more entries don't have a partition configured!", "fstab_badfs": "Filesystem Table Error: Invalid filesystem: (/dev/", - "fstab_small_efi_size": ") Must at least be 512MBs!", - "fstab_badfs_efi": ") Must be FAT32/vFAT to be mounted at /boot/efi!", - "fstab_small_boot_size": ") Must at least be 1GBs!", - "fstab_badfs_boot": ") Must not be FAT32/vFAT to be mounted at /boot!", - "fstab_small_root_size": ") Must at least be 26GBs!", - "fstab_badfs_root": ") Must be a Linux* compatible filesystem such as:\n ext4/btrfs/xfs/f2fs to be mounted at /!", - "fstab_small_home_size": ") Must at least be 11GBs!", - "fstab_badfs_home": ") Must be a Linux* compatible filesystem such as:\n ext4/btrfs/xfs/f2fs to be mounted at /home!", - "fstab_badfs_swap": ") Must not be swap to be used as [SWAP]!", + "fstab_small_efi_size": "EFI Must at least be 512MBs!", + "fstab_badfs_efi": "EFI Must be FAT32/vFAT", + "fstab_small_boot_size": "Boot Must at least be 1GBs!", + "fstab_badfs_boot": "Boot Must be EXT4", + "fstab_small_root_size": "Root Must at least be 26GBs!", + "fstab_badfs_root": "Root Must be a Linux* compatible filesystem such as:\n ext4/btrfs/xfs/f2fs", + "fstab_badfs_swap": "Swap must be linux-swap", "fstab_bad_mountpoint": "Filesystem Table Error: Invalid mountpoint: (", "fstab_bad_mountpoint_msg": ") Is not a valid mountpoint!", "select_a_language": "Select a Language", diff --git a/src/automatic_partitioning_page/mod.rs b/src/automatic_partitioning_page/mod.rs index d6a4145..d46529c 100644 --- a/src/automatic_partitioning_page/mod.rs +++ b/src/automatic_partitioning_page/mod.rs @@ -1,10 +1,10 @@ -use adw::gio; use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib}; -use crate::partitioning_page::{get_block_devices}; -use adw::{prelude::*}; +use crate::partitioning_page::get_block_devices; +use adw::gio; +use adw::prelude::*; use glib::{clone, closure_local, ffi::gboolean}; -use std::{rc::Rc, cell::RefCell}; +use gtk::{glib, prelude::*}; +use std::{cell::RefCell, rc::Rc}; const BOOT_AND_EFI_BYTE_SIZE: f64 = 1611661312.0; const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0; @@ -12,13 +12,13 @@ const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0; pub fn automatic_partitioning_page( partition_carousel: &adw::Carousel, partition_method_type_refcell: &Rc>, - partition_method_automatic_target_refcell: &Rc>, - partition_method_automatic_target_fs_refcell: &Rc>, - partition_method_automatic_luks_enabled_refcell: &Rc>, + partition_method_automatic_target_refcell: &Rc>, + partition_method_automatic_target_fs_refcell: &Rc>, + partition_method_automatic_luks_enabled_refcell: &Rc>, partition_method_automatic_luks_refcell: &Rc>, partition_method_automatic_ratio_refcell: &Rc>, partition_method_automatic_seperation_refcell: &Rc>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let automatic_partitioning_page = installer_stack_page::InstallerStackPage::new(); automatic_partitioning_page.set_page_icon("builder"); @@ -41,62 +41,66 @@ pub fn automatic_partitioning_page( .orientation(gtk::Orientation::Vertical) .build(); - let advanced_box_viewport = - gtk::ScrolledWindow::builder() - .vexpand(true) - .hexpand(true) - .child(&advanced_box) - .build(); + let advanced_box_viewport = gtk::ScrolledWindow::builder() + .vexpand(true) + .hexpand(true) + .child(&advanced_box) + .build(); // - let advanced_home_part_ratio_selection_box = gtk::Box::builder() + let advanced_home_part_ratio_selection_box = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) .build(); - let advanced_home_part_ratio_label_root = gtk::Label::builder() - .build(); + let advanced_home_part_ratio_label_root = gtk::Label::builder().build(); advanced_home_part_ratio_label_root.add_css_class("accent-text"); - let advanced_home_part_ratio_label_home = gtk::Label::builder() - .build(); + let advanced_home_part_ratio_label_home = gtk::Label::builder().build(); advanced_home_part_ratio_label_home.add_css_class("green-text"); - let advanced_home_part_ratio_selection_frame = gtk::Frame::builder() + let advanced_home_part_ratio_selection_frame = gtk::Frame::builder() .child(&advanced_home_part_ratio_selection_box) .hexpand(true) .margin_top(5) .margin_bottom(5) .build(); - let advanced_home_part_ratio_selection_slider= gtk::Scale::builder() - .draw_value(false) - .build(); + let advanced_home_part_ratio_selection_slider = gtk::Scale::builder().draw_value(false).build(); advanced_home_part_ratio_selection_slider.add_css_class("green-trough"); - + let advanced_home_part_ratio_label_root_clone0 = advanced_home_part_ratio_label_root.clone(); let advanced_home_part_ratio_label_home_clone0 = advanced_home_part_ratio_label_home.clone(); - let partition_method_automatic_ratio_refcell_clone0 = partition_method_automatic_ratio_refcell.clone(); + let partition_method_automatic_ratio_refcell_clone0 = + partition_method_automatic_ratio_refcell.clone(); advanced_home_part_ratio_selection_slider.connect_change_value(move |slider, _, value| { let home_size: f64 = slider.adjustment().upper() + 10000000000.0 - value; - advanced_home_part_ratio_label_root_clone0.set_label(&format!("{}: {}", t!("Root Part Size"), pretty_bytes::converter::convert(value.into()))); - advanced_home_part_ratio_label_home_clone0.set_label(&format!("{}: {}", t!("Home Part Size"), pretty_bytes::converter::convert(home_size.into()))); + advanced_home_part_ratio_label_root_clone0.set_label(&format!( + "{}: {}", + t!("Root Part Size"), + pretty_bytes::converter::convert(value.into()) + )); + advanced_home_part_ratio_label_home_clone0.set_label(&format!( + "{}: {}", + t!("Home Part Size"), + pretty_bytes::converter::convert(home_size.into()) + )); *partition_method_automatic_ratio_refcell_clone0.borrow_mut() = value; glib::Propagation::Proceed }); // - let advanced_home_seperation_selection_box = gtk::Box::builder() + let advanced_home_seperation_selection_box = gtk::Box::builder() .orientation(gtk::Orientation::Horizontal) .homogeneous(true) .build(); - let advanced_home_seperation_selection_frame = gtk::Frame::builder() + let advanced_home_seperation_selection_frame = gtk::Frame::builder() .child(&advanced_home_seperation_selection_box) .margin_top(5) .margin_bottom(5) @@ -104,18 +108,18 @@ pub fn automatic_partitioning_page( *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("subvol"); - let advanced_home_seperation_selection_checkbutton_subvol = gtk::CheckButton::builder() - .active(true) - .build(); + let advanced_home_seperation_selection_checkbutton_subvol = + gtk::CheckButton::builder().active(true).build(); - let advanced_home_seperation_selection_checkbutton_partition = gtk::CheckButton::builder() - .build(); + let advanced_home_seperation_selection_checkbutton_partition = + gtk::CheckButton::builder().build(); - let advanced_home_seperation_selection_checkbutton_none = gtk::CheckButton::builder() - .build(); + let advanced_home_seperation_selection_checkbutton_none = gtk::CheckButton::builder().build(); - advanced_home_seperation_selection_checkbutton_partition.set_group(Some(&advanced_home_seperation_selection_checkbutton_subvol)); - advanced_home_seperation_selection_checkbutton_none.set_group(Some(&advanced_home_seperation_selection_checkbutton_subvol)); + advanced_home_seperation_selection_checkbutton_partition + .set_group(Some(&advanced_home_seperation_selection_checkbutton_subvol)); + advanced_home_seperation_selection_checkbutton_none + .set_group(Some(&advanced_home_seperation_selection_checkbutton_subvol)); advanced_home_seperation_selection_checkbutton_partition .bind_property( @@ -123,47 +127,41 @@ pub fn automatic_partitioning_page( &advanced_home_part_ratio_selection_frame, "sensitive", ) - .sync_create() - .build(); + .sync_create() + .build(); advanced_home_seperation_selection_checkbutton_subvol.connect_toggled(clone!( #[strong] partition_method_automatic_seperation_refcell, - move |_| - { - *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("subvol"); - } - ) - ); + move |_| { + *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("subvol"); + } + )); advanced_home_seperation_selection_checkbutton_partition.connect_toggled(clone!( #[strong] partition_method_automatic_seperation_refcell, - move |_| - { - *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("partition"); - } - ) - ); + move |_| { + *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("partition"); + } + )); advanced_home_seperation_selection_checkbutton_none.connect_toggled(clone!( #[strong] partition_method_automatic_seperation_refcell, - move |_| - { - *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("none"); - } - ) - ); + move |_| { + *partition_method_automatic_seperation_refcell.borrow_mut() = String::from("none"); + } + )); // - let advanced_filesystem_selection_box = gtk::Box::builder() + let advanced_filesystem_selection_box = gtk::Box::builder() .orientation(gtk::Orientation::Horizontal) .homogeneous(true) .build(); - let advanced_filesystem_selection_frame = gtk::Frame::builder() + let advanced_filesystem_selection_frame = gtk::Frame::builder() .child(&advanced_filesystem_selection_box) .margin_top(5) .margin_bottom(5) @@ -176,13 +174,11 @@ pub fn automatic_partitioning_page( .active(true) .build(); - let advanced_filesystem_selection_checkbutton_ext4 = gtk::CheckButton::builder() - .label("EXT4") - .build(); + let advanced_filesystem_selection_checkbutton_ext4 = + gtk::CheckButton::builder().label("EXT4").build(); - let advanced_filesystem_selection_checkbutton_xfs = gtk::CheckButton::builder() - .label("XFS") - .build(); + let advanced_filesystem_selection_checkbutton_xfs = + gtk::CheckButton::builder().label("XFS").build(); advanced_filesystem_selection_checkbutton_btrfs .bind_property( @@ -190,18 +186,16 @@ pub fn automatic_partitioning_page( &advanced_home_seperation_selection_checkbutton_subvol, "sensitive", ) - .sync_create() - .build(); + .sync_create() + .build(); advanced_filesystem_selection_checkbutton_btrfs.connect_toggled(clone!( #[strong] partition_method_automatic_target_fs_refcell, - move |_| - { - *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("btrfs"); - } - ) - ); + move |_| { + *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("btrfs"); + } + )); advanced_filesystem_selection_checkbutton_ext4.connect_toggled(clone!( #[weak] @@ -212,15 +206,15 @@ pub fn automatic_partitioning_page( advanced_home_seperation_selection_checkbutton_partition, #[strong] partition_method_automatic_target_fs_refcell, - move |_| + move |_| { + if advanced_filesystem_selection_checkbutton_ext4.is_active() + && advanced_home_seperation_selection_checkbutton_subvol.is_active() { - if advanced_filesystem_selection_checkbutton_ext4.is_active() && advanced_home_seperation_selection_checkbutton_subvol.is_active() { - advanced_home_seperation_selection_checkbutton_partition.set_active(true) - } - *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("ext4"); + advanced_home_seperation_selection_checkbutton_partition.set_active(true) } - ) - ); + *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("ext4"); + } + )); advanced_filesystem_selection_checkbutton_xfs.connect_toggled(clone!( #[weak] @@ -231,19 +225,20 @@ pub fn automatic_partitioning_page( advanced_home_seperation_selection_checkbutton_partition, #[strong] partition_method_automatic_target_fs_refcell, - move |_| + move |_| { + if advanced_filesystem_selection_checkbutton_xfs.is_active() + && advanced_home_seperation_selection_checkbutton_subvol.is_active() { - if advanced_filesystem_selection_checkbutton_xfs.is_active() && advanced_home_seperation_selection_checkbutton_subvol.is_active() { - advanced_home_seperation_selection_checkbutton_partition.set_active(true) - } - *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("xfs"); + advanced_home_seperation_selection_checkbutton_partition.set_active(true) } - ) - ); + *partition_method_automatic_target_fs_refcell.borrow_mut() = String::from("xfs"); + } + )); - - advanced_filesystem_selection_checkbutton_ext4.set_group(Some(&advanced_filesystem_selection_checkbutton_btrfs)); - advanced_filesystem_selection_checkbutton_xfs.set_group(Some(&advanced_filesystem_selection_checkbutton_btrfs)); + advanced_filesystem_selection_checkbutton_ext4 + .set_group(Some(&advanced_filesystem_selection_checkbutton_btrfs)); + advanced_filesystem_selection_checkbutton_xfs + .set_group(Some(&advanced_filesystem_selection_checkbutton_btrfs)); // @@ -255,8 +250,7 @@ pub fn automatic_partitioning_page( // - let devices_selection_expander_row = adw::ExpanderRow::builder() - .build(); + let devices_selection_expander_row = adw::ExpanderRow::builder().build(); let devices_selection_expander_row_viewport_listbox = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -275,8 +269,7 @@ pub fn automatic_partitioning_page( devices_selection_expander_row_viewport_box.add_css_class("boxed-list"); devices_selection_expander_row_viewport_box.add_css_class("round-all-scroll"); - let devices_selection_expander_row_viewport = - gtk::ScrolledWindow::builder() + let devices_selection_expander_row_viewport = gtk::ScrolledWindow::builder() .vexpand(true) .hexpand(true) .has_frame(true) @@ -316,7 +309,12 @@ pub fn automatic_partitioning_page( // - let error_labels = [partition_method_automatic_disk_nodisk_error_label.clone(), partition_method_automatic_disk_small_error_label.clone(), partition_method_automatic_luks_empty_error_label.clone(), partition_method_automatic_luks_missmatch_error_label.clone()]; + let error_labels = [ + partition_method_automatic_disk_nodisk_error_label.clone(), + partition_method_automatic_disk_small_error_label.clone(), + partition_method_automatic_luks_empty_error_label.clone(), + partition_method_automatic_luks_missmatch_error_label.clone(), + ]; // @@ -384,155 +382,182 @@ pub fn automatic_partitioning_page( .build(); device_row.add_prefix(&device_button); devices_selection_expander_row_viewport_box.append(&device_row); - device_button.connect_toggled( - clone!( - #[weak] - device_button, - #[weak] - devices_selection_expander_row, - #[weak] - partition_method_automatic_disk_nodisk_error_label, - #[weak] - partition_method_automatic_disk_small_error_label, - #[weak] - advanced_home_part_ratio_selection_slider, - #[strong] - partition_method_automatic_target_refcell, - #[strong] - error_labels, - #[weak] - automatic_partitioning_page, - move |_| { - disk_check(&device_button, &devices_selection_expander_row, &partition_method_automatic_disk_small_error_label, &device.block_name, device.block_size); - partition_method_automatic_disk_nodisk_error_label.set_visible(false); - let usable_disk_space = device.block_size - BOOT_AND_EFI_BYTE_SIZE; - let default_root_size = if (usable_disk_space * 40.0) / 100.0 > 100000000000.0 { - 100000000000.0 - } else if (usable_disk_space * 40.0) / 100.0 < MINIMUM_ROOT_BYTE_SIZE { - MINIMUM_ROOT_BYTE_SIZE - } else { - (usable_disk_space * 40.0) / 100.0 - }; - advanced_home_part_ratio_selection_slider.set_range(MINIMUM_ROOT_BYTE_SIZE, device.block_size - 10000000000.0); - advanced_home_part_ratio_selection_slider.set_value(default_root_size); - advanced_home_part_ratio_selection_slider.emit_by_name_with_values("change_value", &[gtk::ScrollType::None.into(), default_root_size.into()]); - *partition_method_automatic_target_refcell.borrow_mut() = String::from(&device.block_name); - if check_for_errors(&error_labels) { - automatic_partitioning_page.set_next_sensitive(true) - } else { - automatic_partitioning_page.set_next_sensitive(false) - } + device_button.connect_toggled(clone!( + #[weak] + device_button, + #[weak] + devices_selection_expander_row, + #[weak] + partition_method_automatic_disk_nodisk_error_label, + #[weak] + partition_method_automatic_disk_small_error_label, + #[weak] + advanced_home_part_ratio_selection_slider, + #[strong] + partition_method_automatic_target_refcell, + #[strong] + error_labels, + #[weak] + automatic_partitioning_page, + move |_| { + disk_check( + &device_button, + &devices_selection_expander_row, + &partition_method_automatic_disk_small_error_label, + &device.block_name, + device.block_size, + ); + partition_method_automatic_disk_nodisk_error_label.set_visible(false); + let usable_disk_space = device.block_size - BOOT_AND_EFI_BYTE_SIZE; + let default_root_size = if (usable_disk_space * 40.0) / 100.0 > 100000000000.0 { + 100000000000.0 + } else if (usable_disk_space * 40.0) / 100.0 < MINIMUM_ROOT_BYTE_SIZE { + MINIMUM_ROOT_BYTE_SIZE + } else { + (usable_disk_space * 40.0) / 100.0 + }; + advanced_home_part_ratio_selection_slider + .set_range(MINIMUM_ROOT_BYTE_SIZE, device.block_size - 10000000000.0); + advanced_home_part_ratio_selection_slider.set_value(default_root_size); + advanced_home_part_ratio_selection_slider.emit_by_name_with_values( + "change_value", + &[gtk::ScrollType::None.into(), default_root_size.into()], + ); + *partition_method_automatic_target_refcell.borrow_mut() = + String::from(&device.block_name); + if check_for_errors(&error_labels) { + automatic_partitioning_page.set_next_sensitive(true) + } else { + automatic_partitioning_page.set_next_sensitive(false) } - ) - ); + } + )); } - partition_method_automatic_luks_checkbutton.connect_toggled( - clone!( - #[strong] - partition_method_automatic_luks_missmatch_error_label, - #[strong] - partition_method_automatic_luks_checkbutton, - #[strong] - partition_method_automatic_luks_password_confirm_entry, - #[strong] - partition_method_automatic_luks_password_entry, - #[strong] - partition_method_automatic_luks_empty_error_label, - #[strong] - partition_method_automatic_luks_enabled_refcell, - #[strong] - error_labels, - #[weak] - automatic_partitioning_page, - move |_| { - match partition_method_automatic_luks_checkbutton.is_active() { - true => *partition_method_automatic_luks_enabled_refcell.borrow_mut() = true, - false => *partition_method_automatic_luks_enabled_refcell.borrow_mut() = false, - } - luks_check(&partition_method_automatic_luks_checkbutton, &partition_method_automatic_luks_password_entry, &partition_method_automatic_luks_password_confirm_entry, &partition_method_automatic_luks_missmatch_error_label, &partition_method_automatic_luks_empty_error_label); - if check_for_errors(&error_labels) { - automatic_partitioning_page.set_next_sensitive(true) - } else { - automatic_partitioning_page.set_next_sensitive(false) - } + partition_method_automatic_luks_checkbutton.connect_toggled(clone!( + #[strong] + partition_method_automatic_luks_missmatch_error_label, + #[strong] + partition_method_automatic_luks_checkbutton, + #[strong] + partition_method_automatic_luks_password_confirm_entry, + #[strong] + partition_method_automatic_luks_password_entry, + #[strong] + partition_method_automatic_luks_empty_error_label, + #[strong] + partition_method_automatic_luks_enabled_refcell, + #[strong] + error_labels, + #[weak] + automatic_partitioning_page, + move |_| { + match partition_method_automatic_luks_checkbutton.is_active() { + true => *partition_method_automatic_luks_enabled_refcell.borrow_mut() = true, + false => *partition_method_automatic_luks_enabled_refcell.borrow_mut() = false, } - ) - ); + luks_check( + &partition_method_automatic_luks_checkbutton, + &partition_method_automatic_luks_password_entry, + &partition_method_automatic_luks_password_confirm_entry, + &partition_method_automatic_luks_missmatch_error_label, + &partition_method_automatic_luks_empty_error_label, + ); + if check_for_errors(&error_labels) { + automatic_partitioning_page.set_next_sensitive(true) + } else { + automatic_partitioning_page.set_next_sensitive(false) + } + } + )); - partition_method_automatic_luks_password_entry.connect_changed( - clone!( - #[weak] - partition_method_automatic_luks_missmatch_error_label, - #[weak] - partition_method_automatic_luks_checkbutton, - #[weak] - partition_method_automatic_luks_password_confirm_entry, - #[weak] - partition_method_automatic_luks_password_entry, - #[weak] - partition_method_automatic_luks_empty_error_label, - #[strong] - partition_method_automatic_luks_refcell, - #[strong] - error_labels, - #[weak] - automatic_partitioning_page, - move |_| { - *partition_method_automatic_luks_refcell.borrow_mut() = String::from(partition_method_automatic_luks_password_entry.text()); - luks_check(&partition_method_automatic_luks_checkbutton, &partition_method_automatic_luks_password_entry, &partition_method_automatic_luks_password_confirm_entry, &partition_method_automatic_luks_missmatch_error_label, &partition_method_automatic_luks_empty_error_label); - if check_for_errors(&error_labels) { - automatic_partitioning_page.set_next_sensitive(true) - } else { - automatic_partitioning_page.set_next_sensitive(false) - } + partition_method_automatic_luks_password_entry.connect_changed(clone!( + #[weak] + partition_method_automatic_luks_missmatch_error_label, + #[weak] + partition_method_automatic_luks_checkbutton, + #[weak] + partition_method_automatic_luks_password_confirm_entry, + #[weak] + partition_method_automatic_luks_password_entry, + #[weak] + partition_method_automatic_luks_empty_error_label, + #[strong] + partition_method_automatic_luks_refcell, + #[strong] + error_labels, + #[weak] + automatic_partitioning_page, + move |_| { + *partition_method_automatic_luks_refcell.borrow_mut() = + String::from(partition_method_automatic_luks_password_entry.text()); + luks_check( + &partition_method_automatic_luks_checkbutton, + &partition_method_automatic_luks_password_entry, + &partition_method_automatic_luks_password_confirm_entry, + &partition_method_automatic_luks_missmatch_error_label, + &partition_method_automatic_luks_empty_error_label, + ); + if check_for_errors(&error_labels) { + automatic_partitioning_page.set_next_sensitive(true) + } else { + automatic_partitioning_page.set_next_sensitive(false) } - ) - ); + } + )); - partition_method_automatic_luks_password_confirm_entry.connect_changed( - clone!( - #[weak] - partition_method_automatic_luks_missmatch_error_label, - #[weak] - partition_method_automatic_luks_checkbutton, - #[weak] - partition_method_automatic_luks_password_confirm_entry, - #[weak] - partition_method_automatic_luks_password_entry, - #[weak] - partition_method_automatic_luks_empty_error_label, - #[strong] - partition_method_automatic_luks_refcell, - #[strong] - error_labels, - #[weak] - automatic_partitioning_page, - move |_| { - *partition_method_automatic_luks_refcell.borrow_mut() = String::from(partition_method_automatic_luks_password_entry.text()); - luks_check(&partition_method_automatic_luks_checkbutton, &partition_method_automatic_luks_password_entry, &partition_method_automatic_luks_password_confirm_entry, &partition_method_automatic_luks_missmatch_error_label, &partition_method_automatic_luks_empty_error_label); - if check_for_errors(&error_labels) { - automatic_partitioning_page.set_next_sensitive(true) - } else { - automatic_partitioning_page.set_next_sensitive(false) - } + partition_method_automatic_luks_password_confirm_entry.connect_changed(clone!( + #[weak] + partition_method_automatic_luks_missmatch_error_label, + #[weak] + partition_method_automatic_luks_checkbutton, + #[weak] + partition_method_automatic_luks_password_confirm_entry, + #[weak] + partition_method_automatic_luks_password_entry, + #[weak] + partition_method_automatic_luks_empty_error_label, + #[strong] + partition_method_automatic_luks_refcell, + #[strong] + error_labels, + #[weak] + automatic_partitioning_page, + move |_| { + *partition_method_automatic_luks_refcell.borrow_mut() = + String::from(partition_method_automatic_luks_password_entry.text()); + luks_check( + &partition_method_automatic_luks_checkbutton, + &partition_method_automatic_luks_password_entry, + &partition_method_automatic_luks_password_confirm_entry, + &partition_method_automatic_luks_missmatch_error_label, + &partition_method_automatic_luks_empty_error_label, + ); + if check_for_errors(&error_labels) { + automatic_partitioning_page.set_next_sensitive(true) + } else { + automatic_partitioning_page.set_next_sensitive(false) } - ) - ); + } + )); // devices_selection_expander_row_viewport_listbox.append(&devices_selection_expander_row); partition_method_automatic_luks_listbox.append(&partition_method_automatic_luks_password_entry); - partition_method_automatic_luks_listbox.append(&partition_method_automatic_luks_password_confirm_entry); + partition_method_automatic_luks_listbox + .append(&partition_method_automatic_luks_password_confirm_entry); partition_method_automatic_luks_box.append(&partition_method_automatic_luks_checkbutton); partition_method_automatic_luks_box.append(&partition_method_automatic_luks_listbox); - advanced_home_seperation_selection_box.append(&advanced_home_seperation_selection_checkbutton_subvol); - advanced_home_seperation_selection_box.append(&advanced_home_seperation_selection_checkbutton_partition); - advanced_home_seperation_selection_box.append(&advanced_home_seperation_selection_checkbutton_none); + advanced_home_seperation_selection_box + .append(&advanced_home_seperation_selection_checkbutton_subvol); + advanced_home_seperation_selection_box + .append(&advanced_home_seperation_selection_checkbutton_partition); + advanced_home_seperation_selection_box + .append(&advanced_home_seperation_selection_checkbutton_none); advanced_filesystem_selection_box.append(&advanced_filesystem_selection_checkbutton_btrfs); advanced_filesystem_selection_box.append(&advanced_filesystem_selection_checkbutton_ext4); @@ -560,11 +585,10 @@ pub fn automatic_partitioning_page( closure_local!( #[weak] partition_carousel, - move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| - { - partition_carousel.scroll_to(&partition_carousel.nth_page(0), true) + move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| { + partition_carousel.scroll_to(&partition_carousel.nth_page(0), true) } - ) + ), ); automatic_partitioning_page.connect_closure( @@ -587,8 +611,7 @@ pub fn automatic_partitioning_page( partition_method_automatic_ratio_refcell, #[strong] partition_method_automatic_seperation_refcell, - move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| - { + move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| { *partition_method_type_refcell.borrow_mut() = String::from("automatic"); //partition_carousel.scroll_to(&partition_carousel.nth_page(5), true) dbg!(partition_method_type_refcell.borrow()); @@ -599,7 +622,7 @@ pub fn automatic_partitioning_page( dbg!(partition_method_automatic_ratio_refcell.borrow()); dbg!(partition_method_automatic_seperation_refcell.borrow()); } - ) + ), ); // @@ -627,47 +650,61 @@ pub fn automatic_partitioning_page( advanced_home_seperation_selection_checkbutton_partition, #[weak] advanced_home_seperation_selection_checkbutton_none, - move |_, _| { - automatic_partitioning_page.set_page_title(t!("auto_part_installer")); - automatic_partitioning_page.set_page_subtitle(t!("choose_drive_auto")); - automatic_partitioning_page.set_back_tooltip_label(t!("back")); - automatic_partitioning_page.set_next_tooltip_label(t!("next")); - // - devices_selection_expander_row.set_title(&t!("no_drive_auto_selected")); - // - partition_method_automatic_disk_nodisk_error_label.set_label(&t!("no_disk_specified")); - // - partition_method_automatic_disk_small_error_label.set_label(&t!("disk_auto_target_small")); - // - partition_method_automatic_luks_empty_error_label.set_label(&t!("luks_yes_but_empty")); - // - partition_method_automatic_luks_missmatch_error_label.set_label(&t!("luks_not_match")); - // - partition_method_automatic_luks_checkbutton.set_label(Some(&t!("enable_luks2_enc"))); - // - partition_method_automatic_luks_password_entry.set_title(&t!("luks2_password")); - // - partition_method_automatic_luks_password_confirm_entry.set_title(&t!("luks2_password_confirm")); - // - advanced_expander.set_label(Some(&t!("advanced_options"))); - // - advanced_filesystem_selection_frame.set_label(Some(&t!("choose_fs_auto"))); - // - advanced_home_seperation_selection_frame.set_label(Some(&t!("choose_home_seperation_auto"))); - // - advanced_home_seperation_selection_checkbutton_subvol.set_label(Some(&t!("advanced_home_seperation_selection_checkbutton_subvol_label"))); - // - advanced_home_seperation_selection_checkbutton_partition.set_label(Some(&t!("advanced_home_seperation_selection_checkbutton_partition_label"))); - // - advanced_home_seperation_selection_checkbutton_none.set_label(Some(&t!("advanced_home_seperation_selection_checkbutton_none_label"))); - // - } - ) - ); + move |_, _| { + automatic_partitioning_page.set_page_title(t!("auto_part_installer")); + automatic_partitioning_page.set_page_subtitle(t!("choose_drive_auto")); + automatic_partitioning_page.set_back_tooltip_label(t!("back")); + automatic_partitioning_page.set_next_tooltip_label(t!("next")); + // + devices_selection_expander_row.set_title(&t!("no_drive_auto_selected")); + // + partition_method_automatic_disk_nodisk_error_label.set_label(&t!("no_disk_specified")); + // + partition_method_automatic_disk_small_error_label + .set_label(&t!("disk_auto_target_small")); + // + partition_method_automatic_luks_empty_error_label.set_label(&t!("luks_yes_but_empty")); + // + partition_method_automatic_luks_missmatch_error_label.set_label(&t!("luks_not_match")); + // + partition_method_automatic_luks_checkbutton.set_label(Some(&t!("enable_luks2_enc"))); + // + partition_method_automatic_luks_password_entry.set_title(&t!("luks2_password")); + // + partition_method_automatic_luks_password_confirm_entry + .set_title(&t!("luks2_password_confirm")); + // + advanced_expander.set_label(Some(&t!("advanced_options"))); + // + advanced_filesystem_selection_frame.set_label(Some(&t!("choose_fs_auto"))); + // + advanced_home_seperation_selection_frame + .set_label(Some(&t!("choose_home_seperation_auto"))); + // + advanced_home_seperation_selection_checkbutton_subvol.set_label(Some(&t!( + "advanced_home_seperation_selection_checkbutton_subvol_label" + ))); + // + advanced_home_seperation_selection_checkbutton_partition.set_label(Some(&t!( + "advanced_home_seperation_selection_checkbutton_partition_label" + ))); + // + advanced_home_seperation_selection_checkbutton_none.set_label(Some(&t!( + "advanced_home_seperation_selection_checkbutton_none_label" + ))); + // + } + )); // } -fn disk_check(device_button: >k::CheckButton ,devices_selection_expander_row: &adw::ExpanderRow, partition_method_automatic_disk_size_error_label: >k::Label, device_block_name: &str, device_block_size: f64) { +fn disk_check( + device_button: >k::CheckButton, + devices_selection_expander_row: &adw::ExpanderRow, + partition_method_automatic_disk_size_error_label: >k::Label, + device_block_name: &str, + device_block_size: f64, +) { if device_button.is_active() == true { devices_selection_expander_row.set_title(device_block_name); if device_block_size >= MINIMUM_ROOT_BYTE_SIZE { @@ -678,14 +715,26 @@ fn disk_check(device_button: >k::CheckButton ,devices_selection_expander_row: } } -fn luks_check(partition_method_automatic_luks_checkbutton: >k::CheckButton, partition_method_automatic_luks_password_entry: &adw::PasswordEntryRow, partition_method_automatic_luks_password_confirm_entry: &adw::PasswordEntryRow, partition_method_automatic_luks_missmatch_error_label: >k::Label, partition_method_automatic_luks_empty_error_label: >k::Label) { +fn luks_check( + partition_method_automatic_luks_checkbutton: >k::CheckButton, + partition_method_automatic_luks_password_entry: &adw::PasswordEntryRow, + partition_method_automatic_luks_password_confirm_entry: &adw::PasswordEntryRow, + partition_method_automatic_luks_missmatch_error_label: >k::Label, + partition_method_automatic_luks_empty_error_label: >k::Label, +) { if partition_method_automatic_luks_checkbutton.is_active() == true { - if partition_method_automatic_luks_password_entry.text() != partition_method_automatic_luks_password_confirm_entry.text() { + if partition_method_automatic_luks_password_entry.text() + != partition_method_automatic_luks_password_confirm_entry.text() + { partition_method_automatic_luks_missmatch_error_label.set_visible(true) } else { partition_method_automatic_luks_missmatch_error_label.set_visible(false) } - if partition_method_automatic_luks_password_entry.text().to_string().is_empty() { + if partition_method_automatic_luks_password_entry + .text() + .to_string() + .is_empty() + { partition_method_automatic_luks_empty_error_label.set_visible(true); } else { partition_method_automatic_luks_empty_error_label.set_visible(false); @@ -699,8 +748,8 @@ fn luks_check(partition_method_automatic_luks_checkbutton: >k::CheckButton, pa fn check_for_errors(error_labels: &[gtk::Label]) -> bool { for label in error_labels { if label.is_visible() { - return false + return false; } } true -} \ No newline at end of file +} diff --git a/src/build_ui.rs b/src/build_ui.rs index bafe916..7f08743 100644 --- a/src/build_ui.rs +++ b/src/build_ui.rs @@ -1,6 +1,10 @@ -use std::{path::Path, rc::Rc, cell::RefCell}; -use gtk::{prelude::*, glib as glib, gio as gio}; -use crate::{efi_error_page, eula_page, keyboard_page, language_page, partitioning_page::{self, CrypttabEntry, FstabEntry}, timezone_page, welcome_page}; +use crate::{ + efi_error_page, eula_page, keyboard_page, language_page, + partitioning_page::{self, CrypttabEntry, FstabEntry}, + timezone_page, welcome_page, +}; +use gtk::{gio, glib, prelude::*}; +use std::{cell::RefCell, path::Path, rc::Rc}; pub fn build_ui(app: &adw::Application) { glib::set_prgname(Some("pikaos_installer")); @@ -46,7 +50,7 @@ pub fn build_ui(app: &adw::Application) { match Path::new("/sys/firmware/efi/efivars").exists() { true => welcome_page::welcome_page(&window, &carousel), - _ => efi_error_page::efi_error_page(&window, &carousel) + _ => efi_error_page::efi_error_page(&window, &carousel), } let language_selection_text_refcell: Rc> = Rc::new(RefCell::default()); @@ -54,39 +58,60 @@ pub fn build_ui(app: &adw::Application) { let keymap_varient_selection_text_refcell: Rc> = Rc::new(RefCell::default()); let timezone_selection_text_refcell: Rc> = Rc::new(RefCell::default()); let partition_method_type_refcell: Rc> = Rc::new(RefCell::default()); - let partition_method_automatic_target_refcell: Rc> = Rc::new(RefCell::default()); - let partition_method_automatic_target_fs_refcell: Rc> = Rc::new(RefCell::default()); - let partition_method_automatic_luks_enabled_refcell: Rc> = Rc::new(RefCell::new(false)); + let partition_method_automatic_target_refcell: Rc> = + Rc::new(RefCell::default()); + let partition_method_automatic_target_fs_refcell: Rc> = + Rc::new(RefCell::default()); + let partition_method_automatic_luks_enabled_refcell: Rc> = + Rc::new(RefCell::new(false)); let partition_method_automatic_luks_refcell: Rc> = Rc::new(RefCell::default()); let partition_method_automatic_ratio_refcell: Rc> = Rc::new(RefCell::new(0.0)); - let partition_method_automatic_seperation_refcell: Rc> = Rc::new(RefCell::default()); - let partition_method_manual_fstab_entry_array_refcell: Rc>> = Rc::new(RefCell::new(Vec::new())); - let partition_method_manual_luks_enabled_refcell: Rc> = Rc::new(RefCell::new(false)); - let partition_method_manual_crypttab_entry_array_refcell: Rc>> = Rc::new(RefCell::new(Vec::new())); + let partition_method_automatic_seperation_refcell: Rc> = + Rc::new(RefCell::default()); + let partition_method_manual_fstab_entry_array_refcell: Rc>> = + Rc::new(RefCell::new(Vec::new())); + let partition_method_manual_luks_enabled_refcell: Rc> = + Rc::new(RefCell::new(false)); + let partition_method_manual_crypttab_entry_array_refcell: Rc>> = + Rc::new(RefCell::new(Vec::new())); let language_changed_action = gio::SimpleAction::new("lang-changed", None); - language_page::language_page(&carousel, &language_selection_text_refcell, &language_changed_action); + language_page::language_page( + &carousel, + &language_selection_text_refcell, + &language_changed_action, + ); eula_page::eula_page(&carousel, &language_changed_action); - keyboard_page::keyboard_page(&carousel, &keymap_base_selection_text_refcell, &keymap_varient_selection_text_refcell, &language_changed_action); + keyboard_page::keyboard_page( + &carousel, + &keymap_base_selection_text_refcell, + &keymap_varient_selection_text_refcell, + &language_changed_action, + ); - timezone_page::timezone_page(&carousel, &timezone_selection_text_refcell, &language_changed_action); + timezone_page::timezone_page( + &carousel, + &timezone_selection_text_refcell, + &language_changed_action, + ); partitioning_page::partitioning_page( - &carousel, - &partition_method_type_refcell, - &partition_method_automatic_target_refcell, - &partition_method_automatic_target_fs_refcell, - &partition_method_automatic_luks_enabled_refcell, - &partition_method_automatic_luks_refcell, - &partition_method_automatic_ratio_refcell, - &partition_method_automatic_seperation_refcell, - &partition_method_manual_fstab_entry_array_refcell, - &partition_method_manual_luks_enabled_refcell, - &partition_method_manual_crypttab_entry_array_refcell, - &language_changed_action); + &carousel, + &partition_method_type_refcell, + &partition_method_automatic_target_refcell, + &partition_method_automatic_target_fs_refcell, + &partition_method_automatic_luks_enabled_refcell, + &partition_method_automatic_luks_refcell, + &partition_method_automatic_ratio_refcell, + &partition_method_automatic_seperation_refcell, + &partition_method_manual_fstab_entry_array_refcell, + &partition_method_manual_luks_enabled_refcell, + &partition_method_manual_crypttab_entry_array_refcell, + &language_changed_action, + ); window.present() -} \ No newline at end of file +} diff --git a/src/drive_mount_row/imp.rs b/src/drive_mount_row/imp.rs index f4f006a..025c8db 100644 --- a/src/drive_mount_row/imp.rs +++ b/src/drive_mount_row/imp.rs @@ -1,8 +1,8 @@ use std::{cell::RefCell, rc::Rc, sync::OnceLock}; use adw::{prelude::*, subclass::prelude::*, *}; -use gtk::{glib as glib, Orientation::Horizontal}; use glib::{clone, subclass::Signal, Properties}; +use gtk::{glib, Orientation::Horizontal}; use crate::partitioning_page::FstabEntry; @@ -24,7 +24,7 @@ pub struct DriveMountRow { #[property(get, set)] sizegroup: RefCell>, #[property(get, set)] - langaction: RefCell> + langaction: RefCell>, } // ANCHOR_END: custom_button @@ -45,7 +45,6 @@ impl ObjectImpl for DriveMountRow { SIGNALS.get_or_init(|| vec![Signal::builder("row-deleted").build()]) } fn constructed(&self) { - self.parent_constructed(); // Bind label to number @@ -142,12 +141,10 @@ impl ObjectImpl for DriveMountRow { partition_row_delete_button.connect_clicked(clone!( #[weak] obj, - move |_| - { - obj.emit_by_name::<()>("row-deleted", &[]); - } - ) - ); + move |_| { + obj.emit_by_name::<()>("row-deleted", &[]); + } + )); // @@ -176,21 +173,17 @@ impl ObjectImpl for DriveMountRow { mountpoint_entry_row_adw_listbox, #[weak] mountopts_entry_row_adw_listbox, - move |_| - { - match obj.sizegroup() { - Some(t) => { - t.add_widget(&partition_row_expander_adw_listbox); - t.add_widget(&mountpoint_entry_row_adw_listbox); - t.add_widget(&mountopts_entry_row_adw_listbox); - } - None => { - - } + move |_| { + match obj.sizegroup() { + Some(t) => { + t.add_widget(&partition_row_expander_adw_listbox); + t.add_widget(&mountpoint_entry_row_adw_listbox); + t.add_widget(&mountopts_entry_row_adw_listbox); } + None => {} } - ) - ); + } + )); // Bind label to number // `SYNC_CREATE` ensures that the label will be immediately set @@ -215,12 +208,11 @@ impl ObjectImpl for DriveMountRow { obj, #[weak] partition_row_expander, - move |_| - { - partition_row_expander.add_row(&obj.property::("partitionscroll")); - } - ) - ); + move |_| { + partition_row_expander + .add_row(&obj.property::("partitionscroll")); + } + )); obj.connect_langaction_notify(clone!( #[weak] @@ -231,34 +223,27 @@ impl ObjectImpl for DriveMountRow { mountpoint_entry_row, #[weak] mountopts_entry_row, - move |_| - { - match obj.langaction() { - Some(t) => { - t.connect_activate( - clone!( - #[weak] - partition_row_expander, - #[weak] - mountpoint_entry_row, - #[weak] - mountopts_entry_row, - move |_, _| - { - partition_row_expander.set_subtitle(&t!("subtitle_partition")); - mountpoint_entry_row.set_title(&t!("title_mountpoint")); - mountopts_entry_row.set_title(&t!("title_mountopts")); - } - ) - ); - } - None => { - - } + move |_| { + match obj.langaction() { + Some(t) => { + t.connect_activate(clone!( + #[weak] + partition_row_expander, + #[weak] + mountpoint_entry_row, + #[weak] + mountopts_entry_row, + move |_, _| { + partition_row_expander.set_subtitle(&t!("subtitle_partition")); + mountpoint_entry_row.set_title(&t!("title_mountpoint")); + mountopts_entry_row.set_title(&t!("title_mountopts")); + } + )); } + None => {} } - ) - ); + } + )); obj.set_child(Some(&action_row_content_box)); } @@ -266,4 +251,4 @@ impl ObjectImpl for DriveMountRow { // Trait shared by all widgets impl WidgetImpl for DriveMountRow {} -impl ListBoxRowImpl for DriveMountRow {} \ No newline at end of file +impl ListBoxRowImpl for DriveMountRow {} diff --git a/src/drive_mount_row/mod.rs b/src/drive_mount_row/mod.rs index 18279c8..860b0ee 100644 --- a/src/drive_mount_row/mod.rs +++ b/src/drive_mount_row/mod.rs @@ -21,10 +21,10 @@ impl DriveMountRow { .build() } pub fn get_fstab_entry(&self) -> FstabEntry { - FstabEntry{ + FstabEntry { partition: self.partition(), mountpoint: self.mountpoint(), - mountopts: self.mountopts() + mountopts: self.mountopts(), } } } diff --git a/src/efi_error_page/mod.rs b/src/efi_error_page/mod.rs index 11c9eb7..a295b41 100644 --- a/src/efi_error_page/mod.rs +++ b/src/efi_error_page/mod.rs @@ -1,7 +1,6 @@ -use gtk::{prelude::*, glib as glib, Justification}; use glib::clone; +use gtk::{glib, prelude::*, Justification}; pub fn efi_error_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carousel) { - let efi_error_main_box = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) .build(); @@ -76,7 +75,6 @@ pub fn efi_error_page(window: &adw::ApplicationWindow, main_carousel: &adw::Caro exit_button.connect_clicked(clone!( #[weak] window, - move |_| - window.close() + move |_| window.close() )); } diff --git a/src/eula_page/mod.rs b/src/eula_page/mod.rs index 0c0b466..b230d7e 100644 --- a/src/eula_page/mod.rs +++ b/src/eula_page/mod.rs @@ -1,12 +1,9 @@ -use adw::gio; use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib}; +use adw::gio; use glib::{clone, closure_local}; +use gtk::{glib, prelude::*}; -pub fn eula_page( - main_carousel: &adw::Carousel, - language_changed_action: &gio::SimpleAction -) { +pub fn eula_page(main_carousel: &adw::Carousel, language_changed_action: &gio::SimpleAction) { let eula_page = installer_stack_page::InstallerStackPage::new(); eula_page.set_page_icon("error-correct-symbolic"); eula_page.set_back_visible(true); @@ -20,8 +17,7 @@ pub fn eula_page( .vexpand(true) .build(); - let eula_buffer = gtk::TextBuffer::builder() - .build(); + let eula_buffer = gtk::TextBuffer::builder().build(); let eula_selection_text_view = gtk::TextView::builder() .hexpand(true) @@ -45,47 +41,42 @@ pub fn eula_page( .margin_end(15) .build(); - eula_accept_checkbutton.connect_toggled( - clone!( - #[weak] - eula_accept_checkbutton, - #[weak] - eula_page, - move |_| - { - if eula_accept_checkbutton.is_active() == true { - eula_page.set_next_sensitive(true); - } else { - eula_page.set_next_sensitive(false); - } + eula_accept_checkbutton.connect_toggled(clone!( + #[weak] + eula_accept_checkbutton, + #[weak] + eula_page, + move |_| { + if eula_accept_checkbutton.is_active() == true { + eula_page.set_next_sensitive(true); + } else { + eula_page.set_next_sensitive(false); } - ), - ); + } + )); content_box.append(&eula_selection_text_scroll); content_box.append(&eula_accept_checkbutton); // - language_changed_action.connect_activate( - clone!( - #[weak] - eula_page, - #[weak] - eula_accept_checkbutton, - #[strong] - eula_buffer, - move |_, _| { - eula_page.set_page_title(t!("eula")); - eula_page.set_page_subtitle(t!("pikaos_eula_agreement")); - eula_page.set_back_tooltip_label(t!("back")); - eula_page.set_next_tooltip_label(t!("next")); - // - eula_accept_checkbutton.set_label(Some(&t!("i_agree_eula"))); - // - eula_buffer.set_text(&t!("eula_buffer")) - } - ) - ); + language_changed_action.connect_activate(clone!( + #[weak] + eula_page, + #[weak] + eula_accept_checkbutton, + #[strong] + eula_buffer, + move |_, _| { + eula_page.set_page_title(t!("eula")); + eula_page.set_page_subtitle(t!("pikaos_eula_agreement")); + eula_page.set_back_tooltip_label(t!("back")); + eula_page.set_next_tooltip_label(t!("next")); + // + eula_accept_checkbutton.set_label(Some(&t!("i_agree_eula"))); + // + eula_buffer.set_text(&t!("eula_buffer")) + } + )); // eula_page.set_child_widget(&content_box); @@ -96,11 +87,10 @@ pub fn eula_page( closure_local!( #[weak] main_carousel, - move |_language_page: installer_stack_page::InstallerStackPage| - { - main_carousel.scroll_to(&main_carousel.nth_page(1), true) + move |_language_page: installer_stack_page::InstallerStackPage| { + main_carousel.scroll_to(&main_carousel.nth_page(1), true) } - ) + ), ); eula_page.connect_closure( @@ -109,12 +99,11 @@ pub fn eula_page( closure_local!( #[weak] main_carousel, - move |_language_page: installer_stack_page::InstallerStackPage| - { + move |_language_page: installer_stack_page::InstallerStackPage| { main_carousel.scroll_to(&main_carousel.nth_page(3), true) } - ) + ), ); main_carousel.append(&eula_page); -} \ No newline at end of file +} diff --git a/src/installer_stack_page/imp.rs b/src/installer_stack_page/imp.rs index 1e3a0b6..042a6f3 100644 --- a/src/installer_stack_page/imp.rs +++ b/src/installer_stack_page/imp.rs @@ -1,7 +1,7 @@ -use std::{cell::RefCell, rc::Rc, sync::OnceLock}; -use gtk::{prelude::*, subclass::prelude::*, glib as glib, Justification}; use adw::{prelude::*, subclass::prelude::*}; use glib::{clone, subclass::Signal}; +use gtk::{glib, prelude::*, subclass::prelude::*, Justification}; +use std::{cell::RefCell, rc::Rc, sync::OnceLock}; // ANCHOR: custom_button // Object holding the state @@ -45,7 +45,12 @@ impl ObjectSubclass for InstallerStackPage { impl ObjectImpl for InstallerStackPage { fn signals() -> &'static [Signal] { static SIGNALS: OnceLock> = OnceLock::new(); - SIGNALS.get_or_init(|| vec![Signal::builder("next-button-pressed").build(), Signal::builder("back-button-pressed").build()]) + SIGNALS.get_or_init(|| { + vec![ + Signal::builder("next-button-pressed").build(), + Signal::builder("back-button-pressed").build(), + ] + }) } fn constructed(&self) { self.parent_constructed(); @@ -210,9 +215,7 @@ impl ObjectImpl for InstallerStackPage { obj, #[weak] child_bin, - move |_| { - child_bin.set_child(Some(&obj.property::("child_widget"))) - } + move |_| { child_bin.set_child(Some(&obj.property::("child_widget"))) } )); // @@ -229,4 +232,4 @@ impl ObjectImpl for InstallerStackPage { impl WidgetImpl for InstallerStackPage {} -impl BinImpl for InstallerStackPage {} \ No newline at end of file +impl BinImpl for InstallerStackPage {} diff --git a/src/keyboard_page/mod.rs b/src/keyboard_page/mod.rs index 93ed530..8148186 100644 --- a/src/keyboard_page/mod.rs +++ b/src/keyboard_page/mod.rs @@ -1,15 +1,15 @@ use crate::installer_stack_page; -use gnome_desktop::XkbInfoExt; -use gtk::{prelude::*, glib as glib, gio as gio}; -use adw::{prelude::*}; +use adw::prelude::*; use glib::{clone, closure_local}; -use std::{process::Command, fs, path::Path, rc::Rc, cell::RefCell}; +use gnome_desktop::XkbInfoExt; +use gtk::{gio, glib, prelude::*}; +use std::{cell::RefCell, fs, path::Path, process::Command, rc::Rc}; pub fn keyboard_page( main_carousel: &adw::Carousel, keymap_base_data_refcell: &Rc>, keymap_variant_data_refcell: &Rc>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let keyboard_page = installer_stack_page::InstallerStackPage::new(); keyboard_page.set_page_icon("keyboard-symbolic"); @@ -24,8 +24,7 @@ pub fn keyboard_page( .vexpand(true) .build(); - let null_checkbutton = gtk::CheckButton::builder() - .build(); + let null_checkbutton = gtk::CheckButton::builder().build(); let keyboard_selection_row_viewport_listbox = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -33,8 +32,7 @@ pub fn keyboard_page( keyboard_selection_row_viewport_listbox.add_css_class("boxed-list"); keyboard_selection_row_viewport_listbox.add_css_class("round-border-only"); - let keyboard_selection_row_viewport = - gtk::ScrolledWindow::builder() + let keyboard_selection_row_viewport = gtk::ScrolledWindow::builder() .vexpand(true) .hexpand(true) .has_frame(true) @@ -59,8 +57,7 @@ pub fn keyboard_page( keyboard_test_entry_boxed_list.add_css_class("boxed-list"); - let keyboard_test_entry = adw::EntryRow::builder() - .build(); + let keyboard_test_entry = adw::EntryRow::builder().build(); keyboard_test_entry_boxed_list.append(&keyboard_test_entry); @@ -75,7 +72,7 @@ pub fn keyboard_page( for keymap in keymap_list.iter() { let keymap = keymap.to_string(); let keymap_name = xkbinfo.layout_info(&keymap).unwrap().0.unwrap().to_string(); - let keymap_split: Vec = keymap.split("+").map(|s|s.into()).collect(); + let keymap_split: Vec = keymap.split("+").map(|s| s.into()).collect(); let keymap_base = keymap_split.get(0).unwrap().clone(); let mut keymap_variant = String::new(); let mut split_index = 0; @@ -108,30 +105,29 @@ pub fn keyboard_page( keymap_variant_data_refcell, #[weak] keyboard_page, - move |_| - { - if keymap_checkbutton.is_active() == true { - keyboard_page.set_next_sensitive(true); - if keymap_variant.is_empty() { - *keymap_base_data_refcell.borrow_mut() = String::from(&keymap_base); - Command::new("setxkbmap") - .arg("-layout") - .arg(keymap_base.clone()) - .spawn() - .expect("keyboard failed to start"); - } else { - *keymap_base_data_refcell.borrow_mut() = String::from(&keymap_base); - *keymap_variant_data_refcell.borrow_mut() = String::from(&keymap_variant); - Command::new("setxkbmap") - .arg("-layout") - .arg(keymap_base.clone()) - .arg("-variant") - .arg(keymap_variant.clone()) - .spawn() - .expect("keyboard failed to start"); - } + move |_| { + if keymap_checkbutton.is_active() == true { + keyboard_page.set_next_sensitive(true); + if keymap_variant.is_empty() { + *keymap_base_data_refcell.borrow_mut() = String::from(&keymap_base); + Command::new("setxkbmap") + .arg("-layout") + .arg(keymap_base.clone()) + .spawn() + .expect("keyboard failed to start"); + } else { + *keymap_base_data_refcell.borrow_mut() = String::from(&keymap_base); + *keymap_variant_data_refcell.borrow_mut() = String::from(&keymap_variant); + Command::new("setxkbmap") + .arg("-layout") + .arg(keymap_base.clone()) + .arg("-variant") + .arg(keymap_variant.clone()) + .spawn() + .expect("keyboard failed to start"); } } + } )); if current_keymap == keymap_clone { keymap_checkbutton.set_active(true); @@ -149,13 +145,20 @@ pub fn keyboard_page( keyboard_search_bar, #[weak] keyboard_selection_row_viewport_listbox, - move |_| - { + move |_| { let mut counter = keyboard_selection_row_viewport_listbox.first_child(); while let Some(row) = counter { if row.widget_name() == "AdwActionRow" { if !keyboard_search_bar.text().is_empty() { - if row.property::("subtitle").to_lowercase().contains(&keyboard_search_bar.text().to_string().to_lowercase()) || row.property::("title").to_lowercase().contains(&keyboard_search_bar.text().to_string().to_lowercase()) { + if row + .property::("subtitle") + .to_lowercase() + .contains(&keyboard_search_bar.text().to_string().to_lowercase()) + || row + .property::("title") + .to_lowercase() + .contains(&keyboard_search_bar.text().to_string().to_lowercase()) + { row.set_property("visible", true); keyboard_search_bar.grab_focus(); } else { @@ -173,26 +176,24 @@ pub fn keyboard_page( keyboard_page.set_child_widget(&content_box); // - language_changed_action.connect_activate( - clone!( - #[weak] - keyboard_page, - #[weak] - keyboard_search_bar, - #[weak] - keyboard_test_entry, - move |_, _| { - keyboard_page.set_page_title(t!("keyboard")); - keyboard_page.set_page_subtitle(t!("select_a_keyboard")); - keyboard_page.set_back_tooltip_label(t!("back")); - keyboard_page.set_next_tooltip_label(t!("next")); - // - keyboard_search_bar.set_placeholder_text(Some(&t!("search_for_keyboard"))); - // - keyboard_test_entry.set_title(&t!("test_your_keyboard")) - } - ) - ); + language_changed_action.connect_activate(clone!( + #[weak] + keyboard_page, + #[weak] + keyboard_search_bar, + #[weak] + keyboard_test_entry, + move |_, _| { + keyboard_page.set_page_title(t!("keyboard")); + keyboard_page.set_page_subtitle(t!("select_a_keyboard")); + keyboard_page.set_back_tooltip_label(t!("back")); + keyboard_page.set_next_tooltip_label(t!("next")); + // + keyboard_search_bar.set_placeholder_text(Some(&t!("search_for_keyboard"))); + // + keyboard_test_entry.set_title(&t!("test_your_keyboard")) + } + )); // keyboard_page.connect_closure( @@ -201,11 +202,10 @@ pub fn keyboard_page( closure_local!( #[weak] main_carousel, - move |_keyboard_page: installer_stack_page::InstallerStackPage| - { - main_carousel.scroll_to(&main_carousel.nth_page(2), true) + move |_keyboard_page: installer_stack_page::InstallerStackPage| { + main_carousel.scroll_to(&main_carousel.nth_page(2), true) } - ) + ), ); keyboard_page.connect_closure( @@ -214,12 +214,11 @@ pub fn keyboard_page( closure_local!( #[weak] main_carousel, - move |_keyboard_page: installer_stack_page::InstallerStackPage| - { + move |_keyboard_page: installer_stack_page::InstallerStackPage| { main_carousel.scroll_to(&main_carousel.nth_page(4), true) } - ) + ), ); main_carousel.append(&keyboard_page); -} \ No newline at end of file +} diff --git a/src/language_page/mod.rs b/src/language_page/mod.rs index 8a054ec..bca2d9d 100644 --- a/src/language_page/mod.rs +++ b/src/language_page/mod.rs @@ -1,13 +1,13 @@ use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib, gio as gio}; -use adw::{prelude::*}; +use adw::prelude::*; use glib::{clone, closure_local}; +use gtk::{gio, glib, prelude::*}; use std::{cell::RefCell, env, fs, path::Path, process::Command, rc::Rc}; pub fn language_page( main_carousel: &adw::Carousel, lang_data_refcell: &Rc>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let language_page = installer_stack_page::InstallerStackPage::new(); language_page.set_page_title(t!("select_a_language")); @@ -26,8 +26,7 @@ pub fn language_page( .vexpand(true) .build(); - let null_checkbutton = gtk::CheckButton::builder() - .build(); + let null_checkbutton = gtk::CheckButton::builder().build(); let language_selection_row_viewport_listbox = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -35,8 +34,7 @@ pub fn language_page( language_selection_row_viewport_listbox.add_css_class("boxed-list"); language_selection_row_viewport_listbox.add_css_class("round-all-scroll"); - let language_selection_row_viewport = - gtk::ScrolledWindow::builder() + let language_selection_row_viewport = gtk::ScrolledWindow::builder() .vexpand(true) .hexpand(true) .has_frame(true) @@ -56,176 +54,39 @@ pub fn language_page( language_search_bar.add_css_class("rounded-all-25"); let current_locale = match env::var_os("LANG") { - Some(v) => v.into_string().unwrap().chars() + Some(v) => v + .into_string() + .unwrap() + .chars() .take_while(|&ch| ch != '.') .collect::(), None => panic!("$LANG is not set"), }; - let locale_list = ["ab_GE", - "aa_DJ", - "af_ZA", - "ak_GH", - "sq_AL", - "am_ET", - "ar_EG", - "an_ES", - "hy_AM", - "as_IN", - "ar_AE", - "az_AZ", - "bs_BA", - "eu_ES", - "be_BY", - "bn_BD", - "ar_BH", - "bi_VU", - "bs_BA", - "br_FR", - "bg_BG", - "my_MM", - "ca_ES", - "de_CH", - "ce_RU", - "zh_CN", - "cv_RU", - "kw_GB", - "es_CO", - "es_CR", - "hr_HR", - "cs_CZ", - "da_DK", - "dv_MV", - "nl_NL", - "dz_BT", - "en_US", - "en_GB", - "eo", - "et_EE", - "et_EE", - "fo_FO", - "hif_FJ", - "fi_FI", - "fr_FR", - "ff_SN", - "gl_ES", - "ka_GE", - "de_DE", - "el_GR", - "gu_IN", - "ht_HT", - "ha_NG", - "he_IL", - "hi_IN", - "hu_HU", - "ia_FR", - "id_ID", - "en_IE", - "ga_IE", - "ig_NG", - "ik_CA", - "is_IS", - "it_IT", - "iu_CA", - "ja_JP", - "kl_GL", - "kn_IN", - "ko_KR", - "kk_KZ", - "km_KH", - "rw_RW", - "ky_KG", - "ky_KG", - "ko_KR", - "ku_TR", - "lo_LA", - "lb_LU", - "lg_UG", - "li_NL", - "ln_CD", - "lo_LA", - "lt_LT", - "fr_LU", - "lv_LV", - "gv_GB", - "mk_MK", - "mg_MG", - "ms_MY", - "ml_IN", - "mt_MT", - "mi_NZ", - "mr_IN", - "mn_MN", - "ne_NP", - "en_NG", - "nb_NO", - "nn_NO", - "no_NO", - "nr_ZA", - "oc_FR", - "es_CU", - "om_ET", - "or_IN", - "os_RU", - "pa_IN", - "fa_IR", - "pl_PL", - "ps_AF", - "pt_BR", - "ro_RO", - "ru_RU", - "sa_IN", - "sc_IT", - "sd_IN", - "se_NO", - "sm_WS", - "en_SG", - "sr_RS", - "gd_GB", - "wo_SN", - "si_LK", - "sk_SK", - "sl_SI", - "so_SO", - "st_ZA", - "es_ES", - "sw_KE", - "ss_ZA", - "sv_SE", - "ta_IN", - "te_IN", - "tg_TJ", - "th_TH", - "ti_ER", - "bo_CN", - "tk_TM", - "tl_PH", - "tn_ZA", - "to_TO", - "tr_TR", - "ts_ZA", - "tt_RU", - "zh_TW", - "ug_CN", - "uk_UA", - "ur_PK", - "ve_ZA", - "vi_VN", - "wa_BE", - "cy_GB", - "wo_SN", - "fy_NL", - "xh_ZA", - "yi_US", - "yo_NG", - "zu_ZA", - "zu_ZA", - "pt_BR", - "pt_PT",]; + let locale_list = [ + "ab_GE", "aa_DJ", "af_ZA", "ak_GH", "sq_AL", "am_ET", "ar_EG", "an_ES", "hy_AM", "as_IN", + "ar_AE", "az_AZ", "bs_BA", "eu_ES", "be_BY", "bn_BD", "ar_BH", "bi_VU", "bs_BA", "br_FR", + "bg_BG", "my_MM", "ca_ES", "de_CH", "ce_RU", "zh_CN", "cv_RU", "kw_GB", "es_CO", "es_CR", + "hr_HR", "cs_CZ", "da_DK", "dv_MV", "nl_NL", "dz_BT", "en_US", "en_GB", "eo", "et_EE", + "et_EE", "fo_FO", "hif_FJ", "fi_FI", "fr_FR", "ff_SN", "gl_ES", "ka_GE", "de_DE", "el_GR", + "gu_IN", "ht_HT", "ha_NG", "he_IL", "hi_IN", "hu_HU", "ia_FR", "id_ID", "en_IE", "ga_IE", + "ig_NG", "ik_CA", "is_IS", "it_IT", "iu_CA", "ja_JP", "kl_GL", "kn_IN", "ko_KR", "kk_KZ", + "km_KH", "rw_RW", "ky_KG", "ky_KG", "ko_KR", "ku_TR", "lo_LA", "lb_LU", "lg_UG", "li_NL", + "ln_CD", "lo_LA", "lt_LT", "fr_LU", "lv_LV", "gv_GB", "mk_MK", "mg_MG", "ms_MY", "ml_IN", + "mt_MT", "mi_NZ", "mr_IN", "mn_MN", "ne_NP", "en_NG", "nb_NO", "nn_NO", "no_NO", "nr_ZA", + "oc_FR", "es_CU", "om_ET", "or_IN", "os_RU", "pa_IN", "fa_IR", "pl_PL", "ps_AF", "pt_BR", + "ro_RO", "ru_RU", "sa_IN", "sc_IT", "sd_IN", "se_NO", "sm_WS", "en_SG", "sr_RS", "gd_GB", + "wo_SN", "si_LK", "sk_SK", "sl_SI", "so_SO", "st_ZA", "es_ES", "sw_KE", "ss_ZA", "sv_SE", + "ta_IN", "te_IN", "tg_TJ", "th_TH", "ti_ER", "bo_CN", "tk_TM", "tl_PH", "tn_ZA", "to_TO", + "tr_TR", "ts_ZA", "tt_RU", "zh_TW", "ug_CN", "uk_UA", "ur_PK", "ve_ZA", "vi_VN", "wa_BE", + "cy_GB", "wo_SN", "fy_NL", "xh_ZA", "yi_US", "yo_NG", "zu_ZA", "zu_ZA", "pt_BR", "pt_PT", + ]; for locale in locale_list.iter() { let locale = locale.to_string(); - let locale_name = gnome_desktop::language_from_locale(&locale, None).unwrap_or(locale.clone().into()).to_string(); + let locale_name = gnome_desktop::language_from_locale(&locale, None) + .unwrap_or(locale.clone().into()) + .to_string(); let locale_clone = locale.clone(); let locale_checkbutton = gtk::CheckButton::builder() .valign(gtk::Align::Center) @@ -246,13 +107,12 @@ pub fn language_page( lang_data_refcell, #[weak] language_page, - move |_| - { - if locale_checkbutton.is_active() == true { - language_page.set_next_sensitive(true); - *lang_data_refcell.borrow_mut() = String::from(&locale); - } + move |_| { + if locale_checkbutton.is_active() == true { + language_page.set_next_sensitive(true); + *lang_data_refcell.borrow_mut() = String::from(&locale); } + } )); if ¤t_locale == &locale_clone && current_locale != "C.UTF-8" @@ -274,13 +134,20 @@ pub fn language_page( language_search_bar, #[weak] language_selection_row_viewport_listbox, - move |_| - { + move |_| { let mut counter = language_selection_row_viewport_listbox.first_child(); while let Some(row) = counter { if row.widget_name() == "AdwActionRow" { if !language_search_bar.text().is_empty() { - if row.property::("subtitle").to_lowercase().contains(&language_search_bar.text().to_string().to_lowercase()) || row.property::("title").to_lowercase().contains(&language_search_bar.text().to_string().to_lowercase()) { + if row + .property::("subtitle") + .to_lowercase() + .contains(&language_search_bar.text().to_string().to_lowercase()) + || row + .property::("title") + .to_lowercase() + .contains(&language_search_bar.text().to_string().to_lowercase()) + { row.set_property("visible", true); language_search_bar.grab_focus(); } else { @@ -303,11 +170,10 @@ pub fn language_page( closure_local!( #[weak] main_carousel, - move |_language_page: installer_stack_page::InstallerStackPage| - { - main_carousel.scroll_to(&main_carousel.nth_page(0), true) + move |_language_page: installer_stack_page::InstallerStackPage| { + main_carousel.scroll_to(&main_carousel.nth_page(0), true) } - ) + ), ); language_page.connect_closure( @@ -320,8 +186,7 @@ pub fn language_page( lang_data_refcell, #[strong] language_changed_action, - move |_language_page: installer_stack_page::InstallerStackPage| - { + move |_language_page: installer_stack_page::InstallerStackPage| { let locale = &lang_data_refcell.borrow(); //Command::new("sudo") // .arg("localectl") @@ -333,8 +198,8 @@ pub fn language_page( language_changed_action.activate(None); main_carousel.scroll_to(&main_carousel.nth_page(2), true) } - ) + ), ); main_carousel.append(&language_page); -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index b18fb2c..6555c2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,22 @@ +use gdk::Display; +use gtk::{gdk, glib, prelude::*, CssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION}; use std::env; -use gtk::{CssProvider, gdk, STYLE_PROVIDER_PRIORITY_APPLICATION, prelude::*, glib as glib}; -use gdk::{Display}; -mod config; mod build_ui; +mod config; mod efi_error_page; mod installer_stack_page; // -mod welcome_page; -mod language_page; +mod automatic_partitioning_page; +mod drive_mount_row; mod eula_page; mod keyboard_page; -mod timezone_page; -mod partitioning_page; -mod automatic_partitioning_page; +mod language_page; mod manual_partitioning_page; -mod drive_mount_row; +mod partitioning_page; +mod timezone_page; +mod welcome_page; #[macro_use] extern crate rust_i18n; @@ -24,14 +24,19 @@ i18n!("locales", fallback = "en_US"); fn main() -> glib::ExitCode { let current_locale = match env::var_os("LANG") { - Some(v) => v.into_string().unwrap().chars() + Some(v) => v + .into_string() + .unwrap() + .chars() .take_while(|&ch| ch != '.') .collect::(), None => panic!("$LANG is not set"), }; rust_i18n::set_locale(¤t_locale); - let app = adw::Application::builder().application_id(config::APP_ID).build(); + let app = adw::Application::builder() + .application_id(config::APP_ID) + .build(); app.connect_startup(|app| { load_css(); @@ -50,4 +55,4 @@ fn load_css() { &provider, STYLE_PROVIDER_PRIORITY_APPLICATION, ); -} \ No newline at end of file +} diff --git a/src/manual_partitioning/mod.rs b/src/manual_partitioning/mod.rs deleted file mode 100644 index b395967..0000000 --- a/src/manual_partitioning/mod.rs +++ /dev/null @@ -1,99 +0,0 @@ -use adw::gio; -use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib}; -use crate::partitioning_page::{get_block_devices}; -use adw::{prelude::*}; -use glib::{clone, closure_local, ffi::gboolean}; -use std::{rc::Rc, cell::RefCell}; - -const MINIMUM_EFI_BYTE_SIZE: f64 = 500000000.0; -const MINIMUM_BOOT_BYTE_SIZE: f64 = 1000000000.0; -const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0; - - -pub fn manual_partitioning( - partition_carousel: &adw::Carousel, - partition_method_type_refcell: &Rc>, - partition_method_manual_fstab_entry_array_refcell: &Rc>, - partition_method_manual_luks_enabled_refcell: &Rc>, - partition_method_manual_crypttab_entry_array_refcell: &Rc>, - language_changed_action: &gio::SimpleAction -) { - let manual_partitioning_page = installer_stack_page::InstallerStackPage::new(); - manual_partitioning_page.set_page_icon("emblem-system-symbolic"); - manual_partitioning_page.set_back_visible(true); - manual_partitioning_page.set_next_visible(true); - manual_partitioning_page.set_back_sensitive(true); - manual_partitioning_page.set_next_sensitive(false); - - // - - let content_box = gtk::Box::builder() - .orientation(gtk::Orientation::Vertical) - .hexpand(true) - .vexpand(true) - .build(); - - // - - manual_partitioning_page.connect_closure( - "back-button-pressed", - false, - closure_local!( - #[weak] - partition_carousel, - move |_manual_partitioning_page: installer_stack_page::InstallerStackPage| - { - partition_carousel.scroll_to(&partition_carousel.nth_page(0), true) - } - ) - ); - - manual_partitioning_page.connect_closure( - "next-button-pressed", - false, - closure_local!( - #[weak] - partition_carousel, - #[strong] - partition_method_type_refcell, - #[strong] - partition_method_manual_fstab_entry_array_refcell, - #[strong] - partition_method_manual_luks_enabled_refcell, - #[strong] - partition_method_manual_crypttab_entry_array_refcell, - move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| - { - *partition_method_type_refcell.borrow_mut() = String::from("automatic"); - //partition_carousel.scroll_to(&partition_carousel.nth_page(5), true) - dbg!(partition_method_type_refcell.borrow()); - dbg!(partition_method_manual_fstab_entry_array_refcell.borrow()); - dbg!(partition_method_manual_luks_enabled_refcell.borrow()); - dbg!(partition_method_manual_crypttab_entry_array_refcell.borrow()); - } - ) - ); - // - - - // - - manual_partitioning_page.set_child_widget(&content_box); - - partition_carousel.append(&manual_partitioning_page); - - // - language_changed_action.connect_activate(clone!( - #[weak] - manual_partitioning_page, - move |_, _| { - manual_partitioning_page.set_page_title(t!("auto_part_installer")); - manual_partitioning_page.set_page_subtitle(t!("choose_drive_auto")); - manual_partitioning_page.set_back_tooltip_label(t!("back")); - manual_partitioning_page.set_next_tooltip_label(t!("next")); - } - ) - ); - // -} \ No newline at end of file diff --git a/src/manual_partitioning_page/mod.rs b/src/manual_partitioning_page/mod.rs index 21864f2..f5cddd8 100644 --- a/src/manual_partitioning_page/mod.rs +++ b/src/manual_partitioning_page/mod.rs @@ -1,23 +1,30 @@ -use adw::gio; +use crate::drive_mount_row::DriveMountRow; use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib}; use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition}; -use crate::drive_mount_row::{DriveMountRow}; -use adw::{prelude::*}; +use adw::gio; +use adw::prelude::*; use glib::{clone, closure_local, ffi::gboolean}; -use std::{rc::Rc, cell::RefCell}; +use gtk::{glib, prelude::*}; +use std::{cell::RefCell, rc::Rc}; const MINIMUM_EFI_BYTE_SIZE: f64 = 500000000.0; const MINIMUM_BOOT_BYTE_SIZE: f64 = 1000000000.0; const MINIMUM_ROOT_BYTE_SIZE: f64 = 39000000000.0; +#[derive(Clone, Debug)] +struct PartitionRow { + widget: adw::ActionRow, + used: Rc>, + never: Rc>, +} + pub fn manual_partitioning_page( partition_carousel: &adw::Carousel, partition_method_type_refcell: &Rc>, partition_method_manual_fstab_entry_array_refcell: &Rc>>, partition_method_manual_luks_enabled_refcell: &Rc>, partition_method_manual_crypttab_entry_array_refcell: &Rc>>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let manual_partitioning_page = installer_stack_page::InstallerStackPage::new(); manual_partitioning_page.set_page_icon("emblem-system-symbolic"); @@ -52,8 +59,7 @@ pub fn manual_partitioning_page( drive_mounts_adw_listbox.add_css_class("boxed-list"); drive_mounts_adw_listbox.add_css_class("round-all-scroll"); - let drive_mounts_viewport = - gtk::ScrolledWindow::builder() + let drive_mounts_viewport = gtk::ScrolledWindow::builder() .vexpand(true) .hexpand(true) .has_frame(true) @@ -62,34 +68,18 @@ pub fn manual_partitioning_page( drive_mounts_viewport.add_css_class("round-all-scroll"); - let drive_mount_add_button = gtk::Button::builder() - .icon_name("list-add") - .vexpand(true) - .hexpand(true) - .build(); - - create_root_row(&drive_mounts_adw_listbox, &drive_rows_size_group, &partition_array_refcell.borrow(), &partition_changed_action, &language_changed_action, &used_partition_array_refcell, &do_used_part_check_refcell); - - drive_mounts_adw_listbox.append(&drive_mount_add_button); - content_box.append(&drive_mounts_viewport); - - - drive_mount_add_button.connect_clicked(clone!( - #[weak] - drive_mounts_adw_listbox, - #[strong] - partition_array_refcell, - #[strong] - language_changed_action, - #[strong] - partition_changed_action, - move |_| - { - create_mount_row(&drive_mounts_adw_listbox, &drive_rows_size_group, &partition_array_refcell.borrow(), &partition_changed_action, &language_changed_action, &used_partition_array_refcell, &do_used_part_check_refcell); - } - ) + create_hardcoded_rows( + &drive_mounts_adw_listbox, + &drive_rows_size_group, + &partition_array_refcell, + &partition_changed_action, + &language_changed_action, + &used_partition_array_refcell, + &do_used_part_check_refcell, ); + content_box.append(&drive_mounts_viewport); + // manual_partitioning_page.connect_closure( "back-button-pressed", @@ -97,11 +87,10 @@ pub fn manual_partitioning_page( closure_local!( #[weak] partition_carousel, - move |_manual_partitioning_page: installer_stack_page::InstallerStackPage| - { - partition_carousel.scroll_to(&partition_carousel.nth_page(0), true) + move |_manual_partitioning_page: installer_stack_page::InstallerStackPage| { + partition_carousel.scroll_to(&partition_carousel.nth_page(0), true) } - ) + ), ); manual_partitioning_page.connect_closure( @@ -118,8 +107,7 @@ pub fn manual_partitioning_page( partition_method_manual_luks_enabled_refcell, #[strong] partition_method_manual_crypttab_entry_array_refcell, - move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| - { + move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| { *partition_method_type_refcell.borrow_mut() = String::from("manual"); //partition_carousel.scroll_to(&partition_carousel.nth_page(5), true) dbg!(partition_method_type_refcell.borrow()); @@ -127,11 +115,10 @@ pub fn manual_partitioning_page( dbg!(partition_method_manual_luks_enabled_refcell.borrow()); //dbg!(partition_method_manual_crypttab_entry_array_refcell.borrow()); } - ) + ), ); // - // manual_partitioning_page.set_child_widget(&content_box); @@ -142,160 +129,16 @@ pub fn manual_partitioning_page( language_changed_action.connect_activate(clone!( #[weak] manual_partitioning_page, - move |_, _| { - manual_partitioning_page.set_page_title(t!("manual_part_installer")); - manual_partitioning_page.set_page_subtitle(t!("manual_part_info")); - manual_partitioning_page.set_back_tooltip_label(t!("back")); - manual_partitioning_page.set_next_tooltip_label(t!("next")); - } - ) - ); + move |_, _| { + manual_partitioning_page.set_page_title(t!("manual_part_installer")); + manual_partitioning_page.set_page_subtitle(t!("manual_part_info")); + manual_partitioning_page.set_back_tooltip_label(t!("back")); + manual_partitioning_page.set_next_tooltip_label(t!("next")); + } + )); // } -fn create_mount_row( - listbox: >k::ListBox, - drive_rows_size_group: >k::SizeGroup, - partition_array: &Vec, - partition_changed_action: &gio::SimpleAction, - language_changed_action: &gio::SimpleAction, - used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, -) { - let partition_scroll_child = gtk::ListBox::builder() - .selection_mode(gtk::SelectionMode::None) - .build(); - - let partitions_scroll = gtk::ScrolledWindow::builder() - .hexpand(true) - .vexpand(true) - .child(&partition_scroll_child) - .build(); - - // Create row - let row = DriveMountRow::new_with_scroll(&partitions_scroll); - - row.set_deletable(true); - - row.set_sizegroup(drive_rows_size_group); - - row.set_langaction(language_changed_action); - - 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() - .valign(gtk::Align::Center) - .can_focus(false) - .build(); - partition_button.set_group(Some(&null_checkbutton)); - let partition_row: adw::ActionRow = - if partition.need_mapper { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(t!("part_need_mapper").to_string() + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow - } - else if used_partition_array_refcell.clone().borrow().iter().any(|e| part_name == e && part_name != &row.partition()) { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow - } else { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .build(); - prow - }; - partition_row.add_prefix(&partition_button); - partition_button.connect_toggled(clone!( - #[weak] - row, - #[weak] - partition_button, - #[strong] - partition_changed_action, - #[strong] - used_partition_array_refcell, - #[strong] - partition, - move |_| - { - 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(part_name.to_string()); - } else { - (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name); - } - partition_changed_action.activate(None); - } - ) - ); - partition_changed_action.connect_activate(clone!( - #[strong] - partition_row, - #[strong] - row, - #[strong] - partition, - #[strong] - used_partition_array_refcell, - #[strong] - do_used_part_check_refcell, - move |_, _| { - if *do_used_part_check_refcell.borrow() == true { - let part_name = &partition.part_name; - let used_partition_array = used_partition_array_refcell.borrow(); - if used_partition_array.iter().any(|e| part_name == e && part_name != &row.partition()) { - partition_row.set_sensitive(false); - } else { - partition_row.set_sensitive(true); - } - } - } - ) - ); - partition_scroll_child.append(&partition_row); - } - - - listbox.append(&row); - - row.connect_closure( - "row-deleted", - false, - closure_local!( - #[weak] - listbox, - #[strong] - row, - #[strong] - used_partition_array_refcell, - #[strong] - partition_changed_action, - move |row: DriveMountRow| - { - listbox.remove(&row); - (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); - partition_changed_action.activate(None); - } - ), - ); -} - fn create_efi_row( listbox: >k::ListBox, drive_rows_size_group: >k::SizeGroup, @@ -318,12 +161,14 @@ fn create_efi_row( // Create row let row = DriveMountRow::new_with_scroll(&partitions_scroll); - row.set_deletable(true); + row.set_deletable(false); row.set_sizegroup(drive_rows_size_group); row.set_langaction(language_changed_action); + row.set_mountpoint("/boot/efi"); + let null_checkbutton = gtk::CheckButton::builder().build(); for partition in partition_array { @@ -333,89 +178,119 @@ fn create_efi_row( .can_focus(false) .build(); partition_button.set_group(Some(&null_checkbutton)); - let partition_row: adw::ActionRow = - if partition.need_mapper { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(t!("part_need_mapper").to_string() + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow + let partition_row_struct: PartitionRow = if partition.need_mapper { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + t!("part_need_mapper").to_string() + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), } - else if used_partition_array_refcell.clone().borrow().iter().any(|e| part_name == e && part_name != &row.partition()) { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow - } else { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .build(); - prow - }; - partition_row.add_prefix(&partition_button); - partition_button.connect_toggled(clone!( - #[weak] - row, - #[weak] - partition_button, - #[strong] - partition_changed_action, - #[strong] - used_partition_array_refcell, - #[strong] - partition, - move |_| - { - 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(part_name.to_string()); - } else { - (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name); - } - partition_changed_action.activate(None); - } - ) - ); - partition_changed_action.connect_activate(clone!( - #[strong] - partition_row, - #[strong] - row, - #[strong] - partition, - #[strong] - used_partition_array_refcell, - #[strong] - do_used_part_check_refcell, - move |_, _| { - if *do_used_part_check_refcell.borrow() == true { - let part_name = &partition.part_name; - let used_partition_array = used_partition_array_refcell.borrow(); - if used_partition_array.iter().any(|e| part_name == e && part_name != &row.partition()) { - partition_row.set_sensitive(false); - } else { - partition_row.set_sensitive(true); - } - } - } - ) - ); - partition_scroll_child.append(&partition_row); + } else if used_partition_array_refcell + .clone() + .borrow() + .iter() + .any(|e| part_name == e && part_name != &row.partition()) + { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(true)), + never: Rc::new(RefCell::new(false)), + } + } else if partition.part_fs != "vfat" { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_badfs_efi")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else if partition.part_size < MINIMUM_EFI_BYTE_SIZE { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_small_efi_size")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(true) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(false)), + } + }; + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + partition_scroll_child.append(&partition_row_struct.widget); } - listbox.append(&row); + + row.connect_closure( + "row-deleted", + false, + closure_local!( + #[weak] + listbox, + #[strong] + row, + #[strong] + used_partition_array_refcell, + #[strong] + partition_changed_action, + move |row: DriveMountRow| { + listbox.remove(&row); + (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + partition_changed_action.activate(None); + } + ), + ); } fn create_boot_row( @@ -440,12 +315,14 @@ fn create_boot_row( // Create row let row = DriveMountRow::new_with_scroll(&partitions_scroll); - row.set_deletable(true); + row.set_deletable(false); row.set_sizegroup(drive_rows_size_group); row.set_langaction(language_changed_action); + row.set_mountpoint("/boot"); + let null_checkbutton = gtk::CheckButton::builder().build(); for partition in partition_array { @@ -455,89 +332,119 @@ fn create_boot_row( .can_focus(false) .build(); partition_button.set_group(Some(&null_checkbutton)); - let partition_row: adw::ActionRow = - if partition.need_mapper { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(t!("part_need_mapper").to_string() + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow + let partition_row_struct: PartitionRow = if partition.need_mapper { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + t!("part_need_mapper").to_string() + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), } - else if used_partition_array_refcell.clone().borrow().iter().any(|e| part_name == e && part_name != &row.partition()) { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow - } else { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .build(); - prow - }; - partition_row.add_prefix(&partition_button); - partition_button.connect_toggled(clone!( - #[weak] - row, - #[weak] - partition_button, - #[strong] - partition_changed_action, - #[strong] - used_partition_array_refcell, - #[strong] - partition, - move |_| - { - 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(part_name.to_string()); - } else { - (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name); - } - partition_changed_action.activate(None); - } - ) - ); - partition_changed_action.connect_activate(clone!( - #[strong] - partition_row, - #[strong] - row, - #[strong] - partition, - #[strong] - used_partition_array_refcell, - #[strong] - do_used_part_check_refcell, - move |_, _| { - if *do_used_part_check_refcell.borrow() == true { - let part_name = &partition.part_name; - let used_partition_array = used_partition_array_refcell.borrow(); - if used_partition_array.iter().any(|e| part_name == e && part_name != &row.partition()) { - partition_row.set_sensitive(false); - } else { - partition_row.set_sensitive(true); - } - } - } - ) - ); - partition_scroll_child.append(&partition_row); + } else if used_partition_array_refcell + .clone() + .borrow() + .iter() + .any(|e| part_name == e && part_name != &row.partition()) + { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(true)), + never: Rc::new(RefCell::new(false)), + } + } else if partition.part_fs != "ext4" { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_badfs_boot")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else if partition.part_size < MINIMUM_BOOT_BYTE_SIZE { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_small_boot_size")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(true) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(false)), + } + }; + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + partition_scroll_child.append(&partition_row_struct.widget); } - listbox.append(&row); + + row.connect_closure( + "row-deleted", + false, + closure_local!( + #[weak] + listbox, + #[strong] + row, + #[strong] + used_partition_array_refcell, + #[strong] + partition_changed_action, + move |row: DriveMountRow| { + listbox.remove(&row); + (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + partition_changed_action.activate(None); + } + ), + ); } fn create_root_row( @@ -579,87 +486,398 @@ fn create_root_row( .can_focus(false) .build(); partition_button.set_group(Some(&null_checkbutton)); - let partition_row: adw::ActionRow = - if partition.need_mapper { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(t!("part_need_mapper").to_string() + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow + let partition_row_struct: PartitionRow = if partition.need_mapper { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + t!("part_need_mapper").to_string() + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), } - else if used_partition_array_refcell.clone().borrow().iter().any(|e| part_name == e && part_name != &row.partition()) { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .sensitive(false) - .build(); - prow - } else { - let prow = adw::ActionRow::builder() - .activatable_widget(&partition_button) - .title(part_name) - .name(part_name) - .subtitle(String::from(&partition.part_fs) + " " + &pretty_bytes::converter::convert(partition.part_size)) - .build(); - prow - }; - partition_row.add_prefix(&partition_button); - partition_button.connect_toggled(clone!( - #[weak] - row, - #[weak] - partition_button, - #[strong] - partition_changed_action, - #[strong] - used_partition_array_refcell, - #[strong] - partition, - move |_| - { - 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(part_name.to_string()); - } else { - (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name); - } - partition_changed_action.activate(None); - } - ) - ); - partition_changed_action.connect_activate(clone!( - #[strong] - partition_row, - #[strong] - row, - #[strong] - partition, - #[strong] - used_partition_array_refcell, - #[strong] - do_used_part_check_refcell, - move |_, _| { - if *do_used_part_check_refcell.borrow() == true { - let part_name = &partition.part_name; - let used_partition_array = used_partition_array_refcell.borrow(); - if used_partition_array.iter().any(|e| part_name == e && part_name != &row.partition()) { - partition_row.set_sensitive(false); - } else { - partition_row.set_sensitive(true); - } - } - } - ) - ); - partition_scroll_child.append(&partition_row); + } else if used_partition_array_refcell + .clone() + .borrow() + .iter() + .any(|e| part_name == e && part_name != &row.partition()) + { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(true)), + never: Rc::new(RefCell::new(false)), + } + } else if partition.part_fs == "vfat" + || partition.part_fs == "ntfs" + || partition.part_fs == "swap" + || partition.part_fs == "exfat" + || partition.part_fs == "BitLocker" + { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_badfs_root")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else if partition.part_size < MINIMUM_ROOT_BYTE_SIZE { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle(t!("fstab_small_root_size")) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(true) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(false)), + } + }; + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + partition_scroll_child.append(&partition_row_struct.widget); } - listbox.append(&row); -} \ No newline at end of file + + row.connect_closure( + "row-deleted", + false, + closure_local!( + #[weak] + listbox, + #[strong] + row, + #[strong] + used_partition_array_refcell, + #[strong] + partition_changed_action, + move |row: DriveMountRow| { + listbox.remove(&row); + (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + partition_changed_action.activate(None); + } + ), + ); +} + +fn create_mount_row( + listbox: >k::ListBox, + drive_rows_size_group: >k::SizeGroup, + partition_array: &Vec, + partition_changed_action: &gio::SimpleAction, + language_changed_action: &gio::SimpleAction, + used_partition_array_refcell: &Rc>>, + do_used_part_check_refcell: &Rc>, +) { + let partition_scroll_child = gtk::ListBox::builder() + .selection_mode(gtk::SelectionMode::None) + .build(); + + let partitions_scroll = gtk::ScrolledWindow::builder() + .hexpand(true) + .vexpand(true) + .child(&partition_scroll_child) + .build(); + + // Create row + let row = DriveMountRow::new_with_scroll(&partitions_scroll); + + row.set_deletable(true); + + row.set_sizegroup(drive_rows_size_group); + + row.set_langaction(language_changed_action); + + 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() + .valign(gtk::Align::Center) + .can_focus(false) + .build(); + partition_button.set_group(Some(&null_checkbutton)); + let partition_row_struct: PartitionRow = if partition.need_mapper { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + t!("part_need_mapper").to_string() + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(true)), + } + } else if used_partition_array_refcell + .clone() + .borrow() + .iter() + .any(|e| part_name == e && part_name != &row.partition()) + { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(false) + .build(); + prow + }, + used: Rc::new(RefCell::new(true)), + never: Rc::new(RefCell::new(false)), + } + } else { + PartitionRow { + widget: { + let prow = adw::ActionRow::builder() + .activatable_widget(&partition_button) + .title(part_name) + .subtitle( + String::from(&partition.part_fs) + + " " + + &pretty_bytes::converter::convert(partition.part_size), + ) + .sensitive(true) + .build(); + prow + }, + used: Rc::new(RefCell::new(false)), + never: Rc::new(RefCell::new(false)), + } + }; + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + partition_scroll_child.append(&partition_row_struct.widget); + } + + listbox.append(&row); + + row.connect_closure( + "row-deleted", + false, + closure_local!( + #[weak] + listbox, + #[strong] + row, + #[strong] + used_partition_array_refcell, + #[strong] + partition_changed_action, + move |row: DriveMountRow| { + listbox.remove(&row); + (*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + partition_changed_action.activate(None); + } + ), + ); +} + +fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionRow, partition_button: >k::CheckButton, partition_changed_action: &gio::SimpleAction, partition: &Partition, used_partition_array_refcell: &Rc>>, do_used_part_check_refcell: &Rc>) { + partition_row_struct.widget.add_prefix(partition_button); + partition_button.connect_toggled(clone!( + #[weak] + row, + #[weak] + partition_button, + #[strong] + partition_changed_action, + #[strong] + used_partition_array_refcell, + #[strong] + partition, + move |_| { + 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(part_name.to_string()); + } else { + (*used_partition_array_refcell.borrow_mut()) + .retain(|x| x != &partition.part_name); + } + partition_changed_action.activate(None); + } + )); + row.connect_mountpoint_notify(clone!( + #[strong] + partition_row_struct, + #[strong] + partition, + #[strong] + partition_changed_action, + #[strong] + row, + move |_| { + dbg!(&partition_row_struct); + if row.mountpoint() == "[SWAP]" { + if partition.part_fs != "linux-swap" { + partition_row_struct.widget.set_sensitive(false); + } + } else if *partition_row_struct.used.borrow() == false + && *partition_row_struct.never.borrow() == false + { + partition_row_struct.widget.set_sensitive(true); + } + } + )); + + partition_changed_action.connect_activate(clone!( + #[strong] + partition_row_struct, + #[strong] + row, + #[strong] + partition, + #[strong] + used_partition_array_refcell, + #[strong] + do_used_part_check_refcell, + move |_, _| { + if *do_used_part_check_refcell.borrow() == true { + let part_name = &partition.part_name; + let used_partition_array = used_partition_array_refcell.borrow(); + if used_partition_array + .iter() + .any(|e| part_name == e && part_name != &row.partition()) + { + partition_row_struct.widget.set_sensitive(false); + (*partition_row_struct.used.borrow_mut()) = true; + } else if *partition_row_struct.never.borrow() == false { + partition_row_struct.widget.set_sensitive(true); + (*partition_row_struct.used.borrow_mut()) = false; + } + } + } + )); +} + +fn create_hardcoded_rows( + drive_mounts_adw_listbox: >k::ListBox, + drive_rows_size_group: >k::SizeGroup, + partition_array_refcell: &Rc>>, + partition_changed_action: &gio::SimpleAction, + language_changed_action: &gio::SimpleAction, + used_partition_array_refcell: &Rc>>, + do_used_part_check_refcell: &Rc>, +) { + let drive_mount_add_button = gtk::Button::builder() + .icon_name("list-add") + .vexpand(true) + .hexpand(true) + .build(); + + create_efi_row( + &drive_mounts_adw_listbox, + &drive_rows_size_group, + &partition_array_refcell.borrow(), + &partition_changed_action, + &language_changed_action, + &used_partition_array_refcell, + &do_used_part_check_refcell, + ); + create_boot_row( + &drive_mounts_adw_listbox, + &drive_rows_size_group, + &partition_array_refcell.borrow(), + &partition_changed_action, + &language_changed_action, + &used_partition_array_refcell, + &do_used_part_check_refcell, + ); + create_root_row( + &drive_mounts_adw_listbox, + &drive_rows_size_group, + &partition_array_refcell.borrow(), + &partition_changed_action, + &language_changed_action, + &used_partition_array_refcell, + &do_used_part_check_refcell, + ); + + drive_mounts_adw_listbox.append(&drive_mount_add_button); + + drive_mount_add_button.connect_clicked(clone!( + #[weak] + drive_mounts_adw_listbox, + #[strong] + drive_rows_size_group, + #[strong] + partition_array_refcell, + #[strong] + partition_changed_action, + #[strong] + language_changed_action, + #[strong] + used_partition_array_refcell, + #[strong] + do_used_part_check_refcell, + move |_| { + create_mount_row( + &drive_mounts_adw_listbox, + &drive_rows_size_group, + &partition_array_refcell.borrow(), + &partition_changed_action, + &language_changed_action, + &used_partition_array_refcell, + &do_used_part_check_refcell, + ); + } + )); +} diff --git a/src/partitioning_page/mod.rs b/src/partitioning_page/mod.rs index f648eda..e53ea91 100644 --- a/src/partitioning_page/mod.rs +++ b/src/partitioning_page/mod.rs @@ -1,24 +1,24 @@ use crate::drive_mount_row::DriveMountRow; use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib, gio as gio}; -use glib::{clone, closure_local, Properties}; use crate::{automatic_partitioning_page, manual_partitioning_page}; -use std::{rc::Rc, cell::RefCell}; +use glib::{clone, closure_local, Properties}; +use gtk::{gio, glib, prelude::*}; use std::io::BufRead; +use std::{cell::RefCell, rc::Rc}; pub fn partitioning_page( main_carousel: &adw::Carousel, partition_method_type_refcell: &Rc>, - partition_method_automatic_target_refcell: &Rc>, - partition_method_automatic_target_fs_refcell: &Rc>, - partition_method_automatic_luks_enabled_refcell: &Rc>, + partition_method_automatic_target_refcell: &Rc>, + partition_method_automatic_target_fs_refcell: &Rc>, + partition_method_automatic_luks_enabled_refcell: &Rc>, partition_method_automatic_luks_refcell: &Rc>, partition_method_automatic_ratio_refcell: &Rc>, partition_method_automatic_seperation_refcell: &Rc>, partition_method_manual_fstab_entry_array_refcell: &Rc>>, partition_method_manual_luks_enabled_refcell: &Rc>, partition_method_manual_crypttab_entry_array_refcell: &Rc>>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let partitioning_page = installer_stack_page::InstallerStackPage::new(); partitioning_page.set_page_icon("media-floppy-symbolic"); @@ -46,31 +46,23 @@ pub fn partitioning_page( content_box.add_css_class("linked"); - let automatic_method_button = gtk::Button::builder() - .icon_name("builder") - .build(); + let automatic_method_button = gtk::Button::builder().icon_name("builder").build(); let manual_method_button = gtk::Button::builder() .icon_name("emblem-system-symbolics") .build(); - automatic_method_button.connect_clicked( - clone!( - #[weak] - partitioning_carousel, - move |_| - partitioning_carousel.scroll_to(&partitioning_carousel.nth_page(1), true) - ) - ); + automatic_method_button.connect_clicked(clone!( + #[weak] + partitioning_carousel, + move |_| partitioning_carousel.scroll_to(&partitioning_carousel.nth_page(1), true) + )); - manual_method_button.connect_clicked( - clone!( - #[weak] - partitioning_carousel, - move |_| - partitioning_carousel.scroll_to(&partitioning_carousel.nth_page(2), true) - ) - ); + manual_method_button.connect_clicked(clone!( + #[weak] + partitioning_carousel, + move |_| partitioning_carousel.scroll_to(&partitioning_carousel.nth_page(2), true) + )); content_box.append(&automatic_method_button); content_box.append(&manual_method_button); @@ -78,27 +70,25 @@ pub fn partitioning_page( partitioning_page.set_child_widget(&content_box); // - language_changed_action.connect_activate( - clone!( - #[weak] - partitioning_page, - move |_, _| { - partitioning_page.set_page_title(t!("partitioning")); - partitioning_page.set_page_subtitle(t!("choose_install_method")); - partitioning_page.set_back_tooltip_label(t!("back")); - partitioning_page.set_next_tooltip_label(t!("next")); - // - automatic_method_button.set_label(&t!("auto_partition_drive")); - // - manual_method_button.set_label(&t!("manual_partition_drive")); - } - ) - ); + language_changed_action.connect_activate(clone!( + #[weak] + partitioning_page, + move |_, _| { + partitioning_page.set_page_title(t!("partitioning")); + partitioning_page.set_page_subtitle(t!("choose_install_method")); + partitioning_page.set_back_tooltip_label(t!("back")); + partitioning_page.set_next_tooltip_label(t!("next")); + // + automatic_method_button.set_label(&t!("auto_partition_drive")); + // + manual_method_button.set_label(&t!("manual_partition_drive")); + } + )); // partitioning_carousel.append(&partitioning_page); automatic_partitioning_page::automatic_partitioning_page( - &partitioning_carousel, + &partitioning_carousel, &partition_method_type_refcell, &partition_method_automatic_target_refcell, &partition_method_automatic_target_fs_refcell, @@ -106,14 +96,16 @@ pub fn partitioning_page( &partition_method_automatic_luks_refcell, &partition_method_automatic_ratio_refcell, &partition_method_automatic_seperation_refcell, - &language_changed_action); + &language_changed_action, + ); manual_partitioning_page::manual_partitioning_page( - &partitioning_carousel, - &partition_method_type_refcell, - &partition_method_manual_fstab_entry_array_refcell, - &partition_method_manual_luks_enabled_refcell, - &partition_method_manual_crypttab_entry_array_refcell, - &language_changed_action); + &partitioning_carousel, + &partition_method_type_refcell, + &partition_method_manual_fstab_entry_array_refcell, + &partition_method_manual_luks_enabled_refcell, + &partition_method_manual_crypttab_entry_array_refcell, + &language_changed_action, + ); partitioning_page.connect_closure( "back-button-pressed", @@ -121,11 +113,10 @@ pub fn partitioning_page( closure_local!( #[weak] main_carousel, - move |_partitioning_page: installer_stack_page::InstallerStackPage| - { - main_carousel.scroll_to(&main_carousel.nth_page(4), true) + move |_partitioning_page: installer_stack_page::InstallerStackPage| { + main_carousel.scroll_to(&main_carousel.nth_page(4), true) } - ) + ), ); main_carousel.append(&partitioning_carousel) @@ -134,7 +125,7 @@ pub fn partitioning_page( pub struct BlockDevice { pub block_name: String, pub block_size: f64, - pub block_size_pretty: String + pub block_size_pretty: String, } #[derive(Clone)] @@ -144,7 +135,7 @@ pub struct Partition { pub has_encryption: bool, pub need_mapper: bool, pub part_size: f64, - pub part_size_pretty: String + pub part_size_pretty: String, } #[derive(Default)] @@ -168,10 +159,11 @@ pub fn get_block_devices() -> Vec { .arg("get_block_devices") .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) - .spawn() { - Ok(t) => t, - Err(_) => return block_devices - }; + .spawn() + { + Ok(t) => t, + Err(_) => return block_devices, + }; match command.stdout { Some(t) => { @@ -179,19 +171,17 @@ pub fn get_block_devices() -> Vec { match blockdev { Ok(r) => { let block_size = get_block_size(&r); - block_devices.push( - BlockDevice { - block_name: r, - block_size: block_size, - block_size_pretty: pretty_bytes::converter::convert(block_size) - } - ) + block_devices.push(BlockDevice { + block_name: r, + block_size: block_size, + block_size_pretty: pretty_bytes::converter::convert(block_size), + }) } - Err(_) => return block_devices + Err(_) => return block_devices, } } - }, - None => return block_devices + } + None => return block_devices, }; block_devices @@ -202,15 +192,14 @@ fn get_block_size(block_dev: &str) -> f64 { .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") .arg("get_block_size") .arg(block_dev) - .output() { - Ok(t) => t, - Err(_) => return 0.0 - }; + .output() + { + Ok(t) => t, + Err(_) => return 0.0, + }; let size = match String::from_utf8(command.stdout) { - Ok(t) => { - t.trim().parse::().unwrap_or(0.0) - } - Err(_) => 0.0 + Ok(t) => t.trim().parse::().unwrap_or(0.0), + Err(_) => 0.0, }; size @@ -224,10 +213,11 @@ pub fn get_partitions() -> Vec { .arg("get_partitions") .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) - .spawn() { - Ok(t) => t, - Err(_) => return partitions - }; + .spawn() + { + Ok(t) => t, + Err(_) => return partitions, + }; match command.stdout { Some(t) => { @@ -236,22 +226,20 @@ pub fn get_partitions() -> Vec { Ok(r) => { let part_size = get_part_size(&r); let part_fs = get_part_fs(&r); - partitions.push( - Partition { - has_encryption: is_encrypted(&r), - need_mapper: is_needs_mapper(&part_fs), - part_name: r, - part_fs: part_fs, - part_size: part_size, - part_size_pretty: pretty_bytes::converter::convert(part_size) - } - ) + partitions.push(Partition { + has_encryption: is_encrypted(&r), + need_mapper: is_needs_mapper(&part_fs), + part_name: r, + part_fs: part_fs, + part_size: part_size, + part_size_pretty: pretty_bytes::converter::convert(part_size), + }) } - Err(_) => return partitions + Err(_) => return partitions, } } - }, - None => return partitions + } + None => return partitions, }; partitions @@ -262,15 +250,14 @@ fn get_part_size(part_dev: &str) -> f64 { .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") .arg("get_part_size") .arg(part_dev) - .output() { - Ok(t) => t, - Err(_) => return 0.0 - }; + .output() + { + Ok(t) => t, + Err(_) => return 0.0, + }; let size = match String::from_utf8(command.stdout) { - Ok(t) => { - t.trim().parse::().unwrap_or(0.0) - } - Err(_) => 0.0 + Ok(t) => t.trim().parse::().unwrap_or(0.0), + Err(_) => 0.0, }; size @@ -281,22 +268,21 @@ fn get_part_fs(part_dev: &str) -> String { .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") .arg("get_part_fs") .arg(part_dev.replace("mapper/", "")) - .output() { - Ok(t) => t, - Err(_) => return String::from(t!("fs_unknown")) - }; + .output() + { + Ok(t) => t, + Err(_) => return String::from(t!("fs_unknown")), + }; let fs = match String::from_utf8(command.stdout) { - Ok(t) => { - t.trim().to_owned() - } - Err(_) => String::from(t!("fs_unknown")) + Ok(t) => t.trim().to_owned(), + Err(_) => String::from(t!("fs_unknown")), }; fs } fn is_needs_mapper(part_fs: &str) -> bool { - if part_fs.contains("crypto_LUKS") || part_fs.contains("lvm") { + if part_fs.contains("crypto_LUKS") || part_fs.contains("lvm") || part_fs.contains("BitLocker") { true } else { false @@ -308,14 +294,15 @@ fn is_encrypted(part_dev: &str) -> bool { .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") .arg("has_encryption") .arg(part_dev) - .output() { - Ok(t) => t, - Err(_) => return false - }; - + .output() + { + Ok(t) => t, + Err(_) => return false, + }; + if command.status.success() { true } else { false } -} \ No newline at end of file +} diff --git a/src/timezone_page/mod.rs b/src/timezone_page/mod.rs index 96c56a6..af41bd0 100644 --- a/src/timezone_page/mod.rs +++ b/src/timezone_page/mod.rs @@ -1,14 +1,14 @@ use crate::installer_stack_page; -use gtk::{prelude::*, glib as glib, gio as gio}; -use adw::{prelude::*}; +use adw::prelude::*; use glib::{clone, closure_local}; -use std::{process::Command, fs, path::Path, rc::Rc, cell::RefCell}; +use gtk::{gio, glib, prelude::*}; use std::io::BufRead; +use std::{cell::RefCell, fs, path::Path, process::Command, rc::Rc}; pub fn timezone_page( main_carousel: &adw::Carousel, timezone_data_refcell: &Rc>, - language_changed_action: &gio::SimpleAction + language_changed_action: &gio::SimpleAction, ) { let timezone_page = installer_stack_page::InstallerStackPage::new(); timezone_page.set_page_icon("alarm-symbolic"); @@ -23,8 +23,7 @@ pub fn timezone_page( .vexpand(true) .build(); - let null_checkbutton = gtk::CheckButton::builder() - .build(); + let null_checkbutton = gtk::CheckButton::builder().build(); let timezone_selection_row_viewport_listbox = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -32,14 +31,13 @@ pub fn timezone_page( timezone_selection_row_viewport_listbox.add_css_class("boxed-list"); timezone_selection_row_viewport_listbox.add_css_class("round-all-scroll"); - let timezone_selection_row_viewport = - gtk::ScrolledWindow::builder() - .vexpand(true) - .hexpand(true) - .has_frame(true) - .child(&timezone_selection_row_viewport_listbox) - .build(); - + let timezone_selection_row_viewport = gtk::ScrolledWindow::builder() + .vexpand(true) + .hexpand(true) + .has_frame(true) + .child(&timezone_selection_row_viewport_listbox) + .build(); + timezone_selection_row_viewport.add_css_class("round-all-scroll"); let timezone_search_bar = gtk::SearchEntry::builder() @@ -52,17 +50,19 @@ pub fn timezone_page( timezone_search_bar.add_css_class("rounded-all-25"); let current_timezone_cli = Command::new("timedatectl") - .arg("show") - .arg("--va") - .arg("-p") - .arg("Timezone") - .stdin(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) - .spawn() - .unwrap_or_else(|e| panic!("failed {}", e)); + .arg("show") + .arg("--va") + .arg("-p") + .arg("Timezone") + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap_or_else(|e| panic!("failed {}", e)); let current_timezone_output = current_timezone_cli.wait_with_output().unwrap(); - let current_timezone = String::from_utf8_lossy(¤t_timezone_output.stdout).trim().to_owned(); + let current_timezone = String::from_utf8_lossy(¤t_timezone_output.stdout) + .trim() + .to_owned(); let timezone_cli = Command::new("timedatectl") .arg("list-timezones") @@ -88,23 +88,20 @@ pub fn timezone_page( timezone_row.add_prefix(&timezone_checkbutton); timezone_checkbutton.set_group(Some(&null_checkbutton)); timezone_selection_row_viewport_listbox.append(&timezone_row); - timezone_checkbutton.connect_toggled( - clone!( - #[weak] - timezone_checkbutton, - #[weak] - timezone_page, - #[weak] - timezone_data_refcell, - move |_| - { - if timezone_checkbutton.is_active() == true { - timezone_page.set_next_sensitive(true); - *timezone_data_refcell.borrow_mut() = String::from(&timezone); - } + timezone_checkbutton.connect_toggled(clone!( + #[weak] + timezone_checkbutton, + #[weak] + timezone_page, + #[weak] + timezone_data_refcell, + move |_| { + if timezone_checkbutton.is_active() == true { + timezone_page.set_next_sensitive(true); + *timezone_data_refcell.borrow_mut() = String::from(&timezone); } - ) - ); + } + )); if ¤t_timezone == &timezone_clone { timezone_checkbutton.set_active(true); } @@ -120,13 +117,20 @@ pub fn timezone_page( timezone_search_bar, #[weak] timezone_selection_row_viewport_listbox, - move |_| - { + move |_| { let mut counter = timezone_selection_row_viewport_listbox.first_child(); while let Some(row) = counter { if row.widget_name() == "AdwActionRow" { if !timezone_search_bar.text().is_empty() { - if row.property::("subtitle").to_lowercase().contains(&timezone_search_bar.text().to_string().to_lowercase()) || row.property::("title").to_lowercase().contains(&timezone_search_bar.text().to_string().to_lowercase()) { + if row + .property::("subtitle") + .to_lowercase() + .contains(&timezone_search_bar.text().to_string().to_lowercase()) + || row + .property::("title") + .to_lowercase() + .contains(&timezone_search_bar.text().to_string().to_lowercase()) + { row.set_property("visible", true); timezone_search_bar.grab_focus(); } else { @@ -144,22 +148,20 @@ pub fn timezone_page( timezone_page.set_child_widget(&content_box); // - language_changed_action.connect_activate( - clone!( - #[weak] - timezone_page, - #[weak] - timezone_search_bar, - move |_, _| { - timezone_page.set_page_title(t!("timezone")); - timezone_page.set_page_subtitle(t!("select_a_timezone")); - timezone_page.set_back_tooltip_label(t!("back")); - timezone_page.set_next_tooltip_label(t!("next")); - // - timezone_search_bar.set_placeholder_text(Some(&t!("search_for_timezone"))); - } - ) - ); + language_changed_action.connect_activate(clone!( + #[weak] + timezone_page, + #[weak] + timezone_search_bar, + move |_, _| { + timezone_page.set_page_title(t!("timezone")); + timezone_page.set_page_subtitle(t!("select_a_timezone")); + timezone_page.set_back_tooltip_label(t!("back")); + timezone_page.set_next_tooltip_label(t!("next")); + // + timezone_search_bar.set_placeholder_text(Some(&t!("search_for_timezone"))); + } + )); // timezone_page.connect_closure( @@ -168,11 +170,10 @@ pub fn timezone_page( closure_local!( #[weak] main_carousel, - move |_timezone_page: installer_stack_page::InstallerStackPage| - { - main_carousel.scroll_to(&main_carousel.nth_page(3), true) + move |_timezone_page: installer_stack_page::InstallerStackPage| { + main_carousel.scroll_to(&main_carousel.nth_page(3), true) } - ) + ), ); timezone_page.connect_closure( @@ -183,8 +184,7 @@ pub fn timezone_page( main_carousel, #[strong] timezone_data_refcell, - move |_timezone_page: installer_stack_page::InstallerStackPage| - { + move |_timezone_page: installer_stack_page::InstallerStackPage| { let timezone = timezone_data_refcell.borrow(); Command::new("sudo") .arg("timedatectl") @@ -194,8 +194,8 @@ pub fn timezone_page( .expect("timezone failed to start"); main_carousel.scroll_to(&main_carousel.nth_page(5), true) } - ) + ), ); main_carousel.append(&timezone_page); -} \ No newline at end of file +} diff --git a/src/welcome_page/mod.rs b/src/welcome_page/mod.rs index bec0f87..d1b541a 100644 --- a/src/welcome_page/mod.rs +++ b/src/welcome_page/mod.rs @@ -1,11 +1,8 @@ -use crate::installer_stack_page; use crate::config; -use gtk::{prelude::*, glib as glib}; +use crate::installer_stack_page; use glib::clone; -pub fn welcome_page( - window: &adw::ApplicationWindow, - main_carousel: &adw::Carousel, -) { +use gtk::{glib, prelude::*}; +pub fn welcome_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carousel) { let welcome_page = installer_stack_page::InstallerStackPage::new(); welcome_page.set_page_title(t!("welcome")); welcome_page.set_page_subtitle(t!("welcome_to_pikaos")); @@ -34,23 +31,17 @@ pub fn welcome_page( .label(t!("install_distro_to_system")) .build(); - install_media_button.connect_clicked( - clone!( - #[weak] - main_carousel, - move |_| - main_carousel.scroll_to(&main_carousel.nth_page(1), true) - ) - ); + install_media_button.connect_clicked(clone!( + #[weak] + main_carousel, + move |_| main_carousel.scroll_to(&main_carousel.nth_page(1), true) + )); - live_media_button.connect_clicked( - clone!( - #[weak] - window, - move |_| - window.close() - ) - ); + live_media_button.connect_clicked(clone!( + #[weak] + window, + move |_| window.close() + )); content_box.append(&install_media_button); content_box.append(&live_media_button); @@ -58,4 +49,4 @@ pub fn welcome_page( welcome_page.set_child_widget(&content_box); main_carousel.append(&welcome_page); -} \ No newline at end of file +}