changeset 13838:dd00149f6f9b

[gaim-migrate @ 16287] SF Patch #1503847 from Sadrul "This patch "contactizes" the send history in a conversation, ie. with this patch you can get the previously sent messages by pressing ctrl+up/down after switching the account during a contactized conversation." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 19 Jun 2006 06:31:11 +0000
parents 1a095ac881ce
children 2bd34a419091
files plugins/ChangeLog.API plugins/perl/common/Conversation.xs src/conversation.c src/conversation.h src/gtkconv.c src/gtkconv.h
diffstat 6 files changed, 27 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Mon Jun 19 06:27:18 2006 +0000
+++ b/plugins/ChangeLog.API	Mon Jun 19 06:31:11 2006 +0000
@@ -173,6 +173,8 @@
 	* GAIM_MESSAGE_COLORIZE
 	* user_data from gaim_notify_searchresults_new_rows and from 
 	  notify_searchresults in GaimNotifyUiOps.
+	* gaim_conversation_get_send_history(), and send_history from
+	  GaimConversation
 
 	Added:
 	* gaim_prefs_disconnect_by_handle()
--- a/plugins/perl/common/Conversation.xs	Mon Jun 19 06:27:18 2006 +0000
+++ b/plugins/perl/common/Conversation.xs	Mon Jun 19 06:31:11 2006 +0000
@@ -46,16 +46,6 @@
 PROTOTYPES: ENABLE
 
 void
-gaim_conversation_get_send_history(conv)
-	Gaim::Conversation conv
-PREINIT:
-	GList *l;
-PPCODE:
-	for (l = gaim_conversation_get_send_history(conv); l != NULL; l = l->next) {
-		XPUSHs(sv_2mortal(newSVpv(l->data, 0)));
-	}
-
-void
 gaim_conversation_destroy(conv)
 	Gaim::Conversation conv
 
--- a/src/conversation.c	Mon Jun 19 06:27:18 2006 +0000
+++ b/src/conversation.c	Mon Jun 19 06:31:11 2006 +0000
@@ -263,7 +263,6 @@
 	conv->account      = account;
 	conv->name         = g_strdup(name);
 	conv->title        = g_strdup(name);
-	conv->send_history = g_list_append(NULL, NULL);
 	conv->data         = g_hash_table_new_full(g_str_hash, g_str_equal,
 											   g_free, NULL);
 	/* copy features from the connection. */
@@ -419,17 +418,6 @@
 	conv->name = NULL;
 	conv->title = NULL;
 
-	for (node = g_list_first(conv->send_history);
-		 node != NULL;
-		 node = g_list_next(node)) {
-
-		if (node->data != NULL)
-			g_free(node->data);
-		node->data = NULL;
-	}
-
-	g_list_free(g_list_first(conv->send_history));
-
 	if (conv->type == GAIM_CONV_TYPE_IM) {
 		gaim_conv_im_stop_typing_timeout(conv->u.im);
 		gaim_conv_im_stop_type_again_timeout(conv->u.im);
@@ -708,14 +696,6 @@
 	conv->logs = NULL;
 }
 
-GList *
-gaim_conversation_get_send_history(const GaimConversation *conv)
-{
-	g_return_val_if_fail(conv != NULL, NULL);
-
-	return conv->send_history;
-}
-
 GaimConvIm *
 gaim_conversation_get_im_data(const GaimConversation *conv)
 {
--- a/src/conversation.h	Mon Jun 19 06:27:18 2006 +0000
+++ b/src/conversation.h	Mon Jun 19 06:31:11 2006 +0000
@@ -236,8 +236,6 @@
 
 	GList *logs;                /**< This conversation's logs           */
 
-	GList *send_history;        /**< The send history.                  */
-
 	union
 	{
 		GaimConvIm   *im;       /**< IM-specific data.                  */
@@ -441,15 +439,6 @@
 void gaim_conversation_close_logs(GaimConversation *conv);
 
 /**
- * Returns the specified conversation's send history.
- *
- * @param conv The conversation.
- *
- * @return The conversation's send history.
- */
-GList *gaim_conversation_get_send_history(const GaimConversation *conv);
-
-/**
  * Returns the specified conversation's IM-specific data.
  *
  * If the conversation type is not GAIM_CONV_TYPE_IM, this will return @c NULL.
--- a/src/gtkconv.c	Mon Jun 19 06:27:18 2006 +0000
+++ b/src/gtkconv.c	Mon Jun 19 06:31:11 2006 +0000
@@ -427,18 +427,14 @@
 }
 
 static void
-send_history_add(GaimConversation *conv, const char *message)
+send_history_add(GaimGtkConversation *gtkconv, const char *message)
 {
 	GList *first;
 
-	first = g_list_first(conv->send_history);
-
-	if (first->data)
-		g_free(first->data);
-
+	first = g_list_first(gtkconv->send_history);
+	g_free(first->data);
 	first->data = g_strdup(message);
-
-	conv->send_history = g_list_prepend(first, NULL);
+	gtkconv->send_history = g_list_prepend(first, NULL);
 }
 
 static gboolean
@@ -462,7 +458,7 @@
 		GtkTextIter end;
 
 		send_history = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
-		send_history_add(conv, send_history);
+		send_history_add(gtkconv, send_history);
 		g_free(send_history);
 
 		cmdline = cmd + strlen(prefix);
@@ -562,7 +558,7 @@
 
 		bufs = gtk_imhtml_get_markup_lines(GTK_IMHTML(gtkconv->entry));
 		for (i = 0; bufs[i]; i++) {
-			send_history_add(conv, bufs[i]);
+			send_history_add(gtkconv, bufs[i]);
 			if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
 				gaim_conv_im_send_with_flags(GAIM_CONV_IM(conv), bufs[i], flags);
 			else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
@@ -572,7 +568,7 @@
 		g_strfreev(bufs);
 
 	} else {
-		send_history_add(conv, buf);
+		send_history_add(gtkconv, buf);
 		if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
 			gaim_conv_im_send_with_flags(GAIM_CONV_IM(conv), buf, flags);
 		else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
@@ -1787,29 +1783,28 @@
 	if (event->state & GDK_CONTROL_MASK) {
 		switch (event->keyval) {
 			case GDK_Up:
-				if (!conv->send_history)
+				if (!gtkconv->send_history)
 					break;
 
-				if (!conv->send_history->prev) {
+				if (!gtkconv->send_history->prev) {
 					GtkTextIter start, end;
 
-					if (conv->send_history->data)
-						g_free(conv->send_history->data);
+					g_free(gtkconv->send_history->data);
 
 					gtk_text_buffer_get_start_iter(gtkconv->entry_buffer,
 												   &start);
 					gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end);
 
-					conv->send_history->data =
+					gtkconv->send_history->data =
 						gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
 				}
 
-				if (conv->send_history->next && conv->send_history->next->data) {
+				if (gtkconv->send_history->next && gtkconv->send_history->next->data) {
 					GObject *object;
 					GtkTextIter iter;
 					GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
 
-					conv->send_history = conv->send_history->next;
+					gtkconv->send_history = gtkconv->send_history->next;
 
 					/* Block the signal to prevent application of default formatting. */
 					object = g_object_ref(G_OBJECT(gtkconv->entry));
@@ -1824,7 +1819,7 @@
 
 					gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
 					gtk_imhtml_append_text_with_images(
-						GTK_IMHTML(gtkconv->entry), conv->send_history->data,
+						GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data,
 						0, NULL);
 					/* this is mainly just a hack so the formatting at the
 					 * cursor gets picked up. */
@@ -1836,15 +1831,15 @@
 				break;
 
 			case GDK_Down:
-				if (!conv->send_history)
+				if (!gtkconv->send_history)
 					break;
 
-				if (conv->send_history->prev &&	conv->send_history->prev->data) {
+				if (gtkconv->send_history->prev && gtkconv->send_history->prev->data) {
 					GObject *object;
 					GtkTextIter iter;
 					GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
 
-					conv->send_history = conv->send_history->prev;
+					gtkconv->send_history = gtkconv->send_history->prev;
 
 					/* Block the signal to prevent application of default formatting. */
 					object = g_object_ref(G_OBJECT(gtkconv->entry));
@@ -1859,11 +1854,11 @@
 
 					gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
 					gtk_imhtml_append_text_with_images(
-						GTK_IMHTML(gtkconv->entry), conv->send_history->data,
+						GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data,
 						0, NULL);
 					/* this is mainly just a hack so the formatting at the
 					 * cursor gets picked up. */
-					if (*(char *)conv->send_history->data) {
+					if (*(char *)gtkconv->send_history->data) {
 						gtk_text_buffer_get_end_iter(buffer, &iter);
 						gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter);
 					} else {
@@ -4347,6 +4342,7 @@
 	conv->ui_data = gtkconv;
 	gtkconv->active_conv = conv;
 	gtkconv->convs = g_list_prepend(gtkconv->convs, conv);
+	gtkconv->send_history = g_list_append(NULL, NULL);
 
 	/* Setup some initial variables. */
 	gtkconv->sg       = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
@@ -4515,6 +4511,10 @@
 
 	gtk_object_sink(GTK_OBJECT(gtkconv->tooltips));
 
+	gtkconv->send_history = g_list_first(gtkconv->send_history);
+	g_list_foreach(gtkconv->send_history, (GFunc)g_free, NULL);
+	g_list_free(gtkconv->send_history);
+
 	g_free(gtkconv);
 }
 
--- a/src/gtkconv.h	Mon Jun 19 06:27:18 2006 +0000
+++ b/src/gtkconv.h	Mon Jun 19 06:31:11 2006 +0000
@@ -114,6 +114,7 @@
 {
 	GaimConversation *active_conv;
 	GList *convs;
+	GList *send_history;
 
 	GaimGtkWindow *win;