From de4e48df4ec4fff58df643c1dae8b473fb524a98 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Tue, 6 Aug 2024 19:08:03 +0300 Subject: [PATCH] Add EULA PAGE --- src/build_ui.rs | 8 ++++---- src/language_page/mod.rs | 36 ++++++++++++++++++++++++++++-------- src/main.rs | 4 ++++ src/style.css | 9 +++++++++ src/welcome_page/mod.rs | 7 +++++-- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/build_ui.rs b/src/build_ui.rs index bc1e71c..9c97d7a 100644 --- a/src/build_ui.rs +++ b/src/build_ui.rs @@ -1,8 +1,6 @@ use std::path::Path; use gtk::{prelude::*, glib as glib, gio as gio}; -use crate::efi_error_page; -use crate::welcome_page; -use crate::language_page; +use crate::{efi_error_page, welcome_page, language_page, eula_page}; pub fn build_ui(app: &adw::Application) { glib::set_prgname(Some("pikaos_installer")); @@ -53,7 +51,9 @@ pub fn build_ui(app: &adw::Application) { let language_changed_action = gio::SimpleAction::new("lang-changed", None); - language_page::language_page(&window, &carousel); + language_page::language_page(&window, &carousel, &language_changed_action); + + eula_page::eula_page(&carousel, &language_changed_action); window.present() } \ No newline at end of file diff --git a/src/language_page/mod.rs b/src/language_page/mod.rs index b1ba2ed..42ff808 100644 --- a/src/language_page/mod.rs +++ b/src/language_page/mod.rs @@ -1,10 +1,14 @@ use crate::installer_stack_page; use crate::config; -use gtk::{prelude::*, glib as glib, Justification}; +use gtk::{prelude::*, glib as glib, gio as gio}; use adw::{prelude::*}; use glib::{clone, closure_local}; -use std::{process::Command, env}; -pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carousel) { +use std::{process::Command, env, fs, path::Path}; +pub fn language_page( + window: &adw::ApplicationWindow, + main_carousel: &adw::Carousel, + language_changed_action: &gio::SimpleAction +) { let language_page = installer_stack_page::InstallerStackPage::new(); language_page.set_page_title(t!("select_a_language")); language_page.set_page_subtitle(t!("please_select_locale")); @@ -55,6 +59,8 @@ pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carou .search_delay(500) .build(); + language_search_bar.add_css_class("rounded-all-25"); + let current_locale = match env::var_os("LANG") { Some(v) => v.into_string().unwrap(), None => panic!("$LANG is not set"), @@ -223,6 +229,8 @@ pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carou let lang_data_buffer = gtk::TextBuffer::builder().build(); + let lang_data_buffer_clone0 = lang_data_buffer.clone(); + for locale in locale_list.iter() { let locale = locale.to_string(); let locale_name_cli = @@ -248,14 +256,14 @@ pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carou #[weak] locale_checkbutton, #[weak] - lang_data_buffer, + lang_data_buffer_clone0, #[weak] language_page, move |_| { if locale_checkbutton.is_active() == true { language_page.set_next_sensitive(true); - lang_data_buffer.set_text(&locale); + lang_data_buffer_clone0.set_text(&locale); } } )); @@ -274,8 +282,6 @@ pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carou content_box.append(&language_search_bar); content_box.append(&language_selection_row_viewport); - let lang_data_buffer_clone = lang_data_buffer.clone(); - language_search_bar.connect_search_changed(clone!( #[weak] language_search_bar, @@ -323,9 +329,23 @@ pub fn language_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carou closure_local!( #[weak] main_carousel, + #[strong] + language_changed_action, move |language_page: installer_stack_page::InstallerStackPage| { - main_carousel.scroll_to(&main_carousel.nth_page(2), true) + if Path::new("/tmp/pika-installer-gtk4-lang.txt").exists() { + fs::remove_file("/tmp/pika-installer-gtk4-lang.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-lang.txt"); + } + fs::write("/tmp/pika-installer-gtk4-lang.txt", lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string()).expect("Unable to write file"); +//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") +// .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()); + language_changed_action.activate(None); + main_carousel.scroll_to(&main_carousel.nth_page(2), true) } ) ); diff --git a/src/main.rs b/src/main.rs index c6f96e9..8449b45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,12 @@ mod config; mod build_ui; mod efi_error_page; mod installer_stack_page; + +// + mod welcome_page; mod language_page; +mod eula_page; #[macro_use] extern crate rust_i18n; diff --git a/src/style.css b/src/style.css index 13bf2c4..65f20ef 100644 --- a/src/style.css +++ b/src/style.css @@ -34,3 +34,12 @@ background-color:green; color: white; } + +.rounded-all-25 { + border-radius: 25px; +} + +.rounded-all-25-with-padding { + border-radius: 25px; + padding: 10px; +} diff --git a/src/welcome_page/mod.rs b/src/welcome_page/mod.rs index e8b1235..acff49e 100644 --- a/src/welcome_page/mod.rs +++ b/src/welcome_page/mod.rs @@ -1,8 +1,11 @@ use crate::installer_stack_page; use crate::config; -use gtk::{prelude::*, glib as glib, Justification}; +use gtk::{prelude::*, glib as glib}; use glib::clone; -pub fn welcome_page(window: &adw::ApplicationWindow, main_carousel: &adw::Carousel) { +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"));