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,164 +103,168 @@ pub fn apt_manage_page(
.margin_end(15)
.build();
let unofficial_sources_list_store = gio::ListStore::new::<BoxedAnyObject>();
enum AptSourceConfig {
Legacy(apt_legacy_tools::LegacyAptSource),
DEB822(apt_deb822_tools::Deb822Repository)
}
for deb822_source in unofficial_deb822_sources {
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::DEB822(deb822_source)));
};
match legacy_apt_repos {
Ok(vec) => {
for legacy_repo in vec {
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::Legacy(legacy_repo)));
};
}
Err(_) => {}
}
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);
});
*/
let unofficial_sources_columnview = ColumnView::builder()
.vexpand(true)
.model(&unofficial_sources_selection_model)
.build();
//
let unofficial_sources_columnview_factory0 = gtk::SignalListItemFactory::new();
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();
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,
None => match(&src.uris, &src.suites, &src.components) {
(Some(uris),Some(suites),Some(components)) => {
&format!("{} {} {}", uris, suites, components)
}
(_,_,_) => {
&t!("apt_source_parse_error").to_string()
}
}
}
}
AptSourceConfig::Legacy(src) => {
&format!("{} {} {} {}",
if src.is_source {
"(Legacy Src)"
} else {
"(Legacy)"
},
&src.url,
&src.suite,
&src.components
)
}
};
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_factory1 = gtk::SignalListItemFactory::new();
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();
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() {
"yes" => true,
"true" => true,
"no" => false,
"false" => false,
_ => 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"));
}
});
let unofficial_sources_columnview_col1 = gtk::ColumnViewColumn::builder()
.title(t!("unofficial_sources_columnview_col1_title"))
.factory(&unofficial_sources_columnview_factory1)
.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);
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)));
};
match legacy_apt_repos {
Ok(vec) => {
for legacy_repo in vec {
unofficial_sources_list_store.append(&BoxedAnyObject::new(AptSourceConfig::Legacy(legacy_repo)));
};
}
Err(_) => {}
}
let unofficial_sources_selection_model = SingleSelection::new(Some(unofficial_sources_list_store));
(*unofficial_sources_selection_model_rc_clone0.borrow_mut() = unofficial_sources_selection_model.clone());
let unofficial_sources_columnview = ColumnView::builder()
.vexpand(true)
.model(&unofficial_sources_selection_model)
.build();
//
let unofficial_sources_columnview_factory0 = gtk::SignalListItemFactory::new();
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();
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,
None => match(&src.uris, &src.suites, &src.components) {
(Some(uris),Some(suites),Some(components)) => {
&format!("{} {} {}", uris, suites, components)
}
(_,_,_) => {
&t!("apt_source_parse_error").to_string()
}
}
}
}
AptSourceConfig::Legacy(src) => {
&format!("{} {} {} {}",
if src.is_source {
"(Legacy Src)"
} else {
"(Legacy)"
},
&src.url,
&src.suite,
&src.components
)
}
};
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_factory1 = gtk::SignalListItemFactory::new();
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();
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() {
"yes" => true,
"true" => true,
"no" => false,
"false" => false,
_ => 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"));
}
});
let unofficial_sources_columnview_col1 = gtk::ColumnViewColumn::builder()
.title(t!("unofficial_sources_columnview_col1_title"))
.factory(&unofficial_sources_columnview_factory1)
.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));
};
reload_unofficial_source_closure();
let unofficial_sources_box = Box::builder()
.orientation(Orientation::Vertical)
@ -335,44 +330,56 @@ 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 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() {
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)}
{
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();
match apt_src.deref() {
AptSourceConfig::DEB822(src) => {
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)}
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) => {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(),
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.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);
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();
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);
//