Sat, 29 Jun 2013 20:36:19 +0530
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()
--- a/libpurple/conversationtypes.c Sat Jun 29 20:12:09 2013 +0530 +++ b/libpurple/conversationtypes.c Sat Jun 29 20:36:19 2013 +0530 @@ -127,12 +127,6 @@ * 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 @@ 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 @@ } } -/* 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 @@ 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 @@ NULL, sizeof(PurpleChatUser), 0, - (GInstanceInitFunc)purple_chat_user_init, + NULL, NULL, };
--- a/libpurple/conversationtypes.h Sat Jun 29 20:12:09 2013 +0530 +++ b/libpurple/conversationtypes.h Sat Jun 29 20:36:19 2013 +0530 @@ -609,47 +609,6 @@ 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
--- a/libpurple/protocols/irc/msgs.c Sat Jun 29 20:12:09 2013 +0530 +++ b/libpurple/protocols/irc/msgs.c Sat Jun 29 20:36:19 2013 +0530 @@ -479,7 +479,6 @@ 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 @@ } 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 @@ 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 @@ irc_buddy_status(nick, ib, irc); } - g_free(userhost); g_free(nick); }