2010-03-26 [pawel] 3.7.5cvs40
[claws.git] / src / textview.c
index d3672e0cbfb544ad987f4ac87520e9f767b83a73..eda6c6f1ccaa0fde6611f67e65ef8240742fe744 100644 (file)
@@ -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);
@@ -832,7 +823,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 +849,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 +938,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);
@@ -1111,7 +1108,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 +1149,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 +1221,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 +1533,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 +1720,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 +1762,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 +1782,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 +1864,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 +1892,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 +1938,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 +2034,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 +2137,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) {
@@ -2682,6 +2683,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 +2695,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)) {
@@ -3037,9 +3042,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 +3070,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)