#include <stdlib.h>
#include <gtk/gtk.h>
-#include <glade/glade.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
#include <libmissioncontrol/mc-account.h>
#include <telepathy-glib/util.h>
#include "empathy-avatar-image.h"
#include "empathy-ui-utils.h"
+#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
+#include <libempathy/empathy-debug.h>
+
/* Delay before updating the widget when the id entry changed (seconds) */
#define ID_CHANGED_TIMEOUT 1
EmpathyContactWidgetFlags flags)
{
EmpathyContactWidget *information;
- GladeXML *glade;
+ GtkBuilder *gui;
gchar *filename;
information = g_slice_new0 (EmpathyContactWidget);
information->flags = flags;
- information->factory = empathy_contact_factory_new ();
+ information->factory = empathy_contact_factory_dup_singleton ();
- filename = empathy_file_lookup ("empathy-contact-widget.glade",
+ filename = empathy_file_lookup ("empathy-contact-widget.ui",
"libempathy-gtk");
- glade = empathy_glade_get_file (filename,
- "vbox_contact_widget",
- NULL,
+ gui = empathy_builder_get_file (filename,
"vbox_contact_widget", &information->vbox_contact_widget,
"vbox_contact", &information->vbox_contact,
"hbox_presence", &information->hbox_presence,
NULL);
g_free (filename);
- empathy_glade_connect (glade,
- information,
+ empathy_builder_connect (gui, information,
"vbox_contact_widget", "destroy", contact_widget_destroy_cb,
"entry_group", "changed", contact_widget_entry_group_changed_cb,
"entry_group", "activate", contact_widget_entry_group_activate_cb,
"button_group", "clicked", contact_widget_button_group_clicked_cb,
NULL);
- g_object_unref (glade);
-
g_object_set_data (G_OBJECT (information->vbox_contact_widget),
"EmpathyContactWidget",
information);
contact_widget_set_contact (information, contact);
- gtk_widget_show (information->vbox_contact_widget);
+ g_object_ref (information->vbox_contact_widget);
+ g_object_force_floating (G_OBJECT (information->vbox_contact_widget));
+ g_object_unref (gui);
return information->vbox_contact_widget;
}
}
static void
-contact_widget_contact_setup (EmpathyContactWidget *information)
+update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
+ EmpathyAvatarChooser *avatar_chooser)
{
- if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
- {
- information->widget_avatar = empathy_avatar_chooser_new ();
- g_signal_connect (information->widget_avatar, "changed",
- G_CALLBACK (contact_widget_avatar_changed_cb),
- information);
- }
- else
- {
- information->widget_avatar = empathy_avatar_image_new ();
+ McAccount *account;
- g_signal_connect (information->widget_avatar, "popup-menu",
- G_CALLBACK (widget_avatar_popup_menu_cb), information);
- g_signal_connect (information->widget_avatar, "button-press-event",
- G_CALLBACK (widget_avatar_button_press_event_cb), information);
- }
-
- gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
- information->widget_avatar,
- FALSE, FALSE,
- 6);
- gtk_widget_show (information->widget_avatar);
+ account = empathy_account_chooser_get_account (account_chooser);
+ g_object_set (avatar_chooser, "account", account, NULL);
+}
+static void
+contact_widget_contact_setup (EmpathyContactWidget *information)
+{
/* Setup account label/chooser */
if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
{
else
{
information->widget_account = gtk_label_new (NULL);
- if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
+ if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
}
gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
1, 2, 0, 1);
gtk_widget_show (information->widget_account);
+ /* Set up avatar chooser/display */
+ if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
+ {
+ information->widget_avatar = empathy_avatar_chooser_new ();
+ g_signal_connect (information->widget_avatar, "changed",
+ G_CALLBACK (contact_widget_avatar_changed_cb),
+ information);
+ if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
+ {
+ g_signal_connect (information->widget_account, "changed",
+ G_CALLBACK (update_avatar_chooser_account_cb),
+ information->widget_avatar);
+ update_avatar_chooser_account_cb (
+ EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
+ EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
+ }
+ }
+ else
+ {
+ information->widget_avatar = empathy_avatar_image_new ();
+
+ g_signal_connect (information->widget_avatar, "popup-menu",
+ G_CALLBACK (widget_avatar_popup_menu_cb), information);
+ g_signal_connect (information->widget_avatar, "button-press-event",
+ G_CALLBACK (widget_avatar_button_press_event_cb), information);
+ }
+
+ gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
+ information->widget_avatar,
+ FALSE, FALSE,
+ 6);
+ gtk_widget_show (information->widget_avatar);
+
/* Setup id label/entry */
if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
{
else
{
information->widget_id = gtk_label_new (NULL);
- if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
+ if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
}
gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
else
{
information->widget_alias = gtk_label_new (NULL);
- if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
+ if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
}
gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
}
}
+static void
+contact_widget_change_contact_cb (EmpathyContact *contact,
+ const GError *error,
+ gpointer information,
+ GObject *weak_object)
+{
+ if (error)
+ DEBUG ("Error: %s", error->message);
+ else
+ contact_widget_set_contact (information, contact);
+ g_object_unref (contact);
+}
+
static void
contact_widget_change_contact (EmpathyContactWidget *information)
{
const gchar *id;
id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
- if (G_STR_EMPTY (id))
+ if (EMP_STR_EMPTY (id))
return;
contact = empathy_contact_factory_get_from_id (information->factory,
if (contact)
{
- empathy_contact_run_until_ready (contact,
+ /* Give the contact ref to the callback */
+ empathy_contact_call_when_ready (contact,
EMPATHY_CONTACT_READY_HANDLE |
EMPATHY_CONTACT_READY_ID,
- NULL);
- contact_widget_set_contact (information, contact);
- g_object_unref (contact);
+ contact_widget_change_contact_cb,
+ information, NULL,
+ G_OBJECT (information->vbox_contact_widget));
}
}
{
if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
{
- information->manager = empathy_contact_manager_new ();
+ information->manager = empathy_contact_manager_dup_singleton ();
contact_widget_model_setup (information);
}
}
GtkTreeModel *model;
FindName data;
- if (G_STR_EMPTY (name))
+ if (EMP_STR_EMPTY (name))
return FALSE;
data.information = information;
gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
else
gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
- !G_STR_EMPTY (group));
+ !EMP_STR_EMPTY (group));
}
static void