[buoh/builder-port: 4/4] ui: Port properties dialog to GtkBuilder



commit 09ec737f2d437c9af463b7b2e9796a24d1a4e83e
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon Sep 10 03:11:01 2018 +0200

    ui: Port properties dialog to GtkBuilder
    
    GtkBuilder is a more declarative approach to creating user interfaces.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=607921

 data/org.gnome.buoh.gresource.xml |   1 +
 data/ui/properties-dialog.ui      | 261 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                    |   1 +
 src/buoh-properties-dialog.c      | 160 +++--------------------
 src/buoh-properties-dialog.h      |   7 +
 5 files changed, 290 insertions(+), 140 deletions(-)
---
diff --git a/data/org.gnome.buoh.gresource.xml b/data/org.gnome.buoh.gresource.xml
index 476097c..1689276 100644
--- a/data/org.gnome.buoh.gresource.xml
+++ b/data/org.gnome.buoh.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/buoh">
     <file>buoh-ui.xml</file>
+    <file>ui/properties-dialog.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/properties-dialog.ui b/data/ui/properties-dialog.ui
new file mode 100644
index 0000000..421a7d3
--- /dev/null
+++ b/data/ui/properties-dialog.ui
@@ -0,0 +1,261 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <template class="BuohPropertiesDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="title" translatable="yes">Comic Properties</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <signal name="response" handler="gtk_widget_destroy" swapped="no"/>
+    <child>
+      <placeholder/>
+    </child>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="close">
+                <property name="label" translatable="yes">_Close</property>
+                <property name="name">close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkImage" id="thumbnail">
+                <property name="width_request">96</property>
+                <property name="height_request">96</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="icon_name">image-missing</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="border_width">5</property>
+                <property name="row_spacing">6</property>
+                <property name="column_spacing">12</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Title:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Author:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Link:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Date of publication:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Language:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Publication days:</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="title">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="author">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="uri">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="ellipsize">end</property>
+                    <property name="width_chars">35</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="date">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="language">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="publication_days">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0.5</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">5</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</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 e9f2daf..5dc2023 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/properties-dialog.ui
 src/buoh-add-comic-dialog.c
 src/buoh-comic-list.c
 src/buoh-comic-manager-date.c
diff --git a/src/buoh-properties-dialog.c b/src/buoh-properties-dialog.c
index 7a6280a..2e89328 100644
--- a/src/buoh-properties-dialog.c
+++ b/src/buoh-properties-dialog.c
@@ -45,108 +45,52 @@ buoh_properties_dialog_init (BuohPropertiesDialog *dialog)
 {
         dialog->priv = BUOH_PROPERTIES_DIALOG_GET_PRIVATE (dialog);
 
-        gtk_window_set_title (GTK_WINDOW (dialog), _("Comic Properties"));
-        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);
-        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
-                                         GTK_RESPONSE_ACCEPT);
-
-        g_signal_connect (G_OBJECT (dialog), "response",
-                          G_CALLBACK (gtk_widget_destroy),
-                          NULL);
+        gtk_widget_init_template (GTK_WIDGET (dialog));
 }
 
 static void
 buoh_properties_dialog_class_init (BuohPropertiesDialogClass *klass)
 {
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
         g_type_class_add_private (klass, sizeof (BuohPropertiesDialogPrivate));
+
+        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/buoh/ui/properties-dialog.ui");
+
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, title);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, author);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, uri);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, language);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, date);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, publication_days);
+        gtk_widget_class_bind_template_child (widget_class, BuohPropertiesDialog, thumbnail);
 }
 
 void
 buoh_properties_dialog_set_comic_manager (BuohPropertiesDialog   *dialog,
                                           BuohComicManager       *comic_manager)
 {
-        GtkWidget *table;
-        GtkWidget *label_title, *label_title_val;
-        GtkWidget *label_author, * label_author_val;
-        GtkWidget *label_uri, *label_uri_val;
-        GtkWidget *label_language, *label_language_val;
-        GtkWidget *label_date, *label_date_val;
-        GtkWidget *label_pub_days, *label_pub_days_val;
-        GtkWidget *image;
         GDate     *comic_date;
         gchar      date[DATE_BUFFER];
         gchar     *pub_days;
         BuohComic *comic;
         GdkPixbuf *thumbnail;
-        gchar     *str;
 
         g_return_if_fail (BUOH_IS_PROPERTIES_DIALOG (dialog));
         g_return_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager));
 
         dialog->priv->comic_manager = comic_manager;
 
-        table = gtk_table_new (5, 3, FALSE);
-
         comic = buoh_comic_manager_get_current (comic_manager);
 
         thumbnail = buoh_comic_get_thumbnail (comic);
-        image = gtk_image_new_from_pixbuf (thumbnail);
+        gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->thumbnail), thumbnail);
         g_object_unref (thumbnail);
 
-        gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
-
-        str = g_strdup_printf ("<b>%s:</b>", _("Title"));
-        label_title = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label_title), str);
-        gtk_misc_set_alignment (GTK_MISC (label_title), 0, 0.5);
-        g_free (str);
-
-        str = g_strdup_printf ("<b>%s:</b>", _("Author"));
-        label_author = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label_author), str);
-        gtk_misc_set_alignment (GTK_MISC (label_author), 0, 0.5);
-        g_free (str);
-
-        str = g_strdup_printf ("<b>%s:</b>", _("Link"));
-        label_uri = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label_uri), str);
-        gtk_misc_set_alignment (GTK_MISC (label_uri), 0, 0.5);
-        g_free (str);
-
-        str = g_strdup_printf ("<b>%s:</b>", _("Language"));
-        label_language = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label_language), str);
-        gtk_misc_set_alignment (GTK_MISC (label_language), 0, 0.5);
-        g_free (str);
-
-        str = g_strdup_printf ("<b>%s:</b>", _("Date of publication"));
-        label_date = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label_date), str);
-        gtk_misc_set_alignment (GTK_MISC (label_date), 0, 0.5);
-        g_free (str);
-
-        label_title_val = gtk_label_new (buoh_comic_manager_get_title (comic_manager));
-        gtk_label_set_selectable (GTK_LABEL (label_title_val), TRUE);
-        gtk_misc_set_alignment (GTK_MISC (label_title_val), 0, 0.5);
-
-        label_author_val = gtk_label_new (buoh_comic_manager_get_author (comic_manager));
-        gtk_label_set_selectable (GTK_LABEL (label_author_val), TRUE);
-        gtk_misc_set_alignment (GTK_MISC (label_author_val), 0, 0.5);
-
-        label_uri_val = gtk_label_new (buoh_comic_get_uri (comic));
-        gtk_label_set_selectable (GTK_LABEL (label_uri_val), TRUE);
-        gtk_misc_set_alignment (GTK_MISC (label_uri_val), 0, 0.5);
-        gtk_label_set_width_chars (GTK_LABEL (label_uri_val), 35);
-        gtk_label_set_ellipsize (GTK_LABEL (label_uri_val), PANGO_ELLIPSIZE_END);
-
-        label_language_val = gtk_label_new (buoh_comic_manager_get_language (comic_manager));
-        gtk_label_set_selectable (GTK_LABEL (label_language_val), TRUE);
-        gtk_misc_set_alignment (GTK_MISC (label_language_val), 0, 0.5);
+        gtk_label_set_text (GTK_LABEL (dialog->title), buoh_comic_manager_get_title (comic_manager));
+        gtk_label_set_text (GTK_LABEL (dialog->author), buoh_comic_manager_get_author (comic_manager));
+        gtk_label_set_text (GTK_LABEL (dialog->uri), buoh_comic_get_uri (comic));
+        gtk_label_set_text (GTK_LABEL (dialog->language), buoh_comic_manager_get_language (comic_manager));
 
         comic_date = buoh_comic_get_date (comic);
         if (g_date_strftime (date, DATE_BUFFER,
@@ -154,76 +98,13 @@ buoh_properties_dialog_set_comic_manager (BuohPropertiesDialog   *dialog,
                              comic_date) == 0) {
                 buoh_debug ("Date buffer too short");
         }
-        label_date_val = gtk_label_new (date);
-        gtk_label_set_selectable (GTK_LABEL (label_date_val), TRUE);
-        gtk_misc_set_alignment (GTK_MISC (label_date_val), 0, 0.5);
-
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (image),
-                          0, 1, 0, 5, GTK_FILL, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_title),
-                          1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_title_val),
-                          2, 3, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_author),
-                          1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0 );
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_author_val),
-                          2, 3, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_uri),
-                          1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_uri_val),
-                          2, 3, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_date),
-                          1, 2, 3, 4, GTK_FILL, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_date_val),
-                          2, 3, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_language),
-                          1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
-        gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_language_val),
-                          2, 3, 4, 5, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+        gtk_label_set_text (GTK_LABEL (dialog->date), date);
 
         if (BUOH_IS_COMIC_MANAGER_DATE (comic_manager)) {
-                str = g_strdup_printf ("<b>%s:</b>", _("Publication days"));
-                label_pub_days = gtk_label_new (NULL);
-                gtk_label_set_markup (GTK_LABEL (label_pub_days), str);
-                gtk_misc_set_alignment (GTK_MISC (label_pub_days), 0, 0.5);
-                g_free (str);
-
                 pub_days = buoh_comic_manager_date_get_publication_days (BUOH_COMIC_MANAGER_DATE 
(comic_manager));
-
-                label_pub_days_val = gtk_label_new (pub_days);
-                gtk_label_set_selectable (GTK_LABEL (label_pub_days_val), TRUE);
-                gtk_misc_set_alignment (GTK_MISC (label_pub_days_val), 0, 0.5);
+                gtk_label_set_text (GTK_LABEL (dialog->publication_days), pub_days);
                 g_free (pub_days);
-
-                gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_pub_days),
-                          1, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
-                gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (label_pub_days_val),
-                          2, 3, 5, 6, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-
-                gtk_widget_show (label_pub_days);
-                gtk_widget_show (label_pub_days_val);
         }
-
-        gtk_table_set_row_spacings (GTK_TABLE (table), 6);
-        gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-        gtk_container_set_border_width (GTK_CONTAINER (table), 5);
-
-        gtk_widget_show (image);
-        gtk_widget_show (label_title);
-        gtk_widget_show (label_title_val);
-        gtk_widget_show (label_author);
-        gtk_widget_show (label_author_val);
-        gtk_widget_show (label_uri);
-        gtk_widget_show (label_uri_val);
-        gtk_widget_show (label_language);
-        gtk_widget_show (label_language_val);
-        gtk_widget_show (label_date);
-        gtk_widget_show (label_date_val);
-
-        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
-                            table, TRUE, TRUE, 0);
-
-        gtk_widget_show (table);
 }
 
 BuohComicManager *
@@ -243,4 +124,3 @@ buoh_properties_dialog_new (void)
 
         return dialog;
 }
-
diff --git a/src/buoh-properties-dialog.h b/src/buoh-properties-dialog.h
index 6a09100..75995a5 100644
--- a/src/buoh-properties-dialog.h
+++ b/src/buoh-properties-dialog.h
@@ -41,6 +41,13 @@ typedef struct _BuohPropertiesDialogPrivate BuohPropertiesDialogPrivate;
 struct _BuohPropertiesDialog {
         GtkDialog                   parent;
         BuohPropertiesDialogPrivate *priv;
+        GtkWidget                   *title;
+        GtkWidget                   *author;
+        GtkWidget                   *uri;
+        GtkWidget                   *language;
+        GtkWidget                   *date;
+        GtkWidget                   *publication_days;
+        GtkWidget                   *thumbnail;
 };
 
 struct _BuohPropertiesDialogClass {


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