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 void mime_toggle_button_cb (GtkWidget *button,
139 static void part_button_pressed (MimeView *mimeview,
140 GdkEventButton *event,
142 static void icon_scroll_size_allocate_cb(GtkWidget *widget,
143 GtkAllocation *layout_size,
146 static GtkItemFactoryEntry mimeview_popup_entries[] =
148 {N_("/_Open"), NULL, mimeview_launch, 0, NULL},
149 {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
150 {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
151 {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL},
152 {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL}
155 {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
159 static GtkTargetEntry mimeview_mime_types[] =
161 {"text/uri-list", 0, 0}
164 GSList *mimeviewer_factories;
167 MimeView *mimeview_create(MainWindow *mainwin)
174 GtkWidget *scrolledwin;
176 GtkWidget *mime_notebook;
177 GtkWidget *popupmenu;
178 GtkWidget *ctree_mainbox;
179 GtkWidget *mime_toggle;
180 GtkWidget *icon_mainbox;
181 GtkWidget *icon_scroll;
182 GtkWidget *icon_vbox;
184 GtkWidget *scrollbutton;
186 GtkTooltips *tooltips;
187 GtkItemFactory *popupfactory;
188 gchar *titles[N_MIMEVIEW_COLS];
192 debug_print("Creating MIME view...\n");
193 mimeview = g_new0(MimeView, 1);
195 titles[COL_MIMETYPE] = _("MIME Type");
196 titles[COL_SIZE] = _("Size");
197 titles[COL_NAME] = _("Name");
199 notebook = gtk_notebook_new();
200 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
201 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
202 gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
204 vbox = gtk_vbox_new(FALSE, 0);
205 gtk_container_add(GTK_CONTAINER(notebook), vbox);
207 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
208 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
209 GTK_POLICY_AUTOMATIC,
212 ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
213 gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
214 gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
215 gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
217 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
218 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 90);
219 for (i = 0; i < N_MIMEVIEW_COLS; i++)
220 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
222 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
224 gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
225 GTK_SIGNAL_FUNC(mimeview_selected), mimeview);
226 gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
227 GTK_SIGNAL_FUNC(mimeview_button_pressed), mimeview);
228 gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
229 GTK_SIGNAL_FUNC(mimeview_key_pressed), mimeview);
230 gtk_signal_connect(GTK_OBJECT (ctree),"start_drag",
231 GTK_SIGNAL_FUNC (mimeview_start_drag), mimeview);
232 gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_get",
233 GTK_SIGNAL_FUNC(mimeview_drag_data_get), mimeview);
235 mime_notebook = gtk_notebook_new();
236 gtk_widget_show(mime_notebook);
237 GTK_WIDGET_UNSET_FLAGS(mime_notebook, GTK_CAN_FOCUS);
238 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(mime_notebook), FALSE);
239 gtk_notebook_set_show_border(GTK_NOTEBOOK(mime_notebook), FALSE);
241 gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 0);
243 icon_vbox = gtk_vbox_new(FALSE,0);
244 icon_scroll = gtk_layout_new(NULL, NULL);
245 gtk_layout_put(GTK_LAYOUT(icon_scroll), icon_vbox, 0, 0);
246 scrollbutton = gtk_vscrollbutton_new(gtk_layout_get_vadjustment(GTK_LAYOUT(icon_scroll)));
248 mime_toggle = gtk_toggle_button_new();
249 arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
250 gtk_widget_show(arrow);
251 gtk_container_add(GTK_CONTAINER(mime_toggle), arrow);
252 gtk_signal_connect(GTK_OBJECT(mime_toggle), "toggled",
253 GTK_SIGNAL_FUNC(mime_toggle_button_cb), mimeview);
255 icon_mainbox = gtk_vbox_new(FALSE, 0);
256 gtk_box_pack_start(GTK_BOX(icon_mainbox), mime_toggle, FALSE, FALSE, 0);
257 gtk_box_pack_start(GTK_BOX(icon_mainbox), icon_scroll, TRUE, TRUE, 3);
258 gtk_box_pack_end(GTK_BOX(icon_mainbox), scrollbutton, FALSE, FALSE, 0);
259 gtk_signal_connect(GTK_OBJECT(icon_mainbox), "size_allocate",
260 GTK_SIGNAL_FUNC(icon_scroll_size_allocate_cb), mimeview);
262 ctree_mainbox = gtk_hbox_new(FALSE, 0);
263 gtk_box_pack_start(GTK_BOX(ctree_mainbox), scrolledwin, TRUE, TRUE, 0);
265 n_entries = sizeof(mimeview_popup_entries) /
266 sizeof(mimeview_popup_entries[0]);
267 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
268 "<MimeView>", &popupfactory, mimeview);
269 tooltips = gtk_tooltips_new();
270 gtk_tooltips_set_delay(tooltips, 0);
272 paned = gtk_vpaned_new();
273 gtk_paned_set_gutter_size(GTK_PANED(paned), 6);
274 gtk_paned_pack1(GTK_PANED(paned), ctree_mainbox, FALSE, TRUE);
275 gtk_paned_pack2(GTK_PANED(paned), mime_notebook, TRUE, TRUE);
276 gtk_container_add(GTK_CONTAINER(notebook), paned);
278 hbox = gtk_hbox_new(FALSE, 0);
279 gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 0);
280 gtk_box_pack_start(GTK_BOX(hbox), icon_mainbox, FALSE, FALSE, 0);
282 gtk_widget_show_all(hbox);
283 gtk_widget_hide(ctree_mainbox);
285 mimeview->notebook = notebook;
286 mimeview->vbox = vbox;
287 mimeview->hbox = hbox;
288 mimeview->paned = paned;
289 mimeview->scrolledwin = scrolledwin;
290 mimeview->ctree = ctree;
291 mimeview->mime_notebook = mime_notebook;
292 mimeview->popupmenu = popupmenu;
293 mimeview->popupfactory = popupfactory;
295 mimeview->ctree_mainbox = ctree_mainbox;
296 mimeview->icon_scroll = icon_scroll;
297 mimeview->icon_vbox = icon_vbox;
298 mimeview->icon_mainbox = icon_mainbox;
299 mimeview->icon_count = 0;
300 mimeview->mainwin = mainwin;
301 mimeview->tooltips = tooltips;
302 mimeview->oldsize = 60;
303 mimeview->mime_toggle = mime_toggle;
304 mimeview->scroll_button = scrollbutton;
306 mimeview->target_list = gtk_target_list_new(mimeview_mime_types, 1);
308 mimeviews = g_slist_prepend(mimeviews, mimeview);
313 void mimeview_init(MimeView *mimeview)
315 textview_init(mimeview->textview);
317 gtk_container_add(GTK_CONTAINER(mimeview->mime_notebook),
318 GTK_WIDGET_PTR(mimeview->textview));
322 * Check whether the message is OpenPGP signed
325 static gboolean mimeview_is_signed(MimeView *mimeview)
327 MimeInfo *partinfo = NULL;
329 debug_print("mimeview_is signed of %p\n", mimeview);
331 if (!mimeview) return FALSE;
332 if (!mimeview->opened) return FALSE;
334 debug_print("mimeview_is_signed: open\n" );
336 if (!mimeview->file) return FALSE;
338 debug_print("mimeview_is_signed: file\n" );
340 partinfo = gtk_ctree_node_get_row_data
341 (GTK_CTREE(mimeview->ctree), mimeview->opened);
342 g_return_val_if_fail(partinfo != NULL, FALSE);
344 /* walk the tree and see whether there is a signature somewhere */
346 if (rfc2015_has_signature(partinfo))
348 } while ((partinfo = partinfo->parent) != NULL);
350 debug_print("mimeview_is_signed: FALSE\n" );
355 static void set_unchecked_signature(MimeInfo *mimeinfo)
357 MimeInfo *sig_partinfo;
359 sig_partinfo = rfc2015_find_signature(mimeinfo);
360 if (sig_partinfo == NULL) return;
362 g_free(sig_partinfo->sigstatus);
363 sig_partinfo->sigstatus =
364 g_strdup(_("Right-click here to verify the signature"));
366 g_free(sig_partinfo->sigstatus_full);
367 sig_partinfo->sigstatus_full = NULL;
369 #endif /* USE_GPGME */
371 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
374 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
378 mimeview_clear(mimeview);
379 textview_clear(mimeview->messageview->textview);
381 g_return_if_fail(file != NULL);
382 g_return_if_fail(mimeinfo != NULL);
384 mimeview->mimeinfo = mimeinfo;
386 mimeview->file = g_strdup(file);
389 if (prefs_common.auto_check_signatures && gpg_started) {
390 if ((fp = fopen(file, "rb")) == NULL) {
391 FILE_OP_ERROR(file, "fopen");
394 rfc2015_check_signature(mimeinfo, fp);
397 set_unchecked_signature(mimeinfo);
400 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
403 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
404 icon_list_create(mimeview, mimeinfo);
406 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
407 mimeview_selected, mimeview);
409 /* search first text part */
410 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
411 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
414 partinfo = gtk_ctree_node_get_row_data(ctree, node);
416 (partinfo->mime_type == MIME_TEXT ||
417 partinfo->mime_type == MIME_TEXT_HTML))
420 textview_show_message(mimeview->messageview->textview, mimeinfo, file);
423 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
426 gtk_ctree_select(ctree, node);
427 icon_list_toggle_by_mime_info
428 (mimeview, gtk_ctree_node_get_row_data(ctree, node));
429 gtkut_ctree_set_focus_row(ctree, node);
430 gtk_widget_grab_focus(mimeview->ctree);
434 void mimeview_destroy(MimeView *mimeview)
438 for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
439 MimeViewer *viewer = (MimeViewer *) cur->data;
440 gtk_container_remove(GTK_CONTAINER(mimeview->mime_notebook),
441 GTK_WIDGET(viewer->get_widget(viewer)));
442 viewer->destroy_viewer(viewer);
444 g_slist_free(mimeview->viewers);
445 gtk_target_list_unref(mimeview->target_list);
447 procmime_mimeinfo_free_all(mimeview->mimeinfo);
448 g_free(mimeview->file);
451 mimeviews = g_slist_remove(mimeviews, mimeview);
455 MimeInfo *mimeview_get_selected_part(MimeView *mimeview)
457 if (gtk_notebook_get_current_page
458 (GTK_NOTEBOOK(mimeview->notebook)) == 0)
461 return gtk_ctree_node_get_row_data
462 (GTK_CTREE(mimeview->ctree), mimeview->opened);
465 static void mimeview_set_multipart_tree(MimeView *mimeview,
467 GtkCTreeNode *parent)
471 g_return_if_fail(mimeinfo != NULL);
473 if (mimeinfo->children)
474 mimeinfo = mimeinfo->children;
476 while (mimeinfo != NULL) {
477 node = mimeview_append_part(mimeview, mimeinfo, parent);
479 if (mimeinfo->children)
480 mimeview_set_multipart_tree(mimeview, mimeinfo, node);
481 else if (mimeinfo->sub &&
482 mimeinfo->sub->mime_type != MIME_TEXT &&
483 mimeinfo->sub->mime_type != MIME_TEXT_HTML)
484 mimeview_set_multipart_tree(mimeview, mimeinfo->sub,
486 mimeinfo = mimeinfo->next;
490 static gchar *get_part_name(MimeInfo *partinfo)
493 if (partinfo->sigstatus)
494 return partinfo->sigstatus;
498 return partinfo->name;
499 else if (partinfo->filename)
500 return partinfo->filename;
501 else if (partinfo->description)
502 return partinfo->description;
507 static gchar *get_part_description(MimeInfo *partinfo)
509 if (partinfo->description)
510 return partinfo->description;
511 else if (partinfo->name)
512 return partinfo->name;
513 else if (partinfo->filename)
514 return partinfo->filename;
519 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
521 GtkCTreeNode *parent)
523 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
525 gchar *str[N_MIMEVIEW_COLS];
528 partinfo->content_type ? partinfo->content_type : "";
529 str[COL_SIZE] = to_human_readable(partinfo->size);
530 if (prefs_common.attach_desc)
531 str[COL_NAME] = get_part_description(partinfo);
533 str[COL_NAME] = get_part_name(partinfo);
535 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
536 NULL, NULL, NULL, NULL,
538 gtk_ctree_node_set_row_data(ctree, node, partinfo);
543 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
551 if (!partinfo) return;
554 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
556 fname = pi ? pi->plaintextfile : mimeview->file;
558 fname = mimeview->file;
559 #endif /* USE_GPGME */
562 if ((fp = fopen(fname, "rb")) == NULL) {
563 FILE_OP_ERROR(fname, "fopen");
567 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
568 FILE_OP_ERROR(mimeview->file, "fseek");
573 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
574 textview_show_part(mimeview->textview, partinfo, fp);
579 static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *content_type)
582 MimeViewerFactory *factory = NULL;
583 MimeViewer *viewer = NULL;
586 * FNM_CASEFOLD is a GNU extension
587 * if its not defined copy the string to the stack and
588 * convert the copy to lower case
591 #define FNM_CASEFOLD 0
592 Xstrdup_a(content_type, content_type, return NULL);
593 g_strdown((gchar *)content_type);
596 for (cur = mimeviewer_factories; cur != NULL; cur = g_slist_next(cur)) {
597 MimeViewerFactory *curfactory = cur->data;
600 while (curfactory->content_types[i] != NULL) {
601 debug_print("%s\n", curfactory->content_types[i]);
602 if(!fnmatch(curfactory->content_types[i], content_type, FNM_CASEFOLD)) {
603 factory = curfactory;
614 for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
615 MimeViewer *curviewer = cur->data;
617 if (curviewer->factory == factory)
620 viewer = factory->create_viewer();
621 gtk_container_add(GTK_CONTAINER(mimeview->mime_notebook),
622 GTK_WIDGET(viewer->get_widget(viewer)));
624 mimeview->viewers = g_slist_append(mimeview->viewers, viewer);
629 static MimeViewer *get_viewer_for_mimeinfo(MimeView *mimeview, MimeInfo *partinfo)
631 gchar *content_type = NULL;
632 MimeViewer *viewer = NULL;
634 if ((partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM) &&
635 (partinfo->name != NULL)) {
636 content_type = procmime_get_mime_type(partinfo->name);
638 content_type = g_strdup(partinfo->content_type);
641 if (content_type != NULL) {
642 viewer = get_viewer_for_content_type(mimeview, content_type);
643 g_free(content_type);
649 static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
653 viewer = get_viewer_for_mimeinfo(mimeview, partinfo);
654 if (viewer == NULL) {
655 if (mimeview->mimeviewer != NULL)
656 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
657 mimeview->mimeviewer = NULL;
661 if (mimeview->mimeviewer != viewer) {
662 if (mimeview->mimeviewer != NULL)
663 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
664 mimeview->mimeviewer = viewer;
665 mimeview_change_view_type(mimeview, MIMEVIEW_VIEWER);
667 viewer->show_mimepart(viewer, mimeview->file, partinfo);
672 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
674 TextView *textview = mimeview->textview;
676 if ((mimeview->type != MIMEVIEW_VIEWER) &&
677 (mimeview->type == type)) return;
681 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
682 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
683 GTK_WIDGET_PTR(textview)));
685 case MIMEVIEW_VIEWER:
686 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->mime_notebook),
687 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview->mime_notebook),
688 GTK_WIDGET(mimeview->mimeviewer->get_widget(mimeview->mimeviewer))));
694 mimeview->type = type;
697 static void mimeview_clear(MimeView *mimeview)
699 GtkCList *clist = GTK_CLIST(mimeview->ctree);
701 procmime_mimeinfo_free_all(mimeview->mimeinfo);
702 mimeview->mimeinfo = NULL;
704 gtk_clist_clear(clist);
705 textview_clear(mimeview->textview);
706 if (mimeview->mimeviewer != NULL)
707 mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
709 mimeview->opened = NULL;
711 g_free(mimeview->file);
712 mimeview->file = NULL;
714 gtk_vscrollbutton_reset(GTK_VSCROLLBUTTON(mimeview->scroll_button));
715 icon_list_clear(mimeview);
717 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mimeview->mime_toggle)))
718 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0);
721 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
726 if (mimeview->opened == node) return;
727 mimeview->opened = node;
728 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
730 partinfo = gtk_ctree_node_get_row_data(ctree, node);
731 if (!partinfo) return;
733 /* ungrab the mouse event */
734 if (GTK_WIDGET_HAS_GRAB(ctree)) {
735 gtk_grab_remove(GTK_WIDGET(ctree));
736 if (gdk_pointer_is_grabbed())
737 gdk_pointer_ungrab(GDK_CURRENT_TIME);
740 mimeview->textview->default_text = FALSE;
742 if (!mimeview_show_part(mimeview, partinfo)) {
743 switch (partinfo->mime_type) {
746 case MIME_TEXT_ENRICHED:
747 case MIME_MESSAGE_RFC822:
749 mimeview_show_message_part(mimeview, partinfo);
753 mimeview->textview->default_text = TRUE;
754 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
756 if (g_strcasecmp(partinfo->content_type,
757 "application/pgp-signature") == 0)
758 textview_show_signature_part(mimeview->textview,
762 textview_show_mime_part(mimeview->textview, partinfo);
768 static void mimeview_start_drag(GtkWidget *widget, gint button,
769 GdkEvent *event, MimeView *mimeview)
771 GdkDragContext *context;
774 g_return_if_fail(mimeview != NULL);
776 partinfo = mimeview_get_selected_part(mimeview);
777 if (partinfo->filename == NULL && partinfo->name == NULL) return;
779 context = gtk_drag_begin(widget, mimeview->target_list,
780 GDK_ACTION_COPY, button, event);
781 gtk_drag_set_icon_default(context);
784 static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
787 GtkCList *clist = GTK_CLIST(widget);
790 if (!event) return FALSE;
792 if (event->button == 2 || event->button == 3) {
793 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
796 gtk_clist_unselect_all(clist);
797 gtk_clist_select_row(clist, row, column);
798 gtkut_clist_set_focus_row(clist, row);
800 part_button_pressed(mimeview, event, mimeview_get_selected_part(mimeview));
805 static void part_button_pressed(MimeView *mimeview, GdkEventButton *event,
808 if (event->button == 2 ||
809 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
810 /* call external program for image, audio or html */
811 mimeview_launch(mimeview);
812 } else if (event->button == 3) {
813 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
814 partinfo->mime_type == MIME_TEXT_HTML ||
815 partinfo->mime_type == MIME_TEXT_ENRICHED ||
816 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
817 partinfo->mime_type == MIME_IMAGE ||
818 partinfo->mime_type == MIME_MULTIPART))
819 menu_set_sensitive(mimeview->popupfactory,
820 "/Display as text", FALSE);
822 menu_set_sensitive(mimeview->popupfactory,
823 "/Display as text", TRUE);
825 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
826 menu_set_sensitive(mimeview->popupfactory,
829 menu_set_sensitive(mimeview->popupfactory,
833 menu_set_sensitive(mimeview->popupfactory,
835 mimeview_is_signed(mimeview));
838 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
839 NULL, NULL, NULL, NULL,
840 event->button, event->time);
846 void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
848 mimeview_key_pressed(mimeview->ctree, event, mimeview);
851 #define BREAK_ON_MODIFIER_KEY() \
852 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
854 #define KEY_PRESS_EVENT_STOP() \
855 if (gtk_signal_n_emissions_by_name \
856 (GTK_OBJECT(ctree), "key_press_event") > 0) { \
857 gtk_signal_emit_stop_by_name(GTK_OBJECT(ctree), \
858 "key_press_event"); \
861 static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
864 SummaryView *summaryview;
865 GtkCTree *ctree = GTK_CTREE(widget);
868 if (!event) return FALSE;
869 if (!mimeview->opened) return FALSE;
871 switch (event->keyval) {
873 if (textview_scroll_page(mimeview->textview, FALSE))
876 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
878 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
879 gtk_sctree_select(GTK_SCTREE(ctree), node);
884 textview_scroll_page(mimeview->textview, TRUE);
887 textview_scroll_one_line(mimeview->textview,
888 (event->state & GDK_MOD1_MASK) != 0);
892 BREAK_ON_MODIFIER_KEY();
893 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
894 KEY_PRESS_EVENT_STOP();
896 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
897 GTK_SCROLL_STEP_FORWARD, 0.0);
901 BREAK_ON_MODIFIER_KEY();
902 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
903 KEY_PRESS_EVENT_STOP();
905 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
906 GTK_SCROLL_STEP_BACKWARD, 0.0);
909 BREAK_ON_MODIFIER_KEY();
910 KEY_PRESS_EVENT_STOP();
911 mimeview_save_as(mimeview);
914 BREAK_ON_MODIFIER_KEY();
915 KEY_PRESS_EVENT_STOP();
916 mimeview_display_as_text(mimeview);
919 BREAK_ON_MODIFIER_KEY();
920 KEY_PRESS_EVENT_STOP();
921 mimeview_launch(mimeview);
927 if (!mimeview->messageview->mainwin) return FALSE;
928 summaryview = mimeview->messageview->mainwin->summaryview;
929 summary_pass_key_press_event(summaryview, event);
933 static void mimeview_drag_data_get(GtkWidget *widget,
934 GdkDragContext *drag_context,
935 GtkSelectionData *selection_data,
940 gchar *filename, *uriname;
943 if (!mimeview->opened) return;
944 if (!mimeview->file) return;
946 partinfo = mimeview_get_selected_part(mimeview);
947 if (!partinfo) return;
948 if (!partinfo->filename && !partinfo->name) return;
950 filename = partinfo->filename ? partinfo->filename : partinfo->name;
951 filename = g_basename(filename);
952 if (*filename == '\0') return;
954 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
957 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
959 (_("Can't save the part of multipart message."));
961 uriname = g_strconcat("file:/", filename, NULL);
962 gtk_selection_data_set(selection_data, selection_data->target, 8,
963 uriname, strlen(uriname));
969 static void mimeview_save_all(MimeView *mimeview)
972 gchar *defname = NULL;
974 MimeInfo *attachment;
977 if (!mimeview->opened) return;
978 if (!mimeview->file) return;
980 partinfo = mimeview_get_selected_part(mimeview);
981 g_return_if_fail(partinfo != NULL);
983 dirname = filesel_select_file(_("Save as"), defname);
984 if (!dirname) return;
986 /* return to first children */
987 if (!partinfo->parent->children) return; /* multipart container? */
988 attachment = partinfo->parent->children->next;
989 /* for each attachment, extract it in the selected dir. */
990 while (attachment != NULL) {
991 static guint subst_cnt = 1;
993 gchar *attachname = g_strdup(get_part_name(attachment));
994 AlertValue aval = G_ALERTDEFAULT;
997 if (!attachname || !strlen(attachname))
998 attachname = g_strdup_printf("noname.%d",subst_cnt++);
999 subst_chars(attachname, ":?*&|<>\t\r\n", '_');
1000 g_snprintf(buf, sizeof(buf), "%s%s",
1002 (attachname[0] == G_DIR_SEPARATOR)
1005 subst_chars(buf, "/\\", G_DIR_SEPARATOR);
1006 attachdir = g_dirname(buf);
1007 make_dir_hier(attachdir);
1010 if (is_file_exist(buf)) {
1011 res = g_strdup_printf(_("Overwrite existing file '%s'?"),
1013 aval = alertpanel(_("Overwrite"), res, _("OK"),
1019 if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, mimeview->file, attachment) < 0))
1020 alertpanel_error(_("Can't save the part of multipart message."));
1021 attachment = attachment->next;
1025 static void mimeview_display_as_text(MimeView *mimeview)
1029 if (!mimeview->opened) return;
1031 partinfo = mimeview_get_selected_part(mimeview);
1032 g_return_if_fail(partinfo != NULL);
1033 mimeview_show_message_part(mimeview, partinfo);
1036 static void mimeview_save_as(MimeView *mimeview)
1039 gchar *defname = NULL;
1043 if (!mimeview->opened) return;
1044 if (!mimeview->file) return;
1046 partinfo = mimeview_get_selected_part(mimeview);
1047 g_return_if_fail(partinfo != NULL);
1049 if (partinfo->filename)
1050 defname = partinfo->filename;
1051 else if (partinfo->name) {
1052 Xstrdup_a(defname, partinfo->name, return);
1053 subst_for_filename(defname);
1056 filename = filesel_select_file(_("Save as"), defname);
1057 if (!filename) return;
1058 if (is_file_exist(filename)) {
1060 res = g_strdup_printf(_("Overwrite existing file '%s'?"),
1062 aval = alertpanel(_("Overwrite"), res, _("OK"),
1065 if (G_ALERTDEFAULT != aval) return;
1068 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
1070 (_("Can't save the part of multipart message."));
1073 static void mimeview_launch(MimeView *mimeview)
1078 if (!mimeview->opened) return;
1079 if (!mimeview->file) return;
1081 partinfo = mimeview_get_selected_part(mimeview);
1082 g_return_if_fail(partinfo != NULL);
1084 filename = procmime_get_tmp_file_name(partinfo);
1086 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
1088 (_("Can't save the part of multipart message."));
1090 mimeview_view_file(filename, partinfo, NULL);
1095 static void mimeview_open_with(MimeView *mimeview)
1101 if (!mimeview->opened) return;
1102 if (!mimeview->file) return;
1104 partinfo = mimeview_get_selected_part(mimeview);
1105 g_return_if_fail(partinfo != NULL);
1107 filename = procmime_get_tmp_file_name(partinfo);
1109 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
1111 (_("Can't save the part of multipart message."));
1116 if (!prefs_common.mime_open_cmd_history)
1117 prefs_common.mime_open_cmd_history =
1118 add_history(NULL, prefs_common.mime_open_cmd);
1120 cmd = input_dialog_combo
1122 _("Enter the command line to open file:\n"
1123 "(`%s' will be replaced with file name)"),
1124 prefs_common.mime_open_cmd,
1125 prefs_common.mime_open_cmd_history,
1128 mimeview_view_file(filename, partinfo, cmd);
1129 g_free(prefs_common.mime_open_cmd);
1130 prefs_common.mime_open_cmd = cmd;
1131 prefs_common.mime_open_cmd_history =
1132 add_history(prefs_common.mime_open_cmd_history, cmd);
1138 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
1139 const gchar *cmdline)
1141 static gchar *default_image_cmdline = "display '%s'";
1142 static gchar *default_audio_cmdline = "play '%s'";
1143 static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD;
1144 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
1148 const gchar *def_cmd;
1154 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
1156 } else if (MIME_IMAGE == partinfo->mime_type) {
1157 cmd = prefs_common.mime_image_viewer;
1158 def_cmd = default_image_cmdline;
1159 } else if (MIME_AUDIO == partinfo->mime_type) {
1160 cmd = prefs_common.mime_audio_player;
1161 def_cmd = default_audio_cmdline;
1162 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
1163 cmd = prefs_common.uri_cmd;
1164 def_cmd = default_html_cmdline;
1166 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
1167 partinfo->content_type, "%s");
1172 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
1173 !strchr(p + 2, '%'))
1174 g_snprintf(buf, sizeof(buf), cmd, filename);
1177 g_warning("MIME viewer command line is invalid: `%s'", cmd);
1179 g_snprintf(buf, sizeof(buf), def_cmd, filename);
1184 execute_command_line(buf, TRUE);
1188 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
1194 partinfo = gtk_ctree_node_get_row_data(ctree, node);
1195 g_return_if_fail(partinfo != NULL);
1197 part_name = get_part_name(partinfo);
1198 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
1201 static void mimeview_update_names(MimeView *mimeview)
1203 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
1205 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
1208 static void mimeview_update_signature_info(MimeView *mimeview)
1212 if (!mimeview) return;
1213 if (!mimeview->opened) return;
1215 partinfo = mimeview_get_selected_part(mimeview);
1216 if (!partinfo) return;
1218 if (g_strcasecmp(partinfo->content_type,
1219 "application/pgp-signature") == 0) {
1220 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
1221 textview_show_signature_part(mimeview->textview, partinfo);
1225 void mimeview_check_signature(MimeView *mimeview)
1230 g_return_if_fail (mimeview_is_signed(mimeview));
1231 g_return_if_fail (gpg_started);
1233 mimeinfo = gtk_ctree_node_get_row_data
1234 (GTK_CTREE(mimeview->ctree), mimeview->opened);
1235 g_return_if_fail(mimeinfo != NULL);
1236 g_return_if_fail(mimeview->file != NULL);
1238 while (mimeinfo->parent)
1239 mimeinfo = mimeinfo->parent;
1241 if ((fp = fopen(mimeview->file, "rb")) == NULL) {
1242 FILE_OP_ERROR(mimeview->file, "fopen");
1246 rfc2015_check_signature(mimeinfo, fp);
1249 mimeview_update_names(mimeview);
1250 mimeview_update_signature_info(mimeview);
1252 textview_show_message(mimeview->messageview->textview, mimeinfo,
1255 mimeview_update(mimeview);
1257 #endif /* USE_GPGME */
1259 void mimeview_register_viewer_factory(MimeViewerFactory *factory)
1261 mimeviewer_factories = g_slist_append(mimeviewer_factories, factory);
1264 static gint cmp_viewer_by_factroy(gconstpointer a, gconstpointer b)
1266 return ((MimeViewer *) a)->factory == (MimeViewerFactory *) b ? 0 : -1;
1269 void mimeview_unregister_viewer_factory(MimeViewerFactory *factory)
1271 GSList *mimeview_list, *viewer_list;
1273 for (mimeview_list = mimeviews; mimeview_list != NULL; mimeview_list = g_slist_next(mimeview_list)) {
1274 MimeView *mimeview = (MimeView *) mimeview_list->data;
1276 if (mimeview->mimeviewer && mimeview->mimeviewer->factory == factory) {
1277 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
1278 mimeview->mimeviewer = NULL;
1281 while ((viewer_list = g_slist_find_custom(mimeview->viewers, factory, cmp_viewer_by_factroy)) != NULL) {
1282 MimeViewer *mimeviewer = (MimeViewer *) viewer_list->data;
1284 mimeviewer->destroy_viewer(mimeviewer);
1285 mimeview->viewers = g_slist_remove(mimeview->viewers, mimeviewer);
1289 mimeviewer_factories = g_slist_remove(mimeviewer_factories, factory);
1292 static gboolean icon_clicked_cb (GtkWidget *button, GdkEventButton *event, MimeView *mimeview)
1297 num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(button), "icon_number"));
1298 partinfo = gtk_object_get_data(GTK_OBJECT(button), "partinfo");
1299 if (event->button == 1) {
1300 icon_selected(mimeview, num, partinfo);
1302 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
1303 toggle_icon(GTK_TOGGLE_BUTTON(button), mimeview);
1305 gtk_signal_emit_stop_by_name(GTK_OBJECT(button), "button_press_event");
1308 part_button_pressed(mimeview, event, partinfo);
1313 static void icon_selected (MimeView *mimeview, gint num, MimeInfo *partinfo)
1315 if (num == 1 && (partinfo->mime_type == MIME_TEXT ||
1316 partinfo->mime_type == MIME_TEXT_HTML)) {
1317 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0);
1318 /* don't set the ctree, as it will unload the plugin, and
1319 * we want to be able to switch quickly between the text
1320 * part and the attachment */
1323 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 1);
1324 node = gtk_ctree_find_by_row_data(GTK_CTREE(mimeview->ctree), NULL, partinfo);
1326 gtk_ctree_select(GTK_CTREE(mimeview->ctree), node);
1330 static gint icon_key_pressed(GtkWidget *button, GdkEventKey *event,
1336 num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(button), "icon_number"));
1337 partinfo = gtk_object_get_data(GTK_OBJECT(button), "partinfo");
1339 if (!event) return FALSE;
1341 switch (event->keyval) {
1343 icon_selected(mimeview, num, partinfo);
1352 static void toggle_icon(GtkToggleButton *button, MimeView *mimeview)
1356 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1357 for (; child != NULL; child = g_list_next(child)) {
1358 if (GTK_IS_TOGGLE_BUTTON(child->data) &&
1359 GTK_TOGGLE_BUTTON(child->data) != button &&
1360 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(child->data)))
1361 gtk_toggle_button_set_active
1362 (GTK_TOGGLE_BUTTON(child->data),
1367 static void icon_list_append_icon (MimeView *mimeview, MimeInfo *mimeinfo)
1377 vbox = mimeview->icon_vbox;
1378 mimeview->icon_count++;
1379 if (mimeview->icon_count > 1) {
1380 sep = gtk_hseparator_new();
1381 gtk_widget_show(sep);
1382 gtk_box_pack_start(GTK_BOX(vbox), sep, TRUE, TRUE, 3);
1384 button = gtk_toggle_button_new();
1385 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1386 gtk_object_set_data(GTK_OBJECT(button), "icon_number",
1387 GINT_TO_POINTER(mimeview->icon_count));
1388 gtk_object_set_data(GTK_OBJECT(button), "partinfo",
1391 switch (mimeinfo->mime_type) {
1394 case MIME_MESSAGE_RFC822:
1395 stockp = STOCK_PIXMAP_MIME_TEXT_PLAIN;
1397 case MIME_TEXT_HTML:
1398 stockp = STOCK_PIXMAP_MIME_TEXT_HTML;
1400 case MIME_APPLICATION:
1402 if (mimeinfo->content_type
1403 && g_strcasecmp(mimeinfo->content_type,
1404 "application/pgp-signature") == 0) {
1405 if (mimeinfo->sigstatus_full) {
1406 desc = mimeinfo->sigstatus;
1407 if (mimeinfo->sig_ok)
1408 stockp = STOCK_PIXMAP_MIME_GPG_PASSED;
1409 else if (mimeinfo->sig_unknown)
1410 stockp = STOCK_PIXMAP_MIME_GPG_UNKNOWN;
1411 else if (mimeinfo->sig_expired
1412 || mimeinfo->key_expired)
1413 stockp = STOCK_PIXMAP_MIME_GPG_EXPIRED;
1415 stockp = STOCK_PIXMAP_MIME_GPG_FAILED;
1417 stockp = STOCK_PIXMAP_MIME_GPG_SIGNED;
1420 stockp = STOCK_PIXMAP_MIME_APPLICATION;
1422 case MIME_APPLICATION_OCTET_STREAM:
1423 stockp = STOCK_PIXMAP_MIME_APPLICATION_OCTET_STREAM;
1426 stockp = STOCK_PIXMAP_MIME_IMAGE;
1429 stockp = STOCK_PIXMAP_MIME_AUDIO;
1431 case MIME_TEXT_ENRICHED:
1432 stockp = STOCK_PIXMAP_MIME_TEXT_ENRICHED;
1435 stockp = STOCK_PIXMAP_MIME_UNKNOWN;
1439 pixmap = stock_pixmap_widget(mimeview->mainwin->window, stockp);
1440 gtk_container_add(GTK_CONTAINER(button), pixmap);
1443 if (prefs_common.attach_desc)
1444 desc = get_part_description(mimeinfo);
1446 desc = get_part_name(mimeinfo);
1449 tip = g_strdup_printf("%s\n%s\n%s", desc, mimeinfo->content_type,
1450 to_human_readable(mimeinfo->size));
1452 tip = g_strdup_printf("%s\n%s", mimeinfo->content_type,
1453 to_human_readable(mimeinfo->size));
1455 gtk_tooltips_set_tip(mimeview->tooltips, button, tip, NULL);
1457 gtk_widget_show_all(button);
1458 gtk_signal_connect(GTK_OBJECT(button), "button_press_event",
1459 GTK_SIGNAL_FUNC(icon_clicked_cb), mimeview);
1460 gtk_signal_connect(GTK_OBJECT(button), "key_press_event",
1461 GTK_SIGNAL_FUNC(icon_key_pressed), mimeview);
1462 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
1466 static void icon_list_clear (MimeView *mimeview)
1471 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1472 for (; child != NULL; child = g_list_next(child)) {
1473 gtkut_container_remove(GTK_CONTAINER(mimeview->icon_vbox),
1474 GTK_WIDGET(child->data));
1476 mimeview->icon_count = 0;
1477 adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
1481 static void icon_list_toggle_by_mime_info(MimeView *mimeview,
1486 child = gtk_container_children(GTK_CONTAINER(mimeview->icon_vbox));
1487 for (; child != NULL; child = g_list_next(child)) {
1488 if (GTK_IS_TOGGLE_BUTTON(child->data) &&
1489 gtk_object_get_data(GTK_OBJECT(child->data),
1490 "partinfo") == (gpointer)mimeinfo) {
1491 gtk_toggle_button_set_active
1492 (GTK_TOGGLE_BUTTON(child->data), TRUE);
1497 static void icon_scroll_size_allocate_cb(GtkWidget *widget,
1498 GtkAllocation *size, MimeView *mimeview)
1500 GtkAllocation *mainbox_size;
1501 GtkAllocation *vbox_size;
1502 GtkAllocation *layout_size;
1505 adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
1507 mainbox_size = &mimeview->icon_mainbox->allocation;
1508 vbox_size = &mimeview->icon_vbox->allocation;
1509 layout_size = &mimeview->icon_scroll->allocation;
1511 /* centralise the vbox */
1512 gtk_layout_move(GTK_LAYOUT(mimeview->icon_scroll), mimeview->icon_vbox,
1513 (mainbox_size->width - vbox_size->width)/2, 0);
1515 gtk_layout_set_size(GTK_LAYOUT(mimeview->icon_scroll),
1516 GTK_LAYOUT(mimeview->icon_scroll)->width,
1517 MAX(vbox_size->height, layout_size->height));
1518 adj->step_increment = 5;
1521 static void icon_list_create(MimeView *mimeview, MimeInfo *mimeinfo)
1523 GtkRequisition size;
1525 g_return_if_fail(mimeinfo != NULL);
1527 if (mimeinfo->children)
1528 mimeinfo = mimeinfo->children;
1530 while (mimeinfo != NULL) {
1531 if (mimeinfo->children)
1532 icon_list_create(mimeview, mimeinfo);
1533 else if (mimeinfo->sub &&
1534 mimeinfo->sub->mime_type != MIME_TEXT &&
1535 mimeinfo->sub->mime_type != MIME_TEXT_HTML)
1536 icon_list_create(mimeview, mimeinfo->sub);
1538 icon_list_append_icon(mimeview, mimeinfo);
1539 mimeinfo = mimeinfo->next;
1541 gtk_widget_size_request(mimeview->icon_vbox, &size);
1542 width = size.width + 4;
1543 if (width > mimeview->icon_mainbox->requisition.width) {
1544 gtk_widget_set_usize(mimeview->icon_mainbox,
1550 static void mime_toggle_button_cb (GtkWidget *button, MimeView *mimeview)
1552 gtk_widget_ref(button);
1554 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
1555 gtk_arrow_set(GTK_ARROW(GTK_BIN(button)->child), GTK_ARROW_RIGHT,
1557 gtk_widget_hide(mimeview->icon_mainbox);
1558 gtk_widget_show(mimeview->ctree_mainbox);
1559 gtk_paned_set_position(GTK_PANED(mimeview->paned), mimeview->oldsize);
1561 gtkut_container_remove(GTK_CONTAINER(mimeview->icon_mainbox),
1563 gtk_box_pack_end(GTK_BOX(mimeview->ctree_mainbox),
1564 button, FALSE, FALSE, 0);
1565 gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 1);
1567 gtk_arrow_set(GTK_ARROW(GTK_BIN(button)->child), GTK_ARROW_LEFT,
1569 mimeview->oldsize = mimeview->ctree_mainbox->allocation.height;
1570 gtk_widget_hide(mimeview->ctree_mainbox);
1571 gtk_widget_show(mimeview->icon_mainbox);
1572 gtk_paned_set_position(GTK_PANED(mimeview->paned), 0);
1574 gtkut_container_remove(GTK_CONTAINER(mimeview->ctree_mainbox),
1576 gtk_box_pack_start(GTK_BOX(mimeview->icon_mainbox),
1577 button, FALSE, FALSE, 0);
1578 gtk_box_reorder_child(GTK_BOX(button->parent), button, 0);
1579 if (mimeview->opened)
1580 icon_list_toggle_by_mime_info
1581 (mimeview, gtk_ctree_node_get_row_data(GTK_CTREE(mimeview->ctree),
1585 gtk_widget_grab_focus(button);
1586 gtk_widget_unref(button);
1590 void mimeview_update (MimeView *mimeview) {
1591 if (mimeview && mimeview->mimeinfo) {
1592 icon_list_clear(mimeview);
1593 icon_list_create(mimeview, mimeview->mimeinfo);