aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorEmanuele Aina <emanuele.aina@collabora.com>2013-03-22 20:36:30 +0800
committerEmanuele Aina <emanuele.aina@collabora.com>2013-03-31 23:33:53 +0800
commit788d278853ee3ac061f84b611a3290d5adc31577 (patch)
tree09f49ac54437ec53dc2025cf92445d37e0194790 /libempathy-gtk
parenta53e07b1c85f2ea24a0ee3adb43a6e400c1c4ccc (diff)
downloadgsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar.gz
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar.bz2
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar.lz
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar.xz
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.tar.zst
gsoc2013-empathy-788d278853ee3ac061f84b611a3290d5adc31577.zip
ui-utils: Add empathy_builder_get_resource()
Add the empathy_builder_get_file() companion to load UI elements from embedded resources. https://bugzilla.gnome.org/show_bug.cgi?id=696978
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c45
-rw-r--r--libempathy-gtk/empathy-ui-utils.h3
2 files changed, 43 insertions, 5 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 9f4300840..32f1fe389 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -75,8 +75,15 @@ empathy_gtk_init (void)
initialized = TRUE;
}
+enum _BuilderSource
+{
+ BUILDER_SOURCE_FILE,
+ BUILDER_SOURCE_RESOURCE
+};
+
static GtkBuilder *
-builder_get_file_valist (const gchar *filename,
+builder_get_valist (const gchar *sourcename,
+ enum _BuilderSource source,
const gchar *first_object,
va_list args)
{
@@ -84,16 +91,29 @@ builder_get_file_valist (const gchar *filename,
const gchar *name;
GObject **object_ptr;
GError *error = NULL;
+ gboolean success;
- DEBUG ("Loading file %s", filename);
+ DEBUG ("Loading %s '%s'", source == BUILDER_SOURCE_FILE ? "file" : "resource", sourcename);
gui = gtk_builder_new ();
gtk_builder_set_translation_domain (gui, GETTEXT_PACKAGE);
- if (!gtk_builder_add_from_file (gui, filename, &error))
+ switch (source)
+ {
+ case BUILDER_SOURCE_FILE:
+ success = gtk_builder_add_from_file (gui, sourcename, &error);
+ break;
+ case BUILDER_SOURCE_RESOURCE:
+ success = gtk_builder_add_from_resource (gui, sourcename, &error);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (!success)
{
g_critical ("GtkBuilder Error (%s): %s",
- filename, error->message);
+ sourcename, error->message);
g_clear_error (&error);
g_object_unref (gui);
@@ -134,7 +154,22 @@ empathy_builder_get_file (const gchar *filename,
va_list args;
va_start (args, first_object);
- gui = builder_get_file_valist (filename, first_object, args);
+ gui = builder_get_valist (filename, BUILDER_SOURCE_FILE, first_object, args);
+ va_end (args);
+
+ return gui;
+}
+
+GtkBuilder *
+empathy_builder_get_resource (const gchar *resourcename,
+ const gchar *first_object,
+ ...)
+{
+ GtkBuilder *gui;
+ va_list args;
+
+ va_start (args, first_object);
+ gui = builder_get_valist (resourcename, BUILDER_SOURCE_RESOURCE, first_object, args);
va_end (args);
return gui;
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 73232cf52..e5c3aa1fa 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -57,6 +57,9 @@ void empathy_gtk_init (void);
GtkBuilder * empathy_builder_get_file (const gchar *filename,
const gchar *first_object,
...);
+GtkBuilder * empathy_builder_get_resource (const gchar *resourcename,
+ const gchar *first_object,
+ ...);
void empathy_builder_connect (GtkBuilder *gui,
gpointer user_data,
const gchar *first_object,