[gnome-logs/wip/gl-journal: 17/20] Refactor category, view and toolbar state changes



commit 8b424fc199f1928fbb25fb9b98c0d6b9ca4d9082
Author: David King <davidk gnome org>
Date:   Fri Oct 4 13:47:50 2013 +0100

    Refactor category, view and toolbar state changes

 data/gl-eventtoolbar.ui |    2 +-
 src/gl-eventtoolbar.c   |   52 ++++++++++++++++++++++-------------------
 src/gl-eventview.c      |   59 ++++++++++++++++++++++++----------------------
 src/gl-window.c         |   51 ++++++++++++++++++++++++++++++++--------
 4 files changed, 101 insertions(+), 63 deletions(-)
---
diff --git a/data/gl-eventtoolbar.ui b/data/gl-eventtoolbar.ui
index 26926bc..fc06423 100644
--- a/data/gl-eventtoolbar.ui
+++ b/data/gl-eventtoolbar.ui
@@ -8,7 +8,7 @@
             <object class="GtkButton" id="back_button">
                 <property name="tooltip-text" translatable="yes">Go back to the event view</property>
                 <property name="valign">center</property>
-                <signal name="clicked" handler="on_gl_event_toolbar_back_button_clicked"/>
+                <signal name="clicked" handler="on_gl_event_toolbar_back_button_clicked" 
object="GlEventToolbar" swapped="yes"/>
                 <style>
                     <class name="image-button"/>
                 </style>
diff --git a/src/gl-eventtoolbar.c b/src/gl-eventtoolbar.c
index 10aec39..eb2515f 100644
--- a/src/gl-eventtoolbar.c
+++ b/src/gl-eventtoolbar.c
@@ -21,6 +21,7 @@
 #include <glib/gi18n.h>
 
 #include "gl-enums.h"
+#include "gl-eventview.h"
 
 enum
 {
@@ -42,31 +43,10 @@ G_DEFINE_TYPE_WITH_PRIVATE (GlEventToolbar, gl_event_toolbar, GTK_TYPE_HEADER_BA
 static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
 
 static void
-on_gl_event_toolbar_back_button_clicked (GtkButton *button,
-                                         gpointer user_data)
+on_gl_event_toolbar_back_button_clicked (GlEventToolbar *toolbar,
+                                         GtkButton *button)
 {
-    GtkWidget *toplevel;
-
-    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
-
-    if (gtk_widget_is_toplevel (toplevel))
-    {
-        GAction *mode;
-        GEnumClass *eclass;
-        GEnumValue *evalue;
-
-        mode = g_action_map_lookup_action (G_ACTION_MAP (toplevel), "mode");
-        eclass = g_type_class_ref (GL_TYPE_EVENT_TOOLBAR_MODE);
-        evalue = g_enum_get_value (eclass, GL_EVENT_TOOLBAR_MODE_LIST);
-
-        g_action_activate (mode, g_variant_new_string (evalue->value_nick));
-
-        g_type_class_unref (eclass);
-    }
-    else
-    {
-        g_error ("Widget not in toplevel window, not switching toolbar mode");
-    }
+    gl_event_toolbar_set_mode (toolbar, GL_EVENT_TOOLBAR_MODE_LIST);
 }
 
 static void
@@ -75,6 +55,7 @@ on_notify_mode (GlEventToolbar *toolbar,
                 gpointer user_data)
 {
     GlEventToolbarPrivate *priv;
+    GtkWidget *toplevel;
 
     priv = gl_event_toolbar_get_instance_private (toolbar);
 
@@ -92,6 +73,29 @@ on_notify_mode (GlEventToolbar *toolbar,
             g_assert_not_reached ();
             break;
     }
+
+    /* Propagate change to GlWindow. */
+    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (toolbar));
+
+    if (gtk_widget_is_toplevel (toplevel))
+    {
+        GAction *mode;
+        GEnumClass *eclass;
+        GEnumValue *evalue;
+
+        mode = g_action_map_lookup_action (G_ACTION_MAP (toplevel),
+                                           "toolbar-mode");
+        eclass = g_type_class_ref (GL_TYPE_EVENT_TOOLBAR_MODE);
+        evalue = g_enum_get_value (eclass, priv->mode);
+
+        g_action_activate (mode, g_variant_new_string (evalue->value_nick));
+
+        g_type_class_unref (eclass);
+    }
+    else
+    {
+        g_error ("Widget not in toplevel window, not switching toolbar mode");
+    }
 }
 
 static void
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 7add812..e735e04 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -107,7 +107,6 @@ on_listbox_row_activated (GtkListBox *listbox,
     GtkWidget *label;
     GtkStyleContext *style;
     GtkStack *stack;
-    GtkWidget *toplevel;
 
     priv = gl_event_view_get_instance_private (view);
     cursor = g_object_get_data (G_OBJECT (row), "cursor");
@@ -168,31 +167,9 @@ on_listbox_row_activated (GtkListBox *listbox,
 
     gtk_widget_show_all (grid);
     stack = GTK_STACK (view);
-    gtk_stack_add_named (stack, grid, "detailed");
-    gtk_stack_set_visible_child_name (stack, "detailed");
+    gtk_stack_add_named (stack, grid, "detail");
     gl_event_view_set_mode (view, GL_EVENT_VIEW_MODE_DETAIL);
 
-    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
-    if (gtk_widget_is_toplevel (toplevel))
-    {
-        GAction *mode;
-        GEnumClass *eclass;
-        GEnumValue *evalue;
-
-        mode = g_action_map_lookup_action (G_ACTION_MAP (toplevel), "mode");
-        eclass = g_type_class_ref (GL_TYPE_EVENT_TOOLBAR_MODE);
-        evalue = g_enum_get_value (eclass, GL_EVENT_TOOLBAR_MODE_DETAIL);
-
-        g_action_activate (mode, g_variant_new_string (evalue->value_nick));
-
-        g_type_class_unref (eclass);
-    }
-    else
-    {
-        g_error ("Widget not in toplevel window, not switching toolbar mode");
-    }
-
 out:
     gl_journal_result_free (priv->journal, result);
     return;
@@ -258,29 +235,55 @@ on_notify_mode (GlEventView *view,
                 gpointer user_data)
 {
     GlEventViewPrivate *priv;
+    GtkStack *stack;
+    GtkWidget *toplevel;
 
     priv = gl_event_view_get_instance_private (view);
+    stack = GTK_STACK (view);
 
     switch (priv->mode)
     {
-
         case GL_EVENT_VIEW_MODE_LIST:
             {
-                GtkStack *stack;
                 GtkWidget *visible_child;
+                GtkWidget *viewport;
+                GtkWidget *scrolled_window;
 
-                stack = GTK_STACK (view);
                 visible_child = gtk_stack_get_visible_child (stack);
                 gtk_container_remove (GTK_CONTAINER (stack), visible_child);
+                viewport = gtk_widget_get_parent (GTK_WIDGET (priv->active_listbox));
+                scrolled_window = gtk_widget_get_parent (viewport);
+                gtk_stack_set_visible_child (stack, scrolled_window);
             }
             break;
         case GL_EVENT_VIEW_MODE_DETAIL:
-            /* Ignore. */
+            gtk_stack_set_visible_child_name (stack, "detail");
             break;
         default:
             g_assert_not_reached ();
             break;
     }
+
+    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+    if (gtk_widget_is_toplevel (toplevel))
+    {
+        GAction *mode;
+        GEnumClass *eclass;
+        GEnumValue *evalue;
+
+        mode = g_action_map_lookup_action (G_ACTION_MAP (toplevel), "view-mode");
+        eclass = g_type_class_ref (GL_TYPE_EVENT_VIEW_MODE);
+        evalue = g_enum_get_value (eclass, priv->mode);
+
+        g_action_activate (mode, g_variant_new_string (evalue->value_nick));
+
+        g_type_class_unref (eclass);
+    }
+    else
+    {
+        g_error ("Widget not in toplevel window, not switching toolbar mode");
+    }
 }
 
 static void
diff --git a/src/gl-window.c b/src/gl-window.c
index 8545ad1..1c257f9 100644
--- a/src/gl-window.c
+++ b/src/gl-window.c
@@ -82,25 +82,21 @@ on_category (GSimpleAction *action,
 }
 
 static void
-on_mode (GSimpleAction *action,
-         GVariant *variant,
-         gpointer user_data)
+on_toolbar_mode (GSimpleAction *action,
+                 GVariant *variant,
+                 gpointer user_data)
 {
     GlWindowPrivate *priv;
     const gchar *mode;
-    GAction *search;
-    GlEventToolbar *toolbar;
     GEnumClass *eclass;
     GEnumValue *evalue;
+    GAction *search;
 
     priv = gl_window_get_instance_private (GL_WINDOW (user_data));
     mode = g_variant_get_string (variant, NULL);
-    search = g_action_map_lookup_action (G_ACTION_MAP (user_data), "search");
-    toolbar = GL_EVENT_TOOLBAR (priv->right_toolbar);
     eclass = g_type_class_ref (GL_TYPE_EVENT_TOOLBAR_MODE);
     evalue = g_enum_get_value_by_nick (eclass, mode);
-
-    gl_event_toolbar_set_mode (toolbar, evalue->value);
+    search = g_action_map_lookup_action (G_ACTION_MAP (user_data), "search");
 
     if (evalue->value == GL_EVENT_TOOLBAR_MODE_LIST)
     {
@@ -111,11 +107,45 @@ on_mode (GSimpleAction *action,
         view = GL_EVENT_VIEW (priv->events);
 
         gl_event_view_set_mode (view, GL_EVENT_VIEW_MODE_LIST);
+
         g_simple_action_set_enabled (G_SIMPLE_ACTION (search), TRUE);
     }
     else
     {
         g_simple_action_set_enabled (G_SIMPLE_ACTION (search), FALSE);
+        g_action_change_state (search, g_variant_new_boolean (FALSE));
+    }
+
+    g_simple_action_set_state (action, variant);
+
+    g_type_class_unref (eclass);
+}
+
+static void
+on_view_mode (GSimpleAction *action,
+              GVariant *variant,
+              gpointer user_data)
+{
+    GlWindowPrivate *priv;
+    const gchar *mode;
+    GlEventToolbar *toolbar;
+    GEnumClass *eclass;
+    GEnumValue *evalue;
+
+    priv = gl_window_get_instance_private (GL_WINDOW (user_data));
+    mode = g_variant_get_string (variant, NULL);
+    toolbar = GL_EVENT_TOOLBAR (priv->right_toolbar);
+    eclass = g_type_class_ref (GL_TYPE_EVENT_VIEW_MODE);
+    evalue = g_enum_get_value_by_nick (eclass, mode);
+
+    switch (evalue->value)
+    {
+        case GL_EVENT_VIEW_MODE_LIST:
+            gl_event_toolbar_set_mode (toolbar, GL_EVENT_TOOLBAR_MODE_LIST);
+            break;
+        case GL_EVENT_VIEW_MODE_DETAIL:
+            gl_event_toolbar_set_mode (toolbar, GL_EVENT_TOOLBAR_MODE_DETAIL);
+            break;
     }
 
     g_simple_action_set_state (action, variant);
@@ -211,7 +241,8 @@ on_provider_parsing_error (GtkCssProvider *provider,
 
 static GActionEntry actions[] = {
     { "category", on_action_radio, "s", "'all'", on_category },
-    { "mode", on_action_radio, "s", "'list'", on_mode },
+    { "view-mode", on_action_radio, "s", "'list'", on_view_mode },
+    { "toolbar-mode", on_action_radio, "s", "'list'", on_toolbar_mode },
     { "search", on_action_toggle, NULL, "false", on_search }
 };
 


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