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_matcher_open_cb (MainWindow *mainwin,
324 static void prefs_account_open_cb(MainWindow *mainwin,
327 static void new_account_cb (MainWindow *mainwin,
331 static void account_menu_cb (GtkMenuItem *menuitem,
334 static void manual_open_cb (MainWindow *mainwin,
338 static void scan_tree_func (Folder *folder,
342 static GtkItemFactoryEntry mainwin_entries[] =
344 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
345 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
346 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
347 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
348 {N_("/_File/_Folder/Create _new folder..."),
349 NULL, new_folder_cb, 0, NULL},
350 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
351 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
352 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
353 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
354 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
355 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
356 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
357 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
358 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
359 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
360 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
362 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
363 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
364 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
365 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
366 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
368 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
369 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
370 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
371 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
372 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
373 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
374 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
375 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
376 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
377 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
378 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
379 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
380 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
381 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
382 {N_("/_View/_Code set/_Auto detect"),
383 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
385 #define CODESET_SEPARATOR \
386 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
387 #define CODESET_ACTION(action) \
388 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
390 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
391 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
392 CODESET_ACTION(C_US_ASCII)},
395 {N_("/_View/_Code set/Unicode (_UTF-8)"),
396 CODESET_ACTION(C_UTF_8)},
399 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
400 CODESET_ACTION(C_ISO_8859_1)},
403 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
404 CODESET_ACTION(C_ISO_8859_2)},
406 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
407 CODESET_ACTION(C_ISO_8859_13)},
408 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
409 CODESET_ACTION(C_ISO_8859_4)},
411 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
412 CODESET_ACTION(C_ISO_8859_7)},
414 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
415 CODESET_ACTION(C_ISO_8859_9)},
417 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
418 CODESET_ACTION(C_ISO_8859_5)},
419 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
420 CODESET_ACTION(C_KOI8_R)},
421 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
422 CODESET_ACTION(C_CP1251)},
425 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
426 CODESET_ACTION(C_ISO_2022_JP)},
428 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
429 CODESET_ACTION(C_ISO_2022_JP_2)},
431 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
432 CODESET_ACTION(C_EUC_JP)},
433 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
434 CODESET_ACTION(C_SHIFT_JIS)},
437 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
438 CODESET_ACTION(C_GB2312)},
439 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
440 CODESET_ACTION(C_BIG5)},
441 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
442 CODESET_ACTION(C_EUC_TW)},
443 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
444 CODESET_ACTION(C_ISO_2022_CN)},
446 {N_("/_View/_Code set/Korean (EUC-_KR)"),
447 CODESET_ACTION(C_EUC_KR)},
448 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
449 CODESET_ACTION(C_ISO_2022_KR)},
452 #undef CODESET_SEPARATOR
453 #undef CODESET_ACTION
455 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
456 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
457 {N_("/_Message/Receive from _all accounts"),
458 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
459 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
460 {N_("/_Message/Send queued messa_ges"),
461 NULL, send_queue_cb, 0, NULL},
462 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
463 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
464 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
465 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
466 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
467 {N_("/_Message/Forward as an a_ttachment"),
468 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
471 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
472 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
473 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
474 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
475 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
476 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
477 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
478 {N_("/_Message/_Mark/Mark it as _being read"),
479 NULL, mark_as_read_cb, 0, NULL},
480 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
481 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
482 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
483 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
484 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
486 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
487 {N_("/_Summary/_Delete duplicated messages"),
488 NULL, delete_duplicated_cb, 0, NULL},
489 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
490 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
491 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
492 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
493 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
494 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
495 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
496 {N_("/_Summary/Prev marked message"), NULL, prev_marked_cb, 0, NULL},
497 {N_("/_Summary/Next marked message"), NULL, next_marked_cb, 0, NULL},
498 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
499 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
500 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
501 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
502 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
503 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
504 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
505 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
506 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
507 {N_("/_Summary/_Sort/Sort by sco_re"), NULL, sort_summary_cb, SORT_BY_SCORE, NULL},
508 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
509 {N_("/_Summary/_Sort/_Attract by subject"),
510 NULL, attract_by_subject_cb, 0, NULL},
511 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
512 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
513 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
515 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
516 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
517 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
519 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
520 {N_("/_Configuration/_Common preferences..."),
521 NULL, prefs_common_open_cb, 0, NULL},
522 {N_("/_Configuration/_Filter setting..."),
523 NULL, prefs_filter_open_cb, 0, NULL},
524 {N_("/_Configuration/_Scoring ..."),
525 NULL, prefs_matcher_open_cb, 0, NULL},
526 {N_("/_Configuration/_Preferences per account..."),
527 NULL, prefs_account_open_cb, 0, NULL},
528 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Configuration/Create _new account..."),
530 NULL, new_account_cb, 0, NULL},
531 {N_("/_Configuration/_Edit accounts..."),
532 NULL, account_edit_open, 0, NULL},
533 {N_("/_Configuration/C_hange current account"),
534 NULL, NULL, 0, "<Branch>"},
536 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
537 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
538 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
539 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
540 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
541 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
544 MainWindow *main_window_create(SeparateType type)
550 GtkWidget *handlebox;
551 GtkWidget *vbox_body;
552 GtkWidget *hbox_stat;
553 GtkWidget *statusbar;
554 GtkWidget *ac_button;
557 FolderView *folderview;
558 SummaryView *summaryview;
559 MessageView *messageview;
560 GdkColormap *colormap;
563 guint n_menu_entries;
564 GtkItemFactory *ifactory;
569 debug_print(_("Creating main window...\n"));
570 mainwin = g_new0(MainWindow, 1);
573 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
574 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
575 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
576 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
577 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
578 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
579 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
580 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
581 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
582 gtk_widget_realize(window);
584 vbox = gtk_vbox_new(FALSE, 0);
585 gtk_widget_show(vbox);
586 gtk_container_add(GTK_CONTAINER(window), vbox);
589 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
590 menubar = menubar_create(window, mainwin_entries,
591 n_menu_entries, "<Main>", mainwin);
592 gtk_widget_show(menubar);
593 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
595 handlebox = gtk_handle_box_new();
596 gtk_widget_show(handlebox);
597 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
599 main_window_toolbar_create(mainwin, handlebox);
601 /* vbox that contains body */
602 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
603 gtk_widget_show(vbox_body);
604 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
605 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
607 hbox_stat = gtk_hbox_new(FALSE, 2);
608 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
610 statusbar = statusbar_create();
611 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
613 ac_button = gtk_button_new();
614 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
615 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
616 gtk_widget_set_usize(ac_button, -1, 1);
617 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
618 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
619 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
621 ac_label = gtk_label_new("");
622 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
624 gtk_widget_show_all(hbox_stat);
627 mainwin->folderview = folderview = folderview_create();
628 mainwin->summaryview = summaryview = summary_create();
629 mainwin->messageview = messageview = messageview_create();
630 mainwin->headerwin = header_window_create();
631 mainwin->logwin = log_window_create();
633 folderview->mainwin = mainwin;
634 folderview->summaryview = summaryview;
636 summaryview->mainwin = mainwin;
637 summaryview->folderview = folderview;
638 summaryview->messageview = messageview;
639 summaryview->headerwin = mainwin->headerwin;
640 summaryview->window = window;
642 messageview->mainwin = mainwin;
644 mainwin->window = window;
645 mainwin->vbox = vbox;
646 mainwin->menubar = menubar;
647 mainwin->handlebox = handlebox;
648 mainwin->vbox_body = vbox_body;
649 mainwin->hbox_stat = hbox_stat;
650 mainwin->statusbar = statusbar;
651 mainwin->ac_button = ac_button;
652 mainwin->ac_label = ac_label;
654 /* set context IDs for status bar */
655 mainwin->mainwin_cid = gtk_statusbar_get_context_id
656 (GTK_STATUSBAR(statusbar), "Main Window");
657 mainwin->folderview_cid = gtk_statusbar_get_context_id
658 (GTK_STATUSBAR(statusbar), "Folder View");
659 mainwin->summaryview_cid = gtk_statusbar_get_context_id
660 (GTK_STATUSBAR(statusbar), "Summary View");
662 /* allocate colors for summary view and folder view */
663 summaryview->color_marked.red = summaryview->color_marked.green = 0;
664 summaryview->color_marked.blue = (guint16)65535;
666 summaryview->color_dim.red = summaryview->color_dim.green =
667 summaryview->color_dim.blue = COLOR_DIM;
669 summaryview->color_normal.red = summaryview->color_normal.green =
670 summaryview->color_normal.blue = 0;
672 folderview->color_new.red = (guint16)55000;
673 folderview->color_new.green = folderview->color_new.blue = 15000;
675 folderview->color_normal.red = folderview->color_normal.green =
676 folderview->color_normal.blue = 0;
678 color[0] = summaryview->color_marked;
679 color[1] = summaryview->color_dim;
680 color[2] = summaryview->color_normal;
681 color[3] = folderview->color_new;
682 color[4] = folderview->color_normal;
684 colormap = gdk_window_get_colormap(window->window);
685 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
686 for (i = 0; i < 5; i++) {
687 if (success[i] == FALSE)
688 g_warning(_("MainWindow: color allocation %d failed\n"), i);
691 debug_print(_("done.\n"));
693 main_window_set_widgets(mainwin, type);
696 ifactory = gtk_item_factory_from_widget(menubar);
697 menuitem = gtk_item_factory_get_item
698 (ifactory, "/View/Code set/Auto detect");
699 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
701 switch (prefs_common.toolbar_style) {
703 menuitem = gtk_item_factory_get_item
704 (ifactory, "/View/Toolbar/Non-display");
707 menuitem = gtk_item_factory_get_item
708 (ifactory, "/View/Toolbar/Icon");
711 menuitem = gtk_item_factory_get_item
712 (ifactory, "/View/Toolbar/Text");
715 menuitem = gtk_item_factory_get_item
716 (ifactory, "/View/Toolbar/Icon and text");
718 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
720 gtk_widget_hide(mainwin->hbox_stat);
721 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
722 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
723 prefs_common.show_statusbar);
725 menu_set_sensitive(ifactory, "/Summary/Thread view",
726 prefs_common.enable_thread ? FALSE : TRUE);
727 menu_set_sensitive(ifactory, "/Summary/Unthread view",
728 prefs_common.enable_thread ? TRUE : FALSE);
729 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
731 /* set account selection menu */
732 ac_menu = gtk_item_factory_get_widget
733 (ifactory, "/Configuration/Change current account");
734 mainwin->ac_menu = ac_menu;
736 main_window_set_toolbar_sensitive(mainwin, FALSE);
738 /* show main window */
739 gtk_widget_set_uposition(mainwin->window,
740 prefs_common.mainwin_x,
741 prefs_common.mainwin_y);
742 gtk_widget_set_usize(window, prefs_common.mainwin_width,
743 prefs_common.mainwin_height);
744 gtk_widget_show(mainwin->window);
746 /* initialize views */
747 folderview_init(folderview);
748 summary_init(summaryview);
749 messageview_init(messageview);
750 header_window_init(mainwin->headerwin);
751 log_window_init(mainwin->logwin);
753 mainwin->cursor_count = 0;
756 watch_cursor = gdk_cursor_new(GDK_WATCH);
758 mainwin_list = g_list_append(mainwin_list, mainwin);
763 void main_window_cursor_wait(MainWindow *mainwin)
765 if (mainwin->cursor_count == 0)
766 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
768 mainwin->cursor_count++;
773 void main_window_cursor_normal(MainWindow *mainwin)
775 if (mainwin->cursor_count)
776 mainwin->cursor_count--;
778 if (mainwin->cursor_count == 0)
779 gdk_window_set_cursor(mainwin->window->window, NULL);
784 void main_window_reflect_prefs_all(void)
789 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
790 mainwin = (MainWindow *)cur->data;
792 main_window_show_cur_account(mainwin);
794 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
795 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
797 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
798 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
801 summary_change_display_item(mainwin->summaryview);
802 summary_redisplay_msg(mainwin->summaryview);
803 headerview_set_visibility(mainwin->messageview->headerview,
804 prefs_common.display_header_pane);
808 void main_window_set_account_menu(GList *account_list)
810 GList *cur, *cur_ac, *cur_item;
813 PrefsAccount *ac_prefs;
815 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
816 mainwin = (MainWindow *)cur->data;
818 /* destroy all previous menu item */
819 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
820 while (cur_item != NULL) {
821 GList *next = cur_item->next;
822 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
826 for (cur_ac = account_list; cur_ac != NULL;
827 cur_ac = cur_ac->next) {
828 ac_prefs = (PrefsAccount *)cur_ac->data;
830 menuitem = gtk_menu_item_new_with_label
831 (ac_prefs->account_name
832 ? ac_prefs->account_name : _("Untitled"));
833 gtk_widget_show(menuitem);
834 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
835 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
836 GTK_SIGNAL_FUNC(account_menu_cb),
842 static void main_window_show_cur_account(MainWindow *mainwin)
847 ac_name = g_strdup(cur_account
848 ? (cur_account->account_name
849 ? cur_account->account_name : _("Untitled"))
853 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
855 buf = g_strdup(PROG_VERSION);
856 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
859 buf = g_strdup_printf(_("Current account: %s"), ac_name);
860 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
861 gtk_widget_queue_resize(mainwin->ac_button);
867 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
869 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
870 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
871 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
873 if (mainwin->type == type) return;
875 /* remove widgets from those containers */
876 gtk_widget_ref(folder_wid);
877 gtk_widget_ref(summary_wid);
878 gtk_widget_ref(message_wid);
880 (GTK_CONTAINER(folder_wid->parent), folder_wid);
882 (GTK_CONTAINER(summary_wid->parent), summary_wid);
884 (GTK_CONTAINER(message_wid->parent), message_wid);
886 /* clean containers */
887 switch (mainwin->type) {
889 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
891 case SEPARATE_FOLDER:
892 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
893 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
895 case SEPARATE_MESSAGE:
896 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
897 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
900 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
901 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
905 gtk_widget_hide(mainwin->window);
906 main_window_set_widgets(mainwin, type);
907 gtk_widget_show(mainwin->window);
909 gtk_widget_unref(folder_wid);
910 gtk_widget_unref(summary_wid);
911 gtk_widget_unref(message_wid);
914 void main_window_get_size(MainWindow *mainwin)
916 GtkAllocation *allocation;
918 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
920 prefs_common.summaryview_width = allocation->width;
922 if (mainwin->summaryview->msg_is_toggled_on)
923 prefs_common.summaryview_height = allocation->height;
925 prefs_common.mainview_width = allocation->width;
927 allocation = &mainwin->window->allocation;
929 prefs_common.mainview_height = allocation->height;
930 prefs_common.mainwin_width = allocation->width;
931 prefs_common.mainwin_height = allocation->height;
933 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
935 prefs_common.folderview_width = allocation->width;
936 prefs_common.folderview_height = allocation->height;
939 void main_window_get_position(MainWindow *mainwin)
943 gtkut_widget_get_uposition(mainwin->window, &x, &y);
945 prefs_common.mainview_x = x;
946 prefs_common.mainview_y = y;
947 prefs_common.mainwin_x = x;
948 prefs_common.mainwin_y = y;
950 debug_print(_("window position: x = %d, y = %d\n"), x, y);
953 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
958 if (alertpanel(_("Empty trash"),
959 _("Empty all messages in trash?"),
960 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
962 manage_window_focus_in(mainwin->window, NULL, NULL);
965 procmsg_empty_trash();
967 for (list = folder_get_list(); list != NULL; list = list->next) {
972 folder_item_scan(folder->trash);
973 folderview_update_item(folder->trash, TRUE);
977 if (mainwin->summaryview->folder_item &&
978 mainwin->summaryview->folder_item->stype == F_TRASH)
979 gtk_widget_grab_focus(mainwin->folderview->ctree);
982 void main_window_add_mailbox(MainWindow *mainwin)
987 path = input_dialog(_("Add mailbox"),
988 _("Input the location of mailbox.\n"
989 "If the existing mailbox is specified, it will be\n"
990 "scanned automatically."),
993 if (folder_find_from_path(path)) {
994 alertpanel_error(_("The mailbox `%s' already exists."), path);
998 if (!strcmp(path, "Mail"))
999 folder = folder_new(F_MH, _("Mailbox"), path);
1001 folder = folder_new(F_MH, g_basename(path), path);
1004 if (folder->create_tree(folder) < 0) {
1005 alertpanel_error(_("Creation of the mailbox failed.\n"
1006 "Maybe some files already exist, or you don't have the permission to write there."));
1007 folder_destroy(folder);
1012 folder_set_ui_func(folder, scan_tree_func, mainwin);
1013 folder->scan_tree(folder);
1014 folder_set_ui_func(folder, NULL, NULL);
1016 folderview_set(mainwin->folderview);
1019 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1021 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
1022 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1023 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1024 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1025 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1027 if (!mainwin->summaryview->folder_item ||
1028 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1029 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1031 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1034 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1036 GtkItemFactory *ifactory;
1040 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1042 if (selection == SUMMARY_SELECTED_SINGLE)
1046 if (!mainwin->summaryview->folder_item ||
1047 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1052 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1053 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1054 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1055 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1056 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1057 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1058 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1059 menu_set_sensitive(ifactory, "/Message/View source", sens);
1060 if (sens && (!mainwin->summaryview->folder_item ||
1061 mainwin->summaryview->folder_item->stype != F_DRAFT))
1063 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1065 if (selection == SUMMARY_SELECTED_SINGLE ||
1066 selection == SUMMARY_SELECTED_MULTIPLE)
1071 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1072 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1073 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1074 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1075 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1077 if (selection != SUMMARY_NONE)
1082 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1083 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1084 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1085 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1086 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1087 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1088 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1091 void main_window_popup(MainWindow *mainwin)
1097 gdk_window_get_origin(mainwin->window->window, &x, &y);
1098 sx = gdk_screen_width();
1099 sy = gdk_screen_height();
1100 x %= sx; if (x < 0) x += sx;
1101 y %= sy; if (y < 0) y += sy;
1102 gdk_window_move(mainwin->window->window, x, y);
1103 gdk_window_raise(mainwin->window->window);
1105 debug_print("window position: x = %d, y = %d\n", x, y);
1107 switch (mainwin->type) {
1108 case SEPARATE_FOLDER:
1109 widget = mainwin->win.sep_folder.folderwin;
1110 gdk_window_get_origin(widget->window, &x, &y);
1111 x %= sx; if (x < 0) x += sx;
1112 y %= sy; if (y < 0) y += sy;
1113 gdk_window_move(widget->window, x, y);
1114 gdk_window_raise(widget->window);
1116 case SEPARATE_MESSAGE:
1117 widget = mainwin->win.sep_message.messagewin;
1118 gdk_window_get_origin(widget->window, &x, &y);
1119 x %= sx; if (x < 0) x += sx;
1120 y %= sy; if (y < 0) y += sy;
1121 gdk_window_move(widget->window, x, y);
1122 gdk_window_raise(widget->window);
1125 widget = mainwin->win.sep_both.folderwin;
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);
1131 widget = mainwin->win.sep_both.messagewin;
1132 gdk_window_get_origin(widget->window, &x, &y);
1133 x %= sx; if (x < 0) x += sx;
1134 y %= sy; if (y < 0) y += sy;
1135 gdk_window_move(widget->window, x, y);
1136 gdk_window_raise(widget->window);
1142 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1144 GtkWidget *folderwin = NULL;
1145 GtkWidget *messagewin = NULL;
1148 GtkWidget *vbox_body = mainwin->vbox_body;
1150 debug_print(_("Setting widgets..."));
1152 /* create separated window(s) if needed */
1153 if (type & SEPARATE_FOLDER) {
1154 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1155 gtk_window_set_policy(GTK_WINDOW(folderwin),
1157 gtk_widget_set_usize(folderwin, -1,
1158 prefs_common.mainview_height);
1159 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1161 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1162 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1165 if (type & SEPARATE_MESSAGE) {
1166 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1167 gtk_window_set_policy(GTK_WINDOW(messagewin),
1169 gtk_widget_set_usize
1170 (messagewin, prefs_common.mainview_width,
1171 prefs_common.mainview_height
1172 - prefs_common.summaryview_height
1173 + DEFAULT_HEADERVIEW_HEIGHT);
1174 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1176 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1177 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1183 hpaned = gtk_hpaned_new();
1184 gtk_widget_show(hpaned);
1185 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1186 gtk_paned_add1(GTK_PANED(hpaned),
1187 GTK_WIDGET_PTR(mainwin->folderview));
1189 vpaned = gtk_vpaned_new();
1190 if (mainwin->summaryview->msg_is_toggled_on) {
1191 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1192 gtk_paned_add1(GTK_PANED(vpaned),
1193 GTK_WIDGET_PTR(mainwin->summaryview));
1195 gtk_paned_add2(GTK_PANED(hpaned),
1196 GTK_WIDGET_PTR(mainwin->summaryview));
1197 gtk_widget_ref(vpaned);
1199 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1200 prefs_common.summaryview_width,
1201 prefs_common.summaryview_height);
1202 gtk_paned_add2(GTK_PANED(vpaned),
1203 GTK_WIDGET_PTR(mainwin->messageview));
1204 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1205 prefs_common.mainview_width, -1);
1206 gtk_widget_set_usize(mainwin->window,
1207 prefs_common.folderview_width +
1208 prefs_common.mainview_width,
1209 prefs_common.mainwin_height);
1210 gtk_widget_show_all(vpaned);
1212 mainwin->win.sep_none.hpaned = hpaned;
1213 mainwin->win.sep_none.vpaned = vpaned;
1215 case SEPARATE_FOLDER:
1216 vpaned = gtk_vpaned_new();
1217 if (mainwin->summaryview->msg_is_toggled_on) {
1218 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1220 gtk_paned_add1(GTK_PANED(vpaned),
1221 GTK_WIDGET_PTR(mainwin->summaryview));
1223 gtk_box_pack_start(GTK_BOX(vbox_body),
1224 GTK_WIDGET_PTR(mainwin->summaryview),
1226 gtk_widget_ref(vpaned);
1228 gtk_paned_add2(GTK_PANED(vpaned),
1229 GTK_WIDGET_PTR(mainwin->messageview));
1230 gtk_widget_show_all(vpaned);
1231 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1232 prefs_common.summaryview_width,
1233 prefs_common.summaryview_height);
1234 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1235 prefs_common.mainview_width, -1);
1236 gtk_widget_set_usize(mainwin->window,
1237 prefs_common.mainview_width,
1238 prefs_common.mainview_height);
1240 gtk_container_add(GTK_CONTAINER(folderwin),
1241 GTK_WIDGET_PTR(mainwin->folderview));
1243 mainwin->win.sep_folder.folderwin = folderwin;
1244 mainwin->win.sep_folder.vpaned = vpaned;
1246 gtk_widget_show_all(folderwin);
1248 case SEPARATE_MESSAGE:
1249 hpaned = gtk_hpaned_new();
1250 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1252 gtk_paned_add1(GTK_PANED(hpaned),
1253 GTK_WIDGET_PTR(mainwin->folderview));
1254 gtk_paned_add2(GTK_PANED(hpaned),
1255 GTK_WIDGET_PTR(mainwin->summaryview));
1256 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1257 prefs_common.summaryview_width,
1258 prefs_common.summaryview_height);
1259 gtk_widget_set_usize(mainwin->window,
1260 prefs_common.folderview_width +
1261 prefs_common.mainview_width,
1262 prefs_common.mainwin_height);
1263 gtk_widget_show_all(hpaned);
1264 gtk_container_add(GTK_CONTAINER(messagewin),
1265 GTK_WIDGET_PTR(mainwin->messageview));
1267 mainwin->win.sep_message.messagewin = messagewin;
1268 mainwin->win.sep_message.hpaned = hpaned;
1270 gtk_widget_show_all(messagewin);
1273 gtk_box_pack_start(GTK_BOX(vbox_body),
1274 GTK_WIDGET_PTR(mainwin->summaryview),
1276 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1277 prefs_common.summaryview_width,
1278 prefs_common.summaryview_height);
1279 gtk_widget_set_usize(mainwin->window,
1280 prefs_common.mainview_width,
1281 prefs_common.mainwin_height);
1282 gtk_container_add(GTK_CONTAINER(folderwin),
1283 GTK_WIDGET_PTR(mainwin->folderview));
1284 gtk_container_add(GTK_CONTAINER(messagewin),
1285 GTK_WIDGET_PTR(mainwin->messageview));
1287 mainwin->win.sep_both.folderwin = folderwin;
1288 mainwin->win.sep_both.messagewin = messagewin;
1290 gtk_widget_show_all(folderwin);
1291 gtk_widget_show_all(messagewin);
1295 mainwin->type = type;
1297 debug_print(_("done.\n"));
1300 #include "pixmaps/stock_mail_receive.xpm"
1301 #include "pixmaps/stock_mail_receive_all.xpm"
1302 #include "pixmaps/stock_mail_compose.xpm"
1303 #include "pixmaps/stock_mail_reply.xpm"
1304 #include "pixmaps/stock_mail_reply_to_all.xpm"
1305 #include "pixmaps/stock_mail_forward.xpm"
1306 #include "pixmaps/stock_mail_send.xpm"
1307 #include "pixmaps/stock_preferences.xpm"
1308 #include "pixmaps/stock_properties.xpm"
1309 #include "pixmaps/stock_down_arrow.xpm"
1310 #include "pixmaps/stock_close.xpm"
1311 #include "pixmaps/stock_exec.xpm"
1313 #define CREATE_TOOLBAR_ICON(xpm_d) \
1315 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1316 &container->style->white, \
1318 icon_wid = gtk_pixmap_new(icon, mask); \
1321 static void main_window_toolbar_create(MainWindow *mainwin,
1322 GtkWidget *container)
1327 GtkWidget *icon_wid;
1329 GtkWidget *getall_btn;
1330 GtkWidget *compose_btn;
1331 GtkWidget *reply_btn;
1332 GtkWidget *replyall_btn;
1334 GtkWidget *send_btn;
1335 GtkWidget *prefs_btn;
1336 GtkWidget *account_btn;
1337 GtkWidget *next_btn;
1338 GtkWidget *delete_btn;
1339 GtkWidget *exec_btn;
1341 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1343 gtk_container_add(GTK_CONTAINER(container), toolbar);
1344 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1345 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1346 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1347 GTK_TOOLBAR_SPACE_LINE);
1349 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1350 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1352 _("Incorporate new mail"),
1354 icon_wid, toolbar_inc_cb, mainwin);
1355 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1356 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1358 _("Incorporate new mail of all accounts"),
1364 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1366 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1367 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1369 _("Send queued message(s)"),
1375 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1377 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1378 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1380 _("Compose new message"),
1385 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1386 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1388 _("Reply to the message"),
1393 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1394 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1399 toolbar_reply_to_all_cb,
1401 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1402 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1404 _("Forward the message"),
1410 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1412 CREATE_TOOLBAR_ICON(stock_close_xpm);
1413 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1415 _("Delete the message"),
1421 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1422 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1424 _("Execute marked process"),
1430 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1432 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1433 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1435 _("Next unread message"),
1438 toolbar_next_unread_cb,
1441 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1443 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1444 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1446 _("Common preference"),
1451 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1452 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1454 _("Account setting"),
1459 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1460 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1463 mainwin->toolbar = toolbar;
1464 mainwin->get_btn = get_btn;
1465 mainwin->getall_btn = getall_btn;
1466 mainwin->compose_btn = compose_btn;
1467 mainwin->reply_btn = reply_btn;
1468 mainwin->replyall_btn = replyall_btn;
1469 mainwin->fwd_btn = fwd_btn;
1470 mainwin->send_btn = send_btn;
1471 mainwin->prefs_btn = prefs_btn;
1472 mainwin->account_btn = account_btn;
1473 mainwin->next_btn = next_btn;
1474 mainwin->delete_btn = delete_btn;
1475 mainwin->exec_btn = exec_btn;
1477 gtk_widget_show_all(toolbar);
1480 /* callback functions */
1482 static void toolbar_inc_cb (GtkWidget *widget,
1485 MainWindow *mainwin = (MainWindow *)data;
1487 inc_mail_cb(mainwin, 0, NULL);
1490 static void toolbar_inc_all_cb (GtkWidget *widget,
1493 MainWindow *mainwin = (MainWindow *)data;
1495 inc_all_account_mail_cb(mainwin, 0, NULL);
1498 static void toolbar_send_cb (GtkWidget *widget,
1501 MainWindow *mainwin = (MainWindow *)data;
1503 send_queue_cb(mainwin, 0, NULL);
1506 static void toolbar_compose_cb (GtkWidget *widget,
1509 MainWindow *mainwin = (MainWindow *)data;
1511 compose_cb(mainwin, 0, NULL);
1514 static void toolbar_reply_cb (GtkWidget *widget,
1517 MainWindow *mainwin = (MainWindow *)data;
1519 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1522 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1525 MainWindow *mainwin = (MainWindow *)data;
1527 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1530 static void toolbar_forward_cb (GtkWidget *widget,
1533 MainWindow *mainwin = (MainWindow *)data;
1535 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1538 static void toolbar_delete_cb (GtkWidget *widget,
1541 MainWindow *mainwin = (MainWindow *)data;
1543 summary_delete(mainwin->summaryview);
1546 static void toolbar_exec_cb (GtkWidget *widget,
1549 MainWindow *mainwin = (MainWindow *)data;
1551 summary_execute(mainwin->summaryview);
1554 static void toolbar_next_unread_cb (GtkWidget *widget,
1557 MainWindow *mainwin = (MainWindow *)data;
1559 next_unread_cb(mainwin, 0, NULL);
1562 static void toolbar_prefs_cb (GtkWidget *widget,
1565 prefs_common_open();
1568 static void toolbar_account_cb (GtkWidget *widget,
1571 MainWindow *mainwin = (MainWindow *)data;
1573 prefs_account_open_cb(mainwin, 0, NULL);
1576 static void toolbar_account_button_pressed(GtkWidget *widget,
1577 GdkEventButton *event,
1580 MainWindow *mainwin = (MainWindow *)data;
1583 if (event->button != 3) return;
1585 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1586 event->button, event->time);
1589 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1592 MainWindow *mainwin = (MainWindow *)data;
1596 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1597 event->button, event->time);
1600 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1603 app_exit_cb(data, 0, widget);
1608 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1611 main_window_add_mailbox(mainwin);
1614 static void update_folderview_cb(MainWindow *mainwin, guint action,
1617 summary_show(mainwin->summaryview, NULL, FALSE);
1618 folderview_update_all();
1621 static void new_folder_cb(MainWindow *mainwin, guint action,
1624 folderview_new_folder(mainwin->folderview);
1627 static void rename_folder_cb(MainWindow *mainwin, guint action,
1630 folderview_rename_folder(mainwin->folderview);
1633 static void delete_folder_cb(MainWindow *mainwin, guint action,
1636 folderview_delete_folder(mainwin->folderview);
1639 static void import_mbox_cb(MainWindow *mainwin, guint action,
1642 import_mbox(mainwin->summaryview->folder_item);
1645 static void export_mbox_cb(MainWindow *mainwin, guint action,
1648 export_mbox(mainwin->summaryview->folder_item);
1651 static void empty_trash_cb(MainWindow *mainwin, guint action,
1654 main_window_empty_trash(mainwin, TRUE);
1657 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1659 summary_save_as(mainwin->summaryview);
1662 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1664 summary_print(mainwin->summaryview);
1667 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1669 if (prefs_common.confirm_on_exit) {
1670 if (alertpanel(_("Exit"), _("Exit this program?"),
1671 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1673 manage_window_focus_in(mainwin->window, NULL, NULL);
1676 app_will_exit(widget, mainwin);
1679 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1682 switch (mainwin->type) {
1684 case SEPARATE_MESSAGE:
1686 case SEPARATE_FOLDER:
1687 if (GTK_CHECK_MENU_ITEM(widget)->active)
1688 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1690 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1693 if (GTK_CHECK_MENU_ITEM(widget)->active)
1694 gtk_widget_show(mainwin->win.sep_both.folderwin);
1696 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1701 static void toggle_message_cb(MainWindow *mainwin, guint action,
1704 switch (mainwin->type) {
1706 case SEPARATE_FOLDER:
1708 case SEPARATE_MESSAGE:
1709 if (GTK_CHECK_MENU_ITEM(widget)->active)
1710 gtk_widget_show(mainwin->win.sep_message.messagewin);
1712 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1715 if (GTK_CHECK_MENU_ITEM(widget)->active)
1716 gtk_widget_show(mainwin->win.sep_both.messagewin);
1718 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1723 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1726 switch ((ToolbarStyle)action) {
1728 gtk_widget_hide(mainwin->handlebox);
1730 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1734 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1738 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1743 if (action != TOOLBAR_NONE) {
1744 gtk_widget_show(mainwin->handlebox);
1745 gtk_widget_queue_resize(mainwin->handlebox);
1748 mainwin->toolbar_style = (ToolbarStyle)action;
1749 prefs_common.toolbar_style = (ToolbarStyle)action;
1752 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1755 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1756 gtk_widget_show(mainwin->hbox_stat);
1757 prefs_common.show_statusbar = TRUE;
1759 gtk_widget_hide(mainwin->hbox_stat);
1760 prefs_common.show_statusbar = FALSE;
1764 static void separate_widget_cb(MainWindow *mainwin, guint action,
1769 type = mainwin->type ^ action;
1770 main_window_separation_change(mainwin, type);
1772 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1773 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1776 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1779 addressbook_open(NULL);
1782 static void log_window_show_cb(MainWindow *mainwin, guint action,
1785 log_window_show(mainwin->logwin);
1788 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1793 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1796 inc_all_account_mail(mainwin);
1799 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1803 if (procmsg_send_queue() < 0)
1804 alertpanel_error(_("Sending queued message failed."));
1806 statusbar_pop_all();
1808 for (list = folder_get_list(); list != NULL; list = list->next) {
1811 folder = list->data;
1812 if (folder->queue) {
1813 folder_item_scan(folder->queue);
1814 folderview_update_item(folder->queue, TRUE);
1819 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1821 if (mainwin->summaryview->folder_item)
1822 compose_new(mainwin->summaryview->folder_item->folder->account);
1827 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1831 msginfo = gtk_ctree_node_get_row_data
1832 (GTK_CTREE(mainwin->summaryview->ctree),
1833 mainwin->summaryview->selected);
1835 if (!msginfo) return;
1839 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1841 case COMPOSE_REPLY_TO_ALL:
1842 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1844 case COMPOSE_FORWARD:
1845 compose_forward(msginfo, FALSE);
1847 case COMPOSE_FORWARD_AS_ATTACH:
1848 compose_forward(msginfo, TRUE);
1851 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1854 summary_set_marks_selected(mainwin->summaryview);
1857 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1859 summary_move_to(mainwin->summaryview);
1862 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1864 summary_copy_to(mainwin->summaryview);
1867 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1869 summary_delete(mainwin->summaryview);
1872 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1874 summary_open_msg(mainwin->summaryview);
1877 static void view_source_cb(MainWindow *mainwin, guint action,
1880 summary_view_source(mainwin->summaryview);
1883 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1885 summary_reedit(mainwin->summaryview);
1888 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1890 summary_mark(mainwin->summaryview);
1893 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1895 summary_unmark(mainwin->summaryview);
1898 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1901 summary_mark_as_unread(mainwin->summaryview);
1904 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1907 summary_mark_as_read(mainwin->summaryview);
1910 static void set_charset_cb(MainWindow *mainwin, guint action,
1915 str = conv_get_charset_str((CharSet)action);
1916 g_free(prefs_common.force_charset);
1917 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1919 summary_redisplay_msg(mainwin->summaryview);
1921 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1924 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1926 GtkItemFactory *ifactory;
1928 ifactory = gtk_item_factory_from_widget(widget);
1931 summary_thread_build(mainwin->summaryview);
1932 prefs_common.enable_thread = TRUE;
1933 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1934 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1936 summary_unthread(mainwin->summaryview);
1937 prefs_common.enable_thread = FALSE;
1938 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1939 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1943 static void set_display_item_cb(MainWindow *mainwin, guint action,
1946 prefs_summary_display_item_set();
1949 static void sort_summary_cb(MainWindow *mainwin, guint action,
1952 summary_sort(mainwin->summaryview, (SummarySortType)action);
1955 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1958 summary_attract_by_subject(mainwin->summaryview);
1961 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1964 summary_delete_duplicated(mainwin->summaryview);
1967 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1969 summary_filter(mainwin->summaryview);
1972 static void execute_summary_cb(MainWindow *mainwin, guint action,
1975 summary_execute(mainwin->summaryview);
1978 static void update_summary_cb(MainWindow *mainwin, guint action,
1982 FolderView *folderview = mainwin->folderview;
1984 if (!mainwin->summaryview->folder_item) return;
1985 if (!folderview->opened) return;
1987 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1988 folderview->opened);
1991 summary_show(mainwin->summaryview, fitem, TRUE);
1994 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1996 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1999 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2001 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2004 static void next_unread_cb(MainWindow *mainwin, guint action,
2007 summary_select_next_unread(mainwin->summaryview);
2010 static void next_marked_cb(MainWindow *mainwin, guint action,
2013 summary_select_next_marked(mainwin->summaryview);
2016 static void prev_marked_cb(MainWindow *mainwin, guint action,
2019 summary_select_prev_marked(mainwin->summaryview);
2022 static void goto_folder_cb(MainWindow *mainwin, guint action,
2025 FolderItem *to_folder;
2027 to_folder = foldersel_folder_sel(NULL);
2030 folderview_select(mainwin->folderview, to_folder);
2033 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2035 messageview_copy_clipboard(mainwin->messageview);
2038 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2040 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2041 summary_select_all(mainwin->summaryview);
2042 else if (mainwin->summaryview->msg_is_toggled_on &&
2043 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2044 messageview_select_all(mainwin->messageview);
2047 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2050 prefs_common_open();
2053 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2056 prefs_filter_open();
2059 static void prefs_matcher_open_cb(MainWindow *mainwin, guint action,
2062 prefs_matcher_open(NULL);
2065 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2069 new_account_cb(mainwin, 0, widget);
2071 gboolean prev_default = cur_account->is_default;
2073 prefs_account_open(cur_account);
2074 if (!prev_default && cur_account->is_default)
2075 account_set_as_default(cur_account);
2076 account_save_config_all();
2078 main_window_reflect_prefs_all();
2082 static void new_account_cb(MainWindow *mainwin, guint action,
2085 account_edit_open();
2086 if (!compose_get_compose_list()) account_add();
2089 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2091 cur_account = (PrefsAccount *)data;
2092 main_window_reflect_prefs_all();
2095 static void manual_open_cb(MainWindow *mainwin, guint action,
2098 manual_open((ManualLang)action);
2101 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2103 MainWindow *mainwin = (MainWindow *)data;
2107 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2108 LOCAL_FOLDER(folder)->rootpath,
2112 str = g_strdup_printf(_("Scanning folder %s ..."),
2113 LOCAL_FOLDER(folder)->rootpath);
2115 STATUSBAR_PUSH(mainwin, str);
2116 STATUSBAR_POP(mainwin);