2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto
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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtknotebook.h>
29 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtkctree.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkhbox.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtktext.h>
35 #include <gtk/gtksignal.h>
36 #include <gtk/gtkmenu.h>
37 #include <gtk/gtkdnd.h>
38 #include <gtk/gtkselection.h>
39 #include <gtk/gtktooltips.h>
40 #include <gtk/gtkcontainer.h>
41 #include <gtk/gtkbutton.h>
44 #ifndef HAVE_APACHE_FNMATCH
45 /* kludge: apache's fnmatch clashes with <regex.h>, don't include
55 #include "summaryview.h"
58 #include "alertpanel.h"
59 #include "inputdialog.h"
62 #include "prefs_common.h"
64 #include "stock_pixmap.h"
65 #include "gtk/gtkvscrollbutton.h"
75 #define N_MIMEVIEW_COLS 3
77 static void mimeview_set_multipart_tree (MimeView *mimeview,
79 GtkCTreeNode *parent);
80 static GtkCTreeNode *mimeview_append_part (MimeView *mimeview,
82 GtkCTreeNode *parent);
83 static void mimeview_show_message_part (MimeView *mimeview,
85 static void mimeview_change_view_type (MimeView *mimeview,
87 static void mimeview_clear (MimeView *mimeview);
89 static void mimeview_selected (GtkCTree *ctree,
93 static void mimeview_start_drag (GtkWidget *widget,
97 static gint mimeview_button_pressed (GtkWidget *widget,
98 GdkEventButton *event,
100 static gint mimeview_key_pressed (GtkWidget *widget,
104 static void mimeview_drag_data_get (GtkWidget *widget,
105 GdkDragContext *drag_context,
106 GtkSelectionData *selection_data,
111 static void mimeview_display_as_text (MimeView *mimeview);
112 static void mimeview_save_as (MimeView *mimeview);
113 static void mimeview_save_all (MimeView *mimeview);
114 static void mimeview_launch (MimeView *mimeview);
115 static void mimeview_open_with (MimeView *mimeview);
116 static void mimeview_view_file (const gchar *filename,
118 const gchar *cmdline);
119 static gboolean icon_clicked_cb (GtkWidget *button,
120 GdkEventButton *event,
122 static void icon_selected (MimeView *mimeview,
125 static gint icon_key_pressed (GtkWidget *button,
128 static void toggle_icon (GtkToggleButton *button,
130 static void icon_list_append_icon (MimeView *mimeview,
132 static void icon_list_create (MimeView *mimeview,
134 static void icon_list_clear (MimeView *mimeview);
135 static void icon_list_toggle_by_mime_info (MimeView *mimeview,
137 static gboolean icon_list_select_by_number(MimeView *mimeview,
139 static void mime_toggle_button_cb (GtkWidget *button,
141 static void part_button_pressed (MimeView *mimeview,
142 GdkEventButton *event,
144 static void icon_scroll_size_allocate_cb(GtkWidget *widget,
145 GtkAllocation *layout_size,
148 static GtkItemFactoryEntry mimeview_popup_entries[] =
150 {N_("/_Open"), NULL, mimeview_launch, 0, NULL},
151 {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
152 {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
153 {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL},
154 {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL}
157 {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
161 static GtkTargetEntry mimeview_mime_types[] =
163 {"text/uri-list", 0, 0}
166 GSList *mimeviewer_factories;
169 MimeView *mimeview_create(MainWindow *mainwin)
176 GtkWidget *scrolledwin;
178 GtkWidget *mime_notebook;
179 GtkWidget *popupmenu;
180 GtkWidget *ctree_mainbox;
181 GtkWidget *mime_toggle;
182 GtkWidget *icon_mainbox;
183 GtkWidget *icon_scroll;
184 GtkWidget *icon_vbox;
186 GtkWidget *scrollbutton;
188 GtkTooltips *tooltips;
189 GtkItemFactory *popupfactory;
190 gchar *titles[N_MIMEVIEW_COLS];
194 debug_print("Creating MIME view...\n");
195 mimeview = g_new0(MimeView, 1);
197 titles[COL_MIMETYPE] = _("MIME Type");
198 titles[COL_SIZE] = _("Size");
199 titles[COL_NAME] = _("Name");
201 notebook = gtk_notebook_new();
202 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
203 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
204 gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
206 vbox = gtk_vbox_new(FALSE, 0);
207 gtk_container_add(GTK_CONTAINER(notebook), vbox);
209 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
210 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
211 GTK_POLICY_AUTOMATIC,
214 ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
215 gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
216 gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
217 gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
219 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
220 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 90);
221 for (i = 0; i < N_MIMEVIEW_COLS; i++)
222 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
224 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
226 gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
227 GTK_SIGNAL_FUNC(mimeview_selected), mimeview);
228 gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
229 GTK_SIGNAL_FUNC(mimeview_button_pressed), mimeview);
230 gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
231 GTK_SIGNAL_FUNC(mimeview_key_pressed), mimeview);
232 gtk_signal_connect(GTK_OBJECT (ctree),"start_drag",
233 GTK_SIGNAL_FUNC (mimeview_start_drag), mimeview);
234 gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_get",
235 GTK_SIGNAL_FUNC(mimeview_drag_data_get), mimeview);
237 mime_notebook = gtk_notebook_new();
238 gtk_widget_show(mime_notebook);
239 GTK_WIDGET_UNSET_FLAGS(mime_notebook, GTK_CAN_FOCUS);
240 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(mime_notebook), FALSE);
241 gtk_notebook_set_show_border(GTK_NOTEBOOK(mime_notebook), FALSE);
243 gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 0);
245 icon_vbox = gtk_vbox_new(FALSE, 2);
246 icon_scroll = gtk_layout_new(NULL, NULL);
247 gtk_layout_put(GTK_LAYOUT(icon_scroll), icon_vbox, 0, 0);
248 scrollbutton = gtk_vscrollbutton_new(gtk_layout_get_vadjustment(GTK_LAYOUT(icon_scroll)));
250 mime_toggle = gtk_toggle_button_new();
251 arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
252 gtk_widget_show(arrow);
253 gtk_container_add(GTK_CONTAINER(mime_toggle), arrow);
254 gtk_signal_connect(GTK_OBJECT(mime_toggle), "toggled",
255 GTK_SIGNAL_FUNC(mime_toggle_button_cb), mimeview);
257 icon_mainbox = gtk_vbox_new(FALSE, 0);
258 gtk_box_pack_start(GTK_BOX(icon_mainbox), mime_toggle, FALSE, FALSE, 0);
259 gtk_box_pack_start(GTK_BOX(icon_mainbox), icon_scroll, TRUE, TRUE, 3);
260 gtk_box_pack_end(GTK_BOX(icon_mainbox), scrollbutton, FALSE, FALSE, 0);
261 gtk_signal_connect(GTK_OBJECT(icon_mainbox), "size_allocate",
262 GTK_SIGNAL_FUNC(icon_scroll_size_allocate_cb), mimeview);
264 ctree_mainbox = gtk_hbox_new(FALSE, 0);
265 gtk_box_pack_start(GTK_BOX(ctree_mainbox), scrolledwin, TRUE, TRUE, 0);
267 n_entries = sizeof(mimeview_popup_entries) /
268 sizeof(mimeview_popup_entries[0]);
269 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
270 "<MimeView>", &popupfactory, mimeview);
271 tooltips = gtk_tooltips_new();
272 gtk_tooltips_set_delay(tooltips, 0);
274 paned = gtk_vpaned_new();
275 gtk_paned_set_gutter_size(GTK_PANED(paned), 6);
276 gtk_paned_pack1(GTK_PANED(paned), ctree_mainbox, FALSE, TRUE);
277 gtk_paned_pack2(GTK_PANED(paned), mime_notebook, TRUE, TRUE);
278 gtk_container_add(GTK_CONTAINER(notebook), paned);
280 hbox = gtk_hbox_new(FALSE, 0);
281 gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 0);
282 gtk_box_pack_start(GTK_BOX(hbox), icon_mainbox, FALSE, FALSE, 0);
284 gtk_widget_show_all(hbox);
285 gtk_widget_hide(ctree_mainbox);
287 mimeview->notebook = notebook;
288 mimeview->vbox = vbox;
289 mimeview->hbox = hbox;
290 mimeview->paned = paned;
291 mimeview->scrolledwin = scrolledwin;
292 mimeview->ctree = ctree;
293 mimeview->mime_notebook = mime_notebook;
294 mimeview->popupmenu = popupmenu;
295 mimeview->popupfactory = popupfactory;
297 mimeview->ctree_mainbox = ctree_mainbox;
298 mimeview->icon_scroll = icon_scroll;
299 mimeview->icon_vbox = icon_vbox;
300 mimeview->icon_mainbox = icon_mainbox;
301 mimeview->icon_count = 0;
302 mimeview->mainwin = mainwin;
303 mimeview->tooltips = tooltips;
304 mimeview->oldsize = 60;
305 mimeview->mime_toggle = mime_toggle;
307 mimeview->target_list = gtk_target_list_new(mimeview_mime_types, 1);
309 mimeviews = g_slist_prepend(mimeviews, mimeview);
314 void mimeview_init(MimeView *mimeview)
316 textview_init(mimeview->textview);
318 gtk_container_add(GTK_CONTAINER(mimeview->mime_notebook),
319 GTK_WIDGET_PTR(mimeview->textview));
323 * Check whether the message is OpenPGP signed
326 static gboolean mimeview_is_signed(MimeView *mimeview)
328 MimeInfo *partinfo = NULL;
330 debug_print("mimeview_is signed of %p\n", mimeview);
332 if (!mimeview) return FALSE;
333 if (!mimeview->opened) return FALSE;
335 debug_print("mimeview_is_signed: open\n" );
337 if (!mimeview->file) return FALSE;
339 debug_print("mimeview_is_signed: file\n" );
341 partinfo = gtk_ctree_node_get_row_data
342 (GTK_CTREE(mimeview->ctree), mimeview->opened);
343 g_return_val_if_fail(partinfo != NULL, FALSE);
345 /* walk the tree and see whether there is a signature somewhere */
347 if (rfc2015_has_signature(partinfo))
349 } while ((partinfo = partinfo->parent) != NULL);
351 debug_print("mimeview_is_signed: FALSE\n" );
356 static void set_unchecked_signature(MimeInfo *mimeinfo)
358 MimeInfo *sig_partinfo;
360 sig_partinfo = rfc2015_find_signature(mimeinfo);
361 if (sig_partinfo == NULL) return;
363 g_free(sig_partinfo->sigstatus);
364 sig_partinfo->sigstatus =
365 g_strdup(_("Right-click here to verify the signature"));
367 g_free(sig_partinfo->sigstatus_full);
368 sig_partinfo->sigstatus_full = NULL;
370 #endif /* USE_GPGME */
372 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
375 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
379 mimeview_clear(mimeview);
380 textview_clear(mimeview->messageview->textview);
382 g_return_if_fail(file != NULL);
383 g_return_if_fail(mimeinfo != NULL);
385 mimeview->mimeinfo = mimeinfo;
387 mimeview->file = g_strdup(file);
390 if (prefs_common.auto_check_signatures && gpg_started) {
391 if ((fp = fopen(file, "rb")) == NULL) {
392 FILE_OP_ERROR(file, "fopen");
395 rfc2015_check_signature(mimeinfo, fp);
398 set_unchecked_signature(mimeinfo);
401 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
404 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
405 icon_list_create(mimeview, mimeinfo);
407 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
408 mimeview_selected, mimeview);
410 /* search first text part */
411 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
412 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
415 partinfo = gtk_ctree_node_get_row_data(ctree, node);
417 (partinfo->mime_type == MIME_TEXT ||
418 partinfo->mime_type == MIME_TEXT_HTML))
421 textview_show_message(mimeview->messageview->textview, mimeinfo, file);
424 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
427 gtk_ctree_select(ctree, node);
428 icon_list_toggle_by_mime_info
429 (mimeview, gtk_ctree_node_get_row_data(ctree, node));
430 gtkut_ctree_set_focus_row(ctree, node);
431 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mimeview->mime_toggle)))
432 gtk_widget_grab_focus(mimeview->ctree);
436 void mimeview_destroy(MimeView *mimeview)
440 for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
441 MimeViewer *viewer = (MimeViewer *) cur->data;
442 gtk_container_remove(GTK_CONTAINER(mimeview->mime_notebook),
443 GTK_WIDGET(viewer->get_widget(viewer)));
444 viewer->destroy_viewer(viewer);
446 g_slist_free(mimeview->viewers);
447 gtk_target_list_unref(mimeview->target_list);
449 procmime_mimeinfo_free_all(mimeview->mimeinfo);
450 g_free(mimeview->file);
453 mimeviews = g_slist_remove(mimeviews, mimeview);
457 MimeInfo *mimeview_get_selected_part(MimeView *mimeview)
459 if (gtk_notebook_get_current_page
460 (GTK_NOTEBOOK(mimeview->notebook)) == 0)
463 return gtk_ctree_node_get_row_data
464 (GTK_CTREE(mimeview->ctree), mimeview->opened);
467 static void mimeview_set_multipart_tree(MimeView *mimeview,
469 GtkCTreeNode *parent)
473 g_return_if_fail(mimeinfo != NULL);
475 if (mimeinfo->children)
476 mimeinfo = mimeinfo->children;
478 while (mimeinfo != NULL) {
479 node = mimeview_append_part(mimeview, mimeinfo, parent);
481 if (mimeinfo->children)
482 mimeview_set_multipart_tree(mimeview, mimeinfo, node);
483 else if (mimeinfo->sub &&
484 mimeinfo->sub->mime_type != MIME_TEXT &&
485 mimeinfo->sub->mime_type != MIME_TEXT_HTML)
486 mimeview_set_multipart_tree(mimeview, mimeinfo->sub,
488 mimeinfo = mimeinfo->next;
492 static gchar *get_part_name(MimeInfo *partinfo)
495 if (partinfo->sigstatus)
496 return partinfo->sigstatus;
500 return partinfo->name;
501 else if (partinfo->filename)
502 return partinfo->filename;
503 else if (partinfo->description)
504 return partinfo->description;
509 static gchar *get_part_description(MimeInfo *partinfo)
511 if (partinfo->description)
512 return partinfo->description;
513 else if (partinfo->name)
514 return partinfo->name;
515 else if (partinfo->filename)
516 return partinfo->filename;
521 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
523 GtkCTreeNode *parent)
525 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
527 gchar *str[N_MIMEVIEW_COLS];
530 partinfo->content_type ? partinfo->content_type : "";
531 str[COL_SIZE] = to_human_readable(partinfo->size);
532 if (prefs_common.attach_desc)
533 str[COL_NAME] = get_part_description(partinfo);
535 str[COL_NAME] = get_part_name(partinfo);
537 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
538 NULL, NULL, NULL, NULL,
540 gtk_ctree_node_set_row_data(ctree, node, partinfo);
545 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
553 if (!partinfo) return;
556 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
558 fname = pi ? pi->plaintextfile : mimeview->file;
560 fname = mimeview->file;
561 #endif /* USE_GPGME */
564 if ((fp = fopen(fname, "rb")) == NULL) {
565 FILE_OP_ERROR(fname, "fopen");
569 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
570 FILE_OP_ERROR(mimeview->file, "fseek");
575 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
576 textview_show_part(mimeview->textview, partinfo, fp);
581 static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *content_type)
584 MimeViewerFactory *factory = NULL;
585 MimeViewer *viewer = NULL;
588 * FNM_CASEFOLD is a GNU extension
589 * if its not defined copy the string to the stack and
590 * convert the copy to lower case
593 #define FNM_CASEFOLD 0
594 Xstrdup_a(content_type, content_type, return NULL);
595 g_strdown((gchar *)content_type);
598 for (cur = mimeviewer_factories; cur != NULL; cur = g_slist_next(cur)) {
599 MimeViewerFactory *curfactory = cur->data;
602 while (curfactory->content_types[i] != NULL) {
603 debug_print("%s\n", curfactory->content_types[i]);
604 if(!fnmatch(curfactory->content_types[i], content_type, FNM_CASEFOLD)) {
605 factory = curfactory;
616 for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
617 MimeViewer *curviewer = cur->data;
619 if (curviewer->factory == factory)
622 viewer = factory->create_viewer();
623 gtk_container_add(GTK_CONTAINER(mimeview->mime_notebook),
624 GTK_WIDGET(viewer->get_widget(viewer)));
626 mimeview->viewers = g_slist_append(mimeview->viewers, viewer);
631 static MimeViewer *get_viewer_for_mimeinfo(MimeView *mimeview, MimeInfo *partinfo)
633 gchar *content_type = NULL;
634 MimeViewer *viewer = NULL;
636 if ((partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM) &&
637 (partinfo->name != NULL)) {
638 content_type = procmime_get_mime_type(partinfo->name);
640 content_type = g_strdup(partinfo->content_type);
643 if (content_type != NULL) {
644 viewer = get_viewer_for_content_type(mimeview, content_type);
645 g_free(content_type);
651 static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
655 viewer = get_viewer_for_mimeinfo(mimeview, partinfo);
656 if (viewer == NULL) {
657 if (mimeview->mimeviewer != NULL)
658 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
659 mimeview->mimeviewer = NULL;
663 if (mimeview->mimeviewer != viewer) {
664 if (mimeview->mimeviewer != NULL)
665 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
666 mimeview->mimeviewer = viewer;
667 mimeview_change_view_type(mimeview, MIMEVIEW_VIEWER);
669 viewer->show_mimepart(viewer, mimeview->file, partinfo);
674 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
676 TextView *textview = mimeview->textview;
678 if ((mimeview->type != MIMEVIEW_VIEWER) &&
679 (mimeview->type == type)) return;
683 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
684 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
685 GTK_WIDGET_PTR(textview)));
687 case MIMEVIEW_VIEWER:
688 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
689 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
690 GTK_WIDGET(mimeview->mimeviewer->get_widget(mimeview->mimeviewer))));
696 mimeview->type = type;
699 static void mimeview_clear(MimeView *mimeview)
701 GtkCList *clist = GTK_CLIST(mimeview->ctree);
703 procmime_mimeinfo_free_all(mimeview->mimeinfo);
704 mimeview->mimeinfo = NULL;
706 gtk_clist_clear(clist);
707 textview_clear(mimeview->textview);
708 if (mimeview->mimeviewer != NULL)
709 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
711 mimeview->opened = NULL;
713 g_free(mimeview->file);
714 mimeview->file = NULL;
716 icon_list_clear(mimeview);
718 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mimeview->mime_toggle)))
719 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0);
722 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
727 if (mimeview->opened == node) return;
728 mimeview->opened = node;
729 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
731 partinfo = gtk_ctree_node_get_row_data(ctree, node);
732 if (!partinfo) return;
734 /* ungrab the mouse event */
735 if (GTK_WIDGET_HAS_GRAB(ctree)) {
736 gtk_grab_remove(GTK_WIDGET(ctree));
737 if (gdk_pointer_is_grabbed())
738 gdk_pointer_ungrab(GDK_CURRENT_TIME);
741 mimeview->textview->default_text = FALSE;
743 if (!mimeview_show_part(mimeview, partinfo)) {
744 switch (partinfo->mime_type) {
747 case MIME_TEXT_ENRICHED:
748 case MIME_MESSAGE_RFC822:
750 mimeview_show_message_part(mimeview, partinfo);
754 mimeview->textview->default_text = TRUE;
755 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
757 if (g_strcasecmp(partinfo->content_type,
758 "application/pgp-signature") == 0)
759 textview_show_signature_part(mimeview->textview,
763 textview_show_mime_part(mimeview->textview, partinfo);
769 static void mimeview_start_drag(GtkWidget *widget, gint button,
770 GdkEvent *event, MimeView *mimeview)
772 GdkDragContext *context;
775 g_return_if_fail(mimeview != NULL);
777 partinfo = mimeview_get_selected_part(mimeview);
778 if (partinfo->filename == NULL && partinfo->name == NULL) return;
780 context = gtk_drag_begin(widget, mimeview->target_list,
781 GDK_ACTION_COPY, button, event);
782 gtk_drag_set_icon_default(context);
785 static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
788 GtkCList *clist = GTK_CLIST(widget);
791 if (!event) return FALSE;
793 if (event->button == 2 || event->button == 3) {
794 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
797 gtk_clist_unselect_all(clist);
798 gtk_clist_select_row(clist, row, column);
799 gtkut_clist_set_focus_row(clist, row);
801 part_button_pressed(mimeview, event, mimeview_get_selected_part(mimeview));
806 static void part_button_pressed(MimeView *mimeview, GdkEventButton *event,
809 if (event->button == 2 ||
810 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
811 /* call external program for image, audio or html */
812 mimeview_launch(mimeview);
813 } else if (event->button == 3) {
814 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
815 partinfo->mime_type == MIME_TEXT_HTML ||
816 partinfo->mime_type == MIME_TEXT_ENRICHED ||
817 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
818 partinfo->mime_type == MIME_IMAGE ||
819 partinfo->mime_type == MIME_MULTIPART))
820 menu_set_sensitive(mimeview->popupfactory,
821 "/Display as text", FALSE);
823 menu_set_sensitive(mimeview->popupfactory,
824 "/Display as text", TRUE);
826 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
827 menu_set_sensitive(mimeview->popupfactory,
830 menu_set_sensitive(mimeview->popupfactory,
834 menu_set_sensitive(mimeview->popupfactory,
836 mimeview_is_signed(mimeview));
838 gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
839 "pop_partinfo", partinfo);
841 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
842 NULL, NULL, NULL, NULL,
843 event->button, event->time);
849 void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
851 mimeview_key_pressed(mimeview->ctree, event, mimeview);
854 #define BREAK_ON_MODIFIER_KEY() \
855 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
857 #define KEY_PRESS_EVENT_STOP() \
858 if (gtk_signal_n_emissions_by_name \
859 (GTK_OBJECT(ctree), "key_press_event") > 0) { \
860 gtk_signal_emit_stop_by_name(GTK_OBJECT(ctree), \
861 "key_press_event"); \
864 static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
867 SummaryView *summaryview;
868 GtkCTree *ctree = GTK_CTREE(widget);
871 if (!event) return FALSE;
872 if (!mimeview->opened) return FALSE;
874 switch (event->keyval) {
876 if (textview_scroll_page(mimeview->textview, FALSE))
879 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
881 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
882 gtk_sctree_select(GTK_SCTREE(ctree), node);
887 textview_scroll_page(mimeview->textview, TRUE);
890 textview_scroll_one_line(mimeview->textview,
891 (event->state & GDK_MOD1_MASK) != 0);
895 BREAK_ON_MODIFIER_KEY();
896 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
897 KEY_PRESS_EVENT_STOP();
899 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
900 GTK_SCROLL_STEP_FORWARD, 0.0);
904 BREAK_ON_MODIFIER_KEY();
905 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
906 KEY_PRESS_EVENT_STOP();
908 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
909 GTK_SCROLL_STEP_BACKWARD, 0.0);
912 BREAK_ON_MODIFIER_KEY();
913 KEY_PRESS_EVENT_STOP();
914 mimeview_save_as(mimeview);
917 BREAK_ON_MODIFIER_KEY();
918 KEY_PRESS_EVENT_STOP();
919 mimeview_display_as_text(mimeview);
922 BREAK_ON_MODIFIER_KEY();
923 KEY_PRESS_EVENT_STOP();
924 mimeview_launch(mimeview);
930 if (!mimeview->messageview->mainwin) return FALSE;
931 summaryview = mimeview->messageview->mainwin->summaryview;
932 summary_pass_key_press_event(summaryview, event);
936 static void mimeview_drag_data_get(GtkWidget *widget,
937 GdkDragContext *drag_context,
938 GtkSelectionData *selection_data,
943 gchar *filename, *uriname;
946 if (!mimeview->opened) return;
947 if (!mimeview->file) return;
949 partinfo = mimeview_get_selected_part(mimeview);
950 if (!partinfo) return;
951 if (!partinfo->filename && !partinfo->name) return;
953 filename = partinfo->filename ? partinfo->filename : partinfo->name;
954 filename = g_basename(filename);
955 if (*filename == '\0') return;
957 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
960 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
962 (_("Can't save the part of multipart message."));
964 uriname = g_strconcat("file:/", filename, NULL);
965 gtk_selection_data_set(selection_data, selection_data->target, 8,
966 uriname, strlen(uriname));
972 static void mimeview_save_all(MimeView *mimeview)
975 gchar *defname = NULL;
977 MimeInfo *attachment;
980 if (!mimeview->opened) return;
981 if (!mimeview->file) return;
983 partinfo = mimeview_get_selected_part(mimeview);
984 g_return_if_fail(partinfo != NULL);
986 dirname = filesel_select_file(_("Save as"), defname);
987 if (!dirname) return;
989 /* return to first children */
990 if (!partinfo->parent->children) return; /* multipart container? */
991 attachment = partinfo->parent->children->next;
992 /* for each attachment, extract it in the selected dir. */
993 while (attachment != NULL) {
994 static guint subst_cnt = 1;
996 gchar *attachname = g_strdup(get_part_name(attachment));
997 AlertValue aval = G_ALERTDEFAULT;
1000 if (!attachname || !strlen(attachname))
1001 attachname = g_strdup_printf("noname.%d",subst_cnt++);
1002 subst_chars(attachname, ":?*&|<>\t\r\n", '_');
1003 g_snprintf(buf, sizeof(buf), "%s%s",
1005 (attachname[0] == G_DIR_SEPARATOR)
1008 subst_chars(buf, "/\\", G_DIR_SEPARATOR);
1009 attachdir = g_dirname(buf);
1010 make_dir_hier(attachdir);
1013 if (is_file_exist(buf)) {
1014 res = g_strdup_printf(_("Overwrite existing file '%s'?"),
1016 aval = alertpanel(_("Overwrite"), res, _("OK"),
1022 if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, mimeview->file, attachment) < 0))
1023 alertpanel_error(_("Can't save the part of multipart message."));
1024 attachment = attachment->next;
1028 static void mimeview_display_as_text(MimeView *mimeview)
1032 if (!mimeview->opened) return;
1034 partinfo = mimeview_get_selected_part(mimeview);
1036 partinfo = (MimeInfo *) gtk_object_get_data
1037 (GTK_OBJECT(mimeview->popupmenu),
1039 gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
1040 "pop_partinfo", NULL);
1043 g_return_if_fail(partinfo != NULL);
1044 mimeview_show_message_part(mimeview, partinfo);
1047 static void mimeview_save_as(MimeView *mimeview)
1050 gchar *defname = NULL;
1054 if (!mimeview->opened) return;
1055 if (!mimeview->file) return;
1057 partinfo = mimeview_get_selected_part(mimeview);
1059 partinfo = (MimeInfo *) gtk_object_get_data
1060 (GTK_OBJECT(mimeview->popupmenu),
1062 gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
1063 "pop_partinfo", NULL);
1065 g_return_if_fail(partinfo != NULL);
1067 if (partinfo->filename)
1068 defname = partinfo->filename;
1069 else if (partinfo->name) {
1070 Xstrdup_a(defname, partinfo->name, return);
1071 subst_for_filename(defname);
1074 filename = filesel_select_file(_("Save as"), defname);
1075 if (!filename) return;
1076 if (is_file_exist(filename)) {
1078 res = g_strdup_printf(_("Overwrite existing file '%s'?"),
1080 aval = alertpanel(_("Overwrite"), res, _("OK"),
1083 if (G_ALERTDEFAULT != aval) return;
1086 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
1088 (_("Can't save the part of multipart message."));
1091 static void mimeview_launch(MimeView *mimeview)
1096 if (!mimeview->opened) return;
1097 if (!mimeview->file) return;
1099 partinfo = mimeview_get_selected_part(mimeview);
1101 partinfo = (MimeInfo *) gtk_object_get_data
1102 (GTK_OBJECT(mimeview->popupmenu),
1104 gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
1105 "pop_partinfo", NULL);
1107 g_return_if_fail(partinfo != NULL);
1109 filename = procmime_get_tmp_file_name(partinfo);
1111 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
1113 (_("Can't save the part of multipart message."));
1115 mimeview_view_file(filename, partinfo, NULL);
1120 static void mimeview_open_with(MimeView *mimeview)
1126 if (!mimeview->opened) return;
1127 if (!mimeview->file) return;
1129 partinfo = mimeview_get_selected_part(mimeview);
1131 partinfo = (MimeInfo *) gtk_object_get_data
1132 (GTK_OBJECT(mimeview->popupmenu),
1134 gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
1135 "pop_partinfo", NULL);
1137 g_return_if_fail(partinfo != NULL);
1139 filename = procmime_get_tmp_file_name(partinfo);
1141 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
1143 (_("Can't save the part of multipart message."));
1148 if (!prefs_common.mime_open_cmd_history)
1149 prefs_common.mime_open_cmd_history =
1150 add_history(NULL, prefs_common.mime_open_cmd);
1152 cmd = input_dialog_combo
1154 _("Enter the command line to open file:\n"
1155 "(`%s' will be replaced with file name)"),
1156 prefs_common.mime_open_cmd,
1157 prefs_common.mime_open_cmd_history,
1160 mimeview_view_file(filename, partinfo, cmd);
1161 g_free(prefs_common.mime_open_cmd);
1162 prefs_common.mime_open_cmd = cmd;
1163 prefs_common.mime_open_cmd_history =
1164 add_history(prefs_common.mime_open_cmd_history, cmd);
1170 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
1171 const gchar *cmdline)
1173 static gchar *default_image_cmdline = "display '%s'";
1174 static gchar *default_audio_cmdline = "play '%s'";
1175 static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD;
1176 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
1180 const gchar *def_cmd;
1186 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
1188 } else if (MIME_IMAGE == partinfo->mime_type) {
1189 cmd = prefs_common.mime_image_viewer;
1190 def_cmd = default_image_cmdline;
1191 } else if (MIME_AUDIO == partinfo->mime_type) {
1192 cmd = prefs_common.mime_audio_player;
1193 def_cmd = default_audio_cmdline;
1194 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
1195 cmd = prefs_common.uri_cmd;
1196 def_cmd = default_html_cmdline;
1198 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
1199 partinfo->content_type, "%s");
1204 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
1205 !strchr(p + 2, '%'))
1206 g_snprintf(buf, sizeof(buf), cmd, filename);
1209 g_warning("MIME viewer command line is invalid: `%s'", cmd);
1211 g_snprintf(buf, sizeof(buf), def_cmd, filename);
1216 execute_command_line(buf, TRUE);
1220 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
1226 partinfo = gtk_ctree_node_get_row_data(ctree, node);
1227 g_return_if_fail(partinfo != NULL);
1229 part_name = get_part_name(partinfo);
1230 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
1233 static void mimeview_update_names(MimeView *mimeview)
1235 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
1237 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
1240 static void mimeview_update_signature_info(MimeView *mimeview)
1244 if (!mimeview) return;
1245 if (!mimeview->opened) return;
1247 partinfo = mimeview_get_selected_part(mimeview);
1248 if (!partinfo) return;
1250 if (g_strcasecmp(partinfo->content_type,
1251 "application/pgp-signature") == 0) {
1252 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
1253 textview_show_signature_part(mimeview->textview, partinfo);
1257 void mimeview_check_signature(MimeView *mimeview)
1262 g_return_if_fail (mimeview_is_signed(mimeview));
1263 g_return_if_fail (gpg_started);
1265 mimeinfo = gtk_ctree_node_get_row_data
1266 (GTK_CTREE(mimeview->ctree), mimeview->opened);
1267 g_return_if_fail(mimeinfo != NULL);
1268 g_return_if_fail(mimeview->file != NULL);
1270 while (mimeinfo->parent)
1271 mimeinfo = mimeinfo->parent;
1273 if ((fp = fopen(mimeview->file, "rb")) == NULL) {
1274 FILE_OP_ERROR(mimeview->file, "fopen");
1278 rfc2015_check_signature(mimeinfo, fp);
1281 mimeview_update_names(mimeview);
1282 mimeview_update_signature_info(mimeview);
1284 textview_show_message(mimeview->messageview->textview, mimeinfo,
1287 mimeview_update(mimeview);
1289 #endif /* USE_GPGME */
1291 void mimeview_register_viewer_factory(MimeViewerFactory *factory)
1293 mimeviewer_factories = g_slist_append(mimeviewer_factories, factory);
1296 static gint cmp_viewer_by_factroy(gconstpointer a, gconstpointer b)
1298 return ((MimeViewer *) a)->factory == (MimeViewerFactory *) b ? 0 : -1;
1301 void mimeview_unregister_viewer_factory(MimeViewerFactory *factory)
1303 GSList *mimeview_list, *viewer_list;
1305 for (mimeview_list = mimeviews; mimeview_list != NULL; mimeview_list = g_slist_next(mimeview_list)) {
1306 MimeView *mimeview = (MimeView *) mimeview_list->data;
1308 if (mimeview->mimeviewer && mimeview->mimeviewer->factory == factory) {
1309 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
1310 mimeview->mimeviewer = NULL;
1313 while ((viewer_list = g_slist_find_custom(mimeview->viewers, factory, cmp_viewer_by_factroy)) != NULL) {
1314 MimeViewer *mimeviewer = (MimeViewer *) viewer_list->data;
1316 mimeviewer->destroy_viewer(mimeviewer);
1317 mimeview->viewers = g_slist_remove(mimeview->viewers, mimeviewer);
1321 mimeviewer_factories = g_slist_remove(mimeviewer_factories, factory);
1324 static gboolean icon_clicked_cb (GtkWidget *button, GdkEventButton *event, MimeView *mimeview)
1329 num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(button), "icon_number"));
1330 partinfo = gtk_object_get_data(GTK_OBJECT(button), "partinfo");
1331 if (event->button == 1) {
1332 icon_selected(mimeview, num, partinfo);
1333 gtk_widget_grab_focus(button);
1335 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
1336 toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
1338 gtk_signal_emit_stop_by_name(GTK_OBJECT(button), "button_press_event");
1341 part_button_pressed(mimeview, event, partinfo);
1346 static void icon_selected (MimeView *mimeview, gint num, MimeInfo *partinfo)
1348 if (num == 1 && (partinfo->mime_type == MIME_TEXT ||
1349 partinfo->mime_type == MIME_TEXT_HTML)) {
1350 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0);
1351 /* don't set the ctree, as it will unload the plugin, and
1352 * we want to be able to switch quickly between the text
1353 * part and the attachment */
1356 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 1);
1357 node = gtk_ctree_find_by_row_data(GTK_CTREE(mimeview->ctree), NULL, partinfo);
1359 gtk_ctree_select(GTK_CTREE(mimeview->ctree), node);
1363 #undef KEY_PRESS_EVENT_STOP
1364 #define KEY_PRESS_EVENT_STOP() \
1365 if (gtk_signal_n_emissions_by_name \
1366 (GTK_OBJECT(button), "key_press_event") > 0) { \
1367 gtk_signal_emit_stop_by_name(GTK_OBJECT(button), \
1368 "key_press_event"); \
1370 static gint icon_key_pressed(GtkWidget *button, GdkEventKey *event,
1375 SummaryView *summaryview;
1378 num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(button), "icon_number"));
1379 partinfo = gtk_object_get_data(GTK_OBJECT(button), "partinfo");
1381 if (!event) return FALSE;
1383 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(mimeview->notebook)) == 0)
1384 textview = mimeview->messageview->textview;
1386 textview = mimeview->textview;
1388 switch (event->keyval) {
1390 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
1391 /* stop the button being untoggled */
1392 KEY_PRESS_EVENT_STOP();
1393 if (textview_scroll_page(textview, FALSE))
1396 if (icon_list_select_by_number(mimeview, num + 1))
1399 icon_selected(mimeview, num, partinfo);
1400 toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
1406 textview_scroll_page(textview, TRUE);
1409 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
1410 KEY_PRESS_EVENT_STOP();
1411 textview_scroll_one_line(textview,
1412 (event->state & GDK_MOD1_MASK) != 0);
1415 icon_selected(mimeview, num, partinfo);
1416 toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
1422 BREAK_ON_MODIFIER_KEY();
1423 if (icon_list_select_by_number(mimeview, num + 1))
1424 KEY_PRESS_EVENT_STOP();
1430 BREAK_ON_MODIFIER_KEY();
1431 if (icon_list_select_by_number(mimeview, num - 1))
1432 KEY_PRESS_EVENT_STOP();
1437 BREAK_ON_MODIFIER_KEY();
1438 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(mimeview->notebook)) == 0)
1440 KEY_PRESS_EVENT_STOP();
1441 mimeview_save_as(mimeview);
1444 BREAK_ON_MODIFIER_KEY();
1445 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(mimeview->notebook)) == 0)
1447 KEY_PRESS_EVENT_STOP();
1448 mimeview_display_as_text(mimeview);
1451 BREAK_ON_MODIFIER_KEY();
1452 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(mimeview->notebook)) == 0)
1454 KEY_PRESS_EVENT_STOP();
1455 mimeview_launch(mimeview);
1461 if (!mimeview->messageview->mainwin) return FALSE;
1462 summaryview = mimeview->messageview->mainwin->summaryview;
1463 summary_pass_key_press_event(summaryview, event);
1467 static void toggle_icon(GtkToggleButton *button, MimeView *mimeview)
1471 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1472 for (; child != NULL; child = g_list_next(child)) {
1473 if (GTK_IS_TOGGLE_BUTTON(child->data) &&
1474 GTK_TOGGLE_BUTTON(child->data) != button &&
1475 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(child->data)))
1476 gtk_toggle_button_set_active
1477 (GTK_TOGGLE_BUTTON(child->data),
1482 static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
1491 vbox = mimeview->icon_vbox;
1492 mimeview->icon_count++;
1493 button = gtk_toggle_button_new();
1494 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1495 gtk_object_set_data(GTK_OBJECT(button), "icon_number",
1496 GINT_TO_POINTER(mimeview->icon_count));
1497 gtk_object_set_data(GTK_OBJECT(button), "partinfo",
1500 switch (mimeinfo->mime_type) {
1503 case MIME_MESSAGE_RFC822:
1504 stockp = STOCK_PIXMAP_MIME_TEXT_PLAIN;
1506 case MIME_TEXT_HTML:
1507 stockp = STOCK_PIXMAP_MIME_TEXT_HTML;
1509 case MIME_APPLICATION:
1511 if (mimeinfo->content_type
1512 && g_strcasecmp(mimeinfo->content_type,
1513 "application/pgp-signature") == 0) {
1514 if (mimeinfo->sigstatus_full) {
1515 desc = mimeinfo->sigstatus;
1516 if (mimeinfo->sig_ok)
1517 stockp = STOCK_PIXMAP_MIME_GPG_PASSED;
1518 else if (mimeinfo->sig_unknown)
1519 stockp = STOCK_PIXMAP_MIME_GPG_UNKNOWN;
1520 else if (mimeinfo->sig_expired
1521 || mimeinfo->key_expired)
1522 stockp = STOCK_PIXMAP_MIME_GPG_EXPIRED;
1524 stockp = STOCK_PIXMAP_MIME_GPG_FAILED;
1526 stockp = STOCK_PIXMAP_MIME_GPG_SIGNED;
1529 stockp = STOCK_PIXMAP_MIME_APPLICATION;
1531 case MIME_APPLICATION_OCTET_STREAM:
1532 stockp = STOCK_PIXMAP_MIME_APPLICATION_OCTET_STREAM;
1535 stockp = STOCK_PIXMAP_MIME_IMAGE;
1538 stockp = STOCK_PIXMAP_MIME_AUDIO;
1540 case MIME_TEXT_ENRICHED:
1541 stockp = STOCK_PIXMAP_MIME_TEXT_ENRICHED;
1544 stockp = STOCK_PIXMAP_MIME_UNKNOWN;
1548 pixmap = stock_pixmap_widget(mimeview->mainwin->window, stockp);
1549 gtk_container_add(GTK_CONTAINER(button), pixmap);
1552 if (prefs_common.attach_desc)
1553 desc = get_part_description(mimeinfo);
1555 desc = get_part_name(mimeinfo);
1558 tip = g_strdup_printf("%s\n%s\n%s", desc, mimeinfo->content_type,
1559 to_human_readable(mimeinfo->size));
1561 tip = g_strdup_printf("%s\n%s", mimeinfo->content_type,
1562 to_human_readable(mimeinfo->size));
1564 gtk_tooltips_set_tip(mimeview->tooltips, button, tip, NULL);
1566 gtk_widget_show_all(button);
1567 gtk_signal_connect(GTK_OBJECT(button), "button_press_event",
1568 GTK_SIGNAL_FUNC(icon_clicked_cb), mimeview);
1569 gtk_signal_connect(GTK_OBJECT(button), "key_press_event",
1570 GTK_SIGNAL_FUNC(icon_key_pressed), mimeview);
1571 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
1575 static void icon_list_clear (MimeView *mimeview)
1580 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1581 for (; child != NULL; child = g_list_next(child)) {
1582 gtkut_container_remove(GTK_CONTAINER(mimeview->icon_vbox),
1583 GTK_WIDGET(child->data));
1585 mimeview->icon_count = 0;
1586 adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
1587 adj->value = adj->lower;
1588 gtk_signal_emit_by_name(GTK_OBJECT (adj), "value_changed");
1591 static void icon_list_toggle_by_mime_info(MimeView *mimeview,
1596 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1597 for (; child != NULL; child = g_list_next(child)) {
1598 if (GTK_IS_TOGGLE_BUTTON(child->data) &&
1599 gtk_object_get_data(GTK_OBJECT(child->data),
1600 "partinfo") == (gpointer)mimeinfo) {
1601 toggle_icon(GTK_TOGGLE_BUTTON(child->data), mimeview);
1602 gtk_toggle_button_set_active
1603 (GTK_TOGGLE_BUTTON(child->data), TRUE);
1609 *\brief Used to 'click' the next or previous icon.
1611 *\return true if the icon 'number' exists and was selected.
1613 static gboolean icon_list_select_by_number(MimeView *mimeview,
1618 if (number == 0) return FALSE;
1619 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1620 for (; child != NULL; child = g_list_next(child)) {
1621 if (GTK_IS_TOGGLE_BUTTON(child->data) &&
1622 GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(child->data),
1623 "icon_number")) == number) {
1624 icon_selected(mimeview, number,
1625 (MimeInfo*)gtk_object_get_data(GTK_OBJECT(child->data),
1627 toggle_icon(GTK_TOGGLE_BUTTON(child->data), mimeview);
1628 gtk_toggle_button_set_active
1629 (GTK_TOGGLE_BUTTON(child->data), TRUE);
1630 gtk_widget_grab_focus(GTK_WIDGET(child->data));
1638 static void icon_scroll_size_allocate_cb(GtkWidget *widget,
1639 GtkAllocation *size, MimeView *mimeview)
1641 GtkAllocation *mainbox_size;
1642 GtkAllocation *vbox_size;
1643 GtkAllocation *layout_size;
1646 adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
1648 mainbox_size = &mimeview->icon_mainbox->allocation;
1649 vbox_size = &mimeview->icon_vbox->allocation;
1650 layout_size = &mimeview->icon_scroll->allocation;
1652 /* centralise the vbox */
1653 gtk_layout_move(GTK_LAYOUT(mimeview->icon_scroll), mimeview->icon_vbox,
1654 (mainbox_size->width - vbox_size->width)/2, 0);
1656 gtk_layout_set_size(GTK_LAYOUT(mimeview->icon_scroll),
1657 GTK_LAYOUT(mimeview->icon_scroll)->width,
1658 MAX(vbox_size->height, layout_size->height));
1659 adj->step_increment = 5;
1662 static void icon_list_create(MimeView *mimeview, MimeInfo *mimeinfo)
1664 GtkRequisition size;
1666 g_return_if_fail(mimeinfo != NULL);
1668 if (mimeinfo->children)
1669 mimeinfo = mimeinfo->children;
1671 while (mimeinfo != NULL) {
1672 if (mimeinfo->children)
1673 icon_list_create(mimeview, mimeinfo);
1674 else if (mimeinfo->sub &&
1675 mimeinfo->sub->mime_type != MIME_TEXT &&
1676 mimeinfo->sub->mime_type != MIME_TEXT_HTML)
1677 icon_list_create(mimeview, mimeinfo->sub);
1679 icon_list_append_icon(mimeview, mimeinfo);
1680 mimeinfo = mimeinfo->next;
1682 gtk_widget_size_request(mimeview->icon_vbox, &size);
1683 width = size.width + 4;
1684 if (width > mimeview->icon_mainbox->requisition.width) {
1685 gtk_widget_set_usize(mimeview->icon_mainbox,
1691 static void mime_toggle_button_cb (GtkWidget *button, MimeView *mimeview)
1693 gtk_widget_ref(button);
1695 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
1696 gtk_arrow_set(GTK_ARROW(GTK_BIN(button)->child), GTK_ARROW_RIGHT,
1698 gtk_widget_hide(mimeview->icon_mainbox);
1699 gtk_widget_show(mimeview->ctree_mainbox);
1700 gtk_paned_set_position(GTK_PANED(mimeview->paned), mimeview->oldsize);
1702 gtkut_container_remove(GTK_CONTAINER(mimeview->icon_mainbox),
1704 gtk_box_pack_end(GTK_BOX(mimeview->ctree_mainbox),
1705 button, FALSE, FALSE, 0);
1706 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 1);
1708 gtk_arrow_set(GTK_ARROW(GTK_BIN(button)->child), GTK_ARROW_LEFT,
1710 mimeview->oldsize = mimeview->ctree_mainbox->allocation.height;
1711 gtk_widget_hide(mimeview->ctree_mainbox);
1712 gtk_widget_show(mimeview->icon_mainbox);
1713 gtk_paned_set_position(GTK_PANED(mimeview->paned), 0);
1715 gtkut_container_remove(GTK_CONTAINER(mimeview->ctree_mainbox),
1717 gtk_box_pack_start(GTK_BOX(mimeview->icon_mainbox),
1718 button, FALSE, FALSE, 0);
1719 gtk_box_reorder_child(GTK_BOX(button->parent), button, 0);
1720 if (mimeview->opened)
1721 icon_list_toggle_by_mime_info
1722 (mimeview, gtk_ctree_node_get_row_data(GTK_CTREE(mimeview->ctree),
1726 gtk_widget_grab_focus(button);
1727 gtk_widget_unref(button);
1731 void mimeview_update (MimeView *mimeview) {
1732 if (mimeview && mimeview->mimeinfo) {
1733 icon_list_clear(mimeview);
1734 icon_list_create(mimeview, mimeview->mimeinfo);