[gnome-mud] Make use of gtk_builder_new_from_resource



commit c4c3a5ab1996bc4f91c69055f68b4a8908534b40
Author: Mart Raudsepp <leio gentoo org>
Date:   Sat Jan 5 01:40:39 2019 +0200

    Make use of gtk_builder_new_from_resource
    
    Allows to get rid of 143 lines of boilerplate caused by not having
    gtk3 before.
    Later on we should start using gtk_widget_class_set_template_from_resource
    and co instead.

 meson.build              |  2 +-
 src/debug-logger.c       | 23 ++--------------
 src/mud-connections.c    | 69 +++++-------------------------------------------
 src/mud-log.c            | 19 ++-----------
 src/mud-subwindow.c      | 12 +--------
 src/mud-window-prefs.c   | 12 +--------
 src/mud-window-profile.c | 19 ++-----------
 src/mud-window.c         | 23 ++--------------
 8 files changed, 18 insertions(+), 161 deletions(-)
---
diff --git a/meson.build b/meson.build
index 1a295ad..5b4f130 100644
--- a/meson.build
+++ b/meson.build
@@ -25,7 +25,7 @@ localedir = join_paths(datadir, 'locale')
 schemadir = join_paths(datadir, 'glib-2.0', 'schemas')
 
 libgio_dep = dependency('gio-2.0', version: '>= 2.48')
-libgtk_dep = dependency('gtk+-3.0', version: '>= 3.4')
+libgtk_dep = dependency('gtk+-3.0', version: '>= 3.10')
 libvte_dep = dependency('vte-2.91', version: '>= 0.37')
 libpcre_dep = dependency('libpcre', version: '>= 6.0.0')
 libgst_dep = dependency('gstreamer-1.0', version: '>= 1.0', required: get_option('gstreamer'))
diff --git a/src/debug-logger.c b/src/debug-logger.c
index 99f9b47..6637599 100644
--- a/src/debug-logger.c
+++ b/src/debug-logger.c
@@ -26,7 +26,6 @@
 #include <glib/gprintf.h>
 
 #include "debug-logger.h"
-#include "resources.h"
 
 struct _DebugLoggerPrivate
 {
@@ -597,10 +596,6 @@ static void
 debug_logger_save_clicked(GtkWidget *widget, DebugLogger *logger)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkWidget *dialog;
     gint result;
     GList *selected_rows = NULL, *entry;
@@ -615,12 +610,7 @@ debug_logger_save_clicked(GtkWidget *widget, DebugLogger *logger)
     if (gtk_notebook_get_n_pages(logger->priv->notebook) == 0)
         return;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     dialog = GTK_WIDGET(gtk_builder_get_object(builder, "save_dialog"));
 
@@ -1043,10 +1033,6 @@ void
 debug_logger_create_window(DebugLogger *self)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GSList *entry;
 
     g_return_if_fail(IS_DEBUG_LOGGER(self));
@@ -1056,12 +1042,7 @@ debug_logger_create_window(DebugLogger *self)
 
     self->ui_enabled = TRUE;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     self->priv->window = GTK_WINDOW(gtk_builder_get_object(builder, "log_window"));
     self->priv->vbox = GTK_BOX(gtk_builder_get_object(builder, "vbox"));
diff --git a/src/mud-connections.c b/src/mud-connections.c
index 770e960..0bf8ecf 100644
--- a/src/mud-connections.c
+++ b/src/mud-connections.c
@@ -1,7 +1,7 @@
 /* mud-connections.c
  *
  * Copyright 2008-2009 Les Harris <lharris gnome org>
- * Copyright 2018 Mart Raudsepp <leio gentoo org>
+ * Copyright 2018-2019 Mart Raudsepp <leio gentoo org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,7 +28,6 @@
 
 #include "gnome-mud.h"
 #include "mud-connections.h"
-#include "resources.h"
 #include "mud-mud.h"
 #include "mud-character.h"
 #include "mud-window.h"
@@ -491,22 +490,13 @@ mud_connections_popup (MudConnections *self,
                        GdkEventButton *event)
 {
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   GtkWidget *popup;
   GList *selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (self->iconview));
 
   if (g_list_length(selected) == 0)
     return;
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   popup = GTK_WIDGET (gtk_builder_get_object (builder, "popupmenu"));
 
@@ -539,22 +529,13 @@ static gboolean
 mud_connections_delete_confirm (gchar *name)
 {
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   GtkWidget *dialog;
   GtkWidget *label;
   gint result;
   gchar *message;
   gchar *title;
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   dialog = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewdelconfirm"));
   label = GTK_WIDGET (gtk_builder_get_object (builder, "message"));
@@ -580,20 +561,11 @@ mud_connections_show_properties (MudConnections *self,
                                  MudCharacter   *character)
 {
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   GtkTextBuffer *buffer;
   MudMud *mud;
   const gchar *icon_name, *connect_string;
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   self->properties_window = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewproperties"));
   self->name_entry     = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
@@ -770,19 +742,10 @@ static gint
 mud_connections_property_confirm (void)
 {
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   GtkWidget *dialog;
   gint result;
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   dialog = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewconfirm"));
   g_object_unref (builder);
@@ -924,18 +887,9 @@ static void
 mud_connections_show_icon_dialog (MudConnections *self)
 {
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   gint result;
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   self->icon_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "iconselect"));
   self->icon_dialog_view = GTK_WIDGET (gtk_builder_get_object (builder, "view"));
@@ -1068,10 +1022,6 @@ mud_connections_constructed (GObject *object)
   MudConnections *self = (MudConnections *)object;
 
   GtkBuilder *builder;
-  GBytes *res_bytes;
-  gconstpointer res_data;
-  gsize res_size;
-  GError *error = NULL;
   GtkWidget *main_window;
 
   G_OBJECT_CLASS (mud_connections_parent_class)->constructed (object);
@@ -1081,12 +1031,7 @@ mud_connections_constructed (GObject *object)
                 "tray",   &self->tray,
                 NULL);
 
-  builder = gtk_builder_new ();
-  res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/muds.ui", 0, NULL);
-  res_data = g_bytes_get_data (res_bytes, &res_size);
-  if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-    g_error ("Failed to load resources: %s", error->message);
-  g_bytes_unref (res_bytes);
+  builder = gtk_builder_new_from_resource ("/org/gnome/MUD/muds.ui");
 
   self->window = GTK_WIDGET (gtk_builder_get_object (builder, "mudviewwindow"));
   self->iconview = GTK_WIDGET (gtk_builder_get_object (builder, "iconview"));
diff --git a/src/mud-log.c b/src/mud-log.c
index 94df827..26318a1 100644
--- a/src/mud-log.c
+++ b/src/mud-log.c
@@ -29,7 +29,6 @@
 
 #include "gnome-mud.h"
 #include "mud-log.h"
-#include "resources.h"
 #include "mud-window.h"
 #include "mud-connection-view.h"
 #include "mud-line-buffer.h"
@@ -380,19 +379,10 @@ mud_log_select_clicked_cb(GtkWidget *widget,
                           MudLog *self)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkWidget *dialog;
     gint result;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     dialog = GTK_WIDGET(gtk_builder_get_object(builder, "save_dialog"));
     g_object_unref(builder);
@@ -627,12 +617,7 @@ mud_log_open(MudLog *self)
 
     g_return_if_fail(MUD_IS_LOG(self));
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     self->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "log_config_window"));
     self->priv->check_log_next = GTK_WIDGET(gtk_builder_get_object(builder, "inc_next_check_btn"));
diff --git a/src/mud-subwindow.c b/src/mud-subwindow.c
index 3f98a12..552ab14 100644
--- a/src/mud-subwindow.c
+++ b/src/mud-subwindow.c
@@ -27,7 +27,6 @@
 #include "mud-connection-view.h"
 #include "mud-window.h"
 #include "mud-subwindow.h"
-#include "resources.h"
 
 struct _MudSubwindowPrivate
 {
@@ -342,10 +341,6 @@ mud_subwindow_constructor (GType gtype,
     MudSubwindowClass *klass;
     GObjectClass *parent_class;
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
 
     /* Chain up to parent constructor */
     klass = MUD_SUBWINDOW_CLASS( g_type_class_peek(MUD_TYPE_SUBWINDOW) );
@@ -384,12 +379,7 @@ mud_subwindow_constructor (GType gtype,
     self->priv->initial_height = self->priv->height;
 
     /* start glading */
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     self->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "subwindow"));
 
diff --git a/src/mud-window-prefs.c b/src/mud-window-prefs.c
index b33fd3f..2edf313 100644
--- a/src/mud-window-prefs.c
+++ b/src/mud-window-prefs.c
@@ -27,7 +27,6 @@
 #include "mud-profile-manager.h"
 #include "mud-window.h"
 #include "mud-window-prefs.h"
-#include "resources.h"
 
 struct _MudWindowPrefsPrivate
 {
@@ -382,19 +381,10 @@ static void
 mud_window_prefs_construct_window(MudWindowPrefs *self)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkWidget *main_window;
     gint i;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/prefs.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/prefs.ui");
 
     self->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "preferences_window"));
 
diff --git a/src/mud-window-profile.c b/src/mud-window-profile.c
index 9992dd0..2779afd 100644
--- a/src/mud-window-profile.c
+++ b/src/mud-window-profile.c
@@ -26,7 +26,6 @@
 #include "mud-connection-view.h"
 #include "mud-window.h"
 #include "mud-window-profile.h"
-#include "resources.h"
 #include "utils.h"
 #include "mud-profile-manager.h"
 #include "mud-window-prefs.h"
@@ -144,10 +143,6 @@ mud_profile_window_constructor (GType gtype,
     GObjectClass *parent_class;
 
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkWindow *main_window;
     GtkCellRenderer *renderer;
 
@@ -164,12 +159,7 @@ mud_profile_window_constructor (GType gtype,
         g_error("Tried to instantiate MudProfileWindow without passing parent GtkWindow\n");
     }
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/prefs.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/prefs.ui");
 
     profwin->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "profiles_window"));
 
@@ -303,12 +293,7 @@ mud_profile_window_add_cb(GtkWidget *widget, MudProfileWindow *profwin)
     gint result;
     MudProfile *prof;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/prefs.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/prefs.ui");
 
     window = GTK_WIDGET(gtk_builder_get_object(builder, "newprofile_dialog"));
 
diff --git a/src/mud-window.c b/src/mud-window.c
index 9f0ee06..2650d8e 100644
--- a/src/mud-window.c
+++ b/src/mud-window.c
@@ -29,7 +29,6 @@
 #include <stdlib.h>
 #include <glib/gprintf.h>
 
-#include "resources.h"
 #include "gnome-mud.h"
 #include "gnome-mud-icons.h"
 #include "mud-connection-view.h"
@@ -225,10 +224,6 @@ static void
 mud_window_init (MudWindow *self)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkTextIter iter;
     gint y;
 
@@ -236,12 +231,7 @@ mud_window_init (MudWindow *self)
     self->priv = MUD_WINDOW_GET_PRIVATE(self);
 
     /* start glading */
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     /* set public properties */
     self->window = GTK_WINDOW(gtk_builder_get_object(builder, "main_window"));
@@ -895,19 +885,10 @@ static void
 mud_window_buffer_cb(GtkWidget *widget, MudWindow *self)
 {
     GtkBuilder *builder;
-    GBytes *res_bytes;
-    gconstpointer res_data;
-    gsize res_size;
-    GError *error = NULL;
     GtkWidget *dialog;
     gint result;
 
-    builder = gtk_builder_new ();
-    res_bytes = g_resource_lookup_data (gnome_mud_get_resource (), "/org/gnome/MUD/main.ui", 0, NULL);
-    res_data = g_bytes_get_data (res_bytes, &res_size);
-    if (gtk_builder_add_from_string (builder, res_data, res_size, &error) == 0)
-        g_error ("Failed to load resources: %s", error->message);
-    g_bytes_unref (res_bytes);
+    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     dialog = GTK_WIDGET(gtk_builder_get_object(builder, "save_dialog"));
 


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