/soc/2013/ankitkv/gobjectification: c22b37bb25a8: get ui_data ba...

Ankit Vani a at nevitus.org
Sat Jun 29 12:58:13 EDT 2013


Changeset: c22b37bb25a80e3b0cf5f72a5a53c660c6a4200a
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-29 22:27 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/c22b37bb25a8

Description:

get ui_data back into PurpleChatUser. It serves it's purpose more efficiently than g_object_[gs]et_data()

diffstat:

 libpurple/conversationtypes.c |  23 +++++++++++++++++++++++
 libpurple/conversationtypes.h |  19 +++++++++++++++++++
 pidgin/gtkconv.c              |  20 ++++++++++----------
 3 files changed, 52 insertions(+), 10 deletions(-)

diffs (139 lines):

diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -111,6 +111,7 @@ struct _PurpleChatUserPrivate
 	PurpleChatUserFlags flags;     /**< A bitwise OR of flags for this
 	                                    participant, such as whether they
 	                                    are a channel operator.               */
+	gpointer ui_data;              /**< UI can put whatever it wants here.    */
 };
 
 /* Chat User Property enums */
@@ -1749,6 +1750,28 @@ purple_chat_user_get_flags(const PurpleC
 }
 
 void
+purple_chat_user_set_ui_data(PurpleChatUser *cb, gpointer ui_data)
+{
+	PurpleChatUserPrivate *priv;
+	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
+
+	g_return_if_fail(priv != NULL);
+
+	priv->ui_data = ui_data;
+}
+
+gpointer
+purple_chat_user_get_ui_data(const PurpleChatUser *cb)
+{
+	PurpleChatUserPrivate *priv;
+	priv = PURPLE_CHAT_USER_GET_PRIVATE(cb);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->ui_data;
+}
+
+void
 purple_chat_user_set_chat(PurpleChatUser *cb,
 		PurpleChatConversation *chat)
 {
diff --git a/libpurple/conversationtypes.h b/libpurple/conversationtypes.h
--- a/libpurple/conversationtypes.h
+++ b/libpurple/conversationtypes.h
@@ -640,6 +640,25 @@ PurpleChatUser *purple_chat_user_new(Pur
 		const char *name, const char *alias, PurpleChatUserFlags flags);
 
 /**
+ * Set the UI data associated with this chat user.
+ *
+ * @param cb			The chat user
+ * @param ui_data		A pointer to associate with this chat user.
+ */
+void purple_chat_user_set_ui_data(PurpleChatUser *cb, gpointer ui_data);
+
+/**
+ * Get the UI data associated with this chat user.
+ *
+ * @param cb			The chat user.
+ *
+ * @return The UI data associated with this chat user.  This is a
+ *         convenience field provided to the UIs--it is not
+ *         used by the libpurple core.
+ */
+gpointer purple_chat_user_get_ui_data(const PurpleChatUser *cb);
+
+/**
  * Get the alias of a chat user
  *
  * @param cb    The chat user.
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -4119,11 +4119,11 @@ get_chat_user_status_icon(PurpleChatConv
 static void
 deleting_chat_user_cb(PurpleChatUser *cb)
 {
-	GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(cb), "gtk-row");
+	GtkTreeRowReference *ref = purple_chat_user_get_ui_data(cb);
 
 	if (ref) {
 		gtk_tree_row_reference_free(ref);
-		g_object_set_data(G_OBJECT(cb), "gtk-row", NULL);
+		purple_chat_user_set_ui_data(cb, NULL);
 	}
 }
 
@@ -4208,13 +4208,13 @@ add_chat_user_common(PurpleChatConversat
 			CHAT_USERS_WEIGHT_COLUMN, is_buddy ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
 			-1);
 
-	if (g_object_get_data(G_OBJECT(cb), "gtk-row")) {
-		GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(cb), "gtk-row");
+	if (purple_chat_user_get_ui_data(cb)) {
+		GtkTreeRowReference *ref = purple_chat_user_get_ui_data(cb);
 		gtk_tree_row_reference_free(ref);
 	}
 
 	newpath = gtk_tree_model_get_path(tm, &iter);
-	g_object_set_data(G_OBJECT(cb), "gtk-row", gtk_tree_row_reference_new(tm, newpath));
+	purple_chat_user_set_ui_data(cb, gtk_tree_row_reference_new(tm, newpath));
 	gtk_tree_path_free(newpath);
 
 	if (is_me && color)
@@ -6763,7 +6763,7 @@ static gboolean get_iter_from_chatuser(P
 
 	g_return_val_if_fail(cb != NULL, FALSE);
 
-	ref = g_object_get_data(G_OBJECT(cb), "gtk-row");
+	ref = purple_chat_user_get_ui_data(cb);
 	if (!ref)
 		return FALSE;
 
@@ -6850,11 +6850,11 @@ pidgin_conv_chat_rename_user(PurpleChatC
 		return;
 
 	if (get_iter_from_chatuser(old_chatuser, &iter)) {
-		GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(old_chatuser), "gtk-row");
+		GtkTreeRowReference *ref = purple_chat_user_get_ui_data(old_chatuser);
 
 		gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
 		gtk_tree_row_reference_free(ref);
-		g_object_set_data(G_OBJECT(old_chatuser), "gtk-row", NULL);
+		purple_chat_user_set_ui_data(old_chatuser, NULL);
 	}
 
 	g_return_if_fail(new_alias != NULL);
@@ -6939,10 +6939,10 @@ pidgin_conv_chat_update_user(PurpleChatU
 		return;
 
 	if (get_iter_from_chatuser(chatuser, &iter)) {
-		GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(chatuser), "gtk-row");
+		GtkTreeRowReference *ref = purple_chat_user_get_ui_data(chatuser);
 		gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
 		gtk_tree_row_reference_free(ref);
-		g_object_set_data(G_OBJECT(chatuser), "gtk-row", NULL);
+		purple_chat_user_set_ui_data(chatuser, NULL);
 	}
 
 	if (chatuser)



More information about the Commits mailing list