move from gtk buffer to RefCell

This commit is contained in:
Ward from fusion-voyager-3 2024-08-15 21:07:01 +03:00
parent 92b18f2139
commit 9a0786b0ec
6 changed files with 101 additions and 94 deletions

View File

@ -4,14 +4,16 @@ use gtk::{prelude::*, glib as glib};
use crate::partitioning_page::{get_block_devices};
use adw::{prelude::*};
use glib::{clone, closure_local};
use std::{rc::Rc, cell::RefCell};
pub fn automatic_partitioning_page(
main_carousel: &adw::Carousel,
partition_method_type_buffer: &gtk::TextBuffer,
partition_method_automatic_target_buffer: &gtk::TextBuffer,
partition_method_automatic_luks_buffer: &gtk::TextBuffer,
partition_method_automatic_ratio_buffer: &gtk::TextBuffer,
partition_method_automatic_seperation_buffer: &gtk::TextBuffer,
partition_method_type_refcell: &Rc<RefCell<String>>,
partition_method_automatic_target_refcell: &Rc<RefCell<String>>,
partition_method_automatic_luks_enabled_refcell: &Rc<RefCell<bool>>,
partition_method_automatic_luks_refcell: &Rc<RefCell<String>>,
partition_method_automatic_ratio_refcell: &Rc<RefCell<String>>,
partition_method_automatic_seperation_refcell: &Rc<RefCell<String>>,
language_changed_action: &gio::SimpleAction
) {
let automatic_partitioning_page = installer_stack_page::InstallerStackPage::new();
@ -183,11 +185,11 @@ pub fn automatic_partitioning_page(
#[weak]
partition_method_automatic_disk_small_error_label,
#[strong]
partition_method_automatic_target_buffer,
partition_method_automatic_target_refcell,
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);
partition_method_automatic_target_buffer.set_text(&device.block_name);
*partition_method_automatic_target_refcell.borrow_mut() = String::from(&device.block_name);
}
)
);
@ -210,7 +212,7 @@ pub fn automatic_partitioning_page(
#[weak]
automatic_partitioning_page,
#[strong]
partition_method_automatic_luks_buffer,
partition_method_automatic_luks_refcell,
move |_| {
if partition_method_automatic_luks_checkbutton.is_active() == true {
partition_method_automatic_luks_password_entry.set_sensitive(true);
@ -221,15 +223,15 @@ pub fn automatic_partitioning_page(
}
if partition_method_automatic_luks_password_entry.text().to_string().is_empty() {
partition_method_automatic_luks_error_label.set_visible(true);
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
} else {
partition_method_automatic_luks_error_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -238,10 +240,10 @@ pub fn automatic_partitioning_page(
partition_method_automatic_luks_error_label.set_visible(false);
partition_method_automatic_luks_error2_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -266,7 +268,7 @@ pub fn automatic_partitioning_page(
#[weak]
automatic_partitioning_page,
#[strong]
partition_method_automatic_luks_buffer,
partition_method_automatic_luks_refcell,
move |_| {
if partition_method_automatic_luks_checkbutton.is_active() == true {
partition_method_automatic_luks_password_entry.set_sensitive(true);
@ -277,15 +279,15 @@ pub fn automatic_partitioning_page(
}
if partition_method_automatic_luks_password_entry.text().to_string().is_empty() {
partition_method_automatic_luks_error_label.set_visible(true);
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
} else {
partition_method_automatic_luks_error_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -294,10 +296,10 @@ pub fn automatic_partitioning_page(
partition_method_automatic_luks_error_label.set_visible(false);
partition_method_automatic_luks_error2_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -322,7 +324,7 @@ pub fn automatic_partitioning_page(
#[weak]
automatic_partitioning_page,
#[strong]
partition_method_automatic_luks_buffer,
partition_method_automatic_luks_refcell,
move |_| {
if partition_method_automatic_luks_checkbutton.is_active() == true {
partition_method_automatic_luks_password_entry.set_sensitive(true);
@ -333,15 +335,15 @@ pub fn automatic_partitioning_page(
}
if partition_method_automatic_luks_password_entry.text().to_string().is_empty() {
partition_method_automatic_luks_error_label.set_visible(true);
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
} else {
partition_method_automatic_luks_error_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -350,10 +352,10 @@ pub fn automatic_partitioning_page(
partition_method_automatic_luks_error_label.set_visible(false);
partition_method_automatic_luks_error2_label.set_visible(false);
if !partition_method_automatic_disk_error_label.get_visible() && !partition_method_automatic_luks_error_label.get_visible() && !partition_method_automatic_luks_error2_label.get_visible() {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(true);
} else {
partition_method_automatic_luks_buffer.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
partition_method_automatic_luks_refcell.set_text(&partition_method_automatic_luks_password_entry.text().to_string());
automatic_partitioning_page.set_next_sensitive(false);
}
}
@ -398,23 +400,26 @@ pub fn automatic_partitioning_page(
#[weak]
main_carousel,
#[strong]
partition_method_type_buffer,
partition_method_type_refcell,
#[strong]
partition_method_automatic_target_buffer,
partition_method_automatic_target_refcell,
#[strong]
partition_method_automatic_luks_buffer,
partition_method_automatic_luks_refcell,
#[strong]
partition_method_automatic_ratio_buffer,
partition_method_automatic_luks_enabled_refcell,
#[strong]
partition_method_automatic_seperation_buffer,
partition_method_automatic_ratio_refcell,
#[strong]
partition_method_automatic_seperation_refcell,
move |_automatic_partitioning_page: installer_stack_page::InstallerStackPage|
{
//main_carousel.scroll_to(&main_carousel.nth_page(5), true)
dbg!(partition_method_type_buffer.text(&partition_method_type_buffer.bounds().0, &partition_method_type_buffer.bounds().1, true).to_string());
dbg!(partition_method_automatic_target_buffer.text(&partition_method_automatic_target_buffer.bounds().0, &partition_method_automatic_target_buffer.bounds().1, true).to_string());
dbg!(partition_method_automatic_luks_buffer.text(&partition_method_automatic_luks_buffer.bounds().0, &partition_method_automatic_luks_buffer.bounds().1, true).to_string());
dbg!(partition_method_automatic_ratio_buffer.text(&partition_method_automatic_ratio_buffer.bounds().0, &partition_method_automatic_ratio_buffer.bounds().1, true).to_string());
dbg!(partition_method_automatic_seperation_buffer.text(&partition_method_automatic_seperation_buffer.bounds().0, &partition_method_automatic_seperation_buffer.bounds().1, true).to_string());
dbg!(partition_method_type_refcell.borrow());
dbg!(partition_method_automatic_target_refcell.borrow());
dbg!(partition_method_automatic_luks_enabled_refcell.borrow());
dbg!(partition_method_automatic_luks_refcell.borrow());
dbg!(partition_method_automatic_ratio_refcell.borrow());
dbg!(partition_method_automatic_seperation_refcell.borrow());
}
)
);

View File

@ -1,4 +1,4 @@
use std::path::Path;
use std::{path::Path, rc::Rc, cell::RefCell};
use gtk::{prelude::*, glib as glib, gio as gio};
use crate::{efi_error_page, welcome_page, language_page, eula_page, keyboard_page, timezone_page, partitioning_page};
@ -49,33 +49,35 @@ pub fn build_ui(app: &adw::Application) {
_ => efi_error_page::efi_error_page(&window, &carousel)
}
let language_selection_text_buffer = gtk::TextBuffer::builder().build();
let keymap_base_selection_text_buffer = gtk::TextBuffer::builder().build();
let keymap_varient_selection_text_buffer = gtk::TextBuffer::builder().build();
let timezone_selection_text_buffer = gtk::TextBuffer::builder().build();
let partition_method_type_buffer= gtk::TextBuffer::builder().build();
let partition_method_automatic_target_buffer= gtk::TextBuffer::builder().build();
let partition_method_automatic_luks_buffer = gtk::TextBuffer::builder().build();
let partition_method_automatic_ratio_buffer= gtk::TextBuffer::builder().build();
let partition_method_automatic_seperation_buffer= gtk::TextBuffer::builder().build();
let language_selection_text_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let keymap_base_selection_text_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let keymap_varient_selection_text_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let timezone_selection_text_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let partition_method_type_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let partition_method_automatic_target_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let partition_method_automatic_luks_enabled_refcell: Rc<RefCell<bool>> = Rc::new(RefCell::new(false));
let partition_method_automatic_luks_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let partition_method_automatic_ratio_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let partition_method_automatic_seperation_refcell: Rc<RefCell<String>> = Rc::new(RefCell::default());
let language_changed_action = gio::SimpleAction::new("lang-changed", None);
language_page::language_page(&carousel, &language_selection_text_buffer, &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_buffer, &keymap_varient_selection_text_buffer, &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_buffer, &language_changed_action);
timezone_page::timezone_page(&carousel, &timezone_selection_text_refcell, &language_changed_action);
partitioning_page::partitioning_page(
&carousel,
&partition_method_type_buffer,
&partition_method_automatic_target_buffer,
&partition_method_automatic_luks_buffer,
&partition_method_automatic_ratio_buffer,
&partition_method_automatic_seperation_buffer,
&partition_method_type_refcell,
&partition_method_automatic_target_refcell,
&partition_method_automatic_luks_enabled_refcell,
&partition_method_automatic_luks_refcell,
&partition_method_automatic_ratio_refcell,
&partition_method_automatic_seperation_refcell,
&language_changed_action);
window.present()

View File

@ -3,12 +3,12 @@ use gnome_desktop::XkbInfoExt;
use gtk::{prelude::*, glib as glib, gio as gio};
use adw::{prelude::*};
use glib::{clone, closure_local};
use std::{process::Command, fs, path::Path};
use std::{process::Command, fs, path::Path, rc::Rc, cell::RefCell};
pub fn keyboard_page(
main_carousel: &adw::Carousel,
keymap_base_data_buffer: &gtk::TextBuffer,
keymap_variant_data_buffer: &gtk::TextBuffer,
keymap_base_data_refcell: &Rc<RefCell<String>>,
keymap_variant_data_refcell: &Rc<RefCell<String>>,
language_changed_action: &gio::SimpleAction
) {
let keyboard_page = installer_stack_page::InstallerStackPage::new();
@ -72,10 +72,6 @@ pub fn keyboard_page(
let keymap_list = gnome_desktop::XkbInfo::all_layouts(&xkbinfo);
let keymap_base_data_buffer_clone0 = keymap_base_data_buffer.clone();
let keymap_variant_data_buffer_clone0 = keymap_variant_data_buffer.clone();
for keymap in keymap_list.iter() {
let keymap = keymap.to_string();
let keymap_name = xkbinfo.layout_info(&keymap).unwrap().0.unwrap().to_string();
@ -106,10 +102,10 @@ pub fn keyboard_page(
keymap_checkbutton.connect_toggled(clone!(
#[weak]
keymap_checkbutton,
#[weak]
keymap_base_data_buffer_clone0,
#[weak]
keymap_variant_data_buffer_clone0,
#[strong]
keymap_base_data_refcell,
#[strong]
keymap_variant_data_refcell,
#[weak]
keyboard_page,
move |_|
@ -117,15 +113,15 @@ pub fn keyboard_page(
if keymap_checkbutton.is_active() == true {
keyboard_page.set_next_sensitive(true);
if keymap_variant.is_empty() {
keymap_base_data_buffer_clone0.set_text(&keymap_base);
*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_buffer_clone0.set_text(&keymap_base);
keymap_variant_data_buffer_clone0.set_text(&keymap_variant);
*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())

View File

@ -2,11 +2,11 @@ use crate::installer_stack_page;
use gtk::{prelude::*, glib as glib, gio as gio};
use adw::{prelude::*};
use glib::{clone, closure_local};
use std::{process::Command, env, fs, path::Path};
use std::{cell::RefCell, env, fs, path::Path, process::Command, rc::Rc};
pub fn language_page(
main_carousel: &adw::Carousel,
lang_data_buffer: &gtk::TextBuffer,
lang_data_refcell: &Rc<RefCell<String>>,
language_changed_action: &gio::SimpleAction
) {
let language_page = installer_stack_page::InstallerStackPage::new();
@ -223,8 +223,6 @@ pub fn language_page(
"pt_BR",
"pt_PT",];
let lang_data_buffer_clone0 = lang_data_buffer.clone();
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();
@ -244,15 +242,15 @@ pub fn language_page(
locale_checkbutton.connect_toggled(clone!(
#[weak]
locale_checkbutton,
#[weak]
lang_data_buffer_clone0,
#[strong]
lang_data_refcell,
#[weak]
language_page,
move |_|
{
if locale_checkbutton.is_active() == true {
language_page.set_next_sensitive(true);
lang_data_buffer_clone0.set_text(&locale);
*lang_data_refcell.borrow_mut() = String::from(&locale);
}
}
));
@ -319,16 +317,19 @@ pub fn language_page(
#[weak]
main_carousel,
#[strong]
lang_data_refcell,
#[strong]
language_changed_action,
move |_language_page: installer_stack_page::InstallerStackPage|
{
let locale = &lang_data_refcell.borrow();
//Command::new("sudo")
// .arg("localectl")
// .arg("set-locale")
// .arg("LANG=".to_owned() + &lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string() + ".UTF-8")
// .arg("LANG=".to_owned() + &locale + ".UTF-8")
// .spawn()
// .expect("locale failed to start");
rust_i18n::set_locale(&lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string());
rust_i18n::set_locale(&locale);
language_changed_action.activate(None);
main_carousel.scroll_to(&main_carousel.nth_page(2), true)
}

View File

@ -2,15 +2,17 @@ use crate::installer_stack_page;
use gtk::{prelude::*, glib as glib, gio as gio};
use glib::{clone, closure_local};
use crate::{automatic_partitioning_page};
use std::{rc::Rc, cell::RefCell};
use std::io::BufRead;
pub fn partitioning_page(
main_carousel: &adw::Carousel,
partition_method_type_buffer: &gtk::TextBuffer,
partition_method_automatic_target_buffer: &gtk::TextBuffer,
partition_method_automatic_luks_buffer: &gtk::TextBuffer,
partition_method_automatic_ratio_buffer: &gtk::TextBuffer,
partition_method_automatic_seperation_buffer: &gtk::TextBuffer,
partition_method_type_refcell: &Rc<RefCell<String>>,
partition_method_automatic_target_refcell: &Rc<RefCell<String>>,
partition_method_automatic_luks_enabled_refcell: &Rc<RefCell<bool>>,
partition_method_automatic_luks_refcell: &Rc<RefCell<String>>,
partition_method_automatic_ratio_refcell: &Rc<RefCell<String>>,
partition_method_automatic_seperation_refcell: &Rc<RefCell<String>>,
language_changed_action: &gio::SimpleAction
) {
let partitioning_page = installer_stack_page::InstallerStackPage::new();
@ -92,11 +94,12 @@ pub fn partitioning_page(
partitioning_carousel.append(&partitioning_page);
automatic_partitioning_page::automatic_partitioning_page(
&partitioning_carousel,
&partition_method_type_buffer,
&partition_method_automatic_target_buffer,
&partition_method_automatic_luks_buffer,
&partition_method_automatic_ratio_buffer,
&partition_method_automatic_seperation_buffer,
&partition_method_type_refcell,
&partition_method_automatic_target_refcell,
&partition_method_automatic_luks_enabled_refcell,
&partition_method_automatic_luks_refcell,
&partition_method_automatic_ratio_refcell,
&partition_method_automatic_seperation_refcell,
&language_changed_action);
partitioning_page.connect_closure(

View File

@ -2,12 +2,12 @@ use crate::installer_stack_page;
use gtk::{prelude::*, glib as glib, gio as gio};
use adw::{prelude::*};
use glib::{clone, closure_local};
use std::{process::Command, fs, path::Path};
use std::{process::Command, fs, path::Path, rc::Rc, cell::RefCell};
use std::io::BufRead;
pub fn timezone_page(
main_carousel: &adw::Carousel,
timezone_data_buffer: &gtk::TextBuffer,
timezone_data_refcell: &Rc<RefCell<String>>,
language_changed_action: &gio::SimpleAction
) {
let timezone_page = installer_stack_page::InstallerStackPage::new();
@ -74,8 +74,6 @@ pub fn timezone_page(
let timezone_stdout = timezone_cli.stdout.expect("could not get stdout");
let timezone_reader = std::io::BufReader::new(timezone_stdout);
let timezone_data_buffer_clone0 = timezone_data_buffer.clone();
for timezone in timezone_reader.lines() {
let timezone = timezone.unwrap();
let timezone_clone = timezone.clone();
@ -97,12 +95,12 @@ pub fn timezone_page(
#[weak]
timezone_page,
#[weak]
timezone_data_buffer,
timezone_data_refcell,
move |_|
{
if timezone_checkbutton.is_active() == true {
timezone_page.set_next_sensitive(true);
timezone_data_buffer.set_text(&timezone);
*timezone_data_refcell.borrow_mut() = String::from(&timezone);
}
}
)
@ -183,13 +181,15 @@ pub fn timezone_page(
closure_local!(
#[weak]
main_carousel,
#[strong]
timezone_data_refcell,
move |_timezone_page: installer_stack_page::InstallerStackPage|
{
let timezone_selection = timezone_data_buffer_clone0.text(&timezone_data_buffer_clone0.bounds().0, &timezone_data_buffer_clone0.bounds().1, true).to_string();
let timezone = timezone_data_refcell.borrow();
Command::new("sudo")
.arg("timedatectl")
.arg("set-timezone")
.arg(&timezone_selection)
.arg(timezone.to_owned())
.spawn()
.expect("timezone failed to start");
main_carousel.scroll_to(&main_carousel.nth_page(5), true)