2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkstatusbar.h>
32 #include <gtk/gtkprogressbar.h>
33 #include <gtk/gtkhpaned.h>
34 #include <gtk/gtkvpaned.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkmenu.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkhandlebox.h>
41 #include <gtk/gtktoolbar.h>
42 #include <gtk/gtkbutton.h>
43 #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"
64 #include "prefs_common.h"
65 #include "prefs_actions.h"
66 #include "prefs_filtering.h"
67 #include "prefs_account.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_folder_column.h"
70 #include "prefs_template.h"
73 #include "addressbook.h"
74 #include "logwindow.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "inputdialog.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefs_gtk.h"
88 #include "pluginwindow.h"
90 #include "progressindicator.h"
91 #include "localfolder.h"
92 #include "filtering.h"
93 #include "folderutils.h"
94 #include "foldersort.h"
95 #include "icon_legend.h"
96 #include "colorlabel.h"
101 #define AC_LABEL_WIDTH 240
103 /* list of all instantiated MainWindow */
104 static GList *mainwin_list = NULL;
106 static GdkCursor *watch_cursor = NULL;
107 static GdkCursor *hand_cursor = NULL;
109 static gint iconified_count = 0;
111 static void main_window_menu_callback_block (MainWindow *mainwin);
112 static void main_window_menu_callback_unblock (MainWindow *mainwin);
114 static void main_window_show_cur_account (MainWindow *mainwin);
116 static void main_window_separation_change (MainWindow *mainwin,
117 LayoutType layout_mode);
119 static void main_window_set_widgets (MainWindow *mainwin,
120 LayoutType layout_mode);
122 static void toolbar_child_attached (GtkWidget *widget,
125 static void toolbar_child_detached (GtkWidget *widget,
129 static gboolean ac_label_button_pressed (GtkWidget *widget,
130 GdkEventButton *event,
133 static gint main_window_close_cb (GtkWidget *widget,
137 static void main_window_size_allocate_cb (GtkWidget *widget,
138 GtkAllocation *allocation,
140 static void folder_window_size_allocate_cb (GtkWidget *widget,
141 GtkAllocation *allocation,
143 static void message_window_size_allocate_cb (GtkWidget *widget,
144 GtkAllocation *allocation,
147 static void update_folderview_cb (MainWindow *mainwin,
150 static void add_mailbox_cb (MainWindow *mainwin,
153 static void foldersort_cb (MainWindow *mainwin,
156 static void import_mbox_cb (MainWindow *mainwin,
159 static void export_mbox_cb (MainWindow *mainwin,
162 static void export_list_mbox_cb (MainWindow *mainwin,
165 static void empty_trash_cb (MainWindow *mainwin,
169 static void save_as_cb (MainWindow *mainwin,
172 static void print_cb (MainWindow *mainwin,
175 static void app_exit_cb (MainWindow *mainwin,
179 static void search_cb (MainWindow *mainwin,
183 static void toggle_message_cb (MainWindow *mainwin,
186 static void toggle_toolbar_cb (MainWindow *mainwin,
189 static void toggle_statusbar_cb (MainWindow *mainwin,
192 static void set_layout_cb (MainWindow *mainwin,
196 static void addressbook_open_cb (MainWindow *mainwin,
199 static void log_window_show_cb (MainWindow *mainwin,
203 static void inc_cancel_cb (MainWindow *mainwin,
207 static void open_msg_cb (MainWindow *mainwin,
211 static void view_source_cb (MainWindow *mainwin,
215 static void show_all_header_cb (MainWindow *mainwin,
219 static void hide_quotes_cb(MainWindow *mainwin,
223 static void move_to_cb (MainWindow *mainwin,
226 static void copy_to_cb (MainWindow *mainwin,
229 static void delete_cb (MainWindow *mainwin,
232 static void delete_trash_cb (MainWindow *mainwin,
236 static void cancel_cb (MainWindow *mainwin,
240 static void mark_cb (MainWindow *mainwin,
243 static void unmark_cb (MainWindow *mainwin,
247 static void mark_as_unread_cb (MainWindow *mainwin,
250 static void mark_as_read_cb (MainWindow *mainwin,
253 static void mark_all_read_cb (MainWindow *mainwin,
256 static void mark_as_spam_cb (MainWindow *mainwin,
260 static void ignore_thread_cb (MainWindow *mainwin,
263 static void unignore_thread_cb (MainWindow *mainwin,
266 static void lock_msgs_cb (MainWindow *mainwin,
269 static void unlock_msgs_cb (MainWindow *mainwin,
273 static void reedit_cb (MainWindow *mainwin,
277 static void add_address_cb (MainWindow *mainwin,
281 static void set_charset_cb (MainWindow *mainwin,
285 static void set_decode_cb (MainWindow *mainwin,
289 static void hide_read_messages (MainWindow *mainwin,
293 static void thread_cb (MainWindow *mainwin,
296 static void expand_threads_cb (MainWindow *mainwin,
299 static void collapse_threads_cb (MainWindow *mainwin,
303 static void set_summary_display_item_cb (MainWindow *mainwin,
306 static void set_folder_display_item_cb (MainWindow *mainwin,
309 static void sort_summary_cb (MainWindow *mainwin,
312 static void sort_summary_type_cb (MainWindow *mainwin,
315 static void attract_by_subject_cb(MainWindow *mainwin,
319 static void delete_duplicated_cb (MainWindow *mainwin,
322 static void delete_duplicated_all_cb (MainWindow *mainwin,
325 static void filter_cb (MainWindow *mainwin,
328 static void execute_summary_cb (MainWindow *mainwin,
331 static void update_summary_cb (MainWindow *mainwin,
335 static void prev_cb (MainWindow *mainwin,
338 static void next_cb (MainWindow *mainwin,
341 static void next_unread_cb (MainWindow *mainwin,
344 static void prev_unread_cb (MainWindow *mainwin,
348 static void prev_new_cb (MainWindow *mainwin,
351 static void next_new_cb (MainWindow *mainwin,
354 static void prev_marked_cb (MainWindow *mainwin,
357 static void next_marked_cb (MainWindow *mainwin,
360 static void prev_labeled_cb (MainWindow *mainwin,
363 static void next_labeled_cb (MainWindow *mainwin,
366 static void last_read_cb (MainWindow *mainwin,
369 static void parent_cb (MainWindow *mainwin,
373 static void goto_folder_cb (MainWindow *mainwin,
376 static void goto_unread_folder_cb(MainWindow *mainwin,
380 static void copy_cb (MainWindow *mainwin,
383 static void allsel_cb (MainWindow *mainwin,
386 static void select_thread_cb (MainWindow *mainwin,
389 static void delete_thread_cb (MainWindow *mainwin,
393 static void create_filter_cb (MainWindow *mainwin,
396 static void create_processing_cb (MainWindow *mainwin,
399 static void open_urls_cb (MainWindow *mainwin,
403 static void prefs_template_open_cb (MainWindow *mainwin,
406 static void prefs_actions_open_cb (MainWindow *mainwin,
409 static void prefs_account_open_cb (MainWindow *mainwin,
413 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
417 static void prefs_post_processing_open_cb (MainWindow *mainwin,
421 static void prefs_filtering_open_cb (MainWindow *mainwin,
425 static void ssl_manager_open_cb (MainWindow *mainwin,
429 static void new_account_cb (MainWindow *mainwin,
433 static void account_selector_menu_cb (GtkMenuItem *menuitem,
435 static void account_receive_menu_cb (GtkMenuItem *menuitem,
437 static void account_compose_menu_cb (GtkMenuItem *menuitem,
440 static void prefs_open_cb (GtkMenuItem *menuitem,
442 static void plugins_open_cb (GtkMenuItem *menuitem,
445 static void online_switch_clicked(GtkButton *btn,
448 static void manual_open_cb (MainWindow *mainwin,
452 static void legend_open_cb (GtkMenuItem *menuitem,
455 static void scan_tree_func (Folder *folder,
459 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
461 static void addr_harvest_cb ( MainWindow *mainwin,
465 static void addr_harvest_msg_cb ( MainWindow *mainwin,
468 static void sync_cb ( MainWindow *mainwin,
472 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
473 GdkEventFocus *focus,
475 static gboolean mainwindow_visibility_event_cb (GtkWidget *widget,
476 GdkEventVisibility *state,
478 static gboolean mainwindow_state_event_cb (GtkWidget *widget,
479 GdkEventWindowState *state,
481 static void main_window_reply_cb (MainWindow *mainwin,
484 static gboolean mainwindow_progressindicator_hook (gpointer source,
487 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
490 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
492 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
494 static void mailing_list_compose(GtkWidget *w, gpointer *data);
496 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
497 #define SEPARATE_ACTION 500
498 static void mainwindow_quicksearch (MainWindow *mainwin,
501 static gboolean any_folder_want_synchronise(void);
503 static GtkItemFactoryEntry mainwin_entries[] =
505 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
506 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
507 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
508 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
509 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
510 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
511 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
512 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
513 {N_("/_File/Exp_ort selected to mbox file..."),
514 NULL, export_list_mbox_cb, 0, NULL},
515 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
517 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
518 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
519 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
520 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
522 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
523 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
524 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
525 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
527 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
528 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
529 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
530 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
531 {N_("/_Edit/_Delete thread"), NULL, delete_thread_cb, 0, NULL},
532 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Edit/_Find in current message..."),
534 "<control>F", search_cb, 0, NULL},
535 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
536 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
537 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
538 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
539 {N_("/_View/Show or hi_de/_Message view"),
540 "V", toggle_message_cb, 0, "<ToggleItem>"},
541 {N_("/_View/Show or hi_de/_Toolbar"),
542 NULL, NULL, 0, "<Branch>"},
543 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
544 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
545 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
546 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
547 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
548 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
549 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
550 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
551 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
552 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
553 {N_("/_View/Show or hi_de/Status _bar"),
554 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
555 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
556 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
557 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
559 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
560 {N_("/_View/La_yout"), NULL, NULL, 0, "<Branch>"},
561 {N_("/_View/Layout/_Standard"), NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
562 {N_("/_View/Layout/_Three columns"), NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
563 {N_("/_View/Layout/_Wide message"), NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
564 {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
565 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
566 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
567 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
568 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
569 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
570 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
571 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
572 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
573 {N_("/_View/_Sort/by _color label"),
574 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
575 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
576 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
577 {N_("/_View/_Sort/by a_ttachment"),
578 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
579 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
580 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
581 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
582 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
584 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
585 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
586 {N_("/_View/_Sort/_Attract by subject"),
587 NULL, attract_by_subject_cb, 0, NULL},
588 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
589 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
590 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
591 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
593 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
594 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
595 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
596 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
597 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
598 {N_("/_View/_Go to/P_revious unread message"),
599 "<shift>P", prev_unread_cb, 0, NULL},
600 {N_("/_View/_Go to/N_ext unread message"),
601 "<shift>N", next_unread_cb, 0, NULL},
602 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
603 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
604 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
605 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_View/_Go to/Previous _marked message"),
607 NULL, prev_marked_cb, 0, NULL},
608 {N_("/_View/_Go to/Next m_arked message"),
609 NULL, next_marked_cb, 0, NULL},
610 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_View/_Go to/Previous _labeled message"),
612 NULL, prev_labeled_cb, 0, NULL},
613 {N_("/_View/_Go to/Next la_beled message"),
614 NULL, next_labeled_cb, 0, NULL},
615 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_View/_Go to/Last read message"),
617 NULL, last_read_cb, 0, NULL},
618 {N_("/_View/_Go to/Parent message"),
619 "<control>Up", parent_cb, 0, NULL},
620 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
622 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
623 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
625 #define ENC_SEPARATOR \
626 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
627 #define ENC_ACTION(action) \
628 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
630 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_View/Character _encoding/_Auto detect"),
632 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
633 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
634 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
635 ENC_ACTION(C_US_ASCII)},
636 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
637 ENC_ACTION(C_UTF_8)},
640 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
641 ENC_ACTION(C_ISO_8859_1)},
642 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
643 ENC_ACTION(C_ISO_8859_15)},
644 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
645 ENC_ACTION(C_WINDOWS_1252)},
648 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
649 ENC_ACTION(C_ISO_8859_2)},
652 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
653 ENC_ACTION(C_ISO_8859_13)},
654 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
655 ENC_ACTION(C_ISO_8859_4)},
658 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
659 ENC_ACTION(C_ISO_8859_7)},
662 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
663 ENC_ACTION(C_ISO_8859_8)},
664 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
665 ENC_ACTION(C_CP1255)},
668 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
669 ENC_ACTION(C_ISO_8859_6)},
670 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
671 ENC_ACTION(C_CP1256)},
674 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
675 ENC_ACTION(C_ISO_8859_9)},
678 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
679 ENC_ACTION(C_ISO_8859_5)},
680 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
681 ENC_ACTION(C_KOI8_R)},
682 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
683 ENC_ACTION(C_KOI8_U)},
684 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
685 ENC_ACTION(C_CP1251)},
688 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
689 ENC_ACTION(C_ISO_2022_JP)},
690 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
691 ENC_ACTION(C_ISO_2022_JP_2)},
692 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
693 ENC_ACTION(C_EUC_JP)},
694 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
695 ENC_ACTION(C_SHIFT_JIS)},
698 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
699 ENC_ACTION(C_GB2312)},
700 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
702 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
704 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
705 ENC_ACTION(C_EUC_TW)},
706 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
707 ENC_ACTION(C_ISO_2022_CN)},
710 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
711 ENC_ACTION(C_EUC_KR)},
712 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
713 ENC_ACTION(C_ISO_2022_KR)},
716 {N_("/_View/Character _encoding/Thai (TIS-620)"),
717 ENC_ACTION(C_TIS_620)},
718 {N_("/_View/Character _encoding/Thai (Windows-874)"),
719 ENC_ACTION(C_WINDOWS_874)},
724 #define DEC_SEPARATOR \
725 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
726 #define DEC_ACTION(action) \
727 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
728 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
729 {N_("/_View/Decode/_Auto detect"),
730 NULL, set_decode_cb, 0, "<RadioItem>"},
731 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
732 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
733 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
734 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
735 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
740 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
741 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
742 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
743 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
744 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
745 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
746 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
747 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
748 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
749 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
751 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
752 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
753 {N_("/_Message/Recei_ve/Get from _current account"),
754 "<control>I", inc_mail_cb, 0, NULL},
755 {N_("/_Message/Recei_ve/Get from _all accounts"),
756 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
757 {N_("/_Message/Recei_ve/Cancel receivin_g"),
758 NULL, inc_cancel_cb, 0, NULL},
759 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
760 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
761 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
762 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
763 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
764 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
765 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
766 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
767 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
768 {N_("/_Message/Repl_y to/mailing _list"),
769 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
770 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
771 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
772 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
773 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
774 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
776 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
777 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
778 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
779 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
780 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
781 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
782 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
784 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
785 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
786 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
787 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
788 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
789 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
790 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
791 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
792 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
793 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
794 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
795 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
796 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
797 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
798 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
799 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
800 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
801 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
802 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
803 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
804 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
805 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
806 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
807 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
808 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
810 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
811 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
812 {N_("/_Tools/Add sender to address boo_k"),
813 NULL, add_address_cb, 0, NULL},
814 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
815 {N_("/_Tools/_Harvest addresses/from _Folder..."),
816 NULL, addr_harvest_cb, 0, NULL},
817 {N_("/_Tools/_Harvest addresses/from _Messages..."),
818 NULL, addr_harvest_msg_cb, 0, NULL},
819 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
820 {N_("/_Tools/_Filter all messages in folder"),
821 NULL, filter_cb, 0, NULL},
822 {N_("/_Tools/Filter _selected messages"),
823 NULL, filter_cb, 1, NULL},
824 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
825 {N_("/_Tools/_Create filter rule/_Automatically"),
826 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
827 {N_("/_Tools/_Create filter rule/by _From"),
828 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
829 {N_("/_Tools/_Create filter rule/by _To"),
830 NULL, create_filter_cb, FILTER_BY_TO, NULL},
831 {N_("/_Tools/_Create filter rule/by _Subject"),
832 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
833 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
834 {N_("/_Tools/C_reate processing rule/_Automatically"),
835 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
836 {N_("/_Tools/C_reate processing rule/by _From"),
837 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
838 {N_("/_Tools/C_reate processing rule/by _To"),
839 NULL, create_processing_cb, FILTER_BY_TO, NULL},
840 {N_("/_Tools/C_reate processing rule/by _Subject"),
841 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
842 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
843 {N_("/_Tools/List _URLs..."), "<shift><control>U", open_urls_cb, 0, NULL},
844 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
845 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
846 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
847 {N_("/_Tools/Ch_eck for new messages in all folders"),
848 NULL, update_folderview_cb, 0, NULL},
849 {N_("/_Tools/Delete du_plicated messages"),
850 NULL, NULL, 0, "<Branch>"},
851 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
852 NULL, delete_duplicated_cb, 0, NULL},
853 {N_("/_Tools/Delete du_plicated messages/In all folders"),
854 NULL, delete_duplicated_all_cb, 0, NULL},
855 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
856 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
858 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
859 {N_("/_Tools/SSL cer_tificates..."),
860 NULL, ssl_manager_open_cb, 0, NULL},
862 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
863 {N_("/_Tools/_Log window"), "<shift><control>L", log_window_show_cb, 0, NULL},
865 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
866 {N_("/_Configuration/C_hange current account"),
867 NULL, NULL, 0, "<Branch>"},
868 {N_("/_Configuration/_Preferences for current account..."),
869 NULL, prefs_account_open_cb, 0, NULL},
870 {N_("/_Configuration/Create _new account..."),
871 NULL, new_account_cb, 0, NULL},
872 {N_("/_Configuration/_Edit accounts..."),
873 NULL, account_edit_open, 0, NULL},
874 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
875 {N_("/_Configuration/P_references..."),
876 NULL, prefs_open_cb, 0, NULL},
877 {N_("/_Configuration/Pre-pr_ocessing..."),
878 NULL, prefs_pre_processing_open_cb, 0, NULL},
879 {N_("/_Configuration/Post-pro_cessing..."),
880 NULL, prefs_post_processing_open_cb, 0, NULL},
881 {N_("/_Configuration/_Filtering..."),
882 NULL, prefs_filtering_open_cb, 0, NULL},
883 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
884 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
885 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
887 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
888 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
889 {N_("/_Help/_Online User-contributed FAQ"),
890 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
891 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
892 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
893 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
896 static gboolean offline_ask_sync = TRUE;
897 static guint lastkey;
898 static gboolean is_obscured = FALSE;
900 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
906 MainWindow *mainwin = (MainWindow *)user_data;
908 if (mainwin->summaryview &&
909 mainwin->summaryview->quicksearch &&
910 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
911 (mod == 0 || mod == GDK_SHIFT_MASK)) {
912 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
918 #define N_COLOR_LABELS colorlabel_get_color_count()
920 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
925 GtkCheckMenuItem **items;
930 mainwin = (MainWindow *)data;
931 g_return_if_fail(mainwin != NULL);
933 sel = summary_get_selection(mainwin->summaryview);
936 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
937 g_return_if_fail(menu != NULL);
939 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
941 /* NOTE: don't return prematurely because we set the "dont_toggle"
942 * state for check menu items */
943 g_object_set_data(G_OBJECT(menu), "dont_toggle",
946 /* clear items. get item pointers. */
947 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
948 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
949 gtk_check_menu_item_set_active
950 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
951 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
956 if (n == (N_COLOR_LABELS + 1)) {
957 /* iterate all messages and set the state of the appropriate
959 for (; sel != NULL; sel = sel->next) {
963 msginfo = (MsgInfo *)sel->data;
965 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
966 if (!items[clabel]->active)
967 gtk_check_menu_item_set_active
968 (items[clabel], TRUE);
972 g_warning("invalid number of color elements (%d)\n", n);
974 /* reset "dont_toggle" state */
975 g_object_set_data(G_OBJECT(menu), "dont_toggle",
979 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
982 guint color = GPOINTER_TO_UINT(data);
985 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
986 g_return_if_fail(mainwin != NULL);
988 /* "dont_toggle" state set? */
989 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
993 summary_set_colorlabel(mainwin->summaryview, color, NULL);
996 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
998 GtkWidget *label_menuitem;
1003 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1004 "/Message/Color label");
1005 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1006 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1008 gtk_widget_show(label_menuitem);
1010 menu = gtk_menu_new();
1012 /* create sub items. for the menu item activation callback we pass the
1013 * index of label_colors[] as data parameter. for the None color we
1014 * pass an invalid (high) value. also we attach a data pointer so we
1015 * can always get back the Mainwindow pointer. */
1017 item = gtk_check_menu_item_new_with_label(_("None"));
1018 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1019 g_signal_connect(G_OBJECT(item), "activate",
1020 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1021 GUINT_TO_POINTER(0));
1022 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1023 gtk_widget_show(item);
1025 gtk_widget_add_accelerator(item, "activate",
1026 mainwin->menu_factory->accel_group,
1027 GDK_0, GDK_CONTROL_MASK,
1028 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1030 item = gtk_menu_item_new();
1031 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1032 gtk_widget_show(item);
1034 /* create pixmap/label menu items */
1035 for (i = 0; i < N_COLOR_LABELS; i++) {
1036 item = colorlabel_create_check_color_menu_item(
1037 i, refresh, MAINWIN_COLORMENU);
1038 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1039 g_signal_connect(G_OBJECT(item), "activate",
1040 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1041 GUINT_TO_POINTER(i + 1));
1042 g_object_set_data(G_OBJECT(item), "mainwin",
1044 gtk_widget_show(item);
1046 gtk_widget_add_accelerator(item, "activate",
1047 mainwin->menu_factory->accel_group,
1048 GDK_1+i, GDK_CONTROL_MASK,
1049 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1052 gtk_widget_show(menu);
1053 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1054 mainwin->colorlabel_menu = menu;
1057 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1058 MainWindow *mainwindow)
1060 if (evt && evt->button == 1) {
1061 log_window_show_error(mainwindow->logwin);
1062 gtk_widget_hide(mainwindow->warning_btn);
1067 static gboolean warning_visi_notify(GtkWidget *widget,
1068 GdkEventVisibility *event,
1069 MainWindow *mainwindow)
1071 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1075 static gboolean warning_leave_notify(GtkWidget *widget,
1076 GdkEventCrossing *event,
1077 MainWindow *mainwindow)
1079 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1083 static gboolean warning_enter_notify(GtkWidget *widget,
1084 GdkEventCrossing *event,
1085 MainWindow *mainwindow)
1087 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1091 void mainwindow_show_error(void)
1093 MainWindow *mainwin = mainwindow_get_mainwindow();
1094 gtk_widget_show(mainwin->warning_btn);
1097 void mainwindow_clear_error(MainWindow *mainwin)
1099 gtk_widget_hide(mainwin->warning_btn);
1102 MainWindow *main_window_create()
1104 MainWindow *mainwin;
1108 GtkWidget *handlebox;
1109 GtkWidget *vbox_body;
1110 GtkWidget *hbox_stat;
1111 GtkWidget *statusbar;
1112 GtkWidget *progressbar;
1113 GtkWidget *statuslabel;
1114 GtkWidget *ac_button;
1115 GtkWidget *ac_label;
1116 GtkWidget *online_pixmap;
1117 GtkWidget *offline_pixmap;
1118 GtkWidget *online_switch;
1119 GtkWidget *offline_switch;
1121 GtkWidget *warning_icon;
1122 GtkWidget *warning_btn;
1124 FolderView *folderview;
1125 SummaryView *summaryview;
1126 MessageView *messageview;
1127 GdkColormap *colormap;
1129 gboolean success[4];
1130 GtkItemFactory *ifactory;
1132 GtkWidget *menuitem;
1134 guint n_menu_entries;
1136 static GdkGeometry geometry;
1138 debug_print("Creating main window...\n");
1139 mainwin = g_new0(MainWindow, 1);
1142 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow");
1143 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1144 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1146 if (!geometry.min_height) {
1147 geometry.min_width = 320;
1148 geometry.min_height = 200;
1150 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1153 g_signal_connect(G_OBJECT(window), "delete_event",
1154 G_CALLBACK(main_window_close_cb), mainwin);
1155 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1156 g_signal_connect(G_OBJECT(window), "focus_in_event",
1157 G_CALLBACK(mainwindow_focus_in_event),
1159 g_signal_connect(G_OBJECT(window), "key_press_event",
1160 G_CALLBACK(mainwindow_key_pressed), mainwin);
1162 gtk_widget_realize(window);
1163 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1166 gtkut_widget_set_app_icon(window);
1168 vbox = gtk_vbox_new(FALSE, 0);
1169 gtk_widget_show(vbox);
1170 gtk_container_add(GTK_CONTAINER(window), vbox);
1173 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1174 menubar = menubar_create(window, mainwin_entries,
1175 n_menu_entries, "<Main>", mainwin);
1176 gtk_widget_show(menubar);
1177 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1178 ifactory = gtk_item_factory_from_widget(menubar);
1180 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1181 main_create_mailing_list_menu (mainwin, NULL); */
1183 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1185 if (prefs_common.toolbar_detachable) {
1186 handlebox = gtk_handle_box_new();
1187 gtk_widget_show(handlebox);
1188 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1189 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1190 G_CALLBACK(toolbar_child_attached), mainwin);
1191 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1192 G_CALLBACK(toolbar_child_detached), mainwin);
1194 handlebox = gtk_hbox_new(FALSE, 0);
1195 gtk_widget_show(handlebox);
1196 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1198 /* link window to mainwin->window to avoid gdk warnings */
1199 mainwin->window = window;
1201 /* create toolbar */
1202 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1205 toolbar_set_learn_button
1209 /* vbox that contains body */
1210 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1211 gtk_widget_show(vbox_body);
1212 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1213 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1215 hbox_stat = gtk_hbox_new(FALSE, 2);
1216 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1218 tips = gtk_tooltips_new();
1220 warning_icon = gtk_image_new_from_stock
1221 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1222 warning_btn = gtk_event_box_new();
1223 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1225 mainwin->warning_btn = warning_btn;
1227 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1228 G_CALLBACK(warning_icon_pressed),
1229 (gpointer) mainwin);
1230 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1231 G_CALLBACK(warning_visi_notify), mainwin);
1232 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1233 G_CALLBACK(warning_visi_notify), mainwin);
1234 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1235 G_CALLBACK(warning_leave_notify), mainwin);
1236 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1237 G_CALLBACK(warning_enter_notify), mainwin);
1239 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1241 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1242 _("Some error(s) happened. Click here to view log."), NULL);
1243 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1245 statusbar = statusbar_create();
1246 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1248 progressbar = gtk_progress_bar_new();
1249 gtk_widget_set_size_request(progressbar, 120, 1);
1250 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1252 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1253 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1254 online_switch = gtk_button_new ();
1255 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1256 _("You are online. Click the icon to go offline"), NULL);
1257 offline_switch = gtk_button_new ();
1258 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1259 _("You are offline. Click the icon to go online"),
1261 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1262 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1263 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1264 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1265 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1266 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1267 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1268 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1270 statuslabel = gtk_label_new("");
1271 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1273 ac_button = gtk_button_new();
1274 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1275 ac_button, _("Select account"), NULL);
1276 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1277 gtk_widget_set_size_request(ac_button, -1, 0);
1278 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1279 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1280 G_CALLBACK(ac_label_button_pressed), mainwin);
1282 ac_label = gtk_label_new("");
1283 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1285 gtk_widget_show_all(hbox_stat);
1287 gtk_widget_hide(offline_switch);
1288 gtk_widget_hide(warning_btn);
1290 mainwin->folderview = folderview = folderview_create();
1291 mainwin->summaryview = summaryview = summary_create();
1292 mainwin->messageview = messageview = messageview_create(mainwin);
1293 mainwin->logwin = log_window_create();
1295 log_window_init(mainwin->logwin);
1296 log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1297 prefs_common.loglength);
1299 folderview->mainwin = mainwin;
1300 folderview->summaryview = summaryview;
1302 summaryview->mainwin = mainwin;
1303 summaryview->folderview = folderview;
1304 summaryview->messageview = messageview;
1305 summaryview->window = window;
1307 messageview->statusbar = statusbar;
1308 mainwin->vbox = vbox;
1309 mainwin->menubar = menubar;
1310 mainwin->menu_factory = ifactory;
1311 mainwin->handlebox = handlebox;
1312 mainwin->vbox_body = vbox_body;
1313 mainwin->hbox_stat = hbox_stat;
1314 mainwin->statusbar = statusbar;
1315 mainwin->progressbar = progressbar;
1316 mainwin->statuslabel = statuslabel;
1317 mainwin->online_switch = online_switch;
1318 mainwin->online_pixmap = online_pixmap;
1319 mainwin->offline_pixmap = offline_pixmap;
1320 mainwin->ac_button = ac_button;
1321 mainwin->ac_label = ac_label;
1322 mainwin->offline_switch = offline_switch;
1324 /* set context IDs for status bar */
1325 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1326 (GTK_STATUSBAR(statusbar), "Main Window");
1327 mainwin->folderview_cid = gtk_statusbar_get_context_id
1328 (GTK_STATUSBAR(statusbar), "Folder View");
1329 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1330 (GTK_STATUSBAR(statusbar), "Summary View");
1331 mainwin->messageview_cid = gtk_statusbar_get_context_id
1332 (GTK_STATUSBAR(statusbar), "Message View");
1334 messageview->statusbar_cid = mainwin->messageview_cid;
1336 /* allocate colors for summary view and folder view */
1337 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1338 summaryview->color_marked.blue = (guint16)65535;
1340 summaryview->color_dim.red = summaryview->color_dim.green =
1341 summaryview->color_dim.blue = COLOR_DIM;
1343 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1344 &folderview->color_new);
1346 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1347 &folderview->color_op);
1349 summaryview->color_important.red = 0;
1350 summaryview->color_important.green = 0;
1351 summaryview->color_important.blue = (guint16)65535;
1353 color[0] = summaryview->color_marked;
1354 color[1] = summaryview->color_dim;
1355 color[2] = folderview->color_new;
1356 color[3] = folderview->color_op;
1358 colormap = gdk_drawable_get_colormap(window->window);
1359 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1360 for (i = 0; i < 4; i++) {
1361 if (success[i] == FALSE)
1362 g_warning("MainWindow: color allocation %d failed\n", i);
1365 debug_print("done.\n");
1367 messageview->visible = prefs_common.msgview_visible;
1369 main_window_set_widgets(mainwin, prefs_common.layout_mode);
1371 g_signal_connect(G_OBJECT(window), "size_allocate",
1372 G_CALLBACK(main_window_size_allocate_cb),
1375 /* set menu items */
1376 menuitem = gtk_item_factory_get_item
1377 (ifactory, "/View/Character encoding/Auto detect");
1378 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1380 switch (prefs_common.toolbar_style) {
1382 menuitem = gtk_item_factory_get_item
1383 (ifactory, "/View/Show or hide/Toolbar/Hide");
1386 menuitem = gtk_item_factory_get_item
1387 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1390 menuitem = gtk_item_factory_get_item
1391 (ifactory, "/View/Show or hide/Toolbar/Text only");
1394 menuitem = gtk_item_factory_get_item
1395 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1397 case TOOLBAR_BOTH_HORIZ:
1398 menuitem = gtk_item_factory_get_item
1400 "/View/Show or hide/Toolbar/Text beside icons");
1402 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1404 gtk_widget_hide(mainwin->hbox_stat);
1405 menuitem = gtk_item_factory_get_item
1406 (ifactory, "/View/Show or hide/Status bar");
1407 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1408 prefs_common.show_statusbar);
1410 /* set account selection menu */
1411 ac_menu = gtk_item_factory_get_widget
1412 (ifactory, "/Configuration/Change current account");
1413 mainwin->ac_menu = ac_menu;
1415 toolbar_main_set_sensitive(mainwin);
1417 /* create actions menu */
1418 main_window_update_actions_menu(mainwin);
1420 main_create_mailing_list_menu (mainwin, NULL);
1422 /* attach accel groups to main window */
1423 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1424 gtk_window_add_accel_group \
1426 gtk_item_factory_from_widget(menu)->accel_group); \
1427 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1429 G_CALLBACK(main_window_accel_activate), mainwin);
1432 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1434 /* connect the accelerators for equivalent
1435 menu items in different menus */
1436 menu_connect_identical_items();
1438 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1440 g_signal_connect(G_OBJECT(window), "window_state_event",
1441 G_CALLBACK(mainwindow_state_event_cb), mainwin);
1442 g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1443 G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1444 gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1446 if (prefs_common.layout_mode == VERTICAL_LAYOUT)
1447 summary_relayout(mainwin->summaryview);
1449 gtk_widget_show(mainwin->window);
1451 /* initialize views */
1452 folderview_init(folderview);
1453 summary_init(summaryview);
1454 messageview_init(messageview);
1456 sslcertwindow_register_hook();
1458 mainwin->lock_count = 0;
1459 mainwin->menu_lock_count = 0;
1460 mainwin->cursor_count = 0;
1462 mainwin->progressindicator_hook =
1463 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1466 watch_cursor = gdk_cursor_new(GDK_WATCH);
1468 hand_cursor = gdk_cursor_new(GDK_HAND2);
1470 mainwin_list = g_list_append(mainwin_list, mainwin);
1472 /* init work_offline */
1473 if (prefs_common.work_offline)
1474 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1476 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1481 void main_window_destroy(MainWindow *mainwin)
1483 /* TODO : destroy other component */
1484 messageview_destroy(mainwin->messageview);
1485 mainwin->messageview = NULL;
1488 void main_window_update_actions_menu(MainWindow *mainwin)
1490 GtkItemFactory *ifactory;
1492 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1493 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1496 void main_window_cursor_wait(MainWindow *mainwin)
1499 if (mainwin->cursor_count == 0) {
1500 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1501 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1504 mainwin->cursor_count++;
1509 void main_window_cursor_normal(MainWindow *mainwin)
1511 if (mainwin->cursor_count)
1512 mainwin->cursor_count--;
1514 if (mainwin->cursor_count == 0) {
1515 gdk_window_set_cursor(mainwin->window->window, NULL);
1516 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1521 /* lock / unlock the user-interface */
1522 void main_window_lock(MainWindow *mainwin)
1524 if (mainwin->lock_count == 0)
1525 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1527 mainwin->lock_count++;
1529 main_window_set_menu_sensitive(mainwin);
1530 toolbar_main_set_sensitive(mainwin);
1533 void main_window_unlock(MainWindow *mainwin)
1535 if (mainwin->lock_count)
1536 mainwin->lock_count--;
1538 main_window_set_menu_sensitive(mainwin);
1539 toolbar_main_set_sensitive(mainwin);
1541 if (mainwin->lock_count == 0)
1542 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1545 static void main_window_menu_callback_block(MainWindow *mainwin)
1547 mainwin->menu_lock_count++;
1550 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1552 if (mainwin->menu_lock_count)
1553 mainwin->menu_lock_count--;
1556 static guint prefs_tag = 0;
1558 void main_window_reflect_prefs_all(void)
1560 main_window_reflect_prefs_all_real(FALSE);
1563 static gboolean reflect_prefs_timeout_cb(gpointer data)
1565 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1567 MainWindow *mainwin;
1570 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1571 mainwin = (MainWindow *)cur->data;
1573 main_window_show_cur_account(mainwin);
1574 main_window_set_menu_sensitive(mainwin);
1575 toolbar_main_set_sensitive(mainwin);
1578 if (pixmap_theme_changed) {
1579 toolbar_update(TOOLBAR_MAIN, mainwin);
1580 messageview_reflect_prefs_pixmap_theme();
1581 compose_reflect_prefs_pixmap_theme();
1582 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1583 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1585 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1586 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1587 mainwin->online_pixmap);
1588 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1589 gtk_widget_show(pixmap);
1590 mainwin->online_pixmap = pixmap;
1591 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1592 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1593 mainwin->offline_pixmap);
1594 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1595 gtk_widget_show(pixmap);
1596 mainwin->offline_pixmap = pixmap;
1599 headerview_set_font(mainwin->messageview->headerview);
1600 headerview_set_visibility(mainwin->messageview->headerview,
1601 prefs_common.display_header_pane);
1602 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1603 folderview_reflect_prefs();
1604 summary_reflect_prefs();
1605 summary_redisplay_msg(mainwin->summaryview);
1611 void main_window_reflect_prefs_all_now(void)
1613 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1616 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1621 /* re-create colorlabel submenu */
1622 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1623 g_return_if_fail(menu != NULL);
1625 /* clear items. get item pointers. */
1626 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1627 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1629 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1630 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1634 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1636 if (prefs_tag == 0 || pixmap_theme_changed) {
1637 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1638 GINT_TO_POINTER(pixmap_theme_changed));
1642 void main_window_set_summary_column(void)
1645 MainWindow *mainwin;
1647 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1648 mainwin = (MainWindow *)cur->data;
1649 summary_set_column_order(mainwin->summaryview);
1653 void main_window_set_folder_column(void)
1656 MainWindow *mainwin;
1658 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1659 mainwin = (MainWindow *)cur->data;
1660 folderview_set_column_order(mainwin->folderview);
1664 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1665 GList *account_list)
1667 GList *cur_ac, *cur_item;
1668 GtkWidget *menuitem;
1669 PrefsAccount *ac_prefs;
1671 /* destroy all previous menu item */
1672 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1673 while (cur_item != NULL) {
1674 GList *next = cur_item->next;
1675 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1679 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1680 ac_prefs = (PrefsAccount *)cur_ac->data;
1682 menuitem = gtk_menu_item_new_with_label
1683 (ac_prefs->account_name
1684 ? ac_prefs->account_name : _("Untitled"));
1685 gtk_widget_show(menuitem);
1686 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1687 g_signal_connect(G_OBJECT(menuitem), "activate",
1688 G_CALLBACK(account_selector_menu_cb),
1693 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1694 GList *account_list)
1696 GList *cur_ac, *cur_item;
1698 GtkWidget *menuitem;
1699 PrefsAccount *ac_prefs;
1701 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1702 "/Message/Receive");
1704 /* search for separator */
1705 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1706 cur_item = cur_item->next) {
1707 if (GTK_BIN(cur_item->data)->child == NULL) {
1708 cur_item = cur_item->next;
1713 /* destroy all previous menu item */
1714 while (cur_item != NULL) {
1715 GList *next = cur_item->next;
1716 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1720 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1721 ac_prefs = (PrefsAccount *)cur_ac->data;
1723 menuitem = gtk_menu_item_new_with_label
1724 (ac_prefs->account_name ? ac_prefs->account_name
1726 gtk_widget_show(menuitem);
1727 gtk_menu_append(GTK_MENU(menu), menuitem);
1728 g_signal_connect(G_OBJECT(menuitem), "activate",
1729 G_CALLBACK(account_receive_menu_cb),
1734 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1735 GList *account_list)
1737 GList *cur_ac, *cur_item;
1738 GtkWidget *menuitem;
1739 PrefsAccount *ac_prefs;
1740 GtkWidget *menu = NULL;
1742 if (mainwin->toolbar->getall_btn == NULL
1743 || mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1746 menu = mainwin->toolbar->getall_combo->menu;
1748 /* destroy all previous menu item */
1749 cur_item = GTK_MENU_SHELL(menu)->children;
1750 while (cur_item != NULL) {
1751 GList *next = cur_item->next;
1752 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1756 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1757 ac_prefs = (PrefsAccount *)cur_ac->data;
1759 menuitem = gtk_menu_item_new_with_label
1760 (ac_prefs->account_name
1761 ? ac_prefs->account_name : _("Untitled"));
1762 gtk_widget_show(menuitem);
1763 gtk_menu_append(GTK_MENU(menu), menuitem);
1764 g_signal_connect(G_OBJECT(menuitem), "activate",
1765 G_CALLBACK(account_receive_menu_cb),
1770 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1771 GList *account_list)
1773 GList *cur_ac, *cur_item;
1774 GtkWidget *menuitem;
1775 PrefsAccount *ac_prefs;
1776 GtkWidget *menu = NULL;
1778 if (mainwin->toolbar->compose_mail_btn == NULL
1779 || mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1782 menu = mainwin->toolbar->compose_combo->menu;
1784 /* destroy all previous menu item */
1785 cur_item = GTK_MENU_SHELL(menu)->children;
1786 while (cur_item != NULL) {
1787 GList *next = cur_item->next;
1788 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1792 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1793 ac_prefs = (PrefsAccount *)cur_ac->data;
1795 menuitem = gtk_menu_item_new_with_label
1796 (ac_prefs->account_name
1797 ? ac_prefs->account_name : _("Untitled"));
1798 gtk_widget_show(menuitem);
1799 gtk_menu_append(GTK_MENU(menu), menuitem);
1800 g_signal_connect(G_OBJECT(menuitem), "activate",
1801 G_CALLBACK(account_compose_menu_cb),
1806 void main_window_set_account_menu(GList *account_list)
1809 MainWindow *mainwin;
1811 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1812 mainwin = (MainWindow *)cur->data;
1813 main_window_set_account_selector_menu(mainwin, account_list);
1814 main_window_set_account_receive_menu(mainwin, account_list);
1815 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1816 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1818 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
1821 void main_window_set_account_menu_only_toolbar(GList *account_list)
1824 MainWindow *mainwin;
1826 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1827 mainwin = (MainWindow *)cur->data;
1828 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1829 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1833 static void main_window_show_cur_account(MainWindow *mainwin)
1838 ac_name = g_strdup(cur_account
1839 ? (cur_account->account_name
1840 ? cur_account->account_name : _("Untitled"))
1844 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1846 buf = g_strdup(PROG_VERSION);
1847 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1850 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1851 gtk_widget_queue_resize(mainwin->ac_button);
1856 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
1858 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
1859 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1860 GtkWidget *message_wid = mainwin->messageview->vbox;
1862 if (layout_mode == prefs_common.layout_mode)
1865 debug_print("Changing window separation type from %d to %d\n",
1866 prefs_common.layout_mode, layout_mode);
1868 /* remove widgets from those containers */
1869 gtk_widget_ref(folder_wid);
1870 gtk_widget_ref(summary_wid);
1871 gtk_widget_ref(message_wid);
1872 gtkut_container_remove
1873 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1874 gtkut_container_remove
1875 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1876 gtkut_container_remove
1877 (GTK_CONTAINER(message_wid->parent), message_wid);
1879 gtk_widget_hide(mainwin->window);
1880 main_window_set_widgets(mainwin, layout_mode);
1881 gtk_widget_show(mainwin->window);
1883 gtk_widget_unref(folder_wid);
1884 gtk_widget_unref(summary_wid);
1885 gtk_widget_unref(message_wid);
1888 static void mainwin_reset_paned(GtkPaned *paned)
1891 g_object_get (G_OBJECT(paned),
1894 g_object_get (G_OBJECT(paned),
1899 gtk_paned_set_position(GTK_PANED(paned), mid);
1902 void main_window_toggle_message_view(MainWindow *mainwin)
1904 SummaryView *summaryview = mainwin->summaryview;
1905 GtkWidget *ppaned = NULL;
1906 GtkWidget *container = NULL;
1908 switch (prefs_common.layout_mode) {
1910 case VERTICAL_LAYOUT:
1911 ppaned = mainwin->vpaned;
1912 container = mainwin->hpaned;
1913 if (ppaned->parent != NULL) {
1914 mainwin->messageview->visible = FALSE;
1915 summaryview->displayed = NULL;
1916 gtk_widget_ref(ppaned);
1917 gtkut_container_remove(GTK_CONTAINER(container), ppaned);
1918 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1920 mainwin->messageview->visible = TRUE;
1921 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
1922 gtk_container_add(GTK_CONTAINER(container), ppaned);
1923 gtk_widget_unref(ppaned);
1927 ppaned = mainwin->hpaned;
1928 container = mainwin->vpaned;
1929 if (mainwin->messageview->vbox->parent != NULL) {
1930 mainwin->messageview->visible = FALSE;
1931 summaryview->displayed = NULL;
1932 gtk_widget_ref(mainwin->messageview->vbox);
1933 gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
1935 mainwin->messageview->visible = TRUE;
1936 gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
1937 gtk_widget_unref(mainwin->messageview->vbox);
1940 case WIDE_MSGLIST_LAYOUT:
1941 g_warning("can't hide messageview in this wide msglist layout");
1945 if (messageview_is_visible(mainwin->messageview))
1946 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1947 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1949 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1950 GTK_ARROW_UP, GTK_SHADOW_OUT);
1952 if (mainwin->messageview->visible == FALSE)
1953 messageview_clear(mainwin->messageview);
1955 main_window_set_menu_sensitive(mainwin);
1957 prefs_common.msgview_visible = mainwin->messageview->visible;
1959 if (messageview_is_visible(mainwin->messageview)) {
1960 gtk_widget_queue_resize(mainwin->hpaned);
1961 gtk_widget_queue_resize(mainwin->vpaned);
1963 summary_grab_focus(summaryview);
1966 void main_window_get_size(MainWindow *mainwin)
1968 GtkAllocation *allocation;
1970 if (mainwin_list == NULL || mainwin->messageview == NULL) {
1971 debug_print("called after messageview "
1972 "has been deallocated!\n");
1976 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1978 if (allocation->width > 1 && allocation->height > 1) {
1979 prefs_common.summaryview_width = allocation->width;
1981 if (messageview_is_visible(mainwin->messageview))
1982 prefs_common.summaryview_height = allocation->height;
1984 prefs_common.mainview_width = allocation->width;
1987 allocation = &mainwin->window->allocation;
1988 if (allocation->width > 1 && allocation->height > 1) {
1989 prefs_common.mainview_height = allocation->height;
1990 prefs_common.mainwin_width = allocation->width;
1991 prefs_common.mainwin_height = allocation->height;
1994 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1995 if (allocation->width > 1 && allocation->height > 1) {
1996 prefs_common.folderview_width = allocation->width;
1997 prefs_common.folderview_height = allocation->height;
2000 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2001 if (allocation->width > 1 && allocation->height > 1) {
2002 prefs_common.msgview_width = allocation->width;
2003 prefs_common.msgview_height = allocation->height;
2006 /* debug_print("summaryview size: %d x %d\n",
2007 prefs_common.summaryview_width,
2008 prefs_common.summaryview_height);
2009 debug_print("folderview size: %d x %d\n",
2010 prefs_common.folderview_width,
2011 prefs_common.folderview_height);
2012 debug_print("messageview size: %d x %d\n",
2013 prefs_common.msgview_width,
2014 prefs_common.msgview_height); */
2017 void main_window_get_position(MainWindow *mainwin)
2021 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2023 prefs_common.mainview_x = x;
2024 prefs_common.mainview_y = y;
2025 prefs_common.mainwin_x = x;
2026 prefs_common.mainwin_y = y;
2028 debug_print("main window position: %d, %d\n", x, y);
2031 void main_window_progress_on(MainWindow *mainwin)
2033 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2036 void main_window_progress_off(MainWindow *mainwin)
2038 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2039 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2042 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2046 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2047 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2048 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2049 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2052 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2054 if (confirm && procmsg_have_trashed_mails_fast()) {
2055 if (alertpanel(_("Empty trash"),
2056 _("Delete all messages in trash folders?"),
2057 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2058 != G_ALERTALTERNATE)
2060 manage_window_focus_in(mainwin->window, NULL, NULL);
2063 procmsg_empty_all_trash();
2065 if (mainwin->summaryview->folder_item &&
2066 mainwin->summaryview->folder_item->stype == F_TRASH)
2067 gtk_widget_grab_focus(mainwin->folderview->ctree);
2070 void main_window_add_mailbox(MainWindow *mainwin)
2075 path = input_dialog(_("Add mailbox"),
2076 _("Input the location of mailbox.\n"
2077 "If the existing mailbox is specified, it will be\n"
2078 "scanned automatically."),
2081 if (folder_find_from_path(path)) {
2082 alertpanel_error(_("The mailbox '%s' already exists."), path);
2086 folder = folder_new(folder_get_class_from_string("mh"),
2087 !strcmp(path, "Mail") ? _("Mailbox") :
2088 g_path_get_basename(path), path);
2091 if (folder->klass->create_tree(folder) < 0) {
2092 alertpanel_error(_("Creation of the mailbox failed.\n"
2093 "Maybe some files already exist, or you don't have the permission to write there."));
2094 folder_destroy(folder);
2099 folder_set_ui_func(folder, scan_tree_func, mainwin);
2100 folder_scan_tree(folder, TRUE);
2101 folder_set_ui_func(folder, NULL, NULL);
2104 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2106 SensitiveCond state = 0;
2107 SummarySelection selection;
2108 FolderItem *item = mainwin->summaryview->folder_item;
2109 GList *account_list = account_get_list();
2111 selection = summary_get_selection_type(mainwin->summaryview);
2113 if (mainwin->lock_count == 0)
2114 state |= M_UNLOCKED;
2115 if (selection != SUMMARY_NONE)
2116 state |= M_MSG_EXIST;
2117 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2119 /* if (item->folder->type != F_NEWS) */
2120 state |= M_ALLOW_DELETE;
2122 if (prefs_common.immediate_exec == 0
2123 && mainwin->lock_count == 0)
2124 state |= M_DELAY_EXEC;
2126 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2127 || selection != SUMMARY_NONE)
2128 state |= M_HIDE_READ_MSG;
2130 if (mainwin->summaryview->threaded)
2131 state |= M_THREADED;
2133 state |= M_UNTHREADED;
2134 if (selection == SUMMARY_SELECTED_SINGLE ||
2135 selection == SUMMARY_SELECTED_MULTIPLE)
2136 state |= M_TARGET_EXIST;
2137 if (selection == SUMMARY_SELECTED_SINGLE)
2138 state |= M_SINGLE_TARGET_EXIST;
2139 if (mainwin->summaryview->folder_item &&
2140 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2143 state |= M_NOT_NEWS;
2144 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2145 state |= M_ACTIONS_EXIST;
2147 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2148 state |= M_HAVE_QUEUED_MAILS;
2150 if (selection == SUMMARY_SELECTED_SINGLE &&
2152 (folder_has_parent_of_type(item, F_DRAFT) ||
2153 folder_has_parent_of_type(item, F_OUTBOX) ||
2154 folder_has_parent_of_type(item, F_QUEUE))))
2155 state |= M_ALLOW_REEDIT;
2157 state |= M_HAVE_ACCOUNT;
2159 if (any_folder_want_synchronise())
2160 state |= M_WANT_SYNC;
2162 for ( ; account_list != NULL; account_list = account_list->next) {
2163 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2164 state |= M_HAVE_NEWS_ACCOUNT;
2169 if (procmsg_spam_can_learn() &&
2170 (mainwin->summaryview->folder_item &&
2171 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2172 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2173 state |= M_CAN_LEARN_SPAM;
2176 if (inc_is_active())
2177 state |= M_INC_ACTIVE;
2179 if (mainwin->summaryview->deleted > 0 ||
2180 mainwin->summaryview->moved > 0 ||
2181 mainwin->summaryview->copied > 0)
2182 state |= M_DELAY_EXEC;
2189 void main_window_set_menu_sensitive(MainWindow *mainwin)
2191 GtkItemFactory *ifactory = mainwin->menu_factory;
2192 SensitiveCond state;
2195 GtkWidget *menuitem;
2196 SummaryView *summaryview;
2201 static const struct {
2205 {"/File/Save as...", M_TARGET_EXIST},
2206 {"/File/Print..." , M_TARGET_EXIST},
2207 {"/File/Synchronise folders", M_WANT_SYNC},
2208 {"/File/Exit" , M_UNLOCKED},
2210 {"/Edit/Select thread" , M_SINGLE_TARGET_EXIST},
2211 {"/Edit/Delete thread" , M_SINGLE_TARGET_EXIST},
2212 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2214 {"/View/Set displayed columns/in Folder list..."
2216 {"/View/Sort" , M_EXEC},
2217 {"/View/Thread view" , M_EXEC},
2218 {"/View/Expand all threads" , M_MSG_EXIST},
2219 {"/View/Collapse all threads" , M_MSG_EXIST},
2220 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2221 {"/View/Go to/Previous message" , M_MSG_EXIST},
2222 {"/View/Go to/Next message" , M_MSG_EXIST},
2223 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2224 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2225 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2226 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2227 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2228 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2229 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2230 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2231 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2232 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2233 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2235 {"/Message/Receive/Get from current account"
2236 , M_HAVE_ACCOUNT|M_UNLOCKED},
2237 {"/Message/Receive/Get from all accounts"
2238 , M_HAVE_ACCOUNT|M_UNLOCKED},
2239 {"/Message/Receive/Cancel receiving"
2241 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2242 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2243 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2244 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2245 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2246 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2247 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2248 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2249 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2250 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2251 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2252 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2253 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2254 {"/Message/Mark" , M_TARGET_EXIST},
2255 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2256 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2257 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2258 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2259 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2260 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2261 {"/Message/Color label" , M_TARGET_EXIST},
2262 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2264 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2265 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2266 {"/Tools/Harvest addresses/from Messages..."
2268 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2269 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2270 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2271 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2272 {"/Tools/List URLs..." , M_TARGET_EXIST},
2273 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2274 {"/Tools/Execute" , M_DELAY_EXEC},
2275 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2277 {"/Configuration", M_UNLOCKED},
2282 state = main_window_get_current_state(mainwin);
2284 for (i = 0; entry[i].entry != NULL; i++) {
2285 sensitive = ((entry[i].cond & state) == entry[i].cond);
2286 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2289 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2291 /* search for separator */
2292 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2293 cur_item = cur_item->next) {
2294 if (GTK_BIN(cur_item->data)->child == NULL) {
2295 cur_item = cur_item->next;
2300 for (; cur_item != NULL; cur_item = cur_item->next) {
2301 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2302 (M_UNLOCKED & state) != 0);
2305 main_window_menu_callback_block(mainwin);
2307 #define SET_CHECK_MENU_ACTIVE(path, active) \
2309 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2310 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2313 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2314 messageview_is_visible(mainwin->messageview));
2316 summaryview = mainwin->summaryview;
2317 menu_path = "/View/Sort/Don't sort";
2319 switch (summaryview->sort_key) {
2320 case SORT_BY_NUMBER:
2321 menu_path = "/View/Sort/by number"; break;
2323 menu_path = "/View/Sort/by Size"; break;
2325 menu_path = "/View/Sort/by Date"; break;
2327 menu_path = "/View/Sort/by From"; break;
2329 menu_path = "/View/Sort/by To"; break;
2330 case SORT_BY_SUBJECT:
2331 menu_path = "/View/Sort/by Subject"; break;
2333 menu_path = "/View/Sort/by color label"; break;
2335 menu_path = "/View/Sort/by mark"; break;
2336 case SORT_BY_STATUS:
2337 menu_path = "/View/Sort/by status"; break;
2339 menu_path = "/View/Sort/by attachment"; break;
2341 menu_path = "/View/Sort/by score"; break;
2342 case SORT_BY_LOCKED:
2343 menu_path = "/View/Sort/by locked"; break;
2346 menu_path = "/View/Sort/Don't sort"; break;
2348 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2350 if (summaryview->sort_type == SORT_ASCENDING) {
2351 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2353 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2356 if (summaryview->sort_key != SORT_BY_NONE) {
2357 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2358 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2360 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2361 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2364 if (mainwin->messageview
2365 && mainwin->messageview->mimeview
2366 && mainwin->messageview->mimeview->textview)
2367 SET_CHECK_MENU_ACTIVE("/View/All headers",
2368 mainwin->messageview->mimeview->textview->show_all_headers);
2369 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2370 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2371 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2372 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2373 if (prefs_common.hide_quotes == 1)
2374 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2375 if (prefs_common.hide_quotes == 2)
2376 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2377 if (prefs_common.hide_quotes == 3)
2378 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2380 #undef SET_CHECK_MENU_ACTIVE
2382 main_window_menu_callback_unblock(mainwin);
2385 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2387 GtkItemFactory *ifactory;
2389 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2392 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2394 gtk_widget_set_sensitive (gtk_item_factory_get_item
2395 (ifactory,"/Message/Mailing-List"), TRUE);
2397 gtk_widget_set_sensitive (gtk_item_factory_get_item
2398 (ifactory,"/Message/Mailing-List"), FALSE);
2401 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2404 GtkWidget *menuitem;
2406 if (!msginfo || !msginfo->extradata) {
2407 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2408 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2409 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2410 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2411 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2412 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2416 /* Mailing list post */
2417 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2418 g_free(msginfo->extradata->list_post);
2419 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2421 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2423 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2425 /* Mailing list help */
2426 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2428 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2430 /* Mailing list subscribe */
2431 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2433 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2435 /* Mailing list unsubscribe */
2436 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2438 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2440 /* Mailing list view archive */
2441 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2443 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2445 /* Mailing list contact owner */
2446 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2448 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2453 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2455 GtkWidget *item, *menu;
2456 const gchar *url_pt ;
2457 gchar url_decoded[BUFFSIZE];
2458 GList *amenu, *alist;
2461 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2463 /* First delete old submenu */
2464 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2465 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2466 alist = amenu->next;
2467 item = GTK_WIDGET (amenu->data);
2468 gtk_widget_destroy (item);
2472 for (url_pt = list_header; url_pt && *url_pt;) {
2473 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2475 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2476 item = gtk_menu_item_new_with_label ((url_decoded));
2477 g_signal_connect(G_OBJECT(item), "activate",
2478 G_CALLBACK(mailing_list_compose),
2481 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2482 !g_strncasecmp (url_decoded, "https:",6)) {
2484 item = gtk_menu_item_new_with_label ((url_decoded));
2485 g_signal_connect(G_OBJECT(item), "activate",
2486 G_CALLBACK(mailing_list_open_uri),
2490 gtk_menu_append (GTK_MENU(menu), item);
2491 gtk_widget_show (item);
2497 gtk_widget_set_sensitive (menuitem, TRUE);
2499 gtk_widget_set_sensitive (menuitem, FALSE);
2505 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2507 gchar tmp[BUFFSIZE];
2511 gboolean with_plus = TRUE;
2514 *url_decoded = '\0';
2518 /* Ignore spaces, comments and tabs () */
2519 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2521 for (;*buf != ')' && *buf != 0x00; buf++);
2523 /* First non space and non comment must be a < */
2526 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2528 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2533 *url_decoded = '\0';
2538 *url_decoded = '\0';
2544 decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2546 /* Prepare the work for the next url in the list */
2547 /* after the closing bracket >, ignore space, comments and tabs */
2548 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2550 for (;*buf != ')' && *buf != 0x00; buf++);
2552 if (!buf || !*buf) {
2557 /* now first non space, non comment must be a comma */
2559 for (;*buf != 0x00; buf++);
2565 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2569 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2570 compose_new(NULL, mailto+7, NULL);
2573 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2578 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2579 open_uri (mailto, prefs_common.uri_cmd);
2582 void main_window_popup(MainWindow *mainwin)
2584 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2585 main_window_show(mainwin);
2587 gtkut_window_popup(mainwin->window);
2590 void main_window_show(MainWindow *mainwin)
2592 gtk_widget_show(mainwin->window);
2593 gtk_widget_show(mainwin->vbox_body);
2595 gtk_widget_set_uposition(mainwin->window,
2596 prefs_common.mainwin_x,
2597 prefs_common.mainwin_y);
2599 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2600 prefs_common.folderview_width,
2601 prefs_common.folderview_height);
2602 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2603 prefs_common.summaryview_width,
2604 prefs_common.summaryview_height);
2605 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2606 prefs_common.msgview_width,
2607 prefs_common.msgview_height);
2610 void main_window_hide(MainWindow *mainwin)
2612 main_window_get_size(mainwin);
2613 main_window_get_position(mainwin);
2615 gtk_widget_hide(mainwin->window);
2616 gtk_widget_hide(mainwin->vbox_body);
2619 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2621 GtkWidget *folderwin = NULL;
2622 GtkWidget *messagewin = NULL;
2625 GtkWidget *vbox_body = mainwin->vbox_body;
2626 GtkItemFactory *ifactory = mainwin->menu_factory;
2627 GtkWidget *menuitem;
2629 debug_print("Setting widgets... ");
2631 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2632 prefs_common.folderview_width,
2633 prefs_common.folderview_height);
2634 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2635 prefs_common.summaryview_width,
2636 prefs_common.summaryview_height);
2637 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2638 prefs_common.msgview_width,
2639 prefs_common.msgview_height);
2641 mainwin->messageview->statusbar = mainwin->statusbar;
2642 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2644 /* clean top-most container */
2645 if (mainwin->hpaned) {
2646 if (mainwin->hpaned->parent == mainwin->vpaned)
2647 gtk_widget_destroy(mainwin->vpaned);
2649 gtk_widget_destroy(mainwin->hpaned);
2652 menu_set_sensitive(ifactory, "/View/Show or hide/Message view", (layout_mode != WIDE_MSGLIST_LAYOUT));
2653 switch (layout_mode) {
2654 case VERTICAL_LAYOUT:
2656 hpaned = gtk_hpaned_new();
2657 if (layout_mode == VERTICAL_LAYOUT)
2658 vpaned = gtk_hpaned_new();
2660 vpaned = gtk_vpaned_new();
2661 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2662 gtk_paned_add1(GTK_PANED(hpaned),
2663 GTK_WIDGET_PTR(mainwin->folderview));
2664 gtk_widget_show(hpaned);
2665 gtk_widget_queue_resize(hpaned);
2667 if (messageview_is_visible(mainwin->messageview)) {
2668 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2669 gtk_paned_add1(GTK_PANED(vpaned),
2670 GTK_WIDGET_PTR(mainwin->summaryview));
2672 gtk_paned_add2(GTK_PANED(hpaned),
2673 GTK_WIDGET_PTR(mainwin->summaryview));
2674 gtk_widget_ref(vpaned);
2676 gtk_paned_add2(GTK_PANED(vpaned),
2677 GTK_WIDGET_PTR(mainwin->messageview));
2678 gtk_widget_show(vpaned);
2679 gtk_widget_queue_resize(vpaned);
2682 vpaned = gtk_vpaned_new();
2683 hpaned = gtk_hpaned_new();
2684 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2685 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2687 gtk_paned_add1(GTK_PANED(hpaned),
2688 GTK_WIDGET_PTR(mainwin->folderview));
2689 gtk_paned_add2(GTK_PANED(hpaned),
2690 GTK_WIDGET_PTR(mainwin->summaryview));
2692 gtk_widget_show(hpaned);
2693 gtk_widget_queue_resize(hpaned);
2695 if (messageview_is_visible(mainwin->messageview)) {
2696 gtk_paned_add2(GTK_PANED(vpaned),
2697 GTK_WIDGET_PTR(mainwin->messageview));
2699 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2701 gtk_widget_show(vpaned);
2702 gtk_widget_queue_resize(vpaned);
2704 case WIDE_MSGLIST_LAYOUT:
2705 vpaned = gtk_vpaned_new();
2706 hpaned = gtk_hpaned_new();
2707 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2709 gtk_paned_add1(GTK_PANED(vpaned),
2710 GTK_WIDGET_PTR(mainwin->summaryview));
2711 gtk_paned_add1(GTK_PANED(hpaned),
2712 GTK_WIDGET_PTR(mainwin->folderview));
2714 gtk_widget_show(hpaned);
2715 gtk_widget_queue_resize(hpaned);
2717 if (messageview_is_visible(mainwin->messageview)) {
2718 gtk_paned_add2(GTK_PANED(hpaned),
2719 GTK_WIDGET_PTR(mainwin->messageview));
2721 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2723 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
2725 gtk_widget_show(vpaned);
2726 gtk_widget_queue_resize(vpaned);
2729 g_warning("Unknown layout");
2733 mainwin->hpaned = hpaned;
2734 mainwin->vpaned = vpaned;
2736 /* remove headerview if not in prefs */
2737 headerview_set_visibility(mainwin->messageview->headerview,
2738 prefs_common.display_header_pane);
2740 if (messageview_is_visible(mainwin->messageview))
2741 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2742 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2744 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2745 GTK_ARROW_UP, GTK_SHADOW_OUT);
2747 gtk_window_move(GTK_WINDOW(mainwin->window),
2748 prefs_common.mainwin_x,
2749 prefs_common.mainwin_y);
2751 gtk_widget_queue_resize(vbox_body);
2752 gtk_widget_queue_resize(mainwin->vbox);
2753 gtk_widget_queue_resize(mainwin->window);
2754 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2755 * and mimeview icon list/ctree lose track of their visibility states */
2756 if (!noticeview_is_visible(mainwin->messageview->noticeview))
2757 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2758 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
2759 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2760 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2761 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2763 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2765 prefs_common.layout_mode = layout_mode;
2767 menuitem = gtk_item_factory_get_item
2768 (ifactory, "/View/Show or hide/Message view");
2769 gtk_check_menu_item_set_active
2770 (GTK_CHECK_MENU_ITEM(menuitem),
2771 messageview_is_visible(mainwin->messageview));
2773 #define SET_CHECK_MENU_ACTIVE(path, active) \
2775 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2776 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2779 switch (prefs_common.layout_mode) {
2781 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
2783 case VERTICAL_LAYOUT:
2784 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
2787 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
2789 case WIDE_MSGLIST_LAYOUT:
2790 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
2793 #undef SET_CHECK_MENU_ACTIVE
2797 (G_OBJECT(folderwin), "size_allocate",
2798 G_CALLBACK(folder_window_size_allocate_cb),
2803 (G_OBJECT(messagewin), "size_allocate",
2804 G_CALLBACK(message_window_size_allocate_cb),
2808 debug_print("done.\n");
2811 void main_window_destroy_all(void)
2813 while (mainwin_list != NULL) {
2814 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2816 /* free toolbar stuff */
2817 toolbar_clear_list(TOOLBAR_MAIN);
2818 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2819 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2821 mainwin->folderview->mainwin = NULL;
2822 mainwin->summaryview->mainwin = NULL;
2823 mainwin->messageview->mainwin = NULL;
2825 g_free(mainwin->toolbar);
2828 mainwin_list = g_list_remove(mainwin_list, mainwin);
2830 g_list_free(mainwin_list);
2831 mainwin_list = NULL;
2834 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2837 gtk_widget_set_size_request(child, 1, -1);
2840 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2843 gtk_widget_set_size_request(child, -1, -1);
2846 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2849 MainWindow *mainwin = (MainWindow *)data;
2851 if (!event) return FALSE;
2853 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2854 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2857 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2858 menu_button_position, widget,
2859 event->button, event->time);
2864 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2867 MainWindow *mainwin = (MainWindow *)data;
2868 gboolean close_allowed = TRUE;
2870 hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
2872 if (close_allowed && mainwin->lock_count == 0)
2873 app_exit_cb(data, 0, widget);
2878 static void main_window_size_allocate_cb(GtkWidget *widget,
2879 GtkAllocation *allocation,
2882 MainWindow *mainwin = (MainWindow *)data;
2884 main_window_get_size(mainwin);
2887 static void folder_window_size_allocate_cb(GtkWidget *widget,
2888 GtkAllocation *allocation,
2891 MainWindow *mainwin = (MainWindow *)data;
2893 main_window_get_size(mainwin);
2896 static void message_window_size_allocate_cb(GtkWidget *widget,
2897 GtkAllocation *allocation,
2900 MainWindow *mainwin = (MainWindow *)data;
2902 main_window_get_size(mainwin);
2905 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2908 main_window_add_mailbox(mainwin);
2911 static void update_folderview_cb(MainWindow *mainwin, guint action,
2914 summary_show(mainwin->summaryview, NULL);
2915 folderview_check_new_all();
2918 static void foldersort_cb(MainWindow *mainwin, guint action,
2924 static void import_mbox_cb(MainWindow *mainwin, guint action,
2927 /* only notify if import has failed */
2928 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2929 alertpanel_error(_("Mbox import has failed."));
2933 static void export_mbox_cb(MainWindow *mainwin, guint action,
2936 /* only notify if export has failed */
2937 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2938 alertpanel_error(_("Export to mbox has failed."));
2942 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2945 /* only notify if export has failed */
2946 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
2947 alertpanel_error(_("Export to mbox has failed."));
2951 static void empty_trash_cb(MainWindow *mainwin, guint action,
2954 main_window_empty_trash(mainwin, TRUE);
2957 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2959 summary_save_as(mainwin->summaryview);
2962 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2964 summary_print(mainwin->summaryview);
2967 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2969 if (prefs_common.confirm_on_exit) {
2970 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
2971 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
2972 != G_ALERTALTERNATE)
2974 manage_window_focus_in(mainwin->window, NULL, NULL);
2977 app_will_exit(widget, mainwin);
2980 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2983 summary_search(mainwin->summaryview);
2985 message_search(mainwin->messageview);
2988 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
2990 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
2993 static void toggle_message_cb(MainWindow *mainwin, guint action,
2998 active = GTK_CHECK_MENU_ITEM(widget)->active;
3000 if (active != messageview_is_visible(mainwin->messageview))
3001 summary_toggle_view(mainwin->summaryview);
3004 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3007 toolbar_toggle(action, mainwin);
3010 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3013 MessageView *msgview = (MessageView*)mainwin->messageview;
3014 GSList *msginfo_list = NULL;
3016 g_return_if_fail(msgview != NULL);
3018 msginfo_list = summary_get_selection(mainwin->summaryview);
3019 g_return_if_fail(msginfo_list != NULL);
3020 compose_reply_from_messageview(msgview, msginfo_list, action);
3021 g_slist_free(msginfo_list);
3025 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3028 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3029 gtk_widget_show(mainwin->hbox_stat);
3030 prefs_common.show_statusbar = TRUE;
3032 gtk_widget_hide(mainwin->hbox_stat);
3033 prefs_common.show_statusbar = FALSE;
3037 static void set_layout_cb(MainWindow *mainwin, guint action,
3040 LayoutType layout_mode = action;
3042 if (mainwin->menu_lock_count) {
3045 if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3049 if (layout_mode == prefs_common.layout_mode) {
3053 if (!mainwin->messageview->visible)
3054 main_window_toggle_message_view(mainwin);
3056 main_window_separation_change(mainwin, layout_mode);
3058 mainwin_reset_paned(GTK_PANED(mainwin->vpaned));
3059 summary_relayout(mainwin->summaryview);
3062 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3065 offline_ask_sync = ask_sync;
3067 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3069 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3070 offline_ask_sync = TRUE;
3073 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3075 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3078 static gboolean any_folder_want_synchronise(void)
3080 GList *folderlist = folder_get_list();
3082 /* see if there are synchronised folders */
3083 for (; folderlist; folderlist = folderlist->next) {
3084 Folder *folder = (Folder *)folderlist->data;
3085 if (folder_want_synchronise(folder)) {
3093 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3096 if (!any_folder_want_synchronise())
3099 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3100 _("Do you want to synchronise your folders now?"),
3101 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3104 folder_synchronise(NULL);
3107 static void online_switch_clicked (GtkButton *btn, gpointer data)
3109 MainWindow *mainwin;
3110 GtkItemFactory *ifactory;
3111 GtkCheckMenuItem *menuitem;
3113 mainwin = (MainWindow *) data;
3115 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3116 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3118 g_return_if_fail(mainwin != NULL);
3119 g_return_if_fail(menuitem != NULL);
3121 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3122 gtk_widget_hide (mainwin->online_switch);
3123 gtk_widget_show (mainwin->offline_switch);
3124 menuitem->active = TRUE;
3125 inc_autocheck_timer_remove();
3128 if (prefs_common.work_offline)
3130 mainwindow_check_synchronise(mainwin, TRUE);
3131 prefs_common.work_offline = TRUE;
3132 imap_disconnect_all();
3133 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3136 if (!prefs_common.work_offline)
3138 gtk_widget_hide (mainwin->offline_switch);
3139 gtk_widget_show (mainwin->online_switch);
3140 menuitem->active = FALSE;
3141 prefs_common.work_offline = FALSE;
3142 inc_autocheck_timer_set();
3143 refresh_resolvers();
3144 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3148 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3151 addressbook_open(NULL);
3154 static void log_window_show_cb(MainWindow *mainwin, guint action,
3157 log_window_show(mainwin->logwin);
3160 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3165 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3167 summary_move_to(mainwin->summaryview);
3170 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3172 summary_copy_to(mainwin->summaryview);
3175 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3177 summary_delete(mainwin->summaryview);
3180 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3182 summary_delete_trash(mainwin->summaryview);
3185 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3187 summary_cancel(mainwin->summaryview);
3190 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3192 summary_open_msg(mainwin->summaryview);
3195 static void view_source_cb(MainWindow *mainwin, guint action,
3198 summary_view_source(mainwin->summaryview);
3201 static void show_all_header_cb(MainWindow *mainwin, guint action,
3204 if (mainwin->menu_lock_count) return;
3205 mainwin->summaryview->messageview->all_headers =
3206 GTK_CHECK_MENU_ITEM(widget)->active;
3207 summary_display_msg_selected(mainwin->summaryview,
3208 GTK_CHECK_MENU_ITEM(widget)->active);
3211 #define SET_CHECK_MENU_ACTIVE(path, active) \
3213 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3214 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3217 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3220 GtkWidget *menuitem;
3221 GtkItemFactory *ifactory = mainwin->menu_factory;
3223 if (mainwin->menu_lock_count) return;
3225 prefs_common.hide_quotes =
3226 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3228 mainwin->menu_lock_count++;
3229 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3230 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3231 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3232 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3233 mainwin->menu_lock_count--;
3235 summary_redisplay_msg(mainwin->summaryview);
3238 #undef SET_CHECK_MENU_ACTIVE
3239 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3241 summary_mark(mainwin->summaryview);
3244 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3246 summary_unmark(mainwin->summaryview);
3249 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3252 summary_mark_as_unread(mainwin->summaryview);
3255 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3258 summary_mark_as_read(mainwin->summaryview);
3261 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3264 summary_mark_all_read(mainwin->summaryview);
3267 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3270 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3273 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3276 summary_ignore_thread(mainwin->summaryview);
3279 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3282 summary_unignore_thread(mainwin->summaryview);
3285 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3288 summary_msgs_lock(mainwin->summaryview);
3291 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3294 summary_msgs_unlock(mainwin->summaryview);
3298 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3300 summary_reedit(mainwin->summaryview);
3303 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3305 if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3306 summary_display_msg_selected(mainwin->summaryview,
3307 mainwin->messageview->mimeview->textview->show_all_headers);
3309 messageview_list_urls(mainwin->messageview);
3312 static void add_address_cb(MainWindow *mainwin, guint action,
3315 summary_add_address(mainwin->summaryview);
3318 static void set_charset_cb(MainWindow *mainwin, guint action,
3323 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3324 str = conv_get_charset_str((CharSet)action);
3326 g_free(mainwin->messageview->forced_charset);
3327 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3328 procmime_force_charset(str);
3330 summary_redisplay_msg(mainwin->summaryview);
3332 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3336 static void set_decode_cb(MainWindow *mainwin, guint action,
3339 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3340 mainwin->messageview->forced_encoding = (EncodingType)action;
3342 summary_redisplay_msg(mainwin->summaryview);
3344 debug_print("forced encoding: %d\n", action);
3348 static void hide_read_messages (MainWindow *mainwin, guint action,
3351 if (!mainwin->summaryview->folder_item
3352 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3354 summary_toggle_show_read_messages(mainwin->summaryview);
3357 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3359 gboolean threaded = FALSE;
3360 if (mainwin->menu_lock_count) return;
3361 if (!mainwin->summaryview->folder_item) return;
3363 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3365 mainwin->summaryview->folder_item->threaded = threaded;
3367 mainwin->summaryview->threaded = threaded;
3369 summary_show(mainwin->summaryview,
3370 mainwin->summaryview->folder_item);
3373 static void expand_threads_cb(MainWindow *mainwin, guint action,
3376 summary_expand_threads(mainwin->summaryview);
3379 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3382 summary_collapse_threads(mainwin->summaryview);
3385 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3388 prefs_summary_column_open();
3391 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3394 prefs_folder_column_open();
3397 static void sort_summary_cb(MainWindow *mainwin, guint action,
3400 FolderItem *item = mainwin->summaryview->folder_item;
3401 GtkWidget *menuitem;
3403 if (mainwin->menu_lock_count) return;
3405 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3406 menuitem = gtk_item_factory_get_item
3407 (mainwin->menu_factory, "/View/Sort/Ascending");
3408 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3409 GTK_CHECK_MENU_ITEM(menuitem)->active
3410 ? SORT_ASCENDING : SORT_DESCENDING);
3411 item->sort_key = action;
3415 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3418 FolderItem *item = mainwin->summaryview->folder_item;
3420 if (mainwin->menu_lock_count) return;
3422 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3423 summary_sort(mainwin->summaryview,
3424 item->sort_key, (FolderSortType)action);
3427 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3430 summary_attract_by_subject(mainwin->summaryview);
3433 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3438 item = folderview_get_selected_item(mainwin->folderview);
3440 main_window_cursor_wait(mainwin);
3441 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3443 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3444 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3446 STATUSBAR_POP(mainwin);
3447 main_window_cursor_normal(mainwin);
3457 static void deldup_all(FolderItem *item, gpointer _data)
3459 struct DelDupsData *data = _data;
3462 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3464 data->dups += result;
3469 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3472 struct DelDupsData data = {0, 0};
3474 main_window_cursor_wait(mainwin);
3475 folder_func_to_all_folders(deldup_all, &data);
3476 main_window_cursor_normal(mainwin);
3478 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3479 "Deleted %d duplicate messages in %d folders.\n",
3481 data.dups, data.folders);
3484 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3486 summary_filter(mainwin->summaryview, (gboolean)action);
3489 static void execute_summary_cb(MainWindow *mainwin, guint action,
3492 summary_execute(mainwin->summaryview);
3495 static void update_summary_cb(MainWindow *mainwin, guint action,
3499 FolderView *folderview = mainwin->folderview;
3501 if (!mainwin->summaryview->folder_item) return;
3502 if (!folderview->opened) return;
3504 folder_update_op_count();
3506 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3507 folderview->opened);
3510 folder_item_scan(fitem);
3511 summary_show(mainwin->summaryview, fitem);
3514 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3516 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3519 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3521 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3524 static void prev_unread_cb(MainWindow *mainwin, guint action,
3527 summary_select_prev_unread(mainwin->summaryview);
3530 static void next_unread_cb(MainWindow *mainwin, guint action,
3533 summary_select_next_unread(mainwin->summaryview);
3536 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3538 summary_select_prev_new(mainwin->summaryview);
3541 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3543 summary_select_next_new(mainwin->summaryview);
3546 static void prev_marked_cb(MainWindow *mainwin, guint action,
3549 summary_select_prev_marked(mainwin->summaryview);
3552 static void next_marked_cb(MainWindow *mainwin, guint action,
3555 summary_select_next_marked(mainwin->summaryview);
3558 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3561 summary_select_prev_labeled(mainwin->summaryview);
3564 static void next_labeled_cb(MainWindow *mainwin, guint action,
3567 summary_select_next_labeled(mainwin->summaryview);
3570 static void last_read_cb(MainWindow *mainwin, guint action,
3573 summary_select_last_read(mainwin->summaryview);
3576 static void parent_cb(MainWindow *mainwin, guint action,
3579 summary_select_parent(mainwin->summaryview);
3582 static void goto_folder_cb(MainWindow *mainwin, guint action,
3585 FolderItem *to_folder;
3587 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3590 folderview_select(mainwin->folderview, to_folder);
3593 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3596 folderview_select_next_unread(mainwin->folderview, FALSE);
3599 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3601 messageview_copy_clipboard(mainwin->messageview);
3604 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3606 MessageView *msgview = mainwin->messageview;
3608 if (messageview_is_visible(msgview) &&
3609 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3610 messageview_select_all(mainwin->messageview);
3612 summary_select_all(mainwin->summaryview);
3615 static void select_thread_cb(MainWindow *mainwin, guint action,
3618 summary_select_thread(mainwin->summaryview, FALSE);
3621 static void delete_thread_cb(MainWindow *mainwin, guint action,
3624 summary_select_thread(mainwin->summaryview, TRUE);
3627 static void create_filter_cb(MainWindow *mainwin, guint action,
3630 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3633 static void create_processing_cb(MainWindow *mainwin, guint action,
3636 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3639 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3642 prefs_filtering_open(&pre_global_processing,
3643 _("Processing rules to apply before folder rules"),
3644 MANUAL_ANCHOR_PROCESSING,
3648 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3651 prefs_filtering_open(&post_global_processing,
3652 _("Processing rules to apply after folder rules"),
3653 MANUAL_ANCHOR_PROCESSING,
3657 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3660 prefs_filtering_open(&filtering_rules,
3661 _("Filtering configuration"),
3662 MANUAL_ANCHOR_FILTERING,
3666 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3669 prefs_template_open();
3672 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3675 prefs_actions_open(mainwin);
3678 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3681 ssl_manager_open(mainwin);
3684 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3688 new_account_cb(mainwin, 0, widget);
3690 account_open(cur_account);
3694 static void new_account_cb(MainWindow *mainwin, guint action,
3697 account_edit_open();
3698 if (!compose_get_compose_list()) account_add();
3701 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3703 FolderItem *item = NULL;
3704 cur_account = (PrefsAccount *)data;
3706 if (!mainwindow_get_mainwindow())
3708 main_window_show_cur_account(mainwindow_get_mainwindow());
3709 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3710 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3711 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3712 item = folderview_get_selected_item(
3713 mainwindow_get_mainwindow()->folderview);
3715 toolbar_set_compose_button
3716 (mainwindow_get_mainwindow()->toolbar,
3717 FOLDER_TYPE(item->folder) == F_NEWS ?
3718 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3722 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3724 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3725 PrefsAccount *account = (PrefsAccount *)data;
3727 inc_account_mail(mainwin, account);
3730 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3732 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3733 PrefsAccount *account = (PrefsAccount *)data;
3734 FolderItem *item = mainwin->summaryview->folder_item;
3736 compose_new_with_folderitem(account, item, NULL);
3739 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3744 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3746 pluginwindow_create();
3749 static void manual_open_cb(MainWindow *mainwin, guint action,
3752 manual_open((ManualType)action, NULL);
3755 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3760 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3762 MainWindow *mainwin = (MainWindow *)data;
3766 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3767 LOCAL_FOLDER(folder)->rootpath,
3771 str = g_strdup_printf(_("Scanning folder %s ..."),
3772 LOCAL_FOLDER(folder)->rootpath);
3774 STATUSBAR_PUSH(mainwin, str);
3775 STATUSBAR_POP(mainwin);
3779 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3782 SummaryView *summary;
3784 g_return_val_if_fail(data, FALSE);
3785 if (!g_list_find(mainwin_list, data))
3787 summary = ((MainWindow *)data)->summaryview;
3788 g_return_val_if_fail(summary, FALSE);
3790 if (GTK_CLIST(summary->ctree)->selection &&
3791 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3797 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
3800 is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
3804 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
3807 if (!claws_is_starting()
3808 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
3809 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
3811 if (iconified_count > 0)
3812 hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
3815 if (state->new_window_state == 0)
3816 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
3820 gboolean mainwindow_is_obscured(void)
3825 #define BREAK_ON_MODIFIER_KEY() \
3826 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3828 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3831 MainWindow *mainwin = (MainWindow*) data;
3833 if (!mainwin || !event)
3836 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3838 lastkey = event->keyval;
3842 switch (event->keyval) {
3843 case GDK_Q: /* Quit */
3844 BREAK_ON_MODIFIER_KEY();
3846 app_exit_cb(mainwin, 0, NULL);
3849 if (mainwin->folderview && mainwin->summaryview
3850 && ((!mainwin->summaryview->displayed
3851 && !mainwin->summaryview->selected)
3852 || (mainwin->summaryview->folder_item
3853 && mainwin->summaryview->folder_item->total_msgs == 0))) {
3854 g_signal_stop_emission_by_name(G_OBJECT(widget),
3856 folderview_select_next_unread(mainwin->folderview, TRUE);
3865 #undef BREAK_ON_MODIFIER_KEY
3868 * Harvest addresses for selected folder.
3870 static void addr_harvest_cb( MainWindow *mainwin,
3874 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3878 * Harvest addresses for selected messages in summary view.
3880 static void addr_harvest_msg_cb( MainWindow *mainwin,
3884 summary_harvest_address( mainwin->summaryview );
3888 *\brief get a MainWindow
3890 *\return MainWindow * The first mainwindow in the mainwin_list
3892 MainWindow *mainwindow_get_mainwindow(void)
3894 if (mainwin_list && mainwin_list->data)
3895 return (MainWindow *)(mainwin_list->data);
3900 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3902 ProgressData *data = (ProgressData *) source;
3903 MainWindow *mainwin = (MainWindow *) userdata;
3905 switch (data->cmd) {
3906 case PROGRESS_COMMAND_START:
3907 case PROGRESS_COMMAND_STOP:
3908 gtk_progress_bar_set_fraction
3909 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
3911 case PROGRESS_COMMAND_SET_PERCENTAGE:
3912 gtk_progress_bar_set_fraction
3913 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
3916 while (gtk_events_pending()) gtk_main_iteration ();
3921 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3923 mainwindow_check_synchronise(mainwin, FALSE);
3926 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
3928 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
3931 void mainwindow_jump_to(const gchar *target)
3935 FolderItem *item = NULL;
3937 MainWindow *mainwin = mainwindow_get_mainwindow();
3943 printf("not initialized\n");
3947 tmp = g_strdup(target);
3949 if ((p = strstr(tmp, "\r")) != NULL)
3951 if ((p = strstr(tmp, "\n")) != NULL)
3954 if ((item = folder_find_item_from_identifier(tmp))) {
3955 printf("selecting folder '%s'\n", tmp);
3956 folderview_select(mainwin->folderview, item);
3957 main_window_popup(mainwin);
3962 msg = strrchr(tmp, G_DIR_SEPARATOR);
3965 if ((item = folder_find_item_from_identifier(tmp))) {
3966 printf("selecting folder '%s'\n", tmp);
3967 folderview_select(mainwin->folderview, item);
3969 printf("'%s' not found\n", tmp);
3971 if (item && msg && atoi(msg)) {
3972 printf("selecting message %d\n", atoi(msg));
3973 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
3974 summary_display_msg_selected(mainwin->summaryview, FALSE);
3975 main_window_popup(mainwin);
3978 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
3979 MsgInfo *msginfo = NULL;
3981 msg[strlen(msg)-1] = '\0';
3982 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
3984 printf("selecting message %s\n", msg);
3985 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
3986 summary_display_msg_selected(mainwin->summaryview, FALSE);
3987 main_window_popup(mainwin);
3989 procmsg_msginfo_free(msginfo);
3992 printf("'%s' not found\n", msg);
3995 printf("'%s' not found\n", msg);
3998 printf("'%s' not found\n", tmp);