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 next_marked_cb (MainWindow *mainwin,
300 static void prev_marked_cb (MainWindow *mainwin,
304 static void goto_folder_cb (MainWindow *mainwin,
308 static void copy_cb (MainWindow *mainwin,
311 static void allsel_cb (MainWindow *mainwin,
315 static void prefs_common_open_cb (MainWindow *mainwin,
318 static void prefs_filter_open_cb (MainWindow *mainwin,
321 static void prefs_account_open_cb(MainWindow *mainwin,
324 static void new_account_cb (MainWindow *mainwin,
328 static void account_menu_cb (GtkMenuItem *menuitem,
331 static void manual_open_cb (MainWindow *mainwin,
335 static void scan_tree_func (Folder *folder,
339 static GtkItemFactoryEntry mainwin_entries[] =
341 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
342 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
343 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
344 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
345 {N_("/_File/_Folder/Create _new folder..."),
346 NULL, new_folder_cb, 0, NULL},
347 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
348 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
349 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
350 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
351 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
352 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
353 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
354 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
355 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
356 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
357 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
359 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
360 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
361 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
362 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
363 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
365 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
366 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
367 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
368 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
369 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
370 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
371 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
372 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
373 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
374 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
375 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
376 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
377 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
378 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
379 {N_("/_View/_Code set/_Auto detect"),
380 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
382 #define CODESET_SEPARATOR \
383 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
384 #define CODESET_ACTION(action) \
385 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
387 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
388 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
389 CODESET_ACTION(C_US_ASCII)},
392 {N_("/_View/_Code set/Unicode (_UTF-8)"),
393 CODESET_ACTION(C_UTF_8)},
396 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
397 CODESET_ACTION(C_ISO_8859_1)},
400 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
401 CODESET_ACTION(C_ISO_8859_2)},
403 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
404 CODESET_ACTION(C_ISO_8859_13)},
405 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
406 CODESET_ACTION(C_ISO_8859_4)},
408 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
409 CODESET_ACTION(C_ISO_8859_7)},
411 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
412 CODESET_ACTION(C_ISO_8859_9)},
414 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
415 CODESET_ACTION(C_ISO_8859_5)},
416 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
417 CODESET_ACTION(C_KOI8_R)},
418 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
419 CODESET_ACTION(C_CP1251)},
422 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
423 CODESET_ACTION(C_ISO_2022_JP)},
425 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
426 CODESET_ACTION(C_ISO_2022_JP_2)},
428 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
429 CODESET_ACTION(C_EUC_JP)},
430 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
431 CODESET_ACTION(C_SHIFT_JIS)},
434 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
435 CODESET_ACTION(C_GB2312)},
436 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
437 CODESET_ACTION(C_BIG5)},
438 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
439 CODESET_ACTION(C_EUC_TW)},
440 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
441 CODESET_ACTION(C_ISO_2022_CN)},
443 {N_("/_View/_Code set/Korean (EUC-_KR)"),
444 CODESET_ACTION(C_EUC_KR)},
445 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
446 CODESET_ACTION(C_ISO_2022_KR)},
449 #undef CODESET_SEPARATOR
450 #undef CODESET_ACTION
452 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
453 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
454 {N_("/_Message/Receive from _all accounts"),
455 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
456 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
457 {N_("/_Message/Send queued messa_ges"),
458 NULL, send_queue_cb, 0, NULL},
459 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
460 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
461 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
462 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
463 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
464 {N_("/_Message/Forward as an a_ttachment"),
465 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
466 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
467 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
468 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
469 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
470 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
471 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
472 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
473 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
474 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
475 {N_("/_Message/_Mark/Mark it as _being read"),
476 NULL, mark_as_read_cb, 0, NULL},
477 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
478 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
479 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
480 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
481 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
483 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
484 {N_("/_Summary/_Delete duplicated messages"),
485 NULL, delete_duplicated_cb, 0, NULL},
486 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
487 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
488 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
489 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
490 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
491 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
492 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
493 {N_("/_Summary/Prev marked message"), NULL, prev_marked_cb, 0, NULL},
494 {N_("/_Summary/Next marked message"), NULL, next_marked_cb, 0, NULL},
495 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
496 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
497 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
498 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
499 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
500 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
501 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
502 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
503 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
504 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_Summary/_Sort/_Attract by subject"),
506 NULL, attract_by_subject_cb, 0, NULL},
507 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
508 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
509 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
511 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
512 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
513 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
515 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
516 {N_("/_Configuration/_Common preferences..."),
517 NULL, prefs_common_open_cb, 0, NULL},
518 {N_("/_Configuration/_Filter setting..."),
519 NULL, prefs_filter_open_cb, 0, NULL},
520 {N_("/_Configuration/_Preferences per account..."),
521 NULL, prefs_account_open_cb, 0, NULL},
522 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Configuration/Create _new account..."),
524 NULL, new_account_cb, 0, NULL},
525 {N_("/_Configuration/_Edit accounts..."),
526 NULL, account_edit_open, 0, NULL},
527 {N_("/_Configuration/C_hange current account"),
528 NULL, NULL, 0, "<Branch>"},
530 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
531 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
532 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
533 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
534 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
538 MainWindow *main_window_create(SeparateType type)
544 GtkWidget *handlebox;
545 GtkWidget *vbox_body;
546 GtkWidget *hbox_stat;
547 GtkWidget *statusbar;
548 GtkWidget *ac_button;
551 FolderView *folderview;
552 SummaryView *summaryview;
553 MessageView *messageview;
554 GdkColormap *colormap;
557 guint n_menu_entries;
558 GtkItemFactory *ifactory;
563 debug_print(_("Creating main window...\n"));
564 mainwin = g_new0(MainWindow, 1);
567 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
568 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
569 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
570 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
571 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
572 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
573 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
574 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
575 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
576 gtk_widget_realize(window);
578 vbox = gtk_vbox_new(FALSE, 0);
579 gtk_widget_show(vbox);
580 gtk_container_add(GTK_CONTAINER(window), vbox);
583 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
584 menubar = menubar_create(window, mainwin_entries,
585 n_menu_entries, "<Main>", mainwin);
586 gtk_widget_show(menubar);
587 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
589 handlebox = gtk_handle_box_new();
590 gtk_widget_show(handlebox);
591 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
593 main_window_toolbar_create(mainwin, handlebox);
595 /* vbox that contains body */
596 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
597 gtk_widget_show(vbox_body);
598 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
599 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
601 hbox_stat = gtk_hbox_new(FALSE, 2);
602 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
604 statusbar = statusbar_create();
605 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
607 ac_button = gtk_button_new();
608 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
609 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
610 gtk_widget_set_usize(ac_button, -1, 1);
611 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
612 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
613 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
615 ac_label = gtk_label_new("");
616 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
618 gtk_widget_show_all(hbox_stat);
621 mainwin->folderview = folderview = folderview_create();
622 mainwin->summaryview = summaryview = summary_create();
623 mainwin->messageview = messageview = messageview_create();
624 mainwin->headerwin = header_window_create();
625 mainwin->logwin = log_window_create();
627 folderview->mainwin = mainwin;
628 folderview->summaryview = summaryview;
630 summaryview->mainwin = mainwin;
631 summaryview->folderview = folderview;
632 summaryview->messageview = messageview;
633 summaryview->headerwin = mainwin->headerwin;
634 summaryview->window = window;
636 messageview->mainwin = mainwin;
638 mainwin->window = window;
639 mainwin->vbox = vbox;
640 mainwin->menubar = menubar;
641 mainwin->handlebox = handlebox;
642 mainwin->vbox_body = vbox_body;
643 mainwin->hbox_stat = hbox_stat;
644 mainwin->statusbar = statusbar;
645 mainwin->ac_button = ac_button;
646 mainwin->ac_label = ac_label;
648 /* set context IDs for status bar */
649 mainwin->mainwin_cid = gtk_statusbar_get_context_id
650 (GTK_STATUSBAR(statusbar), "Main Window");
651 mainwin->folderview_cid = gtk_statusbar_get_context_id
652 (GTK_STATUSBAR(statusbar), "Folder View");
653 mainwin->summaryview_cid = gtk_statusbar_get_context_id
654 (GTK_STATUSBAR(statusbar), "Summary View");
656 /* allocate colors for summary view and folder view */
657 summaryview->color_marked.red = summaryview->color_marked.green = 0;
658 summaryview->color_marked.blue = (guint16)65535;
660 summaryview->color_dim.red = summaryview->color_dim.green =
661 summaryview->color_dim.blue = COLOR_DIM;
663 summaryview->color_normal.red = summaryview->color_normal.green =
664 summaryview->color_normal.blue = 0;
666 folderview->color_new.red = (guint16)55000;
667 folderview->color_new.green = folderview->color_new.blue = 15000;
669 folderview->color_normal.red = folderview->color_normal.green =
670 folderview->color_normal.blue = 0;
672 color[0] = summaryview->color_marked;
673 color[1] = summaryview->color_dim;
674 color[2] = summaryview->color_normal;
675 color[3] = folderview->color_new;
676 color[4] = folderview->color_normal;
678 colormap = gdk_window_get_colormap(window->window);
679 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
680 for (i = 0; i < 5; i++) {
681 if (success[i] == FALSE)
682 g_warning(_("MainWindow: color allocation %d failed\n"), i);
685 debug_print(_("done.\n"));
687 main_window_set_widgets(mainwin, type);
690 ifactory = gtk_item_factory_from_widget(menubar);
691 menuitem = gtk_item_factory_get_item
692 (ifactory, "/View/Code set/Auto detect");
693 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
695 switch (prefs_common.toolbar_style) {
697 menuitem = gtk_item_factory_get_item
698 (ifactory, "/View/Toolbar/Non-display");
701 menuitem = gtk_item_factory_get_item
702 (ifactory, "/View/Toolbar/Icon");
705 menuitem = gtk_item_factory_get_item
706 (ifactory, "/View/Toolbar/Text");
709 menuitem = gtk_item_factory_get_item
710 (ifactory, "/View/Toolbar/Icon and text");
712 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
714 gtk_widget_hide(mainwin->hbox_stat);
715 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
716 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
717 prefs_common.show_statusbar);
719 menu_set_sensitive(ifactory, "/Summary/Thread view",
720 prefs_common.enable_thread ? FALSE : TRUE);
721 menu_set_sensitive(ifactory, "/Summary/Unthread view",
722 prefs_common.enable_thread ? TRUE : FALSE);
723 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
725 /* set account selection menu */
726 ac_menu = gtk_item_factory_get_widget
727 (ifactory, "/Configuration/Change current account");
728 mainwin->ac_menu = ac_menu;
730 main_window_set_toolbar_sensitive(mainwin, FALSE);
732 /* show main window */
733 gtk_widget_set_uposition(mainwin->window,
734 prefs_common.mainwin_x,
735 prefs_common.mainwin_y);
736 gtk_widget_set_usize(window, prefs_common.mainwin_width,
737 prefs_common.mainwin_height);
738 gtk_widget_show(mainwin->window);
740 /* initialize views */
741 folderview_init(folderview);
742 summary_init(summaryview);
743 messageview_init(messageview);
744 header_window_init(mainwin->headerwin);
745 log_window_init(mainwin->logwin);
747 mainwin->cursor_count = 0;
750 watch_cursor = gdk_cursor_new(GDK_WATCH);
752 mainwin_list = g_list_append(mainwin_list, mainwin);
757 void main_window_cursor_wait(MainWindow *mainwin)
759 if (mainwin->cursor_count == 0)
760 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
762 mainwin->cursor_count++;
767 void main_window_cursor_normal(MainWindow *mainwin)
769 if (mainwin->cursor_count)
770 mainwin->cursor_count--;
772 if (mainwin->cursor_count == 0)
773 gdk_window_set_cursor(mainwin->window->window, NULL);
778 void main_window_reflect_prefs_all(void)
783 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
784 mainwin = (MainWindow *)cur->data;
786 main_window_show_cur_account(mainwin);
788 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
789 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
791 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
792 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
795 summary_change_display_item(mainwin->summaryview);
796 summary_redisplay_msg(mainwin->summaryview);
797 headerview_set_visibility(mainwin->messageview->headerview,
798 prefs_common.display_header_pane);
802 void main_window_set_account_menu(GList *account_list)
804 GList *cur, *cur_ac, *cur_item;
807 PrefsAccount *ac_prefs;
809 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
810 mainwin = (MainWindow *)cur->data;
812 /* destroy all previous menu item */
813 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
814 while (cur_item != NULL) {
815 GList *next = cur_item->next;
816 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
820 for (cur_ac = account_list; cur_ac != NULL;
821 cur_ac = cur_ac->next) {
822 ac_prefs = (PrefsAccount *)cur_ac->data;
824 menuitem = gtk_menu_item_new_with_label
825 (ac_prefs->account_name
826 ? ac_prefs->account_name : _("Untitled"));
827 gtk_widget_show(menuitem);
828 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
829 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
830 GTK_SIGNAL_FUNC(account_menu_cb),
836 static void main_window_show_cur_account(MainWindow *mainwin)
841 ac_name = g_strdup(cur_account
842 ? (cur_account->account_name
843 ? cur_account->account_name : _("Untitled"))
847 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
849 buf = g_strdup(PROG_VERSION);
850 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
853 buf = g_strdup_printf(_("Current account: %s"), ac_name);
854 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
855 gtk_widget_queue_resize(mainwin->ac_button);
861 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
863 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
864 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
865 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
867 if (mainwin->type == type) return;
869 /* remove widgets from those containers */
870 gtk_widget_ref(folder_wid);
871 gtk_widget_ref(summary_wid);
872 gtk_widget_ref(message_wid);
874 (GTK_CONTAINER(folder_wid->parent), folder_wid);
876 (GTK_CONTAINER(summary_wid->parent), summary_wid);
878 (GTK_CONTAINER(message_wid->parent), message_wid);
880 /* clean containers */
881 switch (mainwin->type) {
883 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
885 case SEPARATE_FOLDER:
886 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
887 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
889 case SEPARATE_MESSAGE:
890 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
891 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
894 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
895 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
899 gtk_widget_hide(mainwin->window);
900 main_window_set_widgets(mainwin, type);
901 gtk_widget_show(mainwin->window);
903 gtk_widget_unref(folder_wid);
904 gtk_widget_unref(summary_wid);
905 gtk_widget_unref(message_wid);
908 void main_window_get_size(MainWindow *mainwin)
910 GtkAllocation *allocation;
912 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
914 prefs_common.summaryview_width = allocation->width;
916 if (mainwin->summaryview->msg_is_toggled_on)
917 prefs_common.summaryview_height = allocation->height;
919 prefs_common.mainview_width = allocation->width;
921 allocation = &mainwin->window->allocation;
923 prefs_common.mainview_height = allocation->height;
924 prefs_common.mainwin_width = allocation->width;
925 prefs_common.mainwin_height = allocation->height;
927 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
929 prefs_common.folderview_width = allocation->width;
930 prefs_common.folderview_height = allocation->height;
933 void main_window_get_position(MainWindow *mainwin)
937 gtkut_widget_get_uposition(mainwin->window, &x, &y);
939 prefs_common.mainview_x = x;
940 prefs_common.mainview_y = y;
941 prefs_common.mainwin_x = x;
942 prefs_common.mainwin_y = y;
944 debug_print(_("window position: x = %d, y = %d\n"), x, y);
947 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
952 if (alertpanel(_("Empty trash"),
953 _("Empty all messages in trash?"),
954 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
956 manage_window_focus_in(mainwin->window, NULL, NULL);
959 procmsg_empty_trash();
961 for (list = folder_get_list(); list != NULL; list = list->next) {
966 folder_item_scan(folder->trash);
967 folderview_update_item(folder->trash, TRUE);
971 if (mainwin->summaryview->folder_item &&
972 mainwin->summaryview->folder_item->stype == F_TRASH)
973 gtk_widget_grab_focus(mainwin->folderview->ctree);
976 void main_window_add_mailbox(MainWindow *mainwin)
981 path = input_dialog(_("Add mailbox"),
982 _("Input the location of mailbox.\n"
983 "If the existing mailbox is specified, it will be\n"
984 "scanned automatically."),
987 if (folder_find_from_path(path)) {
988 alertpanel_error(_("The mailbox `%s' already exists."), path);
992 if (!strcmp(path, "Mail"))
993 folder = folder_new(F_MH, _("Mailbox"), path);
995 folder = folder_new(F_MH, g_basename(path), path);
998 if (folder->create_tree(folder) < 0) {
999 alertpanel_error(_("Creation of the mailbox failed.\n"
1000 "Maybe some files already exist, or you don't have the permission to write there."));
1001 folder_destroy(folder);
1006 folder_set_ui_func(folder, scan_tree_func, mainwin);
1007 folder->scan_tree(folder);
1008 folder_set_ui_func(folder, NULL, NULL);
1010 folderview_set(mainwin->folderview);
1013 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1015 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
1016 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1017 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1018 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1019 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1021 if (!mainwin->summaryview->folder_item ||
1022 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1023 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1025 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1028 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1030 GtkItemFactory *ifactory;
1034 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1036 if (selection == SUMMARY_SELECTED_SINGLE)
1040 if (!mainwin->summaryview->folder_item ||
1041 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1046 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1047 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1048 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1049 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1050 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1051 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1052 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1053 menu_set_sensitive(ifactory, "/Message/View source", sens);
1054 if (sens && (!mainwin->summaryview->folder_item ||
1055 mainwin->summaryview->folder_item->stype != F_DRAFT))
1057 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1059 if (selection == SUMMARY_SELECTED_SINGLE ||
1060 selection == SUMMARY_SELECTED_MULTIPLE)
1065 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1066 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1067 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1068 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1069 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1071 if (selection != SUMMARY_NONE)
1076 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1077 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1078 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1079 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1080 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1081 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1082 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1085 void main_window_popup(MainWindow *mainwin)
1091 gdk_window_get_origin(mainwin->window->window, &x, &y);
1092 sx = gdk_screen_width();
1093 sy = gdk_screen_height();
1094 x %= sx; if (x < 0) x += sx;
1095 y %= sy; if (y < 0) y += sy;
1096 gdk_window_move(mainwin->window->window, x, y);
1097 gdk_window_raise(mainwin->window->window);
1099 debug_print("window position: x = %d, y = %d\n", x, y);
1101 switch (mainwin->type) {
1102 case SEPARATE_FOLDER:
1103 widget = mainwin->win.sep_folder.folderwin;
1104 gdk_window_get_origin(widget->window, &x, &y);
1105 x %= sx; if (x < 0) x += sx;
1106 y %= sy; if (y < 0) y += sy;
1107 gdk_window_move(widget->window, x, y);
1108 gdk_window_raise(widget->window);
1110 case SEPARATE_MESSAGE:
1111 widget = mainwin->win.sep_message.messagewin;
1112 gdk_window_get_origin(widget->window, &x, &y);
1113 x %= sx; if (x < 0) x += sx;
1114 y %= sy; if (y < 0) y += sy;
1115 gdk_window_move(widget->window, x, y);
1116 gdk_window_raise(widget->window);
1119 widget = mainwin->win.sep_both.folderwin;
1120 gdk_window_get_origin(widget->window, &x, &y);
1121 x %= sx; if (x < 0) x += sx;
1122 y %= sy; if (y < 0) y += sy;
1123 gdk_window_move(widget->window, x, y);
1124 gdk_window_raise(widget->window);
1125 widget = mainwin->win.sep_both.messagewin;
1126 gdk_window_get_origin(widget->window, &x, &y);
1127 x %= sx; if (x < 0) x += sx;
1128 y %= sy; if (y < 0) y += sy;
1129 gdk_window_move(widget->window, x, y);
1130 gdk_window_raise(widget->window);
1136 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1138 GtkWidget *folderwin = NULL;
1139 GtkWidget *messagewin = NULL;
1142 GtkWidget *vbox_body = mainwin->vbox_body;
1144 debug_print(_("Setting widgets..."));
1146 /* create separated window(s) if needed */
1147 if (type & SEPARATE_FOLDER) {
1148 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1149 gtk_window_set_policy(GTK_WINDOW(folderwin),
1151 gtk_widget_set_usize(folderwin, -1,
1152 prefs_common.mainview_height);
1153 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1155 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1156 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1159 if (type & SEPARATE_MESSAGE) {
1160 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1161 gtk_window_set_policy(GTK_WINDOW(messagewin),
1163 gtk_widget_set_usize
1164 (messagewin, prefs_common.mainview_width,
1165 prefs_common.mainview_height
1166 - prefs_common.summaryview_height
1167 + DEFAULT_HEADERVIEW_HEIGHT);
1168 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1170 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1171 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1177 hpaned = gtk_hpaned_new();
1178 gtk_widget_show(hpaned);
1179 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1180 gtk_paned_add1(GTK_PANED(hpaned),
1181 GTK_WIDGET_PTR(mainwin->folderview));
1183 vpaned = gtk_vpaned_new();
1184 if (mainwin->summaryview->msg_is_toggled_on) {
1185 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1186 gtk_paned_add1(GTK_PANED(vpaned),
1187 GTK_WIDGET_PTR(mainwin->summaryview));
1189 gtk_paned_add2(GTK_PANED(hpaned),
1190 GTK_WIDGET_PTR(mainwin->summaryview));
1191 gtk_widget_ref(vpaned);
1193 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1194 prefs_common.summaryview_width,
1195 prefs_common.summaryview_height);
1196 gtk_paned_add2(GTK_PANED(vpaned),
1197 GTK_WIDGET_PTR(mainwin->messageview));
1198 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1199 prefs_common.mainview_width, -1);
1200 gtk_widget_set_usize(mainwin->window,
1201 prefs_common.folderview_width +
1202 prefs_common.mainview_width,
1203 prefs_common.mainwin_height);
1204 gtk_widget_show_all(vpaned);
1206 mainwin->win.sep_none.hpaned = hpaned;
1207 mainwin->win.sep_none.vpaned = vpaned;
1209 case SEPARATE_FOLDER:
1210 vpaned = gtk_vpaned_new();
1211 if (mainwin->summaryview->msg_is_toggled_on) {
1212 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1214 gtk_paned_add1(GTK_PANED(vpaned),
1215 GTK_WIDGET_PTR(mainwin->summaryview));
1217 gtk_box_pack_start(GTK_BOX(vbox_body),
1218 GTK_WIDGET_PTR(mainwin->summaryview),
1220 gtk_widget_ref(vpaned);
1222 gtk_paned_add2(GTK_PANED(vpaned),
1223 GTK_WIDGET_PTR(mainwin->messageview));
1224 gtk_widget_show_all(vpaned);
1225 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1226 prefs_common.summaryview_width,
1227 prefs_common.summaryview_height);
1228 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1229 prefs_common.mainview_width, -1);
1230 gtk_widget_set_usize(mainwin->window,
1231 prefs_common.mainview_width,
1232 prefs_common.mainview_height);
1234 gtk_container_add(GTK_CONTAINER(folderwin),
1235 GTK_WIDGET_PTR(mainwin->folderview));
1237 mainwin->win.sep_folder.folderwin = folderwin;
1238 mainwin->win.sep_folder.vpaned = vpaned;
1240 gtk_widget_show_all(folderwin);
1242 case SEPARATE_MESSAGE:
1243 hpaned = gtk_hpaned_new();
1244 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1246 gtk_paned_add1(GTK_PANED(hpaned),
1247 GTK_WIDGET_PTR(mainwin->folderview));
1248 gtk_paned_add2(GTK_PANED(hpaned),
1249 GTK_WIDGET_PTR(mainwin->summaryview));
1250 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1251 prefs_common.summaryview_width,
1252 prefs_common.summaryview_height);
1253 gtk_widget_set_usize(mainwin->window,
1254 prefs_common.folderview_width +
1255 prefs_common.mainview_width,
1256 prefs_common.mainwin_height);
1257 gtk_widget_show_all(hpaned);
1258 gtk_container_add(GTK_CONTAINER(messagewin),
1259 GTK_WIDGET_PTR(mainwin->messageview));
1261 mainwin->win.sep_message.messagewin = messagewin;
1262 mainwin->win.sep_message.hpaned = hpaned;
1264 gtk_widget_show_all(messagewin);
1267 gtk_box_pack_start(GTK_BOX(vbox_body),
1268 GTK_WIDGET_PTR(mainwin->summaryview),
1270 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1271 prefs_common.summaryview_width,
1272 prefs_common.summaryview_height);
1273 gtk_widget_set_usize(mainwin->window,
1274 prefs_common.mainview_width,
1275 prefs_common.mainwin_height);
1276 gtk_container_add(GTK_CONTAINER(folderwin),
1277 GTK_WIDGET_PTR(mainwin->folderview));
1278 gtk_container_add(GTK_CONTAINER(messagewin),
1279 GTK_WIDGET_PTR(mainwin->messageview));
1281 mainwin->win.sep_both.folderwin = folderwin;
1282 mainwin->win.sep_both.messagewin = messagewin;
1284 gtk_widget_show_all(folderwin);
1285 gtk_widget_show_all(messagewin);
1289 mainwin->type = type;
1291 debug_print(_("done.\n"));
1294 #include "pixmaps/stock_mail_receive.xpm"
1295 #include "pixmaps/stock_mail_receive_all.xpm"
1296 #include "pixmaps/stock_mail_compose.xpm"
1297 #include "pixmaps/stock_mail_reply.xpm"
1298 #include "pixmaps/stock_mail_reply_to_all.xpm"
1299 #include "pixmaps/stock_mail_forward.xpm"
1300 #include "pixmaps/stock_mail_send.xpm"
1301 #include "pixmaps/stock_preferences.xpm"
1302 #include "pixmaps/stock_properties.xpm"
1303 #include "pixmaps/stock_down_arrow.xpm"
1304 #include "pixmaps/stock_close.xpm"
1305 #include "pixmaps/stock_exec.xpm"
1307 #define CREATE_TOOLBAR_ICON(xpm_d) \
1309 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1310 &container->style->white, \
1312 icon_wid = gtk_pixmap_new(icon, mask); \
1315 static void main_window_toolbar_create(MainWindow *mainwin,
1316 GtkWidget *container)
1321 GtkWidget *icon_wid;
1323 GtkWidget *getall_btn;
1324 GtkWidget *compose_btn;
1325 GtkWidget *reply_btn;
1326 GtkWidget *replyall_btn;
1328 GtkWidget *send_btn;
1329 GtkWidget *prefs_btn;
1330 GtkWidget *account_btn;
1331 GtkWidget *next_btn;
1332 GtkWidget *delete_btn;
1333 GtkWidget *exec_btn;
1335 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1337 gtk_container_add(GTK_CONTAINER(container), toolbar);
1338 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1339 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1340 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1341 GTK_TOOLBAR_SPACE_LINE);
1343 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1344 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1346 _("Incorporate new mail"),
1348 icon_wid, toolbar_inc_cb, mainwin);
1349 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1350 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1352 _("Incorporate new mail of all accounts"),
1358 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1360 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1361 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1363 _("Send queued message(s)"),
1369 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1371 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1372 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1374 _("Compose new message"),
1379 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1380 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1382 _("Reply to the message"),
1387 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1388 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1393 toolbar_reply_to_all_cb,
1395 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1396 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1398 _("Forward the message"),
1404 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1406 CREATE_TOOLBAR_ICON(stock_close_xpm);
1407 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1409 _("Delete the message"),
1415 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1416 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1418 _("Execute marked process"),
1424 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1426 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1427 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1429 _("Next unread message"),
1432 toolbar_next_unread_cb,
1435 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1437 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1438 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1440 _("Common preference"),
1445 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1446 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1448 _("Account setting"),
1453 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1454 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1457 mainwin->toolbar = toolbar;
1458 mainwin->get_btn = get_btn;
1459 mainwin->getall_btn = getall_btn;
1460 mainwin->compose_btn = compose_btn;
1461 mainwin->reply_btn = reply_btn;
1462 mainwin->replyall_btn = replyall_btn;
1463 mainwin->fwd_btn = fwd_btn;
1464 mainwin->send_btn = send_btn;
1465 mainwin->prefs_btn = prefs_btn;
1466 mainwin->account_btn = account_btn;
1467 mainwin->next_btn = next_btn;
1468 mainwin->delete_btn = delete_btn;
1469 mainwin->exec_btn = exec_btn;
1471 gtk_widget_show_all(toolbar);
1474 /* callback functions */
1476 static void toolbar_inc_cb (GtkWidget *widget,
1479 MainWindow *mainwin = (MainWindow *)data;
1481 inc_mail_cb(mainwin, 0, NULL);
1484 static void toolbar_inc_all_cb (GtkWidget *widget,
1487 MainWindow *mainwin = (MainWindow *)data;
1489 inc_all_account_mail_cb(mainwin, 0, NULL);
1492 static void toolbar_send_cb (GtkWidget *widget,
1495 MainWindow *mainwin = (MainWindow *)data;
1497 send_queue_cb(mainwin, 0, NULL);
1500 static void toolbar_compose_cb (GtkWidget *widget,
1503 MainWindow *mainwin = (MainWindow *)data;
1505 compose_cb(mainwin, 0, NULL);
1508 static void toolbar_reply_cb (GtkWidget *widget,
1511 MainWindow *mainwin = (MainWindow *)data;
1513 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1516 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1519 MainWindow *mainwin = (MainWindow *)data;
1521 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1524 static void toolbar_forward_cb (GtkWidget *widget,
1527 MainWindow *mainwin = (MainWindow *)data;
1529 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1532 static void toolbar_delete_cb (GtkWidget *widget,
1535 MainWindow *mainwin = (MainWindow *)data;
1537 summary_delete(mainwin->summaryview);
1540 static void toolbar_exec_cb (GtkWidget *widget,
1543 MainWindow *mainwin = (MainWindow *)data;
1545 summary_execute(mainwin->summaryview);
1548 static void toolbar_next_unread_cb (GtkWidget *widget,
1551 MainWindow *mainwin = (MainWindow *)data;
1553 next_unread_cb(mainwin, 0, NULL);
1556 static void toolbar_prefs_cb (GtkWidget *widget,
1559 prefs_common_open();
1562 static void toolbar_account_cb (GtkWidget *widget,
1565 MainWindow *mainwin = (MainWindow *)data;
1567 prefs_account_open_cb(mainwin, 0, NULL);
1570 static void toolbar_account_button_pressed(GtkWidget *widget,
1571 GdkEventButton *event,
1574 MainWindow *mainwin = (MainWindow *)data;
1577 if (event->button != 3) return;
1579 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1580 event->button, event->time);
1583 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1586 MainWindow *mainwin = (MainWindow *)data;
1590 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1591 event->button, event->time);
1594 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1597 app_exit_cb(data, 0, widget);
1602 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1605 main_window_add_mailbox(mainwin);
1608 static void update_folderview_cb(MainWindow *mainwin, guint action,
1611 summary_show(mainwin->summaryview, NULL, FALSE);
1612 folderview_update_all();
1615 static void new_folder_cb(MainWindow *mainwin, guint action,
1618 folderview_new_folder(mainwin->folderview);
1621 static void rename_folder_cb(MainWindow *mainwin, guint action,
1624 folderview_rename_folder(mainwin->folderview);
1627 static void delete_folder_cb(MainWindow *mainwin, guint action,
1630 folderview_delete_folder(mainwin->folderview);
1633 static void import_mbox_cb(MainWindow *mainwin, guint action,
1636 import_mbox(mainwin->summaryview->folder_item);
1639 static void export_mbox_cb(MainWindow *mainwin, guint action,
1642 export_mbox(mainwin->summaryview->folder_item);
1645 static void empty_trash_cb(MainWindow *mainwin, guint action,
1648 main_window_empty_trash(mainwin, TRUE);
1651 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1653 summary_save_as(mainwin->summaryview);
1656 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1658 summary_print(mainwin->summaryview);
1661 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1663 if (prefs_common.confirm_on_exit) {
1664 if (alertpanel(_("Exit"), _("Exit this program?"),
1665 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1667 manage_window_focus_in(mainwin->window, NULL, NULL);
1670 app_will_exit(widget, mainwin);
1673 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1676 switch (mainwin->type) {
1678 case SEPARATE_MESSAGE:
1680 case SEPARATE_FOLDER:
1681 if (GTK_CHECK_MENU_ITEM(widget)->active)
1682 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1684 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1687 if (GTK_CHECK_MENU_ITEM(widget)->active)
1688 gtk_widget_show(mainwin->win.sep_both.folderwin);
1690 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1695 static void toggle_message_cb(MainWindow *mainwin, guint action,
1698 switch (mainwin->type) {
1700 case SEPARATE_FOLDER:
1702 case SEPARATE_MESSAGE:
1703 if (GTK_CHECK_MENU_ITEM(widget)->active)
1704 gtk_widget_show(mainwin->win.sep_message.messagewin);
1706 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1709 if (GTK_CHECK_MENU_ITEM(widget)->active)
1710 gtk_widget_show(mainwin->win.sep_both.messagewin);
1712 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1717 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1720 switch ((ToolbarStyle)action) {
1722 gtk_widget_hide(mainwin->handlebox);
1724 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1728 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1732 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1737 if (action != TOOLBAR_NONE) {
1738 gtk_widget_show(mainwin->handlebox);
1739 gtk_widget_queue_resize(mainwin->handlebox);
1742 mainwin->toolbar_style = (ToolbarStyle)action;
1743 prefs_common.toolbar_style = (ToolbarStyle)action;
1746 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1749 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1750 gtk_widget_show(mainwin->hbox_stat);
1751 prefs_common.show_statusbar = TRUE;
1753 gtk_widget_hide(mainwin->hbox_stat);
1754 prefs_common.show_statusbar = FALSE;
1758 static void separate_widget_cb(MainWindow *mainwin, guint action,
1763 type = mainwin->type ^ action;
1764 main_window_separation_change(mainwin, type);
1766 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1767 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1770 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1773 addressbook_open(NULL);
1776 static void log_window_show_cb(MainWindow *mainwin, guint action,
1779 log_window_show(mainwin->logwin);
1782 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1787 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1790 inc_all_account_mail(mainwin);
1793 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1797 if (procmsg_send_queue() < 0)
1798 alertpanel_error(_("Sending queued message failed."));
1800 statusbar_pop_all();
1802 for (list = folder_get_list(); list != NULL; list = list->next) {
1805 folder = list->data;
1806 if (folder->queue) {
1807 folder_item_scan(folder->queue);
1808 folderview_update_item(folder->queue, TRUE);
1813 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1815 if (mainwin->summaryview->folder_item)
1816 compose_new(mainwin->summaryview->folder_item->folder->account);
1821 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1825 msginfo = gtk_ctree_node_get_row_data
1826 (GTK_CTREE(mainwin->summaryview->ctree),
1827 mainwin->summaryview->selected);
1829 if (!msginfo) return;
1833 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1835 case COMPOSE_REPLY_TO_ALL:
1836 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1838 case COMPOSE_FORWARD:
1839 compose_forward(msginfo, FALSE);
1841 case COMPOSE_FORWARD_AS_ATTACH:
1842 compose_forward(msginfo, TRUE);
1845 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1848 summary_set_marks_selected(mainwin->summaryview);
1851 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1853 summary_move_to(mainwin->summaryview);
1856 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1858 summary_copy_to(mainwin->summaryview);
1861 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1863 summary_delete(mainwin->summaryview);
1866 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1868 summary_open_msg(mainwin->summaryview);
1871 static void view_source_cb(MainWindow *mainwin, guint action,
1874 summary_view_source(mainwin->summaryview);
1877 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1879 summary_reedit(mainwin->summaryview);
1882 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1884 summary_mark(mainwin->summaryview);
1887 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1889 summary_unmark(mainwin->summaryview);
1892 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1895 summary_mark_as_unread(mainwin->summaryview);
1898 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1901 summary_mark_as_read(mainwin->summaryview);
1904 static void set_charset_cb(MainWindow *mainwin, guint action,
1909 str = conv_get_charset_str((CharSet)action);
1910 g_free(prefs_common.force_charset);
1911 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1913 summary_redisplay_msg(mainwin->summaryview);
1915 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1918 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1920 GtkItemFactory *ifactory;
1922 ifactory = gtk_item_factory_from_widget(widget);
1925 summary_thread_build(mainwin->summaryview);
1926 prefs_common.enable_thread = TRUE;
1927 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1928 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1930 summary_unthread(mainwin->summaryview);
1931 prefs_common.enable_thread = FALSE;
1932 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1933 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1937 static void set_display_item_cb(MainWindow *mainwin, guint action,
1940 prefs_summary_display_item_set();
1943 static void sort_summary_cb(MainWindow *mainwin, guint action,
1946 summary_sort(mainwin->summaryview, (SummarySortType)action);
1949 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1952 summary_attract_by_subject(mainwin->summaryview);
1955 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1958 summary_delete_duplicated(mainwin->summaryview);
1961 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1963 summary_filter(mainwin->summaryview);
1966 static void execute_summary_cb(MainWindow *mainwin, guint action,
1969 summary_execute(mainwin->summaryview);
1972 static void update_summary_cb(MainWindow *mainwin, guint action,
1976 FolderView *folderview = mainwin->folderview;
1978 if (!mainwin->summaryview->folder_item) return;
1979 if (!folderview->opened) return;
1981 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1982 folderview->opened);
1985 summary_show(mainwin->summaryview, fitem, TRUE);
1988 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1990 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1993 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1995 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
1998 static void next_unread_cb(MainWindow *mainwin, guint action,
2001 summary_select_next_unread(mainwin->summaryview);
2004 static void next_marked_cb(MainWindow *mainwin, guint action,
2007 summary_select_next_marked(mainwin->summaryview);
2010 static void prev_marked_cb(MainWindow *mainwin, guint action,
2013 summary_select_prev_marked(mainwin->summaryview);
2016 static void goto_folder_cb(MainWindow *mainwin, guint action,
2019 FolderItem *to_folder;
2021 to_folder = foldersel_folder_sel(NULL);
2024 folderview_select(mainwin->folderview, to_folder);
2027 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2029 messageview_copy_clipboard(mainwin->messageview);
2032 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2034 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2035 summary_select_all(mainwin->summaryview);
2036 else if (mainwin->summaryview->msg_is_toggled_on &&
2037 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2038 messageview_select_all(mainwin->messageview);
2041 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2044 prefs_common_open();
2047 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2050 prefs_filter_open();
2053 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2057 new_account_cb(mainwin, 0, widget);
2059 gboolean prev_default = cur_account->is_default;
2061 prefs_account_open(cur_account);
2062 if (!prev_default && cur_account->is_default)
2063 account_set_as_default(cur_account);
2064 account_save_config_all();
2066 main_window_reflect_prefs_all();
2070 static void new_account_cb(MainWindow *mainwin, guint action,
2073 account_edit_open();
2074 if (!compose_get_compose_list()) account_add();
2077 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2079 cur_account = (PrefsAccount *)data;
2080 main_window_reflect_prefs_all();
2083 static void manual_open_cb(MainWindow *mainwin, guint action,
2086 manual_open((ManualLang)action);
2089 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2091 MainWindow *mainwin = (MainWindow *)data;
2095 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2096 LOCAL_FOLDER(folder)->rootpath,
2100 str = g_strdup_printf(_("Scanning folder %s ..."),
2101 LOCAL_FOLDER(folder)->rootpath);
2103 STATUSBAR_PUSH(mainwin, str);
2104 STATUSBAR_POP(mainwin);