2005-02-09 [colin] 1.0.1cvs1.1
[claws.git] / src / mimeview.c
index 33fa522fb844705904aca31e6de0a9db866257e7..187ff460a647f6e81e55b5c548166a79af5ed3b3 100644 (file)
@@ -60,7 +60,6 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "prefs_common.h"
-#include "rfc2015.h"
 #include "stock_pixmap.h"
 #include "gtk/gtkvscrollbutton.h"
 
@@ -202,7 +201,7 @@ MimeView *mimeview_create(MainWindow *mainwin)
        gtk_widget_show(scrolledwin);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_AUTOMATIC,
-                                      GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_AUTOMATIC);
 
        ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
        gtk_widget_show(ctree);
@@ -430,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");
        }
@@ -533,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");
@@ -553,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;
        
@@ -585,12 +584,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;
@@ -670,7 +669,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);
 }
@@ -824,7 +823,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
@@ -868,6 +867,11 @@ static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        if (!event) return FALSE;
        if (!mimeview->opened) return FALSE;
 
+       summaryview = mimeview->messageview->mainwin->summaryview;
+       
+       if (summaryview && quicksearch_has_focus(summaryview->quicksearch))
+               return FALSE;
+               
        switch (event->keyval) {
        case GDK_space:
                if (textview_scroll_page(mimeview->textview, FALSE))
@@ -928,7 +932,7 @@ static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        }
 
        if (!mimeview->messageview->mainwin) return FALSE;
-       summaryview = mimeview->messageview->mainwin->summaryview;
+
        summary_pass_key_press_event(summaryview, event);
        return TRUE;
 }
@@ -963,7 +967,7 @@ static void mimeview_drag_data_get(GtkWidget            *widget,
                alertpanel_error
                        (_("Can't save the part of multipart message."));
 
-       uriname = g_strconcat("file:/", filename, NULL);
+       uriname = g_strconcat("file://", filename, NULL);
        gtk_selection_data_set(selection_data, selection_data->target, 8,
                               uriname, strlen(uriname));
 
@@ -1008,7 +1012,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);
@@ -1019,8 +1023,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;
        }
@@ -1054,7 +1058,7 @@ static void mimeview_save_all(MimeView *mimeview)
                startdir = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, NULL);
 
-       dirname = filesel_select_file(_("Select destination folder"), startdir);
+       dirname = filesel_select_file_open_folder(_("Select destination folder"), startdir);
        if (!dirname) {
                if (startdir) g_free(startdir);
                return;
@@ -1070,6 +1074,15 @@ 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 &&
@@ -1098,7 +1111,6 @@ static void mimeview_save_all(MimeView *mimeview)
 static void mimeview_save_as(MimeView *mimeview)
 {
        gchar *filename;
-       gchar *defname = NULL;
        gchar *filepath = NULL;
        gchar *filedir = NULL;
        MimeInfo *partinfo;
@@ -1117,18 +1129,17 @@ static void mimeview_save_as(MimeView *mimeview)
        }                        
        g_return_if_fail(partinfo != NULL);
        
-       if ((partname = get_part_name(partinfo)) != NULL) {
-               Xstrdup_a(defname, partname, return);
-               subst_for_shellsafe_filename(defname);
+       if ((partname = get_part_name(partinfo)) == NULL) {
+               return;
        }
 
        if (prefs_common.attach_save_dir)
                filepath = g_strconcat(prefs_common.attach_save_dir,
-                                      G_DIR_SEPARATOR_S, defname, NULL);
+                                      G_DIR_SEPARATOR_S, partname, NULL);
        else
-               filepath = g_strdup(defname);
+               filepath = g_strdup(partname);
 
-       filename = filesel_select_file(_("Save as"), filepath);
+       filename = filesel_select_file_save(_("Save as"), filepath);
        if (!filename) {
                g_free(filepath);
                return;
@@ -1136,7 +1147,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);
@@ -1262,7 +1273,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;
@@ -1504,9 +1515,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;
@@ -1692,21 +1703,23 @@ static void icon_scroll_size_allocate_cb(GtkWidget *widget,
 static void icon_list_create(MimeView *mimeview, MimeInfo *mimeinfo)
 {
        GtkRequisition size;
-       gint           width;
+
        g_return_if_fail(mimeinfo != NULL);
 
        while (mimeinfo != NULL) {
                if (mimeinfo->type != MIMETYPE_MULTIPART)
                        icon_list_append_icon(mimeview, mimeinfo);
                if (mimeinfo->node->children != NULL)
-                       icon_list_create(mimeview, (MimeInfo *) mimeinfo->node->children->data);
-               mimeinfo = mimeinfo->node->next != NULL ? (MimeInfo *) mimeinfo->node->next->data : NULL;
+                       icon_list_create(mimeview, 
+                               (MimeInfo *) mimeinfo->node->children->data);
+               mimeinfo = mimeinfo->node->next != NULL 
+                        ? (MimeInfo *) mimeinfo->node->next->data 
+                        : NULL;
        }
        gtk_widget_size_request(mimeview->icon_vbox, &size);
-       width = size.width + 4;
-       if (width > mimeview->icon_mainbox->requisition.width) {
+       if (size.width > mimeview->icon_mainbox->requisition.width) {
                gtk_widget_set_size_request(mimeview->icon_mainbox, 
-                                           width, -1);
+                                           size.width, -1);
        }
 
 }