[buoh/cleanups: 2/4] buoh-view: Port to GtkBuilder
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [buoh/cleanups: 2/4] buoh-view: Port to GtkBuilder
- Date: Wed, 23 Jan 2019 10:48:24 +0000 (UTC)
commit 7c791ed272308d5cde76e2cadfc8420a7c8f31fa
Author: Jan Tojnar <jtojnar gmail com>
Date: Wed Jan 23 06:33:02 2019 +0100
buoh-view: Port to GtkBuilder
data/meson.build | 1 +
data/org.gnome.buoh.gresource.xml | 1 +
data/ui/view.ui | 73 +++++++++++++++++++++++++++++++++++++++
src/buoh-view-comic.c | 17 +++++----
src/buoh-view-comic.h | 4 ++-
src/buoh-view.c | 58 +++++++------------------------
src/buoh-view.h | 2 +-
7 files changed, 102 insertions(+), 54 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index bebe700..87c8bf4 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -3,6 +3,7 @@ ui_files = files(
'ui/menus.ui',
'ui/comic-list.ui',
'ui/properties-dialog.ui',
+ 'ui/view.ui',
'ui/view-comic.ui',
'ui/view-message.ui',
'ui/window.ui',
diff --git a/data/org.gnome.buoh.gresource.xml b/data/org.gnome.buoh.gresource.xml
index b8cb6b8..8b192d4 100644
--- a/data/org.gnome.buoh.gresource.xml
+++ b/data/org.gnome.buoh.gresource.xml
@@ -5,6 +5,7 @@
<file alias="gtk/menus.ui">ui/menus.ui</file>
<file>ui/comic-list.ui</file>
<file>ui/properties-dialog.ui</file>
+ <file>ui/view.ui</file>
<file>ui/view-comic.ui</file>
<file>ui/view-message.ui</file>
<file>ui/window.ui</file>
diff --git a/data/ui/view.ui b/data/ui/view.ui
new file mode 100644
index 0000000..3d3d196
--- /dev/null
+++ b/data/ui/view.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <template class="BuohView" parent="GtkNotebook">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <property name="show-tabs">0</property>
+ <signal name="notify::status" handler="buoh_view_status_changed_cb" swapped="no"/>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <property name="shadow-type">in</property>
+ <child>
+ <object class="BuohViewComic" id="comic">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="tab-fill">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <child>
+ <object class="BuohViewMessage" id="message">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="tab-fill">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ <property name="tab-fill">0</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/src/buoh-view-comic.c b/src/buoh-view-comic.c
index df99f27..2b72621 100644
--- a/src/buoh-view-comic.c
+++ b/src/buoh-view-comic.c
@@ -417,20 +417,23 @@ buoh_view_comic_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
}
GtkWidget *
-buoh_view_comic_new (BuohView *view)
+buoh_view_comic_new (void)
{
GtkWidget *c_view;
- g_return_val_if_fail (BUOH_IS_VIEW (view), NULL);
-
c_view = GTK_WIDGET (g_object_new (BUOH_TYPE_VIEW_COMIC, NULL));
- BUOH_VIEW_COMIC (c_view)->view = view;
- g_signal_connect (G_OBJECT (BUOH_VIEW_COMIC (c_view)->view),
+
+ return c_view;
+}
+
+void
+buoh_view_comic_setup (BuohViewComic *c_view, BuohView *view)
+{
+ c_view->view = view;
+ g_signal_connect (G_OBJECT (c_view->view),
"notify::status",
G_CALLBACK (bouh_view_comic_view_status_changed),
(gpointer) c_view);
-
- return c_view;
}
static void
diff --git a/src/buoh-view-comic.h b/src/buoh-view-comic.h
index 54cbc1c..9221e55 100644
--- a/src/buoh-view-comic.h
+++ b/src/buoh-view-comic.h
@@ -29,7 +29,9 @@ G_BEGIN_DECLS
#define BUOH_TYPE_VIEW_COMIC buoh_view_comic_get_type ()
G_DECLARE_FINAL_TYPE (BuohViewComic, buoh_view_comic, BUOH, VIEW_COMIC, GtkViewport)
-GtkWidget *buoh_view_comic_new (BuohView *view);
+GtkWidget *buoh_view_comic_new (void);
+void buoh_view_comic_setup (BuohViewComic *c_view,
+ BuohView *view);
gboolean buoh_view_comic_is_min_zoom (BuohViewComic *c_view);
gboolean buoh_view_comic_is_max_zoom (BuohViewComic *c_view);
diff --git a/src/buoh-view.c b/src/buoh-view.c
index bf51da7..4ddb3bf 100644
--- a/src/buoh-view.c
+++ b/src/buoh-view.c
@@ -79,35 +79,16 @@ G_DEFINE_TYPE (BuohView, buoh_view, GTK_TYPE_NOTEBOOK)
static void
buoh_view_init (BuohView *buoh_view)
{
- GtkWidget *label;
- GtkWidget *swindow;
-
- gtk_widget_set_can_focus (GTK_WIDGET (buoh_view), TRUE);
-
buoh_view->status = STATE_MESSAGE_WELCOME;
- /* Image view */
- swindow = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- buoh_view->comic = buoh_view_comic_new (buoh_view);
- gtk_container_add (GTK_CONTAINER (swindow),
- buoh_view->comic);
- gtk_widget_show (buoh_view->comic);
+ g_type_ensure (BUOH_TYPE_VIEW_COMIC);
+ g_type_ensure (BUOH_TYPE_VIEW_MESSAGE);
+ gtk_widget_init_template (GTK_WIDGET (buoh_view));
- gtk_notebook_insert_page (GTK_NOTEBOOK (buoh_view), swindow,
- NULL, VIEW_PAGE_IMAGE);
- gtk_widget_show (swindow);
+ /* Comic view */
+ buoh_view_comic_setup (BUOH_VIEW_COMIC (buoh_view->comic), buoh_view);
/* Message view */
- swindow = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
- GTK_POLICY_NEVER,
- GTK_POLICY_NEVER);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
- GTK_SHADOW_NONE);
- buoh_view->message = buoh_view_message_new ();
buoh_view_message_set_title (BUOH_VIEW_MESSAGE (buoh_view->message),
_("Buoh online comic strips reader"));
buoh_view_message_set_text (BUOH_VIEW_MESSAGE (buoh_view->message),
@@ -117,33 +98,14 @@ buoh_view_init (BuohView *buoh_view)
"Just select a comic from the list, and it will be displayed "
"on the right side. Thanks for using Buoh."));
buoh_view_message_set_icon (BUOH_VIEW_MESSAGE (buoh_view->message), "buoh");
- gtk_container_add (GTK_CONTAINER (swindow),
- buoh_view->message);
- gtk_widget_show (buoh_view->message);
-
- gtk_notebook_insert_page (GTK_NOTEBOOK (buoh_view), swindow,
- NULL, VIEW_PAGE_MESSAGE);
- gtk_widget_show (swindow);
-
- /* Empty view */
- label = gtk_label_new (NULL);
- gtk_notebook_insert_page (GTK_NOTEBOOK (buoh_view), label,
- NULL, VIEW_PAGE_EMPTY);
- gtk_widget_show (label);
-
gtk_notebook_set_current_page (GTK_NOTEBOOK (buoh_view), VIEW_PAGE_MESSAGE);
/* Callbacks */
- g_signal_connect (G_OBJECT (buoh_view), "notify::status",
- G_CALLBACK (buoh_view_status_changed_cb),
- NULL);
g_signal_connect (G_OBJECT (buoh_view->comic),
"notify::scale",
G_CALLBACK (buoh_view_scale_changed_cb),
(gpointer) buoh_view);
-
- gtk_widget_show (GTK_WIDGET (buoh_view));
}
static void
@@ -179,6 +141,13 @@ buoh_view_class_init (BuohViewClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/buoh/ui/view.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, BuohView, message);
+ gtk_widget_class_bind_template_child (widget_class, BuohView, comic);
+
+ gtk_widget_class_bind_template_callback (widget_class, buoh_view_status_changed_cb);
}
static void
@@ -250,7 +219,6 @@ buoh_view_new (void)
GtkWidget *buoh_view;
buoh_view = GTK_WIDGET (g_object_new (BUOH_TYPE_VIEW,
- "show-tabs", FALSE,
NULL));
return buoh_view;
}
@@ -376,7 +344,7 @@ buoh_view_get_status (BuohView *view)
}
void
-buoh_view_set_comic (BuohView *view, const BuohComic *comic)
+buoh_view_set_comic (BuohView *view, BuohComic *comic)
{
g_return_if_fail (BUOH_IS_VIEW (view));
g_return_if_fail (BUOH_IS_COMIC (comic));
diff --git a/src/buoh-view.h b/src/buoh-view.h
index 14f3079..224299f 100644
--- a/src/buoh-view.h
+++ b/src/buoh-view.h
@@ -59,7 +59,7 @@ BuohViewStatus buoh_view_get_status (BuohView *view);
/* Comic */
void buoh_view_set_comic (BuohView *view,
- const BuohComic *comic);
+ BuohComic *comic);
BuohComic *buoh_view_get_comic (BuohView *view);
/* Message */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]