changeset 31894:a9e077fb65e9

Add a cleared-message-history conversation signal, and use it in Pidgin and Finch This stems out of an email discussion with Andrew Victor back in July 2010 regarding letting protocol plugins clear the message scrollback area for UIs. At the time, nobody objected to having the libpurple-clearing function call the UI clearing function. This should also be happily backward-compatible.
author Paul Aurich <paul@darkrain42.org>
date Thu, 31 Mar 2011 04:41:27 +0000
parents 1551c9a140fd
children 8b9e9c61d061 0123005d0fb8 9e9abd65b840
files ChangeLog.API doc/conversation-signals.dox finch/gntconv.c libpurple/conversation.c pidgin/gtkconv.c
diffstat 5 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Wed Mar 30 22:36:30 2011 +0000
+++ b/ChangeLog.API	Thu Mar 31 04:41:27 2011 +0000
@@ -5,6 +5,7 @@
 		Added:
 		* account-authorization-requested-with-message signal (Stefan Ott)
 		  (#8690)
+		* cleared-message-history signal (conversation signals)
 		* purple_account_add_buddy_with_invite
 		* purple_account_add_buddies_with_invite
 		* purple_notify_user_info_add_pair_plaintext
--- a/doc/conversation-signals.dox	Wed Mar 30 22:36:30 2011 +0000
+++ b/doc/conversation-signals.dox	Thu Mar 31 04:41:27 2011 +0000
@@ -32,6 +32,7 @@
   @signal chat-join-failed
   @signal chat-left
   @signal chat-topic-changed
+  @signal cleared-message-history
   @signal conversation-extended-menu
   @signal sent-attention
   @signal got-attention
@@ -479,6 +480,16 @@
   @since 2.1.0
  @endsignaldef
 
+ @signaldef cleared-message-history
+  @signalproto
+void (*cleared_message_history)(PurpleConversation *conv);
+  @endsignalproto
+  @signaldesc
+    Emitted when the conversation history is cleared.
+  @param conv   The conversation.
+  @since 2.8.0
+ @endsignaldef
+
  @signaldef sent-attention
   @signalproto
 void (*got_attention)(PurpleAccount *account, const char *who, 
--- a/finch/gntconv.c	Wed Mar 30 22:36:30 2011 +0000
+++ b/finch/gntconv.c	Thu Mar 31 04:41:27 2011 +0000
@@ -396,10 +396,18 @@
 }
 
 static void
+cleared_message_history_cb(PurpleConversation *conv, gpointer data)
+{
+	FinchConv *ggc = FINCH_GET_DATA(conv);
+	if (ggc)
+		gnt_text_view_clear(GNT_TEXT_VIEW(ggc->tv));
+}
+
+static void
 clear_scrollback_cb(GntMenuItem *item, gpointer ggconv)
 {
 	FinchConv *ggc = ggconv;
-	gnt_text_view_clear(GNT_TEXT_VIEW(ggc->tv));
+	purple_conversation_clear_message_history(ggc->active_conv);
 }
 
 static void
@@ -1264,8 +1272,6 @@
 clear_command_cb(PurpleConversation *conv,
                  const char *cmd, char **args, char **error, void *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_RET_OK;
 }
@@ -1459,6 +1465,8 @@
 					PURPLE_CALLBACK(update_buddy_typing), NULL);
 	purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(),
 					PURPLE_CALLBACK(chat_left_cb), NULL);
+	purple_signal_connect(purple_conversations_get_handle(), "cleared-message-history", finch_conv_get_handle(),
+					PURPLE_CALLBACK(cleared_message_history_cb), NULL);
 	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", finch_conv_get_handle(),
 					PURPLE_CALLBACK(buddy_signed_on_off), NULL);
 	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", finch_conv_get_handle(),
--- a/libpurple/conversation.c	Wed Mar 30 22:36:30 2011 +0000
+++ b/libpurple/conversation.c	Thu Mar 31 04:41:27 2011 +0000
@@ -575,6 +575,7 @@
 
 	if (ops != NULL && ops->destroy_conversation != NULL)
 		ops->destroy_conversation(conv);
+	conv->ui_data = NULL;
 
 	purple_conversation_close_logs(conv);
 
@@ -2270,6 +2271,9 @@
 	GList *list = conv->message_history;
 	message_history_free(list);
 	conv->message_history = NULL;
+
+	purple_signal_emit(purple_conversations_get_handle(),
+			"cleared-message-history", conv);
 }
 
 GList *purple_conversation_get_message_history(PurpleConversation *conv)
@@ -2626,6 +2630,11 @@
 						 purple_value_new(PURPLE_TYPE_STRING),
 						 purple_value_new(PURPLE_TYPE_STRING));
 
+	purple_signal_register(handle, "cleared-message-history",
+	                       purple_marshal_VOID__POINTER, NULL, 1,
+	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
+	                                        PURPLE_SUBTYPE_CONVERSATION));
+
 	purple_signal_register(handle, "conversation-extended-menu",
 			     purple_marshal_VOID__POINTER_POINTER, NULL, 2,
 			     purple_value_new(PURPLE_TYPE_SUBTYPE,
--- a/pidgin/gtkconv.c	Wed Mar 30 22:36:30 2011 +0000
+++ b/pidgin/gtkconv.c	Thu Mar 31 04:41:27 2011 +0000
@@ -373,23 +373,21 @@
 	return PURPLE_CMD_RET_OK;
 }
 
-static void clear_conversation_scrollback(PurpleConversation *conv)
+static void clear_conversation_scrollback_cb(PurpleConversation *conv,
+                                             void *data)
 {
 	PidginConversation *gtkconv = NULL;
-	GList *iter;
 
 	gtkconv = PIDGIN_CONVERSATION(conv);
-
-	gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml));
-	for (iter = gtkconv->convs; iter; iter = iter->next)
-		purple_conversation_clear_message_history(iter->data);
+	if (gtkconv)
+		gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml));
 }
 
 static PurpleCmdRet
 clear_command_cb(PurpleConversation *conv,
                  const char *cmd, char **args, char **error, void *data)
 {
-	clear_conversation_scrollback(conv);
+	purple_conversation_clear_message_history(conv);
 	return PURPLE_CMD_RET_OK;
 }
 
@@ -397,7 +395,7 @@
 clearall_command_cb(PurpleConversation *conv,
                  const char *cmd, char **args, char **error, void *data)
 {
-	purple_conversation_foreach(clear_conversation_scrollback);
+	purple_conversation_foreach(purple_conversation_clear_message_history);
 	return PURPLE_CMD_RET_OK;
 }
 
@@ -1113,7 +1111,7 @@
 	PurpleConversation *conv;
 
 	conv = pidgin_conv_window_get_active_conversation(win);
-	clear_conversation_scrollback(conv);
+	purple_conversation_clear_message_history(conv);
 }
 
 static void
@@ -8042,6 +8040,8 @@
 
 	purple_signal_connect(purple_conversations_get_handle(), "received-im-msg",
 						handle, G_CALLBACK(received_im_msg_cb), NULL);
+	purple_signal_connect(purple_conversations_get_handle(), "cleared-message-history",
+	                      handle, G_CALLBACK(clear_conversation_scrollback_cb), NULL);
 
 	purple_conversations_set_ui_ops(&conversation_ui_ops);