changeset 22217:ad357ca94de9

We will probably eventually use purple_object_[get|set]_ui_data. Until then, this will do.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 26 Jan 2008 22:33:08 +0000
parents b99d6d21cd79
children 5152a14d06a3
files finch/finch.h finch/gntblist.c finch/gntconv.c finch/gntft.c finch/gntrequest.c finch/gntroomlist.c
diffstat 6 files changed, 72 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/finch/finch.h	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/finch.h	Sat Jan 26 22:33:08 2008 +0000
@@ -29,3 +29,7 @@
 #define FINCH_UI "gnt-purple"
 
 #define FINCH_PREFS_ROOT "/finch"
+
+#define FINCH_GET_DATA(obj)        (obj)->ui_data
+#define FINCH_SET_DATA(obj, data)  (obj)->ui_data = data
+
--- a/finch/gntblist.c	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/gntblist.c	Sat Jan 26 22:33:08 2008 +0000
@@ -156,7 +156,7 @@
 
 	if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
 		PurpleBuddy *buddy = (PurpleBuddy*)node;
-		FinchBlistNode *fnode = node->ui_data;
+		FinchBlistNode *fnode = FINCH_GET_DATA(node);
 		if (!purple_buddy_get_contact(buddy))
 			return FALSE; /* When a new buddy is added and show-offline is set */
 		if (PURPLE_BUDDY_IS_ONLINE(buddy))
@@ -313,11 +313,11 @@
 static FinchBlistNode *
 create_finch_blist_node(PurpleBlistNode *node, gpointer row)
 {
-	FinchBlistNode *fnode = node->ui_data;
+	FinchBlistNode *fnode = FINCH_GET_DATA(node);
 	if (!fnode) {
 		fnode = g_new0(FinchBlistNode, 1);
 		fnode->signed_timer = 0;
-		node->ui_data = fnode;
+		FINCH_SET_DATA(node, fnode);
 	}
 	fnode->row = row;
 	return fnode;
@@ -326,13 +326,13 @@
 static void
 reset_blist_node_ui_data(PurpleBlistNode *node)
 {
-	FinchBlistNode *fnode = node->ui_data;
+	FinchBlistNode *fnode = FINCH_GET_DATA(node);
 	if (fnode == NULL)
 		return;
 	if (fnode->signed_timer)
 		purple_timeout_remove(fnode->signed_timer);
 	g_free(fnode);
-	node->ui_data = NULL;
+	FINCH_SET_DATA(node, NULL);
 }
 
 static int
@@ -365,7 +365,7 @@
 get_blist_node_flag(PurpleBlistNode *node)
 {
 	GntTextFormatFlags flag = 0;
-	FinchBlistNode *fnode = node->ui_data;
+	FinchBlistNode *fnode = FINCH_GET_DATA(node);
 
 	if (ggblist->tagged && g_list_find(ggblist->tagged, node))
 		flag |= GNT_TEXT_FLAG_BOLD;
@@ -374,7 +374,7 @@
 		flag |= GNT_TEXT_FLAG_BLINK;
 	else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
 		node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact *)node);
-		fnode = node->ui_data;
+		fnode = FINCH_GET_DATA(node);
 		if (fnode && fnode->signed_timer)
 			flag |= GNT_TEXT_FLAG_BLINK;
 	}
@@ -396,7 +396,7 @@
 	PurpleBlistNode *node;
 	for (node = purple_blist_node_get_first_child(((PurpleBlistNode*)contact)); node;
 			node = purple_blist_node_get_sibling_next(node)) {
-		FinchBlistNode *fnode = node->ui_data;
+		FinchBlistNode *fnode = FINCH_GET_DATA(node);
 		if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node) ||
 				(fnode && fnode->signed_timer))
 			return TRUE;
@@ -428,7 +428,7 @@
 static void
 add_node(PurpleBlistNode *node, FinchBlist *ggblist)
 {
-	if (node->ui_data)
+	if (FINCH_GET_DATA(node))
 		return;
 
 	if (!ggblist->manager->can_add_node(node))
@@ -462,10 +462,10 @@
 static void
 node_remove(PurpleBuddyList *list, PurpleBlistNode *node)
 {
-	FinchBlist *ggblist = list->ui_data;
+	FinchBlist *ggblist = FINCH_GET_DATA(list);
 	PurpleBlistNode *parent;
 
-	if (ggblist == NULL || node->ui_data == NULL)
+	if (ggblist == NULL || FINCH_GET_DATA(node)== NULL)
 		return;
 
 	gnt_tree_remove(GNT_TREE(ggblist->tree), node);
@@ -496,13 +496,13 @@
            happens, so maybe someone will figure it out. */
 	g_return_if_fail(node != NULL);
 
-	if (list->ui_data == NULL)
+	if (FINCH_GET_DATA(list)== NULL)
 		return;   /* XXX: this is probably the place to auto-join chats */
 
 	if (ggblist->window == NULL)
 		return;
 
-	if (node->ui_data != NULL) {
+	if (FINCH_GET_DATA(node)!= NULL) {
 		gnt_tree_change_text(GNT_TREE(ggblist->tree), node,
 				0, get_display_name(node));
 		gnt_tree_sort_row(GNT_TREE(ggblist->tree), node);
@@ -514,21 +514,21 @@
 
 	if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
 		PurpleBuddy *buddy = (PurpleBuddy*)node;
-		add_node((PurpleBlistNode*)buddy, list->ui_data);
+		add_node((PurpleBlistNode*)buddy, FINCH_GET_DATA(list));
 		node_update(list, purple_blist_node_get_parent(node));
 	} else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
-		add_node(node, list->ui_data);
+		add_node(node, FINCH_GET_DATA(list));
 	} else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
-		if (node->ui_data == NULL) {
+		if (FINCH_GET_DATA(node)== NULL) {
 			/* The core seems to expect the UI to add the buddies. */
 			for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node))
-				add_node(node, list->ui_data);
+				add_node(node, FINCH_GET_DATA(list));
 		}
 	} else if (PURPLE_BLIST_NODE_IS_GROUP(node)) {
 		if (!ggblist->manager->can_add_node(node))
 			node_remove(list, node);
 		else
-			add_node(node, list->ui_data);
+			add_node(node, FINCH_GET_DATA(list));
 	}
 }
 
@@ -539,7 +539,7 @@
 		return;
 
 	ggblist = g_new0(FinchBlist, 1);
-	list->ui_data = ggblist;
+	FINCH_SET_DATA(list, ggblist);
 	ggblist->manager = finch_blist_manager_find(purple_prefs_get_string(PREF_ROOT "/grouping"));
 	if (!ggblist->manager)
 		ggblist->manager = &default_manager;
@@ -763,7 +763,7 @@
 {
 	gpointer parent;
 	PurpleBlistNode *node = (PurpleBlistNode *)group;
-	if (node->ui_data)
+	if (FINCH_GET_DATA(node))
 		return;
 	parent = ggblist->manager->find_parent((PurpleBlistNode*)group);
 	create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group,
@@ -836,7 +836,7 @@
 {
 	gpointer parent;
 	PurpleBlistNode *node = (PurpleBlistNode *)chat;
-	if (node->ui_data)
+	if (FINCH_GET_DATA(node))
 		return;
 	if (!purple_account_is_connected(chat->account))
 		return;
@@ -855,7 +855,7 @@
 	PurpleBlistNode *node = (PurpleBlistNode*)contact;
 	const char *name;
 
-	if (node->ui_data)
+	if (FINCH_GET_DATA(node))
 		return;
 
 	name = get_display_name(node);
@@ -878,7 +878,7 @@
 	PurpleBlistNode *node = (PurpleBlistNode *)buddy;
 	PurpleContact *contact;
 
-	if (node->ui_data)
+	if (FINCH_GET_DATA(node))
 		return;
 
 	contact = purple_buddy_get_contact(buddy);
@@ -936,7 +936,7 @@
 						purple_buddy_get_account(buddy),
 						purple_buddy_get_name(buddy));
 		} else {
-			FinchConv *ggconv = conv->ui_data;
+			FinchConv *ggconv = FINCH_GET_DATA(conv);
 			gnt_window_present(ggconv->window);
 		}
 		finch_conversation_set_active(conv);
@@ -1812,7 +1812,7 @@
 {
 	PurpleBlistNode *node;
 	purple_signals_disconnect_by_handle(finch_blist_get_handle());
-	purple_get_blist()->ui_data = NULL;
+	FINCH_SET_DATA(purple_get_blist(), NULL);
 
 	node = purple_blist_get_root();
 	while (node) {
@@ -2324,7 +2324,7 @@
 buddy_recent_signed_on_off(gpointer data)
 {
 	PurpleBlistNode *node = data;
-	FinchBlistNode *fnode = node->ui_data;
+	FinchBlistNode *fnode = FINCH_GET_DATA(node);
 
 	purple_timeout_remove(fnode->signed_timer);
 	fnode->signed_timer = 0;
@@ -2344,7 +2344,7 @@
 buddy_signed_on_off_cb(gpointer data)
 {
 	PurpleBlistNode *node = data;
-	FinchBlistNode *fnode = node->ui_data;
+	FinchBlistNode *fnode = FINCH_GET_DATA(node);
 	if (!ggblist || !fnode)
 		return FALSE;
 
--- a/finch/gntconv.c	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/gntconv.c	Sat Jan 26 22:33:08 2008 +0000
@@ -282,7 +282,7 @@
 		return;
 
 	im = PURPLE_CONV_IM(conv);
-	ggc = conv->ui_data;
+	ggc = FINCH_GET_DATA(conv);
 
 	if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) {
 		int scroll;
@@ -321,7 +321,7 @@
 	PurpleConversation *conv = find_conv_with_contact(buddy->account, buddy->name);
 	if (conv == NULL)
 		return;
-	generate_send_to_menu(conv->ui_data);
+	generate_send_to_menu(FINCH_GET_DATA(conv));
 }
 
 static void
@@ -333,7 +333,7 @@
 		PurpleConversation *cc = find_conv_with_contact(
 				purple_conversation_get_account(conv), purple_conversation_get_name(conv));
 		if (cc)
-			generate_send_to_menu(cc->ui_data);
+			generate_send_to_menu(FINCH_GET_DATA(cc));
 		list = list->next;
 	}
 
@@ -610,7 +610,7 @@
 static void
 finch_create_conversation(PurpleConversation *conv)
 {
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	char *title;
 	PurpleConversationType type;
 	PurpleConversation *cc;
@@ -622,8 +622,8 @@
 
 	account = purple_conversation_get_account(conv);
 	cc = find_conv_with_contact(account, purple_conversation_get_name(conv));
-	if (cc && cc->ui_data)
-		ggc = cc->ui_data;
+	if (cc && FINCH_GET_DATA(cc))
+		ggc = FINCH_GET_DATA(cc);
 	else
 		ggc = g_new0(FinchConv, 1);
 
@@ -635,9 +635,9 @@
 
 	ggc->list = g_list_prepend(ggc->list, conv);
 	ggc->active_conv = conv;
-	conv->ui_data = ggc;
+	FINCH_SET_DATA(conv, ggc);
 
-	if (cc && cc->ui_data) {
+	if (cc && FINCH_GET_DATA(cc)) {
 		finch_conversation_set_active(conv);
 		return;
 	}
@@ -738,7 +738,7 @@
 finch_destroy_conversation(PurpleConversation *conv)
 {
 	/* do stuff here */
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	ggc->list = g_list_remove(ggc->list, conv);
 	if (ggc->list && conv == ggc->active_conv)
 		ggc->active_conv = ggc->list->data;
@@ -755,7 +755,7 @@
 finch_write_common(PurpleConversation *conv, const char *who, const char *message,
 		PurpleMessageFlags flags, time_t mtime)
 {
-	FinchConv *ggconv = conv->ui_data;
+	FinchConv *ggconv = FINCH_GET_DATA(conv);
 	char *strip, *newline;
 	GntTextFormatFlags fl = 0;
 	int pos;
@@ -908,7 +908,7 @@
 static void
 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals)
 {
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	GntEntry *entry = GNT_ENTRY(ggc->entry);
 
 	if (!new_arrivals)
@@ -947,7 +947,7 @@
 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a)
 {
 	/* Update the name for string completion */
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	GntEntry *entry = GNT_ENTRY(ggc->entry);
 	GntTree *tree = GNT_TREE(ggc->u.chat->userlist);
 	PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), new_n);
@@ -965,7 +965,7 @@
 finch_chat_remove_users(PurpleConversation *conv, GList *list)
 {
 	/* Remove the name from string completion */
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	GntEntry *entry = GNT_ENTRY(ggc->entry);
 	for (; list; list = list->next) {
 		GntTree *tree = GNT_TREE(ggc->u.chat->userlist);
@@ -978,7 +978,7 @@
 finch_chat_update_user(PurpleConversation *conv, const char *user)
 {
 	PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), user);
-	FinchConv *ggc = conv->ui_data;
+	FinchConv *ggc = FINCH_GET_DATA(conv);
 	gnt_tree_change_text(GNT_TREE(ggc->u.chat->userlist), (gpointer)user, 0, chat_flag_text(cb->flags));
 }
 
@@ -1087,7 +1087,7 @@
 clear_command_cb(PurpleConversation *conv,
                  const char *cmd, char **args, char **error, void *data)
 {
-	FinchConv *ggconv = conv->ui_data;
+	FinchConv *ggconv = FINCH_GET_DATA(conv);
 	gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv));
 	purple_conversation_clear_message_history(conv);
 	return PURPLE_CMD_STATUS_OK;
@@ -1144,7 +1144,7 @@
 static PurpleCmdRet
 users_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data)
 {
-	FinchConv *fc = conv->ui_data;
+	FinchConv *fc = FINCH_GET_DATA(conv);
 	FinchConvChat *ch;
 	if (!fc)
 		return PURPLE_CMD_STATUS_FAILED;
@@ -1248,7 +1248,7 @@
 
 void finch_conversation_set_active(PurpleConversation *conv)
 {
-	FinchConv *ggconv = conv->ui_data;
+	FinchConv *ggconv = FINCH_GET_DATA(conv);
 	PurpleAccount *account;
 	char *title;
 
@@ -1264,7 +1264,7 @@
 
 void finch_conversation_set_info_widget(PurpleConversation *conv, GntWidget *widget)
 {
-	FinchConv *fc = conv->ui_data;
+	FinchConv *fc = FINCH_GET_DATA(conv);
 	int height, width;
 
 	gnt_box_remove_all(GNT_BOX(fc->info));
--- a/finch/gntft.c	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/gntft.c	Sat Jan 26 22:33:08 2008 +0000
@@ -23,13 +23,14 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
+#include "finch.h"
+
 #include <gnt.h>
 #include <gntbox.h>
 #include <gntbutton.h>
 #include <gntcheckbox.h>
 #include <gntlabel.h>
 #include <gnttree.h>
-#include "internal.h"
 
 #include "debug.h"
 #include "notify.h"
@@ -41,7 +42,7 @@
 #include "prefs.h"
 
 #define FINCHXFER(xfer) \
-	(PurpleGntXferUiData *)(xfer)->ui_data
+	(PurpleGntXferUiData *)FINCH_GET_DATA(xfer)
 
 typedef struct
 {
@@ -467,7 +468,7 @@
 
 	/* This is where we're setting xfer->ui_data for the first time. */
 	data = g_new0(PurpleGntXferUiData, 1);
-	xfer->ui_data = data;
+	FINCH_SET_DATA(xfer, data);
 }
 
 static void
@@ -479,7 +480,7 @@
 	if (data) {
 		g_free(data->name);
 		g_free(data);
-		xfer->ui_data = NULL;
+		FINCH_SET_DATA(xfer, NULL);
 	}
 }
 
--- a/finch/gntrequest.c	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/gntrequest.c	Sat Jan 26 22:33:08 2008 +0000
@@ -308,26 +308,26 @@
 			PurpleRequestFieldType type = purple_request_field_get_type(field);
 			if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
 			{
-				GntWidget *check = field->ui_data;
+				GntWidget *check = FINCH_GET_DATA(field);
 				gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check));
 				purple_request_field_bool_set_value(field, value);
 			}
 			else if (type == PURPLE_REQUEST_FIELD_STRING)
 			{
-				GntWidget *entry = field->ui_data;
+				GntWidget *entry = FINCH_GET_DATA(field);
 				const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
 				purple_request_field_string_set_value(field, (text && *text) ? text : NULL);
 			}
 			else if (type == PURPLE_REQUEST_FIELD_INTEGER)
 			{
-				GntWidget *entry = field->ui_data;
+				GntWidget *entry = FINCH_GET_DATA(field);
 				const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
 				int value = (text && *text) ? atoi(text) : 0;
 				purple_request_field_int_set_value(field, value);
 			}
 			else if (type == PURPLE_REQUEST_FIELD_CHOICE)
 			{
-				GntWidget *combo = field->ui_data;
+				GntWidget *combo = FINCH_GET_DATA(field);
 				int id;
 				id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)));
 				purple_request_field_choice_set_value(field, id);
@@ -338,7 +338,7 @@
 				if (purple_request_field_list_get_multi_select(field))
 				{
 					GList *iter;
-					GntWidget *tree = field->ui_data;
+					GntWidget *tree = FINCH_GET_DATA(field);
 
 					iter = purple_request_field_list_get_items(field);
 					for (; iter; iter = iter->next)
@@ -351,7 +351,7 @@
 				}
 				else
 				{
-					GntWidget *combo = field->ui_data;
+					GntWidget *combo = FINCH_GET_DATA(field);
 					gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
 					list = g_list_append(list, data);
 				}
@@ -361,7 +361,7 @@
 			}
 			else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
 			{
-				GntWidget *combo = field->ui_data;
+				GntWidget *combo = FINCH_GET_DATA(field);
 				PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
 				purple_request_field_account_set_value(field, acc);
 			}
@@ -594,35 +594,35 @@
 
 			if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
 			{
-				field->ui_data = create_boolean_field(field);
+				FINCH_SET_DATA(field, create_boolean_field(field));
 			}
 			else if (type == PURPLE_REQUEST_FIELD_STRING)
 			{
-				field->ui_data = create_string_field(field, &screenname);
+				FINCH_SET_DATA(field, create_string_field(field, &screenname));
 			}
 			else if (type == PURPLE_REQUEST_FIELD_INTEGER)
 			{
-				field->ui_data = create_integer_field(field);
+				FINCH_SET_DATA(field, create_integer_field(field));
 			}
 			else if (type == PURPLE_REQUEST_FIELD_CHOICE)
 			{
-				field->ui_data = create_choice_field(field);
+				FINCH_SET_DATA(field, create_choice_field(field));
 			}
 			else if (type == PURPLE_REQUEST_FIELD_LIST)
 			{
-				field->ui_data = create_list_field(field);
+				FINCH_SET_DATA(field, create_list_field(field));
 			}
 			else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
 			{
-				accountlist = field->ui_data = create_account_field(field);
+				accountlist = FINCH_SET_DATA(field, create_account_field(field));
 			}
 			else
 			{
-				field->ui_data = gnt_label_new_with_format(_("Not implemented yet."),
-						GNT_TEXT_FLAG_BOLD);
+				FINCH_SET_DATA(field, gnt_label_new_with_format(_("Not implemented yet."),
+						GNT_TEXT_FLAG_BOLD));
 			}
 			gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID);
-			gnt_box_add_widget(GNT_BOX(hbox), GNT_WIDGET(field->ui_data));
+			gnt_box_add_widget(GNT_BOX(hbox), GNT_WIDGET(FINCH_GET_DATA(field)));
 		}
 		if (grlist->next)
 			gnt_box_add_widget(GNT_BOX(box), gnt_hline_new());
--- a/finch/gntroomlist.c	Sat Jan 26 21:58:51 2008 +0000
+++ b/finch/gntroomlist.c	Sat Jan 26 22:33:08 2008 +0000
@@ -24,7 +24,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
-#include"internal.h"
+#include "finch.h"
 
 #include "gntrequest.h"
 #include "gntroomlist.h"
@@ -341,7 +341,7 @@
 static void
 fl_create(PurpleRoomlist *list)
 {
-	list->ui_data = &froomlist;
+	FINCH_SET_DATA(list, &froomlist);
 	setup_roomlist(NULL);
 	update_roomlist(list);
 }