Fix Warnings and fmt

This commit is contained in:
Ward from fusion-voyager-3 2024-10-04 19:15:50 +03:00
parent f5dcfc455a
commit c2010b7136
14 changed files with 2185 additions and 2080 deletions

View File

@ -1,403 +1,416 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use apt_deb822_tools::Deb822Repository;
use regex::Regex; use gtk::glib::clone;
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*; use gtk::*;
use std::cell::Ref; use regex::Regex;
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;
pub fn add_dialog_fn( pub fn add_dialog_fn(
window: adw::ApplicationWindow, window: adw::ApplicationWindow,
reload_action: &gio::SimpleAction, reload_action: &gio::SimpleAction,
apt_retry_signal_action: &gio::SimpleAction, apt_retry_signal_action: &gio::SimpleAction,
) ) {
{
let unofficial_source_add_dialog_child_box = Box::builder() let unofficial_source_add_dialog_child_box = Box::builder()
.hexpand(true) .hexpand(true)
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.build(); .build();
let unofficial_source_add_name_entry = gtk::Entry::builder()
.placeholder_text("WineHQ Debian")
.build();
let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_name_entry = gtk::Entry::builder()
.title(t!("unofficial_source_add_name_prefrencesgroup_title")) .placeholder_text("WineHQ Debian")
.build(); .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() unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry);
.placeholder_text("https://dl.winehq.org/wine-builds/debian")
.build();
let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_uri_entry = gtk::Entry::builder()
.title(t!("unofficial_source_add_uri_prefrencesgroup_title")) .placeholder_text("https://dl.winehq.org/wine-builds/debian")
.build(); .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() unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry);
.placeholder_text("trixie bookworm sid")
.build();
let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_suites_entry = gtk::Entry::builder()
.title(t!("unofficial_source_add_suites_prefrencesgroup_title")) .placeholder_text("trixie bookworm sid")
.build(); .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() unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry);
.placeholder_text("main proprietary")
.build();
let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_components_entry = gtk::Entry::builder()
.title(t!("unofficial_source_add_components_prefrencesgroup_title")) .placeholder_text("main proprietary")
.build(); .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() unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry);
.sensitive(false)
.build();
let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_signed_entry = gtk::Entry::builder().sensitive(false).build();
.title(t!("unofficial_source_add_signed_prefrencesgroup_title"))
.build();
unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry);
let unofficial_source_add_archs_entry = gtk::Entry::builder() let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder()
.placeholder_text("amd64 arm64 i386") .title(t!("unofficial_source_add_signed_prefrencesgroup_title"))
.build(); .build();
let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry);
.title(t!("unofficial_source_add_archs_prefrencesgroup_title"))
.build();
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() let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder()
.margin_top(10) .title(t!("unofficial_source_add_archs_prefrencesgroup_title"))
.orientation(Orientation::Horizontal) .build();
.hexpand(true)
.spacing(5)
.build();
let unofficial_source_add_is_source_label = gtk::Label::builder() unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry);
.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();
let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() let unofficial_source_add_box2 = gtk::Box::builder()
.halign(Align::Start) .margin_top(10)
.valign(Align::Center) .orientation(Orientation::Horizontal)
.label(t!("unofficial_source_signed_keyring_checkbutton_label")) .hexpand(true)
.active(true) .spacing(5)
.build(); .build();
let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() let unofficial_source_add_is_source_label = gtk::Label::builder()
.halign(Align::Start) .label(t!("unofficial_source_add_is_source_label_label"))
.valign(Align::Center) .halign(Align::Start)
.label(t!("unofficial_source_signed_file_checkbutton_label")) .valign(Align::Center)
.group(&unofficial_source_signed_keyring_checkbutton) .build();
.build();
let unofficial_source_signed_url_checkbutton = gtk::CheckButton::builder() let unofficial_source_add_is_source_switch = gtk::Switch::builder()
.halign(Align::Start) .halign(Align::Start)
.valign(Align::Center) .valign(Align::Center)
.label(t!("unofficial_source_signed_url_checkbutton_label")) .build();
.group(&unofficial_source_signed_keyring_checkbutton)
.build();
// let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder()
let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() .halign(Align::Start)
.child(&unofficial_source_add_dialog_child_box) .valign(Align::Center)
.maximum_size(500) .label(t!("unofficial_source_signed_keyring_checkbutton_label"))
.build(); .active(true)
.build();
let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder()
.hexpand(true) .halign(Align::Start)
.vexpand(true) .valign(Align::Center)
.child(&unofficial_source_add_dialog_child_clamp) .label(t!("unofficial_source_signed_file_checkbutton_label"))
.hscrollbar_policy(PolicyType::Never) .group(&unofficial_source_signed_keyring_checkbutton)
.build(); .build();
let unofficial_source_add_dialog = adw::MessageDialog::builder() let unofficial_source_signed_url_checkbutton = gtk::CheckButton::builder()
.transient_for(&window) .halign(Align::Start)
.extra_child(&unofficial_source_add_viewport) .valign(Align::Center)
.heading(t!("unofficial_source_add_dialog_heading")) .label(t!("unofficial_source_signed_url_checkbutton_label"))
.width_request(700) .group(&unofficial_source_signed_keyring_checkbutton)
.height_request(500) .build();
.build();
unofficial_source_add_dialog.add_response( //
"unofficial_source_add_dialog_add", let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder()
&t!("unofficial_source_add_dialog_add_label").to_string(), .child(&unofficial_source_add_dialog_child_box)
); .maximum_size(500)
.build();
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_viewport = gtk::ScrolledWindow::builder()
.hexpand(true)
unofficial_source_add_dialog.set_response_appearance( .vexpand(true)
"unofficial_source_add_dialog_cancel", .child(&unofficial_source_add_dialog_child_clamp)
adw::ResponseAppearance::Destructive, .hscrollbar_policy(PolicyType::Never)
); .build();
unofficial_source_add_dialog.set_response_appearance( let unofficial_source_add_dialog = adw::MessageDialog::builder()
"unofficial_source_add_dialog_add", .transient_for(&window)
adw::ResponseAppearance::Suggested, .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(); unofficial_source_add_dialog.add_response(
let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone(); "unofficial_source_add_dialog_cancel",
let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); &t!("unofficial_source_add_dialog_cancel_label").to_string(),
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 || { unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false);
if
!unofficial_source_add_name_entry_clone0.text().is_empty() && unofficial_source_add_dialog.set_response_appearance(
!unofficial_source_add_uri_entry_clone0.text().is_empty() && "unofficial_source_add_dialog_cancel",
!unofficial_source_add_suites_entry_clone0.text().is_empty() && adw::ResponseAppearance::Destructive,
!unofficial_source_add_components_entry_clone0.text().is_empty() );
{
if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { unofficial_source_add_dialog.set_response_appearance(
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true); "unofficial_source_add_dialog_add",
} else if !unofficial_source_add_signed_entry_clone0.text().is_empty() { adw::ResponseAppearance::Suggested,
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); //
}
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 { } else {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); 0
} };
}; let repo_file_name = non_alphanum_regex
.replace_all(unofficial_source_add_name_entry.text().as_str(), "_")
// .to_string()
.to_lowercase();
for entry in [ let new_repo = Deb822Repository {
&unofficial_source_add_name_entry, repolib_name: Some(unofficial_source_add_name_entry.text().to_string()),
&unofficial_source_add_uri_entry, filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name),
&unofficial_source_add_suites_entry, uris: Some(unofficial_source_add_uri_entry.text().to_string()),
&unofficial_source_add_components_entry, types: if unofficial_source_add_is_source_switch.is_active() {
&unofficial_source_add_signed_entry, Some("deb deb-src".to_string())
] { } else {
entry.connect_text_notify(clone!( Some("deb".to_string())
#[strong] },
add_button_update_state, suites: Some(unofficial_source_add_suites_entry.text().to_string()),
move |_| components: Some(unofficial_source_add_components_entry.text().to_string()),
{ architectures: if unofficial_source_add_archs_entry.text().is_empty() {
add_button_update_state(); 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,
unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( },
#[weak] ..Default::default()
unofficial_source_add_signed_entry, };
#[strong] if sign_method == 2 {
add_button_update_state, match Deb822Repository::write_to_file(
move |checkbutton| new_repo.clone(),
{ format!("/tmp/{}.sources", repo_file_name).into(),
if checkbutton.is_active() { ) {
unofficial_source_add_signed_entry.set_sensitive(false); Ok(_) => {
unofficial_source_add_signed_entry.set_placeholder_text(Some("")); match duct::cmd!(
add_button_update_state(); "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)
unofficial_source_signed_file_checkbutton.connect_toggled(clone!( )
#[weak] .run()
unofficial_source_add_signed_entry, {
#[strong] Ok(_) => {
add_button_update_state, reload_action_clone0.activate(None);
move |checkbutton| apt_retry_signal_action_clone0.activate(None);
{ }
if checkbutton.is_active() { Err(e) => {
unofficial_source_add_signed_entry.set_sensitive(true); let apt_src_create_error_dialog =
unofficial_source_add_signed_entry.set_placeholder_text(Some("/etc/apt/keyrings/winehq-archive.key")); adw::MessageDialog::builder()
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()
.heading(t!("apt_src_create_error_dialog_heading")) .heading(t!("apt_src_create_error_dialog_heading"))
.body(e.to_string()) .body(e.to_string())
.build(); .build();
apt_src_create_error_dialog.add_response( apt_src_create_error_dialog.add_response(
"apt_src_create_error_dialog_ok", "apt_src_create_error_dialog_ok",
&t!("apt_src_create_error_dialog_ok_label").to_string(), &t!("apt_src_create_error_dialog_ok_label").to_string(),
); );
apt_src_create_error_dialog.present(); apt_src_create_error_dialog.present();
reload_action_clone0.activate(None); reload_action_clone0.activate(None);
apt_retry_signal_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()
.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);
}
}
}
}
_ => {}
}
});
}

View File

@ -1,21 +1,8 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use apt_deb822_tools::Deb822Repository;
use regex::Regex; use gtk::glib::clone;
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*; 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; use std::path::Path;
pub fn deb822_edit_dialog_fn( pub fn deb822_edit_dialog_fn(
@ -24,398 +11,399 @@ pub fn deb822_edit_dialog_fn(
reload_action: &gio::SimpleAction, reload_action: &gio::SimpleAction,
apt_retry_signal_action: &SimpleAction, apt_retry_signal_action: &SimpleAction,
) { ) {
let repofile_path = Path::new(&deb822_repo.filepath); let repofile_path = Path::new(&deb822_repo.filepath);
let repo_file_name = repofile_path let repo_file_name = repofile_path
.file_name() .file_name()
.unwrap() .unwrap()
.to_str() .to_str()
.unwrap() .unwrap()
.trim_end_matches(".sources") .trim_end_matches(".sources")
.to_owned(); .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 unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_dialog_child_box = Box::builder()
.title(t!("unofficial_source_add_name_prefrencesgroup_title")) .hexpand(true)
.build(); .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() let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder()
.build(); .title(t!("unofficial_source_add_name_prefrencesgroup_title"))
.build();
let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry);
.title(t!("unofficial_source_add_uri_prefrencesgroup_title"))
.build();
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() let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder()
.build(); .title(t!("unofficial_source_add_uri_prefrencesgroup_title"))
.build();
let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry);
.title(t!("unofficial_source_add_suites_prefrencesgroup_title"))
.build();
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() let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder()
.build(); .title(t!("unofficial_source_add_suites_prefrencesgroup_title"))
.build();
let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry);
.title(t!("unofficial_source_add_components_prefrencesgroup_title"))
.build();
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() let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder()
.sensitive(false) .title(t!("unofficial_source_add_components_prefrencesgroup_title"))
.build(); .build();
let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder() unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry);
.title(t!("unofficial_source_add_signed_prefrencesgroup_title"))
.build();
unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry);
let unofficial_source_add_archs_entry = gtk::Entry::builder() let unofficial_source_add_signed_entry = gtk::Entry::builder().sensitive(false).build();
.build();
let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_archs_prefrencesgroup_title")) .title(t!("unofficial_source_add_signed_prefrencesgroup_title"))
.build(); .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() let unofficial_source_add_archs_entry = gtk::Entry::builder().build();
.margin_top(10)
.orientation(Orientation::Horizontal)
.hexpand(true)
.spacing(5)
.build();
let unofficial_source_add_is_source_label = gtk::Label::builder() let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder()
.label(t!("unofficial_source_add_is_source_label_label")) .title(t!("unofficial_source_add_archs_prefrencesgroup_title"))
.halign(Align::Start) .build();
.valign(Align::Center)
.build();
unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry);
let unofficial_source_add_is_enabled_label = gtk::Label::builder() let unofficial_source_add_box2 = gtk::Box::builder()
.label(t!("unofficial_source_add_is_enabled_label_label")) .margin_top(10)
.halign(Align::Start) .orientation(Orientation::Horizontal)
.valign(Align::Center) .hexpand(true)
.build(); .spacing(5)
.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() let unofficial_source_add_is_source_label = gtk::Label::builder()
.halign(Align::Start) .label(t!("unofficial_source_add_is_source_label_label"))
.valign(Align::Center) .halign(Align::Start)
.build(); .valign(Align::Center)
.build();
let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder() let unofficial_source_add_is_enabled_label = gtk::Label::builder()
.halign(Align::Start) .label(t!("unofficial_source_add_is_enabled_label_label"))
.valign(Align::Center) .halign(Align::Start)
.label(t!("unofficial_source_signed_keyring_checkbutton_label")) .valign(Align::Center)
.active(true) .build();
.build();
let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder() let unofficial_source_add_is_source_switch = gtk::Switch::builder()
.halign(Align::Start) .halign(Align::Start)
.valign(Align::Center) .valign(Align::Center)
.label(t!("unofficial_source_signed_file_checkbutton_label")) .build();
.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_viewport = gtk::ScrolledWindow::builder() let unofficial_source_add_is_enabled_switch = gtk::Switch::builder()
.hexpand(true) .halign(Align::Start)
.vexpand(true) .valign(Align::Center)
.child(&unofficial_source_add_dialog_child_clamp) .build();
.hscrollbar_policy(PolicyType::Never)
.build();
let unofficial_source_add_dialog = adw::MessageDialog::builder() let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder()
.transient_for(&window) .halign(Align::Start)
.extra_child(&unofficial_source_add_viewport) .valign(Align::Center)
.heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) .label(t!("unofficial_source_signed_keyring_checkbutton_label"))
.width_request(700) .active(true)
.height_request(500) .build();
.build();
unofficial_source_add_dialog.add_response( let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder()
"unofficial_source_edit_dialog_edit", .halign(Align::Start)
&t!("unofficial_source_edit_dialog_add_edit").to_string(), .valign(Align::Center)
); .label(t!("unofficial_source_signed_file_checkbutton_label"))
.group(&unofficial_source_signed_keyring_checkbutton)
unofficial_source_add_dialog.add_response( .build();
"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); 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( let unofficial_source_add_dialog = adw::MessageDialog::builder()
"unofficial_source_add_dialog_cancel", .transient_for(&window)
adw::ResponseAppearance::Destructive, .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.add_response(
"unofficial_source_edit_dialog_edit", "unofficial_source_edit_dialog_edit",
adw::ResponseAppearance::Suggested, &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(); unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false);
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 || { unofficial_source_add_dialog.set_response_appearance(
if "unofficial_source_add_dialog_cancel",
!unofficial_source_add_name_entry_clone0.text().is_empty() && adw::ResponseAppearance::Destructive,
!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.set_response_appearance(
{ "unofficial_source_edit_dialog_edit",
if unofficial_source_signed_keyring_checkbutton_clone0.is_active() { adw::ResponseAppearance::Suggested,
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); 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 { } else {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false); 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()),
for entry in [ types: if unofficial_source_add_is_source_switch.is_active() {
&unofficial_source_add_name_entry, Some("deb deb-src".to_string())
&unofficial_source_add_uri_entry, } else {
&unofficial_source_add_suites_entry, Some("deb".to_string())
&unofficial_source_add_components_entry, },
&unofficial_source_add_signed_entry, suites: Some(unofficial_source_add_suites_entry.text().to_string()),
] { components: Some(unofficial_source_add_components_entry.text().to_string()),
entry.connect_text_notify(clone!( architectures: if unofficial_source_add_archs_entry.text().is_empty() {
#[strong] None
add_button_update_state, } else {
move |_| 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(); 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",
unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!( &t!("apt_src_create_error_dialog_ok_label").to_string(),
#[weak] );
unofficial_source_add_signed_entry, apt_src_create_error_dialog.present();
#[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);
}
}
} }
_ => {} }
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);
}
}
}
_ => {}
}
});
}

View File

@ -1,21 +1,8 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_legacy_tools::LegacyAptSource; use apt_legacy_tools::LegacyAptSource;
use regex::Regex; use gtk::glib::clone;
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*; 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; use std::path::Path;
pub fn legacy_edit_dialog_fn( pub fn legacy_edit_dialog_fn(
@ -24,253 +11,270 @@ pub fn legacy_edit_dialog_fn(
reload_action: &gio::SimpleAction, reload_action: &gio::SimpleAction,
apt_retry_signal_action: &SimpleAction, apt_retry_signal_action: &SimpleAction,
) { ) {
let repofile_path = Path::new(&legacy_repo.filepath); let repofile_path = Path::new(&legacy_repo.filepath);
let repo_file_name = repofile_path let repo_file_name = repofile_path
.file_name() .file_name()
.unwrap() .unwrap()
.to_str() .to_str()
.unwrap() .unwrap()
.trim_end_matches(".list") .trim_end_matches(".list")
.to_owned(); .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() let unofficial_source_add_dialog_child_box = Box::builder()
.build(); .hexpand(true)
.orientation(Orientation::Vertical)
.build();
let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_uri_entry = gtk::Entry::builder().build();
.title(t!("unofficial_source_add_uri_prefrencesgroup_title"))
.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() unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry);
.build();
let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_suites_entry = gtk::Entry::builder().build();
.title(t!("unofficial_source_add_suites_prefrencesgroup_title"))
.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() unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry);
.build();
let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_components_entry = gtk::Entry::builder().build();
.title(t!("unofficial_source_add_components_prefrencesgroup_title"))
.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() unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry);
.build();
let unofficial_source_add_legacy_options_prefrencesgroup = adw::PreferencesGroup::builder() let unofficial_source_add_legacy_options_entry = gtk::Entry::builder().build();
.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() let unofficial_source_add_legacy_options_prefrencesgroup = adw::PreferencesGroup::builder()
.margin_top(10) .title(t!(
.orientation(Orientation::Horizontal) "unofficial_source_add_legacy_options_prefrencesgroup_title"
.hexpand(true) ))
.spacing(5) .build();
.build();
let unofficial_source_add_is_source_label = gtk::Label::builder() unofficial_source_add_legacy_options_prefrencesgroup
.label(t!("unofficial_source_add_is_legacy_source_label_label")) .add(&unofficial_source_add_legacy_options_entry);
.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_label = gtk::Label::builder() let unofficial_source_add_is_source_label = gtk::Label::builder()
.label(t!("unofficial_source_add_is_enabled_label_label")) .label(t!("unofficial_source_add_is_legacy_source_label_label"))
.halign(Align::Start) .halign(Align::Start)
.valign(Align::Center) .valign(Align::Center)
.build(); .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() let unofficial_source_add_is_enabled_label = gtk::Label::builder()
.halign(Align::Start) .label(t!("unofficial_source_add_is_enabled_label_label"))
.valign(Align::Center) .halign(Align::Start)
.build(); .valign(Align::Center)
.build();
// let unofficial_source_add_is_source_switch = gtk::Switch::builder()
let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder() .halign(Align::Start)
.child(&unofficial_source_add_dialog_child_box) .valign(Align::Center)
.maximum_size(500) .build();
.build();
let unofficial_source_add_viewport = gtk::ScrolledWindow::builder() let unofficial_source_add_is_enabled_switch = gtk::Switch::builder()
.hexpand(true) .halign(Align::Start)
.vexpand(true) .valign(Align::Center)
.child(&unofficial_source_add_dialog_child_clamp) .build();
.hscrollbar_policy(PolicyType::Never)
.build();
let unofficial_source_add_dialog = adw::MessageDialog::builder() //
.transient_for(&window) let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder()
.extra_child(&unofficial_source_add_viewport) .child(&unofficial_source_add_dialog_child_box)
.heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name) .maximum_size(500)
.width_request(700) .build();
.height_request(500)
.build();
unofficial_source_add_dialog.add_response( let unofficial_source_add_viewport = gtk::ScrolledWindow::builder()
"unofficial_source_edit_dialog_edit", .hexpand(true)
&t!("unofficial_source_edit_dialog_add_edit").to_string(), .vexpand(true)
); .child(&unofficial_source_add_dialog_child_clamp)
.hscrollbar_policy(PolicyType::Never)
unofficial_source_add_dialog.add_response( .build();
"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 = 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.add_response(
"unofficial_source_add_dialog_cancel", "unofficial_source_edit_dialog_edit",
adw::ResponseAppearance::Destructive, &t!("unofficial_source_edit_dialog_add_edit").to_string(),
); );
unofficial_source_add_dialog.set_response_appearance( unofficial_source_add_dialog.add_response(
"unofficial_source_edit_dialog_edit", "unofficial_source_add_dialog_cancel",
adw::ResponseAppearance::Suggested, &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(); unofficial_source_add_dialog.set_response_appearance(
let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone(); "unofficial_source_add_dialog_cancel",
let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone(); adw::ResponseAppearance::Destructive,
let unofficial_source_add_components_entry_clone0 = unofficial_source_add_components_entry.clone(); );
let add_button_update_state = move || { unofficial_source_add_dialog.set_response_appearance(
if "unofficial_source_edit_dialog_edit",
!unofficial_source_add_uri_entry_clone0.text().is_empty() && adw::ResponseAppearance::Suggested,
!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 [ let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone();
&unofficial_source_add_uri_entry, let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone();
&unofficial_source_add_suites_entry, let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone();
&unofficial_source_add_components_entry, let unofficial_source_add_components_entry_clone0 =
&unofficial_source_add_legacy_options_entry, unofficial_source_add_components_entry.clone();
] {
entry.connect_text_notify(clone!( let add_button_update_state = move || {
#[strong] if !unofficial_source_add_uri_entry_clone0.text().is_empty()
add_button_update_state, && !unofficial_source_add_suites_entry_clone0.text().is_empty()
move |_| && !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(); 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",
unofficial_source_add_box2.append(&unofficial_source_add_is_source_label); &t!("apt_src_create_error_dialog_ok_label").to_string(),
unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch); );
unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label); apt_src_create_error_dialog.present();
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);
}
}
} }
_ => {} }
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);
}
}
}
_ => {}
}
});
}

View File

@ -1,22 +1,12 @@
use crate::apt_package_row::AptPackageRow;
use add_dialog::add_dialog_fn;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use apt_deb822_tools::Deb822Repository;
use regex::Regex; use gtk::glib::{clone, BoxedAnyObject};
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*; use gtk::*;
use std::cell::Ref; 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::cell::RefCell;
use std::process::Command; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
use std::thread;
use tokio::runtime::Runtime;
mod add_dialog; mod add_dialog;
mod deb822_edit_dialog; mod deb822_edit_dialog;
@ -24,7 +14,7 @@ mod legacy_edit_dialog;
enum AptSourceConfig { enum AptSourceConfig {
Legacy(apt_legacy_tools::LegacyAptSource), Legacy(apt_legacy_tools::LegacyAptSource),
DEB822(apt_deb822_tools::Deb822Repository) DEB822(apt_deb822_tools::Deb822Repository),
} }
pub fn apt_manage_page( pub fn apt_manage_page(
@ -35,16 +25,22 @@ pub fn apt_manage_page(
let deb822_sources = Deb822Repository::get_deb822_sources().unwrap(); let deb822_sources = Deb822Repository::get_deb822_sources().unwrap();
let system_source = deb822_sources.iter().filter(|x| { let system_source = deb822_sources
match &x.repolib_id { .iter()
Some(t) => { .filter(|x| match &x.repolib_id {
t == "system" Some(t) => t == "system",
} None => false,
None => false })
} .next()
}).next().unwrap(); .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() let main_box = Box::builder()
.hexpand(true) .hexpand(true)
@ -105,7 +101,9 @@ pub fn apt_manage_page(
#[strong] #[strong]
system_mirror_refcell, system_mirror_refcell,
move |entry| { 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())), uris: (Some(system_mirror_entry.text().to_string())),
..system_source.clone() ..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(_) => { 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(_) => { Ok(_) => {
retry_signal_action.activate(None); 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); button.set_sensitive(false);
} }
Err(e) => { Err(e) => {
@ -139,7 +149,7 @@ pub fn apt_manage_page(
apt_src_create_error_dialog.add_response( apt_src_create_error_dialog.add_response(
"apt_src_create_error_dialog_ok", "apt_src_create_error_dialog_ok",
&t!("apt_src_create_error_dialog_ok_label").to_string(), &t!("apt_src_create_error_dialog_ok_label").to_string(),
); );
apt_src_create_error_dialog.present(); apt_src_create_error_dialog.present();
retry_signal_action.activate(None); 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.add_response(
"apt_src_create_error_dialog_ok", "apt_src_create_error_dialog_ok",
&t!("apt_src_create_error_dialog_ok_label").to_string(), &t!("apt_src_create_error_dialog_ok_label").to_string(),
); );
apt_src_create_error_dialog.present(); apt_src_create_error_dialog.present();
} }
} }
@ -182,91 +192,84 @@ pub fn apt_manage_page(
.margin_end(15) .margin_end(15)
.build(); .build();
let unofficial_sources_selection_model_rc: Rc<RefCell<gtk::SingleSelection>> = Rc::new(RefCell::default()); let unofficial_sources_selection_model_rc: Rc<RefCell<gtk::SingleSelection>> =
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 = adw::Bin::new();
let unofficial_sources_columnview_bin_clone0 = unofficial_sources_columnview_bin.clone(); let unofficial_sources_columnview_bin_clone0 = unofficial_sources_columnview_bin.clone();
retry_signal_action.connect_activate(clone!( retry_signal_action.connect_activate(clone!(
#[weak] #[weak]
unofficial_sources_columnview_bin_clone0, unofficial_sources_columnview_bin_clone0,
move |_, _| { 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| { unofficial_deb822_sources.retain(|x| match &x.repolib_id {
match &x.repolib_id { Some(t) => !(t == "system"),
Some(t) => { None => true,
!(t == "system")
}
None => true
}
}); });
let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources();
let unofficial_sources_list_store = gio::ListStore::new::<BoxedAnyObject>(); let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources();
for deb822_source in unofficial_deb822_sources { let unofficial_sources_list_store = gio::ListStore::new::<BoxedAnyObject>();
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source)));
};
match legacy_apt_repos { for deb822_source in unofficial_deb822_sources {
Ok(vec) => { unofficial_sources_list_store
for legacy_repo in vec { .append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source)));
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::Legacy(legacy_repo)));
};
} }
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() (*unofficial_sources_selection_model_rc_clone0.borrow_mut() =
.vexpand(true) unofficial_sources_selection_model.clone());
.model(&unofficial_sources_selection_model)
.build();
// let unofficial_sources_columnview = ColumnView::builder()
.vexpand(true)
let unofficial_sources_columnview_factory0 = gtk::SignalListItemFactory::new(); .model(&unofficial_sources_selection_model)
unofficial_sources_columnview_factory0.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
let row = Label::builder()
.halign(Align::Start)
.build(); .build();
item.set_child(Some(&row));
});
unofficial_sources_columnview_factory0.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap(); let unofficial_sources_columnview_factory0 = gtk::SignalListItemFactory::new();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<AptSourceConfig>(); unofficial_sources_columnview_factory0.connect_setup(move |_factory, item| {
let repo_name = match entry_borrow.deref() { let item = item.downcast_ref::<gtk::ListItem>().unwrap();
AptSourceConfig::DEB822(src) => { let row = Label::builder().halign(Align::Start).build();
match &src.repolib_name { item.set_child(Some(&row));
});
unofficial_sources_columnview_factory0.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<AptSourceConfig>();
let repo_name = match entry_borrow.deref() {
AptSourceConfig::DEB822(src) => match &src.repolib_name {
Some(name) => name, Some(name) => name,
None => match(&src.uris, &src.suites, &src.components) { None => match (&src.uris, &src.suites, &src.components) {
(Some(uris),Some(suites),Some(components)) => { (Some(uris), Some(suites), Some(components)) => {
&format!("{} {} {}", uris, suites, components) &format!("{} {} {}", uris, suites, components)
} }
(_,_,_) => { (_, _, _) => &t!("apt_source_parse_error").to_string(),
&t!("apt_source_parse_error").to_string() },
} },
} AptSourceConfig::Legacy(src) => &format!(
"{} {} {} {}",
}
}
AptSourceConfig::Legacy(src) => {
&format!("{} {} {} {}",
if src.is_source { if src.is_source {
"(Legacy Src)" "(Legacy Src)"
} else { } else {
@ -275,69 +278,64 @@ pub fn apt_manage_page(
&src.url, &src.url,
&src.suite, &src.suite,
&src.components &src.components
) ),
} };
}; child.set_label(&repo_name);
child.set_label(&repo_name); });
});
let unofficial_sources_columnview_col0 = gtk::ColumnViewColumn::builder()
.title(t!("unofficial_sources_columnview_col0_title"))
.factory(&unofficial_sources_columnview_factory0)
.expand(true)
.build();
// let unofficial_sources_columnview_col0 = gtk::ColumnViewColumn::builder()
.title(t!("unofficial_sources_columnview_col0_title"))
let unofficial_sources_columnview_factory1 = gtk::SignalListItemFactory::new(); .factory(&unofficial_sources_columnview_factory0)
.expand(true)
unofficial_sources_columnview_factory1.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
let row = Label::builder()
.halign(Align::Start)
.build(); .build();
item.set_child(Some(&row));
});
unofficial_sources_columnview_factory1.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap(); let unofficial_sources_columnview_factory1 = gtk::SignalListItemFactory::new();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<AptSourceConfig>(); unofficial_sources_columnview_factory1.connect_setup(move |_factory, item| {
let repo_enabled = match entry_borrow.deref() { let item = item.downcast_ref::<gtk::ListItem>().unwrap();
AptSourceConfig::DEB822(src) => { let row = Label::builder().halign(Align::Start).build();
match &src.enabled { item.set_child(Some(&row));
});
unofficial_sources_columnview_factory1.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<AptSourceConfig>();
let repo_enabled = match entry_borrow.deref() {
AptSourceConfig::DEB822(src) => match &src.enabled {
Some(t) => match t.to_lowercase().as_str() { Some(t) => match t.to_lowercase().as_str() {
"yes" => true, "yes" => true,
"true" => true, "true" => true,
"no" => false, "no" => false,
"false" => false, "false" => false,
_ => true, _ => true,
} },
None => true, None => true,
} },
AptSourceConfig::Legacy(src) => src.enabled,
};
if repo_enabled {
child.set_label(&t!("apt_repo_enabled"));
} else {
child.set_label(&t!("apt_repo_disabled"));
} }
AptSourceConfig::Legacy(src) => { });
src.enabled
}
};
if repo_enabled {
child.set_label(&t!("apt_repo_enabled"));
} else {
child.set_label(&t!("apt_repo_disabled"));
}
});
let unofficial_sources_columnview_col1 = gtk::ColumnViewColumn::builder()
.title(t!("unofficial_sources_columnview_col1_title"))
.factory(&unofficial_sources_columnview_factory1)
.build();
// let unofficial_sources_columnview_col1 = gtk::ColumnViewColumn::builder()
unofficial_sources_columnview.append_column(&unofficial_sources_columnview_col0); .title(t!("unofficial_sources_columnview_col1_title"))
unofficial_sources_columnview.append_column(&unofficial_sources_columnview_col1); .factory(&unofficial_sources_columnview_factory1)
unofficial_sources_columnview_bin_clone0.set_child(Some(&unofficial_sources_columnview)); .build();
}));
//
unofficial_sources_columnview.append_column(&unofficial_sources_columnview_col0);
unofficial_sources_columnview.append_column(&unofficial_sources_columnview_col1);
unofficial_sources_columnview_bin_clone0
.set_child(Some(&unofficial_sources_columnview));
}
));
retry_signal_action.activate(None); retry_signal_action.activate(None);
@ -398,17 +396,14 @@ pub fn apt_manage_page(
retry_signal_action, retry_signal_action,
#[strong] #[strong]
apt_retry_signal_action, apt_retry_signal_action,
move move |_| {
|_| add_dialog::add_dialog_fn(
{ window.clone(),
add_dialog::add_dialog_fn( &retry_signal_action,
window.clone(), &apt_retry_signal_action,
&retry_signal_action, );
&apt_retry_signal_action }
); ));
}
)
);
unofficial_source_edit_button.connect_clicked(clone!( unofficial_source_edit_button.connect_clicked(clone!(
#[strong] #[strong]
@ -419,25 +414,29 @@ pub fn apt_manage_page(
retry_signal_action, retry_signal_action,
#[strong] #[strong]
apt_retry_signal_action, apt_retry_signal_action,
move move |_| {
|_| let unofficial_sources_selection_model = unofficial_sources_selection_model_rc.borrow();
{ let selection = unofficial_sources_selection_model.selected_item().unwrap();
let unofficial_sources_selection_model = unofficial_sources_selection_model_rc.borrow(); let item = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let selection = unofficial_sources_selection_model.selected_item().unwrap(); let apt_src: Ref<AptSourceConfig> = item.borrow();
let item = selection.downcast_ref::<BoxedAnyObject>().unwrap(); match apt_src.deref() {
let apt_src: Ref<AptSourceConfig> = item.borrow(); AptSourceConfig::DEB822(src) => {
match apt_src.deref() { deb822_edit_dialog::deb822_edit_dialog_fn(
AptSourceConfig::DEB822(src) => { window.clone(),
deb822_edit_dialog::deb822_edit_dialog_fn(window.clone(), src, &retry_signal_action, &apt_retry_signal_action); src,
} &retry_signal_action,
AptSourceConfig::Legacy(list) => { &apt_retry_signal_action,
legacy_edit_dialog::legacy_edit_dialog_fn(window.clone(), list, &retry_signal_action, &apt_retry_signal_action) );
} }
}; AptSourceConfig::Legacy(list) => legacy_edit_dialog::legacy_edit_dialog_fn(
window.clone(),
} list,
) &retry_signal_action,
); &apt_retry_signal_action,
),
};
}
));
unofficial_source_remove_button.connect_clicked(clone!( unofficial_source_remove_button.connect_clicked(clone!(
#[strong] #[strong]
@ -448,73 +447,90 @@ pub fn apt_manage_page(
retry_signal_action, retry_signal_action,
#[strong] #[strong]
apt_retry_signal_action, apt_retry_signal_action,
move move |_| {
|_|
{ {
let mut _command = duct::cmd!("");
{ {
let mut command = duct::cmd!(""); let unofficial_sources_selection_model =
{ unofficial_sources_selection_model_rc.borrow();
let unofficial_sources_selection_model = unofficial_sources_selection_model_rc.borrow();
let selection = unofficial_sources_selection_model.selected_item().unwrap(); let selection = unofficial_sources_selection_model.selected_item().unwrap();
let item = selection.downcast_ref::<BoxedAnyObject>().unwrap(); let item = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let apt_src: Ref<AptSourceConfig> = item.borrow(); let apt_src: Ref<AptSourceConfig> = item.borrow();
match apt_src.deref() { match apt_src.deref() {
AptSourceConfig::DEB822(src) => { AptSourceConfig::DEB822(src) => {
match &src.signed_by { match &src.signed_by {
Some(t) => {command = duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_deb822", &src.filepath, t)} Some(t) => _command = duct::cmd!(
None => {command = duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_legacy", &src.filepath)} "pkexec",
"/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh",
"delete_deb822",
&src.filepath,
t
),
None => _command = duct::cmd!(
"pkexec",
"/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh",
"delete_legacy",
&src.filepath
),
} }
} }
AptSourceConfig::Legacy(list) => {command = duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_legacy", &list.filepath)} AptSourceConfig::Legacy(list) => {
_command = duct::cmd!(
"pkexec",
"/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh",
"delete_legacy",
&list.filepath
)
}
}; };
}
let apt_src_remove_warning_dialog = adw::MessageDialog::builder()
.heading(t!("apt_src_remove_warning_dialog_heading"))
.body(t!("apt_src_remove_warning_dialog_body"))
.transient_for(&window)
.build();
apt_src_remove_warning_dialog.add_response(
"apt_src_remove_warning_dialog_cancel",
&t!("apt_src_remove_warning_dialog_cancel_label").to_string(),
);
apt_src_remove_warning_dialog.add_response(
"apt_src_remove_warning_dialog_ok",
&t!("apt_src_remove_warning_dialog_ok_label").to_string(),
);
apt_src_remove_warning_dialog.set_response_appearance("apt_src_remove_warning_dialog_ok", adw::ResponseAppearance::Destructive);
let retry_signal_action_clone0 = retry_signal_action.clone();
let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone();
apt_src_remove_warning_dialog.clone()
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"apt_src_remove_warning_dialog_ok" => {
match command.run() {
Ok(_) => {
retry_signal_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();
retry_signal_action_clone0.activate(None);
apt_retry_signal_action_clone0.activate(None)
}
}
}
_ => {}
}
});
} }
let apt_src_remove_warning_dialog = adw::MessageDialog::builder()
.heading(t!("apt_src_remove_warning_dialog_heading"))
.body(t!("apt_src_remove_warning_dialog_body"))
.transient_for(&window)
.build();
apt_src_remove_warning_dialog.add_response(
"apt_src_remove_warning_dialog_cancel",
&t!("apt_src_remove_warning_dialog_cancel_label").to_string(),
);
apt_src_remove_warning_dialog.add_response(
"apt_src_remove_warning_dialog_ok",
&t!("apt_src_remove_warning_dialog_ok_label").to_string(),
);
apt_src_remove_warning_dialog.set_response_appearance(
"apt_src_remove_warning_dialog_ok",
adw::ResponseAppearance::Destructive,
);
let retry_signal_action_clone0 = retry_signal_action.clone();
let apt_retry_signal_action_clone0 = apt_retry_signal_action.clone();
apt_src_remove_warning_dialog.clone().choose(
None::<&gio::Cancellable>,
move |choice| match choice.as_str() {
"apt_src_remove_warning_dialog_ok" => match _command.run() {
Ok(_) => {
retry_signal_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();
retry_signal_action_clone0.activate(None);
apt_retry_signal_action_clone0.activate(None)
}
},
_ => {}
},
);
} }
) }
); ));
// //
@ -539,4 +555,4 @@ pub fn apt_manage_page(
main_box.append(&unofficial_sources_viewport); main_box.append(&unofficial_sources_viewport);
main_box main_box
} }

View File

@ -66,9 +66,7 @@ pub fn apt_update_page(
thread::spawn(move || { thread::spawn(move || {
let apt_update_command = Command::new("pkexec") let apt_update_command = Command::new("pkexec")
.args([ .args(["/usr/lib/pika/pikman-update-manager/scripts/apt_update"])
"/usr/lib/pika/pikman-update-manager/scripts/apt_update",
])
.status() .status()
.unwrap(); .unwrap();
match apt_update_command.code().unwrap() { match apt_update_command.code().unwrap() {
@ -134,7 +132,7 @@ pub fn apt_update_page(
.title(t!("apt_ignored_viewport_page_title")) .title(t!("apt_ignored_viewport_page_title"))
.hexpand(true) .hexpand(true)
.vexpand(true) .vexpand(true)
.build(); .build();
let viewport_bin = adw::Bin::builder() let viewport_bin = adw::Bin::builder()
.child(&packages_no_viewport_page) .child(&packages_no_viewport_page)
@ -182,8 +180,6 @@ pub fn apt_update_page(
apt_update_dialog.set_response_enabled("apt_update_dialog_retry", false); apt_update_dialog.set_response_enabled("apt_update_dialog_retry", false);
apt_update_dialog.set_response_enabled("apt_update_dialog_ignore", false); apt_update_dialog.set_response_enabled("apt_update_dialog_ignore", false);
if window.is_visible() { if window.is_visible() {
let retry_signal_action0 = retry_signal_action.clone(); let retry_signal_action0 = retry_signal_action.clone();
let viewport_bin = viewport_bin.clone(); let viewport_bin = viewport_bin.clone();
@ -455,7 +451,10 @@ pub fn apt_update_page(
(*apt_update_count.borrow_mut() += 1); (*apt_update_count.borrow_mut() += 1);
if state.is_last { if state.is_last {
packages_boxedlist.set_sensitive(true); packages_boxedlist.set_sensitive(true);
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[*apt_update_count.borrow(),*flatpak_update_count.borrow()]))); update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[
*apt_update_count.borrow(),
*flatpak_update_count.borrow(),
])));
} }
} }
} }

View File

@ -412,9 +412,7 @@ fn apt_full_upgrade_from_socket(
thread::spawn(move || { thread::spawn(move || {
let apt_upgrade_command = Command::new("pkexec") let apt_upgrade_command = Command::new("pkexec")
.args([ .args(["/usr/lib/pika/pikman-update-manager/scripts/apt_full_upgrade"])
"/usr/lib/pika/pikman-update-manager/scripts/apt_full_upgrade",
])
.status() .status()
.unwrap(); .unwrap();
match apt_upgrade_command.code().unwrap() { match apt_upgrade_command.code().unwrap() {

View File

@ -1,22 +1,17 @@
use crate::apt_manage_page::apt_manage_page; use crate::apt_manage_page::apt_manage_page;
use crate::flatpak_manage_page::flatpak_manage_page;
use crate::apt_update_page; use crate::apt_update_page;
use crate::config::{APP_GITHUB, APP_ICON, APP_ID, VERSION}; use crate::config::{APP_GITHUB, APP_ICON, APP_ID, VERSION};
use crate::flatpak_manage_page::flatpak_manage_page;
use crate::flatpak_update_page; use crate::flatpak_update_page;
use adw::prelude::*; use adw::prelude::*;
use adw::*; use adw::*;
use async_channel::Sender;
use futures::task::SpawnExt;
use gtk::glib::{clone, MainContext}; use gtk::glib::{clone, MainContext};
use gtk::{License, WindowControls}; use gtk::{License, WindowControls};
use ksni;
use std::cell::RefCell; use std::cell::RefCell;
use std::ops::Index;
use std::process::Command; use std::process::Command;
use std::rc::Rc; use std::rc::Rc;
use std::sync::atomic::AtomicBool;
use std::thread; use std::thread;
use std::sync::Arc;
use ksni;
#[derive(Debug)] #[derive(Debug)]
struct PikmanTray { struct PikmanTray {
@ -30,11 +25,11 @@ impl ksni::Tray for PikmanTray {
fn icon_name(&self) -> String { fn icon_name(&self) -> String {
match &self.icon_name { match &self.icon_name {
Some(t) => t.into(), Some(t) => t.into(),
None => "help-about".into() None => "help-about".into(),
} }
} }
fn title(&self) -> String { fn title(&self) -> String {
t!("application_name").to_string() t!("application_name").to_string()
} }
// NOTE: On some system trays, `id` is a required property to avoid unexpected behaviors // NOTE: On some system trays, `id` is a required property to avoid unexpected behaviors
fn id(&self) -> String { fn id(&self) -> String {
@ -46,8 +41,9 @@ impl ksni::Tray for PikmanTray {
StandardItem { StandardItem {
label: match &self.apt_item_label { label: match &self.apt_item_label {
Some(t) => t, Some(t) => t,
None => "?" None => "?",
}.into(), }
.into(),
icon_name: "application-vnd.debian.binary-package".into(), icon_name: "application-vnd.debian.binary-package".into(),
enabled: false, enabled: false,
..Default::default() ..Default::default()
@ -56,8 +52,9 @@ impl ksni::Tray for PikmanTray {
StandardItem { StandardItem {
label: match &self.flatpak_item_label { label: match &self.flatpak_item_label {
Some(t) => t, Some(t) => t,
None => "?" None => "?",
}.into(), }
.into(),
icon_name: "application-vnd.flatpak".into(), icon_name: "application-vnd.flatpak".into(),
enabled: false, enabled: false,
..Default::default() ..Default::default()
@ -68,7 +65,9 @@ impl ksni::Tray for PikmanTray {
label: t!("pikman_indicator_open_item_label").into(), label: t!("pikman_indicator_open_item_label").into(),
icon_name: "view-paged-symbolic".into(), icon_name: "view-paged-symbolic".into(),
activate: Box::new(|_| { activate: Box::new(|_| {
self.action_sender.send_blocking(String::from("open")).unwrap() self.action_sender
.send_blocking(String::from("open"))
.unwrap()
}), }),
..Default::default() ..Default::default()
} }
@ -111,13 +110,13 @@ pub fn build_ui(app: &Application) {
flatpak_item_label: None, flatpak_item_label: None,
}); });
let tray_handle = tray_service.handle(); let tray_handle = tray_service.handle();
tray_service.spawn(); tray_service.spawn();
update_sys_tray.connect_activate(clone!( update_sys_tray.connect_activate(clone!(
#[strong] #[strong]
tray_handle, tray_handle,
move |_,param| { move |_, param| {
let array: &[i32] = param.unwrap().fixed_array().unwrap(); let array: &[i32] = param.unwrap().fixed_array().unwrap();
let vec = array.to_vec(); let vec = array.to_vec();
let apt_update_count = vec[0]; let apt_update_count = vec[0];
@ -129,35 +128,36 @@ pub fn build_ui(app: &Application) {
}; };
tray_handle.update(|tray: &mut PikmanTray| { tray_handle.update(|tray: &mut PikmanTray| {
tray.icon_name = tray_icon; tray.icon_name = tray_icon;
tray.apt_item_label = Some(strfmt::strfmt( tray.apt_item_label = Some(
&t!("pikman_indicator_apt_count_item_label").to_string(), strfmt::strfmt(
&std::collections::HashMap::from([ &t!("pikman_indicator_apt_count_item_label").to_string(),
( &std::collections::HashMap::from([(
"NUM".to_string(), "NUM".to_string(),
match apt_update_count { match apt_update_count {
-1 => t!("pikman_indicator_flatpak_item_label_calculating").into(), -1 => t!("pikman_indicator_flatpak_item_label_calculating").into(),
_ => apt_update_count.to_string(), _ => apt_update_count.to_string(),
}, },
), )]),
]), )
) .unwrap(),
.unwrap()); );
tray.flatpak_item_label = Some(strfmt::strfmt( tray.flatpak_item_label = Some(
&t!("pikman_indicator_flatpak_count_item_label").to_string(), strfmt::strfmt(
&std::collections::HashMap::from([ &t!("pikman_indicator_flatpak_count_item_label").to_string(),
( &std::collections::HashMap::from([(
"NUM".to_string(), "NUM".to_string(),
match flatpak_update_count { match flatpak_update_count {
-1 => t!("pikman_indicator_flatpak_item_label_calculating").into(), -1 => t!("pikman_indicator_flatpak_item_label_calculating").into(),
_ => flatpak_update_count.to_string(), _ => flatpak_update_count.to_string(),
}, },
), )]),
]), )
) .unwrap(),
.unwrap()); );
}); });
})); }
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[-1,-1]))); ));
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[-1, -1])));
thread::spawn(move || loop { thread::spawn(move || loop {
match Command::new("ping").arg("google.com").arg("-c 1").output() { match Command::new("ping").arg("google.com").arg("-c 1").output() {
@ -228,16 +228,27 @@ pub fn build_ui(app: &Application) {
.margin_end(5) .margin_end(5)
.hexpand(true) .hexpand(true)
.build(); .build();
window_adw_view_switcher_sidebar_control_box.append(&WindowControls::builder().halign(gtk::Align::Start).valign(gtk::Align::Center).build()); window_adw_view_switcher_sidebar_control_box.append(
window_adw_view_switcher_sidebar_control_box.append(&WindowTitle::builder().halign(gtk::Align::Center).margin_top(10).margin_bottom(20).valign(gtk::Align::Center).hexpand(true).title(t!("application_name")).build()); &WindowControls::builder()
.halign(gtk::Align::Start)
.valign(gtk::Align::Center)
.build(),
);
window_adw_view_switcher_sidebar_control_box.append(
&WindowTitle::builder()
.halign(gtk::Align::Center)
.margin_top(10)
.margin_bottom(20)
.valign(gtk::Align::Center)
.hexpand(true)
.title(t!("application_name"))
.build(),
);
let window_adw_view_switcher_sidebar_box = gtk::Box::new(gtk::Orientation::Vertical, 0); let window_adw_view_switcher_sidebar_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
window_adw_view_switcher_sidebar_box.append(&window_adw_view_switcher_sidebar_control_box); window_adw_view_switcher_sidebar_box.append(&window_adw_view_switcher_sidebar_control_box);
let null_toggle_button: gtk::ToggleButton = gtk::ToggleButton::new();
let window_adw_stack_clone0 = window_adw_stack.clone(); let null_toggle_button: gtk::ToggleButton = gtk::ToggleButton::new();
let window_adw_view_switcher_sidebar_box_clone0 = window_adw_view_switcher_sidebar_box.clone();
let sidebar_toggle_button = gtk::ToggleButton::builder() let sidebar_toggle_button = gtk::ToggleButton::builder()
.icon_name("view-right-pane-symbolic") .icon_name("view-right-pane-symbolic")
@ -266,16 +277,8 @@ pub fn build_ui(app: &Application) {
"collapsed", "collapsed",
Some(&true.to_value()), Some(&true.to_value()),
); );
window_breakpoint.add_setter( window_breakpoint.add_setter(&sidebar_toggle_button, "visible", Some(&true.to_value()));
&sidebar_toggle_button, window_breakpoint.add_setter(&window_headerbar, "show_title", Some(&true.to_value()));
"visible",
Some(&true.to_value()),
);
window_breakpoint.add_setter(
&window_headerbar,
"show_title",
Some(&true.to_value()),
);
window_headerbar.pack_end(&sidebar_toggle_button); window_headerbar.pack_end(&sidebar_toggle_button);
@ -312,12 +315,10 @@ pub fn build_ui(app: &Application) {
} }
window.connect_close_request(move |window| { window.connect_close_request(move |window| {
if let Some(application) = window.application() { let size = window.default_size();
let size = window.default_size(); let _ = glib_settings.set_int("window-width", size.0);
let _ = glib_settings.set_int("window-width", size.0); let _ = glib_settings.set_int("window-height", size.1);
let _ = glib_settings.set_int("window-height", size.1); let _ = glib_settings.set_boolean("is-maximized", window.is_maximized());
let _ = glib_settings.set_boolean("is-maximized", window.is_maximized());
}
glib::Propagation::Proceed glib::Propagation::Proceed
}); });
@ -353,8 +354,7 @@ pub fn build_ui(app: &Application) {
let flatpak_retry_signal_action = gio::SimpleAction::new("retry", None); let flatpak_retry_signal_action = gio::SimpleAction::new("retry", None);
let flatpak_update_view_stack_bin = Bin::builder() let flatpak_update_view_stack_bin = Bin::builder().build();
.build();
flatpak_retry_signal_action.connect_activate(clone!( flatpak_retry_signal_action.connect_activate(clone!(
#[weak] #[weak]
@ -370,13 +370,15 @@ pub fn build_ui(app: &Application) {
#[strong] #[strong]
flatpak_update_count, flatpak_update_count,
move |_, _| { move |_, _| {
flatpak_update_view_stack_bin.set_child(Some(&flatpak_update_page::flatpak_update_page( flatpak_update_view_stack_bin.set_child(Some(
window, &flatpak_update_page::flatpak_update_page(
&flatpak_retry_signal_action, window,
&update_sys_tray, &flatpak_retry_signal_action,
&apt_update_count, &update_sys_tray,
&flatpak_update_count, &apt_update_count,
))); &flatpak_update_count,
),
));
} }
)); ));
@ -388,34 +390,34 @@ pub fn build_ui(app: &Application) {
let apt_update_view_stack_bin = Bin::builder().build(); let apt_update_view_stack_bin = Bin::builder().build();
apt_retry_signal_action.connect_activate(clone!( apt_retry_signal_action.connect_activate(clone!(
#[weak] #[weak]
window, window,
#[strong] #[strong]
apt_retry_signal_action, apt_retry_signal_action,
#[strong] #[strong]
flatpak_retry_signal_action, flatpak_retry_signal_action,
#[strong] #[strong]
apt_update_view_stack_bin, apt_update_view_stack_bin,
#[weak] #[weak]
flatpak_ran_once, flatpak_ran_once,
#[strong] #[strong]
update_sys_tray, update_sys_tray,
#[strong] #[strong]
apt_update_count, apt_update_count,
#[strong] #[strong]
flatpak_update_count, flatpak_update_count,
move |_, _| { move |_, _| {
apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page( apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page(
window, window,
&apt_retry_signal_action, &apt_retry_signal_action,
&flatpak_retry_signal_action, &flatpak_retry_signal_action,
flatpak_ran_once, flatpak_ran_once,
&update_sys_tray, &update_sys_tray,
&apt_update_count, &apt_update_count,
&flatpak_update_count, &flatpak_update_count,
))); )));
} }
)); ));
apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page( apt_update_view_stack_bin.set_child(Some(&apt_update_page::apt_update_page(
window.clone(), window.clone(),
@ -435,7 +437,13 @@ pub fn build_ui(app: &Application) {
&t!("apt_update_page_title"), &t!("apt_update_page_title"),
); );
let apt_update_page_toggle_button = add_content_button(&window_adw_stack, true, "apt_update_page".to_string(), t!("apt_update_page_title").to_string(), &null_toggle_button); let apt_update_page_toggle_button = add_content_button(
&window_adw_stack,
true,
"apt_update_page".to_string(),
t!("apt_update_page_title").to_string(),
&null_toggle_button,
);
window_adw_view_switcher_sidebar_box.append(&apt_update_page_toggle_button); window_adw_view_switcher_sidebar_box.append(&apt_update_page_toggle_button);
window_adw_stack.add_titled( window_adw_stack.add_titled(
@ -444,7 +452,13 @@ pub fn build_ui(app: &Application) {
&t!("flatpak_update_page_title"), &t!("flatpak_update_page_title"),
); );
let flatpak_update_page_toggle_button = add_content_button(&window_adw_stack, false, "flatpak_update_page".to_string(), t!("flatpak_update_page_title").to_string(), &null_toggle_button); let flatpak_update_page_toggle_button = add_content_button(
&window_adw_stack,
false,
"flatpak_update_page".to_string(),
t!("flatpak_update_page_title").to_string(),
&null_toggle_button,
);
window_adw_view_switcher_sidebar_box.append(&flatpak_update_page_toggle_button); window_adw_view_switcher_sidebar_box.append(&flatpak_update_page_toggle_button);
window_adw_stack.add_titled( window_adw_stack.add_titled(
@ -453,10 +467,17 @@ pub fn build_ui(app: &Application) {
&t!("apt_manage_page_title"), &t!("apt_manage_page_title"),
); );
let apt_manage_page_toggle_button = add_content_button(&window_adw_stack, false, "apt_manage_page".to_string(), t!("apt_manage_page_title").to_string(), &null_toggle_button); let apt_manage_page_toggle_button = add_content_button(
&window_adw_stack,
false,
"apt_manage_page".to_string(),
t!("apt_manage_page_title").to_string(),
&null_toggle_button,
);
window_adw_view_switcher_sidebar_box.append(&apt_manage_page_toggle_button); window_adw_view_switcher_sidebar_box.append(&apt_manage_page_toggle_button);
let flatpak_entry_signal_action = gio::SimpleAction::new("entry-change", Some(glib::VariantTy::STRING)); let flatpak_entry_signal_action =
gio::SimpleAction::new("entry-change", Some(glib::VariantTy::STRING));
let flatpak_flatref_install_button = gtk::Button::builder() let flatpak_flatref_install_button = gtk::Button::builder()
.icon_name("document-open-symbolic") .icon_name("document-open-symbolic")
@ -466,12 +487,23 @@ pub fn build_ui(app: &Application) {
.build(); .build();
window_adw_stack.add_titled( window_adw_stack.add_titled(
&flatpak_manage_page(window.clone(), &flatpak_retry_signal_action, &flatpak_entry_signal_action, &flatpak_flatref_install_button), &flatpak_manage_page(
window.clone(),
&flatpak_retry_signal_action,
&flatpak_entry_signal_action,
&flatpak_flatref_install_button,
),
Some("flatpak_manage_page"), Some("flatpak_manage_page"),
&t!("flatpak_manage_page_title"), &t!("flatpak_manage_page_title"),
); );
let flatpak_manage_page_toggle_button = add_content_button(&window_adw_stack, false, "flatpak_manage_page".to_string(), t!("flatpak_manage_page_title").to_string(), &null_toggle_button); let flatpak_manage_page_toggle_button = add_content_button(
&window_adw_stack,
false,
"flatpak_manage_page".to_string(),
t!("flatpak_manage_page_title").to_string(),
&null_toggle_button,
);
window_adw_view_switcher_sidebar_box.append(&flatpak_manage_page_toggle_button); window_adw_view_switcher_sidebar_box.append(&flatpak_manage_page_toggle_button);
app.connect_command_line(clone!( app.connect_command_line(clone!(
@ -486,37 +518,45 @@ pub fn build_ui(app: &Application) {
#[strong] #[strong]
flatpak_entry_signal_action, flatpak_entry_signal_action,
move |_, cmdline| { move |_, cmdline| {
// Create Vec from cmdline // Create Vec from cmdline
let mut gtk_application_args = Vec::new(); let mut gtk_application_args = Vec::new();
for arg in cmdline.arguments() { for arg in cmdline.arguments() {
match arg.to_str() { match arg.to_str() {
Some(a) => gtk_application_args.push(a.to_string()), Some(a) => gtk_application_args.push(a.to_string()),
None => {} None => {}
}
} }
}
// Check for cmd lines // Check for cmd lines
if !(gtk_application_args.contains(&"--hidden".to_string())) && !(gtk_application_args.contains(&"--flatpak-installer".to_string())) && !window.is_visible() { if !(gtk_application_args.contains(&"--hidden".to_string()))
window.present(); && !(gtk_application_args.contains(&"--flatpak-installer".to_string()))
} && !window.is_visible()
{
window.present();
}
if gtk_application_args.contains(&"--software-properties".to_string()) { if gtk_application_args.contains(&"--software-properties".to_string()) {
apt_manage_page_toggle_button.set_active(true); apt_manage_page_toggle_button.set_active(true);
apt_manage_page_toggle_button.emit_clicked(); apt_manage_page_toggle_button.emit_clicked();
} }
if gtk_application_args.contains(&"--flatpak-settings".to_string()) { if gtk_application_args.contains(&"--flatpak-settings".to_string()) {
flatpak_manage_page_toggle_button.set_active(true); flatpak_manage_page_toggle_button.set_active(true);
flatpak_manage_page_toggle_button.emit_clicked(); flatpak_manage_page_toggle_button.emit_clicked();
} }
if gtk_application_args.contains(&"--flatpak-installer".to_string()) { if gtk_application_args.contains(&"--flatpak-installer".to_string()) {
flatpak_flatref_install_button.emit_clicked(); flatpak_flatref_install_button.emit_clicked();
let index = ((gtk_application_args.iter().position(|r| r == "--flatpak-installer").unwrap() as i32) +1) as usize; let index = ((gtk_application_args
flatpak_entry_signal_action.activate(Some(&glib::Variant::from(&gtk_application_args[index]))); .iter()
} .position(|r| r == "--flatpak-installer")
.unwrap() as i32)
0 + 1) as usize;
})); flatpak_entry_signal_action
.activate(Some(&glib::Variant::from(&gtk_application_args[index])));
}
0
}
));
// Refresh button // Refresh button
@ -551,15 +591,20 @@ pub fn build_ui(app: &Application) {
window.present(); window.present();
} }
} }
_ => todo!() _ => todo!(),
} }
} }
} }
)); ));
} }
fn add_content_button(window_adw_stack: &gtk::Stack, active: bool, name: String, title: String, null_toggle_button: &gtk::ToggleButton) -> gtk::ToggleButton { fn add_content_button(
window_adw_stack: &gtk::Stack,
active: bool,
name: String,
title: String,
null_toggle_button: &gtk::ToggleButton,
) -> gtk::ToggleButton {
let toggle_button = gtk::ToggleButton::builder() let toggle_button = gtk::ToggleButton::builder()
.group(null_toggle_button) .group(null_toggle_button)
.label(&title) .label(&title)
@ -571,10 +616,14 @@ fn add_content_button(window_adw_stack: &gtk::Stack, active: bool, name: String,
.valign(gtk::Align::Start) .valign(gtk::Align::Start)
.build(); .build();
toggle_button.add_css_class("flat"); toggle_button.add_css_class("flat");
toggle_button.connect_clicked(clone!(#[weak] window_adw_stack,move |toggle_button| { toggle_button.connect_clicked(clone!(
if toggle_button.is_active() { #[weak]
window_adw_stack.set_visible_child_name(&name); window_adw_stack,
move |toggle_button| {
if toggle_button.is_active() {
window_adw_stack.set_visible_child_name(&name);
}
} }
})); ));
toggle_button toggle_button
} }

View File

@ -1,245 +1,234 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use gtk::glib::clone;
use libflatpak::builders::RemoteRefBuilder;
use regex::{bytes, Regex};
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*; 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 libflatpak::prelude::*;
use libflatpak::InstalledRef;
pub fn add_dialog_fn( pub fn add_dialog_fn(
window: adw::ApplicationWindow, window: adw::ApplicationWindow,
reload_action: &gio::SimpleAction, reload_action: &gio::SimpleAction,
flatpak_retry_signal_action: &SimpleAction, flatpak_retry_signal_action: &SimpleAction,
) ) {
{ let flatpak_remote_add_dialog_child_box = Box::builder()
let flatpak_remote_add_dialog_child_box = Box::builder() .hexpand(true)
.hexpand(true) .orientation(Orientation::Vertical)
.orientation(Orientation::Vertical) .build();
.build();
let flatpak_remote_add_name_entry = gtk::Entry::builder()
.placeholder_text("Flathub")
.build();
let flatpak_remote_add_name_prefrencesgroup = adw::PreferencesGroup::builder() let flatpak_remote_add_name_entry = gtk::Entry::builder().placeholder_text("Flathub").build();
.title(t!("flatpak_remote_add_name_prefrencesgroup_title"))
.build();
flatpak_remote_add_name_prefrencesgroup.add(&flatpak_remote_add_name_entry); let flatpak_remote_add_name_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("flatpak_remote_add_name_prefrencesgroup_title"))
.build();
let flatpak_remote_add_url_entry = gtk::Entry::builder() flatpak_remote_add_name_prefrencesgroup.add(&flatpak_remote_add_name_entry);
.placeholder_text("https://dl.flathub.org/repo/flathub.flatpakrepo")
.build();
let flatpak_remote_add_url_prefrencesgroup = adw::PreferencesGroup::builder() let flatpak_remote_add_url_entry = gtk::Entry::builder()
.title(t!("flatpak_remote_add_url_prefrencesgroup_title")) .placeholder_text("https://dl.flathub.org/repo/flathub.flatpakrepo")
.build(); .build();
flatpak_remote_add_url_prefrencesgroup.add(&flatpak_remote_add_url_entry); let flatpak_remote_add_url_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("flatpak_remote_add_url_prefrencesgroup_title"))
.build();
let flatpak_remote_add_box2 = gtk::Box::builder() flatpak_remote_add_url_prefrencesgroup.add(&flatpak_remote_add_url_entry);
.margin_top(10)
.orientation(Orientation::Horizontal)
.hexpand(true)
.spacing(5)
.build();
let flatpak_remote_user_togglebutton = gtk::ToggleButton::builder() let flatpak_remote_add_box2 = gtk::Box::builder()
.valign(Align::Center) .margin_top(10)
.hexpand(true) .orientation(Orientation::Horizontal)
.label(t!("flatpak_remotes_columnview_user")) .hexpand(true)
.active(true) .spacing(5)
.build(); .build();
let flatpak_remote_system_togglebutton = gtk::ToggleButton::builder() let flatpak_remote_user_togglebutton = gtk::ToggleButton::builder()
.valign(Align::Center) .valign(Align::Center)
.hexpand(true) .hexpand(true)
.label(t!("flatpak_remotes_columnview_system")) .label(t!("flatpak_remotes_columnview_user"))
.group(&flatpak_remote_user_togglebutton) .active(true)
.build(); .build();
// let flatpak_remote_system_togglebutton = gtk::ToggleButton::builder()
let flatpak_remote_add_dialog_child_clamp = adw::Clamp::builder() .valign(Align::Center)
.child(&flatpak_remote_add_dialog_child_box) .hexpand(true)
.maximum_size(500) .label(t!("flatpak_remotes_columnview_system"))
.build(); .group(&flatpak_remote_user_togglebutton)
.build();
let flatpak_remote_add_viewport = gtk::ScrolledWindow::builder() //
.hexpand(true) let flatpak_remote_add_dialog_child_clamp = adw::Clamp::builder()
.vexpand(true) .child(&flatpak_remote_add_dialog_child_box)
.child(&flatpak_remote_add_dialog_child_clamp) .maximum_size(500)
.hscrollbar_policy(PolicyType::Never) .build();
.build();
let flatpak_remote_add_dialog = adw::MessageDialog::builder() let flatpak_remote_add_viewport = gtk::ScrolledWindow::builder()
.transient_for(&window) .hexpand(true)
.extra_child(&flatpak_remote_add_viewport) .vexpand(true)
.heading(t!("flatpak_remote_add_dialog_heading")) .child(&flatpak_remote_add_dialog_child_clamp)
.width_request(700) .hscrollbar_policy(PolicyType::Never)
.height_request(400) .build();
.build();
flatpak_remote_add_dialog.add_response( let flatpak_remote_add_dialog = adw::MessageDialog::builder()
"flatpak_remote_add_dialog_add", .transient_for(&window)
&t!("flatpak_remote_add_dialog_add_label").to_string(), .extra_child(&flatpak_remote_add_viewport)
); .heading(t!("flatpak_remote_add_dialog_heading"))
.width_request(700)
flatpak_remote_add_dialog.add_response( .height_request(400)
"flatpak_remote_add_dialog_cancel", .build();
&t!("flatpak_remote_add_dialog_cancel_label").to_string(),
);
flatpak_remote_add_dialog.set_response_enabled("flatpak_remote_add_dialog_add", false); flatpak_remote_add_dialog.add_response(
"flatpak_remote_add_dialog_add",
flatpak_remote_add_dialog.set_response_appearance( &t!("flatpak_remote_add_dialog_add_label").to_string(),
"flatpak_remote_add_dialog_cancel", );
adw::ResponseAppearance::Destructive,
);
flatpak_remote_add_dialog.set_response_appearance( flatpak_remote_add_dialog.add_response(
"flatpak_remote_add_dialog_add", "flatpak_remote_add_dialog_cancel",
adw::ResponseAppearance::Suggested, &t!("flatpak_remote_add_dialog_cancel_label").to_string(),
); );
// flatpak_remote_add_dialog.set_response_enabled("flatpak_remote_add_dialog_add", false);
let flatpak_remote_add_dialog_clone0 = flatpak_remote_add_dialog.clone(); flatpak_remote_add_dialog.set_response_appearance(
let flatpak_remote_add_name_entry_clone0 = flatpak_remote_add_name_entry.clone(); "flatpak_remote_add_dialog_cancel",
let flatpak_remote_add_url_entry_clone0 = flatpak_remote_add_url_entry.clone(); adw::ResponseAppearance::Destructive,
);
flatpak_remote_add_dialog.set_response_appearance(
"flatpak_remote_add_dialog_add",
adw::ResponseAppearance::Suggested,
);
let add_button_update_state = move || { //
if
!flatpak_remote_add_name_entry_clone0.text().is_empty() &&
!flatpak_remote_add_url_entry_clone0.text().is_empty()
{
flatpak_remote_add_dialog_clone0.set_response_enabled("flatpak_remote_add_dialog_add", true);
} else {
flatpak_remote_add_dialog_clone0.set_response_enabled("flatpak_remote_add_dialog_add", false);
}
};
// let flatpak_remote_add_dialog_clone0 = flatpak_remote_add_dialog.clone();
let flatpak_remote_add_name_entry_clone0 = flatpak_remote_add_name_entry.clone();
let flatpak_remote_add_url_entry_clone0 = flatpak_remote_add_url_entry.clone();
for entry in [ let add_button_update_state = move || {
&flatpak_remote_add_name_entry, if !flatpak_remote_add_name_entry_clone0.text().is_empty()
&flatpak_remote_add_url_entry, && !flatpak_remote_add_url_entry_clone0.text().is_empty()
] { {
entry.connect_text_notify(clone!( flatpak_remote_add_dialog_clone0
#[strong] .set_response_enabled("flatpak_remote_add_dialog_add", true);
add_button_update_state, } else {
move |_| flatpak_remote_add_dialog_clone0
{ .set_response_enabled("flatpak_remote_add_dialog_add", false);
add_button_update_state(); }
} };
)
);
}
//
flatpak_remote_add_box2.append(&flatpak_remote_user_togglebutton);
flatpak_remote_add_box2.append(&flatpak_remote_system_togglebutton);
flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_name_prefrencesgroup); //
flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_url_prefrencesgroup);
flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_box2);
let reload_action_clone0 = reload_action.clone(); for entry in [
let flatpak_retry_signal_action_clone0 = flatpak_retry_signal_action.clone(); &flatpak_remote_add_name_entry,
&flatpak_remote_add_url_entry,
] {
entry.connect_text_notify(clone!(
#[strong]
add_button_update_state,
move |_| {
add_button_update_state();
}
));
}
flatpak_remote_add_dialog.clone() //
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"flatpak_remote_add_dialog_add" => {
let cancellable_no = libflatpak::gio::Cancellable::NONE;
/*let flatpak_installation = match flatpak_remote_system_togglebutton.is_active() { flatpak_remote_add_box2.append(&flatpak_remote_user_togglebutton);
true => libflatpak::Installation::new_system(cancellable_no).unwrap(), flatpak_remote_add_box2.append(&flatpak_remote_system_togglebutton);
false => libflatpak::Installation::new_user(cancellable_no).unwrap(),
};
match libflatpak::Remote::from_file(&flatpak_remote_add_name_entry.text(), &get_data_from_url(&flatpak_remote_add_url_entry.text()).unwrap()) { flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_name_prefrencesgroup);
Ok(remote) => { flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_url_prefrencesgroup);
match libflatpak::Installation::add_remote(&flatpak_installation, &remote, true, cancellable_no) { flatpak_remote_add_dialog_child_box.append(&flatpak_remote_add_box2);
Ok(_) => {
reload_action_clone0.activate(None); let reload_action_clone0 = reload_action.clone();
} let flatpak_retry_signal_action_clone0 = flatpak_retry_signal_action.clone();
Err(e) => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder() flatpak_remote_add_dialog
.heading(t!("flatpak_remote_add_error_dialog_heading")) .clone()
.body(e.to_string()) .choose(None::<&gio::Cancellable>, move |choice| {
.build(); match choice.as_str() {
flatpak_remote_add_error_dialog.add_response( "flatpak_remote_add_dialog_add" => {
"flatpak_remote_add_error_dialog_ok", /*let cancellable_no = libflatpak::gio::Cancellable::NONE;
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
); let flatpak_installation = match flatpak_remote_system_togglebutton.is_active() {
flatpak_remote_add_error_dialog.present(); true => libflatpak::Installation::new_system(cancellable_no).unwrap(),
} false => libflatpak::Installation::new_user(cancellable_no).unwrap(),
} };
}
Err(e) => { match libflatpak::Remote::from_file(&flatpak_remote_add_name_entry.text(), &get_data_from_url(&flatpak_remote_add_url_entry.text()).unwrap()) {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder() Ok(remote) => {
.heading(t!("flatpak_remote_add_error_dialog_heading")) match libflatpak::Installation::add_remote(&flatpak_installation, &remote, true, cancellable_no) {
.body(e.to_string()) Ok(_) => {
.build(); reload_action_clone0.activate(None);
flatpak_remote_add_error_dialog.add_response( }
"flatpak_remote_add_error_dialog_ok", Err(e) => {
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(), let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
); );
} flatpak_remote_add_error_dialog.present();
}*/
let flatpak_installation = match flatpak_remote_system_togglebutton.is_active() {
true => "--system",
false => "--user"
};
match duct::cmd!("flatpak", "remote-add", "--if-not-exists", &flatpak_installation, &flatpak_remote_add_name_entry.text(), &flatpak_remote_add_url_entry.text()).run() {
Ok(_) => {
reload_action_clone0.activate(None);
flatpak_retry_signal_action_clone0.activate(None);
}
Err(e) => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
);
flatpak_remote_add_error_dialog.present();
}
} }
} }
_ => {}
} }
}); Err(e) => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
);
}
}*/
let flatpak_installation = match flatpak_remote_system_togglebutton.is_active()
{
true => "--system",
false => "--user",
};
match duct::cmd!(
"flatpak",
"remote-add",
"--if-not-exists",
&flatpak_installation,
&flatpak_remote_add_name_entry.text(),
&flatpak_remote_add_url_entry.text()
)
.run()
{
Ok(_) => {
reload_action_clone0.activate(None);
flatpak_retry_signal_action_clone0.activate(None);
}
Err(e) => {
let flatpak_remote_add_error_dialog = adw::MessageDialog::builder()
.heading(t!("flatpak_remote_add_error_dialog_heading"))
.body(e.to_string())
.build();
flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
);
flatpak_remote_add_error_dialog.present();
}
}
}
_ => {}
}
});
} }
/* /*
fn get_data_from_url(url: &str) -> Result<libflatpak::glib::Bytes, reqwest::Error> { fn get_data_from_url(url: &str) -> Result<libflatpak::glib::Bytes, reqwest::Error> {
let data = reqwest::blocking::get(url)? let data = reqwest::blocking::get(url)?
.text() .text()
.unwrap(); .unwrap();
let bytes = data.as_bytes(); let bytes = data.as_bytes();
let glib_bytes = libflatpak::glib::Bytes::from(bytes); let glib_bytes = libflatpak::glib::Bytes::from(bytes);
Ok(glib_bytes) Ok(glib_bytes)
}*/ }*/

View File

@ -1,318 +1,332 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use configparser::ini::Ini;
use libflatpak::builders::RemoteRefBuilder; use gtk::glib::{clone, MainContext};
use regex::{bytes, Regex};
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject, MainContext};
use gtk::*; use gtk::*;
use std::cell::Ref; use libflatpak::prelude::*;
use std::ops::Deref; use pretty_bytes::converter::convert;
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::cell::RefCell;
use std::fs::OpenOptions;
use std::io::Write;
use std::ops::Deref;
use std::process::Command; use std::process::Command;
use std::rc::Rc; use std::rc::Rc;
use std::thread; use std::thread;
use tokio::runtime::Runtime;
use libflatpak::prelude::*;
use std::io::Write;
use libflatpak::InstalledRef;
use std::fs::OpenOptions;
use pretty_bytes::converter::convert;
use configparser::ini::Ini;
pub fn install_ref_dialog_fn( pub fn install_ref_dialog_fn(
window: adw::ApplicationWindow, window: adw::ApplicationWindow,
reload_action: &gio::SimpleAction, reload_action: &gio::SimpleAction,
flatpak_retry_signal_action: &SimpleAction, flatpak_retry_signal_action: &SimpleAction,
flatpak_ref_entry_action: &SimpleAction, flatpak_ref_entry_action: &SimpleAction,
) ) {
{ let flatpak_ref_install_dialog_child_box = Box::builder()
let flatpak_ref_install_dialog_child_box = Box::builder() .hexpand(true)
.hexpand(true) .orientation(Orientation::Vertical)
.orientation(Orientation::Vertical) .build();
.build();
let flatpak_ref_install_flatref_path_file_dialog_filter = FileFilter::new(); let flatpak_ref_install_flatref_path_file_dialog_filter = FileFilter::new();
flatpak_ref_install_flatref_path_file_dialog_filter.add_pattern("*.flatpakref"); flatpak_ref_install_flatref_path_file_dialog_filter.add_pattern("*.flatpakref");
#[allow(deprecated)] #[allow(deprecated)]
let flatpak_ref_install_flatref_path_file_dialog = gtk::FileChooserNative::builder() let flatpak_ref_install_flatref_path_file_dialog = gtk::FileChooserNative::builder()
.title(t!("flatpak_ref_install_flatref_path_file_dialog_title")) .title(t!("flatpak_ref_install_flatref_path_file_dialog_title"))
.accept_label(t!("flatpak_ref_install_flatref_path_file_dialog_accept_label")) .accept_label(t!(
.cancel_label(t!("flatpak_ref_install_flatref_path_file_dialog_cancel_label")) "flatpak_ref_install_flatref_path_file_dialog_accept_label"
.action(gtk::FileChooserAction::Open) ))
.filter(&flatpak_ref_install_flatref_path_file_dialog_filter) .cancel_label(t!(
.build(); "flatpak_ref_install_flatref_path_file_dialog_cancel_label"
))
.action(gtk::FileChooserAction::Open)
.filter(&flatpak_ref_install_flatref_path_file_dialog_filter)
.build();
let flatpak_ref_install_flatref_path_entry = gtk::Entry::builder() let flatpak_ref_install_flatref_path_entry = gtk::Entry::builder()
.placeholder_text("/home/andy/Downloads/com.visualstudio.code.flatpakref") .placeholder_text("/home/andy/Downloads/com.visualstudio.code.flatpakref")
.hexpand(true) .hexpand(true)
.build(); .build();
flatpak_ref_entry_action.connect_activate(clone!( flatpak_ref_entry_action.connect_activate(clone!(
#[strong] #[strong]
flatpak_ref_install_flatref_path_entry, flatpak_ref_install_flatref_path_entry,
move |_ , param| move |_, param| {
{ flatpak_ref_install_flatref_path_entry
flatpak_ref_install_flatref_path_entry.set_text(&param.unwrap().get::<String>().unwrap()); .set_text(&param.unwrap().get::<String>().unwrap());
}
));
let flatpak_ref_install_flatref_path_entry_open_file_dialog = gtk::Button::builder()
.tooltip_text(t!(
"flatpak_ref_install_flatref_path_entry_open_file_dialog_text"
))
.halign(gtk::Align::End)
.icon_name("document-open-symbolic")
.build();
let flatpak_ref_install_flatref_path_entry_box = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.hexpand(true)
.build();
flatpak_ref_install_flatref_path_entry_box.add_css_class("linked");
flatpak_ref_install_flatref_path_entry_open_file_dialog.connect_clicked(clone!(
#[strong]
flatpak_ref_install_flatref_path_file_dialog,
move |_| {
flatpak_ref_install_flatref_path_file_dialog.set_visible(true);
}
));
flatpak_ref_install_flatref_path_entry_box.append(&flatpak_ref_install_flatref_path_entry);
flatpak_ref_install_flatref_path_entry_box
.append(&flatpak_ref_install_flatref_path_entry_open_file_dialog);
let flatpak_ref_install_flatref_path_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("flatpak_ref_install_flatref_path_prefrencesgroup_title"))
.build();
#[allow(deprecated)]
flatpak_ref_install_flatref_path_file_dialog.connect_response(clone!(
#[weak]
flatpak_ref_install_flatref_path_entry,
move |dialog, response| {
if response == gtk::ResponseType::Accept {
match dialog.file() {
Some(f) => match f.path() {
Some(p) => {
flatpak_ref_install_flatref_path_entry.set_text(p.to_str().unwrap())
} }
) None => {}
); },
None => {}
let flatpak_ref_install_flatref_path_entry_open_file_dialog = gtk::Button::builder()
.tooltip_text(t!("flatpak_ref_install_flatref_path_entry_open_file_dialog_text"))
.halign(gtk::Align::End)
.icon_name("document-open-symbolic")
.build();
let flatpak_ref_install_flatref_path_entry_box = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.hexpand(true)
.build();
flatpak_ref_install_flatref_path_entry_box.add_css_class("linked");
flatpak_ref_install_flatref_path_entry_open_file_dialog.connect_clicked(clone!(
#[strong]
flatpak_ref_install_flatref_path_file_dialog,
move |_| {
flatpak_ref_install_flatref_path_file_dialog.set_visible(true);
}
));
flatpak_ref_install_flatref_path_entry_box.append(&flatpak_ref_install_flatref_path_entry);
flatpak_ref_install_flatref_path_entry_box.append(&flatpak_ref_install_flatref_path_entry_open_file_dialog);
let flatpak_ref_install_flatref_path_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("flatpak_ref_install_flatref_path_prefrencesgroup_title"))
.build();
#[allow(deprecated)]
flatpak_ref_install_flatref_path_file_dialog.connect_response(
clone!(
#[weak]
flatpak_ref_install_flatref_path_entry,
move |dialog, response|
{
if response == gtk::ResponseType::Accept {
match dialog.file() {
Some(f) => {
match f.path() {
Some(p) => flatpak_ref_install_flatref_path_entry.set_text(p.to_str().unwrap()),
None => {}
}
}
None => {}
}
}
}
)
);
flatpak_ref_install_flatref_path_prefrencesgroup.add(&flatpak_ref_install_flatref_path_entry_box);
let flatpak_ref_install_box2 = gtk::Box::builder()
.margin_top(10)
.orientation(Orientation::Horizontal)
.hexpand(true)
.spacing(5)
.build();
let flatpak_ref_install_label0 = gtk::Label::builder()
.margin_top(10)
.margin_bottom(10)
.build();
let flatpak_remote_user_togglebutton = gtk::ToggleButton::builder()
.valign(Align::Center)
.hexpand(true)
.label(t!("flatpak_remotes_columnview_user"))
.active(true)
.build();
let flatpak_remote_system_togglebutton = gtk::ToggleButton::builder()
.valign(Align::Center)
.hexpand(true)
.label(t!("flatpak_remotes_columnview_system"))
.group(&flatpak_remote_user_togglebutton)
.build();
//
let flatpak_ref_install_dialog_child_clamp = adw::Clamp::builder()
.child(&flatpak_ref_install_dialog_child_box)
.maximum_size(500)
.build();
let flatpak_ref_install_viewport = gtk::ScrolledWindow::builder()
.hexpand(true)
.vexpand(true)
.child(&flatpak_ref_install_dialog_child_clamp)
.hscrollbar_policy(PolicyType::Never)
.build();
let flatpak_ref_install_dialog = adw::MessageDialog::builder()
.transient_for(&window)
.extra_child(&flatpak_ref_install_viewport)
.heading(t!("flatpak_ref_install_dialog_heading"))
.width_request(700)
.height_request(400)
.build();
flatpak_ref_install_flatref_path_file_dialog.set_transient_for(Some(&flatpak_ref_install_dialog));
flatpak_ref_install_dialog.add_response(
"flatpak_ref_install_dialog_add",
&t!("flatpak_ref_install_dialog_add_label").to_string(),
);
flatpak_ref_install_dialog.add_response(
"flatpak_ref_install_dialog_cancel",
&t!("flatpak_ref_install_dialog_cancel_label").to_string(),
);
flatpak_ref_install_dialog.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_dialog.set_response_appearance(
"flatpak_ref_install_dialog_cancel",
adw::ResponseAppearance::Destructive,
);
flatpak_ref_install_dialog.set_response_appearance(
"flatpak_ref_install_dialog_add",
adw::ResponseAppearance::Suggested,
);
//
let flatpak_ref_install_dialog_clone0 = flatpak_ref_install_dialog.clone();
let flatpak_ref_install_flatref_path_entry_clone0 = flatpak_ref_install_flatref_path_entry.clone();
let flatpak_ref_install_label0_clone0 = flatpak_ref_install_label0.clone();
let tbi_remote_name = Rc::new(RefCell::new(None));
let tbi_remote_url = Rc::new(RefCell::new(None));
let tbi_remote_name_clone0 = tbi_remote_name.clone();
let tbi_remote_url_clone0 = tbi_remote_url.clone();
let add_button_update_state = move || {
if
!flatpak_ref_install_flatref_path_entry_clone0.text().is_empty()
{
match std::fs::read_to_string(flatpak_ref_install_flatref_path_entry_clone0.text()) {
Ok(t) => {
let mut flatref_file = Ini::new();
match flatref_file.read(t) {
Ok(_) => {
let ref_name = flatref_file.get("Flatpak Ref", "Name");
let ref_remote_name = flatref_file.get("Flatpak Ref", "SuggestRemoteName");
let ref_remote_url = flatref_file.get("Flatpak Ref", "RuntimeRepo");
match (ref_name, ref_remote_name.clone()) {
(Some(name), Some(remote_name)) => {
flatpak_ref_install_label0_clone0.set_label(&strfmt::strfmt(
&t!("flatpak_ref_install_label").to_string(),
&std::collections::HashMap::from([
(
"NAME".to_string(),
name,
),
(
"REMOTE".to_string(),
remote_name,
),
]),
)
.unwrap());
{
*tbi_remote_name_clone0.borrow_mut() = ref_remote_name;
*tbi_remote_url_clone0.borrow_mut() = ref_remote_url;
}
}
(_, _) => {
flatpak_ref_install_dialog_clone0.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
}
flatpak_ref_install_dialog_clone0.set_response_enabled("flatpak_ref_install_dialog_add", true);
}
Err(_) => {
flatpak_ref_install_dialog_clone0.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
}
}
Err(_) => {
flatpak_ref_install_dialog_clone0.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
}
} else {
flatpak_ref_install_dialog_clone0.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
};
//
for entry in [
&flatpak_ref_install_flatref_path_entry,
] {
entry.connect_text_notify(clone!(
#[strong]
add_button_update_state,
move |_|
{
add_button_update_state();
}
)
);
} }
}
// }
));
flatpak_ref_install_box2.append(&flatpak_remote_user_togglebutton);
flatpak_ref_install_box2.append(&flatpak_remote_system_togglebutton);
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_flatref_path_prefrencesgroup); flatpak_ref_install_flatref_path_prefrencesgroup
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_box2); .add(&flatpak_ref_install_flatref_path_entry_box);
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_label0);
let reload_action_clone0 = reload_action.clone(); let flatpak_ref_install_box2 = gtk::Box::builder()
let flatpak_retry_signal_action_clone0 = flatpak_retry_signal_action.clone(); .margin_top(10)
let flatpak_ref_install_flatref_path_entry_clone0 = flatpak_ref_install_flatref_path_entry.clone(); .orientation(Orientation::Horizontal)
let tbi_remote_name_clone0 = tbi_remote_name.clone(); .hexpand(true)
let tbi_remote_url_clone0 = tbi_remote_url.clone(); .spacing(5)
.build();
flatpak_ref_install_dialog.clone() let flatpak_ref_install_label0 = gtk::Label::builder()
.choose(None::<&gio::Cancellable>, move |choice| { .margin_top(10)
match choice.as_str() { .margin_bottom(10)
"flatpak_ref_install_dialog_add" => { .build();
match (tbi_remote_name_clone0.borrow().deref(), tbi_remote_url_clone0.borrow().deref()) {
(Some(remote_name), Some(remote_url)) => { let flatpak_remote_user_togglebutton = gtk::ToggleButton::builder()
add_flatpakref_remote(&reload_action_clone0, &remote_name, &remote_url, flatpak_remote_system_togglebutton.is_active()); .valign(Align::Center)
.hexpand(true)
.label(t!("flatpak_remotes_columnview_user"))
.active(true)
.build();
let flatpak_remote_system_togglebutton = gtk::ToggleButton::builder()
.valign(Align::Center)
.hexpand(true)
.label(t!("flatpak_remotes_columnview_system"))
.group(&flatpak_remote_user_togglebutton)
.build();
//
let flatpak_ref_install_dialog_child_clamp = adw::Clamp::builder()
.child(&flatpak_ref_install_dialog_child_box)
.maximum_size(500)
.build();
let flatpak_ref_install_viewport = gtk::ScrolledWindow::builder()
.hexpand(true)
.vexpand(true)
.child(&flatpak_ref_install_dialog_child_clamp)
.hscrollbar_policy(PolicyType::Never)
.build();
let flatpak_ref_install_dialog = adw::MessageDialog::builder()
.transient_for(&window)
.extra_child(&flatpak_ref_install_viewport)
.heading(t!("flatpak_ref_install_dialog_heading"))
.width_request(700)
.height_request(400)
.build();
flatpak_ref_install_flatref_path_file_dialog
.set_transient_for(Some(&flatpak_ref_install_dialog));
flatpak_ref_install_dialog.add_response(
"flatpak_ref_install_dialog_add",
&t!("flatpak_ref_install_dialog_add_label").to_string(),
);
flatpak_ref_install_dialog.add_response(
"flatpak_ref_install_dialog_cancel",
&t!("flatpak_ref_install_dialog_cancel_label").to_string(),
);
flatpak_ref_install_dialog.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_dialog.set_response_appearance(
"flatpak_ref_install_dialog_cancel",
adw::ResponseAppearance::Destructive,
);
flatpak_ref_install_dialog.set_response_appearance(
"flatpak_ref_install_dialog_add",
adw::ResponseAppearance::Suggested,
);
//
let flatpak_ref_install_dialog_clone0 = flatpak_ref_install_dialog.clone();
let flatpak_ref_install_flatref_path_entry_clone0 =
flatpak_ref_install_flatref_path_entry.clone();
let flatpak_ref_install_label0_clone0 = flatpak_ref_install_label0.clone();
let tbi_remote_name = Rc::new(RefCell::new(None));
let tbi_remote_url = Rc::new(RefCell::new(None));
let tbi_remote_name_clone0 = tbi_remote_name.clone();
let tbi_remote_url_clone0 = tbi_remote_url.clone();
let add_button_update_state = move || {
if !flatpak_ref_install_flatref_path_entry_clone0
.text()
.is_empty()
{
match std::fs::read_to_string(flatpak_ref_install_flatref_path_entry_clone0.text()) {
Ok(t) => {
let mut flatref_file = Ini::new();
match flatref_file.read(t) {
Ok(_) => {
let ref_name = flatref_file.get("Flatpak Ref", "Name");
let ref_remote_name =
flatref_file.get("Flatpak Ref", "SuggestRemoteName");
let ref_remote_url = flatref_file.get("Flatpak Ref", "RuntimeRepo");
match (ref_name, ref_remote_name.clone()) {
(Some(name), Some(remote_name)) => {
flatpak_ref_install_label0_clone0.set_label(
&strfmt::strfmt(
&t!("flatpak_ref_install_label").to_string(),
&std::collections::HashMap::from([
("NAME".to_string(), name),
("REMOTE".to_string(), remote_name),
]),
)
.unwrap(),
);
{
*tbi_remote_name_clone0.borrow_mut() = ref_remote_name;
*tbi_remote_url_clone0.borrow_mut() = ref_remote_url;
} }
(_,_) => {}
} }
run_flatpak_ref_install_transaction(&flatpak_retry_signal_action_clone0, &reload_action_clone0, flatpak_remote_system_togglebutton.is_active(), window, &flatpak_ref_install_flatref_path_entry_clone0.text()); (_, _) => {
flatpak_ref_install_dialog_clone0.set_response_enabled(
"flatpak_ref_install_dialog_add",
false,
);
flatpak_ref_install_label0_clone0.set_label("");
}
} }
_ => {} flatpak_ref_install_dialog_clone0
.set_response_enabled("flatpak_ref_install_dialog_add", true);
} }
}); Err(_) => {
flatpak_ref_install_dialog_clone0
.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
}
}
Err(_) => {
flatpak_ref_install_dialog_clone0
.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
}
} else {
flatpak_ref_install_dialog_clone0
.set_response_enabled("flatpak_ref_install_dialog_add", false);
flatpak_ref_install_label0_clone0.set_label("");
}
};
//
for entry in [&flatpak_ref_install_flatref_path_entry] {
entry.connect_text_notify(clone!(
#[strong]
add_button_update_state,
move |_| {
add_button_update_state();
}
));
}
//
flatpak_ref_install_box2.append(&flatpak_remote_user_togglebutton);
flatpak_ref_install_box2.append(&flatpak_remote_system_togglebutton);
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_flatref_path_prefrencesgroup);
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_box2);
flatpak_ref_install_dialog_child_box.append(&flatpak_ref_install_label0);
let reload_action_clone0 = reload_action.clone();
let flatpak_retry_signal_action_clone0 = flatpak_retry_signal_action.clone();
let flatpak_ref_install_flatref_path_entry_clone0 =
flatpak_ref_install_flatref_path_entry.clone();
let tbi_remote_name_clone0 = tbi_remote_name.clone();
let tbi_remote_url_clone0 = tbi_remote_url.clone();
flatpak_ref_install_dialog.clone().choose(
None::<&gio::Cancellable>,
move |choice| match choice.as_str() {
"flatpak_ref_install_dialog_add" => {
match (
tbi_remote_name_clone0.borrow().deref(),
tbi_remote_url_clone0.borrow().deref(),
) {
(Some(remote_name), Some(remote_url)) => {
add_flatpakref_remote(
&reload_action_clone0,
&remote_name,
&remote_url,
flatpak_remote_system_togglebutton.is_active(),
);
}
(_, _) => {}
}
run_flatpak_ref_install_transaction(
&flatpak_retry_signal_action_clone0,
&reload_action_clone0,
flatpak_remote_system_togglebutton.is_active(),
window,
&flatpak_ref_install_flatref_path_entry_clone0.text(),
);
}
_ => {}
},
);
} }
pub fn run_flatpak_ref_install_transaction(flatpak_retry_signal_action: &gio::SimpleAction, retry_signal_action: &gio::SimpleAction, is_system: bool, window: adw::ApplicationWindow, flatref_path: &str) { pub fn run_flatpak_ref_install_transaction(
flatpak_retry_signal_action: &gio::SimpleAction,
retry_signal_action: &gio::SimpleAction,
is_system: bool,
window: adw::ApplicationWindow,
flatref_path: &str,
) {
let (transaction_percent_sender, transaction_percent_receiver) = let (transaction_percent_sender, transaction_percent_receiver) =
async_channel::unbounded::<u32>(); async_channel::unbounded::<u32>();
let transaction_percent_sender = transaction_percent_sender.clone(); let transaction_percent_sender = transaction_percent_sender.clone();
let (transaction_status_sender, transaction_status_receiver) = let (transaction_status_sender, transaction_status_receiver) =
async_channel::unbounded::<String>(); async_channel::unbounded::<String>();
let transaction_status_sender = transaction_status_sender.clone(); let transaction_status_sender = transaction_status_sender.clone();
let flatref_path_clone0 = flatref_path.clone().to_owned(); let flatref_path_clone0 = flatref_path.to_owned();
thread::spawn(move || { thread::spawn(move || {
let cancellable_no = libflatpak::gio::Cancellable::NONE; let cancellable_no = libflatpak::gio::Cancellable::NONE;
@ -321,30 +335,63 @@ pub fn run_flatpak_ref_install_transaction(flatpak_retry_signal_action: &gio::Si
let transaction_percent_sender0 = transaction_percent_sender.clone(); let transaction_percent_sender0 = transaction_percent_sender.clone();
let transaction_run_closure = let transaction_run_closure =
move |transaction: &libflatpak::Transaction, move |_: &libflatpak::Transaction,
transaction_operation: &libflatpak::TransactionOperation, transaction_operation: &libflatpak::TransactionOperation,
transaction_progress: &libflatpak::TransactionProgress| { transaction_progress: &libflatpak::TransactionProgress| {
let transaction_status_sender = transaction_status_sender0.clone(); let transaction_status_sender = transaction_status_sender0.clone();
let transaction_percent_sender = transaction_percent_sender0.clone(); let transaction_percent_sender = transaction_percent_sender0.clone();
transaction_progress.connect_changed(clone!(@strong transaction_progress, @strong transaction_operation => move |_| { transaction_progress.connect_changed(clone!(
let status_message = format!("{}: {}\n{}: {}\n{}: {}/{}\n{}: {}", t!("flatpak_ref"), transaction_operation.get_ref().unwrap_or(libflatpak::glib::GString::from_string_unchecked("Unknown".to_owned())), t!("flatpak_status") ,transaction_progress.status().unwrap_or(libflatpak::glib::GString::from_string_unchecked("Unknown".to_owned())), t!("flatpak_transaction_bytes_transferred"), convert(transaction_progress.bytes_transferred() as f64), convert(transaction_operation.download_size() as f64), t!("flatpak_transaction_installed_size"), convert(transaction_operation.installed_size() as f64)); #[strong]
transaction_status_sender.send_blocking(status_message).expect("transaction_status_receiver closed!"); transaction_progress,
transaction_percent_sender.send_blocking(transaction_progress.progress().try_into().unwrap_or(0)).expect("transaction_percent_receiver closed!"); #[strong]
})); transaction_operation,
move |_| {
let status_message = format!(
"{}: {}\n{}: {}\n{}: {}/{}\n{}: {}",
t!("flatpak_ref"),
transaction_operation.get_ref().unwrap_or(
libflatpak::glib::GString::from_string_unchecked(
"Unknown".to_owned()
)
),
t!("flatpak_status"),
transaction_progress.status().unwrap_or(
libflatpak::glib::GString::from_string_unchecked(
"Unknown".to_owned()
)
),
t!("flatpak_transaction_bytes_transferred"),
convert(transaction_progress.bytes_transferred() as f64),
convert(transaction_operation.download_size() as f64),
t!("flatpak_transaction_installed_size"),
convert(transaction_operation.installed_size() as f64)
);
transaction_status_sender
.send_blocking(status_message)
.expect("transaction_status_receiver closed!");
transaction_percent_sender
.send_blocking(transaction_progress.progress().try_into().unwrap_or(0))
.expect("transaction_percent_receiver closed!");
}
));
}; };
// //
let (flatpak_installation, flatpak_transaction) = match is_system { let flatpak_transaction = match is_system {
true => { true => {
let installation = libflatpak::Installation::new_system(cancellable_no).unwrap(); let installation = libflatpak::Installation::new_system(cancellable_no).unwrap();
let transaction = libflatpak::Transaction::for_installation(&installation, cancellable_no).unwrap(); let transaction =
(installation, transaction) libflatpak::Transaction::for_installation(&installation, cancellable_no)
.unwrap();
transaction
} }
false => { false => {
let installation = libflatpak::Installation::new_user(cancellable_no).unwrap(); let installation = libflatpak::Installation::new_user(cancellable_no).unwrap();
let transaction = libflatpak::Transaction::for_installation(&installation, cancellable_no).unwrap(); let transaction =
(installation, transaction) libflatpak::Transaction::for_installation(&installation, cancellable_no)
.unwrap();
transaction
} }
}; };
@ -366,7 +413,7 @@ pub fn run_flatpak_ref_install_transaction(flatpak_retry_signal_action: &gio::Si
} }
// //
match flatpak_transaction.run(cancellable_no) { match flatpak_transaction.run(cancellable_no) {
Ok(_) => { Ok(_) => {
transaction_status_sender transaction_status_sender
@ -419,13 +466,12 @@ pub fn run_flatpak_ref_install_transaction(flatpak_retry_signal_action: &gio::Si
flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_spinner); flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_spinner);
flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_progress_bar); flatpak_transaction_dialog_child_box.append(&flatpak_transaction_dialog_progress_bar);
let flatpak_transaction_dialog = let flatpak_transaction_dialog = adw::MessageDialog::builder()
adw::MessageDialog::builder() .transient_for(&window)
.transient_for(&window) .extra_child(&flatpak_transaction_dialog_child_box)
.extra_child(&flatpak_transaction_dialog_child_box) .heading(t!("flatpak_transaction_dialog_heading"))
.heading(t!("flatpak_transaction_dialog_heading")) .width_request(500)
.width_request(500) .build();
.build();
flatpak_transaction_dialog.add_response( flatpak_transaction_dialog.add_response(
"flatpak_transaction_dialog_ok", "flatpak_transaction_dialog_ok",
@ -549,20 +595,34 @@ pub fn run_flatpak_ref_install_transaction(flatpak_retry_signal_action: &gio::Si
fn get_data_from_filepath(filepath: &str) -> Result<libflatpak::glib::Bytes, std::io::Error> { fn get_data_from_filepath(filepath: &str) -> Result<libflatpak::glib::Bytes, std::io::Error> {
let data = std::fs::read_to_string(filepath)?; let data = std::fs::read_to_string(filepath)?;
let bytes = data.as_bytes(); let bytes = data.as_bytes();
let glib_bytes = libflatpak::glib::Bytes::from(bytes); let glib_bytes = libflatpak::glib::Bytes::from(bytes);
Ok(glib_bytes) Ok(glib_bytes)
} }
fn add_flatpakref_remote(reload_action: &gio::SimpleAction, remote_name: &str, remote_url: &str, is_system: bool) { fn add_flatpakref_remote(
reload_action: &gio::SimpleAction,
remote_name: &str,
remote_url: &str,
is_system: bool,
) {
let flatpak_installation = match is_system { let flatpak_installation = match is_system {
true => "--system", true => "--system",
false => "--user" false => "--user",
}; };
match duct::cmd!("flatpak", "remote-add", "--if-not-exists", &flatpak_installation, remote_name, remote_url).run() { match duct::cmd!(
"flatpak",
"remote-add",
"--if-not-exists",
&flatpak_installation,
remote_name,
remote_url
)
.run()
{
Ok(_) => { Ok(_) => {
reload_action.activate(None); reload_action.activate(None);
} }
@ -574,8 +634,8 @@ fn add_flatpakref_remote(reload_action: &gio::SimpleAction, remote_name: &str, r
flatpak_remote_add_error_dialog.add_response( flatpak_remote_add_error_dialog.add_response(
"flatpak_remote_add_error_dialog_ok", "flatpak_remote_add_error_dialog_ok",
&t!("flatpak_remote_add_error_dialog_ok_label").to_string(), &t!("flatpak_remote_add_error_dialog_ok_label").to_string(),
); );
flatpak_remote_add_error_dialog.present(); flatpak_remote_add_error_dialog.present();
} }
} }
} }

View File

@ -1,34 +1,19 @@
use crate::apt_package_row::AptPackageRow;
use add_dialog::add_dialog_fn;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use apt_deb822_tools::Deb822Repository; use gtk::glib::{clone, BoxedAnyObject};
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 crate::flatpak_ref_row::FlatpakRefRow;
use adw::prelude::*;
use gtk::glib::*;
use gtk::*; use gtk::*;
use libflatpak::prelude::*; use libflatpak::prelude::*;
use libflatpak::InstalledRef; use std::cell::Ref;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
mod add_dialog; mod add_dialog;
mod install_ref_dialog; mod install_ref_dialog;
enum FlatpakRemote { enum FlatpakRemote {
System(libflatpak::Remote), System(libflatpak::Remote),
User(libflatpak::Remote) User(libflatpak::Remote),
} }
pub fn flatpak_manage_page( pub fn flatpak_manage_page(
@ -69,194 +54,185 @@ pub fn flatpak_manage_page(
.margin_end(15) .margin_end(15)
.build(); .build();
let flatpak_remotes_selection_model_rc: Rc<RefCell<gtk::SingleSelection>> = Rc::new(RefCell::default()); let flatpak_remotes_selection_model_rc: Rc<RefCell<gtk::SingleSelection>> =
Rc::new(RefCell::default());
let flatpak_remotes_selection_model_rc_clone0 = Rc::clone(&flatpak_remotes_selection_model_rc); let flatpak_remotes_selection_model_rc_clone0 = Rc::clone(&flatpak_remotes_selection_model_rc);
let flatpak_remotes_columnview_bin = adw::Bin::new(); let flatpak_remotes_columnview_bin = adw::Bin::new();
let flatpak_remotes_columnview_bin_clone0 = flatpak_remotes_columnview_bin.clone(); let flatpak_remotes_columnview_bin_clone0 = flatpak_remotes_columnview_bin.clone();
retry_signal_action.connect_activate(clone!( retry_signal_action.connect_activate(clone!(
#[weak] #[weak]
flatpak_remotes_columnview_bin_clone0, flatpak_remotes_columnview_bin_clone0,
#[strong] #[strong]
cancellable_no, cancellable_no,
move |_, _| { move |_, _| {
let flatpak_system_installation = let flatpak_system_installation =
libflatpak::Installation::new_system(cancellable_no).unwrap(); libflatpak::Installation::new_system(cancellable_no).unwrap();
let flatpak_user_installation = let flatpak_user_installation =
libflatpak::Installation::new_user(cancellable_no).unwrap(); libflatpak::Installation::new_user(cancellable_no).unwrap();
let system_remotes = match libflatpak::Installation::list_remotes(&flatpak_system_installation, cancellable_no) { let system_remotes = match libflatpak::Installation::list_remotes(
&flatpak_system_installation,
cancellable_no,
) {
Ok(t) => t, Ok(t) => t,
Err(_) => Vec::new() Err(_) => Vec::new(),
}; };
let user_remotes = match libflatpak::Installation::list_remotes(&flatpak_user_installation, cancellable_no) { let user_remotes = match libflatpak::Installation::list_remotes(
&flatpak_user_installation,
cancellable_no,
) {
Ok(t) => t, Ok(t) => t,
Err(_) => Vec::new() Err(_) => Vec::new(),
}; };
let flatpak_remotes_list_store = gio::ListStore::new::<BoxedAnyObject>(); let flatpak_remotes_list_store = gio::ListStore::new::<BoxedAnyObject>();
for remote in system_remotes { for remote in system_remotes {
flatpak_remotes_list_store.append(&BoxedAnyObject::new(FlatpakRemote::System(remote))); flatpak_remotes_list_store
}; .append(&BoxedAnyObject::new(FlatpakRemote::System(remote)));
}
for remote in user_remotes { for remote in user_remotes {
flatpak_remotes_list_store.append(&BoxedAnyObject::new(FlatpakRemote::User(remote))); flatpak_remotes_list_store
}; .append(&BoxedAnyObject::new(FlatpakRemote::User(remote)));
}
let flatpak_remotes_selection_model = SingleSelection::new(Some(flatpak_remotes_list_store)); let flatpak_remotes_selection_model =
SingleSelection::new(Some(flatpak_remotes_list_store));
(*flatpak_remotes_selection_model_rc_clone0.borrow_mut() = flatpak_remotes_selection_model.clone()); (*flatpak_remotes_selection_model_rc_clone0.borrow_mut() =
flatpak_remotes_selection_model.clone());
let flatpak_remotes_columnview = ColumnView::builder() let flatpak_remotes_columnview = ColumnView::builder()
.vexpand(true) .vexpand(true)
.model(&flatpak_remotes_selection_model) .model(&flatpak_remotes_selection_model)
.build();
//
let flatpak_remotes_columnview_factory0 = gtk::SignalListItemFactory::new();
flatpak_remotes_columnview_factory0.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
let row = Label::builder()
.halign(Align::Start)
.build(); .build();
item.set_child(Some(&row));
});
flatpak_remotes_columnview_factory0.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_name = match entry_borrow.deref() {
FlatpakRemote::System(remote) => {
remote.name().unwrap_or_default()
}
FlatpakRemote::User(remote) => {
remote.name().unwrap_or_default()
}
};
child.set_label(&remote_name);
});
let flatpak_remotes_columnview_col1 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col0_title"))
.factory(&flatpak_remotes_columnview_factory0)
.build();
// let flatpak_remotes_columnview_factory0 = gtk::SignalListItemFactory::new();
let flatpak_remotes_columnview_factory1 = gtk::SignalListItemFactory::new(); flatpak_remotes_columnview_factory0.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
flatpak_remotes_columnview_factory1.connect_setup(move |_factory, item| { let row = Label::builder().halign(Align::Start).build();
let item = item.downcast_ref::<gtk::ListItem>().unwrap(); item.set_child(Some(&row));
let row = Label::builder() });
.halign(Align::Start)
flatpak_remotes_columnview_factory0.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_name = match entry_borrow.deref() {
FlatpakRemote::System(remote) => remote.name().unwrap_or_default(),
FlatpakRemote::User(remote) => remote.name().unwrap_or_default(),
};
child.set_label(&remote_name);
});
let flatpak_remotes_columnview_col1 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col0_title"))
.factory(&flatpak_remotes_columnview_factory0)
.build(); .build();
item.set_child(Some(&row));
});
flatpak_remotes_columnview_factory1.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_title = match entry_borrow.deref() {
FlatpakRemote::System(remote) => {
remote.title().unwrap_or_default()
}
FlatpakRemote::User(remote) => {
remote.title().unwrap_or_default()
}
};
child.set_label(&remote_title);
});
let flatpak_remotes_columnview_col0 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col1_title"))
.factory(&flatpak_remotes_columnview_factory1)
.build();
// let flatpak_remotes_columnview_factory1 = gtk::SignalListItemFactory::new();
let flatpak_remotes_columnview_factory2 = gtk::SignalListItemFactory::new(); flatpak_remotes_columnview_factory1.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
flatpak_remotes_columnview_factory2.connect_setup(move |_factory, item| { let row = Label::builder().halign(Align::Start).build();
let item = item.downcast_ref::<gtk::ListItem>().unwrap(); item.set_child(Some(&row));
let row = Label::builder() });
.halign(Align::Start)
flatpak_remotes_columnview_factory1.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_title = match entry_borrow.deref() {
FlatpakRemote::System(remote) => remote.title().unwrap_or_default(),
FlatpakRemote::User(remote) => remote.title().unwrap_or_default(),
};
child.set_label(&remote_title);
});
let flatpak_remotes_columnview_col0 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col1_title"))
.factory(&flatpak_remotes_columnview_factory1)
.build(); .build();
item.set_child(Some(&row));
});
flatpak_remotes_columnview_factory2.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_url = match entry_borrow.deref() {
FlatpakRemote::System(remote) => {
remote.url().unwrap_or_default()
}
FlatpakRemote::User(remote) => {
remote.url().unwrap_or_default()
}
};
child.set_label(&remote_url);
});
let flatpak_remotes_columnview_col2 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col2_title"))
.factory(&flatpak_remotes_columnview_factory2)
.expand(true)
.build();
// let flatpak_remotes_columnview_factory2 = gtk::SignalListItemFactory::new();
let flatpak_remotes_columnview_factory3 = gtk::SignalListItemFactory::new(); flatpak_remotes_columnview_factory2.connect_setup(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
flatpak_remotes_columnview_factory3.connect_setup(move |_factory, item| { let row = Label::builder().halign(Align::Start).build();
let item = item.downcast_ref::<gtk::ListItem>().unwrap(); item.set_child(Some(&row));
let row = Label::builder() });
.halign(Align::Start)
flatpak_remotes_columnview_factory2.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
let remote_url = match entry_borrow.deref() {
FlatpakRemote::System(remote) => remote.url().unwrap_or_default(),
FlatpakRemote::User(remote) => remote.url().unwrap_or_default(),
};
child.set_label(&remote_url);
});
let flatpak_remotes_columnview_col2 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col2_title"))
.factory(&flatpak_remotes_columnview_factory2)
.expand(true)
.build(); .build();
item.set_child(Some(&row));
});
flatpak_remotes_columnview_factory3.connect_bind(move |_factory, item| { //
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
match entry_borrow.deref() {
FlatpakRemote::System(remote) => {
child.set_label(&t!("flatpak_remotes_columnview_system").to_string());
}
FlatpakRemote::User(remote) => {
child.set_label(&t!("flatpak_remotes_columnview_user").to_string());
}
};
});
let flatpak_remotes_columnview_col3 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col3_title"))
.factory(&flatpak_remotes_columnview_factory3)
.build();
// let flatpak_remotes_columnview_factory3 = gtk::SignalListItemFactory::new();
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col0);
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col1); flatpak_remotes_columnview_factory3.connect_setup(move |_factory, item| {
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col2); let item = item.downcast_ref::<gtk::ListItem>().unwrap();
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col3); let row = Label::builder().halign(Align::Start).build();
flatpak_remotes_columnview_bin_clone0.set_child(Some(&flatpak_remotes_columnview)); item.set_child(Some(&row));
})); });
flatpak_remotes_columnview_factory3.connect_bind(move |_factory, item| {
let item: &ListItem = item.downcast_ref::<gtk::ListItem>().unwrap();
let child = item.child().and_downcast::<Label>().unwrap();
let entry: BoxedAnyObject = item.item().and_downcast::<BoxedAnyObject>().unwrap();
let entry_borrow = entry.borrow::<FlatpakRemote>();
match entry_borrow.deref() {
FlatpakRemote::System(_) => {
child.set_label(&t!("flatpak_remotes_columnview_system").to_string());
}
FlatpakRemote::User(_) => {
child.set_label(&t!("flatpak_remotes_columnview_user").to_string());
}
};
});
let flatpak_remotes_columnview_col3 = gtk::ColumnViewColumn::builder()
.title(t!("flatpak_remotes_columnview_col3_title"))
.factory(&flatpak_remotes_columnview_factory3)
.build();
//
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col0);
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col1);
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col2);
flatpak_remotes_columnview.append_column(&flatpak_remotes_columnview_col3);
flatpak_remotes_columnview_bin_clone0.set_child(Some(&flatpak_remotes_columnview));
}
));
retry_signal_action.activate(None); retry_signal_action.activate(None);
@ -310,17 +286,14 @@ pub fn flatpak_manage_page(
retry_signal_action, retry_signal_action,
#[strong] #[strong]
flatpak_retry_signal_action, flatpak_retry_signal_action,
move move |_| {
|_| add_dialog::add_dialog_fn(
{ window.clone(),
add_dialog::add_dialog_fn( &retry_signal_action,
window.clone(), &flatpak_retry_signal_action,
&retry_signal_action, );
&flatpak_retry_signal_action, }
); ));
}
)
);
flatpak_flatref_install_button.connect_clicked(clone!( flatpak_flatref_install_button.connect_clicked(clone!(
#[strong] #[strong]
@ -331,18 +304,15 @@ pub fn flatpak_manage_page(
flatpak_retry_signal_action, flatpak_retry_signal_action,
#[strong] #[strong]
flatpak_ref_entry_action, flatpak_ref_entry_action,
move move |_| {
|_| install_ref_dialog::install_ref_dialog_fn(
{ window.clone(),
install_ref_dialog::install_ref_dialog_fn( &retry_signal_action,
window.clone(), &flatpak_retry_signal_action,
&retry_signal_action, &flatpak_ref_entry_action,
&flatpak_retry_signal_action, );
&flatpak_ref_entry_action }
); ));
}
)
);
flatpak_remote_remove_button.connect_clicked(clone!( flatpak_remote_remove_button.connect_clicked(clone!(
#[strong] #[strong]
@ -357,7 +327,7 @@ pub fn flatpak_manage_page(
|_| |_|
{ {
{ {
let (mut installation, mut remote_name, mut cmd_installation): (libflatpak::Installation, libflatpak::glib::GString, String); let (installation, remote_name, cmd_installation): (libflatpak::Installation, libflatpak::glib::GString, String);
{ {
let flatpak_remotes_selection_model = flatpak_remotes_selection_model_rc.borrow(); let flatpak_remotes_selection_model = flatpak_remotes_selection_model_rc.borrow();
let selection = flatpak_remotes_selection_model.selected_item().unwrap(); let selection = flatpak_remotes_selection_model.selected_item().unwrap();
@ -459,4 +429,4 @@ pub fn flatpak_manage_page(
main_box.append(&flatpak_remotes_viewport); main_box.append(&flatpak_remotes_viewport);
main_box main_box
} }

View File

@ -96,12 +96,12 @@ impl ObjectImpl for FlatpakRefRow {
let flatref_ref_name = obj.flatref_ref_name(); let flatref_ref_name = obj.flatref_ref_name();
let flatref_summary = obj.flatref_summary(); let flatref_summary = obj.flatref_summary();
let flatref_remote_name = obj.flatref_remote_name(); let flatref_remote_name = obj.flatref_remote_name();
let flatref_installed_size_installed = obj.flatref_installed_size_installed(); //let flatref_installed_size_installed = obj.flatref_installed_size_installed();
let flatref_installed_size_remote = obj.flatref_installed_size_remote(); let flatref_installed_size_remote = obj.flatref_installed_size_remote();
let flatref_download_size = obj.flatref_download_size(); let flatref_download_size = obj.flatref_download_size();
let flatref_ref_format = obj.flatref_download_size(); //let flatref_ref_format = obj.flatref_download_size();
let flatref_is_system = obj.flatref_is_system(); let flatref_is_system = obj.flatref_is_system();
let flatref_marked = obj.flatref_marked(); //let flatref_marked = obj.flatref_marked();
// //
create_prefix_content( create_prefix_content(
&prefix_box, &prefix_box,

View File

@ -1,15 +1,12 @@
mod process; mod process;
use crate::apt_package_row::AptPackageRow;
use crate::flatpak_ref_row::FlatpakRefRow; use crate::flatpak_ref_row::FlatpakRefRow;
use adw::gio::SimpleAction; use adw::gio::SimpleAction;
use adw::prelude::*; use adw::prelude::*;
use gtk::glib::*; use gtk::glib::*;
use gtk::*; use gtk::*;
use libflatpak::prelude::*; use libflatpak::prelude::*;
use libflatpak::InstalledRef;
use std::cell::RefCell; use std::cell::RefCell;
use std::process::Command;
use std::rc::Rc; use std::rc::Rc;
use std::thread; use std::thread;
@ -42,7 +39,6 @@ pub fn flatpak_update_page(
let (appstream_sync_status_sender, appstream_sync_status_receiver) = let (appstream_sync_status_sender, appstream_sync_status_receiver) =
async_channel::unbounded::<String>(); async_channel::unbounded::<String>();
let appstream_sync_status_sender = appstream_sync_status_sender.clone(); let appstream_sync_status_sender = appstream_sync_status_sender.clone();
let appstream_sync_status_sender_clone0 = appstream_sync_status_sender.clone();
let system_refs_for_upgrade_vec: Rc<RefCell<Vec<FlatpakRefRow>>> = let system_refs_for_upgrade_vec: Rc<RefCell<Vec<FlatpakRefRow>>> =
Rc::new(RefCell::new(Vec::new())); Rc::new(RefCell::new(Vec::new()));
@ -201,7 +197,7 @@ pub fn flatpak_update_page(
.title(t!("flatpak_ignored_viewport_page_title")) .title(t!("flatpak_ignored_viewport_page_title"))
.hexpand(true) .hexpand(true)
.vexpand(true) .vexpand(true)
.build(); .build();
let viewport_bin = adw::Bin::builder() let viewport_bin = adw::Bin::builder()
.child(&packages_no_viewport_page) .child(&packages_no_viewport_page)
@ -252,7 +248,7 @@ pub fn flatpak_update_page(
if window.is_visible() { if window.is_visible() {
let retry_signal_action0 = retry_signal_action.clone(); let retry_signal_action0 = retry_signal_action.clone();
let viewport_bin = viewport_bin.clone(); let viewport_bin = viewport_bin.clone();
flatpak_update_dialog flatpak_update_dialog
.clone() .clone()
.choose(None::<&gio::Cancellable>, move |choice| { .choose(None::<&gio::Cancellable>, move |choice| {
@ -400,8 +396,8 @@ pub fn flatpak_update_page(
let mut user_last_triggered = false; let mut user_last_triggered = false;
// //
if !flatpak_system_updates.is_empty() || !flatpak_user_updates.is_empty() { if !flatpak_system_updates.is_empty() || !flatpak_user_updates.is_empty() {
update_button.set_sensitive(true); update_button.set_sensitive(true);
viewport_bin.set_child(Some(&packages_viewport)); viewport_bin.set_child(Some(&packages_viewport));
} }
// //
if !flatpak_system_updates.is_empty() { if !flatpak_system_updates.is_empty() {
@ -551,8 +547,7 @@ pub fn flatpak_update_page(
packages_boxedlist.append(&flatpak_row); packages_boxedlist.append(&flatpak_row);
(*flatpak_update_count.borrow_mut() += 1); (*flatpak_update_count.borrow_mut() += 1);
if flatref_struct.is_system && flatref_struct.is_last if flatref_struct.is_system && flatref_struct.is_last {
{
system_last_triggered = true system_last_triggered = true
} }
} }
@ -705,8 +700,7 @@ pub fn flatpak_update_page(
); );
packages_boxedlist.append(&flatpak_row); packages_boxedlist.append(&flatpak_row);
(*flatpak_update_count.borrow_mut() += 1); (*flatpak_update_count.borrow_mut() += 1);
if !flatref_struct.is_system && flatref_struct.is_last if !flatref_struct.is_system && flatref_struct.is_last {
{
user_last_triggered = true user_last_triggered = true
} }
} }
@ -715,7 +709,9 @@ pub fn flatpak_update_page(
} }
if user_last_triggered && system_last_triggered { if user_last_triggered && system_last_triggered {
packages_boxedlist.set_sensitive(true); packages_boxedlist.set_sensitive(true);
update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(&[*apt_update_count.borrow(),*flatpak_update_count.borrow()]))); update_sys_tray.activate(Some(&glib::Variant::array_from_fixed_array(
&[*apt_update_count.borrow(), *flatpak_update_count.borrow()],
)));
} }
flatpak_update_dialog.close(); flatpak_update_dialog.close();
} }
@ -733,7 +729,8 @@ pub fn flatpak_update_page(
)); ));
flatpak_update_dialog flatpak_update_dialog
.set_response_enabled("flatpak_update_dialog_retry", true); .set_response_enabled("flatpak_update_dialog_retry", true);
flatpak_update_dialog.set_response_enabled("flatpak_update_dialog_ignore", true); flatpak_update_dialog
.set_response_enabled("flatpak_update_dialog_ignore", true);
} }
_ => flatpak_update_dialog.set_body(&state), _ => flatpak_update_dialog.set_body(&state),
} }

View File

@ -4,19 +4,12 @@ use adw::prelude::*;
use gtk::glib::*; use gtk::glib::*;
use gtk::*; use gtk::*;
use libflatpak::prelude::*; use libflatpak::prelude::*;
use libflatpak::Transaction;
use pretty_bytes::converter::convert; use pretty_bytes::converter::convert;
use serde::Serialize;
use serde_json::Value;
use std::cell::RefCell;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::{fs, thread}; use std::{fs, thread};
use tokio::runtime::Runtime;
struct FlatpakChangesInfo { struct FlatpakChangesInfo {
system_flatref_count: u64, system_flatref_count: u64,
@ -58,7 +51,6 @@ pub fn flatpak_process_update(
window: adw::ApplicationWindow, window: adw::ApplicationWindow,
retry_signal_action: &SimpleAction, retry_signal_action: &SimpleAction,
) { ) {
let cancellable = libflatpak::gio::Cancellable::NONE;
// Emulate Flatpak Full Upgrade to get transaction info // Emulate Flatpak Full Upgrade to get transaction info
let mut flatpak_changes_struct = FlatpakChangesInfo { let mut flatpak_changes_struct = FlatpakChangesInfo {
system_flatref_count: 0, system_flatref_count: 0,
@ -248,16 +240,45 @@ fn flatpak_run_transactions(
let transaction_percent_sender0 = transaction_percent_sender.clone(); let transaction_percent_sender0 = transaction_percent_sender.clone();
let transaction_run_closure = let transaction_run_closure =
move |transaction: &libflatpak::Transaction, move |_: &libflatpak::Transaction,
transaction_operation: &libflatpak::TransactionOperation, transaction_operation: &libflatpak::TransactionOperation,
transaction_progress: &libflatpak::TransactionProgress| { transaction_progress: &libflatpak::TransactionProgress| {
let transaction_status_sender = transaction_status_sender0.clone(); let transaction_status_sender = transaction_status_sender0.clone();
let transaction_percent_sender = transaction_percent_sender0.clone(); let transaction_percent_sender = transaction_percent_sender0.clone();
transaction_progress.connect_changed(clone!(@strong transaction_progress, @strong transaction_operation => move |_| { transaction_progress.connect_changed(clone!(
let status_message = format!("{}: {}\n{}: {}\n{}: {}/{}\n{}: {}", t!("flatpak_ref"), transaction_operation.get_ref().unwrap_or(libflatpak::glib::GString::from_string_unchecked("Unknown".to_owned())), t!("flatpak_status") ,transaction_progress.status().unwrap_or(libflatpak::glib::GString::from_string_unchecked("Unknown".to_owned())), t!("flatpak_transaction_bytes_transferred"), convert(transaction_progress.bytes_transferred() as f64), convert(transaction_operation.download_size() as f64), t!("flatpak_transaction_installed_size"), convert(transaction_operation.installed_size() as f64)); #[strong]
transaction_status_sender.send_blocking(status_message).expect("transaction_status_receiver closed!"); transaction_progress,
transaction_percent_sender.send_blocking(transaction_progress.progress().try_into().unwrap_or(0)).expect("transaction_percent_receiver closed!"); #[strong]
})); transaction_operation,
move |_| {
let status_message = format!(
"{}: {}\n{}: {}\n{}: {}/{}\n{}: {}",
t!("flatpak_ref"),
transaction_operation.get_ref().unwrap_or(
libflatpak::glib::GString::from_string_unchecked(
"Unknown".to_owned()
)
),
t!("flatpak_status"),
transaction_progress.status().unwrap_or(
libflatpak::glib::GString::from_string_unchecked(
"Unknown".to_owned()
)
),
t!("flatpak_transaction_bytes_transferred"),
convert(transaction_progress.bytes_transferred() as f64),
convert(transaction_operation.download_size() as f64),
t!("flatpak_transaction_installed_size"),
convert(transaction_operation.installed_size() as f64)
);
transaction_status_sender
.send_blocking(status_message)
.expect("transaction_status_receiver closed!");
transaction_percent_sender
.send_blocking(transaction_progress.progress().try_into().unwrap_or(0))
.expect("transaction_percent_receiver closed!");
}
));
}; };
// //

View File

@ -1,11 +1,11 @@
mod apt_manage_page;
mod apt_package_row; mod apt_package_row;
mod apt_update_page; mod apt_update_page;
mod apt_manage_page;
mod build_ui; mod build_ui;
mod config; mod config;
mod flatpak_manage_page;
mod flatpak_ref_row; mod flatpak_ref_row;
mod flatpak_update_page; mod flatpak_update_page;
mod flatpak_manage_page;
use crate::config::APP_ID; use crate::config::APP_ID;
use adw::prelude::*; use adw::prelude::*;
@ -33,7 +33,8 @@ fn main() {
None => panic!("$LANG is not set"), None => panic!("$LANG is not set"),
}; };
rust_i18n::set_locale(&current_locale); rust_i18n::set_locale(&current_locale);
let application = adw::Application::new(Some(APP_ID), gio::ApplicationFlags::HANDLES_COMMAND_LINE); let application =
adw::Application::new(Some(APP_ID), gio::ApplicationFlags::HANDLES_COMMAND_LINE);
application.connect_startup(|app| { application.connect_startup(|app| {
// The CSS "magic" happens here. // The CSS "magic" happens here.
let provider = CssProvider::new(); let provider = CssProvider::new();