2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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.
23 #include <gtk/gtkmain.h>
24 #include <gtk/gtkwindow.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtksignal.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkcontainer.h>
29 #include <gtk/gtkstatusbar.h>
30 #include <gtk/gtkhpaned.h>
31 #include <gtk/gtkvpaned.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkitemfactory.h>
34 #include <gtk/gtkeditable.h>
35 #include <gtk/gtkmenu.h>
36 #include <gtk/gtkmenuitem.h>
37 #include <gtk/gtkhandlebox.h>
38 #include <gtk/gtktoolbar.h>
39 #include <gtk/gtkbutton.h>
44 #include "mainwindow.h"
45 #include "folderview.h"
46 #include "foldersel.h"
47 #include "summaryview.h"
48 #include "summary_search.h"
49 #include "messageview.h"
50 #include "headerview.h"
58 #include "prefs_common.h"
59 #include "prefs_filter.h"
60 #include "prefs_account.h"
62 #include "addressbook.h"
63 #include "headerwindow.h"
64 #include "logwindow.h"
65 #include "manage_window.h"
66 #include "alertpanel.h"
67 #include "statusbar.h"
68 #include "inputdialog.h"
75 #define AC_LABEL_WIDTH 240
77 #define STATUSBAR_PUSH(mainwin, str) \
79 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
80 mainwin->mainwin_cid, str); \
81 gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
84 #define STATUSBAR_POP(mainwin) \
86 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
87 mainwin->mainwin_cid); \
90 /* list of all instantiated MainWindow */
91 static GList *mainwin_list = NULL;
93 static GdkCursor *watch_cursor;
95 static void main_window_show_cur_account (MainWindow *mainwin);
97 static void main_window_set_widgets (MainWindow *mainwin,
99 static void main_window_toolbar_create (MainWindow *mainwin,
100 GtkWidget *container);
102 /* callback functions */
103 static void toolbar_inc_cb (GtkWidget *widget,
105 static void toolbar_inc_all_cb (GtkWidget *widget,
107 static void toolbar_send_cb (GtkWidget *widget,
110 static void toolbar_compose_cb (GtkWidget *widget,
112 static void toolbar_reply_cb (GtkWidget *widget,
114 static void toolbar_reply_to_all_cb (GtkWidget *widget,
116 static void toolbar_forward_cb (GtkWidget *widget,
119 static void toolbar_delete_cb (GtkWidget *widget,
121 static void toolbar_exec_cb (GtkWidget *widget,
124 static void toolbar_next_unread_cb (GtkWidget *widget,
127 static void toolbar_prefs_cb (GtkWidget *widget,
129 static void toolbar_account_cb (GtkWidget *widget,
132 static void toolbar_account_button_pressed (GtkWidget *widget,
133 GdkEventButton *event,
135 static void ac_label_button_pressed (GtkWidget *widget,
136 GdkEventButton *event,
139 static gint main_window_close_cb (GtkWidget *widget,
143 static void add_mailbox_cb (MainWindow *mainwin,
146 static void update_folderview_cb (MainWindow *mainwin,
149 static void new_folder_cb (MainWindow *mainwin,
152 static void rename_folder_cb (MainWindow *mainwin,
155 static void delete_folder_cb (MainWindow *mainwin,
158 static void import_mbox_cb (MainWindow *mainwin,
161 static void export_mbox_cb (MainWindow *mainwin,
164 static void empty_trash_cb (MainWindow *mainwin,
168 static void save_as_cb (MainWindow *mainwin,
171 static void print_cb (MainWindow *mainwin,
174 static void app_exit_cb (MainWindow *mainwin,
178 static void toggle_folder_cb (MainWindow *mainwin,
181 static void toggle_message_cb (MainWindow *mainwin,
184 static void toggle_toolbar_cb (MainWindow *mainwin,
187 static void toggle_statusbar_cb (MainWindow *mainwin,
190 static void separate_widget_cb (MainWindow *mainwin,
194 static void addressbook_open_cb (MainWindow *mainwin,
197 static void log_window_show_cb (MainWindow *mainwin,
201 static void inc_mail_cb (MainWindow *mainwin,
204 static void inc_all_account_mail_cb (MainWindow *mainwin,
208 static void send_queue_cb (MainWindow *mainwin,
212 static void compose_cb (MainWindow *mainwin,
215 static void reply_cb (MainWindow *mainwin,
219 static void open_msg_cb (MainWindow *mainwin,
223 static void view_source_cb (MainWindow *mainwin,
227 static void reedit_cb (MainWindow *mainwin,
231 static void move_to_cb (MainWindow *mainwin,
234 static void copy_to_cb (MainWindow *mainwin,
237 static void delete_cb (MainWindow *mainwin,
241 static void mark_cb (MainWindow *mainwin,
244 static void unmark_cb (MainWindow *mainwin,
248 static void mark_as_unread_cb (MainWindow *mainwin,
251 static void mark_as_read_cb (MainWindow *mainwin,
255 static void set_charset_cb (MainWindow *mainwin,
259 static void thread_cb (MainWindow *mainwin,
262 static void set_display_item_cb (MainWindow *mainwin,
265 static void sort_summary_cb (MainWindow *mainwin,
268 static void attract_by_subject_cb(MainWindow *mainwin,
272 static void delete_duplicated_cb (MainWindow *mainwin,
275 static void filter_cb (MainWindow *mainwin,
278 static void execute_summary_cb (MainWindow *mainwin,
281 static void update_summary_cb (MainWindow *mainwin,
285 static void prev_cb (MainWindow *mainwin,
288 static void next_cb (MainWindow *mainwin,
292 static void next_unread_cb (MainWindow *mainwin,
296 static void goto_folder_cb (MainWindow *mainwin,
300 static void copy_cb (MainWindow *mainwin,
303 static void allsel_cb (MainWindow *mainwin,
307 static void prefs_common_open_cb (MainWindow *mainwin,
310 static void prefs_filter_open_cb (MainWindow *mainwin,
313 static void prefs_account_open_cb(MainWindow *mainwin,
316 static void new_account_cb (MainWindow *mainwin,
320 static void account_menu_cb (GtkMenuItem *menuitem,
323 static void manual_open_cb (MainWindow *mainwin,
327 static void scan_tree_func (Folder *folder,
331 static GtkItemFactoryEntry mainwin_entries[] =
333 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
334 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
335 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
336 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
337 {N_("/_File/_Folder/Create _new folder..."),
338 NULL, new_folder_cb, 0, NULL},
339 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
340 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
341 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
342 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
343 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
344 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
345 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
346 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
347 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
348 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
349 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
351 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
352 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
353 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
354 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
355 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
357 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
358 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
359 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
360 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
361 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
362 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
363 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
364 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
365 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
366 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
367 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
368 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
369 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
370 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
371 {N_("/_View/_Code set/_Auto detect"),
372 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
374 #define CODESET_SEPARATOR \
375 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
376 #define CODESET_ACTION(action) \
377 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
379 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
380 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
381 CODESET_ACTION(C_US_ASCII)},
384 {N_("/_View/_Code set/Unicode (_UTF-8)"),
385 CODESET_ACTION(C_UTF_8)},
388 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
389 CODESET_ACTION(C_ISO_8859_1)},
392 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
393 CODESET_ACTION(C_ISO_8859_2)},
395 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
396 CODESET_ACTION(C_ISO_8859_13)},
397 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
398 CODESET_ACTION(C_ISO_8859_4)},
400 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
401 CODESET_ACTION(C_ISO_8859_7)},
403 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
404 CODESET_ACTION(C_ISO_8859_9)},
406 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
407 CODESET_ACTION(C_ISO_8859_5)},
408 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
409 CODESET_ACTION(C_KOI8_R)},
410 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
411 CODESET_ACTION(C_CP1251)},
414 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
415 CODESET_ACTION(C_ISO_2022_JP)},
417 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
418 CODESET_ACTION(C_ISO_2022_JP_2)},
420 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
421 CODESET_ACTION(C_EUC_JP)},
422 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
423 CODESET_ACTION(C_SHIFT_JIS)},
426 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
427 CODESET_ACTION(C_GB2312)},
428 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
429 CODESET_ACTION(C_BIG5)},
430 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
431 CODESET_ACTION(C_EUC_TW)},
432 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
433 CODESET_ACTION(C_ISO_2022_CN)},
435 {N_("/_View/_Code set/Korean (EUC-_KR)"),
436 CODESET_ACTION(C_EUC_KR)},
437 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
438 CODESET_ACTION(C_ISO_2022_KR)},
441 #undef CODESET_SEPARATOR
442 #undef CODESET_ACTION
444 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
445 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
446 {N_("/_Message/Receive from _all accounts"),
447 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
448 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
449 {N_("/_Message/Send queued messa_ges"),
450 NULL, send_queue_cb, 0, NULL},
451 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
452 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
453 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
454 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
455 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
456 {N_("/_Message/Forward as an a_ttachment"),
457 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
460 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
461 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
462 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
463 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
464 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
465 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
466 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
467 {N_("/_Message/_Mark/Mark it as _being read"),
468 NULL, mark_as_read_cb, 0, NULL},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
471 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
472 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
473 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
475 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_Summary/_Delete duplicated messages"),
477 NULL, delete_duplicated_cb, 0, NULL},
478 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
479 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
480 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
481 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
482 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
483 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
484 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
485 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
486 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
487 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
489 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
490 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
491 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
492 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
493 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
494 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
495 {N_("/_Summary/_Sort/_Attract by subject"),
496 NULL, attract_by_subject_cb, 0, NULL},
497 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
498 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
499 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
501 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
502 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
503 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
505 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
506 {N_("/_Configuration/_Common preferences..."),
507 NULL, prefs_common_open_cb, 0, NULL},
508 {N_("/_Configuration/_Filter setting..."),
509 NULL, prefs_filter_open_cb, 0, NULL},
510 {N_("/_Configuration/_Preferences per account..."),
511 NULL, prefs_account_open_cb, 0, NULL},
512 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_Configuration/Create _new account..."),
514 NULL, new_account_cb, 0, NULL},
515 {N_("/_Configuration/_Edit accounts..."),
516 NULL, account_edit_open, 0, NULL},
517 {N_("/_Configuration/C_hange current account"),
518 NULL, NULL, 0, "<Branch>"},
520 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
521 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
523 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
524 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
525 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
528 MainWindow *main_window_create(SeparateType type)
534 GtkWidget *handlebox;
535 GtkWidget *vbox_body;
536 GtkWidget *hbox_stat;
537 GtkWidget *statusbar;
538 GtkWidget *ac_button;
541 FolderView *folderview;
542 SummaryView *summaryview;
543 MessageView *messageview;
544 GdkColormap *colormap;
547 guint n_menu_entries;
548 GtkItemFactory *ifactory;
553 debug_print(_("Creating main window...\n"));
554 mainwin = g_new0(MainWindow, 1);
557 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
558 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
559 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
560 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
561 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
562 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
563 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
564 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
565 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
566 gtk_widget_realize(window);
568 vbox = gtk_vbox_new(FALSE, 0);
569 gtk_widget_show(vbox);
570 gtk_container_add(GTK_CONTAINER(window), vbox);
573 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
574 menubar = menubar_create(window, mainwin_entries,
575 n_menu_entries, "<Main>", mainwin);
576 gtk_widget_show(menubar);
577 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
579 handlebox = gtk_handle_box_new();
580 gtk_widget_show(handlebox);
581 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
583 main_window_toolbar_create(mainwin, handlebox);
585 /* vbox that contains body */
586 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
587 gtk_widget_show(vbox_body);
588 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
589 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
591 hbox_stat = gtk_hbox_new(FALSE, 2);
592 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
594 statusbar = statusbar_create();
595 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
597 ac_button = gtk_button_new();
598 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
599 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
600 gtk_widget_set_usize(ac_button, -1, 1);
601 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
602 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
603 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
605 ac_label = gtk_label_new("");
606 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
608 gtk_widget_show_all(hbox_stat);
611 mainwin->folderview = folderview = folderview_create();
612 mainwin->summaryview = summaryview = summary_create();
613 mainwin->messageview = messageview = messageview_create();
614 mainwin->headerwin = header_window_create();
615 mainwin->logwin = log_window_create();
617 folderview->mainwin = mainwin;
618 folderview->summaryview = summaryview;
620 summaryview->mainwin = mainwin;
621 summaryview->folderview = folderview;
622 summaryview->messageview = messageview;
623 summaryview->headerwin = mainwin->headerwin;
624 summaryview->window = window;
626 messageview->mainwin = mainwin;
628 mainwin->window = window;
629 mainwin->vbox = vbox;
630 mainwin->menubar = menubar;
631 mainwin->handlebox = handlebox;
632 mainwin->vbox_body = vbox_body;
633 mainwin->hbox_stat = hbox_stat;
634 mainwin->statusbar = statusbar;
635 mainwin->ac_button = ac_button;
636 mainwin->ac_label = ac_label;
638 /* set context IDs for status bar */
639 mainwin->mainwin_cid = gtk_statusbar_get_context_id
640 (GTK_STATUSBAR(statusbar), "Main Window");
641 mainwin->folderview_cid = gtk_statusbar_get_context_id
642 (GTK_STATUSBAR(statusbar), "Folder View");
643 mainwin->summaryview_cid = gtk_statusbar_get_context_id
644 (GTK_STATUSBAR(statusbar), "Summary View");
646 /* allocate colors for summary view and folder view */
647 summaryview->color_marked.red = summaryview->color_marked.green = 0;
648 summaryview->color_marked.blue = (guint16)65535;
650 summaryview->color_dim.red = summaryview->color_dim.green =
651 summaryview->color_dim.blue = COLOR_DIM;
653 summaryview->color_normal.red = summaryview->color_normal.green =
654 summaryview->color_normal.blue = 0;
656 folderview->color_new.red = (guint16)55000;
657 folderview->color_new.green = folderview->color_new.blue = 15000;
659 folderview->color_normal.red = folderview->color_normal.green =
660 folderview->color_normal.blue = 0;
662 color[0] = summaryview->color_marked;
663 color[1] = summaryview->color_dim;
664 color[2] = summaryview->color_normal;
665 color[3] = folderview->color_new;
666 color[4] = folderview->color_normal;
668 colormap = gdk_window_get_colormap(window->window);
669 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
670 for (i = 0; i < 5; i++) {
671 if (success[i] == FALSE)
672 g_warning(_("MainWindow: color allocation %d failed\n"), i);
675 debug_print(_("done.\n"));
677 main_window_set_widgets(mainwin, type);
680 ifactory = gtk_item_factory_from_widget(menubar);
681 menuitem = gtk_item_factory_get_item
682 (ifactory, "/View/Code set/Auto detect");
683 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
685 switch (prefs_common.toolbar_style) {
687 menuitem = gtk_item_factory_get_item
688 (ifactory, "/View/Toolbar/Non-display");
691 menuitem = gtk_item_factory_get_item
692 (ifactory, "/View/Toolbar/Icon");
695 menuitem = gtk_item_factory_get_item
696 (ifactory, "/View/Toolbar/Text");
699 menuitem = gtk_item_factory_get_item
700 (ifactory, "/View/Toolbar/Icon and text");
702 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
704 gtk_widget_hide(mainwin->hbox_stat);
705 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
706 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
707 prefs_common.show_statusbar);
709 menu_set_sensitive(ifactory, "/Summary/Thread view",
710 prefs_common.enable_thread ? FALSE : TRUE);
711 menu_set_sensitive(ifactory, "/Summary/Unthread view",
712 prefs_common.enable_thread ? TRUE : FALSE);
713 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
715 /* set account selection menu */
716 ac_menu = gtk_item_factory_get_widget
717 (ifactory, "/Configuration/Change current account");
718 mainwin->ac_menu = ac_menu;
720 main_window_set_toolbar_sensitive(mainwin, FALSE);
722 /* show main window */
723 gtk_widget_set_uposition(mainwin->window,
724 prefs_common.mainwin_x,
725 prefs_common.mainwin_y);
726 gtk_widget_set_usize(window, prefs_common.mainwin_width,
727 prefs_common.mainwin_height);
728 gtk_widget_show(mainwin->window);
730 /* initialize views */
731 folderview_init(folderview);
732 summary_init(summaryview);
733 messageview_init(messageview);
734 header_window_init(mainwin->headerwin);
735 log_window_init(mainwin->logwin);
737 mainwin->cursor_count = 0;
740 watch_cursor = gdk_cursor_new(GDK_WATCH);
742 mainwin_list = g_list_append(mainwin_list, mainwin);
747 void main_window_cursor_wait(MainWindow *mainwin)
749 if (mainwin->cursor_count == 0)
750 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
752 mainwin->cursor_count++;
757 void main_window_cursor_normal(MainWindow *mainwin)
759 if (mainwin->cursor_count)
760 mainwin->cursor_count--;
762 if (mainwin->cursor_count == 0)
763 gdk_window_set_cursor(mainwin->window->window, NULL);
768 void main_window_reflect_prefs_all(void)
773 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
774 mainwin = (MainWindow *)cur->data;
776 main_window_show_cur_account(mainwin);
778 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
779 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
781 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
782 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
785 summary_change_display_item(mainwin->summaryview);
786 headerview_set_visibility(mainwin->messageview->headerview,
787 prefs_common.display_header_pane);
791 void main_window_set_account_menu(GList *account_list)
793 GList *cur, *cur_ac, *cur_item;
796 PrefsAccount *ac_prefs;
798 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
799 mainwin = (MainWindow *)cur->data;
801 /* destroy all previous menu item */
802 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
803 while (cur_item != NULL) {
804 GList *next = cur_item->next;
805 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
809 for (cur_ac = account_list; cur_ac != NULL;
810 cur_ac = cur_ac->next) {
811 ac_prefs = (PrefsAccount *)cur_ac->data;
813 menuitem = gtk_menu_item_new_with_label
814 (ac_prefs->account_name
815 ? ac_prefs->account_name : _("Untitled"));
816 gtk_widget_show(menuitem);
817 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
818 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
819 GTK_SIGNAL_FUNC(account_menu_cb),
825 static void main_window_show_cur_account(MainWindow *mainwin)
830 ac_name = g_strdup(cur_account
831 ? (cur_account->account_name
832 ? cur_account->account_name : _("Untitled"))
836 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
838 buf = g_strdup(PROG_VERSION);
839 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
842 buf = g_strdup_printf(_("Current account: %s"), ac_name);
843 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
844 gtk_widget_queue_resize(mainwin->ac_button);
850 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
852 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
853 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
854 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
856 if (mainwin->type == type) return;
858 /* remove widgets from those containers */
859 gtk_widget_ref(folder_wid);
860 gtk_widget_ref(summary_wid);
861 gtk_widget_ref(message_wid);
863 (GTK_CONTAINER(folder_wid->parent), folder_wid);
865 (GTK_CONTAINER(summary_wid->parent), summary_wid);
867 (GTK_CONTAINER(message_wid->parent), message_wid);
869 /* clean containers */
870 switch (mainwin->type) {
872 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
874 case SEPARATE_FOLDER:
875 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
876 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
878 case SEPARATE_MESSAGE:
879 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
880 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
883 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
884 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
888 gtk_widget_hide(mainwin->window);
889 main_window_set_widgets(mainwin, type);
890 gtk_widget_show(mainwin->window);
892 gtk_widget_unref(folder_wid);
893 gtk_widget_unref(summary_wid);
894 gtk_widget_unref(message_wid);
897 void main_window_get_size(MainWindow *mainwin)
899 GtkAllocation *allocation;
901 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
903 prefs_common.summaryview_width = allocation->width;
905 if (mainwin->summaryview->msg_is_toggled_on)
906 prefs_common.summaryview_height = allocation->height;
908 prefs_common.mainview_width = allocation->width;
910 allocation = &mainwin->window->allocation;
912 prefs_common.mainview_height = allocation->height;
913 prefs_common.mainwin_width = allocation->width;
914 prefs_common.mainwin_height = allocation->height;
916 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
918 prefs_common.folderview_width = allocation->width;
919 prefs_common.folderview_height = allocation->height;
922 void main_window_get_position(MainWindow *mainwin)
926 gtkut_widget_get_uposition(mainwin->window, &x, &y);
928 prefs_common.mainview_x = x;
929 prefs_common.mainview_y = y;
930 prefs_common.mainwin_x = x;
931 prefs_common.mainwin_y = y;
933 debug_print(_("window position: x = %d, y = %d\n"), x, y);
936 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
941 if (alertpanel(_("Empty trash"),
942 _("Empty all messages in trash?"),
943 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
947 procmsg_empty_trash();
949 for (list = folder_get_list(); list != NULL; list = list->next) {
954 folder_item_scan(folder->trash);
955 folderview_update_item(folder->trash, TRUE);
959 if (mainwin->summaryview->folder_item &&
960 mainwin->summaryview->folder_item->stype == F_TRASH)
961 gtk_widget_grab_focus(mainwin->folderview->ctree);
964 void main_window_add_mailbox(MainWindow *mainwin)
969 path = input_dialog(_("Add mailbox"),
970 _("Input the location of mailbox.\n"
971 "If the existing mailbox is specified, it will be\n"
972 "scanned automatically."),
975 if (folder_find_from_path(path)) {
976 alertpanel_error(_("The mailbox `%s' already exists."), path);
980 if (!strcmp(path, "Mail"))
981 folder = folder_new(F_MH, _("Mailbox"), path);
983 folder = folder_new(F_MH, g_basename(path), path);
986 if (folder->create_tree(folder) < 0) {
987 alertpanel_error(_("Creation of the mailbox failed.\n"
988 "Maybe some files already exist, or you don't have the permission to write there."));
989 folder_destroy(folder);
994 folder_set_ui_func(folder, scan_tree_func, mainwin);
995 folder->scan_tree(folder);
996 folder_set_ui_func(folder, NULL, NULL);
998 folderview_set(mainwin->folderview);
1001 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1003 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
1004 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1005 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1006 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1007 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1009 if (!mainwin->summaryview->folder_item ||
1010 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1011 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1013 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1016 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1018 GtkItemFactory *ifactory;
1022 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1024 if (selection == SUMMARY_SELECTED_SINGLE)
1028 if (!mainwin->summaryview->folder_item ||
1029 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1034 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1035 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1036 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1037 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1038 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1039 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1040 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1041 menu_set_sensitive(ifactory, "/Message/View source", sens);
1042 if (sens && (!mainwin->summaryview->folder_item ||
1043 mainwin->summaryview->folder_item->stype != F_DRAFT))
1045 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1047 if (selection == SUMMARY_SELECTED_SINGLE ||
1048 selection == SUMMARY_SELECTED_MULTIPLE)
1053 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1054 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1055 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1056 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1057 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1059 if (selection != SUMMARY_NONE)
1064 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1065 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1066 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1067 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1068 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1069 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1070 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1073 void main_window_popup(MainWindow *mainwin)
1079 gdk_window_get_origin(mainwin->window->window, &x, &y);
1080 sx = gdk_screen_width();
1081 sy = gdk_screen_height();
1082 x %= sx; if (x < 0) x += sx;
1083 y %= sy; if (y < 0) y += sy;
1084 gdk_window_move(mainwin->window->window, x, y);
1085 gdk_window_raise(mainwin->window->window);
1087 debug_print("window position: x = %d, y = %d\n", x, y);
1089 switch (mainwin->type) {
1090 case SEPARATE_FOLDER:
1091 widget = mainwin->win.sep_folder.folderwin;
1092 gdk_window_get_origin(widget->window, &x, &y);
1093 x %= sx; if (x < 0) x += sx;
1094 y %= sy; if (y < 0) y += sy;
1095 gdk_window_move(widget->window, x, y);
1096 gdk_window_raise(widget->window);
1098 case SEPARATE_MESSAGE:
1099 widget = mainwin->win.sep_message.messagewin;
1100 gdk_window_get_origin(widget->window, &x, &y);
1101 x %= sx; if (x < 0) x += sx;
1102 y %= sy; if (y < 0) y += sy;
1103 gdk_window_move(widget->window, x, y);
1104 gdk_window_raise(widget->window);
1107 widget = mainwin->win.sep_both.folderwin;
1108 gdk_window_get_origin(widget->window, &x, &y);
1109 x %= sx; if (x < 0) x += sx;
1110 y %= sy; if (y < 0) y += sy;
1111 gdk_window_move(widget->window, x, y);
1112 gdk_window_raise(widget->window);
1113 widget = mainwin->win.sep_both.messagewin;
1114 gdk_window_get_origin(widget->window, &x, &y);
1115 x %= sx; if (x < 0) x += sx;
1116 y %= sy; if (y < 0) y += sy;
1117 gdk_window_move(widget->window, x, y);
1118 gdk_window_raise(widget->window);
1124 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1126 GtkWidget *folderwin = NULL;
1127 GtkWidget *messagewin = NULL;
1130 GtkWidget *vbox_body = mainwin->vbox_body;
1132 debug_print(_("Setting widgets..."));
1134 /* create separated window(s) if needed */
1135 if (type & SEPARATE_FOLDER) {
1136 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1137 gtk_window_set_policy(GTK_WINDOW(folderwin),
1139 gtk_widget_set_usize(folderwin, -1,
1140 prefs_common.mainview_height);
1141 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1143 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1144 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1147 if (type & SEPARATE_MESSAGE) {
1148 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1149 gtk_window_set_policy(GTK_WINDOW(messagewin),
1151 gtk_widget_set_usize
1152 (messagewin, prefs_common.mainview_width,
1153 prefs_common.mainview_height
1154 - prefs_common.summaryview_height
1155 + DEFAULT_HEADERVIEW_HEIGHT);
1156 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1158 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1159 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1165 hpaned = gtk_hpaned_new();
1166 gtk_widget_show(hpaned);
1167 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1168 gtk_paned_add1(GTK_PANED(hpaned),
1169 GTK_WIDGET_PTR(mainwin->folderview));
1171 vpaned = gtk_vpaned_new();
1172 if (mainwin->summaryview->msg_is_toggled_on) {
1173 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1174 gtk_paned_add1(GTK_PANED(vpaned),
1175 GTK_WIDGET_PTR(mainwin->summaryview));
1177 gtk_paned_add2(GTK_PANED(hpaned),
1178 GTK_WIDGET_PTR(mainwin->summaryview));
1179 gtk_widget_ref(vpaned);
1181 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1182 prefs_common.summaryview_width,
1183 prefs_common.summaryview_height);
1184 gtk_paned_add2(GTK_PANED(vpaned),
1185 GTK_WIDGET_PTR(mainwin->messageview));
1186 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1187 prefs_common.mainview_width, -1);
1188 gtk_widget_set_usize(mainwin->window,
1189 prefs_common.folderview_width +
1190 prefs_common.mainview_width,
1191 prefs_common.mainwin_height);
1192 gtk_widget_show_all(vpaned);
1194 mainwin->win.sep_none.hpaned = hpaned;
1195 mainwin->win.sep_none.vpaned = vpaned;
1197 case SEPARATE_FOLDER:
1198 vpaned = gtk_vpaned_new();
1199 if (mainwin->summaryview->msg_is_toggled_on) {
1200 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1202 gtk_paned_add1(GTK_PANED(vpaned),
1203 GTK_WIDGET_PTR(mainwin->summaryview));
1205 gtk_box_pack_start(GTK_BOX(vbox_body),
1206 GTK_WIDGET_PTR(mainwin->summaryview),
1208 gtk_widget_ref(vpaned);
1210 gtk_paned_add2(GTK_PANED(vpaned),
1211 GTK_WIDGET_PTR(mainwin->messageview));
1212 gtk_widget_show_all(vpaned);
1213 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1214 prefs_common.summaryview_width,
1215 prefs_common.summaryview_height);
1216 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1217 prefs_common.mainview_width, -1);
1218 gtk_widget_set_usize(mainwin->window,
1219 prefs_common.mainview_width,
1220 prefs_common.mainview_height);
1222 gtk_container_add(GTK_CONTAINER(folderwin),
1223 GTK_WIDGET_PTR(mainwin->folderview));
1225 mainwin->win.sep_folder.folderwin = folderwin;
1226 mainwin->win.sep_folder.vpaned = vpaned;
1228 gtk_widget_show_all(folderwin);
1230 case SEPARATE_MESSAGE:
1231 hpaned = gtk_hpaned_new();
1232 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1234 gtk_paned_add1(GTK_PANED(hpaned),
1235 GTK_WIDGET_PTR(mainwin->folderview));
1236 gtk_paned_add2(GTK_PANED(hpaned),
1237 GTK_WIDGET_PTR(mainwin->summaryview));
1238 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1239 prefs_common.summaryview_width,
1240 prefs_common.summaryview_height);
1241 gtk_widget_set_usize(mainwin->window,
1242 prefs_common.folderview_width +
1243 prefs_common.mainview_width,
1244 prefs_common.mainwin_height);
1245 gtk_widget_show_all(hpaned);
1246 gtk_container_add(GTK_CONTAINER(messagewin),
1247 GTK_WIDGET_PTR(mainwin->messageview));
1249 mainwin->win.sep_message.messagewin = messagewin;
1250 mainwin->win.sep_message.hpaned = hpaned;
1252 gtk_widget_show_all(messagewin);
1255 gtk_box_pack_start(GTK_BOX(vbox_body),
1256 GTK_WIDGET_PTR(mainwin->summaryview),
1258 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1259 prefs_common.summaryview_width,
1260 prefs_common.summaryview_height);
1261 gtk_widget_set_usize(mainwin->window,
1262 prefs_common.mainview_width,
1263 prefs_common.mainwin_height);
1264 gtk_container_add(GTK_CONTAINER(folderwin),
1265 GTK_WIDGET_PTR(mainwin->folderview));
1266 gtk_container_add(GTK_CONTAINER(messagewin),
1267 GTK_WIDGET_PTR(mainwin->messageview));
1269 mainwin->win.sep_both.folderwin = folderwin;
1270 mainwin->win.sep_both.messagewin = messagewin;
1272 gtk_widget_show_all(folderwin);
1273 gtk_widget_show_all(messagewin);
1277 mainwin->type = type;
1279 debug_print(_("done.\n"));
1282 #include "pixmaps/stock_mail_receive.xpm"
1283 #include "pixmaps/stock_mail_receive_all.xpm"
1284 #include "pixmaps/stock_mail_compose.xpm"
1285 #include "pixmaps/stock_mail_reply.xpm"
1286 #include "pixmaps/stock_mail_reply_to_all.xpm"
1287 #include "pixmaps/stock_mail_forward.xpm"
1288 #include "pixmaps/stock_mail_send.xpm"
1289 #include "pixmaps/stock_preferences.xpm"
1290 #include "pixmaps/stock_properties.xpm"
1291 #include "pixmaps/stock_down_arrow.xpm"
1292 #include "pixmaps/stock_close.xpm"
1293 #include "pixmaps/stock_exec.xpm"
1295 #define CREATE_TOOLBAR_ICON(xpm_d) \
1297 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1298 &container->style->white, \
1300 icon_wid = gtk_pixmap_new(icon, mask); \
1303 static void main_window_toolbar_create(MainWindow *mainwin,
1304 GtkWidget *container)
1309 GtkWidget *icon_wid;
1311 GtkWidget *getall_btn;
1312 GtkWidget *compose_btn;
1313 GtkWidget *reply_btn;
1314 GtkWidget *replyall_btn;
1316 GtkWidget *send_btn;
1317 GtkWidget *prefs_btn;
1318 GtkWidget *account_btn;
1319 GtkWidget *next_btn;
1320 GtkWidget *delete_btn;
1321 GtkWidget *exec_btn;
1323 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1325 gtk_container_add(GTK_CONTAINER(container), toolbar);
1326 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1327 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1328 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1329 GTK_TOOLBAR_SPACE_LINE);
1331 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1332 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1334 _("Incorporate new mail"),
1336 icon_wid, toolbar_inc_cb, mainwin);
1337 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1338 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1340 _("Incorporate new mail of all accounts"),
1346 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1348 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1349 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1351 _("Send queued message(s)"),
1357 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1359 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1360 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1362 _("Compose new message"),
1367 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1368 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1370 _("Reply to the message"),
1375 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1376 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1381 toolbar_reply_to_all_cb,
1383 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1384 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1386 _("Forward the message"),
1392 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1394 CREATE_TOOLBAR_ICON(stock_close_xpm);
1395 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1397 _("Delete the message"),
1403 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1404 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1406 _("Execute marked process"),
1412 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1414 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1415 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1417 _("Next unread message"),
1420 toolbar_next_unread_cb,
1423 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1425 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1426 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1428 _("Common preference"),
1433 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1434 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1436 _("Account setting"),
1441 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1442 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1445 mainwin->toolbar = toolbar;
1446 mainwin->get_btn = get_btn;
1447 mainwin->getall_btn = getall_btn;
1448 mainwin->compose_btn = compose_btn;
1449 mainwin->reply_btn = reply_btn;
1450 mainwin->replyall_btn = replyall_btn;
1451 mainwin->fwd_btn = fwd_btn;
1452 mainwin->send_btn = send_btn;
1453 mainwin->prefs_btn = prefs_btn;
1454 mainwin->account_btn = account_btn;
1455 mainwin->next_btn = next_btn;
1456 mainwin->delete_btn = delete_btn;
1457 mainwin->exec_btn = exec_btn;
1459 gtk_widget_show_all(toolbar);
1462 /* callback functions */
1464 static void toolbar_inc_cb (GtkWidget *widget,
1467 MainWindow *mainwin = (MainWindow *)data;
1469 inc_mail_cb(mainwin, 0, NULL);
1472 static void toolbar_inc_all_cb (GtkWidget *widget,
1475 MainWindow *mainwin = (MainWindow *)data;
1477 inc_all_account_mail_cb(mainwin, 0, NULL);
1480 static void toolbar_send_cb (GtkWidget *widget,
1483 MainWindow *mainwin = (MainWindow *)data;
1485 send_queue_cb(mainwin, 0, NULL);
1488 static void toolbar_compose_cb (GtkWidget *widget,
1491 MainWindow *mainwin = (MainWindow *)data;
1493 compose_cb(mainwin, 0, NULL);
1496 static void toolbar_reply_cb (GtkWidget *widget,
1499 MainWindow *mainwin = (MainWindow *)data;
1501 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1504 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1507 MainWindow *mainwin = (MainWindow *)data;
1509 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1512 static void toolbar_forward_cb (GtkWidget *widget,
1515 MainWindow *mainwin = (MainWindow *)data;
1517 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1520 static void toolbar_delete_cb (GtkWidget *widget,
1523 MainWindow *mainwin = (MainWindow *)data;
1525 summary_delete(mainwin->summaryview);
1528 static void toolbar_exec_cb (GtkWidget *widget,
1531 MainWindow *mainwin = (MainWindow *)data;
1533 summary_execute(mainwin->summaryview);
1536 static void toolbar_next_unread_cb (GtkWidget *widget,
1539 MainWindow *mainwin = (MainWindow *)data;
1541 next_unread_cb(mainwin, 0, NULL);
1544 static void toolbar_prefs_cb (GtkWidget *widget,
1547 prefs_common_open();
1550 static void toolbar_account_cb (GtkWidget *widget,
1553 MainWindow *mainwin = (MainWindow *)data;
1555 prefs_account_open_cb(mainwin, 0, NULL);
1558 static void toolbar_account_button_pressed(GtkWidget *widget,
1559 GdkEventButton *event,
1562 MainWindow *mainwin = (MainWindow *)data;
1565 if (event->button != 3) return;
1567 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1568 event->button, event->time);
1571 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1574 MainWindow *mainwin = (MainWindow *)data;
1578 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1579 event->button, event->time);
1582 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1585 app_exit_cb(data, 0, widget);
1590 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1593 main_window_add_mailbox(mainwin);
1596 static void update_folderview_cb(MainWindow *mainwin, guint action,
1599 summary_show(mainwin->summaryview, NULL, FALSE);
1600 folderview_update_all();
1603 static void new_folder_cb(MainWindow *mainwin, guint action,
1606 folderview_new_folder(mainwin->folderview);
1609 static void rename_folder_cb(MainWindow *mainwin, guint action,
1612 folderview_rename_folder(mainwin->folderview);
1615 static void delete_folder_cb(MainWindow *mainwin, guint action,
1618 folderview_delete_folder(mainwin->folderview);
1621 static void import_mbox_cb(MainWindow *mainwin, guint action,
1624 import_mbox(mainwin->summaryview->folder_item);
1627 static void export_mbox_cb(MainWindow *mainwin, guint action,
1630 export_mbox(mainwin->summaryview->folder_item);
1633 static void empty_trash_cb(MainWindow *mainwin, guint action,
1636 main_window_empty_trash(mainwin, TRUE);
1639 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1641 summary_save_as(mainwin->summaryview);
1644 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1646 summary_print(mainwin->summaryview);
1649 static gint queued_messages(void)
1651 FolderItem *queue = folder_get_default_queue();
1652 folder_item_scan(queue);
1653 return queue->total;
1656 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1658 if (prefs_common.confirm_on_exit) {
1659 if (alertpanel(_("Exit"), _("Exit this program?"),
1660 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1664 if (prefs_common.warn_queued_on_exit && queued_messages() > 0) {
1665 if (alertpanel(_("Queued messages"),
1666 _("Some unsent messages are queued. Exit now?"),
1667 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1671 manage_window_focus_in(mainwin->window, NULL, NULL);
1672 app_will_exit(widget, mainwin);
1675 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1678 switch (mainwin->type) {
1680 case SEPARATE_MESSAGE:
1682 case SEPARATE_FOLDER:
1683 if (GTK_CHECK_MENU_ITEM(widget)->active)
1684 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1686 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1689 if (GTK_CHECK_MENU_ITEM(widget)->active)
1690 gtk_widget_show(mainwin->win.sep_both.folderwin);
1692 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1697 static void toggle_message_cb(MainWindow *mainwin, guint action,
1700 switch (mainwin->type) {
1702 case SEPARATE_FOLDER:
1704 case SEPARATE_MESSAGE:
1705 if (GTK_CHECK_MENU_ITEM(widget)->active)
1706 gtk_widget_show(mainwin->win.sep_message.messagewin);
1708 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1711 if (GTK_CHECK_MENU_ITEM(widget)->active)
1712 gtk_widget_show(mainwin->win.sep_both.messagewin);
1714 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1719 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1722 switch ((ToolbarStyle)action) {
1724 gtk_widget_hide(mainwin->handlebox);
1726 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1730 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1734 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1739 if (action != TOOLBAR_NONE) {
1740 gtk_widget_show(mainwin->handlebox);
1741 gtk_widget_queue_resize(mainwin->handlebox);
1744 mainwin->toolbar_style = (ToolbarStyle)action;
1745 prefs_common.toolbar_style = (ToolbarStyle)action;
1748 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1751 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1752 gtk_widget_show(mainwin->hbox_stat);
1753 prefs_common.show_statusbar = TRUE;
1755 gtk_widget_hide(mainwin->hbox_stat);
1756 prefs_common.show_statusbar = FALSE;
1760 static void separate_widget_cb(MainWindow *mainwin, guint action,
1765 type = mainwin->type ^ action;
1766 main_window_separation_change(mainwin, type);
1768 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1769 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1772 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1775 addressbook_open(NULL);
1778 static void log_window_show_cb(MainWindow *mainwin, guint action,
1781 log_window_show(mainwin->logwin);
1784 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1789 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1792 inc_all_account_mail(mainwin);
1795 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1799 if (procmsg_send_queue() < 0)
1800 alertpanel_error(_("Sending queued message failed."));
1802 statusbar_pop_all();
1804 for (list = folder_get_list(); list != NULL; list = list->next) {
1807 folder = list->data;
1808 if (folder->queue) {
1809 folder_item_scan(folder->queue);
1810 folderview_update_item(folder->queue, TRUE);
1815 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1817 if (mainwin->summaryview->folder_item)
1818 compose_new(mainwin->summaryview->folder_item->folder->account);
1823 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1827 msginfo = gtk_ctree_node_get_row_data
1828 (GTK_CTREE(mainwin->summaryview->ctree),
1829 mainwin->summaryview->selected);
1831 if (!msginfo) return;
1835 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1837 case COMPOSE_REPLY_TO_ALL:
1838 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1840 case COMPOSE_FORWARD:
1841 compose_forward(msginfo, FALSE);
1843 case COMPOSE_FORWARD_AS_ATTACH:
1844 compose_forward(msginfo, TRUE);
1847 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1850 summary_set_marks_selected(mainwin->summaryview);
1853 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1855 summary_move_to(mainwin->summaryview);
1858 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1860 summary_copy_to(mainwin->summaryview);
1863 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1865 summary_delete(mainwin->summaryview);
1868 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1870 summary_open_msg(mainwin->summaryview);
1873 static void view_source_cb(MainWindow *mainwin, guint action,
1876 summary_view_source(mainwin->summaryview);
1879 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1881 summary_reedit(mainwin->summaryview);
1884 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1886 summary_mark(mainwin->summaryview);
1889 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1891 summary_unmark(mainwin->summaryview);
1894 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1897 summary_mark_as_unread(mainwin->summaryview);
1900 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1903 summary_mark_as_read(mainwin->summaryview);
1906 static void set_charset_cb(MainWindow *mainwin, guint action,
1911 str = conv_get_charset_str((CharSet)action);
1912 g_free(prefs_common.force_charset);
1913 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1915 summary_redisplay_msg(mainwin->summaryview);
1917 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1920 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1922 GtkItemFactory *ifactory;
1924 ifactory = gtk_item_factory_from_widget(widget);
1927 summary_thread_build(mainwin->summaryview);
1928 prefs_common.enable_thread = TRUE;
1929 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1930 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1932 summary_unthread(mainwin->summaryview);
1933 prefs_common.enable_thread = FALSE;
1934 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1935 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1939 static void set_display_item_cb(MainWindow *mainwin, guint action,
1942 prefs_summary_display_item_set();
1945 static void sort_summary_cb(MainWindow *mainwin, guint action,
1948 summary_sort(mainwin->summaryview, (SummarySortType)action);
1951 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1954 summary_attract_by_subject(mainwin->summaryview);
1957 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1960 summary_delete_duplicated(mainwin->summaryview);
1963 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1965 summary_filter(mainwin->summaryview);
1968 static void execute_summary_cb(MainWindow *mainwin, guint action,
1971 summary_execute(mainwin->summaryview);
1974 static void update_summary_cb(MainWindow *mainwin, guint action,
1978 FolderView *folderview = mainwin->folderview;
1980 if (!mainwin->summaryview->folder_item) return;
1981 if (!folderview->opened) return;
1983 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1984 folderview->opened);
1987 summary_show(mainwin->summaryview, fitem, TRUE);
1990 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1992 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1995 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1997 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2000 static void next_unread_cb(MainWindow *mainwin, guint action,
2003 summary_select_next_unread(mainwin->summaryview);
2006 static void goto_folder_cb(MainWindow *mainwin, guint action,
2009 FolderItem *to_folder;
2011 to_folder = foldersel_folder_sel(NULL);
2014 folderview_select(mainwin->folderview, to_folder);
2017 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2019 messageview_copy_clipboard(mainwin->messageview);
2022 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2024 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2025 summary_select_all(mainwin->summaryview);
2026 else if (mainwin->summaryview->msg_is_toggled_on &&
2027 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2028 messageview_select_all(mainwin->messageview);
2031 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2034 prefs_common_open();
2037 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2040 prefs_filter_open();
2043 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2047 new_account_cb(mainwin, 0, widget);
2049 gboolean prev_default = cur_account->is_default;
2051 prefs_account_open(cur_account);
2052 if (!prev_default && cur_account->is_default)
2053 account_set_as_default(cur_account);
2054 account_save_config_all();
2056 main_window_reflect_prefs_all();
2060 static void new_account_cb(MainWindow *mainwin, guint action,
2063 account_edit_open();
2064 if (!compose_get_compose_list()) account_add();
2067 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2069 cur_account = (PrefsAccount *)data;
2070 main_window_reflect_prefs_all();
2073 static void manual_open_cb(MainWindow *mainwin, guint action,
2076 manual_open((ManualLang)action);
2079 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2081 MainWindow *mainwin = (MainWindow *)data;
2085 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2086 LOCAL_FOLDER(folder)->rootpath,
2090 str = g_strdup_printf(_("Scanning folder %s ..."),
2091 LOCAL_FOLDER(folder)->rootpath);
2093 STATUSBAR_PUSH(mainwin, str);
2094 STATUSBAR_POP(mainwin);