[buoh/builder-port: 5/5] Port add comic dialog to GtkBuilder



commit bbfb944c36403372e30e421aadc62e78aff9eda2
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon Sep 10 19:47:06 2018 +0200

    Port add comic dialog to GtkBuilder
    
    https://bugzilla.gnome.org/show_bug.cgi?id=607921

 data/meson.build                  |   1 +
 data/org.gnome.buoh.gresource.xml |   1 +
 data/ui/add-comic-dialog.ui       | 157 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                    |   1 +
 src/buoh-add-comic-dialog.c       | 121 ++++-------------------------
 src/buoh-add-comic-dialog.h       |   2 +
 6 files changed, 175 insertions(+), 108 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index c991e40..57ea5b7 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,4 +1,5 @@
 ui_files = files(
+  'ui/add-comic-dialog.ui',
   'ui/properties-dialog.ui',
 )
 if gtk_builder_tool.found()
diff --git a/data/org.gnome.buoh.gresource.xml b/data/org.gnome.buoh.gresource.xml
index 1689276..9bb5757 100644
--- a/data/org.gnome.buoh.gresource.xml
+++ b/data/org.gnome.buoh.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/buoh">
     <file>buoh-ui.xml</file>
+    <file>ui/add-comic-dialog.ui</file>
     <file>ui/properties-dialog.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/add-comic-dialog.ui b/data/ui/add-comic-dialog.ui
new file mode 100644
index 0000000..bf68a26
--- /dev/null
+++ b/data/ui/add-comic-dialog.ui
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkListStore" id="comicstore">
+    <columns>
+      <!-- column-name COMIC_LIST_VISIBLE -->
+      <column type="gboolean"/>
+      <!-- column-name COMIC_LIST_TITLE -->
+      <column type="gchararray"/>
+      <!-- column-name COMIC_LIST_AUTHOR -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <template class="BuohAddComicDialog" parent="GtkDialog">
+    <property name="border-width">5</property>
+    <property name="title" translatable="yes">Add Comic</property>
+    <property name="default-width">400</property>
+    <property name="default-height">300</property>
+    <property name="destroy-with-parent">1</property>
+    <property name="type-hint">dialog</property>
+    <signal name="response" handler="gtk_widget_destroy" swapped="no"/>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="layout-style">end</property>
+            <child>
+              <object class="GtkButton" id="close">
+                <property name="label" translatable="yes">_Close</property>
+                <property name="visible">1</property>
+                <property name="can-focus">1</property>
+                <property name="receives-default">1</property>
+                <property name="use-underline">1</property>
+              </object>
+              <packing>
+                <property name="expand">1</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="fill">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFrame">
+            <property name="visible">1</property>
+            <property name="shadow-type">none</property>
+            <child>
+              <object class="GtkAlignment">
+                <property name="visible">1</property>
+                <property name="left-padding">12</property>
+                <child>
+                  <object class="GtkBox">
+                    <property name="visible">1</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">12</property>
+                    <child>
+                      <object class="GtkScrolledWindow">
+                        <property name="visible">1</property>
+                        <property name="can-focus">1</property>
+                        <property name="vexpand">1</property>
+                        <property name="shadow-type">in</property>
+                        <child>
+                          <object class="GtkTreeView" id="tree_view">
+                            <property name="visible">1</property>
+                            <property name="can-focus">1</property>
+                            <property name="model">comicstore</property>
+                            <property name="rules-hint">1</property>
+                            <property name="search-column">2</property>
+                            <child internal-child="selection">
+                              <object class="GtkTreeSelection"/>
+                            </child>
+                            <child>
+                              <object class="GtkTreeViewColumn" id="active">
+                                <child>
+                                  <object class="GtkCellRendererToggle" id="active_cell">
+                                    <signal name="toggled" handler="buoh_add_comic_toggled_cb" swapped="no"/>
+                                  </object>
+                                  <attributes>
+                                    <attribute name="active">0</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkTreeViewColumn" id="title">
+                                <property name="title" translatable="yes">Title</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="title_cell">
+                                    <property name="xalign">0</property>
+                                    <property name="ellipsize">end</property>
+                                    <property name="width-chars">20</property>
+                                  </object>
+                                  <attributes>
+                                    <attribute name="text">1</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkTreeViewColumn" id="author">
+                                <property name="title" translatable="yes">Author</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="author_cell">
+                                    <property name="xalign">0</property>
+                                    <property name="ellipsize">end</property>
+                                    <property name="width-chars">20</property>
+                                  </object>
+                                  <attributes>
+                                    <attribute name="text">2</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="selected_label">
+                        <property name="visible">1</property>
+                        <property name="label" translatable="yes">Comics selected: %d</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="fill">0</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel">
+                <property name="visible">1</property>
+                <property name="label" translatable="yes">&lt;b&gt;Select Comics&lt;/b&gt;</property>
+                <property name="use-markup">1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">1</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">close</action-widget>
+    </action-widgets>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5dc2023..b805ced 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@
 # Please keep this file sorted alphabetically.
 data/buoh.desktop.in
 data/org.gnome.buoh.gschema.xml
+data/ui/add-comic-dialog.ui
 data/ui/properties-dialog.ui
 src/buoh-add-comic-dialog.c
 src/buoh-comic-list.c
diff --git a/src/buoh-add-comic-dialog.c b/src/buoh-add-comic-dialog.c
index e773b8c..4478922 100644
--- a/src/buoh-add-comic-dialog.c
+++ b/src/buoh-add-comic-dialog.c
@@ -31,7 +31,6 @@
 
 struct _BuohAddComicDialogPrivate {
         GtkTreeModel *model;
-        GtkWidget    *selected_label;
         gint          n_selected;
 };
 
@@ -52,124 +51,32 @@ G_DEFINE_TYPE (BuohAddComicDialog, buoh_add_comic_dialog, GTK_TYPE_DIALOG)
 static void
 buoh_add_comic_dialog_init (BuohAddComicDialog *dialog)
 {
-        GtkWidget         *frame, *label;
-        GtkWidget         *vbox;
-        GtkWidget         *swindow;
-        GtkWidget         *tree_view;
-        GtkCellRenderer   *renderer;
-        GtkTreeViewColumn *column;
-        gchar             *markup;
-
         dialog->priv = BUOH_ADD_COMIC_DIALOG_GET_PRIVATE (dialog);
 
+        gtk_widget_init_template (GTK_WIDGET (dialog));
+
         dialog->priv->model = buoh_get_comics_model (BUOH);
 
-        gtk_window_set_title (GTK_WINDOW (dialog), _("Add Comic"));
-        gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300);
-        gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
-        gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
-        gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
-                             12);
-
-        gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE,
-                               GTK_RESPONSE_ACCEPT);
-
-        label = gtk_label_new (NULL);
-
-        markup = g_strdup_printf ("<b>%s</b>", _("Select Comics"));
-        gtk_label_set_markup (GTK_LABEL (label), markup);
-        g_free (markup);
-
-        frame = gtk_frame_new (NULL);
-        gtk_frame_set_label_widget (GTK_FRAME (frame), label);
-        gtk_widget_show (label);
-        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
-
-        vbox = gtk_vbox_new (FALSE, 12);
-        gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
-
-        /* List */
-        swindow = gtk_scrolled_window_new (NULL, NULL);
-        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
-                                        GTK_POLICY_AUTOMATIC,
-                                        GTK_POLICY_AUTOMATIC);
-        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
-                                             GTK_SHADOW_IN);
-
-        tree_view = gtk_tree_view_new_with_model (dialog->priv->model);
-        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), TRUE);
-        gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
-        gtk_tree_view_set_enable_search (GTK_TREE_VIEW (tree_view), TRUE);
-
-        renderer = gtk_cell_renderer_toggle_new ();
-        column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
-                                                           "active", COMIC_LIST_VISIBLE,
-                                                           NULL);
-        g_signal_connect (G_OBJECT (renderer), "toggled",
-                          G_CALLBACK (buoh_add_comic_toggled_cb),
-                          (gpointer) dialog);
-        gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view),
-                                     column, COMIC_LIST_VISIBLE);
-
-        renderer = gtk_cell_renderer_text_new ();
-        g_object_set (G_OBJECT (renderer),
-                      "width-chars", 20,
-                      "ellipsize-set", TRUE,
-                      "ellipsize", PANGO_ELLIPSIZE_END,
-                      NULL);
-        column = gtk_tree_view_column_new_with_attributes (_("Title"), renderer,
-                                                           "text", COMIC_LIST_TITLE,
-                                                           NULL);
-        gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
-        gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view),
-                                     column, COMIC_LIST_TITLE);
-
-        renderer = gtk_cell_renderer_text_new ();
-        g_object_set (G_OBJECT (renderer),
-                      "width-chars", 20,
-                      "ellipsize-set", TRUE,
-                      "ellipsize", PANGO_ELLIPSIZE_END,
-                      NULL);
-        column = gtk_tree_view_column_new_with_attributes (_("Author"), renderer,
-                                                           "text", COMIC_LIST_AUTHOR,
-                                                           NULL);
-        gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
-        gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view),
-                                     column, COMIC_LIST_AUTHOR);
-
-        gtk_container_add (GTK_CONTAINER (swindow), tree_view);
-        gtk_widget_show (tree_view);
-
-        gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
-        gtk_widget_show (swindow);
+        gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->tree_view), dialog->priv->model);
 
         /* Counter */
-        dialog->priv->selected_label = gtk_label_new (NULL);
-        gtk_misc_set_alignment (GTK_MISC (dialog->priv->selected_label),
-                                0.0, 0.5);
         dialog->priv->n_selected = buoh_add_comic_dialog_get_n_selected (dialog);
         buoh_comic_add_dialog_update_selected (dialog);
-
-        gtk_box_pack_start (GTK_BOX (vbox), dialog->priv->selected_label,
-                            FALSE, FALSE, 0);
-        gtk_widget_show (dialog->priv->selected_label);
-
-        gtk_container_add (GTK_CONTAINER (frame), vbox);
-        gtk_widget_show (vbox);
-
-        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
-                            frame, TRUE, TRUE, 0);
-        gtk_widget_show (frame);
-
-        g_signal_connect (G_OBJECT (dialog), "response",
-                          G_CALLBACK (gtk_widget_destroy),
-                          NULL);
 }
 
 static void
 buoh_add_comic_dialog_class_init (BuohAddComicDialogClass *klass)
 {
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
         g_type_class_add_private (klass, sizeof (BuohAddComicDialogPrivate));
+
+        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/buoh/ui/add-comic-dialog.ui");
+
+        gtk_widget_class_bind_template_child (widget_class, BuohAddComicDialog, selected_label);
+        gtk_widget_class_bind_template_child (widget_class, BuohAddComicDialog, tree_view);
+
+        gtk_widget_class_bind_template_callback (widget_class, buoh_add_comic_toggled_cb);
 }
 
 static gint
@@ -201,10 +108,8 @@ buoh_comic_add_dialog_update_selected (BuohAddComicDialog *dialog)
         gchar *text;
 
         text = g_strdup_printf (_("Comics selected: %d"), dialog->priv->n_selected);
-        gtk_label_set_text (GTK_LABEL (dialog->priv->selected_label), text);
+        gtk_label_set_text (GTK_LABEL (dialog->selected_label), text);
         g_free (text);
-
-        gtk_widget_show (dialog->priv->selected_label);
 }
 
 static void
diff --git a/src/buoh-add-comic-dialog.h b/src/buoh-add-comic-dialog.h
index 94c8d12..c914adb 100644
--- a/src/buoh-add-comic-dialog.h
+++ b/src/buoh-add-comic-dialog.h
@@ -38,6 +38,8 @@ typedef struct _BuohAddComicDialogPrivate BuohAddComicDialogPrivate;
 struct _BuohAddComicDialog {
         GtkDialog                  parent;
         BuohAddComicDialogPrivate *priv;
+        GtkWidget                 *selected_label;
+        GtkWidget                 *tree_view;
 };
 
 struct _BuohAddComicDialogClass {


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