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"
57 #include "prefs_common.h"
58 #include "prefs_filter.h"
59 #include "prefs_account.h"
61 #include "addressbook.h"
62 #include "headerwindow.h"
63 #include "logwindow.h"
64 #include "manage_window.h"
65 #include "alertpanel.h"
66 #include "statusbar.h"
67 #include "inputdialog.h"
74 #define AC_LABEL_WIDTH 240
76 #define STATUSBAR_PUSH(mainwin, str) \
78 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
79 mainwin->mainwin_cid, str); \
80 gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
83 #define STATUSBAR_POP(mainwin) \
85 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
86 mainwin->mainwin_cid); \
89 /* list of all instantiated MainWindow */
90 static GList *mainwin_list = NULL;
92 static GdkCursor *watch_cursor;
94 static void main_window_show_cur_account (MainWindow *mainwin);
96 static void main_window_set_widgets (MainWindow *mainwin,
98 static void main_window_toolbar_create (MainWindow *mainwin,
99 GtkWidget *container);
101 /* callback functions */
102 static void toolbar_inc_cb (GtkWidget *widget,
104 static void toolbar_inc_all_cb (GtkWidget *widget,
106 static void toolbar_send_cb (GtkWidget *widget,
109 static void toolbar_compose_cb (GtkWidget *widget,
111 static void toolbar_reply_cb (GtkWidget *widget,
113 static void toolbar_reply_to_all_cb (GtkWidget *widget,
115 static void toolbar_forward_cb (GtkWidget *widget,
118 static void toolbar_delete_cb (GtkWidget *widget,
120 static void toolbar_exec_cb (GtkWidget *widget,
123 static void toolbar_next_unread_cb (GtkWidget *widget,
126 static void toolbar_prefs_cb (GtkWidget *widget,
128 static void toolbar_account_cb (GtkWidget *widget,
131 static void toolbar_account_button_pressed (GtkWidget *widget,
132 GdkEventButton *event,
134 static void ac_label_button_pressed (GtkWidget *widget,
135 GdkEventButton *event,
138 static gint main_window_close_cb (GtkWidget *widget,
142 static void add_mailbox_cb (MainWindow *mainwin,
145 static void update_folderview_cb (MainWindow *mainwin,
148 static void new_folder_cb (MainWindow *mainwin,
151 static void rename_folder_cb (MainWindow *mainwin,
154 static void delete_folder_cb (MainWindow *mainwin,
157 static void import_mbox_cb (MainWindow *mainwin,
160 static void empty_trash_cb (MainWindow *mainwin,
164 static void save_as_cb (MainWindow *mainwin,
167 static void print_cb (MainWindow *mainwin,
170 static void app_exit_cb (MainWindow *mainwin,
174 static void toggle_folder_cb (MainWindow *mainwin,
177 static void toggle_message_cb (MainWindow *mainwin,
180 static void toggle_toolbar_cb (MainWindow *mainwin,
183 static void toggle_statusbar_cb (MainWindow *mainwin,
186 static void separate_widget_cb (MainWindow *mainwin,
190 static void addressbook_open_cb (MainWindow *mainwin,
193 static void log_window_show_cb (MainWindow *mainwin,
197 static void inc_mail_cb (MainWindow *mainwin,
200 static void inc_all_account_mail_cb (MainWindow *mainwin,
204 static void send_queue_cb (MainWindow *mainwin,
208 static void compose_cb (MainWindow *mainwin,
211 static void reply_cb (MainWindow *mainwin,
215 static void open_msg_cb (MainWindow *mainwin,
219 static void view_source_cb (MainWindow *mainwin,
223 static void reedit_cb (MainWindow *mainwin,
227 static void move_to_cb (MainWindow *mainwin,
230 static void copy_to_cb (MainWindow *mainwin,
233 static void delete_cb (MainWindow *mainwin,
237 static void mark_cb (MainWindow *mainwin,
240 static void unmark_cb (MainWindow *mainwin,
244 static void mark_as_unread_cb (MainWindow *mainwin,
247 static void mark_as_read_cb (MainWindow *mainwin,
251 static void set_charset_cb (MainWindow *mainwin,
255 static void thread_cb (MainWindow *mainwin,
258 static void set_display_item_cb (MainWindow *mainwin,
261 static void sort_summary_cb (MainWindow *mainwin,
264 static void attract_by_subject_cb(MainWindow *mainwin,
268 static void delete_duplicated_cb (MainWindow *mainwin,
271 static void filter_cb (MainWindow *mainwin,
274 static void execute_summary_cb (MainWindow *mainwin,
277 static void update_summary_cb (MainWindow *mainwin,
281 static void prev_cb (MainWindow *mainwin,
284 static void next_cb (MainWindow *mainwin,
288 static void next_unread_cb (MainWindow *mainwin,
292 static void goto_folder_cb (MainWindow *mainwin,
296 static void copy_cb (MainWindow *mainwin,
299 static void allsel_cb (MainWindow *mainwin,
303 static void prefs_common_open_cb (MainWindow *mainwin,
306 static void prefs_filter_open_cb (MainWindow *mainwin,
309 static void prefs_account_open_cb(MainWindow *mainwin,
312 static void new_account_cb (MainWindow *mainwin,
316 static void account_menu_cb (GtkMenuItem *menuitem,
319 static void manual_open_cb (MainWindow *mainwin,
323 static void scan_tree_func (Folder *folder,
327 static GtkItemFactoryEntry mainwin_entries[] =
329 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
330 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
331 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
332 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
333 {N_("/_File/_Folder/Create _new folder..."),
334 NULL, new_folder_cb, 0, NULL},
335 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
336 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
337 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
338 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
339 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
340 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
341 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
342 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
343 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
344 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
346 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
347 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
348 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
349 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
350 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
352 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
353 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
354 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
355 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
356 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
357 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
358 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
359 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
360 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
361 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
362 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
363 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
364 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
365 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
366 {N_("/_View/_Code set/_Auto detect"),
367 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
369 #define CODESET_SEPARATOR \
370 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
371 #define CODESET_ACTION(action) \
372 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
374 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
375 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
376 CODESET_ACTION(C_US_ASCII)},
379 {N_("/_View/_Code set/Unicode (_UTF-8)"),
380 CODESET_ACTION(C_UTF_8)},
383 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
384 CODESET_ACTION(C_ISO_8859_1)},
387 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
388 CODESET_ACTION(C_ISO_8859_2)},
390 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
391 CODESET_ACTION(C_ISO_8859_13)},
392 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
393 CODESET_ACTION(C_ISO_8859_4)},
395 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
396 CODESET_ACTION(C_ISO_8859_7)},
398 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
399 CODESET_ACTION(C_ISO_8859_9)},
401 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
402 CODESET_ACTION(C_ISO_8859_5)},
403 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
404 CODESET_ACTION(C_KOI8_R)},
405 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
406 CODESET_ACTION(C_CP1251)},
409 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
410 CODESET_ACTION(C_ISO_2022_JP)},
412 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
413 CODESET_ACTION(C_ISO_2022_JP_2)},
415 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
416 CODESET_ACTION(C_EUC_JP)},
417 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
418 CODESET_ACTION(C_SHIFT_JIS)},
421 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
422 CODESET_ACTION(C_GB2312)},
423 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
424 CODESET_ACTION(C_BIG5)},
425 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
426 CODESET_ACTION(C_EUC_TW)},
427 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
428 CODESET_ACTION(C_ISO_2022_CN)},
430 {N_("/_View/_Code set/Korean (EUC-_KR)"),
431 CODESET_ACTION(C_EUC_KR)},
432 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
433 CODESET_ACTION(C_ISO_2022_KR)},
436 #undef CODESET_SEPARATOR
437 #undef CODESET_ACTION
439 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
440 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
441 {N_("/_Message/Receive from _all accounts"),
442 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
443 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
444 {N_("/_Message/Send queued messa_ges"),
445 NULL, send_queue_cb, 0, NULL},
446 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
447 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
448 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
449 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
450 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
451 {N_("/_Message/Forward as an a_ttachment"),
452 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
453 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
454 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
455 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
456 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
457 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
458 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
459 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
460 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
461 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
462 {N_("/_Message/_Mark/Mark it as _being read"),
463 NULL, mark_as_read_cb, 0, NULL},
464 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
465 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
466 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
467 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
468 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
470 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
471 {N_("/_Summary/_Delete duplicated messages"),
472 NULL, delete_duplicated_cb, 0, NULL},
473 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
474 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
475 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
476 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
477 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
478 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
479 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
480 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
481 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
482 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
483 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
484 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
485 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
486 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
487 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
488 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
489 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
490 {N_("/_Summary/_Sort/_Attract by subject"),
491 NULL, attract_by_subject_cb, 0, NULL},
492 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
493 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
494 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
496 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
497 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
498 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
500 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
501 {N_("/_Configuration/_Common preferences..."),
502 NULL, prefs_common_open_cb, 0, NULL},
503 {N_("/_Configuration/_Filter setting..."),
504 NULL, prefs_filter_open_cb, 0, NULL},
505 {N_("/_Configuration/_Preferences per account..."),
506 NULL, prefs_account_open_cb, 0, NULL},
507 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_Configuration/Create _new account..."),
509 NULL, new_account_cb, 0, NULL},
510 {N_("/_Configuration/_Edit accounts..."),
511 NULL, account_edit_open, 0, NULL},
512 {N_("/_Configuration/C_hange current account"),
513 NULL, NULL, 0, "<Branch>"},
515 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
516 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
518 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
519 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
523 MainWindow *main_window_create(SeparateType type)
529 GtkWidget *handlebox;
530 GtkWidget *vbox_body;
531 GtkWidget *hbox_stat;
532 GtkWidget *statusbar;
533 GtkWidget *ac_button;
536 FolderView *folderview;
537 SummaryView *summaryview;
538 MessageView *messageview;
539 GdkColormap *colormap;
542 guint n_menu_entries;
543 GtkItemFactory *ifactory;
548 debug_print(_("Creating main window...\n"));
549 mainwin = g_new0(MainWindow, 1);
552 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
553 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
554 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
555 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
556 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
557 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
558 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
559 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
560 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
561 gtk_widget_realize(window);
563 vbox = gtk_vbox_new(FALSE, 0);
564 gtk_widget_show(vbox);
565 gtk_container_add(GTK_CONTAINER(window), vbox);
568 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
569 menubar = menubar_create(window, mainwin_entries,
570 n_menu_entries, "<Main>", mainwin);
571 gtk_widget_show(menubar);
572 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
574 handlebox = gtk_handle_box_new();
575 gtk_widget_show(handlebox);
576 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
578 main_window_toolbar_create(mainwin, handlebox);
580 /* vbox that contains body */
581 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
582 gtk_widget_show(vbox_body);
583 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
584 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
586 hbox_stat = gtk_hbox_new(FALSE, 2);
587 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
589 statusbar = statusbar_create();
590 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
592 ac_button = gtk_button_new();
593 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
594 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
595 gtk_widget_set_usize(ac_button, -1, 1);
596 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
597 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
598 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
600 ac_label = gtk_label_new("");
601 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
603 gtk_widget_show_all(hbox_stat);
606 mainwin->folderview = folderview = folderview_create();
607 mainwin->summaryview = summaryview = summary_create();
608 mainwin->messageview = messageview = messageview_create();
609 mainwin->headerwin = header_window_create();
610 mainwin->logwin = log_window_create();
612 folderview->mainwin = mainwin;
613 folderview->summaryview = summaryview;
615 summaryview->mainwin = mainwin;
616 summaryview->folderview = folderview;
617 summaryview->messageview = messageview;
618 summaryview->headerwin = mainwin->headerwin;
619 summaryview->window = window;
621 messageview->mainwin = mainwin;
623 mainwin->window = window;
624 mainwin->vbox = vbox;
625 mainwin->menubar = menubar;
626 mainwin->handlebox = handlebox;
627 mainwin->vbox_body = vbox_body;
628 mainwin->hbox_stat = hbox_stat;
629 mainwin->statusbar = statusbar;
630 mainwin->ac_button = ac_button;
631 mainwin->ac_label = ac_label;
633 /* set context IDs for status bar */
634 mainwin->mainwin_cid = gtk_statusbar_get_context_id
635 (GTK_STATUSBAR(statusbar), "Main Window");
636 mainwin->folderview_cid = gtk_statusbar_get_context_id
637 (GTK_STATUSBAR(statusbar), "Folder View");
638 mainwin->summaryview_cid = gtk_statusbar_get_context_id
639 (GTK_STATUSBAR(statusbar), "Summary View");
641 /* allocate colors for summary view and folder view */
642 summaryview->color_marked.red = summaryview->color_marked.green = 0;
643 summaryview->color_marked.blue = (guint16)65535;
645 summaryview->color_dim.red = summaryview->color_dim.green =
646 summaryview->color_dim.blue = COLOR_DIM;
648 summaryview->color_normal.red = summaryview->color_normal.green =
649 summaryview->color_normal.blue = 0;
651 folderview->color_new.red = (guint16)55000;
652 folderview->color_new.green = folderview->color_new.blue = 15000;
654 folderview->color_normal.red = folderview->color_normal.green =
655 folderview->color_normal.blue = 0;
657 color[0] = summaryview->color_marked;
658 color[1] = summaryview->color_dim;
659 color[2] = summaryview->color_normal;
660 color[3] = folderview->color_new;
661 color[4] = folderview->color_normal;
663 colormap = gdk_window_get_colormap(window->window);
664 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
665 for (i = 0; i < 5; i++) {
666 if (success[i] == FALSE)
667 g_warning(_("MainWindow: color allocation %d failed\n"), i);
670 debug_print(_("done.\n"));
672 main_window_set_widgets(mainwin, type);
675 ifactory = gtk_item_factory_from_widget(menubar);
676 menuitem = gtk_item_factory_get_item
677 (ifactory, "/View/Code set/Auto detect");
678 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
680 switch (prefs_common.toolbar_style) {
682 menuitem = gtk_item_factory_get_item
683 (ifactory, "/View/Toolbar/Non-display");
686 menuitem = gtk_item_factory_get_item
687 (ifactory, "/View/Toolbar/Icon");
690 menuitem = gtk_item_factory_get_item
691 (ifactory, "/View/Toolbar/Text");
694 menuitem = gtk_item_factory_get_item
695 (ifactory, "/View/Toolbar/Icon and text");
697 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
699 gtk_widget_hide(mainwin->hbox_stat);
700 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
701 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
702 prefs_common.show_statusbar);
704 menu_set_sensitive(ifactory, "/Summary/Thread view",
705 prefs_common.enable_thread ? FALSE : TRUE);
706 menu_set_sensitive(ifactory, "/Summary/Unthread view",
707 prefs_common.enable_thread ? TRUE : FALSE);
708 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
710 /* set account selection menu */
711 ac_menu = gtk_item_factory_get_widget
712 (ifactory, "/Configuration/Change current account");
713 mainwin->ac_menu = ac_menu;
715 main_window_set_toolbar_sensitive(mainwin, FALSE);
717 /* show main window */
718 gtk_widget_set_uposition(mainwin->window,
719 prefs_common.mainwin_x,
720 prefs_common.mainwin_y);
721 gtk_widget_set_usize(window, prefs_common.mainwin_width,
722 prefs_common.mainwin_height);
723 gtk_widget_show(mainwin->window);
725 /* initialize views */
726 folderview_init(folderview);
727 summary_init(summaryview);
728 messageview_init(messageview);
729 header_window_init(mainwin->headerwin);
730 log_window_init(mainwin->logwin);
732 mainwin->cursor_count = 0;
735 watch_cursor = gdk_cursor_new(GDK_WATCH);
737 mainwin_list = g_list_append(mainwin_list, mainwin);
742 void main_window_cursor_wait(MainWindow *mainwin)
744 if (mainwin->cursor_count == 0)
745 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
747 mainwin->cursor_count++;
752 void main_window_cursor_normal(MainWindow *mainwin)
754 if (mainwin->cursor_count)
755 mainwin->cursor_count--;
757 if (mainwin->cursor_count == 0)
758 gdk_window_set_cursor(mainwin->window->window, NULL);
763 void main_window_reflect_prefs_all(void)
768 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
769 mainwin = (MainWindow *)cur->data;
771 main_window_show_cur_account(mainwin);
773 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
774 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
776 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
777 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
780 summary_change_display_item(mainwin->summaryview);
781 headerview_set_visibility(mainwin->messageview->headerview,
782 prefs_common.display_header_pane);
786 void main_window_set_account_menu(GList *account_list)
788 GList *cur, *cur_ac, *cur_item;
791 PrefsAccount *ac_prefs;
793 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
794 mainwin = (MainWindow *)cur->data;
796 /* destroy all previous menu item */
797 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
798 while (cur_item != NULL) {
799 GList *next = cur_item->next;
800 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
804 for (cur_ac = account_list; cur_ac != NULL;
805 cur_ac = cur_ac->next) {
806 ac_prefs = (PrefsAccount *)cur_ac->data;
808 menuitem = gtk_menu_item_new_with_label
809 (ac_prefs->account_name
810 ? ac_prefs->account_name : _("Untitled"));
811 gtk_widget_show(menuitem);
812 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
813 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
814 GTK_SIGNAL_FUNC(account_menu_cb),
820 static void main_window_show_cur_account(MainWindow *mainwin)
825 ac_name = g_strdup(cur_account
826 ? (cur_account->account_name
827 ? cur_account->account_name : _("Untitled"))
831 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
833 buf = g_strdup(PROG_VERSION);
834 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
837 buf = g_strdup_printf(_("Current account: %s"), ac_name);
838 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
839 gtk_widget_queue_resize(mainwin->ac_button);
845 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
847 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
848 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
849 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
851 if (mainwin->type == type) return;
853 /* remove widgets from those containers */
854 gtk_widget_ref(folder_wid);
855 gtk_widget_ref(summary_wid);
856 gtk_widget_ref(message_wid);
858 (GTK_CONTAINER(folder_wid->parent), folder_wid);
860 (GTK_CONTAINER(summary_wid->parent), summary_wid);
862 (GTK_CONTAINER(message_wid->parent), message_wid);
864 /* clean containers */
865 switch (mainwin->type) {
867 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
869 case SEPARATE_FOLDER:
870 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
871 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
873 case SEPARATE_MESSAGE:
874 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
875 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
878 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
879 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
883 gtk_widget_hide(mainwin->window);
884 main_window_set_widgets(mainwin, type);
885 gtk_widget_show(mainwin->window);
887 gtk_widget_unref(folder_wid);
888 gtk_widget_unref(summary_wid);
889 gtk_widget_unref(message_wid);
892 void main_window_get_size(MainWindow *mainwin)
894 GtkAllocation *allocation;
896 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
898 prefs_common.summaryview_width = allocation->width;
900 if (mainwin->summaryview->msg_is_toggled_on)
901 prefs_common.summaryview_height = allocation->height;
903 prefs_common.mainview_width = allocation->width;
905 allocation = &mainwin->window->allocation;
907 prefs_common.mainview_height = allocation->height;
908 prefs_common.mainwin_width = allocation->width;
909 prefs_common.mainwin_height = allocation->height;
911 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
913 prefs_common.folderview_width = allocation->width;
914 prefs_common.folderview_height = allocation->height;
917 void main_window_get_position(MainWindow *mainwin)
921 gtkut_widget_get_uposition(mainwin->window, &x, &y);
923 prefs_common.mainview_x = x;
924 prefs_common.mainview_y = y;
925 prefs_common.mainwin_x = x;
926 prefs_common.mainwin_y = y;
928 debug_print(_("window position: x = %d, y = %d\n"), x, y);
931 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
936 if (alertpanel(_("Empty trash"),
937 _("Empty all messages in trash?"),
938 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
942 procmsg_empty_trash();
944 for (list = folder_get_list(); list != NULL; list = list->next) {
949 folder_item_scan(folder->trash);
950 folderview_update_item(folder->trash, TRUE);
954 if (mainwin->summaryview->folder_item &&
955 mainwin->summaryview->folder_item->stype == F_TRASH)
956 gtk_widget_grab_focus(mainwin->folderview->ctree);
959 void main_window_add_mailbox(MainWindow *mainwin)
964 path = input_dialog(_("Add mailbox"),
965 _("Input the location of mailbox.\n"
966 "If the existing mailbox is specified, it will be\n"
967 "scanned automatically."),
970 if (folder_find_from_path(path)) {
971 alertpanel_error(_("The mailbox `%s' already exists."), path);
975 if (!strcmp(path, "Mail"))
976 folder = folder_new(F_MH, _("Mailbox"), path);
978 folder = folder_new(F_MH, g_basename(path), path);
981 if (folder->create_tree(folder) < 0) {
982 alertpanel_error(_("Creation of the mailbox failed.\n"
983 "Maybe some files already exist, or you don't have the permission to write there."));
984 folder_destroy(folder);
989 folder_set_ui_func(folder, scan_tree_func, mainwin);
990 folder->scan_tree(folder);
991 folder_set_ui_func(folder, NULL, NULL);
993 folderview_set(mainwin->folderview);
996 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
998 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
999 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1000 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1001 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1002 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1004 if (!mainwin->summaryview->folder_item ||
1005 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1006 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1008 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1011 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1013 GtkItemFactory *ifactory;
1017 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1019 if (selection == SUMMARY_SELECTED_SINGLE)
1023 if (!mainwin->summaryview->folder_item ||
1024 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1029 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1030 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1031 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1032 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1033 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1034 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1035 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1036 menu_set_sensitive(ifactory, "/Message/View source", sens);
1037 if (sens && (!mainwin->summaryview->folder_item ||
1038 mainwin->summaryview->folder_item->stype != F_DRAFT))
1040 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1042 if (selection == SUMMARY_SELECTED_SINGLE ||
1043 selection == SUMMARY_SELECTED_MULTIPLE)
1048 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1049 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1050 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1051 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1052 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1054 if (selection != SUMMARY_NONE)
1059 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1060 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1061 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1062 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1063 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1064 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1065 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1068 void main_window_popup(MainWindow *mainwin)
1074 gdk_window_get_origin(mainwin->window->window, &x, &y);
1075 sx = gdk_screen_width();
1076 sy = gdk_screen_height();
1077 x %= sx; if (x < 0) x += sx;
1078 y %= sy; if (y < 0) y += sy;
1079 gdk_window_move(mainwin->window->window, x, y);
1080 gdk_window_raise(mainwin->window->window);
1082 debug_print("window position: x = %d, y = %d\n", x, y);
1084 switch (mainwin->type) {
1085 case SEPARATE_FOLDER:
1086 widget = mainwin->win.sep_folder.folderwin;
1087 gdk_window_get_origin(widget->window, &x, &y);
1088 x %= sx; if (x < 0) x += sx;
1089 y %= sy; if (y < 0) y += sy;
1090 gdk_window_move(widget->window, x, y);
1091 gdk_window_raise(widget->window);
1093 case SEPARATE_MESSAGE:
1094 widget = mainwin->win.sep_message.messagewin;
1095 gdk_window_get_origin(widget->window, &x, &y);
1096 x %= sx; if (x < 0) x += sx;
1097 y %= sy; if (y < 0) y += sy;
1098 gdk_window_move(widget->window, x, y);
1099 gdk_window_raise(widget->window);
1102 widget = mainwin->win.sep_both.folderwin;
1103 gdk_window_get_origin(widget->window, &x, &y);
1104 x %= sx; if (x < 0) x += sx;
1105 y %= sy; if (y < 0) y += sy;
1106 gdk_window_move(widget->window, x, y);
1107 gdk_window_raise(widget->window);
1108 widget = mainwin->win.sep_both.messagewin;
1109 gdk_window_get_origin(widget->window, &x, &y);
1110 x %= sx; if (x < 0) x += sx;
1111 y %= sy; if (y < 0) y += sy;
1112 gdk_window_move(widget->window, x, y);
1113 gdk_window_raise(widget->window);
1119 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1121 GtkWidget *folderwin = NULL;
1122 GtkWidget *messagewin = NULL;
1125 GtkWidget *vbox_body = mainwin->vbox_body;
1127 debug_print(_("Setting widgets..."));
1129 /* create separated window(s) if needed */
1130 if (type & SEPARATE_FOLDER) {
1131 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1132 gtk_window_set_policy(GTK_WINDOW(folderwin),
1134 gtk_widget_set_usize(folderwin, -1,
1135 prefs_common.mainview_height);
1136 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1138 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1139 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1142 if (type & SEPARATE_MESSAGE) {
1143 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1144 gtk_window_set_policy(GTK_WINDOW(messagewin),
1146 gtk_widget_set_usize
1147 (messagewin, prefs_common.mainview_width,
1148 prefs_common.mainview_height
1149 - prefs_common.summaryview_height
1150 + DEFAULT_HEADERVIEW_HEIGHT);
1151 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1153 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1154 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1160 hpaned = gtk_hpaned_new();
1161 gtk_widget_show(hpaned);
1162 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1163 gtk_paned_add1(GTK_PANED(hpaned),
1164 GTK_WIDGET_PTR(mainwin->folderview));
1166 vpaned = gtk_vpaned_new();
1167 if (mainwin->summaryview->msg_is_toggled_on) {
1168 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1169 gtk_paned_add1(GTK_PANED(vpaned),
1170 GTK_WIDGET_PTR(mainwin->summaryview));
1172 gtk_paned_add2(GTK_PANED(hpaned),
1173 GTK_WIDGET_PTR(mainwin->summaryview));
1174 gtk_widget_ref(vpaned);
1176 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1177 prefs_common.summaryview_width,
1178 prefs_common.summaryview_height);
1179 gtk_paned_add2(GTK_PANED(vpaned),
1180 GTK_WIDGET_PTR(mainwin->messageview));
1181 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1182 prefs_common.mainview_width, -1);
1183 gtk_widget_set_usize(mainwin->window,
1184 prefs_common.folderview_width +
1185 prefs_common.mainview_width,
1186 prefs_common.mainwin_height);
1187 gtk_widget_show_all(vpaned);
1189 mainwin->win.sep_none.hpaned = hpaned;
1190 mainwin->win.sep_none.vpaned = vpaned;
1192 case SEPARATE_FOLDER:
1193 vpaned = gtk_vpaned_new();
1194 if (mainwin->summaryview->msg_is_toggled_on) {
1195 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1197 gtk_paned_add1(GTK_PANED(vpaned),
1198 GTK_WIDGET_PTR(mainwin->summaryview));
1200 gtk_box_pack_start(GTK_BOX(vbox_body),
1201 GTK_WIDGET_PTR(mainwin->summaryview),
1203 gtk_widget_ref(vpaned);
1205 gtk_paned_add2(GTK_PANED(vpaned),
1206 GTK_WIDGET_PTR(mainwin->messageview));
1207 gtk_widget_show_all(vpaned);
1208 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1209 prefs_common.summaryview_width,
1210 prefs_common.summaryview_height);
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.mainview_width,
1215 prefs_common.mainview_height);
1217 gtk_container_add(GTK_CONTAINER(folderwin),
1218 GTK_WIDGET_PTR(mainwin->folderview));
1220 mainwin->win.sep_folder.folderwin = folderwin;
1221 mainwin->win.sep_folder.vpaned = vpaned;
1223 gtk_widget_show_all(folderwin);
1225 case SEPARATE_MESSAGE:
1226 hpaned = gtk_hpaned_new();
1227 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1229 gtk_paned_add1(GTK_PANED(hpaned),
1230 GTK_WIDGET_PTR(mainwin->folderview));
1231 gtk_paned_add2(GTK_PANED(hpaned),
1232 GTK_WIDGET_PTR(mainwin->summaryview));
1233 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1234 prefs_common.summaryview_width,
1235 prefs_common.summaryview_height);
1236 gtk_widget_set_usize(mainwin->window,
1237 prefs_common.folderview_width +
1238 prefs_common.mainview_width,
1239 prefs_common.mainwin_height);
1240 gtk_widget_show_all(hpaned);
1241 gtk_container_add(GTK_CONTAINER(messagewin),
1242 GTK_WIDGET_PTR(mainwin->messageview));
1244 mainwin->win.sep_message.messagewin = messagewin;
1245 mainwin->win.sep_message.hpaned = hpaned;
1247 gtk_widget_show_all(messagewin);
1250 gtk_box_pack_start(GTK_BOX(vbox_body),
1251 GTK_WIDGET_PTR(mainwin->summaryview),
1253 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1254 prefs_common.summaryview_width,
1255 prefs_common.summaryview_height);
1256 gtk_widget_set_usize(mainwin->window,
1257 prefs_common.mainview_width,
1258 prefs_common.mainwin_height);
1259 gtk_container_add(GTK_CONTAINER(folderwin),
1260 GTK_WIDGET_PTR(mainwin->folderview));
1261 gtk_container_add(GTK_CONTAINER(messagewin),
1262 GTK_WIDGET_PTR(mainwin->messageview));
1264 mainwin->win.sep_both.folderwin = folderwin;
1265 mainwin->win.sep_both.messagewin = messagewin;
1267 gtk_widget_show_all(folderwin);
1268 gtk_widget_show_all(messagewin);
1272 mainwin->type = type;
1274 debug_print(_("done.\n"));
1277 #include "pixmaps/stock_mail_receive.xpm"
1278 #include "pixmaps/stock_mail_receive_all.xpm"
1279 #include "pixmaps/stock_mail_compose.xpm"
1280 #include "pixmaps/stock_mail_reply.xpm"
1281 #include "pixmaps/stock_mail_reply_to_all.xpm"
1282 #include "pixmaps/stock_mail_forward.xpm"
1283 #include "pixmaps/stock_mail_send.xpm"
1284 #include "pixmaps/stock_preferences.xpm"
1285 #include "pixmaps/stock_properties.xpm"
1286 #include "pixmaps/stock_down_arrow.xpm"
1287 #include "pixmaps/stock_close.xpm"
1288 #include "pixmaps/stock_exec.xpm"
1290 #define CREATE_TOOLBAR_ICON(xpm_d) \
1292 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1293 &container->style->white, \
1295 icon_wid = gtk_pixmap_new(icon, mask); \
1298 static void main_window_toolbar_create(MainWindow *mainwin,
1299 GtkWidget *container)
1304 GtkWidget *icon_wid;
1306 GtkWidget *getall_btn;
1307 GtkWidget *compose_btn;
1308 GtkWidget *reply_btn;
1309 GtkWidget *replyall_btn;
1311 GtkWidget *send_btn;
1312 GtkWidget *prefs_btn;
1313 GtkWidget *account_btn;
1314 GtkWidget *next_btn;
1315 GtkWidget *delete_btn;
1316 GtkWidget *exec_btn;
1318 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1320 gtk_container_add(GTK_CONTAINER(container), toolbar);
1321 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1322 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1323 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1324 GTK_TOOLBAR_SPACE_LINE);
1326 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1327 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1329 _("Incorporate new mail"),
1331 icon_wid, toolbar_inc_cb, mainwin);
1332 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1333 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1335 _("Incorporate new mail of all accounts"),
1341 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1343 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1344 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1346 _("Send queued message(s)"),
1352 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1354 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1355 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1357 _("Compose new message"),
1362 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1363 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1365 _("Reply to the message"),
1370 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1371 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1376 toolbar_reply_to_all_cb,
1378 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1379 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1381 _("Forward the message"),
1387 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1389 CREATE_TOOLBAR_ICON(stock_close_xpm);
1390 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1392 _("Delete the message"),
1398 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1399 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1401 _("Execute marked process"),
1407 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1409 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1410 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1412 _("Next unread message"),
1415 toolbar_next_unread_cb,
1418 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1420 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1421 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1423 _("Common preference"),
1428 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1429 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1431 _("Account setting"),
1436 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1437 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1440 mainwin->toolbar = toolbar;
1441 mainwin->get_btn = get_btn;
1442 mainwin->getall_btn = getall_btn;
1443 mainwin->compose_btn = compose_btn;
1444 mainwin->reply_btn = reply_btn;
1445 mainwin->replyall_btn = replyall_btn;
1446 mainwin->fwd_btn = fwd_btn;
1447 mainwin->send_btn = send_btn;
1448 mainwin->prefs_btn = prefs_btn;
1449 mainwin->account_btn = account_btn;
1450 mainwin->next_btn = next_btn;
1451 mainwin->delete_btn = delete_btn;
1452 mainwin->exec_btn = exec_btn;
1454 gtk_widget_show_all(toolbar);
1457 /* callback functions */
1459 static void toolbar_inc_cb (GtkWidget *widget,
1462 MainWindow *mainwin = (MainWindow *)data;
1464 inc_mail_cb(mainwin, 0, NULL);
1467 static void toolbar_inc_all_cb (GtkWidget *widget,
1470 MainWindow *mainwin = (MainWindow *)data;
1472 inc_all_account_mail_cb(mainwin, 0, NULL);
1475 static void toolbar_send_cb (GtkWidget *widget,
1478 MainWindow *mainwin = (MainWindow *)data;
1480 send_queue_cb(mainwin, 0, NULL);
1483 static void toolbar_compose_cb (GtkWidget *widget,
1486 MainWindow *mainwin = (MainWindow *)data;
1488 compose_cb(mainwin, 0, NULL);
1491 static void toolbar_reply_cb (GtkWidget *widget,
1494 MainWindow *mainwin = (MainWindow *)data;
1496 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1499 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1502 MainWindow *mainwin = (MainWindow *)data;
1504 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1507 static void toolbar_forward_cb (GtkWidget *widget,
1510 MainWindow *mainwin = (MainWindow *)data;
1512 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1515 static void toolbar_delete_cb (GtkWidget *widget,
1518 MainWindow *mainwin = (MainWindow *)data;
1520 summary_delete(mainwin->summaryview);
1523 static void toolbar_exec_cb (GtkWidget *widget,
1526 MainWindow *mainwin = (MainWindow *)data;
1528 summary_execute(mainwin->summaryview);
1531 static void toolbar_next_unread_cb (GtkWidget *widget,
1534 MainWindow *mainwin = (MainWindow *)data;
1536 next_unread_cb(mainwin, 0, NULL);
1539 static void toolbar_prefs_cb (GtkWidget *widget,
1542 prefs_common_open();
1545 static void toolbar_account_cb (GtkWidget *widget,
1548 MainWindow *mainwin = (MainWindow *)data;
1550 prefs_account_open_cb(mainwin, 0, NULL);
1553 static void toolbar_account_button_pressed(GtkWidget *widget,
1554 GdkEventButton *event,
1557 MainWindow *mainwin = (MainWindow *)data;
1560 if (event->button != 3) return;
1562 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1563 event->button, event->time);
1566 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1569 MainWindow *mainwin = (MainWindow *)data;
1573 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1574 event->button, event->time);
1577 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1580 app_exit_cb(data, 0, widget);
1585 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1588 main_window_add_mailbox(mainwin);
1591 static void update_folderview_cb(MainWindow *mainwin, guint action,
1594 summary_show(mainwin->summaryview, NULL, FALSE);
1595 folderview_update_all();
1598 static void new_folder_cb(MainWindow *mainwin, guint action,
1601 folderview_new_folder(mainwin->folderview);
1604 static void rename_folder_cb(MainWindow *mainwin, guint action,
1607 folderview_rename_folder(mainwin->folderview);
1610 static void delete_folder_cb(MainWindow *mainwin, guint action,
1613 folderview_delete_folder(mainwin->folderview);
1616 static void import_mbox_cb(MainWindow *mainwin, guint action,
1622 static void empty_trash_cb(MainWindow *mainwin, guint action,
1625 main_window_empty_trash(mainwin, TRUE);
1628 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1630 summary_save_as(mainwin->summaryview);
1633 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1635 summary_print(mainwin->summaryview);
1638 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1640 if (prefs_common.confirm_on_exit) {
1641 if (alertpanel(_("Exit"), _("Exit this program?"),
1642 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1646 manage_window_focus_in(mainwin->window, NULL, NULL);
1647 app_will_exit(widget, mainwin);
1650 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1653 switch (mainwin->type) {
1655 case SEPARATE_MESSAGE:
1657 case SEPARATE_FOLDER:
1658 if (GTK_CHECK_MENU_ITEM(widget)->active)
1659 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1661 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1664 if (GTK_CHECK_MENU_ITEM(widget)->active)
1665 gtk_widget_show(mainwin->win.sep_both.folderwin);
1667 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1672 static void toggle_message_cb(MainWindow *mainwin, guint action,
1675 switch (mainwin->type) {
1677 case SEPARATE_FOLDER:
1679 case SEPARATE_MESSAGE:
1680 if (GTK_CHECK_MENU_ITEM(widget)->active)
1681 gtk_widget_show(mainwin->win.sep_message.messagewin);
1683 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1686 if (GTK_CHECK_MENU_ITEM(widget)->active)
1687 gtk_widget_show(mainwin->win.sep_both.messagewin);
1689 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1694 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1697 switch ((ToolbarStyle)action) {
1699 gtk_widget_hide(mainwin->handlebox);
1701 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1705 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1709 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1714 if (action != TOOLBAR_NONE) {
1715 gtk_widget_show(mainwin->handlebox);
1716 gtk_widget_queue_resize(mainwin->handlebox);
1719 mainwin->toolbar_style = (ToolbarStyle)action;
1720 prefs_common.toolbar_style = (ToolbarStyle)action;
1723 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1726 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1727 gtk_widget_show(mainwin->hbox_stat);
1728 prefs_common.show_statusbar = TRUE;
1730 gtk_widget_hide(mainwin->hbox_stat);
1731 prefs_common.show_statusbar = FALSE;
1735 static void separate_widget_cb(MainWindow *mainwin, guint action,
1740 type = mainwin->type ^ action;
1741 main_window_separation_change(mainwin, type);
1743 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1744 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1747 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1750 addressbook_open(NULL);
1753 static void log_window_show_cb(MainWindow *mainwin, guint action,
1756 log_window_show(mainwin->logwin);
1759 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1764 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1767 inc_all_account_mail(mainwin);
1770 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1774 if (procmsg_send_queue() < 0)
1775 alertpanel_error(_("Sending queued message failed."));
1777 statusbar_pop_all();
1779 for (list = folder_get_list(); list != NULL; list = list->next) {
1782 folder = list->data;
1783 if (folder->queue) {
1784 folder_item_scan(folder->queue);
1785 folderview_update_item(folder->queue, TRUE);
1790 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1792 if (mainwin->summaryview->folder_item)
1793 compose_new(mainwin->summaryview->folder_item->folder->account);
1798 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1802 msginfo = gtk_ctree_node_get_row_data
1803 (GTK_CTREE(mainwin->summaryview->ctree),
1804 mainwin->summaryview->selected);
1806 if (!msginfo) return;
1810 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1812 case COMPOSE_REPLY_TO_ALL:
1813 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1815 case COMPOSE_FORWARD:
1816 compose_forward(msginfo, FALSE);
1818 case COMPOSE_FORWARD_AS_ATTACH:
1819 compose_forward(msginfo, TRUE);
1822 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1825 summary_set_marks_selected(mainwin->summaryview);
1828 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1830 summary_move_to(mainwin->summaryview);
1833 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1835 summary_copy_to(mainwin->summaryview);
1838 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1840 summary_delete(mainwin->summaryview);
1843 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1845 summary_open_msg(mainwin->summaryview);
1848 static void view_source_cb(MainWindow *mainwin, guint action,
1851 summary_view_source(mainwin->summaryview);
1854 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1856 summary_reedit(mainwin->summaryview);
1859 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1861 summary_mark(mainwin->summaryview);
1864 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1866 summary_unmark(mainwin->summaryview);
1869 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1872 summary_mark_as_unread(mainwin->summaryview);
1875 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1878 summary_mark_as_read(mainwin->summaryview);
1881 static void set_charset_cb(MainWindow *mainwin, guint action,
1886 str = conv_get_charset_str((CharSet)action);
1887 g_free(prefs_common.force_charset);
1888 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1890 summary_redisplay_msg(mainwin->summaryview);
1892 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1895 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1897 GtkItemFactory *ifactory;
1899 ifactory = gtk_item_factory_from_widget(widget);
1902 summary_thread_build(mainwin->summaryview);
1903 prefs_common.enable_thread = TRUE;
1904 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1905 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1907 summary_unthread(mainwin->summaryview);
1908 prefs_common.enable_thread = FALSE;
1909 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1910 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1914 static void set_display_item_cb(MainWindow *mainwin, guint action,
1917 prefs_summary_display_item_set();
1920 static void sort_summary_cb(MainWindow *mainwin, guint action,
1923 summary_sort(mainwin->summaryview, (SummarySortType)action);
1926 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1929 summary_attract_by_subject(mainwin->summaryview);
1932 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1935 summary_delete_duplicated(mainwin->summaryview);
1938 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1940 summary_filter(mainwin->summaryview);
1943 static void execute_summary_cb(MainWindow *mainwin, guint action,
1946 summary_execute(mainwin->summaryview);
1949 static void update_summary_cb(MainWindow *mainwin, guint action,
1953 FolderView *folderview = mainwin->folderview;
1955 if (!mainwin->summaryview->folder_item) return;
1956 if (!folderview->opened) return;
1958 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1959 folderview->opened);
1962 summary_show(mainwin->summaryview, fitem, TRUE);
1965 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1967 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1970 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1972 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
1975 static void next_unread_cb(MainWindow *mainwin, guint action,
1978 summary_select_next_unread(mainwin->summaryview);
1981 static void goto_folder_cb(MainWindow *mainwin, guint action,
1984 FolderItem *to_folder;
1986 to_folder = foldersel_folder_sel(NULL);
1989 folderview_select(mainwin->folderview, to_folder);
1992 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1994 messageview_copy_clipboard(mainwin->messageview);
1997 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1999 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2000 summary_select_all(mainwin->summaryview);
2001 else if (mainwin->summaryview->msg_is_toggled_on &&
2002 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2003 messageview_select_all(mainwin->messageview);
2006 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2009 prefs_common_open();
2012 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2015 prefs_filter_open();
2018 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2022 new_account_cb(mainwin, 0, widget);
2024 gboolean prev_default = cur_account->is_default;
2026 prefs_account_open(cur_account);
2027 if (!prev_default && cur_account->is_default)
2028 account_set_as_default(cur_account);
2029 account_save_config_all();
2031 main_window_reflect_prefs_all();
2035 static void new_account_cb(MainWindow *mainwin, guint action,
2038 account_edit_open();
2039 if (!compose_get_compose_list()) account_add();
2042 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2044 cur_account = (PrefsAccount *)data;
2045 main_window_reflect_prefs_all();
2048 static void manual_open_cb(MainWindow *mainwin, guint action,
2051 manual_open((ManualLang)action);
2054 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2056 MainWindow *mainwin = (MainWindow *)data;
2060 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2061 LOCAL_FOLDER(folder)->rootpath,
2065 str = g_strdup_printf(_("Scanning folder %s ..."),
2066 LOCAL_FOLDER(folder)->rootpath);
2068 STATUSBAR_PUSH(mainwin, str);
2069 STATUSBAR_POP(mainwin);