From c41d1e704f9f5fb18f68857ca2d063f7928019e5 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 3 Mar 2017 21:59:39 +0000 Subject: [PATCH 1/3] trivial: Switch the shell refresh code to a vfunc This allows us to make the page code much simpler. --- src/gs-page.c | 14 +++- src/gs-page.h | 12 ++- src/gs-shell-category.c | 56 +++++++------- src/gs-shell-category.h | 5 -- src/gs-shell-details.c | 18 ++--- src/gs-shell-details.h | 5 -- src/gs-shell-extras.c | 19 +++-- src/gs-shell-extras.h | 5 -- src/gs-shell-installed.c | 20 +++-- src/gs-shell-installed.h | 6 -- src/gs-shell-loading.c | 15 ++-- src/gs-shell-loading.h | 5 -- src/gs-shell-moderate.c | 18 ++--- src/gs-shell-moderate.h | 5 -- src/gs-shell-overview.c | 20 +++-- src/gs-shell-overview.h | 6 -- src/gs-shell-search.c | 19 +++-- src/gs-shell-search.h | 5 -- src/gs-shell-updates.c | 18 ++--- src/gs-shell-updates.h | 5 -- src/gs-shell.c | 195 +++++++++++++++++++++++------------------------ 21 files changed, 210 insertions(+), 261 deletions(-) diff --git a/src/gs-page.c b/src/gs-page.c index 69424b2..eed74fd 100644 --- a/src/gs-page.c +++ b/src/gs-page.c @@ -630,18 +630,26 @@ gs_page_reload (GsPage *page) klass->reload (page); } -void +gboolean gs_page_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, - GCancellable *cancellable) + GtkBuilder *builder, + GCancellable *cancellable, + GError **error) { + GsPageClass *klass; GsPagePrivate *priv = gs_page_get_instance_private (page); - g_return_if_fail (GS_IS_PAGE (page)); + g_return_val_if_fail (GS_IS_PAGE (page), FALSE); + + klass = GS_PAGE_GET_CLASS (page); + g_assert (klass->setup != NULL); priv->plugin_loader = g_object_ref (plugin_loader); priv->shell = shell; + + return klass->setup (page, shell, plugin_loader, builder, cancellable, error); } static void diff --git a/src/gs-page.h b/src/gs-page.h index 13d2fa7..1d5c64f 100644 --- a/src/gs-page.h +++ b/src/gs-page.h @@ -45,6 +45,12 @@ struct _GsPageClass void (*switch_to) (GsPage *page, gboolean scroll_up); void (*reload) (GsPage *page); + gboolean (*setup) (GsPage *page, + GsShell *shell, + GsPluginLoader *plugin_loader, + GtkBuilder *builder, + GCancellable *cancellable, + GError **error); }; GsPage *gs_page_new (void); @@ -76,10 +82,12 @@ void gs_page_shortcut_remove (GsPage *page, void gs_page_switch_to (GsPage *page, gboolean scroll_up); void gs_page_reload (GsPage *page); -void gs_page_setup (GsPage *page, +gboolean gs_page_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, - GCancellable *cancellable); + GtkBuilder *builder, + GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c index 5c401ed..56f6d19 100644 --- a/src/gs-shell-category.c +++ b/src/gs-shell-category.c @@ -277,27 +277,6 @@ gs_shell_category_dispose (GObject *object) G_OBJECT_CLASS (gs_shell_category_parent_class)->dispose (object); } -static void -gs_shell_category_class_init (GsShellCategoryClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GsPageClass *page_class = GS_PAGE_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = gs_shell_category_dispose; - page_class->switch_to = gs_shell_category_switch_to; - page_class->reload = gs_shell_category_reload; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-category.ui"); - - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, category_detail_box); - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, infobar_category_shell_extensions); - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, button_category_shell_extensions); - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, listbox_filter); - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, scrolledwindow_category); - gtk_widget_class_bind_template_child (widget_class, GsShellCategory, scrolledwindow_filter); -} - static gboolean key_event (GtkWidget *listbox, GdkEvent *event, GsShellCategory *self) { @@ -336,13 +315,15 @@ button_shell_extensions_cb (GtkButton *button, GsShellCategory *self) g_warning ("failed to exec %s: %s", argv[0], error->message); } -void -gs_shell_category_setup (GsShellCategory *self, +static gboolean +gs_shell_category_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellCategory *self = GS_SHELL_CATEGORY (page); GtkAdjustment *adj; self->plugin_loader = g_object_ref (plugin_loader); @@ -359,12 +340,29 @@ gs_shell_category_setup (GsShellCategory *self, g_signal_connect (self->button_category_shell_extensions, "clicked", G_CALLBACK (button_shell_extensions_cb), self); + return TRUE; +} + +static void +gs_shell_category_class_init (GsShellCategoryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GsPageClass *page_class = GS_PAGE_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = gs_shell_category_dispose; + page_class->switch_to = gs_shell_category_switch_to; + page_class->reload = gs_shell_category_reload; + page_class->setup = gs_shell_category_setup; - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-category.ui"); + + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, category_detail_box); + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, infobar_category_shell_extensions); + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, button_category_shell_extensions); + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, listbox_filter); + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, scrolledwindow_category); + gtk_widget_class_bind_template_child (widget_class, GsShellCategory, scrolledwindow_filter); } GsShellCategory * diff --git a/src/gs-shell-category.h b/src/gs-shell-category.h index 71d38a2..cda7606 100644 --- a/src/gs-shell-category.h +++ b/src/gs-shell-category.h @@ -40,11 +40,6 @@ GsShellCategory *gs_shell_category_new (void); void gs_shell_category_set_category (GsShellCategory *self, GsCategory *category); GsCategory *gs_shell_category_get_category (GsShellCategory *self); -void gs_shell_category_setup (GsShellCategory *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c index 5a26a87..2f2606a 100644 --- a/src/gs-shell-details.c +++ b/src/gs-shell-details.c @@ -2040,16 +2040,18 @@ gs_shell_details_network_available_notify_cb (GsPluginLoader *plugin_loader, gs_shell_details_refresh_reviews (self); } -void -gs_shell_details_setup (GsShellDetails *self, +static gboolean +gs_shell_details_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellDetails *self = GS_SHELL_DETAILS (page); GtkAdjustment *adj; - g_return_if_fail (GS_IS_SHELL_DETAILS (self)); + g_return_val_if_fail (GS_IS_SHELL_DETAILS (self), TRUE); self->shell = shell; @@ -2116,12 +2118,7 @@ gs_shell_details_setup (GsShellDetails *self, adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow_details)); gtk_container_set_focus_vadjustment (GTK_CONTAINER (self->box_details), adj); - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -2154,6 +2151,7 @@ gs_shell_details_class_init (GsShellDetailsClass *klass) page_class->app_removed = gs_shell_details_app_removed; page_class->switch_to = gs_shell_details_switch_to; page_class->reload = gs_shell_details_reload; + page_class->setup = gs_shell_details_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-details.ui"); diff --git a/src/gs-shell-details.h b/src/gs-shell-details.h index 5ad1086..8cfa5fb 100644 --- a/src/gs-shell-details.h +++ b/src/gs-shell-details.h @@ -44,11 +44,6 @@ void gs_shell_details_set_local_file(GsShellDetails *self, void gs_shell_details_set_url (GsShellDetails *self, const gchar *url); GsApp *gs_shell_details_get_app (GsShellDetails *self); -void gs_shell_details_setup (GsShellDetails *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-extras.c b/src/gs-shell-extras.c index 3940fe9..95aa0cf 100644 --- a/src/gs-shell-extras.c +++ b/src/gs-shell-extras.c @@ -1120,14 +1120,17 @@ list_header_func (GtkListBoxRow *row, gtk_list_box_row_set_header (row, header); } -void -gs_shell_extras_setup (GsShellExtras *self, +static gboolean +gs_shell_extras_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { - g_return_if_fail (GS_IS_SHELL_EXTRAS (self)); + GsShellExtras *self = GS_SHELL_EXTRAS (page); + + g_return_val_if_fail (GS_IS_SHELL_EXTRAS (self), TRUE); self->shell = shell; @@ -1142,12 +1145,7 @@ gs_shell_extras_setup (GsShellExtras *self, gtk_list_box_set_sort_func (GTK_LIST_BOX (self->list_box_results), list_sort_func, self, NULL); - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -1203,6 +1201,7 @@ gs_shell_extras_class_init (GsShellExtrasClass *klass) object_class->dispose = gs_shell_extras_dispose; page_class->switch_to = gs_shell_extras_switch_to; page_class->reload = gs_shell_extras_reload; + page_class->setup = gs_shell_extras_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-extras.ui"); diff --git a/src/gs-shell-extras.h b/src/gs-shell-extras.h index 6363693..1002f9f 100644 --- a/src/gs-shell-extras.h +++ b/src/gs-shell-extras.h @@ -53,11 +53,6 @@ GsShellExtras *gs_shell_extras_new (void); void gs_shell_extras_search (GsShellExtras *self, const gchar *mode, gchar **resources); -void gs_shell_extras_setup (GsShellExtras *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c index 6704e24..6bed6e1 100644 --- a/src/gs-shell-installed.c +++ b/src/gs-shell-installed.c @@ -67,7 +67,7 @@ static void gs_shell_installed_pending_apps_changed_cb (GsPluginLoader *plugin_l GsShellInstalled *self); static void set_selection_mode (GsShellInstalled *self, gboolean selection_mode); -void +static void gs_shell_installed_invalidate (GsShellInstalled *self) { self->cache_valid = FALSE; @@ -773,17 +773,19 @@ gs_shell_settings_changed_cb (GsShellInstalled *self, } } -void -gs_shell_installed_setup (GsShellInstalled *self, +static gboolean +gs_shell_installed_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellInstalled *self = GS_SHELL_INSTALLED (page); AtkObject *accessible; GtkWidget *widget; - g_return_if_fail (GS_IS_SHELL_INSTALLED (self)); + g_return_val_if_fail (GS_IS_SHELL_INSTALLED (self), TRUE); self->shell = shell; self->plugin_loader = g_object_ref (plugin_loader); @@ -827,12 +829,7 @@ gs_shell_installed_setup (GsShellInstalled *self, widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "select_none_menuitem")); g_signal_connect (widget, "activate", G_CALLBACK (select_none_cb), self); - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -863,6 +860,7 @@ gs_shell_installed_class_init (GsShellInstalledClass *klass) page_class->app_removed = gs_shell_installed_app_removed; page_class->switch_to = gs_shell_installed_switch_to; page_class->reload = gs_shell_installed_reload; + page_class->setup = gs_shell_installed_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-installed.ui"); diff --git a/src/gs-shell-installed.h b/src/gs-shell-installed.h index ba32125..1b5e9fa 100644 --- a/src/gs-shell-installed.h +++ b/src/gs-shell-installed.h @@ -35,12 +35,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (GsShellInstalled, gs_shell_installed, GS, SHELL_INSTALLED, GsPage) GsShellInstalled *gs_shell_installed_new (void); -void gs_shell_installed_invalidate (GsShellInstalled *self); -void gs_shell_installed_setup (GsShellInstalled *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-loading.c b/src/gs-shell-loading.c index bd7e6e1..413a453 100644 --- a/src/gs-shell-loading.c +++ b/src/gs-shell-loading.c @@ -128,23 +128,23 @@ gs_shell_loading_switch_to (GsPage *page, gboolean scroll_up) gs_shell_loading_load (self); } -void -gs_shell_loading_setup (GsShellLoading *self, +static gboolean +gs_shell_loading_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellLoading *self = GS_SHELL_LOADING (page); GsShellLoadingPrivate *priv = gs_shell_loading_get_instance_private (self); - g_return_if_fail (GS_IS_SHELL_LOADING (self)); + g_return_val_if_fail (GS_IS_SHELL_LOADING (self), TRUE); priv->shell = shell; priv->plugin_loader = g_object_ref (plugin_loader); priv->cancellable = g_object_ref (cancellable); - - /* chain up */ - gs_page_setup (GS_PAGE (self), shell, plugin_loader, cancellable); + return TRUE; } static void @@ -168,6 +168,7 @@ gs_shell_loading_class_init (GsShellLoadingClass *klass) object_class->dispose = gs_shell_loading_dispose; page_class->switch_to = gs_shell_loading_switch_to; + page_class->setup = gs_shell_loading_setup; signals [SIGNAL_REFRESHED] = g_signal_new ("refreshed", diff --git a/src/gs-shell-loading.h b/src/gs-shell-loading.h index 5808560..272e376 100644 --- a/src/gs-shell-loading.h +++ b/src/gs-shell-loading.h @@ -42,11 +42,6 @@ struct _GsShellLoadingClass }; GsShellLoading *gs_shell_loading_new (void); -void gs_shell_loading_setup (GsShellLoading *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-moderate.c b/src/gs-shell-moderate.c index def33bb..b6d8101 100644 --- a/src/gs-shell-moderate.c +++ b/src/gs-shell-moderate.c @@ -37,7 +37,6 @@ struct _GsShellModerate GsPage parent_instance; GsPluginLoader *plugin_loader; - GtkBuilder *builder; GCancellable *cancellable; GtkSizeGroup *sizegroup_image; GtkSizeGroup *sizegroup_name; @@ -237,26 +236,25 @@ gs_shell_moderate_list_header_func (GtkListBoxRow *row, } } -void -gs_shell_moderate_setup (GsShellModerate *self, +static gboolean +gs_shell_moderate_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { - g_return_if_fail (GS_IS_SHELL_MODERATE (self)); + GsShellModerate *self = GS_SHELL_MODERATE (page); + g_return_val_if_fail (GS_IS_SHELL_MODERATE (self), TRUE); self->shell = shell; self->plugin_loader = g_object_ref (plugin_loader); - self->builder = g_object_ref (builder); self->cancellable = g_object_ref (cancellable); gtk_list_box_set_header_func (GTK_LIST_BOX (self->list_box_install), gs_shell_moderate_list_header_func, self, NULL); - - /* chain up */ - gs_page_setup (GS_PAGE (self), shell, plugin_loader, cancellable); + return TRUE; } static void @@ -268,7 +266,6 @@ gs_shell_moderate_dispose (GObject *object) g_clear_object (&self->sizegroup_name); g_clear_object (&self->sizegroup_button); - g_clear_object (&self->builder); g_clear_object (&self->plugin_loader); g_clear_object (&self->cancellable); @@ -285,6 +282,7 @@ gs_shell_moderate_class_init (GsShellModerateClass *klass) object_class->dispose = gs_shell_moderate_dispose; page_class->switch_to = gs_shell_moderate_switch_to; page_class->reload = gs_shell_moderate_reload; + page_class->setup = gs_shell_moderate_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-moderate.ui"); diff --git a/src/gs-shell-moderate.h b/src/gs-shell-moderate.h index 27fe6ea..7149009 100644 --- a/src/gs-shell-moderate.h +++ b/src/gs-shell-moderate.h @@ -35,11 +35,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (GsShellModerate, gs_shell_moderate, GS, SHELL_MODERATE, GsPage) GsShellModerate *gs_shell_moderate_new (void); -void gs_shell_moderate_setup (GsShellModerate *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c index 28f7318..3a0f443 100644 --- a/src/gs-shell-overview.c +++ b/src/gs-shell-overview.c @@ -97,7 +97,7 @@ load_data_free (LoadData *data) g_slice_free (LoadData, data); } -void +static void gs_shell_overview_invalidate (GsShellOverview *self) { GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); @@ -762,19 +762,21 @@ gs_shell_overview_refresh_proprietary (GsShellOverview *self) } } -void -gs_shell_overview_setup (GsShellOverview *self, +static gboolean +gs_shell_overview_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellOverview *self = GS_SHELL_OVERVIEW (page); GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GtkAdjustment *adj; GtkWidget *tile; gint i; - g_return_if_fail (GS_IS_SHELL_OVERVIEW (self)); + g_return_val_if_fail (GS_IS_SHELL_OVERVIEW (self), TRUE); priv->plugin_loader = g_object_ref (plugin_loader); priv->builder = g_object_ref (builder); @@ -809,12 +811,7 @@ gs_shell_overview_setup (GsShellOverview *self, G_CALLBACK (gs_shell_overview_categories_expander_down_cb), self); g_signal_connect (priv->categories_expander_button_up, "clicked", G_CALLBACK (gs_shell_overview_categories_expander_up_cb), self); - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -883,6 +880,7 @@ gs_shell_overview_class_init (GsShellOverviewClass *klass) object_class->dispose = gs_shell_overview_dispose; page_class->switch_to = gs_shell_overview_switch_to; page_class->reload = gs_shell_overview_reload; + page_class->setup = gs_shell_overview_setup; klass->refreshed = gs_shell_overview_refreshed; signals [SIGNAL_REFRESHED] = diff --git a/src/gs-shell-overview.h b/src/gs-shell-overview.h index 03bc5ed..f873411 100644 --- a/src/gs-shell-overview.h +++ b/src/gs-shell-overview.h @@ -44,12 +44,6 @@ struct _GsShellOverviewClass }; GsShellOverview *gs_shell_overview_new (void); -void gs_shell_overview_invalidate (GsShellOverview *self); -void gs_shell_overview_setup (GsShellOverview *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); void gs_shell_overview_set_category (GsShellOverview *self, const gchar *category); diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c index b9c9a2d..96e981b 100644 --- a/src/gs-shell-search.c +++ b/src/gs-shell-search.c @@ -389,14 +389,17 @@ gs_shell_search_app_removed (GsPage *page, GsApp *app) gs_shell_search_reload (page); } -void -gs_shell_search_setup (GsShellSearch *self, +static gboolean +gs_shell_search_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { - g_return_if_fail (GS_IS_SHELL_SEARCH (self)); + GsShellSearch *self = GS_SHELL_SEARCH (page); + + g_return_val_if_fail (GS_IS_SHELL_SEARCH (self), TRUE); self->plugin_loader = g_object_ref (plugin_loader); self->builder = g_object_ref (builder); @@ -417,12 +420,7 @@ gs_shell_search_setup (GsShellSearch *self, gtk_list_box_set_sort_func (GTK_LIST_BOX (self->list_box_search), gs_shell_search_sort_func, self, NULL); - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -466,6 +464,7 @@ gs_shell_search_class_init (GsShellSearchClass *klass) page_class->app_removed = gs_shell_search_app_removed; page_class->switch_to = gs_shell_search_switch_to; page_class->reload = gs_shell_search_reload; + page_class->setup = gs_shell_search_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-search.ui"); diff --git a/src/gs-shell-search.h b/src/gs-shell-search.h index 1a2449b..a7c9bd3 100644 --- a/src/gs-shell-search.h +++ b/src/gs-shell-search.h @@ -41,11 +41,6 @@ void gs_shell_search_set_appid_to_show (GsShellSearch *self, const gchar *gs_shell_search_get_text (GsShellSearch *self); void gs_shell_search_set_text (GsShellSearch *self, const gchar *value); -void gs_shell_search_setup (GsShellSearch *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c index 49f13b4..a245dc7 100644 --- a/src/gs-shell-updates.c +++ b/src/gs-shell-updates.c @@ -1281,16 +1281,18 @@ gs_shell_updates_upgrade_cancel_cb (GsUpgradeBanner *upgrade_banner, g_cancellable_cancel (self->cancellable_upgrade_download); } -void -gs_shell_updates_setup (GsShellUpdates *self, +static gboolean +gs_shell_updates_setup (GsPage *page, GsShell *shell, GsPluginLoader *plugin_loader, GtkBuilder *builder, - GCancellable *cancellable) + GCancellable *cancellable, + GError **error) { + GsShellUpdates *self = GS_SHELL_UPDATES (page); AtkObject *accessible; - g_return_if_fail (GS_IS_SHELL_UPDATES (self)); + g_return_val_if_fail (GS_IS_SHELL_UPDATES (self), TRUE); self->shell = shell; @@ -1367,12 +1369,7 @@ gs_shell_updates_setup (GsShellUpdates *self, /* set initial state */ if (!gs_plugin_loader_get_allow_updates (self->plugin_loader)) self->state = GS_SHELL_UPDATES_STATE_MANAGED; - - /* chain up */ - gs_page_setup (GS_PAGE (self), - shell, - plugin_loader, - cancellable); + return TRUE; } static void @@ -1404,6 +1401,7 @@ gs_shell_updates_class_init (GsShellUpdatesClass *klass) object_class->dispose = gs_shell_updates_dispose; page_class->switch_to = gs_shell_updates_switch_to; page_class->reload = gs_shell_updates_reload; + page_class->setup = gs_shell_updates_setup; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-shell-updates.ui"); diff --git a/src/gs-shell-updates.h b/src/gs-shell-updates.h index 91c8882..3c7bb1f 100644 --- a/src/gs-shell-updates.h +++ b/src/gs-shell-updates.h @@ -36,11 +36,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (GsShellUpdates, gs_shell_updates, GS, SHELL_UPDATES, GsPage) GsShellUpdates *gs_shell_updates_new (void); -void gs_shell_updates_setup (GsShellUpdates *self, - GsShell *shell, - GsPluginLoader *plugin_loader, - GtkBuilder *builder, - GCancellable *cancellable); G_END_DECLS diff --git a/src/gs-shell.c b/src/gs-shell.c index 5a057c6..6303f33 100644 --- a/src/gs-shell.c +++ b/src/gs-shell.c @@ -67,15 +67,7 @@ typedef struct GCancellable *cancellable; GsPluginLoader *plugin_loader; GsShellMode mode; - GsShellOverview *shell_overview; - GsShellInstalled *shell_installed; - GsShellModerate *shell_moderate; - GsShellLoading *shell_loading; - GsShellSearch *shell_search; - GsShellUpdates *shell_updates; - GsShellDetails *shell_details; - GsShellCategory *shell_category; - GsShellExtras *shell_extras; + GHashTable *pages; GtkWidget *header_start_widget; GtkWidget *header_end_widget; GtkBuilder *builder; @@ -255,7 +247,7 @@ gs_shell_change_mode (GsShell *shell, { GsShellPrivate *priv = gs_shell_get_instance_private (shell); GsApp *app; - GsPage *new_page; + GsPage *page; GtkWidget *widget; GtkStyleContext *context; @@ -316,46 +308,46 @@ gs_shell_change_mode (GsShell *shell, switch (mode) { case GS_SHELL_MODE_OVERVIEW: gs_shell_clean_back_entry_stack (shell); - new_page = GS_PAGE (priv->shell_overview); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "overview")); break; case GS_SHELL_MODE_INSTALLED: gs_shell_clean_back_entry_stack (shell); - new_page = GS_PAGE (priv->shell_installed); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "installed")); break; case GS_SHELL_MODE_MODERATE: - new_page = GS_PAGE (priv->shell_moderate); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "moderate")); break; case GS_SHELL_MODE_LOADING: - new_page = GS_PAGE (priv->shell_loading); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "loading")); break; case GS_SHELL_MODE_SEARCH: - gs_shell_search_set_text (priv->shell_search, data); - new_page = GS_PAGE (priv->shell_search); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "search")); + gs_shell_search_set_text (GS_SHELL_SEARCH (page), data); break; case GS_SHELL_MODE_UPDATES: gs_shell_clean_back_entry_stack (shell); - new_page = GS_PAGE (priv->shell_updates); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "updates")); break; case GS_SHELL_MODE_DETAILS: app = GS_APP (data); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "details")); if (gs_app_get_local_file (app) != NULL) { - gs_shell_details_set_local_file (priv->shell_details, + gs_shell_details_set_local_file (GS_SHELL_DETAILS (page), gs_app_get_local_file (app)); } else if (gs_app_get_metadata_item (app, "GnomeSoftware::from-url") != NULL) { - gs_shell_details_set_url (priv->shell_details, + gs_shell_details_set_url (GS_SHELL_DETAILS (page), gs_app_get_metadata_item (app, "GnomeSoftware::from-url")); } else { - gs_shell_details_set_app (priv->shell_details, data); + gs_shell_details_set_app (GS_SHELL_DETAILS (page), data); } - new_page = GS_PAGE (priv->shell_details); break; case GS_SHELL_MODE_CATEGORY: - gs_shell_category_set_category (priv->shell_category, + page = GS_PAGE (g_hash_table_lookup (priv->pages, "category")); + gs_shell_category_set_category (GS_SHELL_CATEGORY (page), GS_CATEGORY (data)); - new_page = GS_PAGE (priv->shell_category); break; case GS_SHELL_MODE_EXTRAS: - new_page = GS_PAGE (priv->shell_extras); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "extras")); break; default: g_assert_not_reached (); @@ -368,14 +360,14 @@ gs_shell_change_mode (GsShell *shell, !g_queue_is_empty (priv->back_entry_stack)); priv->in_mode_change = TRUE; - gs_page_switch_to (new_page, scroll_up); + gs_page_switch_to (page, scroll_up); priv->in_mode_change = FALSE; /* update header bar widgets */ - widget = gs_page_get_header_start_widget (new_page); + widget = gs_page_get_header_start_widget (page); gs_shell_set_header_start_widget (shell, widget); - widget = gs_page_get_header_end_widget (new_page); + widget = gs_page_get_header_end_widget (page); gs_shell_set_header_end_widget (shell, widget); /* destroy any existing modals */ @@ -409,6 +401,7 @@ save_back_entry (GsShell *shell) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); BackEntry *entry; + GsPage *page; entry = g_new0 (BackEntry, 1); entry->mode = priv->mode; @@ -420,21 +413,24 @@ save_back_entry (GsShell *shell) switch (priv->mode) { case GS_SHELL_MODE_CATEGORY: - entry->category = gs_shell_category_get_category (priv->shell_category); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "category")); + entry->category = gs_shell_category_get_category (GS_SHELL_CATEGORY (page)); g_object_ref (entry->category); g_debug ("pushing back entry for %s with %s", page_name[entry->mode], gs_category_get_id (entry->category)); break; case GS_SHELL_MODE_DETAILS: - entry->app = gs_shell_details_get_app (priv->shell_details); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "details")); + entry->app = gs_shell_details_get_app (GS_SHELL_DETAILS (page)); g_object_ref (entry->app); g_debug ("pushing back entry for %s with %s", page_name[entry->mode], gs_app_get_id (entry->app)); break; case GS_SHELL_MODE_SEARCH: - entry->search = g_strdup (gs_shell_search_get_text (priv->shell_search)); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "search")); + entry->search = g_strdup (gs_shell_search_get_text (GS_SHELL_SEARCH (page))); g_debug ("pushing back entry for %s with %s", page_name[entry->mode], entry->search); break; @@ -551,13 +547,16 @@ gs_shell_back_button_cb (GtkWidget *widget, GsShell *shell) static void initial_overview_load_done (GsShellOverview *shell_overview, gpointer data) { + GsPage *page; GsShell *shell = data; GsShellPrivate *priv = gs_shell_get_instance_private (shell); g_signal_handlers_disconnect_by_func (shell_overview, initial_overview_load_done, data); - gs_page_reload (GS_PAGE (priv->shell_updates)); - gs_page_reload (GS_PAGE (priv->shell_installed)); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_updates")); + gs_page_reload (page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_installed")); + gs_page_reload (page); g_signal_emit (shell, signals[SIGNAL_LOADED], 0); } @@ -604,8 +603,9 @@ search_changed_handler (GObject *entry, GsShell *shell) gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, (gpointer) text, TRUE); } else { - gs_shell_search_set_text (priv->shell_search, text); - gs_page_switch_to (GS_PAGE (priv->shell_search), TRUE); + GsPage *page = GS_PAGE (g_hash_table_lookup (priv->pages, "search")); + gs_shell_search_set_text (GS_SHELL_SEARCH (page), text); + gs_page_switch_to (page, TRUE); } } } @@ -711,13 +711,11 @@ static void gs_shell_reload_cb (GsPluginLoader *plugin_loader, GsShell *shell) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); - gs_page_reload (GS_PAGE (priv->shell_category)); - gs_page_reload (GS_PAGE (priv->shell_extras)); - gs_page_reload (GS_PAGE (priv->shell_details)); - gs_page_reload (GS_PAGE (priv->shell_installed)); - gs_page_reload (GS_PAGE (priv->shell_overview)); - gs_page_reload (GS_PAGE (priv->shell_search)); - gs_page_reload (GS_PAGE (priv->shell_updates)); + g_autoptr(GList) keys = g_hash_table_get_keys (priv->pages); + for (GList *l = keys; l != NULL; l = l->next) { + GsPage *page = GS_PAGE (g_hash_table_lookup (priv->pages, l->data)); + gs_page_reload (page); + } } static void @@ -1591,11 +1589,30 @@ gs_shell_plugin_event_dismissed_cb (GtkButton *button, GsShell *shell) gs_shell_rescan_events (shell); } +static void +gs_shell_setup_pages (GsShell *shell) +{ + GsShellPrivate *priv = gs_shell_get_instance_private (shell); + g_autoptr(GList) keys = g_hash_table_get_keys (priv->pages); + for (GList *l = keys; l != NULL; l = l->next) { + g_autoptr(GError) error = NULL; + GsPage *page = GS_PAGE (g_hash_table_lookup (priv->pages, l->data)); + if (!gs_page_setup (page, shell, + priv->plugin_loader, + priv->builder, + priv->cancellable, + &error)) { + g_warning ("Failed to setup panel: %s", error->message); + } + } +} + void gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *cancellable) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); GtkWidget *widget; + GsPage *page; g_return_if_fail (GS_IS_SHELL (shell)); @@ -1691,60 +1708,26 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can g_signal_connect (widget, "clicked", G_CALLBACK (gs_shell_plugin_events_restart_required_cb), shell); - priv->shell_overview = GS_SHELL_OVERVIEW (gtk_builder_get_object (priv->builder, "shell_overview")); - gs_shell_overview_setup (priv->shell_overview, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_updates = GS_SHELL_UPDATES (gtk_builder_get_object (priv->builder, "shell_updates")); - gs_shell_updates_setup (priv->shell_updates, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_installed = GS_SHELL_INSTALLED (gtk_builder_get_object (priv->builder, "shell_installed")); - gs_shell_installed_setup (priv->shell_installed, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_moderate = GS_SHELL_MODERATE (gtk_builder_get_object (priv->builder, "shell_moderate")); - gs_shell_moderate_setup (priv->shell_moderate, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_loading = GS_SHELL_LOADING (gtk_builder_get_object (priv->builder, "shell_loading")); - gs_shell_loading_setup (priv->shell_loading, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_search = GS_SHELL_SEARCH (gtk_builder_get_object (priv->builder, "shell_search")); - gs_shell_search_setup (priv->shell_search, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_details = GS_SHELL_DETAILS (gtk_builder_get_object (priv->builder, "shell_details")); - gs_shell_details_setup (priv->shell_details, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_category = GS_SHELL_CATEGORY (gtk_builder_get_object (priv->builder, "shell_category")); - gs_shell_category_setup (priv->shell_category, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); - priv->shell_extras = GS_SHELL_EXTRAS (gtk_builder_get_object (priv->builder, "shell_extras")); - gs_shell_extras_setup (priv->shell_extras, - shell, - priv->plugin_loader, - priv->builder, - priv->cancellable); + /* add pages to hash */ + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_overview")); + g_hash_table_insert (priv->pages, g_strdup ("overview"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_updates")); + g_hash_table_insert (priv->pages, g_strdup ("updates"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_installed")); + g_hash_table_insert (priv->pages, g_strdup ("installed"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_moderate")); + g_hash_table_insert (priv->pages, g_strdup ("moderate"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_loading")); + g_hash_table_insert (priv->pages, g_strdup ("loading"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_search")); + g_hash_table_insert (priv->pages, g_strdup ("search"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_details")); + g_hash_table_insert (priv->pages, g_strdup ("details"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_category")); + g_hash_table_insert (priv->pages, g_strdup ("category"), page); + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_extras")); + g_hash_table_insert (priv->pages, g_strdup ("extras"), page); + gs_shell_setup_pages (shell); /* set up search */ g_signal_connect (priv->main_window, "key-press-event", @@ -1755,7 +1738,8 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can G_CALLBACK (search_changed_handler), shell); /* load content */ - g_signal_connect (priv->shell_loading, "refreshed", + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_loading")); + g_signal_connect (page, "refreshed", G_CALLBACK (initial_overview_load_done), shell); /* coldplug */ @@ -1771,7 +1755,8 @@ gs_shell_set_mode (GsShell *shell, GsShellMode mode) /* if we're loading a different mode at startup then don't wait for * the overview page to load before showing content */ if (mode != GS_SHELL_MODE_OVERVIEW) { - matched = g_signal_handlers_disconnect_by_func (priv->shell_overview, + GsPage *page = g_hash_table_lookup (priv->pages, "overview"); + matched = g_signal_handlers_disconnect_by_func (page, initial_overview_load_done, shell); if (matched > 0) @@ -1798,12 +1783,13 @@ gs_shell_get_mode_string (GsShell *shell) void gs_shell_install (GsShell *shell, GsApp *app, GsShellInteraction interaction) { + GsPage *page; GsShellPrivate *priv = gs_shell_get_instance_private (shell); save_back_entry (shell); gs_shell_change_mode (shell, GS_SHELL_MODE_DETAILS, (gpointer) app, TRUE); - gs_page_install_app (GS_PAGE (priv->shell_details), app, interaction, - priv->cancellable); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "details")); + gs_page_install_app (page, app, interaction, priv->cancellable); } void @@ -1855,9 +1841,12 @@ gs_shell_show_category (GsShell *shell, GsCategory *category) void gs_shell_show_extras_search (GsShell *shell, const gchar *mode, gchar **resources) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); + GsPage *page; + + page = GS_PAGE (gtk_builder_get_object (priv->builder, "shell_extras")); save_back_entry (shell); - gs_shell_extras_search (priv->shell_extras, mode, resources); + gs_shell_extras_search (GS_SHELL_EXTRAS (page), mode, resources); gs_shell_change_mode (shell, GS_SHELL_MODE_EXTRAS, NULL, TRUE); gs_shell_activate (shell); } @@ -1885,9 +1874,11 @@ void gs_shell_show_search_result (GsShell *shell, const gchar *id, const gchar *search) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); + GsPage *page; save_back_entry (shell); - gs_shell_search_set_appid_to_show (priv->shell_search, id); + page = GS_PAGE (g_hash_table_lookup (priv->pages, "search")); + gs_shell_search_set_appid_to_show (GS_SHELL_SEARCH (page), id); gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, (gpointer) search, TRUE); } @@ -1907,6 +1898,7 @@ gs_shell_dispose (GObject *object) g_clear_object (&priv->plugin_loader); g_clear_object (&priv->header_start_widget); g_clear_object (&priv->header_end_widget); + g_clear_pointer (&priv->pages, (GDestroyNotify) g_hash_table_unref); g_clear_pointer (&priv->events_info_uri, (GDestroyNotify) g_free); g_clear_pointer (&priv->modal_dialogs, (GDestroyNotify) g_ptr_array_unref); @@ -1932,6 +1924,7 @@ gs_shell_init (GsShell *shell) { GsShellPrivate *priv = gs_shell_get_instance_private (shell); + priv->pages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); priv->back_entry_stack = g_queue_new (); priv->ignore_primary_buttons = FALSE; priv->modal_dialogs = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_widget_destroy); -- 2.9.3