2024-01-14 22:31:40 +01:00
|
|
|
// Use libraries
|
|
|
|
use adw::prelude::*;
|
|
|
|
use adw::*;
|
2024-02-16 22:21:09 +01:00
|
|
|
use glib::*;
|
|
|
|
/// Use all gtk4 libraries (gtk4 -> gtk because cargo)
|
|
|
|
/// Use all libadwaita libraries (libadwaita -> adw because cargo)
|
|
|
|
use gtk::*;
|
2024-01-15 16:33:56 +01:00
|
|
|
|
2024-02-18 18:28:14 +01:00
|
|
|
use gettextrs::{gettext, LocaleCategory};
|
|
|
|
|
2024-01-20 18:48:32 +01:00
|
|
|
use std::path::Path;
|
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::save_window_size::save_window_size;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::welcome_page::welcome_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::efi_error_page::efi_error_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::language_page::language_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::eula_page::eula_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::timezone_page::timezone_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::keyboard_page::keyboard_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-02-14 16:32:01 +01:00
|
|
|
use crate::partitioning_page::partitioning_page;
|
2024-02-11 15:39:32 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
// build ui function linked to app startup above
|
|
|
|
pub fn build_ui(app: &adw::Application) {
|
|
|
|
// setup glib
|
2024-02-18 18:28:14 +01:00
|
|
|
gtk::glib::set_prgname(Some(gettext("pikaos_installer")));
|
2024-01-14 22:31:40 +01:00
|
|
|
glib::set_application_name("PikaOS Installer");
|
|
|
|
let glib_settings = gio::Settings::new("com.github.pikaos-linux.pikainstallergtk4");
|
|
|
|
|
|
|
|
// Widget Bank
|
|
|
|
|
|
|
|
let _main_box = gtk::Box::builder()
|
|
|
|
// that puts items vertically
|
|
|
|
.orientation(Orientation::Vertical)
|
|
|
|
.build();
|
2024-02-16 22:21:09 +01:00
|
|
|
|
|
|
|
let window_title_bar = adw::HeaderBar::builder().build();
|
2024-01-14 22:31:40 +01:00
|
|
|
|
|
|
|
let content_stack = gtk::Stack::builder()
|
|
|
|
.hexpand(true)
|
|
|
|
.vexpand(true)
|
2024-01-16 11:28:13 +01:00
|
|
|
.transition_type(StackTransitionType::SlideLeftRight)
|
2024-01-14 22:31:40 +01:00
|
|
|
.build();
|
2024-02-16 22:21:09 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
let content_stack_switcher = gtk::StackSwitcher::builder()
|
|
|
|
.stack(&content_stack)
|
|
|
|
.margin_top(15)
|
|
|
|
.margin_bottom(15)
|
|
|
|
.margin_start(15)
|
|
|
|
.margin_end(15)
|
2024-01-22 18:08:04 +01:00
|
|
|
.sensitive(false)
|
2024-01-14 22:31:40 +01:00
|
|
|
.build();
|
2024-02-16 22:21:09 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
// / _main_box appends
|
|
|
|
//// Add the a title bar to the _main_box
|
2024-02-16 22:21:09 +01:00
|
|
|
_main_box.append(&window_title_bar);
|
2024-01-14 22:31:40 +01:00
|
|
|
//// Add the step indicator to _main_box
|
|
|
|
_main_box.append(&content_stack_switcher);
|
|
|
|
//// Add the stack pager containing all the steps to _main_box
|
|
|
|
_main_box.append(&content_stack);
|
2024-02-17 14:52:07 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
let window = adw::ApplicationWindow::builder()
|
|
|
|
// The text on the titlebar
|
|
|
|
.title("PikaOS Installer")
|
|
|
|
// link it to the application "app"
|
|
|
|
.application(app)
|
|
|
|
// Add the box called "_main_box" to it
|
|
|
|
.content(&_main_box)
|
|
|
|
// Application icon
|
2024-01-24 20:17:19 +01:00
|
|
|
.icon_name("calamares")
|
2024-01-14 22:31:40 +01:00
|
|
|
// Get current size from glib
|
|
|
|
.default_width(glib_settings.int("window-width"))
|
|
|
|
.default_height(glib_settings.int("window-height"))
|
|
|
|
// Minimum Size/Default
|
|
|
|
.width_request(700)
|
|
|
|
.height_request(500)
|
|
|
|
// Hide window instead of destroy
|
|
|
|
.hide_on_close(true)
|
2024-01-30 15:01:47 +01:00
|
|
|
//
|
|
|
|
.deletable(false)
|
2024-01-14 22:31:40 +01:00
|
|
|
// Startup
|
|
|
|
.startup_id("pika-installer-gtk4")
|
|
|
|
// build the window
|
|
|
|
.build();
|
2024-02-16 22:21:09 +01:00
|
|
|
|
2024-01-16 21:22:32 +01:00
|
|
|
// Add welcome_page.rs as a page for content_stack
|
2024-01-20 18:48:32 +01:00
|
|
|
if Path::new("/sys/firmware/efi/efivars").exists() {
|
|
|
|
welcome_page(&window, &content_stack);
|
|
|
|
} else {
|
|
|
|
efi_error_page(&window, &content_stack);
|
|
|
|
}
|
2024-02-16 22:21:09 +01:00
|
|
|
|
2024-01-16 21:22:32 +01:00
|
|
|
// bottom_box moved per page
|
2024-02-16 22:21:09 +01:00
|
|
|
// if content_stack visible child becomes NOT content_stack, show the buttom box
|
2024-01-16 21:22:32 +01:00
|
|
|
//content_stack.connect_visible_child_notify(clone!(@weak bottom_box => move |content_stack| {
|
|
|
|
// let state = content_stack.visible_child_name().as_deref() != Some("welcome_page");
|
|
|
|
// bottom_box.set_visible(state);
|
|
|
|
// }));
|
|
|
|
|
|
|
|
// Add language_page.rs as a page for content_stack
|
|
|
|
language_page(&content_stack);
|
|
|
|
|
2024-01-17 14:50:32 +01:00
|
|
|
// Add eula_page.rs as a page for content_stack
|
|
|
|
eula_page(&content_stack);
|
|
|
|
|
2024-01-19 14:16:15 +01:00
|
|
|
// Add timezone_page.rs as a page for content_stack
|
|
|
|
timezone_page(&content_stack);
|
|
|
|
|
2024-01-17 14:18:22 +01:00
|
|
|
// Add keyboard_page.rs as a page for content_stack
|
|
|
|
keyboard_page(&content_stack);
|
|
|
|
|
2024-01-21 19:43:58 +01:00
|
|
|
// Add install_page.rs as a page for content_stack
|
|
|
|
let install_main_box = gtk::Box::builder()
|
|
|
|
.orientation(Orientation::Vertical)
|
|
|
|
.build();
|
|
|
|
|
2024-01-22 16:07:38 +01:00
|
|
|
let done_main_box = gtk::Box::builder()
|
|
|
|
.orientation(Orientation::Vertical)
|
|
|
|
.build();
|
|
|
|
|
2024-01-17 20:25:36 +01:00
|
|
|
// Add partitioning_page.rs as a page for content_stack
|
2024-02-16 22:21:09 +01:00
|
|
|
partitioning_page(&done_main_box, &install_main_box, &content_stack, &window);
|
2024-01-21 19:43:58 +01:00
|
|
|
|
|
|
|
//// Add the install_main_box as page: install_page, Give it nice title
|
|
|
|
content_stack.add_titled(&install_main_box, Some("install_page"), "Installation");
|
2024-01-17 20:25:36 +01:00
|
|
|
|
2024-01-22 16:07:38 +01:00
|
|
|
// Add done_page.rs as a page for content_stack
|
2024-01-24 18:51:29 +01:00
|
|
|
content_stack.add_titled(&done_main_box, Some("done_page"), "Done");
|
2024-01-22 16:07:38 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
// glib maximization
|
|
|
|
if glib_settings.boolean("is-maximized") == true {
|
|
|
|
window.maximize()
|
|
|
|
}
|
2024-02-16 22:21:09 +01:00
|
|
|
|
2024-01-14 22:31:40 +01:00
|
|
|
// Connect the hiding of window to the save_window_size function and window destruction
|
|
|
|
window.connect_hide(clone!(@weak window => move |_| save_window_size(&window, &glib_settings)));
|
|
|
|
window.connect_hide(clone!(@weak window => move |_| window.destroy()));
|
2024-01-16 21:22:32 +01:00
|
|
|
// bottom_box moved per page
|
|
|
|
//let content_stack_clone = content_stack.clone();
|
|
|
|
//let content_stack_clone2 = content_stack.clone();
|
|
|
|
//bottom_next_button.connect_clicked(move |_| content_stack_clone.set_visible_child(&content_stack_clone.visible_child().expect("null").next_sibling().unwrap()));
|
|
|
|
//bottom_back_button.connect_clicked(move |_| content_stack_clone2.set_visible_child(&content_stack_clone2.visible_child().expect("null").prev_sibling().unwrap()));
|
2024-01-19 12:37:40 +01:00
|
|
|
window.present();
|
2024-01-24 20:17:19 +01:00
|
|
|
}
|