comparison 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
comparison
equal deleted inserted replaced
10848:98de05966d6d 10849:c203cd637f95
865 menu_new_conv_cb(gpointer data, guint action, GtkWidget *widget) 865 menu_new_conv_cb(gpointer data, guint action, GtkWidget *widget)
866 { 866 {
867 gaim_gtkdialogs_im(); 867 gaim_gtkdialogs_im();
868 } 868 }
869 869
870 /* XXX change how this works, unless someone can justify it, i think
871 * it's really stupid, lets just grab the text from the imhtml, not
872 * keep an extra copy of it! */
873 static void 870 static void
874 savelog_writefile_cb(void *user_data, const char *filename) 871 savelog_writefile_cb(void *user_data, const char *filename)
875 { 872 {
876 GaimConversation *conv = (GaimConversation *)user_data; 873 GaimConversation *conv = (GaimConversation *)user_data;
877 FILE *fp; 874 FILE *fp;
878 const char *name; 875 const char *name;
876 gchar *text;
879 877
880 if ((fp = g_fopen(filename, "w+")) == NULL) { 878 if ((fp = g_fopen(filename, "w+")) == NULL) {
881 gaim_notify_error(conv, NULL, _("Unable to open file."), NULL); 879 gaim_notify_error(conv, NULL, _("Unable to open file."), NULL);
882 return; 880 return;
883 } 881 }
884 882
885 name = gaim_conversation_get_name(conv); 883 name = gaim_conversation_get_name(conv);
884 fprintf(fp, "<html>\n<head><title>%s</title></head>\n<body>", name);
886 fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name); 885 fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name);
887 fprintf(fp, "%s", conv->history->str); 886
887 text = gtk_imhtml_get_markup(
888 GTK_IMHTML(GAIM_GTK_CONVERSATION(conv)->imhtml));
889 fprintf(fp, "%s", text);
890 g_free(text);
891
892 fprintf(fp, "\n</body>\n</html>\n");
888 fclose(fp); 893 fclose(fp);
889 } 894 }
890 895
896 /*
897 * It would be kinda cool if this gave the option of saving a
898 * plaintext v. HTML file.
899 */
891 static void 900 static void
892 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget) 901 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget)
893 { 902 {
894 GaimConvWindow *win = (GaimConvWindow *)data; 903 GaimConvWindow *win = (GaimConvWindow *)data;
895 GaimConversation *conv = gaim_conv_window_get_active_conversation(win); 904 GaimConversation *conv = gaim_conv_window_get_active_conversation(win);
896 gchar *buf; 905 gchar *buf;
897 906
898 buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name)); 907 buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name));
899 908
900 gaim_request_file(conv, _("Save Conversation"), buf, TRUE, 909 gaim_request_file(conv, _("Save Conversation"), gaim_escape_filename(buf),
901 G_CALLBACK(savelog_writefile_cb), NULL, conv); 910 TRUE, G_CALLBACK(savelog_writefile_cb), NULL, conv);
902 911
903 g_free(buf); 912 g_free(buf);
904 } 913 }
905 914
906 static void 915 static void
950 959
951 conv = gaim_conv_window_get_active_conversation(win); 960 conv = gaim_conv_window_get_active_conversation(win);
952 gtkconv = GAIM_GTK_CONVERSATION(conv); 961 gtkconv = GAIM_GTK_CONVERSATION(conv);
953 962
954 gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); 963 gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml));
955 g_string_free(conv->history, TRUE);
956 conv->history = g_string_new("");
957 } 964 }
958 965
959 struct _search { 966 struct _search {
960 GaimGtkConversation *gtkconv; 967 GaimGtkConversation *gtkconv;
961 GtkWidget *entry; 968 GtkWidget *entry;
1629 GaimGtkConversation *gtkconv; 1636 GaimGtkConversation *gtkconv;
1630 GaimGtkWindow *gtkwin; 1637 GaimGtkWindow *gtkwin;
1631 int curconv; 1638 int curconv;
1632 1639
1633 gtkconv = (GaimGtkConversation *)data; 1640 gtkconv = (GaimGtkConversation *)data;
1634 conv = gtkconv->active_conv;; 1641 conv = gtkconv->active_conv;
1635 win = gaim_conversation_get_window(conv); 1642 win = gaim_conversation_get_window(conv);
1636 gtkwin = GAIM_GTK_WINDOW(win); 1643 gtkwin = GAIM_GTK_WINDOW(win);
1637 curconv = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)); 1644 curconv = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook));
1638 1645
1639 /* If CTRL was held down... */ 1646 /* If CTRL was held down... */
2473 } 2480 }
2474 2481
2475 static void 2482 static void
2476 remove_icon(GaimGtkConversation *gtkconv) 2483 remove_icon(GaimGtkConversation *gtkconv)
2477 { 2484 {
2478 GaimConversation *conv = gtkconv->active_conv;; 2485 GaimConversation *conv = gtkconv->active_conv;
2479 GaimGtkWindow *gtkwin; 2486 GaimGtkWindow *gtkwin;
2480 2487
2481 g_return_if_fail(conv != NULL); 2488 g_return_if_fail(conv != NULL);
2482 2489
2483 if (gtkconv->u.im->icon_container != NULL) 2490 if (gtkconv->u.im->icon_container != NULL)
4805 "<FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT>", 4812 "<FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT>",
4806 sml_attrib, mdate, message); 4813 sml_attrib, mdate, message);
4807 4814
4808 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0); 4815 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0);
4809 4816
4810 /* Add the message to a conversations scrollback buffer */
4811 conv->history = g_string_append(conv->history, buf);
4812 conv->history = g_string_append(conv->history, "<BR>\n");
4813
4814 } else if (flags & GAIM_MESSAGE_ERROR) { 4817 } else if (flags & GAIM_MESSAGE_ERROR) {
4815 g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"#ff0000\"><FONT SIZE=\"2\">(%s)</FONT> <B>%s</B></FONT>", 4818 g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"#ff0000\"><FONT SIZE=\"2\">(%s)</FONT> <B>%s</B></FONT>",
4816 mdate, message); 4819 mdate, message);
4817 4820
4818 g_snprintf(buf2, sizeof(buf2), 4821 g_snprintf(buf2, sizeof(buf2),
4819 "<FONT COLOR=\"#ff0000\"><FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT></FONT>", 4822 "<FONT COLOR=\"#ff0000\"><FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT></FONT>",
4820 sml_attrib, mdate, message); 4823 sml_attrib, mdate, message);
4821 4824
4822 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0); 4825 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0);
4823 4826
4824 /* Add the message to a conversations scrollback buffer */
4825 conv->history = g_string_append(conv->history, buf);
4826 conv->history = g_string_append(conv->history, "<BR>\n");
4827 } else if (flags & GAIM_MESSAGE_NO_LOG) { 4827 } else if (flags & GAIM_MESSAGE_NO_LOG) {
4828 g_snprintf(buf, BUF_LONG, 4828 g_snprintf(buf, BUF_LONG,
4829 "<B><FONT %s COLOR=\"#777777\">%s</FONT></B>", 4829 "<B><FONT %s COLOR=\"#777777\">%s</FONT></B>",
4830 sml_attrib, message); 4830 sml_attrib, message);
4831 4831
4929 with_font_tag = g_memdup(new_message, length); 4929 with_font_tag = g_memdup(new_message, length);
4930 4930
4931 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), 4931 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml),
4932 with_font_tag, gtk_font_options); 4932 with_font_tag, gtk_font_options);
4933 4933
4934 conv->history = g_string_append(conv->history, buf);
4935 conv->history = g_string_append(conv->history, new_message);
4936 conv->history = g_string_append(conv->history, "<BR>\n");
4937
4938 g_free(with_font_tag); 4934 g_free(with_font_tag);
4939 g_free(new_message); 4935 g_free(new_message);
4940 } 4936 }
4941 4937
4942 4938