pidgin: 7ee5e1d4: Patch from Zac West, plucked from severa...

evands at pidgin.im evands at pidgin.im
Sun Feb 20 20:36:53 EST 2011


----------------------------------------------------------------------
Revision: 7ee5e1d431651ed2b1a54bc942d63f35580af55c
Parent:   3de680fff7ddd1b00149657afb7f6cd833000a90
Author:   evands at pidgin.im
Date:     02/20/11 19:19:45
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/7ee5e1d431651ed2b1a54bc942d63f35580af55c

Changelog: 

Patch from Zac West, plucked from several im.pidgin.adium commits, which adds an API for setting and getting attributes on PurpleConvChatBuddys

Changes against parent 3de680fff7ddd1b00149657afb7f6cd833000a90

  patched  libpurple/conversation.c
  patched  libpurple/conversation.h

-------------- next part --------------
============================================================
--- libpurple/conversation.c	292bafeeae0e74e5a4235a58322c44c563150d6d
+++ libpurple/conversation.c	a065e8a8285ea67cbc9b7e8595074e4922ad2226
@@ -2135,6 +2135,8 @@ purple_conv_chat_cb_new(const char *name
 	cb->name = g_strdup(name);
 	cb->flags = flags;
 	cb->alias = g_strdup(alias);
+	cb->attributes = g_hash_table_new_full(g_str_hash, g_str_equal,
+										   g_free, g_free);
 
 	PURPLE_DBUS_REGISTER_POINTER(cb, PurpleConvChatBuddy);
 	return cb;
@@ -2167,6 +2169,7 @@ purple_conv_chat_cb_destroy(PurpleConvCh
 	g_free(cb->alias);
 	g_free(cb->alias_key);
 	g_free(cb->name);
+	g_hash_table_destroy(cb->attributes);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(cb);
 	g_free(cb);
@@ -2180,7 +2183,77 @@ purple_conv_chat_cb_get_name(PurpleConvC
 	return cb->name;
 }
 
+const char *
+purple_conv_chat_cb_get_attribute(PurpleConvChatBuddy *cb, const char *key)
+{
+	g_return_val_if_fail(cb != NULL, NULL);
+	g_return_val_if_fail(key != NULL, NULL);
+	
+	return g_hash_table_lookup(cb->attributes, key);
+}
+
+static void
+append_attribute_key(gpointer key, gpointer value, gpointer user_data)
+{
+	GList **list = user_data;
+	*list = g_list_prepend(*list, key);
+}
+
 GList *
+purple_conv_chat_cb_get_attribute_keys(PurpleConvChatBuddy *cb)
+{
+	GList *keys = NULL;
+	
+	g_return_val_if_fail(cb != NULL, NULL);
+	
+	g_hash_table_foreach(cb->attributes, (GHFunc)append_attribute_key, &keys);
+	
+	return keys;
+}
+
+void
+purple_conv_chat_cb_set_attribute(PurpleConvChat *chat, PurpleConvChatBuddy *cb, const char *key, const char *value)
+{
+	PurpleConversation *conv;
+	PurpleConversationUiOps *ops;
+	
+	g_return_if_fail(cb != NULL);
+	g_return_if_fail(key != NULL);
+	g_return_if_fail(value != NULL);
+	
+	g_hash_table_replace(cb->attributes, g_strdup(key), g_strdup(value));
+	
+	conv = purple_conv_chat_get_conversation(chat);
+	ops = purple_conversation_get_ui_ops(conv);
+	
+	if (ops != NULL && ops->chat_update_user != NULL)
+		ops->chat_update_user(conv, cb->name);
+}
+
+void
+purple_conv_chat_cb_set_attributes(PurpleConvChat *chat, PurpleConvChatBuddy *cb, GList *keys, GList *values)
+{
+	PurpleConversation *conv;
+	PurpleConversationUiOps *ops;
+	
+	g_return_if_fail(cb != NULL);
+	g_return_if_fail(keys != NULL);
+	g_return_if_fail(values != NULL);
+	
+	while (keys != NULL && values != NULL) {
+		g_hash_table_replace(cb->attributes, g_strdup(keys->data), g_strdup(values->data));
+		keys = g_list_next(keys);
+		values = g_list_next(values);
+	}
+	
+	conv = purple_conv_chat_get_conversation(chat);
+	ops = purple_conversation_get_ui_ops(conv);
+	
+	if (ops != NULL && ops->chat_update_user != NULL)
+		ops->chat_update_user(conv, cb->name);
+}
+
+GList *
 purple_conversation_get_extended_menu(PurpleConversation *conv)
 {
 	GList *menu = NULL;
============================================================
--- libpurple/conversation.h	381a495feb11bace150cc4afcf6b7b50a9c8624d
+++ libpurple/conversation.h	f567b4f28ebe35e5cb816e8fb13d6008f2566dc7
@@ -300,6 +300,9 @@ struct _PurpleConvChatBuddy
 	PurpleConvChatBuddyFlags flags;  /**< A bitwise OR of flags for this participant,
 	                                  *   such as whether they are a channel operator.
 	                                  */
+	GHashTable *attributes;          /**< A hash table of attributes about the user, such as
+                                    *   real name, user at host, etc.
+                                    */
 };
 
 /**
@@ -513,6 +516,46 @@ const char *purple_conversation_get_name
 const char *purple_conversation_get_name(const PurpleConversation *conv);
 
 /**
+ * Get an attribute of a chat buddy
+ *
+ * @param cb	The chat buddy.
+ * @param key	The key of the attribute.
+ *
+ * @return The value of the attribute key.
+ */
+const char *purple_conv_chat_cb_get_attribute(PurpleConvChatBuddy *cb, const char *key);
+
+/**
+ * Get the keys of all atributes of a chat buddy
+ *
+ * @param cb	The chat buddy.
+ *
+ * @return A list of the attributes of a chat buddy.
+ */
+GList *purple_conv_chat_cb_get_attribute_keys(PurpleConvChatBuddy *cb);
+	
+/**
+ * Set an attribute of a chat buddy
+ *
+ * @param chat	The chat.
+ * @param cb	The chat buddy.
+ * @param key	The key of the attribute.
+ * @param value	The value of the attribute.
+ */
+void purple_conv_chat_cb_set_attribute(PurpleConvChat *chat, PurpleConvChatBuddy *cb, const char *key, const char *value);
+
+/**
+ * Set attributes of a chat buddy
+ *
+ * @param chat	The chat.
+ * @param cb	The chat buddy.
+ * @param keys	A GList of the keys.
+ * @param values A GList of the values.
+ */
+void
+purple_conv_chat_cb_set_attributes(PurpleConvChat *chat, PurpleConvChatBuddy *cb, GList *keys, GList *values);
+
+/**
  * Enables or disables logging for this conversation.
  *
  * @param conv The conversation.


More information about the Commits mailing list