org.guifications.plugins: 3b2816a0447e73551fa506262639525e97c5d880

sadrul at guifications.org sadrul at guifications.org
Tue Mar 11 04:00:08 CDT 2008


-----------------------------------------------------------------
Revision: 3b2816a0447e73551fa506262639525e97c5d880
Ancestor: 694d4977ce71d086417a932f5d00ad8e43fcead5
Author: sadrul at guifications.org
Date: 2008-03-11T09:04:36
Branch: org.guifications.plugins

Modified files:
        xchat-chats/xchat-chats.c

ChangeLog: 

Update the xchat plugin to not crash because of the changes in the input
area in pidgin 2.4.0. Includes a workaround for a bug that shows up only
for hidden conversations.
I have tried to make the change backward compatible, ie. it should still
work correctly with pidgin 2.3.1. Could someone please test that out?
Do we need a pidgin_version_check in pidgin?


-----------------------------------------------------------------
This revision's diffstat output:
 xchat-chats.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 12 deletions(-)
-------------- next part --------------
============================================================
--- xchat-chats/xchat-chats.c	357ade9521604bc931686f71e4a20f5873cde36f
+++ xchat-chats/xchat-chats.c	bf3355fa9a6578f3c3562b65fdd26c5bc0aac97e
@@ -147,8 +147,15 @@ mg_word_check (GtkWidget * xtext, char *
 }
 #endif
 
-GtkWidget *get_xtext(PurpleConversation *conv)
+static gboolean
+is_2_4_0_or_above(void)
 {
+	return (purple_version_check(2, 4, 0) == NULL);
+}
+
+
+static GtkWidget *get_xtext(PurpleConversation *conv)
+{
 	PurpleXChat *gx;
 
 	if ((gx = g_hash_table_lookup(xchats, conv)) == NULL)
@@ -258,35 +265,44 @@ static void purple_xchat_write_conv(Purp
 	g_free(msg);
 }
 
+#define	DEBUG_INFO(x)	\
+	name = G_OBJECT_TYPE_NAME(x);	\
+	printf("%s\n", name)
+
 static GtkWidget*
 hack_and_get_widget(PidginConversation *gtkconv)
 {
-	GtkWidget *tab_cont, *pane, *vbox, *hpaned, *frame;
+	GtkWidget *tab_cont, *vbox, *hpaned, *frame;
 	GList *list;
 	const char *name;
 
 	/* If you think this is ugly, you are right. */
-#define	DEBUG_INFO(x)	\
-	name = G_OBJECT_TYPE_NAME(x);	\
-	printf("%s\n", name)
-	
 	tab_cont = gtkconv->tab_cont;
 	DEBUG_INFO(tab_cont);
 
 	list = gtk_container_get_children(GTK_CONTAINER(tab_cont));
-	pane = list->data;
+	if (!is_2_4_0_or_above()) {
+		GtkWidget *pane = list->data;
+		DEBUG_INFO(pane);
+
+		vbox = GTK_PANED(pane)->child1;
+	} else {
+		vbox = list->data;
+	}
 	g_list_free(list);
-	DEBUG_INFO(pane);
 
-	vbox = GTK_PANED(pane)->child1;
 	DEBUG_INFO(vbox);
 	list = GTK_BOX(vbox)->children;
-	while (list->next)
+	while (list) {
+		if (GTK_IS_PANED(((GtkBoxChild*)list->data)->widget))
+			break;
 		list = list->next;
+	}
 	hpaned = ((GtkBoxChild*)list->data)->widget;
 	DEBUG_INFO(hpaned);
 
 	frame = GTK_PANED(hpaned)->child1;
+
 	return frame;
 }
 
@@ -310,6 +326,7 @@ purple_conversation_use_xtext(PurpleConv
 
 	box = gtk_hbox_new(FALSE, 0);
 	xtext = get_xtext(conv);
+
 	GTK_PANED(parent)->child1 = NULL;
 	gtk_paned_pack1(GTK_PANED(parent), box, TRUE, TRUE);
 
@@ -345,6 +362,17 @@ purple_xchat_destroy_conv(PurpleConversa
 	}
 }
 
+static void
+workaround_for_hidden_convs(PidginConversation *gtkconv)
+{
+	PurpleConversation *conv = gtkconv->active_conv;
+
+	if (purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_CHAT ||
+			g_hash_table_lookup(xchats, conv))
+		return;
+	purple_conversation_use_xtext(conv);
+}
+
 static gboolean
 plugin_load(PurplePlugin *plugin)
 {
@@ -370,10 +398,17 @@ plugin_load(PurplePlugin *plugin)
 	list = purple_get_chats();
 	while (list)
 	{
+		/* TODO: We can get the message history of the conversation and populate
+		 * the next xtext with that data.
+		 * Note: purple_conversation_get_message_history
+		 */
 		purple_conversation_use_xtext(list->data);
 		list = list->next;
 	}
-	
+
+	purple_signal_connect(pidgin_conversations_get_handle(), "conversation-displayed",
+			plugin, G_CALLBACK(workaround_for_hidden_convs), NULL);
+
 	return TRUE;
 }
 
@@ -401,7 +436,7 @@ plugin_unload(PurplePlugin *plugin)
 	uiops->write_conv = default_write_conv;
 	uiops->create_conversation = default_create_conversation;
 	uiops->destroy_conversation = default_destroy_conversation;
-	
+
 	/* Clear up everything */
 	g_hash_table_foreach(xchats, (GHFunc)remove_xtext, NULL);
 	g_hash_table_destroy(xchats);


More information about the Plugins-commits mailing list