empathy r1677 - trunk/libempathy-gtk



Author: xclaesse
Date: Tue Nov 11 15:26:09 2008
New Revision: 1677
URL: http://svn.gnome.org/viewvc/empathy?rev=1677&view=rev

Log:
Make avatar chooser (in)sensitive when the TpContactFactory becomes (not) ready

Modified:
   trunk/libempathy-gtk/empathy-avatar-chooser.c

Modified: trunk/libempathy-gtk/empathy-avatar-chooser.c
==============================================================================
--- trunk/libempathy-gtk/empathy-avatar-chooser.c	(original)
+++ trunk/libempathy-gtk/empathy-avatar-chooser.c	Tue Nov 11 15:26:09 2008
@@ -43,8 +43,11 @@
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAvatarChooser)
 typedef struct {
-	EmpathyContactFactory *contact_factory;
-	McAccount             *account;
+	EmpathyContactFactory   *contact_factory;
+	McAccount               *account;
+	EmpathyTpContactFactory *tp_contact_factory;
+
+	gulong ready_handler_id;
 
 	gchar *image_data;
 	gsize  image_data_size;
@@ -52,6 +55,8 @@
 } EmpathyAvatarChooserPriv;
 
 static void       avatar_chooser_finalize              (GObject              *object);
+static void       avatar_chooser_set_account           (EmpathyAvatarChooser *self,
+							McAccount            *account);
 static void       avatar_chooser_set_image_from_data   (EmpathyAvatarChooser *chooser,
 							gchar                *data,
 							gsize                 size);
@@ -150,12 +155,7 @@
 
 		break;
 	case PROP_ACCOUNT:
-		if (priv->account)
-			g_object_unref (priv->account);
-
-		priv->account = g_value_get_object (value);
-		if (priv->account)
-			g_object_ref (priv->account);
+		avatar_chooser_set_account (self, g_value_get_object (value));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -248,8 +248,10 @@
 	priv = GET_PRIV (object);
 
 	g_object_unref (priv->contact_factory);
-	if (priv->account)
-		g_object_unref (priv->account);
+	priv->contact_factory = NULL;
+
+	avatar_chooser_set_account (EMPATHY_AVATAR_CHOOSER (object), NULL);
+	g_assert (priv->account == NULL && priv->tp_contact_factory == NULL);
 
 	g_free (priv->image_data);
 	g_free (priv->mime_type);
@@ -258,6 +260,56 @@
 }
 
 static void
+avatar_chooser_tp_cf_ready_cb (EmpathyTpContactFactory *tp_cf,
+			       GParamSpec              *unused,
+			       EmpathyAvatarChooser    *self)
+{
+	EmpathyAvatarChooserPriv *priv = GET_PRIV (self);
+	gboolean ready;
+
+	/* sanity check that we're listening on the right ETpCF */
+	g_assert (priv->tp_contact_factory == tp_cf);
+
+	ready = empathy_tp_contact_factory_is_ready (tp_cf);
+	gtk_widget_set_sensitive (GTK_WIDGET (self), ready);
+}
+
+static void
+avatar_chooser_set_account (EmpathyAvatarChooser *self,
+			    McAccount            *account)
+{
+	EmpathyAvatarChooserPriv *priv = GET_PRIV (self);
+
+	if (priv->account != NULL) {
+		g_object_unref (priv->account);
+		priv->account = NULL;
+
+		g_assert (priv->tp_contact_factory != NULL);
+
+		g_signal_handler_disconnect (priv->tp_contact_factory,
+			priv->ready_handler_id);
+		priv->ready_handler_id = 0;
+
+		g_object_unref (priv->tp_contact_factory);
+		priv->tp_contact_factory = NULL;
+	}
+
+	if (account != NULL) {
+		priv->account = g_object_ref (account);
+		priv->tp_contact_factory =
+			empathy_contact_factory_get_tp_factory (
+				priv->contact_factory, priv->account);
+
+		priv->ready_handler_id = g_signal_connect (
+			priv->tp_contact_factory, "notify::ready",
+			G_CALLBACK (avatar_chooser_tp_cf_ready_cb), self);
+		avatar_chooser_tp_cf_ready_cb (priv->tp_contact_factory, NULL,
+			self);
+	}
+}
+
+
+static void
 avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
 			  GdkPixbuf            *pixbuf,
 			  gchar                *image_data,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]