2011-01-06 [colin] 3.7.8cvs30
[claws.git] / src / messageview.c
index 915ab38eb01142f5d21aa09573fad102378b58b5..3d540cc37c04d75b808625489251e1c32db8cb37 100644 (file)
@@ -58,7 +58,6 @@
 #include "hooks.h"
 #include "filtering.h"
 #include "partial_download.h"
-#include "gedit-print.h"
 #include "uri_opener.h"
 #include "inc.h"
 #include "log.h"
@@ -94,10 +93,8 @@ static void partial_recv_unmark_clicked (NoticeView  *noticeview,
                                          MsgInfo        *msginfo);
 static void save_as_cb                 (GtkAction      *action,
                                         gpointer        data);
-#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb              (GtkAction      *action,
                                         gpointer        data);
-#endif
 static void print_cb                   (GtkAction      *action,
                                         gpointer        data);
 static void close_cb                   (GtkAction      *action,
@@ -193,9 +190,7 @@ static GtkActionEntry msgview_entries[] =
 
 /* File menu */
        {"File/SaveAs",                 NULL, N_("_Save as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
-#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
        {"File/PageSetup",              NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
-#endif
        {"File/Print",                  NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
        {"File/---",                    NULL, "---", NULL, NULL, NULL },
        {"File/Close",                  NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(close_cb) },
@@ -333,6 +328,7 @@ static GtkRadioActionEntry msgview_radio_enc_entries[] =
        ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
        ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
        ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
+       ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
        ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
@@ -454,9 +450,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
 
 /* File menu */
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
-#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
-#endif
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Close", "File/Close", GTK_UI_MANAGER_MENUITEM)
@@ -535,6 +529,7 @@ static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
 
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
@@ -864,7 +859,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        addrp = addr;
        
        /* write queue headers */
-       if (fprintf(fp, "AF:\n"
+       ok = fprintf(fp, "AF:\n"
                    "NF:0\n"
                    "PS:10\n"
                    "SRH:1\n"
@@ -880,14 +875,11 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                    "R:<%s>\n", 
                    account->address,
                    account->smtp_server?account->smtp_server:"",
-                   addrp) < 0) {
-               g_free(addrp);
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+                   addrp);
 
        g_free(addrp);
+       if (ok < 0)
+               goto FILE_ERROR;
        
        /* check whether we need to save the message */
        outbox = account_get_special_folder(account, F_OUTBOX); 
@@ -895,61 +887,40 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                outbox = NULL;
        if (outbox) {
                path = folder_item_get_identifier(outbox);
-               if (fprintf(fp, "SCF:%s\n", path) < 0) {
-                       g_free(path);
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               ok = fprintf(fp, "SCF:%s\n", path);
                g_free(path);
+               
+               if (ok < 0)
+                       goto FILE_ERROR;
        }               
 
-       if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0)
+               goto FILE_ERROR;
 
        /* Date */
        get_rfc822_date(buf, sizeof(buf));
-       if (fprintf(fp, "Date: %s\n", buf) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "Date: %s\n", buf) < 0)
+               goto FILE_ERROR;
 
        /* From */
        if (account->name && *account->name) {
                notification_convert_header
                        (buf, sizeof(buf), account->name,
                         strlen("From: "));
-               if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0)
+                       goto FILE_ERROR;
        } else
-               if (fprintf(fp, "From: %s\n", account->address) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               if (fprintf(fp, "From: %s\n", account->address) < 0)
+                       goto FILE_ERROR;
 
-
-       if (fprintf(fp, "To: %s\n", to) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "To: %s\n", to) < 0)
+               goto FILE_ERROR;
 
        /* Subject */
        notification_convert_header(buf, sizeof(buf), msginfo->subject,
                                    strlen("Subject: "));
-       if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               return -1;
-       }
+       if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0)
+               goto FILE_ERROR;
 
        /* Message ID */
        if (account->set_domain && account->domain) {
@@ -970,11 +941,8 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                }
                generate_msgid(buf, sizeof(buf), addr);
 
-               if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0) {
-                       fclose(fp);
-                       claws_unlink(tmp);
-                       return -1;
-               }
+               if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0)
+                       goto FILE_ERROR;
        }
 
        boundary = generate_mime_boundary("DN");
@@ -989,7 +957,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                qp_encode_line(enc_sub, (const guchar *)msginfo->subject);
                g_strstrip(enc_sub);
        }
-       if (fprintf(fp, "MIME-Version: 1.0\n"
+       ok = fprintf(fp,"MIME-Version: 1.0\n"
                        "Content-Type: multipart/report; report-type=disposition-notification;\n"
                        "  boundary=\"%s\"\n"
                        "\n"
@@ -1038,18 +1006,16 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                        orig_to?orig_to:"No To:",
                        account->address,
                        msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
-                       boundary) < 0) {
-               fclose(fp);
-               claws_unlink(tmp);
-               g_free(boundary);
-               return -1;
-       }
+                       boundary);
 
        g_free(enc_sub);
        g_free(orig_to);
        g_free(date);
        g_free(boundary);
 
+       if (ok < 0)
+               goto FILE_ERROR;        
+
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
                claws_unlink(tmp);
@@ -1086,6 +1052,11 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                folder_item_remove_msg(queue, num);
 
        return ok;
+
+FILE_ERROR:
+       fclose(fp);
+       claws_unlink(tmp);
+       return -1;
 }
 
 static gboolean find_encrypted_func(GNode *node, gpointer data)
@@ -1730,7 +1701,9 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
                return TRUE;
        }
 
-       if (event && (event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK|GDK_SHIFT_MASK)) != 0)
+       if (event && (event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
+               return FALSE;
+       if (event && (event->state & GDK_SHIFT_MASK) && event->keyval != GDK_space) 
                return FALSE;
 
        g_signal_stop_emission_by_name(G_OBJECT(widget),
@@ -2006,12 +1979,9 @@ static void save_as_cb(GtkAction *action, gpointer data)
        messageview_save_as(messageview);
 }
 
-#if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum) 
 {
-#if !defined(USE_GNOMEPRINT) && GTK_CHECK_VERSION(2,10,0)
        MainWindow *mainwin;
-#endif
        if (!mimeview 
        ||  !mimeview->textview
        ||  !mimeview->textview->text)
@@ -2038,15 +2008,11 @@ static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gin
                        gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
                        gtk_text_buffer_select_range(buffer, &start, &end);
                }
-#if defined(USE_GNOMEPRINT)
-               gedit_print(GTK_TEXT_VIEW(mimeview->textview->text));
-#else
                /* TODO: Get the real parent window, not the main window */
                mainwin = mainwindow_get_mainwindow();
                printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
                               mainwin ? GTK_WINDOW(mainwin->window) : NULL,
                                sel_start, sel_end);
-#endif
        }
 }
 
@@ -2078,51 +2044,26 @@ void messageview_print(MsgInfo *msginfo, gboolean all_headers,
        }
        messageview_destroy(tmpview);
 }
-#endif
 
-#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
 static void page_setup_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
        printing_page_setup(messageview ?
                            GTK_WINDOW(messageview->window) : NULL);
 }
-#endif
 
 static void print_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
-#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
-       gchar *cmdline = NULL;
-       gchar *p;
-#else
        gint sel_start = -1, sel_end = -1, partnum = 0;
-#endif
 
        if (!messageview->msginfo) return;
 
-#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
-       cmdline = input_dialog(_("Print"),
-                              _("Enter the print command-line:\n"
-                                "('%s' will be replaced with file name)"),
-                              prefs_common.print_cmd);
-       if (!cmdline) return;
-       if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
-           strchr(p + 2, '%')) {
-               alertpanel_error(_("Print command-line is invalid:\n'%s'"),
-                                cmdline);
-               g_free(cmdline);
-               return;
-       }
-       procmsg_print_message(messageview->msginfo, cmdline);
-       g_free(cmdline);
-#else
        partnum = mimeview_get_selected_part_num(messageview->mimeview);
        textview_get_selection_offsets(messageview->mimeview->textview,
                &sel_start, &sel_end);
        messageview_print(messageview->msginfo, messageview->all_headers, 
                sel_start, sel_end, partnum);
-#endif
 }
 
 static void close_cb(GtkAction *action, gpointer data)
@@ -2802,7 +2743,12 @@ void messageview_list_urls (MessageView  *msgview)
 {
        GSList *cur = msgview->mimeview->textview->uri_list;
        GSList *newlist = NULL;
-       GHashTable *uri_hashtable = g_hash_table_new(g_str_hash, g_str_equal); 
+       GHashTable *uri_hashtable;
+       gchar *tmp;
+       
+       uri_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                        (GDestroyNotify) g_free, NULL);
+       
        for (; cur; cur = cur->next) {
                ClickableText *uri = (ClickableText *)cur->data;
                if (uri->uri &&
@@ -2812,12 +2758,16 @@ void messageview_list_urls (MessageView *msgview)
                     !g_ascii_strncasecmp(uri->uri, "http:", 5) ||
                     !g_ascii_strncasecmp(uri->uri, "https:", 6)))
                {
-                       if(g_hash_table_lookup(uri_hashtable, uri->uri))
+                       tmp = g_utf8_strdown(uri->uri, -1);
+                       
+                       if (g_hash_table_lookup(uri_hashtable, tmp)) {
+                               g_free(tmp);
                                continue;
+                       }
                        
                        newlist = g_slist_prepend(newlist, uri);
-                       g_hash_table_insert(uri_hashtable, uri->uri,
-                                           GUINT_TO_POINTER(g_str_hash(uri->uri)));
+                       g_hash_table_insert(uri_hashtable, tmp,
+                                           GUINT_TO_POINTER(g_str_hash(tmp)));
                }
        }
        newlist = g_slist_reverse(newlist);