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 watch_thread_cb (MainWindow *mainwin,
277 static void unwatch_thread_cb (MainWindow *mainwin,
280 static void lock_msgs_cb (MainWindow *mainwin,
283 static void unlock_msgs_cb (MainWindow *mainwin,
287 static void reedit_cb (MainWindow *mainwin,
291 static void add_address_cb (MainWindow *mainwin,
295 static void set_charset_cb (MainWindow *mainwin,
299 static void set_decode_cb (MainWindow *mainwin,
303 static void hide_read_messages (MainWindow *mainwin,
307 static void thread_cb (MainWindow *mainwin,
310 static void expand_threads_cb (MainWindow *mainwin,
313 static void collapse_threads_cb (MainWindow *mainwin,
317 static void set_summary_display_item_cb (MainWindow *mainwin,
320 static void set_folder_display_item_cb (MainWindow *mainwin,
323 static void sort_summary_cb (MainWindow *mainwin,
326 static void sort_summary_type_cb (MainWindow *mainwin,
329 static void attract_by_subject_cb(MainWindow *mainwin,
333 static void delete_duplicated_cb (MainWindow *mainwin,
336 static void delete_duplicated_all_cb (MainWindow *mainwin,
339 static void filter_cb (MainWindow *mainwin,
342 static void execute_summary_cb (MainWindow *mainwin,
345 static void update_summary_cb (MainWindow *mainwin,
349 static void prev_cb (MainWindow *mainwin,
352 static void next_cb (MainWindow *mainwin,
355 static void next_unread_cb (MainWindow *mainwin,
358 static void prev_unread_cb (MainWindow *mainwin,
362 static void prev_new_cb (MainWindow *mainwin,
365 static void next_new_cb (MainWindow *mainwin,
368 static void prev_marked_cb (MainWindow *mainwin,
371 static void next_marked_cb (MainWindow *mainwin,
374 static void prev_labeled_cb (MainWindow *mainwin,
377 static void next_labeled_cb (MainWindow *mainwin,
380 static void last_read_cb (MainWindow *mainwin,
383 static void parent_cb (MainWindow *mainwin,
387 static void goto_folder_cb (MainWindow *mainwin,
390 static void goto_unread_folder_cb(MainWindow *mainwin,
394 static void copy_cb (MainWindow *mainwin,
397 static void allsel_cb (MainWindow *mainwin,
400 static void select_thread_cb (MainWindow *mainwin,
403 static void delete_thread_cb (MainWindow *mainwin,
407 static void create_filter_cb (MainWindow *mainwin,
410 static void create_processing_cb (MainWindow *mainwin,
413 static void open_urls_cb (MainWindow *mainwin,
417 static void prefs_template_open_cb (MainWindow *mainwin,
420 static void prefs_actions_open_cb (MainWindow *mainwin,
423 static void prefs_tags_open_cb (MainWindow *mainwin,
426 static void prefs_account_open_cb (MainWindow *mainwin,
430 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
434 static void prefs_post_processing_open_cb (MainWindow *mainwin,
438 static void prefs_filtering_open_cb (MainWindow *mainwin,
442 static void ssl_manager_open_cb (MainWindow *mainwin,
446 static void new_account_cb (MainWindow *mainwin,
450 static void account_selector_menu_cb (GtkMenuItem *menuitem,
452 static void account_receive_menu_cb (GtkMenuItem *menuitem,
454 static void account_compose_menu_cb (GtkMenuItem *menuitem,
457 static void prefs_open_cb (GtkMenuItem *menuitem,
459 static void plugins_open_cb (GtkMenuItem *menuitem,
462 static void online_switch_clicked(GtkButton *btn,
465 static void manual_open_cb (MainWindow *mainwin,
469 static void legend_open_cb (GtkMenuItem *menuitem,
472 static void scan_tree_func (Folder *folder,
476 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
478 static void addr_harvest_cb ( MainWindow *mainwin,
482 static void addr_harvest_msg_cb ( MainWindow *mainwin,
485 static void sync_cb ( MainWindow *mainwin,
489 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
490 GdkEventFocus *focus,
492 static gboolean mainwindow_visibility_event_cb (GtkWidget *widget,
493 GdkEventVisibility *state,
495 static gboolean mainwindow_state_event_cb (GtkWidget *widget,
496 GdkEventWindowState *state,
498 static void main_window_reply_cb (MainWindow *mainwin,
501 static gboolean mainwindow_progressindicator_hook (gpointer source,
504 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
507 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
509 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
511 static void mailing_list_compose(GtkWidget *w, gpointer *data);
513 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
514 #define SEPARATE_ACTION 500
515 static void mainwindow_quicksearch (MainWindow *mainwin,
518 static gboolean any_folder_want_synchronise(void);
520 static GtkItemFactoryEntry mainwin_entries[] =
522 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
523 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
524 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
525 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
527 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
528 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
529 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
530 {N_("/_File/Exp_ort selected to mbox file..."),
531 NULL, export_list_mbox_cb, 0, NULL},
532 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
534 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
536 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
537 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
539 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
540 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
541 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
542 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
544 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
545 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
546 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
547 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
548 {N_("/_Edit/_Delete thread"), NULL, delete_thread_cb, 0, NULL},
549 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
550 {N_("/_Edit/_Find in current message..."),
551 "<control>F", search_cb, 0, NULL},
552 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
553 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
554 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
555 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
556 {N_("/_View/Show or hi_de/_Message view"),
557 "V", toggle_message_cb, 0, "<ToggleItem>"},
558 {N_("/_View/Show or hi_de/_Toolbar"),
559 NULL, NULL, 0, "<Branch>"},
560 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
561 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
562 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
563 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
564 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
565 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
566 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
567 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
568 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
569 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
571 {N_("/_View/Show or hi_de/Status _bar"),
572 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
574 {N_("/_View/Show or hi_de/Column headers"),
575 NULL, toggle_col_headers_cb, 0, "<ToggleItem>"},
576 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
577 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
578 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
580 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
582 {N_("/_View/La_yout"), NULL, NULL, 0, "<Branch>"},
583 {N_("/_View/Layout/_Standard"), NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
584 {N_("/_View/Layout/_Three columns"), NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
585 {N_("/_View/Layout/_Wide message"), NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
586 {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
587 {N_("/_View/Layout/S_mall screen"), NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
588 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
590 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
591 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
592 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
593 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
594 {N_("/_View/_Sort/by Thread date"), NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
595 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
596 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
597 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
598 {N_("/_View/_Sort/by _color label"), NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
599 {N_("/_View/_Sort/by tag"), NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
600 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
601 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
602 {N_("/_View/_Sort/by a_ttachment"),
603 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
604 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
605 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
606 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
607 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
608 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
609 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
610 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_View/_Sort/_Attract by subject"),
612 NULL, attract_by_subject_cb, 0, NULL},
613 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
614 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
615 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
616 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
618 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
620 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
621 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
622 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_View/_Go to/P_revious unread message"),
624 "<shift>P", prev_unread_cb, 0, NULL},
625 {N_("/_View/_Go to/N_ext unread message"),
626 "<shift>N", next_unread_cb, 0, NULL},
627 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
629 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
630 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_View/_Go to/Previous _marked message"),
632 NULL, prev_marked_cb, 0, NULL},
633 {N_("/_View/_Go to/Next m_arked message"),
634 NULL, next_marked_cb, 0, NULL},
635 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_View/_Go to/Previous _labeled message"),
637 NULL, prev_labeled_cb, 0, NULL},
638 {N_("/_View/_Go to/Next la_beled message"),
639 NULL, next_labeled_cb, 0, NULL},
640 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_View/_Go to/Last read message"),
642 NULL, last_read_cb, 0, NULL},
643 {N_("/_View/_Go to/Parent message"),
644 "<control>Up", parent_cb, 0, NULL},
645 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
647 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
648 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
650 #define ENC_SEPARATOR \
651 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
652 #define ENC_ACTION(action) \
653 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
655 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
656 {N_("/_View/Character _encoding/_Auto detect"),
657 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
658 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
660 ENC_ACTION(C_US_ASCII)},
661 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
662 ENC_ACTION(C_UTF_8)},
665 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
666 ENC_ACTION(C_ISO_8859_1)},
667 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
668 ENC_ACTION(C_ISO_8859_15)},
669 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
670 ENC_ACTION(C_WINDOWS_1252)},
673 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
674 ENC_ACTION(C_ISO_8859_2)},
677 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
678 ENC_ACTION(C_ISO_8859_13)},
679 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
680 ENC_ACTION(C_ISO_8859_4)},
683 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
684 ENC_ACTION(C_ISO_8859_7)},
687 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
688 ENC_ACTION(C_ISO_8859_8)},
689 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
690 ENC_ACTION(C_CP1255)},
693 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
694 ENC_ACTION(C_ISO_8859_6)},
695 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
696 ENC_ACTION(C_CP1256)},
699 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
700 ENC_ACTION(C_ISO_8859_9)},
703 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
704 ENC_ACTION(C_ISO_8859_5)},
705 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
706 ENC_ACTION(C_KOI8_R)},
707 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
708 ENC_ACTION(C_KOI8_U)},
709 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
710 ENC_ACTION(C_CP1251)},
713 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
714 ENC_ACTION(C_ISO_2022_JP)},
715 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
716 ENC_ACTION(C_ISO_2022_JP_2)},
717 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
718 ENC_ACTION(C_EUC_JP)},
719 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
720 ENC_ACTION(C_SHIFT_JIS)},
723 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
724 ENC_ACTION(C_GB2312)},
725 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
727 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
729 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
730 ENC_ACTION(C_EUC_TW)},
731 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
732 ENC_ACTION(C_ISO_2022_CN)},
735 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
736 ENC_ACTION(C_EUC_KR)},
737 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
738 ENC_ACTION(C_ISO_2022_KR)},
741 {N_("/_View/Character _encoding/Thai (TIS-620)"),
742 ENC_ACTION(C_TIS_620)},
743 {N_("/_View/Character _encoding/Thai (Windows-874)"),
744 ENC_ACTION(C_WINDOWS_874)},
749 #define DEC_SEPARATOR \
750 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
751 #define DEC_ACTION(action) \
752 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
753 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
754 {N_("/_View/Decode/_Auto detect"),
755 NULL, set_decode_cb, 0, "<RadioItem>"},
756 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
757 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
758 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
759 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
760 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
765 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
766 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
767 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
768 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
769 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
770 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
771 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
772 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
773 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
774 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
776 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
777 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
778 {N_("/_Message/Recei_ve/Get from _current account"),
779 "<control>I", inc_mail_cb, 0, NULL},
780 {N_("/_Message/Recei_ve/Get from _all accounts"),
781 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
782 {N_("/_Message/Recei_ve/Cancel receivin_g"),
783 NULL, inc_cancel_cb, 0, NULL},
784 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
785 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
786 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
787 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
788 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
789 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
790 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
791 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
792 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
793 {N_("/_Message/Repl_y to/mailing _list"),
794 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
795 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
796 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
797 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
798 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
799 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
801 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
802 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
803 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
804 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
805 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
806 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
807 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
809 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
810 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
811 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
812 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
813 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
814 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
815 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
816 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
817 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
818 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
819 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
820 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
821 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
822 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
823 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
824 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
825 {N_("/_Message/_Mark/Watch thread"), NULL, watch_thread_cb, 0, NULL},
826 {N_("/_Message/_Mark/Unwatch thread"), NULL, unwatch_thread_cb, 0, NULL},
827 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
828 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
829 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
830 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
831 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
832 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
833 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
834 {N_("/_Message/T_ags"), NULL, NULL, 0, NULL},
835 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
836 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
838 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
839 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
840 {N_("/_Tools/Add sender to address boo_k"),
841 NULL, add_address_cb, 0, NULL},
842 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
843 {N_("/_Tools/_Harvest addresses/from _Folder..."),
844 NULL, addr_harvest_cb, 0, NULL},
845 {N_("/_Tools/_Harvest addresses/from _Messages..."),
846 NULL, addr_harvest_msg_cb, 0, NULL},
847 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
848 {N_("/_Tools/_Filter all messages in folder"),
849 NULL, filter_cb, 0, NULL},
850 {N_("/_Tools/Filter _selected messages"),
851 NULL, filter_cb, 1, NULL},
852 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
853 {N_("/_Tools/_Create filter rule/_Automatically"),
854 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
855 {N_("/_Tools/_Create filter rule/by _From"),
856 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
857 {N_("/_Tools/_Create filter rule/by _To"),
858 NULL, create_filter_cb, FILTER_BY_TO, NULL},
859 {N_("/_Tools/_Create filter rule/by _Subject"),
860 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
861 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
862 {N_("/_Tools/C_reate processing rule/_Automatically"),
863 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
864 {N_("/_Tools/C_reate processing rule/by _From"),
865 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
866 {N_("/_Tools/C_reate processing rule/by _To"),
867 NULL, create_processing_cb, FILTER_BY_TO, NULL},
868 {N_("/_Tools/C_reate processing rule/by _Subject"),
869 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
870 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
871 {N_("/_Tools/List _URLs..."), "<shift><control>U", open_urls_cb, 0, NULL},
872 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
873 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
874 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
875 {N_("/_Tools/Ch_eck for new messages in all folders"),
876 NULL, update_folderview_cb, 0, NULL},
877 {N_("/_Tools/Delete du_plicated messages"),
878 NULL, NULL, 0, "<Branch>"},
879 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
880 NULL, delete_duplicated_cb, 0, NULL},
881 {N_("/_Tools/Delete du_plicated messages/In all folders"),
882 NULL, delete_duplicated_all_cb, 0, NULL},
883 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
884 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
886 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
887 {N_("/_Tools/SSL cer_tificates..."),
888 NULL, ssl_manager_open_cb, 0, NULL},
890 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
891 {N_("/_Tools/Filtering Log"), NULL, filtering_debug_window_show_cb, 0, NULL},
892 {N_("/_Tools/Network _Log"), "<shift><control>L", log_window_show_cb, 0, NULL},
894 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
895 {N_("/_Configuration/C_hange current account"),
896 NULL, NULL, 0, "<Branch>"},
897 {N_("/_Configuration/_Preferences for current account..."),
898 NULL, prefs_account_open_cb, 0, NULL},
899 {N_("/_Configuration/Create _new account..."),
900 NULL, new_account_cb, 0, NULL},
901 {N_("/_Configuration/_Edit accounts..."),
902 NULL, account_edit_open, 0, NULL},
903 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
904 {N_("/_Configuration/P_references..."),
905 NULL, prefs_open_cb, 0, NULL},
906 {N_("/_Configuration/Pre-pr_ocessing..."),
907 NULL, prefs_pre_processing_open_cb, 0, NULL},
908 {N_("/_Configuration/Post-pro_cessing..."),
909 NULL, prefs_post_processing_open_cb, 0, NULL},
910 {N_("/_Configuration/_Filtering..."),
911 NULL, prefs_filtering_open_cb, 0, NULL},
912 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
913 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
914 {N_("/_Configuration/Tag_s..."), NULL, prefs_tags_open_cb, 0, NULL},
915 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
916 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
918 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
919 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
920 {N_("/_Help/_Online User-contributed FAQ"),
921 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
922 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
923 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
924 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
927 static gboolean offline_ask_sync = TRUE;
928 static guint lastkey;
929 static gboolean is_obscured = FALSE;
931 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
937 MainWindow *mainwin = (MainWindow *)user_data;
939 if (mainwin->summaryview &&
940 mainwin->summaryview->quicksearch &&
941 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
942 (mod == 0 || mod == GDK_SHIFT_MASK)) {
943 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
949 #define N_COLOR_LABELS colorlabel_get_color_count()
951 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
956 GtkCheckMenuItem **items;
961 mainwin = (MainWindow *)data;
962 g_return_if_fail(mainwin != NULL);
964 sel = summary_get_selection(mainwin->summaryview);
967 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
968 g_return_if_fail(menu != NULL);
970 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
972 /* NOTE: don't return prematurely because we set the "dont_toggle"
973 * state for check menu items */
974 g_object_set_data(G_OBJECT(menu), "dont_toggle",
977 /* clear items. get item pointers. */
978 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
979 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
980 gtk_check_menu_item_set_active
981 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
982 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
987 if (n == (N_COLOR_LABELS + 1)) {
988 /* iterate all messages and set the state of the appropriate
990 for (; sel != NULL; sel = sel->next) {
994 msginfo = (MsgInfo *)sel->data;
996 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
997 if (!items[clabel]->active)
998 gtk_check_menu_item_set_active
999 (items[clabel], TRUE);
1003 g_warning("invalid number of color elements (%d)\n", n);
1006 /* reset "dont_toggle" state */
1007 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1008 GINT_TO_POINTER(0));
1011 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
1014 guint color = GPOINTER_TO_UINT(data);
1015 MainWindow *mainwin;
1017 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1018 g_return_if_fail(mainwin != NULL);
1020 /* "dont_toggle" state set? */
1021 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
1025 summary_set_colorlabel(mainwin->summaryview, color, NULL);
1028 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
1031 MainWindow *mainwin;
1035 GHashTable *menu_table = g_hash_table_new_full(
1039 GHashTable *menu_allsel_table = g_hash_table_new_full(
1044 mainwin = (MainWindow *)data;
1045 g_return_if_fail(mainwin != NULL);
1047 sel = summary_get_selection(mainwin->summaryview);
1050 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1051 g_return_if_fail(menu != NULL);
1053 /* NOTE: don't return prematurely because we set the "dont_toggle"
1054 * state for check menu items */
1055 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1056 GINT_TO_POINTER(1));
1058 /* clear items. get item pointers. */
1059 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1060 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1061 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1063 gtk_check_menu_item_set_active
1064 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1066 g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1067 g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1071 /* iterate all messages and set the state of the appropriate
1074 for (; sel != NULL; sel = sel->next) {
1076 GSList *tags = NULL;
1078 GtkCheckMenuItem *item;
1079 msginfo = (MsgInfo *)sel->data;
1082 tags = msginfo->tags;
1086 for (; tags; tags = tags->next) {
1087 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1088 id = GPOINTER_TO_INT(tags->data);
1089 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1090 if (item && !item->active) {
1091 gtk_check_menu_item_set_active
1095 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1100 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1101 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1102 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1104 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1105 if (num_checked < sel_len && num_checked > 0)
1106 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1108 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1112 g_hash_table_destroy(menu_table);
1113 g_hash_table_destroy(menu_allsel_table);
1114 /* reset "dont_toggle" state */
1115 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1116 GINT_TO_POINTER(0));
1119 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1122 gint id = GPOINTER_TO_INT(data);
1123 gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1124 MainWindow *mainwin;
1126 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1127 g_return_if_fail(mainwin != NULL);
1129 /* "dont_toggle" state set? */
1130 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1136 summary_set_tag(mainwin->summaryview, id, NULL);
1139 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1141 GtkWidget *label_menuitem;
1146 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1147 "/Message/Color label");
1148 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1149 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1151 gtk_widget_show(label_menuitem);
1153 menu = gtk_menu_new();
1155 /* create sub items. for the menu item activation callback we pass the
1156 * index of label_colors[] as data parameter. for the None color we
1157 * pass an invalid (high) value. also we attach a data pointer so we
1158 * can always get back the Mainwindow pointer. */
1160 item = gtk_check_menu_item_new_with_label(_("None"));
1161 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1162 g_signal_connect(G_OBJECT(item), "activate",
1163 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1164 GUINT_TO_POINTER(0));
1165 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1166 gtk_widget_show(item);
1168 gtk_widget_add_accelerator(item, "activate",
1169 mainwin->menu_factory->accel_group,
1170 GDK_0, GDK_CONTROL_MASK,
1171 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1173 item = gtk_menu_item_new();
1174 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1175 gtk_widget_show(item);
1177 /* create pixmap/label menu items */
1178 for (i = 0; i < N_COLOR_LABELS; i++) {
1179 item = colorlabel_create_check_color_menu_item(
1180 i, refresh, MAINWIN_COLORMENU);
1181 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1182 g_signal_connect(G_OBJECT(item), "activate",
1183 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1184 GUINT_TO_POINTER(i + 1));
1185 g_object_set_data(G_OBJECT(item), "mainwin",
1187 gtk_widget_show(item);
1189 gtk_widget_add_accelerator(item, "activate",
1190 mainwin->menu_factory->accel_group,
1191 GDK_1+i, GDK_CONTROL_MASK,
1192 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1194 gtk_widget_show(menu);
1195 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1196 mainwin->colorlabel_menu = menu;
1199 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1202 MainWindow *mainwin;
1204 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1205 g_return_if_fail(mainwin != NULL);
1207 /* "dont_toggle" state set? */
1208 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1212 tag_apply_open(summary_get_selection(mainwin->summaryview));
1215 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1217 GtkWidget *label_menuitem;
1220 GSList *cur = tags_get_list();
1222 gboolean existing_tags = FALSE;
1224 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1226 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1227 G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1230 gtk_widget_show(label_menuitem);
1232 menu = gtk_menu_new();
1234 /* create tags menu items */
1235 for (; cur; cur = cur->next) {
1236 gint id = GPOINTER_TO_INT(cur->data);
1237 const gchar *tag = tags_get_tag(id);
1239 item = gtk_check_menu_item_new_with_label(tag);
1240 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1241 g_signal_connect(G_OBJECT(item), "activate",
1242 G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1243 GINT_TO_POINTER(id));
1244 g_object_set_data(G_OBJECT(item), "mainwin",
1246 g_object_set_data(G_OBJECT(item), "tag_id",
1247 GINT_TO_POINTER(id));
1248 gtk_widget_show(item);
1249 existing_tags = TRUE;
1251 if (existing_tags) {
1253 item = gtk_menu_item_new();
1254 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1255 gtk_widget_show(item);
1258 item = gtk_menu_item_new_with_label(_("Apply tags..."));
1259 gtk_widget_add_accelerator(item, "activate",
1260 mainwin->menu_factory->accel_group,
1261 GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
1262 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1263 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1264 g_signal_connect(G_OBJECT(item), "activate",
1265 G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1267 g_object_set_data(G_OBJECT(item), "mainwin",
1269 gtk_widget_show(item);
1272 gtk_widget_show(menu);
1273 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1274 mainwin->tags_menu = menu;
1277 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1278 MainWindow *mainwindow)
1280 if (evt && evt->button == 1) {
1281 log_window_show_error(mainwindow->logwin);
1282 gtk_widget_hide(mainwindow->warning_btn);
1287 static gboolean warning_visi_notify(GtkWidget *widget,
1288 GdkEventVisibility *event,
1289 MainWindow *mainwindow)
1291 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1295 static gboolean warning_leave_notify(GtkWidget *widget,
1296 GdkEventCrossing *event,
1297 MainWindow *mainwindow)
1299 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1303 static gboolean warning_enter_notify(GtkWidget *widget,
1304 GdkEventCrossing *event,
1305 MainWindow *mainwindow)
1307 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1311 void mainwindow_show_error(void)
1313 MainWindow *mainwin = mainwindow_get_mainwindow();
1314 gtk_widget_show(mainwin->warning_btn);
1317 void mainwindow_clear_error(MainWindow *mainwin)
1319 gtk_widget_hide(mainwin->warning_btn);
1322 MainWindow *main_window_create()
1324 MainWindow *mainwin;
1328 GtkWidget *handlebox;
1329 GtkWidget *vbox_body;
1331 GtkWidget *hbox_stat;
1332 GtkWidget *statusbar;
1333 GtkWidget *progressbar;
1334 GtkWidget *statuslabel;
1335 GtkWidget *ac_button;
1336 GtkWidget *ac_label;
1337 GtkWidget *online_pixmap;
1338 GtkWidget *offline_pixmap;
1340 GtkWidget *warning_icon;
1341 GtkWidget *warning_btn;
1343 GtkWidget *online_switch;
1344 GtkWidget *offline_switch;
1345 FolderView *folderview;
1346 SummaryView *summaryview;
1347 MessageView *messageview;
1348 GdkColormap *colormap;
1350 gboolean success[4];
1351 GtkItemFactory *ifactory;
1353 GtkWidget *menuitem;
1355 guint n_menu_entries;
1357 static GdkGeometry geometry;
1359 debug_print("Creating main window...\n");
1360 mainwin = g_new0(MainWindow, 1);
1363 window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1364 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1365 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1367 prefs_common.layout_mode = SMALL_LAYOUT;
1369 if (!geometry.min_height) {
1370 geometry.min_width = 320;
1371 geometry.min_height = 200;
1373 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1376 g_signal_connect(G_OBJECT(window), "delete_event",
1377 G_CALLBACK(main_window_close_cb), mainwin);
1378 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1379 g_signal_connect(G_OBJECT(window), "focus_in_event",
1380 G_CALLBACK(mainwindow_focus_in_event),
1382 g_signal_connect(G_OBJECT(window), "key_press_event",
1383 G_CALLBACK(mainwindow_key_pressed), mainwin);
1385 gtk_widget_realize(window);
1386 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1389 gtkut_widget_set_app_icon(window);
1391 vbox = gtk_vbox_new(FALSE, 0);
1392 gtk_widget_show(vbox);
1393 gtk_container_add(GTK_CONTAINER(window), vbox);
1396 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1397 menubar = menubar_create(window, mainwin_entries,
1398 n_menu_entries, "<Main>", mainwin);
1399 gtk_widget_show(menubar);
1402 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1405 ifactory = gtk_item_factory_from_widget(menubar);
1407 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1408 main_create_mailing_list_menu (mainwin, NULL); */
1410 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1412 if (prefs_common.toolbar_detachable) {
1413 handlebox = gtk_handle_box_new();
1414 gtk_widget_show(handlebox);
1415 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1416 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1417 G_CALLBACK(toolbar_child_attached), mainwin);
1418 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1419 G_CALLBACK(toolbar_child_detached), mainwin);
1421 handlebox = gtk_hbox_new(FALSE, 0);
1422 gtk_widget_show(handlebox);
1423 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1425 /* link window to mainwin->window to avoid gdk warnings */
1426 mainwin->window = window;
1427 mainwin_list = g_list_append(mainwin_list, mainwin);
1430 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1434 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1438 toolbar_set_learn_button
1442 /* vbox that contains body */
1443 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1444 gtk_widget_show(vbox_body);
1445 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1446 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1449 hbox_stat = gtk_hbox_new(FALSE, 2);
1450 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1452 tips = gtk_tooltips_new();
1454 warning_icon = gtk_image_new_from_stock
1455 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1456 warning_btn = gtk_event_box_new();
1457 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1459 mainwin->warning_btn = warning_btn;
1461 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1462 G_CALLBACK(warning_icon_pressed),
1463 (gpointer) mainwin);
1464 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1465 G_CALLBACK(warning_visi_notify), mainwin);
1466 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1467 G_CALLBACK(warning_visi_notify), mainwin);
1468 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1469 G_CALLBACK(warning_leave_notify), mainwin);
1470 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1471 G_CALLBACK(warning_enter_notify), mainwin);
1473 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1475 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1476 _("Some error(s) happened. Click here to view log."), NULL);
1477 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1479 statusbar = statusbar_create();
1480 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1482 progressbar = gtk_progress_bar_new();
1483 gtk_widget_set_size_request(progressbar, 120, 1);
1484 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1486 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1487 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1488 online_switch = gtk_button_new ();
1489 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1490 _("You are online. Click the icon to go offline"), NULL);
1491 offline_switch = gtk_button_new ();
1492 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1493 _("You are offline. Click the icon to go online"),
1495 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1496 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1497 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1498 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1499 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1500 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1501 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1502 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1504 statuslabel = gtk_label_new("");
1505 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1507 ac_button = gtk_button_new();
1508 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1509 ac_button, _("Select account"), NULL);
1510 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1511 gtk_widget_set_size_request(ac_button, -1, 0);
1512 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1513 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1514 G_CALLBACK(ac_label_button_pressed), mainwin);
1516 ac_label = gtk_label_new("");
1517 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1519 gtk_widget_show_all(hbox_stat);
1521 gtk_widget_hide(offline_switch);
1522 gtk_widget_hide(warning_btn);
1524 online_switch = gtk_button_new ();
1525 offline_switch = gtk_button_new ();
1526 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1527 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1530 mainwin->folderview = folderview = folderview_create();
1531 mainwin->summaryview = summaryview = summary_create();
1532 mainwin->messageview = messageview = messageview_create(mainwin);
1534 /* init log instances data before creating log views */
1535 set_log_title(LOG_PROTOCOL, _("Network log"));
1536 set_log_prefs(LOG_PROTOCOL,
1537 &prefs_common.logwin_width,
1538 &prefs_common.logwin_height);
1539 set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1540 set_log_prefs(LOG_DEBUG_FILTERING,
1541 &prefs_common.filtering_debugwin_width,
1542 &prefs_common.filtering_debugwin_height);
1544 /* setup log windows */
1545 mainwin->logwin = log_window_create(LOG_PROTOCOL);
1546 log_window_init(mainwin->logwin);
1548 mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1549 log_window_set_clipping(mainwin->logwin,
1550 prefs_common.cliplog,
1551 prefs_common.loglength);
1553 log_window_init(mainwin->filtering_debugwin);
1554 log_window_set_clipping(mainwin->filtering_debugwin,
1555 prefs_common.filtering_debug_cliplog,
1556 prefs_common.filtering_debug_loglength);
1557 if (prefs_common.enable_filtering_debug)
1558 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1560 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1562 folderview->mainwin = mainwin;
1563 folderview->summaryview = summaryview;
1565 summaryview->mainwin = mainwin;
1566 summaryview->folderview = folderview;
1567 summaryview->messageview = messageview;
1568 summaryview->window = window;
1570 mainwin->vbox = vbox;
1571 mainwin->menubar = menubar;
1572 mainwin->menu_factory = ifactory;
1573 mainwin->handlebox = handlebox;
1574 mainwin->vbox_body = vbox_body;
1575 mainwin->online_switch = online_switch;
1576 mainwin->offline_switch = offline_switch;
1578 messageview->statusbar = statusbar;
1579 mainwin->statusbar = statusbar;
1580 mainwin->hbox_stat = hbox_stat;
1581 mainwin->progressbar = progressbar;
1582 mainwin->statuslabel = statuslabel;
1583 mainwin->online_pixmap = online_pixmap;
1584 mainwin->offline_pixmap = offline_pixmap;
1585 mainwin->ac_button = ac_button;
1586 mainwin->ac_label = ac_label;
1587 /* set context IDs for status bar */
1588 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1589 (GTK_STATUSBAR(statusbar), "Main Window");
1590 mainwin->folderview_cid = gtk_statusbar_get_context_id
1591 (GTK_STATUSBAR(statusbar), "Folder View");
1592 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1593 (GTK_STATUSBAR(statusbar), "Summary View");
1594 mainwin->messageview_cid = gtk_statusbar_get_context_id
1595 (GTK_STATUSBAR(statusbar), "Message View");
1596 messageview->statusbar_cid = mainwin->messageview_cid;
1599 messageview->statusbar = NULL;
1600 mainwin->statusbar = NULL;
1601 mainwin->hbox_stat = NULL;
1602 /* mainwin->progressbar is set in toolbar.c */
1603 mainwin->statuslabel = NULL;
1604 mainwin->online_pixmap = NULL;
1605 mainwin->offline_pixmap = NULL;
1606 mainwin->ac_button = NULL;
1607 mainwin->ac_label = NULL;
1610 /* allocate colors for summary view and folder view */
1611 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1612 summaryview->color_marked.blue = (guint16)65535;
1614 summaryview->color_dim.red = summaryview->color_dim.green =
1615 summaryview->color_dim.blue = COLOR_DIM;
1617 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1618 &folderview->color_new);
1620 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1621 &folderview->color_op);
1623 summaryview->color_important.red = 0;
1624 summaryview->color_important.green = 0;
1625 summaryview->color_important.blue = (guint16)65535;
1627 color[0] = summaryview->color_marked;
1628 color[1] = summaryview->color_dim;
1629 color[2] = folderview->color_new;
1630 color[3] = folderview->color_op;
1632 colormap = gdk_drawable_get_colormap(window->window);
1633 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1634 for (i = 0; i < 4; i++) {
1635 if (success[i] == FALSE)
1636 g_warning("MainWindow: color allocation %d failed\n", i);
1639 debug_print("done.\n");
1641 messageview->visible = prefs_common.msgview_visible;
1643 main_window_set_widgets(mainwin, prefs_common.layout_mode);
1645 g_signal_connect(G_OBJECT(window), "size_allocate",
1646 G_CALLBACK(main_window_size_allocate_cb),
1649 /* set menu items */
1650 menuitem = gtk_item_factory_get_item
1651 (ifactory, "/View/Character encoding/Auto detect");
1652 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1654 switch (prefs_common.toolbar_style) {
1656 menuitem = gtk_item_factory_get_item
1657 (ifactory, "/View/Show or hide/Toolbar/Hide");
1660 menuitem = gtk_item_factory_get_item
1661 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1664 menuitem = gtk_item_factory_get_item
1665 (ifactory, "/View/Show or hide/Toolbar/Text only");
1668 menuitem = gtk_item_factory_get_item
1669 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1671 case TOOLBAR_BOTH_HORIZ:
1672 menuitem = gtk_item_factory_get_item
1674 "/View/Show or hide/Toolbar/Text beside icons");
1676 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1679 gtk_widget_hide(mainwin->hbox_stat);
1680 menuitem = gtk_item_factory_get_item
1681 (ifactory, "/View/Show or hide/Status bar");
1682 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1683 prefs_common.show_statusbar);
1685 menuitem = gtk_item_factory_get_item
1686 (ifactory, "/View/Show or hide/Column headers");
1687 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1688 prefs_common.show_col_headers);
1689 /* set account selection menu */
1690 ac_menu = gtk_item_factory_get_widget
1691 (ifactory, "/Configuration/Change current account");
1692 mainwin->ac_menu = ac_menu;
1694 toolbar_main_set_sensitive(mainwin);
1696 /* create actions menu */
1697 main_window_update_actions_menu(mainwin);
1699 main_create_mailing_list_menu (mainwin, NULL);
1701 /* attach accel groups to main window */
1702 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1703 gtk_window_add_accel_group \
1705 gtk_item_factory_from_widget(menu)->accel_group); \
1706 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1708 G_CALLBACK(main_window_accel_activate), mainwin);
1711 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1713 /* connect the accelerators for equivalent
1714 menu items in different menus */
1715 menu_connect_identical_items();
1718 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1721 g_signal_connect(G_OBJECT(window), "window_state_event",
1722 G_CALLBACK(mainwindow_state_event_cb), mainwin);
1723 g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1724 G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1725 gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1727 if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1728 prefs_common.layout_mode == SMALL_LAYOUT) {
1729 summary_relayout(mainwin->summaryview);
1731 summary_update_unread(mainwin->summaryview, NULL);
1733 gtk_widget_show(mainwin->window);
1735 /* initialize views */
1736 folderview_init(folderview);
1737 summary_init(summaryview);
1738 messageview_init(messageview);
1740 sslcertwindow_register_hook();
1742 mainwin->lock_count = 0;
1743 mainwin->menu_lock_count = 0;
1744 mainwin->cursor_count = 0;
1746 mainwin->progressindicator_hook =
1747 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1750 watch_cursor = gdk_cursor_new(GDK_WATCH);
1752 hand_cursor = gdk_cursor_new(GDK_HAND2);
1754 /* init work_offline */
1755 if (prefs_common.work_offline)
1756 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1758 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1759 mainwindow_tags_menu_create(mainwin, FALSE);
1764 void main_window_destroy(MainWindow *mainwin)
1766 /* TODO : destroy other component */
1767 messageview_destroy(mainwin->messageview);
1768 mainwin->messageview = NULL;
1771 void main_window_update_actions_menu(MainWindow *mainwin)
1773 GtkItemFactory *ifactory;
1775 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1776 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1779 void main_window_cursor_wait(MainWindow *mainwin)
1782 if (mainwin->cursor_count == 0) {
1783 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1784 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1787 mainwin->cursor_count++;
1792 void main_window_cursor_normal(MainWindow *mainwin)
1794 if (mainwin->cursor_count)
1795 mainwin->cursor_count--;
1797 if (mainwin->cursor_count == 0) {
1798 gdk_window_set_cursor(mainwin->window->window, NULL);
1799 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1804 /* lock / unlock the user-interface */
1805 void main_window_lock(MainWindow *mainwin)
1807 if (mainwin->lock_count == 0 && mainwin->ac_button)
1808 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1810 mainwin->lock_count++;
1812 main_window_set_menu_sensitive(mainwin);
1813 toolbar_main_set_sensitive(mainwin);
1816 void main_window_unlock(MainWindow *mainwin)
1818 if (mainwin->lock_count)
1819 mainwin->lock_count--;
1821 main_window_set_menu_sensitive(mainwin);
1822 toolbar_main_set_sensitive(mainwin);
1824 if (mainwin->lock_count == 0 && mainwin->ac_button)
1825 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1828 static void main_window_menu_callback_block(MainWindow *mainwin)
1830 mainwin->menu_lock_count++;
1833 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1835 if (mainwin->menu_lock_count)
1836 mainwin->menu_lock_count--;
1839 static guint prefs_tag = 0;
1841 void main_window_reflect_prefs_all(void)
1843 main_window_reflect_prefs_all_real(FALSE);
1846 static gboolean reflect_prefs_timeout_cb(gpointer data)
1848 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1850 MainWindow *mainwin;
1853 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1854 mainwin = (MainWindow *)cur->data;
1856 main_window_show_cur_account(mainwin);
1857 main_window_set_menu_sensitive(mainwin);
1858 toolbar_main_set_sensitive(mainwin);
1861 if (pixmap_theme_changed) {
1862 toolbar_update(TOOLBAR_MAIN, mainwin);
1863 messageview_reflect_prefs_pixmap_theme();
1864 compose_reflect_prefs_pixmap_theme();
1865 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1866 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1868 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1869 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1870 mainwin->online_pixmap);
1871 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1872 gtk_widget_show(pixmap);
1873 mainwin->online_pixmap = pixmap;
1874 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1875 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1876 mainwin->offline_pixmap);
1877 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1878 gtk_widget_show(pixmap);
1879 mainwin->offline_pixmap = pixmap;
1883 headerview_set_font(mainwin->messageview->headerview);
1884 headerview_set_visibility(mainwin->messageview->headerview,
1885 prefs_common.display_header_pane);
1886 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1887 folderview_reflect_prefs();
1888 summary_reflect_prefs();
1890 summary_redisplay_msg(mainwin->summaryview);
1892 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1893 if (mainwin->in_folder) {
1894 mainwindow_enter_folder(mainwin);
1896 mainwindow_exit_folder(mainwin);
1904 void main_window_reflect_prefs_all_now(void)
1906 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1909 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1914 /* re-create colorlabel submenu */
1915 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1916 g_return_if_fail(menu != NULL);
1918 /* clear items. get item pointers. */
1919 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1920 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1922 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1923 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1927 void main_window_reflect_tags_changes(MainWindow *mainwin)
1932 /* re-create tags submenu */
1933 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1934 g_return_if_fail(menu != NULL);
1936 /* clear items. get item pointers. */
1937 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1938 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1940 mainwindow_tags_menu_create(mainwin, TRUE);
1941 summary_reflect_tags_changes(mainwin->summaryview);
1945 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1947 if (prefs_tag == 0 || pixmap_theme_changed) {
1948 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1949 GINT_TO_POINTER(pixmap_theme_changed));
1953 void main_window_set_summary_column(void)
1956 MainWindow *mainwin;
1958 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1959 mainwin = (MainWindow *)cur->data;
1960 summary_set_column_order(mainwin->summaryview);
1964 void main_window_set_folder_column(void)
1967 MainWindow *mainwin;
1969 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1970 mainwin = (MainWindow *)cur->data;
1971 folderview_set_column_order(mainwin->folderview);
1975 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1976 GList *account_list)
1978 GList *cur_ac, *cur_item;
1979 GtkWidget *menuitem;
1980 PrefsAccount *ac_prefs;
1982 /* destroy all previous menu item */
1983 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1984 while (cur_item != NULL) {
1985 GList *next = cur_item->next;
1986 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1990 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1991 ac_prefs = (PrefsAccount *)cur_ac->data;
1993 menuitem = gtk_menu_item_new_with_label
1994 (ac_prefs->account_name
1995 ? ac_prefs->account_name : _("Untitled"));
1996 gtk_widget_show(menuitem);
1997 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1998 g_signal_connect(G_OBJECT(menuitem), "activate",
1999 G_CALLBACK(account_selector_menu_cb),
2004 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2005 GList *account_list)
2007 GList *cur_ac, *cur_item;
2009 GtkWidget *menuitem;
2010 PrefsAccount *ac_prefs;
2012 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
2013 "/Message/Receive");
2015 /* search for separator */
2016 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2017 cur_item = cur_item->next) {
2018 if (GTK_BIN(cur_item->data)->child == NULL) {
2019 cur_item = cur_item->next;
2024 /* destroy all previous menu item */
2025 while (cur_item != NULL) {
2026 GList *next = cur_item->next;
2027 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2031 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2032 ac_prefs = (PrefsAccount *)cur_ac->data;
2034 menuitem = gtk_menu_item_new_with_label
2035 (ac_prefs->account_name ? ac_prefs->account_name
2037 gtk_widget_show(menuitem);
2038 gtk_menu_append(GTK_MENU(menu), menuitem);
2039 g_signal_connect(G_OBJECT(menuitem), "activate",
2040 G_CALLBACK(account_receive_menu_cb),
2045 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2046 GList *account_list)
2049 GtkWidget *menuitem;
2050 PrefsAccount *ac_prefs;
2051 GtkWidget *menu = NULL;
2053 if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2056 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2058 gtk_widget_destroy(menu);
2059 menu = gtk_menu_new();
2061 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2062 ac_prefs = (PrefsAccount *)cur_ac->data;
2064 menuitem = gtk_menu_item_new_with_label
2065 (ac_prefs->account_name
2066 ? ac_prefs->account_name : _("Untitled"));
2067 gtk_widget_show(menuitem);
2068 gtk_menu_append(GTK_MENU(menu), menuitem);
2069 g_signal_connect(G_OBJECT(menuitem), "activate",
2070 G_CALLBACK(account_receive_menu_cb),
2073 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2076 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2077 GList *account_list)
2081 GtkWidget *menuitem;
2082 PrefsAccount *ac_prefs;
2083 GtkWidget *menu = NULL;
2085 if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2088 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2090 gtk_widget_destroy(menu);
2091 menu = gtk_menu_new();
2093 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2094 ac_prefs = (PrefsAccount *)cur_ac->data;
2096 menuitem = gtk_menu_item_new_with_label
2097 (ac_prefs->account_name
2098 ? ac_prefs->account_name : _("Untitled"));
2099 gtk_widget_show(menuitem);
2100 gtk_menu_append(GTK_MENU(menu), menuitem);
2101 g_signal_connect(G_OBJECT(menuitem), "activate",
2102 G_CALLBACK(account_compose_menu_cb),
2105 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2109 void main_window_set_account_menu(GList *account_list)
2112 MainWindow *mainwin;
2114 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2115 mainwin = (MainWindow *)cur->data;
2116 main_window_set_account_selector_menu(mainwin, account_list);
2117 main_window_set_account_receive_menu(mainwin, account_list);
2118 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2119 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2121 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2124 void main_window_set_account_menu_only_toolbar(GList *account_list)
2127 MainWindow *mainwin;
2129 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2130 mainwin = (MainWindow *)cur->data;
2131 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2132 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2136 static void main_window_show_cur_account(MainWindow *mainwin)
2141 ac_name = g_strdup(cur_account
2142 ? (cur_account->account_name
2143 ? cur_account->account_name : _("Untitled"))
2147 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2149 buf = g_strdup(PROG_VERSION);
2150 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2153 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2154 if (mainwin->ac_button)
2155 gtk_widget_queue_resize(mainwin->ac_button);
2160 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2162 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
2163 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2164 GtkWidget *message_wid = mainwin->messageview->vbox;
2166 if (layout_mode == prefs_common.layout_mode)
2169 debug_print("Changing window separation type from %d to %d\n",
2170 prefs_common.layout_mode, layout_mode);
2172 /* remove widgets from those containers */
2173 gtk_widget_ref(folder_wid);
2174 gtk_widget_ref(summary_wid);
2175 gtk_widget_ref(message_wid);
2176 gtkut_container_remove
2177 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2178 gtkut_container_remove
2179 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2180 gtkut_container_remove
2181 (GTK_CONTAINER(message_wid->parent), message_wid);
2183 gtk_widget_hide(mainwin->window);
2184 main_window_set_widgets(mainwin, layout_mode);
2185 gtk_widget_show(mainwin->window);
2187 gtk_widget_unref(folder_wid);
2188 gtk_widget_unref(summary_wid);
2189 gtk_widget_unref(message_wid);
2192 void mainwindow_reset_paned(GtkPaned *paned)
2196 if (gtk_paned_get_child1(GTK_PANED(paned)))
2197 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2198 if (gtk_paned_get_child2(GTK_PANED(paned)))
2199 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2202 g_object_get (G_OBJECT(paned),
2205 g_object_get (G_OBJECT(paned),
2209 gtk_paned_set_position(GTK_PANED(paned), mid);
2212 static void mainwin_paned_show_first(GtkPaned *paned)
2215 g_object_get (G_OBJECT(paned),
2219 if (gtk_paned_get_child1(GTK_PANED(paned)))
2220 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2221 if (gtk_paned_get_child2(GTK_PANED(paned)))
2222 gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2223 gtk_paned_set_position(GTK_PANED(paned), max);
2226 static void mainwin_paned_show_last(GtkPaned *paned)
2229 g_object_get (G_OBJECT(paned),
2233 if (gtk_paned_get_child1(GTK_PANED(paned)))
2234 gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2235 if (gtk_paned_get_child2(GTK_PANED(paned)))
2236 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2237 gtk_paned_set_position(GTK_PANED(paned), min);
2240 void main_window_toggle_message_view(MainWindow *mainwin)
2242 SummaryView *summaryview = mainwin->summaryview;
2243 GtkWidget *ppaned = NULL;
2244 GtkWidget *container = NULL;
2246 switch (prefs_common.layout_mode) {
2248 case VERTICAL_LAYOUT:
2250 ppaned = mainwin->vpaned;
2251 container = mainwin->hpaned;
2252 if (ppaned->parent != NULL) {
2253 mainwin->messageview->visible = FALSE;
2254 summaryview->displayed = NULL;
2255 gtk_widget_ref(ppaned);
2256 gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2257 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2259 mainwin->messageview->visible = TRUE;
2260 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2261 gtk_container_add(GTK_CONTAINER(container), ppaned);
2262 gtk_widget_unref(ppaned);
2266 ppaned = mainwin->hpaned;
2267 container = mainwin->vpaned;
2268 if (mainwin->messageview->vbox->parent != NULL) {
2269 mainwin->messageview->visible = FALSE;
2270 summaryview->displayed = NULL;
2271 gtk_widget_ref(mainwin->messageview->vbox);
2272 gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2274 mainwin->messageview->visible = TRUE;
2275 gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2276 gtk_widget_unref(mainwin->messageview->vbox);
2279 case WIDE_MSGLIST_LAYOUT:
2280 g_warning("can't hide messageview in this wide msglist layout");
2284 if (messageview_is_visible(mainwin->messageview))
2285 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2286 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2288 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2289 GTK_ARROW_UP, GTK_SHADOW_OUT);
2291 if (mainwin->messageview->visible == FALSE)
2292 messageview_clear(mainwin->messageview);
2294 main_window_set_menu_sensitive(mainwin);
2296 prefs_common.msgview_visible = mainwin->messageview->visible;
2298 if (messageview_is_visible(mainwin->messageview)) {
2299 gtk_widget_queue_resize(mainwin->hpaned);
2300 gtk_widget_queue_resize(mainwin->vpaned);
2302 summary_grab_focus(summaryview);
2305 void main_window_get_size(MainWindow *mainwin)
2307 GtkAllocation *allocation;
2309 if (mainwin_list == NULL || mainwin->messageview == NULL) {
2310 debug_print("called after messageview "
2311 "has been deallocated!\n");
2315 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2317 if (allocation->width > 1 && allocation->height > 1) {
2318 prefs_common.summaryview_width = allocation->width;
2320 if (messageview_is_visible(mainwin->messageview))
2321 prefs_common.summaryview_height = allocation->height;
2323 prefs_common.mainview_width = allocation->width;
2326 allocation = &mainwin->window->allocation;
2327 if (allocation->width > 1 && allocation->height > 1) {
2328 prefs_common.mainview_height = allocation->height;
2329 prefs_common.mainwin_width = allocation->width;
2330 prefs_common.mainwin_height = allocation->height;
2333 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2334 if (allocation->width > 1 && allocation->height > 1) {
2335 prefs_common.folderview_width = allocation->width;
2336 prefs_common.folderview_height = allocation->height;
2339 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2340 if (allocation->width > 1 && allocation->height > 1) {
2341 prefs_common.msgview_width = allocation->width;
2342 prefs_common.msgview_height = allocation->height;
2345 /* debug_print("summaryview size: %d x %d\n",
2346 prefs_common.summaryview_width,
2347 prefs_common.summaryview_height);
2348 debug_print("folderview size: %d x %d\n",
2349 prefs_common.folderview_width,
2350 prefs_common.folderview_height);
2351 debug_print("messageview size: %d x %d\n",
2352 prefs_common.msgview_width,
2353 prefs_common.msgview_height); */
2356 void main_window_get_position(MainWindow *mainwin)
2360 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2362 prefs_common.mainview_x = x;
2363 prefs_common.mainview_y = y;
2364 prefs_common.mainwin_x = x;
2365 prefs_common.mainwin_y = y;
2367 debug_print("main window position: %d, %d\n", x, y);
2370 void main_window_progress_on(MainWindow *mainwin)
2372 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2375 void main_window_progress_off(MainWindow *mainwin)
2377 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2378 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2381 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2385 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2386 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2387 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2388 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2391 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2393 if (confirm && procmsg_have_trashed_mails_fast()) {
2394 if (alertpanel(_("Empty trash"),
2395 _("Delete all messages in trash folders?"),
2396 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2397 != G_ALERTALTERNATE)
2399 manage_window_focus_in(mainwin->window, NULL, NULL);
2402 procmsg_empty_all_trash();
2404 if (mainwin->summaryview->folder_item &&
2405 mainwin->summaryview->folder_item->stype == F_TRASH)
2406 gtk_widget_grab_focus(mainwin->folderview->ctree);
2409 void main_window_add_mailbox(MainWindow *mainwin)
2414 path = input_dialog(_("Add mailbox"),
2415 _("Input the location of mailbox.\n"
2416 "If an existing mailbox is specified, it will be\n"
2417 "scanned automatically."),
2420 if (folder_find_from_path(path)) {
2421 alertpanel_error(_("The mailbox '%s' already exists."), path);
2425 folder = folder_new(folder_get_class_from_string("mh"),
2426 !strcmp(path, "Mail") ? _("Mailbox") :
2427 g_path_get_basename(path), path);
2430 if (folder->klass->create_tree(folder) < 0) {
2431 alertpanel_error(_("Creation of the mailbox failed.\n"
2432 "Maybe some files already exist, or you don't have the permission to write there."));
2433 folder_destroy(folder);
2438 folder_set_ui_func(folder, scan_tree_func, mainwin);
2439 folder_scan_tree(folder, TRUE);
2440 folder_set_ui_func(folder, NULL, NULL);
2443 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2445 SensitiveCond state = 0;
2446 SummarySelection selection;
2447 FolderItem *item = mainwin->summaryview->folder_item;
2448 GList *account_list = account_get_list();
2451 selection = summary_get_selection_type(mainwin->summaryview);
2453 if (mainwin->lock_count == 0)
2454 state |= M_UNLOCKED;
2455 if (selection != SUMMARY_NONE)
2456 state |= M_MSG_EXIST;
2457 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2459 /* if (item->folder->type != F_NEWS) */
2460 state |= M_ALLOW_DELETE;
2462 if (prefs_common.immediate_exec == 0
2463 && mainwin->lock_count == 0)
2464 state |= M_DELAY_EXEC;
2466 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2467 || selection != SUMMARY_NONE)
2468 state |= M_HIDE_READ_MSG;
2470 if (mainwin->summaryview->threaded)
2471 state |= M_THREADED;
2473 state |= M_UNTHREADED;
2474 if (selection == SUMMARY_SELECTED_SINGLE ||
2475 selection == SUMMARY_SELECTED_MULTIPLE)
2476 state |= M_TARGET_EXIST;
2477 if (selection == SUMMARY_SELECTED_SINGLE)
2478 state |= M_SINGLE_TARGET_EXIST;
2479 if (mainwin->summaryview->folder_item &&
2480 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2483 state |= M_NOT_NEWS;
2484 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2485 state |= M_ACTIONS_EXIST;
2487 tmp = tags_get_list();
2488 if (tmp && g_slist_length(tmp))
2489 state |= M_TAGS_EXIST;
2492 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2493 state |= M_HAVE_QUEUED_MAILS;
2495 if (selection == SUMMARY_SELECTED_SINGLE &&
2497 (folder_has_parent_of_type(item, F_DRAFT) ||
2498 folder_has_parent_of_type(item, F_OUTBOX) ||
2499 folder_has_parent_of_type(item, F_QUEUE))))
2500 state |= M_ALLOW_REEDIT;
2502 state |= M_HAVE_ACCOUNT;
2504 if (any_folder_want_synchronise())
2505 state |= M_WANT_SYNC;
2507 for ( ; account_list != NULL; account_list = account_list->next) {
2508 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2509 state |= M_HAVE_NEWS_ACCOUNT;
2514 if (procmsg_spam_can_learn() &&
2515 (mainwin->summaryview->folder_item &&
2516 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2517 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2518 state |= M_CAN_LEARN_SPAM;
2521 if (inc_is_active())
2522 state |= M_INC_ACTIVE;
2523 if (imap_cancel_all_enabled())
2524 state |= M_INC_ACTIVE;
2526 if (mainwin->summaryview->deleted > 0 ||
2527 mainwin->summaryview->moved > 0 ||
2528 mainwin->summaryview->copied > 0)
2529 state |= M_DELAY_EXEC;
2536 void main_window_set_menu_sensitive(MainWindow *mainwin)
2538 GtkItemFactory *ifactory = mainwin->menu_factory;
2539 SensitiveCond state;
2542 GtkWidget *menuitem;
2543 SummaryView *summaryview;
2548 static const struct {
2552 {"/File/Save as...", M_TARGET_EXIST},
2553 {"/File/Print..." , M_TARGET_EXIST},
2554 {"/File/Synchronise folders", M_WANT_SYNC},
2555 {"/File/Exit" , M_UNLOCKED},
2557 {"/Edit/Select thread" , M_TARGET_EXIST},
2558 {"/Edit/Delete thread" , M_TARGET_EXIST},
2559 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2561 {"/View/Set displayed columns/in Folder list..."
2563 {"/View/Sort" , M_EXEC},
2564 {"/View/Thread view" , M_EXEC},
2565 {"/View/Expand all threads" , M_MSG_EXIST},
2566 {"/View/Collapse all threads" , M_MSG_EXIST},
2567 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2568 {"/View/Go to/Previous message" , M_MSG_EXIST},
2569 {"/View/Go to/Next message" , M_MSG_EXIST},
2570 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2571 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2572 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2573 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2574 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2575 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2576 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2577 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2578 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2579 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2580 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2582 {"/Message/Receive/Get from current account"
2583 , M_HAVE_ACCOUNT|M_UNLOCKED},
2584 {"/Message/Receive/Get from all accounts"
2585 , M_HAVE_ACCOUNT|M_UNLOCKED},
2586 {"/Message/Receive/Cancel receiving"
2588 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2589 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2590 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2591 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2592 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2593 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2594 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2595 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2596 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2597 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2598 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2599 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2600 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2601 {"/Message/Mark" , M_TARGET_EXIST},
2602 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2603 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2604 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2605 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2606 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2607 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2608 {"/Message/Color label" , M_TARGET_EXIST},
2609 {"/Message/Tags" , M_TARGET_EXIST},
2610 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2612 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2613 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2614 {"/Tools/Harvest addresses/from Messages..."
2616 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2617 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2618 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2619 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2620 {"/Tools/List URLs..." , M_TARGET_EXIST},
2621 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2622 {"/Tools/Execute" , M_DELAY_EXEC},
2623 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2625 {"/Configuration", M_UNLOCKED},
2626 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2627 {"/Configuration/Create new account...", M_UNLOCKED},
2628 {"/Configuration/Edit accounts...", M_UNLOCKED},
2633 state = main_window_get_current_state(mainwin);
2635 for (i = 0; entry[i].entry != NULL; i++) {
2636 sensitive = ((entry[i].cond & state) == entry[i].cond);
2637 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2640 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2642 /* search for separator */
2643 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2644 cur_item = cur_item->next) {
2645 if (GTK_BIN(cur_item->data)->child == NULL) {
2646 cur_item = cur_item->next;
2651 for (; cur_item != NULL; cur_item = cur_item->next) {
2652 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2653 (M_UNLOCKED & state) != 0);
2656 main_window_menu_callback_block(mainwin);
2658 #define SET_CHECK_MENU_ACTIVE(path, active) \
2660 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2661 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2664 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2665 messageview_is_visible(mainwin->messageview));
2667 summaryview = mainwin->summaryview;
2668 menu_path = "/View/Sort/Don't sort";
2670 switch (summaryview->sort_key) {
2671 case SORT_BY_NUMBER:
2672 menu_path = "/View/Sort/by number"; break;
2674 menu_path = "/View/Sort/by Size"; break;
2676 menu_path = "/View/Sort/by Date"; break;
2677 case SORT_BY_THREAD_DATE:
2678 menu_path = "/View/Sort/by Thread date"; break;
2680 menu_path = "/View/Sort/by From"; break;
2682 menu_path = "/View/Sort/by To"; break;
2683 case SORT_BY_SUBJECT:
2684 menu_path = "/View/Sort/by Subject"; break;
2686 menu_path = "/View/Sort/by color label"; break;
2688 menu_path = "/View/Sort/by mark"; break;
2689 case SORT_BY_STATUS:
2690 menu_path = "/View/Sort/by status"; break;
2692 menu_path = "/View/Sort/by attachment"; break;
2694 menu_path = "/View/Sort/by score"; break;
2695 case SORT_BY_LOCKED:
2696 menu_path = "/View/Sort/by locked"; break;
2698 menu_path = "/View/Sort/by tag"; break;
2701 menu_path = "/View/Sort/Don't sort"; break;
2703 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2705 if (summaryview->sort_type == SORT_ASCENDING) {
2706 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2708 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2711 if (summaryview->sort_key != SORT_BY_NONE) {
2712 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2713 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2715 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2716 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2719 if (mainwin->messageview
2720 && mainwin->messageview->mimeview
2721 && mainwin->messageview->mimeview->textview)
2722 SET_CHECK_MENU_ACTIVE("/View/All headers",
2723 mainwin->messageview->mimeview->textview->show_all_headers);
2724 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2725 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2726 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2727 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2728 if (prefs_common.hide_quotes == 1)
2729 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2730 if (prefs_common.hide_quotes == 2)
2731 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2732 if (prefs_common.hide_quotes == 3)
2733 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2735 #undef SET_CHECK_MENU_ACTIVE
2737 main_window_menu_callback_unblock(mainwin);
2740 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2742 GtkItemFactory *ifactory;
2744 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2747 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2749 gtk_widget_set_sensitive (gtk_item_factory_get_item
2750 (ifactory,"/Message/Mailing-List"), TRUE);
2752 gtk_widget_set_sensitive (gtk_item_factory_get_item
2753 (ifactory,"/Message/Mailing-List"), FALSE);
2756 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2759 GtkWidget *menuitem;
2761 if (!msginfo || !msginfo->extradata) {
2762 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2763 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2764 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2765 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2766 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2767 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2771 /* Mailing list post */
2772 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2773 g_free(msginfo->extradata->list_post);
2774 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2776 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2778 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2780 /* Mailing list help */
2781 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2783 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2785 /* Mailing list subscribe */
2786 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2788 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2790 /* Mailing list unsubscribe */
2791 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2793 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2795 /* Mailing list view archive */
2796 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2798 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2800 /* Mailing list contact owner */
2801 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2803 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2808 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2810 GtkWidget *item, *menu;
2811 const gchar *url_pt ;
2812 gchar url_decoded[BUFFSIZE];
2813 GList *amenu, *alist;
2816 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2818 /* First delete old submenu */
2819 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2820 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2821 alist = amenu->next;
2822 item = GTK_WIDGET (amenu->data);
2823 gtk_widget_destroy (item);
2827 for (url_pt = list_header; url_pt && *url_pt;) {
2828 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2830 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2831 item = gtk_menu_item_new_with_label ((url_decoded));
2832 g_signal_connect(G_OBJECT(item), "activate",
2833 G_CALLBACK(mailing_list_compose),
2836 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2837 !g_strncasecmp (url_decoded, "https:",6)) {
2839 item = gtk_menu_item_new_with_label ((url_decoded));
2840 g_signal_connect(G_OBJECT(item), "activate",
2841 G_CALLBACK(mailing_list_open_uri),
2845 gtk_menu_append (GTK_MENU(menu), item);
2846 gtk_widget_show (item);
2852 gtk_widget_set_sensitive (menuitem, TRUE);
2854 gtk_widget_set_sensitive (menuitem, FALSE);
2860 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2862 gchar tmp[BUFFSIZE];
2866 gboolean with_plus = TRUE;
2869 *url_decoded = '\0';
2873 /* Ignore spaces, comments and tabs () */
2874 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2876 for (;*buf != ')' && *buf != 0x00; buf++);
2878 /* First non space and non comment must be a < */
2881 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2883 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2888 *url_decoded = '\0';
2893 *url_decoded = '\0';
2899 decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2901 /* Prepare the work for the next url in the list */
2902 /* after the closing bracket >, ignore space, comments and tabs */
2903 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2905 for (;*buf != ')' && *buf != 0x00; buf++);
2907 if (!buf || !*buf) {
2912 /* now first non space, non comment must be a comma */
2914 for (;*buf != 0x00; buf++);
2920 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2924 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2925 compose_new(NULL, mailto+7, NULL);
2928 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2933 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2934 open_uri (mailto, prefs_common.uri_cmd);
2937 void main_window_popup(MainWindow *mainwin)
2939 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2940 main_window_show(mainwin);
2942 gtkut_window_popup(mainwin->window);
2943 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2944 if (mainwin->in_folder) {
2945 mainwindow_enter_folder(mainwin);
2947 mainwindow_exit_folder(mainwin);
2952 void main_window_show(MainWindow *mainwin)
2954 gtk_widget_show(mainwin->window);
2955 gtk_widget_show(mainwin->vbox_body);
2957 gtk_widget_set_uposition(mainwin->window,
2958 prefs_common.mainwin_x,
2959 prefs_common.mainwin_y);
2961 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2962 prefs_common.folderview_width,
2963 prefs_common.folderview_height);
2964 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2965 prefs_common.summaryview_width,
2966 prefs_common.summaryview_height);
2967 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2968 prefs_common.msgview_width,
2969 prefs_common.msgview_height);
2972 void main_window_hide(MainWindow *mainwin)
2974 main_window_get_size(mainwin);
2975 main_window_get_position(mainwin);
2977 gtk_widget_hide(mainwin->window);
2978 gtk_widget_hide(mainwin->vbox_body);
2981 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2983 GtkWidget *folderwin = NULL;
2984 GtkWidget *messagewin = NULL;
2987 GtkWidget *vbox_body = mainwin->vbox_body;
2988 GtkItemFactory *ifactory = mainwin->menu_factory;
2989 GtkWidget *menuitem;
2990 gboolean first_set = (mainwin->hpaned == NULL);
2991 debug_print("Setting widgets... ");
2993 if (layout_mode == SMALL_LAYOUT && first_set) {
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),
2999 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3002 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3003 prefs_common.folderview_width,
3004 prefs_common.folderview_height);
3005 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3006 prefs_common.summaryview_width,
3007 prefs_common.summaryview_height);
3008 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3009 prefs_common.msgview_width,
3010 prefs_common.msgview_height);
3014 mainwin->messageview->statusbar = mainwin->statusbar;
3015 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3017 /* clean top-most container */
3018 if (mainwin->hpaned) {
3019 if (mainwin->hpaned->parent == mainwin->vpaned)
3020 gtk_widget_destroy(mainwin->vpaned);
3022 gtk_widget_destroy(mainwin->hpaned);
3025 menu_set_sensitive(ifactory, "/View/Show or hide/Message view",
3026 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3027 switch (layout_mode) {
3028 case VERTICAL_LAYOUT:
3031 hpaned = gtk_hpaned_new();
3032 if (layout_mode == VERTICAL_LAYOUT)
3033 vpaned = gtk_hpaned_new();
3035 vpaned = gtk_vpaned_new();
3036 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3037 gtk_paned_add1(GTK_PANED(hpaned),
3038 GTK_WIDGET_PTR(mainwin->folderview));
3039 gtk_widget_show(hpaned);
3040 gtk_widget_queue_resize(hpaned);
3042 if (messageview_is_visible(mainwin->messageview)) {
3043 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3044 gtk_paned_add1(GTK_PANED(vpaned),
3045 GTK_WIDGET_PTR(mainwin->summaryview));
3047 gtk_paned_add2(GTK_PANED(hpaned),
3048 GTK_WIDGET_PTR(mainwin->summaryview));
3049 gtk_widget_ref(vpaned);
3051 gtk_paned_add2(GTK_PANED(vpaned),
3052 GTK_WIDGET_PTR(mainwin->messageview));
3053 gtk_widget_show(vpaned);
3054 if (layout_mode == SMALL_LAYOUT && first_set) {
3055 mainwin_paned_show_first(GTK_PANED(hpaned));
3057 gtk_widget_queue_resize(vpaned);
3060 vpaned = gtk_vpaned_new();
3061 hpaned = gtk_hpaned_new();
3062 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3063 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3065 gtk_paned_add1(GTK_PANED(hpaned),
3066 GTK_WIDGET_PTR(mainwin->folderview));
3067 gtk_paned_add2(GTK_PANED(hpaned),
3068 GTK_WIDGET_PTR(mainwin->summaryview));
3070 gtk_widget_show(hpaned);
3071 gtk_widget_queue_resize(hpaned);
3073 if (messageview_is_visible(mainwin->messageview)) {
3074 gtk_paned_add2(GTK_PANED(vpaned),
3075 GTK_WIDGET_PTR(mainwin->messageview));
3077 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3079 gtk_widget_show(vpaned);
3080 gtk_widget_queue_resize(vpaned);
3082 case WIDE_MSGLIST_LAYOUT:
3083 vpaned = gtk_vpaned_new();
3084 hpaned = gtk_hpaned_new();
3085 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3087 gtk_paned_add1(GTK_PANED(vpaned),
3088 GTK_WIDGET_PTR(mainwin->summaryview));
3089 gtk_paned_add1(GTK_PANED(hpaned),
3090 GTK_WIDGET_PTR(mainwin->folderview));
3092 gtk_widget_show(hpaned);
3093 gtk_widget_queue_resize(hpaned);
3095 if (messageview_is_visible(mainwin->messageview)) {
3096 gtk_paned_add2(GTK_PANED(hpaned),
3097 GTK_WIDGET_PTR(mainwin->messageview));
3099 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3101 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3103 gtk_widget_show(vpaned);
3104 gtk_widget_queue_resize(vpaned);
3107 g_warning("Unknown layout");
3111 mainwin->hpaned = hpaned;
3112 mainwin->vpaned = vpaned;
3114 if (layout_mode == SMALL_LAYOUT) {
3115 if (mainwin->messageview->visible)
3116 main_window_toggle_message_view(mainwin);
3119 if (layout_mode == SMALL_LAYOUT && first_set) {
3120 gtk_widget_realize(mainwin->window);
3121 gtk_widget_realize(mainwin->folderview->ctree);
3122 gtk_widget_realize(mainwin->summaryview->hbox);
3123 gtk_widget_realize(mainwin->summaryview->hbox_l);
3124 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3125 prefs_common.folderview_width,
3126 prefs_common.folderview_height);
3127 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3129 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3131 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3132 prefs_common.mainwin_width,
3133 prefs_common.mainwin_height);
3134 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3136 /* remove headerview if not in prefs */
3137 headerview_set_visibility(mainwin->messageview->headerview,
3138 prefs_common.display_header_pane);
3140 if (messageview_is_visible(mainwin->messageview))
3141 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3142 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3144 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3145 GTK_ARROW_UP, GTK_SHADOW_OUT);
3147 gtk_window_move(GTK_WINDOW(mainwin->window),
3148 prefs_common.mainwin_x,
3149 prefs_common.mainwin_y);
3151 gtk_widget_queue_resize(vbox_body);
3152 gtk_widget_queue_resize(mainwin->vbox);
3153 gtk_widget_queue_resize(mainwin->window);
3154 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3155 * and mimeview icon list/ctree lose track of their visibility states */
3156 if (!noticeview_is_visible(mainwin->messageview->noticeview))
3157 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3158 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
3159 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3160 if (mainwin->messageview->mimeview->ctree_mode)
3161 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3163 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3165 prefs_common.layout_mode = layout_mode;
3167 menuitem = gtk_item_factory_get_item
3168 (ifactory, "/View/Show or hide/Message view");
3169 gtk_check_menu_item_set_active
3170 (GTK_CHECK_MENU_ITEM(menuitem),
3171 messageview_is_visible(mainwin->messageview));
3173 #define SET_CHECK_MENU_ACTIVE(path, active) \
3175 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3176 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3180 switch (prefs_common.layout_mode) {
3182 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3184 case VERTICAL_LAYOUT:
3185 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3188 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3190 case WIDE_MSGLIST_LAYOUT:
3191 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3194 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3198 #undef SET_CHECK_MENU_ACTIVE
3202 (G_OBJECT(folderwin), "size_allocate",
3203 G_CALLBACK(folder_window_size_allocate_cb),
3208 (G_OBJECT(messagewin), "size_allocate",
3209 G_CALLBACK(message_window_size_allocate_cb),
3213 debug_print("done.\n");
3216 void main_window_destroy_all(void)
3218 while (mainwin_list != NULL) {
3219 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3221 /* free toolbar stuff */
3222 toolbar_clear_list(TOOLBAR_MAIN);
3223 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3224 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3226 mainwin->folderview->mainwin = NULL;
3227 mainwin->summaryview->mainwin = NULL;
3228 mainwin->messageview->mainwin = NULL;
3230 g_free(mainwin->toolbar);
3233 mainwin_list = g_list_remove(mainwin_list, mainwin);
3235 g_list_free(mainwin_list);
3236 mainwin_list = NULL;
3239 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3242 gtk_widget_set_size_request(child, 1, -1);
3245 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3248 gtk_widget_set_size_request(child, -1, -1);
3251 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3254 MainWindow *mainwin = (MainWindow *)data;
3256 if (!event) return FALSE;
3258 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3259 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3262 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3263 menu_button_position, widget,
3264 event->button, event->time);
3269 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3272 MainWindow *mainwin = (MainWindow *)data;
3273 gboolean close_allowed = TRUE;
3275 hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3277 if (close_allowed && mainwin->lock_count == 0)
3278 app_exit_cb(data, 0, widget);
3283 static void main_window_size_allocate_cb(GtkWidget *widget,
3284 GtkAllocation *allocation,
3287 MainWindow *mainwin = (MainWindow *)data;
3288 main_window_get_size(mainwin);
3291 static void folder_window_size_allocate_cb(GtkWidget *widget,
3292 GtkAllocation *allocation,
3295 MainWindow *mainwin = (MainWindow *)data;
3297 main_window_get_size(mainwin);
3300 static void message_window_size_allocate_cb(GtkWidget *widget,
3301 GtkAllocation *allocation,
3304 MainWindow *mainwin = (MainWindow *)data;
3306 main_window_get_size(mainwin);
3309 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3312 main_window_add_mailbox(mainwin);
3315 static void update_folderview_cb(MainWindow *mainwin, guint action,
3318 summary_show(mainwin->summaryview, NULL);
3319 folderview_check_new_all();
3322 static void foldersort_cb(MainWindow *mainwin, guint action,
3328 static void import_mbox_cb(MainWindow *mainwin, guint action,
3331 /* only notify if import has failed */
3332 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3333 alertpanel_error(_("Mbox import has failed."));
3337 static void export_mbox_cb(MainWindow *mainwin, guint action,
3340 /* only notify if export has failed */
3341 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3342 alertpanel_error(_("Export to mbox has failed."));
3346 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3349 /* only notify if export has failed */
3350 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3351 alertpanel_error(_("Export to mbox has failed."));
3355 static void empty_trash_cb(MainWindow *mainwin, guint action,
3358 main_window_empty_trash(mainwin, TRUE);
3361 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3363 summary_save_as(mainwin->summaryview);
3366 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3368 summary_print(mainwin->summaryview);
3371 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3373 if (prefs_common.confirm_on_exit) {
3374 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3375 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
3376 != G_ALERTALTERNATE)
3378 manage_window_focus_in(mainwin->window, NULL, NULL);
3381 app_will_exit(widget, mainwin);
3384 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3387 summary_search(mainwin->summaryview);
3389 message_search(mainwin->messageview);
3392 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3394 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3397 static void toggle_message_cb(MainWindow *mainwin, guint action,
3402 active = GTK_CHECK_MENU_ITEM(widget)->active;
3404 if (active != messageview_is_visible(mainwin->messageview))
3405 summary_toggle_view(mainwin->summaryview);
3408 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3411 toolbar_toggle(action, mainwin);
3414 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3417 MessageView *msgview = (MessageView*)mainwin->messageview;
3418 GSList *msginfo_list = NULL;
3420 g_return_if_fail(msgview != NULL);
3422 msginfo_list = summary_get_selection(mainwin->summaryview);
3423 g_return_if_fail(msginfo_list != NULL);
3424 compose_reply_from_messageview(msgview, msginfo_list, action);
3425 g_slist_free(msginfo_list);
3428 static void toggle_col_headers_cb(MainWindow *mainwin, guint action,
3431 FolderView *folderview = mainwin->folderview;
3432 SummaryView *summaryview = mainwin->summaryview;
3434 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3435 gtk_clist_column_titles_show(GTK_CLIST(folderview->ctree));
3436 gtk_clist_column_titles_show(GTK_CLIST(summaryview->ctree));
3437 prefs_common.show_col_headers = TRUE;
3439 gtk_clist_column_titles_hide(GTK_CLIST(folderview->ctree));
3440 gtk_clist_column_titles_hide(GTK_CLIST(summaryview->ctree));
3441 prefs_common.show_col_headers = FALSE;
3446 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3449 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3450 gtk_widget_show(mainwin->hbox_stat);
3451 prefs_common.show_statusbar = TRUE;
3453 gtk_widget_hide(mainwin->hbox_stat);
3454 prefs_common.show_statusbar = FALSE;
3458 static void set_layout_cb(MainWindow *mainwin, guint action,
3461 LayoutType layout_mode = action;
3462 LayoutType old_layout_mode = prefs_common.layout_mode;
3463 if (mainwin->menu_lock_count) {
3466 if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3470 if (layout_mode == prefs_common.layout_mode) {
3474 if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3475 main_window_toggle_message_view(mainwin);
3476 else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3477 main_window_toggle_message_view(mainwin);
3479 main_window_separation_change(mainwin, layout_mode);
3480 mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3481 if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3482 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3484 if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3485 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3486 mainwindow_exit_folder(mainwin);
3488 summary_relayout(mainwin->summaryview);
3489 summary_update_unread(mainwin->summaryview, NULL);
3493 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3496 offline_ask_sync = ask_sync;
3498 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3500 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3501 offline_ask_sync = TRUE;
3504 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3506 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3509 static gboolean any_folder_want_synchronise(void)
3511 GList *folderlist = folder_get_list();
3513 /* see if there are synchronised folders */
3514 for (; folderlist; folderlist = folderlist->next) {
3515 Folder *folder = (Folder *)folderlist->data;
3516 if (folder_want_synchronise(folder)) {
3524 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3527 if (!any_folder_want_synchronise())
3530 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3531 _("Do you want to synchronise your folders now?"),
3532 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3535 if (offline_ask_sync)
3536 folder_synchronise(NULL);
3539 static void online_switch_clicked (GtkButton *btn, gpointer data)
3541 MainWindow *mainwin;
3542 GtkItemFactory *ifactory;
3543 GtkCheckMenuItem *menuitem;
3545 mainwin = (MainWindow *) data;
3547 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3548 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3550 g_return_if_fail(mainwin != NULL);
3551 g_return_if_fail(menuitem != NULL);
3553 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3555 gtk_widget_hide (mainwin->online_switch);
3556 gtk_widget_show (mainwin->offline_switch);
3558 menuitem->active = TRUE;
3559 inc_autocheck_timer_remove();
3562 if (prefs_common.work_offline)
3564 mainwindow_check_synchronise(mainwin, TRUE);
3565 prefs_common.work_offline = TRUE;
3566 imap_disconnect_all();
3567 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3570 if (!prefs_common.work_offline)
3573 gtk_widget_hide (mainwin->offline_switch);
3574 gtk_widget_show (mainwin->online_switch);
3576 menuitem->active = FALSE;
3577 prefs_common.work_offline = FALSE;
3578 inc_autocheck_timer_set();
3579 refresh_resolvers();
3580 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3584 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3587 addressbook_open(NULL);
3590 static void log_window_show_cb(MainWindow *mainwin, guint action,
3593 log_window_show(mainwin->logwin);
3596 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3599 log_window_show(mainwin->filtering_debugwin);
3602 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3608 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3610 summary_move_to(mainwin->summaryview);
3613 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3615 summary_copy_to(mainwin->summaryview);
3618 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3620 summary_delete(mainwin->summaryview);
3623 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3625 summary_delete_trash(mainwin->summaryview);
3628 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3630 summary_cancel(mainwin->summaryview);
3633 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3635 summary_open_msg(mainwin->summaryview);
3638 static void view_source_cb(MainWindow *mainwin, guint action,
3641 summary_view_source(mainwin->summaryview);
3644 static void show_all_header_cb(MainWindow *mainwin, guint action,
3647 if (mainwin->menu_lock_count) return;
3648 mainwin->summaryview->messageview->all_headers =
3649 GTK_CHECK_MENU_ITEM(widget)->active;
3650 summary_display_msg_selected(mainwin->summaryview,
3651 GTK_CHECK_MENU_ITEM(widget)->active);
3654 #define SET_CHECK_MENU_ACTIVE(path, active) \
3656 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3657 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3660 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3663 GtkWidget *menuitem;
3664 GtkItemFactory *ifactory = mainwin->menu_factory;
3666 if (mainwin->menu_lock_count) return;
3668 prefs_common.hide_quotes =
3669 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3671 mainwin->menu_lock_count++;
3672 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3673 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3674 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3675 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3676 mainwin->menu_lock_count--;
3678 summary_redisplay_msg(mainwin->summaryview);
3681 #undef SET_CHECK_MENU_ACTIVE
3682 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3684 summary_mark(mainwin->summaryview);
3687 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3689 summary_unmark(mainwin->summaryview);
3692 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3695 summary_mark_as_unread(mainwin->summaryview);
3698 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3701 summary_mark_as_read(mainwin->summaryview);
3704 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3707 summary_mark_all_read(mainwin->summaryview);
3710 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3713 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3716 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3719 summary_ignore_thread(mainwin->summaryview);
3722 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3725 summary_unignore_thread(mainwin->summaryview);
3728 static void watch_thread_cb(MainWindow *mainwin, guint action,
3731 summary_watch_thread(mainwin->summaryview);
3734 static void unwatch_thread_cb(MainWindow *mainwin, guint action,
3737 summary_unwatch_thread(mainwin->summaryview);
3740 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3743 summary_msgs_lock(mainwin->summaryview);
3746 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3749 summary_msgs_unlock(mainwin->summaryview);
3753 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3755 summary_reedit(mainwin->summaryview);
3758 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3760 if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3761 summary_display_msg_selected(mainwin->summaryview,
3762 mainwin->messageview->mimeview->textview->show_all_headers);
3764 messageview_list_urls(mainwin->messageview);
3767 static void add_address_cb(MainWindow *mainwin, guint action,
3770 summary_add_address(mainwin->summaryview);
3773 static void set_charset_cb(MainWindow *mainwin, guint action,
3778 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3779 str = conv_get_charset_str((CharSet)action);
3781 g_free(mainwin->messageview->forced_charset);
3782 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3783 procmime_force_charset(str);
3785 summary_redisplay_msg(mainwin->summaryview);
3787 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3791 static void set_decode_cb(MainWindow *mainwin, guint action,
3794 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3795 mainwin->messageview->forced_encoding = (EncodingType)action;
3797 summary_redisplay_msg(mainwin->summaryview);
3799 debug_print("forced encoding: %d\n", action);
3803 static void hide_read_messages (MainWindow *mainwin, guint action,
3806 if (!mainwin->summaryview->folder_item
3807 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3809 summary_toggle_show_read_messages(mainwin->summaryview);
3812 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3814 gboolean threaded = FALSE;
3815 if (mainwin->menu_lock_count) return;
3816 if (!mainwin->summaryview->folder_item) return;
3818 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3820 mainwin->summaryview->folder_item->threaded = threaded;
3822 mainwin->summaryview->threaded = threaded;
3824 summary_show(mainwin->summaryview,
3825 mainwin->summaryview->folder_item);
3828 static void expand_threads_cb(MainWindow *mainwin, guint action,
3831 summary_expand_threads(mainwin->summaryview);
3834 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3837 summary_collapse_threads(mainwin->summaryview);
3840 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3843 prefs_summary_column_open();
3846 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3849 prefs_folder_column_open();
3852 static void sort_summary_cb(MainWindow *mainwin, guint action,
3855 FolderItem *item = mainwin->summaryview->folder_item;
3856 GtkWidget *menuitem;
3858 if (mainwin->menu_lock_count) return;
3860 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3861 menuitem = gtk_item_factory_get_item
3862 (mainwin->menu_factory, "/View/Sort/Ascending");
3863 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3864 GTK_CHECK_MENU_ITEM(menuitem)->active
3865 ? SORT_ASCENDING : SORT_DESCENDING);
3866 item->sort_key = action;
3870 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3873 FolderItem *item = mainwin->summaryview->folder_item;
3875 if (mainwin->menu_lock_count) return;
3877 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3878 summary_sort(mainwin->summaryview,
3879 item->sort_key, (FolderSortType)action);
3882 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3885 summary_attract_by_subject(mainwin->summaryview);
3888 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3893 item = folderview_get_selected_item(mainwin->folderview);
3895 main_window_cursor_wait(mainwin);
3896 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3898 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3899 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3901 STATUSBAR_POP(mainwin);
3902 main_window_cursor_normal(mainwin);
3912 static void deldup_all(FolderItem *item, gpointer _data)
3914 struct DelDupsData *data = _data;
3917 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3919 data->dups += result;
3924 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3927 struct DelDupsData data = {0, 0};
3929 main_window_cursor_wait(mainwin);
3930 folder_func_to_all_folders(deldup_all, &data);
3931 main_window_cursor_normal(mainwin);
3933 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3934 "Deleted %d duplicate messages in %d folders.\n",
3936 data.dups, data.folders);
3939 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3941 summary_filter(mainwin->summaryview, (gboolean)action);
3944 static void execute_summary_cb(MainWindow *mainwin, guint action,
3947 summary_execute(mainwin->summaryview);
3950 static void update_summary_cb(MainWindow *mainwin, guint action,
3954 FolderView *folderview = mainwin->folderview;
3956 if (!mainwin->summaryview->folder_item) return;
3957 if (!folderview->opened) return;
3959 folder_update_op_count();
3961 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3962 folderview->opened);
3965 folder_item_scan(fitem);
3966 summary_show(mainwin->summaryview, fitem);
3969 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3971 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3974 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3976 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3979 static void prev_unread_cb(MainWindow *mainwin, guint action,
3982 summary_select_prev_unread(mainwin->summaryview);
3985 static void next_unread_cb(MainWindow *mainwin, guint action,
3988 summary_select_next_unread(mainwin->summaryview);
3991 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3993 summary_select_prev_new(mainwin->summaryview);
3996 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3998 summary_select_next_new(mainwin->summaryview);
4001 static void prev_marked_cb(MainWindow *mainwin, guint action,
4004 summary_select_prev_marked(mainwin->summaryview);
4007 static void next_marked_cb(MainWindow *mainwin, guint action,
4010 summary_select_next_marked(mainwin->summaryview);
4013 static void prev_labeled_cb(MainWindow *mainwin, guint action,
4016 summary_select_prev_labeled(mainwin->summaryview);
4019 static void next_labeled_cb(MainWindow *mainwin, guint action,
4022 summary_select_next_labeled(mainwin->summaryview);
4025 static void last_read_cb(MainWindow *mainwin, guint action,
4028 summary_select_last_read(mainwin->summaryview);
4031 static void parent_cb(MainWindow *mainwin, guint action,
4034 summary_select_parent(mainwin->summaryview);
4037 static void goto_folder_cb(MainWindow *mainwin, guint action,
4040 FolderItem *to_folder;
4042 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
4045 folderview_select(mainwin->folderview, to_folder);
4048 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
4051 folderview_select_next_unread(mainwin->folderview, FALSE);
4054 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4056 messageview_copy_clipboard(mainwin->messageview);
4059 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4061 MessageView *msgview = mainwin->messageview;
4063 if (messageview_is_visible(msgview) &&
4064 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
4065 messageview_select_all(mainwin->messageview);
4067 summary_select_all(mainwin->summaryview);
4070 static void select_thread_cb(MainWindow *mainwin, guint action,
4073 summary_select_thread(mainwin->summaryview, FALSE);
4076 static void delete_thread_cb(MainWindow *mainwin, guint action,
4079 summary_select_thread(mainwin->summaryview, TRUE);
4082 static void create_filter_cb(MainWindow *mainwin, guint action,
4085 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4088 static void create_processing_cb(MainWindow *mainwin, guint action,
4091 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4094 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
4097 prefs_filtering_open(&pre_global_processing,
4098 _("Processing rules to apply before folder rules"),
4099 MANUAL_ANCHOR_PROCESSING,
4103 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
4106 prefs_filtering_open(&post_global_processing,
4107 _("Processing rules to apply after folder rules"),
4108 MANUAL_ANCHOR_PROCESSING,
4112 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
4115 prefs_filtering_open(&filtering_rules,
4116 _("Filtering configuration"),
4117 MANUAL_ANCHOR_FILTERING,
4121 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4124 prefs_template_open();
4127 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4130 prefs_actions_open(mainwin);
4133 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4136 prefs_tags_open(mainwin);
4139 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4142 ssl_manager_open(mainwin);
4145 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4149 new_account_cb(mainwin, 0, widget);
4151 account_open(cur_account);
4155 static void new_account_cb(MainWindow *mainwin, guint action,
4158 account_edit_open();
4159 if (!compose_get_compose_list()) account_add();
4162 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4164 FolderItem *item = NULL;
4165 cur_account = (PrefsAccount *)data;
4167 if (!mainwindow_get_mainwindow())
4169 main_window_show_cur_account(mainwindow_get_mainwindow());
4170 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4171 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4172 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4173 item = folderview_get_selected_item(
4174 mainwindow_get_mainwindow()->folderview);
4176 toolbar_set_compose_button
4177 (mainwindow_get_mainwindow()->toolbar,
4178 FOLDER_TYPE(item->folder) == F_NEWS ?
4179 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4183 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4185 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4186 PrefsAccount *account = (PrefsAccount *)data;
4188 inc_account_mail(mainwin, account);
4191 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4193 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4194 PrefsAccount *account = (PrefsAccount *)data;
4195 FolderItem *item = mainwin->summaryview->folder_item;
4197 compose_new_with_folderitem(account, item, NULL);
4200 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4205 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4207 pluginwindow_create();
4210 static void manual_open_cb(MainWindow *mainwin, guint action,
4213 manual_open((ManualType)action, NULL);
4216 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4221 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4223 MainWindow *mainwin = (MainWindow *)data;
4227 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4228 LOCAL_FOLDER(folder)->rootpath,
4232 str = g_strdup_printf(_("Scanning folder %s ..."),
4233 LOCAL_FOLDER(folder)->rootpath);
4235 STATUSBAR_PUSH(mainwin, str);
4236 STATUSBAR_POP(mainwin);
4240 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4243 SummaryView *summary;
4245 g_return_val_if_fail(data, FALSE);
4246 if (!g_list_find(mainwin_list, data))
4248 summary = ((MainWindow *)data)->summaryview;
4249 g_return_val_if_fail(summary, FALSE);
4251 if (GTK_CLIST(summary->ctree)->selection &&
4252 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4258 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4261 is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4265 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4268 if (!claws_is_starting()
4269 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4270 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4272 if (iconified_count > 0)
4273 hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4276 if (state->new_window_state == 0)
4277 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4281 gboolean mainwindow_is_obscured(void)
4286 #define BREAK_ON_MODIFIER_KEY() \
4287 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
4289 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
4292 MainWindow *mainwin = (MainWindow*) data;
4294 if (!mainwin || !event)
4297 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
4299 lastkey = event->keyval;
4303 switch (event->keyval) {
4304 case GDK_Q: /* Quit */
4305 BREAK_ON_MODIFIER_KEY();
4307 app_exit_cb(mainwin, 0, NULL);
4310 if (mainwin->folderview && mainwin->summaryview
4311 && ((!mainwin->summaryview->displayed
4312 && !mainwin->summaryview->selected)
4313 || (mainwin->summaryview->folder_item
4314 && mainwin->summaryview->folder_item->total_msgs == 0))) {
4315 g_signal_stop_emission_by_name(G_OBJECT(widget),
4317 folderview_select_next_unread(mainwin->folderview, TRUE);
4322 if (maemo_mainwindow_is_fullscreen(widget)) {
4323 gtk_window_unfullscreen(GTK_WINDOW(widget));
4325 gtk_window_fullscreen(GTK_WINDOW(widget));
4335 #undef BREAK_ON_MODIFIER_KEY
4338 * Harvest addresses for selected folder.
4340 static void addr_harvest_cb( MainWindow *mainwin,
4344 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4348 * Harvest addresses for selected messages in summary view.
4350 static void addr_harvest_msg_cb( MainWindow *mainwin,
4354 summary_harvest_address( mainwin->summaryview );
4358 *\brief get a MainWindow
4360 *\return MainWindow * The first mainwindow in the mainwin_list
4362 MainWindow *mainwindow_get_mainwindow(void)
4364 if (mainwin_list && mainwin_list->data)
4365 return (MainWindow *)(mainwin_list->data);
4370 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4372 ProgressData *data = (ProgressData *) source;
4373 MainWindow *mainwin = (MainWindow *) userdata;
4375 switch (data->cmd) {
4376 case PROGRESS_COMMAND_START:
4377 case PROGRESS_COMMAND_STOP:
4378 gtk_progress_bar_set_fraction
4379 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4381 case PROGRESS_COMMAND_SET_PERCENTAGE:
4382 gtk_progress_bar_set_fraction
4383 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4386 while (gtk_events_pending()) gtk_main_iteration ();
4391 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4393 mainwindow_check_synchronise(mainwin, FALSE);
4396 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4398 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4401 void mainwindow_jump_to(const gchar *target, gboolean popup)
4405 FolderItem *item = NULL;
4407 MainWindow *mainwin = mainwindow_get_mainwindow();
4413 printf("not initialized\n");
4417 tmp = g_strdup(target);
4419 if ((p = strstr(tmp, "\r")) != NULL)
4421 if ((p = strstr(tmp, "\n")) != NULL)
4424 if ((item = folder_find_item_from_identifier(tmp))) {
4425 printf("selecting folder '%s'\n", tmp);
4426 folderview_select(mainwin->folderview, item);
4428 main_window_popup(mainwin);
4433 msg = strrchr(tmp, G_DIR_SEPARATOR);
4436 if ((item = folder_find_item_from_identifier(tmp))) {
4437 printf("selecting folder '%s'\n", tmp);
4438 folderview_select(mainwin->folderview, item);
4440 printf("'%s' not found\n", tmp);
4442 if (item && msg && atoi(msg)) {
4443 printf("selecting message %d\n", atoi(msg));
4444 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4445 summary_display_msg_selected(mainwin->summaryview, FALSE);
4447 main_window_popup(mainwin);
4450 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4451 MsgInfo *msginfo = NULL;
4453 msg[strlen(msg)-1] = '\0';
4454 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4456 printf("selecting message %s\n", msg);
4457 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4458 summary_display_msg_selected(mainwin->summaryview, FALSE);
4460 main_window_popup(mainwin);
4462 procmsg_msginfo_free(msginfo);
4465 printf("'%s' not found\n", msg);
4468 printf("'%s' not found\n", msg);
4471 printf("'%s' not found\n", tmp);
4477 void mainwindow_exit_folder(MainWindow *mainwin) {
4478 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4479 folderview_close_opened(mainwin->folderview);
4480 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4482 mainwin->in_folder = FALSE;
4485 void mainwindow_enter_folder(MainWindow *mainwin) {
4486 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4487 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4489 mainwin->in_folder = TRUE;
4493 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4496 gtk_window_get_size(GTK_WINDOW(widget), &w, &h);
4500 void maemo_window_full_screen_if_needed (GtkWindow *window)
4502 if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4503 gtk_window_fullscreen(GTK_WINDOW(window));
4507 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4509 g_signal_connect(G_OBJECT(window), "key_press_event",
4510 G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());