pika-installer-gtk4/src/manual_partitioning_page/mod.rs

222 lines
7.4 KiB
Rust
Raw Normal View History

2024-08-19 01:12:35 +02:00
use crate::drive_mount_row::DriveMountRow;
2024-08-17 00:15:03 +02:00
use crate::installer_stack_page;
2024-08-18 00:17:57 +02:00
use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition};
2024-08-19 01:12:35 +02:00
use adw::gio;
use adw::prelude::*;
2024-08-17 00:15:03 +02:00
use glib::{clone, closure_local, ffi::gboolean};
2024-08-19 01:12:35 +02:00
use gtk::{glib, prelude::*};
use std::{cell::RefCell, rc::Rc};
2024-08-17 00:15:03 +02:00
mod func;
2024-08-19 01:12:35 +02:00
2024-08-17 00:15:03 +02:00
pub fn manual_partitioning_page(
partition_carousel: &adw::Carousel,
partition_method_type_refcell: &Rc<RefCell<String>>,
2024-08-18 00:17:57 +02:00
partition_method_manual_fstab_entry_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
2024-08-17 00:15:03 +02:00
partition_method_manual_luks_enabled_refcell: &Rc<RefCell<bool>>,
2024-08-18 00:17:57 +02:00
partition_method_manual_crypttab_entry_array_refcell: &Rc<RefCell<Vec<CrypttabEntry>>>,
2024-08-19 01:12:35 +02:00
language_changed_action: &gio::SimpleAction,
2024-08-17 00:15:03 +02:00
) {
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);
2024-08-18 00:17:57 +02:00
let partition_array_refcell = Rc::new(RefCell::new(get_partitions()));
2024-08-18 18:56:31 +02:00
let used_partition_array_refcell: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::default());
2024-08-19 02:39:52 +02:00
let subvol_partition_array_refcell: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::default());
2024-08-18 18:56:31 +02:00
//
let partition_changed_action = gio::SimpleAction::new("partition-changed", None);
2024-08-18 00:17:57 +02:00
2024-08-17 00:15:03 +02:00
//
2024-08-18 20:50:25 +02:00
let drive_rows_size_group = gtk::SizeGroup::new(gtk::SizeGroupMode::Horizontal);
//
2024-08-17 00:15:03 +02:00
let content_box = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.hexpand(true)
.vexpand(true)
.build();
2024-08-18 18:56:31 +02:00
let drive_mounts_adw_listbox = gtk::ListBox::builder()
.selection_mode(gtk::SelectionMode::None)
.build();
2024-08-18 00:17:57 +02:00
drive_mounts_adw_listbox.add_css_class("boxed-list");
2024-08-18 18:56:31 +02:00
drive_mounts_adw_listbox.add_css_class("round-all-scroll");
2024-08-19 01:12:35 +02:00
let drive_mounts_viewport = gtk::ScrolledWindow::builder()
2024-08-18 00:17:57 +02:00
.vexpand(true)
2024-08-18 18:56:31 +02:00
.hexpand(true)
.has_frame(true)
2024-08-18 00:17:57 +02:00
.child(&drive_mounts_adw_listbox)
.build();
2024-08-18 18:56:31 +02:00
drive_mounts_viewport.add_css_class("round-all-scroll");
2024-08-19 01:12:35 +02:00
create_hardcoded_rows(
&drive_mounts_adw_listbox,
&drive_rows_size_group,
&partition_array_refcell,
&partition_changed_action,
&language_changed_action,
&used_partition_array_refcell,
2024-08-19 02:39:52 +02:00
&subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
);
2024-08-18 00:17:57 +02:00
2024-08-18 18:56:31 +02:00
content_box.append(&drive_mounts_viewport);
2024-08-17 00:15:03 +02:00
2024-08-18 00:17:57 +02:00
//
2024-08-17 00:15:03 +02:00
manual_partitioning_page.connect_closure(
"back-button-pressed",
false,
closure_local!(
#[weak]
partition_carousel,
2024-08-19 01:12:35 +02:00
move |_manual_partitioning_page: installer_stack_page::InstallerStackPage| {
partition_carousel.scroll_to(&partition_carousel.nth_page(0), true)
2024-08-17 00:15:03 +02:00
}
2024-08-19 01:12:35 +02:00
),
2024-08-17 00:15:03 +02:00
);
manual_partitioning_page.connect_closure(
"next-button-pressed",
false,
closure_local!(
#[weak]
partition_carousel,
#[strong]
partition_method_type_refcell,
#[strong]
2024-08-18 00:17:57 +02:00
partition_method_manual_fstab_entry_array_refcell,
2024-08-17 00:15:03 +02:00
#[strong]
partition_method_manual_luks_enabled_refcell,
#[strong]
2024-08-18 00:17:57 +02:00
partition_method_manual_crypttab_entry_array_refcell,
2024-08-19 01:12:35 +02:00
move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage| {
2024-08-17 00:15:03 +02:00
*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());
2024-08-18 00:17:57 +02:00
//dbg!(partition_method_manual_fstab_entry_array_refcell.borrow());
2024-08-17 00:15:03 +02:00
dbg!(partition_method_manual_luks_enabled_refcell.borrow());
2024-08-18 00:17:57 +02:00
//dbg!(partition_method_manual_crypttab_entry_array_refcell.borrow());
2024-08-17 00:15:03 +02:00
}
2024-08-19 01:12:35 +02:00
),
2024-08-17 00:15:03 +02:00
);
//
//
manual_partitioning_page.set_child_widget(&content_box);
partition_carousel.append(&manual_partitioning_page);
2024-08-18 18:56:31 +02:00
//
language_changed_action.connect_activate(clone!(
#[weak]
manual_partitioning_page,
2024-08-19 01:12:35 +02:00
move |_, _| {
2024-08-19 01:50:56 +02:00
manual_partitioning_page.set_page_title(t!("manual_partitioning_page_title"));
manual_partitioning_page.set_page_subtitle(t!("manual_partitioning_page_subtitle"));
2024-08-19 01:12:35 +02:00
manual_partitioning_page.set_back_tooltip_label(t!("back"));
manual_partitioning_page.set_next_tooltip_label(t!("next"));
}
));
2024-08-18 18:56:31 +02:00
//
2024-08-18 00:17:57 +02:00
}
2024-08-19 01:12:35 +02:00
fn create_hardcoded_rows(
drive_mounts_adw_listbox: &gtk::ListBox,
drive_rows_size_group: &gtk::SizeGroup,
partition_array_refcell: &Rc<RefCell<Vec<Partition>>>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
2024-08-19 02:39:52 +02:00
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
2024-08-19 01:12:35 +02:00
) {
2024-08-19 08:20:36 +02:00
let drive_mount_add_button_icon = gtk::Image::builder()
2024-08-19 01:12:35 +02:00
.icon_name("list-add")
2024-08-19 08:20:36 +02:00
.halign(gtk::Align::Start)
.build();
let drive_mount_add_button_label = gtk::Label::builder()
.label(t!("drive_mount_add_button_label"))
.halign(gtk::Align::Center)
.hexpand(true)
.build();
let drive_mount_add_button_child_box = gtk::Box::new(gtk::Orientation::Horizontal, 0);
drive_mount_add_button_child_box.append(&drive_mount_add_button_icon);
drive_mount_add_button_child_box.append(&drive_mount_add_button_label);
let drive_mount_add_button = gtk::Button::builder()
.child(&drive_mount_add_button_child_box)
2024-08-19 01:12:35 +02:00
.vexpand(true)
.hexpand(true)
.build();
func::create_efi_row(
2024-08-19 01:12:35 +02:00
&drive_mounts_adw_listbox,
&drive_rows_size_group,
&partition_array_refcell.borrow(),
&partition_changed_action,
&language_changed_action,
&used_partition_array_refcell,
2024-08-19 02:39:52 +02:00
&subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
);
func::create_boot_row(
2024-08-19 01:12:35 +02:00
&drive_mounts_adw_listbox,
&drive_rows_size_group,
&partition_array_refcell.borrow(),
&partition_changed_action,
&language_changed_action,
&used_partition_array_refcell,
2024-08-19 02:39:52 +02:00
&subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
);
func::create_root_row(
2024-08-19 01:12:35 +02:00
&drive_mounts_adw_listbox,
&drive_rows_size_group,
&partition_array_refcell.borrow(),
&partition_changed_action,
&language_changed_action,
&used_partition_array_refcell,
2024-08-19 02:39:52 +02:00
&subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
);
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]
2024-08-19 02:39:52 +02:00
subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
move |_| {
func::create_mount_row(
2024-08-19 01:12:35 +02:00
&drive_mounts_adw_listbox,
&drive_rows_size_group,
&partition_array_refcell.borrow(),
&partition_changed_action,
&language_changed_action,
&used_partition_array_refcell,
2024-08-19 02:39:52 +02:00
&subvol_partition_array_refcell,
2024-08-19 01:12:35 +02:00
);
}
));
}