2010-12-21 [colin] 3.7.8cvs16
[claws.git] / src / textview.c
index 4abc0dbc65a62ff79b98348dda618ce7c5af44a1..b2d334a684a081940f6f74ebc2c691373ec24f09 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -191,6 +191,8 @@ static void copy_uri_cb                             (GtkAction      *action,
                                                 TextView       *textview);
 static void add_uri_to_addrbook_cb             (GtkAction      *action,
                                                 TextView       *textview);
+static void reply_to_uri_cb                    (GtkAction      *action,
+                                                TextView       *textview);
 static void mail_to_uri_cb                     (GtkAction      *action,
                                                 TextView       *textview);
 static void copy_mail_to_uri_cb                        (GtkAction      *action,
@@ -212,6 +214,7 @@ static GtkActionEntry textview_mail_popup_entries[] =
 {
        {"TextviewPopupMail",                   NULL, "TextviewPopupMail" },
        {"TextviewPopupMail/Compose",           NULL, N_("Compose _new message"), NULL, NULL, G_CALLBACK(mail_to_uri_cb) },
+       {"TextviewPopupMail/ReplyTo",           NULL, N_("_Reply to this address"), NULL, NULL, G_CALLBACK(reply_to_uri_cb) },
        {"TextviewPopupMail/AddAB",             NULL, N_("Add to _Address book"), NULL, NULL, G_CALLBACK(add_uri_to_addrbook_cb) },
        {"TextviewPopupMail/Copy",              NULL, N_("Copy this add_ress"), NULL, NULL, G_CALLBACK(copy_mail_to_uri_cb) },
 };
@@ -342,6 +345,8 @@ TextView *textview_create(void)
                        "/Menus/TextviewPopupLink", "Copy", "TextviewPopupLink/Copy", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
                        "/Menus/TextviewPopupMail", "Compose", "TextviewPopupMail/Compose", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupMail", "ReplyTo", "TextviewPopupMail/ReplyTo", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
                        "/Menus/TextviewPopupMail", "AddAB", "TextviewPopupMail/AddAB", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
@@ -452,16 +457,10 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                "foreground-gdk", &quote_colors[2],
                                NULL);
        }
-#if GTK_CHECK_VERSION(2, 8, 0)
        gtk_text_buffer_create_tag(buffer, "tags",
                        "foreground-gdk", &black,
                        "paragraph-background-gdk", &yellow,
                        NULL);
-#else
-       gtk_text_buffer_create_tag(buffer, "tags",
-                       "foreground-gdk", &emphasis_color,
-                       NULL);
-#endif
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
                        NULL);
@@ -501,19 +500,11 @@ void textview_init(TextView *textview)
        textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
 }
 
-#if GTK_CHECK_VERSION(2, 8, 0)
  #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
        tag = gtk_text_tag_table_lookup(tags, tagname); \
        if (tag) \
                g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, "paragraph-background-gdk", colorbg, NULL); \
  }
-#else
- #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
-       tag = gtk_text_tag_table_lookup(tags, tagname); \
-       if (tag) \
-               g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, NULL); \
- }
-#endif
 
 static void textview_update_message_colors(TextView *textview)
 {
@@ -576,8 +567,8 @@ void textview_reflect_prefs(TextView *textview)
 void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
 {
        START_TIMING("");
-       g_return_if_fail(mimeinfo != NULL);
-       g_return_if_fail(fp != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(fp != NULL);
 
        if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
            ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
@@ -622,7 +613,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        gint charcount;
        START_TIMING("");
 
-       g_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
        text = GTK_TEXT_VIEW(textview->text);
        buffer = gtk_text_view_get_buffer(text);
        charcount = gtk_text_buffer_get_char_count(buffer);
@@ -720,6 +711,9 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                else
                                        pixbuf = gdk_pixbuf_new_from_file(filename, &error);
                        }
+                       if (textview->stop_loading) {
+                               return;
+                       }
                        if (error != NULL) {
                                g_warning("%s\n", error->message);
                                g_error_free(error);
@@ -738,7 +732,10 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                uri->start = gtk_text_iter_get_offset(&iter);
                                
                                gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
-                               
+                               if (textview->stop_loading) {
+                                       g_free(uri);
+                                       return;
+                               }
                                uri->end = uri->start + 1;
                                uri->filename = procmime_get_part_file_name(mimeinfo);
                                textview->uri_list =
@@ -750,6 +747,10 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                                &start_iter, &iter);
                        } else {
                                gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+                               if (textview->stop_loading) {
+                                       g_free(uri);
+                                       return;
+                               }
                                gtk_text_buffer_insert(buffer, &iter, " ", 1);
                        }
 
@@ -832,7 +833,7 @@ static void recursive_add_parts(TextView *textview, GNode *node)
 
 static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo)
 {
-       g_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
         
         recursive_add_parts(textview, mimeinfo->node);
 }
@@ -858,7 +859,6 @@ void textview_show_error(TextView *textview)
        TEXTVIEW_INSERT_LINK(_("'View Log'"), "sc://view_log", NULL);
        TEXTVIEW_INSERT(_(" in the Tools menu for more information."));
        textview_show_icon(textview, GTK_STOCK_DIALOG_ERROR);
-
 }
 
 void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
@@ -948,9 +948,16 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        if (textview->messageview->forced_charset)
                charset = textview->messageview->forced_charset;
        else {
+               /* use supersets transparently when possible */
                charset = procmime_mimeinfo_get_parameter(mimeinfo, "charset");
                if (charset && !strcasecmp(charset, CS_ISO_8859_1))
                        charset = CS_WINDOWS_1252;
+               else if (charset && !strcasecmp(charset, CS_X_GBK))
+                       charset = CS_GB18030;
+               else if (charset && !strcasecmp(charset, CS_GBK))
+                       charset = CS_GB18030;
+               else if (charset && !strcasecmp(charset, CS_GB2312))
+                       charset = CS_GB18030;
        }
 
        textview_set_font(textview, charset);
@@ -1021,7 +1028,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        argv = strsplit_with_quote(buf, " ", 0);
                        close(1);
                        close(pfd[0]);
-                       dup(pfd[1]);
+                       rc = dup(pfd[1]);
                        rc = execvp(argv[0], argv);
                        close(pfd[1]);
                        g_print(_("The command to view attachment "
@@ -1111,7 +1118,7 @@ static void textview_show_html(TextView *textview, FILE *fp,
        gint lines = 0;
 
        parser = sc_html_parser_new(fp, conv);
-       g_return_if_fail(parser != NULL);
+       cm_return_if_fail(parser != NULL);
 
        while ((str = sc_html_parse(parser)) != NULL) {
                if (parser->state == SC_HTML_HREF) {
@@ -1152,7 +1159,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
        gint lines = 0;
 
        parser = ertf_parser_new(fp, conv);
-       g_return_if_fail(parser != NULL);
+       cm_return_if_fail(parser != NULL);
 
        while ((str = ertf_parse(parser)) != NULL) {
                textview_write_line(textview, str, NULL, FALSE);
@@ -1224,6 +1231,7 @@ static void textview_make_clickable_parts(TextView *textview,
                {"https://", strcasestr, get_uri_part,   make_uri_string},
                {"ftp://",   strcasestr, get_uri_part,   make_uri_string},
                {"sftp://",  strcasestr, get_uri_part,   make_uri_string},
+               {"gopher://",strcasestr, get_uri_part,   make_uri_string},
                {"www.",     strcasestr, get_uri_part,   make_http_string},
                {"mailto:",  strcasestr, get_uri_part,   make_uri_string},
                {"@",        strcasestr, get_email_part, make_email_string}
@@ -1535,16 +1543,18 @@ do_quote:
                        } else {
                                g_print("oops (%d %d)\n",
                                        real_quotelevel, textview->prev_quote_level);
-                       }               
-                       if (lasturi->is_quote == FALSE) {
-                               textview->prev_quote_level = -1;
-                               goto do_quote;
+                       }       
+                       if (lasturi) {  
+                               if (lasturi->is_quote == FALSE) {
+                                       textview->prev_quote_level = -1;
+                                       goto do_quote;
+                               }
+                               e_len = lasturi->data ? strlen(lasturi->data):0;
+                               n_len = strlen(buf);
+                               lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
+                               strcpy((gchar *)lasturi->data + e_len, buf);
+                               *((gchar *)lasturi->data + e_len + n_len) = '\0';
                        }
-                       e_len = lasturi->data ? strlen(lasturi->data):0;
-                       n_len = strlen(buf);
-                       lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
-                       strcpy((gchar *)lasturi->data + e_len, buf);
-                       *((gchar *)lasturi->data + e_len + n_len) = '\0';
                }
        } else {
                textview_make_clickable_parts(textview, fg_color, "link", buf, FALSE);
@@ -1720,8 +1730,8 @@ void textview_set_text(TextView *textview, const gchar *text)
        GtkTextView *view;
        GtkTextBuffer *buffer;
 
-       g_return_if_fail(textview != NULL);
-       g_return_if_fail(text != NULL);
+       cm_return_if_fail(textview != NULL);
+       cm_return_if_fail(text != NULL);
 
        textview_clear(textview);
 
@@ -1762,6 +1772,7 @@ static gboolean header_is_internal(Header *header)
                 "X-Claws-Account-Id:", "X-Claws-Sign:", "X-Claws-Encrypt:", 
                 "X-Claws-Privacy-System:", "X-Claws-End-Special-Headers:",
                 "X-Sylpheed-Account-Id:", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt:", 
+                "X-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
                 "X-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
                 NULL};
        int i;
@@ -1781,7 +1792,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        Header *header;
        gint i;
 
-       g_return_val_if_fail(fp != NULL, NULL);
+       cm_return_val_if_fail(fp != NULL, NULL);
 
        if (textview->show_all_headers) {
                headers = procheader_get_header_array_asis(fp);
@@ -1863,7 +1874,7 @@ static void textview_show_face(TextView *textview)
                gtk_widget_destroy(textview->image);
        
        textview->image = face_get_from_header(msginfo->extradata->face);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -1891,7 +1902,7 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
                gtk_widget_destroy(textview->image);
        
        textview->image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -1937,7 +1948,7 @@ static void textview_show_xface(TextView *textview)
        textview->image = xface_get_from_header(msginfo->extradata->xface,
                                &textview->text->style->white,
                                window);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -2033,7 +2044,7 @@ static void textview_show_contact_pic(TextView *textview)
                textview->image = gtk_image_new_from_pixbuf(picture);
                g_object_unref(picture);
        }
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -2136,11 +2147,11 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
        Header *header;
        gint i;
 
-       g_return_if_fail(headers != NULL);
+       cm_return_if_fail(headers != NULL);
 
        for (i = 0; i < headers->len; i++) {
                header = g_ptr_array_index(headers, i);
-               g_return_if_fail(header->name != NULL);
+               cm_return_if_fail(header->name != NULL);
 
                gtk_text_buffer_get_end_iter (buffer, &iter);
                if(prefs_common.trans_hdr == TRUE) {
@@ -2669,7 +2680,8 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } 
                        return TRUE;
                } else if (qlink && bevent->button == 1) {
-                       textview_toggle_quote(textview, NULL, uri, FALSE);
+                       if (prefs_common.hide_quoted)
+                               textview_toggle_quote(textview, NULL, uri, FALSE);
                        return TRUE;
                } else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
                        if (bevent->button == 3) {
@@ -2682,6 +2694,8 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } else {
                                PrefsAccount *account = NULL;
                                FolderItem   *folder_item = NULL;
+                               Compose *compose;
+                               
                                if (textview->messageview && textview->messageview->msginfo &&
                                    textview->messageview->msginfo->folder) {
                                        
@@ -2692,7 +2706,9 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                                        if (!account)
                                                account = account_find_from_item(folder_item);
                                }
-                               compose_new_with_folderitem(account, folder_item, uri->uri + 7);
+                               compose = compose_new_with_folderitem(account,
+                                                               folder_item, uri->uri + 7);
+                               compose_check_for_email_account(compose);
                        }
                        return TRUE;
                } else if (g_ascii_strncasecmp(uri->uri, "file:", 5)) {
@@ -2927,7 +2943,7 @@ static void save_file_cb (GtkAction *action, TextView *textview)
 
        subst_for_filename(filename);
        
-       if (prefs_common.attach_save_dir)
+       if (prefs_common.attach_save_dir && *prefs_common.attach_save_dir)
                filepath = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, filename, NULL);
        else
@@ -3037,9 +3053,21 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        g_free(fromname);
 }
 
+static void reply_to_uri_cb (GtkAction *action, TextView *textview)
+{
+       ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+                                          "menu_button");
+       if (!textview->messageview || !uri)
+               return;
+
+       compose_reply_to_address (textview->messageview,
+                                 textview->messageview->msginfo, uri->uri+7);
+}
+
 static void mail_to_uri_cb (GtkAction *action, TextView *textview)
 {
        PrefsAccount *account = NULL;
+       Compose *compose;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");
        if (uri == NULL)
@@ -3053,10 +3081,11 @@ static void mail_to_uri_cb (GtkAction *action, TextView *textview)
                if (folder_item->prefs && folder_item->prefs->enable_default_account)
                        account = account_find_from_id(folder_item->prefs->default_account);
                
-               compose_new_with_folderitem(account, folder_item, uri->uri+7);
+               compose = compose_new_with_folderitem(account, folder_item, uri->uri+7);
        } else {
-               compose_new(account, uri->uri + 7, NULL);
+               compose = compose_new(account, uri->uri + 7, NULL);
        }
+       compose_check_for_email_account(compose);
 }
 
 static void copy_mail_to_uri_cb        (GtkAction *action, TextView *textview)