From e6c08cc200cab17bd15d7f47a41fef307d49e870 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Tue, 24 Sep 2024 21:56:20 +0300 Subject: [PATCH] Attempt to fix legacy repo --- Cargo.lock | 4 +- Cargo.toml | 2 +- locales/en_US.json | 4 +- .../gui/apt_manage_page/legacy_edit_dialog.rs | 271 ++++++++++++++++++ src/bin/gui/apt_manage_page/mod.rs | 5 +- src/bin/gui/flatpak_update_page/process.rs | 4 +- 6 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 src/bin/gui/apt_manage_page/legacy_edit_dialog.rs diff --git a/Cargo.lock b/Cargo.lock index 5450bfc..193933f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,8 +1071,8 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "legacy-apt-list-tools-rs" -version = "0.1.0" -source = "git+https://github.com/CosmicFusion/legacy-apt-list-tools-rs#0606e8431239a45a14cddc9934ad3eab46e4bb99" +version = "0.1.1" +source = "git+https://github.com/CosmicFusion/legacy-apt-list-tools-rs#f6ad0545a2cc32bda63ba4d72f99374644c3abf9" dependencies = [ "apt-sources-lists", ] diff --git a/Cargo.toml b/Cargo.toml index e6b90a9..b5e0ab4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ async-channel = "2.1.1" rust-i18n = "3.0.1" rust-apt = { git = "https://gitlab.com/volian/rust-apt" } apt-deb822-tools = { package = "deb822-tools", git = "https://github.com/CosmicFusion/deb822-tools" } -apt-legacy-tools = { package = "legacy-apt-list-tools-rs", git = "https://github.com/CosmicFusion/legacy-apt-list-tools-rs" } +apt-legacy-tools = { version = "0.1.1", package = "legacy-apt-list-tools-rs", git = "https://github.com/CosmicFusion/legacy-apt-list-tools-rs" } tokio = { version = "1", features = ["full"] } tokio-uds = "0.2" serde = { version = "1.0.203", features = ["derive"] } diff --git a/locales/en_US.json b/locales/en_US.json index 7c7c491..5d36927 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -120,5 +120,7 @@ "apt_src_remove_warning_dialog_ok_label": "OK", "unofficial_source_add_is_enabled_label_label": "Enabled", "unofficial_source_edit_dialog_add_edit": "Save Changes", - "unofficial_source_edit_dialog_heading": "Editing" + "unofficial_source_edit_dialog_heading": "Editing", + "unofficial_source_add_legacy_options_prefrencesgroup_title": "Options", + "unofficial_source_add_is_legacy_source_label_label": "Is A Source Repository" } \ No newline at end of file diff --git a/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs b/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs new file mode 100644 index 0000000..c70edb5 --- /dev/null +++ b/src/bin/gui/apt_manage_page/legacy_edit_dialog.rs @@ -0,0 +1,271 @@ +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::*; +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( + window: adw::ApplicationWindow, + legacy_repo: &LegacyAptSource, + reload_action: &gio::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 unofficial_source_add_uri_entry = gtk::Entry::builder() + .build(); + + let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_uri_prefrencesgroup_title")) + .build(); + + unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry); + + let unofficial_source_add_suites_entry = gtk::Entry::builder() + .build(); + + let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_suites_prefrencesgroup_title")) + .build(); + + unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry); + + let unofficial_source_add_components_entry = gtk::Entry::builder() + .build(); + + let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() + .title(t!("unofficial_source_add_components_prefrencesgroup_title")) + .build(); + + unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry); + + let unofficial_source_add_legacy_options_entry = gtk::Entry::builder() + .build(); + + 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_box2 = gtk::Box::builder() + .margin_top(10) + .orientation(Orientation::Horizontal) + .hexpand(true) + .spacing(5) + .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_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_enabled_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_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_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.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(), + ); + + 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_edit_dialog_edit", + adw::ResponseAppearance::Suggested, + ); + + // + + 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(); + + unofficial_source_add_dialog.clone() + .choose(None::<&gio::Cancellable>, move |choice| { + match choice.as_str() { + "unofficial_source_edit_dialog_edit" => { + 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 + }; + /*match LegacyAptSource::save_to_file(new_repo.clone(), LegacyAptSource::get_legacy_sources().unwrap(), &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); + } + 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); + } + }*/ + dbg!(&new_repo); + LegacyAptSource::save_to_file(new_repo.clone(), LegacyAptSource::get_legacy_sources().unwrap(), &format!("/tmp/{}.list", repo_file_name)).unwrap(); + } + _ => {} + } + }); +} \ No newline at end of file diff --git a/src/bin/gui/apt_manage_page/mod.rs b/src/bin/gui/apt_manage_page/mod.rs index edccb5a..02b847d 100644 --- a/src/bin/gui/apt_manage_page/mod.rs +++ b/src/bin/gui/apt_manage_page/mod.rs @@ -20,6 +20,7 @@ use tokio::runtime::Runtime; mod add_dialog; mod deb822_edit_dialog; +mod legacy_edit_dialog; enum AptSourceConfig { Legacy(apt_legacy_tools::LegacyAptSource), @@ -349,7 +350,9 @@ pub fn apt_manage_page( AptSourceConfig::DEB822(src) => { deb822_edit_dialog::deb822_edit_dialog_fn(window.clone(), src, &reload_unofficial_action); } - AptSourceConfig::Legacy(list) => {} + AptSourceConfig::Legacy(list) => { + legacy_edit_dialog::legacy_edit_dialog_fn(window.clone(), list, &reload_unofficial_action) + } }; } diff --git a/src/bin/gui/flatpak_update_page/process.rs b/src/bin/gui/flatpak_update_page/process.rs index 202ed5a..7a6e83d 100644 --- a/src/bin/gui/flatpak_update_page/process.rs +++ b/src/bin/gui/flatpak_update_page/process.rs @@ -24,10 +24,10 @@ struct FlatpakChangesInfo { total_download_size: u64, total_installed_size: i64, } -#[derive(Serialize)] +/*#[derive(Serialize)] struct Exclusions { exclusions: Vec, -} +}*/ impl FlatpakChangesInfo { fn add_system(&mut self) {