/*
* 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
MimeInfo *partinfo);
static void mimeview_change_view_type (MimeView *mimeview,
MimeViewType type);
-gchar *mimeview_get_filename_for_part (MimeInfo *partinfo,
+static gchar *mimeview_get_filename_for_part (MimeInfo *partinfo,
const gchar *basedir,
gint number);
static gboolean mimeview_write_part (const gchar *filename,
static void mimeview_display_as_text (MimeView *mimeview);
static void mimeview_save_as (MimeView *mimeview);
static void mimeview_save_all (MimeView *mimeview);
-static void mimeview_launch (MimeView *mimeview);
+static void mimeview_launch (MimeView *mimeview,
+ MimeInfo *partinfo);
static void mimeview_open_with (MimeView *mimeview);
static void mimeview_open_part_with (MimeView *mimeview,
MimeInfo *partinfo,
gboolean automatic);
+static void mimeview_select_next_part (MimeView *mimeview);
static void mimeview_view_file (const gchar *filename,
MimeInfo *partinfo,
const gchar *cmd,
static void icon_scroll_size_allocate_cb(GtkWidget *widget,
GtkAllocation *layout_size,
MimeView *mimeview);
+static MimeInfo *mimeview_get_part_to_use(MimeView *mimeview);
+static void mimeview_launch_cb(MimeView *mimeview)
+{
+ mimeview_launch(mimeview, mimeview_get_part_to_use(mimeview));
+}
static GtkItemFactoryEntry mimeview_popup_entries[] =
{
- {N_("/_Open"), NULL, mimeview_launch, 0, NULL},
- {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
- {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
- {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL},
- {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL},
+ {N_("/_Open (l)"), NULL, mimeview_launch_cb, 0, NULL},
+ {N_("/Open _with (o)..."), NULL, mimeview_open_with, 0, NULL},
+ {N_("/_Display as text (t)"), NULL, mimeview_display_as_text, 0, NULL},
+ {N_("/_Save as (y)..."), NULL, mimeview_save_as, 0, NULL},
+ {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL},
+ {N_("/Next part (a)"), NULL, mimeview_select_next_part,0, NULL},
};
static GtkTargetEntry mimeview_mime_types[] =
popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
"<MimeView>", &popupfactory, mimeview);
tooltips = gtk_tooltips_new();
- gtk_tooltips_set_delay(tooltips, 0);
vbox = gtk_vbox_new(FALSE, 0);
gtk_widget_show(vbox);
GTK_WIDGET_PTR(mimeview->textview));
}
+static gboolean any_part_is_signed(MimeInfo *mimeinfo)
+{
+ while (mimeinfo) {
+ if (privacy_mimeinfo_is_signed(mimeinfo))
+ return TRUE;
+ mimeinfo = procmime_mimeinfo_next(mimeinfo);
+ }
+
+ return FALSE;
+}
+
void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
const gchar *file)
{
g_signal_handlers_block_by_func(G_OBJECT(ctree), mimeview_selected,
mimeview);
+ /* check if the mail's signed - it can change the mail structure */
+
+ if (any_part_is_signed(mimeinfo))
+ debug_print("signed mail\n");
+
mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
+ icon_list_clear(mimeview);
icon_list_create(mimeview, mimeinfo);
g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
(GTK_CTREE(mimeview->ctree), mimeview->opened);
}
+gint mimeview_get_selected_part_num(MimeView *mimeview)
+{
+ gint i = 0;
+ GList *rows = GTK_CLIST(mimeview->ctree)->row_list;
+ while (rows) {
+ if (mimeview->opened == GTK_CTREE_NODE(rows))
+ return i;
+ i++;
+ rows = rows->next;
+ }
+ return -1;
+}
+
+void mimeview_select_part_num(MimeView *mimeview, gint i)
+{
+ if (i < 0)
+ return;
+ gtk_clist_unselect_all(GTK_CLIST(mimeview->ctree));
+ gtk_clist_select_row(GTK_CLIST(mimeview->ctree), i, -1);
+ gtkut_clist_set_focus_row(GTK_CLIST(mimeview->ctree), i);
+}
+
static void mimeview_set_multipart_tree(MimeView *mimeview,
MimeInfo *mimeinfo,
GtkCTreeNode *parent)
const gchar *fname;
if (!partinfo) return;
- if (partinfo == mimeview->opened)
- return;
fname = mimeview->file;
if (!fname) return;
static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
{
TextView *textview = mimeview->textview;
+ GtkWidget *focused = NULL;
+
+ if (mainwindow_get_mainwindow())
+ focused = gtkut_get_focused_child(
+ GTK_CONTAINER(mainwindow_get_mainwindow()->window));
if ((mimeview->type != MIMEVIEW_VIEWER) &&
(mimeview->type == type)) return;
default:
return;
}
-
+ if (focused)
+ gtk_widget_grab_focus(focused);
mimeview->type = type;
}
if (event->button == 2 ||
(event->button == 1 && (event->time - lasttime) < DOUBLE_CLICK_TIME && lastinfo == partinfo)) {
/* call external program for image, audio or html */
- mimeview_launch(mimeview);
+ mimeview_launch(mimeview, partinfo);
return TRUE;
} else if (event->button == 3) {
if (partinfo && (partinfo->type == MIMETYPE_MESSAGE ||
partinfo->type == MIMETYPE_IMAGE ||
partinfo->type == MIMETYPE_MULTIPART))
menu_set_sensitive(mimeview->popupfactory,
- "/Display as text", FALSE);
+ "/Display as text (t)", FALSE);
else
menu_set_sensitive(mimeview->popupfactory,
- "/Display as text", TRUE);
+ "/Display as text (t)", TRUE);
if (partinfo &&
partinfo->type == MIMETYPE_APPLICATION &&
!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))
menu_set_sensitive(mimeview->popupfactory,
- "/Open", FALSE);
+ "/Open (l)", FALSE);
else
menu_set_sensitive(mimeview->popupfactory,
- "/Open", TRUE);
+ "/Open (l)", TRUE);
g_object_set_data(G_OBJECT(mimeview->popupmenu),
"pop_partinfo", partinfo);
mimeview_key_pressed(mimeview->ctree, event, mimeview);
}
+static void mimeview_select_next_part(MimeView *mimeview)
+{
+ gboolean is_next = FALSE;
+
+ GList *child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
+ for (; child != NULL; child = g_list_next(child)) {
+ if (GTK_IS_TOGGLE_BUTTON(child->data) &&
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(child->data))) {
+ is_next = TRUE;
+ } else if (GTK_IS_TOGGLE_BUTTON(child->data) &&
+ is_next) {
+ toggle_icon(GTK_TOGGLE_BUTTON(child->data), mimeview);
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON(child->data), TRUE);
+ icon_selected(mimeview, -1,
+ (MimeInfo *)g_object_get_data(G_OBJECT(child->data),
+ "partinfo"));
+ is_next = FALSE;
+ break;
+ }
+ }
+ if (is_next) {
+ /* we were on the last one, go to first */
+ child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
+ for (; child != NULL; child = g_list_next(child)) {
+ if (GTK_IS_TOGGLE_BUTTON(child->data)) {
+ toggle_icon(GTK_TOGGLE_BUTTON(child->data), mimeview);
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON(child->data), TRUE);
+ icon_selected(mimeview, -1,
+ (MimeInfo *)g_object_get_data(G_OBJECT(child->data),
+ "partinfo"));
+ break;
+ }
+ }
+ }
+}
+
#define BREAK_ON_MODIFIER_KEY() \
if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
case GDK_l:
BREAK_ON_MODIFIER_KEY();
KEY_PRESS_EVENT_STOP();
- mimeview_launch(mimeview);
+ mimeview_launch(mimeview, NULL);
return TRUE;
case GDK_o:
BREAK_ON_MODIFIER_KEY();
KEY_PRESS_EVENT_STOP();
mimeview_check_signature(mimeview);
return TRUE;
+ case GDK_a:
+ BREAK_ON_MODIFIER_KEY();
+ KEY_PRESS_EVENT_STOP();
+ mimeview_select_next_part(mimeview);
+ return TRUE;
default:
break;
}
{
gchar *filename = NULL, *uriname, *tmp;
MimeInfo *partinfo;
+ gint err;
if (!mimeview->opened) return;
if (!mimeview->file) return;
}
if (filename == NULL)
filename = g_path_get_basename("Unnamed part");
-
- tmp = g_filename_from_utf8(filename, -1, NULL, NULL, NULL);
-
+ if (!g_utf8_validate(filename, -1, NULL))
+ tmp = conv_codeset_strdup(filename,
+ conv_get_locale_charset_str(),
+ CS_UTF_8);
+ else
+ tmp = g_strdup(filename);
+
if (tmp == NULL) {
g_warning("filename not in UTF-8");
tmp = g_strdup("Unnamed part");
g_free(tmp);
- if (procmime_get_part(filename, partinfo) < 0)
+ if ((err = procmime_get_part(filename, partinfo)) < 0)
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message: %s"),
+ strerror(-err));
+
uriname = g_strconcat("file://", filename, "\r\n", NULL);
gtk_selection_data_set(selection_data, selection_data->target, 8,
* \param basedir The target directory
* \param number Used for dummy filename if attachment is unnamed
*/
-gchar *mimeview_get_filename_for_part(MimeInfo *partinfo,
+static gchar *mimeview_get_filename_for_part(MimeInfo *partinfo,
const gchar *basedir,
gint number)
{
MimeInfo *partinfo)
{
gchar *dir;
-
+ gint err;
+
dir= g_path_get_dirname(filename);
if (!is_dir_exist(dir))
make_dir_hier(dir);
if (G_ALERTALTERNATE != aval) return FALSE;
}
- if (procmime_get_part(filename, partinfo) < 0) {
+ if ((err = procmime_get_part(filename, partinfo)) < 0) {
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message: %s"),
+ strerror(-err));
return FALSE;
}
if (!mimeview->mimeinfo) return;
partinfo = mimeview->mimeinfo;
- if (prefs_common.attach_save_dir)
+ if (prefs_common.attach_save_dir && *prefs_common.attach_save_dir)
startdir = g_strconcat(prefs_common.attach_save_dir,
G_DIR_SEPARATOR_S, NULL);
+ else
+ startdir = g_strdup(get_home_dir());
dirname = filesel_select_file_save_folder(_("Select destination folder"), startdir);
if (!dirname) {
g_free(prefs_common.attach_save_dir);
g_free(startdir);
- prefs_common.attach_save_dir = g_strdup(dirname);
+ prefs_common.attach_save_dir = g_filename_to_utf8(dirname,
+ -1, NULL, NULL, NULL);
}
static MimeInfo *mimeview_get_part_to_use(MimeView *mimeview)
partinfo = mimeview->spec_part;
mimeview->spec_part = NULL;
} else {
- partinfo = mimeview_get_selected_part(mimeview);
+ partinfo = (MimeInfo *) g_object_get_data
+ (G_OBJECT(mimeview->popupmenu),
+ "pop_partinfo");
+ g_object_set_data(G_OBJECT(mimeview->popupmenu),
+ "pop_partinfo", NULL);
if (!partinfo) {
- partinfo = (MimeInfo *) g_object_get_data
- (G_OBJECT(mimeview->popupmenu),
- "pop_partinfo");
- g_object_set_data(G_OBJECT(mimeview->popupmenu),
- "pop_partinfo", NULL);
+ partinfo = mimeview_get_selected_part(mimeview);
}
}
if (!g_utf8_validate(partname, -1, NULL)) {
gchar *tmp = conv_filename_to_utf8(partname);
- g_free(partname);
- partname = tmp;
+ if (!tmp) {
+ tmp = conv_codeset_strdup(partname,
+ conv_get_locale_charset_str(),
+ CS_UTF_8);
+ }
+ if (tmp) {
+ g_free(partname);
+ partname = tmp;
+ }
}
subst_for_filename(partname);
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);
if (!mimeview->opened) return;
partinfo = mimeview_get_part_to_use(mimeview);
-
+ mimeview_select_mimepart_icon(mimeview, partinfo);
g_return_if_fail(partinfo != NULL);
mimeview_show_message_part(mimeview, partinfo);
}
-static void mimeview_launch(MimeView *mimeview)
+static void mimeview_launch(MimeView *mimeview, MimeInfo *partinfo)
{
- MimeInfo *partinfo;
gchar *filename;
+ gint err;
if (!mimeview->opened) return;
if (!mimeview->file) return;
- partinfo = mimeview_get_part_to_use(mimeview);
+ if (!partinfo)
+ partinfo = mimeview_get_part_to_use(mimeview);
g_return_if_fail(partinfo != NULL);
filename = procmime_get_tmp_file_name(partinfo);
- if (procmime_get_part(filename, partinfo) < 0)
+ if ((err = procmime_get_part(filename, partinfo)) < 0)
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message: %s"),
+ strerror(-err));
else
mimeview_view_file(filename, partinfo, NULL, mimeview);
gchar *cmd;
gchar *mime_command = NULL;
gchar *content_type = NULL;
-
+ gint err;
g_return_if_fail(partinfo != NULL);
filename = procmime_get_tmp_file_name(partinfo);
- if (procmime_get_part(filename, partinfo) < 0) {
+ if ((err = procmime_get_part(filename, partinfo)) < 0) {
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message: %s"),
+ strerror(-err));
g_free(filename);
return;
}
num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "icon_number"));
partinfo = g_object_get_data(G_OBJECT(button), "partinfo");
- 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);
+ 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);
+ }
}
-
part_button_pressed(mimeview, event, partinfo);
return FALSE;
{
GtkCTreeNode *node;
node = gtk_ctree_find_by_row_data(GTK_CTREE(mimeview->ctree), NULL, partinfo);
+
if (node)
gtk_ctree_select(GTK_CTREE(mimeview->ctree), node);
}
case GDK_l:
BREAK_ON_MODIFIER_KEY();
KEY_PRESS_EVENT_STOP();
- mimeview_launch(mimeview);
+ mimeview_launch(mimeview, NULL);
return TRUE;
case GDK_o:
BREAK_ON_MODIFIER_KEY();
KEY_PRESS_EVENT_STOP();
mimeview_check_signature(mimeview);
return TRUE;
+ case GDK_a:
+ BREAK_ON_MODIFIER_KEY();
+ KEY_PRESS_EVENT_STOP();
+ mimeview_select_next_part(mimeview);
+ return TRUE;
default:
break;
}
}
}
+static gboolean icon_popup_menu(GtkWidget *widget, gpointer data)
+{
+ MimeView *mimeview = (MimeView *)data;
+ MimeInfo *partinfo = g_object_get_data(G_OBJECT(widget), "partinfo");
+
+ g_object_set_data(G_OBJECT(mimeview->popupmenu),
+ "pop_partinfo", partinfo);
+ gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
+ NULL, NULL, NULL, NULL,
+ 0, gtk_get_current_event_time());
+ return TRUE;
+}
+
static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
{
GtkWidget *pixmap = NULL;
GINT_TO_POINTER(mimeview->icon_count));
g_object_set_data(G_OBJECT(button), "partinfo",
mimeinfo);
-
+
switch (mimeinfo->type) {
case MIMETYPE_TEXT:
stockp = STOCK_PIXMAP_MIME_TEXT_HTML;
else if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "enriched"))
stockp = STOCK_PIXMAP_MIME_TEXT_ENRICHED;
+ else if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "calendar"))
+ stockp = STOCK_PIXMAP_MIME_TEXT_CALENDAR;
else
stockp = STOCK_PIXMAP_MIME_TEXT_PLAIN;
break;
stockp = STOCK_PIXMAP_MIME_MESSAGE;
break;
case MIMETYPE_APPLICATION:
- stockp = STOCK_PIXMAP_MIME_APPLICATION;
+ if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "pgp-signature"))
+ stockp = STOCK_PIXMAP_MIME_PGP_SIG;
+ else if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "pdf"))
+ stockp = STOCK_PIXMAP_MIME_PDF;
+ else if (mimeinfo->subtype && !g_ascii_strcasecmp(mimeinfo->subtype, "postscript"))
+ stockp = STOCK_PIXMAP_MIME_PS;
+ else
+ stockp = STOCK_PIXMAP_MIME_APPLICATION;
break;
case MIMETYPE_IMAGE:
stockp = STOCK_PIXMAP_MIME_IMAGE;
gtk_widget_show_all(button);
gtk_drag_source_set(button, GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
mimeview_mime_types, 1, GDK_ACTION_COPY);
+#ifndef MAEMO
+ g_signal_connect(G_OBJECT(button), "popup-menu",
+ G_CALLBACK(icon_popup_menu), mimeview);
+#else
+ gtk_widget_tap_and_hold_setup(GTK_WIDGET(button), NULL, NULL,
+ GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
+ g_signal_connect(G_OBJECT(button), "tap-and-hold",
+ G_CALLBACK(icon_popup_menu), mimeview);
+#endif
g_signal_connect(G_OBJECT(button), "button_release_event",
G_CALLBACK(icon_clicked_cb), mimeview);
g_signal_connect(G_OBJECT(button), "key_press_event",
{
GList *child;
GtkAdjustment *adj;
-
+
child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
for (; child != NULL; child = g_list_next(child)) {
gtkut_container_remove(GTK_CONTAINER(mimeview->icon_vbox),
"partinfo") == (gpointer)mimeinfo) {
toggle_icon(GTK_TOGGLE_BUTTON(child->data), mimeview);
gtk_toggle_button_set_active
- (GTK_TOGGLE_BUTTON(child->data), TRUE);
+ (GTK_TOGGLE_BUTTON(child->data), TRUE);
}
}
}
if (!mainwin)
return;
- else if (!strcmp(cmd, "sc://view_log"))
+ g_object_set_data(G_OBJECT(mimeview->popupmenu),
+ "pop_partinfo", NULL);
+
+ if (!strcmp(cmd, "sc://view_log"))
log_window_show(mainwin->logwin);
else if (!strcmp(cmd, "sc://save_as"))
mimeview_save_as(mimeview);
else if (!strcmp(cmd, "sc://open_with"))
mimeview_open_with(mimeview);
else if (!strcmp(cmd, "sc://open"))
- mimeview_launch(mimeview);
+ mimeview_launch(mimeview, NULL);
else if (!strcmp(cmd, "sc://select_attachment") && data != NULL) {
icon_list_toggle_by_mime_info(mimeview, (MimeInfo *)data);
icon_selected(mimeview, -1, (MimeInfo *)data);
} else if (!strcmp(cmd, "sc://open_attachment") && data != NULL) {
- icon_list_toggle_by_mime_info(mimeview, (MimeInfo *)data);
- icon_selected(mimeview, -1, (MimeInfo *)data);
- mimeview_launch(mimeview);
+ mimeview_launch(mimeview, (MimeInfo *)data);
} else if (!strcmp(cmd, "sc://menu_attachment") && data != NULL) {
mimeview->spec_part = (MimeInfo *)data;
part_button_pressed(mimeview, event, (MimeInfo *)data);