[gnome-software/gnome-3-20] Factor out gs_page_switch_to virtual method



commit d86615f32c8aadb539b25ceb8c3585a93293fa4e
Author: Kalev Lember <klember redhat com>
Date:   Tue Feb 23 11:46:39 2016 +0100

    Factor out gs_page_switch_to virtual method
    
    All of the GsPage-derived shell pages already had a non-virtual
    switch_to() function. This commit changes it to use a more common
    pattern where each page has to implement a switch_to virtual method from
    the base GsPage class.

 src/gs-page.c            |   20 ++++++++++++++++++++
 src/gs-page.h            |    4 ++++
 src/gs-shell-category.c  |    7 +++++--
 src/gs-shell-category.h  |    1 -
 src/gs-shell-details.c   |   10 ++++++----
 src/gs-shell-details.h   |    1 -
 src/gs-shell-extras.c    |    9 ++++++---
 src/gs-shell-extras.h    |    2 --
 src/gs-shell-installed.c |    6 ++++--
 src/gs-shell-installed.h |    2 --
 src/gs-shell-moderate.c  |    8 ++++++--
 src/gs-shell-moderate.h  |    2 --
 src/gs-shell-overview.c  |    7 +++++--
 src/gs-shell-overview.h  |    2 --
 src/gs-shell-search.c    |    6 ++++--
 src/gs-shell-search.h    |    2 --
 src/gs-shell-updates.c   |    9 ++++++---
 src/gs-shell-updates.h   |    2 --
 src/gs-shell.c           |   20 ++++++++++----------
 19 files changed, 76 insertions(+), 44 deletions(-)
---
diff --git a/src/gs-page.c b/src/gs-page.c
index b7e9646..fed8fcf 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -278,6 +278,26 @@ gs_page_launch_app (GsPage *page, GsApp *app)
                                           NULL);
 }
 
+/**
+ * gs_page_switch_to:
+ *
+ * Pure virtual method that subclasses have to override to show page specific
+ * widgets.
+ */
+void
+gs_page_switch_to (GsPage *page,
+                   gboolean scroll_up)
+{
+       GsPageClass *klass;
+
+       g_return_if_fail (GS_IS_PAGE (page));
+
+       klass = GS_PAGE_GET_CLASS (page);
+       g_assert (klass->switch_to != NULL);
+
+       klass->switch_to (page, scroll_up);
+}
+
 void
 gs_page_setup (GsPage *page,
                GsShell *shell,
diff --git a/src/gs-page.h b/src/gs-page.h
index 76550ab..b2a4145 100644
--- a/src/gs-page.h
+++ b/src/gs-page.h
@@ -42,6 +42,8 @@ struct _GsPageClass
                                                 GsApp           *app);
        void            (*app_removed)          (GsPage          *page,
                                                 GsApp           *app);
+       void            (*switch_to)            (GsPage          *page,
+                                                gboolean         scroll_up);
 };
 
 GsPage         *gs_page_new                            (void);
@@ -53,6 +55,8 @@ void           gs_page_update_app                     (GsPage         *page,
                                                         GsApp          *app);
 void            gs_page_launch_app                     (GsPage         *page,
                                                         GsApp          *app);
+void            gs_page_switch_to                      (GsPage         *page,
+                                                        gboolean        scroll_up);
 void            gs_page_setup                          (GsPage         *page,
                                                         GsShell        *shell,
                                                         GsPluginLoader *plugin_loader,
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index 71ecb3b..f172c9d 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -55,9 +55,10 @@ gs_shell_category_reload (GsShellCategory *self)
 {
 }
 
-void
-gs_shell_category_switch_to (GsShellCategory *self)
+static void
+gs_shell_category_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellCategory *self = GS_SHELL_CATEGORY (page);
        GtkWidget *widget;
 
        widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "application_details_header"));
@@ -262,9 +263,11 @@ 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;
 
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-shell-category.ui");
 
diff --git a/src/gs-shell-category.h b/src/gs-shell-category.h
index 4b103b1..6340348 100644
--- a/src/gs-shell-category.h
+++ b/src/gs-shell-category.h
@@ -40,7 +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_switch_to    (GsShellCategory        *self);
 void            gs_shell_category_reload       (GsShellCategory        *self);
 void            gs_shell_category_setup        (GsShellCategory        *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 3990b5e..9940560 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -155,9 +155,10 @@ gs_shell_details_set_state (GsShellDetails *self,
 /**
  * gs_shell_details_switch_to:
  **/
-void
-gs_shell_details_switch_to (GsShellDetails *self)
+static void
+gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellDetails *self = GS_SHELL_DETAILS (page);
        AsAppState state;
        GtkWidget *widget;
        GtkAdjustment *adj;
@@ -367,7 +368,7 @@ gs_shell_details_switch_to_idle (gpointer user_data)
        GsShellDetails *self = GS_SHELL_DETAILS (user_data);
 
        if (gs_shell_get_mode (self->shell) == GS_SHELL_MODE_DETAILS)
-               gs_shell_details_switch_to (self);
+               gs_page_switch_to (GS_PAGE (self), TRUE);
 
        g_object_unref (self);
        return G_SOURCE_REMOVE;
@@ -1186,7 +1187,7 @@ gs_shell_details_filename_to_app_cb (GObject *source,
        g_debug ("%s", tmp);
 
        /* change widgets */
-       gs_shell_details_switch_to (self);
+       gs_page_switch_to (GS_PAGE (self), TRUE);
        gs_shell_details_refresh_screenshots (self);
        gs_shell_details_refresh_addons (self);
        gs_shell_details_refresh_reviews (self);
@@ -1523,6 +1524,7 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
        object_class->dispose = gs_shell_details_dispose;
        page_class->app_installed = gs_shell_details_app_installed;
        page_class->app_removed = gs_shell_details_app_removed;
+       page_class->switch_to = gs_shell_details_switch_to;
 
        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 30532aa..3ffd72a 100644
--- a/src/gs-shell-details.h
+++ b/src/gs-shell-details.h
@@ -43,7 +43,6 @@ void           gs_shell_details_set_app       (GsShellDetails         *self,
 void            gs_shell_details_set_filename  (GsShellDetails         *self,
                                                 const gchar            *filename);
 GsApp          *gs_shell_details_get_app       (GsShellDetails         *self);
-void            gs_shell_details_switch_to     (GsShellDetails         *self);
 void            gs_shell_details_reload        (GsShellDetails         *self);
 void            gs_shell_details_setup         (GsShellDetails         *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-extras.c b/src/gs-shell-extras.c
index 44ca9b6..96ba78d 100644
--- a/src/gs-shell-extras.c
+++ b/src/gs-shell-extras.c
@@ -1011,10 +1011,11 @@ gs_shell_extras_search (GsShellExtras  *self,
        }
 }
 
-void
-gs_shell_extras_switch_to (GsShellExtras *self,
-                           gboolean scroll_up)
+static void
+gs_shell_extras_switch_to (GsPage *page,
+                           gboolean scroll_up)
 {
+       GsShellExtras *self = GS_SHELL_EXTRAS (page);
        GtkWidget *widget;
 
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_EXTRAS) {
@@ -1187,9 +1188,11 @@ static void
 gs_shell_extras_class_init (GsShellExtrasClass *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_extras_dispose;
+       page_class->switch_to = gs_shell_extras_switch_to;
 
        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 6ed674d..1d51bc6 100644
--- a/src/gs-shell-extras.h
+++ b/src/gs-shell-extras.h
@@ -53,8 +53,6 @@ GsShellExtras         *gs_shell_extras_new                    (void);
 void                    gs_shell_extras_search                 (GsShellExtras           *self,
                                                                 const gchar             *mode,
                                                                 gchar                  **resources);
-void                    gs_shell_extras_switch_to              (GsShellExtras           *self,
-                                                                gboolean                 scroll_up);
 void                    gs_shell_extras_reload                 (GsShellExtras           *self);
 void                    gs_shell_extras_setup                  (GsShellExtras           *self,
                                                                 GsShell                 *shell,
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 0512bfb..3e304a9 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -258,9 +258,10 @@ gs_shell_installed_reload (GsShellInstalled *self)
 /**
  * gs_shell_installed_switch_to:
  **/
-void
-gs_shell_installed_switch_to (GsShellInstalled *self, gboolean scroll_up)
+static void
+gs_shell_installed_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellInstalled *self = GS_SHELL_INSTALLED (page);
        GtkWidget *widget;
 
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_INSTALLED) {
@@ -759,6 +760,7 @@ gs_shell_installed_class_init (GsShellInstalledClass *klass)
 
        object_class->dispose = gs_shell_installed_dispose;
        page_class->app_removed = gs_shell_installed_app_removed;
+       page_class->switch_to = gs_shell_installed_switch_to;
 
        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 432b671..f071805 100644
--- a/src/gs-shell-installed.h
+++ b/src/gs-shell-installed.h
@@ -36,8 +36,6 @@ G_DECLARE_FINAL_TYPE (GsShellInstalled, gs_shell_installed, GS, SHELL_INSTALLED,
 
 GsShellInstalled *gs_shell_installed_new       (void);
 void            gs_shell_installed_invalidate  (GsShellInstalled       *self);
-void            gs_shell_installed_switch_to   (GsShellInstalled       *self,
-                                                gboolean               scroll_up);
 void            gs_shell_installed_reload      (GsShellInstalled       *self);
 void            gs_shell_installed_setup       (GsShellInstalled       *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-moderate.c b/src/gs-shell-moderate.c
index e32c464..5db01ac 100644
--- a/src/gs-shell-moderate.c
+++ b/src/gs-shell-moderate.c
@@ -211,9 +211,11 @@ gs_shell_moderate_reload (GsShellModerate *self)
 /**
  * gs_shell_moderate_switch_to:
  **/
-void
-gs_shell_moderate_switch_to (GsShellModerate *self, gboolean scroll_up)
+static void
+gs_shell_moderate_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellModerate *self = GS_SHELL_MODERATE (page);
+
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_MODERATE) {
                g_warning ("Called switch_to(moderate) when in mode %s",
                           gs_shell_get_mode_string (self->shell));
@@ -292,9 +294,11 @@ static void
 gs_shell_moderate_class_init (GsShellModerateClass *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_moderate_dispose;
+       page_class->switch_to = gs_shell_moderate_switch_to;
 
        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 4a74492..0fb4ae5 100644
--- a/src/gs-shell-moderate.h
+++ b/src/gs-shell-moderate.h
@@ -35,8 +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_switch_to    (GsShellModerate        *self,
-                                                gboolean               scroll_up);
 void            gs_shell_moderate_reload       (GsShellModerate        *self);
 void            gs_shell_moderate_setup        (GsShellModerate        *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 8c04e9c..ec35c82 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -454,9 +454,10 @@ gs_shell_overview_reload (GsShellOverview *self)
 /**
  * gs_shell_overview_switch_to:
  **/
-void
-gs_shell_overview_switch_to (GsShellOverview *self, gboolean scroll_up)
+static void
+gs_shell_overview_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellOverview *self = GS_SHELL_OVERVIEW (page);
        GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
        GtkWidget *widget;
        GtkAdjustment *adj;
@@ -567,9 +568,11 @@ static void
 gs_shell_overview_class_init (GsShellOverviewClass *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_overview_dispose;
+       page_class->switch_to = gs_shell_overview_switch_to;
        klass->refreshed = gs_shell_overview_refreshed;
 
        signals [SIGNAL_REFRESHED] =
diff --git a/src/gs-shell-overview.h b/src/gs-shell-overview.h
index d8135b2..08bba19 100644
--- a/src/gs-shell-overview.h
+++ b/src/gs-shell-overview.h
@@ -45,8 +45,6 @@ struct _GsShellOverviewClass
 
 GsShellOverview        *gs_shell_overview_new          (void);
 void            gs_shell_overview_invalidate   (GsShellOverview        *self);
-void            gs_shell_overview_switch_to    (GsShellOverview        *self,
-                                                gboolean               scroll_up);
 void            gs_shell_overview_reload       (GsShellOverview        *self);
 void            gs_shell_overview_setup        (GsShellOverview        *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 7772876..45017a1 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -207,9 +207,10 @@ gs_shell_search_set_text (GsShellSearch *self, const gchar *value)
 /**
  * gs_shell_search_switch_to:
  **/
-void
-gs_shell_search_switch_to (GsShellSearch *self, gboolean scroll_up)
+static void
+gs_shell_search_switch_to (GsPage *page, gboolean scroll_up)
 {
+       GsShellSearch *self = GS_SHELL_SEARCH (page);
        GtkWidget *widget;
 
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_SEARCH) {
@@ -444,6 +445,7 @@ gs_shell_search_class_init (GsShellSearchClass *klass)
        object_class->finalize = gs_shell_search_finalize;
        page_class->app_installed = gs_shell_search_app_installed;
        page_class->app_removed = gs_shell_search_app_removed;
+       page_class->switch_to = gs_shell_search_switch_to;
 
        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 bb64fb8..ecf69d9 100644
--- a/src/gs-shell-search.h
+++ b/src/gs-shell-search.h
@@ -40,8 +40,6 @@ void           gs_shell_search_set_appid_to_show (GsShellSearch       *self,
                                                 const gchar            *appid);
 void            gs_shell_search_set_text       (GsShellSearch          *self,
                                                 const gchar            *value);
-void            gs_shell_search_switch_to      (GsShellSearch          *self,
-                                                gboolean                scroll_up);
 void            gs_shell_search_reload         (GsShellSearch          *self);
 void            gs_shell_search_setup          (GsShellSearch          *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index c75716d..348f456 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -554,10 +554,11 @@ gs_shell_updates_reload (GsShellUpdates *self)
 /**
  * gs_shell_updates_switch_to:
  **/
-void
-gs_shell_updates_switch_to (GsShellUpdates *self,
+static void
+gs_shell_updates_switch_to (GsPage *page,
                            gboolean scroll_up)
 {
+       GsShellUpdates *self = GS_SHELL_UPDATES (page);
        GtkWidget *widget;
 
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_UPDATES) {
@@ -679,7 +680,7 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
 
        /* get the new list */
        gs_shell_updates_invalidate (self);
-       gs_shell_updates_switch_to (self, TRUE);
+       gs_page_switch_to (GS_PAGE (self), TRUE);
 }
 
 /**
@@ -1198,9 +1199,11 @@ static void
 gs_shell_updates_class_init (GsShellUpdatesClass *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_updates_dispose;
+       page_class->switch_to = gs_shell_updates_switch_to;
 
        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 733e38a..d5bdded 100644
--- a/src/gs-shell-updates.h
+++ b/src/gs-shell-updates.h
@@ -36,8 +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_switch_to     (GsShellUpdates         *self,
-                                                gboolean                scroll_up);
 void            gs_shell_updates_reload        (GsShellUpdates         *self);
 void            gs_shell_updates_setup         (GsShellUpdates         *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 6103eb6..da99ab9 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -187,27 +187,27 @@ gs_shell_change_mode (GsShell *shell,
        priv->mode = mode;
        switch (mode) {
        case GS_SHELL_MODE_OVERVIEW:
-               gs_shell_overview_switch_to (priv->shell_overview, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_overview), scroll_up);
                break;
        case GS_SHELL_MODE_INSTALLED:
-               gs_shell_installed_switch_to (priv->shell_installed, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_installed), scroll_up);
                break;
        case GS_SHELL_MODE_MODERATE:
-               gs_shell_moderate_switch_to (priv->shell_moderate, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_moderate), scroll_up);
                break;
        case GS_SHELL_MODE_SEARCH:
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
                text = gtk_entry_get_text (GTK_ENTRY (widget));
                gs_shell_search_set_text (priv->shell_search, text);
-               gs_shell_search_switch_to (priv->shell_search, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_search), scroll_up);
                break;
        case GS_SHELL_MODE_UPDATES:
-               gs_shell_updates_switch_to (priv->shell_updates, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_updates), scroll_up);
                break;
        case GS_SHELL_MODE_DETAILS:
                if (app != NULL) {
                        gs_shell_details_set_app (priv->shell_details, app);
-                       gs_shell_details_switch_to (priv->shell_details);
+                       gs_page_switch_to (GS_PAGE (priv->shell_details), scroll_up);
                }
                if (data != NULL)
                        gs_shell_details_set_filename (priv->shell_details, data);
@@ -215,10 +215,10 @@ gs_shell_change_mode (GsShell *shell,
        case GS_SHELL_MODE_CATEGORY:
                gs_shell_category_set_category (priv->shell_category,
                                                GS_CATEGORY (data));
-               gs_shell_category_switch_to (priv->shell_category);
+               gs_page_switch_to (GS_PAGE (priv->shell_category), scroll_up);
                break;
        case GS_SHELL_MODE_EXTRAS:
-               gs_shell_extras_switch_to (priv->shell_extras, scroll_up);
+               gs_page_switch_to (GS_PAGE (priv->shell_extras), scroll_up);
                break;
        default:
                g_assert_not_reached ();
@@ -321,7 +321,7 @@ gs_shell_search_activated_cb (GtkEntry *entry, GsShell *shell)
 
        if (gs_shell_get_mode (shell) == GS_SHELL_MODE_SEARCH) {
                gs_shell_search_set_text (priv->shell_search, text);
-               gs_shell_search_switch_to (priv->shell_search, TRUE);
+               gs_page_switch_to (GS_PAGE (priv->shell_search), TRUE);
        } else {
                gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
        }
@@ -449,7 +449,7 @@ search_changed_handler (GObject *entry, GsShell *shell)
                        gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
                } else {
                        gs_shell_search_set_text (priv->shell_search, text);
-                       gs_shell_search_switch_to (priv->shell_search, TRUE);
+                       gs_page_switch_to (GS_PAGE (priv->shell_search), TRUE);
                }
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]