/*
* 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
#include "stock_pixmap.h"
#include "gtk/gtkvscrollbutton.h"
#include "gtk/logwindow.h"
-
+#include "timing.h"
typedef enum
{
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);
+ MimeInfo *partinfo,
+ gboolean automatic);
static void mimeview_view_file (const gchar *filename,
MimeInfo *partinfo,
- const gchar *cmdline,
+ const gchar *cmd,
MimeView *mimeview);
static gboolean icon_clicked_cb (GtkWidget *button,
GdkEventButton *event,
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"), NULL, mimeview_launch_cb, 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},
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)
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 ||
switch (event->keyval) {
case GDK_space:
- if (textview_scroll_page(mimeview->textview, FALSE))
+ if (mimeview_scroll_page(mimeview, FALSE))
return TRUE;
node = GTK_CTREE_NODE_NEXT(mimeview->opened);
}
break;
case GDK_BackSpace:
- textview_scroll_page(mimeview->textview, TRUE);
+ mimeview_scroll_page(mimeview, TRUE);
return TRUE;
case GDK_Return:
- textview_scroll_one_line(mimeview->textview,
+ mimeview_scroll_one_line(mimeview,
(event->state & GDK_MOD1_MASK) != 0);
return TRUE;
case GDK_n:
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();
if (procmime_get_part(filename, partinfo) < 0)
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message."));
uriname = g_strconcat("file://", filename, "\r\n", NULL);
gtk_selection_data_set(selection_data, selection_data->target, 8,
if (procmime_get_part(filename, partinfo) < 0) {
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message."));
return FALSE;
}
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);
}
}
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;
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);
if (procmime_get_part(filename, partinfo) < 0)
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message."));
else
mimeview_view_file(filename, partinfo, NULL, mimeview);
partinfo = mimeview_get_part_to_use(mimeview);
- mimeview_open_part_with(mimeview, partinfo);
+ mimeview_open_part_with(mimeview, partinfo, FALSE);
}
-static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo)
+static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboolean automatic)
{
gchar *filename;
gchar *cmd;
if (procmime_get_part(filename, partinfo) < 0) {
alertpanel_error
- (_("Can't save the part of multipart message."));
+ (_("Couldn't save the part of multipart message."));
g_free(filename);
return;
}
content_type = procmime_get_content_type_str(partinfo->type,
partinfo->subtype);
}
- mime_command = mailcap_get_command_for_type(content_type);
-
+
+ if ((partinfo->type == MIMETYPE_TEXT && !strcmp(partinfo->subtype, "html"))
+ && prefs_common.uri_cmd && prefs_common.uri_cmd[0]) {
+ mime_command = g_strdup(prefs_common.uri_cmd);
+ g_free(content_type);
+ content_type = NULL;
+ } else if (partinfo->type != MIMETYPE_TEXT || !prefs_common.ext_editor_cmd
+ || !prefs_common.ext_editor_cmd[0]) {
+ mime_command = mailcap_get_command_for_type(content_type, filename);
+ } else {
+ mime_command = g_strdup(prefs_common.ext_editor_cmd);
+ g_free(content_type);
+ content_type = NULL;
+ }
if (mime_command == NULL) {
/* try with extension this time */
g_free(content_type);
content_type = procmime_get_mime_type(filename);
- mime_command = mailcap_get_command_for_type(content_type);
+ mime_command = mailcap_get_command_for_type(content_type, filename);
}
- g_free(content_type);
- cmd = input_dialog_combo
- (_("Open with"),
- _("Enter the command line to open file:\n"
- "('%s' will be replaced with file name)"),
- mime_command ? mime_command : prefs_common.mime_open_cmd,
- prefs_common.mime_open_cmd_history,
- TRUE);
- g_free(mime_command);
+ if (mime_command == NULL)
+ automatic = FALSE;
+
+ if (!automatic) {
+ gboolean remember = FALSE;
+ if (content_type != NULL)
+ cmd = input_dialog_combo_remember
+ (_("Open with"),
+ _("Enter the command line to open file:\n"
+ "('%s' will be replaced with file name)"),
+ mime_command ? mime_command : prefs_common.mime_open_cmd,
+ prefs_common.mime_open_cmd_history,
+ TRUE, &remember);
+ else
+ cmd = input_dialog_combo
+ (_("Open with"),
+ _("Enter the command line to open file:\n"
+ "('%s' will be replaced with file name)"),
+ mime_command ? mime_command : prefs_common.mime_open_cmd,
+ prefs_common.mime_open_cmd_history,
+ TRUE);
+ if (cmd && remember) {
+ mailcap_update_default(content_type, cmd);
+ }
+ g_free(mime_command);
+ } else {
+ cmd = mime_command;
+ }
if (cmd) {
mimeview_view_file(filename, partinfo, cmd, mimeview);
g_free(prefs_common.mime_open_cmd);
prefs_common.mime_open_cmd_history =
add_history(prefs_common.mime_open_cmd_history, cmd);
}
-
+ g_free(content_type);
g_free(filename);
}
static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
- const gchar *cmdline, MimeView *mimeview)
-{
- 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 = DEFAULT_MIME_CMD;
- gchar buf[1024];
- gchar m_buf[1024];
- const gchar *cmd;
- const gchar *def_cmd;
- const gchar *p;
-
- if (cmdline) {
- cmd = cmdline;
- def_cmd = NULL;
- } else if (MIMETYPE_APPLICATION == partinfo->type &&
- !g_ascii_strcasecmp(partinfo->subtype, "octet-stream")) {
- mimeview_open_part_with(mimeview, partinfo);
- return;
- } else if (MIMETYPE_IMAGE == partinfo->type) {
- cmd = prefs_common.mime_image_viewer;
- def_cmd = default_image_cmdline;
- } else if (MIMETYPE_AUDIO == partinfo->type) {
- cmd = prefs_common.mime_audio_player;
- def_cmd = default_audio_cmdline;
- } else if (MIMETYPE_TEXT == partinfo->type && !strcmp(partinfo->subtype, "html")) {
- cmd = prefs_common.uri_cmd;
- def_cmd = default_html_cmdline;
- } else {
- gchar *content_type;
-
- content_type = procmime_get_content_type_str(partinfo->type, partinfo->subtype);
- g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
- content_type, "%s");
- g_free(content_type);
- cmd = m_buf;
- def_cmd = NULL;
- }
-
- if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
- !strchr(p + 2, '%'))
- g_snprintf(buf, sizeof(buf), cmd, filename);
+ const gchar *cmd, MimeView *mimeview)
+{
+ gchar *p;
+ gchar buf[BUFFSIZE];
+ if (cmd == NULL)
+ mimeview_open_part_with(mimeview, partinfo, TRUE);
else {
- if (cmd)
+ if ((p = strchr(cmd, '%')) && *(p + 1) == 's' &&
+ !strchr(p + 2, '%'))
+ g_snprintf(buf, sizeof(buf), cmd, filename);
+ else {
g_warning("MIME viewer command line is invalid: '%s'", cmd);
- if (def_cmd)
- g_snprintf(buf, sizeof(buf), def_cmd, filename);
- else {
- mimeview_open_part_with(mimeview, partinfo);
- return;
- }
+ mimeview_open_part_with(mimeview, partinfo, FALSE);
+ }
+ if (execute_command_line(buf, TRUE) != 0)
+ mimeview_open_part_with(mimeview, partinfo, FALSE);
}
-
- if (execute_command_line(buf, TRUE) != 0)
- mimeview_open_part_with(mimeview, partinfo);
}
void mimeview_register_viewer_factory(MimeViewerFactory *factory)
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);
}
+void mimeview_select_mimepart_icon(MimeView *mimeview, MimeInfo *partinfo)
+{
+ icon_list_toggle_by_mime_info(mimeview, partinfo);
+ icon_selected(mimeview, -1, partinfo);
+}
+
#undef KEY_PRESS_EVENT_STOP
#define KEY_PRESS_EVENT_STOP() \
g_signal_stop_emission_by_name(G_OBJECT(button), \
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
/* stop the button being untoggled */
KEY_PRESS_EVENT_STOP();
- if (textview_scroll_page(textview, FALSE))
+ if (mimeview_scroll_page(mimeview, FALSE))
return TRUE;
if (icon_list_select_by_number(mimeview, num + 1))
break;
case GDK_BackSpace:
- textview_scroll_page(textview, TRUE);
+ mimeview_scroll_page(mimeview, TRUE);
return TRUE;
case GDK_Return:
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
KEY_PRESS_EVENT_STOP();
- textview_scroll_one_line(textview,
+ mimeview_scroll_one_line(mimeview,
(event->state & GDK_MOD1_MASK) != 0);
return TRUE;
} else {
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();
GINT_TO_POINTER(mimeview->icon_count));
g_object_set_data(G_OBJECT(button), "partinfo",
mimeinfo);
-
+
switch (mimeinfo->type) {
case MIMETYPE_TEXT:
{
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),
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);
}
}
+gboolean mimeview_scroll_page(MimeView *mimeview, gboolean up)
+{
+ if (mimeview->type == MIMEVIEW_TEXT)
+ return textview_scroll_page(mimeview->textview, up);
+ else if (mimeview->mimeviewer) {
+ MimeViewer *mimeviewer = mimeview->mimeviewer;
+ if (mimeviewer->scroll_page)
+ return mimeviewer->scroll_page(mimeviewer, up);
+ }
+ return TRUE;
+}
+
+void mimeview_scroll_one_line(MimeView *mimeview, gboolean up)
+{
+ if (mimeview->type == MIMEVIEW_TEXT)
+ textview_scroll_one_line(mimeview->textview, up);
+ else if (mimeview->mimeviewer) {
+ MimeViewer *mimeviewer = mimeview->mimeviewer;
+ if (mimeviewer->scroll_one_line)
+ mimeviewer->scroll_one_line(mimeviewer, up);
+ }
+}