2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
36 #include <sys/types.h>
43 #include "summaryview.h"
46 #include "alertpanel.h"
47 #include "inputdialog.h"
50 #include "prefs_common.h"
51 #include "procheader.h"
52 #include "stock_pixmap.h"
53 #include "gtk/gtkvscrollbutton.h"
54 #include "gtk/logwindow.h"
56 #include "manage_window.h"
67 #define N_MIMEVIEW_COLS 4
69 static void mimeview_set_multipart_tree (MimeView
*mimeview
,
72 static void mimeview_show_message_part (MimeView
*mimeview
,
74 static void mimeview_change_view_type (MimeView
*mimeview
,
76 static gchar
*mimeview_get_filename_for_part (MimeInfo
*partinfo
,
79 static gboolean
mimeview_write_part (const gchar
*filename
,
81 gboolean handle_error
);
83 static void mimeview_selected (GtkTreeSelection
*selection
,
85 static gint
mimeview_button_pressed (GtkWidget
*widget
,
86 GdkEventButton
*event
,
88 static gint
mimeview_key_pressed (GtkWidget
*widget
,
92 static void mimeview_drag_data_get (GtkWidget
*widget
,
93 GdkDragContext
*drag_context
,
94 GtkSelectionData
*selection_data
,
99 static gboolean
mimeview_scrolled (GtkWidget
*widget
,
100 GdkEventScroll
*event
,
103 static void mimeview_save_all (MimeView
*mimeview
);
105 static void mimeview_open_part_with (MimeView
*mimeview
,
109 static void mimeview_send_to (MimeView
*mimeview
,
111 static void mimeview_view_file (const gchar
*filename
,
115 static gboolean
icon_clicked_cb (GtkWidget
*button
,
116 GdkEventButton
*event
,
118 static void icon_selected (MimeView
*mimeview
,
121 static gint
icon_key_pressed (GtkWidget
*button
,
124 static void icon_list_append_icon (MimeView
*mimeview
,
126 static void icon_list_create (MimeView
*mimeview
,
128 static void icon_list_clear (MimeView
*mimeview
);
129 static void icon_list_toggle_by_mime_info (MimeView
*mimeview
,
131 static void ctree_size_allocate_cb (GtkWidget
*widget
,
132 GtkAllocation
*allocation
,
134 static gint
mime_toggle_button_cb(GtkWidget
*button
, GdkEventButton
*event
,
136 static gboolean
part_button_pressed (MimeView
*mimeview
,
137 GdkEventButton
*event
,
139 static void icon_scroll_size_allocate_cb(GtkWidget
*widget
,
140 GtkAllocation
*layout_size
,
142 static MimeInfo
*mimeview_get_part_to_use(MimeView
*mimeview
);
143 static const gchar
*get_part_name(MimeInfo
*partinfo
);
144 static const gchar
*get_part_description(MimeInfo
*partinfo
);
146 static void mimeview_launch_cb(GtkAction
*action
, gpointer data
)
148 MimeView
*mimeview
= (MimeView
*)data
;
149 mimeview_launch(mimeview
, mimeview_get_part_to_use(mimeview
));
153 static void mimeview_open_with_cb(GtkAction
*action
, gpointer data
)
155 mimeview_open_with((MimeView
*)data
);
159 static void mimeview_send_to_cb(GtkAction
*action
, gpointer data
)
161 MimeView
*mimeview
= (MimeView
*)data
;
162 mimeview_send_to(mimeview
, mimeview_get_part_to_use(mimeview
));
165 static void mimeview_display_as_text_cb(GtkAction
*action
, gpointer data
)
167 mimeview_display_as_text((MimeView
*)data
);
170 static void mimeview_save_as_cb(GtkAction
*action
, gpointer data
)
172 mimeview_save_as((MimeView
*)data
);
175 static void mimeview_save_all_cb(GtkAction
*action
, gpointer data
)
177 mimeview_save_all((MimeView
*)data
);
180 static void mimeview_select_next_part_cb(GtkAction
*action
, gpointer data
)
182 mimeview_select_next_part((MimeView
*)data
);
185 static void mimeview_select_prev_part_cb(GtkAction
*action
, gpointer data
)
187 mimeview_select_prev_part((MimeView
*)data
);
190 static GtkActionEntry mimeview_menu_actions
[] = {
191 { "MimeView", NULL
, "MimeView" },
192 { "MimeView/Open", NULL
, N_("_Open"), NULL
, "Open MIME part", G_CALLBACK(mimeview_launch_cb
) },
193 #if (!defined G_OS_WIN32)
194 { "MimeView/OpenWith", NULL
, N_("Open _with..."), NULL
, "Open MIME part with...", G_CALLBACK(mimeview_open_with_cb
) },
196 { "MimeView/SendTo", NULL
, N_("Send to..."), NULL
, "Send to", G_CALLBACK(mimeview_send_to_cb
) },
197 { "MimeView/DisplayAsText", NULL
, N_("_Display as text"), NULL
, "Display as text", G_CALLBACK(mimeview_display_as_text_cb
) },
198 { "MimeView/SaveAs", NULL
, N_("_Save as..."), NULL
, "Save as", G_CALLBACK(mimeview_save_as_cb
) },
199 { "MimeView/SaveAll", NULL
, N_("Save _all..."), NULL
, "Save all parts", G_CALLBACK(mimeview_save_all_cb
) },
200 { "MimeView/NextPart", NULL
, N_("Next part"), NULL
, "Next part", G_CALLBACK(mimeview_select_next_part_cb
) },
201 { "MimeView/PrevPart", NULL
, N_("Previous part"), NULL
, "Previous part", G_CALLBACK(mimeview_select_prev_part_cb
) }
204 static GtkTargetEntry mimeview_mime_types
[] =
206 {"text/uri-list", 0, 0}
209 GSList
*mimeviewer_factories
;
212 static GdkCursor
*hand_cursor
= NULL
;
214 static gboolean
mimeview_visi_notify(GtkWidget
*widget
,
215 GdkEventVisibility
*event
,
218 gdk_window_set_cursor(gtk_widget_get_window(widget
), hand_cursor
);
222 static gboolean
mimeview_leave_notify(GtkWidget
*widget
,
223 GdkEventCrossing
*event
,
226 gdk_window_set_cursor(gtk_widget_get_window(widget
), NULL
);
230 static gboolean
mimeview_enter_notify(GtkWidget
*widget
,
231 GdkEventCrossing
*event
,
234 gdk_window_set_cursor(gtk_widget_get_window(widget
), hand_cursor
);
238 MimeView
*mimeview_create(MainWindow
*mainwin
)
243 GtkWidget
*scrolledwin
;
245 GtkWidget
*mime_notebook
;
246 GtkWidget
*popupmenu
;
247 GtkWidget
*ctree_mainbox
;
249 GtkWidget
*mime_toggle
;
250 GtkWidget
*icon_mainbox
;
251 GtkWidget
*icon_scroll
;
252 GtkWidget
*icon_vbox
;
254 GtkWidget
*scrollbutton
;
256 NoticeView
*siginfoview
;
259 GtkCellRenderer
*renderer
;
260 GtkTreeViewColumn
*column
;
261 GtkTreeSelection
*selection
;
263 gchar
*titles
[N_MIMEVIEW_COLS
];
267 hand_cursor
= gdk_cursor_new(GDK_HAND2
);
269 debug_print("Creating MIME view...\n");
270 mimeview
= g_new0(MimeView
, 1);
272 titles
[COL_MIMETYPE
] = _("MIME Type");
273 titles
[COL_SIZE
] = _("Size");
274 titles
[COL_NAME
] = _("Name");
276 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
277 gtk_widget_show(scrolledwin
);
278 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
279 GTK_POLICY_AUTOMATIC
,
280 GTK_POLICY_AUTOMATIC
);
282 model
= gtk_tree_store_new(N_MIMEVIEW_COLS
,
288 ctree
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(model
));
289 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ctree
), FALSE
);
290 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(ctree
),
291 prefs_common
.use_stripes_everywhere
);
292 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ctree
),
293 prefs_common
.show_col_headers
);
295 renderer
= gtk_cell_renderer_text_new();
296 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
297 -1, titles
[COL_MIMETYPE
],renderer
,
298 "text", COL_MIMETYPE
, NULL
);
299 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
301 renderer
= gtk_cell_renderer_text_new();
302 #if(GTK_CHECK_VERSION(2,18,0))
303 gtk_cell_renderer_set_alignment(renderer
, 1, 0.5);
305 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
306 -1, titles
[COL_SIZE
], renderer
,
307 "text", COL_SIZE
, NULL
);
308 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
309 gtk_tree_view_column_set_alignment(GTK_TREE_VIEW_COLUMN(column
), 1);
311 renderer
= gtk_cell_renderer_text_new();
312 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
313 -1, titles
[COL_NAME
], renderer
,
314 "text", COL_NAME
, NULL
);
315 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
316 gtk_tree_view_column_set_expand(GTK_TREE_VIEW_COLUMN(column
), TRUE
);
318 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(ctree
));
319 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_BROWSE
);
321 gtk_widget_show(ctree
);
322 gtk_container_add(GTK_CONTAINER(scrolledwin
), ctree
);
323 gtk_drag_source_set(ctree
, GDK_BUTTON1_MASK
|GDK_BUTTON3_MASK
,
324 mimeview_mime_types
, 1, GDK_ACTION_COPY
);
326 g_signal_connect(G_OBJECT(selection
), "changed",
327 G_CALLBACK(mimeview_selected
), mimeview
);
328 g_signal_connect(G_OBJECT(ctree
), "button_release_event",
329 G_CALLBACK(mimeview_button_pressed
), mimeview
);
330 g_signal_connect(G_OBJECT(ctree
), "key_press_event",
331 G_CALLBACK(mimeview_key_pressed
), mimeview
);
332 g_signal_connect(G_OBJECT(ctree
), "drag_data_get",
333 G_CALLBACK(mimeview_drag_data_get
), mimeview
);
335 mime_notebook
= gtk_notebook_new();
336 gtk_widget_show(mime_notebook
);
337 gtkut_widget_set_can_focus(mime_notebook
, FALSE
);
338 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(mime_notebook
), FALSE
);
339 gtk_notebook_set_show_border(GTK_NOTEBOOK(mime_notebook
), FALSE
);
341 icon_vbox
= gtk_vbox_new(FALSE
, 2);
342 gtk_widget_show(icon_vbox
);
343 icon_scroll
= gtk_layout_new(NULL
, NULL
);
344 gtk_widget_show(icon_scroll
);
345 gtk_layout_put(GTK_LAYOUT(icon_scroll
), icon_vbox
, 0, 0);
346 scrollbutton
= gtk_vscrollbutton_new(gtk_layout_get_vadjustment(GTK_LAYOUT(icon_scroll
)));
347 gtk_widget_show(scrollbutton
);
349 g_signal_connect(G_OBJECT(icon_scroll
), "scroll_event",
350 G_CALLBACK(mimeview_scrolled
), mimeview
);
352 mime_toggle
= gtk_event_box_new();
353 gtk_event_box_set_visible_window(GTK_EVENT_BOX(mime_toggle
), FALSE
);
355 g_signal_connect(G_OBJECT(mime_toggle
), "motion-notify-event",
356 G_CALLBACK(mimeview_visi_notify
), mimeview
);
357 g_signal_connect(G_OBJECT(mime_toggle
), "leave-notify-event",
358 G_CALLBACK(mimeview_leave_notify
), mimeview
);
359 g_signal_connect(G_OBJECT(mime_toggle
), "enter-notify-event",
360 G_CALLBACK(mimeview_enter_notify
), mimeview
);
362 gtk_container_set_border_width(GTK_CONTAINER(mime_toggle
), 2);
363 gtk_widget_show(mime_toggle
);
364 mimeview
->ctree_mode
= FALSE
;
365 arrow
= gtk_arrow_new(GTK_ARROW_LEFT
, GTK_SHADOW_NONE
);
366 gtk_widget_show(arrow
);
367 gtk_widget_size_request(arrow
, &r
);
368 gtk_container_add(GTK_CONTAINER(mime_toggle
), arrow
);
369 g_signal_connect(G_OBJECT(mime_toggle
), "button_release_event",
370 G_CALLBACK(mime_toggle_button_cb
), mimeview
);
372 icon_mainbox
= gtk_vbox_new(FALSE
, 0);
373 gtk_widget_show(icon_mainbox
);
374 gtk_widget_set_size_request(icon_mainbox
, 32, -1);
375 gtk_box_pack_start(GTK_BOX(icon_mainbox
), mime_toggle
, FALSE
, FALSE
, 0);
376 gtk_box_pack_start(GTK_BOX(icon_mainbox
), icon_scroll
, TRUE
, TRUE
, 3);
377 gtk_box_pack_end(GTK_BOX(icon_mainbox
), scrollbutton
, FALSE
, FALSE
, 0);
378 g_signal_connect(G_OBJECT(icon_mainbox
), "size_allocate",
379 G_CALLBACK(icon_scroll_size_allocate_cb
), mimeview
);
381 ctree_mainbox
= gtk_hbox_new(FALSE
, 0);
382 gtk_box_pack_start(GTK_BOX(ctree_mainbox
), scrolledwin
, TRUE
, TRUE
, 0);
383 g_signal_connect(G_OBJECT(ctree_mainbox
), "size_allocate",
384 G_CALLBACK(ctree_size_allocate_cb
), mimeview
);
386 mimeview
->ui_manager
= gtk_ui_manager_new();
387 mimeview
->action_group
= cm_menu_create_action_group_full(mimeview
->ui_manager
,
388 "MimeView", mimeview_menu_actions
,
389 G_N_ELEMENTS(mimeview_menu_actions
), (gpointer
)mimeview
);
391 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR
)
392 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
393 "/Menus/", "MimeView", "MimeView", GTK_UI_MANAGER_MENU
);
394 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
395 "/Menus/MimeView/", "Open", "MimeView/Open",
396 GTK_UI_MANAGER_MENUITEM
);
397 #if (!defined G_OS_WIN32)
398 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
399 "/Menus/MimeView/", "OpenWith", "MimeView/OpenWith",
400 GTK_UI_MANAGER_MENUITEM
);
402 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
403 "/Menus/MimeView/", "SendTo", "MimeView/SendTo",
404 GTK_UI_MANAGER_MENUITEM
);
405 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
406 "/Menus/MimeView/", "DisplayAsText", "MimeView/DisplayAsText",
407 GTK_UI_MANAGER_MENUITEM
);
408 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
409 "/Menus/MimeView/", "SaveAs", "MimeView/SaveAs",
410 GTK_UI_MANAGER_MENUITEM
);
411 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
412 "/Menus/MimeView/", "SaveAll", "MimeView/SaveAll",
413 GTK_UI_MANAGER_MENUITEM
);
414 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
415 "/Menus/MimeView/", "NextPart", "MimeView/NextPart",
416 GTK_UI_MANAGER_MENUITEM
);
417 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
418 "/Menus/MimeView/", "PrevPart", "MimeView/PrevPart",
419 GTK_UI_MANAGER_MENUITEM
);
421 popupmenu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
422 gtk_ui_manager_get_widget(mimeview
->ui_manager
, "/Menus/MimeView")) );
425 vbox
= gtk_vbox_new(FALSE
, 0);
426 gtk_widget_show(vbox
);
427 siginfoview
= noticeview_create(mainwin
);
428 noticeview_hide(siginfoview
);
429 noticeview_set_icon_clickable(siginfoview
, TRUE
);
430 gtk_box_pack_start(GTK_BOX(vbox
), mime_notebook
, TRUE
, TRUE
, 0);
431 gtk_box_pack_end(GTK_BOX(vbox
), GTK_WIDGET_PTR(siginfoview
), FALSE
, FALSE
, 0);
433 paned
= gtk_vpaned_new();
434 gtk_widget_show(paned
);
435 gtk_paned_pack1(GTK_PANED(paned
), ctree_mainbox
, FALSE
, TRUE
);
436 gtk_paned_pack2(GTK_PANED(paned
), vbox
, TRUE
, TRUE
);
438 hbox
= gtk_hbox_new(FALSE
, 0);
439 gtk_box_pack_start(GTK_BOX(hbox
), paned
, TRUE
, TRUE
, 0);
440 gtk_box_pack_start(GTK_BOX(hbox
), icon_mainbox
, FALSE
, FALSE
, 0);
442 gtk_widget_show(hbox
);
443 gtk_widget_hide(ctree_mainbox
);
445 gtk_widget_set_size_request(mime_toggle
, -1, r
.height
+ 8);
447 mimeview
->hbox
= hbox
;
448 mimeview
->paned
= paned
;
449 mimeview
->scrolledwin
= scrolledwin
;
450 mimeview
->ctree
= ctree
;
451 mimeview
->mime_notebook
= mime_notebook
;
452 mimeview
->popupmenu
= popupmenu
;
454 mimeview
->ctree_mainbox
= ctree_mainbox
;
455 mimeview
->icon_scroll
= icon_scroll
;
456 mimeview
->icon_vbox
= icon_vbox
;
457 mimeview
->icon_mainbox
= icon_mainbox
;
458 mimeview
->icon_count
= 0;
459 mimeview
->mainwin
= mainwin
;
460 mimeview
->mime_toggle
= mime_toggle
;
461 mimeview
->siginfoview
= siginfoview
;
462 mimeview
->scrollbutton
= scrollbutton
;
463 mimeview
->target_list
= gtk_target_list_new(mimeview_mime_types
, 1);
465 mimeviews
= g_slist_prepend(mimeviews
, mimeview
);
470 void mimeview_init(MimeView
*mimeview
)
472 textview_init(mimeview
->textview
);
474 gtk_container_add(GTK_CONTAINER(mimeview
->mime_notebook
),
475 GTK_WIDGET_PTR(mimeview
->textview
));
478 static gboolean
any_part_is_signed(MimeInfo
*mimeinfo
)
481 if (privacy_mimeinfo_is_signed(mimeinfo
))
483 mimeinfo
= procmime_mimeinfo_next(mimeinfo
);
489 void mimeview_show_message(MimeView
*mimeview
, MimeInfo
*mimeinfo
,
492 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
494 mimeview_clear(mimeview
);
496 cm_return_if_fail(file
!= NULL
);
497 cm_return_if_fail(mimeinfo
!= NULL
);
499 mimeview
->mimeinfo
= mimeinfo
;
501 mimeview
->file
= g_strdup(file
);
503 g_signal_handlers_block_by_func(G_OBJECT(ctree
), mimeview_selected
,
506 /* check if the mail's signed - it can change the mail structure */
508 if (any_part_is_signed(mimeinfo
))
509 debug_print("signed mail\n");
511 mimeview_set_multipart_tree(mimeview
, mimeinfo
, NULL
);
512 gtk_tree_view_expand_all(ctree
);
513 icon_list_clear(mimeview
);
514 icon_list_create(mimeview
, mimeinfo
);
516 g_signal_handlers_unblock_by_func(G_OBJECT(ctree
),
517 mimeview_selected
, mimeview
);
521 static void mimeview_check_sig_cancel_now(MimeView
*mimeview
);
524 static void mimeview_free_mimeinfo(MimeView
*mimeview
)
526 gboolean defer
= FALSE
;
528 defer
= (mimeview
->check_data
!= NULL
);
530 mimeview
->check_data
->free_after_use
= TRUE
;
532 if (mimeview
->mimeinfo
!= NULL
&& !defer
) {
533 procmime_mimeinfo_free_all(&mimeview
->mimeinfo
);
534 mimeview
->mimeinfo
= NULL
;
537 debug_print("deferring free(mimeinfo) and cancelling check\n");
538 mimeview_check_sig_cancel_now(mimeview
);
543 void mimeview_destroy(MimeView
*mimeview
)
547 for (cur
= mimeview
->viewers
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
548 MimeViewer
*viewer
= (MimeViewer
*) cur
->data
;
549 viewer
->destroy_viewer(viewer
);
551 g_slist_free(mimeview
->viewers
);
552 gtk_target_list_unref(mimeview
->target_list
);
555 if (mimeview
->check_data
) {
556 mimeview
->check_data
->destroy_mimeview
= TRUE
;
557 debug_print("deferring destroy\n");
561 mimeview_free_mimeinfo(mimeview
);
562 gtk_tree_path_free(mimeview
->opened
);
563 g_free(mimeview
->file
);
565 mimeviews
= g_slist_remove(mimeviews
, mimeview
);
570 MimeInfo
*mimeview_get_selected_part(MimeView
*mimeview
)
572 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
574 GtkTreeSelection
*selection
;
575 MimeInfo
*partinfo
= NULL
;
577 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mimeview
->ctree
));
578 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
579 gtk_tree_model_get(model
, &iter
, COL_DATA
, &partinfo
, -1);
584 MimeInfo
*mimeview_get_node_part(MimeView
*mimeview
, GtkTreePath
*path
)
586 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
590 gtk_tree_model_get_iter(model
, &iter
, path
);
591 gtk_tree_model_get(model
, &iter
, COL_DATA
, &partinfo
, -1);
595 gboolean
mimeview_tree_is_empty(MimeView
*mimeview
)
597 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
599 return !gtk_tree_model_get_iter_first(model
, &iter
);
602 static gboolean
mimeview_tree_next(GtkTreeModel
*model
, GtkTreePath
*path
)
604 GtkTreeIter iter
, parent
;
607 gtk_tree_model_get_iter(model
, &iter
, path
);
609 if (gtk_tree_model_iter_has_child(model
, &iter
)) {
610 gtk_tree_path_down(path
);
614 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &iter
);
616 if (!gtk_tree_model_iter_next(model
, &iter
)) {
618 GtkTreeIter saved_parent
= parent
;
619 gtk_tree_path_up(path
);
620 if (gtk_tree_model_iter_next(model
, &parent
)) {
621 gtk_tree_path_next(path
);
624 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &saved_parent
);
629 gtk_tree_path_next(path
);
636 static gboolean
mimeview_tree_prev(MimeView
*mimeview
, GtkTreePath
*path
)
638 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
639 GtkTreeIter iter
, child
, parent
;
642 gtk_tree_model_get_iter(model
, &iter
, path
);
643 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &iter
);
645 if (gtk_tree_path_prev(path
)) {
646 gtk_tree_model_get_iter(model
, &iter
, path
);
648 if (gtk_tree_model_iter_nth_child(model
, &child
, &iter
, 0)) {
649 gtk_tree_path_down(path
);
651 while (gtk_tree_model_iter_next(model
, &child
))
652 gtk_tree_path_next(path
);
659 gtk_tree_path_up(path
);
666 gint
mimeview_get_selected_part_num(MimeView
*mimeview
)
668 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
673 gtk_tree_model_get_iter_first(model
, &iter
);
674 path
= gtk_tree_model_get_path(model
, &iter
);
677 if (!gtk_tree_path_compare(mimeview
->opened
, path
)) {
678 gtk_tree_path_free(path
);
683 } while (mimeview_tree_next(model
, path
));
685 gtk_tree_path_free(path
);
690 void mimeview_select_part_num(MimeView
*mimeview
, gint i
)
692 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
695 GtkTreeSelection
*selection
;
701 gtk_tree_model_get_iter_first(model
, &iter
);
702 path
= gtk_tree_model_get_path(model
, &iter
);
705 if (!mimeview_tree_next(model
, path
)) {
706 gtk_tree_path_free(path
);
712 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mimeview
->ctree
));
713 gtk_tree_selection_select_path(selection
, path
);
714 gtk_tree_path_free(path
);
717 static void mimeview_set_multipart_tree(MimeView
*mimeview
,
721 GtkTreeStore
*model
= GTK_TREE_STORE(gtk_tree_view_get_model(
722 GTK_TREE_VIEW(mimeview
->ctree
)));
724 gchar
*content_type
, *length
, *name
;
726 cm_return_if_fail(mimeinfo
!= NULL
);
728 while (mimeinfo
!= NULL
) {
729 if (mimeinfo
->type
!= MIMETYPE_UNKNOWN
&& mimeinfo
->subtype
)
730 content_type
= g_strdup_printf("%s/%s",
731 procmime_get_media_type_str(mimeinfo
->type
),
734 content_type
= g_strdup("UNKNOWN");
736 length
= g_strdup(to_human_readable((goffset
) mimeinfo
->length
));
738 if (prefs_common
.attach_desc
)
739 name
= g_strdup(get_part_description(mimeinfo
));
741 name
= g_strdup(get_part_name(mimeinfo
));
743 gtk_tree_store_append(model
, &iter
, parent
);
744 gtk_tree_store_set(model
, &iter
,
745 COL_MIMETYPE
, content_type
,
748 COL_DATA
, mimeinfo
, -1);
749 g_free(content_type
);
753 if (mimeinfo
->node
->children
)
754 mimeview_set_multipart_tree(mimeview
,
755 (MimeInfo
*) mimeinfo
->node
->children
->data
, &iter
);
756 mimeinfo
= mimeinfo
->node
->next
!= NULL
?
757 (MimeInfo
*) mimeinfo
->node
->next
->data
: NULL
;
761 static const gchar
*get_real_part_name(MimeInfo
*partinfo
)
763 const gchar
*name
= NULL
;
765 name
= procmime_mimeinfo_get_parameter(partinfo
, "filename");
767 name
= procmime_mimeinfo_get_parameter(partinfo
, "name");
772 static const gchar
*get_part_name(MimeInfo
*partinfo
)
776 name
= get_real_part_name(partinfo
);
783 static const gchar
*get_part_description(MimeInfo
*partinfo
)
785 if (partinfo
->description
)
786 return partinfo
->description
;
788 return get_part_name(partinfo
);
791 static void mimeview_show_message_part(MimeView
*mimeview
, MimeInfo
*partinfo
)
796 if (!partinfo
) return;
798 fname
= mimeview
->file
;
801 if ((fp
= g_fopen(fname
, "rb")) == NULL
) {
802 FILE_OP_ERROR(fname
, "fopen");
806 if (fseek(fp
, partinfo
->offset
, SEEK_SET
) < 0) {
807 FILE_OP_ERROR(mimeview
->file
, "fseek");
812 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
813 textview_show_part(mimeview
->textview
, partinfo
, fp
);
818 static MimeViewer
*get_viewer_for_content_type(MimeView
*mimeview
, const gchar
*content_type
)
821 MimeViewerFactory
*factory
= NULL
;
822 MimeViewer
*viewer
= NULL
;
823 gchar
*real_contenttype
= NULL
, *tmp
;
825 real_contenttype
= g_utf8_strdown((gchar
*)content_type
, -1);
827 for (cur
= mimeviewer_factories
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
828 MimeViewerFactory
*curfactory
= cur
->data
;
831 while (curfactory
->content_types
[i
] != NULL
) {
832 tmp
= g_utf8_strdown(curfactory
->content_types
[i
], -1);
833 if (g_pattern_match_simple(tmp
, real_contenttype
)) {
834 debug_print("%s\n", curfactory
->content_types
[i
]);
835 factory
= curfactory
;
845 g_free(real_contenttype
);
849 for (cur
= mimeview
->viewers
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
850 MimeViewer
*curviewer
= cur
->data
;
852 if (curviewer
->factory
== factory
)
855 viewer
= factory
->create_viewer();
856 gtk_container_add(GTK_CONTAINER(mimeview
->mime_notebook
),
857 GTK_WIDGET(viewer
->get_widget(viewer
)));
859 mimeview
->viewers
= g_slist_append(mimeview
->viewers
, viewer
);
864 gboolean
mimeview_has_viewer_for_content_type(MimeView
*mimeview
, const gchar
*content_type
)
866 return (get_viewer_for_content_type(mimeview
, content_type
) != NULL
);
869 static MimeViewer
*get_viewer_for_mimeinfo(MimeView
*mimeview
, MimeInfo
*partinfo
)
871 gchar
*content_type
= NULL
;
872 MimeViewer
*viewer
= NULL
;
874 if ((partinfo
->type
== MIMETYPE_APPLICATION
) &&
875 (!g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))) {
876 const gchar
*filename
;
878 filename
= procmime_mimeinfo_get_parameter(partinfo
, "filename");
879 if (filename
== NULL
)
880 filename
= procmime_mimeinfo_get_parameter(partinfo
, "name");
881 if (filename
!= NULL
)
882 content_type
= procmime_get_mime_type(filename
);
884 content_type
= procmime_get_content_type_str(partinfo
->type
, partinfo
->subtype
);
887 if (content_type
!= NULL
) {
888 viewer
= get_viewer_for_content_type(mimeview
, content_type
);
889 g_free(content_type
);
895 gboolean
mimeview_show_part(MimeView
*mimeview
, MimeInfo
*partinfo
)
899 if (mimeview
->messageview
->partial_display_shown
) {
900 noticeview_hide(mimeview
->messageview
->noticeview
);
901 mimeview
->messageview
->partial_display_shown
= FALSE
;
904 viewer
= get_viewer_for_mimeinfo(mimeview
, partinfo
);
905 if (viewer
== NULL
) {
906 if (mimeview
->mimeviewer
!= NULL
)
907 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
908 mimeview
->mimeviewer
= NULL
;
912 if (mimeview
->mimeviewer
!= NULL
)
913 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
915 if (mimeview
->mimeviewer
!= viewer
)
916 mimeview
->mimeviewer
= viewer
;
918 mimeview_change_view_type(mimeview
, MIMEVIEW_VIEWER
);
919 viewer
->mimeview
= mimeview
;
920 viewer
->show_mimepart(viewer
, mimeview
->file
, partinfo
);
925 static void mimeview_change_view_type(MimeView
*mimeview
, MimeViewType type
)
927 TextView
*textview
= mimeview
->textview
;
928 GtkWidget
*focused
= NULL
;
930 if (mainwindow_get_mainwindow())
931 focused
= gtkut_get_focused_child(
932 GTK_CONTAINER(mainwindow_get_mainwindow()->window
));
934 if ((mimeview
->type
!= MIMEVIEW_VIEWER
) &&
935 (mimeview
->type
== type
)) return;
939 gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview
->mime_notebook
),
940 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview
->mime_notebook
),
941 GTK_WIDGET_PTR(textview
)));
943 case MIMEVIEW_VIEWER
:
944 gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview
->mime_notebook
),
945 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview
->mime_notebook
),
946 GTK_WIDGET(mimeview
->mimeviewer
->get_widget(mimeview
->mimeviewer
))));
952 gtk_widget_grab_focus(focused
);
953 mimeview
->type
= type
;
956 void mimeview_clear(MimeView
*mimeview
)
963 if (g_slist_find(mimeviews
, mimeview
) == NULL
)
966 noticeview_hide(mimeview
->siginfoview
);
968 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
969 gtk_tree_store_clear(GTK_TREE_STORE(model
));
971 textview_clear(mimeview
->textview
);
972 if (mimeview
->mimeviewer
!= NULL
)
973 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
975 mimeview_free_mimeinfo(mimeview
);
977 mimeview
->mimeinfo
= NULL
;
979 gtk_tree_path_free(mimeview
->opened
);
980 mimeview
->opened
= NULL
;
982 g_free(mimeview
->file
);
983 mimeview
->file
= NULL
;
985 icon_list_clear(mimeview
);
986 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
989 gchar
* get_message_check_signature_shortcut(MessageView
*messageview
) {
990 GtkUIManager
*ui_manager
;
992 if (messageview
->window
!= NULL
)
993 ui_manager
= messageview
->ui_manager
;
995 ui_manager
= messageview
->mainwin
->ui_manager
;
997 return cm_menu_item_get_shortcut(ui_manager
, "Menu/Message/CheckSignature");
1000 static void check_signature_cb(GtkWidget
*widget
, gpointer user_data
);
1001 static void display_full_info_cb(GtkWidget
*widget
, gpointer user_data
);
1003 static void update_signature_noticeview(MimeView
*mimeview
, MimeInfo
*mimeinfo
,
1004 gboolean special
, SignatureStatus code
)
1006 gchar
*text
= NULL
, *button_text
= NULL
;
1008 StockPixmap icon
= STOCK_PIXMAP_PRIVACY_SIGNED
;
1009 SignatureStatus mycode
= SIGNATURE_UNCHECKED
;
1011 cm_return_if_fail(mimeview
!= NULL
);
1012 cm_return_if_fail(mimeinfo
!= NULL
);
1017 mycode
= privacy_mimeinfo_get_sig_status(mimeinfo
);
1020 case SIGNATURE_UNCHECKED
:
1021 button_text
= _("Check signature");
1022 func
= check_signature_cb
;
1023 icon
= STOCK_PIXMAP_PRIVACY_SIGNED
;
1026 button_text
= _("View full information");
1027 func
= display_full_info_cb
;
1028 icon
= STOCK_PIXMAP_PRIVACY_PASSED
;
1030 case SIGNATURE_WARN
:
1031 button_text
= _("View full information");
1032 func
= display_full_info_cb
;
1033 icon
= STOCK_PIXMAP_PRIVACY_WARN
;
1035 case SIGNATURE_KEY_EXPIRED
:
1036 button_text
= _("View full information");
1037 func
= display_full_info_cb
;
1038 icon
= STOCK_PIXMAP_PRIVACY_EXPIRED
;
1040 case SIGNATURE_INVALID
:
1041 button_text
= _("View full information");
1042 func
= display_full_info_cb
;
1043 icon
= STOCK_PIXMAP_PRIVACY_FAILED
;
1045 case SIGNATURE_CHECK_FAILED
:
1046 case SIGNATURE_CHECK_TIMEOUT
:
1047 button_text
= _("Check again");
1048 func
= check_signature_cb
;
1049 icon
= STOCK_PIXMAP_PRIVACY_UNKNOWN
;
1054 if (mycode
== SIGNATURE_UNCHECKED
) {
1055 gchar
*tmp
= privacy_mimeinfo_sig_info_short(mimeinfo
);
1056 gchar
*shortcut
= get_message_check_signature_shortcut(mimeview
->messageview
);
1058 if (*shortcut
== '\0')
1059 text
= g_strdup_printf(_("%s Click the icon to check it."), tmp
);
1061 text
= g_strdup_printf(_("%s Click the icon or hit '%s' to check it."),
1065 } else if (mycode
!= SIGNATURE_CHECK_TIMEOUT
) {
1066 text
= privacy_mimeinfo_sig_info_short(mimeinfo
);
1067 } else if (mycode
== SIGNATURE_CHECK_TIMEOUT
) {
1068 gchar
*shortcut
= get_message_check_signature_shortcut(mimeview
->messageview
);
1070 if (*shortcut
== '\0')
1071 text
= g_strdup(_("Timeout checking the signature. Click the icon to try again."));
1073 text
= g_strdup_printf(_("Timeout checking the signature. Click the icon or hit '%s' to try again."), shortcut
);
1077 noticeview_set_text(mimeview
->siginfoview
, text
);
1078 gtk_label_set_selectable(GTK_LABEL(mimeview
->siginfoview
->text
), TRUE
);
1081 noticeview_set_button_text(mimeview
->siginfoview
, NULL
);
1082 noticeview_set_button_press_callback(
1083 mimeview
->siginfoview
,
1085 (gpointer
) mimeview
);
1086 noticeview_set_icon(mimeview
->siginfoview
, icon
);
1087 noticeview_set_tooltip(mimeview
->siginfoview
, button_text
);
1089 icon_list_clear(mimeview
);
1090 icon_list_create(mimeview
, mimeview
->mimeinfo
);
1095 /* reset all thread stuff, and do the cleanups we've been left to do */
1096 static void mimeview_check_data_reset(MimeView
*mimeview
)
1099 gboolean must_destroy
;
1101 if (!mimeview
->check_data
)
1104 must_free
= mimeview
->check_data
->free_after_use
;
1105 must_destroy
= mimeview
->check_data
->destroy_mimeview
;
1107 if (mimeview
->check_data
->cancel_th_init
) {
1108 debug_print("killing canceller thread\n");
1109 mimeview
->check_data
->cancel_th_init
= FALSE
;
1110 pthread_cancel(mimeview
->check_data
->cancel_th
);
1114 debug_print("freeing deferred mimeinfo\n");
1115 procmime_mimeinfo_free_all(&mimeview
->check_data
->siginfo
);
1118 g_free(mimeview
->check_data
);
1119 mimeview
->check_data
= NULL
;
1122 debug_print("freeing deferred mimeview\n");
1123 mimeview_free_mimeinfo(mimeview
);
1124 gtk_tree_path_free(mimeview
->opened
);
1125 g_free(mimeview
->file
);
1127 mimeviews
= g_slist_remove(mimeviews
, mimeview
);
1131 /* GUI update once the checker thread is done or killed */
1132 static gboolean
mimeview_check_sig_thread_cb(void *data
)
1134 MimeView
*mimeview
= (MimeView
*) data
;
1135 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1137 debug_print("mimeview_check_sig_thread_cb\n");
1139 if (mimeinfo
== NULL
) {
1140 /* message changed !? */
1141 g_warning("no more siginfo!");
1145 if (!mimeview
->check_data
) {
1146 g_warning("nothing to check");
1150 if (mimeview
->check_data
->siginfo
!= mimeinfo
) {
1151 /* message changed !? */
1152 g_warning("different siginfo!");
1156 if (mimeview
->check_data
->destroy_mimeview
||
1157 mimeview
->check_data
->free_after_use
) {
1158 debug_print("not bothering, we're changing message\n");
1163 if (mimeview
->check_data
->timeout
)
1164 update_signature_noticeview(mimeview
, mimeview
->siginfo
,
1165 TRUE
, SIGNATURE_CHECK_TIMEOUT
);
1167 update_signature_noticeview(mimeview
, mimeview
->siginfo
,
1171 mimeview_check_data_reset(mimeview
);
1175 /* sig checker thread */
1176 static void *mimeview_check_sig_worker_thread(void *data
)
1178 MimeView
*mimeview
= (MimeView
*)data
;
1179 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1181 debug_print("checking...\n");
1183 if (!mimeview
->check_data
)
1186 if (mimeinfo
&& mimeinfo
== mimeview
->check_data
->siginfo
) {
1187 privacy_mimeinfo_check_signature(mimeinfo
);
1188 if (mimeview
->check_data
&& mimeview
->check_data
->cancel_th_init
) {
1189 mimeview
->check_data
->cancel_th_init
= FALSE
;
1190 pthread_cancel(mimeview
->check_data
->cancel_th
);
1193 /* that's strange! we changed message without
1194 * getting killed. */
1195 g_warning("different siginfo!");
1196 mimeview_check_data_reset(mimeview
);
1200 /* use g_timeout so that GUI updates is done from the
1202 g_timeout_add(0,mimeview_check_sig_thread_cb
,mimeview
);
1207 /* killer thread - acts when the checker didn't work fast
1209 static void *mimeview_check_sig_cancel_thread(void *data
)
1211 MimeView
*mimeview
= (MimeView
*)data
;
1213 if (!mimeview
->check_data
)
1214 return NULL
; /* nothing to kill ! */
1216 /* wait for a few seconds... */
1217 debug_print("waiting a while\n");
1219 g_usleep(5 * 1000 * 1000);
1221 if (!mimeview
->check_data
)
1222 return NULL
; /* nothing to kill, it's done in time :) */
1224 /* too late, go away checker thread */
1225 debug_print("killing checker thread\n");
1226 if (mimeview
->check_data
->th_init
) {
1227 mimeview
->check_data
->th_init
= FALSE
;
1228 pthread_cancel(mimeview
->check_data
->th
);
1231 /* tell upstream it was a timeout */
1232 mimeview
->check_data
->timeout
= TRUE
;
1233 /* use g_timeout so that GUI updates is done from the
1235 g_timeout_add(0,mimeview_check_sig_thread_cb
,mimeview
);
1240 /* get rid of the checker thread right now - used when changing the
1241 * displayed message for example. */
1242 static void mimeview_check_sig_cancel_now(MimeView
*mimeview
)
1244 if (!mimeview
->check_data
)
1246 debug_print("killing checker thread NOW\n");
1247 if (mimeview
->check_data
->th_init
) {
1248 mimeview
->check_data
->th_init
= FALSE
;
1249 pthread_cancel(mimeview
->check_data
->th
);
1252 /* tell upstream it was a timeout */
1253 mimeview
->check_data
->timeout
= TRUE
;
1254 mimeview_check_sig_thread_cb(mimeview
);
1258 /* creates a thread to check the signature, and a second one
1259 * to kill the first one after a timeout */
1260 static void mimeview_check_sig_in_thread(MimeView
*mimeview
)
1263 pthread_attr_t detach
, detach2
;
1265 if (mimeview
->check_data
) {
1266 g_warning("already checking it");
1270 mimeview
->check_data
= g_new0(SigCheckData
, 1);
1271 mimeview
->check_data
->siginfo
= mimeview
->siginfo
;
1272 debug_print("creating thread\n");
1274 /* init thread attributes and create the checker thread */
1275 if (pthread_attr_init(&detach
) != 0 ||
1276 pthread_attr_setdetachstate(&detach
, PTHREAD_CREATE_DETACHED
) != 0 ||
1277 pthread_attr_init(&detach2
) != 0 ||
1278 pthread_attr_setdetachstate(&detach2
, PTHREAD_CREATE_DETACHED
) != 0 ||
1279 pthread_create(&th
, &detach
,
1280 mimeview_check_sig_worker_thread
,
1282 /* arh. We'll do it synchronously. */
1283 g_warning("can't create thread");
1284 g_free(mimeview
->check_data
);
1285 mimeview
->check_data
= NULL
;
1288 mimeview
->check_data
->th
= th
;
1289 mimeview
->check_data
->th_init
= TRUE
;
1292 /* create the killer thread */
1293 pthread_create(&th2
, &detach2
,
1294 mimeview_check_sig_cancel_thread
,
1297 mimeview
->check_data
->cancel_th
= th2
;
1298 mimeview
->check_data
->cancel_th_init
= TRUE
;
1302 static void check_signature_cb(GtkWidget
*widget
, gpointer user_data
)
1304 MimeView
*mimeview
= (MimeView
*) user_data
;
1305 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1307 if (mimeinfo
== NULL
)
1310 if (mimeview
->check_data
)
1313 noticeview_set_text(mimeview
->siginfoview
, _("Checking signature..."));
1316 /* let's do it non-blocking */
1317 mimeview_check_sig_in_thread(mimeview
);
1318 if (!mimeview
->check_data
) /* let's check syncronously */
1321 debug_print("checking without thread\n");
1322 privacy_mimeinfo_check_signature(mimeinfo
);
1323 update_signature_noticeview(mimeview
, mimeview
->siginfo
, FALSE
, 0);
1327 void mimeview_check_signature(MimeView
*mimeview
)
1329 check_signature_cb(NULL
, mimeview
);
1332 static void redisplay_email(GtkWidget
*widget
, gpointer user_data
)
1334 MimeView
*mimeview
= (MimeView
*) user_data
;
1335 gtk_tree_path_free(mimeview
->opened
);
1336 mimeview
->opened
= NULL
;
1337 mimeview_selected(gtk_tree_view_get_selection(
1338 GTK_TREE_VIEW(mimeview
->ctree
)), mimeview
);
1341 static void display_full_info_cb(GtkWidget
*widget
, gpointer user_data
)
1343 MimeView
*mimeview
= (MimeView
*) user_data
;
1346 siginfo
= privacy_mimeinfo_sig_info_full(mimeview
->siginfo
);
1347 textview_set_text(mimeview
->textview
, siginfo
);
1349 noticeview_set_button_text(mimeview
->siginfoview
, NULL
);
1350 noticeview_set_button_press_callback(
1351 mimeview
->siginfoview
,
1352 G_CALLBACK(redisplay_email
),
1353 (gpointer
) mimeview
);
1354 noticeview_set_tooltip(mimeview
->siginfoview
, _("Go back to email"));
1357 static void update_signature_info(MimeView
*mimeview
, MimeInfo
*selected
)
1360 MimeInfo
*first_text
;
1362 cm_return_if_fail(mimeview
!= NULL
);
1363 cm_return_if_fail(selected
!= NULL
);
1365 if (selected
->type
== MIMETYPE_MESSAGE
1366 && !g_ascii_strcasecmp(selected
->subtype
, "rfc822")) {
1367 /* if the first text part is signed, check that */
1368 first_text
= selected
;
1369 while (first_text
&& first_text
->type
!= MIMETYPE_TEXT
) {
1370 first_text
= procmime_mimeinfo_next(first_text
);
1373 update_signature_info(mimeview
, first_text
);
1379 while (siginfo
!= NULL
) {
1380 if (privacy_mimeinfo_is_signed(siginfo
))
1382 siginfo
= procmime_mimeinfo_parent(siginfo
);
1384 mimeview
->siginfo
= siginfo
;
1386 /* This shortcut boolean is there to correctly set the menu's
1387 * CheckSignature item sensitivity without killing performance
1388 * each time the menu sensitiveness is updated (a lot).
1390 mimeview
->signed_part
= (siginfo
!= NULL
);
1392 if (siginfo
== NULL
) {
1393 noticeview_hide(mimeview
->siginfoview
);
1397 update_signature_noticeview(mimeview
, siginfo
, FALSE
, 0);
1398 noticeview_show(mimeview
->siginfoview
);
1401 static void mimeview_selected(GtkTreeSelection
*selection
, MimeView
*mimeview
)
1403 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1404 GtkTreeModel
*model
;
1409 selection
= gtk_tree_view_get_selection(ctree
);
1410 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1413 path
= gtk_tree_model_get_path(model
, &iter
);
1415 if (mimeview
->opened
&& !gtk_tree_path_compare(mimeview
->opened
, path
)) {
1416 gtk_tree_path_free(path
);
1420 gtk_tree_path_free(mimeview
->opened
);
1421 mimeview
->opened
= path
;
1422 mimeview
->spec_part
= NULL
;
1423 gtk_tree_view_scroll_to_cell(ctree
, path
, NULL
, TRUE
, 0.5, 0);
1425 partinfo
= mimeview_get_node_part(mimeview
, path
);
1426 if (!partinfo
) return;
1428 /* ungrab the mouse event */
1429 if (gtk_widget_has_grab(GTK_WIDGET(ctree
))) {
1430 gtk_grab_remove(GTK_WIDGET(ctree
));
1431 if (gdk_pointer_is_grabbed())
1432 gdk_pointer_ungrab(GDK_CURRENT_TIME
);
1435 mimeview
->textview
->default_text
= FALSE
;
1437 update_signature_info(mimeview
, partinfo
);
1439 if (!mimeview_show_part(mimeview
, partinfo
)) {
1440 switch (partinfo
->type
) {
1442 case MIMETYPE_MESSAGE
:
1443 case MIMETYPE_MULTIPART
:
1444 mimeview_show_message_part(mimeview
, partinfo
);
1448 mimeview
->textview
->default_text
= TRUE
;
1449 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
1450 textview_clear(mimeview
->textview
);
1451 textview_show_mime_part(mimeview
->textview
, partinfo
);
1456 if (mimeview
->siginfo
&& privacy_auto_check_signatures(mimeview
->siginfo
)
1457 && privacy_mimeinfo_get_sig_status(mimeview
->siginfo
) == SIGNATURE_UNCHECKED
) {
1458 mimeview_check_signature(mimeview
);
1462 static gint
mimeview_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
,
1465 GtkTreeSelection
*selection
;
1468 if (!event
) return FALSE
;
1470 if (event
->button
== 2 || event
->button
== 3) {
1471 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(widget
));
1472 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
1475 gtk_tree_selection_select_iter(selection
, &iter
);
1477 part_button_pressed(mimeview
, event
, mimeview_get_selected_part(mimeview
));
1482 static gboolean
mimeview_scrolled(GtkWidget
*widget
, GdkEventScroll
*event
,
1485 GtkVScrollbutton
*scrollbutton
= (GtkVScrollbutton
*)mimeview
->scrollbutton
;
1486 if (event
->direction
== GDK_SCROLL_UP
) {
1487 scrollbutton
->scroll_type
= GTK_SCROLL_STEP_BACKWARD
;
1489 scrollbutton
->scroll_type
= GTK_SCROLL_STEP_FORWARD
;
1491 gtk_vscrollbutton_scroll(scrollbutton
);
1495 /* from gdkevents.c */
1496 #define DOUBLE_CLICK_TIME 250
1498 static gboolean
part_button_pressed(MimeView
*mimeview
, GdkEventButton
*event
,
1501 static MimeInfo
*lastinfo
;
1502 static guint32 lasttime
;
1504 if (event
->button
== 2 ||
1505 (event
->button
== 1 && (event
->time
- lasttime
) < DOUBLE_CLICK_TIME
&& lastinfo
== partinfo
)) {
1506 /* call external program for image, audio or html */
1507 mimeview_launch(mimeview
, partinfo
);
1509 } else if (event
->button
== 3) {
1510 if (partinfo
&& (partinfo
->type
== MIMETYPE_MESSAGE
||
1511 partinfo
->type
== MIMETYPE_IMAGE
||
1512 partinfo
->type
== MIMETYPE_MULTIPART
))
1513 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/DisplayAsText", FALSE
);
1515 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/DisplayAsText", TRUE
);
1518 partinfo
->type
== MIMETYPE_APPLICATION
&&
1519 !g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))
1520 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/Open", FALSE
);
1523 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/Open", TRUE
);
1525 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
1526 "pop_partinfo", partinfo
);
1528 gtk_menu_popup(GTK_MENU(mimeview
->popupmenu
),
1529 NULL
, NULL
, NULL
, NULL
,
1530 event
->button
, event
->time
);
1534 lastinfo
= partinfo
;
1535 lasttime
= event
->time
;
1540 gboolean
mimeview_pass_key_press_event(MimeView
*mimeview
, GdkEventKey
*event
)
1542 return mimeview_key_pressed(mimeview
->ctree
, event
, mimeview
);
1545 void mimeview_select_next_part(MimeView
*mimeview
)
1547 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1548 GtkTreeModel
*model
= gtk_tree_view_get_model(ctree
);
1549 GtkTreeSelection
*selection
;
1552 MimeInfo
*partinfo
= NULL
;
1555 if (!mimeview
->opened
) return;
1557 gtk_tree_model_get_iter(model
, &iter
, mimeview
->opened
);
1558 path
= gtk_tree_model_get_path(model
, &iter
);
1560 has_next
= mimeview_tree_next(model
, path
);
1562 has_next
= gtk_tree_model_get_iter_first(model
, &iter
);
1563 gtk_tree_path_free(path
);
1564 path
= gtk_tree_model_get_path(model
, &iter
);
1568 partinfo
= mimeview_get_node_part(mimeview
, path
);
1569 if (partinfo
->type
== MIMETYPE_MULTIPART
||
1570 (!prefs_common
.show_inline_attachments
&& partinfo
->id
))
1572 selection
= gtk_tree_view_get_selection(ctree
);
1573 gtk_tree_selection_select_path(selection
, path
);
1574 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
1577 gtk_tree_path_free(path
);
1580 void mimeview_select_prev_part(MimeView
*mimeview
)
1582 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1583 GtkTreeModel
*model
= gtk_tree_view_get_model(ctree
);
1584 GtkTreeSelection
*selection
;
1587 MimeInfo
*partinfo
= NULL
;
1590 if (!mimeview
->opened
) return;
1592 gtk_tree_model_get_iter(model
, &iter
, mimeview
->opened
);
1593 path
= gtk_tree_model_get_path(model
, &iter
);
1595 has_prev
= mimeview_tree_prev(mimeview
, path
);
1597 while (mimeview_tree_next(model
, path
)) {}
1602 partinfo
= mimeview_get_node_part(mimeview
, path
);
1603 if (partinfo
->type
== MIMETYPE_MULTIPART
||
1604 (!prefs_common
.show_inline_attachments
&& partinfo
->id
))
1606 selection
= gtk_tree_view_get_selection(ctree
);
1607 gtk_tree_selection_select_path(selection
, path
);
1608 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
1611 gtk_tree_path_free(path
);
1614 #define BREAK_ON_MODIFIER_KEY() \
1615 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
1617 static gint
mimeview_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1620 SummaryView
*summaryview
;
1622 if (!event
) return FALSE
;
1623 if (!mimeview
->opened
) return FALSE
;
1625 summaryview
= mimeview
->messageview
->mainwin
->summaryview
;
1627 if (summaryview
&& quicksearch_has_focus(summaryview
->quicksearch
))
1630 switch (event
->keyval
) {
1633 textview_scroll_max(mimeview
->textview
,
1634 (event
->keyval
== GDK_KEY_Home
));
1636 case GDK_KEY_Page_Down
:
1638 if (mimeview_scroll_page(mimeview
,
1639 (event
->state
& GDK_SHIFT_MASK
) != 0))
1642 if (!(event
->state
& GDK_SHIFT_MASK
))
1643 mimeview_select_next_part(mimeview
);
1645 case GDK_KEY_Page_Up
:
1646 case GDK_KEY_BackSpace
:
1647 mimeview_scroll_page(mimeview
, TRUE
);
1649 case GDK_KEY_Return
:
1650 case GDK_KEY_KP_Enter
:
1651 mimeview_scroll_one_line(mimeview
,
1652 (event
->state
& GDK_MOD1_MASK
) != 0);
1656 mimeview_scroll_one_line(mimeview
, (event
->keyval
== GDK_KEY_Up
));
1662 if (mimeview
->messageview
->new_window
) return FALSE
;
1664 return summary_pass_key_press_event(summaryview
, event
);
1667 static void mimeview_drag_data_get(GtkWidget
*widget
,
1668 GdkDragContext
*drag_context
,
1669 GtkSelectionData
*selection_data
,
1674 gchar
*filename
= NULL
, *uriname
, *tmp
;
1679 if (!mimeview
->opened
) return;
1680 if (!mimeview
->file
) return;
1682 partinfo
= mimeview_get_selected_part(mimeview
);
1683 if (!partinfo
) return;
1685 if (strlen(get_part_name(partinfo
)) > 0) {
1686 filename
= g_path_get_basename(get_part_name(partinfo
));
1687 if (*filename
== '\0') return;
1688 } else if (partinfo
->type
== MIMETYPE_MESSAGE
1689 && !g_ascii_strcasecmp(partinfo
->subtype
, "rfc822")) {
1691 GPtrArray
*headers
= NULL
;
1694 fp
= g_fopen(partinfo
->data
.filename
, "rb");
1695 if (fp
!= NULL
&& fseek(fp
, partinfo
->offset
, SEEK_SET
) == 0) {
1696 headers
= procheader_get_header_array_asis(fp
);
1699 for (i
= 0; i
< headers
->len
; i
++) {
1700 Header
*header
= g_ptr_array_index(headers
, i
);
1701 if (procheader_headername_equal(header
->name
, "Subject")) {
1702 unfold_line(header
->body
);
1703 name
= g_strconcat(header
->body
, ".txt", NULL
);
1704 subst_for_filename(name
);
1707 procheader_header_array_destroy(headers
);
1713 filename
= g_path_get_basename(name
);
1716 if (filename
== NULL
)
1717 filename
= g_path_get_basename("Unnamed part");
1719 if (!g_utf8_validate(filename
, -1, NULL
))
1720 tmp
= conv_codeset_strdup(filename
,
1721 conv_get_locale_charset_str(),
1724 tmp
= g_strdup(filename
);
1727 g_warning("filename not in UTF-8");
1728 tmp
= g_strdup("Unnamed part");
1730 filename
= g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S
,
1734 if (is_file_exist(filename
)) {
1736 gchar
*prefix
= NULL
;
1737 gchar
*new_name
= NULL
;
1738 if (strrchr(tmp
, '.')) {
1739 prefix
= g_strdup(tmp
);
1740 ext
= g_strdup(strrchr(tmp
, '.'));
1741 *(strrchr(prefix
, '.')) = '\0';
1743 prefix
= g_strdup(tmp
);
1747 new_name
= g_strdup_printf("%s.%d%s", prefix
, count
, ext
);
1751 filename
= g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S
,
1754 goto check_new_file
;
1759 if ((err
= procmime_get_part(filename
, partinfo
)) < 0)
1761 (_("Couldn't save the part of multipart message: %s"),
1764 tmp
= g_filename_to_uri(filename
, NULL
, NULL
);
1765 uriname
= g_strconcat(tmp
, "\r\n", NULL
);
1768 gtk_selection_data_set(selection_data
,
1769 gtk_selection_data_get_target(selection_data
), 8,
1770 (guchar
*)uriname
, strlen(uriname
));
1777 * Returns a filename (with path) for an attachment
1778 * \param partinfo The attachment to save
1779 * \param basedir The target directory
1780 * \param number Used for dummy filename if attachment is unnamed
1782 static gchar
*mimeview_get_filename_for_part(MimeInfo
*partinfo
,
1783 const gchar
*basedir
,
1789 filename
= g_strdup(get_part_name(partinfo
));
1790 if (!filename
|| !*filename
) {
1792 filename
= g_strdup_printf("noname.%d", number
);
1795 if (!g_utf8_validate(filename
, -1, NULL
)) {
1796 gchar
*tmp
= conv_filename_to_utf8(filename
);
1801 subst_for_filename(filename
);
1803 fullname
= g_strconcat
1804 (basedir
, G_DIR_SEPARATOR_S
, (g_path_is_absolute(filename
))
1805 ? &filename
[1] : filename
, NULL
);
1808 filename
= conv_filename_from_utf8(fullname
);
1814 * Write a single attachment to file
1815 * \param filename Filename with path
1816 * \param partinfo Attachment to save
1818 static gboolean
mimeview_write_part(const gchar
*filename
,
1820 gboolean handle_error
)
1825 dir
= g_path_get_dirname(filename
);
1826 if (!is_dir_exist(dir
))
1830 if (is_file_exist(filename
)) {
1835 if (!g_utf8_validate(filename
, -1, NULL
))
1836 tmp
= conv_filename_to_utf8(filename
);
1838 tmp
= g_strdup(filename
);
1840 res
= g_strdup_printf(_("Overwrite existing file '%s'?"),
1843 aval
= alertpanel(_("Overwrite"), res
, GTK_STOCK_CANCEL
,
1844 GTK_STOCK_OK
, NULL
);
1846 if (G_ALERTALTERNATE
!= aval
) return FALSE
;
1849 if ((err
= procmime_get_part(filename
, partinfo
)) < 0) {
1850 debug_print("error saving MIME part: %d\n", err
);
1853 (_("Couldn't save the part of multipart message: %s"),
1861 static AlertValue
mimeview_save_all_error_ask(gint n
)
1863 gchar
*message
= g_strdup_printf(
1864 _("An error has occurred while saving attachment #%d. "
1865 "Do you want to cancel operation or skip error and "
1867 AlertValue av
= alertpanel_full(_("Error saving all attachments"),
1868 message
, GTK_STOCK_CANCEL
, _("Skip"), _("Skip all"),
1869 FALSE
, NULL
, ALERT_WARNING
, G_ALERTDEFAULT
);
1874 static void mimeview_save_all_info(gint errors
, gint total
)
1877 gchar
*msg
= g_strdup_printf(
1878 ngettext("%d attachment saved succesfully.",
1879 "%d attachments saved succesfully.",
1882 alertpanel_notice(msg
);
1885 gchar
*msg1
= g_strdup_printf(
1886 ngettext("%d attachment saved successfully",
1887 "%d attachments saved successfully",
1890 gchar
*msg2
= g_strdup_printf(
1891 ngettext("%s, %d attachment failed.",
1892 "%s, %d attachments failed.",
1895 alertpanel_warning(msg2
);
1902 * Menu callback: Save all attached files
1903 * \param mimeview Current display
1905 static void mimeview_save_all(MimeView
*mimeview
)
1909 gchar
*startdir
= NULL
;
1910 gint number
= 1, errors
= 0;
1911 gboolean skip_errors
= FALSE
;
1913 if (!mimeview
->opened
) return;
1914 if (!mimeview
->file
) return;
1915 if (!mimeview
->mimeinfo
) return;
1917 partinfo
= mimeview
->mimeinfo
;
1918 if (prefs_common
.attach_save_dir
&& *prefs_common
.attach_save_dir
)
1919 startdir
= g_strconcat(prefs_common
.attach_save_dir
, G_DIR_SEPARATOR_S
, NULL
);
1921 startdir
= g_strdup(get_home_dir());
1923 manage_window_focus_in(gtk_widget_get_ancestor(mimeview
->hbox
, GTK_TYPE_WINDOW
), NULL
, NULL
);
1924 dirname
= filesel_select_file_save_folder(_("Select destination folder"), startdir
);
1930 if (!is_dir_exist (dirname
)) {
1931 alertpanel_error(_("'%s' is not a directory."), dirname
);
1937 if (dirname
[strlen(dirname
)-1] == G_DIR_SEPARATOR
)
1938 dirname
[strlen(dirname
)-1] = '\0';
1940 /* Skip the first part, that is sometimes DISPOSITIONTYPE_UNKNOWN */
1941 if (partinfo
&& partinfo
->type
== MIMETYPE_MESSAGE
)
1942 partinfo
= procmime_mimeinfo_next(partinfo
);
1943 if (partinfo
&& partinfo
->type
== MIMETYPE_MULTIPART
) {
1944 partinfo
= procmime_mimeinfo_next(partinfo
);
1945 if (partinfo
&& partinfo
->type
== MIMETYPE_TEXT
)
1946 partinfo
= procmime_mimeinfo_next(partinfo
);
1949 while (partinfo
!= NULL
) {
1950 if (partinfo
->type
!= MIMETYPE_MESSAGE
&&
1951 partinfo
->type
!= MIMETYPE_MULTIPART
&&
1952 (partinfo
->disposition
!= DISPOSITIONTYPE_INLINE
1953 || get_real_part_name(partinfo
) != NULL
)) {
1954 gchar
*filename
= mimeview_get_filename_for_part(
1955 partinfo
, dirname
, number
++);
1957 gboolean ok
= mimeview_write_part(filename
, partinfo
, FALSE
);
1962 AlertValue av
= mimeview_save_all_error_ask(number
- 1);
1963 skip_errors
= (av
== G_ALERTOTHER
);
1964 if (av
== G_ALERTDEFAULT
) /* cancel */
1969 partinfo
= procmime_mimeinfo_next(partinfo
);
1972 g_free(prefs_common
.attach_save_dir
);
1974 prefs_common
.attach_save_dir
= g_filename_to_utf8(dirname
,
1975 -1, NULL
, NULL
, NULL
);
1978 mimeview_save_all_info(errors
, number
- 1);
1981 static MimeInfo
*mimeview_get_part_to_use(MimeView
*mimeview
)
1983 MimeInfo
*partinfo
= NULL
;
1984 if (mimeview
->spec_part
) {
1985 partinfo
= mimeview
->spec_part
;
1986 mimeview
->spec_part
= NULL
;
1988 partinfo
= (MimeInfo
*) g_object_get_data
1989 (G_OBJECT(mimeview
->popupmenu
),
1991 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
1992 "pop_partinfo", NULL
);
1994 partinfo
= mimeview_get_selected_part(mimeview
);
2001 * Menu callback: Save the selected attachment
2002 * \param mimeview Current display
2004 void mimeview_save_as(MimeView
*mimeview
)
2007 gchar
*filepath
= NULL
;
2008 gchar
*filedir
= NULL
;
2010 gchar
*partname
= NULL
;
2012 if (!mimeview
->opened
) return;
2013 if (!mimeview
->file
) return;
2015 partinfo
= mimeview_get_part_to_use(mimeview
);
2017 cm_return_if_fail(partinfo
!= NULL
);
2019 if (get_part_name(partinfo
) == NULL
) {
2022 partname
= g_strdup(get_part_name(partinfo
));
2024 if (!g_utf8_validate(partname
, -1, NULL
)) {
2025 gchar
*tmp
= conv_filename_to_utf8(partname
);
2027 tmp
= conv_codeset_strdup(partname
,
2028 conv_get_locale_charset_str(),
2037 subst_for_filename(partname
);
2039 if (prefs_common
.attach_save_dir
&& *prefs_common
.attach_save_dir
)
2040 filepath
= g_strconcat(prefs_common
.attach_save_dir
,
2041 G_DIR_SEPARATOR_S
, partname
, NULL
);
2043 filepath
= g_strdup(partname
);
2047 manage_window_focus_in(gtk_widget_get_ancestor(mimeview
->hbox
, GTK_TYPE_WINDOW
), NULL
, NULL
);
2048 filename
= filesel_select_file_save(_("Save as"), filepath
);
2054 mimeview_write_part(filename
, partinfo
, TRUE
);
2056 filedir
= g_path_get_dirname(filename
);
2057 if (filedir
&& strcmp(filedir
, ".")) {
2058 g_free(prefs_common
.attach_save_dir
);
2059 prefs_common
.attach_save_dir
= g_filename_to_utf8(filedir
, -1, NULL
, NULL
, NULL
);
2066 void mimeview_display_as_text(MimeView
*mimeview
)
2070 if (!mimeview
->opened
) return;
2072 partinfo
= mimeview_get_part_to_use(mimeview
);
2073 mimeview_select_mimepart_icon(mimeview
, partinfo
);
2074 cm_return_if_fail(partinfo
!= NULL
);
2075 mimeview_show_message_part(mimeview
, partinfo
);
2078 void mimeview_launch(MimeView
*mimeview
, MimeInfo
*partinfo
)
2083 if (!mimeview
->opened
) return;
2084 if (!mimeview
->file
) return;
2087 partinfo
= mimeview_get_part_to_use(mimeview
);
2089 cm_return_if_fail(partinfo
!= NULL
);
2091 filename
= procmime_get_tmp_file_name(partinfo
);
2093 if ((err
= procmime_get_part(filename
, partinfo
)) < 0)
2095 (_("Couldn't save the part of multipart message: %s"),
2098 mimeview_view_file(filename
, partinfo
, NULL
, mimeview
);
2104 void mimeview_open_with(MimeView
*mimeview
)
2108 if (!mimeview
) return;
2109 if (!mimeview
->opened
) return;
2110 if (!mimeview
->file
) return;
2112 partinfo
= mimeview_get_part_to_use(mimeview
);
2114 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2117 static void mimeview_open_part_with(MimeView
*mimeview
, MimeInfo
*partinfo
, gboolean automatic
)
2121 gchar
*mime_command
= NULL
;
2122 gchar
*content_type
= NULL
;
2125 cm_return_if_fail(partinfo
!= NULL
);
2127 filename
= procmime_get_tmp_file_name(partinfo
);
2129 if ((err
= procmime_get_part(filename
, partinfo
)) < 0) {
2131 (_("Couldn't save the part of multipart message: %s"),
2137 if (!prefs_common
.mime_open_cmd_history
)
2138 prefs_common
.mime_open_cmd_history
=
2139 add_history(NULL
, prefs_common
.mime_open_cmd
);
2141 if ((partinfo
->type
== MIMETYPE_APPLICATION
) &&
2142 (!g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))) {
2143 /* guess content-type from filename */
2144 content_type
= procmime_get_mime_type(filename
);
2146 if (content_type
== NULL
) {
2147 content_type
= procmime_get_content_type_str(partinfo
->type
,
2151 if ((partinfo
->type
== MIMETYPE_TEXT
&& !strcmp(partinfo
->subtype
, "html"))
2152 && prefs_common_get_uri_cmd() && prefs_common
.uri_cmd
[0]) {
2153 mime_command
= g_strdup(prefs_common_get_uri_cmd());
2154 g_free(content_type
);
2155 content_type
= NULL
;
2156 } else if (partinfo
->type
!= MIMETYPE_TEXT
|| !prefs_common_get_ext_editor_cmd()
2157 || !prefs_common_get_ext_editor_cmd()[0]) {
2158 mime_command
= mailcap_get_command_for_type(content_type
, filename
);
2160 mime_command
= g_strdup(prefs_common_get_ext_editor_cmd());
2161 g_free(content_type
);
2162 content_type
= NULL
;
2164 if (mime_command
== NULL
) {
2165 /* try with extension this time */
2166 g_free(content_type
);
2167 content_type
= procmime_get_mime_type(filename
);
2168 mime_command
= mailcap_get_command_for_type(content_type
, filename
);
2171 if (mime_command
== NULL
)
2175 gboolean remember
= FALSE
;
2176 if (content_type
!= NULL
)
2177 cmd
= input_dialog_combo_remember
2179 _("Enter the command-line to open file:\n"
2180 "('%s' will be replaced with file name)"),
2181 mime_command
? mime_command
: prefs_common
.mime_open_cmd
,
2182 prefs_common
.mime_open_cmd_history
, &remember
);
2184 cmd
= input_dialog_combo
2186 _("Enter the command-line to open file:\n"
2187 "('%s' will be replaced with file name)"),
2188 mime_command
? mime_command
: prefs_common
.mime_open_cmd
,
2189 prefs_common
.mime_open_cmd_history
);
2190 if (cmd
&& remember
) {
2191 mailcap_update_default(content_type
, cmd
);
2193 g_free(mime_command
);
2198 mimeview_view_file(filename
, partinfo
, cmd
, mimeview
);
2199 g_free(prefs_common
.mime_open_cmd
);
2200 prefs_common
.mime_open_cmd
= cmd
;
2201 prefs_common
.mime_open_cmd_history
=
2202 add_history(prefs_common
.mime_open_cmd_history
, cmd
);
2205 g_free(content_type
);
2210 static void mimeview_send_to(MimeView
*mimeview
, MimeInfo
*partinfo
)
2212 GList
*attach_file
= NULL
;
2213 AttachInfo
*ainfo
= NULL
;
2217 if (!mimeview
->opened
) return;
2218 if (!mimeview
->file
) return;
2220 cm_return_if_fail(partinfo
!= NULL
);
2222 filename
= procmime_get_tmp_file_name(partinfo
);
2224 if (!(err
= procmime_get_part(filename
, partinfo
))) {
2225 ainfo
= g_new0(AttachInfo
, 1);
2226 ainfo
->file
= filename
;
2227 ainfo
->name
= g_strdup(get_part_name(partinfo
));
2228 ainfo
->content_type
= procmime_get_content_type_str(
2229 partinfo
->type
, partinfo
->subtype
);
2230 ainfo
->charset
= g_strdup(procmime_mimeinfo_get_parameter(
2231 partinfo
, "charset"));
2232 attach_file
= g_list_append(attach_file
, ainfo
);
2234 compose_new(NULL
, NULL
, attach_file
);
2236 g_free(ainfo
->name
);
2237 g_free(ainfo
->content_type
);
2238 g_free(ainfo
->charset
);
2240 g_list_free(attach_file
);
2243 (_("Couldn't save the part of multipart message: %s"),
2248 static void mimeview_view_file(const gchar
*filename
, MimeInfo
*partinfo
,
2249 const gchar
*cmd
, MimeView
*mimeview
)
2253 gchar buf
[BUFFSIZE
];
2256 mimeview_open_part_with(mimeview
, partinfo
, TRUE
);
2258 if ((p
= strchr(cmd
, '%')) && *(p
+ 1) == 's' &&
2259 !strchr(p
+ 2, '%')) {
2260 g_snprintf(buf
, sizeof(buf
), cmd
, filename
);
2261 if (!prefs_common
.save_parts_readwrite
)
2262 g_chmod(filename
, S_IRUSR
);
2264 g_chmod(filename
, S_IRUSR
|S_IWUSR
);
2266 g_warning("MIME viewer command-line is invalid: '%s'", cmd
);
2267 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2269 if (execute_command_line(buf
, TRUE
, NULL
) != 0) {
2270 if (!prefs_common
.save_parts_readwrite
)
2271 g_chmod(filename
, S_IRUSR
|S_IWUSR
);
2272 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2276 SHFILEINFO file_info
;
2277 GError
*error
= NULL
;
2278 gunichar2
*fn16
= g_utf8_to_utf16(filename
, -1, NULL
, NULL
, &error
);
2280 if (error
!= NULL
) {
2281 alertpanel_error(_("Could not convert attachment name to UTF-16:\n\n%s"),
2283 debug_print("filename '%s' conversion to UTF-16 failed\n", filename
);
2284 g_error_free(error
);
2288 if ((SHGetFileInfo((LPCWSTR
)fn16
, 0, &file_info
, sizeof(SHFILEINFO
), SHGFI_EXETYPE
)) != 0) {
2289 AlertValue val
= alertpanel_full(_("Execute untrusted binary?"),
2290 _("This attachment is an executable file. Executing "
2291 "untrusted binaries is dangerous and could probably "
2292 "lead to compromission of your computer.\n\n"
2293 "Do you want to run this file?"), GTK_STOCK_CANCEL
,
2295 NULL
, FALSE
, NULL
, ALERT_WARNING
, G_ALERTDEFAULT
);
2296 if (val
== G_ALERTALTERNATE
) {
2297 debug_print("executing binary\n");
2298 ShellExecute(NULL
, L
"open", (LPCWSTR
)fn16
, NULL
, NULL
, SW_SHOW
);
2301 ShellExecute(NULL
, L
"open", (LPCWSTR
)fn16
, NULL
, NULL
, SW_SHOW
);
2309 void mimeview_register_viewer_factory(MimeViewerFactory
*factory
)
2311 mimeviewer_factories
= g_slist_append(mimeviewer_factories
, factory
);
2314 static gint
cmp_viewer_by_factroy(gconstpointer a
, gconstpointer b
)
2316 return ((MimeViewer
*) a
)->factory
== (MimeViewerFactory
*) b
? 0 : -1;
2319 void mimeview_unregister_viewer_factory(MimeViewerFactory
*factory
)
2321 GSList
*mimeview_list
, *viewer_list
;
2323 for (mimeview_list
= mimeviews
; mimeview_list
!= NULL
; mimeview_list
= g_slist_next(mimeview_list
)) {
2324 MimeView
*mimeview
= (MimeView
*) mimeview_list
->data
;
2326 if (mimeview
->mimeviewer
&& mimeview
->mimeviewer
->factory
== factory
) {
2327 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
2328 mimeview
->mimeviewer
= NULL
;
2331 while ((viewer_list
= g_slist_find_custom(mimeview
->viewers
, factory
, cmp_viewer_by_factroy
)) != NULL
) {
2332 MimeViewer
*mimeviewer
= (MimeViewer
*) viewer_list
->data
;
2334 mimeviewer
->destroy_viewer(mimeviewer
);
2335 mimeview
->viewers
= g_slist_remove(mimeview
->viewers
, mimeviewer
);
2339 mimeviewer_factories
= g_slist_remove(mimeviewer_factories
, factory
);
2342 static gboolean
icon_clicked_cb (GtkWidget
*button
, GdkEventButton
*event
, MimeView
*mimeview
)
2347 num
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button
), "icon_number"));
2348 partinfo
= g_object_get_data(G_OBJECT(button
), "partinfo");
2350 if (event
->button
== 1) {
2351 icon_selected(mimeview
, num
, partinfo
);
2352 gtk_widget_grab_focus(button
);
2353 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
2355 part_button_pressed(mimeview
, event
, partinfo
);
2360 static void icon_selected (MimeView
*mimeview
, gint num
, MimeInfo
*partinfo
)
2362 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
2365 MimeInfo
*curr
= NULL
;
2367 gtk_tree_model_get_iter_first(model
, &iter
);
2368 path
= gtk_tree_model_get_path(model
, &iter
);
2371 gtk_tree_model_get_iter(model
, &iter
, path
);
2372 gtk_tree_model_get(model
, &iter
, COL_DATA
, &curr
, -1);
2373 if (curr
== partinfo
) {
2374 GtkTreeSelection
*sel
= gtk_tree_view_get_selection(
2375 GTK_TREE_VIEW(mimeview
->ctree
));
2376 gtk_tree_selection_select_iter(sel
, &iter
);
2377 gtk_tree_path_free(path
);
2380 } while (mimeview_tree_next(model
, path
));
2382 gtk_tree_path_free(path
);
2385 void mimeview_select_mimepart_icon(MimeView
*mimeview
, MimeInfo
*partinfo
)
2387 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
2388 icon_selected(mimeview
, -1, partinfo
);
2391 static gint
icon_key_pressed(GtkWidget
*button
, GdkEventKey
*event
,
2394 SummaryView
*summaryview
;
2396 if (!event
) return FALSE
;
2398 switch (event
->keyval
) {
2400 if (mimeview_scroll_page(mimeview
, FALSE
))
2403 mimeview_select_next_part(mimeview
);
2407 case GDK_KEY_BackSpace
:
2408 mimeview_scroll_page(mimeview
, TRUE
);
2410 case GDK_KEY_Return
:
2411 case GDK_KEY_KP_Enter
:
2412 mimeview_scroll_one_line(mimeview
,
2413 (event
->state
& GDK_MOD1_MASK
) != 0);
2416 BREAK_ON_MODIFIER_KEY();
2417 mimeview_save_as(mimeview
);
2420 BREAK_ON_MODIFIER_KEY();
2421 mimeview_display_as_text(mimeview
);
2424 BREAK_ON_MODIFIER_KEY();
2425 mimeview_launch(mimeview
, NULL
);
2429 BREAK_ON_MODIFIER_KEY();
2430 mimeview_open_with(mimeview
);
2434 BREAK_ON_MODIFIER_KEY();
2435 mimeview_check_signature(mimeview
);
2438 BREAK_ON_MODIFIER_KEY();
2439 mimeview_select_next_part(mimeview
);
2445 if (!mimeview
->messageview
->mainwin
) return FALSE
;
2446 summaryview
= mimeview
->messageview
->mainwin
->summaryview
;
2447 return summary_pass_key_press_event(summaryview
, event
);
2450 static gboolean
icon_popup_menu(GtkWidget
*widget
, gpointer data
)
2452 MimeView
*mimeview
= (MimeView
*)data
;
2453 MimeInfo
*partinfo
= g_object_get_data(G_OBJECT(widget
), "partinfo");
2455 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
2456 "pop_partinfo", partinfo
);
2457 gtk_menu_popup(GTK_MENU(mimeview
->popupmenu
),
2458 NULL
, NULL
, NULL
, NULL
,
2459 0, gtk_get_current_event_time());
2463 static void icon_list_append_icon (MimeView
*mimeview
, MimeInfo
*mimeinfo
)
2465 GtkWidget
*pixmap
= NULL
;
2470 const gchar
*desc
= NULL
;
2471 gchar
*sigshort
= NULL
;
2472 gchar
*content_type
;
2475 MimeInfo
*siginfo
= NULL
;
2476 MimeInfo
*encrypted
= NULL
;
2481 if (!prefs_common
.show_inline_attachments
&& mimeinfo
->id
)
2484 vbox
= mimeview
->icon_vbox
;
2485 mimeview
->icon_count
++;
2486 button
= gtk_event_box_new();
2488 g_signal_connect(G_OBJECT(button
), "motion-notify-event",
2489 G_CALLBACK(mimeview_visi_notify
), mimeview
);
2490 g_signal_connect(G_OBJECT(button
), "leave-notify-event",
2491 G_CALLBACK(mimeview_leave_notify
), mimeview
);
2492 g_signal_connect(G_OBJECT(button
), "enter-notify-event",
2493 G_CALLBACK(mimeview_enter_notify
), mimeview
);
2495 gtk_container_set_border_width(GTK_CONTAINER(button
), 2);
2496 g_object_set_data(G_OBJECT(button
), "icon_number",
2497 GINT_TO_POINTER(mimeview
->icon_count
));
2498 g_object_set_data(G_OBJECT(button
), "partinfo",
2501 switch (mimeinfo
->type
) {
2504 if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "html"))
2505 stockp
= STOCK_PIXMAP_MIME_TEXT_HTML
;
2506 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "enriched"))
2507 stockp
= STOCK_PIXMAP_MIME_TEXT_ENRICHED
;
2508 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "calendar"))
2509 stockp
= STOCK_PIXMAP_MIME_TEXT_CALENDAR
;
2510 else if (mimeinfo
->subtype
&& (!g_ascii_strcasecmp(mimeinfo
->subtype
, "x-patch")
2511 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "x-diff")))
2512 stockp
= STOCK_PIXMAP_MIME_TEXT_PATCH
;
2514 stockp
= STOCK_PIXMAP_MIME_TEXT_PLAIN
;
2516 case MIMETYPE_MESSAGE
:
2517 stockp
= STOCK_PIXMAP_MIME_MESSAGE
;
2519 case MIMETYPE_APPLICATION
:
2520 if (mimeinfo
->subtype
&& (!g_ascii_strcasecmp(mimeinfo
->subtype
, "pgp-signature")
2521 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "x-pkcs7-signature")
2522 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "pkcs7-signature")))
2523 stockp
= STOCK_PIXMAP_MIME_PGP_SIG
;
2524 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "pdf"))
2525 stockp
= STOCK_PIXMAP_MIME_PDF
;
2526 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "postscript"))
2527 stockp
= STOCK_PIXMAP_MIME_PS
;
2529 stockp
= STOCK_PIXMAP_MIME_APPLICATION
;
2531 case MIMETYPE_IMAGE
:
2532 stockp
= STOCK_PIXMAP_MIME_IMAGE
;
2534 case MIMETYPE_AUDIO
:
2535 stockp
= STOCK_PIXMAP_MIME_AUDIO
;
2538 stockp
= STOCK_PIXMAP_MIME_UNKNOWN
;
2542 partinfo
= mimeinfo
;
2543 while (partinfo
!= NULL
) {
2544 if (privacy_mimeinfo_is_signed(partinfo
)) {
2548 if (privacy_mimeinfo_is_encrypted(partinfo
)) {
2549 encrypted
= partinfo
;
2552 partinfo
= procmime_mimeinfo_parent(partinfo
);
2555 if (siginfo
!= NULL
) {
2556 switch (privacy_mimeinfo_get_sig_status(siginfo
)) {
2557 case SIGNATURE_UNCHECKED
:
2558 case SIGNATURE_CHECK_FAILED
:
2559 case SIGNATURE_CHECK_TIMEOUT
:
2560 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2561 STOCK_PIXMAP_PRIVACY_EMBLEM_SIGNED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2564 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2565 STOCK_PIXMAP_PRIVACY_EMBLEM_PASSED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2567 case SIGNATURE_WARN
:
2568 case SIGNATURE_KEY_EXPIRED
:
2569 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2570 STOCK_PIXMAP_PRIVACY_EMBLEM_WARN
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2572 case SIGNATURE_INVALID
:
2573 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2574 STOCK_PIXMAP_PRIVACY_EMBLEM_FAILED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2577 sigshort
= privacy_mimeinfo_sig_info_short(siginfo
);
2578 } else if (encrypted
!= NULL
) {
2579 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2580 STOCK_PIXMAP_PRIVACY_EMBLEM_ENCRYPTED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2582 pixmap
= stock_pixmap_widget_with_overlay(stockp
, 0,
2583 OVERLAY_NONE
, 6, 3);
2585 gtk_container_add(GTK_CONTAINER(button
), pixmap
);
2587 if (prefs_common
.attach_desc
)
2588 desc
= get_part_description(mimeinfo
);
2590 desc
= get_part_name(mimeinfo
);
2593 content_type
= procmime_get_content_type_str(mimeinfo
->type
,
2596 tip
= g_strconcat("<b>", _("Type:"), " </b>", content_type
,
2597 "\n<b>", _("Size:"), " </b>",
2598 to_human_readable((goffset
)mimeinfo
->length
), NULL
);
2599 g_free(content_type
);
2600 if (desc
&& *desc
) {
2601 gchar
*tmp
= NULL
, *escaped
= NULL
;
2602 if (!g_utf8_validate(desc
, -1, NULL
)) {
2603 tmp
= conv_filename_to_utf8(desc
);
2605 tmp
= g_strdup(desc
);
2607 escaped
= g_markup_escape_text(tmp
,-1);
2609 tiptmp
= g_strconcat(tip
, "\n<b>",
2610 prefs_common
.attach_desc
&& mimeinfo
->description
?
2611 _("Description:") : _("Filename:"),
2612 " </b>", escaped
, NULL
);
2618 if (sigshort
&& *sigshort
) {
2619 tiptmp
= g_strjoin("\n", tip
, g_markup_escape_text(sigshort
, -1), NULL
);
2625 gtk_widget_set_tooltip_markup(button
, tip
);
2627 gtk_widget_show_all(button
);
2628 gtk_drag_source_set(button
, GDK_BUTTON1_MASK
|GDK_BUTTON3_MASK
,
2629 mimeview_mime_types
, 1, GDK_ACTION_COPY
);
2631 g_signal_connect(G_OBJECT(button
), "popup-menu",
2632 G_CALLBACK(icon_popup_menu
), mimeview
);
2633 g_signal_connect(G_OBJECT(button
), "button_release_event",
2634 G_CALLBACK(icon_clicked_cb
), mimeview
);
2635 g_signal_connect(G_OBJECT(button
), "key_press_event",
2636 G_CALLBACK(icon_key_pressed
), mimeview
);
2637 g_signal_connect(G_OBJECT(button
), "drag_data_get",
2638 G_CALLBACK(mimeview_drag_data_get
), mimeview
);
2639 gtk_box_pack_start(GTK_BOX(vbox
), button
, FALSE
, FALSE
, 0);
2641 gtk_widget_size_request(pixmap
, &r
);
2642 gtk_widget_set_size_request(button
, -1, r
.height
+ 4);
2647 static void icon_list_clear (MimeView
*mimeview
)
2649 GList
*child
, *orig
;
2652 orig
= gtk_container_get_children(GTK_CONTAINER(mimeview
->icon_vbox
));
2653 for (child
= orig
; child
!= NULL
; child
= g_list_next(child
)) {
2654 gtkut_container_remove(GTK_CONTAINER(mimeview
->icon_vbox
),
2655 GTK_WIDGET(child
->data
));
2658 mimeview
->icon_count
= 0;
2659 adj
= gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview
->icon_scroll
));
2660 gtk_adjustment_set_value(adj
, gtk_adjustment_get_lower(adj
));
2661 gtk_adjustment_changed(adj
);
2665 *\brief Used to 'click' the next or previous icon.
2667 *\return true if the icon 'number' exists and was selected.
2669 static void icon_scroll_size_allocate_cb(GtkWidget
*widget
,
2670 GtkAllocation
*size
, MimeView
*mimeview
)
2672 GtkAllocation vbox_size
;
2673 GtkAllocation layout_size
;
2678 adj
= gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview
->icon_scroll
));
2680 gtk_widget_get_allocation(mimeview
->icon_vbox
, &vbox_size
);
2681 gtk_widget_get_allocation(mimeview
->icon_scroll
, &layout_size
);
2683 gtk_layout_get_size(GTK_LAYOUT(mimeview
->icon_scroll
), &width
, &height
);
2684 gtk_layout_set_size(GTK_LAYOUT(mimeview
->icon_scroll
),
2686 MAX(vbox_size
.height
, layout_size
.height
));
2687 gtk_adjustment_set_step_increment(adj
, 10);
2690 static void icon_list_create(MimeView
*mimeview
, MimeInfo
*mimeinfo
)
2692 GtkRequisition size
;
2693 GtkRequisition requisition
;
2695 cm_return_if_fail(mimeinfo
!= NULL
);
2697 while (mimeinfo
!= NULL
) {
2698 if (mimeinfo
->type
!= MIMETYPE_MULTIPART
)
2699 icon_list_append_icon(mimeview
, mimeinfo
);
2700 if (mimeinfo
->node
->children
!= NULL
)
2701 icon_list_create(mimeview
,
2702 (MimeInfo
*) mimeinfo
->node
->children
->data
);
2703 mimeinfo
= mimeinfo
->node
->next
!= NULL
2704 ? (MimeInfo
*) mimeinfo
->node
->next
->data
2707 gtk_widget_size_request(mimeview
->icon_vbox
, &size
);
2708 gtk_widget_get_requisition(mimeview
->icon_mainbox
, &requisition
);
2709 if (size
.width
> requisition
.width
) {
2710 gtk_widget_set_size_request(mimeview
->icon_mainbox
,
2713 if (mimeview
->opened
)
2714 icon_list_toggle_by_mime_info(mimeview
,
2715 mimeview_get_node_part(mimeview
, mimeview
->opened
));
2718 static void icon_list_toggle_by_mime_info (MimeView
*mimeview
,
2721 GList
*children
, *child
;
2723 children
= gtk_container_get_children(GTK_CONTAINER(mimeview
->icon_vbox
));
2724 for (child
= children
; child
!= NULL
; child
= g_list_next(child
)) {
2725 gboolean
*highlight
= NULL
;
2726 GtkWidget
*icon
= gtk_bin_get_child(GTK_BIN(child
->data
));
2728 if (!GTK_IS_EVENT_BOX(child
->data
))
2731 highlight
= g_object_get_data(G_OBJECT(icon
), "highlight");
2732 *highlight
= (g_object_get_data(G_OBJECT(child
->data
),
2733 "partinfo") == (gpointer
)mimeinfo
);
2735 gtk_widget_queue_draw(icon
);
2737 g_list_free(children
);
2740 static void ctree_size_allocate_cb(GtkWidget
*widget
, GtkAllocation
*allocation
,
2743 prefs_common
.mimeview_tree_height
= allocation
->height
;
2746 static gint
mime_toggle_button_cb(GtkWidget
*button
, GdkEventButton
*event
,
2749 g_object_ref(button
);
2751 mimeview_leave_notify(button
, NULL
, NULL
);
2753 mimeview
->ctree_mode
= !mimeview
->ctree_mode
;
2754 if (mimeview
->ctree_mode
) {
2755 gtk_arrow_set(GTK_ARROW(gtk_bin_get_child(GTK_BIN((button
)))), GTK_ARROW_RIGHT
,
2757 gtk_widget_hide(mimeview
->icon_mainbox
);
2758 gtk_widget_show(mimeview
->ctree_mainbox
);
2759 gtk_paned_set_position(GTK_PANED(mimeview
->paned
),
2760 prefs_common
.mimeview_tree_height
);
2762 gtkut_container_remove(GTK_CONTAINER(mimeview
->icon_mainbox
),
2764 gtk_box_pack_end(GTK_BOX(mimeview
->ctree_mainbox
),
2765 button
, FALSE
, FALSE
, 0);
2767 gtk_arrow_set(GTK_ARROW(gtk_bin_get_child(GTK_BIN((button
)))), GTK_ARROW_LEFT
,
2769 gtk_widget_hide(mimeview
->ctree_mainbox
);
2770 gtk_widget_show(mimeview
->icon_mainbox
);
2771 gtk_paned_set_position(GTK_PANED(mimeview
->paned
), 0);
2773 gtkut_container_remove(GTK_CONTAINER(mimeview
->ctree_mainbox
),
2775 gtk_box_pack_start(GTK_BOX(mimeview
->icon_mainbox
),
2776 button
, FALSE
, FALSE
, 0);
2777 gtk_box_reorder_child(GTK_BOX(gtk_widget_get_parent(button
)), button
, 0);
2778 if (mimeview
->opened
)
2779 icon_list_toggle_by_mime_info(mimeview
,
2780 mimeview_get_node_part(mimeview
, mimeview
->opened
));
2781 summary_grab_focus(mimeview
->mainwin
->summaryview
);
2783 g_object_unref(button
);
2787 void mimeview_update (MimeView
*mimeview
)
2789 if (mimeview
&& mimeview
->mimeinfo
) {
2790 icon_list_clear(mimeview
);
2791 icon_list_create(mimeview
, mimeview
->mimeinfo
);
2795 void mimeview_handle_cmd(MimeView
*mimeview
, const gchar
*cmd
, GdkEventButton
*event
, gpointer data
)
2797 MessageView
*msgview
= NULL
;
2798 MainWindow
*mainwin
= NULL
;
2803 msgview
= mimeview
->messageview
;
2807 mainwin
= msgview
->mainwin
;
2811 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
2812 "pop_partinfo", NULL
);
2814 if (!strcmp(cmd
, "sc://view_log"))
2815 log_window_show(mainwin
->logwin
);
2816 else if (!strcmp(cmd
, "sc://save_as"))
2817 mimeview_save_as(mimeview
);
2818 else if (!strcmp(cmd
, "sc://display_as_text"))
2819 mimeview_display_as_text(mimeview
);
2821 else if (!strcmp(cmd
, "sc://open_with"))
2822 mimeview_open_with(mimeview
);
2824 else if (!strcmp(cmd
, "sc://open"))
2825 mimeview_launch(mimeview
, NULL
);
2826 else if (!strcmp(cmd
, "sc://select_attachment") && data
!= NULL
) {
2827 icon_list_toggle_by_mime_info(mimeview
, (MimeInfo
*)data
);
2828 icon_selected(mimeview
, -1, (MimeInfo
*)data
);
2829 } else if (!strcmp(cmd
, "sc://open_attachment") && data
!= NULL
) {
2830 mimeview_launch(mimeview
, (MimeInfo
*)data
);
2831 } else if (!strcmp(cmd
, "sc://menu_attachment") && data
!= NULL
) {
2832 mimeview
->spec_part
= (MimeInfo
*)data
;
2833 part_button_pressed(mimeview
, event
, (MimeInfo
*)data
);
2834 } else if (!strncmp(cmd
, "sc://search_tags:", strlen("sc://search_tags:"))) {
2835 const gchar
*tagname
= cmd
+ strlen("sc://search_tags:");
2836 gchar
*buf
= g_strdup_printf("tag matchcase \"%s\"", tagname
);
2837 gtk_toggle_button_set_active(
2838 GTK_TOGGLE_BUTTON(mimeview
->messageview
->mainwin
->summaryview
->toggle_search
),
2840 quicksearch_set(mimeview
->messageview
->mainwin
->summaryview
->quicksearch
,
2841 ADVANCED_SEARCH_EXTENDED
, buf
);
2846 gboolean
mimeview_scroll_page(MimeView
*mimeview
, gboolean up
)
2848 if (mimeview
->type
== MIMEVIEW_TEXT
)
2849 return textview_scroll_page(mimeview
->textview
, up
);
2850 else if (mimeview
->mimeviewer
) {
2851 MimeViewer
*mimeviewer
= mimeview
->mimeviewer
;
2852 if (mimeviewer
->scroll_page
)
2853 return mimeviewer
->scroll_page(mimeviewer
, up
);
2858 void mimeview_scroll_one_line(MimeView
*mimeview
, gboolean up
)
2860 if (mimeview
->type
== MIMEVIEW_TEXT
)
2861 textview_scroll_one_line(mimeview
->textview
, up
);
2862 else if (mimeview
->mimeviewer
) {
2863 MimeViewer
*mimeviewer
= mimeview
->mimeviewer
;
2864 if (mimeviewer
->scroll_one_line
)
2865 mimeviewer
->scroll_one_line(mimeviewer
, up
);