0.9.6claws83
[claws.git] / src / mimeview.c
index 063d2ef76eb3fcfe13033aaeb3571dc4439b1383..13e01b6497776f9e6cfab34b3c186a155b411c65 100644 (file)
@@ -347,8 +347,6 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
                icon_list_toggle_by_mime_info
                        (mimeview, gtk_ctree_node_get_row_data(ctree, node));
                gtkut_ctree_set_focus_row(ctree, node);
-               if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mimeview->mime_toggle)))
-                       gtk_widget_grab_focus(mimeview->ctree);
        }
 }
 
@@ -390,9 +388,9 @@ static void mimeview_set_multipart_tree(MimeView *mimeview,
        while (mimeinfo != NULL) {
                node = mimeview_append_part(mimeview, mimeinfo, parent);
 
-               if (mimeinfo->children)
-                       mimeview_set_multipart_tree(mimeview, mimeinfo->children, node);
-               mimeinfo = mimeinfo->next;
+               if (mimeinfo->node->children)
+                       mimeview_set_multipart_tree(mimeview, (MimeInfo *) mimeinfo->node->children->data, node);
+               mimeinfo = mimeinfo->node->next != NULL ? (MimeInfo *) mimeinfo->node->next->data : NULL;
        }
 }
 
@@ -496,8 +494,8 @@ static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *
                gint i = 0;
 
                while (curfactory->content_types[i] != NULL) {
-                       debug_print("%s\n", curfactory->content_types[i]);
                        if(!fnmatch(curfactory->content_types[i], content_type, FNM_CASEFOLD)) {
+                               debug_print("%s\n", curfactory->content_types[i]);
                                factory = curfactory;
                                break;
                        }
@@ -530,7 +528,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_strcasecmp(partinfo->subtype, "octet-stream")) &&
            (partinfo->name != NULL)) {
                content_type = procmime_get_mime_type(partinfo->name);
        } else {
@@ -616,6 +614,101 @@ void mimeview_clear(MimeView *mimeview)
        icon_list_clear(mimeview);
 }
 
+static void check_signature_cb(GtkWidget *widget, gpointer user_data);
+static void display_full_info_cb(GtkWidget *widget, gpointer user_data);
+
+static void update_signature_noticeview(MimeView *mimeview, MimeInfo *mimeinfo)
+{
+       gchar *text = NULL, *button_text = NULL;
+       GtkSignalFunc func = NULL;
+       StockPixmap icon = STOCK_PIXMAP_PRIVACY_SIGNED;
+
+       g_return_if_fail(mimeview != NULL);
+       g_return_if_fail(mimeinfo != NULL);
+       
+       switch (privacy_mimeinfo_get_sig_status(mimeinfo)) {
+       case SIGNATURE_UNCHECKED:
+               button_text = _("Check");
+               func = check_signature_cb;
+               icon = STOCK_PIXMAP_PRIVACY_SIGNED;
+               break;
+       case SIGNATURE_OK:
+               button_text = _("Full info");
+               func = display_full_info_cb;
+               icon = STOCK_PIXMAP_PRIVACY_PASSED;
+               break;
+       case SIGNATURE_WARN:
+               button_text = _("Full info");
+               func = display_full_info_cb;
+               icon = STOCK_PIXMAP_PRIVACY_WARN;
+               break;
+       case SIGNATURE_INVALID:
+               button_text = _("Full info");
+               func = display_full_info_cb;
+               icon = STOCK_PIXMAP_PRIVACY_FAILED;
+               break;
+       case SIGNATURE_CHECK_FAILED:
+               button_text = _("Check again");
+               func = check_signature_cb;
+               icon = STOCK_PIXMAP_PRIVACY_UNKNOWN;
+       default:
+               break;
+       }
+       text = privacy_mimeinfo_sig_info_short(mimeinfo);
+       noticeview_set_text(mimeview->siginfoview, text);
+       g_free(text);
+       noticeview_set_button_text(mimeview->siginfoview, button_text);
+       noticeview_set_button_press_callback(
+               mimeview->siginfoview,
+               func,
+               (gpointer) mimeview);
+       noticeview_set_icon(mimeview->siginfoview, icon);
+}
+
+static void check_signature_cb(GtkWidget *widget, gpointer user_data)
+{
+       MimeView *mimeview = (MimeView *) user_data;
+       MimeInfo *mimeinfo = mimeview->siginfo;
+       
+       privacy_mimeinfo_check_signature(mimeinfo);
+       update_signature_noticeview(mimeview, mimeview->siginfo);
+}
+
+static void display_full_info_cb(GtkWidget *widget, gpointer user_data)
+{
+       MimeView *mimeview = (MimeView *) user_data;
+       gchar *siginfo;
+
+       siginfo = privacy_mimeinfo_sig_info_full(mimeview->siginfo);
+       textview_set_text(mimeview->textview, siginfo);
+       g_free(siginfo);
+       noticeview_set_button_text(mimeview->siginfoview, NULL);
+}
+
+static void update_signature_info(MimeView *mimeview, MimeInfo *selected)
+{
+       MimeInfo *siginfo;
+
+       g_return_if_fail(mimeview != NULL);
+       g_return_if_fail(selected != NULL);
+       
+       siginfo = selected;
+       while (siginfo != NULL) {
+               if (privacy_mimeinfo_is_signed(siginfo))
+                       break;
+               siginfo = procmime_mimeinfo_parent(siginfo);
+       }
+       mimeview->siginfo = siginfo;
+       
+       if (siginfo == NULL) {
+               noticeview_hide(mimeview->siginfoview);
+               return;
+       }
+       
+       update_signature_noticeview(mimeview, siginfo);
+       noticeview_show(mimeview->siginfoview);
+}
+
 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
                              MimeView *mimeview)
 {
@@ -637,12 +730,7 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
        
        mimeview->textview->default_text = FALSE;
 
-       if (privacy_mimeinfo_is_signed(partinfo)) {
-               noticeview_set_text(mimeview->siginfoview, "Signed Part");
-               noticeview_show(mimeview->siginfoview);
-       } else {
-               noticeview_hide(mimeview->siginfoview);
-       }
+       update_signature_info(mimeview, partinfo);
 
        if (!mimeview_show_part(mimeview, partinfo)) {
                switch (partinfo->type) {
@@ -716,7 +804,8 @@ static void part_button_pressed(MimeView *mimeview, GdkEventButton *event,
                        menu_set_sensitive(mimeview->popupfactory,
                                           "/Display as text", TRUE);
                if (partinfo &&
-                   partinfo->type == MIMETYPE_APPLICATION)
+                   partinfo->type == MIMETYPE_APPLICATION &&
+                   !g_strcasecmp(partinfo->subtype, "octet-stream"))
                        menu_set_sensitive(mimeview->popupfactory,
                                           "/Open", FALSE);
                else
@@ -860,55 +949,74 @@ static void mimeview_save_all(MimeView *mimeview)
 {
        gchar *dirname;
        gchar *defname = NULL;
-       MimeInfo *partinfo;
        MimeInfo *attachment;
        gchar buf[1024];
 
        if (!mimeview->opened) return;
        if (!mimeview->file) return;
 
-       partinfo = mimeview_get_selected_part(mimeview);
-       g_return_if_fail(partinfo != NULL);
+       attachment = mimeview->mimeinfo;
+       g_return_if_fail(attachment != NULL);
 
        dirname = filesel_select_file(_("Save as"), defname);
        if (!dirname) return;
 
-       /* return to first children */
-       if (!partinfo->parent->children) return;  /* multipart container? */
-       attachment = partinfo->parent->children->next;
+       if (!is_dir_exist (dirname)) {
+               alertpanel_error(_("`%s' is not a directory."),
+                                dirname);
+               g_free (dirname);
+               return;
+       }
+       
+       { /* add a / after the dirname, in case the user didn't */
+               gchar *dirname_tmp = NULL;
+               int dirname_last_char = strlen (dirname) - 1;
+
+               if (dirname[dirname_last_char] != G_DIR_SEPARATOR) {
+                       dirname_tmp = g_strconcat (dirname, G_DIR_SEPARATOR_S, NULL);
+                       g_free (dirname);
+                       dirname = dirname_tmp;
+               }
+       }
+
        /* for each attachment, extract it in the selected dir. */
        while (attachment != NULL) {
-               static guint subst_cnt = 1;
-               gchar *attachdir;
-               gchar *attachname = g_strdup(get_part_name(attachment));
-               AlertValue aval = G_ALERTDEFAULT;
-               gchar *res;
-
-               if (!attachname || !strlen(attachname))
-                       attachname = g_strdup_printf("noname.%d",subst_cnt++);
-               subst_chars(attachname, ":?*&|<>\t\r\n", '_');
-               g_snprintf(buf, sizeof(buf), "%s%s",
-                          dirname,
-                          (attachname[0] == G_DIR_SEPARATOR)
-                          ? &attachname[1]
-                          : attachname);
-               subst_chars(buf, "/\\", G_DIR_SEPARATOR);
-               attachdir = g_dirname(buf);
-               make_dir_hier(attachdir);
-               g_free(attachdir);
-
-               if (is_file_exist(buf)) {
-                       res = g_strdup_printf(_("Overwrite existing file '%s'?"),
-                                             attachname);
-                       aval = alertpanel(_("Overwrite"), res, _("OK"), 
-                                         _("Cancel"), NULL);
-                       g_free(res);                                      
+               if (attachment->type != MIMETYPE_MESSAGE &&
+                   attachment->type != MIMETYPE_MULTIPART &&
+                   (procmime_mimeinfo_get_parameter(attachment, "name") ||
+                    procmime_mimeinfo_get_parameter(attachment, "filename"))) {
+                       static guint subst_cnt = 1;
+                       gchar *attachdir;
+                       gchar *attachname = g_strdup(get_part_name(attachment));
+                       AlertValue aval = G_ALERTDEFAULT;
+                       gchar *res;
+
+                       if (!attachname || !strlen(attachname))
+                               attachname = g_strdup_printf("noname.%d",subst_cnt++);
+                       subst_chars(attachname, ":?*&|<>\t\r\n", '_');
+                       g_snprintf(buf, sizeof(buf), "%s%s",
+                                  dirname,
+                                  (attachname[0] == G_DIR_SEPARATOR)
+                                  ? &attachname[1]
+                                  : attachname);
+                       subst_chars(buf, "/\\", G_DIR_SEPARATOR);
+                       attachdir = g_dirname(buf);
+                       make_dir_hier(attachdir);
+                       g_free(attachdir);
+                       
+                       if (is_file_exist(buf)) {
+                               res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                                     attachname);
+                               aval = alertpanel(_("Overwrite"), res, _("OK"), 
+                                                 _("Cancel"), NULL);
+                               g_free(res);                                      
+                       }
+                       g_free(attachname);
+                       
+                       if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, attachment) < 0))
+                               alertpanel_error(_("Can't save the part of multipart message."));
                }
-               g_free(attachname);
-
-               if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, attachment) < 0))
-                       alertpanel_error(_("Can't save the part of multipart message."));
-               attachment = attachment->next;
+               attachment = procmime_mimeinfo_next(attachment);
        }
 }
 
@@ -937,6 +1045,7 @@ static void mimeview_save_as(MimeView *mimeview)
        gchar *defname = NULL;
        MimeInfo *partinfo;
        gchar *res;
+       const gchar *partname = NULL;
 
        if (!mimeview->opened) return;
        if (!mimeview->file) return;
@@ -950,11 +1059,9 @@ static void mimeview_save_as(MimeView *mimeview)
                                    "pop_partinfo", NULL);
        }                        
        g_return_if_fail(partinfo != NULL);
-
-       if (partinfo->filename)
-               defname = partinfo->filename;
-       else if (partinfo->name) {
-               Xstrdup_a(defname, partinfo->name, return);
+       
+       if ((partname = procmime_mimeinfo_get_parameter(partinfo, "name")) != NULL) {
+               Xstrdup_a(defname, partname, return);
                subst_for_filename(defname);
        }
 
@@ -1070,7 +1177,8 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
        if (cmdline) {
                cmd = cmdline;
                def_cmd = NULL;
-       } else if (MIMETYPE_APPLICATION == partinfo->type) {
+       } else if (MIMETYPE_APPLICATION == partinfo->type &&
+                  !g_strcasecmp(partinfo->subtype, "octet-stream")) {
                return;
        } else if (MIMETYPE_IMAGE == partinfo->type) {
                cmd = prefs_common.mime_image_viewer;
@@ -1147,15 +1255,17 @@ static gboolean icon_clicked_cb (GtkWidget *button, GdkEventButton *event, MimeV
 
        num      = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(button), "icon_number"));
        partinfo = gtk_object_get_data(GTK_OBJECT(button), "partinfo");
-       if (event->button == 1) { 
-               icon_selected(mimeview, num, partinfo);
-               gtk_widget_grab_focus(button);
-               
-               if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
-                       toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
-               else
-                       gtk_signal_emit_stop_by_name(GTK_OBJECT(button), "button_press_event");
-       }               
+
+       icon_selected(mimeview, num, partinfo);
+       gtk_widget_grab_focus(button);
+       if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
+               toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
+               if (event->button == 2 || event->button == 3)
+                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
+                                                    TRUE);
+       } else {
+               gtk_signal_emit_stop_by_name(GTK_OBJECT(button), "button_press_event");
+       }
 
        part_button_pressed(mimeview, event, partinfo);
 
@@ -1227,17 +1337,19 @@ static gint icon_key_pressed(GtkWidget *button, GdkEventKey *event,
        case GDK_n:
        case GDK_N:
                BREAK_ON_MODIFIER_KEY();
-               if (icon_list_select_by_number(mimeview, num + 1))
+               if (icon_list_select_by_number(mimeview, num + 1)) {
                        KEY_PRESS_EVENT_STOP();
                        return TRUE;
+               }
                break;
                
        case GDK_p:
        case GDK_P:
                BREAK_ON_MODIFIER_KEY();
-               if (icon_list_select_by_number(mimeview, num - 1))
+               if (icon_list_select_by_number(mimeview, num - 1)) {
                        KEY_PRESS_EVENT_STOP();
                        return TRUE;
+               }
                break;
 
        case GDK_y:
@@ -1312,10 +1424,7 @@ static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
                stockp = STOCK_PIXMAP_MIME_MESSAGE;
                break;
        case MIMETYPE_APPLICATION:
-               if (mimeinfo->subtype && !g_strcasecmp(mimeinfo->subtype, "octet-stream"))
-                       stockp = STOCK_PIXMAP_MIME_APPLICATION_OCTET_STREAM;
-               else
-                       stockp = STOCK_PIXMAP_MIME_APPLICATION;
+               stockp = STOCK_PIXMAP_MIME_APPLICATION;
                break;
        case MIMETYPE_IMAGE:
                stockp = STOCK_PIXMAP_MIME_IMAGE;
@@ -1456,9 +1565,9 @@ static void icon_list_create(MimeView *mimeview, MimeInfo *mimeinfo)
        while (mimeinfo != NULL) {
                if (mimeinfo->type != MIMETYPE_MULTIPART)
                        icon_list_append_icon(mimeview, mimeinfo);
-               if (mimeinfo->children != NULL)
-                       icon_list_create(mimeview, mimeinfo->children);
-               mimeinfo = mimeinfo->next;
+               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;
        }
        gtk_widget_size_request(mimeview->icon_vbox, &size);
        width = size.width + 4;