From 0cae3cdf9fa733e7047b38acbdf6a5418562990a Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Thu, 11 Jul 2024 06:09:06 +0300 Subject: [PATCH] handle removals with warnings --- .idea/workspace.xml | 6 +-- src/bin/gui/apt_package_row/imp.rs | 1 - src/bin/gui/apt_update_page/mod.rs | 5 +- src/bin/gui/apt_update_page/process.rs | 64 ++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 04a3df0..04ab7f9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -9,11 +9,9 @@ - - + - diff --git a/src/bin/gui/apt_package_row/imp.rs b/src/bin/gui/apt_package_row/imp.rs index 00230ca..6968bb2 100644 --- a/src/bin/gui/apt_package_row/imp.rs +++ b/src/bin/gui/apt_package_row/imp.rs @@ -423,7 +423,6 @@ fn description_stack_page(package_description: &str) -> gtk::Box { .margin_start(15) .margin_end(15) .editable(false) - .buffer(&description_text_buffer) .build(); description_content_box.append(&description_text_view); description_content_box diff --git a/src/bin/gui/apt_update_page/mod.rs b/src/bin/gui/apt_update_page/mod.rs index 721a4b3..ca5be7f 100644 --- a/src/bin/gui/apt_update_page/mod.rs +++ b/src/bin/gui/apt_update_page/mod.rs @@ -146,7 +146,6 @@ pub fn apt_update_page( .transient_for(&window) .extra_child(&apt_update_dialog_child_box) .heading(t!("apt_update_dialog_heading")) - .hide_on_close(true) .width_request(500) .build(); @@ -242,7 +241,8 @@ pub fn apt_update_page( let mut upgradeable_iter = upgradable_cache.get_changes(false).peekable(); while let Some(pkg) = upgradeable_iter.next() { - let candidate_version_pkg = pkg.candidate().unwrap(); + if !pkg.marked_delete() { + let candidate_version_pkg = pkg.candidate().unwrap(); let package_struct = AptPackageSocket { name: pkg.name().to_string(), arch: pkg.arch().to_string(), @@ -265,6 +265,7 @@ pub fn apt_update_page( is_last: upgradeable_iter.peek().is_none() }; get_upgradable_sender.send_blocking(package_struct).unwrap() + } } }); apt_update_dialog.close(); diff --git a/src/bin/gui/apt_update_page/process.rs b/src/bin/gui/apt_update_page/process.rs index 3f5f12c..f42febd 100644 --- a/src/bin/gui/apt_update_page/process.rs +++ b/src/bin/gui/apt_update_page/process.rs @@ -13,6 +13,8 @@ use serde_json::Value; use std::path::Path; use std::process::Command; use std::{fs::*, thread}; +use std::cell::RefCell; +use std::rc::Rc; use tokio::runtime::Runtime; struct AptChangesInfo { @@ -108,6 +110,7 @@ fn apt_confirm_window( window: adw::ApplicationWindow, retry_signal_action: &SimpleAction, ) { + let to_be_removed_packages_vec: Rc>> = Rc::new(RefCell::new(Vec::new())); // Emulate Apt Full Upgrade to get transaction info let mut apt_changes_struct = AptChangesInfo { package_count_upgrade: 0, @@ -133,6 +136,7 @@ fn apt_confirm_window( pkg.mark_install(true, false); } else if change.marked_delete() { pkg.mark_delete(false); + to_be_removed_packages_vec.borrow_mut().push(pkg.name().to_owned()); } pkg.protect(); } @@ -263,6 +267,7 @@ fn apt_confirm_window( ); apt_confirm_dialog.set_default_response(Some("apt_confirm_dialog_confirm")); + apt_confirm_dialog.set_close_response("apt_confirm_dialog_cancel"); if !excluded_updates_vec.is_empty() { let exclusions_array = Exclusions { @@ -285,13 +290,67 @@ fn apt_confirm_window( .expect("Failed to write to json file"); } - let retry_signal_action0 = retry_signal_action.clone(); + let apt_confirm_start_signal_action = gio::SimpleAction::new("apt_confirm_start", None); - apt_confirm_dialog.choose(None::<&gio::Cancellable>, move |choice| { + apt_confirm_start_signal_action.connect_activate(clone!(@weak window, @strong retry_signal_action, @strong apt_confirm_dialog => move |_, _| { + let retry_signal_action0 = retry_signal_action.clone(); + apt_confirm_dialog.clone().choose(None::<&gio::Cancellable>, move |choice| { if choice == "apt_confirm_dialog_confirm" { apt_full_upgrade_from_socket(window, &retry_signal_action0); } }); + })); + + let to_be_removed_packages_borrow = to_be_removed_packages_vec.borrow(); + if to_be_removed_packages_borrow.is_empty() { + apt_confirm_start_signal_action.activate(None); + } else { + let apt_remove_confirm_text_buffer = gtk::TextBuffer::builder() + .text(to_be_removed_packages_borrow.iter().map(|x| x.to_string() + "\n").collect::() + "\n") + .build(); + + let description_text_view = gtk::TextView::builder() + .buffer(&apt_remove_confirm_text_buffer) + .hexpand(true) + .vexpand(true) + .margin_top(15) + .margin_bottom(15) + .margin_start(15) + .margin_end(15) + .editable(false) + .build(); + + let apt_remove_confirm_dialog = adw::MessageDialog::builder() + .transient_for(&window) + .heading(t!("apt_remove_confirm_dialog_heading")) + .body(t!("apt_remove_confirm_dialog_body")) + .extra_child(&description_text_view) + .build(); + + apt_remove_confirm_dialog.add_response( + "apt_remove_confirm_dialog_cancel", + &t!("apt_remove_confirm_dialog_cancel_label").to_string(), + ); + + apt_remove_confirm_dialog.add_response( + "apt_remove_confirm_dialog_confirm", + &t!("apt_remove_confirm_dialog_confirm_label").to_string(), + ); + + apt_remove_confirm_dialog.set_response_appearance( + "apt_remove_confirm_dialog_confirm", + adw::ResponseAppearance::Destructive, + ); + + apt_remove_confirm_dialog.set_default_response(Some("apt_remove_confirm_dialog_confirm")); + apt_remove_confirm_dialog.set_close_response("apt_remove_confirm_dialog_cancel"); + + apt_remove_confirm_dialog.choose(None::<&gio::Cancellable>, move |choice| { + if choice == "apt_remove_confirm_dialog_confirm" { + apt_confirm_start_signal_action.activate(None); + } + }); + } } fn apt_full_upgrade_from_socket( @@ -373,7 +432,6 @@ fn apt_full_upgrade_from_socket( .transient_for(&window) .extra_child(&apt_upgrade_dialog_child_box) .heading(t!("apt_upgrade_dialog_heading")) - .hide_on_close(true) .width_request(500) .build();