gobjectification.conversation: d02e6bfe: Allow changing names of a conversation.

sadrul at pidgin.im sadrul at pidgin.im
Sat Jul 24 23:55:37 EDT 2010


----------------------------------------------------------------------
Revision: d02e6bfe171111664a65f57da2a9139cb3ebc4c3
Parent:   e2083369c97cc5cdb95ba1c199a503f3fa59f0ca
Author:   sadrul at pidgin.im
Date:     07/24/10 23:50:51
Branch:   im.pidgin.gobjectification.conversation
URL: http://d.pidgin.im/viewmtn/revision/info/d02e6bfe171111664a65f57da2a9139cb3ebc4c3

Changelog: 

Allow changing names of a conversation.

Changes against parent e2083369c97cc5cdb95ba1c199a503f3fa59f0ca

  patched  libpurple/conversation/conv.c
  patched  libpurple/conversation/conv.h
  patched  libpurple/conversation/convs.c
  patched  libpurple/conversation.c

-------------- next part --------------
============================================================
--- libpurple/conversation.c	9761e4c1e29225c5b290df3b312b2f99fce96b5c
+++ libpurple/conversation.c	72830f73fc5eec36a4073e133d4fb192417a6685
@@ -845,27 +845,6 @@ purple_conversation_foreach(void (*func)
 	}
 }
 
-void
-purple_conversation_set_name(PurpleConversation *conv, const char *name)
-{
-	struct _purple_hconv *hc;
-	g_return_if_fail(conv != NULL);
-
-	hc = g_new(struct _purple_hconv, 1);
-	hc->type = conv->type;
-	hc->account = conv->account;
-	hc->name = (gchar *)purple_normalize(conv->account, conv->name);
-
-	g_hash_table_remove(conversation_cache, hc);
-	g_free(conv->name);
-
-	conv->name = g_strdup(name);
-	hc->name = g_strdup(purple_normalize(conv->account, conv->name));
-	g_hash_table_insert(conversation_cache, hc, conv);
-
-	purple_conversation_autoset_title(conv);
-}
-
 PurpleBuddy *
 purple_conversation_find_buddy(const PurpleConversation *conv)
 {
============================================================
--- libpurple/conversation/conv.h	2a6546cdb9115d52de39a62aa731b14404af4493
+++ libpurple/conversation/conv.h	09afa45139ba2dbc6e616fb44e6998fb143cb76e
@@ -287,24 +287,6 @@ void purple_conversation_autoset_title(P
  */
 void purple_conversation_autoset_title(PurpleConversation *conv);
 
-/**
- * Sets the specified conversation's name.
- *
- * @param conv The conversation.
- * @param name The conversation's name.
- */
-void purple_conversation_set_name(PurpleConversation *conv, const char *name);
-
-/**
- * Returns the specified conversation's name.
- *
- * @param conv The conversation.
- *
- * @return The conversation's name. If the conversation is an IM with a PurpleBuddy,
- *         then it's the name of the PurpleBuddy.
- */
-const char *purple_conversation_get_name(const PurpleConversation *conv);
-
 PurpleBuddy * purple_conversation_find_buddy(const PurpleConversation *conv);
 
 GSList * purple_conversation_find_buddies(const PurpleConversation *conv);
@@ -1277,6 +1259,24 @@ void purple_conversation_send_confirm(Pu
 void purple_conversation_send_confirm(PurpleConversation *conv, const char *message);
 
 /**
+ * Returns the specified conversation's name.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's name. If the conversation is an IM with a PurpleBuddy,
+ *         then it's the name of the PurpleBuddy.
+ */
+const char *purple_conversation_get_name(const PurpleConversation *conv);
+
+/**
+ * Sets the specified conversation's name.
+ *
+ * @param conv The conversation.
+ * @param name The conversation's name.
+ */
+void purple_conversation_set_name(PurpleConversation *conv, const char *name);
+
+/**
  * Returns the specified conversation's purple_account.
  *
  * This purple_account represents the user using purple, not the person the user
============================================================
--- libpurple/conversation/conv.c	d243a11fbf2f2a1858e74f0163b526c9ab17c76f
+++ libpurple/conversation/conv.c	0aaa5e55ff81a309a8df331adcd74acc926ad2f5
@@ -251,6 +251,22 @@ purple_conversation_get_name(const Purpl
 	return priv->name;
 }
 
+void
+purple_conversation_set_name(PurpleConversation *conv, const char *name)
+{
+	PurpleConversationPrivate *priv = GET_PRIVATE(conv);
+	g_return_if_fail(priv);
+
+	if (priv->name && name && g_utf8_collate(name, priv->name) == 0) {
+		return;
+	}
+
+	g_free(priv->name);
+	priv->name = g_strdup(name);
+
+	g_object_notify(G_OBJECT(conv), "name");
+}
+
 PurpleAccount *
 purple_conversation_get_account(const PurpleConversation *conv)
 {
============================================================
--- libpurple/conversation/convs.c	64919d0874366532a01ace33ee80d1d1fd7a302f
+++ libpurple/conversation/convs.c	fe9e4855bd086da6cffb0035b2a48d857c4afd66
@@ -160,6 +160,23 @@ static void
 }
 
 static void
+conv_name_changed(PurpleConversation *conv, GParamSpec *spec,
+		PurpleConvHash *hkey)
+{
+	g_signal_handlers_disconnect_matched(G_OBJECT(conv),
+			G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+			0, 0, NULL,
+			conv_name_changed, hkey);
+	g_hash_table_remove(global.conversation_cache, hkey);
+
+	hkey = conv_hash_create(conv, NULL);
+	g_hash_table_insert(global.conversation_cache, hkey, conv);
+
+	g_signal_connect(G_OBJECT(conv), "notify::name",
+			G_CALLBACK(conv_name_changed), hkey);
+}
+
+static void
 conversation_new_cb(PurpleConversation *conv)
 {
 	PurpleConvHash *hkey;
@@ -174,6 +191,9 @@ conversation_new_cb(PurpleConversation *
 
 	global.convs = g_list_prepend(global.convs, conv);
 
+	g_signal_connect(G_OBJECT(conv), "notify::name",
+			G_CALLBACK(conv_name_changed), hkey);
+
 	hkey = conv_hash_create(conv, NULL);
 	g_hash_table_insert(global.conversation_cache, hkey, conv);
 }


More information about the Commits mailing list