2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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 <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <gtk/gtktooltips.h>
47 #include "mainwindow.h"
48 #include "folderview.h"
49 #include "foldersel.h"
50 #include "summaryview.h"
51 #include "summary_search.h"
52 #include "messageview.h"
53 #include "message_search.h"
54 #include "headerview.h"
56 #include "stock_pixmap.h"
63 #include "prefs_common.h"
64 #include "prefs_actions.h"
65 #include "prefs_filtering.h"
66 #include "prefs_account.h"
67 #include "prefs_summary_column.h"
68 #include "prefs_template.h"
71 #include "addressbook.h"
72 #include "logwindow.h"
73 #include "manage_window.h"
74 #include "alertpanel.h"
75 #include "statusbar.h"
76 #include "inputdialog.h"
83 #include "ssl_manager.h"
84 #include "sslcertwindow.h"
85 #include "prefs_gtk.h"
86 #include "pluginwindow.h"
88 #include "progressindicator.h"
89 #include "localfolder.h"
90 #include "filtering.h"
91 #include "folderutils.h"
92 #include "foldersort.h"
94 #define AC_LABEL_WIDTH 240
96 /* list of all instantiated MainWindow */
97 static GList *mainwin_list = NULL;
99 static GdkCursor *watch_cursor;
101 static void main_window_menu_callback_block (MainWindow *mainwin);
102 static void main_window_menu_callback_unblock (MainWindow *mainwin);
104 static void main_window_show_cur_account (MainWindow *mainwin);
106 static void main_window_set_widgets (MainWindow *mainwin,
110 static void toolbar_account_button_pressed (GtkWidget *widget,
111 GdkEventButton *event,
115 static void toolbar_child_attached (GtkWidget *widget,
118 static void toolbar_child_detached (GtkWidget *widget,
122 static void ac_label_button_pressed (GtkWidget *widget,
123 GdkEventButton *event,
125 static void ac_menu_popup_closed (GtkMenuShell *menu_shell,
128 static gint main_window_close_cb (GtkWidget *widget,
131 static gint folder_window_close_cb (GtkWidget *widget,
134 static gint message_window_close_cb (GtkWidget *widget,
138 static void main_window_size_allocate_cb (GtkWidget *widget,
139 GtkAllocation *allocation,
141 static void folder_window_size_allocate_cb (GtkWidget *widget,
142 GtkAllocation *allocation,
144 static void message_window_size_allocate_cb (GtkWidget *widget,
145 GtkAllocation *allocation,
148 static void update_folderview_cb (MainWindow *mainwin,
151 static void add_mailbox_cb (MainWindow *mainwin,
154 static void foldersort_cb (MainWindow *mainwin,
157 static void import_mbox_cb (MainWindow *mainwin,
160 static void export_mbox_cb (MainWindow *mainwin,
163 static void empty_trash_cb (MainWindow *mainwin,
167 static void save_as_cb (MainWindow *mainwin,
170 static void print_cb (MainWindow *mainwin,
173 static void app_exit_cb (MainWindow *mainwin,
177 static void search_cb (MainWindow *mainwin,
181 static void toggle_folder_cb (MainWindow *mainwin,
184 static void toggle_message_cb (MainWindow *mainwin,
187 static void toggle_toolbar_cb (MainWindow *mainwin,
190 static void toggle_statusbar_cb (MainWindow *mainwin,
193 static void separate_widget_cb (MainWindow *mainwin,
197 static void addressbook_open_cb (MainWindow *mainwin,
200 static void log_window_show_cb (MainWindow *mainwin,
204 static void inc_cancel_cb (MainWindow *mainwin,
208 static void open_msg_cb (MainWindow *mainwin,
212 static void view_source_cb (MainWindow *mainwin,
216 static void show_all_header_cb (MainWindow *mainwin,
220 static void move_to_cb (MainWindow *mainwin,
223 static void copy_to_cb (MainWindow *mainwin,
226 static void delete_cb (MainWindow *mainwin,
230 static void cancel_cb (MainWindow *mainwin,
234 static void mark_cb (MainWindow *mainwin,
237 static void unmark_cb (MainWindow *mainwin,
241 static void mark_as_unread_cb (MainWindow *mainwin,
244 static void mark_as_read_cb (MainWindow *mainwin,
247 static void mark_all_read_cb (MainWindow *mainwin,
251 static void reedit_cb (MainWindow *mainwin,
255 static void add_address_cb (MainWindow *mainwin,
259 static void set_charset_cb (MainWindow *mainwin,
263 static void set_decode_cb (MainWindow *mainwin,
267 static void hide_read_messages (MainWindow *mainwin,
271 static void thread_cb (MainWindow *mainwin,
274 static void expand_threads_cb (MainWindow *mainwin,
277 static void collapse_threads_cb (MainWindow *mainwin,
281 static void set_display_item_cb (MainWindow *mainwin,
284 static void sort_summary_cb (MainWindow *mainwin,
287 static void sort_summary_type_cb (MainWindow *mainwin,
290 static void attract_by_subject_cb(MainWindow *mainwin,
294 static void delete_duplicated_cb (MainWindow *mainwin,
297 static void delete_duplicated_all_cb (MainWindow *mainwin,
300 static void filter_cb (MainWindow *mainwin,
303 static void execute_summary_cb (MainWindow *mainwin,
306 static void update_summary_cb (MainWindow *mainwin,
310 static void prev_cb (MainWindow *mainwin,
313 static void next_cb (MainWindow *mainwin,
316 static void next_unread_cb (MainWindow *mainwin,
319 static void prev_unread_cb (MainWindow *mainwin,
323 static void prev_new_cb (MainWindow *mainwin,
326 static void next_new_cb (MainWindow *mainwin,
329 static void prev_marked_cb (MainWindow *mainwin,
332 static void next_marked_cb (MainWindow *mainwin,
335 static void prev_labeled_cb (MainWindow *mainwin,
338 static void next_labeled_cb (MainWindow *mainwin,
342 static void goto_folder_cb (MainWindow *mainwin,
346 static void copy_cb (MainWindow *mainwin,
349 static void allsel_cb (MainWindow *mainwin,
352 static void select_thread_cb (MainWindow *mainwin,
356 static void create_filter_cb (MainWindow *mainwin,
359 static void create_processing_cb (MainWindow *mainwin,
363 static void prefs_common_open_cb (MainWindow *mainwin,
366 static void prefs_template_open_cb (MainWindow *mainwin,
369 static void prefs_actions_open_cb (MainWindow *mainwin,
372 static void prefs_account_open_cb (MainWindow *mainwin,
376 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
380 static void prefs_post_processing_open_cb (MainWindow *mainwin,
384 static void prefs_filtering_open_cb (MainWindow *mainwin,
388 static void ssl_manager_open_cb (MainWindow *mainwin,
392 static void new_account_cb (MainWindow *mainwin,
396 static void account_selector_menu_cb (GtkMenuItem *menuitem,
398 static void account_receive_menu_cb (GtkMenuItem *menuitem,
401 static void prefs_open_cb (GtkMenuItem *menuitem,
403 static void plugins_open_cb (GtkMenuItem *menuitem,
406 static void online_switch_clicked(GtkButton *btn,
409 static void manual_open_cb (MainWindow *mainwin,
413 static void scan_tree_func (Folder *folder,
417 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
419 static void addr_harvest_cb ( MainWindow *mainwin,
423 static void addr_harvest_msg_cb ( MainWindow *mainwin,
427 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
428 GdkEventFocus *focus,
430 void main_window_reply_cb (MainWindow *mainwin,
433 gboolean mainwindow_progressindicator_hook (gpointer source,
435 #define SEPARATE_ACTION 500
437 static GtkItemFactoryEntry mainwin_entries[] =
439 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
440 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
441 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
442 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
443 {N_("/_File/Change folder order"), NULL, foldersort_cb, 0, NULL},
444 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
445 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
446 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
447 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
448 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
449 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
450 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
451 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
452 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
453 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
454 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
455 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
456 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
458 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
459 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
460 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
461 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
462 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
463 {N_("/_Edit/_Find in current message..."),
464 "<control>F", search_cb, 0, NULL},
465 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
466 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
467 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
468 {N_("/_View/Show or hi_de/_Folder tree"),
469 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
470 {N_("/_View/Show or hi_de/_Message view"),
471 "V", toggle_message_cb, 0, "<ToggleItem>"},
472 {N_("/_View/Show or hi_de/_Toolbar"),
473 NULL, NULL, 0, "<Branch>"},
474 {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
475 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
476 {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
477 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
478 {N_("/_View/Show or hi_de/_Toolbar/_Text"),
479 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
480 {N_("/_View/Show or hi_de/_Toolbar/_None"),
481 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
482 {N_("/_View/Show or hi_de/Status _bar"),
483 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
484 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
485 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
486 {N_("/_View/Separate m_essage view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
487 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
489 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
490 {N_("/_View/_Sort/by s_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
491 {N_("/_View/_Sort/by _date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
492 {N_("/_View/_Sort/by _from"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
493 {N_("/_View/_Sort/by _recipient"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
494 {N_("/_View/_Sort/by _subject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
495 {N_("/_View/_Sort/by _color label"),
496 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
497 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
498 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
499 {N_("/_View/_Sort/by a_ttachment"),
500 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
501 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
502 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
503 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
504 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
506 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
507 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_View/_Sort/_Attract by subject"),
509 NULL, attract_by_subject_cb, 0, NULL},
510 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
511 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
512 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
513 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
514 {N_("/_View/Set displayed _items..."), NULL, set_display_item_cb, 0, NULL},
516 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
518 {N_("/_View/_Go to/_Prev message"), "P", prev_cb, 0, NULL},
519 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
520 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_View/_Go to/P_rev unread message"),
522 "<shift>P", prev_unread_cb, 0, NULL},
523 {N_("/_View/_Go to/N_ext unread message"),
524 "<shift>N", next_unread_cb, 0, NULL},
525 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
527 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
528 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_View/_Go to/Prev _marked message"),
530 NULL, prev_marked_cb, 0, NULL},
531 {N_("/_View/_Go to/Next m_arked message"),
532 NULL, next_marked_cb, 0, NULL},
533 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_View/_Go to/Prev _labeled message"),
535 NULL, prev_labeled_cb, 0, NULL},
536 {N_("/_View/_Go to/Next la_beled message"),
537 NULL, next_labeled_cb, 0, NULL},
538 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_View/_Go to/Other _folder..."), "G", goto_folder_cb, 0, NULL},
540 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
542 #define CODESET_SEPARATOR \
543 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
544 #define CODESET_ACTION(action) \
545 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
547 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
548 {N_("/_View/_Code set/_Auto detect"),
549 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
550 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"},
551 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
552 CODESET_ACTION(C_US_ASCII)},
555 {N_("/_View/_Code set/Unicode (_UTF-8)"),
556 CODESET_ACTION(C_UTF_8)},
559 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
560 CODESET_ACTION(C_ISO_8859_1)},
561 {N_("/_View/_Code set/Western European (ISO-8859-15)"),
562 CODESET_ACTION(C_ISO_8859_15)},
565 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
566 CODESET_ACTION(C_ISO_8859_2)},
568 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
569 CODESET_ACTION(C_ISO_8859_13)},
570 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
571 CODESET_ACTION(C_ISO_8859_4)},
573 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
574 CODESET_ACTION(C_ISO_8859_7)},
576 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
577 CODESET_ACTION(C_ISO_8859_9)},
579 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
580 CODESET_ACTION(C_ISO_8859_5)},
581 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
582 CODESET_ACTION(C_KOI8_R)},
583 {N_("/_View/_Code set/Cyrillic (KOI8-U)"),
584 CODESET_ACTION(C_KOI8_U)},
585 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
586 CODESET_ACTION(C_WINDOWS_1251)},
589 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
590 CODESET_ACTION(C_ISO_2022_JP)},
592 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
593 CODESET_ACTION(C_ISO_2022_JP_2)},
595 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
596 CODESET_ACTION(C_EUC_JP)},
597 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
598 CODESET_ACTION(C_SHIFT_JIS)},
601 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
602 CODESET_ACTION(C_GB2312)},
603 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
604 CODESET_ACTION(C_BIG5)},
605 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
606 CODESET_ACTION(C_EUC_TW)},
607 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
608 CODESET_ACTION(C_ISO_2022_CN)},
610 {N_("/_View/_Code set/Korean (EUC-_KR)"),
611 CODESET_ACTION(C_EUC_KR)},
612 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
613 CODESET_ACTION(C_ISO_2022_KR)},
615 {N_("/_View/_Code set/Thai (TIS-620)"),
616 CODESET_ACTION(C_TIS_620)},
617 {N_("/_View/_Code set/Thai (Windows-874)"),
618 CODESET_ACTION(C_WINDOWS_874)},
621 #undef CODESET_SEPARATOR
622 #undef CODESET_ACTION
624 #define DECODE_SEPARATOR \
625 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
626 #define DECODE_ACTION(action) \
627 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
628 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
629 {N_("/_View/Decode/_Auto detect"),
630 NULL, set_decode_cb, 0, "<RadioItem>"},
631 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_View/Decode/_8bit"), DECODE_ACTION(ENC_8BIT)},
633 {N_("/_View/Decode/_Quoted printable"), DECODE_ACTION(ENC_QUOTED_PRINTABLE)},
634 {N_("/_View/Decode/_Base64"), DECODE_ACTION(ENC_BASE64)},
635 {N_("/_View/Decode/_Uuencode"), DECODE_ACTION(ENC_X_UUENCODE)},
637 #undef DECODE_SEPARATOR
640 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
642 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
643 {N_("/_View/Show all _headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
644 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
647 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
648 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Message/Recei_ve/Get from _current account"),
650 "<control>I", inc_mail_cb, 0, NULL},
651 {N_("/_Message/Recei_ve/Get from _all accounts"),
652 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
653 {N_("/_Message/Recei_ve/Cancel receivin_g"),
654 NULL, inc_cancel_cb, 0, NULL},
655 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
657 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
659 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
660 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
661 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
663 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
664 {N_("/_Message/Repl_y to/mailing _list"),
665 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
666 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
667 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD, NULL},
669 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
670 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
671 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
672 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
673 {N_("/_Message/_Delete"), "<control>D", delete_cb, 0, NULL},
674 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
675 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
676 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
677 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
678 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
679 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
681 {N_("/_Message/_Mark/Mark as rea_d"),
682 NULL, mark_as_read_cb, 0, NULL},
683 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
684 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
687 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
688 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
689 {N_("/_Tools/Add sender to address boo_k"),
690 NULL, add_address_cb, 0, NULL},
691 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
692 {N_("/_Tools/_Harvest addresses/from _Folder..."),
693 NULL, addr_harvest_cb, 0, NULL},
694 {N_("/_Tools/_Harvest addresses/from _Messages..."),
695 NULL, addr_harvest_msg_cb, 0, NULL},
696 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Tools/_Filter all messages in folder"),
698 NULL, filter_cb, 0, NULL},
699 {N_("/_Tools/Filter _selected messages"),
700 NULL, filter_cb, 1, NULL},
701 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
702 {N_("/_Tools/_Create filter rule/_Automatically"),
703 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
704 {N_("/_Tools/_Create filter rule/by _From"),
705 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
706 {N_("/_Tools/_Create filter rule/by _To"),
707 NULL, create_filter_cb, FILTER_BY_TO, NULL},
708 {N_("/_Tools/_Create filter rule/by _Subject"),
709 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
710 {N_("/_Tools/_Create processing rule"), NULL, NULL, 0, "<Branch>"},
711 {N_("/_Tools/_Create processing rule/_Automatically"),
712 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
713 {N_("/_Tools/_Create processing rule/by _From"),
714 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
715 {N_("/_Tools/_Create processing rule/by _To"),
716 NULL, create_processing_cb, FILTER_BY_TO, NULL},
717 {N_("/_Tools/_Create processing rule/by _Subject"),
718 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
719 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
721 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
722 {N_("/_Tools/_Check for new messages in all folders"),
723 NULL, update_folderview_cb, 0, NULL},
724 {N_("/_Tools/Delete du_plicated messages"),
725 NULL, NULL, 0, "<Branch>"},
726 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
727 NULL, delete_duplicated_cb, 0, NULL},
728 {N_("/_Tools/Delete du_plicated messages/In all folders"),
729 NULL, delete_duplicated_all_cb, 0, NULL},
730 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
731 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
733 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Tools/SSL certi_ficates..."),
735 NULL, ssl_manager_open_cb, 0, NULL},
737 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Tools/_Log window"), "<shift><control>L", log_window_show_cb, 0, NULL},
740 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Configuration/C_hange current account"),
742 NULL, NULL, 0, "<Branch>"},
743 {N_("/_Configuration/_Preferences for current account..."),
744 NULL, prefs_account_open_cb, 0, NULL},
745 {N_("/_Configuration/Create _new account..."),
746 NULL, new_account_cb, 0, NULL},
747 {N_("/_Configuration/_Edit accounts..."),
748 NULL, account_edit_open, 0, NULL},
749 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
750 {N_("/_Configuration/_Preferences..."),
751 NULL, prefs_open_cb, 0, NULL},
752 {N_("/_Configuration/Pre-processing..."),
753 NULL, prefs_pre_processing_open_cb, 0, NULL},
754 {N_("/_Configuration/Post-processing..."),
755 NULL, prefs_post_processing_open_cb, 0, NULL},
756 {N_("/_Configuration/_Filtering..."),
757 NULL, prefs_filtering_open_cb, 0, NULL},
758 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
759 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
760 {N_("/_Configuration/Plugins..."), NULL, plugins_open_cb, 0, NULL},
762 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
763 {N_("/_Help/_Manual (Local)"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
764 {N_("/_Help/_Manual (Sylpheed Doc Homepage)"),
765 NULL, manual_open_cb, MANUAL_MANUAL_SYLDOC, NULL},
766 {N_("/_Help/_FAQ (Local)"), NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
767 {N_("/_Help/_FAQ (Sylpheed Doc Homepage)"),
768 NULL, manual_open_cb, MANUAL_FAQ_SYLDOC, NULL},
769 {N_("/_Help/_Claws FAQ (Claws Documentation)"),
770 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
771 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
772 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
775 MainWindow *main_window_create(SeparateType type)
781 GtkWidget *handlebox;
782 GtkWidget *vbox_body;
783 GtkWidget *hbox_stat;
784 GtkWidget *statusbar;
785 GtkWidget *progressbar;
786 GtkWidget *statuslabel;
787 GtkWidget *ac_button;
789 GtkWidget *online_pixmap;
790 GtkWidget *offline_pixmap;
791 GtkWidget *online_switch;
792 GtkWidget *offline_switch;
793 GtkTooltips *offline_tip;
794 GtkTooltips *online_tip;
795 GtkTooltips *sel_ac_tip;
797 FolderView *folderview;
798 SummaryView *summaryview;
799 MessageView *messageview;
800 GdkColormap *colormap;
803 GtkItemFactory *ifactory;
807 guint n_menu_entries;
808 gboolean hide_messageview = FALSE;
810 static GdkGeometry geometry;
812 debug_print("Creating main window...\n");
813 mainwin = g_new0(MainWindow, 1);
816 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
817 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
818 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
819 gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
821 if (!geometry.min_height) {
822 geometry.min_width = 320;
823 geometry.min_height = 200;
825 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
828 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
829 GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
830 MANAGE_WINDOW_SIGNALS_CONNECT(window);
831 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
832 GTK_SIGNAL_FUNC(mainwindow_focus_in_event),
834 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
835 GTK_SIGNAL_FUNC(mainwindow_key_pressed), mainwin);
837 gtk_widget_realize(window);
838 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
841 gtkut_widget_set_app_icon(window);
843 vbox = gtk_vbox_new(FALSE, 0);
844 gtk_widget_show(vbox);
845 gtk_container_add(GTK_CONTAINER(window), vbox);
848 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
849 menubar = menubar_create(window, mainwin_entries,
850 n_menu_entries, "<Main>", mainwin);
851 gtk_widget_show(menubar);
852 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
853 ifactory = gtk_item_factory_from_widget(menubar);
855 menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
856 menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
858 handlebox = gtk_handle_box_new();
859 gtk_widget_show(handlebox);
860 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
861 gtk_signal_connect(GTK_OBJECT(handlebox), "child_attached",
862 GTK_SIGNAL_FUNC(toolbar_child_attached), mainwin);
863 gtk_signal_connect(GTK_OBJECT(handlebox), "child_detached",
864 GTK_SIGNAL_FUNC(toolbar_child_detached), mainwin);
866 /* link window to mainwin->window to avoid gdk warnings */
867 mainwin->window = window;
870 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
874 /* vbox that contains body */
875 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
876 gtk_widget_show(vbox_body);
877 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
878 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
880 hbox_stat = gtk_hbox_new(FALSE, 2);
881 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
883 statusbar = statusbar_create();
884 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
886 progressbar = gtk_progress_bar_new();
887 gtk_widget_set_usize(progressbar, 120, 1);
888 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
890 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
891 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
892 online_tip = gtk_tooltips_new();
893 online_switch = gtk_button_new ();
894 gtk_tooltips_set_tip(GTK_TOOLTIPS(online_tip),online_switch,
895 _("You are online. Click the icon to go offline"), NULL);
896 offline_tip = gtk_tooltips_new();
897 offline_switch = gtk_button_new ();
898 gtk_tooltips_set_tip(GTK_TOOLTIPS(offline_tip),offline_switch,
899 _("You are offline. Click the icon to go online"),
901 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
902 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
903 gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
904 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
905 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
906 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
907 gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
908 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
910 statuslabel = gtk_label_new("");
911 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
913 sel_ac_tip = gtk_tooltips_new();
914 ac_button = gtk_button_new();
915 gtk_tooltips_set_tip(GTK_TOOLTIPS(sel_ac_tip),
916 ac_button, _("Select account"), NULL);
917 gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
918 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
919 gtk_widget_set_usize(ac_button, -1, 1);
920 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
921 gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
922 GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
924 ac_label = gtk_label_new("");
925 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
927 gtk_widget_show_all(hbox_stat);
929 gtk_widget_hide(offline_switch);
931 mainwin->folderview = folderview = folderview_create();
932 mainwin->summaryview = summaryview = summary_create();
933 mainwin->messageview = messageview = messageview_create(mainwin);
934 mainwin->logwin = log_window_create();
936 folderview->mainwin = mainwin;
937 folderview->summaryview = summaryview;
939 summaryview->mainwin = mainwin;
940 summaryview->folderview = folderview;
941 summaryview->messageview = messageview;
942 summaryview->window = window;
944 messageview->statusbar = statusbar;
945 mainwin->vbox = vbox;
946 mainwin->menubar = menubar;
947 mainwin->menu_factory = ifactory;
948 mainwin->handlebox = handlebox;
949 mainwin->vbox_body = vbox_body;
950 mainwin->hbox_stat = hbox_stat;
951 mainwin->statusbar = statusbar;
952 mainwin->progressbar = progressbar;
953 mainwin->statuslabel = statuslabel;
954 mainwin->online_switch = online_switch;
955 mainwin->online_pixmap = online_pixmap;
956 mainwin->offline_pixmap = offline_pixmap;
957 mainwin->ac_button = ac_button;
958 mainwin->ac_label = ac_label;
959 mainwin->offline_switch = offline_switch;
961 /* set context IDs for status bar */
962 mainwin->mainwin_cid = gtk_statusbar_get_context_id
963 (GTK_STATUSBAR(statusbar), "Main Window");
964 mainwin->folderview_cid = gtk_statusbar_get_context_id
965 (GTK_STATUSBAR(statusbar), "Folder View");
966 mainwin->summaryview_cid = gtk_statusbar_get_context_id
967 (GTK_STATUSBAR(statusbar), "Summary View");
968 mainwin->messageview_cid = gtk_statusbar_get_context_id
969 (GTK_STATUSBAR(statusbar), "Message View");
971 messageview->statusbar_cid = mainwin->messageview_cid;
973 /* allocate colors for summary view and folder view */
974 summaryview->color_marked.red = summaryview->color_marked.green = 0;
975 summaryview->color_marked.blue = (guint16)65535;
977 summaryview->color_dim.red = summaryview->color_dim.green =
978 summaryview->color_dim.blue = COLOR_DIM;
980 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
981 &folderview->color_new);
983 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
984 &folderview->color_op);
986 summaryview->color_important.red = 0;
987 summaryview->color_important.green = 0;
988 summaryview->color_important.blue = (guint16)65535;
990 color[0] = summaryview->color_marked;
991 color[1] = summaryview->color_dim;
992 color[2] = folderview->color_new;
993 color[3] = folderview->color_op;
995 colormap = gdk_window_get_colormap(window->window);
996 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
997 for (i = 0; i < 4; i++) {
998 if (success[i] == FALSE)
999 g_warning("MainWindow: color allocation %d failed\n", i);
1002 debug_print("done.\n");
1004 messageview->visible = prefs_common.msgview_visible;
1005 hide_messageview = !messageview->visible;
1007 main_window_set_widgets(mainwin, type);
1009 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
1010 GTK_SIGNAL_FUNC(main_window_size_allocate_cb),
1013 /* set menu items */
1014 menuitem = gtk_item_factory_get_item
1015 (ifactory, "/View/Code set/Auto detect");
1016 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1018 switch (prefs_common.toolbar_style) {
1020 menuitem = gtk_item_factory_get_item
1021 (ifactory, "/View/Show or hide/Toolbar/None");
1024 menuitem = gtk_item_factory_get_item
1025 (ifactory, "/View/Show or hide/Toolbar/Icon");
1028 menuitem = gtk_item_factory_get_item
1029 (ifactory, "/View/Show or hide/Toolbar/Text");
1032 menuitem = gtk_item_factory_get_item
1033 (ifactory, "/View/Show or hide/Toolbar/Icon and text");
1035 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1037 gtk_widget_hide(mainwin->hbox_stat);
1038 menuitem = gtk_item_factory_get_item
1039 (ifactory, "/View/Show or hide/Status bar");
1040 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1041 prefs_common.show_statusbar);
1043 /* set account selection menu */
1044 ac_menu = gtk_item_factory_get_widget
1045 (ifactory, "/Configuration/Change current account");
1046 gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
1047 GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
1048 mainwin->ac_menu = ac_menu;
1050 toolbar_main_set_sensitive(mainwin);
1052 /* create actions menu */
1053 main_window_update_actions_menu(mainwin);
1055 /* attach accel groups to main window */
1056 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1057 gtk_window_add_accel_group \
1059 gtk_item_factory_from_widget(menu)->accel_group)
1061 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1063 /* connect the accelerators for equivalent
1064 menu items in different menus */
1065 menu_connect_identical_items();
1069 /* show main window */
1070 gtk_widget_show(mainwin->window);
1072 /* initialize views */
1073 folderview_init(folderview);
1074 summary_init(summaryview);
1075 messageview_init(messageview);
1076 log_window_init(mainwin->logwin);
1077 log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1078 prefs_common.loglength);
1080 sslcertwindow_register_hook();
1082 mainwin->lock_count = 0;
1083 mainwin->menu_lock_count = 0;
1084 mainwin->cursor_count = 0;
1086 mainwin->progressindicator_hook =
1087 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1090 watch_cursor = gdk_cursor_new(GDK_WATCH);
1092 mainwin_list = g_list_append(mainwin_list, mainwin);
1094 /* init work_offline */
1095 if (prefs_common.work_offline)
1096 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1098 if (mainwin->type == SEPARATE_NONE && hide_messageview)
1099 main_window_toggle_message_view(mainwin);
1104 void main_window_destroy(MainWindow *mainwin)
1106 /* TODO : destroy other component */
1107 messageview_destroy(mainwin->messageview);
1110 void main_window_update_actions_menu(MainWindow *mainwin)
1112 GtkItemFactory *ifactory;
1114 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1115 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1118 void main_window_cursor_wait(MainWindow *mainwin)
1121 if (mainwin->cursor_count == 0)
1122 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1124 mainwin->cursor_count++;
1129 void main_window_cursor_normal(MainWindow *mainwin)
1131 if (mainwin->cursor_count)
1132 mainwin->cursor_count--;
1134 if (mainwin->cursor_count == 0)
1135 gdk_window_set_cursor(mainwin->window->window, NULL);
1140 /* lock / unlock the user-interface */
1141 void main_window_lock(MainWindow *mainwin)
1143 if (mainwin->lock_count == 0)
1144 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1146 mainwin->lock_count++;
1148 main_window_set_menu_sensitive(mainwin);
1149 toolbar_main_set_sensitive(mainwin);
1152 void main_window_unlock(MainWindow *mainwin)
1154 if (mainwin->lock_count)
1155 mainwin->lock_count--;
1157 main_window_set_menu_sensitive(mainwin);
1158 toolbar_main_set_sensitive(mainwin);
1160 if (mainwin->lock_count == 0)
1161 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1164 static void main_window_menu_callback_block(MainWindow *mainwin)
1166 mainwin->menu_lock_count++;
1169 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1171 if (mainwin->menu_lock_count)
1172 mainwin->menu_lock_count--;
1175 void main_window_reflect_prefs_all(void)
1177 main_window_reflect_prefs_all_real(FALSE);
1180 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1183 MainWindow *mainwin;
1186 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1187 mainwin = (MainWindow *)cur->data;
1189 main_window_show_cur_account(mainwin);
1190 main_window_set_menu_sensitive(mainwin);
1191 toolbar_main_set_sensitive(mainwin);
1194 if (pixmap_theme_changed) {
1195 toolbar_update(TOOLBAR_MAIN, mainwin);
1196 messageview_reflect_prefs_pixmap_theme();
1197 compose_reflect_prefs_pixmap_theme();
1198 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1199 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1201 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1202 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1203 mainwin->online_pixmap);
1204 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1205 gtk_widget_show(pixmap);
1206 mainwin->online_pixmap = pixmap;
1207 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1208 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1209 mainwin->offline_pixmap);
1210 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1211 gtk_widget_show(pixmap);
1212 mainwin->offline_pixmap = pixmap;
1215 summary_redisplay_msg(mainwin->summaryview);
1216 headerview_set_visibility(mainwin->messageview->headerview,
1217 prefs_common.display_header_pane);
1221 void main_window_set_summary_column(void)
1224 MainWindow *mainwin;
1226 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1227 mainwin = (MainWindow *)cur->data;
1228 summary_set_column_order(mainwin->summaryview);
1232 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1233 GList *account_list)
1235 GList *cur_ac, *cur_item;
1236 GtkWidget *menuitem;
1237 PrefsAccount *ac_prefs;
1239 /* destroy all previous menu item */
1240 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1241 while (cur_item != NULL) {
1242 GList *next = cur_item->next;
1243 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1247 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1248 ac_prefs = (PrefsAccount *)cur_ac->data;
1250 menuitem = gtk_menu_item_new_with_label
1251 (ac_prefs->account_name
1252 ? ac_prefs->account_name : _("Untitled"));
1253 gtk_widget_show(menuitem);
1254 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1255 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1256 GTK_SIGNAL_FUNC(account_selector_menu_cb),
1261 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1262 GList *account_list)
1264 GList *cur_ac, *cur_item;
1266 GtkWidget *menuitem;
1267 PrefsAccount *ac_prefs;
1269 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1270 "/Message/Receive");
1272 /* search for separator */
1273 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1274 cur_item = cur_item->next) {
1275 if (GTK_BIN(cur_item->data)->child == NULL) {
1276 cur_item = cur_item->next;
1281 /* destroy all previous menu item */
1282 while (cur_item != NULL) {
1283 GList *next = cur_item->next;
1284 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1288 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1289 ac_prefs = (PrefsAccount *)cur_ac->data;
1291 menuitem = gtk_menu_item_new_with_label
1292 (ac_prefs->account_name ? ac_prefs->account_name
1294 gtk_widget_show(menuitem);
1295 gtk_menu_append(GTK_MENU(menu), menuitem);
1296 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1297 GTK_SIGNAL_FUNC(account_receive_menu_cb),
1302 void main_window_set_account_menu(GList *account_list)
1305 MainWindow *mainwin;
1307 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1308 mainwin = (MainWindow *)cur->data;
1309 main_window_set_account_selector_menu(mainwin, account_list);
1310 main_window_set_account_receive_menu(mainwin, account_list);
1314 static void main_window_show_cur_account(MainWindow *mainwin)
1319 ac_name = g_strdup(cur_account
1320 ? (cur_account->account_name
1321 ? cur_account->account_name : _("Untitled"))
1325 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1327 buf = g_strdup(PROG_VERSION);
1328 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1331 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1332 gtk_widget_queue_resize(mainwin->ac_button);
1337 GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
1339 switch (mainwin->type) {
1340 case SEPARATE_FOLDER:
1341 return mainwin->win.sep_folder.folderwin;
1343 return mainwin->win.sep_both.folderwin;
1349 GtkWidget *main_window_get_message_window(MainWindow *mainwin)
1351 switch (mainwin->type) {
1352 case SEPARATE_MESSAGE:
1353 return mainwin->win.sep_message.messagewin;
1355 return mainwin->win.sep_both.messagewin;
1361 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1363 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
1364 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1365 /* GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); */
1366 GtkWidget *message_wid = mainwin->messageview->vbox;
1368 debug_print("Changing window separation type from %d to %d\n",
1369 mainwin->type, type);
1371 if (mainwin->type == type) return;
1373 /* remove widgets from those containers */
1374 gtk_widget_ref(folder_wid);
1375 gtk_widget_ref(summary_wid);
1376 gtk_widget_ref(message_wid);
1377 gtkut_container_remove
1378 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1379 gtkut_container_remove
1380 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1381 gtkut_container_remove
1382 (GTK_CONTAINER(message_wid->parent), message_wid);
1384 /* clean containers */
1385 switch (mainwin->type) {
1387 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1389 case SEPARATE_FOLDER:
1390 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1391 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1393 case SEPARATE_MESSAGE:
1394 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1395 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1398 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1399 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1403 gtk_widget_hide(mainwin->window);
1404 main_window_set_widgets(mainwin, type);
1405 gtk_widget_show(mainwin->window);
1407 gtk_widget_unref(folder_wid);
1408 gtk_widget_unref(summary_wid);
1409 gtk_widget_unref(message_wid);
1412 void main_window_toggle_message_view(MainWindow *mainwin)
1414 SummaryView *summaryview = mainwin->summaryview;
1415 union CompositeWin *cwin = &mainwin->win;
1416 GtkWidget *vpaned = NULL;
1417 GtkWidget *container = NULL;
1418 GtkWidget *msgwin = NULL;
1420 switch (mainwin->type) {
1422 vpaned = cwin->sep_none.vpaned;
1423 container = cwin->sep_none.hpaned;
1425 case SEPARATE_FOLDER:
1426 vpaned = cwin->sep_folder.vpaned;
1427 container = mainwin->vbox_body;
1429 case SEPARATE_MESSAGE:
1430 msgwin = mainwin->win.sep_message.messagewin;
1433 msgwin = mainwin->win.sep_both.messagewin;
1438 if (GTK_WIDGET_VISIBLE(msgwin)) {
1439 gtk_widget_hide(msgwin);
1440 mainwin->messageview->visible = FALSE;
1441 summaryview->displayed = NULL;
1443 gtk_widget_show(msgwin);
1444 mainwin->messageview->visible = TRUE;
1446 } else if (vpaned->parent != NULL) {
1447 mainwin->messageview->visible = FALSE;
1448 summaryview->displayed = NULL;
1449 gtk_widget_ref(vpaned);
1450 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1451 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1452 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1453 GTK_ARROW_UP, GTK_SHADOW_OUT);
1455 mainwin->messageview->visible = TRUE;
1456 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1457 gtk_container_add(GTK_CONTAINER(container), vpaned);
1458 gtk_widget_unref(vpaned);
1459 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1460 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1463 if (mainwin->messageview->visible == FALSE)
1464 messageview_clear(mainwin->messageview);
1466 main_window_set_menu_sensitive(mainwin);
1468 prefs_common.msgview_visible = mainwin->messageview->visible;
1470 gtk_widget_grab_focus(summaryview->ctree);
1473 void main_window_get_size(MainWindow *mainwin)
1475 GtkAllocation *allocation;
1477 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1479 if (allocation->width > 1 && allocation->height > 1) {
1480 prefs_common.summaryview_width = allocation->width;
1482 if ((mainwin->type == SEPARATE_NONE ||
1483 mainwin->type == SEPARATE_FOLDER) &&
1484 messageview_is_visible(mainwin->messageview))
1485 prefs_common.summaryview_height = allocation->height;
1487 prefs_common.mainview_width = allocation->width;
1490 allocation = &mainwin->window->allocation;
1491 if (allocation->width > 1 && allocation->height > 1) {
1492 prefs_common.mainview_height = allocation->height;
1493 prefs_common.mainwin_width = allocation->width;
1494 prefs_common.mainwin_height = allocation->height;
1497 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1498 if (allocation->width > 1 && allocation->height > 1) {
1499 prefs_common.folderview_width = allocation->width;
1500 prefs_common.folderview_height = allocation->height;
1503 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
1504 if (allocation->width > 1 && allocation->height > 1) {
1505 prefs_common.msgview_width = allocation->width;
1506 prefs_common.msgview_height = allocation->height;
1509 debug_print("summaryview size: %d x %d\n",
1510 prefs_common.summaryview_width,
1511 prefs_common.summaryview_height);
1512 debug_print("folderview size: %d x %d\n",
1513 prefs_common.folderview_width,
1514 prefs_common.folderview_height);
1515 debug_print("messageview size: %d x %d\n",
1516 prefs_common.msgview_width,
1517 prefs_common.msgview_height);
1520 void main_window_get_position(MainWindow *mainwin)
1525 gtkut_widget_get_uposition(mainwin->window, &x, &y);
1527 prefs_common.mainview_x = x;
1528 prefs_common.mainview_y = y;
1529 prefs_common.mainwin_x = x;
1530 prefs_common.mainwin_y = y;
1532 debug_print("main window position: %d, %d\n", x, y);
1534 window = main_window_get_folder_window(mainwin);
1536 gtkut_widget_get_uposition(window, &x, &y);
1537 prefs_common.folderwin_x = x;
1538 prefs_common.folderwin_y = y;
1539 debug_print("folder window position: %d, %d\n", x, y);
1541 window = main_window_get_message_window(mainwin);
1543 gtkut_widget_get_uposition(window, &x, &y);
1544 prefs_common.main_msgwin_x = x;
1545 prefs_common.main_msgwin_y = y;
1546 debug_print("message window position: %d, %d\n", x, y);
1550 void main_window_progress_on(MainWindow *mainwin)
1552 gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), TRUE);
1553 gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
1556 void main_window_progress_off(MainWindow *mainwin)
1558 gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), FALSE);
1559 gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
1560 gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
1563 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
1567 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
1568 gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), buf);
1569 gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar),
1570 (cur == 0 && total == 0) ? 0 :
1571 (gfloat)cur / (gfloat)total);
1574 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1580 for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1581 folder = FOLDER(list->data);
1582 if (folder && folder->trash && folder->trash->total_msgs > 0)
1586 if (!has_trash) return;
1589 if (alertpanel(_("Empty trash"),
1590 _("Empty all messages in trash?"),
1591 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1593 manage_window_focus_in(mainwin->window, NULL, NULL);
1596 procmsg_empty_all_trash();
1598 if (mainwin->summaryview->folder_item &&
1599 mainwin->summaryview->folder_item->stype == F_TRASH)
1600 gtk_widget_grab_focus(mainwin->folderview->ctree);
1603 void main_window_add_mailbox(MainWindow *mainwin)
1608 path = input_dialog(_("Add mailbox"),
1609 _("Input the location of mailbox.\n"
1610 "If the existing mailbox is specified, it will be\n"
1611 "scanned automatically."),
1614 if (folder_find_from_path(path)) {
1615 alertpanel_error(_("The mailbox `%s' already exists."), path);
1619 folder = folder_new(folder_get_class_from_string("mh"),
1620 !strcmp(path, "Mail") ? _("Mailbox") : g_basename(path),
1624 if (folder->klass->create_tree(folder) < 0) {
1625 alertpanel_error(_("Creation of the mailbox failed.\n"
1626 "Maybe some files already exist, or you don't have the permission to write there."));
1627 folder_destroy(folder);
1632 folder_set_ui_func(folder, scan_tree_func, mainwin);
1633 folder_scan_tree(folder);
1634 folder_set_ui_func(folder, NULL, NULL);
1637 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1639 SensitiveCond state = 0;
1640 SummarySelection selection;
1641 FolderItem *item = mainwin->summaryview->folder_item;
1642 GList *account_list = account_get_list();
1644 selection = summary_get_selection_type(mainwin->summaryview);
1646 if (mainwin->lock_count == 0)
1647 state |= M_UNLOCKED;
1648 if (selection != SUMMARY_NONE)
1649 state |= M_MSG_EXIST;
1650 if (item && item->path && folder_item_parent(item) && !item->no_select) {
1652 /* if (item->folder->type != F_NEWS) */
1653 state |= M_ALLOW_DELETE;
1655 if (prefs_common.immediate_exec == 0
1656 && mainwin->lock_count == 0)
1657 state |= M_DELAY_EXEC;
1659 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1660 || selection != SUMMARY_NONE)
1661 state |= M_HIDE_READ_MSG;
1663 if (mainwin->summaryview->threaded)
1664 state |= M_THREADED;
1666 state |= M_UNTHREADED;
1667 if (selection == SUMMARY_SELECTED_SINGLE ||
1668 selection == SUMMARY_SELECTED_MULTIPLE)
1669 state |= M_TARGET_EXIST;
1670 if (selection == SUMMARY_SELECTED_SINGLE)
1671 state |= M_SINGLE_TARGET_EXIST;
1672 if (mainwin->summaryview->folder_item &&
1673 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
1676 state |= M_NOT_NEWS;
1677 if (selection == SUMMARY_SELECTED_SINGLE &&
1679 (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1680 item->stype == F_QUEUE)))
1681 state |= M_ALLOW_REEDIT;
1683 state |= M_HAVE_ACCOUNT;
1685 for ( ; account_list != NULL; account_list = account_list->next) {
1686 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1687 state |= M_HAVE_NEWS_ACCOUNT;
1692 if (inc_is_active())
1693 state |= M_INC_ACTIVE;
1700 void main_window_set_menu_sensitive(MainWindow *mainwin)
1702 GtkItemFactory *ifactory = mainwin->menu_factory;
1703 SensitiveCond state;
1706 GtkWidget *menuitem;
1707 SummaryView *summaryview;
1712 static const struct {
1716 {"/File/Add mailbox" , M_UNLOCKED},
1718 {"/File/Add mailbox/MH..." , M_UNLOCKED},
1719 {"/File/Change folder order" , M_UNLOCKED},
1720 {"/File/Export to mbox file..." , M_UNLOCKED},
1721 {"/File/Empty all Trash folders" , M_UNLOCKED},
1722 {"/File/Work offline" , M_UNLOCKED},
1724 {"/File/Save as...", M_TARGET_EXIST|M_UNLOCKED},
1725 {"/File/Print..." , M_TARGET_EXIST|M_UNLOCKED},
1726 /* {"/File/Close" , M_UNLOCKED}, */
1727 {"/File/Exit" , M_UNLOCKED},
1729 {"/Edit/Select thread" , M_SINGLE_TARGET_EXIST},
1731 {"/View/Sort" , M_EXEC},
1732 {"/View/Thread view" , M_EXEC},
1733 {"/View/Expand all threads" , M_MSG_EXIST},
1734 {"/View/Collapse all threads" , M_MSG_EXIST},
1735 {"/View/Hide read messages" , M_HIDE_READ_MSG},
1736 {"/View/Go to/Prev message" , M_MSG_EXIST},
1737 {"/View/Go to/Next message" , M_MSG_EXIST},
1738 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1739 {"/View/Go to/Prev new message" , M_MSG_EXIST},
1740 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1741 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1742 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1743 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1744 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
1745 {"/View/Show all headers" , M_SINGLE_TARGET_EXIST},
1746 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
1748 {"/Message/Receive/Get from current account"
1749 , M_HAVE_ACCOUNT|M_UNLOCKED},
1750 {"/Message/Receive/Get from all accounts"
1751 , M_HAVE_ACCOUNT|M_UNLOCKED},
1752 {"/Message/Receive/Cancel receiving"
1755 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1756 {"/Message/Reply" , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1757 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1758 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1759 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1760 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1761 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1762 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1763 {"/Message/Delete" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
1764 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
1765 {"/Message/Mark" , M_TARGET_EXIST},
1766 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1768 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
1769 {"/Tools/Harvest addresses" , M_UNLOCKED},
1770 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1771 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1772 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1773 {"/Tools/Actions" , M_TARGET_EXIST|M_UNLOCKED},
1774 {"/Tools/Execute" , M_DELAY_EXEC},
1775 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1777 {"/Configuration", M_UNLOCKED},
1782 state = main_window_get_current_state(mainwin);
1784 for (i = 0; entry[i].entry != NULL; i++) {
1785 sensitive = ((entry[i].cond & state) == entry[i].cond);
1786 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1789 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
1791 /* search for separator */
1792 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1793 cur_item = cur_item->next) {
1794 if (GTK_BIN(cur_item->data)->child == NULL) {
1795 cur_item = cur_item->next;
1800 for (; cur_item != NULL; cur_item = cur_item->next) {
1801 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
1802 (M_UNLOCKED & state) != 0);
1805 main_window_menu_callback_block(mainwin);
1807 #define SET_CHECK_MENU_ACTIVE(path, active) \
1809 menuitem = gtk_item_factory_get_widget(ifactory, path); \
1810 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1813 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1814 messageview_is_visible(mainwin->messageview));
1816 summaryview = mainwin->summaryview;
1817 menu_path = "/View/Sort/Don't sort";
1819 switch (summaryview->sort_key) {
1820 case SORT_BY_NUMBER:
1821 menu_path = "/View/Sort/by number"; break;
1823 menu_path = "/View/Sort/by size"; break;
1825 menu_path = "/View/Sort/by date"; break;
1827 menu_path = "/View/Sort/by from"; break;
1829 menu_path = "/View/Sort/by recipient"; break;
1830 case SORT_BY_SUBJECT:
1831 menu_path = "/View/Sort/by subject"; break;
1833 menu_path = "/View/Sort/by color label"; break;
1835 menu_path = "/View/Sort/by mark"; break;
1836 case SORT_BY_STATUS:
1837 menu_path = "/View/Sort/by status"; break;
1839 menu_path = "/View/Sort/by attachment"; break;
1841 menu_path = "/View/Sort/by score"; break;
1842 case SORT_BY_LOCKED:
1843 menu_path = "/View/Sort/by locked"; break;
1846 menu_path = "/View/Sort/Don't sort"; break;
1848 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1850 if (summaryview->sort_type == SORT_ASCENDING) {
1851 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1853 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1856 if (summaryview->sort_key != SORT_BY_NONE) {
1857 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1858 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1860 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1861 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1864 SET_CHECK_MENU_ACTIVE("/View/Show all headers",
1865 mainwin->messageview->mimeview->textview->show_all_headers);
1866 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1868 #undef SET_CHECK_MENU_ACTIVE
1870 main_window_menu_callback_unblock(mainwin);
1873 void main_window_popup(MainWindow *mainwin)
1875 gtkut_window_popup(mainwin->window);
1877 switch (mainwin->type) {
1878 case SEPARATE_FOLDER:
1879 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
1881 case SEPARATE_MESSAGE:
1882 gtkut_window_popup(mainwin->win.sep_message.messagewin);
1885 gtkut_window_popup(mainwin->win.sep_both.folderwin);
1886 gtkut_window_popup(mainwin->win.sep_both.messagewin);
1893 void main_window_show(MainWindow *mainwin)
1895 gtk_widget_show(mainwin->window);
1896 gtk_widget_show(mainwin->vbox_body);
1898 gtk_widget_set_uposition(mainwin->window,
1899 prefs_common.mainwin_x,
1900 prefs_common.mainwin_y);
1902 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->folderview),
1903 prefs_common.folderview_width,
1904 prefs_common.folderview_height);
1905 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1906 prefs_common.summaryview_width,
1907 prefs_common.summaryview_height);
1908 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1909 prefs_common.msgview_width,
1910 prefs_common.msgview_height);
1912 if (mainwin->type & SEPARATE_FOLDER) {
1913 GtkWidget *folderwin;
1915 folderwin = main_window_get_folder_window(mainwin);
1916 gtk_widget_show(folderwin);
1917 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
1918 prefs_common.folderwin_y);
1921 if (mainwin->type & SEPARATE_MESSAGE) {
1922 GtkWidget *messagewin;
1924 messagewin = main_window_get_message_window(mainwin);
1925 gtk_widget_show(messagewin);
1926 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
1927 prefs_common.main_msgwin_y);
1931 void main_window_hide(MainWindow *mainwin)
1933 main_window_get_size(mainwin);
1934 main_window_get_position(mainwin);
1936 gtk_widget_hide(mainwin->window);
1937 gtk_widget_hide(mainwin->vbox_body);
1939 if (mainwin->type & SEPARATE_FOLDER) {
1940 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1943 if (mainwin->type & SEPARATE_MESSAGE) {
1944 gtk_widget_hide(mainwin->win.sep_message.messagewin);
1948 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1950 GtkWidget *folderwin = NULL;
1951 GtkWidget *messagewin = NULL;
1954 GtkWidget *vbox_body = mainwin->vbox_body;
1955 GtkItemFactory *ifactory = mainwin->menu_factory;
1956 GtkWidget *menuitem;
1957 GtkItemFactory *msgview_ifactory;
1959 debug_print("Setting widgets... ");
1961 /* create separated window(s) if needed */
1962 if (type & SEPARATE_FOLDER) {
1963 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1964 gtk_window_set_title(GTK_WINDOW(folderwin),
1965 _("Sylpheed - Folder View"));
1966 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1967 "folder_view", "Sylpheed");
1968 gtk_window_set_policy(GTK_WINDOW(folderwin),
1970 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
1971 prefs_common.folderwin_y);
1972 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1974 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1975 GTK_SIGNAL_FUNC(folder_window_close_cb),
1977 gtk_container_add(GTK_CONTAINER(folderwin),
1978 GTK_WIDGET_PTR(mainwin->folderview));
1979 gtk_widget_realize(folderwin);
1980 if (prefs_common.folderview_visible)
1981 gtk_widget_show(folderwin);
1983 if (type & SEPARATE_MESSAGE) {
1984 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1985 gtk_window_set_title(GTK_WINDOW(messagewin),
1986 _("Sylpheed - Message View"));
1987 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1988 "message_view", "Sylpheed");
1989 gtk_window_set_policy(GTK_WINDOW(messagewin),
1991 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
1992 prefs_common.main_msgwin_y);
1993 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1995 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1996 GTK_SIGNAL_FUNC(message_window_close_cb),
1998 if (messageview_is_visible(mainwin->messageview))
1999 gtk_widget_show(messagewin);
2002 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->folderview),
2003 prefs_common.folderview_width,
2004 prefs_common.folderview_height);
2005 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
2006 prefs_common.summaryview_width,
2007 prefs_common.summaryview_height);
2008 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
2009 prefs_common.msgview_width,
2010 prefs_common.msgview_height);
2014 hpaned = gtk_hpaned_new();
2015 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2016 gtk_paned_add1(GTK_PANED(hpaned),
2017 GTK_WIDGET_PTR(mainwin->folderview));
2018 gtk_widget_show(hpaned);
2019 gtk_widget_queue_resize(hpaned);
2021 vpaned = gtk_vpaned_new();
2022 if (messageview_is_visible(mainwin->messageview)) {
2023 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2024 gtk_paned_add1(GTK_PANED(vpaned),
2025 GTK_WIDGET_PTR(mainwin->summaryview));
2027 gtk_paned_add2(GTK_PANED(hpaned),
2028 GTK_WIDGET_PTR(mainwin->summaryview));
2029 gtk_widget_ref(vpaned);
2031 gtk_paned_add2(GTK_PANED(vpaned),
2032 GTK_WIDGET_PTR(mainwin->messageview));
2033 gtk_widget_show(vpaned);
2034 gtk_widget_queue_resize(vpaned);
2036 mainwin->win.sep_none.hpaned = hpaned;
2037 mainwin->win.sep_none.vpaned = vpaned;
2039 /* remove headerview if not in prefs */
2040 headerview_set_visibility(mainwin->messageview->headerview,
2041 prefs_common.display_header_pane);
2043 case SEPARATE_FOLDER:
2044 vpaned = gtk_vpaned_new();
2045 if (messageview_is_visible(mainwin->messageview)) {
2046 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
2048 gtk_paned_add1(GTK_PANED(vpaned),
2049 GTK_WIDGET_PTR(mainwin->summaryview));
2051 gtk_box_pack_start(GTK_BOX(vbox_body),
2052 GTK_WIDGET_PTR(mainwin->summaryview),
2054 gtk_widget_ref(vpaned);
2056 gtk_paned_add2(GTK_PANED(vpaned),
2057 GTK_WIDGET_PTR(mainwin->messageview));
2058 gtk_widget_show(vpaned);
2059 gtk_widget_queue_resize(vpaned);
2061 mainwin->win.sep_folder.folderwin = folderwin;
2062 mainwin->win.sep_folder.vpaned = vpaned;
2064 /* remove headerview if not in prefs */
2065 headerview_set_visibility(mainwin->messageview->headerview,
2066 prefs_common.display_header_pane);
2069 case SEPARATE_MESSAGE:
2070 hpaned = gtk_hpaned_new();
2071 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2072 gtk_paned_add1(GTK_PANED(hpaned),
2073 GTK_WIDGET_PTR(mainwin->folderview));
2074 gtk_paned_add2(GTK_PANED(hpaned),
2075 GTK_WIDGET_PTR(mainwin->summaryview));
2076 gtk_widget_show(hpaned);
2077 gtk_widget_queue_resize(hpaned);
2078 messageview_add_toolbar(mainwin->messageview, messagewin);
2079 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2080 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2082 mainwin->win.sep_message.messagewin = messagewin;
2083 mainwin->win.sep_message.hpaned = hpaned;
2085 gtk_widget_realize(messagewin);
2086 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2087 gtk_widget_show_all(messagewin);
2088 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2089 mainwin->messageview->handlebox,
2090 prefs_common.toolbar_style);
2094 messageview_add_toolbar(mainwin->messageview, messagewin);
2095 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2096 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2098 gtk_box_pack_start(GTK_BOX(vbox_body),
2099 GTK_WIDGET_PTR(mainwin->summaryview),
2102 mainwin->win.sep_both.folderwin = folderwin;
2103 mainwin->win.sep_both.messagewin = messagewin;
2105 gtk_widget_realize(messagewin);
2106 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2107 gtk_widget_show_all(messagewin);
2108 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2109 mainwin->messageview->handlebox,
2110 prefs_common.toolbar_style);
2115 gtk_widget_set_uposition(mainwin->window,
2116 prefs_common.mainwin_x,
2117 prefs_common.mainwin_y);
2119 gtk_widget_queue_resize(vbox_body);
2120 gtk_widget_queue_resize(mainwin->vbox);
2121 gtk_widget_queue_resize(mainwin->window);
2122 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2123 * and mimeview icon list/ctree lose track of their visibility states */
2124 if (!noticeview_is_visible(mainwin->messageview->noticeview))
2125 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2126 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
2127 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2128 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2129 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2131 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2133 mainwin->type = type;
2136 /* toggle menu state */
2137 menuitem = gtk_item_factory_get_item
2138 (ifactory, "/View/Show or hide/Folder tree");
2139 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2140 (type & SEPARATE_FOLDER) == 0 ? TRUE :
2141 prefs_common.folderview_visible);
2142 gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2143 menuitem = gtk_item_factory_get_item
2144 (ifactory, "/View/Show or hide/Message view");
2145 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2146 (type & SEPARATE_MESSAGE) == 0 ? TRUE :
2147 prefs_common.msgview_visible);
2149 menuitem = gtk_item_factory_get_item
2150 (ifactory, "/View/Separate folder tree");
2151 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2152 ((type & SEPARATE_FOLDER) != 0));
2153 menuitem = gtk_item_factory_get_item
2154 (ifactory, "/View/Separate message view");
2155 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2156 ((type & SEPARATE_MESSAGE) != 0));
2160 (GTK_OBJECT(folderwin), "size_allocate",
2161 GTK_SIGNAL_FUNC(folder_window_size_allocate_cb),
2166 (GTK_OBJECT(messagewin), "size_allocate",
2167 GTK_SIGNAL_FUNC(message_window_size_allocate_cb),
2171 debug_print("done.\n");
2174 void main_window_destroy_all(void)
2176 while (mainwin_list != NULL) {
2177 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2179 /* free toolbar stuff */
2180 toolbar_clear_list(TOOLBAR_MAIN);
2181 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2182 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2184 g_free(mainwin->toolbar);
2187 mainwin_list = g_list_remove(mainwin_list, mainwin);
2189 g_list_free(mainwin_list);
2193 static void toolbar_account_button_pressed(GtkWidget *widget,
2194 GdkEventButton *event,
2197 MainWindow *mainwin = (MainWindow *)data;
2200 if (event->button != 3) return;
2202 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2203 gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2206 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2207 menu_button_position, widget,
2208 event->button, event->time);
2212 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2215 gtk_widget_set_usize(child, 1, -1);
2218 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2221 gtk_widget_set_usize(child, -1, -1);
2224 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2227 MainWindow *mainwin = (MainWindow *)data;
2231 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2232 gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2235 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2236 menu_button_position, widget,
2237 event->button, event->time);
2240 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2242 MainWindow *mainwin = (MainWindow *)data;
2245 button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2246 if (!button) return;
2247 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2248 gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2249 manage_window_focus_in(mainwin->window, NULL, NULL);
2252 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2255 MainWindow *mainwin = (MainWindow *)data;
2257 if (mainwin->lock_count == 0)
2258 app_exit_cb(data, 0, widget);
2263 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2266 MainWindow *mainwin = (MainWindow *)data;
2267 GtkWidget *menuitem;
2269 menuitem = gtk_item_factory_get_item
2270 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2271 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2276 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2279 MainWindow *mainwin = (MainWindow *)data;
2280 GtkWidget *menuitem;
2282 menuitem = gtk_item_factory_get_item
2283 (mainwin->menu_factory, "/View/Show or hide/Message view");
2284 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2289 static void main_window_size_allocate_cb(GtkWidget *widget,
2290 GtkAllocation *allocation,
2293 MainWindow *mainwin = (MainWindow *)data;
2295 main_window_get_size(mainwin);
2298 static void folder_window_size_allocate_cb(GtkWidget *widget,
2299 GtkAllocation *allocation,
2302 MainWindow *mainwin = (MainWindow *)data;
2304 main_window_get_size(mainwin);
2307 static void message_window_size_allocate_cb(GtkWidget *widget,
2308 GtkAllocation *allocation,
2311 MainWindow *mainwin = (MainWindow *)data;
2313 main_window_get_size(mainwin);
2316 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2319 main_window_add_mailbox(mainwin);
2322 static void update_folderview_cb(MainWindow *mainwin, guint action,
2325 summary_show(mainwin->summaryview, NULL);
2326 folderview_check_new_all();
2329 static void foldersort_cb(MainWindow *mainwin, guint action,
2335 static void import_mbox_cb(MainWindow *mainwin, guint action,
2338 import_mbox(mainwin->summaryview->folder_item);
2341 static void export_mbox_cb(MainWindow *mainwin, guint action,
2344 export_mbox(mainwin->summaryview->folder_item);
2347 static void empty_trash_cb(MainWindow *mainwin, guint action,
2350 main_window_empty_trash(mainwin, TRUE);
2353 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2355 summary_save_as(mainwin->summaryview);
2358 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2360 summary_print(mainwin->summaryview);
2363 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2365 if (prefs_common.confirm_on_exit) {
2366 if (alertpanel(_("Exit"), _("Exit this program?"),
2367 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2369 manage_window_focus_in(mainwin->window, NULL, NULL);
2372 app_will_exit(widget, mainwin);
2375 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2378 summary_search(mainwin->summaryview);
2380 message_search(mainwin->messageview);
2383 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2388 active = GTK_CHECK_MENU_ITEM(widget)->active;
2390 switch (mainwin->type) {
2392 case SEPARATE_MESSAGE:
2395 gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2397 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2400 case SEPARATE_FOLDER:
2401 debug_print("separate folder\n");
2403 gtk_widget_show(mainwin->win.sep_folder.folderwin);
2405 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2409 gtk_widget_show(mainwin->win.sep_both.folderwin);
2411 gtk_widget_hide(mainwin->win.sep_both.folderwin);
2415 prefs_common.folderview_visible = active;
2418 static void toggle_message_cb(MainWindow *mainwin, guint action,
2423 active = GTK_CHECK_MENU_ITEM(widget)->active;
2425 if (active != messageview_is_visible(mainwin->messageview))
2426 summary_toggle_view(mainwin->summaryview);
2429 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2432 toolbar_toggle(action, mainwin);
2435 void main_window_reply_cb(MainWindow *mainwin, guint action,
2438 MessageView *msgview = (MessageView*)mainwin->messageview;
2439 GSList *msginfo_list = NULL;
2442 g_return_if_fail(msgview != NULL);
2444 msginfo_list = summary_get_selection(mainwin->summaryview);
2445 g_return_if_fail(msginfo_list != NULL);
2447 body = messageview_get_selection(msgview);
2448 compose_reply_mode((ComposeMode)action, msginfo_list, body);
2450 g_slist_free(msginfo_list);
2454 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2457 if (GTK_CHECK_MENU_ITEM(widget)->active) {
2458 gtk_widget_show(mainwin->hbox_stat);
2459 prefs_common.show_statusbar = TRUE;
2461 gtk_widget_hide(mainwin->hbox_stat);
2462 prefs_common.show_statusbar = FALSE;
2466 static void separate_widget_cb(MainWindow *mainwin, guint action,
2471 if (GTK_CHECK_MENU_ITEM(widget)->active)
2472 type = mainwin->type | action;
2474 type = mainwin->type & ~action;
2476 main_window_separation_change(mainwin, type);
2478 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
2479 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
2482 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline)
2485 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2487 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
2490 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
2492 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active);
2495 static void online_switch_clicked (GtkButton *btn, gpointer data)
2497 MainWindow *mainwin;
2498 GtkItemFactory *ifactory;
2499 GtkCheckMenuItem *menuitem;
2501 mainwin = (MainWindow *) data;
2503 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2504 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2506 g_return_if_fail(mainwin != NULL);
2507 g_return_if_fail(menuitem != NULL);
2509 if (btn == GTK_BUTTON(mainwin->online_switch)) {
2511 gtk_widget_hide (mainwin->online_switch);
2512 gtk_widget_show (mainwin->offline_switch);
2513 menuitem->active = TRUE;
2514 prefs_common.work_offline = TRUE;
2515 inc_autocheck_timer_remove();
2518 gtk_widget_hide (mainwin->offline_switch);
2519 gtk_widget_show (mainwin->online_switch);
2520 menuitem->active = FALSE;
2521 prefs_common.work_offline = FALSE;
2522 inc_autocheck_timer_set();
2526 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2529 addressbook_open(NULL);
2532 static void log_window_show_cb(MainWindow *mainwin, guint action,
2535 log_window_show(mainwin->logwin);
2538 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2543 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2545 summary_move_to(mainwin->summaryview);
2548 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2550 summary_copy_to(mainwin->summaryview);
2553 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2555 summary_delete(mainwin->summaryview);
2558 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2560 summary_cancel(mainwin->summaryview);
2563 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2565 summary_open_msg(mainwin->summaryview);
2568 static void view_source_cb(MainWindow *mainwin, guint action,
2571 summary_view_source(mainwin->summaryview);
2574 static void show_all_header_cb(MainWindow *mainwin, guint action,
2577 if (mainwin->menu_lock_count) return;
2578 summary_display_msg_selected(mainwin->summaryview,
2579 GTK_CHECK_MENU_ITEM(widget)->active);
2582 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2584 summary_mark(mainwin->summaryview);
2587 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2589 summary_unmark(mainwin->summaryview);
2592 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2595 summary_mark_as_unread(mainwin->summaryview);
2598 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2601 summary_mark_as_read(mainwin->summaryview);
2604 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2607 summary_mark_all_read(mainwin->summaryview);
2610 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2612 summary_reedit(mainwin->summaryview);
2615 static void add_address_cb(MainWindow *mainwin, guint action,
2618 summary_add_address(mainwin->summaryview);
2621 static void set_charset_cb(MainWindow *mainwin, guint action,
2626 if (GTK_CHECK_MENU_ITEM(widget)->active) {
2627 str = conv_get_charset_str((CharSet)action);
2629 g_free(mainwin->messageview->forced_charset);
2630 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
2631 procmime_force_charset(str);
2633 summary_redisplay_msg(mainwin->summaryview);
2635 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2639 static void set_decode_cb(MainWindow *mainwin, guint action,
2642 if (GTK_CHECK_MENU_ITEM(widget)->active) {
2643 mainwin->messageview->forced_encoding = (EncodingType)action;
2645 summary_redisplay_msg(mainwin->summaryview);
2647 debug_print("forced encoding: %d\n", action);
2651 static void hide_read_messages (MainWindow *mainwin, guint action,
2654 if (!mainwin->summaryview->folder_item
2655 || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2657 summary_toggle_show_read_messages(mainwin->summaryview);
2660 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2662 if (mainwin->menu_lock_count) return;
2663 if (!mainwin->summaryview->folder_item) return;
2665 if (GTK_CHECK_MENU_ITEM(widget)->active) {
2666 summary_thread_build(mainwin->summaryview);
2667 /* mainwin->summaryview->folder_item->threaded = TRUE; */
2669 summary_unthread(mainwin->summaryview);
2670 /* mainwin->summaryview->folder_item->threaded = FALSE; */
2674 static void expand_threads_cb(MainWindow *mainwin, guint action,
2677 summary_expand_threads(mainwin->summaryview);
2680 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2683 summary_collapse_threads(mainwin->summaryview);
2686 static void set_display_item_cb(MainWindow *mainwin, guint action,
2689 prefs_summary_column_open();
2692 static void sort_summary_cb(MainWindow *mainwin, guint action,
2695 FolderItem *item = mainwin->summaryview->folder_item;
2696 GtkWidget *menuitem;
2698 if (mainwin->menu_lock_count) return;
2700 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
2701 menuitem = gtk_item_factory_get_item
2702 (mainwin->menu_factory, "/View/Sort/Ascending");
2703 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2704 GTK_CHECK_MENU_ITEM(menuitem)->active
2705 ? SORT_ASCENDING : SORT_DESCENDING);
2709 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2712 FolderItem *item = mainwin->summaryview->folder_item;
2714 if (mainwin->menu_lock_count) return;
2716 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
2717 summary_sort(mainwin->summaryview,
2718 item->sort_key, (FolderSortType)action);
2721 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2724 summary_attract_by_subject(mainwin->summaryview);
2727 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2732 item = folderview_get_selected_item(mainwin->folderview);
2734 main_window_cursor_wait(mainwin);
2735 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
2737 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
2738 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
2740 STATUSBAR_POP(mainwin);
2741 main_window_cursor_normal(mainwin);
2751 static void deldup_all(FolderItem *item, gpointer _data)
2753 struct DelDupsData *data = _data;
2756 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
2758 data->dups += result;
2763 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
2766 struct DelDupsData data = {0, 0};
2768 folder_func_to_all_folders(deldup_all, &data);
2769 alertpanel_notice(_("Deleted %d duplicate message(s) in %d folders.\n"),
2770 data.dups, data.folders);
2773 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2775 summary_filter(mainwin->summaryview, (gboolean)action);
2778 static void execute_summary_cb(MainWindow *mainwin, guint action,
2781 summary_execute(mainwin->summaryview);
2784 static void update_summary_cb(MainWindow *mainwin, guint action,
2788 FolderView *folderview = mainwin->folderview;
2790 if (!mainwin->summaryview->folder_item) return;
2791 if (!folderview->opened) return;
2793 folder_update_op_count();
2795 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2796 folderview->opened);
2799 folder_item_scan(fitem);
2800 summary_show(mainwin->summaryview, fitem);
2803 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2805 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2808 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2810 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2813 static void prev_unread_cb(MainWindow *mainwin, guint action,
2816 summary_select_prev_unread(mainwin->summaryview);
2819 static void next_unread_cb(MainWindow *mainwin, guint action,
2822 summary_select_next_unread(mainwin->summaryview);
2825 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2827 summary_select_prev_new(mainwin->summaryview);
2830 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2832 summary_select_next_new(mainwin->summaryview);
2835 static void prev_marked_cb(MainWindow *mainwin, guint action,
2838 summary_select_prev_marked(mainwin->summaryview);
2841 static void next_marked_cb(MainWindow *mainwin, guint action,
2844 summary_select_next_marked(mainwin->summaryview);
2847 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2850 summary_select_prev_labeled(mainwin->summaryview);
2853 static void next_labeled_cb(MainWindow *mainwin, guint action,
2856 summary_select_next_labeled(mainwin->summaryview);
2859 static void goto_folder_cb(MainWindow *mainwin, guint action,
2862 FolderItem *to_folder;
2864 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2867 folderview_select(mainwin->folderview, to_folder);
2870 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2872 messageview_copy_clipboard(mainwin->messageview);
2875 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2877 MessageView *msgview = mainwin->messageview;
2879 if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2880 summary_select_all(mainwin->summaryview);
2881 else if (messageview_is_visible(msgview) &&
2882 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2883 messageview_select_all(mainwin->messageview);
2886 static void select_thread_cb(MainWindow *mainwin, guint action,
2889 summary_select_thread(mainwin->summaryview);
2892 static void create_filter_cb(MainWindow *mainwin, guint action,
2895 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
2898 static void create_processing_cb(MainWindow *mainwin, guint action,
2901 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
2904 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2907 /* prefs_common_open(); */
2910 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
2913 prefs_filtering_open(&pre_global_processing,
2914 _("Processing rules to apply before folder rules"),
2918 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
2921 prefs_filtering_open(&post_global_processing,
2922 _("Processing rules to apply after folder rules"),
2926 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2929 prefs_filtering_open(&filtering_rules,
2930 _("Filtering configuration"),
2934 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2937 prefs_template_open();
2940 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2943 prefs_actions_open(mainwin);
2946 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
2949 ssl_manager_open(mainwin);
2952 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2956 new_account_cb(mainwin, 0, widget);
2958 account_open(cur_account);
2962 static void new_account_cb(MainWindow *mainwin, guint action,
2965 account_edit_open();
2966 if (!compose_get_compose_list()) account_add();
2969 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
2971 cur_account = (PrefsAccount *)data;
2972 main_window_reflect_prefs_all();
2975 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
2977 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
2978 PrefsAccount *account = (PrefsAccount *)data;
2980 inc_account_mail(mainwin, account);
2983 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
2988 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
2990 pluginwindow_create();
2993 static void manual_open_cb(MainWindow *mainwin, guint action,
2996 manual_open((ManualType)action);
2999 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3001 MainWindow *mainwin = (MainWindow *)data;
3005 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3006 LOCAL_FOLDER(folder)->rootpath,
3010 str = g_strdup_printf(_("Scanning folder %s ..."),
3011 LOCAL_FOLDER(folder)->rootpath);
3013 STATUSBAR_PUSH(mainwin, str);
3014 STATUSBAR_POP(mainwin);
3018 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3021 SummaryView *summary;
3023 g_return_val_if_fail(data, FALSE);
3024 summary = ((MainWindow *)data)->summaryview;
3025 g_return_val_if_fail(summary, FALSE);
3027 if (GTK_CLIST(summary->ctree)->selection &&
3028 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3031 if (summary->selected != summary->displayed)
3032 summary_select_node(summary, summary->displayed, FALSE, TRUE);
3036 #define BREAK_ON_MODIFIER_KEY() \
3037 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3039 void mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3042 MainWindow *mainwin = (MainWindow*) data;
3044 if (!mainwin || !event) return;
3046 switch (event->keyval) {
3047 case GDK_Q: /* Quit */
3048 BREAK_ON_MODIFIER_KEY();
3050 app_exit_cb(mainwin, 0, NULL);
3053 if (mainwin->folderview && mainwin->summaryview
3054 && !mainwin->summaryview->displayed) {
3055 summary_lock(mainwin->summaryview);
3056 folderview_select_next_unread(mainwin->folderview);
3057 summary_unlock(mainwin->summaryview);
3065 #undef BREAK_ON_MODIFIER_KEY
3068 * Harvest addresses for selected folder.
3070 static void addr_harvest_cb( MainWindow *mainwin,
3074 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3078 * Harvest addresses for selected messages in summary view.
3080 static void addr_harvest_msg_cb( MainWindow *mainwin,
3084 summary_harvest_address( mainwin->summaryview );
3088 *\brief get a MainWindow
3090 *\return MainWindow * The first mainwindow in the mainwin_list
3092 MainWindow *mainwindow_get_mainwindow(void)
3094 if (mainwin_list && mainwin_list->data)
3095 return (MainWindow *)(mainwin_list->data);
3100 gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3102 ProgressData *data = (ProgressData *) source;
3103 MainWindow *mainwin = (MainWindow *) userdata;
3105 switch (data->cmd) {
3106 case PROGRESS_COMMAND_START:
3107 case PROGRESS_COMMAND_STOP:
3108 gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), 0.0);
3110 case PROGRESS_COMMAND_SET_PERCENTAGE:
3111 gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), data->value);
3114 while (gtk_events_pending()) gtk_main_iteration ();