diff src/gtkconv.c @ 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 bc92c35db3e7
children bdd72261ec8c
line wrap: on
line diff
--- 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);
 	}