[gnome-software] Refactor handling of header buttons



commit 763751a9bbe71be96cebb45b194a3f7c469bb843
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Aug 26 21:40:55 2013 -0400

    Refactor handling of header buttons
    
    The central GsShell code now only hides these buttons,
    and each refresh function is responsible for showing the
    ones that are needed for its mode.

 src/gs-shell-category.c  |    3 +
 src/gs-shell-details.c   |    5 ++
 src/gs-shell-installed.c |    3 +
 src/gs-shell-overview.c  |    4 ++
 src/gs-shell-updates.c   |    3 +
 src/gs-shell.c           |  117 ++++++++--------------------------------------
 6 files changed, 38 insertions(+), 97 deletions(-)
---
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index b8effdc..15146cb 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -45,7 +45,10 @@ gs_shell_category_refresh (GsShellCategory *shell)
        GsShellCategoryPrivate *priv = shell->priv;
         GtkWidget *widget;
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
+        gtk_widget_show (widget);
         widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
+        gtk_widget_show (widget);
         gtk_label_set_label (GTK_LABEL (widget), priv->category);
 }
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index daca11c..0a2f441 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -61,6 +61,11 @@ gs_shell_details_refresh (GsShellDetails *shell_details)
        GsShellDetailsPrivate *priv = shell_details->priv;
        GtkWidget *widget;
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
+        gtk_widget_show (widget);
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
+        gtk_widget_show (widget);
+
        kind = gs_app_get_kind (priv->app);
        state = gs_app_get_state (priv->app);
 
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 37cb24e..86deac3 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -289,6 +289,9 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed)
        GsShellInstalledPrivate *priv = shell_installed->priv;
         GtkWidget *widget;
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
+        gtk_widget_show (widget);
+
        /* no need to refresh */
        if (priv->cache_valid)
                return;
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 0fb0bfd..d05a106 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -257,8 +257,12 @@ void
 gs_shell_overview_refresh (GsShellOverview *shell_overview)
 {
        GsShellOverviewPrivate *priv = shell_overview->priv;
+       GtkWidget *widget;
        GtkWidget *grid;
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
+        gtk_widget_show (widget);
+
        /* no need to refresh */
        if (priv->cache_valid)
                return;
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index add71b3..5f050ae 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -151,6 +151,9 @@ gs_shell_updates_refresh (GsShellUpdates *shell_updates)
        GsShellUpdatesPrivate *priv = shell_updates->priv;
         GtkWidget *widget;
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
+        gtk_widget_show (widget);
+
        /* no need to refresh */
        if (priv->cache_valid) {
                 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_update_all"));
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 5cde52f..1663a30 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -66,68 +66,39 @@ gs_shell_activate (GsShell *shell)
 }
 
 /**
- * gs_shell_set_overview_mode_ui:
+ * gs_shell_set_overview_mode:
  **/
 static void
-gs_shell_set_overview_mode_ui (GsShell *shell, GsShellMode mode)
+gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, const gchar *category)
 {
-       GtkWidget *widget;
        GsShellPrivate *priv = shell->priv;
+        GtkWidget *widget;
 
-       priv->ignore_primary_buttons = TRUE;
+       if (priv->ignore_primary_buttons)
+               return;
 
         /* hide all mode specific header widgets here, they will be shown in the
          * refresh functions
          */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_update_all"));
-       gtk_widget_set_visible (widget, FALSE);
+       gtk_widget_hide (widget);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_install"));
-       gtk_widget_set_visible (widget, FALSE);
+       gtk_widget_hide (widget);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_remove"));
-       gtk_widget_set_visible (widget, FALSE);
+       gtk_widget_hide (widget);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "header_spinner"));
-       gtk_widget_set_visible (widget, FALSE);
+       gtk_widget_hide (widget);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_wait"));
-       gtk_widget_set_visible (widget, FALSE);
-
-       switch (mode) {
-       case GS_SHELL_MODE_OVERVIEW:
-       case GS_SHELL_MODE_INSTALLED:
-       case GS_SHELL_MODE_UPDATES:
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
-               gtk_widget_set_visible (widget, TRUE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
-               gtk_widget_set_visible (widget, FALSE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
-               gtk_widget_set_visible (widget, FALSE);
-               break;
-
-       case GS_SHELL_MODE_DETAILS:
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
-               gtk_widget_set_visible (widget, FALSE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
-               gtk_widget_set_visible (widget, TRUE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
-               gtk_widget_set_visible (widget, TRUE);
-#ifdef SEARCH
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
-               gtk_widget_set_visible (widget, FALSE);
-#endif
-               break;
-       case GS_SHELL_MODE_CATEGORY:
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
-               gtk_widget_set_visible (widget, FALSE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
-               gtk_widget_set_visible (widget, TRUE);
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
-               gtk_widget_set_visible (widget, TRUE);
-               break;
-
-       default:
-               g_assert_not_reached ();
-               break;
-       }
+       gtk_widget_hide (widget);
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
+       gtk_widget_hide (widget);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_back"));
+       gtk_widget_hide (widget);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
+       gtk_widget_hide (widget);
 
+        /* update main buttons according to mode */
+       priv->ignore_primary_buttons = TRUE;
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_all"));
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), mode == GS_SHELL_MODE_OVERVIEW);
 
@@ -138,57 +109,9 @@ gs_shell_set_overview_mode_ui (GsShell *shell, GsShellMode mode)
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), mode == GS_SHELL_MODE_UPDATES);
        priv->ignore_primary_buttons = FALSE;
 
-       switch (mode) {
-       case GS_SHELL_MODE_OVERVIEW:
-#ifdef SEARCH
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
-               gtk_entry_set_text (GTK_ENTRY (widget), "");
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
-               gtk_widget_show (widget);
-#endif
-               break;
-
-       case GS_SHELL_MODE_INSTALLED:
-#ifdef SEARCH
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
-               gtk_entry_set_text (GTK_ENTRY (widget), "");
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
-               gtk_widget_show (widget);
-#endif
-               break;
-
-       case GS_SHELL_MODE_UPDATES:
-#ifdef SEARCH
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
-               gtk_widget_hide (widget);
-#endif
-               break;
-
-       case GS_SHELL_MODE_DETAILS:
-       case GS_SHELL_MODE_CATEGORY:
-               break;
-       default:
-               g_assert_not_reached ();
-       }
-
-       /* set panel */
+       /* switch page */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "notebook_main"));
        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), mode);
-}
-
-/**
- * gs_shell_set_overview_mode:
- **/
-static void
-gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, const gchar *category)
-{
-       GsShellPrivate *priv = shell->priv;
-
-       if (priv->ignore_primary_buttons)
-               return;
-
-       /* set controls */
-       gs_shell_set_overview_mode_ui (shell, mode);
 
        /* do action for mode */
        priv->mode = mode;


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