From fce2150b6f2fea5cc0be667583a42ee3052f66f9 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 4 Nov 2024 00:02:18 +0300 Subject: [PATCH] basis for main page --- locales/en_US.json | 3 +- src/bin/gui/apt_update_page/mod.rs | 33 ++++++++----- src/bin/gui/apt_update_page/process.rs | 27 +++++++++++ src/bin/gui/build_ui/mod.rs | 64 +++++++++++++++++++++--- src/bin/gui/flatpak_update_page/mod.rs | 35 ++++++++------ src/bin/gui/main.rs | 1 + src/bin/gui/main_update_page/mod.rs | 67 ++++++++++++++++++++++++++ 7 files changed, 196 insertions(+), 34 deletions(-) create mode 100644 src/bin/gui/main_update_page/mod.rs diff --git a/locales/en_US.json b/locales/en_US.json index 34c0939..07c0776 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -168,5 +168,6 @@ "retry_interval_labal_label": "Automatically Check for updates", "retry_interval_spinrow_title": "Automatic Check Interval", "retry_interval_spinrow_subtitle": "In Hours", - "progress_bar_circle_center_text": "Percent %" + "progress_bar_circle_center_text": "Percent %", + "main_update_page_title": "Main Updates Page" } \ No newline at end of file diff --git a/src/bin/gui/apt_update_page/mod.rs b/src/bin/gui/apt_update_page/mod.rs index 05a8671..5cbb5d2 100644 --- a/src/bin/gui/apt_update_page/mod.rs +++ b/src/bin/gui/apt_update_page/mod.rs @@ -61,10 +61,13 @@ pub struct AptPackageSocket { } pub fn apt_update_page( window: adw::ApplicationWindow, + update_button: &Rc>, + flatpak_update_button: &Rc>, retry_signal_action: &SimpleAction, flatpak_retry_signal_action: &SimpleAction, theme_changed_action: &SimpleAction, flatpak_ran_once: Rc>, + initiated_by_main: Rc>, update_sys_tray: &SimpleAction, apt_update_count: &Rc>, flatpak_update_count: &Rc>, @@ -180,8 +183,8 @@ pub fn apt_update_page( .search_delay(500) .margin_top(15) .margin_bottom(15) - .margin_end(30) - .margin_start(30) + .margin_end(15) + .margin_start(15) .build(); searchbar.add_css_class("rounded-all-25"); @@ -349,16 +352,16 @@ pub fn apt_update_page( } )); - let update_button = Button::builder() - .halign(Align::End) - .valign(Align::Center) - .hexpand(false) - .sensitive(false) - .margin_start(10) - .margin_end(30) - .margin_bottom(15) - .label(t!("update_button_label")) - .build(); + let update_button = update_button.borrow().clone(); + + update_button.set_halign(Align::End); + update_button.set_valign(Align::Center); + update_button.set_hexpand(false); + update_button.set_sensitive(false); + update_button.set_margin_start(10); + update_button.set_margin_end(30); + update_button.set_margin_bottom(15); + update_button.set_label(&t!("update_button_label")); update_button.add_css_class("destructive-action"); update_button.connect_clicked(clone!( @@ -370,11 +373,17 @@ pub fn apt_update_page( excluded_updates_vec, #[strong] theme_changed_action, + #[strong] + flatpak_update_button, + #[strong] + initiated_by_main, move |_| { process::apt_process_update( &excluded_updates_vec.borrow(), window, &retry_signal_action, + &flatpak_update_button.borrow(), + initiated_by_main.clone(), &theme_changed_action, ); } diff --git a/src/bin/gui/apt_update_page/process.rs b/src/bin/gui/apt_update_page/process.rs index 4019d4c..dc8306f 100644 --- a/src/bin/gui/apt_update_page/process.rs +++ b/src/bin/gui/apt_update_page/process.rs @@ -63,6 +63,8 @@ pub fn apt_process_update( excluded_updates_vec: &Vec, window: adw::ApplicationWindow, retry_signal_action: &SimpleAction, + flatpak_update_button: &Button, + initiated_by_main: Rc>, theme_changed_action: &SimpleAction, ) { let excluded_updates_alert_dialog = adw::MessageDialog::builder() @@ -100,10 +102,16 @@ pub fn apt_process_update( excluded_updates_vec, #[strong] theme_changed_action, + #[strong] + initiated_by_main, + #[strong] + flatpak_update_button, move |_, _| apt_confirm_window( &excluded_updates_vec, window, &retry_signal_action, + &flatpak_update_button, + initiated_by_main.clone(), &theme_changed_action ) )); @@ -123,6 +131,8 @@ fn apt_confirm_window( excluded_updates_vec: &Vec, window: adw::ApplicationWindow, retry_signal_action: &SimpleAction, + flatpak_update_button: &Button, + initiated_by_main: Rc>, theme_changed_action: &SimpleAction, ) { let to_be_removed_packages_vec: Rc>> = Rc::new(RefCell::new(Vec::new())); @@ -323,9 +333,15 @@ fn apt_confirm_window( apt_confirm_dialog, #[strong] theme_changed_action, + #[strong] + flatpak_update_button, + #[strong] + initiated_by_main, move |_, _| { let retry_signal_action0 = retry_signal_action.clone(); let theme_changed_action0 = theme_changed_action.clone(); + let flatpak_update_button0 = flatpak_update_button.clone(); + let initiated_by_main0 = initiated_by_main.clone(); apt_confirm_dialog .clone() .choose(None::<&gio::Cancellable>, move |choice| { @@ -333,6 +349,8 @@ fn apt_confirm_window( apt_full_upgrade_from_socket( window, &retry_signal_action0, + &flatpak_update_button0, + initiated_by_main0, &theme_changed_action0, ); } @@ -406,6 +424,8 @@ fn apt_confirm_window( fn apt_full_upgrade_from_socket( window: adw::ApplicationWindow, retry_signal_action: &SimpleAction, + flatpak_update_button: &Button, + initiated_by_main: Rc>, theme_changed_action: &SimpleAction, ) { let (upgrade_percent_sender, upgrade_percent_receiver) = async_channel::unbounded::(); @@ -646,6 +666,8 @@ fn apt_full_upgrade_from_socket( )); let retry_signal_action0 = retry_signal_action.clone(); + let flatpak_update_button0 = flatpak_update_button.clone(); + let initiated_by_main_clone0 = initiated_by_main.clone(); apt_upgrade_log_button.connect_clicked(move |_| { let _ = Command::new("xdg-open") @@ -657,6 +679,11 @@ fn apt_full_upgrade_from_socket( match choice.as_str() { "apt_upgrade_dialog_ok" => { retry_signal_action0.activate(None); + let mut initiated_by_main_borrow = initiated_by_main_clone0.borrow_mut(); + if *initiated_by_main_borrow == true { + flatpak_update_button0.emit_clicked(); + *initiated_by_main_borrow = false; + } } _ => {} } diff --git a/src/bin/gui/build_ui/mod.rs b/src/bin/gui/build_ui/mod.rs index 23aa4b0..45d30eb 100644 --- a/src/bin/gui/build_ui/mod.rs +++ b/src/bin/gui/build_ui/mod.rs @@ -3,10 +3,11 @@ use crate::apt_update_page; use crate::config::{APP_GITHUB, APP_ICON, APP_ID, VERSION}; use crate::flatpak_manage_page::flatpak_manage_page; use crate::flatpak_update_page; +use crate::main_update_page::main_update_page; use adw::prelude::*; use adw::*; use gtk::glib::{clone, MainContext}; -use gtk::{License, WindowControls}; +use gtk::License; use ksni; use std::cell::RefCell; use std::process::Command; @@ -304,10 +305,12 @@ pub fn build_ui(app: &Application) { .bottom_bar_style(ToolbarStyle::Flat) .build(); - window_adw_view_switcher_sidebar_toolbar.add_top_bar(&HeaderBar::builder() - .title_widget(&WindowTitle::builder().title(t!("application_name")).build()) - .show_title(true) - .build()); + window_adw_view_switcher_sidebar_toolbar.add_top_bar( + &HeaderBar::builder() + .title_widget(&WindowTitle::builder().title(t!("application_name")).build()) + .show_title(true) + .build(), + ); let window_content_page_split_view = adw::OverlaySplitView::builder() .content(&window_toolbar) @@ -466,6 +469,12 @@ pub fn build_ui(app: &Application) { } } )); + + // Update buttons + + let apt_update_button = Rc::new(RefCell::new(gtk::Button::new())); + let flatpak_update_button = Rc::new(RefCell::new(gtk::Button::new())); + // Flatpak Update Page let flatpak_retry_signal_action = gio::SimpleAction::new("retry", None); @@ -476,6 +485,8 @@ pub fn build_ui(app: &Application) { #[weak] window, #[strong] + flatpak_update_button, + #[strong] flatpak_retry_signal_action, #[strong] flatpak_update_view_stack_bin, @@ -488,9 +499,11 @@ pub fn build_ui(app: &Application) { #[strong] theme_changed_action, move |_, _| { + (*flatpak_update_button.borrow_mut() = gtk::Button::new()); flatpak_update_view_stack_bin.set_child(Some( &flatpak_update_page::flatpak_update_page( window, + &flatpak_update_button, &flatpak_retry_signal_action, &theme_changed_action, &update_sys_tray, @@ -505,6 +518,7 @@ pub fn build_ui(app: &Application) { let apt_retry_signal_action = gio::SimpleAction::new("retry", None); let flatpak_ran_once = Rc::new(RefCell::new(false)); + let initiated_by_main = Rc::new(RefCell::new(false)); let apt_update_view_stack_bin = Bin::builder().build(); @@ -512,12 +526,18 @@ pub fn build_ui(app: &Application) { #[strong] window, #[strong] + apt_update_button, + #[strong] + flatpak_update_button, + #[strong] flatpak_retry_signal_action, #[strong] apt_update_view_stack_bin, #[strong] flatpak_ran_once, #[strong] + initiated_by_main, + #[strong] update_sys_tray, #[strong] apt_update_count, @@ -526,12 +546,16 @@ pub fn build_ui(app: &Application) { #[strong] theme_changed_action, move |action, _| { + (*apt_update_button.borrow_mut() = gtk::Button::new()); apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page( window.clone(), + &apt_update_button, + &flatpak_update_button, &action, &flatpak_retry_signal_action, &theme_changed_action, flatpak_ran_once.clone(), + initiated_by_main.clone(), &update_sys_tray, &apt_update_count, &flatpak_update_count, @@ -541,10 +565,13 @@ pub fn build_ui(app: &Application) { apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page( window.clone(), + &apt_update_button, + &flatpak_update_button, &apt_retry_signal_action, &flatpak_retry_signal_action, &theme_changed_action, flatpak_ran_once.clone(), + initiated_by_main.clone(), &update_sys_tray, &apt_update_count, &flatpak_update_count, @@ -552,6 +579,25 @@ pub fn build_ui(app: &Application) { // Add to stack switcher + window_adw_stack.add_titled( + &main_update_page( + &apt_update_button, + &initiated_by_main, + &theme_changed_action, + ), + Some("main_update_page"), + &t!("main_update_page_title"), + ); + + let main_update_page_toggle_button = add_content_button( + &window_adw_stack, + true, + "main_update_page".to_string(), + t!("main_update_page_title").to_string(), + &null_toggle_button, + ); + window_adw_view_switcher_sidebar_box.append(&main_update_page_toggle_button); + window_adw_stack.add_titled( &apt_update_view_stack_bin, Some("apt_update_page"), @@ -560,7 +606,7 @@ pub fn build_ui(app: &Application) { let apt_update_page_toggle_button = add_content_button( &window_adw_stack, - true, + false, "apt_update_page".to_string(), t!("apt_update_page_title").to_string(), &null_toggle_button, @@ -699,8 +745,14 @@ pub fn build_ui(app: &Application) { flatpak_retry_signal_action, #[weak] window_adw_stack, + #[strong] + flatpak_ran_once, move |_| { match window_adw_stack.visible_child_name().unwrap().as_str() { + "main_update_page" => { + *flatpak_ran_once.borrow_mut() = false; + apt_retry_signal_action.activate(None); + } "apt_update_page" => apt_retry_signal_action.activate(None), "apt_manage_page" => apt_retry_signal_action.activate(None), "flatpak_update_page" => flatpak_retry_signal_action.activate(None), diff --git a/src/bin/gui/flatpak_update_page/mod.rs b/src/bin/gui/flatpak_update_page/mod.rs index 970d6fd..928c6bb 100644 --- a/src/bin/gui/flatpak_update_page/mod.rs +++ b/src/bin/gui/flatpak_update_page/mod.rs @@ -27,6 +27,7 @@ pub struct FlatpakRefStruct { } pub fn flatpak_update_page( window: adw::ApplicationWindow, + update_button: &Rc>, retry_signal_action: &SimpleAction, theme_changed_action: &SimpleAction, update_sys_tray: &SimpleAction, @@ -162,8 +163,8 @@ pub fn flatpak_update_page( .search_delay(500) .margin_top(15) .margin_bottom(15) - .margin_end(30) - .margin_start(30) + .margin_end(15) + .margin_start(15) .build(); searchbar.add_css_class("rounded-all-25"); @@ -312,16 +313,16 @@ pub fn flatpak_update_page( } )); - let update_button = Button::builder() - .halign(Align::End) - .valign(Align::Center) - .sensitive(false) - .hexpand(false) - .margin_start(10) - .margin_end(30) - .margin_bottom(15) - .label(t!("update_button_label")) - .build(); + let update_button = update_button.borrow().clone(); + + update_button.set_halign(Align::End); + update_button.set_valign(Align::Center); + update_button.set_hexpand(false); + update_button.set_sensitive(false); + update_button.set_margin_start(10); + update_button.set_margin_end(30); + update_button.set_margin_bottom(15); + update_button.set_label(&t!("update_button_label")); update_button.add_css_class("destructive-action"); let system_refs_for_upgrade_vec_all_clone0 = &system_refs_for_upgrade_vec_all.clone(); @@ -354,9 +355,6 @@ pub fn flatpak_update_page( } )); - bottom_bar.append(&select_button); - bottom_bar.append(&update_button); - let appstream_sync_percent_server_context = MainContext::default(); // The main loop executes the asynchronous block appstream_sync_percent_server_context.spawn_local(clone!( @@ -389,6 +387,10 @@ pub fn flatpak_update_page( #[strong] viewport_bin, #[strong] + update_button, + #[strong] + select_button, + #[strong] packages_viewport, #[strong] update_sys_tray, @@ -492,6 +494,9 @@ pub fn flatpak_update_page( } )); + bottom_bar.append(&select_button); + bottom_bar.append(&update_button); + main_box.append(&searchbar); main_box.append(&viewport_bin); main_box.append(&bottom_bar); diff --git a/src/bin/gui/main.rs b/src/bin/gui/main.rs index 3756ea0..f3df36f 100644 --- a/src/bin/gui/main.rs +++ b/src/bin/gui/main.rs @@ -6,6 +6,7 @@ mod config; mod flatpak_manage_page; mod flatpak_ref_row; mod flatpak_update_page; +mod main_update_page; use crate::config::APP_ID; use adw::prelude::*; diff --git a/src/bin/gui/main_update_page/mod.rs b/src/bin/gui/main_update_page/mod.rs new file mode 100644 index 0000000..43f0946 --- /dev/null +++ b/src/bin/gui/main_update_page/mod.rs @@ -0,0 +1,67 @@ +use adw::gio::SimpleAction; +use adw::prelude::*; +use gtk::glib::*; +use gtk::*; +use std::cell::RefCell; +use std::rc::Rc; + +pub fn main_update_page( + apt_update_button: &Rc>, + initiated_by_main: &Rc>, + theme_changed_action: &gio::SimpleAction, +) -> gtk::Box { + let main_box = Box::builder() + .hexpand(true) + .vexpand(true) + .orientation(Orientation::Vertical) + .build(); + + let bottom_icon = gtk::Image::builder() + .pixel_size(128) + .halign(Align::Center) + .hexpand(true) + .icon_name("tux-symbolic") + .margin_start(10) + .margin_end(10) + .margin_bottom(20) + .margin_top(20) + .build(); + + let update_badge_box = gtk::Box::builder() + .hexpand(true) + .vexpand(true) + .orientation(Orientation::Vertical) + .build(); + + let bottom_bar = Box::builder().valign(Align::End).build(); + + let update_button = Button::builder() + .halign(Align::End) + .valign(Align::Center) + .hexpand(true) + .margin_start(10) + .margin_end(30) + .margin_bottom(15) + .label(t!("update_button_label")) + .build(); + update_button.add_css_class("destructive-action"); + + update_button.connect_clicked(clone!( + #[strong] + initiated_by_main, + #[strong] + apt_update_button, + move |_| { + *initiated_by_main.borrow_mut() = true; + apt_update_button.borrow().emit_clicked(); + } + )); + + bottom_bar.append(&update_button); + + main_box.append(&update_badge_box); + main_box.append(&bottom_icon); + main_box.append(&bottom_bar); + + main_box +}