empathy r772 - in trunk: libempathy libempathy-gtk



Author: xclaesse
Date: Tue Mar 11 12:23:06 2008
New Revision: 772
URL: http://svn.gnome.org/viewvc/empathy?rev=772&view=rev

Log:
Fix usage of property iface and make use of it to get chatroom topic.


Modified:
   trunk/libempathy-gtk/empathy-group-chat.c
   trunk/libempathy/empathy-tp-chat.c

Modified: trunk/libempathy-gtk/empathy-group-chat.c
==============================================================================
--- trunk/libempathy-gtk/empathy-group-chat.c	(original)
+++ trunk/libempathy-gtk/empathy-group-chat.c	Tue Mar 11 12:23:06 2008
@@ -102,12 +102,6 @@
 static gboolean      group_chat_is_group_chat            (EmpathyChat       *chat);
 static void          group_chat_set_tp_chat              (EmpathyChat       *chat,
 							  EmpathyTpChat     *tp_chat);
-static void          group_chat_subject_notify_cb        (EmpathyTpChat     *tp_chat,
-							  GParamSpec        *param,
-							  EmpathyGroupChat  *chat);
-static void          group_chat_name_notify_cb           (EmpathyTpChat     *tp_chat,
-							  GParamSpec        *param,
-							  EmpathyGroupChat  *chat);
 static gboolean      group_chat_key_press_event          (EmpathyChat       *chat,
 							  GdkEventKey       *event);
 static gint          group_chat_contacts_completion_func (const gchar       *s1,
@@ -486,6 +480,52 @@
 }
 
 static void
+group_chat_property_changed_cb (EmpathyTpChat    *tp_chat,
+				gchar            *name,
+				GValue           *value,
+				EmpathyGroupChat *chat)
+{
+	EmpathyGroupChatPriv *priv;
+	const gchar          *str = NULL;
+
+	priv = GET_PRIV (chat);
+
+	/* FIXME: this is ugly, should use properties on EmpathyChat obj */
+
+	if (!tp_strdiff (name, "name")) {
+		str = g_value_get_string (value);
+		g_free (priv->name);
+		priv->name = g_strdup (str);
+		return;
+	}
+
+	if (tp_strdiff (name, "subject")) {
+		return;
+	}
+
+	str = g_value_get_string (value);
+	if (!tp_strdiff (priv->topic, str)) {
+		return;
+	}
+
+	g_free (priv->topic);
+	priv->topic = g_strdup (str);
+	gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->topic);
+
+	if (!EMPATHY_CHAT (chat)->block_events) {
+		gchar *string;
+
+		if (!G_STR_EMPTY (priv->topic)) {
+			string = g_strdup_printf (_("Topic set to: %s"), priv->topic);
+		} else {
+			string = g_strdup (_("No topic defined"));
+		}
+		empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, string);
+		g_free (string);
+	}
+}
+
+static void
 group_chat_set_tp_chat (EmpathyChat    *chat,
 			EmpathyTpChat *tp_chat)
 {
@@ -546,56 +586,9 @@
 	g_signal_connect (priv->tp_chat, "members-changed",
 			  G_CALLBACK (group_chat_members_changed_cb),
 			  chat);
-	g_signal_connect (priv->tp_chat, "notify::subject",
-			  G_CALLBACK (group_chat_subject_notify_cb),
+	g_signal_connect (priv->tp_chat, "property-changed",
+			  G_CALLBACK (group_chat_property_changed_cb),
 			  chat);
-	g_signal_connect (priv->tp_chat, "notify::name",
-			  G_CALLBACK (group_chat_name_notify_cb),
-			  chat);
-}
-
-static void
-group_chat_subject_notify_cb (EmpathyTpChat   *tp_chat,
-			      GParamSpec      *param,
-			      EmpathyGroupChat *chat)
-{
-	EmpathyGroupChatPriv *priv;
-	gchar                *str = NULL;
-
-	priv = GET_PRIV (chat);
-
-	g_object_get (priv->tp_chat, "subject", &str, NULL);
-	if (!tp_strdiff (priv->topic, str)) {
-		g_free (str);
-		return;
-	}
-
-	g_free (priv->topic);
-	priv->topic = str;
-	gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->topic);
-
-	if (!EMPATHY_CHAT (chat)->block_events) {
-		if (!G_STR_EMPTY (priv->topic)) {
-			str = g_strdup_printf (_("Topic set to: %s"), priv->topic);
-		} else {
-			str = g_strdup (_("No topic defined"));
-		}
-		empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
-		g_free (str);
-	}
-}
-
-static void
-group_chat_name_notify_cb (EmpathyTpChat   *tp_chat,
-			   GParamSpec      *param,
-			   EmpathyGroupChat *chat)
-{
-	EmpathyGroupChatPriv *priv;
-
-	priv = GET_PRIV (chat);
-
-	g_free (priv->name);
-	g_object_get (priv->tp_chat, "name", &priv->name, NULL);
 }
 
 static gboolean

Modified: trunk/libempathy/empathy-tp-chat.c
==============================================================================
--- trunk/libempathy/empathy-tp-chat.c	(original)
+++ trunk/libempathy/empathy-tp-chat.c	Tue Mar 11 12:23:06 2008
@@ -54,9 +54,10 @@
 };
 
 typedef struct {
-	gchar  *name;
-	guint   id;
-	GValue *value;
+	gchar          *name;
+	guint           id;
+	TpPropertyFlags flags;
+	GValue         *value;
 } TpChatProperty;
 
 static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass);
@@ -394,10 +395,6 @@
 	EmpathyTpChatPriv *priv = GET_PRIV (chat);
 	guint              i, j;
 
-	if (!priv->had_properties_list || !properties) {
-		return;
-	}
-
 	for (i = 0; i < properties->len; i++) {
 		GValueArray    *prop_struct;
 		TpChatProperty *property;
@@ -406,7 +403,7 @@
 
 		prop_struct = g_ptr_array_index (properties, i);
 		id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
-		src_value = g_value_array_get_nth (prop_struct, 1);
+		src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
 
 		for (j = 0; j < priv->properties->len; j++) {
 			property = g_ptr_array_index (priv->properties, j);
@@ -416,6 +413,7 @@
 				} else {
 					property->value = g_slice_new0 (GValue);
 				}
+				g_value_init (property->value, G_VALUE_TYPE (src_value));
 				g_value_copy (src_value, property->value);
 
 				empathy_debug (DEBUG_DOMAIN, "property %s changed",
@@ -441,7 +439,6 @@
 		return;
 	}
 
-	empathy_debug (DEBUG_DOMAIN, "Got value of properties");
 	tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
 }
 
@@ -469,19 +466,19 @@
 	for (i = 0; i < properties->len; i++) {
 		GValueArray    *prop_struct;
 		TpChatProperty *property;
-		guint           id;
-		const gchar    *name;
 
 		prop_struct = g_ptr_array_index (properties, i);
-		id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
-		name = g_value_get_string (g_value_array_get_nth (prop_struct, 1));
-
-		empathy_debug (DEBUG_DOMAIN, "Adding property %s", name);
 		property = g_slice_new0 (TpChatProperty);
-		property->id = id;
-		property->name = g_strdup (name);
+		property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
+		property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
+		property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
+
+		empathy_debug (DEBUG_DOMAIN, "Adding property name=%s id=%d flags=%d",
+			       property->name, property->id, property->flags);
 		g_ptr_array_add (priv->properties, property);
-		g_array_append_val (ids, id);
+		if (property->flags & TP_PROPERTY_FLAG_READ) {
+			g_array_append_val (ids, property->id);
+		}
 	}
 
 	tp_cli_properties_interface_call_get_properties (proxy, -1,



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