diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2009-04-16 20:27:48 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-04-16 20:27:48 +0800 |
commit | 11e07f923c7bc1655cfd1609024304fa1c8fe2c3 (patch) | |
tree | 593087a8fcbefc6d5d1eec154853adaf2ac932e7 | |
parent | 36ccb3786fa69009a63f14a498005b8d95449c72 (diff) | |
download | gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar.gz gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar.bz2 gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar.lz gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar.xz gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.tar.zst gsoc2013-empathy-11e07f923c7bc1655cfd1609024304fa1c8fe2c3.zip |
Port glade helpers to GtkBuilber
From: Xavier Claessens <xclaesse@gmail.com>
svn path=/trunk/; revision=2841
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.c | 165 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.h | 21 |
2 files changed, 53 insertions, 133 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 9e8928e8e..a1f4a6bfc 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -37,7 +37,6 @@ #include <glib/gi18n-lib.h> #include <gtk/gtk.h> #include <gio/gio.h> -#include <glade/glade.h> #include <canberra-gtk.h> #include <libmissioncontrol/mc-profile.h> @@ -89,39 +88,33 @@ empathy_uri_regex_dup_singleton (void) return g_regex_ref (uri_regex); } -struct SizeData { - gint width; - gint height; - gboolean preserve_aspect_ratio; -}; - -static GladeXML * -get_glade_file (const gchar *filename, - const gchar *root, - const gchar *domain, - const gchar *first_required_widget, - va_list args) +static GtkBuilder * +builder_get_file_valist (const gchar *filename, + const gchar *first_object, + va_list args) { - GladeXML *gui; - const char *name; - GtkWidget **widget_ptr; - - DEBUG ("Loading glade file %s", filename); + GtkBuilder *gui; + const gchar *name; + GObject **object_ptr; + GError *error = NULL; - gui = glade_xml_new (filename, root, domain); + DEBUG ("Loading file %s", filename); - if (!gui) { - g_warning ("Couldn't find necessary glade file '%s'", filename); + gui = gtk_builder_new (); + if (!gtk_builder_add_from_file (gui, filename, &error)) { + DEBUG ("Error: %s", error->message); + g_clear_error (&error); + g_object_unref (gui); + return NULL; } - for (name = first_required_widget; name; name = va_arg (args, char *)) { - widget_ptr = va_arg (args, void *); + for (name = first_object; name; name = va_arg (args, const gchar *)) { + object_ptr = va_arg (args, GObject**); - *widget_ptr = glade_xml_get_widget (gui, name); + *object_ptr = gtk_builder_get_object (gui, name); - if (!*widget_ptr) { - g_warning ("Glade file '%s' is missing widget '%s'.", - filename, name); + if (!*object_ptr) { + g_warning ("File is missing object '%s'.", name); continue; } } @@ -129,115 +122,47 @@ get_glade_file (const gchar *filename, return gui; } -void -empathy_glade_get_file_simple (const gchar *filename, - const gchar *root, - const gchar *domain, - const gchar *first_required_widget, ...) -{ - va_list args; - GladeXML *gui; - - va_start (args, first_required_widget); - - gui = get_glade_file (filename, - root, - domain, - first_required_widget, - args); - - va_end (args); - - if (gui) { - g_object_unref (gui); - } -} - -GladeXML * -empathy_glade_get_file (const gchar *filename, - const gchar *root, - const gchar *domain, - const gchar *first_required_widget, ...) +GtkBuilder * +empathy_builder_get_file (const gchar *filename, + const gchar *first_object, + ...) { - va_list args; - GladeXML *gui; - - va_start (args, first_required_widget); - - gui = get_glade_file (filename, - root, - domain, - first_required_widget, - args); + GtkBuilder *gui; + va_list args; + va_start (args, first_object); + gui = builder_get_file_valist (filename, first_object, args); va_end (args); - if (!gui) { - return NULL; - } - return gui; } void -empathy_glade_connect (GladeXML *gui, - gpointer user_data, - gchar *first_widget, ...) +empathy_builder_connect (GtkBuilder *gui, + gpointer user_data, + gchar *first_object, + ...) { va_list args; const gchar *name; const gchar *signal; - GtkWidget *widget; - gpointer *callback; - - va_start (args, first_widget); - - for (name = first_widget; name; name = va_arg (args, char *)) { - signal = va_arg (args, void *); - callback = va_arg (args, void *); - - widget = glade_xml_get_widget (gui, name); - if (!widget) { - g_warning ("Glade file is missing widget '%s', aborting", - name); - continue; - } - - g_signal_connect (widget, - signal, - G_CALLBACK (callback), - user_data); - } - - va_end (args); -} - -void -empathy_glade_setup_size_group (GladeXML *gui, - GtkSizeGroupMode mode, - gchar *first_widget, ...) -{ - va_list args; - GtkWidget *widget; - GtkSizeGroup *size_group; - const gchar *name; - - va_start (args, first_widget); + GObject *object; + GCallback callback; - size_group = gtk_size_group_new (mode); + va_start (args, first_object); + for (name = first_object; name; name = va_arg (args, const gchar *)) { + signal = va_arg (args, const gchar *); + callback = va_arg (args, GCallback); - for (name = first_widget; name; name = va_arg (args, char *)) { - widget = glade_xml_get_widget (gui, name); - if (!widget) { - g_warning ("Glade file is missing widget '%s'", name); + object = gtk_builder_get_object (gui, name); + if (!object) { + g_warning ("File is missing object '%s'.", name); continue; } - gtk_size_group_add_widget (size_group, widget); + g_signal_connect (object, signal, callback, user_data); } - g_object_unref (size_group); - va_end (args); } @@ -346,6 +271,12 @@ out: return pixbuf; } +struct SizeData { + gint width; + gint height; + gboolean preserve_aspect_ratio; +}; + static void pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader, int width, diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 64c1f1a14..3f9cbff25 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -33,7 +33,6 @@ #define __EMPATHY_UI_UTILS_H__ #include <gtk/gtk.h> -#include <glade/glade.h> #include <canberra-gtk.h> @@ -66,24 +65,14 @@ void empathy_gtk_init (void); GRegex * empathy_uri_regex_dup_singleton (void); /* Glade */ -void empathy_glade_get_file_simple (const gchar *filename, - const gchar *root, - const gchar *domain, - const gchar *first_required_widget, +GtkBuilder * empathy_builder_get_file (const gchar *filename, + const gchar *first_object, ...); -GladeXML * empathy_glade_get_file (const gchar *filename, - const gchar *root, - const gchar *domain, - const gchar *first_required_widget, - ...); -void empathy_glade_connect (GladeXML *gui, +void empathy_builder_connect (GtkBuilder *gui, gpointer user_data, - gchar *first_widget, - ...); -void empathy_glade_setup_size_group (GladeXML *gui, - GtkSizeGroupMode mode, - gchar *first_widget, + gchar *first_object, ...); + /* Pixbufs */ const gchar * empathy_icon_name_from_account (McAccount *account); const gchar * empathy_icon_name_for_presence (McPresence presence); |