2007-02-01 [colin] 2.7.2cvs10
[claws.git] / src / textview.c
index 8af9f77996464d71b34b24520ded66d1f89daf38..8fe69e1df0b69f8c593ece70c03a0f54641a0f25 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
+ * Copyright (C) 1999-2007 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
@@ -657,12 +657,13 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        gchar *filename;
                        ClickableText *uri;
                        gchar *uri_str;
+                       gint err;
                        START_TIMING("inserting image");
 
                        filename = procmime_get_tmp_file_name(mimeinfo);
 
-                       if (procmime_get_part(filename, mimeinfo) < 0) {
-                               g_warning("Can't get the image file.");
+                       if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
+                               g_warning("Can't get the image file.(%s)", strerror(-err));
                                g_free(filename);
                                END_TIMING();
                                return;
@@ -673,7 +674,8 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        } else {
                                gint w, h;
                                gdk_pixbuf_get_file_info(filename, &w, &h);
-                               if (w > textview->scrolledwin->allocation.width - 100)
+                               if (textview->scrolledwin->allocation.width - 100 > 0 &&
+                                   w > textview->scrolledwin->allocation.width - 100)
                                        pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, 
                                                textview->scrolledwin->allocation.width - 100, 
                                                -1, TRUE, &error);
@@ -1022,7 +1024,7 @@ static void textview_show_html(TextView *textview, FILE *fp,
                if (parser->state == SC_HTML_HREF) {
                        /* first time : get and copy the URL */
                        if (parser->href == NULL) {
-                               /* ALF - the sylpheed html parser returns an empty string,
+                               /* ALF - the claws html parser returns an empty string,
                                 * if still inside an <a>, but already parsed past HREF */
                                str = strtok(str, " ");
                                if (str) {
@@ -1580,6 +1582,7 @@ void textview_set_font(TextView *textview, const gchar *codeset)
                if (font_desc) {
                        gtk_widget_modify_font(textview->text, font_desc);
                        CHANGE_TAG_FONT("header", font_desc);
+                       CHANGE_TAG_FONT("hlink", font_desc);
                        pango_font_description_free(font_desc);
                }
                if (bold_font_desc) {
@@ -1650,6 +1653,8 @@ static gboolean header_is_internal(Header *header)
                {"AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:", 
                 "CFG:", "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:", 
                 "R:", "MAID:", "SCF:", "RMID:", "FMID:", "NAID:", 
+                "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-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
                 NULL};
@@ -1889,7 +1894,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                if ((procheader_headername_equal(header->name, "X-Mailer") ||
                     procheader_headername_equal(header->name,
                                                 "X-Newsreader")) &&
-                   strstr(header->body, "Sylpheed-Claws") != NULL) {
+                   (strstr(header->body, "Claws Mail") != NULL ||
+                    strstr(header->body, "Sylpheed-Claws") != NULL)) {
                        gtk_text_buffer_get_end_iter (buffer, &iter);
                        gtk_text_buffer_insert_with_tags_by_name
                                (buffer, &iter, header->body, -1,
@@ -2661,7 +2667,7 @@ static void save_file_cb (TextView *textview, guint action, void *data)
        filedir = g_path_get_dirname(filename);
        if (filedir && strcmp(filedir, ".")) {
                g_free(prefs_common.attach_save_dir);
-               prefs_common.attach_save_dir = g_strdup(filedir);
+               prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
        }
 
        g_free(filedir);
@@ -2697,7 +2703,7 @@ static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data
        /* Hiroyuki: please put this function in utils.c! */
        fromname = procheader_get_fromname(fromaddress);
        extract_address(fromaddress);
-       g_message("adding from textview %s <%s>", fromname, fromaddress);
+
        /* Add to address book - Match */
        addressbook_add_contact( fromname, fromaddress, NULL );
 
@@ -2737,3 +2743,20 @@ static void copy_mail_to_uri_cb  (TextView *textview, guint action, void *data)
                          NULL);
 }
 
+void textview_get_selection_offsets(TextView *textview, gint *sel_start, gint *sel_end)
+{
+               GtkTextView *text = GTK_TEXT_VIEW(textview->text);
+               GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+               GtkTextIter start, end;
+               if (gtk_text_buffer_get_selection_bounds(buffer, &start, &end)) {
+                       if (sel_start)
+                               *sel_start = gtk_text_iter_get_offset(&start);
+                       if (sel_end)
+                               *sel_end = gtk_text_iter_get_offset(&end);
+               } else {
+                       if (sel_start)
+                               *sel_start = -1;
+                       if (sel_end)
+                               *sel_end = -1;
+               }
+}