[gnome-software/wip/templates: 4/6] Use a GtkBuilder template for GsShellSearch



commit 07d1c1f09ac5ff68e9367e3737e5453838ca24fd
Author: Kalev Lember <kalevlember gmail com>
Date:   Thu Mar 27 21:18:26 2014 +0100

    Use a GtkBuilder template for GsShellSearch
    
    Move the UI definition to separate file and use a GtkBuilder template
    for subclassing the widget.

 po/POTFILES.in                   |    1 +
 src/Makefile.am                  |    1 +
 src/gnome-software.gresource.xml |    1 +
 src/gnome-software.ui            |   87 +----------------------------------
 src/gs-shell-search.c            |   44 ++++++++++-------
 src/gs-shell-search.h            |    4 +-
 src/gs-shell-search.ui           |   96 ++++++++++++++++++++++++++++++++++++++
 src/gs-shell.c                   |    3 +-
 8 files changed, 129 insertions(+), 108 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 863aba8..571fab7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -24,6 +24,7 @@ src/gs-shell-details.c
 src/gs-shell-installed.c
 src/gs-shell-overview.c
 src/gs-shell-search.c
+[type: gettext/glade]src/gs-shell-search.ui
 src/gs-shell-updates.c
 [type: gettext/glade]src/gs-shell-updates.ui
 src/gs-sources-dialog.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 6811a99..7846828 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ UI_FILES =                                            \
        gs-history-dialog.ui                            \
        gs-shell-category.ui                            \
        gs-shell-details.ui                             \
+       gs-shell-search.ui                              \
        gs-shell-updates.ui                             \
        gs-sources-dialog.ui                            \
        gs-star-widget.ui                               \
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 45580a1..fda9a64 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -13,6 +13,7 @@
   <file preprocess="xml-stripblanks">gs-history-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-category.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-details.ui</file>
+  <file preprocess="xml-stripblanks">gs-shell-search.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-updates.ui</file>
   <file preprocess="xml-stripblanks">gs-sources-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-star-widget.ui</file>
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index a39704a..5b2f482 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -741,93 +741,8 @@
               </packing>
             </child>
             <child>
-              <object class="GtkStack" id="stack_search">
+              <object class="GsShellSearch" id="shell_search">
                 <property name="visible">True</property>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="search-accessible">
-                    <property name="accessible-name" translatable="yes">Search page</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSpinner" id="spinner_search">
-                    <property name="visible">True</property>
-                    <property name="width_request">128</property>
-                    <property name="height_request">128</property>
-                    <property name="halign">center</property>
-                    <property name="valign">center</property>
-                  </object>
-                  <packing>
-                    <property name="name">spinner</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkGrid" id="noresults_grid_search">
-                    <property name="visible">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <property name="halign">center</property>
-                    <property name="valign">center</property>
-                    <property name="row-spacing">12</property>
-                    <property name="column-spacing">12</property>
-                    <style>
-                      <class name="dim-label"/>
-                    </style>
-                    <child>
-                      <object class="GtkImage" id="noresults_icon">
-                        <property name="visible">True</property>
-                        <property name="icon_name">gnome-software-symbolic</property>
-                        <property name="pixel-size">64</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="noresults_label">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">No Application Found</property>
-                        <property name="halign">start</property>
-                        <property name="valign">center</property>
-                        <attributes>
-                          <attribute name="scale" value="1.4"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">no-results</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkScrolledWindow" id="scrolledwindow_search">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hscrollbar_policy">never</property>
-                    <property name="vscrollbar_policy">automatic</property>
-                    <property name="shadow_type">none</property>
-                    <style>
-                      <class name="main-scrolled-software"/>
-                    </style>
-                    <child>
-                      <object class="GtkListBox" id="list_box_search">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="selection_mode">none</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">results</property>
-                  </packing>
-                </child>
               </object>
               <packing>
                 <property name="name">search</property>
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 68f3d08..a7b419c 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -37,15 +37,19 @@ struct GsShellSearchPrivate
        GsPluginLoader          *plugin_loader;
        GtkBuilder              *builder;
        GCancellable            *cancellable;
-       GtkListBox              *list_box_search;
        GtkSizeGroup            *sizegroup_image;
        GtkSizeGroup            *sizegroup_name;
        gboolean                 waiting;
        GsShell                 *shell;
        gchar                   *value;
+
+       GtkWidget               *list_box_search;
+       GtkWidget               *scrolledwindow_search;
+       GtkWidget               *spinner_search;
+       GtkWidget               *stack_search;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GsShellSearch, gs_shell_search, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GsShellSearch, gs_shell_search, GTK_TYPE_BIN)
 
 static void
 gs_shell_search_app_widget_activated_cb (GtkListBox *list_box,
@@ -249,9 +253,7 @@ gs_shell_search_get_search_cb (GObject *source_object,
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
        GtkWidget *widget;
 
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "spinner_search"));
-       gs_stop_spinner (GTK_SPINNER (widget));
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "stack_search"));
+       gs_stop_spinner (GTK_SPINNER (priv->spinner_search));
 
        priv->waiting = FALSE;
 
@@ -266,10 +268,10 @@ gs_shell_search_get_search_cb (GObject *source_object,
                                   error->message);
                }
                g_error_free (error);
-               gtk_stack_set_visible_child_name (GTK_STACK (widget), "no-results");
+               gtk_stack_set_visible_child_name (GTK_STACK (priv->stack_search), "no-results");
                goto out;
        }
-       gtk_stack_set_visible_child_name (GTK_STACK (widget), "results");
+       gtk_stack_set_visible_child_name (GTK_STACK (priv->stack_search), "results");
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                widget = gs_app_widget_new ();
@@ -295,7 +297,6 @@ gs_shell_search_refresh (GsShellSearch *shell_search, const gchar *value, gboole
 {
        GsShellSearchPrivate *priv = shell_search->priv;
        GtkWidget *widget;
-       GtkSpinner *spinner;
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
        gtk_widget_show (widget);
@@ -306,14 +307,13 @@ gs_shell_search_refresh (GsShellSearch *shell_search, const gchar *value, gboole
        if (priv->waiting)
                return;
 
-        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_search"));
         if (scroll_up) {
                 GtkAdjustment *adj;
-                adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
+                adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(priv->scrolledwindow_search));
                 gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
         }
         if (gs_shell_get_mode (priv->shell) == GS_SHELL_MODE_SEARCH) {
-                gs_grab_focus_when_mapped (widget);
+                gs_grab_focus_when_mapped (priv->scrolledwindow_search);
         }
 
        if (g_strcmp0 (value, priv->value) == 0)
@@ -337,10 +337,8 @@ gs_shell_search_refresh (GsShellSearch *shell_search, const gchar *value, gboole
                                       gs_shell_search_get_search_cb,
                                       shell_search);
 
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "stack_search"));
-       gtk_stack_set_visible_child_name (GTK_STACK (widget), "spinner");
-       spinner = GTK_SPINNER (gtk_builder_get_object (priv->builder, "spinner_search"));
-       gs_start_spinner (spinner);
+       gtk_stack_set_visible_child_name (GTK_STACK (priv->stack_search), "spinner");
+       gs_start_spinner (GTK_SPINNER (priv->spinner_search));
        priv->waiting = TRUE;
 }
 
@@ -489,13 +487,12 @@ gs_shell_search_setup (GsShellSearch *shell_search,
                          G_CALLBACK (gs_shell_search_filter_text_changed_cb), shell_search);
 
        /* setup search */
-       priv->list_box_search = GTK_LIST_BOX (gtk_builder_get_object (priv->builder, "list_box_search"));
        g_signal_connect (priv->list_box_search, "row-activated",
                          G_CALLBACK (gs_shell_search_app_widget_activated_cb), shell_search);
-       gtk_list_box_set_header_func (priv->list_box_search,
+       gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list_box_search),
                                      gs_shell_search_list_header_func,
                                      shell_search, NULL);
-       gtk_list_box_set_sort_func (priv->list_box_search,
+       gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->list_box_search),
                                    gs_shell_search_sort_func,
                                    shell_search, NULL);
 }
@@ -507,7 +504,16 @@ static void
 gs_shell_search_class_init (GsShellSearchClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
        object_class->finalize = gs_shell_search_finalize;
+
+       gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/software/gs-shell-search.ui");
+
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellSearch, list_box_search);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellSearch, scrolledwindow_search);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellSearch, spinner_search);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellSearch, stack_search);
 }
 
 /**
@@ -516,6 +522,8 @@ gs_shell_search_class_init (GsShellSearchClass *klass)
 static void
 gs_shell_search_init (GsShellSearch *shell_search)
 {
+       gtk_widget_init_template (GTK_WIDGET (shell_search));
+
        shell_search->priv = gs_shell_search_get_instance_private (shell_search);
        shell_search->priv->sizegroup_image = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
        shell_search->priv->sizegroup_name = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
diff --git a/src/gs-shell-search.h b/src/gs-shell-search.h
index 5c44b15..b7faea8 100644
--- a/src/gs-shell-search.h
+++ b/src/gs-shell-search.h
@@ -41,13 +41,13 @@ typedef struct GsShellSearchPrivate GsShellSearchPrivate;
 
 typedef struct
 {
-        GObject                         parent;
+        GtkBin                          parent;
         GsShellSearchPrivate           *priv;
 } GsShellSearch;
 
 typedef struct
 {
-       GObjectClass                     parent_class;
+       GtkBinClass                      parent_class;
 } GsShellSearchClass;
 
 GType           gs_shell_search_get_type       (void);
diff --git a/src/gs-shell-search.ui b/src/gs-shell-search.ui
new file mode 100644
index 0000000..73f6448
--- /dev/null
+++ b/src/gs-shell-search.ui
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <template class="GsShellSearch" parent="GtkBin">
+    <child internal-child="accessible">
+      <object class="AtkObject" id="search-accessible">
+        <property name="accessible-name" translatable="yes">Search page</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkStack" id="stack_search">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkSpinner" id="spinner_search">
+            <property name="visible">True</property>
+            <property name="width_request">128</property>
+            <property name="height_request">128</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+          </object>
+          <packing>
+            <property name="name">spinner</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="noresults_grid_search">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="row-spacing">12</property>
+            <property name="column-spacing">12</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+            <child>
+              <object class="GtkImage" id="noresults_icon">
+                <property name="visible">True</property>
+                <property name="icon_name">gnome-software-symbolic</property>
+                <property name="pixel-size">64</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="noresults_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">No Application Found</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <attributes>
+                  <attribute name="scale" value="1.4"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="name">no-results</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow_search">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">never</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <property name="shadow_type">none</property>
+            <style>
+              <class name="main-scrolled-software"/>
+            </style>
+            <child>
+              <object class="GtkListBox" id="list_box_search">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="selection_mode">none</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="name">results</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 96fac98..17c8f26 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -536,6 +536,7 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
                                  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,
@@ -735,7 +736,6 @@ gs_shell_init (GsShell *shell)
        shell->priv = gs_shell_get_instance_private (shell);
        shell->priv->shell_overview = gs_shell_overview_new ();
        shell->priv->shell_installed = gs_shell_installed_new ();
-       shell->priv->shell_search = gs_shell_search_new ();
        shell->priv->ignore_primary_buttons = FALSE;
 }
 
@@ -754,7 +754,6 @@ gs_shell_finalize (GObject *object)
        g_object_unref (priv->plugin_loader);
        g_object_unref (priv->shell_overview);
        g_object_unref (priv->shell_installed);
-       g_object_unref (priv->shell_search);
 
        G_OBJECT_CLASS (gs_shell_parent_class)->finalize (object);
 }


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