[buoh/builder-port: 4/5] Port properties dialog to GtkBuilder
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [buoh/builder-port: 4/5] Port properties dialog to GtkBuilder
- Date: Wed, 12 Sep 2018 11:56:17 +0000 (UTC)
commit a3beb212ff26e794909e983e836dd3046cb11c0a
Author: Jan Tojnar <jtojnar gmail com>
Date: Mon Sep 10 03:11:01 2018 +0200
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/meson.build | 14 +++
data/org.gnome.buoh.gresource.xml | 1 +
data/ui/properties-dialog.ui | 223 ++++++++++++++++++++++++++++++++++++++
default.nix | 8 +-
meson.build | 1 +
po/POTFILES.in | 1 +
src/buoh-properties-dialog.c | 160 ++++-----------------------
src/buoh-properties-dialog.h | 7 ++
8 files changed, 274 insertions(+), 141 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 36c2c14..c991e40 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,3 +1,17 @@
+ui_files = files(
+ 'ui/properties-dialog.ui',
+)
+if gtk_builder_tool.found()
+ foreach ui : ui_files
+ test(
+ 'Validating @0@'.format(ui),
+ gtk_builder_tool,
+ args: ['validate', ui],
+ workdir: meson.current_build_dir(),
+ )
+ endforeach
+endif
+
desktop = 'buoh.desktop'
i18n.merge_file(
desktop,
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..90b1a5a
--- /dev/null
+++ b/data/ui/properties-dialog.ui
@@ -0,0 +1,223 @@
+<?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="border-width">5</property>
+ <property name="title" translatable="yes">Comic Properties</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="name">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>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="fill">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <child>
+ <object class="GtkImage" id="thumbnail">
+ <property name="width-request">96</property>
+ <property name="height-request">96</property>
+ <property name="visible">1</property>
+ <property name="valign">start</property>
+ <property name="icon-name">image-missing</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">1</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">1</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">1</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">1</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">1</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">1</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">1</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">1</property>
+ <property name="selectable">1</property>
+ <property name="xalign">0</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">1</property>
+ <property name="selectable">1</property>
+ <property name="xalign">0</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">1</property>
+ <property name="selectable">1</property>
+ <property name="ellipsize">end</property>
+ <property name="width-chars">35</property>
+ <property name="xalign">0</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">1</property>
+ <property name="selectable">1</property>
+ <property name="xalign">0</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">1</property>
+ <property name="selectable">1</property>
+ <property name="xalign">0</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">1</property>
+ <property name="selectable">1</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">5</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </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/default.nix b/default.nix
index cc202b4..35b7cdf 100644
--- a/default.nix
+++ b/default.nix
@@ -40,7 +40,7 @@ stdenv.mkDerivation rec {
name = "buoh";
nativeBuildInputs = [
- meson ninja pkgconfig gettext python3 wrapGAppsHook
+ meson ninja pkgconfig gettext python3 xvfb_run wrapGAppsHook
];
buildInputs = [
@@ -57,5 +57,11 @@ stdenv.mkDerivation rec {
with builtins; filterSource
(path: _: !elem (baseNameOf path) [ ".git" "result" ]) ./.;
+ checkPhase = ''
+ export NO_AT_BRIDGE=1
+ xvfb-run -s '-screen 0 800x600x24' \
+ meson test --print-errorlogs
+ '';
+
inherit doCheck;
}
diff --git a/meson.build b/meson.build
index 69f4a43..c7a4535 100644
--- a/meson.build
+++ b/meson.build
@@ -27,6 +27,7 @@ libsoup = dependency('libsoup-2.4', version: '>= 2.4.0')
libxml2 = dependency('libxml-2.0', version: '>= 2.4.0')
desktop_file_validate = find_program('desktop-file-validate', required: false)
+gtk_builder_tool = find_program('gtk-builder-tool', required: false)
buoh_deps = [
gtk,
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]