turn automatic device data, into safe struct
This commit is contained in:
parent
53271d1f16
commit
0f2a7eb5fa
@ -7,6 +7,9 @@ use glib::{clone, closure_local};
|
||||
|
||||
pub fn automatic_partitioning_page(
|
||||
main_carousel: &adw::Carousel,
|
||||
partition_method_type_buffer: >k::TextBuffer,
|
||||
partition_method_automatic_target_buffer: >k::TextBuffer,
|
||||
partition_method_automatic_luks_buffer: >k::TextBuffer,
|
||||
language_changed_action: &gio::SimpleAction
|
||||
) {
|
||||
let automatic_partitioning_page = installer_stack_page::InstallerStackPage::new();
|
||||
@ -62,6 +65,135 @@ pub fn automatic_partitioning_page(
|
||||
|
||||
devices_selection_expander_row.add_row(&devices_selection_expander_row_viewport);
|
||||
|
||||
let partition_method_automatic_disk_error_label = gtk::Label::builder()
|
||||
.name("status:no_disk_specified,")
|
||||
.halign(gtk::Align::Start)
|
||||
.valign(gtk::Align::End)
|
||||
.vexpand(true)
|
||||
.build();
|
||||
partition_method_automatic_disk_error_label.add_css_class("small_error_text");
|
||||
|
||||
let partition_method_automatic_luks_error_label = gtk::Label::builder()
|
||||
.name("status:luks_yes_but_empty,")
|
||||
.halign(gtk::Align::Start)
|
||||
.valign(gtk::Align::End)
|
||||
.vexpand(true)
|
||||
.visible(false)
|
||||
.build();
|
||||
partition_method_automatic_luks_error_label.add_css_class("small_error_text");
|
||||
|
||||
let partition_method_automatic_luks_error2_label = gtk::Label::builder()
|
||||
.name("status:luks_not_match,")
|
||||
.halign(gtk::Align::Start)
|
||||
.valign(gtk::Align::End)
|
||||
.vexpand(true)
|
||||
.visible(false)
|
||||
.build();
|
||||
partition_method_automatic_luks_error2_label.add_css_class("small_error_text");
|
||||
|
||||
//
|
||||
|
||||
let partition_method_automatic_luks_box = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
|
||||
let partition_method_automatic_luks_checkbutton = gtk::CheckButton::builder()
|
||||
.label(t!("enable_luks2_enc"))
|
||||
.margin_top(15)
|
||||
.margin_bottom(15)
|
||||
.margin_start(15)
|
||||
.margin_end(15)
|
||||
.build();
|
||||
|
||||
let partition_method_automatic_luks_listbox = gtk::ListBox::builder()
|
||||
.margin_top(15)
|
||||
.margin_bottom(15)
|
||||
.margin_start(0)
|
||||
.margin_end(15)
|
||||
.build();
|
||||
partition_method_automatic_luks_listbox.add_css_class("boxed-list");
|
||||
|
||||
let partition_method_automatic_luks_password_entry = adw::PasswordEntryRow::builder()
|
||||
.title(t!("luks2_password"))
|
||||
.hexpand(true)
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
let partition_method_automatic_luks_password_confirm_entry = adw::PasswordEntryRow::builder()
|
||||
.title(t!("luks2_password_confirm"))
|
||||
.hexpand(true)
|
||||
.sensitive(true)
|
||||
.visible(false)
|
||||
.build();
|
||||
|
||||
let _partition_method_automatic_luks_password = partition_method_automatic_luks_password_entry
|
||||
.bind_property(
|
||||
"sensitive",
|
||||
&partition_method_automatic_luks_password_confirm_entry,
|
||||
"visible",
|
||||
)
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
//
|
||||
|
||||
for device in get_block_devices() {
|
||||
let device_button = gtk::CheckButton::builder()
|
||||
.valign(gtk::Align::Center)
|
||||
.can_focus(false)
|
||||
.build();
|
||||
device_button.set_group(Some(&null_checkbutton));
|
||||
let device_row = adw::ActionRow::builder()
|
||||
.activatable_widget(&device_button)
|
||||
.title(device.block_name)
|
||||
.subtitle(device.block_size_pretty)
|
||||
.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]
|
||||
partition_method_automatic_luks_password_entry,
|
||||
#[weak]
|
||||
devices_selection_expander_row,
|
||||
#[weak]
|
||||
automatic_partitioning_page,
|
||||
#[weak]
|
||||
partition_method_automatic_disk_error_label,
|
||||
#[weak]
|
||||
partition_method_automatic_luks_error_label,
|
||||
#[weak]
|
||||
partition_method_automatic_luks_checkbutton,
|
||||
#[weak]
|
||||
partition_method_automatic_target_buffer,
|
||||
#[weak]
|
||||
partition_method_automatic_luks_buffer,
|
||||
move |_| {
|
||||
if device_button.is_active() == true {
|
||||
devices_selection_expander_row.set_title(&device.block_name);
|
||||
if device.block_size > 39000000000.0 {
|
||||
partition_method_automatic_disk_error_label.set_visible(false);
|
||||
if partition_method_automatic_luks_checkbutton.is_active() == true {
|
||||
if partition_method_automatic_luks_error_label.get_visible() {
|
||||
//
|
||||
} else {
|
||||
automatic_partitioning_page.set_next_sensitive(true);
|
||||
}
|
||||
} else {
|
||||
partition_method_automatic_target_buffer.set_text(&device.block_name);
|
||||
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
|
||||
automatic_partitioning_page.set_next_sensitive(true);
|
||||
}
|
||||
} else {
|
||||
partition_method_automatic_disk_error_label.set_visible(true);
|
||||
partition_method_automatic_disk_error_label.set_label(&t!("disk_auto_target_small"));
|
||||
automatic_partitioning_page.set_next_sensitive(false);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
//
|
||||
language_changed_action.connect_activate(
|
||||
@ -79,6 +211,18 @@ pub fn automatic_partitioning_page(
|
||||
if devices_selection_expander_row.widget_name() == "status:disk=none," {
|
||||
devices_selection_expander_row.set_title(&t!("no_drive_auto_selected"));
|
||||
}
|
||||
//
|
||||
if partition_method_automatic_disk_error_label.widget_name() == "status:no_disk_specified," {
|
||||
partition_method_automatic_disk_error_label.set_label(&t!("no_disk_specified"));
|
||||
}
|
||||
//
|
||||
if partition_method_automatic_luks_error_label.widget_name() == "status:luks_yes_but_empty," {
|
||||
partition_method_automatic_luks_error_label.set_label(&t!("luks_yes_but_empty"));
|
||||
}
|
||||
//
|
||||
if partition_method_automatic_luks_error2_label.widget_name() == "status:luks_not_match," {
|
||||
partition_method_automatic_luks_error2_label.set_label(&t!("luks_not_match"));
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -103,27 +103,64 @@ pub fn partitioning_page(
|
||||
main_carousel.append(&partitioning_carousel)
|
||||
}
|
||||
|
||||
pub fn get_block_devices() -> Result<Vec<String>, std::io::Error> {
|
||||
let command = std::process::Command::new("sudo")
|
||||
struct BlockDevice {
|
||||
pub block_name: String,
|
||||
pub block_size: f64,
|
||||
pub block_size_pretty: String
|
||||
}
|
||||
|
||||
pub fn get_block_devices() -> Vec<BlockDevice> {
|
||||
let mut block_devices = Vec::new();
|
||||
|
||||
let command = match std::process::Command::new("sudo")
|
||||
.arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh")
|
||||
.arg("get_block_devices")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let mut block_devices = Vec::new();
|
||||
.spawn() {
|
||||
Ok(t) => t,
|
||||
Err(_) => return block_devices
|
||||
};
|
||||
|
||||
match command.stdout {
|
||||
Some(t) => {
|
||||
for blockdev in std::io::BufReader::new(t).lines() {
|
||||
match blockdev {
|
||||
Ok(r) => block_devices.push(r),
|
||||
Err(e) => return Err(e)
|
||||
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)
|
||||
}
|
||||
)
|
||||
}
|
||||
Err(_) => return block_devices
|
||||
}
|
||||
}
|
||||
},
|
||||
None => return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "No stdout")),
|
||||
None => return block_devices
|
||||
};
|
||||
|
||||
Ok(block_devices)
|
||||
block_devices
|
||||
}
|
||||
|
||||
fn get_block_size(block_dev: &str) -> f64 {
|
||||
let command = match std::process::Command::new("sudo")
|
||||
.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
|
||||
};
|
||||
let size = match String::from_utf8(command.stdout) {
|
||||
Ok(t) => {
|
||||
t.trim().parse::<f64>().unwrap_or(0.0)
|
||||
}
|
||||
Err(_) => 0.0
|
||||
};
|
||||
|
||||
size
|
||||
}
|
Loading…
Reference in New Issue
Block a user