2 Claws Mail -- 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 3 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, see <http://www.gnu.org/licenses/>.
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <gtk/gtktooltips.h>
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
55 #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"
102 #define AC_LABEL_WIDTH 240
104 /* list of all instantiated MainWindow */
105 static GList *mainwin_list = NULL;
107 static GdkCursor *watch_cursor = NULL;
108 static GdkCursor *hand_cursor = NULL;
110 static gint iconified_count = 0;
112 static void main_window_menu_callback_block (MainWindow *mainwin);
113 static void main_window_menu_callback_unblock (MainWindow *mainwin);
115 static void main_window_show_cur_account (MainWindow *mainwin);
117 static void main_window_separation_change (MainWindow *mainwin,
118 LayoutType layout_mode);
120 static void main_window_set_widgets (MainWindow *mainwin,
121 LayoutType layout_mode);
123 static void toolbar_child_attached (GtkWidget *widget,
126 static void toolbar_child_detached (GtkWidget *widget,
130 static gboolean ac_label_button_pressed (GtkWidget *widget,
131 GdkEventButton *event,
134 static gint main_window_close_cb (GtkWidget *widget,
138 static void main_window_size_allocate_cb (GtkWidget *widget,
139 GtkAllocation *allocation,
141 static void folder_window_size_allocate_cb (GtkWidget *widget,
142 GtkAllocation *allocation,
144 static void message_window_size_allocate_cb (GtkWidget *widget,
145 GtkAllocation *allocation,
148 static void update_folderview_cb (MainWindow *mainwin,
151 static void add_mailbox_cb (MainWindow *mainwin,
154 static void foldersort_cb (MainWindow *mainwin,
157 static void import_mbox_cb (MainWindow *mainwin,
160 static void export_mbox_cb (MainWindow *mainwin,
163 static void export_list_mbox_cb (MainWindow *mainwin,
166 static void empty_trash_cb (MainWindow *mainwin,
170 static void save_as_cb (MainWindow *mainwin,
173 static void print_cb (MainWindow *mainwin,
176 static void app_exit_cb (MainWindow *mainwin,
180 static void search_cb (MainWindow *mainwin,
184 static void toggle_message_cb (MainWindow *mainwin,
187 static void toggle_toolbar_cb (MainWindow *mainwin,
190 static void toggle_col_headers_cb(MainWindow *mainwin,
194 static void toggle_statusbar_cb (MainWindow *mainwin,
197 static void set_layout_cb (MainWindow *mainwin,
201 static void addressbook_open_cb (MainWindow *mainwin,
204 static void log_window_show_cb (MainWindow *mainwin,
207 static void filtering_debug_window_show_cb (MainWindow *mainwin,
211 static void inc_cancel_cb (MainWindow *mainwin,
215 static void open_msg_cb (MainWindow *mainwin,
219 static void view_source_cb (MainWindow *mainwin,
223 static void show_all_header_cb (MainWindow *mainwin,
227 static void hide_quotes_cb(MainWindow *mainwin,
231 static void move_to_cb (MainWindow *mainwin,
234 static void copy_to_cb (MainWindow *mainwin,
237 static void delete_cb (MainWindow *mainwin,
240 static void delete_trash_cb (MainWindow *mainwin,
244 static void cancel_cb (MainWindow *mainwin,
248 static void mark_cb (MainWindow *mainwin,
251 static void unmark_cb (MainWindow *mainwin,
255 static void mark_as_unread_cb (MainWindow *mainwin,
258 static void mark_as_read_cb (MainWindow *mainwin,
261 static void mark_all_read_cb (MainWindow *mainwin,
264 static void mark_as_spam_cb (MainWindow *mainwin,
268 static void ignore_thread_cb (MainWindow *mainwin,
271 static void unignore_thread_cb (MainWindow *mainwin,
274 static void lock_msgs_cb (MainWindow *mainwin,
277 static void unlock_msgs_cb (MainWindow *mainwin,
281 static void reedit_cb (MainWindow *mainwin,
285 static void add_address_cb (MainWindow *mainwin,
289 static void set_charset_cb (MainWindow *mainwin,
293 static void set_decode_cb (MainWindow *mainwin,
297 static void hide_read_messages (MainWindow *mainwin,
301 static void thread_cb (MainWindow *mainwin,
304 static void expand_threads_cb (MainWindow *mainwin,
307 static void collapse_threads_cb (MainWindow *mainwin,
311 static void set_summary_display_item_cb (MainWindow *mainwin,
314 static void set_folder_display_item_cb (MainWindow *mainwin,
317 static void sort_summary_cb (MainWindow *mainwin,
320 static void sort_summary_type_cb (MainWindow *mainwin,
323 static void attract_by_subject_cb(MainWindow *mainwin,
327 static void delete_duplicated_cb (MainWindow *mainwin,
330 static void delete_duplicated_all_cb (MainWindow *mainwin,
333 static void filter_cb (MainWindow *mainwin,
336 static void execute_summary_cb (MainWindow *mainwin,
339 static void update_summary_cb (MainWindow *mainwin,
343 static void prev_cb (MainWindow *mainwin,
346 static void next_cb (MainWindow *mainwin,
349 static void next_unread_cb (MainWindow *mainwin,
352 static void prev_unread_cb (MainWindow *mainwin,
356 static void prev_new_cb (MainWindow *mainwin,
359 static void next_new_cb (MainWindow *mainwin,
362 static void prev_marked_cb (MainWindow *mainwin,
365 static void next_marked_cb (MainWindow *mainwin,
368 static void prev_labeled_cb (MainWindow *mainwin,
371 static void next_labeled_cb (MainWindow *mainwin,
374 static void last_read_cb (MainWindow *mainwin,
377 static void parent_cb (MainWindow *mainwin,
381 static void goto_folder_cb (MainWindow *mainwin,
384 static void goto_unread_folder_cb(MainWindow *mainwin,
388 static void copy_cb (MainWindow *mainwin,
391 static void allsel_cb (MainWindow *mainwin,
394 static void select_thread_cb (MainWindow *mainwin,
397 static void delete_thread_cb (MainWindow *mainwin,
401 static void create_filter_cb (MainWindow *mainwin,
404 static void create_processing_cb (MainWindow *mainwin,
407 static void open_urls_cb (MainWindow *mainwin,
411 static void prefs_template_open_cb (MainWindow *mainwin,
414 static void prefs_actions_open_cb (MainWindow *mainwin,
417 static void prefs_tags_open_cb (MainWindow *mainwin,
420 static void prefs_account_open_cb (MainWindow *mainwin,
424 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
428 static void prefs_post_processing_open_cb (MainWindow *mainwin,
432 static void prefs_filtering_open_cb (MainWindow *mainwin,
436 static void ssl_manager_open_cb (MainWindow *mainwin,
440 static void new_account_cb (MainWindow *mainwin,
444 static void account_selector_menu_cb (GtkMenuItem *menuitem,
446 static void account_receive_menu_cb (GtkMenuItem *menuitem,
448 static void account_compose_menu_cb (GtkMenuItem *menuitem,
451 static void prefs_open_cb (GtkMenuItem *menuitem,
453 static void plugins_open_cb (GtkMenuItem *menuitem,
456 static void online_switch_clicked(GtkButton *btn,
459 static void manual_open_cb (MainWindow *mainwin,
463 static void legend_open_cb (GtkMenuItem *menuitem,
466 static void scan_tree_func (Folder *folder,
470 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
472 static void addr_harvest_cb ( MainWindow *mainwin,
476 static void addr_harvest_msg_cb ( MainWindow *mainwin,
479 static void sync_cb ( MainWindow *mainwin,
483 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
484 GdkEventFocus *focus,
486 static gboolean mainwindow_visibility_event_cb (GtkWidget *widget,
487 GdkEventVisibility *state,
489 static gboolean mainwindow_state_event_cb (GtkWidget *widget,
490 GdkEventWindowState *state,
492 static void main_window_reply_cb (MainWindow *mainwin,
495 static gboolean mainwindow_progressindicator_hook (gpointer source,
498 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
501 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
503 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
505 static void mailing_list_compose(GtkWidget *w, gpointer *data);
507 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
508 #define SEPARATE_ACTION 500
509 static void mainwindow_quicksearch (MainWindow *mainwin,
512 static gboolean any_folder_want_synchronise(void);
514 static GtkItemFactoryEntry mainwin_entries[] =
516 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
518 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
519 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
521 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
522 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
523 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
524 {N_("/_File/Exp_ort selected to mbox file..."),
525 NULL, export_list_mbox_cb, 0, NULL},
526 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
528 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
530 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
531 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
532 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
533 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
534 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
535 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
536 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
538 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
539 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
540 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
541 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
542 {N_("/_Edit/_Delete thread"), NULL, delete_thread_cb, 0, NULL},
543 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
544 {N_("/_Edit/_Find in current message..."),
545 "<control>F", search_cb, 0, NULL},
546 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
547 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
548 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
549 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
550 {N_("/_View/Show or hi_de/_Message view"),
551 "V", toggle_message_cb, 0, "<ToggleItem>"},
552 {N_("/_View/Show or hi_de/_Toolbar"),
553 NULL, NULL, 0, "<Branch>"},
554 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
555 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
556 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
557 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
558 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
559 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
560 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
561 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
562 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
563 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
565 {N_("/_View/Show or hi_de/Status _bar"),
566 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
568 {N_("/_View/Show or hi_de/Column headers"),
569 NULL, toggle_col_headers_cb, 0, "<ToggleItem>"},
570 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
571 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
572 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
574 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
576 {N_("/_View/La_yout"), NULL, NULL, 0, "<Branch>"},
577 {N_("/_View/Layout/_Standard"), NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
578 {N_("/_View/Layout/_Three columns"), NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
579 {N_("/_View/Layout/_Wide message"), NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
580 {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
581 {N_("/_View/Layout/S_mall screen"), NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
582 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
584 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
585 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
586 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
587 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
588 {N_("/_View/_Sort/by Thread date"), NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
589 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
590 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
591 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
592 {N_("/_View/_Sort/by _color label"), NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
593 {N_("/_View/_Sort/by tag"), NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
594 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
595 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
596 {N_("/_View/_Sort/by a_ttachment"),
597 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
598 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
599 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
600 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
601 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
602 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
603 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
604 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
605 {N_("/_View/_Sort/_Attract by subject"),
606 NULL, attract_by_subject_cb, 0, NULL},
607 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
608 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
609 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
610 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
612 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
613 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
614 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
615 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
616 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_View/_Go to/P_revious unread message"),
618 "<shift>P", prev_unread_cb, 0, NULL},
619 {N_("/_View/_Go to/N_ext unread message"),
620 "<shift>N", next_unread_cb, 0, NULL},
621 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
623 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
624 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_View/_Go to/Previous _marked message"),
626 NULL, prev_marked_cb, 0, NULL},
627 {N_("/_View/_Go to/Next m_arked message"),
628 NULL, next_marked_cb, 0, NULL},
629 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_View/_Go to/Previous _labeled message"),
631 NULL, prev_labeled_cb, 0, NULL},
632 {N_("/_View/_Go to/Next la_beled message"),
633 NULL, next_labeled_cb, 0, NULL},
634 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_View/_Go to/Last read message"),
636 NULL, last_read_cb, 0, NULL},
637 {N_("/_View/_Go to/Parent message"),
638 "<control>Up", parent_cb, 0, NULL},
639 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
640 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
641 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
642 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
644 #define ENC_SEPARATOR \
645 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
646 #define ENC_ACTION(action) \
647 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
649 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_View/Character _encoding/_Auto detect"),
651 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
652 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
654 ENC_ACTION(C_US_ASCII)},
655 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
656 ENC_ACTION(C_UTF_8)},
659 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
660 ENC_ACTION(C_ISO_8859_1)},
661 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
662 ENC_ACTION(C_ISO_8859_15)},
663 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
664 ENC_ACTION(C_WINDOWS_1252)},
667 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
668 ENC_ACTION(C_ISO_8859_2)},
671 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
672 ENC_ACTION(C_ISO_8859_13)},
673 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
674 ENC_ACTION(C_ISO_8859_4)},
677 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
678 ENC_ACTION(C_ISO_8859_7)},
681 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
682 ENC_ACTION(C_ISO_8859_8)},
683 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
684 ENC_ACTION(C_CP1255)},
687 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
688 ENC_ACTION(C_ISO_8859_6)},
689 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
690 ENC_ACTION(C_CP1256)},
693 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
694 ENC_ACTION(C_ISO_8859_9)},
697 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
698 ENC_ACTION(C_ISO_8859_5)},
699 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
700 ENC_ACTION(C_KOI8_R)},
701 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
702 ENC_ACTION(C_KOI8_U)},
703 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
704 ENC_ACTION(C_CP1251)},
707 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
708 ENC_ACTION(C_ISO_2022_JP)},
709 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
710 ENC_ACTION(C_ISO_2022_JP_2)},
711 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
712 ENC_ACTION(C_EUC_JP)},
713 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
714 ENC_ACTION(C_SHIFT_JIS)},
717 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
718 ENC_ACTION(C_GB2312)},
719 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
721 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
723 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
724 ENC_ACTION(C_EUC_TW)},
725 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
726 ENC_ACTION(C_ISO_2022_CN)},
729 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
730 ENC_ACTION(C_EUC_KR)},
731 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
732 ENC_ACTION(C_ISO_2022_KR)},
735 {N_("/_View/Character _encoding/Thai (TIS-620)"),
736 ENC_ACTION(C_TIS_620)},
737 {N_("/_View/Character _encoding/Thai (Windows-874)"),
738 ENC_ACTION(C_WINDOWS_874)},
743 #define DEC_SEPARATOR \
744 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
745 #define DEC_ACTION(action) \
746 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
747 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
748 {N_("/_View/Decode/_Auto detect"),
749 NULL, set_decode_cb, 0, "<RadioItem>"},
750 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
752 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
753 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
754 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
759 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
760 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
761 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
762 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
763 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
764 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
765 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
766 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
767 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
768 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
770 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
771 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
772 {N_("/_Message/Recei_ve/Get from _current account"),
773 "<control>I", inc_mail_cb, 0, NULL},
774 {N_("/_Message/Recei_ve/Get from _all accounts"),
775 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
776 {N_("/_Message/Recei_ve/Cancel receivin_g"),
777 NULL, inc_cancel_cb, 0, NULL},
778 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
779 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
780 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
781 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
782 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
783 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
784 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
785 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
786 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
787 {N_("/_Message/Repl_y to/mailing _list"),
788 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
789 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
790 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
791 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
792 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
793 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
795 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
796 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
797 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
798 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
799 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
800 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
801 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
803 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
804 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
805 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
806 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
807 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
808 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
809 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
810 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
811 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
812 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
813 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
814 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
815 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
816 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
817 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
818 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
819 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
820 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
821 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
822 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
823 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
824 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
825 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
826 {N_("/_Message/T_ags"), NULL, NULL, 0, NULL},
827 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
828 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
830 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
831 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
832 {N_("/_Tools/Add sender to address boo_k"),
833 NULL, add_address_cb, 0, NULL},
834 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
835 {N_("/_Tools/_Harvest addresses/from _Folder..."),
836 NULL, addr_harvest_cb, 0, NULL},
837 {N_("/_Tools/_Harvest addresses/from _Messages..."),
838 NULL, addr_harvest_msg_cb, 0, NULL},
839 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
840 {N_("/_Tools/_Filter all messages in folder"),
841 NULL, filter_cb, 0, NULL},
842 {N_("/_Tools/Filter _selected messages"),
843 NULL, filter_cb, 1, NULL},
844 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
845 {N_("/_Tools/_Create filter rule/_Automatically"),
846 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
847 {N_("/_Tools/_Create filter rule/by _From"),
848 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
849 {N_("/_Tools/_Create filter rule/by _To"),
850 NULL, create_filter_cb, FILTER_BY_TO, NULL},
851 {N_("/_Tools/_Create filter rule/by _Subject"),
852 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
853 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
854 {N_("/_Tools/C_reate processing rule/_Automatically"),
855 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
856 {N_("/_Tools/C_reate processing rule/by _From"),
857 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
858 {N_("/_Tools/C_reate processing rule/by _To"),
859 NULL, create_processing_cb, FILTER_BY_TO, NULL},
860 {N_("/_Tools/C_reate processing rule/by _Subject"),
861 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
862 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
863 {N_("/_Tools/List _URLs..."), "<shift><control>U", open_urls_cb, 0, NULL},
864 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
865 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
866 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
867 {N_("/_Tools/Ch_eck for new messages in all folders"),
868 NULL, update_folderview_cb, 0, NULL},
869 {N_("/_Tools/Delete du_plicated messages"),
870 NULL, NULL, 0, "<Branch>"},
871 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
872 NULL, delete_duplicated_cb, 0, NULL},
873 {N_("/_Tools/Delete du_plicated messages/In all folders"),
874 NULL, delete_duplicated_all_cb, 0, NULL},
875 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
876 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
878 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
879 {N_("/_Tools/SSL cer_tificates..."),
880 NULL, ssl_manager_open_cb, 0, NULL},
882 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
883 {N_("/_Tools/Filtering Log"), NULL, filtering_debug_window_show_cb, 0, NULL},
884 {N_("/_Tools/Network _Log"), "<shift><control>L", log_window_show_cb, 0, NULL},
886 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
887 {N_("/_Configuration/C_hange current account"),
888 NULL, NULL, 0, "<Branch>"},
889 {N_("/_Configuration/_Preferences for current account..."),
890 NULL, prefs_account_open_cb, 0, NULL},
891 {N_("/_Configuration/Create _new account..."),
892 NULL, new_account_cb, 0, NULL},
893 {N_("/_Configuration/_Edit accounts..."),
894 NULL, account_edit_open, 0, NULL},
895 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
896 {N_("/_Configuration/P_references..."),
897 NULL, prefs_open_cb, 0, NULL},
898 {N_("/_Configuration/Pre-pr_ocessing..."),
899 NULL, prefs_pre_processing_open_cb, 0, NULL},
900 {N_("/_Configuration/Post-pro_cessing..."),
901 NULL, prefs_post_processing_open_cb, 0, NULL},
902 {N_("/_Configuration/_Filtering..."),
903 NULL, prefs_filtering_open_cb, 0, NULL},
904 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
905 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
906 {N_("/_Configuration/Tag_s..."), NULL, prefs_tags_open_cb, 0, NULL},
907 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
908 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
910 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
911 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
912 {N_("/_Help/_Online User-contributed FAQ"),
913 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
914 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
915 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
916 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
919 static gboolean offline_ask_sync = TRUE;
920 static guint lastkey;
921 static gboolean is_obscured = FALSE;
923 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
929 MainWindow *mainwin = (MainWindow *)user_data;
931 if (mainwin->summaryview &&
932 mainwin->summaryview->quicksearch &&
933 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
934 (mod == 0 || mod == GDK_SHIFT_MASK)) {
935 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
941 #define N_COLOR_LABELS colorlabel_get_color_count()
943 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
948 GtkCheckMenuItem **items;
953 mainwin = (MainWindow *)data;
954 g_return_if_fail(mainwin != NULL);
956 sel = summary_get_selection(mainwin->summaryview);
959 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
960 g_return_if_fail(menu != NULL);
962 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
964 /* NOTE: don't return prematurely because we set the "dont_toggle"
965 * state for check menu items */
966 g_object_set_data(G_OBJECT(menu), "dont_toggle",
969 /* clear items. get item pointers. */
970 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
971 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
972 gtk_check_menu_item_set_active
973 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
974 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
979 if (n == (N_COLOR_LABELS + 1)) {
980 /* iterate all messages and set the state of the appropriate
982 for (; sel != NULL; sel = sel->next) {
986 msginfo = (MsgInfo *)sel->data;
988 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
989 if (!items[clabel]->active)
990 gtk_check_menu_item_set_active
991 (items[clabel], TRUE);
995 g_warning("invalid number of color elements (%d)\n", n);
998 /* reset "dont_toggle" state */
999 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1000 GINT_TO_POINTER(0));
1003 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
1006 guint color = GPOINTER_TO_UINT(data);
1007 MainWindow *mainwin;
1009 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1010 g_return_if_fail(mainwin != NULL);
1012 /* "dont_toggle" state set? */
1013 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
1017 summary_set_colorlabel(mainwin->summaryview, color, NULL);
1020 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
1023 MainWindow *mainwin;
1027 GHashTable *menu_table = g_hash_table_new_full(
1031 GHashTable *menu_allsel_table = g_hash_table_new_full(
1036 mainwin = (MainWindow *)data;
1037 g_return_if_fail(mainwin != NULL);
1039 sel = summary_get_selection(mainwin->summaryview);
1042 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1043 g_return_if_fail(menu != NULL);
1045 /* NOTE: don't return prematurely because we set the "dont_toggle"
1046 * state for check menu items */
1047 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1048 GINT_TO_POINTER(1));
1050 /* clear items. get item pointers. */
1051 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1052 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1053 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1055 gtk_check_menu_item_set_active
1056 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1058 g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1059 g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1063 /* iterate all messages and set the state of the appropriate
1066 for (; sel != NULL; sel = sel->next) {
1068 GSList *tags = NULL;
1070 GtkCheckMenuItem *item;
1071 msginfo = (MsgInfo *)sel->data;
1074 tags = msginfo->tags;
1078 for (; tags; tags = tags->next) {
1079 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1080 id = GPOINTER_TO_INT(tags->data);
1081 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1082 if (item && !item->active) {
1083 gtk_check_menu_item_set_active
1087 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1092 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1093 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1094 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1096 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1097 if (num_checked < sel_len && num_checked > 0)
1098 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1100 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1104 g_hash_table_destroy(menu_table);
1105 g_hash_table_destroy(menu_allsel_table);
1106 /* reset "dont_toggle" state */
1107 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1108 GINT_TO_POINTER(0));
1111 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1114 gint id = GPOINTER_TO_INT(data);
1115 gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1116 MainWindow *mainwin;
1118 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1119 g_return_if_fail(mainwin != NULL);
1121 /* "dont_toggle" state set? */
1122 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1128 summary_set_tag(mainwin->summaryview, id, NULL);
1131 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1133 GtkWidget *label_menuitem;
1138 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1139 "/Message/Color label");
1140 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1141 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1143 gtk_widget_show(label_menuitem);
1145 menu = gtk_menu_new();
1147 /* create sub items. for the menu item activation callback we pass the
1148 * index of label_colors[] as data parameter. for the None color we
1149 * pass an invalid (high) value. also we attach a data pointer so we
1150 * can always get back the Mainwindow pointer. */
1152 item = gtk_check_menu_item_new_with_label(_("None"));
1153 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1154 g_signal_connect(G_OBJECT(item), "activate",
1155 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1156 GUINT_TO_POINTER(0));
1157 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1158 gtk_widget_show(item);
1160 gtk_widget_add_accelerator(item, "activate",
1161 mainwin->menu_factory->accel_group,
1162 GDK_0, GDK_CONTROL_MASK,
1163 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1165 item = gtk_menu_item_new();
1166 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1167 gtk_widget_show(item);
1169 /* create pixmap/label menu items */
1170 for (i = 0; i < N_COLOR_LABELS; i++) {
1171 item = colorlabel_create_check_color_menu_item(
1172 i, refresh, MAINWIN_COLORMENU);
1173 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1174 g_signal_connect(G_OBJECT(item), "activate",
1175 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1176 GUINT_TO_POINTER(i + 1));
1177 g_object_set_data(G_OBJECT(item), "mainwin",
1179 gtk_widget_show(item);
1181 gtk_widget_add_accelerator(item, "activate",
1182 mainwin->menu_factory->accel_group,
1183 GDK_1+i, GDK_CONTROL_MASK,
1184 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1186 gtk_widget_show(menu);
1187 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1188 mainwin->colorlabel_menu = menu;
1191 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1194 MainWindow *mainwin;
1196 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1197 g_return_if_fail(mainwin != NULL);
1199 /* "dont_toggle" state set? */
1200 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1204 tag_apply_open(summary_get_selection(mainwin->summaryview));
1207 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1209 GtkWidget *label_menuitem;
1212 GSList *cur = tags_get_list();
1214 gboolean existing_tags = FALSE;
1216 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1218 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1219 G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1222 gtk_widget_show(label_menuitem);
1224 menu = gtk_menu_new();
1226 /* create tags menu items */
1227 for (; cur; cur = cur->next) {
1228 gint id = GPOINTER_TO_INT(cur->data);
1229 const gchar *tag = tags_get_tag(id);
1231 item = gtk_check_menu_item_new_with_label(tag);
1232 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1233 g_signal_connect(G_OBJECT(item), "activate",
1234 G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1235 GINT_TO_POINTER(id));
1236 g_object_set_data(G_OBJECT(item), "mainwin",
1238 g_object_set_data(G_OBJECT(item), "tag_id",
1239 GINT_TO_POINTER(id));
1240 gtk_widget_show(item);
1241 existing_tags = TRUE;
1243 if (existing_tags) {
1245 item = gtk_menu_item_new();
1246 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1247 gtk_widget_show(item);
1250 item = gtk_menu_item_new_with_label(_("Apply tags..."));
1251 gtk_widget_add_accelerator(item, "activate",
1252 mainwin->menu_factory->accel_group,
1253 GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
1254 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1255 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1256 g_signal_connect(G_OBJECT(item), "activate",
1257 G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1259 g_object_set_data(G_OBJECT(item), "mainwin",
1261 gtk_widget_show(item);
1264 gtk_widget_show(menu);
1265 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1266 mainwin->tags_menu = menu;
1269 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1270 MainWindow *mainwindow)
1272 if (evt && evt->button == 1) {
1273 log_window_show_error(mainwindow->logwin);
1274 gtk_widget_hide(mainwindow->warning_btn);
1279 static gboolean warning_visi_notify(GtkWidget *widget,
1280 GdkEventVisibility *event,
1281 MainWindow *mainwindow)
1283 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1287 static gboolean warning_leave_notify(GtkWidget *widget,
1288 GdkEventCrossing *event,
1289 MainWindow *mainwindow)
1291 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1295 static gboolean warning_enter_notify(GtkWidget *widget,
1296 GdkEventCrossing *event,
1297 MainWindow *mainwindow)
1299 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1303 void mainwindow_show_error(void)
1305 MainWindow *mainwin = mainwindow_get_mainwindow();
1306 gtk_widget_show(mainwin->warning_btn);
1309 void mainwindow_clear_error(MainWindow *mainwin)
1311 gtk_widget_hide(mainwin->warning_btn);
1314 MainWindow *main_window_create()
1316 MainWindow *mainwin;
1320 GtkWidget *handlebox;
1321 GtkWidget *vbox_body;
1323 GtkWidget *hbox_stat;
1324 GtkWidget *statusbar;
1325 GtkWidget *progressbar;
1326 GtkWidget *statuslabel;
1327 GtkWidget *ac_button;
1328 GtkWidget *ac_label;
1329 GtkWidget *online_pixmap;
1330 GtkWidget *offline_pixmap;
1332 GtkWidget *warning_icon;
1333 GtkWidget *warning_btn;
1335 GtkWidget *online_switch;
1336 GtkWidget *offline_switch;
1337 FolderView *folderview;
1338 SummaryView *summaryview;
1339 MessageView *messageview;
1340 GdkColormap *colormap;
1342 gboolean success[4];
1343 GtkItemFactory *ifactory;
1345 GtkWidget *menuitem;
1347 guint n_menu_entries;
1349 static GdkGeometry geometry;
1351 debug_print("Creating main window...\n");
1352 mainwin = g_new0(MainWindow, 1);
1355 window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1356 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1357 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1359 prefs_common.layout_mode = SMALL_LAYOUT;
1361 if (!geometry.min_height) {
1362 geometry.min_width = 320;
1363 geometry.min_height = 200;
1365 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1368 g_signal_connect(G_OBJECT(window), "delete_event",
1369 G_CALLBACK(main_window_close_cb), mainwin);
1370 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1371 g_signal_connect(G_OBJECT(window), "focus_in_event",
1372 G_CALLBACK(mainwindow_focus_in_event),
1374 g_signal_connect(G_OBJECT(window), "key_press_event",
1375 G_CALLBACK(mainwindow_key_pressed), mainwin);
1377 gtk_widget_realize(window);
1378 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1381 gtkut_widget_set_app_icon(window);
1383 vbox = gtk_vbox_new(FALSE, 0);
1384 gtk_widget_show(vbox);
1385 gtk_container_add(GTK_CONTAINER(window), vbox);
1388 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1389 menubar = menubar_create(window, mainwin_entries,
1390 n_menu_entries, "<Main>", mainwin);
1391 gtk_widget_show(menubar);
1394 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1397 ifactory = gtk_item_factory_from_widget(menubar);
1399 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1400 main_create_mailing_list_menu (mainwin, NULL); */
1402 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1404 if (prefs_common.toolbar_detachable) {
1405 handlebox = gtk_handle_box_new();
1406 gtk_widget_show(handlebox);
1407 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1408 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1409 G_CALLBACK(toolbar_child_attached), mainwin);
1410 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1411 G_CALLBACK(toolbar_child_detached), mainwin);
1413 handlebox = gtk_hbox_new(FALSE, 0);
1414 gtk_widget_show(handlebox);
1415 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1417 /* link window to mainwin->window to avoid gdk warnings */
1418 mainwin->window = window;
1419 mainwin_list = g_list_append(mainwin_list, mainwin);
1422 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1426 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1430 toolbar_set_learn_button
1434 /* vbox that contains body */
1435 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1436 gtk_widget_show(vbox_body);
1437 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1438 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1441 hbox_stat = gtk_hbox_new(FALSE, 2);
1442 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1444 tips = gtk_tooltips_new();
1446 warning_icon = gtk_image_new_from_stock
1447 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1448 warning_btn = gtk_event_box_new();
1449 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1451 mainwin->warning_btn = warning_btn;
1453 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1454 G_CALLBACK(warning_icon_pressed),
1455 (gpointer) mainwin);
1456 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1457 G_CALLBACK(warning_visi_notify), mainwin);
1458 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1459 G_CALLBACK(warning_visi_notify), mainwin);
1460 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1461 G_CALLBACK(warning_leave_notify), mainwin);
1462 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1463 G_CALLBACK(warning_enter_notify), mainwin);
1465 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1467 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1468 _("Some error(s) happened. Click here to view log."), NULL);
1469 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1471 statusbar = statusbar_create();
1472 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1474 progressbar = gtk_progress_bar_new();
1475 gtk_widget_set_size_request(progressbar, 120, 1);
1476 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1478 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1479 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1480 online_switch = gtk_button_new ();
1481 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1482 _("You are online. Click the icon to go offline"), NULL);
1483 offline_switch = gtk_button_new ();
1484 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1485 _("You are offline. Click the icon to go online"),
1487 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1488 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1489 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1490 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1491 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1492 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1493 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1494 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1496 statuslabel = gtk_label_new("");
1497 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1499 ac_button = gtk_button_new();
1500 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1501 ac_button, _("Select account"), NULL);
1502 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1503 gtk_widget_set_size_request(ac_button, -1, 0);
1504 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1505 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1506 G_CALLBACK(ac_label_button_pressed), mainwin);
1508 ac_label = gtk_label_new("");
1509 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1511 gtk_widget_show_all(hbox_stat);
1513 gtk_widget_hide(offline_switch);
1514 gtk_widget_hide(warning_btn);
1516 online_switch = gtk_button_new ();
1517 offline_switch = gtk_button_new ();
1518 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1519 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1522 mainwin->folderview = folderview = folderview_create();
1523 mainwin->summaryview = summaryview = summary_create();
1524 mainwin->messageview = messageview = messageview_create(mainwin);
1526 /* init log instances data before creating log views */
1527 set_log_title(LOG_PROTOCOL, _("Network log"));
1528 set_log_prefs(LOG_PROTOCOL,
1529 &prefs_common.logwin_width,
1530 &prefs_common.logwin_height);
1531 set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1532 set_log_prefs(LOG_DEBUG_FILTERING,
1533 &prefs_common.filtering_debugwin_width,
1534 &prefs_common.filtering_debugwin_height);
1536 /* setup log windows */
1537 mainwin->logwin = log_window_create(LOG_PROTOCOL);
1538 log_window_init(mainwin->logwin);
1540 mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1541 log_window_set_clipping(mainwin->logwin,
1542 prefs_common.cliplog,
1543 prefs_common.loglength);
1545 log_window_init(mainwin->filtering_debugwin);
1546 log_window_set_clipping(mainwin->filtering_debugwin,
1547 prefs_common.filtering_debug_cliplog,
1548 prefs_common.filtering_debug_loglength);
1549 if (prefs_common.enable_filtering_debug)
1550 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1552 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1554 folderview->mainwin = mainwin;
1555 folderview->summaryview = summaryview;
1557 summaryview->mainwin = mainwin;
1558 summaryview->folderview = folderview;
1559 summaryview->messageview = messageview;
1560 summaryview->window = window;
1562 mainwin->vbox = vbox;
1563 mainwin->menubar = menubar;
1564 mainwin->menu_factory = ifactory;
1565 mainwin->handlebox = handlebox;
1566 mainwin->vbox_body = vbox_body;
1567 mainwin->online_switch = online_switch;
1568 mainwin->offline_switch = offline_switch;
1570 messageview->statusbar = statusbar;
1571 mainwin->statusbar = statusbar;
1572 mainwin->hbox_stat = hbox_stat;
1573 mainwin->progressbar = progressbar;
1574 mainwin->statuslabel = statuslabel;
1575 mainwin->online_pixmap = online_pixmap;
1576 mainwin->offline_pixmap = offline_pixmap;
1577 mainwin->ac_button = ac_button;
1578 mainwin->ac_label = ac_label;
1579 /* set context IDs for status bar */
1580 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1581 (GTK_STATUSBAR(statusbar), "Main Window");
1582 mainwin->folderview_cid = gtk_statusbar_get_context_id
1583 (GTK_STATUSBAR(statusbar), "Folder View");
1584 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1585 (GTK_STATUSBAR(statusbar), "Summary View");
1586 mainwin->messageview_cid = gtk_statusbar_get_context_id
1587 (GTK_STATUSBAR(statusbar), "Message View");
1588 messageview->statusbar_cid = mainwin->messageview_cid;
1591 messageview->statusbar = NULL;
1592 mainwin->statusbar = NULL;
1593 mainwin->hbox_stat = NULL;
1594 /* mainwin->progressbar is set in toolbar.c */
1595 mainwin->statuslabel = NULL;
1596 mainwin->online_pixmap = NULL;
1597 mainwin->offline_pixmap = NULL;
1598 mainwin->ac_button = NULL;
1599 mainwin->ac_label = NULL;
1602 /* allocate colors for summary view and folder view */
1603 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1604 summaryview->color_marked.blue = (guint16)65535;
1606 summaryview->color_dim.red = summaryview->color_dim.green =
1607 summaryview->color_dim.blue = COLOR_DIM;
1609 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1610 &folderview->color_new);
1612 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1613 &folderview->color_op);
1615 summaryview->color_important.red = 0;
1616 summaryview->color_important.green = 0;
1617 summaryview->color_important.blue = (guint16)65535;
1619 color[0] = summaryview->color_marked;
1620 color[1] = summaryview->color_dim;
1621 color[2] = folderview->color_new;
1622 color[3] = folderview->color_op;
1624 colormap = gdk_drawable_get_colormap(window->window);
1625 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1626 for (i = 0; i < 4; i++) {
1627 if (success[i] == FALSE)
1628 g_warning("MainWindow: color allocation %d failed\n", i);
1631 debug_print("done.\n");
1633 messageview->visible = prefs_common.msgview_visible;
1635 main_window_set_widgets(mainwin, prefs_common.layout_mode);
1637 g_signal_connect(G_OBJECT(window), "size_allocate",
1638 G_CALLBACK(main_window_size_allocate_cb),
1641 /* set menu items */
1642 menuitem = gtk_item_factory_get_item
1643 (ifactory, "/View/Character encoding/Auto detect");
1644 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1646 switch (prefs_common.toolbar_style) {
1648 menuitem = gtk_item_factory_get_item
1649 (ifactory, "/View/Show or hide/Toolbar/Hide");
1652 menuitem = gtk_item_factory_get_item
1653 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1656 menuitem = gtk_item_factory_get_item
1657 (ifactory, "/View/Show or hide/Toolbar/Text only");
1660 menuitem = gtk_item_factory_get_item
1661 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1663 case TOOLBAR_BOTH_HORIZ:
1664 menuitem = gtk_item_factory_get_item
1666 "/View/Show or hide/Toolbar/Text beside icons");
1668 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1671 gtk_widget_hide(mainwin->hbox_stat);
1672 menuitem = gtk_item_factory_get_item
1673 (ifactory, "/View/Show or hide/Status bar");
1674 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1675 prefs_common.show_statusbar);
1677 menuitem = gtk_item_factory_get_item
1678 (ifactory, "/View/Show or hide/Column headers");
1679 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1680 prefs_common.show_col_headers);
1681 /* set account selection menu */
1682 ac_menu = gtk_item_factory_get_widget
1683 (ifactory, "/Configuration/Change current account");
1684 mainwin->ac_menu = ac_menu;
1686 toolbar_main_set_sensitive(mainwin);
1688 /* create actions menu */
1689 main_window_update_actions_menu(mainwin);
1691 main_create_mailing_list_menu (mainwin, NULL);
1693 /* attach accel groups to main window */
1694 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1695 gtk_window_add_accel_group \
1697 gtk_item_factory_from_widget(menu)->accel_group); \
1698 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1700 G_CALLBACK(main_window_accel_activate), mainwin);
1703 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1705 /* connect the accelerators for equivalent
1706 menu items in different menus */
1707 menu_connect_identical_items();
1710 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1713 g_signal_connect(G_OBJECT(window), "window_state_event",
1714 G_CALLBACK(mainwindow_state_event_cb), mainwin);
1715 g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1716 G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1717 gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1719 if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1720 prefs_common.layout_mode == SMALL_LAYOUT) {
1721 summary_relayout(mainwin->summaryview);
1723 summary_update_unread(mainwin->summaryview, NULL);
1725 gtk_widget_show(mainwin->window);
1727 /* initialize views */
1728 folderview_init(folderview);
1729 summary_init(summaryview);
1730 messageview_init(messageview);
1732 sslcertwindow_register_hook();
1734 mainwin->lock_count = 0;
1735 mainwin->menu_lock_count = 0;
1736 mainwin->cursor_count = 0;
1738 mainwin->progressindicator_hook =
1739 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1742 watch_cursor = gdk_cursor_new(GDK_WATCH);
1744 hand_cursor = gdk_cursor_new(GDK_HAND2);
1746 /* init work_offline */
1747 if (prefs_common.work_offline)
1748 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1750 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1751 mainwindow_tags_menu_create(mainwin, FALSE);
1756 void main_window_destroy(MainWindow *mainwin)
1758 /* TODO : destroy other component */
1759 messageview_destroy(mainwin->messageview);
1760 mainwin->messageview = NULL;
1763 void main_window_update_actions_menu(MainWindow *mainwin)
1765 GtkItemFactory *ifactory;
1767 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1768 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1771 void main_window_cursor_wait(MainWindow *mainwin)
1774 if (mainwin->cursor_count == 0) {
1775 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1776 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1779 mainwin->cursor_count++;
1784 void main_window_cursor_normal(MainWindow *mainwin)
1786 if (mainwin->cursor_count)
1787 mainwin->cursor_count--;
1789 if (mainwin->cursor_count == 0) {
1790 gdk_window_set_cursor(mainwin->window->window, NULL);
1791 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1796 /* lock / unlock the user-interface */
1797 void main_window_lock(MainWindow *mainwin)
1799 if (mainwin->lock_count == 0 && mainwin->ac_button)
1800 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1802 mainwin->lock_count++;
1804 main_window_set_menu_sensitive(mainwin);
1805 toolbar_main_set_sensitive(mainwin);
1808 void main_window_unlock(MainWindow *mainwin)
1810 if (mainwin->lock_count)
1811 mainwin->lock_count--;
1813 main_window_set_menu_sensitive(mainwin);
1814 toolbar_main_set_sensitive(mainwin);
1816 if (mainwin->lock_count == 0 && mainwin->ac_button)
1817 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1820 static void main_window_menu_callback_block(MainWindow *mainwin)
1822 mainwin->menu_lock_count++;
1825 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1827 if (mainwin->menu_lock_count)
1828 mainwin->menu_lock_count--;
1831 static guint prefs_tag = 0;
1833 void main_window_reflect_prefs_all(void)
1835 main_window_reflect_prefs_all_real(FALSE);
1838 static gboolean reflect_prefs_timeout_cb(gpointer data)
1840 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1842 MainWindow *mainwin;
1845 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1846 mainwin = (MainWindow *)cur->data;
1848 main_window_show_cur_account(mainwin);
1849 main_window_set_menu_sensitive(mainwin);
1850 toolbar_main_set_sensitive(mainwin);
1853 if (pixmap_theme_changed) {
1854 toolbar_update(TOOLBAR_MAIN, mainwin);
1855 messageview_reflect_prefs_pixmap_theme();
1856 compose_reflect_prefs_pixmap_theme();
1857 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1858 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1860 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1861 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1862 mainwin->online_pixmap);
1863 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1864 gtk_widget_show(pixmap);
1865 mainwin->online_pixmap = pixmap;
1866 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1867 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1868 mainwin->offline_pixmap);
1869 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1870 gtk_widget_show(pixmap);
1871 mainwin->offline_pixmap = pixmap;
1875 headerview_set_font(mainwin->messageview->headerview);
1876 headerview_set_visibility(mainwin->messageview->headerview,
1877 prefs_common.display_header_pane);
1878 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1879 folderview_reflect_prefs();
1880 summary_reflect_prefs();
1882 summary_redisplay_msg(mainwin->summaryview);
1884 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1885 if (mainwin->in_folder) {
1886 mainwindow_enter_folder(mainwin);
1888 mainwindow_exit_folder(mainwin);
1896 void main_window_reflect_prefs_all_now(void)
1898 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1901 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1906 /* re-create colorlabel submenu */
1907 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1908 g_return_if_fail(menu != NULL);
1910 /* clear items. get item pointers. */
1911 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1912 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1914 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1915 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1919 void main_window_reflect_tags_changes(MainWindow *mainwin)
1924 /* re-create tags submenu */
1925 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1926 g_return_if_fail(menu != NULL);
1928 /* clear items. get item pointers. */
1929 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1930 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1932 mainwindow_tags_menu_create(mainwin, TRUE);
1933 summary_reflect_tags_changes(mainwin->summaryview);
1937 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1939 if (prefs_tag == 0 || pixmap_theme_changed) {
1940 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1941 GINT_TO_POINTER(pixmap_theme_changed));
1945 void main_window_set_summary_column(void)
1948 MainWindow *mainwin;
1950 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1951 mainwin = (MainWindow *)cur->data;
1952 summary_set_column_order(mainwin->summaryview);
1956 void main_window_set_folder_column(void)
1959 MainWindow *mainwin;
1961 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1962 mainwin = (MainWindow *)cur->data;
1963 folderview_set_column_order(mainwin->folderview);
1967 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1968 GList *account_list)
1970 GList *cur_ac, *cur_item;
1971 GtkWidget *menuitem;
1972 PrefsAccount *ac_prefs;
1974 /* destroy all previous menu item */
1975 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1976 while (cur_item != NULL) {
1977 GList *next = cur_item->next;
1978 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1982 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1983 ac_prefs = (PrefsAccount *)cur_ac->data;
1985 menuitem = gtk_menu_item_new_with_label
1986 (ac_prefs->account_name
1987 ? ac_prefs->account_name : _("Untitled"));
1988 gtk_widget_show(menuitem);
1989 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1990 g_signal_connect(G_OBJECT(menuitem), "activate",
1991 G_CALLBACK(account_selector_menu_cb),
1996 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1997 GList *account_list)
1999 GList *cur_ac, *cur_item;
2001 GtkWidget *menuitem;
2002 PrefsAccount *ac_prefs;
2004 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
2005 "/Message/Receive");
2007 /* search for separator */
2008 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2009 cur_item = cur_item->next) {
2010 if (GTK_BIN(cur_item->data)->child == NULL) {
2011 cur_item = cur_item->next;
2016 /* destroy all previous menu item */
2017 while (cur_item != NULL) {
2018 GList *next = cur_item->next;
2019 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2023 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2024 ac_prefs = (PrefsAccount *)cur_ac->data;
2026 menuitem = gtk_menu_item_new_with_label
2027 (ac_prefs->account_name ? ac_prefs->account_name
2029 gtk_widget_show(menuitem);
2030 gtk_menu_append(GTK_MENU(menu), menuitem);
2031 g_signal_connect(G_OBJECT(menuitem), "activate",
2032 G_CALLBACK(account_receive_menu_cb),
2037 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2038 GList *account_list)
2041 GtkWidget *menuitem;
2042 PrefsAccount *ac_prefs;
2043 GtkWidget *menu = NULL;
2045 if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2048 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2050 gtk_widget_destroy(menu);
2051 menu = gtk_menu_new();
2053 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2054 ac_prefs = (PrefsAccount *)cur_ac->data;
2056 menuitem = gtk_menu_item_new_with_label
2057 (ac_prefs->account_name
2058 ? ac_prefs->account_name : _("Untitled"));
2059 gtk_widget_show(menuitem);
2060 gtk_menu_append(GTK_MENU(menu), menuitem);
2061 g_signal_connect(G_OBJECT(menuitem), "activate",
2062 G_CALLBACK(account_receive_menu_cb),
2065 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2068 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2069 GList *account_list)
2073 GtkWidget *menuitem;
2074 PrefsAccount *ac_prefs;
2075 GtkWidget *menu = NULL;
2077 if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2080 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2082 gtk_widget_destroy(menu);
2083 menu = gtk_menu_new();
2085 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2086 ac_prefs = (PrefsAccount *)cur_ac->data;
2088 menuitem = gtk_menu_item_new_with_label
2089 (ac_prefs->account_name
2090 ? ac_prefs->account_name : _("Untitled"));
2091 gtk_widget_show(menuitem);
2092 gtk_menu_append(GTK_MENU(menu), menuitem);
2093 g_signal_connect(G_OBJECT(menuitem), "activate",
2094 G_CALLBACK(account_compose_menu_cb),
2097 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2101 void main_window_set_account_menu(GList *account_list)
2104 MainWindow *mainwin;
2106 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2107 mainwin = (MainWindow *)cur->data;
2108 main_window_set_account_selector_menu(mainwin, account_list);
2109 main_window_set_account_receive_menu(mainwin, account_list);
2110 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2111 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2113 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2116 void main_window_set_account_menu_only_toolbar(GList *account_list)
2119 MainWindow *mainwin;
2121 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2122 mainwin = (MainWindow *)cur->data;
2123 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2124 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2128 static void main_window_show_cur_account(MainWindow *mainwin)
2133 ac_name = g_strdup(cur_account
2134 ? (cur_account->account_name
2135 ? cur_account->account_name : _("Untitled"))
2139 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2141 buf = g_strdup(PROG_VERSION);
2142 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2145 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2146 if (mainwin->ac_button)
2147 gtk_widget_queue_resize(mainwin->ac_button);
2152 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2154 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
2155 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2156 GtkWidget *message_wid = mainwin->messageview->vbox;
2158 if (layout_mode == prefs_common.layout_mode)
2161 debug_print("Changing window separation type from %d to %d\n",
2162 prefs_common.layout_mode, layout_mode);
2164 /* remove widgets from those containers */
2165 gtk_widget_ref(folder_wid);
2166 gtk_widget_ref(summary_wid);
2167 gtk_widget_ref(message_wid);
2168 gtkut_container_remove
2169 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2170 gtkut_container_remove
2171 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2172 gtkut_container_remove
2173 (GTK_CONTAINER(message_wid->parent), message_wid);
2175 gtk_widget_hide(mainwin->window);
2176 main_window_set_widgets(mainwin, layout_mode);
2177 gtk_widget_show(mainwin->window);
2179 gtk_widget_unref(folder_wid);
2180 gtk_widget_unref(summary_wid);
2181 gtk_widget_unref(message_wid);
2184 void mainwindow_reset_paned(GtkPaned *paned)
2188 if (gtk_paned_get_child1(GTK_PANED(paned)))
2189 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2190 if (gtk_paned_get_child2(GTK_PANED(paned)))
2191 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2194 g_object_get (G_OBJECT(paned),
2197 g_object_get (G_OBJECT(paned),
2201 gtk_paned_set_position(GTK_PANED(paned), mid);
2204 static void mainwin_paned_show_first(GtkPaned *paned)
2207 g_object_get (G_OBJECT(paned),
2211 if (gtk_paned_get_child1(GTK_PANED(paned)))
2212 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2213 if (gtk_paned_get_child2(GTK_PANED(paned)))
2214 gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2215 gtk_paned_set_position(GTK_PANED(paned), max);
2218 static void mainwin_paned_show_last(GtkPaned *paned)
2221 g_object_get (G_OBJECT(paned),
2225 if (gtk_paned_get_child1(GTK_PANED(paned)))
2226 gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2227 if (gtk_paned_get_child2(GTK_PANED(paned)))
2228 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2229 gtk_paned_set_position(GTK_PANED(paned), min);
2232 void main_window_toggle_message_view(MainWindow *mainwin)
2234 SummaryView *summaryview = mainwin->summaryview;
2235 GtkWidget *ppaned = NULL;
2236 GtkWidget *container = NULL;
2238 switch (prefs_common.layout_mode) {
2240 case VERTICAL_LAYOUT:
2242 ppaned = mainwin->vpaned;
2243 container = mainwin->hpaned;
2244 if (ppaned->parent != NULL) {
2245 mainwin->messageview->visible = FALSE;
2246 summaryview->displayed = NULL;
2247 gtk_widget_ref(ppaned);
2248 gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2249 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2251 mainwin->messageview->visible = TRUE;
2252 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2253 gtk_container_add(GTK_CONTAINER(container), ppaned);
2254 gtk_widget_unref(ppaned);
2258 ppaned = mainwin->hpaned;
2259 container = mainwin->vpaned;
2260 if (mainwin->messageview->vbox->parent != NULL) {
2261 mainwin->messageview->visible = FALSE;
2262 summaryview->displayed = NULL;
2263 gtk_widget_ref(mainwin->messageview->vbox);
2264 gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2266 mainwin->messageview->visible = TRUE;
2267 gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2268 gtk_widget_unref(mainwin->messageview->vbox);
2271 case WIDE_MSGLIST_LAYOUT:
2272 g_warning("can't hide messageview in this wide msglist layout");
2276 if (messageview_is_visible(mainwin->messageview))
2277 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2278 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2280 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2281 GTK_ARROW_UP, GTK_SHADOW_OUT);
2283 if (mainwin->messageview->visible == FALSE)
2284 messageview_clear(mainwin->messageview);
2286 main_window_set_menu_sensitive(mainwin);
2288 prefs_common.msgview_visible = mainwin->messageview->visible;
2290 if (messageview_is_visible(mainwin->messageview)) {
2291 gtk_widget_queue_resize(mainwin->hpaned);
2292 gtk_widget_queue_resize(mainwin->vpaned);
2294 summary_grab_focus(summaryview);
2297 void main_window_get_size(MainWindow *mainwin)
2299 GtkAllocation *allocation;
2301 if (mainwin_list == NULL || mainwin->messageview == NULL) {
2302 debug_print("called after messageview "
2303 "has been deallocated!\n");
2307 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2309 if (allocation->width > 1 && allocation->height > 1) {
2310 prefs_common.summaryview_width = allocation->width;
2312 if (messageview_is_visible(mainwin->messageview))
2313 prefs_common.summaryview_height = allocation->height;
2315 prefs_common.mainview_width = allocation->width;
2318 allocation = &mainwin->window->allocation;
2319 if (allocation->width > 1 && allocation->height > 1) {
2320 prefs_common.mainview_height = allocation->height;
2321 prefs_common.mainwin_width = allocation->width;
2322 prefs_common.mainwin_height = allocation->height;
2325 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2326 if (allocation->width > 1 && allocation->height > 1) {
2327 prefs_common.folderview_width = allocation->width;
2328 prefs_common.folderview_height = allocation->height;
2331 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2332 if (allocation->width > 1 && allocation->height > 1) {
2333 prefs_common.msgview_width = allocation->width;
2334 prefs_common.msgview_height = allocation->height;
2337 /* debug_print("summaryview size: %d x %d\n",
2338 prefs_common.summaryview_width,
2339 prefs_common.summaryview_height);
2340 debug_print("folderview size: %d x %d\n",
2341 prefs_common.folderview_width,
2342 prefs_common.folderview_height);
2343 debug_print("messageview size: %d x %d\n",
2344 prefs_common.msgview_width,
2345 prefs_common.msgview_height); */
2348 void main_window_get_position(MainWindow *mainwin)
2352 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2354 prefs_common.mainview_x = x;
2355 prefs_common.mainview_y = y;
2356 prefs_common.mainwin_x = x;
2357 prefs_common.mainwin_y = y;
2359 debug_print("main window position: %d, %d\n", x, y);
2362 void main_window_progress_on(MainWindow *mainwin)
2364 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2367 void main_window_progress_off(MainWindow *mainwin)
2369 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2370 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2373 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2377 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2378 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2379 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2380 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2383 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2385 if (confirm && procmsg_have_trashed_mails_fast()) {
2386 if (alertpanel(_("Empty trash"),
2387 _("Delete all messages in trash folders?"),
2388 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2389 != G_ALERTALTERNATE)
2391 manage_window_focus_in(mainwin->window, NULL, NULL);
2394 procmsg_empty_all_trash();
2396 if (mainwin->summaryview->folder_item &&
2397 mainwin->summaryview->folder_item->stype == F_TRASH)
2398 gtk_widget_grab_focus(mainwin->folderview->ctree);
2401 void main_window_add_mailbox(MainWindow *mainwin)
2406 path = input_dialog(_("Add mailbox"),
2407 _("Input the location of mailbox.\n"
2408 "If an existing mailbox is specified, it will be\n"
2409 "scanned automatically."),
2412 if (folder_find_from_path(path)) {
2413 alertpanel_error(_("The mailbox '%s' already exists."), path);
2417 folder = folder_new(folder_get_class_from_string("mh"),
2418 !strcmp(path, "Mail") ? _("Mailbox") :
2419 g_path_get_basename(path), path);
2422 if (folder->klass->create_tree(folder) < 0) {
2423 alertpanel_error(_("Creation of the mailbox failed.\n"
2424 "Maybe some files already exist, or you don't have the permission to write there."));
2425 folder_destroy(folder);
2430 folder_set_ui_func(folder, scan_tree_func, mainwin);
2431 folder_scan_tree(folder, TRUE);
2432 folder_set_ui_func(folder, NULL, NULL);
2435 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2437 SensitiveCond state = 0;
2438 SummarySelection selection;
2439 FolderItem *item = mainwin->summaryview->folder_item;
2440 GList *account_list = account_get_list();
2443 selection = summary_get_selection_type(mainwin->summaryview);
2445 if (mainwin->lock_count == 0)
2446 state |= M_UNLOCKED;
2447 if (selection != SUMMARY_NONE)
2448 state |= M_MSG_EXIST;
2449 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2451 /* if (item->folder->type != F_NEWS) */
2452 state |= M_ALLOW_DELETE;
2454 if (prefs_common.immediate_exec == 0
2455 && mainwin->lock_count == 0)
2456 state |= M_DELAY_EXEC;
2458 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2459 || selection != SUMMARY_NONE)
2460 state |= M_HIDE_READ_MSG;
2462 if (mainwin->summaryview->threaded)
2463 state |= M_THREADED;
2465 state |= M_UNTHREADED;
2466 if (selection == SUMMARY_SELECTED_SINGLE ||
2467 selection == SUMMARY_SELECTED_MULTIPLE)
2468 state |= M_TARGET_EXIST;
2469 if (selection == SUMMARY_SELECTED_SINGLE)
2470 state |= M_SINGLE_TARGET_EXIST;
2471 if (mainwin->summaryview->folder_item &&
2472 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2475 state |= M_NOT_NEWS;
2476 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2477 state |= M_ACTIONS_EXIST;
2479 tmp = tags_get_list();
2480 if (tmp && g_slist_length(tmp))
2481 state |= M_TAGS_EXIST;
2484 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2485 state |= M_HAVE_QUEUED_MAILS;
2487 if (selection == SUMMARY_SELECTED_SINGLE &&
2489 (folder_has_parent_of_type(item, F_DRAFT) ||
2490 folder_has_parent_of_type(item, F_OUTBOX) ||
2491 folder_has_parent_of_type(item, F_QUEUE))))
2492 state |= M_ALLOW_REEDIT;
2494 state |= M_HAVE_ACCOUNT;
2496 if (any_folder_want_synchronise())
2497 state |= M_WANT_SYNC;
2499 for ( ; account_list != NULL; account_list = account_list->next) {
2500 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2501 state |= M_HAVE_NEWS_ACCOUNT;
2506 if (procmsg_spam_can_learn() &&
2507 (mainwin->summaryview->folder_item &&
2508 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2509 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2510 state |= M_CAN_LEARN_SPAM;
2513 if (inc_is_active())
2514 state |= M_INC_ACTIVE;
2515 if (imap_cancel_all_enabled())
2516 state |= M_INC_ACTIVE;
2518 if (mainwin->summaryview->deleted > 0 ||
2519 mainwin->summaryview->moved > 0 ||
2520 mainwin->summaryview->copied > 0)
2521 state |= M_DELAY_EXEC;
2528 void main_window_set_menu_sensitive(MainWindow *mainwin)
2530 GtkItemFactory *ifactory = mainwin->menu_factory;
2531 SensitiveCond state;
2534 GtkWidget *menuitem;
2535 SummaryView *summaryview;
2540 static const struct {
2544 {"/File/Save as...", M_TARGET_EXIST},
2545 {"/File/Print..." , M_TARGET_EXIST},
2546 {"/File/Synchronise folders", M_WANT_SYNC},
2547 {"/File/Exit" , M_UNLOCKED},
2549 {"/Edit/Select thread" , M_TARGET_EXIST},
2550 {"/Edit/Delete thread" , M_TARGET_EXIST},
2551 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2553 {"/View/Set displayed columns/in Folder list..."
2555 {"/View/Sort" , M_EXEC},
2556 {"/View/Thread view" , M_EXEC},
2557 {"/View/Expand all threads" , M_MSG_EXIST},
2558 {"/View/Collapse all threads" , M_MSG_EXIST},
2559 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2560 {"/View/Go to/Previous message" , M_MSG_EXIST},
2561 {"/View/Go to/Next message" , M_MSG_EXIST},
2562 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2563 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2564 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2565 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2566 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2567 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2568 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2569 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2570 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2571 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2572 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2574 {"/Message/Receive/Get from current account"
2575 , M_HAVE_ACCOUNT|M_UNLOCKED},
2576 {"/Message/Receive/Get from all accounts"
2577 , M_HAVE_ACCOUNT|M_UNLOCKED},
2578 {"/Message/Receive/Cancel receiving"
2580 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2581 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2582 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2583 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2584 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2585 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2586 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2587 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2588 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2589 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2590 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2591 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2592 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2593 {"/Message/Mark" , M_TARGET_EXIST},
2594 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2595 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2596 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2597 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2598 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2599 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2600 {"/Message/Color label" , M_TARGET_EXIST},
2601 {"/Message/Tags" , M_TARGET_EXIST},
2602 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2604 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2605 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2606 {"/Tools/Harvest addresses/from Messages..."
2608 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2609 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2610 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2611 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2612 {"/Tools/List URLs..." , M_TARGET_EXIST},
2613 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2614 {"/Tools/Execute" , M_DELAY_EXEC},
2615 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2617 {"/Configuration", M_UNLOCKED},
2618 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2619 {"/Configuration/Create new account...", M_UNLOCKED},
2620 {"/Configuration/Edit accounts...", M_UNLOCKED},
2625 state = main_window_get_current_state(mainwin);
2627 for (i = 0; entry[i].entry != NULL; i++) {
2628 sensitive = ((entry[i].cond & state) == entry[i].cond);
2629 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2632 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2634 /* search for separator */
2635 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2636 cur_item = cur_item->next) {
2637 if (GTK_BIN(cur_item->data)->child == NULL) {
2638 cur_item = cur_item->next;
2643 for (; cur_item != NULL; cur_item = cur_item->next) {
2644 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2645 (M_UNLOCKED & state) != 0);
2648 main_window_menu_callback_block(mainwin);
2650 #define SET_CHECK_MENU_ACTIVE(path, active) \
2652 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2653 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2656 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2657 messageview_is_visible(mainwin->messageview));
2659 summaryview = mainwin->summaryview;
2660 menu_path = "/View/Sort/Don't sort";
2662 switch (summaryview->sort_key) {
2663 case SORT_BY_NUMBER:
2664 menu_path = "/View/Sort/by number"; break;
2666 menu_path = "/View/Sort/by Size"; break;
2668 menu_path = "/View/Sort/by Date"; break;
2669 case SORT_BY_THREAD_DATE:
2670 menu_path = "/View/Sort/by Thread date"; break;
2672 menu_path = "/View/Sort/by From"; break;
2674 menu_path = "/View/Sort/by To"; break;
2675 case SORT_BY_SUBJECT:
2676 menu_path = "/View/Sort/by Subject"; break;
2678 menu_path = "/View/Sort/by color label"; break;
2680 menu_path = "/View/Sort/by mark"; break;
2681 case SORT_BY_STATUS:
2682 menu_path = "/View/Sort/by status"; break;
2684 menu_path = "/View/Sort/by attachment"; break;
2686 menu_path = "/View/Sort/by score"; break;
2687 case SORT_BY_LOCKED:
2688 menu_path = "/View/Sort/by locked"; break;
2690 menu_path = "/View/Sort/by tag"; break;
2693 menu_path = "/View/Sort/Don't sort"; break;
2695 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2697 if (summaryview->sort_type == SORT_ASCENDING) {
2698 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2700 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2703 if (summaryview->sort_key != SORT_BY_NONE) {
2704 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2705 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2707 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2708 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2711 if (mainwin->messageview
2712 && mainwin->messageview->mimeview
2713 && mainwin->messageview->mimeview->textview)
2714 SET_CHECK_MENU_ACTIVE("/View/All headers",
2715 mainwin->messageview->mimeview->textview->show_all_headers);
2716 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2717 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2718 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2719 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2720 if (prefs_common.hide_quotes == 1)
2721 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2722 if (prefs_common.hide_quotes == 2)
2723 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2724 if (prefs_common.hide_quotes == 3)
2725 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2727 #undef SET_CHECK_MENU_ACTIVE
2729 main_window_menu_callback_unblock(mainwin);
2732 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2734 GtkItemFactory *ifactory;
2736 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2739 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2741 gtk_widget_set_sensitive (gtk_item_factory_get_item
2742 (ifactory,"/Message/Mailing-List"), TRUE);
2744 gtk_widget_set_sensitive (gtk_item_factory_get_item
2745 (ifactory,"/Message/Mailing-List"), FALSE);
2748 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2751 GtkWidget *menuitem;
2753 if (!msginfo || !msginfo->extradata) {
2754 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2755 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2756 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2757 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2758 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2759 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2763 /* Mailing list post */
2764 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2765 g_free(msginfo->extradata->list_post);
2766 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2768 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2770 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2772 /* Mailing list help */
2773 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2775 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2777 /* Mailing list subscribe */
2778 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2780 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2782 /* Mailing list unsubscribe */
2783 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2785 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2787 /* Mailing list view archive */
2788 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2790 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2792 /* Mailing list contact owner */
2793 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2795 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2800 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2802 GtkWidget *item, *menu;
2803 const gchar *url_pt ;
2804 gchar url_decoded[BUFFSIZE];
2805 GList *amenu, *alist;
2808 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2810 /* First delete old submenu */
2811 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2812 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2813 alist = amenu->next;
2814 item = GTK_WIDGET (amenu->data);
2815 gtk_widget_destroy (item);
2819 for (url_pt = list_header; url_pt && *url_pt;) {
2820 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2822 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2823 item = gtk_menu_item_new_with_label ((url_decoded));
2824 g_signal_connect(G_OBJECT(item), "activate",
2825 G_CALLBACK(mailing_list_compose),
2828 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2829 !g_strncasecmp (url_decoded, "https:",6)) {
2831 item = gtk_menu_item_new_with_label ((url_decoded));
2832 g_signal_connect(G_OBJECT(item), "activate",
2833 G_CALLBACK(mailing_list_open_uri),
2837 gtk_menu_append (GTK_MENU(menu), item);
2838 gtk_widget_show (item);
2844 gtk_widget_set_sensitive (menuitem, TRUE);
2846 gtk_widget_set_sensitive (menuitem, FALSE);
2852 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2854 gchar tmp[BUFFSIZE];
2858 gboolean with_plus = TRUE;
2861 *url_decoded = '\0';
2865 /* Ignore spaces, comments and tabs () */
2866 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2868 for (;*buf != ')' && *buf != 0x00; buf++);
2870 /* First non space and non comment must be a < */
2873 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2875 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2880 *url_decoded = '\0';
2885 *url_decoded = '\0';
2891 decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2893 /* Prepare the work for the next url in the list */
2894 /* after the closing bracket >, ignore space, comments and tabs */
2895 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2897 for (;*buf != ')' && *buf != 0x00; buf++);
2899 if (!buf || !*buf) {
2904 /* now first non space, non comment must be a comma */
2906 for (;*buf != 0x00; buf++);
2912 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2916 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2917 compose_new(NULL, mailto+7, NULL);
2920 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2925 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2926 open_uri (mailto, prefs_common.uri_cmd);
2929 void main_window_popup(MainWindow *mainwin)
2931 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2932 main_window_show(mainwin);
2934 gtkut_window_popup(mainwin->window);
2935 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2936 if (mainwin->in_folder) {
2937 mainwindow_enter_folder(mainwin);
2939 mainwindow_exit_folder(mainwin);
2944 void main_window_show(MainWindow *mainwin)
2946 gtk_widget_show(mainwin->window);
2947 gtk_widget_show(mainwin->vbox_body);
2949 gtk_widget_set_uposition(mainwin->window,
2950 prefs_common.mainwin_x,
2951 prefs_common.mainwin_y);
2953 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2954 prefs_common.folderview_width,
2955 prefs_common.folderview_height);
2956 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2957 prefs_common.summaryview_width,
2958 prefs_common.summaryview_height);
2959 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2960 prefs_common.msgview_width,
2961 prefs_common.msgview_height);
2964 void main_window_hide(MainWindow *mainwin)
2966 main_window_get_size(mainwin);
2967 main_window_get_position(mainwin);
2969 gtk_widget_hide(mainwin->window);
2970 gtk_widget_hide(mainwin->vbox_body);
2973 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2975 GtkWidget *folderwin = NULL;
2976 GtkWidget *messagewin = NULL;
2979 GtkWidget *vbox_body = mainwin->vbox_body;
2980 GtkItemFactory *ifactory = mainwin->menu_factory;
2981 GtkWidget *menuitem;
2982 gboolean first_set = (mainwin->hpaned == NULL);
2983 debug_print("Setting widgets... ");
2985 if (layout_mode == SMALL_LAYOUT && first_set) {
2986 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2987 prefs_common.folderview_width,
2988 prefs_common.folderview_height);
2989 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2991 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2994 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2995 prefs_common.folderview_width,
2996 prefs_common.folderview_height);
2997 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2998 prefs_common.summaryview_width,
2999 prefs_common.summaryview_height);
3000 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3001 prefs_common.msgview_width,
3002 prefs_common.msgview_height);
3006 mainwin->messageview->statusbar = mainwin->statusbar;
3007 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3009 /* clean top-most container */
3010 if (mainwin->hpaned) {
3011 if (mainwin->hpaned->parent == mainwin->vpaned)
3012 gtk_widget_destroy(mainwin->vpaned);
3014 gtk_widget_destroy(mainwin->hpaned);
3017 menu_set_sensitive(ifactory, "/View/Show or hide/Message view",
3018 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3019 switch (layout_mode) {
3020 case VERTICAL_LAYOUT:
3023 hpaned = gtk_hpaned_new();
3024 if (layout_mode == VERTICAL_LAYOUT)
3025 vpaned = gtk_hpaned_new();
3027 vpaned = gtk_vpaned_new();
3028 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3029 gtk_paned_add1(GTK_PANED(hpaned),
3030 GTK_WIDGET_PTR(mainwin->folderview));
3031 gtk_widget_show(hpaned);
3032 gtk_widget_queue_resize(hpaned);
3034 if (messageview_is_visible(mainwin->messageview)) {
3035 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3036 gtk_paned_add1(GTK_PANED(vpaned),
3037 GTK_WIDGET_PTR(mainwin->summaryview));
3039 gtk_paned_add2(GTK_PANED(hpaned),
3040 GTK_WIDGET_PTR(mainwin->summaryview));
3041 gtk_widget_ref(vpaned);
3043 gtk_paned_add2(GTK_PANED(vpaned),
3044 GTK_WIDGET_PTR(mainwin->messageview));
3045 gtk_widget_show(vpaned);
3046 if (layout_mode == SMALL_LAYOUT && first_set) {
3047 mainwin_paned_show_first(GTK_PANED(hpaned));
3049 gtk_widget_queue_resize(vpaned);
3052 vpaned = gtk_vpaned_new();
3053 hpaned = gtk_hpaned_new();
3054 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3055 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3057 gtk_paned_add1(GTK_PANED(hpaned),
3058 GTK_WIDGET_PTR(mainwin->folderview));
3059 gtk_paned_add2(GTK_PANED(hpaned),
3060 GTK_WIDGET_PTR(mainwin->summaryview));
3062 gtk_widget_show(hpaned);
3063 gtk_widget_queue_resize(hpaned);
3065 if (messageview_is_visible(mainwin->messageview)) {
3066 gtk_paned_add2(GTK_PANED(vpaned),
3067 GTK_WIDGET_PTR(mainwin->messageview));
3069 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3071 gtk_widget_show(vpaned);
3072 gtk_widget_queue_resize(vpaned);
3074 case WIDE_MSGLIST_LAYOUT:
3075 vpaned = gtk_vpaned_new();
3076 hpaned = gtk_hpaned_new();
3077 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3079 gtk_paned_add1(GTK_PANED(vpaned),
3080 GTK_WIDGET_PTR(mainwin->summaryview));
3081 gtk_paned_add1(GTK_PANED(hpaned),
3082 GTK_WIDGET_PTR(mainwin->folderview));
3084 gtk_widget_show(hpaned);
3085 gtk_widget_queue_resize(hpaned);
3087 if (messageview_is_visible(mainwin->messageview)) {
3088 gtk_paned_add2(GTK_PANED(hpaned),
3089 GTK_WIDGET_PTR(mainwin->messageview));
3091 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3093 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3095 gtk_widget_show(vpaned);
3096 gtk_widget_queue_resize(vpaned);
3099 g_warning("Unknown layout");
3103 mainwin->hpaned = hpaned;
3104 mainwin->vpaned = vpaned;
3106 if (layout_mode == SMALL_LAYOUT) {
3107 if (mainwin->messageview->visible)
3108 main_window_toggle_message_view(mainwin);
3111 if (layout_mode == SMALL_LAYOUT && first_set) {
3112 gtk_widget_realize(mainwin->window);
3113 gtk_widget_realize(mainwin->folderview->ctree);
3114 gtk_widget_realize(mainwin->summaryview->hbox);
3115 gtk_widget_realize(mainwin->summaryview->hbox_l);
3116 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3117 prefs_common.folderview_width,
3118 prefs_common.folderview_height);
3119 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3121 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3123 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3124 prefs_common.mainwin_width,
3125 prefs_common.mainwin_height);
3126 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3128 /* remove headerview if not in prefs */
3129 headerview_set_visibility(mainwin->messageview->headerview,
3130 prefs_common.display_header_pane);
3132 if (messageview_is_visible(mainwin->messageview))
3133 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3134 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3136 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3137 GTK_ARROW_UP, GTK_SHADOW_OUT);
3139 gtk_window_move(GTK_WINDOW(mainwin->window),
3140 prefs_common.mainwin_x,
3141 prefs_common.mainwin_y);
3143 gtk_widget_queue_resize(vbox_body);
3144 gtk_widget_queue_resize(mainwin->vbox);
3145 gtk_widget_queue_resize(mainwin->window);
3146 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3147 * and mimeview icon list/ctree lose track of their visibility states */
3148 if (!noticeview_is_visible(mainwin->messageview->noticeview))
3149 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3150 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
3151 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3152 if (mainwin->messageview->mimeview->ctree_mode)
3153 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3155 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3157 prefs_common.layout_mode = layout_mode;
3159 menuitem = gtk_item_factory_get_item
3160 (ifactory, "/View/Show or hide/Message view");
3161 gtk_check_menu_item_set_active
3162 (GTK_CHECK_MENU_ITEM(menuitem),
3163 messageview_is_visible(mainwin->messageview));
3165 #define SET_CHECK_MENU_ACTIVE(path, active) \
3167 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3168 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3172 switch (prefs_common.layout_mode) {
3174 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3176 case VERTICAL_LAYOUT:
3177 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3180 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3182 case WIDE_MSGLIST_LAYOUT:
3183 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3186 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3190 #undef SET_CHECK_MENU_ACTIVE
3194 (G_OBJECT(folderwin), "size_allocate",
3195 G_CALLBACK(folder_window_size_allocate_cb),
3200 (G_OBJECT(messagewin), "size_allocate",
3201 G_CALLBACK(message_window_size_allocate_cb),
3205 debug_print("done.\n");
3208 void main_window_destroy_all(void)
3210 while (mainwin_list != NULL) {
3211 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3213 /* free toolbar stuff */
3214 toolbar_clear_list(TOOLBAR_MAIN);
3215 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3216 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3218 mainwin->folderview->mainwin = NULL;
3219 mainwin->summaryview->mainwin = NULL;
3220 mainwin->messageview->mainwin = NULL;
3222 g_free(mainwin->toolbar);
3225 mainwin_list = g_list_remove(mainwin_list, mainwin);
3227 g_list_free(mainwin_list);
3228 mainwin_list = NULL;
3231 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3234 gtk_widget_set_size_request(child, 1, -1);
3237 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3240 gtk_widget_set_size_request(child, -1, -1);
3243 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3246 MainWindow *mainwin = (MainWindow *)data;
3248 if (!event) return FALSE;
3250 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3251 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3254 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3255 menu_button_position, widget,
3256 event->button, event->time);
3261 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3264 MainWindow *mainwin = (MainWindow *)data;
3265 gboolean close_allowed = TRUE;
3267 hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3269 if (close_allowed && mainwin->lock_count == 0)
3270 app_exit_cb(data, 0, widget);
3275 static void main_window_size_allocate_cb(GtkWidget *widget,
3276 GtkAllocation *allocation,
3279 MainWindow *mainwin = (MainWindow *)data;
3280 main_window_get_size(mainwin);
3283 static void folder_window_size_allocate_cb(GtkWidget *widget,
3284 GtkAllocation *allocation,
3287 MainWindow *mainwin = (MainWindow *)data;
3289 main_window_get_size(mainwin);
3292 static void message_window_size_allocate_cb(GtkWidget *widget,
3293 GtkAllocation *allocation,
3296 MainWindow *mainwin = (MainWindow *)data;
3298 main_window_get_size(mainwin);
3301 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3304 main_window_add_mailbox(mainwin);
3307 static void update_folderview_cb(MainWindow *mainwin, guint action,
3310 summary_show(mainwin->summaryview, NULL);
3311 folderview_check_new_all();
3314 static void foldersort_cb(MainWindow *mainwin, guint action,
3320 static void import_mbox_cb(MainWindow *mainwin, guint action,
3323 /* only notify if import has failed */
3324 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3325 alertpanel_error(_("Mbox import has failed."));
3329 static void export_mbox_cb(MainWindow *mainwin, guint action,
3332 /* only notify if export has failed */
3333 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3334 alertpanel_error(_("Export to mbox has failed."));
3338 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3341 /* only notify if export has failed */
3342 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3343 alertpanel_error(_("Export to mbox has failed."));
3347 static void empty_trash_cb(MainWindow *mainwin, guint action,
3350 main_window_empty_trash(mainwin, TRUE);
3353 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3355 summary_save_as(mainwin->summaryview);
3358 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3360 summary_print(mainwin->summaryview);
3363 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3365 if (prefs_common.confirm_on_exit) {
3366 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3367 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
3368 != G_ALERTALTERNATE)
3370 manage_window_focus_in(mainwin->window, NULL, NULL);
3373 app_will_exit(widget, mainwin);
3376 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3379 summary_search(mainwin->summaryview);
3381 message_search(mainwin->messageview);
3384 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3386 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3389 static void toggle_message_cb(MainWindow *mainwin, guint action,
3394 active = GTK_CHECK_MENU_ITEM(widget)->active;
3396 if (active != messageview_is_visible(mainwin->messageview))
3397 summary_toggle_view(mainwin->summaryview);
3400 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3403 toolbar_toggle(action, mainwin);
3406 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3409 MessageView *msgview = (MessageView*)mainwin->messageview;
3410 GSList *msginfo_list = NULL;
3412 g_return_if_fail(msgview != NULL);
3414 msginfo_list = summary_get_selection(mainwin->summaryview);
3415 g_return_if_fail(msginfo_list != NULL);
3416 compose_reply_from_messageview(msgview, msginfo_list, action);
3417 g_slist_free(msginfo_list);
3420 static void toggle_col_headers_cb(MainWindow *mainwin, guint action,
3423 FolderView *folderview = mainwin->folderview;
3424 SummaryView *summaryview = mainwin->summaryview;
3426 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3427 gtk_clist_column_titles_show(GTK_CLIST(folderview->ctree));
3428 gtk_clist_column_titles_show(GTK_CLIST(summaryview->ctree));
3429 prefs_common.show_col_headers = TRUE;
3431 gtk_clist_column_titles_hide(GTK_CLIST(folderview->ctree));
3432 gtk_clist_column_titles_hide(GTK_CLIST(summaryview->ctree));
3433 prefs_common.show_col_headers = FALSE;
3438 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3441 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3442 gtk_widget_show(mainwin->hbox_stat);
3443 prefs_common.show_statusbar = TRUE;
3445 gtk_widget_hide(mainwin->hbox_stat);
3446 prefs_common.show_statusbar = FALSE;
3450 static void set_layout_cb(MainWindow *mainwin, guint action,
3453 LayoutType layout_mode = action;
3454 LayoutType old_layout_mode = prefs_common.layout_mode;
3455 if (mainwin->menu_lock_count) {
3458 if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3462 if (layout_mode == prefs_common.layout_mode) {
3466 if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3467 main_window_toggle_message_view(mainwin);
3468 else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3469 main_window_toggle_message_view(mainwin);
3471 main_window_separation_change(mainwin, layout_mode);
3472 mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3473 if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3474 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3476 if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3477 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3478 mainwindow_exit_folder(mainwin);
3480 summary_relayout(mainwin->summaryview);
3481 summary_update_unread(mainwin->summaryview, NULL);
3485 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3488 offline_ask_sync = ask_sync;
3490 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3492 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3493 offline_ask_sync = TRUE;
3496 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3498 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3501 static gboolean any_folder_want_synchronise(void)
3503 GList *folderlist = folder_get_list();
3505 /* see if there are synchronised folders */
3506 for (; folderlist; folderlist = folderlist->next) {
3507 Folder *folder = (Folder *)folderlist->data;
3508 if (folder_want_synchronise(folder)) {
3516 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3519 if (!any_folder_want_synchronise())
3522 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3523 _("Do you want to synchronise your folders now?"),
3524 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3527 if (offline_ask_sync)
3528 folder_synchronise(NULL);
3531 static void online_switch_clicked (GtkButton *btn, gpointer data)
3533 MainWindow *mainwin;
3534 GtkItemFactory *ifactory;
3535 GtkCheckMenuItem *menuitem;
3537 mainwin = (MainWindow *) data;
3539 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3540 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3542 g_return_if_fail(mainwin != NULL);
3543 g_return_if_fail(menuitem != NULL);
3545 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3547 gtk_widget_hide (mainwin->online_switch);
3548 gtk_widget_show (mainwin->offline_switch);
3550 menuitem->active = TRUE;
3551 inc_autocheck_timer_remove();
3554 if (prefs_common.work_offline)
3556 mainwindow_check_synchronise(mainwin, TRUE);
3557 prefs_common.work_offline = TRUE;
3558 imap_disconnect_all();
3559 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3562 if (!prefs_common.work_offline)
3565 gtk_widget_hide (mainwin->offline_switch);
3566 gtk_widget_show (mainwin->online_switch);
3568 menuitem->active = FALSE;
3569 prefs_common.work_offline = FALSE;
3570 inc_autocheck_timer_set();
3571 refresh_resolvers();
3572 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3576 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3579 addressbook_open(NULL);
3582 static void log_window_show_cb(MainWindow *mainwin, guint action,
3585 log_window_show(mainwin->logwin);
3588 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3591 log_window_show(mainwin->filtering_debugwin);
3594 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3600 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3602 summary_move_to(mainwin->summaryview);
3605 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3607 summary_copy_to(mainwin->summaryview);
3610 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3612 summary_delete(mainwin->summaryview);
3615 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3617 summary_delete_trash(mainwin->summaryview);
3620 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3622 summary_cancel(mainwin->summaryview);
3625 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3627 summary_open_msg(mainwin->summaryview);
3630 static void view_source_cb(MainWindow *mainwin, guint action,
3633 summary_view_source(mainwin->summaryview);
3636 static void show_all_header_cb(MainWindow *mainwin, guint action,
3639 if (mainwin->menu_lock_count) return;
3640 mainwin->summaryview->messageview->all_headers =
3641 GTK_CHECK_MENU_ITEM(widget)->active;
3642 summary_display_msg_selected(mainwin->summaryview,
3643 GTK_CHECK_MENU_ITEM(widget)->active);
3646 #define SET_CHECK_MENU_ACTIVE(path, active) \
3648 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3649 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3652 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3655 GtkWidget *menuitem;
3656 GtkItemFactory *ifactory = mainwin->menu_factory;
3658 if (mainwin->menu_lock_count) return;
3660 prefs_common.hide_quotes =
3661 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3663 mainwin->menu_lock_count++;
3664 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3665 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3666 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3667 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3668 mainwin->menu_lock_count--;
3670 summary_redisplay_msg(mainwin->summaryview);
3673 #undef SET_CHECK_MENU_ACTIVE
3674 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3676 summary_mark(mainwin->summaryview);
3679 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3681 summary_unmark(mainwin->summaryview);
3684 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3687 summary_mark_as_unread(mainwin->summaryview);
3690 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3693 summary_mark_as_read(mainwin->summaryview);
3696 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3699 summary_mark_all_read(mainwin->summaryview);
3702 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3705 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3708 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3711 summary_ignore_thread(mainwin->summaryview);
3714 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3717 summary_unignore_thread(mainwin->summaryview);
3720 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3723 summary_msgs_lock(mainwin->summaryview);
3726 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3729 summary_msgs_unlock(mainwin->summaryview);
3733 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3735 summary_reedit(mainwin->summaryview);
3738 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3740 if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3741 summary_display_msg_selected(mainwin->summaryview,
3742 mainwin->messageview->mimeview->textview->show_all_headers);
3744 messageview_list_urls(mainwin->messageview);
3747 static void add_address_cb(MainWindow *mainwin, guint action,
3750 summary_add_address(mainwin->summaryview);
3753 static void set_charset_cb(MainWindow *mainwin, guint action,
3758 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3759 str = conv_get_charset_str((CharSet)action);
3761 g_free(mainwin->messageview->forced_charset);
3762 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3763 procmime_force_charset(str);
3765 summary_redisplay_msg(mainwin->summaryview);
3767 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3771 static void set_decode_cb(MainWindow *mainwin, guint action,
3774 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3775 mainwin->messageview->forced_encoding = (EncodingType)action;
3777 summary_redisplay_msg(mainwin->summaryview);
3779 debug_print("forced encoding: %d\n", action);
3783 static void hide_read_messages (MainWindow *mainwin, guint action,
3786 if (!mainwin->summaryview->folder_item
3787 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3789 summary_toggle_show_read_messages(mainwin->summaryview);
3792 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3794 gboolean threaded = FALSE;
3795 if (mainwin->menu_lock_count) return;
3796 if (!mainwin->summaryview->folder_item) return;
3798 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3800 mainwin->summaryview->folder_item->threaded = threaded;
3802 mainwin->summaryview->threaded = threaded;
3804 summary_show(mainwin->summaryview,
3805 mainwin->summaryview->folder_item);
3808 static void expand_threads_cb(MainWindow *mainwin, guint action,
3811 summary_expand_threads(mainwin->summaryview);
3814 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3817 summary_collapse_threads(mainwin->summaryview);
3820 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3823 prefs_summary_column_open();
3826 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3829 prefs_folder_column_open();
3832 static void sort_summary_cb(MainWindow *mainwin, guint action,
3835 FolderItem *item = mainwin->summaryview->folder_item;
3836 GtkWidget *menuitem;
3838 if (mainwin->menu_lock_count) return;
3840 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3841 menuitem = gtk_item_factory_get_item
3842 (mainwin->menu_factory, "/View/Sort/Ascending");
3843 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3844 GTK_CHECK_MENU_ITEM(menuitem)->active
3845 ? SORT_ASCENDING : SORT_DESCENDING);
3846 item->sort_key = action;
3850 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3853 FolderItem *item = mainwin->summaryview->folder_item;
3855 if (mainwin->menu_lock_count) return;
3857 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3858 summary_sort(mainwin->summaryview,
3859 item->sort_key, (FolderSortType)action);
3862 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3865 summary_attract_by_subject(mainwin->summaryview);
3868 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3873 item = folderview_get_selected_item(mainwin->folderview);
3875 main_window_cursor_wait(mainwin);
3876 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3878 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3879 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3881 STATUSBAR_POP(mainwin);
3882 main_window_cursor_normal(mainwin);
3892 static void deldup_all(FolderItem *item, gpointer _data)
3894 struct DelDupsData *data = _data;
3897 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3899 data->dups += result;
3904 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3907 struct DelDupsData data = {0, 0};
3909 main_window_cursor_wait(mainwin);
3910 folder_func_to_all_folders(deldup_all, &data);
3911 main_window_cursor_normal(mainwin);
3913 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3914 "Deleted %d duplicate messages in %d folders.\n",
3916 data.dups, data.folders);
3919 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3921 summary_filter(mainwin->summaryview, (gboolean)action);
3924 static void execute_summary_cb(MainWindow *mainwin, guint action,
3927 summary_execute(mainwin->summaryview);
3930 static void update_summary_cb(MainWindow *mainwin, guint action,
3934 FolderView *folderview = mainwin->folderview;
3936 if (!mainwin->summaryview->folder_item) return;
3937 if (!folderview->opened) return;
3939 folder_update_op_count();
3941 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3942 folderview->opened);
3945 folder_item_scan(fitem);
3946 summary_show(mainwin->summaryview, fitem);
3949 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3951 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3954 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3956 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3959 static void prev_unread_cb(MainWindow *mainwin, guint action,
3962 summary_select_prev_unread(mainwin->summaryview);
3965 static void next_unread_cb(MainWindow *mainwin, guint action,
3968 summary_select_next_unread(mainwin->summaryview);
3971 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3973 summary_select_prev_new(mainwin->summaryview);
3976 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3978 summary_select_next_new(mainwin->summaryview);
3981 static void prev_marked_cb(MainWindow *mainwin, guint action,
3984 summary_select_prev_marked(mainwin->summaryview);
3987 static void next_marked_cb(MainWindow *mainwin, guint action,
3990 summary_select_next_marked(mainwin->summaryview);
3993 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3996 summary_select_prev_labeled(mainwin->summaryview);
3999 static void next_labeled_cb(MainWindow *mainwin, guint action,
4002 summary_select_next_labeled(mainwin->summaryview);
4005 static void last_read_cb(MainWindow *mainwin, guint action,
4008 summary_select_last_read(mainwin->summaryview);
4011 static void parent_cb(MainWindow *mainwin, guint action,
4014 summary_select_parent(mainwin->summaryview);
4017 static void goto_folder_cb(MainWindow *mainwin, guint action,
4020 FolderItem *to_folder;
4022 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
4025 folderview_select(mainwin->folderview, to_folder);
4028 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
4031 folderview_select_next_unread(mainwin->folderview, FALSE);
4034 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4036 messageview_copy_clipboard(mainwin->messageview);
4039 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4041 MessageView *msgview = mainwin->messageview;
4043 if (messageview_is_visible(msgview) &&
4044 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
4045 messageview_select_all(mainwin->messageview);
4047 summary_select_all(mainwin->summaryview);
4050 static void select_thread_cb(MainWindow *mainwin, guint action,
4053 summary_select_thread(mainwin->summaryview, FALSE);
4056 static void delete_thread_cb(MainWindow *mainwin, guint action,
4059 summary_select_thread(mainwin->summaryview, TRUE);
4062 static void create_filter_cb(MainWindow *mainwin, guint action,
4065 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4068 static void create_processing_cb(MainWindow *mainwin, guint action,
4071 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4074 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
4077 prefs_filtering_open(&pre_global_processing,
4078 _("Processing rules to apply before folder rules"),
4079 MANUAL_ANCHOR_PROCESSING,
4083 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
4086 prefs_filtering_open(&post_global_processing,
4087 _("Processing rules to apply after folder rules"),
4088 MANUAL_ANCHOR_PROCESSING,
4092 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
4095 prefs_filtering_open(&filtering_rules,
4096 _("Filtering configuration"),
4097 MANUAL_ANCHOR_FILTERING,
4101 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4104 prefs_template_open();
4107 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4110 prefs_actions_open(mainwin);
4113 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4116 prefs_tags_open(mainwin);
4119 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4122 ssl_manager_open(mainwin);
4125 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4129 new_account_cb(mainwin, 0, widget);
4131 account_open(cur_account);
4135 static void new_account_cb(MainWindow *mainwin, guint action,
4138 account_edit_open();
4139 if (!compose_get_compose_list()) account_add();
4142 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4144 FolderItem *item = NULL;
4145 cur_account = (PrefsAccount *)data;
4147 if (!mainwindow_get_mainwindow())
4149 main_window_show_cur_account(mainwindow_get_mainwindow());
4150 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4151 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4152 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4153 item = folderview_get_selected_item(
4154 mainwindow_get_mainwindow()->folderview);
4156 toolbar_set_compose_button
4157 (mainwindow_get_mainwindow()->toolbar,
4158 FOLDER_TYPE(item->folder) == F_NEWS ?
4159 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4163 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4165 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4166 PrefsAccount *account = (PrefsAccount *)data;
4168 inc_account_mail(mainwin, account);
4171 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4173 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4174 PrefsAccount *account = (PrefsAccount *)data;
4175 FolderItem *item = mainwin->summaryview->folder_item;
4177 compose_new_with_folderitem(account, item, NULL);
4180 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4185 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4187 pluginwindow_create();
4190 static void manual_open_cb(MainWindow *mainwin, guint action,
4193 manual_open((ManualType)action, NULL);
4196 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4201 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4203 MainWindow *mainwin = (MainWindow *)data;
4207 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4208 LOCAL_FOLDER(folder)->rootpath,
4212 str = g_strdup_printf(_("Scanning folder %s ..."),
4213 LOCAL_FOLDER(folder)->rootpath);
4215 STATUSBAR_PUSH(mainwin, str);
4216 STATUSBAR_POP(mainwin);
4220 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4223 SummaryView *summary;
4225 g_return_val_if_fail(data, FALSE);
4226 if (!g_list_find(mainwin_list, data))
4228 summary = ((MainWindow *)data)->summaryview;
4229 g_return_val_if_fail(summary, FALSE);
4231 if (GTK_CLIST(summary->ctree)->selection &&
4232 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4238 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4241 is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4245 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4248 if (!claws_is_starting()
4249 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4250 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4252 if (iconified_count > 0)
4253 hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4256 if (state->new_window_state == 0)
4257 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4261 gboolean mainwindow_is_obscured(void)
4266 #define BREAK_ON_MODIFIER_KEY() \
4267 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
4269 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
4272 MainWindow *mainwin = (MainWindow*) data;
4274 if (!mainwin || !event)
4277 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
4279 lastkey = event->keyval;
4283 switch (event->keyval) {
4284 case GDK_Q: /* Quit */
4285 BREAK_ON_MODIFIER_KEY();
4287 app_exit_cb(mainwin, 0, NULL);
4290 if (mainwin->folderview && mainwin->summaryview
4291 && ((!mainwin->summaryview->displayed
4292 && !mainwin->summaryview->selected)
4293 || (mainwin->summaryview->folder_item
4294 && mainwin->summaryview->folder_item->total_msgs == 0))) {
4295 g_signal_stop_emission_by_name(G_OBJECT(widget),
4297 folderview_select_next_unread(mainwin->folderview, TRUE);
4302 if (maemo_mainwindow_is_fullscreen(widget)) {
4303 gtk_window_unfullscreen(GTK_WINDOW(widget));
4305 gtk_window_fullscreen(GTK_WINDOW(widget));
4315 #undef BREAK_ON_MODIFIER_KEY
4318 * Harvest addresses for selected folder.
4320 static void addr_harvest_cb( MainWindow *mainwin,
4324 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4328 * Harvest addresses for selected messages in summary view.
4330 static void addr_harvest_msg_cb( MainWindow *mainwin,
4334 summary_harvest_address( mainwin->summaryview );
4338 *\brief get a MainWindow
4340 *\return MainWindow * The first mainwindow in the mainwin_list
4342 MainWindow *mainwindow_get_mainwindow(void)
4344 if (mainwin_list && mainwin_list->data)
4345 return (MainWindow *)(mainwin_list->data);
4350 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4352 ProgressData *data = (ProgressData *) source;
4353 MainWindow *mainwin = (MainWindow *) userdata;
4355 switch (data->cmd) {
4356 case PROGRESS_COMMAND_START:
4357 case PROGRESS_COMMAND_STOP:
4358 gtk_progress_bar_set_fraction
4359 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4361 case PROGRESS_COMMAND_SET_PERCENTAGE:
4362 gtk_progress_bar_set_fraction
4363 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4366 while (gtk_events_pending()) gtk_main_iteration ();
4371 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4373 mainwindow_check_synchronise(mainwin, FALSE);
4376 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4378 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4381 void mainwindow_jump_to(const gchar *target, gboolean popup)
4385 FolderItem *item = NULL;
4387 MainWindow *mainwin = mainwindow_get_mainwindow();
4393 printf("not initialized\n");
4397 tmp = g_strdup(target);
4399 if ((p = strstr(tmp, "\r")) != NULL)
4401 if ((p = strstr(tmp, "\n")) != NULL)
4404 if ((item = folder_find_item_from_identifier(tmp))) {
4405 printf("selecting folder '%s'\n", tmp);
4406 folderview_select(mainwin->folderview, item);
4408 main_window_popup(mainwin);
4413 msg = strrchr(tmp, G_DIR_SEPARATOR);
4416 if ((item = folder_find_item_from_identifier(tmp))) {
4417 printf("selecting folder '%s'\n", tmp);
4418 folderview_select(mainwin->folderview, item);
4420 printf("'%s' not found\n", tmp);
4422 if (item && msg && atoi(msg)) {
4423 printf("selecting message %d\n", atoi(msg));
4424 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4425 summary_display_msg_selected(mainwin->summaryview, FALSE);
4427 main_window_popup(mainwin);
4430 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4431 MsgInfo *msginfo = NULL;
4433 msg[strlen(msg)-1] = '\0';
4434 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4436 printf("selecting message %s\n", msg);
4437 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4438 summary_display_msg_selected(mainwin->summaryview, FALSE);
4440 main_window_popup(mainwin);
4442 procmsg_msginfo_free(msginfo);
4445 printf("'%s' not found\n", msg);
4448 printf("'%s' not found\n", msg);
4451 printf("'%s' not found\n", tmp);
4457 void mainwindow_exit_folder(MainWindow *mainwin) {
4458 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4459 folderview_close_opened(mainwin->folderview);
4460 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4462 mainwin->in_folder = FALSE;
4465 void mainwindow_enter_folder(MainWindow *mainwin) {
4466 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4467 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4469 mainwin->in_folder = TRUE;
4473 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4476 gtk_window_get_size(GTK_WINDOW(widget), &w, &h);
4480 void maemo_window_full_screen_if_needed (GtkWindow *window)
4482 if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4483 gtk_window_fullscreen(GTK_WINDOW(window));
4487 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4489 g_signal_connect(G_OBJECT(window), "key_press_event",
4490 G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());