RR: hook partition UI to pikainstall linker

This commit is contained in:
Ward from fusion-voyager-3 2024-02-16 18:16:45 +03:00
parent 663bff897a
commit 948be55a18
5 changed files with 92 additions and 49 deletions

40
Cargo.lock generated
View File

@ -373,6 +373,12 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]] [[package]]
name = "gobject-sys" name = "gobject-sys"
version = "0.18.0" version = "0.18.0"
@ -540,6 +546,12 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "itoa"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]] [[package]]
name = "libadwaita" name = "libadwaita"
version = "0.5.3" version = "0.5.3"
@ -648,9 +660,12 @@ dependencies = [
"duct", "duct",
"fragile", "fragile",
"glib", "glib",
"glob",
"gtk4", "gtk4",
"libadwaita", "libadwaita",
"pretty-bytes", "pretty-bytes",
"serde",
"serde_json",
"time", "time",
"zoha-vte4", "zoha-vte4",
] ]
@ -760,6 +775,12 @@ dependencies = [
"semver", "semver",
] ]
[[package]]
name = "ryu"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.21" version = "1.0.21"
@ -768,24 +789,35 @@ checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.195" version = "1.0.196"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.195" version = "1.0.196"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.48", "syn 2.0.48",
] ]
[[package]]
name = "serde_json"
version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]] [[package]]
name = "serde_spanned" name = "serde_spanned"
version = "0.6.5" version = "0.6.5"

View File

@ -15,3 +15,6 @@ gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
pretty-bytes = "0.2.2" pretty-bytes = "0.2.2"
time = "0.3.31" time = "0.3.31"
vte = { version = "0.0.2", package = "zoha-vte4", features = ["v0_72"] } vte = { version = "0.0.2", package = "zoha-vte4", features = ["v0_72"] }
glob = "0.3.1"
serde_json = "1.0.113"
serde = { version = "1.0", features = ["derive"] }

View File

@ -1,3 +1,4 @@
use std::cell::RefCell;
// Use libraries // Use libraries
/// Use all gtk4 libraries (gtk4 -> gtk because cargo) /// Use all gtk4 libraries (gtk4 -> gtk because cargo)
/// Use all libadwaita libraries (libadwaita -> adw because cargo) /// Use all libadwaita libraries (libadwaita -> adw because cargo)
@ -18,8 +19,13 @@ use pretty_bytes::converter::convert;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::rc::Rc;
pub fn install_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,content_stack: &gtk::Stack, window: &adw::ApplicationWindow) { use serde::*;
use serde_json::*;
use crate::manual_partitioning::DriveMount;
pub fn install_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,content_stack: &gtk::Stack, window: &adw::ApplicationWindow, manual_drive_mount_array: &Rc<RefCell<Vec<DriveMount>>>) {
// create the bottom box for next and back buttons // create the bottom box for next and back buttons
let bottom_box = gtk::Box::builder() let bottom_box = gtk::Box::builder()
@ -117,18 +123,23 @@ pub fn install_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,conte
.build(); .build();
install_confirm_detail_keyboard.add_css_class("property"); install_confirm_detail_keyboard.add_css_class("property");
let install_confirm_detail_target = adw::ActionRow::builder()
.title("Install Target:")
.build();
if Path::new("/tmp/pika-installer-gtk4-target-manual.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-target-manual.txt").exists() {
install_confirm_detail_target.set_subtitle(&fs::read_to_string("/tmp/pika-installer-gtk4-target-manual.txt").expect("Unable to read file")); //install_confirm_detail_target.set_subtitle(&fs::read_to_string("/tmp/pika-installer-gtk4-target-manual.txt").expect("Unable to read file"));
install_confirm_details_boxed_list.append(&install_confirm_detail_language);
install_confirm_details_boxed_list.append(&install_confirm_detail_timezone);
install_confirm_details_boxed_list.append(&install_confirm_detail_keyboard);
for partitions in manual_drive_mount_array.borrow_mut().iter() {
let confirm_row = adw::ActionRow::builder()
.title("/dev/".to_owned() + &partitions.partition + " mounted on " + &partitions.mountpoint)
.build();
install_confirm_details_boxed_list.append(&confirm_row);
}
} else { } else {
let install_confirm_detail_target = adw::ActionRow::builder()
.title("Install Target:")
.build();
install_confirm_detail_target.set_subtitle(&fs::read_to_string("/tmp/pika-installer-gtk4-target-auto.txt").expect("Unable to read file")); install_confirm_detail_target.set_subtitle(&fs::read_to_string("/tmp/pika-installer-gtk4-target-auto.txt").expect("Unable to read file"));
} install_confirm_detail_target.add_css_class("property");
install_confirm_detail_target.add_css_class("property");
if Path::new("/tmp/pika-installer-gtk4-target-auto.txt").exists() {
let target_block_device = &fs::read_to_string("/tmp/pika-installer-gtk4-target-auto.txt").expect("Unable to read file"); let target_block_device = &fs::read_to_string("/tmp/pika-installer-gtk4-target-auto.txt").expect("Unable to read file");
let target_size_cli = Command::new("sudo") let target_size_cli = Command::new("sudo")
.arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh")
@ -188,13 +199,6 @@ pub fn install_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,conte
install_confirm_details_boxed_list.append(&install_confirm_p2); install_confirm_details_boxed_list.append(&install_confirm_p2);
install_confirm_details_boxed_list.append(&install_confirm_p3); install_confirm_details_boxed_list.append(&install_confirm_p3);
install_confirm_details_boxed_list.append(&install_confirm_p4); install_confirm_details_boxed_list.append(&install_confirm_p4);
} else {
// / install_confirm_selection_box appends
//// add live and install media button to install page selections
install_confirm_details_boxed_list.append(&install_confirm_detail_language);
install_confirm_details_boxed_list.append(&install_confirm_detail_timezone);
install_confirm_details_boxed_list.append(&install_confirm_detail_keyboard);
install_confirm_details_boxed_list.append(&install_confirm_detail_target);
} }
let install_confirm_button = gtk::Button::builder() let install_confirm_button = gtk::Button::builder()

View File

@ -46,16 +46,18 @@ use gtk::Orientation::Vertical;
use pretty_bytes::converter::convert; use pretty_bytes::converter::convert;
use crate::drive_mount_row::DriveMountRow; use crate::drive_mount_row::DriveMountRow;
use serde::*;
#[derive(PartialEq)] #[derive(PartialEq)]
#[derive(Debug)] #[derive(Debug)]
#[derive(Eq)] #[derive(Eq)]
#[derive(Hash)] #[derive(Hash)]
#[derive(Clone)] #[derive(Clone)]
#[derive(Serialize, Deserialize)]
pub struct DriveMount { pub struct DriveMount {
partition: String, pub partition: String,
mountpoint: String, pub mountpoint: String,
mountopt: String, pub mountopt: String,
} }
fn create_mount_row(listbox: &gtk::ListBox, manual_drive_mount_array: &Rc<RefCell<Vec<DriveMount>>>, part_table_array: &Rc<RefCell<Vec<String>>>, check_part_unique: &Rc<RefCell<bool>>) -> DriveMountRow { fn create_mount_row(listbox: &gtk::ListBox, manual_drive_mount_array: &Rc<RefCell<Vec<DriveMount>>>, part_table_array: &Rc<RefCell<Vec<String>>>, check_part_unique: &Rc<RefCell<bool>>) -> DriveMountRow {
@ -129,7 +131,7 @@ fn create_mount_row(listbox: &gtk::ListBox, manual_drive_mount_array: &Rc<RefCel
} }
//pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack: &gtk::Stack, bottom_next_button: &gtk::Button) -> (gtk::TextBuffer, gtk::TextBuffer, adw::PasswordEntryRow) { //pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack: &gtk::Stack, bottom_next_button: &gtk::Button) -> (gtk::TextBuffer, gtk::TextBuffer, adw::PasswordEntryRow) {
pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack: &gtk::Stack, bottom_next_button: &gtk::Button, manual_drive_mount_array: Rc<RefCell<Vec<DriveMount>>>) { pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack: &gtk::Stack, bottom_next_button: &gtk::Button, manual_drive_mount_array: &Rc<RefCell<Vec<DriveMount>>>) {
let part_table_array: Rc<RefCell<Vec<String>>> = Default::default(); let part_table_array: Rc<RefCell<Vec<String>>> = Default::default();
@ -309,7 +311,7 @@ pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack:
}); });
let anti_dup_partition_loop_context = MainContext::default(); let anti_dup_partition_loop_context = MainContext::default();
anti_dup_partition_loop_context.spawn_local(clone!(@weak drive_mounts_adw_listbox, @strong manual_drive_mount_array,@weak bottom_next_button, @strong check_part_unique => async move { anti_dup_partition_loop_context.spawn_local(clone!(@weak drive_mounts_adw_listbox, @weak partitioning_stack, @strong manual_drive_mount_array,@weak bottom_next_button, @strong check_part_unique => async move {
while let Ok(_state) = anti_dup_partition_receiver.recv().await { while let Ok(_state) = anti_dup_partition_receiver.recv().await {
let mut counter = drive_mounts_adw_listbox.first_child(); let mut counter = drive_mounts_adw_listbox.first_child();
@ -357,13 +359,15 @@ pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack:
} }
let manual_drive_mount_array_ref_clone = manual_drive_mount_array_ref.clone(); let manual_drive_mount_array_ref_clone = manual_drive_mount_array_ref.clone();
partition_err_check(&partition_method_manual_warn_label, &partition_method_manual_error_label, manual_drive_mount_array_ref, &check_part_unique); partition_err_check(&partition_method_manual_warn_label, &partition_method_manual_error_label, manual_drive_mount_array_ref, &check_part_unique);
if manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/" {return true} else {return false}}) && manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/boot" {return true} else {return false}}) && manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/boot/efi" {return true} else {return false}}) && !partition_method_manual_error_label.is_visible() { if partitioning_stack.visible_child_name() == Some(GString::from_string_unchecked("partition_method_manual_page".into())) {
if !bottom_next_button.is_sensitive() { if manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/" {return true} else {return false}}) && manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/boot" {return true} else {return false}}) && manual_drive_mount_array_ref_clone.iter().any(|x| {if x.mountpoint == "/boot/efi" {return true} else {return false}}) && !partition_method_manual_error_label.is_visible() {
bottom_next_button.set_sensitive(true); if !bottom_next_button.is_sensitive() {
} bottom_next_button.set_sensitive(true);
} else { }
if bottom_next_button.is_sensitive() { } else {
bottom_next_button.set_sensitive(false); if bottom_next_button.is_sensitive() {
bottom_next_button.set_sensitive(false);
}
} }
} }
} }

View File

@ -8,6 +8,7 @@ use adw::*;
use glib::*; use glib::*;
use gdk::Display; use gdk::Display;
use gtk::subclass::layout_child; use gtk::subclass::layout_child;
use glob::glob;
use crate::automatic_partitioning::automatic_partitioning; use crate::automatic_partitioning::automatic_partitioning;
use crate::manual_partitioning::manual_partitioning; use crate::manual_partitioning::manual_partitioning;
@ -219,7 +220,7 @@ pub fn partitioning_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,
/// add all pages to partitioning stack /// add all pages to partitioning stack
partitioning_stack.add_titled(&partitioning_method_main_box, Some("partition_method_select_page"), "partition_method_select_page"); partitioning_stack.add_titled(&partitioning_method_main_box, Some("partition_method_select_page"), "partition_method_select_page");
let partitioning_page_automatic_partitioning = automatic_partitioning(&partitioning_stack, &bottom_next_button); let partitioning_page_automatic_partitioning = automatic_partitioning(&partitioning_stack, &bottom_next_button);
let partitioning_page_manual_partitioning= manual_partitioning(window, &partitioning_stack, &bottom_next_button, manual_drive_mount_array); let partitioning_page_manual_partitioning= manual_partitioning(window, &partitioning_stack, &bottom_next_button, &manual_drive_mount_array);
// add everything to the main box // add everything to the main box
partitioning_main_box.append(&partitioning_stack); partitioning_main_box.append(&partitioning_stack);
@ -236,10 +237,6 @@ pub fn partitioning_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,
let partition_method_automatic_luks_buffer_clone = partitioning_page_automatic_partitioning.1.clone(); let partition_method_automatic_luks_buffer_clone = partitioning_page_automatic_partitioning.1.clone();
//let partition_method_manual_target_buffer_clone = partitioning_page_manual_partitioning.0.clone();
//let partition_method_manual_luks_buffer_clone = partitioning_page_manual_partitioning.1.clone();
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| { bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("install_page") content_stack.set_visible_child_name("install_page")
})); }));
@ -249,7 +246,7 @@ pub fn partitioning_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,
bottom_next_button.set_sensitive(false); bottom_next_button.set_sensitive(false);
})); }));
bottom_next_button.connect_clicked(clone!(@weak content_stack, @weak partitioning_stack, @weak install_main_box, @weak window, @weak done_main_box => move |_| { bottom_next_button.connect_clicked(clone!(@strong manual_drive_mount_array, @weak content_stack, @weak partitioning_stack, @weak install_main_box, @weak window, @weak done_main_box => move |_| {
if Path::new("/tmp/pika-installer-gtk4-target-auto.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-target-auto.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-target-auto.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-target-auto.txt"); fs::remove_file("/tmp/pika-installer-gtk4-target-auto.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-target-auto.txt");
} }
@ -262,6 +259,10 @@ pub fn partitioning_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,
if Path::new("/tmp/pika-installer-gtk4-target-manual-luks.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-target-manual-luks.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-target-manual-luks.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-target-manual.txt"); fs::remove_file("/tmp/pika-installer-gtk4-target-manual-luks.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-target-manual.txt");
} }
for partition_file in glob("/tmp/pika-installer-gtk4-target-manual-p*").expect("Failed to read glob pattern") {
let partition_file = partition_file.unwrap();
fs::remove_file(&partition_file).expect(&partition_file.to_str().unwrap());
}
if partitioning_stack.visible_child_name() == Some(GString::from_string_unchecked("partition_method_automatic_page".into())) { if partitioning_stack.visible_child_name() == Some(GString::from_string_unchecked("partition_method_automatic_page".into())) {
fs::write("/tmp/pika-installer-gtk4-target-auto.txt", partition_method_automatic_target_buffer_clone.text(&partition_method_automatic_target_buffer_clone.bounds().0, &partition_method_automatic_target_buffer_clone.bounds().1, true).to_string()).expect("Unable to write file"); fs::write("/tmp/pika-installer-gtk4-target-auto.txt", partition_method_automatic_target_buffer_clone.text(&partition_method_automatic_target_buffer_clone.bounds().0, &partition_method_automatic_target_buffer_clone.bounds().1, true).to_string()).expect("Unable to write file");
let automatic_luks_result = partition_method_automatic_luks_buffer_clone.text(&partition_method_automatic_luks_buffer_clone.bounds().0, &partition_method_automatic_luks_buffer_clone.bounds().1, true).to_string(); let automatic_luks_result = partition_method_automatic_luks_buffer_clone.text(&partition_method_automatic_luks_buffer_clone.bounds().0, &partition_method_automatic_luks_buffer_clone.bounds().1, true).to_string();
@ -270,18 +271,17 @@ pub fn partitioning_page(done_main_box: &gtk::Box, install_main_box: &gtk::Box ,
} else { } else {
fs::write("/tmp/pika-installer-gtk4-target-automatic-luks.txt", automatic_luks_result); fs::write("/tmp/pika-installer-gtk4-target-automatic-luks.txt", automatic_luks_result);
} }
install_page(&done_main_box, &install_main_box, &content_stack, &window); install_page(&done_main_box, &install_main_box, &content_stack, &window, &manual_drive_mount_array);
content_stack.set_visible_child_name("install_page"); content_stack.set_visible_child_name("install_page");
} else { } else {
//fs::write("/tmp/pika-installer-gtk4-target-manual.txt", partition_method_manual_target_buffer_clone.text(&partition_method_manual_target_buffer_clone.bounds().0, &partition_method_manual_target_buffer_clone.bounds().1, true).to_string()).expect("Unable to write file"); fs::write("/tmp/pika-installer-gtk4-target-manual.txt", "").expect("Unable to write file");
//partition_method_manual_luks_buffer_clone.set_text(&partitioning_page_manual_partitioning.2.text().to_string()); let mut iter_count = 0;
//let manual_luks_result = partition_method_manual_luks_buffer_clone.text(&partition_method_manual_luks_buffer_clone.bounds().0, &partition_method_manual_luks_buffer_clone.bounds().1, true).to_string(); iter_count = 0;
//if manual_luks_result.is_empty() { for partitions in manual_drive_mount_array.borrow_mut().iter() {
// // fs::write("/tmp/pika-installer-gtk4-target-manual-p".to_owned() + &iter_count.to_string() + ".json", serde_json::to_string(partitions).unwrap()).expect("Unable to write file");
//} else { iter_count += 1;
// fs::write("/tmp/pika-installer-gtk4-target-manual-luks.txt", manual_luks_result); }
//} install_page(&done_main_box, &install_main_box, &content_stack, &window, &manual_drive_mount_array);
install_page(&done_main_box, &install_main_box, &content_stack, &window);
content_stack.set_visible_child_name("install_page"); content_stack.set_visible_child_name("install_page");
} }
})); }));