diff --git a/src/bin/gui/apt_manage_page/add_dialog.rs b/src/bin/gui/apt_manage_page/add_dialog.rs index 5be5d59..fd8f116 100644 --- a/src/bin/gui/apt_manage_page/add_dialog.rs +++ b/src/bin/gui/apt_manage_page/add_dialog.rs @@ -1,403 +1,416 @@ -use crate::apt_package_row::AptPackageRow; -use adw::gio::SimpleAction; use adw::prelude::*; use apt_deb822_tools::Deb822Repository; -use regex::Regex; -use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject}; +use gtk::glib::clone; use gtk::*; -use std::cell::Ref; -use std::ops::Deref; -use pika_unixsocket_tools::pika_unixsocket_tools::*; -use rust_apt::cache::*; -use rust_apt::new_cache; -use rust_apt::records::RecordField; -use std::cell::RefCell; -use std::process::Command; -use std::rc::Rc; -use std::thread; -use tokio::runtime::Runtime; +use regex::Regex; pub fn add_dialog_fn( - window: adw::ApplicationWindow, - reload_action: &gio::SimpleAction, - apt_retry_signal_action: &gio::SimpleAction, - ) - { + window: adw::ApplicationWindow, + reload_action: &gio::SimpleAction, + apt_retry_signal_action: &gio::SimpleAction, +) { let unofficial_source_add_dialog_child_box = Box::builder() - .hexpand(true) - .orientation(Orientation::Vertical) - .build(); - - let unofficial_source_add_name_entry = gtk::Entry::builder() - .placeholder_text("WineHQ Debian") - .build(); + .hexpand(true) + .orientation(Orientation::Vertical) + .build(); - let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_name_prefrencesgroup_title")) - .build(); + let unofficial_source_add_name_entry = gtk::Entry::builder() + .placeholder_text("WineHQ Debian") + .build(); - unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry); + let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_name_prefrencesgroup_title")) + .build(); - let unofficial_source_add_uri_entry = gtk::Entry::builder() - .placeholder_text("https://dl.winehq.org/wine-builds/debian") - .build(); + unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry); - let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) - .build(); + let unofficial_source_add_uri_entry = gtk::Entry::builder() + .placeholder_text("https://dl.winehq.org/wine-builds/debian") + .build(); - unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); + let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) + .build(); - let unofficial_source_add_suites_entry = gtk::Entry::builder() - .placeholder_text("trixie bookworm sid") - .build(); + unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); - let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) - .build(); + let unofficial_source_add_suites_entry = gtk::Entry::builder() + .placeholder_text("trixie bookworm sid") + .build(); - unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); + let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) + .build(); - let unofficial_source_add_components_entry = gtk::Entry::builder() - .placeholder_text("main proprietary") - .build(); + unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); - let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_components_prefrencesgroup_title")) - .build(); + let unofficial_source_add_components_entry = gtk::Entry::builder() + .placeholder_text("main proprietary") + .build(); - unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); + let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_components_prefrencesgroup_title")) + .build(); - let unofficial_source_add_signed_entry = gtk::Entry::builder() - .sensitive(false) - .build(); + unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); - let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_signed_prefrencesgroup_title")) - .build(); - - unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry); + let unofficial_source_add_signed_entry = gtk::Entry::builder().sensitive(false).build(); - let unofficial_source_add_archs_entry = gtk::Entry::builder() - .placeholder_text("amd64 arm64 i386") - .build(); + let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_signed_prefrencesgroup_title")) + .build(); - let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_archs_prefrencesgroup_title")) - .build(); + unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry); - unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry); + let unofficial_source_add_archs_entry = gtk::Entry::builder() + .placeholder_text("amd64 arm64 i386") + .build(); - let unofficial_source_add_box2 = gtk::Box::builder() - .margin_top(10) - .orientation(Orientation::Horizontal) - .hexpand(true) - .spacing(5) - .build(); + let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_archs_prefrencesgroup_title")) + .build(); - let unofficial_source_add_is_source_label = gtk::Label::builder() - .label(t!("unofficial_source_add_is_source_label_label")) - .halign(Align::Start) - .valign(Align::Center) - .build(); - - let unofficial_source_add_is_source_switch = gtk::Switch::builder() - .halign(Align::Start) - .valign(Align::Center) - .build(); + unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry); - let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() - .halign(Align::Start) - .valign(Align::Center) - .label(t!("unofficial_source_signed_keyring_checkbutton_label")) - .active(true) - .build(); + let unofficial_source_add_box2 = gtk::Box::builder() + .margin_top(10) + .orientation(Orientation::Horizontal) + .hexpand(true) + .spacing(5) + .build(); - let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() - .halign(Align::Start) - .valign(Align::Center) - .label(t!("unofficial_source_signed_file_checkbutton_label")) - .group(&unofficial_source_signed_keyring_checkbutton) - .build(); + let unofficial_source_add_is_source_label = gtk::Label::builder() + .label(t!("unofficial_source_add_is_source_label_label")) + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_signed_url_checkbutton = gtk::CheckButton::builder() - .halign(Align::Start) - .valign(Align::Center) - .label(t!("unofficial_source_signed_url_checkbutton_label")) - .group(&unofficial_source_signed_keyring_checkbutton) - .build(); + let unofficial_source_add_is_source_switch = gtk::Switch::builder() + .halign(Align::Start) + .valign(Align::Center) + .build(); - // - let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() - .child(&unofficial_source_add_dialog_child_box) - .maximum_size(500) - .build(); + let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() + .halign(Align::Start) + .valign(Align::Center) + .label(t!("unofficial_source_signed_keyring_checkbutton_label")) + .active(true) + .build(); - let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() - .hexpand(true) - .vexpand(true) - .child(&unofficial_source_add_dialog_child_clamp) - .hscrollbar_policy(PolicyType::Never) - .build(); + let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() + .halign(Align::Start) + .valign(Align::Center) + .label(t!("unofficial_source_signed_file_checkbutton_label")) + .group(&unofficial_source_signed_keyring_checkbutton) + .build(); - let unofficial_source_add_dialog = adw::MessageDialog::builder() - .transient_for(&window) - .extra_child(&unofficial_source_add_viewport) - .heading(t!("unofficial_source_add_dialog_heading")) - .width_request(700) - .height_request(500) - .build(); + let unofficial_source_signed_url_checkbutton = gtk::CheckButton::builder() + .halign(Align::Start) + .valign(Align::Center) + .label(t!("unofficial_source_signed_url_checkbutton_label")) + .group(&unofficial_source_signed_keyring_checkbutton) + .build(); - unofficial_source_add_dialog.add_response( - "unofficial_source_add_dialog_add", - &t!("unofficial_source_add_dialog_add_label").to_string(), - ); - - unofficial_source_add_dialog.add_response( - "unofficial_source_add_dialog_cancel", - &t!("unofficial_source_add_dialog_cancel_label").to_string(), - ); + // + let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() + .child(&unofficial_source_add_dialog_child_box) + .maximum_size(500) + .build(); - unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); - - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_add_dialog_cancel", - adw::ResponseAppearance::Destructive, - ); + let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() + .hexpand(true) + .vexpand(true) + .child(&unofficial_source_add_dialog_child_clamp) + .hscrollbar_policy(PolicyType::Never) + .build(); - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_add_dialog_add", - adw::ResponseAppearance::Suggested, - ); + let unofficial_source_add_dialog = adw::MessageDialog::builder() + .transient_for(&window) + .extra_child(&unofficial_source_add_viewport) + .heading(t!("unofficial_source_add_dialog_heading")) + .width_request(700) + .height_request(500) + .build(); - // + unofficial_source_add_dialog.add_response( + "unofficial_source_add_dialog_add", + &t!("unofficial_source_add_dialog_add_label").to_string(), + ); - let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); - let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone(); - let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); - let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); - let unofficial_source_add_components_entry_clone0 = unofficial_source_add_components_entry.clone(); - let unofficial_source_add_signed_entry_clone0 = unofficial_source_add_signed_entry.clone(); - let unofficial_source_signed_keyring_checkbutton_clone0 = unofficial_source_signed_keyring_checkbutton.clone(); + unofficial_source_add_dialog.add_response( + "unofficial_source_add_dialog_cancel", + &t!("unofficial_source_add_dialog_cancel_label").to_string(), + ); - let add_button_update_state = move || { - if - !unofficial_source_add_name_entry_clone0.text().is_empty() && - !unofficial_source_add_uri_entry_clone0.text().is_empty() && - !unofficial_source_add_suites_entry_clone0.text().is_empty() && - !unofficial_source_add_components_entry_clone0.text().is_empty() - { - if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); - } else if !unofficial_source_add_signed_entry_clone0.text().is_empty() { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); - } else { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); - } + unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); + + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_add_dialog_cancel", + adw::ResponseAppearance::Destructive, + ); + + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_add_dialog_add", + adw::ResponseAppearance::Suggested, + ); + + // + + let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); + let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone(); + let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); + let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); + let unofficial_source_add_components_entry_clone0 = + unofficial_source_add_components_entry.clone(); + let unofficial_source_add_signed_entry_clone0 = unofficial_source_add_signed_entry.clone(); + let unofficial_source_signed_keyring_checkbutton_clone0 = + unofficial_source_signed_keyring_checkbutton.clone(); + + let add_button_update_state = move || { + if !unofficial_source_add_name_entry_clone0.text().is_empty() + && !unofficial_source_add_uri_entry_clone0.text().is_empty() + && !unofficial_source_add_suites_entry_clone0.text().is_empty() + && !unofficial_source_add_components_entry_clone0 + .text() + .is_empty() + { + if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", true); + } else if !unofficial_source_add_signed_entry_clone0.text().is_empty() { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", true); + } else { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", false); + } + } else { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", false); + } + }; + + // + + for entry in [ + &unofficial_source_add_name_entry, + &unofficial_source_add_uri_entry, + &unofficial_source_add_suites_entry, + &unofficial_source_add_components_entry, + &unofficial_source_add_signed_entry, + ] { + entry.connect_text_notify(clone!( + #[strong] + add_button_update_state, + move |_| { + add_button_update_state(); + } + )); + } + + // + + unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( + #[weak] + unofficial_source_add_signed_entry, + #[strong] + add_button_update_state, + move |checkbutton| { + if checkbutton.is_active() { + unofficial_source_add_signed_entry.set_sensitive(false); + unofficial_source_add_signed_entry.set_placeholder_text(Some("")); + add_button_update_state(); + } + } + )); + + unofficial_source_signed_file_checkbutton.connect_toggled(clone!( + #[weak] + unofficial_source_add_signed_entry, + #[strong] + add_button_update_state, + move |checkbutton| { + if checkbutton.is_active() { + unofficial_source_add_signed_entry.set_sensitive(true); + unofficial_source_add_signed_entry + .set_placeholder_text(Some("/etc/apt/keyrings/winehq-archive.key")); + add_button_update_state(); + } + } + )); + + unofficial_source_signed_url_checkbutton.connect_toggled(clone!( + #[weak] + unofficial_source_add_signed_entry, + #[strong] + add_button_update_state, + move |checkbutton| { + if checkbutton.is_active() { + unofficial_source_add_signed_entry.set_sensitive(true); + unofficial_source_add_signed_entry + .set_placeholder_text(Some("https://dl.winehq.org/wine-builds/winehq.key")); + add_button_update_state(); + } + } + )); + + unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); + unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); + unofficial_source_add_box2.append(&unofficial_source_signed_keyring_checkbutton); + unofficial_source_add_box2.append(&unofficial_source_signed_file_checkbutton); + unofficial_source_add_box2.append(&unofficial_source_signed_url_checkbutton); + + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_name_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); + unofficial_source_add_dialog_child_box + .append(&unofficial_source_add_components_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_archs_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_signed_prefrencesgroup); + + let reload_action_clone0 = reload_action.clone(); + let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); + + unofficial_source_add_dialog + .clone() + .choose(None::<&gio::Cancellable>, move |choice| { + match choice.as_str() { + "unofficial_source_add_dialog_add" => { + let non_alphanum_regex = Regex::new(r"[^a-zA-Z0-9]").unwrap(); + let sign_method = if unofficial_source_signed_file_checkbutton.is_active() { + 1 + } else if unofficial_source_signed_url_checkbutton.is_active() { + 2 } else { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); - } - }; - - // - - for entry in [ - &unofficial_source_add_name_entry, - &unofficial_source_add_uri_entry, - &unofficial_source_add_suites_entry, - &unofficial_source_add_components_entry, - &unofficial_source_add_signed_entry, - ] { - entry.connect_text_notify(clone!( - #[strong] - add_button_update_state, - move |_| - { - add_button_update_state(); - } - ) - ); - } - - // - - unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( - #[weak] - unofficial_source_add_signed_entry, - #[strong] - add_button_update_state, - move |checkbutton| - { - if checkbutton.is_active() { - unofficial_source_add_signed_entry.set_sensitive(false); - unofficial_source_add_signed_entry.set_placeholder_text(Some("")); - add_button_update_state(); - } - } - ) - ); - - unofficial_source_signed_file_checkbutton.connect_toggled(clone!( - #[weak] - unofficial_source_add_signed_entry, - #[strong] - add_button_update_state, - move |checkbutton| - { - if checkbutton.is_active() { - unofficial_source_add_signed_entry.set_sensitive(true); - unofficial_source_add_signed_entry.set_placeholder_text(Some("/etc/apt/keyrings/winehq-archive.key")); - add_button_update_state(); - } - } - ) - ); - - unofficial_source_signed_url_checkbutton.connect_toggled(clone!( - #[weak] - unofficial_source_add_signed_entry, - #[strong] - add_button_update_state, - move |checkbutton| - { - if checkbutton.is_active() { - unofficial_source_add_signed_entry.set_sensitive(true); - unofficial_source_add_signed_entry.set_placeholder_text(Some("https://dl.winehq.org/wine-builds/winehq.key")); - add_button_update_state(); - } - } - ) - ); - - unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); - unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); - unofficial_source_add_box2.append(&unofficial_source_signed_keyring_checkbutton); - unofficial_source_add_box2.append(&unofficial_source_signed_file_checkbutton); - unofficial_source_add_box2.append(&unofficial_source_signed_url_checkbutton); - - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_name_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_components_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_archs_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_signed_prefrencesgroup); - - let reload_action_clone0 = reload_action.clone(); - let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); - - unofficial_source_add_dialog.clone() - .choose(None::<&gio::Cancellable>, move |choice| { - match choice.as_str() { - "unofficial_source_add_dialog_add" => { - let non_alphanum_regex = Regex::new(r"[^a-zA-Z0-9]").unwrap(); - let sign_method = if unofficial_source_signed_file_checkbutton.is_active() { - 1 - } else if unofficial_source_signed_url_checkbutton.is_active() { - 2 - } else { - 0 - }; - let repo_file_name = non_alphanum_regex.replace_all(unofficial_source_add_name_entry.text().as_str(), "_").to_string().to_lowercase(); - let new_repo = Deb822Repository { - repolib_name: Some(unofficial_source_add_name_entry.text().to_string()), - filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name), - uris: Some(unofficial_source_add_uri_entry.text().to_string()), - types: if unofficial_source_add_is_source_switch.is_active() { - Some("deb deb-src".to_string()) - } else { - Some("deb".to_string()) - }, - suites: Some(unofficial_source_add_suites_entry.text().to_string()), - components: Some(unofficial_source_add_components_entry.text().to_string()), - architectures: if unofficial_source_add_archs_entry.text().is_empty() { - None - } else { - Some(unofficial_source_add_archs_entry.text().to_string()) - }, - signed_by: match sign_method { - 1 => Some(unofficial_source_add_signed_entry.text().to_string()), - 2 => Some(format!("/etc/apt/keyrings/{}.gpg.key", repo_file_name)), - _ => None - }, - ..Default::default() - }; - if sign_method == 2 { - match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) { - Ok(_) => { - match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move_with_wget", &repo_file_name, &unofficial_source_add_signed_entry.text().to_string(), &format!("/etc/apt/keyrings/{}.gpg.key", &repo_file_name)).run() { - Ok(_) => { - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - } - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - } - } - } else { - match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) { - Ok(_) => { - match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move", repo_file_name).run() { - Ok(_) => { - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - } - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() + 0 + }; + let repo_file_name = non_alphanum_regex + .replace_all(unofficial_source_add_name_entry.text().as_str(), "_") + .to_string() + .to_lowercase(); + let new_repo = Deb822Repository { + repolib_name: Some(unofficial_source_add_name_entry.text().to_string()), + filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name), + uris: Some(unofficial_source_add_uri_entry.text().to_string()), + types: if unofficial_source_add_is_source_switch.is_active() { + Some("deb deb-src".to_string()) + } else { + Some("deb".to_string()) + }, + suites: Some(unofficial_source_add_suites_entry.text().to_string()), + components: Some(unofficial_source_add_components_entry.text().to_string()), + architectures: if unofficial_source_add_archs_entry.text().is_empty() { + None + } else { + Some(unofficial_source_add_archs_entry.text().to_string()) + }, + signed_by: match sign_method { + 1 => Some(unofficial_source_add_signed_entry.text().to_string()), + 2 => Some(format!("/etc/apt/keyrings/{}.gpg.key", repo_file_name)), + _ => None, + }, + ..Default::default() + }; + if sign_method == 2 { + match Deb822Repository::write_to_file( + new_repo.clone(), + format!("/tmp/{}.sources", repo_file_name).into(), + ) { + Ok(_) => { + match duct::cmd!( + "pkexec", + "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", + "deb822_move_with_wget", + &repo_file_name, + &unofficial_source_add_signed_entry.text().to_string(), + &format!("/etc/apt/keyrings/{}.gpg.key", &repo_file_name) + ) + .run() + { + Ok(_) => { + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + Err(e) => { + let apt_src_create_error_dialog = + adw::MessageDialog::builder() .heading(t!("apt_src_create_error_dialog_heading")) .body(e.to_string()) .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); } } } - _ => {} + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + } } - }); -} \ No newline at end of file + } else { + match Deb822Repository::write_to_file( + new_repo.clone(), + format!("/tmp/{}.sources", repo_file_name).into(), + ) { + Ok(_) => { + match duct::cmd!( + "pkexec", + "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", + "deb822_move", + repo_file_name + ) + .run() + { + Ok(_) => { + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + Err(e) => { + let apt_src_create_error_dialog = + adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + } + } + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + } + } + } + _ => {} + } + }); +} diff --git a/src/bin/gui/apt_manage_page/deb822_edit_dialog.rs b/src/bin/gui/apt_manage_page/deb822_edit_dialog.rs index 857aad5..9feb8f7 100644 --- a/src/bin/gui/apt_manage_page/deb822_edit_dialog.rs +++ b/src/bin/gui/apt_manage_page/deb822_edit_dialog.rs @@ -1,21 +1,8 @@ -use crate::apt_package_row::AptPackageRow; use adw::gio::SimpleAction; use adw::prelude::*; use apt_deb822_tools::Deb822Repository; -use regex::Regex; -use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject}; +use gtk::glib::clone; use gtk::*; -use std::cell::Ref; -use std::ops::Deref; -use pika_unixsocket_tools::pika_unixsocket_tools::*; -use rust_apt::cache::*; -use rust_apt::new_cache; -use rust_apt::records::RecordField; -use std::cell::RefCell; -use std::process::Command; -use std::rc::Rc; -use std::thread; -use tokio::runtime::Runtime; use std::path::Path; pub fn deb822_edit_dialog_fn( @@ -24,398 +11,399 @@ pub fn deb822_edit_dialog_fn( reload_action: &gio::SimpleAction, apt_retry_signal_action: &SimpleAction, ) { - let repofile_path = Path::new(&deb822_repo.filepath); - let repo_file_name = repofile_path - .file_name() - .unwrap() - .to_str() - .unwrap() - .trim_end_matches(".sources") - .to_owned(); - - let unofficial_source_add_dialog_child_box = Box::builder() - .hexpand(true) - .orientation(Orientation::Vertical) - .build(); - - let unofficial_source_add_name_entry = gtk::Entry::builder() - .build(); + let repofile_path = Path::new(&deb822_repo.filepath); + let repo_file_name = repofile_path + .file_name() + .unwrap() + .to_str() + .unwrap() + .trim_end_matches(".sources") + .to_owned(); - let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_name_prefrencesgroup_title")) - .build(); + let unofficial_source_add_dialog_child_box = Box::builder() + .hexpand(true) + .orientation(Orientation::Vertical) + .build(); - unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry); + let unofficial_source_add_name_entry = gtk::Entry::builder().build(); - let unofficial_source_add_uri_entry = gtk::Entry::builder() - .build(); + let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_name_prefrencesgroup_title")) + .build(); - let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) - .build(); + unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry); - unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); + let unofficial_source_add_uri_entry = gtk::Entry::builder().build(); - let unofficial_source_add_suites_entry = gtk::Entry::builder() - .build(); + let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) + .build(); - let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) - .build(); + unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); - unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); + let unofficial_source_add_suites_entry = gtk::Entry::builder().build(); - let unofficial_source_add_components_entry = gtk::Entry::builder() - .build(); + let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) + .build(); - let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_components_prefrencesgroup_title")) - .build(); + unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); - unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); + let unofficial_source_add_components_entry = gtk::Entry::builder().build(); - let unofficial_source_add_signed_entry = gtk::Entry::builder() - .sensitive(false) - .build(); + let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_components_prefrencesgroup_title")) + .build(); - let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_signed_prefrencesgroup_title")) - .build(); - - unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry); + unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); - let unofficial_source_add_archs_entry = gtk::Entry::builder() - .build(); + let unofficial_source_add_signed_entry = gtk::Entry::builder().sensitive(false).build(); - let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_archs_prefrencesgroup_title")) - .build(); + let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_signed_prefrencesgroup_title")) + .build(); - unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry); + unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry); - let unofficial_source_add_box2 = gtk::Box::builder() - .margin_top(10) - .orientation(Orientation::Horizontal) - .hexpand(true) - .spacing(5) - .build(); + let unofficial_source_add_archs_entry = gtk::Entry::builder().build(); - let unofficial_source_add_is_source_label = gtk::Label::builder() - .label(t!("unofficial_source_add_is_source_label_label")) - .halign(Align::Start) - .valign(Align::Center) - .build(); + let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_archs_prefrencesgroup_title")) + .build(); + unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry); - let unofficial_source_add_is_enabled_label = gtk::Label::builder() - .label(t!("unofficial_source_add_is_enabled_label_label")) - .halign(Align::Start) - .valign(Align::Center) - .build(); - - let unofficial_source_add_is_source_switch = gtk::Switch::builder() - .halign(Align::Start) - .valign(Align::Center) - .build(); + let unofficial_source_add_box2 = gtk::Box::builder() + .margin_top(10) + .orientation(Orientation::Horizontal) + .hexpand(true) + .spacing(5) + .build(); - let unofficial_source_add_is_enabled_switch = gtk::Switch::builder() - .halign(Align::Start) - .valign(Align::Center) - .build(); + let unofficial_source_add_is_source_label = gtk::Label::builder() + .label(t!("unofficial_source_add_is_source_label_label")) + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() - .halign(Align::Start) - .valign(Align::Center) - .label(t!("unofficial_source_signed_keyring_checkbutton_label")) - .active(true) - .build(); + let unofficial_source_add_is_enabled_label = gtk::Label::builder() + .label(t!("unofficial_source_add_is_enabled_label_label")) + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() - .halign(Align::Start) - .valign(Align::Center) - .label(t!("unofficial_source_signed_file_checkbutton_label")) - .group(&unofficial_source_signed_keyring_checkbutton) - .build(); - // - let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() - .child(&unofficial_source_add_dialog_child_box) - .maximum_size(500) - .build(); + let unofficial_source_add_is_source_switch = gtk::Switch::builder() + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() - .hexpand(true) - .vexpand(true) - .child(&unofficial_source_add_dialog_child_clamp) - .hscrollbar_policy(PolicyType::Never) - .build(); + let unofficial_source_add_is_enabled_switch = gtk::Switch::builder() + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_add_dialog = adw::MessageDialog::builder() - .transient_for(&window) - .extra_child(&unofficial_source_add_viewport) - .heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) - .width_request(700) - .height_request(500) - .build(); + let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() + .halign(Align::Start) + .valign(Align::Center) + .label(t!("unofficial_source_signed_keyring_checkbutton_label")) + .active(true) + .build(); - unofficial_source_add_dialog.add_response( - "unofficial_source_edit_dialog_edit", - &t!("unofficial_source_edit_dialog_add_edit").to_string(), - ); - - unofficial_source_add_dialog.add_response( - "unofficial_source_add_dialog_cancel", - &t!("unofficial_source_add_dialog_cancel_label").to_string(), - ); + let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() + .halign(Align::Start) + .valign(Align::Center) + .label(t!("unofficial_source_signed_file_checkbutton_label")) + .group(&unofficial_source_signed_keyring_checkbutton) + .build(); + // + let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() + .child(&unofficial_source_add_dialog_child_box) + .maximum_size(500) + .build(); - unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); + let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() + .hexpand(true) + .vexpand(true) + .child(&unofficial_source_add_dialog_child_clamp) + .hscrollbar_policy(PolicyType::Never) + .build(); - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_add_dialog_cancel", - adw::ResponseAppearance::Destructive, - ); + let unofficial_source_add_dialog = adw::MessageDialog::builder() + .transient_for(&window) + .extra_child(&unofficial_source_add_viewport) + .heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) + .width_request(700) + .height_request(500) + .build(); - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_edit_dialog_edit", - adw::ResponseAppearance::Suggested, - ); + unofficial_source_add_dialog.add_response( + "unofficial_source_edit_dialog_edit", + &t!("unofficial_source_edit_dialog_add_edit").to_string(), + ); - // + unofficial_source_add_dialog.add_response( + "unofficial_source_add_dialog_cancel", + &t!("unofficial_source_add_dialog_cancel_label").to_string(), + ); - let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); - let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone(); - let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); - let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); - let unofficial_source_add_components_entry_clone0 = unofficial_source_add_components_entry.clone(); - let unofficial_source_add_signed_entry_clone0 = unofficial_source_add_signed_entry.clone(); - let unofficial_source_signed_keyring_checkbutton_clone0 = unofficial_source_signed_keyring_checkbutton.clone(); + unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); - let add_button_update_state = move || { - if - !unofficial_source_add_name_entry_clone0.text().is_empty() && - !unofficial_source_add_uri_entry_clone0.text().is_empty() && - !unofficial_source_add_suites_entry_clone0.text().is_empty() && - !unofficial_source_add_components_entry_clone0.text().is_empty() - { - if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); - } else if !unofficial_source_add_signed_entry_clone0.text().is_empty() { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); - } else { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); - } + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_add_dialog_cancel", + adw::ResponseAppearance::Destructive, + ); + + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_edit_dialog_edit", + adw::ResponseAppearance::Suggested, + ); + + // + + let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); + let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone(); + let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); + let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); + let unofficial_source_add_components_entry_clone0 = + unofficial_source_add_components_entry.clone(); + let unofficial_source_add_signed_entry_clone0 = unofficial_source_add_signed_entry.clone(); + let unofficial_source_signed_keyring_checkbutton_clone0 = + unofficial_source_signed_keyring_checkbutton.clone(); + + let add_button_update_state = move || { + if !unofficial_source_add_name_entry_clone0.text().is_empty() + && !unofficial_source_add_uri_entry_clone0.text().is_empty() + && !unofficial_source_add_suites_entry_clone0.text().is_empty() + && !unofficial_source_add_components_entry_clone0 + .text() + .is_empty() + { + if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", true); + } else if !unofficial_source_add_signed_entry_clone0.text().is_empty() { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", true); + } else { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", false); + } + } else { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", false); + } + }; + + // + + for entry in [ + &unofficial_source_add_name_entry, + &unofficial_source_add_uri_entry, + &unofficial_source_add_suites_entry, + &unofficial_source_add_components_entry, + &unofficial_source_add_signed_entry, + ] { + entry.connect_text_notify(clone!( + #[strong] + add_button_update_state, + move |_| { + add_button_update_state(); + } + )); + } + + // + + unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( + #[weak] + unofficial_source_add_signed_entry, + #[strong] + add_button_update_state, + move |checkbutton| { + if checkbutton.is_active() { + unofficial_source_add_signed_entry.set_sensitive(false); + add_button_update_state(); + } + } + )); + + unofficial_source_signed_file_checkbutton.connect_toggled(clone!( + #[weak] + unofficial_source_add_signed_entry, + #[strong] + add_button_update_state, + move |checkbutton| { + if checkbutton.is_active() { + unofficial_source_add_signed_entry.set_sensitive(true); + add_button_update_state(); + } + } + )); + + unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); + unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); + unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label); + unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_switch); + unofficial_source_add_box2.append(&unofficial_source_signed_keyring_checkbutton); + unofficial_source_add_box2.append(&unofficial_source_signed_file_checkbutton); + + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_name_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); + unofficial_source_add_dialog_child_box + .append(&unofficial_source_add_components_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_archs_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_signed_prefrencesgroup); + + // + + match &deb822_repo.repolib_name { + Some(t) => { + unofficial_source_add_name_entry.set_text(&t); + } + None => {} + } + match &deb822_repo.uris { + Some(t) => { + unofficial_source_add_uri_entry.set_text(&t); + } + None => {} + } + match &deb822_repo.suites { + Some(t) => { + unofficial_source_add_suites_entry.set_text(&t); + } + None => {} + } + match &deb822_repo.components { + Some(t) => { + unofficial_source_add_components_entry.set_text(&t); + } + None => {} + } + match &deb822_repo.signed_by { + Some(t) => { + unofficial_source_signed_file_checkbutton.set_active(true); + unofficial_source_add_signed_entry.set_text(&t); + } + None => unofficial_source_signed_keyring_checkbutton.set_active(true), + } + match &deb822_repo.architectures { + Some(t) => { + unofficial_source_add_archs_entry.set_text(&t); + } + None => {} + } + match &deb822_repo.enabled { + Some(t) => { + unofficial_source_add_is_enabled_switch.set_active(match t.to_lowercase().as_str() { + "yes" => true, + "true" => true, + "no" => false, + "false" => false, + _ => true, + }); + } + None => { + unofficial_source_add_is_enabled_switch.set_active(true); + } + } + + match &deb822_repo.types { + Some(t) => { + unofficial_source_add_is_source_switch.set_active(t.contains("deb-src")); + } + None => {} + } + + // + let deb822_repo_clone0 = deb822_repo.clone(); + + let reload_action_clone0 = reload_action.clone(); + let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); + + unofficial_source_add_dialog + .clone() + .choose(None::<&gio::Cancellable>, move |choice| { + match choice.as_str() { + "unofficial_source_edit_dialog_edit" => { + let sign_method = if unofficial_source_signed_file_checkbutton.is_active() { + 1 } else { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); - } - }; - - // - - for entry in [ - &unofficial_source_add_name_entry, - &unofficial_source_add_uri_entry, - &unofficial_source_add_suites_entry, - &unofficial_source_add_components_entry, - &unofficial_source_add_signed_entry, - ] { - entry.connect_text_notify(clone!( - #[strong] - add_button_update_state, - move |_| + 0 + }; + let new_repo = Deb822Repository { + repolib_name: Some(unofficial_source_add_name_entry.text().to_string()), + filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name), + uris: Some(unofficial_source_add_uri_entry.text().to_string()), + types: if unofficial_source_add_is_source_switch.is_active() { + Some("deb deb-src".to_string()) + } else { + Some("deb".to_string()) + }, + suites: Some(unofficial_source_add_suites_entry.text().to_string()), + components: Some(unofficial_source_add_components_entry.text().to_string()), + architectures: if unofficial_source_add_archs_entry.text().is_empty() { + None + } else { + Some(unofficial_source_add_archs_entry.text().to_string()) + }, + signed_by: match sign_method { + 1 => Some(unofficial_source_add_signed_entry.text().to_string()), + _ => None, + }, + enabled: match unofficial_source_add_is_enabled_switch.is_active() { + true => Some("yes".to_string()), + false => Some("no".to_string()), + }, + ..deb822_repo_clone0 + }; + match Deb822Repository::write_to_file( + new_repo.clone(), + format!("/tmp/{}.sources", repo_file_name).into(), + ) { + Ok(_) => { + match duct::cmd!( + "pkexec", + "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", + "deb822_move", + repo_file_name + ) + .run() { - add_button_update_state(); - } - ) - ); - } - - // - - unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( - #[weak] - unofficial_source_add_signed_entry, - #[strong] - add_button_update_state, - move |checkbutton| - { - if checkbutton.is_active() { - unofficial_source_add_signed_entry.set_sensitive(false); - add_button_update_state(); - } - } - ) - ); - - unofficial_source_signed_file_checkbutton.connect_toggled(clone!( - #[weak] - unofficial_source_add_signed_entry, - #[strong] - add_button_update_state, - move |checkbutton| - { - if checkbutton.is_active() { - unofficial_source_add_signed_entry.set_sensitive(true); - add_button_update_state(); - } - } - ) - ); - - unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); - unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); - unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label); - unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_switch); - unofficial_source_add_box2.append(&unofficial_source_signed_keyring_checkbutton); - unofficial_source_add_box2.append(&unofficial_source_signed_file_checkbutton); - - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_name_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_components_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_archs_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_signed_prefrencesgroup); - - - // - - match &deb822_repo.repolib_name { - Some(t) => { - unofficial_source_add_name_entry.set_text(&t); - } - None => {} - } - match &deb822_repo.uris { - Some(t) => { - unofficial_source_add_uri_entry.set_text(&t); - } - None => {} - } - match &deb822_repo.suites { - Some(t) => { - unofficial_source_add_suites_entry.set_text(&t); - } - None => {} - } - match &deb822_repo.components { - Some(t) => { - unofficial_source_add_components_entry.set_text(&t); - } - None => {} - } - match &deb822_repo.signed_by { - Some(t) => { - unofficial_source_signed_file_checkbutton.set_active(true); - unofficial_source_add_signed_entry.set_text(&t); - } - None => { - unofficial_source_signed_keyring_checkbutton.set_active(true) - } - } - match &deb822_repo.architectures { - Some(t) => { - unofficial_source_add_archs_entry.set_text(&t); - } - None => {} - } - match &deb822_repo.enabled { - Some(t) => { - unofficial_source_add_is_enabled_switch.set_active(match t.to_lowercase().as_str() { - "yes" => true, - "true" => true, - "no" => false, - "false" => false, - _ => true, - }); - } - None => { - unofficial_source_add_is_enabled_switch.set_active(true); - } - } - - match &deb822_repo.types { - Some(t) => { - unofficial_source_add_is_source_switch.set_active(t.contains("deb-src")); - } - None => {} - } - - // - let deb822_repo_clone0 = deb822_repo.clone(); - - let reload_action_clone0 = reload_action.clone(); - let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); - - - unofficial_source_add_dialog.clone() - .choose(None::<&gio::Cancellable>, move |choice| { - match choice.as_str() { - "unofficial_source_edit_dialog_edit" => { - let sign_method = if unofficial_source_signed_file_checkbutton.is_active() { - 1 - } else { - 0 - }; - let new_repo = Deb822Repository { - repolib_name: Some(unofficial_source_add_name_entry.text().to_string()), - filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name), - uris: Some(unofficial_source_add_uri_entry.text().to_string()), - types: if unofficial_source_add_is_source_switch.is_active() { - Some("deb deb-src".to_string()) - } else { - Some("deb".to_string()) - }, - suites: Some(unofficial_source_add_suites_entry.text().to_string()), - components: Some(unofficial_source_add_components_entry.text().to_string()), - architectures: if unofficial_source_add_archs_entry.text().is_empty() { - None - } else { - Some(unofficial_source_add_archs_entry.text().to_string()) - }, - signed_by: match sign_method { - 1 => Some(unofficial_source_add_signed_entry.text().to_string()), - _ => None - }, - enabled: match unofficial_source_add_is_enabled_switch.is_active() { - true => Some("yes".to_string()), - false => Some("no".to_string()) - }, - ..deb822_repo_clone0 - }; - match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) { - Ok(_) => { - match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move", repo_file_name).run() { - Ok(_) => {} - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - } - } - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - } + Ok(_) => {} + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); } - _ => {} + } + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); } - }); -} \ No newline at end of file + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + } + } + _ => {} + } + }); +} diff --git a/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs b/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs index 34a6421..60dca11 100644 --- a/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs +++ b/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs @@ -1,21 +1,8 @@ -use crate::apt_package_row::AptPackageRow; use adw::gio::SimpleAction; use adw::prelude::*; use apt_legacy_tools::LegacyAptSource; -use regex::Regex; -use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject}; +use gtk::glib::clone; use gtk::*; -use std::cell::Ref; -use std::ops::Deref; -use pika_unixsocket_tools::pika_unixsocket_tools::*; -use rust_apt::cache::*; -use rust_apt::new_cache; -use rust_apt::records::RecordField; -use std::cell::RefCell; -use std::process::Command; -use std::rc::Rc; -use std::thread; -use tokio::runtime::Runtime; use std::path::Path; pub fn legacy_edit_dialog_fn( @@ -24,253 +11,270 @@ pub fn legacy_edit_dialog_fn( reload_action: &gio::SimpleAction, apt_retry_signal_action: &SimpleAction, ) { - let repofile_path = Path::new(&legacy_repo.filepath); - let repo_file_name = repofile_path - .file_name() - .unwrap() - .to_str() - .unwrap() - .trim_end_matches(".list") - .to_owned(); - - let unofficial_source_add_dialog_child_box = Box::builder() - .hexpand(true) - .orientation(Orientation::Vertical) - .build(); + let repofile_path = Path::new(&legacy_repo.filepath); + let repo_file_name = repofile_path + .file_name() + .unwrap() + .to_str() + .unwrap() + .trim_end_matches(".list") + .to_owned(); - let unofficial_source_add_uri_entry = gtk::Entry::builder() - .build(); + let unofficial_source_add_dialog_child_box = Box::builder() + .hexpand(true) + .orientation(Orientation::Vertical) + .build(); - let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) - .build(); + let unofficial_source_add_uri_entry = gtk::Entry::builder().build(); - unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); + let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) + .build(); - let unofficial_source_add_suites_entry = gtk::Entry::builder() - .build(); + unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); - let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) - .build(); + let unofficial_source_add_suites_entry = gtk::Entry::builder().build(); - unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); + let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) + .build(); - let unofficial_source_add_components_entry = gtk::Entry::builder() - .build(); + unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); - let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_components_prefrencesgroup_title")) - .build(); + let unofficial_source_add_components_entry = gtk::Entry::builder().build(); - unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); + let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_components_prefrencesgroup_title")) + .build(); - let unofficial_source_add_legacy_options_entry = gtk::Entry::builder() - .build(); + unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); - let unofficial_source_add_legacy_options_prefrencesgroup = adw::PreferencesGroup::builder() - .title(t!("unofficial_source_add_legacy_options_prefrencesgroup_title")) - .build(); - - unofficial_source_add_legacy_options_prefrencesgroup.add(&unofficial_source_add_legacy_options_entry); + let unofficial_source_add_legacy_options_entry = gtk::Entry::builder().build(); - let unofficial_source_add_box2 = gtk::Box::builder() - .margin_top(10) - .orientation(Orientation::Horizontal) - .hexpand(true) - .spacing(5) - .build(); + let unofficial_source_add_legacy_options_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!( + "unofficial_source_add_legacy_options_prefrencesgroup_title" + )) + .build(); - let unofficial_source_add_is_source_label = gtk::Label::builder() - .label(t!("unofficial_source_add_is_legacy_source_label_label")) - .halign(Align::Start) - .valign(Align::Center) - .build(); + unofficial_source_add_legacy_options_prefrencesgroup + .add(&unofficial_source_add_legacy_options_entry); + let unofficial_source_add_box2 = gtk::Box::builder() + .margin_top(10) + .orientation(Orientation::Horizontal) + .hexpand(true) + .spacing(5) + .build(); - let unofficial_source_add_is_enabled_label = gtk::Label::builder() - .label(t!("unofficial_source_add_is_enabled_label_label")) - .halign(Align::Start) - .valign(Align::Center) - .build(); - - let unofficial_source_add_is_source_switch = gtk::Switch::builder() - .halign(Align::Start) - .valign(Align::Center) - .build(); + let unofficial_source_add_is_source_label = gtk::Label::builder() + .label(t!("unofficial_source_add_is_legacy_source_label_label")) + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_add_is_enabled_switch = gtk::Switch::builder() - .halign(Align::Start) - .valign(Align::Center) - .build(); + let unofficial_source_add_is_enabled_label = gtk::Label::builder() + .label(t!("unofficial_source_add_is_enabled_label_label")) + .halign(Align::Start) + .valign(Align::Center) + .build(); - // - let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() - .child(&unofficial_source_add_dialog_child_box) - .maximum_size(500) - .build(); + let unofficial_source_add_is_source_switch = gtk::Switch::builder() + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() - .hexpand(true) - .vexpand(true) - .child(&unofficial_source_add_dialog_child_clamp) - .hscrollbar_policy(PolicyType::Never) - .build(); + let unofficial_source_add_is_enabled_switch = gtk::Switch::builder() + .halign(Align::Start) + .valign(Align::Center) + .build(); - let unofficial_source_add_dialog = adw::MessageDialog::builder() - .transient_for(&window) - .extra_child(&unofficial_source_add_viewport) - .heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) - .width_request(700) - .height_request(500) - .build(); + // + let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() + .child(&unofficial_source_add_dialog_child_box) + .maximum_size(500) + .build(); - unofficial_source_add_dialog.add_response( - "unofficial_source_edit_dialog_edit", - &t!("unofficial_source_edit_dialog_add_edit").to_string(), - ); - - unofficial_source_add_dialog.add_response( - "unofficial_source_add_dialog_cancel", - &t!("unofficial_source_add_dialog_cancel_label").to_string(), - ); + let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() + .hexpand(true) + .vexpand(true) + .child(&unofficial_source_add_dialog_child_clamp) + .hscrollbar_policy(PolicyType::Never) + .build(); - unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); + let unofficial_source_add_dialog = adw::MessageDialog::builder() + .transient_for(&window) + .extra_child(&unofficial_source_add_viewport) + .heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) + .width_request(700) + .height_request(500) + .build(); - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_add_dialog_cancel", - adw::ResponseAppearance::Destructive, - ); + unofficial_source_add_dialog.add_response( + "unofficial_source_edit_dialog_edit", + &t!("unofficial_source_edit_dialog_add_edit").to_string(), + ); - unofficial_source_add_dialog.set_response_appearance( - "unofficial_source_edit_dialog_edit", - adw::ResponseAppearance::Suggested, - ); + unofficial_source_add_dialog.add_response( + "unofficial_source_add_dialog_cancel", + &t!("unofficial_source_add_dialog_cancel_label").to_string(), + ); - // + unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false); - let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); - let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); - let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); - let unofficial_source_add_components_entry_clone0 = unofficial_source_add_components_entry.clone(); + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_add_dialog_cancel", + adw::ResponseAppearance::Destructive, + ); - let add_button_update_state = move || { - if - !unofficial_source_add_uri_entry_clone0.text().is_empty() && - !unofficial_source_add_suites_entry_clone0.text().is_empty() && - !unofficial_source_add_components_entry_clone0.text().is_empty() - { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); - } else { - unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); - } - }; + unofficial_source_add_dialog.set_response_appearance( + "unofficial_source_edit_dialog_edit", + adw::ResponseAppearance::Suggested, + ); - // + // - for entry in [ - &unofficial_source_add_uri_entry, - &unofficial_source_add_suites_entry, - &unofficial_source_add_components_entry, - &unofficial_source_add_legacy_options_entry, - ] { - entry.connect_text_notify(clone!( - #[strong] - add_button_update_state, - move |_| + let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone(); + let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); + let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); + let unofficial_source_add_components_entry_clone0 = + unofficial_source_add_components_entry.clone(); + + let add_button_update_state = move || { + if !unofficial_source_add_uri_entry_clone0.text().is_empty() + && !unofficial_source_add_suites_entry_clone0.text().is_empty() + && !unofficial_source_add_components_entry_clone0 + .text() + .is_empty() + { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", true); + } else { + unofficial_source_add_dialog_clone0 + .set_response_enabled("unofficial_source_add_dialog_add", false); + } + }; + + // + + for entry in [ + &unofficial_source_add_uri_entry, + &unofficial_source_add_suites_entry, + &unofficial_source_add_components_entry, + &unofficial_source_add_legacy_options_entry, + ] { + entry.connect_text_notify(clone!( + #[strong] + add_button_update_state, + move |_| { + add_button_update_state(); + } + )); + } + + // + + unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); + unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); + unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label); + unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_switch); + + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); + unofficial_source_add_dialog_child_box + .append(&unofficial_source_add_components_prefrencesgroup); + unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); + unofficial_source_add_dialog_child_box + .append(&unofficial_source_add_legacy_options_prefrencesgroup); + + // + + unofficial_source_add_uri_entry.set_text(&legacy_repo.url); + unofficial_source_add_suites_entry.set_text(&legacy_repo.suite); + unofficial_source_add_components_entry.set_text(&legacy_repo.components); + match &legacy_repo.options { + Some(t) => { + unofficial_source_add_legacy_options_entry.set_text(&t); + } + None => {} + } + unofficial_source_add_is_enabled_switch.set_active(legacy_repo.enabled); + + unofficial_source_add_is_source_switch.set_active(legacy_repo.is_source); + + // + let legacy_repo_clone0 = legacy_repo.clone(); + + let reload_action_clone0 = reload_action.clone(); + let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); + + unofficial_source_add_dialog + .clone() + .choose(None::<&gio::Cancellable>, move |choice| { + match choice.as_str() { + "unofficial_source_edit_dialog_edit" => { + let mut new_apt_legacy_vec = LegacyAptSource::get_legacy_sources().unwrap(); + new_apt_legacy_vec.retain(|x| x != &legacy_repo_clone0); + let new_repo = LegacyAptSource { + url: unofficial_source_add_uri_entry.text().to_string(), + is_source: unofficial_source_add_is_source_switch.is_active(), + suite: unofficial_source_add_suites_entry.text().to_string(), + components: unofficial_source_add_components_entry.text().to_string(), + options: Some( + unofficial_source_add_legacy_options_entry + .text() + .to_string(), + ), + enabled: unofficial_source_add_is_enabled_switch.is_active(), + ..legacy_repo_clone0 + }; + new_apt_legacy_vec.push(new_repo.clone()); + match LegacyAptSource::save_to_file( + new_repo, + new_apt_legacy_vec, + &format!("/tmp/{}.list", repo_file_name), + ) { + Ok(_) => { + match duct::cmd!( + "pkexec", + "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", + "legacy_move", + repo_file_name + ) + .run() { - add_button_update_state(); - } - ) - ); - } - - // - - unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); - unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); - unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label); - unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_switch); - - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_components_prefrencesgroup); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2); - unofficial_source_add_dialog_child_box.append(&unofficial_source_add_legacy_options_prefrencesgroup); - - - // - - unofficial_source_add_uri_entry.set_text(&legacy_repo.url); - unofficial_source_add_suites_entry.set_text(&legacy_repo.suite); - unofficial_source_add_components_entry.set_text(&legacy_repo.components); - match &legacy_repo.options { - Some(t) => { - unofficial_source_add_legacy_options_entry.set_text(&t); - } - None => {} - } - unofficial_source_add_is_enabled_switch.set_active(legacy_repo.enabled); - - unofficial_source_add_is_source_switch.set_active(legacy_repo.is_source); - - // - let legacy_repo_clone0 = legacy_repo.clone(); - - let reload_action_clone0 = reload_action.clone(); - let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone(); - - unofficial_source_add_dialog.clone() - .choose(None::<&gio::Cancellable>, move |choice| { - match choice.as_str() { - "unofficial_source_edit_dialog_edit" => { - let mut new_apt_legacy_vec = LegacyAptSource::get_legacy_sources().unwrap(); - new_apt_legacy_vec.retain(|x| x != &legacy_repo_clone0); - let new_repo = LegacyAptSource { - url: unofficial_source_add_uri_entry.text().to_string(), - is_source: unofficial_source_add_is_source_switch.is_active(), - suite: unofficial_source_add_suites_entry.text().to_string(), - components: unofficial_source_add_components_entry.text().to_string(), - options: Some(unofficial_source_add_legacy_options_entry.text().to_string()), - enabled: unofficial_source_add_is_enabled_switch.is_active(), - ..legacy_repo_clone0 - }; - new_apt_legacy_vec.push(new_repo.clone()); - match LegacyAptSource::save_to_file(new_repo, new_apt_legacy_vec, &format!("/tmp/{}.list", repo_file_name)) { - Ok(_) => { - match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "legacy_move", repo_file_name).run() { - Ok(_) => {} - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - } - } - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - Err(e) => { - let apt_src_create_error_dialog = adw::MessageDialog::builder() - .heading(t!("apt_src_create_error_dialog_heading")) - .body(e.to_string()) - .build(); - apt_src_create_error_dialog.add_response( - "apt_src_create_error_dialog_ok", - &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); - apt_src_create_error_dialog.present(); - reload_action_clone0.activate(None); - apt_retry_signal_action_clone0.activate(None); - } - } + Ok(_) => {} + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); } - _ => {} + } + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); } - }); -} \ No newline at end of file + Err(e) => { + let apt_src_create_error_dialog = adw::MessageDialog::builder() + .heading(t!("apt_src_create_error_dialog_heading")) + .body(e.to_string()) + .build(); + apt_src_create_error_dialog.add_response( + "apt_src_create_error_dialog_ok", + &t!("apt_src_create_error_dialog_ok_label").to_string(), + ); + apt_src_create_error_dialog.present(); + reload_action_clone0.activate(None); + apt_retry_signal_action_clone0.activate(None); + } + } + } + _ => {} + } + }); +} diff --git a/src/bin/gui/apt_manage_page/mod.rs b/src/bin/gui/apt_manage_page/mod.rs index e21ac9d..0713d2e 100644 --- a/src/bin/gui/apt_manage_page/mod.rs +++ b/src/bin/gui/apt_manage_page/mod.rs @@ -1,22 +1,12 @@ -use crate::apt_package_row::AptPackageRow; -use add_dialog::add_dialog_fn; use adw::gio::SimpleAction; use adw::prelude::*; use apt_deb822_tools::Deb822Repository; -use regex::Regex; -use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject}; +use gtk::glib::{clone, BoxedAnyObject}; use gtk::*; use std::cell::Ref; -use std::ops::Deref; -use pika_unixsocket_tools::pika_unixsocket_tools::*; -use rust_apt::cache::*; -use rust_apt::new_cache; -use rust_apt::records::RecordField; use std::cell::RefCell; -use std::process::Command; +use std::ops::Deref; use std::rc::Rc; -use std::thread; -use tokio::runtime::Runtime; mod add_dialog; mod deb822_edit_dialog; @@ -24,7 +14,7 @@ mod legacy_edit_dialog; enum AptSourceConfig { Legacy(apt_legacy_tools::LegacyAptSource), - DEB822(apt_deb822_tools::Deb822Repository) + DEB822(apt_deb822_tools::Deb822Repository), } pub fn apt_manage_page( @@ -35,16 +25,22 @@ pub fn apt_manage_page( let deb822_sources = Deb822Repository::get_deb822_sources().unwrap(); - let system_source = deb822_sources.iter().filter(|x| { - match &x.repolib_id { - Some(t) => { - t == "system" - } - None => false - } - }).next().unwrap(); + let system_source = deb822_sources + .iter() + .filter(|x| match &x.repolib_id { + Some(t) => t == "system", + None => false, + }) + .next() + .unwrap(); - let system_mirror_refcell = Rc::new(RefCell::new(system_source.repolib_default_mirror.as_deref().unwrap().to_string())); + let system_mirror_refcell = Rc::new(RefCell::new( + system_source + .repolib_default_mirror + .as_deref() + .unwrap() + .to_string(), + )); let main_box = Box::builder() .hexpand(true) @@ -105,7 +101,9 @@ pub fn apt_manage_page( #[strong] system_mirror_refcell, move |entry| { - system_mirror_save_button.set_sensitive(!(entry.text().to_string() == system_mirror_refcell.borrow().to_string())); + system_mirror_save_button.set_sensitive( + !(entry.text().to_string() == system_mirror_refcell.borrow().to_string()), + ); } )); @@ -123,12 +121,24 @@ pub fn apt_manage_page( uris: (Some(system_mirror_entry.text().to_string())), ..system_source.clone() }; - match Deb822Repository::write_to_file(new_repo.clone(), std::path::Path::new("/tmp/system.sources").to_path_buf()) { + match Deb822Repository::write_to_file( + new_repo.clone(), + std::path::Path::new("/tmp/system.sources").to_path_buf(), + ) { Ok(_) => { - match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move", "system", "system").run() { + match duct::cmd!( + "pkexec", + "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", + "deb822_move", + "system", + "system" + ) + .run() + { Ok(_) => { retry_signal_action.activate(None); - *system_mirror_refcell.borrow_mut() = system_mirror_entry.text().to_string(); + *system_mirror_refcell.borrow_mut() = + system_mirror_entry.text().to_string(); button.set_sensitive(false); } Err(e) => { @@ -139,7 +149,7 @@ pub fn apt_manage_page( apt_src_create_error_dialog.add_response( "apt_src_create_error_dialog_ok", &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); + ); apt_src_create_error_dialog.present(); retry_signal_action.activate(None); } @@ -153,7 +163,7 @@ pub fn apt_manage_page( apt_src_create_error_dialog.add_response( "apt_src_create_error_dialog_ok", &t!("apt_src_create_error_dialog_ok_label").to_string(), - ); + ); apt_src_create_error_dialog.present(); } } @@ -182,91 +192,84 @@ pub fn apt_manage_page( .margin_end(15) .build(); - let unofficial_sources_selection_model_rc: Rc> = Rc::new(RefCell::default()); + let unofficial_sources_selection_model_rc: Rc> = + Rc::new(RefCell::default()); - let unofficial_sources_selection_model_rc_clone0 = Rc::clone(&unofficial_sources_selection_model_rc); + let unofficial_sources_selection_model_rc_clone0 = + Rc::clone(&unofficial_sources_selection_model_rc); let unofficial_sources_columnview_bin = adw::Bin::new(); let unofficial_sources_columnview_bin_clone0 = unofficial_sources_columnview_bin.clone(); - + retry_signal_action.connect_activate(clone!( #[weak] unofficial_sources_columnview_bin_clone0, move |_, _| { - - let mut unofficial_deb822_sources = Deb822Repository::get_deb822_sources().unwrap(); + let mut unofficial_deb822_sources = Deb822Repository::get_deb822_sources().unwrap(); - unofficial_deb822_sources.retain(|x| { - match &x.repolib_id { - Some(t) => { - !(t == "system") - } - None => true - } + unofficial_deb822_sources.retain(|x| match &x.repolib_id { + Some(t) => !(t == "system"), + None => true, }); - - let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources(); - let unofficial_sources_list_store = gio::ListStore::new::(); + let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources(); - for deb822_source in unofficial_deb822_sources { - unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source))); - }; + let unofficial_sources_list_store = gio::ListStore::new::(); - match legacy_apt_repos { - Ok(vec) => { - for legacy_repo in vec { - unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::Legacy(legacy_repo))); - }; + for deb822_source in unofficial_deb822_sources { + unofficial_sources_list_store + .append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source))); } - Err(_) => {} - } - let unofficial_sources_selection_model = SingleSelection::new(Some(unofficial_sources_list_store)); + match legacy_apt_repos { + Ok(vec) => { + for legacy_repo in vec { + unofficial_sources_list_store + .append(&BoxedAnyObject::new(AptSourceConfig::Legacy(legacy_repo))); + } + } + Err(_) => {} + } - (*unofficial_sources_selection_model_rc_clone0.borrow_mut() = unofficial_sources_selection_model.clone()); + let unofficial_sources_selection_model = + SingleSelection::new(Some(unofficial_sources_list_store)); - let unofficial_sources_columnview = ColumnView::builder() - .vexpand(true) - .model(&unofficial_sources_selection_model) - .build(); + (*unofficial_sources_selection_model_rc_clone0.borrow_mut() = + unofficial_sources_selection_model.clone()); - // - - let unofficial_sources_columnview_factory0 = gtk::SignalListItemFactory::new(); - - unofficial_sources_columnview_factory0.connect_setup(move |_factory, item| { - let item = item.downcast_ref::().unwrap(); - let row = Label::builder() - .halign(Align::Start) + let unofficial_sources_columnview = ColumnView::builder() + .vexpand(true) + .model(&unofficial_sources_selection_model) .build(); - item.set_child(Some(&row)); - }); - unofficial_sources_columnview_factory0.connect_bind(move |_factory, item| { - let item: &ListItem = item.downcast_ref::().unwrap(); - let child = item.child().and_downcast::