diff options
author | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-05-09 22:50:15 +0800 |
---|---|---|
committer | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-08-20 18:03:05 +0800 |
commit | 1f633bf20747995395b1dcc7001e0c9502104eda (patch) | |
tree | 33eadea37c7a822d332d564ecc6a6e5e5d08db2b | |
parent | eb7ddccaf6365f4ceb45d8a2ccd006e67e5dd340 (diff) | |
download | gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar.gz gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar.bz2 gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar.lz gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar.xz gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.tar.zst gsoc2013-empathy-1f633bf20747995395b1dcc7001e0c9502104eda.zip |
builder: move empathy_builder_* from Empathy to tp-account-widgets
This commit also changes the licence of the moved code from GPL to LGPL.
See GOSSIP-RELICENSING.txt for details.
https://bugzilla.gnome.org/show_bug.cgi?id=699492
26 files changed, 265 insertions, 229 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 5bdc7ba1b..dd6208b48 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -34,6 +34,7 @@ #include <glib/gi18n-lib.h> #include <tp-account-widgets/tpaw-keyring.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-client-factory.h" #include "empathy-gsettings.h" @@ -3251,7 +3252,7 @@ chat_create_ui (EmpathyChat *chat) filename = empathy_file_lookup ("empathy-chat.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "chat_widget", &priv->widget, "hpaned", &priv->hpaned, "vbox_left", &priv->vbox_left, @@ -3264,7 +3265,7 @@ chat_create_ui (EmpathyChat *chat) "info_bar_vbox", &priv->info_bar_vbox, NULL); - empathy_builder_connect (gui, chat, + tpaw_builder_connect (gui, chat, "expander_topic", "notify::expanded", chat_topic_expander_activate_cb, "label_topic", "size-allocate", chat_topic_label_size_allocate_cb, NULL); diff --git a/libempathy-gtk/empathy-contact-blocking-dialog.c b/libempathy-gtk/empathy-contact-blocking-dialog.c index ddcbcf315..046356ae1 100644 --- a/libempathy-gtk/empathy-contact-blocking-dialog.c +++ b/libempathy-gtk/empathy-contact-blocking-dialog.c @@ -26,6 +26,7 @@ #include "empathy-contact-blocking-dialog.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-account-chooser.h" #include "empathy-ui-utils.h" @@ -614,7 +615,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "contents", &contents, "account-hbox", &account_hbox, "add-button", &self->priv->add_button, @@ -626,7 +627,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) "remove-toolbar", &remove_toolbar, NULL); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "add-button", "clicked", contact_blocking_dialog_add_contact, "add-contact-entry", "activate", contact_blocking_dialog_add_contact, "remove-button", "clicked", contact_blocking_dialog_remove_contacts, diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 80a1aafb4..be0b745f2 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -23,6 +23,7 @@ #include "empathy-contact-widget.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-avatar-image.h" #include "empathy-client-factory.h" @@ -660,7 +661,7 @@ empathy_contact_widget_new (EmpathyContact *contact) filename = empathy_file_lookup ("empathy-contact-widget.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "vbox_contact_widget", &main_vbox, "hbox_presence", &self->priv->hbox_presence, "label_alias", &self->priv->label_alias, diff --git a/libempathy-gtk/empathy-individual-widget.c b/libempathy-gtk/empathy-individual-widget.c index a267a7d79..e24aeadab 100644 --- a/libempathy-gtk/empathy-individual-widget.c +++ b/libempathy-gtk/empathy-individual-widget.c @@ -23,6 +23,7 @@ #include "empathy-individual-widget.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #ifdef HAVE_LIBCHAMPLAIN #include <champlain/champlain.h> @@ -1965,7 +1966,7 @@ empathy_individual_widget_init (EmpathyIndividualWidget *self) filename = empathy_file_lookup ("empathy-individual-widget.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "scrolled_window_individual", &priv->scrolled_window_individual, "viewport_individual", &priv->viewport_individual, "vbox_individual_widget", &priv->vbox_individual_widget, diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index a815c45fe..fa7753e28 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -27,6 +27,7 @@ #include <glib/gi18n-lib.h> #include <telepathy-glib/proxy-subclass.h> +#include <tp-account-widgets/tpaw-builder.h> #include "action-chain-internal.h" #include "empathy-account-chooser.h" @@ -629,7 +630,7 @@ empathy_log_window_init (EmpathyLogWindow *self) gtk_window_set_default_size (GTK_WINDOW (self), 800, 600); filename = empathy_file_lookup ("empathy-log-window.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "vbox1", &self->priv->vbox, "toolbutton_profile", &self->priv->button_profile, "toolbutton_chat", &self->priv->button_chat, @@ -647,7 +648,7 @@ empathy_log_window_init (EmpathyLogWindow *self) NULL); g_free (filename); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "toolbutton_profile", "clicked", toolbutton_profile_clicked, "toolbutton_chat", "clicked", toolbutton_chat_clicked, "toolbutton_call", "clicked", toolbutton_av_clicked, diff --git a/libempathy-gtk/empathy-search-bar.c b/libempathy-gtk/empathy-search-bar.c index dce1bdd1b..1ffdc1dc4 100644 --- a/libempathy-gtk/empathy-search-bar.c +++ b/libempathy-gtk/empathy-search-bar.c @@ -21,6 +21,7 @@ #include "empathy-search-bar.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-ui-utils.h" #include "empathy-utils.h" @@ -263,7 +264,7 @@ empathy_search_bar_init (EmpathySearchBar * self) self->priv = priv; filename = empathy_file_lookup ("empathy-search-bar.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "search_widget", &internal, "search_close", &priv->search_close, "search_entry", &priv->search_entry, @@ -275,7 +276,7 @@ empathy_search_bar_init (EmpathySearchBar * self) g_free (filename); /* Add the signals */ - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "search_close", "clicked", empathy_search_bar_close_cb, "search_entry", "changed", empathy_search_bar_entry_changed, "search_previous", "clicked", empathy_search_bar_previous_cb, diff --git a/libempathy-gtk/empathy-status-preset-dialog.c b/libempathy-gtk/empathy-status-preset-dialog.c index b122f287e..f487b8cc1 100644 --- a/libempathy-gtk/empathy-status-preset-dialog.c +++ b/libempathy-gtk/empathy-status-preset-dialog.c @@ -38,6 +38,7 @@ #include "empathy-status-preset-dialog.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-status-presets.h" #include "empathy-ui-utils.h" @@ -298,7 +299,7 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) filename = empathy_file_lookup ("empathy-status-preset-dialog.ui", "libempathy-gtk"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "toplevel-vbox", &toplevel_vbox, "presets-sw", &presets_sw, "presets-treeview", &priv->presets_treeview, @@ -321,7 +322,7 @@ empathy_status_preset_dialog_init (EmpathyStatusPresetDialog *self) remove_button); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "remove-button", "clicked", status_preset_dialog_preset_remove, NULL); diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index ec868a39f..cd7462081 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -75,154 +75,6 @@ empathy_gtk_init (void) initialized = TRUE; } -enum _BuilderSource -{ - BUILDER_SOURCE_FILE, - BUILDER_SOURCE_RESOURCE -}; - -static GtkBuilder * -builder_get_valist (const gchar *sourcename, - enum _BuilderSource source, - const gchar *first_object, - va_list args) -{ - GtkBuilder *gui; - const gchar *name; - GObject **object_ptr; - GError *error = NULL; - gboolean success; - - DEBUG ("Loading %s '%s'", source == BUILDER_SOURCE_FILE ? "file" : "resource", sourcename); - - gui = gtk_builder_new (); - gtk_builder_set_translation_domain (gui, GETTEXT_PACKAGE); - - 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", - sourcename, error->message); - - g_clear_error (&error); - g_object_unref (gui); - - /* we need to iterate and set all of the pointers to NULL */ - for (name = first_object; name; name = va_arg (args, const gchar *)) - { - object_ptr = va_arg (args, GObject**); - - *object_ptr = NULL; - } - - return NULL; - } - - for (name = first_object; name; name = va_arg (args, const gchar *)) - { - object_ptr = va_arg (args, GObject**); - - *object_ptr = gtk_builder_get_object (gui, name); - - if (!*object_ptr) - { - g_warning ("File is missing object '%s'.", name); - continue; - } - } - - return gui; -} - -GtkBuilder * -empathy_builder_get_file (const gchar *filename, - const gchar *first_object, - ...) -{ - GtkBuilder *gui; - va_list args; - - va_start (args, first_object); - 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; -} - -void -empathy_builder_connect (GtkBuilder *gui, - gpointer user_data, - const gchar *first_object, - ...) -{ - va_list args; - const gchar *name; - const gchar *sig; - GObject *object; - GCallback callback; - - va_start (args, first_object); - for (name = first_object; name; name = va_arg (args, const gchar *)) - { - sig = va_arg (args, const gchar *); - callback = va_arg (args, GCallback); - - object = gtk_builder_get_object (gui, name); - if (!object) - { - g_warning ("File is missing object '%s'.", name); - continue; - } - - g_signal_connect (object, sig, callback, user_data); - } - - va_end (args); -} - -GtkWidget * -empathy_builder_unref_and_keep_widget (GtkBuilder *gui, - GtkWidget *widget) -{ - /* On construction gui sinks the initial reference to widget. When gui - * is finalized it will drop its ref to widget. We take our own ref to - * prevent widget being finalised. The widget is forced to have a - * floating reference, like when it was initially unowned so that it can - * be used like any other GtkWidget. */ - - g_object_ref (widget); - g_object_force_floating (G_OBJECT (widget)); - g_object_unref (gui); - - return widget; -} - const gchar * empathy_icon_name_for_presence (TpConnectionPresenceType presence) { diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index baf250e32..13559d80b 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -54,20 +54,6 @@ typedef void (*EmpathyPixbufAvatarFromIndividualCb) ( void empathy_gtk_init (void); -/* Glade */ -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, - ...); -GtkWidget * empathy_builder_unref_and_keep_widget (GtkBuilder *gui, - GtkWidget *root); - /* Pixbufs */ const gchar * empathy_icon_name_for_presence ( TpConnectionPresenceType presence); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 42bf35d76..53f6997d8 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -29,6 +29,7 @@ #include <glib/gi18n-lib.h> #include <tp-account-widgets/tpaw-account-widget.h> +#include <tp-account-widgets/tpaw-builder.h> #include <tp-account-widgets/tpaw-utils.h> #include "empathy-accounts-common.h" @@ -2283,7 +2284,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "accounts_dialog_hbox", &top_hbox, "vbox_details", &priv->vbox_details, "alignment_settings", &priv->alignment_settings, @@ -2299,7 +2300,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) NULL); g_free (filename); - empathy_builder_connect (gui, dialog, + tpaw_builder_connect (gui, dialog, "button_add", "clicked", accounts_dialog_button_add_clicked_cb, "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb, "button_import", "clicked", accounts_dialog_button_import_clicked_cb, diff --git a/src/empathy-call-window-fullscreen.c b/src/empathy-call-window-fullscreen.c index e6dca4868..5ecc123ad 100644 --- a/src/empathy-call-window-fullscreen.c +++ b/src/empathy-call-window-fullscreen.c @@ -25,6 +25,8 @@ #include "config.h" #include "empathy-call-window-fullscreen.h" +#include <tp-account-widgets/tpaw-builder.h> + #include "empathy-ui-utils.h" #include "empathy-utils.h" @@ -185,7 +187,7 @@ empathy_call_window_fullscreen_init (EmpathyCallWindowFullscreen *self) gchar *filename; filename = empathy_file_lookup ("empathy-call-window-fullscreen.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "leave_fullscreen_window", &priv->leave_fullscreen_popup, "leave_fullscreen_button", &self->leave_fullscreen_button, NULL); diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c index 03c9efb61..ed5de4ee7 100644 --- a/src/empathy-call-window.c +++ b/src/empathy-call-window.c @@ -25,6 +25,7 @@ #include <telepathy-farstream/telepathy-farstream.h> #include <farstream/fs-element-added-notifier.h> #include <farstream/fs-utils.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-about-dialog.h" #include "empathy-audio-sink.h" @@ -1622,7 +1623,7 @@ empathy_call_window_init (EmpathyCallWindow *self) priv->timer = g_timer_new (); filename = empathy_file_lookup ("empathy-call-window.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "call_window_vbox", &top_vbox, "errors_vbox", &priv->errors_vbox, "pane", &priv->pane, @@ -1659,7 +1660,7 @@ empathy_call_window_init (EmpathyCallWindow *self) NULL); g_free (filename); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "hangup", "clicked", empathy_call_window_hangup_cb, "audiocall", "clicked", empathy_call_window_audio_call_cb, "videocall", "clicked", empathy_call_window_video_call_cb, diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index b373b9c4e..5f23b6a47 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -29,6 +29,7 @@ #include "empathy-chat-window.h" #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-about-dialog.h" #include "empathy-chat-manager.h" @@ -2411,7 +2412,7 @@ empathy_chat_window_init (EmpathyChatWindow *self) EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv); filename = empathy_file_lookup ("empathy-chat-window.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "chat_vbox", &chat_vbox, "ui_manager", &self->priv->ui_manager, "menu_conv_insert_smiley", &self->priv->menu_conv_insert_smiley, @@ -2433,7 +2434,7 @@ empathy_chat_window_init (EmpathyChatWindow *self) NULL); g_free (filename); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "menu_conv", "activate", chat_window_conv_activate_cb, "menu_conv_clear", "activate", chat_window_clear_activate_cb, "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb, diff --git a/src/empathy-chatrooms-window.c b/src/empathy-chatrooms-window.c index 553c91290..25c7814f6 100644 --- a/src/empathy-chatrooms-window.c +++ b/src/empathy-chatrooms-window.c @@ -27,6 +27,7 @@ #include "empathy-chatrooms-window.h" #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-account-chooser.h" #include "empathy-chatroom-manager.h" @@ -100,16 +101,16 @@ empathy_chatrooms_window_show (GtkWindow *parent) window = g_new0 (EmpathyChatroomsWindow, 1); filename = empathy_file_lookup ("empathy-chatrooms-window.ui", "src"); - gui = empathy_builder_get_file (filename, - "chatrooms_window", &window->window, - "hbox_account", &window->hbox_account, - "label_account", &window->label_account, - "sw_room_list", &sw, - "treeview", &window->treeview, - "toolbar_remove", &toolbar, - "button_remove", &window->button_remove, - "button_close", &window->button_close, - NULL); + gui = tpaw_builder_get_file (filename, + "chatrooms_window", &window->window, + "hbox_account", &window->hbox_account, + "label_account", &window->label_account, + "sw_room_list", &sw, + "treeview", &window->treeview, + "toolbar_remove", &toolbar, + "button_remove", &window->button_remove, + "button_close", &window->button_close, + NULL); g_free (filename); /* join the remove toolbar to the treeview */ @@ -118,7 +119,7 @@ empathy_chatrooms_window_show (GtkWindow *parent) context = gtk_widget_get_style_context (toolbar); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); - empathy_builder_connect (gui, window, + tpaw_builder_connect (gui, window, "chatrooms_window", "destroy", chatrooms_window_destroy_cb, "button_remove", "clicked", chatrooms_window_button_remove_clicked_cb, "button_close", "clicked", chatrooms_window_button_close_clicked_cb, diff --git a/src/empathy-ft-manager.c b/src/empathy-ft-manager.c index 18e05dc19..4321969d6 100644 --- a/src/empathy-ft-manager.c +++ b/src/empathy-ft-manager.c @@ -31,6 +31,7 @@ #include "empathy-ft-manager.h" #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-geometry.h" #include "empathy-ui-utils.h" @@ -970,7 +971,7 @@ ft_manager_build_ui (EmpathyFTManager *manager) EmpathyFTManagerPriv *priv = GET_PRIV (manager); filename = empathy_file_lookup ("empathy-ft-manager.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "ft_manager_dialog", &priv->window, "ft_list", &priv->treeview, "clear_button", &priv->clear_button, @@ -979,14 +980,14 @@ ft_manager_build_ui (EmpathyFTManager *manager) NULL); g_free (filename); - empathy_builder_connect (gui, manager, + tpaw_builder_connect (gui, manager, "ft_manager_dialog", "destroy", ft_manager_destroy_cb, "ft_manager_dialog", "response", ft_manager_response_cb, "ft_manager_dialog", "delete-event", ft_manager_delete_event_cb, "ft_manager_dialog", "key-press-event", ft_manager_key_press_event_cb, NULL); - empathy_builder_unref_and_keep_widget (gui, priv->window); + tpaw_builder_unref_and_keep_widget (gui, priv->window); /* Window geometry. */ empathy_geometry_bind (GTK_WINDOW (priv->window), "ft-manager"); diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 400a00629..42ffdd30b 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -26,6 +26,7 @@ #include "empathy-import-widget.h" #include <glib/gi18n-lib.h> +#include <tp-account-widgets/tpaw-builder.h> #include <tp-account-widgets/tpaw-utils.h> #include "empathy-ui-utils.h" @@ -431,14 +432,14 @@ do_constructed (GObject *obj) gchar *filename; filename = empathy_file_lookup ("empathy-import-dialog.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "widget_vbox", &priv->vbox, "treeview", &priv->treeview, "scrolledwindow", &priv->scrolledwindow, NULL); g_free (filename); - empathy_builder_unref_and_keep_widget (gui, priv->vbox); + tpaw_builder_unref_and_keep_widget (gui, priv->vbox); g_signal_connect (priv->vbox, "destroy", G_CALLBACK (import_widget_destroy_cb), self); diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c index 5edf45a5a..ad44d2122 100644 --- a/src/empathy-new-chatroom-dialog.c +++ b/src/empathy-new-chatroom-dialog.c @@ -25,6 +25,7 @@ #include "empathy-new-chatroom-dialog.h" #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-account-chooser.h" #include "empathy-gsettings.h" @@ -747,7 +748,7 @@ empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self) EMPATHY_TYPE_NEW_CHATROOM_DIALOG, EmpathyNewChatroomDialogPriv); filename = empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "vbox_new_chatroom", &vbox, "table_grid", &self->priv->table_grid, "label_account", &self->priv->label_account, @@ -763,7 +764,7 @@ empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self) NULL); g_free (filename); - empathy_builder_connect (gui, self, + tpaw_builder_connect (gui, self, "entry_server", "changed", new_chatroom_dialog_entry_changed_cb, "entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb, "entry_server", "focus-out-event", diff --git a/src/empathy-preferences.c b/src/empathy-preferences.c index b5e02b650..e37bc7475 100644 --- a/src/empathy-preferences.c +++ b/src/empathy-preferences.c @@ -27,6 +27,7 @@ #include "empathy-preferences.h" #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-client-factory.h" #include "empathy-gsettings.h" @@ -1029,7 +1030,7 @@ empathy_preferences_init (EmpathyPreferences *preferences) gtk_window_set_icon_name (GTK_WINDOW (preferences), "preferences-desktop"); filename = empathy_file_lookup ("empathy-preferences.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "notebook", &priv->notebook, "vbox_chat_theme", &priv->vbox_chat_theme, "combobox_chat_theme", &priv->combobox_chat_theme, diff --git a/src/empathy-roster-window.c b/src/empathy-roster-window.c index 1a30f7117..600d19610 100644 --- a/src/empathy-roster-window.c +++ b/src/empathy-roster-window.c @@ -26,6 +26,7 @@ #include <sys/stat.h> #include <glib/gi18n.h> +#include <tp-account-widgets/tpaw-builder.h> #include "empathy-about-dialog.h" #include "empathy-accounts-dialog.h" @@ -2245,7 +2246,7 @@ empathy_roster_window_init (EmpathyRosterWindow *self) /* Set up interface */ filename = empathy_file_lookup ("empathy-roster-window.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "main_vbox", &self->priv->main_vbox, "balance_vbox", &self->priv->balance_vbox, "errors_vbox", &self->priv->errors_vbox, @@ -2290,7 +2291,7 @@ empathy_roster_window_init (EmpathyRosterWindow *self) roster_window_setup_actions (self); filename = empathy_file_lookup ("empathy-roster-window-menubar.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "appmenu", &self->priv->menumodel, "rooms", &self->priv->rooms_section, NULL); diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index 917fab383..e000f32e1 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -22,6 +22,8 @@ #include "config.h" #include "empathy-status-icon.h" +#include <tp-account-widgets/tpaw-builder.h> + #include "empathy-event-manager.h" #include "empathy-gsettings.h" #include "empathy-new-call-dialog.h" @@ -351,7 +353,7 @@ status_icon_create_menu (EmpathyStatusIcon *icon) gchar *filename; filename = empathy_file_lookup ("empathy-status-icon.ui", "src"); - gui = empathy_builder_get_file (filename, + gui = tpaw_builder_get_file (filename, "ui_manager", &priv->ui_manager, "menu", &priv->popup_menu, "show_list", &priv->show_window_item, @@ -360,7 +362,7 @@ status_icon_create_menu (EmpathyStatusIcon *icon) NULL); g_free (filename); - empathy_builder_connect (gui, icon, + tpaw_builder_connect (gui, icon, "show_list", "toggled", status_icon_show_hide_window_cb, "new_message", "activate", status_icon_new_message_cb, "new_call", "activate", status_icon_new_call_cb, diff --git a/tp-account-widgets/tpaw-account-widget-irc.c b/tp-account-widgets/tpaw-account-widget-irc.c index a547a2309..970f3a265 100644 --- a/tp-account-widgets/tpaw-account-widget-irc.c +++ b/tp-account-widgets/tpaw-account-widget-irc.c @@ -22,6 +22,7 @@ #include "tpaw-account-widget-irc.h" #include "tpaw-account-widget-private.h" +#include "tpaw-builder.h" #include "empathy-ui-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT | EMPATHY_DEBUG_IRC @@ -142,7 +143,7 @@ tpaw_account_widget_irc_build (TpawAccountWidget *self, settings = g_slice_new0 (TpawAccountWidgetIrc); settings->self = self; - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "table_irc_settings", table_common_settings, "vbox_irc", box, "table_irc_settings", &settings->vbox_settings, @@ -172,7 +173,7 @@ tpaw_account_widget_irc_build (TpawAccountWidget *self, "entry_username", "username", NULL); - empathy_builder_connect (self->ui_details->gui, settings, + tpaw_builder_connect (self->ui_details->gui, settings, "table_irc_settings", "destroy", account_widget_irc_destroy_cb, NULL); @@ -209,7 +210,7 @@ tpaw_account_widget_irc_build_simple (TpawAccountWidget *self, settings = g_slice_new0 (TpawAccountWidgetIrc); settings->self = self; - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_irc_simple", box, "alignment_network_simple", &alignment, NULL); @@ -230,7 +231,7 @@ tpaw_account_widget_irc_build_simple (TpawAccountWidget *self, "entry_nick_simple", "account", NULL); - empathy_builder_connect (self->ui_details->gui, settings, + tpaw_builder_connect (self->ui_details->gui, settings, "vbox_irc_simple", "destroy", account_widget_irc_destroy_cb, NULL); diff --git a/tp-account-widgets/tpaw-account-widget-sip.c b/tp-account-widgets/tpaw-account-widget-sip.c index 44d5aecf3..1e48e312c 100644 --- a/tp-account-widgets/tpaw-account-widget-sip.c +++ b/tp-account-widgets/tpaw-account-widget-sip.c @@ -25,6 +25,7 @@ #include <glib/gi18n-lib.h> #include "tpaw-account-widget-private.h" +#include "tpaw-builder.h" #include "empathy-ui-utils.h" typedef struct { @@ -113,7 +114,7 @@ tpaw_account_widget_sip_build (TpawAccountWidget *self, if (is_simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_sip_simple", &vbox_settings, NULL); @@ -133,7 +134,7 @@ tpaw_account_widget_sip_build (TpawAccountWidget *self, settings = g_slice_new0 (TpawAccountWidgetSip); settings->self = self; - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", grid_common_settings, "grid_advanced_sip_settings", &grid_advanced, "vbox_sip_settings", &vbox_settings, @@ -173,7 +174,7 @@ tpaw_account_widget_sip_build (TpawAccountWidget *self, settings->checkbutton_discover_stun, settings); - empathy_builder_connect (self->ui_details->gui, settings, + tpaw_builder_connect (self->ui_details->gui, settings, "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb, "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb, diff --git a/tp-account-widgets/tpaw-account-widget.c b/tp-account-widgets/tpaw-account-widget.c index 20eb64f6e..a86a32f73 100644 --- a/tp-account-widgets/tpaw-account-widget.c +++ b/tp-account-widgets/tpaw-account-widget.c @@ -33,6 +33,7 @@ #include "tpaw-account-widget-irc.h" #include "tpaw-account-widget-private.h" #include "tpaw-account-widget-sip.h" +#include "tpaw-builder.h" #include "empathy-ui-utils.h" #include "empathy-utils.h" #include "tpaw-utils.h" @@ -1060,7 +1061,7 @@ account_widget_build_generic (TpawAccountWidget *self, { GtkWidget *expander_advanced, *box; - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_generic_settings", &box, "expander_advanced_settings", &expander_advanced, @@ -1086,7 +1087,7 @@ account_widget_build_salut (TpawAccountWidget *self, { GtkWidget *expander_advanced, *box; - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_salut_settings", &box, "expander_advanced_settings", &expander_advanced, @@ -1167,7 +1168,7 @@ account_widget_build_msn (TpawAccountWidget *self, if (self->priv->simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_msn_simple", &box, NULL); @@ -1184,7 +1185,7 @@ account_widget_build_msn (TpawAccountWidget *self, } else { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_msn_settings", &self->priv->grid_common_settings, "vbox_msn_settings", &box, NULL); @@ -1323,7 +1324,7 @@ account_widget_build_jabber (TpawAccountWidget *self, if (self->priv->simple && service == NO_SERVICE) { /* Simple widget for XMPP */ - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_jabber_simple", &box, "label_id_simple", &label_id, "label_id_create", &label_id_create, @@ -1354,7 +1355,7 @@ account_widget_build_jabber (TpawAccountWidget *self, else if (self->priv->simple && service == GTALK_SERVICE) { /* Simple widget for Google Talk */ - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_gtalk_simple", &box, NULL); @@ -1372,7 +1373,7 @@ account_widget_build_jabber (TpawAccountWidget *self, else if (self->priv->simple && service == FACEBOOK_SERVICE) { /* Simple widget for Facebook */ - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_fb_simple", &box, "entry_id_fb_simple", &entry_id, NULL); @@ -1394,7 +1395,7 @@ account_widget_build_jabber (TpawAccountWidget *self, ServiceInfo info = services_infos[service]; /* Full widget for XMPP, Google Talk and Facebook*/ - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_jabber_settings", &box, "spinbutton_port", &spinbutton_port, @@ -1474,7 +1475,7 @@ account_widget_build_icq (TpawAccountWidget *self, if (self->priv->simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_icq_simple", &box, NULL); @@ -1491,7 +1492,7 @@ account_widget_build_icq (TpawAccountWidget *self, } else { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_icq_settings", &box, "spinbutton_port", &spinbutton_port, @@ -1522,7 +1523,7 @@ account_widget_build_aim (TpawAccountWidget *self, if (self->priv->simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_aim_simple", &box, NULL); @@ -1539,7 +1540,7 @@ account_widget_build_aim (TpawAccountWidget *self, } else { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_aim_settings", &box, "spinbutton_port", &spinbutton_port, @@ -1572,7 +1573,7 @@ account_widget_build_yahoo (TpawAccountWidget *self, if (self->priv->simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_yahoo_simple", &box, NULL); @@ -1589,7 +1590,7 @@ account_widget_build_yahoo (TpawAccountWidget *self, } else { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_settings", &self->priv->grid_common_settings, "vbox_yahoo_settings", &box, NULL); @@ -1620,7 +1621,7 @@ account_widget_build_groupwise (TpawAccountWidget *self, if (self->priv->simple) { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "vbox_groupwise_simple", &box, NULL); @@ -1637,7 +1638,7 @@ account_widget_build_groupwise (TpawAccountWidget *self, } else { - self->ui_details->gui = empathy_builder_get_resource (filename, + self->ui_details->gui = tpaw_builder_get_resource (filename, "grid_common_groupwise_settings", &self->priv->grid_common_settings, "vbox_groupwise_settings", &box, NULL); diff --git a/tp-account-widgets/tpaw-builder.c b/tp-account-widgets/tpaw-builder.c index 8b7587adc..fc730981d 100644 --- a/tp-account-widgets/tpaw-builder.c +++ b/tp-account-widgets/tpaw-builder.c @@ -2,6 +2,11 @@ * Copyright (C) 2013 Collabora Ltd. * * Authors: Marco Barisione <marco.barisione@collabora.co.uk> + * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> + * Xavier Claessens <xavier.claessens@collabora.co.uk> + * Mikael Hallendal <micke@imendio.com> + * Richard Hult <richard@imendio.com> + * Martyn Russell <martyn@imendio.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,3 +25,154 @@ #include "config.h" #include "tpaw-builder.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include "empathy-debug.h" + +enum _BuilderSource +{ + BUILDER_SOURCE_FILE, + BUILDER_SOURCE_RESOURCE +}; + +static GtkBuilder * +builder_get_valist (const gchar *sourcename, + enum _BuilderSource source, + const gchar *first_object, + va_list args) +{ + GtkBuilder *gui; + const gchar *name; + GObject **object_ptr; + GError *error = NULL; + gboolean success; + + DEBUG ("Loading %s '%s'", source == BUILDER_SOURCE_FILE ? "file" : "resource", sourcename); + + gui = gtk_builder_new (); + gtk_builder_set_translation_domain (gui, GETTEXT_PACKAGE); + + 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", + sourcename, error->message); + + g_clear_error (&error); + g_object_unref (gui); + + /* we need to iterate and set all of the pointers to NULL */ + for (name = first_object; name; name = va_arg (args, const gchar *)) + { + object_ptr = va_arg (args, GObject**); + + *object_ptr = NULL; + } + + return NULL; + } + + for (name = first_object; name; name = va_arg (args, const gchar *)) + { + object_ptr = va_arg (args, GObject**); + + *object_ptr = gtk_builder_get_object (gui, name); + + if (!*object_ptr) + { + g_warning ("File is missing object '%s'.", name); + continue; + } + } + + return gui; +} + +GtkBuilder * +tpaw_builder_get_file (const gchar *filename, + const gchar *first_object, + ...) +{ + GtkBuilder *gui; + va_list args; + + va_start (args, first_object); + gui = builder_get_valist (filename, BUILDER_SOURCE_FILE, first_object, args); + va_end (args); + + return gui; +} + +GtkBuilder * +tpaw_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; +} + +void +tpaw_builder_connect (GtkBuilder *gui, + gpointer user_data, + const gchar *first_object, + ...) +{ + va_list args; + const gchar *name; + const gchar *sig; + GObject *object; + GCallback callback; + + va_start (args, first_object); + for (name = first_object; name; name = va_arg (args, const gchar *)) + { + sig = va_arg (args, const gchar *); + callback = va_arg (args, GCallback); + + object = gtk_builder_get_object (gui, name); + if (!object) + { + g_warning ("File is missing object '%s'.", name); + continue; + } + + g_signal_connect (object, sig, callback, user_data); + } + + va_end (args); +} + +GtkWidget * +tpaw_builder_unref_and_keep_widget (GtkBuilder *gui, + GtkWidget *widget) +{ + /* On construction gui sinks the initial reference to widget. When gui + * is finalized it will drop its ref to widget. We take our own ref to + * prevent widget being finalised. The widget is forced to have a + * floating reference, like when it was initially unowned so that it can + * be used like any other GtkWidget. */ + + g_object_ref (widget); + g_object_force_floating (G_OBJECT (widget)); + g_object_unref (gui); + + return widget; +} diff --git a/tp-account-widgets/tpaw-builder.h b/tp-account-widgets/tpaw-builder.h index 66a9d4483..57134ce12 100644 --- a/tp-account-widgets/tpaw-builder.h +++ b/tp-account-widgets/tpaw-builder.h @@ -2,6 +2,11 @@ * Copyright (C) 2013 Collabora Ltd. * * Authors: Marco Barisione <marco.barisione@collabora.co.uk> + * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> + * Xavier Claessens <xavier.claessens@collabora.co.uk> + * Mikael Hallendal <micke@imendio.com> + * Richard Hult <richard@imendio.com> + * Martyn Russell <martyn@imendio.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -26,6 +31,19 @@ G_BEGIN_DECLS +GtkBuilder * tpaw_builder_get_file (const gchar *filename, + const gchar *first_object, + ...); +GtkBuilder * tpaw_builder_get_resource (const gchar *resourcename, + const gchar *first_object, + ...); +void tpaw_builder_connect (GtkBuilder *gui, + gpointer user_data, + const gchar *first_object, + ...); +GtkWidget * tpaw_builder_unref_and_keep_widget (GtkBuilder *gui, + GtkWidget *root); + G_END_DECLS #endif /* __TPAW_BUILDER_H__ */ diff --git a/tp-account-widgets/tpaw-irc-network-dialog.c b/tp-account-widgets/tpaw-irc-network-dialog.c index 0f6b7ce83..77cc86589 100644 --- a/tp-account-widgets/tpaw-irc-network-dialog.c +++ b/tp-account-widgets/tpaw-irc-network-dialog.c @@ -24,6 +24,7 @@ #include <glib/gi18n-lib.h> #include "empathy-ui-utils.h" +#include "tpaw-builder.h" #include "totem-subtitle-encoding.h" typedef struct { @@ -468,7 +469,7 @@ tpaw_irc_network_dialog_show (TpawIrcNetwork *network, dialog->network = network; g_object_ref (dialog->network); - gui = empathy_builder_get_resource (ACCOUNT_WIDGETS_RESOURCES_PREFIX "/tpaw-account-widget-irc.ui", + gui = tpaw_builder_get_resource (ACCOUNT_WIDGETS_RESOURCES_PREFIX "/tpaw-account-widget-irc.ui", "irc_network_dialog", &dialog->dialog, "button_close", &dialog->button_close, "entry_network", &dialog->entry_network, @@ -548,7 +549,7 @@ tpaw_irc_network_dialog_show (TpawIrcNetwork *network, irc_network_dialog_setup (dialog); - empathy_builder_connect (gui, dialog, + tpaw_builder_connect (gui, dialog, "irc_network_dialog", "destroy", irc_network_dialog_destroy_cb, "button_close", "clicked", irc_network_dialog_close_clicked_cb, "entry_network", "focus-out-event", irc_network_dialog_network_focus_cb, |