]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-widget.c
Port EmpathyContactWidget to new API
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
index 66c03b4344e6d4fe212840409d959fd74bb72e68..6d302171af633aa4283265d13209a19d37a8e074 100644 (file)
@@ -25,8 +25,7 @@
 #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>
@@ -42,6 +41,9 @@
 #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
 
@@ -157,18 +159,16 @@ empathy_contact_widget_new (EmpathyContact *contact,
                             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,
@@ -190,16 +190,13 @@ empathy_contact_widget_new (EmpathyContact *contact,
        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);
@@ -212,7 +209,9 @@ empathy_contact_widget_new (EmpathyContact *contact,
 
   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;
 }
@@ -493,31 +492,18 @@ widget_avatar_button_press_event_cb (GtkWidget *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)
     {
@@ -530,7 +516,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
   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);
@@ -540,6 +526,39 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
            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)
     {
@@ -554,7 +573,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
   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);
@@ -578,7 +597,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
   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);
@@ -667,6 +686,19 @@ contact_widget_contact_update (EmpathyContactWidget *information)
     }
 }
 
+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)
 {
@@ -683,7 +715,7 @@ 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,
@@ -697,12 +729,13 @@ contact_widget_change_contact (EmpathyContactWidget *information)
 
   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));
     }
 }
 
@@ -808,7 +841,7 @@ contact_widget_groups_setup (EmpathyContactWidget *information)
 {
   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);
     }
 }
@@ -959,7 +992,7 @@ contact_widget_model_find_name (EmpathyContactWidget *information,
   GtkTreeModel *model;
   FindName data;
 
-  if (G_STR_EMPTY (name))
+  if (EMP_STR_EMPTY (name))
       return FALSE;
 
   data.information = information;
@@ -1071,7 +1104,7 @@ contact_widget_entry_group_changed_cb (GtkEditable *editable,
       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