From 44d7c60ba9a77c2dde283d617dababf5771eb849 Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Sat, 5 Oct 2024 13:49:45 +0200 Subject: [PATCH] refactor: Use static dispatch --- src/utils.rs | 48 ++++++++++++-------- src/view/action_page.rs | 4 +- src/view/action_row.rs | 4 +- src/view/actions_button.rs | 2 +- src/view/actions_sidebar.rs | 8 +--- src/view/client_view.rs | 2 +- src/view/connection_chooser_page.rs | 4 +- src/view/connection_creation_page.rs | 8 ++-- src/view/connection_custom_info_page.rs | 13 +++--- src/view/connection_row.rs | 4 +- src/view/connections_sidebar.rs | 4 +- src/view/container.rs | 16 ++++--- src/view/container_card.rs | 34 +++++++------- src/view/container_commit_page.rs | 8 ++-- src/view/container_creation_page.rs | 8 ++-- src/view/container_details_page.rs | 60 ++++++++++--------------- src/view/container_files_get_page.rs | 8 ++-- src/view/container_files_put_page.rs | 8 ++-- src/view/container_health_check_page.rs | 6 +-- src/view/container_log_page.rs | 19 ++++---- src/view/container_menu_button.rs | 18 ++++---- src/view/container_properties_group.rs | 6 +-- src/view/container_renamer.rs | 2 +- src/view/container_resources.rs | 2 +- src/view/container_row.rs | 4 +- src/view/container_terminal.rs | 11 +++-- src/view/container_terminal_page.rs | 9 ++-- src/view/container_volume_row.rs | 4 +- src/view/containers_count_bar.rs | 2 +- src/view/containers_panel.rs | 29 +++++------- src/view/containers_prune_page.rs | 2 +- src/view/containers_row.rs | 2 +- src/view/image.rs | 19 ++++---- src/view/image_build_page.rs | 10 ++--- src/view/image_details_page.rs | 20 ++++----- src/view/image_history_page.rs | 4 +- src/view/image_menu_button.rs | 6 +-- src/view/image_pull_page.rs | 2 +- src/view/image_row.rs | 4 +- src/view/image_search_page.rs | 4 +- src/view/image_search_response_row.rs | 2 +- src/view/image_selection_combo_row.rs | 4 +- src/view/image_selection_page.rs | 2 +- src/view/images_panel.rs | 28 ++++-------- src/view/images_prune_page.rs | 2 +- src/view/images_row.rs | 2 +- src/view/info_panel.rs | 4 +- src/view/info_row.rs | 2 +- src/view/mount_row.rs | 2 +- src/view/pod.rs | 29 ++++++------ src/view/pod_creation_page.rs | 6 +-- src/view/pod_details_page.rs | 37 +++++++-------- src/view/pod_menu_button.rs | 18 ++++---- src/view/pod_row.rs | 6 +-- src/view/pod_selection_page.rs | 12 ++--- src/view/pods_panel.rs | 26 ++++------- src/view/pods_prune_page.rs | 2 +- src/view/pods_row.rs | 2 +- src/view/repo_tag_push_page.rs | 10 ++--- src/view/repo_tag_row.rs | 8 +--- src/view/repo_tag_selection_page.rs | 4 +- src/view/scalable_text_view_page.rs | 19 +++----- src/view/search_panel.rs | 4 +- src/view/search_row.rs | 3 +- src/view/top_page.rs | 10 ++--- src/view/volume.rs | 19 ++++---- src/view/volume_creation_page.rs | 6 +-- src/view/volume_details_page.rs | 14 +++--- src/view/volume_row.rs | 6 +-- src/view/volume_selection_page.rs | 12 ++--- src/view/volumes_panel.rs | 19 +++----- src/view/volumes_prune_page.rs | 2 +- src/view/volumes_row.rs | 2 +- src/view/welcome_page.rs | 2 +- src/view/window.rs | 12 ++--- src/widget/circular_progress_bar.rs | 2 +- src/widget/count_badge.rs | 2 +- src/widget/main_menu_button.rs | 3 +- src/widget/source_view_search_widget.rs | 2 +- src/widget/spinner.rs | 2 +- src/widget/text_search_entry.rs | 2 +- src/widget/zoom_control.rs | 2 +- 82 files changed, 359 insertions(+), 422 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index c0c5bff2..32701f01 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,6 +16,7 @@ use gettextrs::ngettext; use glib::clone; use gtk::gio; use gtk::glib; +use gtk::glib::clone::Downgrade; use crate::config; use crate::APPLICATION_OPTS; @@ -158,23 +159,23 @@ pub(crate) fn format_id(id: &str) -> String { id.chars().take(12).collect::() } -pub(crate) fn root(widget: >k::Widget) -> gtk::Window { +pub(crate) fn root>(widget: &W) -> gtk::Window { widget.root().unwrap().downcast::().unwrap() } -pub(crate) struct Dialog<'a> { - widget: &'a gtk::Widget, - content: &'a gtk::Widget, +pub(crate) struct Dialog<'a, P, C> { + parent: &'a P, + content: &'a C, height: Option, width: Option, follows_content_size: Option, } -impl<'a> Dialog<'a> { +impl<'a, C, P> Dialog<'a, C, P> { #[must_use] - pub(crate) fn new(widget: &'a gtk::Widget, content: &'a gtk::Widget) -> Self { + pub(crate) fn new(widget: &'a C, content: &'a P) -> Self { Self { - widget, + parent: widget, content, height: None, width: None, @@ -193,7 +194,13 @@ impl<'a> Dialog<'a> { self.follows_content_size = Some(follows_content_size); self } +} +impl<'a, C, P> Dialog<'a, C, P> +where + C: IsA, + P: IsA, +{ pub(crate) fn present(self) { let toast_overlay = adw::ToastOverlay::new(); toast_overlay.set_child(Some(self.content)); @@ -206,11 +213,11 @@ impl<'a> Dialog<'a> { .follows_content_size(self.follows_content_size.unwrap_or(false)) .build(); - dialog.present(Some(self.widget)); + dialog.present(Some(self.parent)); } } -pub(crate) fn show_toast(widget: >k::Widget, title: impl Into) { +pub(crate) fn show_toast>(widget: &W, title: impl Into) { widget .ancestor(adw::ToastOverlay::static_type()) .unwrap() @@ -225,17 +232,17 @@ pub(crate) fn show_toast(widget: >k::Widget, title: impl Into) ); } -pub(crate) fn show_error_toast(widget: >k::Widget, title: &str, msg: &str) { +pub(crate) fn show_error_toast>(widget: &W, title: &str, msg: &str) { show_toast(widget, format!("{title}: {msg}")); } -pub(crate) fn try_navigation_view(widget: >k::Widget) -> Option { +pub(crate) fn try_navigation_view>(widget: &W) -> Option { widget .ancestor(adw::NavigationView::static_type()) .and_downcast::() } -pub(crate) fn navigation_view(widget: >k::Widget) -> adw::NavigationView { +pub(crate) fn navigation_view>(widget: &W) -> adw::NavigationView { try_navigation_view(widget).unwrap() } @@ -383,7 +390,7 @@ pub(crate) fn run_stream_with_finish_handler( }); } -pub(crate) fn css_classes(widget: >k::Widget) -> Vec { +pub(crate) fn css_classes>(widget: &W) -> Vec { widget .css_classes() .iter() @@ -392,8 +399,8 @@ pub(crate) fn css_classes(widget: >k::Widget) -> Vec { } pub(crate) struct ChildIter(Option); -impl From<>k::Widget> for ChildIter { - fn from(widget: >k::Widget) -> Self { +impl> From<&W> for ChildIter { + fn from(widget: &W) -> Self { Self(widget.first_child()) } } @@ -407,12 +414,13 @@ impl Iterator for ChildIter { } } -pub(crate) fn unparent_children(widget: >k::Widget) { +pub(crate) fn unparent_children>(widget: &W) { ChildIter::from(widget).for_each(|child| child.unparent()); } -pub(crate) async fn show_open_file_dialog(request: OpenFileRequest, widget: >k::Widget, op: F) +pub(crate) async fn show_open_file_dialog(request: OpenFileRequest, widget: &W, op: F) where + W: IsA + Downgrade>, F: Fn(SelectedFiles) + 'static, { do_async( @@ -425,8 +433,9 @@ where ); } -pub(crate) async fn show_save_file_dialog(request: SaveFileRequest, widget: >k::Widget, op: F) +pub(crate) async fn show_save_file_dialog(request: SaveFileRequest, widget: &W, op: F) where + W: IsA + Downgrade>, F: Fn(SelectedFiles) + 'static, { do_async( @@ -439,8 +448,9 @@ where ); } -fn show_file_dialog(files: Result, widget: >k::Widget, op: F) +fn show_file_dialog(files: Result, widget: &W, op: F) where + W: IsA, F: Fn(SelectedFiles), { match files { diff --git a/src/view/action_page.rs b/src/view/action_page.rs index 3eaa7075..75af3e34 100644 --- a/src/view/action_page.rs +++ b/src/view/action_page.rs @@ -114,7 +114,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -308,7 +308,7 @@ impl ActionPage { self.activate_action("win.close", None).unwrap(); } None => utils::show_error_toast( - self.upcast_ref(), + self, &gettext("Error on opening artifact"), &gettext("Artifact has been deleted"), ), diff --git a/src/view/action_row.rs b/src/view/action_row.rs index 45d82832..fa06aa4b 100644 --- a/src/view/action_row.rs +++ b/src/view/action_row.rs @@ -102,7 +102,7 @@ mod imp { description_expr.bind(obj, "tooltip-markup", Some(obj)); description_expr.bind(&*self.description_label, "label", Some(obj)); - let classes = utils::css_classes(self.state_label.upcast_ref()); + let classes = utils::css_classes(&*self.state_label); state_expr .chain_closure::>(closure!( |_: Self::Type, state: model::ActionState| { @@ -151,7 +151,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/actions_button.rs b/src/view/actions_button.rs index aea9c6b6..f9f6bf93 100644 --- a/src/view/actions_button.rs +++ b/src/view/actions_button.rs @@ -106,7 +106,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/actions_sidebar.rs b/src/view/actions_sidebar.rs index a832ee17..d027e169 100644 --- a/src/view/actions_sidebar.rs +++ b/src/view/actions_sidebar.rs @@ -116,7 +116,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -135,11 +135,7 @@ mod imp { .downcast::() .unwrap(); - utils::Dialog::new( - self.obj().upcast_ref(), - view::ActionPage::from(&action).upcast_ref(), - ) - .present(); + utils::Dialog::new(&*self.obj(), &view::ActionPage::from(&action)).present(); } pub(super) fn set_action_list(&self, value: Option<&model::ActionList>) { diff --git a/src/view/client_view.rs b/src/view/client_view.rs index a6525f07..685f6fcd 100644 --- a/src/view/client_view.rs +++ b/src/view/client_view.rs @@ -159,7 +159,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/connection_chooser_page.rs b/src/view/connection_chooser_page.rs index 2cb52004..39890056 100644 --- a/src/view/connection_chooser_page.rs +++ b/src/view/connection_chooser_page.rs @@ -54,7 +54,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -105,7 +105,7 @@ mod imp { obj, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on establishing connection"), &e.to_string(), ); diff --git a/src/view/connection_creation_page.rs b/src/view/connection_creation_page.rs index 972dad0e..e744457d 100644 --- a/src/view/connection_creation_page.rs +++ b/src/view/connection_creation_page.rs @@ -156,7 +156,7 @@ mod imp { let obj = &*self.obj(); obj.abort(); - utils::unparent_children(obj.upcast_ref()); + utils::unparent_children(obj); } } @@ -176,11 +176,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.connect_button)); + utils::root(widget).set_default_widget(Some(&*self.connect_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -297,6 +297,6 @@ impl ConnectionCreationPage { } fn on_error(&self, msg: &str) { - utils::show_error_toast(self.upcast_ref(), &gettext("Error"), msg); + utils::show_error_toast(self, &gettext("Error"), msg); } } diff --git a/src/view/connection_custom_info_page.rs b/src/view/connection_custom_info_page.rs index 885ee9db..9b6d204e 100644 --- a/src/view/connection_custom_info_page.rs +++ b/src/view/connection_custom_info_page.rs @@ -97,7 +97,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -136,7 +136,7 @@ impl ConnectionCustomInfoDialog { label.select_region(0, -1); label.emit_copy_clipboard(); - utils::show_toast(self.upcast_ref(), gettext("systemd unit path copied")); + utils::show_toast(self, gettext("systemd unit path copied")); } fn copy_root_systemd_unit_content(&self) { @@ -144,7 +144,7 @@ impl ConnectionCustomInfoDialog { buffer.select_range(&buffer.start_iter(), &buffer.end_iter()); buffer.copy_clipboard(&gdk::Display::default().unwrap().clipboard()); - utils::show_toast(self.upcast_ref(), gettext("systemd unit content copied")); + utils::show_toast(self, gettext("systemd unit content copied")); } fn copy_root_socket_acivation_command(&self) { @@ -152,10 +152,7 @@ impl ConnectionCustomInfoDialog { label.select_region(0, -1); label.emit_copy_clipboard(); - utils::show_toast( - self.upcast_ref(), - gettext("socket activation command copied"), - ); + utils::show_toast(self, gettext("socket activation command copied")); } fn copy_root_url(&self) { @@ -163,6 +160,6 @@ impl ConnectionCustomInfoDialog { label.select_region(0, -1); label.emit_copy_clipboard(); - utils::show_toast(self.upcast_ref(), gettext("URL copied")); + utils::show_toast(self, gettext("URL copied")); } } diff --git a/src/view/connection_row.rs b/src/view/connection_row.rs index 15aeea59..1d1a14db 100644 --- a/src/view/connection_row.rs +++ b/src/view/connection_row.rs @@ -101,7 +101,7 @@ mod imp { ) .bind(&*self.url_label, "label", Some(obj)); - let classes = utils::css_classes(self.image.upcast_ref()); + let classes = utils::css_classes(&*self.image); is_active_expr .chain_closure::>(closure!(|_: Self::Type, is_active: bool| { classes @@ -142,7 +142,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/connections_sidebar.rs b/src/view/connections_sidebar.rs index 92962b36..674297c4 100644 --- a/src/view/connections_sidebar.rs +++ b/src/view/connections_sidebar.rs @@ -68,7 +68,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -103,7 +103,7 @@ mod imp { obj, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on switching connection"), &e.to_string(), ); diff --git a/src/view/container.rs b/src/view/container.rs index 712e7c16..f27a432f 100644 --- a/src/view/container.rs +++ b/src/view/container.rs @@ -3,6 +3,7 @@ use gettextrs::gettext; use glib::clone; use glib::closure; use gtk::glib; +use gtk::glib::clone::Downgrade; use crate::model; use crate::utils; @@ -52,7 +53,10 @@ pub(crate) fn container_status_combined_css_class( } } -pub(crate) fn rename(widget: >k::Widget, container: Option<&model::Container>) { +pub(crate) fn rename(widget: &W, container: Option<&model::Container>) +where + W: IsA + Downgrade>, +{ if let Some(container) = container { let container_renamer = view::ContainerRenamer::from(container); @@ -129,12 +133,14 @@ pub(crate) fn rename(widget: >k::Widget, container: Option<&model::Container>) macro_rules! container_action { (fn $name:ident => $action:ident($($param:literal),*) => $error:tt) => { - pub(crate) fn $name(widget: >k::Widget) { - use gtk::glib; - if let Some(container) = ::property::>(widget, "container") { + pub(crate) fn $name(widget: &W, container: Option) + where + W: gtk::glib::prelude::IsA + gtk::glib::clone::Downgrade>, + { + if let Some(container) = container { container.$action( $($param,)* - glib::clone!(#[weak] widget, move |result| if let Err(e) = result { + gtk::glib::clone!(#[weak] widget, move |result| if let Err(e) = result { crate::utils::show_error_toast( &widget, &$error, diff --git a/src/view/container_card.rs b/src/view/container_card.rs index ef27d654..a31b80a1 100644 --- a/src/view/container_card.rs +++ b/src/view/container_card.rs @@ -106,30 +106,30 @@ mod imp { }); klass.install_action(ACTION_RENAME, None, |widget, _, _| { - view::container::rename(widget.upcast_ref(), widget.container().as_ref()); + view::container::rename(widget, widget.container().as_ref()); }); klass.install_action(ACTION_START_OR_RESUME, None, |widget, _, _| { if widget.container().map(|c| c.can_start()).unwrap_or(false) { - view::container::start(widget.upcast_ref()); + view::container::start(widget, widget.container()); } else { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); } }); klass.install_action(ACTION_STOP, None, |widget, _, _| { - view::container::stop(widget.upcast_ref()); + view::container::stop(widget, widget.container()); }); klass.install_action(ACTION_KILL, None, |widget, _, _| { - view::container::kill(widget.upcast_ref()); + view::container::kill(widget, widget.container()); }); klass.install_action(ACTION_RESTART, None, |widget, _, _| { - view::container::restart(widget.upcast_ref()); + view::container::restart(widget, widget.container()); }); klass.install_action(ACTION_PAUSE, None, |widget, _, _| { - view::container::pause(widget.upcast_ref()); + view::container::pause(widget, widget.container()); }); klass.install_action(ACTION_RESUME, None, |widget, _, _| { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); }); klass.install_action(ACTION_DELETE, None, |widget, _, _| { widget.delete(); @@ -211,7 +211,7 @@ mod imp { ), ); - let css_classes = utils::css_classes(obj.upcast_ref()); + let css_classes = utils::css_classes(obj); status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::ContainerStatus| { @@ -250,7 +250,7 @@ mod imp { ) .bind(&*self.spinner, "icon-name", Some(obj)); - let css_classes = utils::css_classes(self.spinner.upcast_ref()); + let css_classes = utils::css_classes(&*self.spinner); gtk::ClosureExpression::new::>( [&status_expr, &health_status_expr], closure!(|_: Self::Type, @@ -399,7 +399,7 @@ mod imp { pod_name_expr.bind(&*self.pod_name_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.pod_center_box.upcast_ref()); + let css_classes = utils::css_classes(&*self.pod_center_box); pod_status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::PodStatus| { @@ -414,7 +414,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -491,7 +491,7 @@ mod imp { )) .build(); - let css_classes = utils::css_classes(label.upcast_ref()); + let css_classes = utils::css_classes(&label); super::ContainerCard::this_expression("container") .chain_property::("status") .chain_closure::>(closure!( @@ -562,7 +562,7 @@ impl ContainerCard { ))) .bind(&nav_page, "title", Some(self)); - utils::navigation_view(self.upcast_ref()).push(&nav_page); + utils::navigation_view(self).push(&nav_page); } } } @@ -584,7 +584,7 @@ impl ContainerCard { dialog.set_response_appearance("confirm", adw::ResponseAppearance::Destructive); if glib::MainContext::default().block_on(dialog.choose_future(self)) == "confirm" { - view::container::delete(self.upcast_ref()) + view::container::delete(self, self.container()) } } @@ -616,7 +616,7 @@ impl ContainerCard { ), ); - let classes = utils::css_classes(progress_bar.upcast_ref()); + let classes = utils::css_classes(progress_bar); #[rustfmt::skip] percent_expr.chain_closure::>(closure!(|_: Self, value: f64| { @@ -653,7 +653,7 @@ impl ContainerCard { })) .bind(label, "label", Some(self)); - let css_classes = utils::css_classes(box_.upcast_ref()); + let css_classes = utils::css_classes(box_); self.curr_value_expr(stats_expr) .chain_closure::>(closure!(|_: Self, value: u64| { css_classes diff --git a/src/view/container_commit_page.rs b/src/view/container_commit_page.rs index 7f0263c2..7bc58c58 100644 --- a/src/view/container_commit_page.rs +++ b/src/view/container_commit_page.rs @@ -113,7 +113,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -133,11 +133,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.commit_button)); + utils::root(widget).set_default_widget(Some(&*self.commit_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -204,7 +204,7 @@ impl ContainerCommitPage { Err(e) => { if let ashpd::Error::Portal(ashpd::PortalError::Cancelled(_)) = e { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on fetching user name"), &e.to_string(), ); diff --git a/src/view/container_creation_page.rs b/src/view/container_creation_page.rs index df141134..10afd50b 100644 --- a/src/view/container_creation_page.rs +++ b/src/view/container_creation_page.rs @@ -241,7 +241,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -261,11 +261,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.create_button)); + utils::root(widget).set_default_widget(Some(&*self.create_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -531,7 +531,7 @@ impl ContainerCreationPage { view::ImageSelectionMode::Unset => { log::error!("Error while starting container: no image selected"); utils::show_error_toast( - self.upcast_ref(), + self, &gettext("Failed to create container"), &gettext("no image selected"), ) diff --git a/src/view/container_details_page.rs b/src/view/container_details_page.rs index ff5d7a06..f5678ae5 100644 --- a/src/view/container_details_page.rs +++ b/src/view/container_details_page.rs @@ -71,7 +71,7 @@ mod imp { klass.bind_template(); klass.install_action(ACTION_RENAME, None, |widget, _, _| { - view::container::rename(widget.upcast_ref(), widget.container().as_ref()); + view::container::rename(widget, widget.container().as_ref()); }); klass.install_action(ACTION_COMMIT, None, |widget, _, _| { widget.commit(); @@ -93,28 +93,28 @@ mod imp { }); klass.install_action(ACTION_START_OR_RESUME, None, |widget, _, _| { if widget.container().map(|c| c.can_start()).unwrap_or(false) { - view::container::start(widget.upcast_ref()); + view::container::start(widget, widget.container()); } else { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); } }); klass.install_action(ACTION_STOP, None, |widget, _, _| { - view::container::stop(widget.upcast_ref()); + view::container::stop(widget, widget.container()); }); klass.install_action(ACTION_KILL, None, |widget, _, _| { - view::container::kill(widget.upcast_ref()); + view::container::kill(widget, widget.container()); }); klass.install_action(ACTION_RESTART, None, |widget, _, _| { - view::container::restart(widget.upcast_ref()); + view::container::restart(widget, widget.container()); }); klass.install_action(ACTION_PAUSE, None, |widget, _, _| { - view::container::pause(widget.upcast_ref()); + view::container::pause(widget, widget.container()); }); klass.install_action(ACTION_RESUME, None, |widget, _, _| { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); }); klass.install_action(ACTION_DELETE, None, |widget, _, _| { - view::container::delete(widget.upcast_ref()); + view::container::delete(widget, widget.container()); }); klass.install_action(ACTION_INSPECT, None, |widget, _, _| { widget.show_inspection(); @@ -240,7 +240,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -263,7 +263,7 @@ mod imp { obj, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on loading container details"), &e.to_string(), ); @@ -275,10 +275,10 @@ mod imp { obj, move |container| { utils::show_toast( - obj.upcast_ref(), + &obj, gettext!("Container '{}' has been deleted", container.name()), ); - utils::navigation_view(obj.upcast_ref()).pop(); + utils::navigation_view(&obj).pop(); } )); self.handler_id.replace(Some(handler_id)); @@ -362,11 +362,7 @@ impl ContainerDetailsPage { pub(crate) fn commit(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::Dialog::new( - self.upcast_ref(), - view::ContainerCommitPage::from(&container).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::ContainerCommitPage::from(&container)).present(); } }); } @@ -374,11 +370,7 @@ impl ContainerDetailsPage { pub(crate) fn get_files(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::Dialog::new( - self.upcast_ref(), - view::ContainerFilesGetPage::from(&container).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::ContainerFilesGetPage::from(&container)).present(); } }); } @@ -386,11 +378,7 @@ impl ContainerDetailsPage { pub(crate) fn put_files(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::Dialog::new( - self.upcast_ref(), - view::ContainerFilesPutPage::from(&container).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::ContainerFilesPutPage::from(&container)).present(); } }); } @@ -398,7 +386,7 @@ impl ContainerDetailsPage { pub(crate) fn show_health_details(&self) { self.exec_action(|| { if let Some(ref container) = self.container() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ContainerHealthCheckPage::from(container)) .build(), @@ -410,7 +398,7 @@ impl ContainerDetailsPage { pub(crate) fn show_image_details(&self) { self.exec_action(|| { if let Some(image) = self.container().as_ref().and_then(model::Container::image) { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ImageDetailsPage::from(&image)) .build(), @@ -422,7 +410,7 @@ impl ContainerDetailsPage { pub(crate) fn show_pod_details(&self) { self.exec_action(|| { if let Some(pod) = self.container().as_ref().and_then(model::Container::pod) { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::PodDetailsPage::from(&pod)) .build(), @@ -445,7 +433,7 @@ impl ContainerDetailsPage { let weak_ref = glib::WeakRef::new(); weak_ref.set(Some(&container)); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ScalableTextViewPage::from(view::Entity::Container { container: weak_ref, @@ -460,7 +448,7 @@ impl ContainerDetailsPage { pub(crate) fn show_log(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ContainerLogPage::from(&container)) .build(), @@ -472,7 +460,7 @@ impl ContainerDetailsPage { pub(crate) fn show_processes(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::TopPage::from(&container)) .build(), @@ -484,7 +472,7 @@ impl ContainerDetailsPage { pub(crate) fn show_tty(&self) { self.exec_action(|| { if let Some(container) = self.container() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ContainerTerminalPage::from(&container)) .build(), @@ -494,7 +482,7 @@ impl ContainerDetailsPage { } fn exec_action(&self, op: F) { - if utils::navigation_view(self.upcast_ref()) + if utils::navigation_view(self) .visible_page() .filter(|page| page.child().as_ref() == Some(self.upcast_ref())) .is_some() diff --git a/src/view/container_files_get_page.rs b/src/view/container_files_get_page.rs index eb7dd016..5df8cbbc 100644 --- a/src/view/container_files_get_page.rs +++ b/src/view/container_files_get_page.rs @@ -87,7 +87,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -107,11 +107,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.get_button)); + utils::root(widget).set_default_widget(Some(&*self.get_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -162,7 +162,7 @@ impl ContainerFilesGetPage { utils::show_save_file_dialog( request, - self.upcast_ref(), + self, clone!( #[weak(rename_to = obj)] self, diff --git a/src/view/container_files_put_page.rs b/src/view/container_files_put_page.rs index 215453ce..6f85b138 100644 --- a/src/view/container_files_put_page.rs +++ b/src/view/container_files_put_page.rs @@ -98,7 +98,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -118,11 +118,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.put_button)); + utils::root(widget).set_default_widget(Some(&*self.put_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -180,7 +180,7 @@ impl ContainerFilesPutPage { utils::show_open_file_dialog( request, - self.upcast_ref(), + self, clone!( #[weak(rename_to = obj)] self, diff --git a/src/view/container_health_check_page.rs b/src/view/container_health_check_page.rs index 1c83a8d3..bbc14c4a 100644 --- a/src/view/container_health_check_page.rs +++ b/src/view/container_health_check_page.rs @@ -119,7 +119,7 @@ mod imp { )) .bind(&*self.status_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.status_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.status_label); health_status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::ContainerHealthStatus| { @@ -179,7 +179,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -264,7 +264,7 @@ impl ContainerHealthCheckPage { self, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on running health check"), &e.to_string(), ); diff --git a/src/view/container_log_page.rs b/src/view/container_log_page.rs index c128971d..10f9e814 100644 --- a/src/view/container_log_page.rs +++ b/src/view/container_log_page.rs @@ -308,7 +308,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -512,7 +512,7 @@ impl ContainerLogPage { Err(e) => { log::warn!("Stopping container log stream due to error: {e}"); utils::show_error_toast( - self.upcast_ref(), + self, &gettext("Error while following log"), &e.to_string(), ); @@ -669,7 +669,7 @@ impl ContainerLogPage { utils::show_save_file_dialog( request, - self.upcast_ref(), + self, clone!( #[weak(rename_to = obj)] self, @@ -718,7 +718,7 @@ impl ContainerLogPage { Err(e) => { log::warn!("Error on saving logs: {e}"); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on saving logs"), &e.to_string(), ); @@ -732,7 +732,7 @@ impl ContainerLogPage { Err(e) => { log::warn!("Error on retrieving logs: {e}"); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on retrieving logs"), &e.to_string(), ); @@ -746,10 +746,7 @@ impl ContainerLogPage { obj, move || { obj.action_set_enabled(ACTION_SAVE_TO_FILE, true); - utils::show_toast( - obj.upcast_ref(), - gettext("Log has been saved"), - ); + utils::show_toast(&obj, gettext("Log has been saved")); } ), ); @@ -778,7 +775,7 @@ impl ContainerLogPage { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error starting container"), &e.to_string(), ); @@ -792,7 +789,7 @@ impl ContainerLogPage { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error resuming container"), &e.to_string(), ); diff --git a/src/view/container_menu_button.rs b/src/view/container_menu_button.rs index 6fd33348..24e54ede 100644 --- a/src/view/container_menu_button.rs +++ b/src/view/container_menu_button.rs @@ -42,30 +42,30 @@ mod imp { klass.bind_template(); klass.install_action(ACTION_START, None, |widget, _, _| { - view::container::start(widget.upcast_ref()); + view::container::start(widget, widget.container()); }); klass.install_action(ACTION_STOP, None, |widget, _, _| { - view::container::stop(widget.upcast_ref()); + view::container::stop(widget, widget.container()); }); klass.install_action(ACTION_KILL, None, |widget, _, _| { - view::container::kill(widget.upcast_ref()); + view::container::kill(widget, widget.container()); }); klass.install_action(ACTION_RESTART, None, |widget, _, _| { - view::container::restart(widget.upcast_ref()); + view::container::restart(widget, widget.container()); }); klass.install_action(ACTION_PAUSE, None, |widget, _, _| { - view::container::pause(widget.upcast_ref()); + view::container::pause(widget, widget.container()); }); klass.install_action(ACTION_RESUME, None, |widget, _, _| { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); }); klass.install_action(ACTION_RENAME, None, |widget, _, _| { - view::container::rename(widget.upcast_ref(), widget.container().as_ref()); + view::container::rename(widget, widget.container().as_ref()); }); klass.install_action(ACTION_DELETE, None, |widget, _, _| { - view::container::delete(widget.upcast_ref()); + view::container::delete(widget, widget.container()); }); } @@ -120,7 +120,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/container_properties_group.rs b/src/view/container_properties_group.rs index cf9461a9..7257e8b1 100644 --- a/src/view/container_properties_group.rs +++ b/src/view/container_properties_group.rs @@ -150,7 +150,7 @@ mod imp { let imp = obj.imp(); imp.port_bindings_label.set_label(""); - utils::ChildIter::from(imp.port_bindings_row.upcast_ref()) + utils::ChildIter::from(&*imp.port_bindings_row) .filter(|child| child.is::()) .for_each(|child| imp.port_bindings_row.remove(&child)); @@ -292,7 +292,7 @@ mod imp { )) .bind(&*self.status_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.status_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.status_label); status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::ContainerStatus| { @@ -313,7 +313,7 @@ mod imp { )) .bind(&*self.health_status_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.status_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.status_label); health_status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::ContainerHealthStatus| { diff --git a/src/view/container_renamer.rs b/src/view/container_renamer.rs index 7cbeecca..23011d32 100644 --- a/src/view/container_renamer.rs +++ b/src/view/container_renamer.rs @@ -70,7 +70,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/container_resources.rs b/src/view/container_resources.rs index b37129b8..4cfee978 100644 --- a/src/view/container_resources.rs +++ b/src/view/container_resources.rs @@ -253,7 +253,7 @@ impl ContainerResources { ), ); - let classes = utils::css_classes(progress_bar.upcast_ref()); + let classes = utils::css_classes(progress_bar); #[rustfmt::skip] percent_expr.chain_closure::>(closure!(|_: Self, value: f64| { diff --git a/src/view/container_row.rs b/src/view/container_row.rs index 0453e3b0..36d65c8a 100644 --- a/src/view/container_row.rs +++ b/src/view/container_row.rs @@ -103,7 +103,7 @@ mod imp { ) .bind(&*self.spinner, "icon-name", Some(obj)); - let css_classes = utils::css_classes(self.spinner.upcast_ref()); + let css_classes = utils::css_classes(&*self.spinner); gtk::ClosureExpression::new::>( [&status_expr, &health_status_expr], closure!(|_: Self::Type, @@ -260,7 +260,7 @@ impl ContainerRow { ))) .bind(&nav_page, "title", Some(self)); - utils::navigation_view(self.upcast_ref()).push(&nav_page); + utils::navigation_view(self).push(&nav_page); } } } diff --git a/src/view/container_terminal.rs b/src/view/container_terminal.rs index 7b411f57..ba898471 100644 --- a/src/view/container_terminal.rs +++ b/src/view/container_terminal.rs @@ -69,10 +69,10 @@ mod imp { klass.install_action(ACTION_START_OR_RESUME, None, |widget, _, _| { if let Some(container) = widget.container() { if container.can_start() { - view::container::start(widget.upcast_ref()); + view::container::start(widget, widget.container()); widget.action_set_enabled(ACTION_START_OR_RESUME, false); } else if container.can_resume() { - view::container::resume(widget.upcast_ref()); + view::container::resume(widget, widget.container()); widget.action_set_enabled(ACTION_START_OR_RESUME, false); } } @@ -223,7 +223,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -483,13 +483,12 @@ impl ContainerTerminal { move |result: podman::Result<_>| { if result.is_err() { utils::show_error_toast( - gio::Application::default() + &gio::Application::default() .unwrap() .downcast::() .unwrap() .main_window() - .toast_overlay() - .upcast_ref(), + .toast_overlay(), &gettext("Terminal error"), &gettext("'/bin/sh' not found"), ); diff --git a/src/view/container_terminal_page.rs b/src/view/container_terminal_page.rs index 8c5a8531..fead39a2 100644 --- a/src/view/container_terminal_page.rs +++ b/src/view/container_terminal_page.rs @@ -122,7 +122,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -133,12 +133,11 @@ mod imp { #[template_callback] fn on_terminal_terminated(&self) { let obj = &*self.obj(); - let widget = obj.upcast_ref(); - match utils::try_navigation_view(widget) { + match utils::try_navigation_view(obj) { Some(navigation_view) => { navigation_view.pop(); } - None => utils::root(widget).close(), + None => utils::root(obj).close(), } } } @@ -158,7 +157,7 @@ impl From<&model::Container> for ContainerTerminalPage { impl ContainerTerminalPage { pub(crate) fn pip_out(&self) { - if let Some(navigation_view) = utils::try_navigation_view(self.upcast_ref()) { + if let Some(navigation_view) = utils::try_navigation_view(self) { self.imp().terminal.keep_alive_on_next_unroot(); self.action_set_enabled(ACTION_PIP_OUT, false); diff --git a/src/view/container_volume_row.rs b/src/view/container_volume_row.rs index 71258217..72535d0c 100644 --- a/src/view/container_volume_row.rs +++ b/src/view/container_volume_row.rs @@ -105,7 +105,7 @@ mod imp { ) .bind(&*self.name_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.name_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.name_label); volume_name_is_id_expr .chain_closure::>(closure!(|_: Self::Type, name_is_id: bool| { css_classes @@ -219,7 +219,7 @@ impl ContainerVolumeRow { .as_ref() .and_then(model::ContainerVolume::volume) { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::VolumeDetailsPage::from(volume)) .build(), diff --git a/src/view/containers_count_bar.rs b/src/view/containers_count_bar.rs index 572b9f86..7c60d7db 100644 --- a/src/view/containers_count_bar.rs +++ b/src/view/containers_count_bar.rs @@ -82,7 +82,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/containers_panel.rs b/src/view/containers_panel.rs index e88fb880..cc66ffb1 100644 --- a/src/view/containers_panel.rs +++ b/src/view/containers_panel.rs @@ -330,7 +330,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -507,22 +507,15 @@ impl ContainersPanel { .as_ref() .and_then(model::ContainerList::client) { - utils::Dialog::new( - self.upcast_ref(), - view::ContainerCreationPage::from(&client).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::ContainerCreationPage::from(&client)).present(); } } pub(crate) fn show_prune_page(&self) { if let Some(client) = self.client() { - utils::Dialog::new( - self.upcast_ref(), - view::ContainersPrunePage::from(&client).upcast_ref(), - ) - .follows_content_size(true) - .present(); + utils::Dialog::new(self, &view::ContainersPrunePage::from(&client)) + .follows_content_size(true) + .present(); } } @@ -579,7 +572,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &if force { gettext("Error on killing container") } else { @@ -611,7 +604,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on restarting container"), &e.to_string(), ); @@ -637,7 +630,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on resuming container"), &e.to_string(), ); @@ -652,7 +645,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on starting container"), &e.to_string(), ); @@ -679,7 +672,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on pausing container"), &e.to_string(), ); @@ -735,7 +728,7 @@ impl ContainersPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on deleting container"), &e.to_string(), ); diff --git a/src/view/containers_prune_page.rs b/src/view/containers_prune_page.rs index 9094ccbd..0f5201fb 100644 --- a/src/view/containers_prune_page.rs +++ b/src/view/containers_prune_page.rs @@ -60,7 +60,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/containers_row.rs b/src/view/containers_row.rs index 21656914..b243cb1f 100644 --- a/src/view/containers_row.rs +++ b/src/view/containers_row.rs @@ -47,7 +47,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/image.rs b/src/view/image.rs index 63578a64..14effa7e 100644 --- a/src/view/image.rs +++ b/src/view/image.rs @@ -1,6 +1,7 @@ use adw::prelude::*; use gettextrs::gettext; use glib::clone; +use glib::clone::Downgrade; use gtk::gio; use gtk::glib; @@ -8,7 +9,10 @@ use crate::model; use crate::utils; use crate::view; -pub(crate) fn delete_image_show_confirmation(widget: >k::Widget, image: Option) { +pub(crate) fn delete_image_show_confirmation(widget: &W, image: Option) +where + W: IsA + Downgrade>, +{ if let Some(image) = image { match image.container_list().get(0) { Some(container) => { @@ -50,7 +54,10 @@ pub(crate) fn delete_image_show_confirmation(widget: >k::Widget, image: Option } } -pub(crate) fn delete_image(widget: >k::Widget, image: &model::Image) { +pub(crate) fn delete_image(widget: &W, image: &model::Image) +where + W: IsA + Downgrade>, +{ image.delete(clone!( #[weak] widget, @@ -67,12 +74,8 @@ pub(crate) fn delete_image(widget: >k::Widget, image: &model::Image) { )); } -pub(crate) fn create_container(widget: >k::Widget, image: Option) { +pub(crate) fn create_container>(widget: &W, image: Option) { if let Some(image) = image { - utils::Dialog::new( - widget, - view::ContainerCreationPage::from(&image).upcast_ref(), - ) - .present(); + utils::Dialog::new(widget, &view::ContainerCreationPage::from(&image)).present(); } } diff --git a/src/view/image_build_page.rs b/src/view/image_build_page.rs index a6959531..8eb8cb54 100644 --- a/src/view/image_build_page.rs +++ b/src/view/image_build_page.rs @@ -124,7 +124,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -144,11 +144,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.build_button)); + utils::root(widget).set_default_widget(Some(&*self.build_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -202,7 +202,7 @@ impl ImageBuildPage { utils::show_open_file_dialog( request, - self.upcast_ref(), + self, clone!( #[weak(rename_to = obj)] self, @@ -242,7 +242,7 @@ impl ImageBuildPage { if imp.tag_entry_row.text().contains(char::is_uppercase) { utils::show_toast( - self.upcast_ref(), + self, gettext("Image name must not contain uppercase characters"), ); return; diff --git a/src/view/image_details_page.rs b/src/view/image_details_page.rs index ebcdb55d..63e5cc3f 100644 --- a/src/view/image_details_page.rs +++ b/src/view/image_details_page.rs @@ -255,7 +255,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -282,7 +282,7 @@ mod imp { obj, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on loading image details"), &e.to_string(), ); @@ -294,10 +294,10 @@ mod imp { obj, move |image| { utils::show_toast( - obj.upcast_ref(), + &obj, gettext!("Image '{}' has been deleted", image.id()), ); - utils::navigation_view(obj.upcast_ref()).pop(); + utils::navigation_view(&obj).pop(); } )); self.handler_id.replace(Some(handler_id)); @@ -337,7 +337,7 @@ impl ImageDetailsPage { self.exec_action(|| { if let Some(image) = self.image() { let dialog = view::RepoTagAddDialog::from(&image); - dialog.set_transient_for(Some(&utils::root(self.upcast_ref()))); + dialog.set_transient_for(Some(&utils::root(self))); dialog.present(); } }); @@ -349,7 +349,7 @@ impl ImageDetailsPage { let weak_ref = glib::WeakRef::new(); weak_ref.set(Some(&image)); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ScalableTextViewPage::from(view::Entity::Image( weak_ref, @@ -363,7 +363,7 @@ impl ImageDetailsPage { fn show_history(&self) { self.exec_action(|| { if let Some(image) = self.image() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ImageHistoryPage::from(&image)) .build(), @@ -374,18 +374,18 @@ impl ImageDetailsPage { fn delete_image(&self) { self.exec_action(|| { - view::image::delete_image_show_confirmation(self.upcast_ref(), self.image()); + view::image::delete_image_show_confirmation(self, self.image()); }); } fn create_container(&self) { self.exec_action(|| { - view::image::create_container(self.upcast_ref(), self.image()); + view::image::create_container(self, self.image()); }); } fn exec_action(&self, op: F) { - if utils::navigation_view(self.upcast_ref()) + if utils::navigation_view(self) .visible_page() .filter(|page| page.child().as_ref() == Some(self.upcast_ref())) .is_some() diff --git a/src/view/image_history_page.rs b/src/view/image_history_page.rs index 9beb2cbb..d0b51545 100644 --- a/src/view/image_history_page.rs +++ b/src/view/image_history_page.rs @@ -44,7 +44,7 @@ mod imp { impl ObjectImpl for ImageHistoryPage { fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -188,7 +188,7 @@ impl From<&model::Image> for ImageHistoryPage { imp.spinner.set_visible(false); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on retrieving history"), &e.to_string(), ); diff --git a/src/view/image_menu_button.rs b/src/view/image_menu_button.rs index 69f21d99..cda91938 100644 --- a/src/view/image_menu_button.rs +++ b/src/view/image_menu_button.rs @@ -99,7 +99,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -114,10 +114,10 @@ glib::wrapper! { impl ImageMenuButton { pub(crate) fn delete_image(&self) { - view::image::delete_image_show_confirmation(self.upcast_ref(), self.image()); + view::image::delete_image_show_confirmation(self, self.image()); } pub(crate) fn create_container(&self) { - view::image::create_container(self.upcast_ref(), self.image()); + view::image::create_container(self, self.image()); } } diff --git a/src/view/image_pull_page.rs b/src/view/image_pull_page.rs index d38fd5df..078b5909 100644 --- a/src/view/image_pull_page.rs +++ b/src/view/image_pull_page.rs @@ -52,7 +52,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/image_row.rs b/src/view/image_row.rs index e76bf5ea..df62a3b2 100644 --- a/src/view/image_row.rs +++ b/src/view/image_row.rs @@ -109,7 +109,7 @@ mod imp { ) .bind(&*self.id_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.id_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.id_label); image_expr .chain_property::("repo-tags") .chain_property::("len") @@ -206,7 +206,7 @@ impl ImageRow { { image.select(); } else { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .title(gettext!("Image {}", utils::format_id(&image.id()))) .child(&view::ImageDetailsPage::from(image)) diff --git a/src/view/image_search_page.rs b/src/view/image_search_page.rs index 4f5d0444..16ca41f7 100644 --- a/src/view/image_search_page.rs +++ b/src/view/image_search_page.rs @@ -137,7 +137,7 @@ mod imp { if let Some(abort_handle) = self.search_abort_handle.take() { abort_handle.abort(); } - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -228,7 +228,7 @@ mod imp { Err(e) => { log::error!("Failed to search for images: {}", e); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Failed to search for images"), &e.to_string(), ); diff --git a/src/view/image_search_response_row.rs b/src/view/image_search_response_row.rs index fbea2ae6..0dec2a32 100644 --- a/src/view/image_search_response_row.rs +++ b/src/view/image_search_response_row.rs @@ -124,7 +124,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/image_selection_combo_row.rs b/src/view/image_selection_combo_row.rs index 03aee41d..ffa222e2 100644 --- a/src/view/image_selection_combo_row.rs +++ b/src/view/image_selection_combo_row.rs @@ -139,7 +139,7 @@ impl ImageSelectionComboRow { obj.set_image(Some(image)); } )); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&image_selection_page) .build(), @@ -162,7 +162,7 @@ impl ImageSelectionComboRow { obj.set_subtitle(image); } )); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&image_search_page) .build(), diff --git a/src/view/image_selection_page.rs b/src/view/image_selection_page.rs index 23e0b1fd..e07fbbe9 100644 --- a/src/view/image_selection_page.rs +++ b/src/view/image_selection_page.rs @@ -154,7 +154,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/images_panel.rs b/src/view/images_panel.rs index 0b9a740a..f73d3247 100644 --- a/src/view/images_panel.rs +++ b/src/view/images_panel.rs @@ -289,7 +289,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -429,33 +429,23 @@ impl ImagesPanel { pub(crate) fn show_download_page(&self) { if let Some(client) = self.client() { - utils::Dialog::new( - self.upcast_ref(), - view::ImagePullPage::from(&client).upcast_ref(), - ) - .height(640) - .present(); + utils::Dialog::new(self, &view::ImagePullPage::from(&client)) + .height(640) + .present(); } } pub(crate) fn show_build_page(&self) { if let Some(client) = self.client() { - utils::Dialog::new( - self.upcast_ref(), - view::ImageBuildPage::from(&client).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::ImageBuildPage::from(&client)).present(); } } pub(crate) fn show_prune_page(&self) { if let Some(client) = self.client() { - utils::Dialog::new( - self.upcast_ref(), - view::ImagesPrunePage::from(&client).upcast_ref(), - ) - .follows_content_size(true) - .present(); + utils::Dialog::new(self, &view::ImagesPrunePage::from(&client)) + .follows_content_size(true) + .present(); } } @@ -533,7 +523,7 @@ impl ImagesPanel { move |image, result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, // Translators: The first "{}" is a placeholder for the image id, the second is for an error message. &gettext!( "Error on deleting image '{}'", diff --git a/src/view/images_prune_page.rs b/src/view/images_prune_page.rs index f375e43a..6f7e6374 100644 --- a/src/view/images_prune_page.rs +++ b/src/view/images_prune_page.rs @@ -81,7 +81,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/images_row.rs b/src/view/images_row.rs index 3746e813..bdd45a83 100644 --- a/src/view/images_row.rs +++ b/src/view/images_row.rs @@ -47,7 +47,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/info_panel.rs b/src/view/info_panel.rs index 9dc55ca5..6e2da14e 100644 --- a/src/view/info_panel.rs +++ b/src/view/info_panel.rs @@ -109,7 +109,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -325,7 +325,7 @@ impl InfoPanel { log::error!("Failed to retrieve host info: {e}"); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on retrieving info"), &e.to_string(), ); diff --git a/src/view/info_row.rs b/src/view/info_row.rs index e1ca672e..bc47e30c 100644 --- a/src/view/info_row.rs +++ b/src/view/info_row.rs @@ -75,7 +75,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/mount_row.rs b/src/view/mount_row.rs index e7506650..4b69ab08 100644 --- a/src/view/mount_row.rs +++ b/src/view/mount_row.rs @@ -331,7 +331,7 @@ impl MountRow { } } )); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&volume_selection_page) .build(), diff --git a/src/view/pod.rs b/src/view/pod.rs index 236d116e..572279cc 100644 --- a/src/view/pod.rs +++ b/src/view/pod.rs @@ -1,6 +1,7 @@ use adw::prelude::*; use gettextrs::gettext; use glib::clone; +use glib::clone::Downgrade; use gtk::gio; use gtk::glib; @@ -21,13 +22,14 @@ pub(crate) fn pod_status_css_class(status: model::PodStatus) -> &'static str { macro_rules! pod_action { (fn $name:ident => $action:ident($($param:literal),*) => $error:tt) => { - pub(crate) fn $name(widget: >k::Widget) { - use gtk::glib; - - if let Some(pod) = ::property::>(widget, "pod") { + pub(crate) fn $name(widget: &W, pod: Option) + where + W: gtk::glib::prelude::IsA + gtk::glib::clone::Downgrade>, + { + if let Some(pod) = pod { pod.$action( $($param,)* - glib::clone!(#[weak] widget, move |result| if let Err(e) = result { + gtk::glib::clone!(#[weak] widget, move |result| if let Err(e) = result { crate::utils::show_error_toast(&widget, &$error, &e.to_string()); }), ); @@ -44,10 +46,11 @@ pod_action!(fn pause => pause() => { gettextrs::gettext("Error on pausing pod") pod_action!(fn resume => resume() => { gettextrs::gettext("Error on resuming pod") }); pod_action!(fn delete => delete(false) => { gettextrs::gettext("Error on deleting pod") }); -pub(crate) fn show_delete_confirmation_dialog(widget: >k::Widget) { - if let Some(pod) = - ::property::>(widget, "pod") - { +pub(crate) fn show_delete_confirmation_dialog(widget: &W, pod: Option) +where + W: IsA + Downgrade>, +{ + if let Some(pod) = pod { match pod.container_list().first_non_infra() { Some(container) => { let dialog = adw::AlertDialog::builder() @@ -75,19 +78,19 @@ pub(crate) fn show_delete_confirmation_dialog(widget: >k::Widget) { widget, move |response| { if response == "delete" { - delete(&widget); + delete(&widget, Some(pod)); } } ), ); } - None => delete(widget), + None => delete(widget, Some(pod)), } } } -pub(crate) fn create_container(widget: >k::Widget, pod: Option) { +pub(crate) fn create_container>(widget: &W, pod: Option) { if let Some(pod) = pod { - utils::Dialog::new(widget, view::ContainerCreationPage::from(&pod).upcast_ref()).present(); + utils::Dialog::new(widget, &view::ContainerCreationPage::from(&pod)).present(); } } diff --git a/src/view/pod_creation_page.rs b/src/view/pod_creation_page.rs index 89661c36..ada27614 100644 --- a/src/view/pod_creation_page.rs +++ b/src/view/pod_creation_page.rs @@ -217,7 +217,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -237,11 +237,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.create_button)); + utils::root(widget).set_default_widget(Some(&*self.create_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } diff --git a/src/view/pod_details_page.rs b/src/view/pod_details_page.rs index 9f8eddfa..31783c6f 100644 --- a/src/view/pod_details_page.rs +++ b/src/view/pod_details_page.rs @@ -69,28 +69,28 @@ mod imp { klass.install_action(ACTION_START_OR_RESUME, None, |widget, _, _| { if widget.pod().map(|pod| pod.can_start()).unwrap_or(false) { - view::pod::start(widget.upcast_ref()); + view::pod::start(widget, widget.pod()); } else { - view::pod::resume(widget.upcast_ref()); + view::pod::resume(widget, widget.pod()); } }); klass.install_action(ACTION_STOP, None, |widget, _, _| { - view::pod::stop(widget.upcast_ref()); + view::pod::stop(widget, widget.pod()); }); klass.install_action(ACTION_KILL, None, |widget, _, _| { - view::pod::kill(widget.upcast_ref()); + view::pod::kill(widget, widget.pod()); }); klass.install_action(ACTION_RESTART, None, |widget, _, _| { - view::pod::restart(widget.upcast_ref()); + view::pod::restart(widget, widget.pod()); }); klass.install_action(ACTION_PAUSE, None, |widget, _, _| { - view::pod::pause(widget.upcast_ref()); + view::pod::pause(widget, widget.pod()); }); klass.install_action(ACTION_RESUME, None, |widget, _, _| { - view::pod::resume(widget.upcast_ref()); + view::pod::resume(widget, widget.pod()); }); klass.install_action(ACTION_DELETE, None, |widget, _, _| { - view::pod::delete(widget.upcast_ref()); + view::pod::delete(widget, widget.pod()); }); klass.install_action(ACTION_INSPECT_POD, None, |widget, _, _| { @@ -176,7 +176,7 @@ mod imp { })) .bind(&*self.status_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.status_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.status_label); status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::PodStatus| { @@ -219,7 +219,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -244,7 +244,7 @@ mod imp { obj, move |result| if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on loading pod data"), &e.to_string(), ); @@ -255,11 +255,8 @@ mod imp { #[weak] obj, move |pod| { - utils::show_toast( - obj.upcast_ref(), - gettext!("Pod '{}' has been deleted", pod.name()), - ); - utils::navigation_view(obj.upcast_ref()).pop(); + utils::show_toast(&obj, gettext!("Pod '{}' has been deleted", pod.name())); + utils::navigation_view(&obj).pop(); } )); self.handler_id.replace(Some(handler_id)); @@ -324,7 +321,7 @@ impl PodDetailsPage { let weak_ref = glib::WeakRef::new(); weak_ref.set(Some(&pod)); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ScalableTextViewPage::from(view::Entity::Pod { pod: weak_ref, @@ -339,7 +336,7 @@ impl PodDetailsPage { fn show_processes(&self) { self.exec_action(|| { if let Some(pod) = self.pod() { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::TopPage::from(&pod)) .build(), @@ -350,12 +347,12 @@ impl PodDetailsPage { fn create_container(&self) { self.exec_action(|| { - view::pod::create_container(self.upcast_ref(), self.pod()); + view::pod::create_container(self, self.pod()); }); } fn exec_action(&self, op: F) { - if utils::navigation_view(self.upcast_ref()) + if utils::navigation_view(self) .visible_page() .filter(|page| page.child().as_ref() == Some(self.upcast_ref())) .is_some() diff --git a/src/view/pod_menu_button.rs b/src/view/pod_menu_button.rs index cc8f45d4..7ffa5387 100644 --- a/src/view/pod_menu_button.rs +++ b/src/view/pod_menu_button.rs @@ -46,26 +46,26 @@ mod imp { }); klass.install_action(ACTION_START, None, |widget, _, _| { - view::pod::start(widget.upcast_ref()); + view::pod::start(widget, widget.pod()); }); klass.install_action(ACTION_STOP, None, |widget, _, _| { - view::pod::stop(widget.upcast_ref()); + view::pod::stop(widget, widget.pod()); }); klass.install_action(ACTION_KILL, None, |widget, _, _| { - view::pod::kill(widget.upcast_ref()); + view::pod::kill(widget, widget.pod()); }); klass.install_action(ACTION_RESTART, None, |widget, _, _| { - view::pod::restart(widget.upcast_ref()); + view::pod::restart(widget, widget.pod()); }); klass.install_action(ACTION_PAUSE, None, |widget, _, _| { - view::pod::pause(widget.upcast_ref()); + view::pod::pause(widget, widget.pod()); }); klass.install_action(ACTION_RESUME, None, |widget, _, _| { - view::pod::resume(widget.upcast_ref()); + view::pod::resume(widget, widget.pod()); }); klass.install_action(ACTION_DELETE, None, |widget, _, _| { - view::pod::show_delete_confirmation_dialog(widget.upcast_ref()); + view::pod::show_delete_confirmation_dialog(widget, widget.pod()); }); } @@ -118,7 +118,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -133,7 +133,7 @@ glib::wrapper! { impl PodMenuButton { pub(crate) fn create_container(&self) { - view::pod::create_container(self.upcast_ref(), self.pod()); + view::pod::create_container(self, self.pod()); } fn update_actions(&self) { diff --git a/src/view/pod_row.rs b/src/view/pod_row.rs index 053cbc19..ac6a15db 100644 --- a/src/view/pod_row.rs +++ b/src/view/pod_row.rs @@ -112,7 +112,7 @@ mod imp { })) .bind(&*self.spinner, "icon-name", Some(obj)); - let css_classes = utils::css_classes(self.spinner.upcast_ref()); + let css_classes = utils::css_classes(&*self.spinner); status_expr .chain_closure::>(closure!( |_: Self::Type, status: model::PodStatus| { @@ -219,7 +219,7 @@ mod imp { )) .build(); - let css_classes = utils::css_classes(label.upcast_ref()); + let css_classes = utils::css_classes(&label); super::PodRow::this_expression("pod") .chain_property::("status") .chain_closure::>(closure!( @@ -269,7 +269,7 @@ impl PodRow { { pod.select(); } else { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .title(gettext("Pod Details")) .child(&view::PodDetailsPage::from(pod)) diff --git a/src/view/pod_selection_page.rs b/src/view/pod_selection_page.rs index 39469d97..02999fa0 100644 --- a/src/view/pod_selection_page.rs +++ b/src/view/pod_selection_page.rs @@ -155,7 +155,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -300,7 +300,7 @@ impl PodSelectionPage { let imp = self.imp(); if !enable && !imp.filter_button.is_active() { - utils::navigation_view(self.upcast_ref()).pop(); + utils::navigation_view(self).pop(); } else { imp.filter_button.set_active(enable); if !enable { @@ -318,11 +318,7 @@ impl PodSelectionPage { pub(crate) fn create_pod(&self) { if let Some(client) = self.pod_list().and_then(|list| list.client()) { - utils::Dialog::new( - self.upcast_ref(), - view::PodCreationPage::new(&client, false).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::PodCreationPage::new(&client, false)).present(); } } @@ -336,7 +332,7 @@ impl PodSelectionPage { if let Some(pod) = self.selected_pod() { self.emit_by_name::<()>("pod-selected", &[&pod]); - utils::navigation_view(self.upcast_ref()).pop(); + utils::navigation_view(self).pop(); } } diff --git a/src/view/pods_panel.rs b/src/view/pods_panel.rs index 7cfdb4df..24e29847 100644 --- a/src/view/pods_panel.rs +++ b/src/view/pods_panel.rs @@ -295,7 +295,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -430,21 +430,13 @@ impl PodsPanel { pub(crate) fn create_pod(&self) { if let Some(client) = self.pod_list().as_ref().and_then(model::PodList::client) { - utils::Dialog::new( - self.upcast_ref(), - view::PodCreationPage::from(&client).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::PodCreationPage::from(&client)).present(); } } pub(crate) fn prune_pods(&self) { if let Some(client) = self.pod_list().and_then(|pod_list| pod_list.client()) { - utils::Dialog::new( - self.upcast_ref(), - view::PodsPrunePage::from(&client).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::PodsPrunePage::from(&client)).present(); } } @@ -494,7 +486,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on resuming pod"), &e.to_string(), ); @@ -509,7 +501,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on starting pod"), &e.to_string(), ); @@ -538,7 +530,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &if force { gettext("Error on killing pod") } else { @@ -568,7 +560,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on stopping pod"), &e.to_string(), ); @@ -595,7 +587,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on restarting pod"), &e.to_string(), ); @@ -645,7 +637,7 @@ impl PodsPanel { move |result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on deleting pod"), &e.to_string(), ); diff --git a/src/view/pods_prune_page.rs b/src/view/pods_prune_page.rs index 04e92561..c5bd4862 100644 --- a/src/view/pods_prune_page.rs +++ b/src/view/pods_prune_page.rs @@ -56,7 +56,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/pods_row.rs b/src/view/pods_row.rs index b3d75603..f02f1a52 100644 --- a/src/view/pods_row.rs +++ b/src/view/pods_row.rs @@ -47,7 +47,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/repo_tag_push_page.rs b/src/view/repo_tag_push_page.rs index 46f05e71..29047cee 100644 --- a/src/view/repo_tag_push_page.rs +++ b/src/view/repo_tag_push_page.rs @@ -174,7 +174,7 @@ mod imp { Err(e) => { log::error!("Error on accessing keyring: {e}"); utils::show_error_toast( - imp.toast_overlay.upcast_ref(), + &*imp.toast_overlay, &gettext("Error on accessing keyring"), &e.to_string(), ); @@ -191,18 +191,18 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } impl WidgetImpl for RepoTagPushPage { fn root(&self) { self.parent_root(); - utils::root(self.obj().upcast_ref()).set_default_widget(Some(&*self.push_button)); + utils::root(&*self.obj()).set_default_widget(Some(&*self.push_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } @@ -269,7 +269,7 @@ impl RepoTagPushPage { None => { log::error!("Cannot save credentials, because secret service isn't available."); utils::show_error_toast( - imp.toast_overlay.upcast_ref(), + &*imp.toast_overlay, &gettext("Error saving credentials"), &gettext("Secret Service is not available"), ); diff --git a/src/view/repo_tag_row.rs b/src/view/repo_tag_row.rs index 713bde0d..d406c78c 100644 --- a/src/view/repo_tag_row.rs +++ b/src/view/repo_tag_row.rs @@ -188,11 +188,7 @@ impl RepoTagRow { fn push(&self) { if let Some(repo_tag) = self.repo_tag() { - utils::Dialog::new( - self.upcast_ref(), - view::RepoTagPushPage::from(&repo_tag).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::RepoTagPushPage::from(&repo_tag)).present(); } } @@ -229,7 +225,7 @@ impl RepoTagRow { } log::warn!("Error on untagging image: {e}"); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Error on untagging image"), &e.to_string(), ); diff --git a/src/view/repo_tag_selection_page.rs b/src/view/repo_tag_selection_page.rs index e940eded..ae9fffd7 100644 --- a/src/view/repo_tag_selection_page.rs +++ b/src/view/repo_tag_selection_page.rs @@ -164,7 +164,7 @@ mod imp { Err(e) => { log::error!("Failed to search for images: {}", e); utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext("Failed to search for images"), &e.to_string(), ); @@ -230,7 +230,7 @@ mod imp { fn dispose(&self) { self.search_abort_handle.get().unwrap().abort(); - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/scalable_text_view_page.rs b/src/view/scalable_text_view_page.rs index bec7a1bb..fe55f53d 100644 --- a/src/view/scalable_text_view_page.rs +++ b/src/view/scalable_text_view_page.rs @@ -204,7 +204,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -318,10 +318,7 @@ impl From for ScalableTextViewPage { Some(lang) => imp.source_buffer.set_language(Some(&lang)), None => { log::warn!("Could not set language to '{language}'"); - utils::show_toast( - obj.upcast_ref(), - gettext!("Could not set language to '{}'", language), - ); + utils::show_toast(&obj, gettext!("Could not set language to '{}'", language)); } } @@ -423,14 +420,14 @@ impl ScalableTextViewPage { Err(e) => { imp.spinner.set_visible(false); utils::show_error_toast( - self.upcast_ref(), + self, &match mode { Mode::Inspect => gettext("Inspection error"), Mode::Kube => gettext("Kube generation error"), }, &e.to_string(), ); - utils::navigation_view(self.upcast_ref()).pop(); + utils::navigation_view(self).pop(); } } } @@ -445,7 +442,7 @@ impl ScalableTextViewPage { utils::show_save_file_dialog( request, - self.upcast_ref(), + self, clone!( #[weak(rename_to = obj)] self, @@ -471,11 +468,7 @@ impl ScalableTextViewPage { .write_all_future(text, glib::Priority::default()) .await { - utils::show_error_toast( - obj.upcast_ref(), - &gettext("Error"), - &msg, - ); + utils::show_error_toast(&obj, &gettext("Error"), &msg); } } )); diff --git a/src/view/search_panel.rs b/src/view/search_panel.rs index f7aacbbf..a07fab24 100644 --- a/src/view/search_panel.rs +++ b/src/view/search_panel.rs @@ -149,7 +149,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -157,7 +157,7 @@ mod imp { fn map(&self) { self.parent_map(); self.search_entry - .set_key_capture_widget(Some(&utils::root(self.obj().upcast_ref()))); + .set_key_capture_widget(Some(&utils::root(&*self.obj()))); self.search_entry.grab_focus(); self.search_entry.select_region(0, -1); } diff --git a/src/view/search_row.rs b/src/view/search_row.rs index 8d72ac2c..5af9de03 100644 --- a/src/view/search_row.rs +++ b/src/view/search_row.rs @@ -1,4 +1,3 @@ -use adw::prelude::*; use adw::subclass::prelude::*; use gtk::glib; use gtk::CompositeTemplate; @@ -29,7 +28,7 @@ mod imp { impl ObjectImpl for SearchRow { fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/top_page.rs b/src/view/top_page.rs index b4c0ba19..06261e4e 100644 --- a/src/view/top_page.rs +++ b/src/view/top_page.rs @@ -393,7 +393,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -528,17 +528,13 @@ impl TopPage { #[weak(rename_to = obj)] self, move |result| if let Err(e) = result { - utils::show_error_toast( - obj.upcast_ref(), - &gettext("Error"), - e.trim(), - ); + utils::show_error_toast(&obj, &gettext("Error"), e.trim()); } ), ) } None => utils::show_error_toast( - self.upcast_ref(), + self, &gettext("Error"), &gettext("Killing pod processes is not supported"), ), diff --git a/src/view/volume.rs b/src/view/volume.rs index 2997f82f..8a0e070c 100644 --- a/src/view/volume.rs +++ b/src/view/volume.rs @@ -1,6 +1,7 @@ use adw::prelude::*; use gettextrs::gettext; use glib::clone; +use glib::clone::Downgrade; use gtk::gio; use gtk::glib; @@ -8,7 +9,10 @@ use crate::model; use crate::utils; use crate::view; -pub(crate) fn delete_volume_show_confirmation(widget: >k::Widget, volume: Option) { +pub(crate) fn delete_volume_show_confirmation(widget: &W, volume: Option) +where + W: IsA + Downgrade>, +{ if let Some(volume) = volume { match volume.container_list().get(0) { Some(container) => { @@ -50,7 +54,10 @@ pub(crate) fn delete_volume_show_confirmation(widget: >k::Widget, volume: Opti } } -fn delete_volume(widget: >k::Widget, volume: &model::Volume, force: bool) { +fn delete_volume(widget: &W, volume: &model::Volume, force: bool) +where + W: IsA + Downgrade>, +{ volume.delete( force, clone!( @@ -70,12 +77,8 @@ fn delete_volume(widget: >k::Widget, volume: &model::Volume, force: bool) { ); } -pub(crate) fn create_container(widget: >k::Widget, volume: Option) { +pub(crate) fn create_container>(widget: &W, volume: Option) { if let Some(volume) = volume { - utils::Dialog::new( - widget, - view::ContainerCreationPage::from(&volume).upcast_ref(), - ) - .present(); + utils::Dialog::new(widget, &view::ContainerCreationPage::from(&volume)).present(); } } diff --git a/src/view/volume_creation_page.rs b/src/view/volume_creation_page.rs index 6e042e31..1812c372 100644 --- a/src/view/volume_creation_page.rs +++ b/src/view/volume_creation_page.rs @@ -67,7 +67,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -87,11 +87,11 @@ mod imp { glib::ControlFlow::Break } )); - utils::root(widget.upcast_ref()).set_default_widget(Some(&*self.create_button)); + utils::root(widget).set_default_widget(Some(&*self.create_button)); } fn unroot(&self) { - utils::root(self.obj().upcast_ref()).set_default_widget(gtk::Widget::NONE); + utils::root(&*self.obj()).set_default_widget(gtk::Widget::NONE); self.parent_unroot() } } diff --git a/src/view/volume_details_page.rs b/src/view/volume_details_page.rs index e0144bbf..380f23c3 100644 --- a/src/view/volume_details_page.rs +++ b/src/view/volume_details_page.rs @@ -157,7 +157,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -184,10 +184,10 @@ mod imp { obj, move |volume| { utils::show_toast( - obj.upcast_ref(), + &obj, gettext!("Volume '{}' has been deleted", volume.inner().name), ); - utils::navigation_view(obj.upcast_ref()).pop(); + utils::navigation_view(&obj).pop(); } )); self.handler_id.replace(Some(handler_id)); @@ -218,7 +218,7 @@ impl VolumeDetailsPage { let weak_ref = glib::WeakRef::new(); weak_ref.set(Some(&volume)); - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .child(&view::ScalableTextViewPage::from(view::Entity::Volume( weak_ref, @@ -231,12 +231,12 @@ impl VolumeDetailsPage { pub(crate) fn delete_volume(&self) { self.exec_action(|| { - view::volume::delete_volume_show_confirmation(self.upcast_ref(), self.volume()); + view::volume::delete_volume_show_confirmation(self, self.volume()); }); } fn exec_action(&self, op: F) { - if utils::navigation_view(self.upcast_ref()) + if utils::navigation_view(self) .visible_page() .filter(|page| page.child().as_ref() == Some(self.upcast_ref())) .is_some() @@ -247,7 +247,7 @@ impl VolumeDetailsPage { pub(crate) fn create_container(&self) { self.exec_action(|| { - view::volume::create_container(self.upcast_ref(), self.volume()); + view::volume::create_container(self, self.volume()); }); } } diff --git a/src/view/volume_row.rs b/src/view/volume_row.rs index 4528909a..1a57ee11 100644 --- a/src/view/volume_row.rs +++ b/src/view/volume_row.rs @@ -139,7 +139,7 @@ mod imp { ) .bind(&*self.name_label, "label", Some(obj)); - let css_classes = utils::css_classes(self.name_label.upcast_ref()); + let css_classes = utils::css_classes(&*self.name_label); gtk::ClosureExpression::new::>( [ container_list_expr @@ -277,7 +277,7 @@ impl VolumeRow { { volume.select(); } else { - utils::navigation_view(self.upcast_ref()).push( + utils::navigation_view(self).push( &adw::NavigationPage::builder() .title(gettext!( "Volume {}", @@ -291,6 +291,6 @@ impl VolumeRow { } pub(crate) fn delete_volume(&self) { - view::volume::delete_volume_show_confirmation(self.upcast_ref(), self.volume()); + view::volume::delete_volume_show_confirmation(self, self.volume()); } } diff --git a/src/view/volume_selection_page.rs b/src/view/volume_selection_page.rs index 4cc24611..91fe2012 100644 --- a/src/view/volume_selection_page.rs +++ b/src/view/volume_selection_page.rs @@ -155,7 +155,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -303,7 +303,7 @@ impl VolumeSelectionPage { let imp = self.imp(); if !enable && !imp.filter_button.is_active() { - utils::navigation_view(self.upcast_ref()).pop(); + utils::navigation_view(self).pop(); } else { imp.filter_button.set_active(enable); if !enable { @@ -321,11 +321,7 @@ impl VolumeSelectionPage { pub(crate) fn create_volume(&self) { if let Some(client) = self.volume_list().and_then(|list| list.client()) { - utils::Dialog::new( - self.upcast_ref(), - view::VolumeCreationPage::new(&client, false).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::VolumeCreationPage::new(&client, false)).present(); } } @@ -339,7 +335,7 @@ impl VolumeSelectionPage { if let Some(volume) = self.selected_volume() { self.emit_by_name::<()>("volume-selected", &[&volume]); - utils::navigation_view(self.upcast_ref()).pop(); + utils::navigation_view(self).pop(); } } diff --git a/src/view/volumes_panel.rs b/src/view/volumes_panel.rs index ef57266e..3373f77d 100644 --- a/src/view/volumes_panel.rs +++ b/src/view/volumes_panel.rs @@ -266,7 +266,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } @@ -412,22 +412,15 @@ impl VolumesPanel { .as_ref() .and_then(model::VolumeList::client) { - utils::Dialog::new( - self.upcast_ref(), - view::VolumeCreationPage::from(&client).upcast_ref(), - ) - .present(); + utils::Dialog::new(self, &view::VolumeCreationPage::from(&client)).present(); } } pub(crate) fn show_prune_page(&self) { if let Some(client) = self.volume_list().and_then(|list| list.client()) { - utils::Dialog::new( - self.upcast_ref(), - view::VolumesPrunePage::from(&client).upcast_ref(), - ) - .follows_content_size(true) - .present(); + utils::Dialog::new(self, &view::VolumesPrunePage::from(&client)) + .follows_content_size(true) + .present(); } } @@ -507,7 +500,7 @@ impl VolumesPanel { move |volume, result| { if let Err(e) = result { utils::show_error_toast( - obj.upcast_ref(), + &obj, &gettext!( "Error on deleting volume '{}'", volume.inner().name diff --git a/src/view/volumes_prune_page.rs b/src/view/volumes_prune_page.rs index bc8dc0f3..fc33736b 100644 --- a/src/view/volumes_prune_page.rs +++ b/src/view/volumes_prune_page.rs @@ -60,7 +60,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/volumes_row.rs b/src/view/volumes_row.rs index 28392483..e2d92875 100644 --- a/src/view/volumes_row.rs +++ b/src/view/volumes_row.rs @@ -47,7 +47,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/welcome_page.rs b/src/view/welcome_page.rs index a8882eb4..ba3ceebc 100644 --- a/src/view/welcome_page.rs +++ b/src/view/welcome_page.rs @@ -47,7 +47,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/view/window.rs b/src/view/window.rs index 2217c39f..b28aef60 100644 --- a/src/view/window.rs +++ b/src/view/window.rs @@ -170,7 +170,7 @@ mod imp { manager, move |e| { utils::show_error_toast( - obj.imp().toast_overlay.upcast_ref(), + &*obj.imp().toast_overlay, "Connection lost", &e.to_string(), ); @@ -253,8 +253,8 @@ impl Window { pub(crate) fn add_connection(&self) { utils::Dialog::new( - self.upcast_ref(), - view::ConnectionCreationPage::from(&self.connection_manager()).upcast_ref(), + self, + &view::ConnectionCreationPage::from(&self.connection_manager()), ) .present(); } @@ -285,11 +285,7 @@ impl Window { "welcome" }); - utils::show_error_toast( - imp.toast_overlay.upcast_ref(), - "Connection lost", - &e.to_string(), - ); + utils::show_error_toast(&*imp.toast_overlay, "Connection lost", &e.to_string()); } fn client_err_op(&self, e: model::ClientError) { diff --git a/src/widget/circular_progress_bar.rs b/src/widget/circular_progress_bar.rs index 6a0fbc68..a6a997ea 100644 --- a/src/widget/circular_progress_bar.rs +++ b/src/widget/circular_progress_bar.rs @@ -97,7 +97,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/count_badge.rs b/src/widget/count_badge.rs index a666b1f1..c3897992 100644 --- a/src/widget/count_badge.rs +++ b/src/widget/count_badge.rs @@ -95,7 +95,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()) + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/main_menu_button.rs b/src/widget/main_menu_button.rs index e4bc8732..d7472d22 100644 --- a/src/widget/main_menu_button.rs +++ b/src/widget/main_menu_button.rs @@ -1,4 +1,3 @@ -use adw::prelude::*; use adw::subclass::prelude::*; use gtk::glib; use gtk::CompositeTemplate; @@ -29,7 +28,7 @@ mod imp { impl ObjectImpl for MainMenuButton { fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/source_view_search_widget.rs b/src/widget/source_view_search_widget.rs index aea8a93a..a2d19727 100644 --- a/src/widget/source_view_search_widget.rs +++ b/src/widget/source_view_search_widget.rs @@ -116,7 +116,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/spinner.rs b/src/widget/spinner.rs index 295de8f6..ef6c5196 100644 --- a/src/widget/spinner.rs +++ b/src/widget/spinner.rs @@ -116,7 +116,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/text_search_entry.rs b/src/widget/text_search_entry.rs index 09145a72..de9db234 100644 --- a/src/widget/text_search_entry.rs +++ b/src/widget/text_search_entry.rs @@ -110,7 +110,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } } diff --git a/src/widget/zoom_control.rs b/src/widget/zoom_control.rs index 537dbdc1..446f527e 100644 --- a/src/widget/zoom_control.rs +++ b/src/widget/zoom_control.rs @@ -95,7 +95,7 @@ mod imp { } fn dispose(&self) { - utils::unparent_children(self.obj().upcast_ref()); + utils::unparent_children(&*self.obj()); } }