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_scoring.h"
61 #include "prefs_account.h"
62 #include "prefs_folder_item.h"
64 #include "addressbook.h"
65 #include "headerwindow.h"
66 #include "logwindow.h"
67 #include "manage_window.h"
68 #include "alertpanel.h"
69 #include "statusbar.h"
70 #include "inputdialog.h"
77 #define AC_LABEL_WIDTH 240
79 #define STATUSBAR_PUSH(mainwin, str) \
81 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
82 mainwin->mainwin_cid, str); \
83 gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
86 #define STATUSBAR_POP(mainwin) \
88 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
89 mainwin->mainwin_cid); \
92 /* list of all instantiated MainWindow */
93 static GList *mainwin_list = NULL;
95 static GdkCursor *watch_cursor;
97 static void main_window_show_cur_account (MainWindow *mainwin);
99 static void main_window_set_widgets (MainWindow *mainwin,
101 static void main_window_toolbar_create (MainWindow *mainwin,
102 GtkWidget *container);
104 /* callback functions */
105 static void toolbar_inc_cb (GtkWidget *widget,
107 static void toolbar_inc_all_cb (GtkWidget *widget,
109 static void toolbar_send_cb (GtkWidget *widget,
112 static void toolbar_compose_cb (GtkWidget *widget,
114 static void toolbar_reply_cb (GtkWidget *widget,
116 static void toolbar_reply_to_all_cb (GtkWidget *widget,
118 static void toolbar_forward_cb (GtkWidget *widget,
121 static void toolbar_delete_cb (GtkWidget *widget,
123 static void toolbar_exec_cb (GtkWidget *widget,
126 static void toolbar_next_unread_cb (GtkWidget *widget,
129 static void toolbar_prefs_cb (GtkWidget *widget,
131 static void toolbar_account_cb (GtkWidget *widget,
134 static void toolbar_account_button_pressed (GtkWidget *widget,
135 GdkEventButton *event,
137 static void ac_label_button_pressed (GtkWidget *widget,
138 GdkEventButton *event,
141 static gint main_window_close_cb (GtkWidget *widget,
145 static void add_mailbox_cb (MainWindow *mainwin,
148 static void update_folderview_cb (MainWindow *mainwin,
151 static void new_folder_cb (MainWindow *mainwin,
154 static void rename_folder_cb (MainWindow *mainwin,
157 static void delete_folder_cb (MainWindow *mainwin,
160 static void import_mbox_cb (MainWindow *mainwin,
163 static void export_mbox_cb (MainWindow *mainwin,
166 static void empty_trash_cb (MainWindow *mainwin,
170 static void save_as_cb (MainWindow *mainwin,
173 static void print_cb (MainWindow *mainwin,
176 static void app_exit_cb (MainWindow *mainwin,
180 static void toggle_folder_cb (MainWindow *mainwin,
183 static void toggle_message_cb (MainWindow *mainwin,
186 static void toggle_toolbar_cb (MainWindow *mainwin,
189 static void toggle_statusbar_cb (MainWindow *mainwin,
192 static void separate_widget_cb (MainWindow *mainwin,
196 static void addressbook_open_cb (MainWindow *mainwin,
199 static void log_window_show_cb (MainWindow *mainwin,
203 static void inc_mail_cb (MainWindow *mainwin,
206 static void inc_all_account_mail_cb (MainWindow *mainwin,
210 static void send_queue_cb (MainWindow *mainwin,
214 static void compose_cb (MainWindow *mainwin,
217 static void reply_cb (MainWindow *mainwin,
221 static void open_msg_cb (MainWindow *mainwin,
225 static void view_source_cb (MainWindow *mainwin,
229 static void reedit_cb (MainWindow *mainwin,
233 static void move_to_cb (MainWindow *mainwin,
236 static void copy_to_cb (MainWindow *mainwin,
239 static void delete_cb (MainWindow *mainwin,
243 static void mark_cb (MainWindow *mainwin,
246 static void unmark_cb (MainWindow *mainwin,
250 static void mark_as_unread_cb (MainWindow *mainwin,
253 static void mark_as_read_cb (MainWindow *mainwin,
257 static void set_charset_cb (MainWindow *mainwin,
261 static void thread_cb (MainWindow *mainwin,
264 static void set_display_item_cb (MainWindow *mainwin,
267 static void sort_summary_cb (MainWindow *mainwin,
270 static void attract_by_subject_cb(MainWindow *mainwin,
274 static void delete_duplicated_cb (MainWindow *mainwin,
277 static void filter_cb (MainWindow *mainwin,
280 static void execute_summary_cb (MainWindow *mainwin,
283 static void update_summary_cb (MainWindow *mainwin,
287 static void prev_cb (MainWindow *mainwin,
290 static void next_cb (MainWindow *mainwin,
294 static void next_unread_cb (MainWindow *mainwin,
298 static void next_marked_cb (MainWindow *mainwin,
302 static void prev_marked_cb (MainWindow *mainwin,
306 static void goto_folder_cb (MainWindow *mainwin,
310 static void copy_cb (MainWindow *mainwin,
313 static void allsel_cb (MainWindow *mainwin,
317 static void prefs_common_open_cb (MainWindow *mainwin,
320 static void prefs_filter_open_cb (MainWindow *mainwin,
323 static void prefs_scoring_open_cb (MainWindow *mainwin,
326 static void prefs_filtering_open_cb (MainWindow *mainwin,
329 static void prefs_account_open_cb(MainWindow *mainwin,
332 static void new_account_cb (MainWindow *mainwin,
336 static void account_menu_cb (GtkMenuItem *menuitem,
339 static void manual_open_cb (MainWindow *mainwin,
343 static void scan_tree_func (Folder *folder,
347 static GtkItemFactoryEntry mainwin_entries[] =
349 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
350 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
351 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
352 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
353 {N_("/_File/_Folder/Create _new folder..."),
354 NULL, new_folder_cb, 0, NULL},
355 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
356 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
357 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
358 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
359 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
360 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
361 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
362 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
363 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
364 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
365 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
367 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
368 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
369 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
370 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
371 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
373 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
374 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
375 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
376 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
377 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
378 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
379 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
380 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
381 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
382 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
383 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
384 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
385 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
386 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
387 {N_("/_View/_Code set/_Auto detect"),
388 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
390 #define CODESET_SEPARATOR \
391 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
392 #define CODESET_ACTION(action) \
393 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
395 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
396 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
397 CODESET_ACTION(C_US_ASCII)},
400 {N_("/_View/_Code set/Unicode (_UTF-8)"),
401 CODESET_ACTION(C_UTF_8)},
404 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
405 CODESET_ACTION(C_ISO_8859_1)},
408 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
409 CODESET_ACTION(C_ISO_8859_2)},
411 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
412 CODESET_ACTION(C_ISO_8859_13)},
413 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
414 CODESET_ACTION(C_ISO_8859_4)},
416 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
417 CODESET_ACTION(C_ISO_8859_7)},
419 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
420 CODESET_ACTION(C_ISO_8859_9)},
422 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
423 CODESET_ACTION(C_ISO_8859_5)},
424 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
425 CODESET_ACTION(C_KOI8_R)},
426 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
427 CODESET_ACTION(C_CP1251)},
430 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
431 CODESET_ACTION(C_ISO_2022_JP)},
433 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
434 CODESET_ACTION(C_ISO_2022_JP_2)},
436 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
437 CODESET_ACTION(C_EUC_JP)},
438 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
439 CODESET_ACTION(C_SHIFT_JIS)},
442 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
443 CODESET_ACTION(C_GB2312)},
444 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
445 CODESET_ACTION(C_BIG5)},
446 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
447 CODESET_ACTION(C_EUC_TW)},
448 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
449 CODESET_ACTION(C_ISO_2022_CN)},
451 {N_("/_View/_Code set/Korean (EUC-_KR)"),
452 CODESET_ACTION(C_EUC_KR)},
453 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
454 CODESET_ACTION(C_ISO_2022_KR)},
457 #undef CODESET_SEPARATOR
458 #undef CODESET_ACTION
460 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
461 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
462 {N_("/_Message/Receive from _all accounts"),
463 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
464 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
465 {N_("/_Message/Send queued messa_ges"),
466 NULL, send_queue_cb, 0, NULL},
467 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
468 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
469 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
470 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
471 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
472 {N_("/_Message/Forward as an a_ttachment"),
473 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
474 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
475 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
476 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
477 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
478 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
479 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
480 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
481 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
482 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
483 {N_("/_Message/_Mark/Mark it as _being read"),
484 NULL, mark_as_read_cb, 0, NULL},
485 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
486 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
487 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
488 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
489 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
491 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
492 {N_("/_Summary/_Delete duplicated messages"),
493 NULL, delete_duplicated_cb, 0, NULL},
494 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
495 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
496 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
497 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
498 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
499 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
500 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
501 {N_("/_Summary/Prev marked message"), NULL, prev_marked_cb, 0, NULL},
502 {N_("/_Summary/Next marked message"), NULL, next_marked_cb, 0, NULL},
503 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
504 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
505 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
506 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
507 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
508 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
509 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
510 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
511 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
512 {N_("/_Summary/_Sort/Sort by sco_re"), NULL, sort_summary_cb, SORT_BY_SCORE, NULL},
513 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
514 {N_("/_Summary/_Sort/_Attract by subject"),
515 NULL, attract_by_subject_cb, 0, NULL},
516 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
517 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
518 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
520 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
521 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
522 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
524 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
525 {N_("/_Configuration/_Common preferences..."),
526 NULL, prefs_common_open_cb, 0, NULL},
527 {N_("/_Configuration/_Filter setting..."),
528 NULL, prefs_filter_open_cb, 0, NULL},
529 {N_("/_Configuration/_Scoring ..."),
530 NULL, prefs_scoring_open_cb, 0, NULL},
531 {N_("/_Configuration/_Filtering ..."),
532 NULL, prefs_filtering_open_cb, 0, NULL},
533 {N_("/_Configuration/_Preferences per account..."),
534 NULL, prefs_account_open_cb, 0, NULL},
535 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
536 {N_("/_Configuration/Create _new account..."),
537 NULL, new_account_cb, 0, NULL},
538 {N_("/_Configuration/_Edit accounts..."),
539 NULL, account_edit_open, 0, NULL},
540 {N_("/_Configuration/C_hange current account"),
541 NULL, NULL, 0, "<Branch>"},
543 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
544 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
545 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
546 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
547 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
548 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
551 MainWindow *main_window_create(SeparateType type)
557 GtkWidget *handlebox;
558 GtkWidget *vbox_body;
559 GtkWidget *hbox_stat;
560 GtkWidget *statusbar;
561 GtkWidget *ac_button;
564 FolderView *folderview;
565 SummaryView *summaryview;
566 MessageView *messageview;
567 GdkColormap *colormap;
570 guint n_menu_entries;
571 GtkItemFactory *ifactory;
576 debug_print(_("Creating main window...\n"));
577 mainwin = g_new0(MainWindow, 1);
580 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
581 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
582 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
583 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
584 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
585 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
586 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
587 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
588 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
589 gtk_widget_realize(window);
591 vbox = gtk_vbox_new(FALSE, 0);
592 gtk_widget_show(vbox);
593 gtk_container_add(GTK_CONTAINER(window), vbox);
596 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
597 menubar = menubar_create(window, mainwin_entries,
598 n_menu_entries, "<Main>", mainwin);
599 gtk_widget_show(menubar);
600 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
602 handlebox = gtk_handle_box_new();
603 gtk_widget_show(handlebox);
604 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
606 main_window_toolbar_create(mainwin, handlebox);
608 /* vbox that contains body */
609 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
610 gtk_widget_show(vbox_body);
611 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
612 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
614 hbox_stat = gtk_hbox_new(FALSE, 2);
615 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
617 statusbar = statusbar_create();
618 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
620 ac_button = gtk_button_new();
621 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
622 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
623 gtk_widget_set_usize(ac_button, -1, 1);
624 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
625 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
626 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
628 ac_label = gtk_label_new("");
629 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
631 gtk_widget_show_all(hbox_stat);
634 mainwin->folderview = folderview = folderview_create();
635 mainwin->summaryview = summaryview = summary_create();
636 mainwin->messageview = messageview = messageview_create();
637 mainwin->headerwin = header_window_create();
638 mainwin->logwin = log_window_create();
640 folderview->mainwin = mainwin;
641 folderview->summaryview = summaryview;
643 summaryview->mainwin = mainwin;
644 summaryview->folderview = folderview;
645 summaryview->messageview = messageview;
646 summaryview->headerwin = mainwin->headerwin;
647 summaryview->window = window;
649 messageview->mainwin = mainwin;
651 mainwin->window = window;
652 mainwin->vbox = vbox;
653 mainwin->menubar = menubar;
654 mainwin->handlebox = handlebox;
655 mainwin->vbox_body = vbox_body;
656 mainwin->hbox_stat = hbox_stat;
657 mainwin->statusbar = statusbar;
658 mainwin->ac_button = ac_button;
659 mainwin->ac_label = ac_label;
661 /* set context IDs for status bar */
662 mainwin->mainwin_cid = gtk_statusbar_get_context_id
663 (GTK_STATUSBAR(statusbar), "Main Window");
664 mainwin->folderview_cid = gtk_statusbar_get_context_id
665 (GTK_STATUSBAR(statusbar), "Folder View");
666 mainwin->summaryview_cid = gtk_statusbar_get_context_id
667 (GTK_STATUSBAR(statusbar), "Summary View");
669 /* allocate colors for summary view and folder view */
670 summaryview->color_marked.red = summaryview->color_marked.green = 0;
671 summaryview->color_marked.blue = (guint16)65535;
673 summaryview->color_dim.red = summaryview->color_dim.green =
674 summaryview->color_dim.blue = COLOR_DIM;
676 summaryview->color_normal.red = summaryview->color_normal.green =
677 summaryview->color_normal.blue = 0;
679 folderview->color_new.red = (guint16)55000;
680 folderview->color_new.green = folderview->color_new.blue = 15000;
682 folderview->color_normal.red = folderview->color_normal.green =
683 folderview->color_normal.blue = 0;
685 color[0] = summaryview->color_marked;
686 color[1] = summaryview->color_dim;
687 color[2] = summaryview->color_normal;
688 color[3] = folderview->color_new;
689 color[4] = folderview->color_normal;
691 colormap = gdk_window_get_colormap(window->window);
692 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
693 for (i = 0; i < 5; i++) {
694 if (success[i] == FALSE)
695 g_warning(_("MainWindow: color allocation %d failed\n"), i);
698 debug_print(_("done.\n"));
700 main_window_set_widgets(mainwin, type);
703 ifactory = gtk_item_factory_from_widget(menubar);
704 menuitem = gtk_item_factory_get_item
705 (ifactory, "/View/Code set/Auto detect");
706 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
708 switch (prefs_common.toolbar_style) {
710 menuitem = gtk_item_factory_get_item
711 (ifactory, "/View/Toolbar/Non-display");
714 menuitem = gtk_item_factory_get_item
715 (ifactory, "/View/Toolbar/Icon");
718 menuitem = gtk_item_factory_get_item
719 (ifactory, "/View/Toolbar/Text");
722 menuitem = gtk_item_factory_get_item
723 (ifactory, "/View/Toolbar/Icon and text");
725 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
727 gtk_widget_hide(mainwin->hbox_stat);
728 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
729 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
730 prefs_common.show_statusbar);
732 menu_set_sensitive(ifactory, "/Summary/Thread view",
733 prefs_common.enable_thread ? FALSE : TRUE);
734 menu_set_sensitive(ifactory, "/Summary/Unthread view",
735 prefs_common.enable_thread ? TRUE : FALSE);
736 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
738 /* set account selection menu */
739 ac_menu = gtk_item_factory_get_widget
740 (ifactory, "/Configuration/Change current account");
741 mainwin->ac_menu = ac_menu;
743 main_window_set_toolbar_sensitive(mainwin, FALSE);
745 /* show main window */
746 gtk_widget_set_uposition(mainwin->window,
747 prefs_common.mainwin_x,
748 prefs_common.mainwin_y);
749 gtk_widget_set_usize(window, prefs_common.mainwin_width,
750 prefs_common.mainwin_height);
751 gtk_widget_show(mainwin->window);
753 /* initialize views */
754 folderview_init(folderview);
755 summary_init(summaryview);
756 messageview_init(messageview);
757 header_window_init(mainwin->headerwin);
758 log_window_init(mainwin->logwin);
760 mainwin->cursor_count = 0;
763 watch_cursor = gdk_cursor_new(GDK_WATCH);
765 mainwin_list = g_list_append(mainwin_list, mainwin);
770 void main_window_cursor_wait(MainWindow *mainwin)
772 if (mainwin->cursor_count == 0)
773 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
775 mainwin->cursor_count++;
780 void main_window_cursor_normal(MainWindow *mainwin)
782 if (mainwin->cursor_count)
783 mainwin->cursor_count--;
785 if (mainwin->cursor_count == 0)
786 gdk_window_set_cursor(mainwin->window->window, NULL);
791 void main_window_reflect_prefs_all(void)
796 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
797 mainwin = (MainWindow *)cur->data;
799 main_window_show_cur_account(mainwin);
801 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
802 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
804 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
805 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
808 summary_change_display_item(mainwin->summaryview);
809 summary_redisplay_msg(mainwin->summaryview);
810 headerview_set_visibility(mainwin->messageview->headerview,
811 prefs_common.display_header_pane);
815 void main_window_set_account_menu(GList *account_list)
817 GList *cur, *cur_ac, *cur_item;
820 PrefsAccount *ac_prefs;
822 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
823 mainwin = (MainWindow *)cur->data;
825 /* destroy all previous menu item */
826 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
827 while (cur_item != NULL) {
828 GList *next = cur_item->next;
829 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
833 for (cur_ac = account_list; cur_ac != NULL;
834 cur_ac = cur_ac->next) {
835 ac_prefs = (PrefsAccount *)cur_ac->data;
837 menuitem = gtk_menu_item_new_with_label
838 (ac_prefs->account_name
839 ? ac_prefs->account_name : _("Untitled"));
840 gtk_widget_show(menuitem);
841 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
842 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
843 GTK_SIGNAL_FUNC(account_menu_cb),
849 static void main_window_show_cur_account(MainWindow *mainwin)
854 ac_name = g_strdup(cur_account
855 ? (cur_account->account_name
856 ? cur_account->account_name : _("Untitled"))
860 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
862 buf = g_strdup(PROG_VERSION);
863 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
866 buf = g_strdup_printf(_("Current account: %s"), ac_name);
867 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
868 gtk_widget_queue_resize(mainwin->ac_button);
874 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
876 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
877 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
878 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
880 if (mainwin->type == type) return;
882 /* remove widgets from those containers */
883 gtk_widget_ref(folder_wid);
884 gtk_widget_ref(summary_wid);
885 gtk_widget_ref(message_wid);
887 (GTK_CONTAINER(folder_wid->parent), folder_wid);
889 (GTK_CONTAINER(summary_wid->parent), summary_wid);
891 (GTK_CONTAINER(message_wid->parent), message_wid);
893 /* clean containers */
894 switch (mainwin->type) {
896 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
898 case SEPARATE_FOLDER:
899 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
900 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
902 case SEPARATE_MESSAGE:
903 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
904 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
907 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
908 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
912 gtk_widget_hide(mainwin->window);
913 main_window_set_widgets(mainwin, type);
914 gtk_widget_show(mainwin->window);
916 gtk_widget_unref(folder_wid);
917 gtk_widget_unref(summary_wid);
918 gtk_widget_unref(message_wid);
921 void main_window_get_size(MainWindow *mainwin)
923 GtkAllocation *allocation;
925 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
927 prefs_common.summaryview_width = allocation->width;
929 if (mainwin->summaryview->msg_is_toggled_on)
930 prefs_common.summaryview_height = allocation->height;
932 prefs_common.mainview_width = allocation->width;
934 allocation = &mainwin->window->allocation;
936 prefs_common.mainview_height = allocation->height;
937 prefs_common.mainwin_width = allocation->width;
938 prefs_common.mainwin_height = allocation->height;
940 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
942 prefs_common.folderview_width = allocation->width;
943 prefs_common.folderview_height = allocation->height;
946 void main_window_get_position(MainWindow *mainwin)
950 gtkut_widget_get_uposition(mainwin->window, &x, &y);
952 prefs_common.mainview_x = x;
953 prefs_common.mainview_y = y;
954 prefs_common.mainwin_x = x;
955 prefs_common.mainwin_y = y;
957 debug_print(_("window position: x = %d, y = %d\n"), x, y);
960 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
965 if (alertpanel(_("Empty trash"),
966 _("Empty all messages in trash?"),
967 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
969 manage_window_focus_in(mainwin->window, NULL, NULL);
972 procmsg_empty_trash();
974 for (list = folder_get_list(); list != NULL; list = list->next) {
979 folder_item_scan(folder->trash);
980 folderview_update_item(folder->trash, TRUE);
984 if (mainwin->summaryview->folder_item &&
985 mainwin->summaryview->folder_item->stype == F_TRASH)
986 gtk_widget_grab_focus(mainwin->folderview->ctree);
989 void main_window_add_mailbox(MainWindow *mainwin)
994 path = input_dialog(_("Add mailbox"),
995 _("Input the location of mailbox.\n"
996 "If the existing mailbox is specified, it will be\n"
997 "scanned automatically."),
1000 if (folder_find_from_path(path)) {
1001 alertpanel_error(_("The mailbox `%s' already exists."), path);
1005 if (!strcmp(path, "Mail"))
1006 folder = folder_new(F_MH, _("Mailbox"), path);
1008 folder = folder_new(F_MH, g_basename(path), path);
1011 if (folder->create_tree(folder) < 0) {
1012 alertpanel_error(_("Creation of the mailbox failed.\n"
1013 "Maybe some files already exist, or you don't have the permission to write there."));
1014 folder_destroy(folder);
1019 folder_set_ui_func(folder, scan_tree_func, mainwin);
1020 folder->scan_tree(folder);
1021 folder_set_ui_func(folder, NULL, NULL);
1023 folderview_set(mainwin->folderview);
1026 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1028 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
1029 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1030 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1031 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1032 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1034 if (!mainwin->summaryview->folder_item ||
1035 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1036 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1038 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1041 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1043 GtkItemFactory *ifactory;
1047 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1049 if (selection == SUMMARY_SELECTED_SINGLE)
1053 if (!mainwin->summaryview->folder_item ||
1054 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1059 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1060 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1061 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1062 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1063 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1064 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1065 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1066 menu_set_sensitive(ifactory, "/Message/View source", sens);
1067 if (sens && (!mainwin->summaryview->folder_item ||
1068 mainwin->summaryview->folder_item->stype != F_DRAFT))
1070 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1072 if (selection == SUMMARY_SELECTED_SINGLE ||
1073 selection == SUMMARY_SELECTED_MULTIPLE)
1078 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1079 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1080 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1081 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1082 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1084 if (selection != SUMMARY_NONE)
1089 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1090 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1091 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1092 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1093 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1094 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1095 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1098 void main_window_popup(MainWindow *mainwin)
1104 gdk_window_get_origin(mainwin->window->window, &x, &y);
1105 sx = gdk_screen_width();
1106 sy = gdk_screen_height();
1107 x %= sx; if (x < 0) x += sx;
1108 y %= sy; if (y < 0) y += sy;
1109 gdk_window_move(mainwin->window->window, x, y);
1110 gdk_window_raise(mainwin->window->window);
1112 debug_print("window position: x = %d, y = %d\n", x, y);
1114 switch (mainwin->type) {
1115 case SEPARATE_FOLDER:
1116 widget = mainwin->win.sep_folder.folderwin;
1117 gdk_window_get_origin(widget->window, &x, &y);
1118 x %= sx; if (x < 0) x += sx;
1119 y %= sy; if (y < 0) y += sy;
1120 gdk_window_move(widget->window, x, y);
1121 gdk_window_raise(widget->window);
1123 case SEPARATE_MESSAGE:
1124 widget = mainwin->win.sep_message.messagewin;
1125 gdk_window_get_origin(widget->window, &x, &y);
1126 x %= sx; if (x < 0) x += sx;
1127 y %= sy; if (y < 0) y += sy;
1128 gdk_window_move(widget->window, x, y);
1129 gdk_window_raise(widget->window);
1132 widget = mainwin->win.sep_both.folderwin;
1133 gdk_window_get_origin(widget->window, &x, &y);
1134 x %= sx; if (x < 0) x += sx;
1135 y %= sy; if (y < 0) y += sy;
1136 gdk_window_move(widget->window, x, y);
1137 gdk_window_raise(widget->window);
1138 widget = mainwin->win.sep_both.messagewin;
1139 gdk_window_get_origin(widget->window, &x, &y);
1140 x %= sx; if (x < 0) x += sx;
1141 y %= sy; if (y < 0) y += sy;
1142 gdk_window_move(widget->window, x, y);
1143 gdk_window_raise(widget->window);
1149 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1151 GtkWidget *folderwin = NULL;
1152 GtkWidget *messagewin = NULL;
1155 GtkWidget *vbox_body = mainwin->vbox_body;
1157 debug_print(_("Setting widgets..."));
1159 /* create separated window(s) if needed */
1160 if (type & SEPARATE_FOLDER) {
1161 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1162 gtk_window_set_policy(GTK_WINDOW(folderwin),
1164 gtk_widget_set_usize(folderwin, -1,
1165 prefs_common.mainview_height);
1166 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1168 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1169 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1172 if (type & SEPARATE_MESSAGE) {
1173 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1174 gtk_window_set_policy(GTK_WINDOW(messagewin),
1176 gtk_widget_set_usize
1177 (messagewin, prefs_common.mainview_width,
1178 prefs_common.mainview_height
1179 - prefs_common.summaryview_height
1180 + DEFAULT_HEADERVIEW_HEIGHT);
1181 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1183 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1184 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1190 hpaned = gtk_hpaned_new();
1191 gtk_widget_show(hpaned);
1192 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1193 gtk_paned_add1(GTK_PANED(hpaned),
1194 GTK_WIDGET_PTR(mainwin->folderview));
1196 vpaned = gtk_vpaned_new();
1197 if (mainwin->summaryview->msg_is_toggled_on) {
1198 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1199 gtk_paned_add1(GTK_PANED(vpaned),
1200 GTK_WIDGET_PTR(mainwin->summaryview));
1202 gtk_paned_add2(GTK_PANED(hpaned),
1203 GTK_WIDGET_PTR(mainwin->summaryview));
1204 gtk_widget_ref(vpaned);
1206 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1207 prefs_common.summaryview_width,
1208 prefs_common.summaryview_height);
1209 gtk_paned_add2(GTK_PANED(vpaned),
1210 GTK_WIDGET_PTR(mainwin->messageview));
1211 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1212 prefs_common.mainview_width, -1);
1213 gtk_widget_set_usize(mainwin->window,
1214 prefs_common.folderview_width +
1215 prefs_common.mainview_width,
1216 prefs_common.mainwin_height);
1217 gtk_widget_show_all(vpaned);
1219 mainwin->win.sep_none.hpaned = hpaned;
1220 mainwin->win.sep_none.vpaned = vpaned;
1222 case SEPARATE_FOLDER:
1223 vpaned = gtk_vpaned_new();
1224 if (mainwin->summaryview->msg_is_toggled_on) {
1225 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1227 gtk_paned_add1(GTK_PANED(vpaned),
1228 GTK_WIDGET_PTR(mainwin->summaryview));
1230 gtk_box_pack_start(GTK_BOX(vbox_body),
1231 GTK_WIDGET_PTR(mainwin->summaryview),
1233 gtk_widget_ref(vpaned);
1235 gtk_paned_add2(GTK_PANED(vpaned),
1236 GTK_WIDGET_PTR(mainwin->messageview));
1237 gtk_widget_show_all(vpaned);
1238 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1239 prefs_common.summaryview_width,
1240 prefs_common.summaryview_height);
1241 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1242 prefs_common.mainview_width, -1);
1243 gtk_widget_set_usize(mainwin->window,
1244 prefs_common.mainview_width,
1245 prefs_common.mainview_height);
1247 gtk_container_add(GTK_CONTAINER(folderwin),
1248 GTK_WIDGET_PTR(mainwin->folderview));
1250 mainwin->win.sep_folder.folderwin = folderwin;
1251 mainwin->win.sep_folder.vpaned = vpaned;
1253 gtk_widget_show_all(folderwin);
1255 case SEPARATE_MESSAGE:
1256 hpaned = gtk_hpaned_new();
1257 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1259 gtk_paned_add1(GTK_PANED(hpaned),
1260 GTK_WIDGET_PTR(mainwin->folderview));
1261 gtk_paned_add2(GTK_PANED(hpaned),
1262 GTK_WIDGET_PTR(mainwin->summaryview));
1263 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1264 prefs_common.summaryview_width,
1265 prefs_common.summaryview_height);
1266 gtk_widget_set_usize(mainwin->window,
1267 prefs_common.folderview_width +
1268 prefs_common.mainview_width,
1269 prefs_common.mainwin_height);
1270 gtk_widget_show_all(hpaned);
1271 gtk_container_add(GTK_CONTAINER(messagewin),
1272 GTK_WIDGET_PTR(mainwin->messageview));
1274 mainwin->win.sep_message.messagewin = messagewin;
1275 mainwin->win.sep_message.hpaned = hpaned;
1277 gtk_widget_show_all(messagewin);
1280 gtk_box_pack_start(GTK_BOX(vbox_body),
1281 GTK_WIDGET_PTR(mainwin->summaryview),
1283 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1284 prefs_common.summaryview_width,
1285 prefs_common.summaryview_height);
1286 gtk_widget_set_usize(mainwin->window,
1287 prefs_common.mainview_width,
1288 prefs_common.mainwin_height);
1289 gtk_container_add(GTK_CONTAINER(folderwin),
1290 GTK_WIDGET_PTR(mainwin->folderview));
1291 gtk_container_add(GTK_CONTAINER(messagewin),
1292 GTK_WIDGET_PTR(mainwin->messageview));
1294 mainwin->win.sep_both.folderwin = folderwin;
1295 mainwin->win.sep_both.messagewin = messagewin;
1297 gtk_widget_show_all(folderwin);
1298 gtk_widget_show_all(messagewin);
1302 mainwin->type = type;
1304 debug_print(_("done.\n"));
1307 #include "pixmaps/stock_mail_receive.xpm"
1308 #include "pixmaps/stock_mail_receive_all.xpm"
1309 #include "pixmaps/stock_mail_compose.xpm"
1310 #include "pixmaps/stock_mail_reply.xpm"
1311 #include "pixmaps/stock_mail_reply_to_all.xpm"
1312 #include "pixmaps/stock_mail_forward.xpm"
1313 #include "pixmaps/stock_mail_send.xpm"
1314 #include "pixmaps/stock_preferences.xpm"
1315 #include "pixmaps/stock_properties.xpm"
1316 #include "pixmaps/stock_down_arrow.xpm"
1317 #include "pixmaps/stock_close.xpm"
1318 #include "pixmaps/stock_exec.xpm"
1320 #define CREATE_TOOLBAR_ICON(xpm_d) \
1322 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1323 &container->style->white, \
1325 icon_wid = gtk_pixmap_new(icon, mask); \
1328 static void main_window_toolbar_create(MainWindow *mainwin,
1329 GtkWidget *container)
1334 GtkWidget *icon_wid;
1336 GtkWidget *getall_btn;
1337 GtkWidget *compose_btn;
1338 GtkWidget *reply_btn;
1339 GtkWidget *replyall_btn;
1341 GtkWidget *send_btn;
1342 GtkWidget *prefs_btn;
1343 GtkWidget *account_btn;
1344 GtkWidget *next_btn;
1345 GtkWidget *delete_btn;
1346 GtkWidget *exec_btn;
1348 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1350 gtk_container_add(GTK_CONTAINER(container), toolbar);
1351 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1352 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1353 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1354 GTK_TOOLBAR_SPACE_LINE);
1356 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1357 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1359 _("Incorporate new mail"),
1361 icon_wid, toolbar_inc_cb, mainwin);
1362 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1363 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1365 _("Incorporate new mail of all accounts"),
1371 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1373 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1374 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1376 _("Send queued message(s)"),
1382 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1384 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1385 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1387 _("Compose new message"),
1392 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1393 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1395 _("Reply to the message"),
1400 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1401 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1406 toolbar_reply_to_all_cb,
1408 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1409 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1411 _("Forward the message"),
1417 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1419 CREATE_TOOLBAR_ICON(stock_close_xpm);
1420 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1422 _("Delete the message"),
1428 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1429 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1431 _("Execute marked process"),
1437 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1439 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1440 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1442 _("Next unread message"),
1445 toolbar_next_unread_cb,
1448 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1450 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1451 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1453 _("Common preference"),
1458 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1459 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1461 _("Account setting"),
1466 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1467 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1470 mainwin->toolbar = toolbar;
1471 mainwin->get_btn = get_btn;
1472 mainwin->getall_btn = getall_btn;
1473 mainwin->compose_btn = compose_btn;
1474 mainwin->reply_btn = reply_btn;
1475 mainwin->replyall_btn = replyall_btn;
1476 mainwin->fwd_btn = fwd_btn;
1477 mainwin->send_btn = send_btn;
1478 mainwin->prefs_btn = prefs_btn;
1479 mainwin->account_btn = account_btn;
1480 mainwin->next_btn = next_btn;
1481 mainwin->delete_btn = delete_btn;
1482 mainwin->exec_btn = exec_btn;
1484 gtk_widget_show_all(toolbar);
1487 /* callback functions */
1489 static void toolbar_inc_cb (GtkWidget *widget,
1492 MainWindow *mainwin = (MainWindow *)data;
1494 inc_mail_cb(mainwin, 0, NULL);
1497 static void toolbar_inc_all_cb (GtkWidget *widget,
1500 MainWindow *mainwin = (MainWindow *)data;
1502 inc_all_account_mail_cb(mainwin, 0, NULL);
1505 static void toolbar_send_cb (GtkWidget *widget,
1508 MainWindow *mainwin = (MainWindow *)data;
1510 send_queue_cb(mainwin, 0, NULL);
1513 static void toolbar_compose_cb (GtkWidget *widget,
1516 MainWindow *mainwin = (MainWindow *)data;
1518 compose_cb(mainwin, 0, NULL);
1521 static void toolbar_reply_cb (GtkWidget *widget,
1524 MainWindow *mainwin = (MainWindow *)data;
1526 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1529 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1532 MainWindow *mainwin = (MainWindow *)data;
1534 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1537 static void toolbar_forward_cb (GtkWidget *widget,
1540 MainWindow *mainwin = (MainWindow *)data;
1542 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1545 static void toolbar_delete_cb (GtkWidget *widget,
1548 MainWindow *mainwin = (MainWindow *)data;
1550 summary_delete(mainwin->summaryview);
1553 static void toolbar_exec_cb (GtkWidget *widget,
1556 MainWindow *mainwin = (MainWindow *)data;
1558 summary_execute(mainwin->summaryview);
1561 static void toolbar_next_unread_cb (GtkWidget *widget,
1564 MainWindow *mainwin = (MainWindow *)data;
1566 next_unread_cb(mainwin, 0, NULL);
1569 static void toolbar_prefs_cb (GtkWidget *widget,
1572 prefs_common_open();
1575 static void toolbar_account_cb (GtkWidget *widget,
1578 MainWindow *mainwin = (MainWindow *)data;
1580 prefs_account_open_cb(mainwin, 0, NULL);
1583 static void toolbar_account_button_pressed(GtkWidget *widget,
1584 GdkEventButton *event,
1587 MainWindow *mainwin = (MainWindow *)data;
1590 if (event->button != 3) return;
1592 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1593 event->button, event->time);
1596 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1599 MainWindow *mainwin = (MainWindow *)data;
1603 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1604 event->button, event->time);
1607 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1610 app_exit_cb(data, 0, widget);
1615 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1618 main_window_add_mailbox(mainwin);
1621 static void update_folderview_cb(MainWindow *mainwin, guint action,
1624 summary_show(mainwin->summaryview, NULL, FALSE);
1625 folderview_update_all();
1628 static void new_folder_cb(MainWindow *mainwin, guint action,
1631 folderview_new_folder(mainwin->folderview);
1634 static void rename_folder_cb(MainWindow *mainwin, guint action,
1637 folderview_rename_folder(mainwin->folderview);
1640 static void delete_folder_cb(MainWindow *mainwin, guint action,
1643 folderview_delete_folder(mainwin->folderview);
1646 static void import_mbox_cb(MainWindow *mainwin, guint action,
1649 import_mbox(mainwin->summaryview->folder_item);
1652 static void export_mbox_cb(MainWindow *mainwin, guint action,
1655 export_mbox(mainwin->summaryview->folder_item);
1658 static void empty_trash_cb(MainWindow *mainwin, guint action,
1661 main_window_empty_trash(mainwin, TRUE);
1664 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1666 summary_save_as(mainwin->summaryview);
1669 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1671 summary_print(mainwin->summaryview);
1674 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1676 if (prefs_common.confirm_on_exit) {
1677 if (alertpanel(_("Exit"), _("Exit this program?"),
1678 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1680 manage_window_focus_in(mainwin->window, NULL, NULL);
1683 app_will_exit(widget, mainwin);
1686 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1689 switch (mainwin->type) {
1691 case SEPARATE_MESSAGE:
1693 case SEPARATE_FOLDER:
1694 if (GTK_CHECK_MENU_ITEM(widget)->active)
1695 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1697 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1700 if (GTK_CHECK_MENU_ITEM(widget)->active)
1701 gtk_widget_show(mainwin->win.sep_both.folderwin);
1703 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1708 static void toggle_message_cb(MainWindow *mainwin, guint action,
1711 switch (mainwin->type) {
1713 case SEPARATE_FOLDER:
1715 case SEPARATE_MESSAGE:
1716 if (GTK_CHECK_MENU_ITEM(widget)->active)
1717 gtk_widget_show(mainwin->win.sep_message.messagewin);
1719 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1722 if (GTK_CHECK_MENU_ITEM(widget)->active)
1723 gtk_widget_show(mainwin->win.sep_both.messagewin);
1725 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1730 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1733 switch ((ToolbarStyle)action) {
1735 gtk_widget_hide(mainwin->handlebox);
1737 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1741 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1745 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1750 if (action != TOOLBAR_NONE) {
1751 gtk_widget_show(mainwin->handlebox);
1752 gtk_widget_queue_resize(mainwin->handlebox);
1755 mainwin->toolbar_style = (ToolbarStyle)action;
1756 prefs_common.toolbar_style = (ToolbarStyle)action;
1759 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1762 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1763 gtk_widget_show(mainwin->hbox_stat);
1764 prefs_common.show_statusbar = TRUE;
1766 gtk_widget_hide(mainwin->hbox_stat);
1767 prefs_common.show_statusbar = FALSE;
1771 static void separate_widget_cb(MainWindow *mainwin, guint action,
1776 type = mainwin->type ^ action;
1777 main_window_separation_change(mainwin, type);
1779 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1780 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1783 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1786 addressbook_open(NULL);
1789 static void log_window_show_cb(MainWindow *mainwin, guint action,
1792 log_window_show(mainwin->logwin);
1795 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1800 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1803 inc_all_account_mail(mainwin);
1806 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1810 if (procmsg_send_queue() < 0)
1811 alertpanel_error(_("Sending queued message failed."));
1813 statusbar_pop_all();
1815 for (list = folder_get_list(); list != NULL; list = list->next) {
1818 folder = list->data;
1819 if (folder->queue) {
1820 folder_item_scan(folder->queue);
1821 folderview_update_item(folder->queue, TRUE);
1826 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1828 if (mainwin->summaryview->folder_item)
1829 compose_new(mainwin->summaryview->folder_item->folder->account);
1834 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1838 msginfo = gtk_ctree_node_get_row_data
1839 (GTK_CTREE(mainwin->summaryview->ctree),
1840 mainwin->summaryview->selected);
1842 if (!msginfo) return;
1846 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1848 case COMPOSE_REPLY_TO_ALL:
1849 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1851 case COMPOSE_FORWARD:
1852 compose_forward(msginfo, FALSE);
1854 case COMPOSE_FORWARD_AS_ATTACH:
1855 compose_forward(msginfo, TRUE);
1858 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1861 summary_set_marks_selected(mainwin->summaryview);
1864 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1866 summary_move_to(mainwin->summaryview);
1869 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1871 summary_copy_to(mainwin->summaryview);
1874 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1876 summary_delete(mainwin->summaryview);
1879 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1881 summary_open_msg(mainwin->summaryview);
1884 static void view_source_cb(MainWindow *mainwin, guint action,
1887 summary_view_source(mainwin->summaryview);
1890 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1892 summary_reedit(mainwin->summaryview);
1895 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1897 summary_mark(mainwin->summaryview);
1900 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1902 summary_unmark(mainwin->summaryview);
1905 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1908 summary_mark_as_unread(mainwin->summaryview);
1911 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1914 summary_mark_as_read(mainwin->summaryview);
1917 static void set_charset_cb(MainWindow *mainwin, guint action,
1922 str = conv_get_charset_str((CharSet)action);
1923 g_free(prefs_common.force_charset);
1924 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1926 summary_redisplay_msg(mainwin->summaryview);
1928 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1931 void main_window_set_thread_option(MainWindow *mainwin)
1933 GtkItemFactory *ifactory;
1935 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1937 if (mainwin->summaryview->folder_item->prefs->enable_thread) {
1938 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1939 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1940 summary_thread_build(mainwin->summaryview);
1943 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1944 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1945 summary_unthread(mainwin->summaryview);
1947 prefs_folder_item_save_config(mainwin->summaryview->folder_item);
1950 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1953 ifactory = gtk_item_factory_from_widget(widget);
1955 mainwin->summaryview->folder_item->prefs->enable_thread =
1956 !mainwin->summaryview->folder_item->prefs->enable_thread;
1957 main_window_set_thread_option(mainwin);
1961 summary_thread_build(mainwin->summaryview);
1962 mainwin->summaryview->folder_item->prefs->enable_thread =
1964 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1965 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1967 summary_unthread(mainwin->summaryview);
1968 mainwin->summaryview->folder_item->prefs->enable_thread =
1970 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1971 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1976 static void set_display_item_cb(MainWindow *mainwin, guint action,
1979 prefs_summary_display_item_set();
1982 static void sort_summary_cb(MainWindow *mainwin, guint action,
1985 summary_sort(mainwin->summaryview, (SummarySortType)action);
1988 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1991 summary_attract_by_subject(mainwin->summaryview);
1994 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1997 summary_delete_duplicated(mainwin->summaryview);
2000 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2002 summary_filter(mainwin->summaryview);
2005 static void execute_summary_cb(MainWindow *mainwin, guint action,
2008 summary_execute(mainwin->summaryview);
2011 static void update_summary_cb(MainWindow *mainwin, guint action,
2015 FolderView *folderview = mainwin->folderview;
2017 if (!mainwin->summaryview->folder_item) return;
2018 if (!folderview->opened) return;
2020 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2021 folderview->opened);
2024 summary_show(mainwin->summaryview, fitem, TRUE);
2027 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2029 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2032 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2034 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2037 static void next_unread_cb(MainWindow *mainwin, guint action,
2040 summary_select_next_unread(mainwin->summaryview);
2043 static void next_marked_cb(MainWindow *mainwin, guint action,
2046 summary_select_next_marked(mainwin->summaryview);
2049 static void prev_marked_cb(MainWindow *mainwin, guint action,
2052 summary_select_prev_marked(mainwin->summaryview);
2055 static void goto_folder_cb(MainWindow *mainwin, guint action,
2058 FolderItem *to_folder;
2060 to_folder = foldersel_folder_sel(NULL);
2063 folderview_select(mainwin->folderview, to_folder);
2066 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2068 messageview_copy_clipboard(mainwin->messageview);
2071 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2073 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2074 summary_select_all(mainwin->summaryview);
2075 else if (mainwin->summaryview->msg_is_toggled_on &&
2076 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2077 messageview_select_all(mainwin->messageview);
2080 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2083 prefs_common_open();
2086 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2089 prefs_filter_open();
2092 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2095 prefs_scoring_open();
2098 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2101 prefs_filtering_open();
2104 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2108 new_account_cb(mainwin, 0, widget);
2110 gboolean prev_default = cur_account->is_default;
2112 prefs_account_open(cur_account);
2113 if (!prev_default && cur_account->is_default)
2114 account_set_as_default(cur_account);
2115 account_save_config_all();
2117 main_window_reflect_prefs_all();
2121 static void new_account_cb(MainWindow *mainwin, guint action,
2124 account_edit_open();
2125 if (!compose_get_compose_list()) account_add();
2128 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2130 cur_account = (PrefsAccount *)data;
2131 main_window_reflect_prefs_all();
2134 static void manual_open_cb(MainWindow *mainwin, guint action,
2137 manual_open((ManualLang)action);
2140 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2142 MainWindow *mainwin = (MainWindow *)data;
2146 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2147 LOCAL_FOLDER(folder)->rootpath,
2151 str = g_strdup_printf(_("Scanning folder %s ..."),
2152 LOCAL_FOLDER(folder)->rootpath);
2154 STATUSBAR_PUSH(mainwin, str);
2155 STATUSBAR_POP(mainwin);