make sources refresh

This commit is contained in:
Ward from fusion-voyager-3 2024-09-23 17:45:51 +03:00
parent 51250c37ad
commit e45147dbcd

View File

@ -20,6 +20,10 @@ use tokio::runtime::Runtime;
mod add_dialog;
enum AptSourceConfig {
Legacy(apt_legacy_tools::LegacyAptSource),
DEB822(apt_deb822_tools::Deb822Repository)
}
pub fn apt_manage_page(
window: adw::ApplicationWindow,
@ -28,8 +32,6 @@ pub fn apt_manage_page(
let deb822_sources = Deb822Repository::get_deb822_sources().unwrap();
let mut unofficial_deb822_sources = deb822_sources.clone();
let system_source = deb822_sources.iter().filter(|x| {
match &x.repolib_id {
Some(t) => {
@ -39,17 +41,6 @@ pub fn apt_manage_page(
}
}).next().unwrap();
unofficial_deb822_sources.retain(|x| {
match &x.repolib_id {
Some(t) => {
!(t == "system")
}
None => true
}
});
let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources();
let main_box = Box::builder()
.hexpand(true)
.vexpand(true)
@ -112,12 +103,37 @@ pub fn apt_manage_page(
.margin_end(15)
.build();
let unofficial_sources_list_store = gio::ListStore::new::<BoxedAnyObject>();
/*unofficial_sources_selection_model.connect_selected_item_notify(|selection| {
let selection = selection.selected_item().unwrap();
let entry = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let r: Ref<AptSourceConfig> = entry.borrow();
println!("{}", r.col2.to_string())
});*/
enum AptSourceConfig {
Legacy(apt_legacy_tools::LegacyAptSource),
DEB822(apt_deb822_tools::Deb822Repository)
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_columnview_bin = adw::Bin::new();
let unofficial_sources_columnview_bin_clone0 = unofficial_sources_columnview_bin.clone();
let reload_unofficial_source_closure = move || {
let mut unofficial_deb822_sources = Deb822Repository::get_deb822_sources().unwrap();
unofficial_deb822_sources.retain(|x| {
match &x.repolib_id {
Some(t) => {
!(t == "system")
}
None => true
}
});
let legacy_apt_repos = apt_legacy_tools::LegacyAptSource::get_legacy_sources();
let unofficial_sources_list_store = gio::ListStore::new::<BoxedAnyObject>();
for deb822_source in unofficial_deb822_sources {
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source)));
@ -134,25 +150,7 @@ pub fn apt_manage_page(
let unofficial_sources_selection_model = SingleSelection::new(Some(unofficial_sources_list_store));
/*let unofficial_sources_item_factory = SignalListItemFactory::new();
unofficial_sources_item_factory.connect_setup(|_item_factory, list_item| {
let label = gtk::Label::new(Some("DDD"));
let list_item = list_item.downcast_ref::<gtk::ListItem>().unwrap();
list_item.set_child(Some(&label));
});
unofficial_sources_item_factory.connect_bind(|_item_factory, list_item| {
let list_item = list_item.downcast_ref::<gtk::ListItem>().unwrap();
let list_item_item = list_item.item().unwrap().to_value().get::<String>().unwrap();
let list_item_label = list_item.child().unwrap().downcast::<gtk::Label>().unwrap();
list_item_label.set_label(&list_item_item);
});
*/
(*unofficial_sources_selection_model_rc_clone0.borrow_mut() = unofficial_sources_selection_model.clone());
let unofficial_sources_columnview = ColumnView::builder()
.vexpand(true)
@ -261,15 +259,12 @@ pub fn apt_manage_page(
.build();
//
/*unofficial_sources_selection_model.connect_selected_item_notify(|selection| {
let selection = selection.selected_item().unwrap();
let entry = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let r: Ref<AptSourceConfig> = entry.borrow();
println!("{}", r.col2.to_string())
});*/
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));
};
reload_unofficial_source_closure();
let unofficial_sources_box = Box::builder()
.orientation(Orientation::Vertical)
@ -335,21 +330,30 @@ pub fn apt_manage_page(
unofficial_source_remove_button.connect_clicked(clone!(
#[strong]
window,
#[strong]
unofficial_sources_selection_model_rc,
#[strong]
reload_unofficial_source_closure,
move
|_|
{
{
let mut command = duct::cmd!("");
{
let unofficial_sources_selection_model = unofficial_sources_selection_model_rc.borrow();
let selection = unofficial_sources_selection_model.selected_item().unwrap();
let item = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let apt_src: Ref<AptSourceConfig> = item.borrow();
let command = match apt_src.deref() {
match apt_src.deref() {
AptSourceConfig::DEB822(src) => {
match &src.signed_by {
Some(t) => {duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_deb822", &src.filepath, t)}
None => {duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "delete_legacy", &src.filepath)}
Some(t) => {command = duct::cmd!("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) => {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"))
@ -364,16 +368,19 @@ pub fn apt_manage_page(
&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 reload_unofficial_source_closure_clone0 = reload_unofficial_source_closure.clone();
apt_src_remove_warning_dialog.clone()
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"apt_src_remove_warning_dialog_ok" => {
let _ = command.run().unwrap();
reload_unofficial_source_closure_clone0();
}
_ => {}
}
});
}
}
)
);
@ -383,7 +390,7 @@ pub fn apt_manage_page(
unofficial_sources_edit_box.append(&unofficial_source_edit_button);
unofficial_sources_edit_box.append(&unofficial_source_remove_button);
unofficial_sources_box.append(&unofficial_sources_columnview);
unofficial_sources_box.append(&unofficial_sources_columnview_bin);
unofficial_sources_box.append(&unofficial_sources_edit_box);
//