2005-08-30 [colin] 1.9.13cvs72
[claws.git] / src / mimeview.c
index 122dbf8ba8709f142bf77dbc2e9be544e62faeba..9faf8056d268ca9ecdbe4a0a707132af5fbe1878 100644 (file)
@@ -24,6 +24,7 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkscrolledwindow.h>
@@ -47,7 +48,6 @@
 #include <fnmatch.h>
 #endif
 
-#include "intl.h"
 #include "main.h"
 #include "mimeview.h"
 #include "textview.h"
@@ -429,7 +429,7 @@ static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
        gchar *str[N_MIMEVIEW_COLS];
 
        if (partinfo->type != MIMETYPE_UNKNOWN && partinfo->subtype) {
-               g_snprintf(content_type, 64, "%s/%s", procmime_get_type_str(partinfo->type), partinfo->subtype);
+               g_snprintf(content_type, 64, "%s/%s", procmime_get_media_type_str(partinfo->type), partinfo->subtype);
        } else {
                g_snprintf(content_type, 64, "UNKNOWN");
        }
@@ -459,7 +459,7 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
        fname = mimeview->file;
        if (!fname) return;
 
-       if ((fp = fopen(fname, "rb")) == NULL) {
+       if ((fp = g_fopen(fname, "rb")) == NULL) {
                FILE_OP_ERROR(fname, "fopen");
                return;
        }
@@ -532,7 +532,7 @@ static MimeViewer *get_viewer_for_mimeinfo(MimeView *mimeview, MimeInfo *partinf
        MimeViewer *viewer = NULL;
 
        if ((partinfo->type == MIMETYPE_APPLICATION) &&
-            (!g_strcasecmp(partinfo->subtype, "octet-stream"))) {
+            (!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))) {
                const gchar *filename;
 
                filename = procmime_mimeinfo_get_parameter(partinfo, "filename");
@@ -552,7 +552,7 @@ static MimeViewer *get_viewer_for_mimeinfo(MimeView *mimeview, MimeInfo *partinf
        return viewer;
 }
 
-static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
+gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
 {
        MimeViewer *viewer;
        
@@ -564,9 +564,10 @@ static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
                return FALSE;
        }
 
+       if (mimeview->mimeviewer != NULL)
+               mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
+
        if (mimeview->mimeviewer != viewer) {
-               if (mimeview->mimeviewer != NULL)
-                       mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
                mimeview->mimeviewer = viewer;
                mimeview_change_view_type(mimeview, MIMEVIEW_VIEWER);
        }
@@ -584,12 +585,12 @@ static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
 
        switch (type) {
        case MIMEVIEW_TEXT:
-               gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
+               gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview->mime_notebook),
                        gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook), 
                        GTK_WIDGET_PTR(textview)));
                break;
        case MIMEVIEW_VIEWER:
-               gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
+               gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview->mime_notebook),
                        gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook), 
                        GTK_WIDGET(mimeview->mimeviewer->get_widget(mimeview->mimeviewer))));
                break;
@@ -669,7 +670,7 @@ static void update_signature_noticeview(MimeView *mimeview, MimeInfo *mimeinfo)
        noticeview_set_button_text(mimeview->siginfoview, button_text);
        noticeview_set_button_press_callback(
                mimeview->siginfoview,
-               GTK_SIGNAL_FUNC(func),
+               G_CALLBACK(func),
                (gpointer) mimeview);
        noticeview_set_icon(mimeview->siginfoview, icon);
 }
@@ -823,7 +824,7 @@ static gboolean part_button_pressed(MimeView *mimeview, GdkEventButton *event,
                                           "/Display as text", TRUE);
                if (partinfo &&
                    partinfo->type == MIMETYPE_APPLICATION &&
-                   !g_strcasecmp(partinfo->subtype, "octet-stream"))
+                   !g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))
                        menu_set_sensitive(mimeview->popupfactory,
                                           "/Open", FALSE);
                else
@@ -991,12 +992,18 @@ gchar *mimeview_get_filename_for_part(MimeInfo *partinfo,
        filename = g_strdup(get_part_name(partinfo));
        if (!filename || !*filename)
                filename = g_strdup_printf("noname.%d", number);
-       subst_for_shellsafe_filename(filename);
+
+       if (!g_utf8_validate(filename, -1, NULL)) {
+               gchar *tmp = conv_filename_to_utf8(filename);
+               g_free(filename);
+               filename = tmp;
+       }
+       
+       subst_for_filename(filename);
 
        fullname = g_strconcat
                (basedir, G_DIR_SEPARATOR_S, (filename[0] == G_DIR_SEPARATOR)
                 ? &filename[1] : filename, NULL);
-       subst_chars(fullname, "/\\", G_DIR_SEPARATOR);
 
        g_free(filename);
        return fullname;
@@ -1012,7 +1019,7 @@ static gboolean mimeview_write_part(const gchar *filename,
 {
        gchar *dir;
        
-       dir= g_dirname(filename);
+       dir= g_path_get_dirname(filename);
        if (!is_dir_exist(dir))
                make_dir_hier(dir);
        g_free(dir);
@@ -1023,8 +1030,8 @@ static gboolean mimeview_write_part(const gchar *filename,
                
                res = g_strdup_printf(_("Overwrite existing file '%s'?"),
                                      filename);
-               aval = alertpanel(_("Overwrite"), res, _("OK")
-                                 _("Cancel"), NULL);
+               aval = alertpanel(_("Overwrite"), res, GTK_STOCK_OK
+                                 GTK_STOCK_CANCEL, NULL);
                g_free(res);                                      
                if (G_ALERTDEFAULT != aval) return FALSE;
        }
@@ -1058,14 +1065,14 @@ static void mimeview_save_all(MimeView *mimeview)
                startdir = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, NULL);
 
-       dirname = filesel_select_file_open_folder(_("Select destination folder"), startdir);
+       dirname = filesel_select_file_save_folder(_("Select destination folder"), startdir);
        if (!dirname) {
                if (startdir) g_free(startdir);
                return;
        }
 
        if (!is_dir_exist (dirname)) {
-               alertpanel_error(_("`%s' is not a directory."),
+               alertpanel_error(_("'%s' is not a directory."),
                                 dirname);
                if (startdir) g_free(startdir);
                return;
@@ -1074,10 +1081,19 @@ static void mimeview_save_all(MimeView *mimeview)
        if (dirname[strlen(dirname)-1] == G_DIR_SEPARATOR)
                dirname[strlen(dirname)-1] = '\0';
 
+       /* Skip the first part, that is sometimes DISPOSITIONTYPE_UNKNOWN */
+       if (partinfo && partinfo->type == MIMETYPE_MESSAGE)
+               partinfo = procmime_mimeinfo_next(partinfo);
+       if (partinfo && partinfo->type == MIMETYPE_MULTIPART) {
+               partinfo = procmime_mimeinfo_next(partinfo);
+               if (partinfo && partinfo->type == MIMETYPE_TEXT)
+                       partinfo = procmime_mimeinfo_next(partinfo);
+       }
+               
        while (partinfo != NULL) {
                if (partinfo->type != MIMETYPE_MESSAGE &&
                    partinfo->type != MIMETYPE_MULTIPART &&
-                   partinfo->disposition == DISPOSITIONTYPE_ATTACHMENT) {
+                   partinfo->disposition != DISPOSITIONTYPE_INLINE) {
                        gchar *filename = mimeview_get_filename_for_part
                                (partinfo, dirname, number++);
 
@@ -1105,7 +1121,7 @@ static void mimeview_save_as(MimeView *mimeview)
        gchar *filepath = NULL;
        gchar *filedir = NULL;
        MimeInfo *partinfo;
-       const gchar *partname = NULL;
+       gchar *partname = NULL;
 
        if (!mimeview->opened) return;
        if (!mimeview->file) return;
@@ -1120,16 +1136,27 @@ static void mimeview_save_as(MimeView *mimeview)
        }                        
        g_return_if_fail(partinfo != NULL);
        
-       if ((partname = get_part_name(partinfo)) == NULL) {
+       if (get_part_name(partinfo) == NULL) {
                return;
        }
+       partname = g_strdup(get_part_name(partinfo));
+       
+       if (!g_utf8_validate(partname, -1, NULL)) {
+               gchar *tmp = conv_filename_to_utf8(partname);
+               g_free(partname);
+               partname = tmp;
+       }
 
+       subst_for_filename(partname);
+       
        if (prefs_common.attach_save_dir)
                filepath = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, partname, NULL);
        else
                filepath = g_strdup(partname);
 
+       g_free(partname);
+
        filename = filesel_select_file_save(_("Save as"), filepath);
        if (!filename) {
                g_free(filepath);
@@ -1138,7 +1165,7 @@ static void mimeview_save_as(MimeView *mimeview)
 
        mimeview_write_part(filename, partinfo);
 
-       filedir = g_dirname(filename);
+       filedir = g_path_get_dirname(filename);
        if (filedir && strcmp(filedir, ".")) {
                if (prefs_common.attach_save_dir)
                        g_free(prefs_common.attach_save_dir);
@@ -1232,7 +1259,7 @@ static void mimeview_open_with(MimeView *mimeview)
        cmd = input_dialog_combo
                (_("Open with"),
                 _("Enter the command line to open file:\n"
-                  "(`%s' will be replaced with file name)"),
+                  "('%s' will be replaced with file name)"),
                 prefs_common.mime_open_cmd,
                 prefs_common.mime_open_cmd_history,
                 TRUE);
@@ -1250,10 +1277,10 @@ static void mimeview_open_with(MimeView *mimeview)
 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                               const gchar *cmdline)
 {
-       static gchar *default_image_cmdline = "display '%s'";
-       static gchar *default_audio_cmdline = "play '%s'";
+       static gchar *default_image_cmdline = DEFAULT_IMAGE_VIEWER_CMD;
+       static gchar *default_audio_cmdline = DEFAULT_AUDIO_PLAYER_CMD;
        static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD;
-       static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
+       static gchar *mime_cmdline = DEFAULT_MIME_CMD;
        gchar buf[1024];
        gchar m_buf[1024];
        const gchar *cmd;
@@ -1264,7 +1291,7 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                cmd = cmdline;
                def_cmd = NULL;
        } else if (MIMETYPE_APPLICATION == partinfo->type &&
-                  !g_strcasecmp(partinfo->subtype, "octet-stream")) {
+                  !g_ascii_strcasecmp(partinfo->subtype, "octet-stream")) {
                return;
        } else if (MIMETYPE_IMAGE == partinfo->type) {
                cmd = prefs_common.mime_image_viewer;
@@ -1291,7 +1318,7 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                g_snprintf(buf, sizeof(buf), cmd, filename);
        else {
                if (cmd)
-                       g_warning("MIME viewer command line is invalid: `%s'", cmd);
+                       g_warning("MIME viewer command line is invalid: '%s'", cmd);
                if (def_cmd)
                        g_snprintf(buf, sizeof(buf), def_cmd, filename);
                else
@@ -1481,7 +1508,7 @@ static void toggle_icon(GtkToggleButton *button, MimeView *mimeview)
 
 static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo) 
 {
-       GtkWidget *pixmap;
+       GtkWidget *pixmap = NULL;
        GtkWidget *vbox;
        GtkWidget *button;
        gchar *tip;
@@ -1506,9 +1533,9 @@ static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
        switch (mimeinfo->type) {
                
        case MIMETYPE_TEXT:
-               if (mimeinfo->subtype && !g_strcasecmp(mimeinfo->subtype, "html"))
+               if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "html"))
                        stockp = STOCK_PIXMAP_MIME_TEXT_HTML;
-               else if  (mimeinfo->subtype && !g_strcasecmp(mimeinfo->subtype, "enriched"))
+               else if  (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "enriched"))
                        stockp = STOCK_PIXMAP_MIME_TEXT_ENRICHED;
                else
                        stockp = STOCK_PIXMAP_MIME_TEXT_PLAIN;
@@ -1587,9 +1614,16 @@ static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
                        to_human_readable(mimeinfo->length), NULL);
        g_free(content_type);
        if (desc && *desc) {
-               tiptmp = g_strjoin("\n", desc, tip, NULL);
+               gchar *tmp = NULL;
+               if (!g_utf8_validate(desc, -1, NULL)) {
+                       tmp = conv_filename_to_utf8(desc);
+               } else {
+                       tmp = g_strdup(desc);
+               }
+               tiptmp = g_strjoin("\n", tmp, tip, NULL);
                g_free(tip);
                tip = tiptmp;
+               g_free(tmp);
        }
        if (sigshort && *sigshort) {
                tiptmp = g_strjoin("\n", tip, sigshort, NULL);
@@ -1621,7 +1655,7 @@ static void icon_list_clear (MimeView *mimeview)
        }
        mimeview->icon_count = 0;
        adj  = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
-       adj->value = adj->lower;
+       gtk_adjustment_set_value(adj, adj->lower);
 }
 
 static void icon_list_toggle_by_mime_info(MimeView     *mimeview,