/soc/2013/ankitkv/gobjectification: b70177e7a8b7: Removed attrib...

Ankit Vani a at nevitus.org
Sat Jun 29 11:06:30 EDT 2013


Changeset: b70177e7a8b79fdc2b1bf6028d7c749c4b57a80b
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-29 20:36 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/b70177e7a8b7

Description:

Removed attributes from PurpleChatUser. Used g_object_[gs]et_data()/g_object_[gs]et_data_full() instead
* Removed purple_chat_user_get_attribute()
* Removed purple_chat_user_get_attribute_keys()
* Removed purple_chat_user_set_attribute()
* Removed purple_chat_user_set_attributes()

diffstat:

 libpurple/conversationtypes.c  |  96 +-----------------------------------------
 libpurple/conversationtypes.h  |  41 -----------------
 libpurple/protocols/irc/msgs.c |  19 +-------
 3 files changed, 4 insertions(+), 152 deletions(-)

diffs (235 lines):

diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -127,12 +127,6 @@ struct _PurpleChatUserPrivate
 	 * are a channel operator.
 	 */
 	PurpleChatUserFlags flags;
-
-	/**
-	 * A hash table of attributes about the user, such as real name,
-	 * user\@host, etc.
-	 */
-	GHashTable *attributes;
 };
 
 /* Chat User Property enums */
@@ -1770,83 +1764,6 @@ purple_chat_user_get_flags(const PurpleC
 	return priv->flags;
 }
 
-const char *
-purple_chat_user_get_attribute(PurpleChatUser *cb, const char *key)
-{
-	PurpleChatUserPrivate *priv;
-	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
-
-	g_return_val_if_fail(priv != NULL, NULL);
-	g_return_val_if_fail(key != NULL, NULL);
-	
-	return g_hash_table_lookup(priv->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_chat_user_get_attribute_keys(PurpleChatUser *cb)
-{
-	GList *keys = NULL;
-	PurpleChatUserPrivate *priv;
-	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
-	
-	g_return_val_if_fail(priv != NULL, NULL);
-	
-	g_hash_table_foreach(priv->attributes, (GHFunc)append_attribute_key, &keys);
-	
-	return keys;
-}
-
-void
-purple_chat_user_set_attribute(PurpleChatUser *cb,
-		PurpleChatConversation *chat, const char *key, const char *value)
-{
-	PurpleConversationUiOps *ops;
-	PurpleChatUserPrivate *priv;
-	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
-
-	g_return_if_fail(priv != NULL);
-	g_return_if_fail(key != NULL);
-	g_return_if_fail(value != NULL);
-
-	g_hash_table_replace(priv->attributes, g_strdup(key), g_strdup(value));
-
-	ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat));
-
-	if (ops != NULL && ops->chat_update_user != NULL)
-		ops->chat_update_user(cb);
-}
-
-void
-purple_chat_user_set_attributes(PurpleChatUser *cb,
-		PurpleChatConversation *chat, GList *keys, GList *values)
-{
-	PurpleConversationUiOps *ops;
-	PurpleChatUserPrivate *priv;
-	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
-
-	g_return_if_fail(priv != NULL);
-	g_return_if_fail(keys != NULL);
-	g_return_if_fail(values != NULL);
-
-	while (keys != NULL && values != NULL) {
-		g_hash_table_replace(priv->attributes, g_strdup(keys->data), g_strdup(values->data));
-		keys = g_list_next(keys);
-		values = g_list_next(values);
-	}
-
-	ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat));
-
-	if (ops != NULL && ops->chat_update_user != NULL)
-		ops->chat_update_user(cb);
-}
-
 void
 purple_chat_user_set_chat(PurpleChatUser *cb,
 		PurpleChatConversation *chat)
@@ -1965,16 +1882,6 @@ purple_chat_user_get_property(GObject *o
 	}
 }
 
-/* GObject initialization function */
-static void purple_chat_user_init(GTypeInstance *instance, gpointer klass)
-{
-	PurpleChatUserPrivate *priv;
-	priv = PURPLE_CHAT_USER_GET_PRIVATE(instance);
-
-	priv->attributes = g_hash_table_new_full(g_str_hash, g_str_equal,
-										   g_free, g_free);
-}
-
 /* GObject dispose function */
 static void
 purple_chat_user_dispose(GObject *object)
@@ -1998,7 +1905,6 @@ purple_chat_user_finalize(GObject *objec
 	g_free(priv->alias);
 	g_free(priv->alias_key);
 	g_free(priv->name);
-	g_hash_table_destroy(priv->attributes);
 
 	cb_parent_class->finalize(object);
 }
@@ -2066,7 +1972,7 @@ purple_chat_user_get_type(void)
 			NULL,
 			sizeof(PurpleChatUser),
 			0,
-			(GInstanceInitFunc)purple_chat_user_init,
+			NULL,
 			NULL,
 		};
 
diff --git a/libpurple/conversationtypes.h b/libpurple/conversationtypes.h
--- a/libpurple/conversationtypes.h
+++ b/libpurple/conversationtypes.h
@@ -609,47 +609,6 @@ gboolean purple_chat_conversation_has_le
 GType purple_chat_user_get_type(void);
 
 /**
- * Get an attribute of a chat user
- *
- * @param cb	The chat user.
- * @param key	The key of the attribute.
- *
- * @return The value of the attribute key.
- */
-const char *purple_chat_user_get_attribute(PurpleChatUser *cb, const char *key);
-
-/**
- * Get the keys of all atributes of a chat user
- *
- * @param cb	The chat user.
- *
- * @return A list of the attributes of a chat user.
- */
-GList *purple_chat_user_get_attribute_keys(PurpleChatUser *cb);
-	
-/**
- * Set an attribute of a chat user
- *
- * @param chat	The chat.
- * @param cb	The chat user.
- * @param key	The key of the attribute.
- * @param value	The value of the attribute.
- */
-void purple_chat_user_set_attribute(PurpleChatUser *cb,
-		PurpleChatConversation *chat, const char *key, const char *value);
-
-/**
- * Set attributes of a chat user
- *
- * @param chat	The chat.
- * @param cb	The chat user.
- * @param keys	A GList of the keys.
- * @param values A GList of the values.
- */
-void purple_chat_user_set_attributes(PurpleChatUser *cb,
-		PurpleChatConversation *chat, GList *keys, GList *values);
-
-/**
  * Set the chat conversation associated with this chat user.
  *
  * @param cb	The chat user
diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c
--- a/libpurple/protocols/irc/msgs.c
+++ b/libpurple/protocols/irc/msgs.c
@@ -479,7 +479,6 @@ void irc_msg_who(struct irc_conn *irc, c
 		char *cur, *userhost, *realname;
 		
 		PurpleChatUserFlags flags;
-		GList *keys = NULL, *values = NULL;
 
 		if (!args || !args[0] || !args[1] || !args[2] || !args[3]
 		    || !args[4] || !args[5] || !args[6] || !args[7]) {
@@ -512,19 +511,8 @@ void irc_msg_who(struct irc_conn *irc, c
 		}
 		realname = g_strdup(cur);
 		
-		keys = g_list_prepend(keys, "userhost");
-		values = g_list_prepend(values, userhost);
-		
-		keys = g_list_prepend(keys, "realname");
-		values = g_list_prepend(values, realname);
-		
-		purple_chat_user_set_attributes(cb, chat, keys, values);
-		
-		g_list_free(keys);
-		g_list_free(values);
-		
-		g_free(userhost);
-		g_free(realname);
+		g_object_set_data_full(G_OBJECT(cb), "userhost", userhost, (GDestroyNotify)g_free);
+		g_object_set_data_full(G_OBJECT(cb), "realname", realname, (GDestroyNotify)g_free);
 		
 		flags = purple_chat_user_get_flags(cb);
 
@@ -1019,7 +1007,7 @@ void irc_msg_join(struct irc_conn *irc, 
 	cb = purple_chat_conversation_find_user(chat, nick);
 	
 	if (cb) {
-		purple_chat_user_set_attribute(cb, chat, "userhost", userhost);		
+		g_object_set_data_full(G_OBJECT(cb), "userhost", userhost, (GDestroyNotify)g_free);
 	}
 	
 	if ((ib = g_hash_table_lookup(irc->buddies, nick)) != NULL) {
@@ -1027,7 +1015,6 @@ void irc_msg_join(struct irc_conn *irc, 
 		irc_buddy_status(nick, ib, irc);
 	}
 
-	g_free(userhost);
 	g_free(nick);
 }
 



More information about the Commits mailing list