2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <gtk/gtkmain.h>
24 #include <gtk/gtkwindow.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtksignal.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkcontainer.h>
29 #include <gtk/gtkstatusbar.h>
30 #include <gtk/gtkhpaned.h>
31 #include <gtk/gtkvpaned.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkitemfactory.h>
34 #include <gtk/gtkeditable.h>
35 #include <gtk/gtkmenu.h>
36 #include <gtk/gtkmenuitem.h>
37 #include <gtk/gtkhandlebox.h>
38 #include <gtk/gtktoolbar.h>
39 #include <gtk/gtkbutton.h>
44 #include "mainwindow.h"
45 #include "folderview.h"
46 #include "foldersel.h"
47 #include "summaryview.h"
48 #include "summary_search.h"
49 #include "messageview.h"
50 #include "headerview.h"
58 #include "prefs_common.h"
59 #include "prefs_filter.h"
60 #include "prefs_account.h"
62 #include "addressbook.h"
63 #include "headerwindow.h"
64 #include "logwindow.h"
65 #include "manage_window.h"
66 #include "alertpanel.h"
67 #include "statusbar.h"
68 #include "inputdialog.h"
75 #define AC_LABEL_WIDTH 240
77 #define STATUSBAR_PUSH(mainwin, str) \
79 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
80 mainwin->mainwin_cid, str); \
81 gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
84 #define STATUSBAR_POP(mainwin) \
86 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
87 mainwin->mainwin_cid); \
90 /* list of all instantiated MainWindow */
91 static GList *mainwin_list = NULL;
93 static GdkCursor *watch_cursor;
95 static void main_window_show_cur_account (MainWindow *mainwin);
97 static void main_window_set_widgets (MainWindow *mainwin,
99 static void main_window_toolbar_create (MainWindow *mainwin,
100 GtkWidget *container);
102 /* callback functions */
103 static void toolbar_inc_cb (GtkWidget *widget,
105 static void toolbar_inc_all_cb (GtkWidget *widget,
107 static void toolbar_send_cb (GtkWidget *widget,
110 static void toolbar_compose_cb (GtkWidget *widget,
112 static void toolbar_reply_cb (GtkWidget *widget,
114 static void toolbar_reply_to_all_cb (GtkWidget *widget,
116 static void toolbar_forward_cb (GtkWidget *widget,
119 static void toolbar_delete_cb (GtkWidget *widget,
121 static void toolbar_exec_cb (GtkWidget *widget,
124 static void toolbar_next_unread_cb (GtkWidget *widget,
127 static void toolbar_prefs_cb (GtkWidget *widget,
129 static void toolbar_account_cb (GtkWidget *widget,
132 static void toolbar_account_button_pressed (GtkWidget *widget,
133 GdkEventButton *event,
135 static void ac_label_button_pressed (GtkWidget *widget,
136 GdkEventButton *event,
139 static gint main_window_close_cb (GtkWidget *widget,
143 static void add_mailbox_cb (MainWindow *mainwin,
146 static void update_folderview_cb (MainWindow *mainwin,
149 static void new_folder_cb (MainWindow *mainwin,
152 static void rename_folder_cb (MainWindow *mainwin,
155 static void delete_folder_cb (MainWindow *mainwin,
158 static void import_mbox_cb (MainWindow *mainwin,
161 static void export_mbox_cb (MainWindow *mainwin,
164 static void empty_trash_cb (MainWindow *mainwin,
168 static void save_as_cb (MainWindow *mainwin,
171 static void print_cb (MainWindow *mainwin,
174 static void app_exit_cb (MainWindow *mainwin,
178 static void toggle_folder_cb (MainWindow *mainwin,
181 static void toggle_message_cb (MainWindow *mainwin,
184 static void toggle_toolbar_cb (MainWindow *mainwin,
187 static void toggle_statusbar_cb (MainWindow *mainwin,
190 static void separate_widget_cb (MainWindow *mainwin,
194 static void addressbook_open_cb (MainWindow *mainwin,
197 static void log_window_show_cb (MainWindow *mainwin,
201 static void inc_mail_cb (MainWindow *mainwin,
204 static void inc_all_account_mail_cb (MainWindow *mainwin,
208 static void send_queue_cb (MainWindow *mainwin,
212 static void compose_cb (MainWindow *mainwin,
215 static void reply_cb (MainWindow *mainwin,
219 static void open_msg_cb (MainWindow *mainwin,
223 static void view_source_cb (MainWindow *mainwin,
227 static void reedit_cb (MainWindow *mainwin,
231 static void move_to_cb (MainWindow *mainwin,
234 static void copy_to_cb (MainWindow *mainwin,
237 static void delete_cb (MainWindow *mainwin,
241 static void mark_cb (MainWindow *mainwin,
244 static void unmark_cb (MainWindow *mainwin,
248 static void mark_as_unread_cb (MainWindow *mainwin,
251 static void mark_as_read_cb (MainWindow *mainwin,
255 static void set_charset_cb (MainWindow *mainwin,
259 static void thread_cb (MainWindow *mainwin,
262 static void set_display_item_cb (MainWindow *mainwin,
265 static void sort_summary_cb (MainWindow *mainwin,
268 static void attract_by_subject_cb(MainWindow *mainwin,
272 static void delete_duplicated_cb (MainWindow *mainwin,
275 static void filter_cb (MainWindow *mainwin,
278 static void execute_summary_cb (MainWindow *mainwin,
281 static void update_summary_cb (MainWindow *mainwin,
285 static void prev_cb (MainWindow *mainwin,
288 static void next_cb (MainWindow *mainwin,
292 static void next_unread_cb (MainWindow *mainwin,
296 static void goto_folder_cb (MainWindow *mainwin,
300 static void copy_cb (MainWindow *mainwin,
303 static void allsel_cb (MainWindow *mainwin,
307 static void prefs_common_open_cb (MainWindow *mainwin,
310 static void prefs_filter_open_cb (MainWindow *mainwin,
313 static void prefs_account_open_cb(MainWindow *mainwin,
316 static void new_account_cb (MainWindow *mainwin,
320 static void account_menu_cb (GtkMenuItem *menuitem,
323 static void manual_open_cb (MainWindow *mainwin,
327 static void scan_tree_func (Folder *folder,
331 static GtkItemFactoryEntry mainwin_entries[] =
333 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
334 {N_("/_File/_Add mailbox..."), NULL, add_mailbox_cb, 0, NULL},
335 {N_("/_File/_Update folder tree"), NULL, update_folderview_cb, 0, NULL},
336 {N_("/_File/_Folder"), NULL, NULL, 0, "<Branch>"},
337 {N_("/_File/_Folder/Create _new folder..."),
338 NULL, new_folder_cb, 0, NULL},
339 {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
340 {N_("/_File/_Folder/_Delete folder"), NULL, delete_folder_cb, 0, NULL},
341 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
342 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
343 {N_("/_File/Empty _trash"), NULL, empty_trash_cb, 0, NULL},
344 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
345 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
346 {N_("/_File/_Print..."), "<alt>P", print_cb, 0, NULL},
347 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
348 {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL},
349 {N_("/_File/E_xit"), "<alt>Q", app_exit_cb, 0, NULL},
351 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
352 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
353 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
354 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
355 {N_("/_Edit/_Search"), "<control>S", summary_search_cb, 0, NULL},
357 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
358 {N_("/_View/_Folder tree"), NULL, toggle_folder_cb, 0, "<ToggleItem>"},
359 {N_("/_View/_Message view"), NULL, toggle_message_cb, 0, "<ToggleItem>"},
360 {N_("/_View/_Toolbar"), NULL, NULL, 0, "<Branch>"},
361 {N_("/_View/_Toolbar/Icon _and text"), NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
362 {N_("/_View/_Toolbar/_Icon"), NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
363 {N_("/_View/_Toolbar/_Text"), NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
364 {N_("/_View/_Toolbar/_Non-display"), NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
365 {N_("/_View/_Status bar"), NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
366 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
367 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
368 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
369 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
370 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
371 {N_("/_View/_Code set/_Auto detect"),
372 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
374 #define CODESET_SEPARATOR \
375 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
376 #define CODESET_ACTION(action) \
377 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
379 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
380 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
381 CODESET_ACTION(C_US_ASCII)},
384 {N_("/_View/_Code set/Unicode (_UTF-8)"),
385 CODESET_ACTION(C_UTF_8)},
388 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
389 CODESET_ACTION(C_ISO_8859_1)},
392 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
393 CODESET_ACTION(C_ISO_8859_2)},
395 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
396 CODESET_ACTION(C_ISO_8859_13)},
397 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
398 CODESET_ACTION(C_ISO_8859_4)},
400 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
401 CODESET_ACTION(C_ISO_8859_7)},
403 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
404 CODESET_ACTION(C_ISO_8859_9)},
406 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
407 CODESET_ACTION(C_ISO_8859_5)},
408 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
409 CODESET_ACTION(C_KOI8_R)},
410 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
411 CODESET_ACTION(C_CP1251)},
414 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
415 CODESET_ACTION(C_ISO_2022_JP)},
417 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
418 CODESET_ACTION(C_ISO_2022_JP_2)},
420 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
421 CODESET_ACTION(C_EUC_JP)},
422 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
423 CODESET_ACTION(C_SHIFT_JIS)},
426 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
427 CODESET_ACTION(C_GB2312)},
428 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
429 CODESET_ACTION(C_BIG5)},
430 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
431 CODESET_ACTION(C_EUC_TW)},
432 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
433 CODESET_ACTION(C_ISO_2022_CN)},
435 {N_("/_View/_Code set/Korean (EUC-_KR)"),
436 CODESET_ACTION(C_EUC_KR)},
437 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
438 CODESET_ACTION(C_ISO_2022_KR)},
441 #undef CODESET_SEPARATOR
442 #undef CODESET_ACTION
444 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
445 {N_("/_Message/Rece_ive new mail"), "<alt>I", inc_mail_cb, 0, NULL},
446 {N_("/_Message/Receive from _all accounts"),
447 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
448 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
449 {N_("/_Message/Send queued messa_ges"),
450 NULL, send_queue_cb, 0, NULL},
451 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
452 {N_("/_Message/Compose _new message"), "<alt>N", compose_cb, 0, NULL},
453 {N_("/_Message/_Reply"), "<alt>R", reply_cb, COMPOSE_REPLY, NULL},
454 {N_("/_Message/Reply to a_ll"), "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
455 {N_("/_Message/_Forward"), "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
456 {N_("/_Message/Forward as an a_ttachment"),
457 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/M_ove..."), "<alt>O", move_to_cb, 0, NULL},
460 {N_("/_Message/_Copy..."), NULL, copy_to_cb, 0, NULL},
461 {N_("/_Message/_Delete"), "<alt>D", delete_cb, 0, NULL},
462 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
463 {N_("/_Message/_Mark/_Mark"), NULL, mark_cb, 0, NULL},
464 {N_("/_Message/_Mark/_Unmark"), NULL, unmark_cb, 0, NULL},
465 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
466 {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
467 {N_("/_Message/_Mark/Mark it as _being read"),
468 NULL, mark_as_read_cb, 0, NULL},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/Open in new _window"), "<shift><control>N", open_msg_cb, 0, NULL},
471 {N_("/_Message/View _source"), "<control>U", view_source_cb, 0, NULL},
472 {N_("/_Message/Show all _header"), "<control>H", header_window_show_cb, 0, NULL},
473 {N_("/_Message/Re_edit"), NULL, reedit_cb, 0, NULL},
475 {N_("/_Summary"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_Summary/_Delete duplicated messages"),
477 NULL, delete_duplicated_cb, 0, NULL},
478 {N_("/_Summary/_Filter messages"), NULL, filter_cb, 0, NULL},
479 {N_("/_Summary/E_xecute"), "<alt>X", execute_summary_cb, 0, NULL},
480 {N_("/_Summary/_Update"), "<alt>U", update_summary_cb, 0, NULL},
481 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
482 {N_("/_Summary/_Prev message"), NULL, prev_cb, 0, NULL},
483 {N_("/_Summary/_Next message"), NULL, next_cb, 0, NULL},
484 {N_("/_Summary/N_ext unread message"), NULL, next_unread_cb, 0, NULL},
485 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
486 {N_("/_Summary/_Go to other folder"), "<alt>G", goto_folder_cb, 0, NULL},
487 {N_("/_Summary/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_Summary/_Sort"), NULL, NULL, 0, "<Branch>"},
489 {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
490 {N_("/_Summary/_Sort/Sort by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
491 {N_("/_Summary/_Sort/Sort by _date"), NULL, sort_summary_cb, SORT_BY_DATE, NULL},
492 {N_("/_Summary/_Sort/Sort by _from"), NULL, sort_summary_cb, SORT_BY_FROM, NULL},
493 {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
494 {N_("/_Summary/_Sort/---"), NULL, NULL, 0, "<Separator>"},
495 {N_("/_Summary/_Sort/_Attract by subject"),
496 NULL, attract_by_subject_cb, 0, NULL},
497 {N_("/_Summary/_Thread view"), "<control>T", thread_cb, 0, NULL},
498 {N_("/_Summary/Unt_hread view"), "<shift><control>T", thread_cb, 1, NULL},
499 {N_("/_Summary/Set display _item..."), NULL, set_display_item_cb, 0, NULL},
501 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
502 {N_("/_Tool/_Address book"), "<alt>A", addressbook_open_cb, 0, NULL},
503 {N_("/_Tool/_Log window"), "<alt>L", log_window_show_cb, 0, NULL},
505 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
506 {N_("/_Configuration/_Common preferences..."),
507 NULL, prefs_common_open_cb, 0, NULL},
508 {N_("/_Configuration/_Filter setting..."),
509 NULL, prefs_filter_open_cb, 0, NULL},
510 {N_("/_Configuration/_Preferences per account..."),
511 NULL, prefs_account_open_cb, 0, NULL},
512 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_Configuration/Create _new account..."),
514 NULL, new_account_cb, 0, NULL},
515 {N_("/_Configuration/_Edit accounts..."),
516 NULL, account_edit_open, 0, NULL},
517 {N_("/_Configuration/C_hange current account"),
518 NULL, NULL, 0, "<Branch>"},
520 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
521 {N_("/_Help/_Manual"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Help/_Manual/_English"), NULL, NULL, MANUAL_LANG_EN, NULL},
523 {N_("/_Help/_Manual/_Japanese"), NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
524 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
525 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
528 MainWindow *main_window_create(SeparateType type)
534 GtkWidget *handlebox;
535 GtkWidget *vbox_body;
536 GtkWidget *hbox_stat;
537 GtkWidget *statusbar;
538 GtkWidget *ac_button;
541 FolderView *folderview;
542 SummaryView *summaryview;
543 MessageView *messageview;
544 GdkColormap *colormap;
547 guint n_menu_entries;
548 GtkItemFactory *ifactory;
553 debug_print(_("Creating main window...\n"));
554 mainwin = g_new0(MainWindow, 1);
557 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
558 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
559 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
560 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
561 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
562 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
563 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
564 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
565 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
566 gtk_widget_realize(window);
568 vbox = gtk_vbox_new(FALSE, 0);
569 gtk_widget_show(vbox);
570 gtk_container_add(GTK_CONTAINER(window), vbox);
573 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
574 menubar = menubar_create(window, mainwin_entries,
575 n_menu_entries, "<Main>", mainwin);
576 gtk_widget_show(menubar);
577 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
579 handlebox = gtk_handle_box_new();
580 gtk_widget_show(handlebox);
581 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
583 main_window_toolbar_create(mainwin, handlebox);
585 /* vbox that contains body */
586 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
587 gtk_widget_show(vbox_body);
588 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
589 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
591 hbox_stat = gtk_hbox_new(FALSE, 2);
592 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
594 statusbar = statusbar_create();
595 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
597 ac_button = gtk_button_new();
598 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
599 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
600 gtk_widget_set_usize(ac_button, -1, 1);
601 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
602 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
603 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
605 ac_label = gtk_label_new("");
606 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
608 gtk_widget_show_all(hbox_stat);
611 mainwin->folderview = folderview = folderview_create();
612 mainwin->summaryview = summaryview = summary_create();
613 mainwin->messageview = messageview = messageview_create();
614 mainwin->headerwin = header_window_create();
615 mainwin->logwin = log_window_create();
617 folderview->mainwin = mainwin;
618 folderview->summaryview = summaryview;
620 summaryview->mainwin = mainwin;
621 summaryview->folderview = folderview;
622 summaryview->messageview = messageview;
623 summaryview->headerwin = mainwin->headerwin;
624 summaryview->window = window;
626 messageview->mainwin = mainwin;
628 mainwin->window = window;
629 mainwin->vbox = vbox;
630 mainwin->menubar = menubar;
631 mainwin->handlebox = handlebox;
632 mainwin->vbox_body = vbox_body;
633 mainwin->hbox_stat = hbox_stat;
634 mainwin->statusbar = statusbar;
635 mainwin->ac_button = ac_button;
636 mainwin->ac_label = ac_label;
638 /* set context IDs for status bar */
639 mainwin->mainwin_cid = gtk_statusbar_get_context_id
640 (GTK_STATUSBAR(statusbar), "Main Window");
641 mainwin->folderview_cid = gtk_statusbar_get_context_id
642 (GTK_STATUSBAR(statusbar), "Folder View");
643 mainwin->summaryview_cid = gtk_statusbar_get_context_id
644 (GTK_STATUSBAR(statusbar), "Summary View");
646 /* allocate colors for summary view and folder view */
647 summaryview->color_marked.red = summaryview->color_marked.green = 0;
648 summaryview->color_marked.blue = (guint16)65535;
650 summaryview->color_dim.red = summaryview->color_dim.green =
651 summaryview->color_dim.blue = COLOR_DIM;
653 summaryview->color_normal.red = summaryview->color_normal.green =
654 summaryview->color_normal.blue = 0;
656 folderview->color_new.red = (guint16)55000;
657 folderview->color_new.green = folderview->color_new.blue = 15000;
659 folderview->color_normal.red = folderview->color_normal.green =
660 folderview->color_normal.blue = 0;
662 color[0] = summaryview->color_marked;
663 color[1] = summaryview->color_dim;
664 color[2] = summaryview->color_normal;
665 color[3] = folderview->color_new;
666 color[4] = folderview->color_normal;
668 colormap = gdk_window_get_colormap(window->window);
669 gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
670 for (i = 0; i < 5; i++) {
671 if (success[i] == FALSE)
672 g_warning(_("MainWindow: color allocation %d failed\n"), i);
675 debug_print(_("done.\n"));
677 main_window_set_widgets(mainwin, type);
680 ifactory = gtk_item_factory_from_widget(menubar);
681 menuitem = gtk_item_factory_get_item
682 (ifactory, "/View/Code set/Auto detect");
683 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
685 switch (prefs_common.toolbar_style) {
687 menuitem = gtk_item_factory_get_item
688 (ifactory, "/View/Toolbar/Non-display");
691 menuitem = gtk_item_factory_get_item
692 (ifactory, "/View/Toolbar/Icon");
695 menuitem = gtk_item_factory_get_item
696 (ifactory, "/View/Toolbar/Text");
699 menuitem = gtk_item_factory_get_item
700 (ifactory, "/View/Toolbar/Icon and text");
702 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
704 gtk_widget_hide(mainwin->hbox_stat);
705 menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
706 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
707 prefs_common.show_statusbar);
709 menu_set_sensitive(ifactory, "/Summary/Thread view",
710 prefs_common.enable_thread ? FALSE : TRUE);
711 menu_set_sensitive(ifactory, "/Summary/Unthread view",
712 prefs_common.enable_thread ? TRUE : FALSE);
713 menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
715 /* set account selection menu */
716 ac_menu = gtk_item_factory_get_widget
717 (ifactory, "/Configuration/Change current account");
718 mainwin->ac_menu = ac_menu;
720 main_window_set_toolbar_sensitive(mainwin, FALSE);
722 /* show main window */
723 gtk_widget_set_uposition(mainwin->window,
724 prefs_common.mainwin_x,
725 prefs_common.mainwin_y);
726 gtk_widget_set_usize(window, prefs_common.mainwin_width,
727 prefs_common.mainwin_height);
728 gtk_widget_show(mainwin->window);
730 /* initialize views */
731 folderview_init(folderview);
732 summary_init(summaryview);
733 messageview_init(messageview);
734 header_window_init(mainwin->headerwin);
735 log_window_init(mainwin->logwin);
737 mainwin->cursor_count = 0;
740 watch_cursor = gdk_cursor_new(GDK_WATCH);
742 mainwin_list = g_list_append(mainwin_list, mainwin);
747 void main_window_cursor_wait(MainWindow *mainwin)
749 if (mainwin->cursor_count == 0)
750 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
752 mainwin->cursor_count++;
757 void main_window_cursor_normal(MainWindow *mainwin)
759 if (mainwin->cursor_count)
760 mainwin->cursor_count--;
762 if (mainwin->cursor_count == 0)
763 gdk_window_set_cursor(mainwin->window->window, NULL);
768 void main_window_reflect_prefs_all(void)
773 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
774 mainwin = (MainWindow *)cur->data;
776 main_window_show_cur_account(mainwin);
778 gtk_widget_set_sensitive(mainwin->get_btn, TRUE);
779 gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
781 gtk_widget_set_sensitive(mainwin->get_btn, FALSE);
782 gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
785 summary_change_display_item(mainwin->summaryview);
786 summary_redisplay_msg(mainwin->summaryview);
787 headerview_set_visibility(mainwin->messageview->headerview,
788 prefs_common.display_header_pane);
792 void main_window_set_account_menu(GList *account_list)
794 GList *cur, *cur_ac, *cur_item;
797 PrefsAccount *ac_prefs;
799 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
800 mainwin = (MainWindow *)cur->data;
802 /* destroy all previous menu item */
803 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
804 while (cur_item != NULL) {
805 GList *next = cur_item->next;
806 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
810 for (cur_ac = account_list; cur_ac != NULL;
811 cur_ac = cur_ac->next) {
812 ac_prefs = (PrefsAccount *)cur_ac->data;
814 menuitem = gtk_menu_item_new_with_label
815 (ac_prefs->account_name
816 ? ac_prefs->account_name : _("Untitled"));
817 gtk_widget_show(menuitem);
818 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
819 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
820 GTK_SIGNAL_FUNC(account_menu_cb),
826 static void main_window_show_cur_account(MainWindow *mainwin)
831 ac_name = g_strdup(cur_account
832 ? (cur_account->account_name
833 ? cur_account->account_name : _("Untitled"))
837 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
839 buf = g_strdup(PROG_VERSION);
840 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
843 buf = g_strdup_printf(_("Current account: %s"), ac_name);
844 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
845 gtk_widget_queue_resize(mainwin->ac_button);
851 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
853 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
854 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
855 GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
857 if (mainwin->type == type) return;
859 /* remove widgets from those containers */
860 gtk_widget_ref(folder_wid);
861 gtk_widget_ref(summary_wid);
862 gtk_widget_ref(message_wid);
864 (GTK_CONTAINER(folder_wid->parent), folder_wid);
866 (GTK_CONTAINER(summary_wid->parent), summary_wid);
868 (GTK_CONTAINER(message_wid->parent), message_wid);
870 /* clean containers */
871 switch (mainwin->type) {
873 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
875 case SEPARATE_FOLDER:
876 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
877 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
879 case SEPARATE_MESSAGE:
880 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
881 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
884 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
885 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
889 gtk_widget_hide(mainwin->window);
890 main_window_set_widgets(mainwin, type);
891 gtk_widget_show(mainwin->window);
893 gtk_widget_unref(folder_wid);
894 gtk_widget_unref(summary_wid);
895 gtk_widget_unref(message_wid);
898 void main_window_get_size(MainWindow *mainwin)
900 GtkAllocation *allocation;
902 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
904 prefs_common.summaryview_width = allocation->width;
906 if (mainwin->summaryview->msg_is_toggled_on)
907 prefs_common.summaryview_height = allocation->height;
909 prefs_common.mainview_width = allocation->width;
911 allocation = &mainwin->window->allocation;
913 prefs_common.mainview_height = allocation->height;
914 prefs_common.mainwin_width = allocation->width;
915 prefs_common.mainwin_height = allocation->height;
917 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
919 prefs_common.folderview_width = allocation->width;
920 prefs_common.folderview_height = allocation->height;
923 void main_window_get_position(MainWindow *mainwin)
927 gtkut_widget_get_uposition(mainwin->window, &x, &y);
929 prefs_common.mainview_x = x;
930 prefs_common.mainview_y = y;
931 prefs_common.mainwin_x = x;
932 prefs_common.mainwin_y = y;
934 debug_print(_("window position: x = %d, y = %d\n"), x, y);
937 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
942 if (alertpanel(_("Empty trash"),
943 _("Empty all messages in trash?"),
944 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
946 manage_window_focus_in(mainwin->window, NULL, NULL);
949 procmsg_empty_trash();
951 for (list = folder_get_list(); list != NULL; list = list->next) {
956 folder_item_scan(folder->trash);
957 folderview_update_item(folder->trash, TRUE);
961 if (mainwin->summaryview->folder_item &&
962 mainwin->summaryview->folder_item->stype == F_TRASH)
963 gtk_widget_grab_focus(mainwin->folderview->ctree);
966 void main_window_add_mailbox(MainWindow *mainwin)
971 path = input_dialog(_("Add mailbox"),
972 _("Input the location of mailbox.\n"
973 "If the existing mailbox is specified, it will be\n"
974 "scanned automatically."),
977 if (folder_find_from_path(path)) {
978 alertpanel_error(_("The mailbox `%s' already exists."), path);
982 if (!strcmp(path, "Mail"))
983 folder = folder_new(F_MH, _("Mailbox"), path);
985 folder = folder_new(F_MH, g_basename(path), path);
988 if (folder->create_tree(folder) < 0) {
989 alertpanel_error(_("Creation of the mailbox failed.\n"
990 "Maybe some files already exist, or you don't have the permission to write there."));
991 folder_destroy(folder);
996 folder_set_ui_func(folder, scan_tree_func, mainwin);
997 folder->scan_tree(folder);
998 folder_set_ui_func(folder, NULL, NULL);
1000 folderview_set(mainwin->folderview);
1003 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1005 gtk_widget_set_sensitive(mainwin->reply_btn, sensitive);
1006 gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1007 gtk_widget_set_sensitive(mainwin->fwd_btn, sensitive);
1008 gtk_widget_set_sensitive(mainwin->exec_btn, sensitive);
1009 gtk_widget_set_sensitive(mainwin->next_btn, sensitive);
1011 if (!mainwin->summaryview->folder_item ||
1012 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1013 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1015 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1018 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1020 GtkItemFactory *ifactory;
1024 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1026 if (selection == SUMMARY_SELECTED_SINGLE)
1030 if (!mainwin->summaryview->folder_item ||
1031 mainwin->summaryview->folder_item->folder->type == F_NEWS)
1036 menu_set_sensitive(ifactory, "/File/Save as...", sens);
1037 menu_set_sensitive(ifactory, "/Message/Reply", sens);
1038 menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1039 menu_set_sensitive(ifactory, "/Message/Forward", sens);
1040 menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1041 menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1042 menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1043 menu_set_sensitive(ifactory, "/Message/View source", sens);
1044 if (sens && (!mainwin->summaryview->folder_item ||
1045 mainwin->summaryview->folder_item->stype != F_DRAFT))
1047 menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1049 if (selection == SUMMARY_SELECTED_SINGLE ||
1050 selection == SUMMARY_SELECTED_MULTIPLE)
1055 menu_set_sensitive(ifactory, "/File/Print..." , sens);
1056 menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1057 menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1058 menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1059 menu_set_sensitive(ifactory, "/Message/Mark" , sens);
1061 if (selection != SUMMARY_NONE)
1066 menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1067 menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1068 menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1069 menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1070 menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1071 menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1072 menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1075 void main_window_popup(MainWindow *mainwin)
1081 gdk_window_get_origin(mainwin->window->window, &x, &y);
1082 sx = gdk_screen_width();
1083 sy = gdk_screen_height();
1084 x %= sx; if (x < 0) x += sx;
1085 y %= sy; if (y < 0) y += sy;
1086 gdk_window_move(mainwin->window->window, x, y);
1087 gdk_window_raise(mainwin->window->window);
1089 debug_print("window position: x = %d, y = %d\n", x, y);
1091 switch (mainwin->type) {
1092 case SEPARATE_FOLDER:
1093 widget = mainwin->win.sep_folder.folderwin;
1094 gdk_window_get_origin(widget->window, &x, &y);
1095 x %= sx; if (x < 0) x += sx;
1096 y %= sy; if (y < 0) y += sy;
1097 gdk_window_move(widget->window, x, y);
1098 gdk_window_raise(widget->window);
1100 case SEPARATE_MESSAGE:
1101 widget = mainwin->win.sep_message.messagewin;
1102 gdk_window_get_origin(widget->window, &x, &y);
1103 x %= sx; if (x < 0) x += sx;
1104 y %= sy; if (y < 0) y += sy;
1105 gdk_window_move(widget->window, x, y);
1106 gdk_window_raise(widget->window);
1109 widget = mainwin->win.sep_both.folderwin;
1110 gdk_window_get_origin(widget->window, &x, &y);
1111 x %= sx; if (x < 0) x += sx;
1112 y %= sy; if (y < 0) y += sy;
1113 gdk_window_move(widget->window, x, y);
1114 gdk_window_raise(widget->window);
1115 widget = mainwin->win.sep_both.messagewin;
1116 gdk_window_get_origin(widget->window, &x, &y);
1117 x %= sx; if (x < 0) x += sx;
1118 y %= sy; if (y < 0) y += sy;
1119 gdk_window_move(widget->window, x, y);
1120 gdk_window_raise(widget->window);
1126 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1128 GtkWidget *folderwin = NULL;
1129 GtkWidget *messagewin = NULL;
1132 GtkWidget *vbox_body = mainwin->vbox_body;
1134 debug_print(_("Setting widgets..."));
1136 /* create separated window(s) if needed */
1137 if (type & SEPARATE_FOLDER) {
1138 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1139 gtk_window_set_policy(GTK_WINDOW(folderwin),
1141 gtk_widget_set_usize(folderwin, -1,
1142 prefs_common.mainview_height);
1143 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1145 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1146 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1149 if (type & SEPARATE_MESSAGE) {
1150 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1151 gtk_window_set_policy(GTK_WINDOW(messagewin),
1153 gtk_widget_set_usize
1154 (messagewin, prefs_common.mainview_width,
1155 prefs_common.mainview_height
1156 - prefs_common.summaryview_height
1157 + DEFAULT_HEADERVIEW_HEIGHT);
1158 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1160 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1161 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1167 hpaned = gtk_hpaned_new();
1168 gtk_widget_show(hpaned);
1169 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1170 gtk_paned_add1(GTK_PANED(hpaned),
1171 GTK_WIDGET_PTR(mainwin->folderview));
1173 vpaned = gtk_vpaned_new();
1174 if (mainwin->summaryview->msg_is_toggled_on) {
1175 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1176 gtk_paned_add1(GTK_PANED(vpaned),
1177 GTK_WIDGET_PTR(mainwin->summaryview));
1179 gtk_paned_add2(GTK_PANED(hpaned),
1180 GTK_WIDGET_PTR(mainwin->summaryview));
1181 gtk_widget_ref(vpaned);
1183 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1184 prefs_common.summaryview_width,
1185 prefs_common.summaryview_height);
1186 gtk_paned_add2(GTK_PANED(vpaned),
1187 GTK_WIDGET_PTR(mainwin->messageview));
1188 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1189 prefs_common.mainview_width, -1);
1190 gtk_widget_set_usize(mainwin->window,
1191 prefs_common.folderview_width +
1192 prefs_common.mainview_width,
1193 prefs_common.mainwin_height);
1194 gtk_widget_show_all(vpaned);
1196 mainwin->win.sep_none.hpaned = hpaned;
1197 mainwin->win.sep_none.vpaned = vpaned;
1199 case SEPARATE_FOLDER:
1200 vpaned = gtk_vpaned_new();
1201 if (mainwin->summaryview->msg_is_toggled_on) {
1202 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1204 gtk_paned_add1(GTK_PANED(vpaned),
1205 GTK_WIDGET_PTR(mainwin->summaryview));
1207 gtk_box_pack_start(GTK_BOX(vbox_body),
1208 GTK_WIDGET_PTR(mainwin->summaryview),
1210 gtk_widget_ref(vpaned);
1212 gtk_paned_add2(GTK_PANED(vpaned),
1213 GTK_WIDGET_PTR(mainwin->messageview));
1214 gtk_widget_show_all(vpaned);
1215 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1216 prefs_common.summaryview_width,
1217 prefs_common.summaryview_height);
1218 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1219 prefs_common.mainview_width, -1);
1220 gtk_widget_set_usize(mainwin->window,
1221 prefs_common.mainview_width,
1222 prefs_common.mainview_height);
1224 gtk_container_add(GTK_CONTAINER(folderwin),
1225 GTK_WIDGET_PTR(mainwin->folderview));
1227 mainwin->win.sep_folder.folderwin = folderwin;
1228 mainwin->win.sep_folder.vpaned = vpaned;
1230 gtk_widget_show_all(folderwin);
1232 case SEPARATE_MESSAGE:
1233 hpaned = gtk_hpaned_new();
1234 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1236 gtk_paned_add1(GTK_PANED(hpaned),
1237 GTK_WIDGET_PTR(mainwin->folderview));
1238 gtk_paned_add2(GTK_PANED(hpaned),
1239 GTK_WIDGET_PTR(mainwin->summaryview));
1240 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1241 prefs_common.summaryview_width,
1242 prefs_common.summaryview_height);
1243 gtk_widget_set_usize(mainwin->window,
1244 prefs_common.folderview_width +
1245 prefs_common.mainview_width,
1246 prefs_common.mainwin_height);
1247 gtk_widget_show_all(hpaned);
1248 gtk_container_add(GTK_CONTAINER(messagewin),
1249 GTK_WIDGET_PTR(mainwin->messageview));
1251 mainwin->win.sep_message.messagewin = messagewin;
1252 mainwin->win.sep_message.hpaned = hpaned;
1254 gtk_widget_show_all(messagewin);
1257 gtk_box_pack_start(GTK_BOX(vbox_body),
1258 GTK_WIDGET_PTR(mainwin->summaryview),
1260 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1261 prefs_common.summaryview_width,
1262 prefs_common.summaryview_height);
1263 gtk_widget_set_usize(mainwin->window,
1264 prefs_common.mainview_width,
1265 prefs_common.mainwin_height);
1266 gtk_container_add(GTK_CONTAINER(folderwin),
1267 GTK_WIDGET_PTR(mainwin->folderview));
1268 gtk_container_add(GTK_CONTAINER(messagewin),
1269 GTK_WIDGET_PTR(mainwin->messageview));
1271 mainwin->win.sep_both.folderwin = folderwin;
1272 mainwin->win.sep_both.messagewin = messagewin;
1274 gtk_widget_show_all(folderwin);
1275 gtk_widget_show_all(messagewin);
1279 mainwin->type = type;
1281 debug_print(_("done.\n"));
1284 #include "pixmaps/stock_mail_receive.xpm"
1285 #include "pixmaps/stock_mail_receive_all.xpm"
1286 #include "pixmaps/stock_mail_compose.xpm"
1287 #include "pixmaps/stock_mail_reply.xpm"
1288 #include "pixmaps/stock_mail_reply_to_all.xpm"
1289 #include "pixmaps/stock_mail_forward.xpm"
1290 #include "pixmaps/stock_mail_send.xpm"
1291 #include "pixmaps/stock_preferences.xpm"
1292 #include "pixmaps/stock_properties.xpm"
1293 #include "pixmaps/stock_down_arrow.xpm"
1294 #include "pixmaps/stock_close.xpm"
1295 #include "pixmaps/stock_exec.xpm"
1297 #define CREATE_TOOLBAR_ICON(xpm_d) \
1299 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1300 &container->style->white, \
1302 icon_wid = gtk_pixmap_new(icon, mask); \
1305 static void main_window_toolbar_create(MainWindow *mainwin,
1306 GtkWidget *container)
1311 GtkWidget *icon_wid;
1313 GtkWidget *getall_btn;
1314 GtkWidget *compose_btn;
1315 GtkWidget *reply_btn;
1316 GtkWidget *replyall_btn;
1318 GtkWidget *send_btn;
1319 GtkWidget *prefs_btn;
1320 GtkWidget *account_btn;
1321 GtkWidget *next_btn;
1322 GtkWidget *delete_btn;
1323 GtkWidget *exec_btn;
1325 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1327 gtk_container_add(GTK_CONTAINER(container), toolbar);
1328 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1329 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1330 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1331 GTK_TOOLBAR_SPACE_LINE);
1333 CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1334 get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1336 _("Incorporate new mail"),
1338 icon_wid, toolbar_inc_cb, mainwin);
1339 CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1340 getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1342 _("Incorporate new mail of all accounts"),
1348 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1350 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1351 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1353 _("Send queued message(s)"),
1359 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1361 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1362 compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1364 _("Compose new message"),
1369 CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1370 reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1372 _("Reply to the message"),
1377 CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1378 replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1383 toolbar_reply_to_all_cb,
1385 CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1386 fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1388 _("Forward the message"),
1394 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1396 CREATE_TOOLBAR_ICON(stock_close_xpm);
1397 delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1399 _("Delete the message"),
1405 CREATE_TOOLBAR_ICON(stock_exec_xpm);
1406 exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1408 _("Execute marked process"),
1414 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1416 CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1417 next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1419 _("Next unread message"),
1422 toolbar_next_unread_cb,
1425 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1427 CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1428 prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1430 _("Common preference"),
1435 CREATE_TOOLBAR_ICON(stock_properties_xpm);
1436 account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1438 _("Account setting"),
1443 gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1444 GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1447 mainwin->toolbar = toolbar;
1448 mainwin->get_btn = get_btn;
1449 mainwin->getall_btn = getall_btn;
1450 mainwin->compose_btn = compose_btn;
1451 mainwin->reply_btn = reply_btn;
1452 mainwin->replyall_btn = replyall_btn;
1453 mainwin->fwd_btn = fwd_btn;
1454 mainwin->send_btn = send_btn;
1455 mainwin->prefs_btn = prefs_btn;
1456 mainwin->account_btn = account_btn;
1457 mainwin->next_btn = next_btn;
1458 mainwin->delete_btn = delete_btn;
1459 mainwin->exec_btn = exec_btn;
1461 gtk_widget_show_all(toolbar);
1464 /* callback functions */
1466 static void toolbar_inc_cb (GtkWidget *widget,
1469 MainWindow *mainwin = (MainWindow *)data;
1471 inc_mail_cb(mainwin, 0, NULL);
1474 static void toolbar_inc_all_cb (GtkWidget *widget,
1477 MainWindow *mainwin = (MainWindow *)data;
1479 inc_all_account_mail_cb(mainwin, 0, NULL);
1482 static void toolbar_send_cb (GtkWidget *widget,
1485 MainWindow *mainwin = (MainWindow *)data;
1487 send_queue_cb(mainwin, 0, NULL);
1490 static void toolbar_compose_cb (GtkWidget *widget,
1493 MainWindow *mainwin = (MainWindow *)data;
1495 compose_cb(mainwin, 0, NULL);
1498 static void toolbar_reply_cb (GtkWidget *widget,
1501 MainWindow *mainwin = (MainWindow *)data;
1503 reply_cb(mainwin, COMPOSE_REPLY, NULL);
1506 static void toolbar_reply_to_all_cb (GtkWidget *widget,
1509 MainWindow *mainwin = (MainWindow *)data;
1511 reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1514 static void toolbar_forward_cb (GtkWidget *widget,
1517 MainWindow *mainwin = (MainWindow *)data;
1519 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1522 static void toolbar_delete_cb (GtkWidget *widget,
1525 MainWindow *mainwin = (MainWindow *)data;
1527 summary_delete(mainwin->summaryview);
1530 static void toolbar_exec_cb (GtkWidget *widget,
1533 MainWindow *mainwin = (MainWindow *)data;
1535 summary_execute(mainwin->summaryview);
1538 static void toolbar_next_unread_cb (GtkWidget *widget,
1541 MainWindow *mainwin = (MainWindow *)data;
1543 next_unread_cb(mainwin, 0, NULL);
1546 static void toolbar_prefs_cb (GtkWidget *widget,
1549 prefs_common_open();
1552 static void toolbar_account_cb (GtkWidget *widget,
1555 MainWindow *mainwin = (MainWindow *)data;
1557 prefs_account_open_cb(mainwin, 0, NULL);
1560 static void toolbar_account_button_pressed(GtkWidget *widget,
1561 GdkEventButton *event,
1564 MainWindow *mainwin = (MainWindow *)data;
1567 if (event->button != 3) return;
1569 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1570 event->button, event->time);
1573 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1576 MainWindow *mainwin = (MainWindow *)data;
1580 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1581 event->button, event->time);
1584 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1587 app_exit_cb(data, 0, widget);
1592 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1595 main_window_add_mailbox(mainwin);
1598 static void update_folderview_cb(MainWindow *mainwin, guint action,
1601 summary_show(mainwin->summaryview, NULL, FALSE);
1602 folderview_update_all();
1605 static void new_folder_cb(MainWindow *mainwin, guint action,
1608 folderview_new_folder(mainwin->folderview);
1611 static void rename_folder_cb(MainWindow *mainwin, guint action,
1614 folderview_rename_folder(mainwin->folderview);
1617 static void delete_folder_cb(MainWindow *mainwin, guint action,
1620 folderview_delete_folder(mainwin->folderview);
1623 static void import_mbox_cb(MainWindow *mainwin, guint action,
1626 import_mbox(mainwin->summaryview->folder_item);
1629 static void export_mbox_cb(MainWindow *mainwin, guint action,
1632 export_mbox(mainwin->summaryview->folder_item);
1635 static void empty_trash_cb(MainWindow *mainwin, guint action,
1638 main_window_empty_trash(mainwin, TRUE);
1641 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1643 summary_save_as(mainwin->summaryview);
1646 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1648 summary_print(mainwin->summaryview);
1651 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1653 if (prefs_common.confirm_on_exit) {
1654 if (alertpanel(_("Exit"), _("Exit this program?"),
1655 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1657 manage_window_focus_in(mainwin->window, NULL, NULL);
1660 app_will_exit(widget, mainwin);
1663 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1666 switch (mainwin->type) {
1668 case SEPARATE_MESSAGE:
1670 case SEPARATE_FOLDER:
1671 if (GTK_CHECK_MENU_ITEM(widget)->active)
1672 gtk_widget_show(mainwin->win.sep_folder.folderwin);
1674 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1677 if (GTK_CHECK_MENU_ITEM(widget)->active)
1678 gtk_widget_show(mainwin->win.sep_both.folderwin);
1680 gtk_widget_hide(mainwin->win.sep_both.folderwin);
1685 static void toggle_message_cb(MainWindow *mainwin, guint action,
1688 switch (mainwin->type) {
1690 case SEPARATE_FOLDER:
1692 case SEPARATE_MESSAGE:
1693 if (GTK_CHECK_MENU_ITEM(widget)->active)
1694 gtk_widget_show(mainwin->win.sep_message.messagewin);
1696 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1699 if (GTK_CHECK_MENU_ITEM(widget)->active)
1700 gtk_widget_show(mainwin->win.sep_both.messagewin);
1702 gtk_widget_hide(mainwin->win.sep_both.messagewin);
1707 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1710 switch ((ToolbarStyle)action) {
1712 gtk_widget_hide(mainwin->handlebox);
1714 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1718 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1722 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1727 if (action != TOOLBAR_NONE) {
1728 gtk_widget_show(mainwin->handlebox);
1729 gtk_widget_queue_resize(mainwin->handlebox);
1732 mainwin->toolbar_style = (ToolbarStyle)action;
1733 prefs_common.toolbar_style = (ToolbarStyle)action;
1736 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1739 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1740 gtk_widget_show(mainwin->hbox_stat);
1741 prefs_common.show_statusbar = TRUE;
1743 gtk_widget_hide(mainwin->hbox_stat);
1744 prefs_common.show_statusbar = FALSE;
1748 static void separate_widget_cb(MainWindow *mainwin, guint action,
1753 type = mainwin->type ^ action;
1754 main_window_separation_change(mainwin, type);
1756 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
1757 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
1760 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1763 addressbook_open(NULL);
1766 static void log_window_show_cb(MainWindow *mainwin, guint action,
1769 log_window_show(mainwin->logwin);
1772 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1777 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1780 inc_all_account_mail(mainwin);
1783 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1787 if (procmsg_send_queue() < 0)
1788 alertpanel_error(_("Sending queued message failed."));
1790 statusbar_pop_all();
1792 for (list = folder_get_list(); list != NULL; list = list->next) {
1795 folder = list->data;
1796 if (folder->queue) {
1797 folder_item_scan(folder->queue);
1798 folderview_update_item(folder->queue, TRUE);
1803 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1805 if (mainwin->summaryview->folder_item)
1806 compose_new(mainwin->summaryview->folder_item->folder->account);
1811 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1815 msginfo = gtk_ctree_node_get_row_data
1816 (GTK_CTREE(mainwin->summaryview->ctree),
1817 mainwin->summaryview->selected);
1819 if (!msginfo) return;
1823 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1825 case COMPOSE_REPLY_TO_ALL:
1826 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1828 case COMPOSE_FORWARD:
1829 compose_forward(msginfo, FALSE);
1831 case COMPOSE_FORWARD_AS_ATTACH:
1832 compose_forward(msginfo, TRUE);
1835 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1838 summary_set_marks_selected(mainwin->summaryview);
1841 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1843 summary_move_to(mainwin->summaryview);
1846 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1848 summary_copy_to(mainwin->summaryview);
1851 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1853 summary_delete(mainwin->summaryview);
1856 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1858 summary_open_msg(mainwin->summaryview);
1861 static void view_source_cb(MainWindow *mainwin, guint action,
1864 summary_view_source(mainwin->summaryview);
1867 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1869 summary_reedit(mainwin->summaryview);
1872 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1874 summary_mark(mainwin->summaryview);
1877 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1879 summary_unmark(mainwin->summaryview);
1882 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1885 summary_mark_as_unread(mainwin->summaryview);
1888 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1891 summary_mark_as_read(mainwin->summaryview);
1894 static void set_charset_cb(MainWindow *mainwin, guint action,
1899 str = conv_get_charset_str((CharSet)action);
1900 g_free(prefs_common.force_charset);
1901 prefs_common.force_charset = str ? g_strdup(str) : NULL;
1903 summary_redisplay_msg(mainwin->summaryview);
1905 debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1908 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1910 GtkItemFactory *ifactory;
1912 ifactory = gtk_item_factory_from_widget(widget);
1915 summary_thread_build(mainwin->summaryview);
1916 prefs_common.enable_thread = TRUE;
1917 menu_set_sensitive(ifactory, "/Summary/Thread view", FALSE);
1918 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1920 summary_unthread(mainwin->summaryview);
1921 prefs_common.enable_thread = FALSE;
1922 menu_set_sensitive(ifactory, "/Summary/Thread view", TRUE);
1923 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1927 static void set_display_item_cb(MainWindow *mainwin, guint action,
1930 prefs_summary_display_item_set();
1933 static void sort_summary_cb(MainWindow *mainwin, guint action,
1936 summary_sort(mainwin->summaryview, (SummarySortType)action);
1939 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1942 summary_attract_by_subject(mainwin->summaryview);
1945 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1948 summary_delete_duplicated(mainwin->summaryview);
1951 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1953 summary_filter(mainwin->summaryview);
1956 static void execute_summary_cb(MainWindow *mainwin, guint action,
1959 summary_execute(mainwin->summaryview);
1962 static void update_summary_cb(MainWindow *mainwin, guint action,
1966 FolderView *folderview = mainwin->folderview;
1968 if (!mainwin->summaryview->folder_item) return;
1969 if (!folderview->opened) return;
1971 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1972 folderview->opened);
1975 summary_show(mainwin->summaryview, fitem, TRUE);
1978 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1980 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1983 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1985 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
1988 static void next_unread_cb(MainWindow *mainwin, guint action,
1991 summary_select_next_unread(mainwin->summaryview);
1994 static void goto_folder_cb(MainWindow *mainwin, guint action,
1997 FolderItem *to_folder;
1999 to_folder = foldersel_folder_sel(NULL);
2002 folderview_select(mainwin->folderview, to_folder);
2005 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2007 messageview_copy_clipboard(mainwin->messageview);
2010 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2012 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2013 summary_select_all(mainwin->summaryview);
2014 else if (mainwin->summaryview->msg_is_toggled_on &&
2015 GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2016 messageview_select_all(mainwin->messageview);
2019 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2022 prefs_common_open();
2025 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2028 prefs_filter_open();
2031 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2035 new_account_cb(mainwin, 0, widget);
2037 gboolean prev_default = cur_account->is_default;
2039 prefs_account_open(cur_account);
2040 if (!prev_default && cur_account->is_default)
2041 account_set_as_default(cur_account);
2042 account_save_config_all();
2044 main_window_reflect_prefs_all();
2048 static void new_account_cb(MainWindow *mainwin, guint action,
2051 account_edit_open();
2052 if (!compose_get_compose_list()) account_add();
2055 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2057 cur_account = (PrefsAccount *)data;
2058 main_window_reflect_prefs_all();
2061 static void manual_open_cb(MainWindow *mainwin, guint action,
2064 manual_open((ManualLang)action);
2067 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2069 MainWindow *mainwin = (MainWindow *)data;
2073 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2074 LOCAL_FOLDER(folder)->rootpath,
2078 str = g_strdup_printf(_("Scanning folder %s ..."),
2079 LOCAL_FOLDER(folder)->rootpath);
2081 STATUSBAR_PUSH(mainwin, str);
2082 STATUSBAR_POP(mainwin);