[gnome-software/wip/hughsie/bz779463: 4/5] trivial: Add a switch_from() vfunc



commit e79b13c98124a284d2203d05f5dd18ff8853391c
Author: Richard Hughes <richard hughsie com>
Date:   Fri Mar 3 22:17:58 2017 +0000

    trivial: Add a switch_from() vfunc

 src/gs-page.c  |   27 ++++++++++++++++++++-------
 src/gs-page.h  |    2 ++
 src/gs-shell.c |    6 ++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-page.c b/src/gs-page.c
index eed74fd..a5cf904 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -610,14 +610,27 @@ 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);
+       GsPageClass *klass = GS_PAGE_GET_CLASS (page);
+       GsPagePrivate *priv = gs_page_get_instance_private (page);
+       priv->is_active = TRUE;
+       if (klass->switch_to != NULL)
+               klass->switch_to (page, scroll_up);
+}
 
-       klass->switch_to (page, scroll_up);
+/**
+ * gs_page_switch_from:
+ *
+ * Pure virtual method that subclasses have to override to show page specific
+ * widgets.
+ */
+void
+gs_page_switch_from (GsPage *page)
+{
+       GsPageClass *klass = GS_PAGE_GET_CLASS (page);
+       GsPagePrivate *priv = gs_page_get_instance_private (page);
+       priv->is_active = FALSE;
+       if (klass->switch_from != NULL)
+               klass->switch_from (page);
 }
 
 void
diff --git a/src/gs-page.h b/src/gs-page.h
index 1d5c64f..62d224f 100644
--- a/src/gs-page.h
+++ b/src/gs-page.h
@@ -44,6 +44,7 @@ struct _GsPageClass
                                                 GsApp           *app);
        void            (*switch_to)            (GsPage          *page,
                                                 gboolean         scroll_up);
+       void            (*switch_from)          (GsPage          *page);
        void            (*reload)               (GsPage          *page);
        gboolean        (*setup)                (GsPage          *page,
                                                 GsShell        *shell,
@@ -81,6 +82,7 @@ void           gs_page_shortcut_remove                (GsPage         *page,
                                                         GCancellable   *cancellable);
 void            gs_page_switch_to                      (GsPage         *page,
                                                         gboolean        scroll_up);
+void            gs_page_switch_from                    (GsPage         *page);
 void            gs_page_reload                         (GsPage         *page);
 gboolean        gs_page_setup                          (GsPage         *page,
                                                         GsShell        *shell,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 6303f33..5dff5c9 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -78,6 +78,7 @@ typedef struct
        gchar                   *events_info_uri;
        gboolean                 profile_mode;
        gboolean                 in_mode_change;
+       GsPage                  *page_last;
 } GsShellPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsShell, gs_shell, G_TYPE_OBJECT)
@@ -360,6 +361,10 @@ gs_shell_change_mode (GsShell *shell,
                                !g_queue_is_empty (priv->back_entry_stack));
 
        priv->in_mode_change = TRUE;
+
+       if (priv->page_last)
+               gs_page_switch_from (priv->page_last);
+       g_set_object (&priv->page_last, page);
        gs_page_switch_to (page, scroll_up);
        priv->in_mode_change = FALSE;
 
@@ -1898,6 +1903,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_object (&priv->page_last);
        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);


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