changeset 10849:c203cd637f95

[gaim-migrate @ 12521] sf patch #1185449, from Richard Laager "As the comment in gtkconv.c says, saving a duplicate copy of the entire conversation is completely bogus. Saving a copy of a conversation is a UI thing (if the UI is only showing the last five messages, for example, that's all the user would expect to be saved). Therefore, there's no problem having the UI save its own buffer. The GTK+ UI is already doing this with the imhtml object. This patch removes the history from GaimConversation and uses the buffer in the imhtml object when saving a conversation. It also adds <html>, <head>, <title>, and <body> tags to the file to make it a bit more valid. This patch is extremely likely to break plugins because it changes the size of the GaimConversation struct. As such, if this is committed, I recommend the developers recompile non-default plugins. This broke Gaim-Encryption for me, hence the warning." committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 19 Apr 2005 04:21:39 +0000
parents 98de05966d6d
children fa06fda62868
files plugins/ChangeLog.API src/conversation.c src/conversation.h src/gtkconv.c src/gtkimhtml.c
diffstat 5 files changed, 23 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Tue Apr 19 04:06:57 2005 +0000
+++ b/plugins/ChangeLog.API	Tue Apr 19 04:21:39 2005 +0000
@@ -44,6 +44,9 @@
 	           to use Gaim's built-in code for these purposes.
 	* Added:   GaimLogCommonLoggerData struct for a basic logger_data
 	           struct to be used with "common" logger functions.
+	* Removed: gaim_conversation_set_history, gaim_conversation_get_history,
+	           and GaimConversation->history.  Use gtk_imhtml_get_markup
+	           instead.
 
 	Signals:
 	* Changed: "received-im-msg and "received-chat-msg" to match, both
--- a/src/conversation.c	Tue Apr 19 04:06:57 2005 +0000
+++ b/src/conversation.c	Tue Apr 19 04:21:39 2005 +0000
@@ -695,7 +695,6 @@
 	conv->name         = g_strdup(name);
 	conv->title        = g_strdup(name);
 	conv->send_history = g_list_append(NULL, NULL);
-	conv->history      = g_string_new("");
 	conv->data         = g_hash_table_new_full(g_str_hash, g_str_equal,
 											   g_free, NULL);
 	conv->log          = gaim_log_new(type == GAIM_CONV_CHAT ? GAIM_LOG_CHAT :
@@ -877,10 +876,6 @@
 
 	g_list_free(g_list_first(conv->send_history));
 
-	if (conv->history != NULL)
-		g_string_free(conv->history, TRUE);
-	conv->history = NULL;
-
 	conversations = g_list_remove(conversations, conv);
 
 	if (conv->type == GAIM_CONV_IM) {
@@ -1176,22 +1171,6 @@
 	return conv->send_history;
 }
 
-void
-gaim_conversation_set_history(GaimConversation *conv, GString *history)
-{
-	g_return_if_fail(conv != NULL);
-
-	conv->history = history;
-}
-
-GString *
-gaim_conversation_get_history(const GaimConversation *conv)
-{
-	g_return_val_if_fail(conv != NULL, NULL);
-
-	return conv->history;
-}
-
 GaimConvWindow *
 gaim_conversation_get_window(const GaimConversation *conv)
 {
--- a/src/conversation.h	Tue Apr 19 04:06:57 2005 +0000
+++ b/src/conversation.h	Tue Apr 19 04:21:39 2005 +0000
@@ -291,7 +291,6 @@
 	GaimLog *log;               /**< This conversation's log            */
 
 	GList *send_history;        /**< The send history.                  */
-	GString *history;           /**< The conversation history.          */
 
 	GaimUnseenState unseen;     /**< The unseen tab state.              */
 
@@ -307,7 +306,7 @@
 	void *ui_data;                           /**< UI-specific data.       */
 
 	GHashTable *data;                        /**< Plugin-specific data.   */
-  
+
 	GaimConnectionFlags features; /**< The supported features */
 
 };
@@ -666,23 +665,6 @@
 GList *gaim_conversation_get_send_history(const GaimConversation *conv);
 
 /**
- * Sets the specified conversation's history.
- *
- * @param conv    The conversation.
- * @param history The history.
- */
-void gaim_conversation_set_history(GaimConversation *conv, GString *history);
-
-/**
- * Returns the specified conversation's history.
- *
- * @param conv The conversation.
- *
- * @return The conversation's history.
- */
-GString *gaim_conversation_get_history(const GaimConversation *conv);
-
-/**
  * Returns the specified conversation's parent window.
  *
  * @param conv The conversation.
--- a/src/gtkconv.c	Tue Apr 19 04:06:57 2005 +0000
+++ b/src/gtkconv.c	Tue Apr 19 04:21:39 2005 +0000
@@ -867,15 +867,13 @@
 	gaim_gtkdialogs_im();
 }
 
-/* XXX change how this works, unless someone can justify it, i think
- * it's really stupid, lets just grab the text from the imhtml, not
- * keep an extra copy of it! */
 static void
 savelog_writefile_cb(void *user_data, const char *filename)
 {
 	GaimConversation *conv = (GaimConversation *)user_data;
 	FILE *fp;
 	const char *name;
+	gchar *text;
 
 	if ((fp = g_fopen(filename, "w+")) == NULL) {
 		gaim_notify_error(conv, NULL, _("Unable to open file."), NULL);
@@ -883,11 +881,22 @@
 	}
 
 	name = gaim_conversation_get_name(conv);
+	fprintf(fp, "<html>\n<head><title>%s</title></head>\n<body>", name);
 	fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name);
-	fprintf(fp, "%s", conv->history->str);
+
+	text = gtk_imhtml_get_markup(
+		GTK_IMHTML(GAIM_GTK_CONVERSATION(conv)->imhtml));
+	fprintf(fp, "%s", text);
+	g_free(text);
+
+	fprintf(fp, "\n</body>\n</html>\n");
 	fclose(fp);
 }
 
+/*
+ * It would be kinda cool if this gave the option of saving a
+ * plaintext v. HTML file.
+ */
 static void
 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget)
 {
@@ -897,8 +906,8 @@
 
 	buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name));
 
-	gaim_request_file(conv, _("Save Conversation"), buf, TRUE,
-					  G_CALLBACK(savelog_writefile_cb), NULL, conv);
+	gaim_request_file(conv, _("Save Conversation"), gaim_escape_filename(buf),
+					  TRUE, G_CALLBACK(savelog_writefile_cb), NULL, conv);
 
 	g_free(buf);
 }
@@ -952,8 +961,6 @@
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
 
 	gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml));
-	g_string_free(conv->history, TRUE);
-	conv->history = g_string_new("");
 }
 
 struct _search {
@@ -1631,7 +1638,7 @@
 	int curconv;
 
 	gtkconv  = (GaimGtkConversation *)data;
-	conv     = gtkconv->active_conv;;
+	conv     = gtkconv->active_conv;
 	win      = gaim_conversation_get_window(conv);
 	gtkwin   = GAIM_GTK_WINDOW(win);
 	curconv = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook));
@@ -2475,7 +2482,7 @@
 static void
 remove_icon(GaimGtkConversation *gtkconv)
 {
-	GaimConversation *conv = gtkconv->active_conv;;
+	GaimConversation *conv = gtkconv->active_conv;
 	GaimGtkWindow *gtkwin;
 
 	g_return_if_fail(conv != NULL);
@@ -4807,10 +4814,6 @@
 
 		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0);
 
-		/* Add the message to a conversations scrollback buffer */
-		conv->history = g_string_append(conv->history, buf);
-		conv->history = g_string_append(conv->history, "<BR>\n");
-
 	} else if (flags & GAIM_MESSAGE_ERROR) {
 		g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"#ff0000\"><FONT SIZE=\"2\">(%s)</FONT> <B>%s</B></FONT>",
 				   mdate, message);
@@ -4821,9 +4824,6 @@
 
 		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0);
 
-		/* Add the message to a conversations scrollback buffer */
-		conv->history = g_string_append(conv->history, buf);
-		conv->history = g_string_append(conv->history, "<BR>\n");
 	} else if (flags & GAIM_MESSAGE_NO_LOG) {
 		g_snprintf(buf, BUF_LONG,
 			   "<B><FONT %s COLOR=\"#777777\">%s</FONT></B>",
@@ -4931,10 +4931,6 @@
 		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml),
 							 with_font_tag, gtk_font_options);
 
-		conv->history = g_string_append(conv->history, buf);
-		conv->history = g_string_append(conv->history, new_message);
-		conv->history = g_string_append(conv->history, "<BR>\n");
-
 		g_free(with_font_tag);
 		g_free(new_message);
 	}
--- a/src/gtkimhtml.c	Tue Apr 19 04:06:57 2005 +0000
+++ b/src/gtkimhtml.c	Tue Apr 19 04:21:39 2005 +0000
@@ -532,8 +532,8 @@
  * It's supposed to be fixed in gtk2.2.  You can view the bug report at
  * http://bugzilla.gnome.org/show_bug.cgi?id=107939
  */
-
-gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data)
+static gboolean
+gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data)
 {
 	if (event->state & GDK_CONTROL_MASK) {
 		switch (event->keyval) {