From 830def1d3d4487e7b0f70c69a50c91e61c182a44 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Sat, 21 Sep 2024 18:35:46 +0300 Subject: [PATCH] parse new repo --- Cargo.lock | 5 ++-- Cargo.toml | 1 + src/bin/gui/apt_manage_page/mod.rs | 42 +++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4da664..3924124 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1412,6 +1412,7 @@ dependencies = [ "libflatpak", "lock_api 0.4.12", "pretty-bytes", + "regex", "rust-apt", "rust-i18n", "serde", @@ -1516,9 +1517,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", diff --git a/Cargo.toml b/Cargo.toml index ded7277..7188869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,4 +39,5 @@ crossbeam-utils = "0.8.20" chrono = "0.4.38" lock_api = "0.4.2" libflatpak = { version = "0.5.0", package = "libflatpak", features = ["v1_11_1"] } +regex = "1.10.6" diff --git a/src/bin/gui/apt_manage_page/mod.rs b/src/bin/gui/apt_manage_page/mod.rs index 9c2067b..ceee9a0 100644 --- a/src/bin/gui/apt_manage_page/mod.rs +++ b/src/bin/gui/apt_manage_page/mod.rs @@ -2,12 +2,12 @@ use crate::apt_package_row::AptPackageRow; use adw::gio::SimpleAction; use adw::prelude::*; use apt_deb822_tools::Deb822Repository; -use gtk::glib::*; +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 property::PropertyGet; use rust_apt::cache::*; use rust_apt::new_cache; use rust_apt::records::RecordField; @@ -17,6 +17,7 @@ use std::rc::Rc; use std::thread; use tokio::runtime::Runtime; + pub fn apt_manage_page( window: adw::ApplicationWindow, retry_signal_action: &SimpleAction, @@ -478,7 +479,7 @@ pub fn apt_manage_page( !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() && + !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); @@ -580,7 +581,40 @@ pub fn apt_manage_page( .choose(None::<&gio::Cancellable>, move |choice| { match choice.as_str() { "unofficial_source_add_dialog_add" => { - println!("add") + println!("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_archs_entry.text().to_string()), + 2 => Some(format!("/etc/apt/keyrings/{}.gpg.key", repo_file_name)), + _ => None + }, + ..Default::default() + }; + dbg!(new_repo); } "apt_update_dialog_ignore" => { unofficial_source_add_dialog.close();