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,
191 static void toggle_statusbar_cb (MainWindow *mainwin,
194 static void set_layout_cb (MainWindow *mainwin,
198 static void addressbook_open_cb (MainWindow *mainwin,
201 static void log_window_show_cb (MainWindow *mainwin,
204 static void filtering_debug_window_show_cb (MainWindow *mainwin,
208 static void inc_cancel_cb (MainWindow *mainwin,
212 static void open_msg_cb (MainWindow *mainwin,
216 static void view_source_cb (MainWindow *mainwin,
220 static void show_all_header_cb (MainWindow *mainwin,
224 static void hide_quotes_cb(MainWindow *mainwin,
228 static void move_to_cb (MainWindow *mainwin,
231 static void copy_to_cb (MainWindow *mainwin,
234 static void delete_cb (MainWindow *mainwin,
237 static void delete_trash_cb (MainWindow *mainwin,
241 static void cancel_cb (MainWindow *mainwin,
245 static void mark_cb (MainWindow *mainwin,
248 static void unmark_cb (MainWindow *mainwin,
252 static void mark_as_unread_cb (MainWindow *mainwin,
255 static void mark_as_read_cb (MainWindow *mainwin,
258 static void mark_all_read_cb (MainWindow *mainwin,
261 static void mark_as_spam_cb (MainWindow *mainwin,
265 static void ignore_thread_cb (MainWindow *mainwin,
268 static void unignore_thread_cb (MainWindow *mainwin,
271 static void lock_msgs_cb (MainWindow *mainwin,
274 static void unlock_msgs_cb (MainWindow *mainwin,
278 static void reedit_cb (MainWindow *mainwin,
282 static void add_address_cb (MainWindow *mainwin,
286 static void set_charset_cb (MainWindow *mainwin,
290 static void set_decode_cb (MainWindow *mainwin,
294 static void hide_read_messages (MainWindow *mainwin,
298 static void thread_cb (MainWindow *mainwin,
301 static void expand_threads_cb (MainWindow *mainwin,
304 static void collapse_threads_cb (MainWindow *mainwin,
308 static void set_summary_display_item_cb (MainWindow *mainwin,
311 static void set_folder_display_item_cb (MainWindow *mainwin,
314 static void sort_summary_cb (MainWindow *mainwin,
317 static void sort_summary_type_cb (MainWindow *mainwin,
320 static void attract_by_subject_cb(MainWindow *mainwin,
324 static void delete_duplicated_cb (MainWindow *mainwin,
327 static void delete_duplicated_all_cb (MainWindow *mainwin,
330 static void filter_cb (MainWindow *mainwin,
333 static void execute_summary_cb (MainWindow *mainwin,
336 static void update_summary_cb (MainWindow *mainwin,
340 static void prev_cb (MainWindow *mainwin,
343 static void next_cb (MainWindow *mainwin,
346 static void next_unread_cb (MainWindow *mainwin,
349 static void prev_unread_cb (MainWindow *mainwin,
353 static void prev_new_cb (MainWindow *mainwin,
356 static void next_new_cb (MainWindow *mainwin,
359 static void prev_marked_cb (MainWindow *mainwin,
362 static void next_marked_cb (MainWindow *mainwin,
365 static void prev_labeled_cb (MainWindow *mainwin,
368 static void next_labeled_cb (MainWindow *mainwin,
371 static void last_read_cb (MainWindow *mainwin,
374 static void parent_cb (MainWindow *mainwin,
378 static void goto_folder_cb (MainWindow *mainwin,
381 static void goto_unread_folder_cb(MainWindow *mainwin,
385 static void copy_cb (MainWindow *mainwin,
388 static void allsel_cb (MainWindow *mainwin,
391 static void select_thread_cb (MainWindow *mainwin,
394 static void delete_thread_cb (MainWindow *mainwin,
398 static void create_filter_cb (MainWindow *mainwin,
401 static void create_processing_cb (MainWindow *mainwin,
404 static void open_urls_cb (MainWindow *mainwin,
408 static void prefs_template_open_cb (MainWindow *mainwin,
411 static void prefs_actions_open_cb (MainWindow *mainwin,
414 static void prefs_tags_open_cb (MainWindow *mainwin,
417 static void prefs_account_open_cb (MainWindow *mainwin,
421 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
425 static void prefs_post_processing_open_cb (MainWindow *mainwin,
429 static void prefs_filtering_open_cb (MainWindow *mainwin,
433 static void ssl_manager_open_cb (MainWindow *mainwin,
437 static void new_account_cb (MainWindow *mainwin,
441 static void account_selector_menu_cb (GtkMenuItem *menuitem,
443 static void account_receive_menu_cb (GtkMenuItem *menuitem,
445 static void account_compose_menu_cb (GtkMenuItem *menuitem,
448 static void prefs_open_cb (GtkMenuItem *menuitem,
450 static void plugins_open_cb (GtkMenuItem *menuitem,
453 static void online_switch_clicked(GtkButton *btn,
456 static void manual_open_cb (MainWindow *mainwin,
460 static void legend_open_cb (GtkMenuItem *menuitem,
463 static void scan_tree_func (Folder *folder,
467 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
469 static void addr_harvest_cb ( MainWindow *mainwin,
473 static void addr_harvest_msg_cb ( MainWindow *mainwin,
476 static void sync_cb ( MainWindow *mainwin,
480 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
481 GdkEventFocus *focus,
483 static gboolean mainwindow_visibility_event_cb (GtkWidget *widget,
484 GdkEventVisibility *state,
486 static gboolean mainwindow_state_event_cb (GtkWidget *widget,
487 GdkEventWindowState *state,
489 static void main_window_reply_cb (MainWindow *mainwin,
492 static gboolean mainwindow_progressindicator_hook (gpointer source,
495 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
498 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
500 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
502 static void mailing_list_compose(GtkWidget *w, gpointer *data);
504 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
505 #define SEPARATE_ACTION 500
506 static void mainwindow_quicksearch (MainWindow *mainwin,
509 static gboolean any_folder_want_synchronise(void);
511 static GtkItemFactoryEntry mainwin_entries[] =
513 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
514 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
515 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
516 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
518 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
519 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
520 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
521 {N_("/_File/Exp_ort selected to mbox file..."),
522 NULL, export_list_mbox_cb, 0, NULL},
523 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
525 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
527 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
528 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
530 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
531 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
532 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
533 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
535 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
537 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
538 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
539 {N_("/_Edit/_Delete thread"), NULL, delete_thread_cb, 0, NULL},
540 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
541 {N_("/_Edit/_Find in current message..."),
542 "<control>F", search_cb, 0, NULL},
543 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
544 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
545 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
546 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
547 {N_("/_View/Show or hi_de/_Message view"),
548 "V", toggle_message_cb, 0, "<ToggleItem>"},
549 {N_("/_View/Show or hi_de/_Toolbar"),
550 NULL, NULL, 0, "<Branch>"},
551 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
552 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
553 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
554 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
555 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
556 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
557 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
558 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
559 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
560 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
562 {N_("/_View/Show or hi_de/Status _bar"),
563 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
565 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
566 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
567 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
569 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
571 {N_("/_View/La_yout"), NULL, NULL, 0, "<Branch>"},
572 {N_("/_View/Layout/_Standard"), NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
573 {N_("/_View/Layout/_Three columns"), NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
574 {N_("/_View/Layout/_Wide message"), NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
575 {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
576 {N_("/_View/Layout/S_mall screen"), NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
577 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
579 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
580 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
581 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
582 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
583 {N_("/_View/_Sort/by Thread date"), NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
584 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
585 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
586 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
587 {N_("/_View/_Sort/by _color label"), NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
588 {N_("/_View/_Sort/by tag"), NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
589 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
590 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
591 {N_("/_View/_Sort/by a_ttachment"),
592 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
593 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
594 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
595 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
596 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
597 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
598 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
599 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_View/_Sort/_Attract by subject"),
601 NULL, attract_by_subject_cb, 0, NULL},
602 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
603 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
604 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
605 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
607 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
608 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
609 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
610 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
611 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_View/_Go to/P_revious unread message"),
613 "<shift>P", prev_unread_cb, 0, NULL},
614 {N_("/_View/_Go to/N_ext unread message"),
615 "<shift>N", next_unread_cb, 0, NULL},
616 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
618 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
619 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
620 {N_("/_View/_Go to/Previous _marked message"),
621 NULL, prev_marked_cb, 0, NULL},
622 {N_("/_View/_Go to/Next m_arked message"),
623 NULL, next_marked_cb, 0, NULL},
624 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_View/_Go to/Previous _labeled message"),
626 NULL, prev_labeled_cb, 0, NULL},
627 {N_("/_View/_Go to/Next la_beled message"),
628 NULL, next_labeled_cb, 0, NULL},
629 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_View/_Go to/Last read message"),
631 NULL, last_read_cb, 0, NULL},
632 {N_("/_View/_Go to/Parent message"),
633 "<control>Up", parent_cb, 0, NULL},
634 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
636 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
637 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
639 #define ENC_SEPARATOR \
640 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
641 #define ENC_ACTION(action) \
642 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
644 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
645 {N_("/_View/Character _encoding/_Auto detect"),
646 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
647 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
648 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
649 ENC_ACTION(C_US_ASCII)},
650 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
651 ENC_ACTION(C_UTF_8)},
654 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
655 ENC_ACTION(C_ISO_8859_1)},
656 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
657 ENC_ACTION(C_ISO_8859_15)},
658 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
659 ENC_ACTION(C_WINDOWS_1252)},
662 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
663 ENC_ACTION(C_ISO_8859_2)},
666 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
667 ENC_ACTION(C_ISO_8859_13)},
668 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
669 ENC_ACTION(C_ISO_8859_4)},
672 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
673 ENC_ACTION(C_ISO_8859_7)},
676 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
677 ENC_ACTION(C_ISO_8859_8)},
678 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
679 ENC_ACTION(C_CP1255)},
682 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
683 ENC_ACTION(C_ISO_8859_6)},
684 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
685 ENC_ACTION(C_CP1256)},
688 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
689 ENC_ACTION(C_ISO_8859_9)},
692 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
693 ENC_ACTION(C_ISO_8859_5)},
694 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
695 ENC_ACTION(C_KOI8_R)},
696 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
697 ENC_ACTION(C_KOI8_U)},
698 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
699 ENC_ACTION(C_CP1251)},
702 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
703 ENC_ACTION(C_ISO_2022_JP)},
704 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
705 ENC_ACTION(C_ISO_2022_JP_2)},
706 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
707 ENC_ACTION(C_EUC_JP)},
708 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
709 ENC_ACTION(C_SHIFT_JIS)},
712 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
713 ENC_ACTION(C_GB2312)},
714 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
716 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
718 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
719 ENC_ACTION(C_EUC_TW)},
720 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
721 ENC_ACTION(C_ISO_2022_CN)},
724 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
725 ENC_ACTION(C_EUC_KR)},
726 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
727 ENC_ACTION(C_ISO_2022_KR)},
730 {N_("/_View/Character _encoding/Thai (TIS-620)"),
731 ENC_ACTION(C_TIS_620)},
732 {N_("/_View/Character _encoding/Thai (Windows-874)"),
733 ENC_ACTION(C_WINDOWS_874)},
738 #define DEC_SEPARATOR \
739 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
740 #define DEC_ACTION(action) \
741 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
742 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
743 {N_("/_View/Decode/_Auto detect"),
744 NULL, set_decode_cb, 0, "<RadioItem>"},
745 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
746 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
747 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
748 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
749 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
754 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
755 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
756 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
757 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
758 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
759 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
760 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
761 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
762 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
763 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
765 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
766 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
767 {N_("/_Message/Recei_ve/Get from _current account"),
768 "<control>I", inc_mail_cb, 0, NULL},
769 {N_("/_Message/Recei_ve/Get from _all accounts"),
770 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
771 {N_("/_Message/Recei_ve/Cancel receivin_g"),
772 NULL, inc_cancel_cb, 0, NULL},
773 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
774 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
775 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
776 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
777 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
778 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
779 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
780 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
781 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
782 {N_("/_Message/Repl_y to/mailing _list"),
783 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
784 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
785 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
786 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
787 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
788 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
790 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
791 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
792 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
793 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
794 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
795 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
796 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
798 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
799 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
800 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
801 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
802 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
803 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
804 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
805 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
806 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
807 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
808 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
809 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
810 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
811 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
812 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
813 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
814 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
815 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
816 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
817 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
818 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
819 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
820 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
821 {N_("/_Message/T_ags"), NULL, NULL, 0, NULL},
822 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
823 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
825 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
826 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
827 {N_("/_Tools/Add sender to address boo_k"),
828 NULL, add_address_cb, 0, NULL},
829 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
830 {N_("/_Tools/_Harvest addresses/from _Folder..."),
831 NULL, addr_harvest_cb, 0, NULL},
832 {N_("/_Tools/_Harvest addresses/from _Messages..."),
833 NULL, addr_harvest_msg_cb, 0, NULL},
834 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
835 {N_("/_Tools/_Filter all messages in folder"),
836 NULL, filter_cb, 0, NULL},
837 {N_("/_Tools/Filter _selected messages"),
838 NULL, filter_cb, 1, NULL},
839 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
840 {N_("/_Tools/_Create filter rule/_Automatically"),
841 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
842 {N_("/_Tools/_Create filter rule/by _From"),
843 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
844 {N_("/_Tools/_Create filter rule/by _To"),
845 NULL, create_filter_cb, FILTER_BY_TO, NULL},
846 {N_("/_Tools/_Create filter rule/by _Subject"),
847 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
848 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
849 {N_("/_Tools/C_reate processing rule/_Automatically"),
850 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
851 {N_("/_Tools/C_reate processing rule/by _From"),
852 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
853 {N_("/_Tools/C_reate processing rule/by _To"),
854 NULL, create_processing_cb, FILTER_BY_TO, NULL},
855 {N_("/_Tools/C_reate processing rule/by _Subject"),
856 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
857 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
858 {N_("/_Tools/List _URLs..."), "<shift><control>U", open_urls_cb, 0, NULL},
859 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
860 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
861 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
862 {N_("/_Tools/Ch_eck for new messages in all folders"),
863 NULL, update_folderview_cb, 0, NULL},
864 {N_("/_Tools/Delete du_plicated messages"),
865 NULL, NULL, 0, "<Branch>"},
866 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
867 NULL, delete_duplicated_cb, 0, NULL},
868 {N_("/_Tools/Delete du_plicated messages/In all folders"),
869 NULL, delete_duplicated_all_cb, 0, NULL},
870 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
871 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
873 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
874 {N_("/_Tools/SSL cer_tificates..."),
875 NULL, ssl_manager_open_cb, 0, NULL},
877 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
878 {N_("/_Tools/Filtering Log"), NULL, filtering_debug_window_show_cb, 0, NULL},
879 {N_("/_Tools/Network _Log"), "<shift><control>L", log_window_show_cb, 0, NULL},
881 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
882 {N_("/_Configuration/C_hange current account"),
883 NULL, NULL, 0, "<Branch>"},
884 {N_("/_Configuration/_Preferences for current account..."),
885 NULL, prefs_account_open_cb, 0, NULL},
886 {N_("/_Configuration/Create _new account..."),
887 NULL, new_account_cb, 0, NULL},
888 {N_("/_Configuration/_Edit accounts..."),
889 NULL, account_edit_open, 0, NULL},
890 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
891 {N_("/_Configuration/P_references..."),
892 NULL, prefs_open_cb, 0, NULL},
893 {N_("/_Configuration/Pre-pr_ocessing..."),
894 NULL, prefs_pre_processing_open_cb, 0, NULL},
895 {N_("/_Configuration/Post-pro_cessing..."),
896 NULL, prefs_post_processing_open_cb, 0, NULL},
897 {N_("/_Configuration/_Filtering..."),
898 NULL, prefs_filtering_open_cb, 0, NULL},
899 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
900 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
901 {N_("/_Configuration/Tag_s..."), NULL, prefs_tags_open_cb, 0, NULL},
902 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
903 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
905 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
906 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
907 {N_("/_Help/_Online User-contributed FAQ"),
908 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
909 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
910 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
911 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
914 static gboolean offline_ask_sync = TRUE;
915 static guint lastkey;
916 static gboolean is_obscured = FALSE;
918 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
924 MainWindow *mainwin = (MainWindow *)user_data;
926 if (mainwin->summaryview &&
927 mainwin->summaryview->quicksearch &&
928 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
929 (mod == 0 || mod == GDK_SHIFT_MASK)) {
930 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
936 #define N_COLOR_LABELS colorlabel_get_color_count()
938 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
943 GtkCheckMenuItem **items;
948 mainwin = (MainWindow *)data;
949 g_return_if_fail(mainwin != NULL);
951 sel = summary_get_selection(mainwin->summaryview);
954 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
955 g_return_if_fail(menu != NULL);
957 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
959 /* NOTE: don't return prematurely because we set the "dont_toggle"
960 * state for check menu items */
961 g_object_set_data(G_OBJECT(menu), "dont_toggle",
964 /* clear items. get item pointers. */
965 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
966 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
967 gtk_check_menu_item_set_active
968 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
969 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
974 if (n == (N_COLOR_LABELS + 1)) {
975 /* iterate all messages and set the state of the appropriate
977 for (; sel != NULL; sel = sel->next) {
981 msginfo = (MsgInfo *)sel->data;
983 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
984 if (!items[clabel]->active)
985 gtk_check_menu_item_set_active
986 (items[clabel], TRUE);
990 g_warning("invalid number of color elements (%d)\n", n);
993 /* reset "dont_toggle" state */
994 g_object_set_data(G_OBJECT(menu), "dont_toggle",
998 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
1001 guint color = GPOINTER_TO_UINT(data);
1002 MainWindow *mainwin;
1004 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1005 g_return_if_fail(mainwin != NULL);
1007 /* "dont_toggle" state set? */
1008 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
1012 summary_set_colorlabel(mainwin->summaryview, color, NULL);
1015 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
1018 MainWindow *mainwin;
1022 GHashTable *menu_table = g_hash_table_new_full(
1026 GHashTable *menu_allsel_table = g_hash_table_new_full(
1031 mainwin = (MainWindow *)data;
1032 g_return_if_fail(mainwin != NULL);
1034 sel = summary_get_selection(mainwin->summaryview);
1037 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1038 g_return_if_fail(menu != NULL);
1040 /* NOTE: don't return prematurely because we set the "dont_toggle"
1041 * state for check menu items */
1042 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1043 GINT_TO_POINTER(1));
1045 /* clear items. get item pointers. */
1046 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1047 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1048 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1050 gtk_check_menu_item_set_active
1051 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1053 g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1054 g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1058 /* iterate all messages and set the state of the appropriate
1061 for (; sel != NULL; sel = sel->next) {
1063 GSList *tags = NULL;
1065 GtkCheckMenuItem *item;
1066 msginfo = (MsgInfo *)sel->data;
1069 tags = msginfo->tags;
1073 for (; tags; tags = tags->next) {
1074 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1075 id = GPOINTER_TO_INT(tags->data);
1076 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1077 if (item && !item->active) {
1078 gtk_check_menu_item_set_active
1082 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1087 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1088 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1089 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1091 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1092 if (num_checked < sel_len && num_checked > 0)
1093 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1095 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1099 g_hash_table_destroy(menu_table);
1100 g_hash_table_destroy(menu_allsel_table);
1101 /* reset "dont_toggle" state */
1102 g_object_set_data(G_OBJECT(menu), "dont_toggle",
1103 GINT_TO_POINTER(0));
1106 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1109 gint id = GPOINTER_TO_INT(data);
1110 gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1111 MainWindow *mainwin;
1113 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1114 g_return_if_fail(mainwin != NULL);
1116 /* "dont_toggle" state set? */
1117 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1123 summary_set_tag(mainwin->summaryview, id, NULL);
1126 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1128 GtkWidget *label_menuitem;
1133 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1134 "/Message/Color label");
1135 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1136 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1138 gtk_widget_show(label_menuitem);
1140 menu = gtk_menu_new();
1142 /* create sub items. for the menu item activation callback we pass the
1143 * index of label_colors[] as data parameter. for the None color we
1144 * pass an invalid (high) value. also we attach a data pointer so we
1145 * can always get back the Mainwindow pointer. */
1147 item = gtk_check_menu_item_new_with_label(_("None"));
1148 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1149 g_signal_connect(G_OBJECT(item), "activate",
1150 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1151 GUINT_TO_POINTER(0));
1152 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1153 gtk_widget_show(item);
1155 gtk_widget_add_accelerator(item, "activate",
1156 mainwin->menu_factory->accel_group,
1157 GDK_0, GDK_CONTROL_MASK,
1158 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1160 item = gtk_menu_item_new();
1161 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1162 gtk_widget_show(item);
1164 /* create pixmap/label menu items */
1165 for (i = 0; i < N_COLOR_LABELS; i++) {
1166 item = colorlabel_create_check_color_menu_item(
1167 i, refresh, MAINWIN_COLORMENU);
1168 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1169 g_signal_connect(G_OBJECT(item), "activate",
1170 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1171 GUINT_TO_POINTER(i + 1));
1172 g_object_set_data(G_OBJECT(item), "mainwin",
1174 gtk_widget_show(item);
1176 gtk_widget_add_accelerator(item, "activate",
1177 mainwin->menu_factory->accel_group,
1178 GDK_1+i, GDK_CONTROL_MASK,
1179 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1181 gtk_widget_show(menu);
1182 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1183 mainwin->colorlabel_menu = menu;
1186 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1189 MainWindow *mainwin;
1191 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1192 g_return_if_fail(mainwin != NULL);
1194 /* "dont_toggle" state set? */
1195 if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1199 tag_apply_open(summary_get_selection(mainwin->summaryview));
1202 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1204 GtkWidget *label_menuitem;
1207 GSList *cur = tags_get_list();
1209 gboolean existing_tags = FALSE;
1211 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1213 g_signal_connect(G_OBJECT(label_menuitem), "activate",
1214 G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1217 gtk_widget_show(label_menuitem);
1219 menu = gtk_menu_new();
1221 /* create tags menu items */
1222 for (; cur; cur = cur->next) {
1223 gint id = GPOINTER_TO_INT(cur->data);
1224 const gchar *tag = tags_get_tag(id);
1226 item = gtk_check_menu_item_new_with_label(tag);
1227 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1228 g_signal_connect(G_OBJECT(item), "activate",
1229 G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1230 GINT_TO_POINTER(id));
1231 g_object_set_data(G_OBJECT(item), "mainwin",
1233 g_object_set_data(G_OBJECT(item), "tag_id",
1234 GINT_TO_POINTER(id));
1235 gtk_widget_show(item);
1236 existing_tags = TRUE;
1238 if (existing_tags) {
1240 item = gtk_menu_item_new();
1241 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1242 gtk_widget_show(item);
1245 item = gtk_menu_item_new_with_label(_("Apply tags..."));
1246 gtk_widget_add_accelerator(item, "activate",
1247 mainwin->menu_factory->accel_group,
1248 GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
1249 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1250 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1251 g_signal_connect(G_OBJECT(item), "activate",
1252 G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1254 g_object_set_data(G_OBJECT(item), "mainwin",
1256 gtk_widget_show(item);
1259 gtk_widget_show(menu);
1260 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1261 mainwin->tags_menu = menu;
1264 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1265 MainWindow *mainwindow)
1267 if (evt && evt->button == 1) {
1268 log_window_show_error(mainwindow->logwin);
1269 gtk_widget_hide(mainwindow->warning_btn);
1274 static gboolean warning_visi_notify(GtkWidget *widget,
1275 GdkEventVisibility *event,
1276 MainWindow *mainwindow)
1278 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1282 static gboolean warning_leave_notify(GtkWidget *widget,
1283 GdkEventCrossing *event,
1284 MainWindow *mainwindow)
1286 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1290 static gboolean warning_enter_notify(GtkWidget *widget,
1291 GdkEventCrossing *event,
1292 MainWindow *mainwindow)
1294 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1298 void mainwindow_show_error(void)
1300 MainWindow *mainwin = mainwindow_get_mainwindow();
1301 gtk_widget_show(mainwin->warning_btn);
1304 void mainwindow_clear_error(MainWindow *mainwin)
1306 gtk_widget_hide(mainwin->warning_btn);
1309 MainWindow *main_window_create()
1311 MainWindow *mainwin;
1315 GtkWidget *handlebox;
1316 GtkWidget *vbox_body;
1318 GtkWidget *hbox_stat;
1319 GtkWidget *statusbar;
1320 GtkWidget *progressbar;
1321 GtkWidget *statuslabel;
1322 GtkWidget *ac_button;
1323 GtkWidget *ac_label;
1324 GtkWidget *online_pixmap;
1325 GtkWidget *offline_pixmap;
1327 GtkWidget *warning_icon;
1328 GtkWidget *warning_btn;
1330 GtkWidget *online_switch;
1331 GtkWidget *offline_switch;
1332 FolderView *folderview;
1333 SummaryView *summaryview;
1334 MessageView *messageview;
1335 GdkColormap *colormap;
1337 gboolean success[4];
1338 GtkItemFactory *ifactory;
1340 GtkWidget *menuitem;
1342 guint n_menu_entries;
1344 static GdkGeometry geometry;
1346 debug_print("Creating main window...\n");
1347 mainwin = g_new0(MainWindow, 1);
1350 window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1351 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1352 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1354 prefs_common.layout_mode = SMALL_LAYOUT;
1356 if (!geometry.min_height) {
1357 geometry.min_width = 320;
1358 geometry.min_height = 200;
1360 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1363 g_signal_connect(G_OBJECT(window), "delete_event",
1364 G_CALLBACK(main_window_close_cb), mainwin);
1365 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1366 g_signal_connect(G_OBJECT(window), "focus_in_event",
1367 G_CALLBACK(mainwindow_focus_in_event),
1369 g_signal_connect(G_OBJECT(window), "key_press_event",
1370 G_CALLBACK(mainwindow_key_pressed), mainwin);
1372 gtk_widget_realize(window);
1373 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1376 gtkut_widget_set_app_icon(window);
1378 vbox = gtk_vbox_new(FALSE, 0);
1379 gtk_widget_show(vbox);
1380 gtk_container_add(GTK_CONTAINER(window), vbox);
1383 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1384 menubar = menubar_create(window, mainwin_entries,
1385 n_menu_entries, "<Main>", mainwin);
1386 gtk_widget_show(menubar);
1389 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1392 ifactory = gtk_item_factory_from_widget(menubar);
1394 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1395 main_create_mailing_list_menu (mainwin, NULL); */
1397 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1399 if (prefs_common.toolbar_detachable) {
1400 handlebox = gtk_handle_box_new();
1401 gtk_widget_show(handlebox);
1402 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1403 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1404 G_CALLBACK(toolbar_child_attached), mainwin);
1405 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1406 G_CALLBACK(toolbar_child_detached), mainwin);
1408 handlebox = gtk_hbox_new(FALSE, 0);
1409 gtk_widget_show(handlebox);
1410 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1412 /* link window to mainwin->window to avoid gdk warnings */
1413 mainwin->window = window;
1414 mainwin_list = g_list_append(mainwin_list, mainwin);
1417 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1421 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1425 toolbar_set_learn_button
1429 /* vbox that contains body */
1430 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1431 gtk_widget_show(vbox_body);
1432 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1433 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1436 hbox_stat = gtk_hbox_new(FALSE, 2);
1437 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1439 tips = gtk_tooltips_new();
1441 warning_icon = gtk_image_new_from_stock
1442 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1443 warning_btn = gtk_event_box_new();
1444 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1446 mainwin->warning_btn = warning_btn;
1448 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1449 G_CALLBACK(warning_icon_pressed),
1450 (gpointer) mainwin);
1451 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1452 G_CALLBACK(warning_visi_notify), mainwin);
1453 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1454 G_CALLBACK(warning_visi_notify), mainwin);
1455 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1456 G_CALLBACK(warning_leave_notify), mainwin);
1457 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1458 G_CALLBACK(warning_enter_notify), mainwin);
1460 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1462 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1463 _("Some error(s) happened. Click here to view log."), NULL);
1464 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1466 statusbar = statusbar_create();
1467 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1469 progressbar = gtk_progress_bar_new();
1470 gtk_widget_set_size_request(progressbar, 120, 1);
1471 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1473 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1474 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1475 online_switch = gtk_button_new ();
1476 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1477 _("You are online. Click the icon to go offline"), NULL);
1478 offline_switch = gtk_button_new ();
1479 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1480 _("You are offline. Click the icon to go online"),
1482 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1483 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1484 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1485 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1486 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1487 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1488 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1489 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1491 statuslabel = gtk_label_new("");
1492 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1494 ac_button = gtk_button_new();
1495 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1496 ac_button, _("Select account"), NULL);
1497 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1498 gtk_widget_set_size_request(ac_button, -1, 0);
1499 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1500 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1501 G_CALLBACK(ac_label_button_pressed), mainwin);
1503 ac_label = gtk_label_new("");
1504 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1506 gtk_widget_show_all(hbox_stat);
1508 gtk_widget_hide(offline_switch);
1509 gtk_widget_hide(warning_btn);
1511 online_switch = gtk_button_new ();
1512 offline_switch = gtk_button_new ();
1513 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1514 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1517 mainwin->folderview = folderview = folderview_create();
1518 mainwin->summaryview = summaryview = summary_create();
1519 mainwin->messageview = messageview = messageview_create(mainwin);
1521 /* init log instances data before creating log views */
1522 set_log_title(LOG_PROTOCOL, _("Network log"));
1523 set_log_prefs(LOG_PROTOCOL,
1524 &prefs_common.logwin_width,
1525 &prefs_common.logwin_height);
1526 set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1527 set_log_prefs(LOG_DEBUG_FILTERING,
1528 &prefs_common.filtering_debugwin_width,
1529 &prefs_common.filtering_debugwin_height);
1531 /* setup log windows */
1532 mainwin->logwin = log_window_create(LOG_PROTOCOL);
1533 log_window_init(mainwin->logwin);
1535 mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1536 log_window_set_clipping(mainwin->logwin,
1537 prefs_common.cliplog,
1538 prefs_common.loglength);
1540 log_window_init(mainwin->filtering_debugwin);
1541 log_window_set_clipping(mainwin->filtering_debugwin,
1542 prefs_common.filtering_debug_cliplog,
1543 prefs_common.filtering_debug_loglength);
1544 if (prefs_common.enable_filtering_debug)
1545 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1547 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1549 folderview->mainwin = mainwin;
1550 folderview->summaryview = summaryview;
1552 summaryview->mainwin = mainwin;
1553 summaryview->folderview = folderview;
1554 summaryview->messageview = messageview;
1555 summaryview->window = window;
1557 mainwin->vbox = vbox;
1558 mainwin->menubar = menubar;
1559 mainwin->menu_factory = ifactory;
1560 mainwin->handlebox = handlebox;
1561 mainwin->vbox_body = vbox_body;
1562 mainwin->online_switch = online_switch;
1563 mainwin->offline_switch = offline_switch;
1565 messageview->statusbar = statusbar;
1566 mainwin->statusbar = statusbar;
1567 mainwin->hbox_stat = hbox_stat;
1568 mainwin->progressbar = progressbar;
1569 mainwin->statuslabel = statuslabel;
1570 mainwin->online_pixmap = online_pixmap;
1571 mainwin->offline_pixmap = offline_pixmap;
1572 mainwin->ac_button = ac_button;
1573 mainwin->ac_label = ac_label;
1574 /* set context IDs for status bar */
1575 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1576 (GTK_STATUSBAR(statusbar), "Main Window");
1577 mainwin->folderview_cid = gtk_statusbar_get_context_id
1578 (GTK_STATUSBAR(statusbar), "Folder View");
1579 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1580 (GTK_STATUSBAR(statusbar), "Summary View");
1581 mainwin->messageview_cid = gtk_statusbar_get_context_id
1582 (GTK_STATUSBAR(statusbar), "Message View");
1583 messageview->statusbar_cid = mainwin->messageview_cid;
1586 messageview->statusbar = NULL;
1587 mainwin->statusbar = NULL;
1588 mainwin->hbox_stat = NULL;
1589 /* mainwin->progressbar is set in toolbar.c */
1590 mainwin->statuslabel = NULL;
1591 mainwin->online_pixmap = NULL;
1592 mainwin->offline_pixmap = NULL;
1593 mainwin->ac_button = NULL;
1594 mainwin->ac_label = NULL;
1597 /* allocate colors for summary view and folder view */
1598 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1599 summaryview->color_marked.blue = (guint16)65535;
1601 summaryview->color_dim.red = summaryview->color_dim.green =
1602 summaryview->color_dim.blue = COLOR_DIM;
1604 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1605 &folderview->color_new);
1607 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1608 &folderview->color_op);
1610 summaryview->color_important.red = 0;
1611 summaryview->color_important.green = 0;
1612 summaryview->color_important.blue = (guint16)65535;
1614 color[0] = summaryview->color_marked;
1615 color[1] = summaryview->color_dim;
1616 color[2] = folderview->color_new;
1617 color[3] = folderview->color_op;
1619 colormap = gdk_drawable_get_colormap(window->window);
1620 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1621 for (i = 0; i < 4; i++) {
1622 if (success[i] == FALSE)
1623 g_warning("MainWindow: color allocation %d failed\n", i);
1626 debug_print("done.\n");
1628 messageview->visible = prefs_common.msgview_visible;
1630 main_window_set_widgets(mainwin, prefs_common.layout_mode);
1632 g_signal_connect(G_OBJECT(window), "size_allocate",
1633 G_CALLBACK(main_window_size_allocate_cb),
1636 /* set menu items */
1637 menuitem = gtk_item_factory_get_item
1638 (ifactory, "/View/Character encoding/Auto detect");
1639 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1641 switch (prefs_common.toolbar_style) {
1643 menuitem = gtk_item_factory_get_item
1644 (ifactory, "/View/Show or hide/Toolbar/Hide");
1647 menuitem = gtk_item_factory_get_item
1648 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1651 menuitem = gtk_item_factory_get_item
1652 (ifactory, "/View/Show or hide/Toolbar/Text only");
1655 menuitem = gtk_item_factory_get_item
1656 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1658 case TOOLBAR_BOTH_HORIZ:
1659 menuitem = gtk_item_factory_get_item
1661 "/View/Show or hide/Toolbar/Text beside icons");
1663 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1666 gtk_widget_hide(mainwin->hbox_stat);
1667 menuitem = gtk_item_factory_get_item
1668 (ifactory, "/View/Show or hide/Status bar");
1669 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1670 prefs_common.show_statusbar);
1672 /* set account selection menu */
1673 ac_menu = gtk_item_factory_get_widget
1674 (ifactory, "/Configuration/Change current account");
1675 mainwin->ac_menu = ac_menu;
1677 toolbar_main_set_sensitive(mainwin);
1679 /* create actions menu */
1680 main_window_update_actions_menu(mainwin);
1682 main_create_mailing_list_menu (mainwin, NULL);
1684 /* attach accel groups to main window */
1685 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1686 gtk_window_add_accel_group \
1688 gtk_item_factory_from_widget(menu)->accel_group); \
1689 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1691 G_CALLBACK(main_window_accel_activate), mainwin);
1694 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1696 /* connect the accelerators for equivalent
1697 menu items in different menus */
1698 menu_connect_identical_items();
1701 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1704 g_signal_connect(G_OBJECT(window), "window_state_event",
1705 G_CALLBACK(mainwindow_state_event_cb), mainwin);
1706 g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1707 G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1708 gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1710 if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1711 prefs_common.layout_mode == SMALL_LAYOUT) {
1712 summary_relayout(mainwin->summaryview);
1714 summary_update_unread(mainwin->summaryview, NULL);
1716 gtk_widget_show(mainwin->window);
1718 /* initialize views */
1719 folderview_init(folderview);
1720 summary_init(summaryview);
1721 messageview_init(messageview);
1723 sslcertwindow_register_hook();
1725 mainwin->lock_count = 0;
1726 mainwin->menu_lock_count = 0;
1727 mainwin->cursor_count = 0;
1729 mainwin->progressindicator_hook =
1730 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1733 watch_cursor = gdk_cursor_new(GDK_WATCH);
1735 hand_cursor = gdk_cursor_new(GDK_HAND2);
1737 /* init work_offline */
1738 if (prefs_common.work_offline)
1739 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1741 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1742 mainwindow_tags_menu_create(mainwin, FALSE);
1747 void main_window_destroy(MainWindow *mainwin)
1749 /* TODO : destroy other component */
1750 messageview_destroy(mainwin->messageview);
1751 mainwin->messageview = NULL;
1754 void main_window_update_actions_menu(MainWindow *mainwin)
1756 GtkItemFactory *ifactory;
1758 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1759 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1762 void main_window_cursor_wait(MainWindow *mainwin)
1765 if (mainwin->cursor_count == 0) {
1766 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1767 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1770 mainwin->cursor_count++;
1775 void main_window_cursor_normal(MainWindow *mainwin)
1777 if (mainwin->cursor_count)
1778 mainwin->cursor_count--;
1780 if (mainwin->cursor_count == 0) {
1781 gdk_window_set_cursor(mainwin->window->window, NULL);
1782 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1787 /* lock / unlock the user-interface */
1788 void main_window_lock(MainWindow *mainwin)
1790 if (mainwin->lock_count == 0 && mainwin->ac_button)
1791 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1793 mainwin->lock_count++;
1795 main_window_set_menu_sensitive(mainwin);
1796 toolbar_main_set_sensitive(mainwin);
1799 void main_window_unlock(MainWindow *mainwin)
1801 if (mainwin->lock_count)
1802 mainwin->lock_count--;
1804 main_window_set_menu_sensitive(mainwin);
1805 toolbar_main_set_sensitive(mainwin);
1807 if (mainwin->lock_count == 0 && mainwin->ac_button)
1808 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1811 static void main_window_menu_callback_block(MainWindow *mainwin)
1813 mainwin->menu_lock_count++;
1816 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1818 if (mainwin->menu_lock_count)
1819 mainwin->menu_lock_count--;
1822 static guint prefs_tag = 0;
1824 void main_window_reflect_prefs_all(void)
1826 main_window_reflect_prefs_all_real(FALSE);
1829 static gboolean reflect_prefs_timeout_cb(gpointer data)
1831 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1833 MainWindow *mainwin;
1836 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1837 mainwin = (MainWindow *)cur->data;
1839 main_window_show_cur_account(mainwin);
1840 main_window_set_menu_sensitive(mainwin);
1841 toolbar_main_set_sensitive(mainwin);
1844 if (pixmap_theme_changed) {
1845 toolbar_update(TOOLBAR_MAIN, mainwin);
1846 messageview_reflect_prefs_pixmap_theme();
1847 compose_reflect_prefs_pixmap_theme();
1848 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1849 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1851 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1852 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1853 mainwin->online_pixmap);
1854 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1855 gtk_widget_show(pixmap);
1856 mainwin->online_pixmap = pixmap;
1857 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1858 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1859 mainwin->offline_pixmap);
1860 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1861 gtk_widget_show(pixmap);
1862 mainwin->offline_pixmap = pixmap;
1866 headerview_set_font(mainwin->messageview->headerview);
1867 headerview_set_visibility(mainwin->messageview->headerview,
1868 prefs_common.display_header_pane);
1869 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1870 folderview_reflect_prefs();
1871 summary_reflect_prefs();
1873 summary_redisplay_msg(mainwin->summaryview);
1875 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1876 if (mainwin->in_folder) {
1877 mainwindow_enter_folder(mainwin);
1879 mainwindow_exit_folder(mainwin);
1887 void main_window_reflect_prefs_all_now(void)
1889 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1892 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1897 /* re-create colorlabel submenu */
1898 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1899 g_return_if_fail(menu != NULL);
1901 /* clear items. get item pointers. */
1902 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1903 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1905 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1906 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1910 void main_window_reflect_tags_changes(MainWindow *mainwin)
1915 /* re-create tags submenu */
1916 menu = GTK_MENU_SHELL(mainwin->tags_menu);
1917 g_return_if_fail(menu != NULL);
1919 /* clear items. get item pointers. */
1920 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1921 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1923 mainwindow_tags_menu_create(mainwin, TRUE);
1924 summary_reflect_tags_changes(mainwin->summaryview);
1928 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1930 if (prefs_tag == 0 || pixmap_theme_changed) {
1931 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1932 GINT_TO_POINTER(pixmap_theme_changed));
1936 void main_window_set_summary_column(void)
1939 MainWindow *mainwin;
1941 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1942 mainwin = (MainWindow *)cur->data;
1943 summary_set_column_order(mainwin->summaryview);
1947 void main_window_set_folder_column(void)
1950 MainWindow *mainwin;
1952 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1953 mainwin = (MainWindow *)cur->data;
1954 folderview_set_column_order(mainwin->folderview);
1958 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1959 GList *account_list)
1961 GList *cur_ac, *cur_item;
1962 GtkWidget *menuitem;
1963 PrefsAccount *ac_prefs;
1965 /* destroy all previous menu item */
1966 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1967 while (cur_item != NULL) {
1968 GList *next = cur_item->next;
1969 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1973 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1974 ac_prefs = (PrefsAccount *)cur_ac->data;
1976 menuitem = gtk_menu_item_new_with_label
1977 (ac_prefs->account_name
1978 ? ac_prefs->account_name : _("Untitled"));
1979 gtk_widget_show(menuitem);
1980 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1981 g_signal_connect(G_OBJECT(menuitem), "activate",
1982 G_CALLBACK(account_selector_menu_cb),
1987 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1988 GList *account_list)
1990 GList *cur_ac, *cur_item;
1992 GtkWidget *menuitem;
1993 PrefsAccount *ac_prefs;
1995 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1996 "/Message/Receive");
1998 /* search for separator */
1999 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2000 cur_item = cur_item->next) {
2001 if (GTK_BIN(cur_item->data)->child == NULL) {
2002 cur_item = cur_item->next;
2007 /* destroy all previous menu item */
2008 while (cur_item != NULL) {
2009 GList *next = cur_item->next;
2010 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2014 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2015 ac_prefs = (PrefsAccount *)cur_ac->data;
2017 menuitem = gtk_menu_item_new_with_label
2018 (ac_prefs->account_name ? ac_prefs->account_name
2020 gtk_widget_show(menuitem);
2021 gtk_menu_append(GTK_MENU(menu), menuitem);
2022 g_signal_connect(G_OBJECT(menuitem), "activate",
2023 G_CALLBACK(account_receive_menu_cb),
2028 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2029 GList *account_list)
2032 GtkWidget *menuitem;
2033 PrefsAccount *ac_prefs;
2034 GtkWidget *menu = NULL;
2036 if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2039 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2041 gtk_widget_destroy(menu);
2042 menu = gtk_menu_new();
2044 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2045 ac_prefs = (PrefsAccount *)cur_ac->data;
2047 menuitem = gtk_menu_item_new_with_label
2048 (ac_prefs->account_name
2049 ? ac_prefs->account_name : _("Untitled"));
2050 gtk_widget_show(menuitem);
2051 gtk_menu_append(GTK_MENU(menu), menuitem);
2052 g_signal_connect(G_OBJECT(menuitem), "activate",
2053 G_CALLBACK(account_receive_menu_cb),
2056 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2059 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2060 GList *account_list)
2064 GtkWidget *menuitem;
2065 PrefsAccount *ac_prefs;
2066 GtkWidget *menu = NULL;
2068 if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2071 menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2073 gtk_widget_destroy(menu);
2074 menu = gtk_menu_new();
2076 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2077 ac_prefs = (PrefsAccount *)cur_ac->data;
2079 menuitem = gtk_menu_item_new_with_label
2080 (ac_prefs->account_name
2081 ? ac_prefs->account_name : _("Untitled"));
2082 gtk_widget_show(menuitem);
2083 gtk_menu_append(GTK_MENU(menu), menuitem);
2084 g_signal_connect(G_OBJECT(menuitem), "activate",
2085 G_CALLBACK(account_compose_menu_cb),
2088 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2092 void main_window_set_account_menu(GList *account_list)
2095 MainWindow *mainwin;
2097 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2098 mainwin = (MainWindow *)cur->data;
2099 main_window_set_account_selector_menu(mainwin, account_list);
2100 main_window_set_account_receive_menu(mainwin, account_list);
2101 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2102 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2104 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2107 void main_window_set_account_menu_only_toolbar(GList *account_list)
2110 MainWindow *mainwin;
2112 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2113 mainwin = (MainWindow *)cur->data;
2114 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2115 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2119 static void main_window_show_cur_account(MainWindow *mainwin)
2124 ac_name = g_strdup(cur_account
2125 ? (cur_account->account_name
2126 ? cur_account->account_name : _("Untitled"))
2130 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2132 buf = g_strdup(PROG_VERSION);
2133 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2136 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2137 if (mainwin->ac_button)
2138 gtk_widget_queue_resize(mainwin->ac_button);
2143 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2145 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
2146 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2147 GtkWidget *message_wid = mainwin->messageview->vbox;
2149 if (layout_mode == prefs_common.layout_mode)
2152 debug_print("Changing window separation type from %d to %d\n",
2153 prefs_common.layout_mode, layout_mode);
2155 /* remove widgets from those containers */
2156 gtk_widget_ref(folder_wid);
2157 gtk_widget_ref(summary_wid);
2158 gtk_widget_ref(message_wid);
2159 gtkut_container_remove
2160 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2161 gtkut_container_remove
2162 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2163 gtkut_container_remove
2164 (GTK_CONTAINER(message_wid->parent), message_wid);
2166 gtk_widget_hide(mainwin->window);
2167 main_window_set_widgets(mainwin, layout_mode);
2168 gtk_widget_show(mainwin->window);
2170 gtk_widget_unref(folder_wid);
2171 gtk_widget_unref(summary_wid);
2172 gtk_widget_unref(message_wid);
2175 void mainwindow_reset_paned(GtkPaned *paned)
2179 if (gtk_paned_get_child1(GTK_PANED(paned)))
2180 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2181 if (gtk_paned_get_child2(GTK_PANED(paned)))
2182 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2185 g_object_get (G_OBJECT(paned),
2188 g_object_get (G_OBJECT(paned),
2192 gtk_paned_set_position(GTK_PANED(paned), mid);
2195 static void mainwin_paned_show_first(GtkPaned *paned)
2198 g_object_get (G_OBJECT(paned),
2202 if (gtk_paned_get_child1(GTK_PANED(paned)))
2203 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2204 if (gtk_paned_get_child2(GTK_PANED(paned)))
2205 gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2206 gtk_paned_set_position(GTK_PANED(paned), max);
2209 static void mainwin_paned_show_last(GtkPaned *paned)
2212 g_object_get (G_OBJECT(paned),
2216 if (gtk_paned_get_child1(GTK_PANED(paned)))
2217 gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2218 if (gtk_paned_get_child2(GTK_PANED(paned)))
2219 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2220 gtk_paned_set_position(GTK_PANED(paned), min);
2223 void main_window_toggle_message_view(MainWindow *mainwin)
2225 SummaryView *summaryview = mainwin->summaryview;
2226 GtkWidget *ppaned = NULL;
2227 GtkWidget *container = NULL;
2229 switch (prefs_common.layout_mode) {
2231 case VERTICAL_LAYOUT:
2233 ppaned = mainwin->vpaned;
2234 container = mainwin->hpaned;
2235 if (ppaned->parent != NULL) {
2236 mainwin->messageview->visible = FALSE;
2237 summaryview->displayed = NULL;
2238 gtk_widget_ref(ppaned);
2239 gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2240 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2242 mainwin->messageview->visible = TRUE;
2243 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2244 gtk_container_add(GTK_CONTAINER(container), ppaned);
2245 gtk_widget_unref(ppaned);
2249 ppaned = mainwin->hpaned;
2250 container = mainwin->vpaned;
2251 if (mainwin->messageview->vbox->parent != NULL) {
2252 mainwin->messageview->visible = FALSE;
2253 summaryview->displayed = NULL;
2254 gtk_widget_ref(mainwin->messageview->vbox);
2255 gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2257 mainwin->messageview->visible = TRUE;
2258 gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2259 gtk_widget_unref(mainwin->messageview->vbox);
2262 case WIDE_MSGLIST_LAYOUT:
2263 g_warning("can't hide messageview in this wide msglist layout");
2267 if (messageview_is_visible(mainwin->messageview))
2268 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2269 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2271 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2272 GTK_ARROW_UP, GTK_SHADOW_OUT);
2274 if (mainwin->messageview->visible == FALSE)
2275 messageview_clear(mainwin->messageview);
2277 main_window_set_menu_sensitive(mainwin);
2279 prefs_common.msgview_visible = mainwin->messageview->visible;
2281 if (messageview_is_visible(mainwin->messageview)) {
2282 gtk_widget_queue_resize(mainwin->hpaned);
2283 gtk_widget_queue_resize(mainwin->vpaned);
2285 summary_grab_focus(summaryview);
2288 void main_window_get_size(MainWindow *mainwin)
2290 GtkAllocation *allocation;
2292 if (mainwin_list == NULL || mainwin->messageview == NULL) {
2293 debug_print("called after messageview "
2294 "has been deallocated!\n");
2298 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2300 if (allocation->width > 1 && allocation->height > 1) {
2301 prefs_common.summaryview_width = allocation->width;
2303 if (messageview_is_visible(mainwin->messageview))
2304 prefs_common.summaryview_height = allocation->height;
2306 prefs_common.mainview_width = allocation->width;
2309 allocation = &mainwin->window->allocation;
2310 if (allocation->width > 1 && allocation->height > 1) {
2311 prefs_common.mainview_height = allocation->height;
2312 prefs_common.mainwin_width = allocation->width;
2313 prefs_common.mainwin_height = allocation->height;
2316 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2317 if (allocation->width > 1 && allocation->height > 1) {
2318 prefs_common.folderview_width = allocation->width;
2319 prefs_common.folderview_height = allocation->height;
2322 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2323 if (allocation->width > 1 && allocation->height > 1) {
2324 prefs_common.msgview_width = allocation->width;
2325 prefs_common.msgview_height = allocation->height;
2328 /* debug_print("summaryview size: %d x %d\n",
2329 prefs_common.summaryview_width,
2330 prefs_common.summaryview_height);
2331 debug_print("folderview size: %d x %d\n",
2332 prefs_common.folderview_width,
2333 prefs_common.folderview_height);
2334 debug_print("messageview size: %d x %d\n",
2335 prefs_common.msgview_width,
2336 prefs_common.msgview_height); */
2339 void main_window_get_position(MainWindow *mainwin)
2343 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2345 prefs_common.mainview_x = x;
2346 prefs_common.mainview_y = y;
2347 prefs_common.mainwin_x = x;
2348 prefs_common.mainwin_y = y;
2350 debug_print("main window position: %d, %d\n", x, y);
2353 void main_window_progress_on(MainWindow *mainwin)
2355 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2358 void main_window_progress_off(MainWindow *mainwin)
2360 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2361 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2364 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2368 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2369 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2370 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2371 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2374 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2376 if (confirm && procmsg_have_trashed_mails_fast()) {
2377 if (alertpanel(_("Empty trash"),
2378 _("Delete all messages in trash folders?"),
2379 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2380 != G_ALERTALTERNATE)
2382 manage_window_focus_in(mainwin->window, NULL, NULL);
2385 procmsg_empty_all_trash();
2387 if (mainwin->summaryview->folder_item &&
2388 mainwin->summaryview->folder_item->stype == F_TRASH)
2389 gtk_widget_grab_focus(mainwin->folderview->ctree);
2392 void main_window_add_mailbox(MainWindow *mainwin)
2397 path = input_dialog(_("Add mailbox"),
2398 _("Input the location of mailbox.\n"
2399 "If an existing mailbox is specified, it will be\n"
2400 "scanned automatically."),
2403 if (folder_find_from_path(path)) {
2404 alertpanel_error(_("The mailbox '%s' already exists."), path);
2408 folder = folder_new(folder_get_class_from_string("mh"),
2409 !strcmp(path, "Mail") ? _("Mailbox") :
2410 g_path_get_basename(path), path);
2413 if (folder->klass->create_tree(folder) < 0) {
2414 alertpanel_error(_("Creation of the mailbox failed.\n"
2415 "Maybe some files already exist, or you don't have the permission to write there."));
2416 folder_destroy(folder);
2421 folder_set_ui_func(folder, scan_tree_func, mainwin);
2422 folder_scan_tree(folder, TRUE);
2423 folder_set_ui_func(folder, NULL, NULL);
2426 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2428 SensitiveCond state = 0;
2429 SummarySelection selection;
2430 FolderItem *item = mainwin->summaryview->folder_item;
2431 GList *account_list = account_get_list();
2434 selection = summary_get_selection_type(mainwin->summaryview);
2436 if (mainwin->lock_count == 0)
2437 state |= M_UNLOCKED;
2438 if (selection != SUMMARY_NONE)
2439 state |= M_MSG_EXIST;
2440 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2442 /* if (item->folder->type != F_NEWS) */
2443 state |= M_ALLOW_DELETE;
2445 if (prefs_common.immediate_exec == 0
2446 && mainwin->lock_count == 0)
2447 state |= M_DELAY_EXEC;
2449 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2450 || selection != SUMMARY_NONE)
2451 state |= M_HIDE_READ_MSG;
2453 if (mainwin->summaryview->threaded)
2454 state |= M_THREADED;
2456 state |= M_UNTHREADED;
2457 if (selection == SUMMARY_SELECTED_SINGLE ||
2458 selection == SUMMARY_SELECTED_MULTIPLE)
2459 state |= M_TARGET_EXIST;
2460 if (selection == SUMMARY_SELECTED_SINGLE)
2461 state |= M_SINGLE_TARGET_EXIST;
2462 if (mainwin->summaryview->folder_item &&
2463 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2466 state |= M_NOT_NEWS;
2467 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2468 state |= M_ACTIONS_EXIST;
2470 tmp = tags_get_list();
2471 if (tmp && g_slist_length(tmp))
2472 state |= M_TAGS_EXIST;
2475 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2476 state |= M_HAVE_QUEUED_MAILS;
2478 if (selection == SUMMARY_SELECTED_SINGLE &&
2480 (folder_has_parent_of_type(item, F_DRAFT) ||
2481 folder_has_parent_of_type(item, F_OUTBOX) ||
2482 folder_has_parent_of_type(item, F_QUEUE))))
2483 state |= M_ALLOW_REEDIT;
2485 state |= M_HAVE_ACCOUNT;
2487 if (any_folder_want_synchronise())
2488 state |= M_WANT_SYNC;
2490 for ( ; account_list != NULL; account_list = account_list->next) {
2491 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2492 state |= M_HAVE_NEWS_ACCOUNT;
2497 if (procmsg_spam_can_learn() &&
2498 (mainwin->summaryview->folder_item &&
2499 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2500 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2501 state |= M_CAN_LEARN_SPAM;
2504 if (inc_is_active())
2505 state |= M_INC_ACTIVE;
2506 if (imap_cancel_all_enabled())
2507 state |= M_INC_ACTIVE;
2509 if (mainwin->summaryview->deleted > 0 ||
2510 mainwin->summaryview->moved > 0 ||
2511 mainwin->summaryview->copied > 0)
2512 state |= M_DELAY_EXEC;
2519 void main_window_set_menu_sensitive(MainWindow *mainwin)
2521 GtkItemFactory *ifactory = mainwin->menu_factory;
2522 SensitiveCond state;
2525 GtkWidget *menuitem;
2526 SummaryView *summaryview;
2531 static const struct {
2535 {"/File/Save as...", M_TARGET_EXIST},
2536 {"/File/Print..." , M_TARGET_EXIST},
2537 {"/File/Synchronise folders", M_WANT_SYNC},
2538 {"/File/Exit" , M_UNLOCKED},
2540 {"/Edit/Select thread" , M_TARGET_EXIST},
2541 {"/Edit/Delete thread" , M_TARGET_EXIST},
2542 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2544 {"/View/Set displayed columns/in Folder list..."
2546 {"/View/Sort" , M_EXEC},
2547 {"/View/Thread view" , M_EXEC},
2548 {"/View/Expand all threads" , M_MSG_EXIST},
2549 {"/View/Collapse all threads" , M_MSG_EXIST},
2550 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2551 {"/View/Go to/Previous message" , M_MSG_EXIST},
2552 {"/View/Go to/Next message" , M_MSG_EXIST},
2553 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2554 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2555 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2556 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2557 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2558 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2559 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2560 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2561 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2562 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2563 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2565 {"/Message/Receive/Get from current account"
2566 , M_HAVE_ACCOUNT|M_UNLOCKED},
2567 {"/Message/Receive/Get from all accounts"
2568 , M_HAVE_ACCOUNT|M_UNLOCKED},
2569 {"/Message/Receive/Cancel receiving"
2571 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2572 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2573 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2574 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2575 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2576 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2577 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2578 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2579 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2580 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2581 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2582 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2583 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2584 {"/Message/Mark" , M_TARGET_EXIST},
2585 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2586 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2587 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2588 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2589 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2590 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2591 {"/Message/Color label" , M_TARGET_EXIST},
2592 {"/Message/Tags" , M_TARGET_EXIST},
2593 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2595 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2596 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2597 {"/Tools/Harvest addresses/from Messages..."
2599 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2600 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2601 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2602 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2603 {"/Tools/List URLs..." , M_TARGET_EXIST},
2604 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2605 {"/Tools/Execute" , M_DELAY_EXEC},
2606 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2608 {"/Configuration", M_UNLOCKED},
2609 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2610 {"/Configuration/Create new account...", M_UNLOCKED},
2611 {"/Configuration/Edit accounts...", M_UNLOCKED},
2616 state = main_window_get_current_state(mainwin);
2618 for (i = 0; entry[i].entry != NULL; i++) {
2619 sensitive = ((entry[i].cond & state) == entry[i].cond);
2620 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2623 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2625 /* search for separator */
2626 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2627 cur_item = cur_item->next) {
2628 if (GTK_BIN(cur_item->data)->child == NULL) {
2629 cur_item = cur_item->next;
2634 for (; cur_item != NULL; cur_item = cur_item->next) {
2635 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2636 (M_UNLOCKED & state) != 0);
2639 main_window_menu_callback_block(mainwin);
2641 #define SET_CHECK_MENU_ACTIVE(path, active) \
2643 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2644 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2647 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2648 messageview_is_visible(mainwin->messageview));
2650 summaryview = mainwin->summaryview;
2651 menu_path = "/View/Sort/Don't sort";
2653 switch (summaryview->sort_key) {
2654 case SORT_BY_NUMBER:
2655 menu_path = "/View/Sort/by number"; break;
2657 menu_path = "/View/Sort/by Size"; break;
2659 menu_path = "/View/Sort/by Date"; break;
2660 case SORT_BY_THREAD_DATE:
2661 menu_path = "/View/Sort/by Thread date"; break;
2663 menu_path = "/View/Sort/by From"; break;
2665 menu_path = "/View/Sort/by To"; break;
2666 case SORT_BY_SUBJECT:
2667 menu_path = "/View/Sort/by Subject"; break;
2669 menu_path = "/View/Sort/by color label"; break;
2671 menu_path = "/View/Sort/by mark"; break;
2672 case SORT_BY_STATUS:
2673 menu_path = "/View/Sort/by status"; break;
2675 menu_path = "/View/Sort/by attachment"; break;
2677 menu_path = "/View/Sort/by score"; break;
2678 case SORT_BY_LOCKED:
2679 menu_path = "/View/Sort/by locked"; break;
2681 menu_path = "/View/Sort/by tag"; break;
2684 menu_path = "/View/Sort/Don't sort"; break;
2686 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2688 if (summaryview->sort_type == SORT_ASCENDING) {
2689 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2691 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2694 if (summaryview->sort_key != SORT_BY_NONE) {
2695 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2696 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2698 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2699 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2702 if (mainwin->messageview
2703 && mainwin->messageview->mimeview
2704 && mainwin->messageview->mimeview->textview)
2705 SET_CHECK_MENU_ACTIVE("/View/All headers",
2706 mainwin->messageview->mimeview->textview->show_all_headers);
2707 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2708 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2709 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2710 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2711 if (prefs_common.hide_quotes == 1)
2712 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2713 if (prefs_common.hide_quotes == 2)
2714 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2715 if (prefs_common.hide_quotes == 3)
2716 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2718 #undef SET_CHECK_MENU_ACTIVE
2720 main_window_menu_callback_unblock(mainwin);
2723 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2725 GtkItemFactory *ifactory;
2727 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2730 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2732 gtk_widget_set_sensitive (gtk_item_factory_get_item
2733 (ifactory,"/Message/Mailing-List"), TRUE);
2735 gtk_widget_set_sensitive (gtk_item_factory_get_item
2736 (ifactory,"/Message/Mailing-List"), FALSE);
2739 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2742 GtkWidget *menuitem;
2744 if (!msginfo || !msginfo->extradata) {
2745 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2746 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2747 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2748 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2749 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2750 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2754 /* Mailing list post */
2755 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2756 g_free(msginfo->extradata->list_post);
2757 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2759 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2761 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2763 /* Mailing list help */
2764 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2766 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2768 /* Mailing list subscribe */
2769 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2771 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2773 /* Mailing list unsubscribe */
2774 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2776 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2778 /* Mailing list view archive */
2779 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2781 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2783 /* Mailing list contact owner */
2784 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2786 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2791 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2793 GtkWidget *item, *menu;
2794 const gchar *url_pt ;
2795 gchar url_decoded[BUFFSIZE];
2796 GList *amenu, *alist;
2799 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2801 /* First delete old submenu */
2802 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2803 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2804 alist = amenu->next;
2805 item = GTK_WIDGET (amenu->data);
2806 gtk_widget_destroy (item);
2810 for (url_pt = list_header; url_pt && *url_pt;) {
2811 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2813 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2814 item = gtk_menu_item_new_with_label ((url_decoded));
2815 g_signal_connect(G_OBJECT(item), "activate",
2816 G_CALLBACK(mailing_list_compose),
2819 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2820 !g_strncasecmp (url_decoded, "https:",6)) {
2822 item = gtk_menu_item_new_with_label ((url_decoded));
2823 g_signal_connect(G_OBJECT(item), "activate",
2824 G_CALLBACK(mailing_list_open_uri),
2828 gtk_menu_append (GTK_MENU(menu), item);
2829 gtk_widget_show (item);
2835 gtk_widget_set_sensitive (menuitem, TRUE);
2837 gtk_widget_set_sensitive (menuitem, FALSE);
2843 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2845 gchar tmp[BUFFSIZE];
2849 gboolean with_plus = TRUE;
2852 *url_decoded = '\0';
2856 /* Ignore spaces, comments and tabs () */
2857 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2859 for (;*buf != ')' && *buf != 0x00; buf++);
2861 /* First non space and non comment must be a < */
2864 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2866 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2871 *url_decoded = '\0';
2876 *url_decoded = '\0';
2882 decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2884 /* Prepare the work for the next url in the list */
2885 /* after the closing bracket >, ignore space, comments and tabs */
2886 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2888 for (;*buf != ')' && *buf != 0x00; buf++);
2890 if (!buf || !*buf) {
2895 /* now first non space, non comment must be a comma */
2897 for (;*buf != 0x00; buf++);
2903 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2907 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2908 compose_new(NULL, mailto+7, NULL);
2911 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2916 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2917 open_uri (mailto, prefs_common.uri_cmd);
2920 void main_window_popup(MainWindow *mainwin)
2922 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2923 main_window_show(mainwin);
2925 gtkut_window_popup(mainwin->window);
2926 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2927 if (mainwin->in_folder) {
2928 mainwindow_enter_folder(mainwin);
2930 mainwindow_exit_folder(mainwin);
2935 void main_window_show(MainWindow *mainwin)
2937 gtk_widget_show(mainwin->window);
2938 gtk_widget_show(mainwin->vbox_body);
2940 gtk_widget_set_uposition(mainwin->window,
2941 prefs_common.mainwin_x,
2942 prefs_common.mainwin_y);
2944 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2945 prefs_common.folderview_width,
2946 prefs_common.folderview_height);
2947 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2948 prefs_common.summaryview_width,
2949 prefs_common.summaryview_height);
2950 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2951 prefs_common.msgview_width,
2952 prefs_common.msgview_height);
2955 void main_window_hide(MainWindow *mainwin)
2957 main_window_get_size(mainwin);
2958 main_window_get_position(mainwin);
2960 gtk_widget_hide(mainwin->window);
2961 gtk_widget_hide(mainwin->vbox_body);
2964 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2966 GtkWidget *folderwin = NULL;
2967 GtkWidget *messagewin = NULL;
2970 GtkWidget *vbox_body = mainwin->vbox_body;
2971 GtkItemFactory *ifactory = mainwin->menu_factory;
2972 GtkWidget *menuitem;
2973 gboolean first_set = (mainwin->hpaned == NULL);
2974 debug_print("Setting widgets... ");
2976 if (layout_mode == SMALL_LAYOUT && first_set) {
2977 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2978 prefs_common.folderview_width,
2979 prefs_common.folderview_height);
2980 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2982 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2985 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2986 prefs_common.folderview_width,
2987 prefs_common.folderview_height);
2988 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2989 prefs_common.summaryview_width,
2990 prefs_common.summaryview_height);
2991 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2992 prefs_common.msgview_width,
2993 prefs_common.msgview_height);
2997 mainwin->messageview->statusbar = mainwin->statusbar;
2998 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3000 /* clean top-most container */
3001 if (mainwin->hpaned) {
3002 if (mainwin->hpaned->parent == mainwin->vpaned)
3003 gtk_widget_destroy(mainwin->vpaned);
3005 gtk_widget_destroy(mainwin->hpaned);
3008 menu_set_sensitive(ifactory, "/View/Show or hide/Message view",
3009 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3010 switch (layout_mode) {
3011 case VERTICAL_LAYOUT:
3014 hpaned = gtk_hpaned_new();
3015 if (layout_mode == VERTICAL_LAYOUT)
3016 vpaned = gtk_hpaned_new();
3018 vpaned = gtk_vpaned_new();
3019 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3020 gtk_paned_add1(GTK_PANED(hpaned),
3021 GTK_WIDGET_PTR(mainwin->folderview));
3022 gtk_widget_show(hpaned);
3023 gtk_widget_queue_resize(hpaned);
3025 if (messageview_is_visible(mainwin->messageview)) {
3026 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3027 gtk_paned_add1(GTK_PANED(vpaned),
3028 GTK_WIDGET_PTR(mainwin->summaryview));
3030 gtk_paned_add2(GTK_PANED(hpaned),
3031 GTK_WIDGET_PTR(mainwin->summaryview));
3032 gtk_widget_ref(vpaned);
3034 gtk_paned_add2(GTK_PANED(vpaned),
3035 GTK_WIDGET_PTR(mainwin->messageview));
3036 gtk_widget_show(vpaned);
3037 if (layout_mode == SMALL_LAYOUT && first_set) {
3038 mainwin_paned_show_first(GTK_PANED(hpaned));
3040 gtk_widget_queue_resize(vpaned);
3043 vpaned = gtk_vpaned_new();
3044 hpaned = gtk_hpaned_new();
3045 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3046 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3048 gtk_paned_add1(GTK_PANED(hpaned),
3049 GTK_WIDGET_PTR(mainwin->folderview));
3050 gtk_paned_add2(GTK_PANED(hpaned),
3051 GTK_WIDGET_PTR(mainwin->summaryview));
3053 gtk_widget_show(hpaned);
3054 gtk_widget_queue_resize(hpaned);
3056 if (messageview_is_visible(mainwin->messageview)) {
3057 gtk_paned_add2(GTK_PANED(vpaned),
3058 GTK_WIDGET_PTR(mainwin->messageview));
3060 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3062 gtk_widget_show(vpaned);
3063 gtk_widget_queue_resize(vpaned);
3065 case WIDE_MSGLIST_LAYOUT:
3066 vpaned = gtk_vpaned_new();
3067 hpaned = gtk_hpaned_new();
3068 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3070 gtk_paned_add1(GTK_PANED(vpaned),
3071 GTK_WIDGET_PTR(mainwin->summaryview));
3072 gtk_paned_add1(GTK_PANED(hpaned),
3073 GTK_WIDGET_PTR(mainwin->folderview));
3075 gtk_widget_show(hpaned);
3076 gtk_widget_queue_resize(hpaned);
3078 if (messageview_is_visible(mainwin->messageview)) {
3079 gtk_paned_add2(GTK_PANED(hpaned),
3080 GTK_WIDGET_PTR(mainwin->messageview));
3082 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3084 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3086 gtk_widget_show(vpaned);
3087 gtk_widget_queue_resize(vpaned);
3090 g_warning("Unknown layout");
3094 mainwin->hpaned = hpaned;
3095 mainwin->vpaned = vpaned;
3097 if (layout_mode == SMALL_LAYOUT) {
3098 if (mainwin->messageview->visible)
3099 main_window_toggle_message_view(mainwin);
3102 if (layout_mode == SMALL_LAYOUT && first_set) {
3103 gtk_widget_realize(mainwin->window);
3104 gtk_widget_realize(mainwin->folderview->ctree);
3105 gtk_widget_realize(mainwin->summaryview->hbox);
3106 gtk_widget_realize(mainwin->summaryview->hbox_l);
3107 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3108 prefs_common.folderview_width,
3109 prefs_common.folderview_height);
3110 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3112 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3114 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3115 prefs_common.mainwin_width,
3116 prefs_common.mainwin_height);
3117 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3119 /* remove headerview if not in prefs */
3120 headerview_set_visibility(mainwin->messageview->headerview,
3121 prefs_common.display_header_pane);
3123 if (messageview_is_visible(mainwin->messageview))
3124 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3125 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3127 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3128 GTK_ARROW_UP, GTK_SHADOW_OUT);
3130 gtk_window_move(GTK_WINDOW(mainwin->window),
3131 prefs_common.mainwin_x,
3132 prefs_common.mainwin_y);
3134 gtk_widget_queue_resize(vbox_body);
3135 gtk_widget_queue_resize(mainwin->vbox);
3136 gtk_widget_queue_resize(mainwin->window);
3137 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3138 * and mimeview icon list/ctree lose track of their visibility states */
3139 if (!noticeview_is_visible(mainwin->messageview->noticeview))
3140 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3141 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
3142 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3143 if (mainwin->messageview->mimeview->ctree_mode)
3144 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3146 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3148 prefs_common.layout_mode = layout_mode;
3150 menuitem = gtk_item_factory_get_item
3151 (ifactory, "/View/Show or hide/Message view");
3152 gtk_check_menu_item_set_active
3153 (GTK_CHECK_MENU_ITEM(menuitem),
3154 messageview_is_visible(mainwin->messageview));
3156 #define SET_CHECK_MENU_ACTIVE(path, active) \
3158 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3159 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3163 switch (prefs_common.layout_mode) {
3165 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3167 case VERTICAL_LAYOUT:
3168 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3171 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3173 case WIDE_MSGLIST_LAYOUT:
3174 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3177 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3181 #undef SET_CHECK_MENU_ACTIVE
3185 (G_OBJECT(folderwin), "size_allocate",
3186 G_CALLBACK(folder_window_size_allocate_cb),
3191 (G_OBJECT(messagewin), "size_allocate",
3192 G_CALLBACK(message_window_size_allocate_cb),
3196 debug_print("done.\n");
3199 void main_window_destroy_all(void)
3201 while (mainwin_list != NULL) {
3202 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3204 /* free toolbar stuff */
3205 toolbar_clear_list(TOOLBAR_MAIN);
3206 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3207 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3209 mainwin->folderview->mainwin = NULL;
3210 mainwin->summaryview->mainwin = NULL;
3211 mainwin->messageview->mainwin = NULL;
3213 g_free(mainwin->toolbar);
3216 mainwin_list = g_list_remove(mainwin_list, mainwin);
3218 g_list_free(mainwin_list);
3219 mainwin_list = NULL;
3222 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3225 gtk_widget_set_size_request(child, 1, -1);
3228 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3231 gtk_widget_set_size_request(child, -1, -1);
3234 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3237 MainWindow *mainwin = (MainWindow *)data;
3239 if (!event) return FALSE;
3241 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3242 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3245 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3246 menu_button_position, widget,
3247 event->button, event->time);
3252 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3255 MainWindow *mainwin = (MainWindow *)data;
3256 gboolean close_allowed = TRUE;
3258 hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3260 if (close_allowed && mainwin->lock_count == 0)
3261 app_exit_cb(data, 0, widget);
3266 static void main_window_size_allocate_cb(GtkWidget *widget,
3267 GtkAllocation *allocation,
3270 MainWindow *mainwin = (MainWindow *)data;
3271 main_window_get_size(mainwin);
3274 static void folder_window_size_allocate_cb(GtkWidget *widget,
3275 GtkAllocation *allocation,
3278 MainWindow *mainwin = (MainWindow *)data;
3280 main_window_get_size(mainwin);
3283 static void message_window_size_allocate_cb(GtkWidget *widget,
3284 GtkAllocation *allocation,
3287 MainWindow *mainwin = (MainWindow *)data;
3289 main_window_get_size(mainwin);
3292 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3295 main_window_add_mailbox(mainwin);
3298 static void update_folderview_cb(MainWindow *mainwin, guint action,
3301 summary_show(mainwin->summaryview, NULL);
3302 folderview_check_new_all();
3305 static void foldersort_cb(MainWindow *mainwin, guint action,
3311 static void import_mbox_cb(MainWindow *mainwin, guint action,
3314 /* only notify if import has failed */
3315 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3316 alertpanel_error(_("Mbox import has failed."));
3320 static void export_mbox_cb(MainWindow *mainwin, guint action,
3323 /* only notify if export has failed */
3324 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3325 alertpanel_error(_("Export to mbox has failed."));
3329 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3332 /* only notify if export has failed */
3333 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3334 alertpanel_error(_("Export to mbox has failed."));
3338 static void empty_trash_cb(MainWindow *mainwin, guint action,
3341 main_window_empty_trash(mainwin, TRUE);
3344 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3346 summary_save_as(mainwin->summaryview);
3349 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3351 summary_print(mainwin->summaryview);
3354 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3356 if (prefs_common.confirm_on_exit) {
3357 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3358 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
3359 != G_ALERTALTERNATE)
3361 manage_window_focus_in(mainwin->window, NULL, NULL);
3364 app_will_exit(widget, mainwin);
3367 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3370 summary_search(mainwin->summaryview);
3372 message_search(mainwin->messageview);
3375 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3377 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3380 static void toggle_message_cb(MainWindow *mainwin, guint action,
3385 active = GTK_CHECK_MENU_ITEM(widget)->active;
3387 if (active != messageview_is_visible(mainwin->messageview))
3388 summary_toggle_view(mainwin->summaryview);
3391 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3394 toolbar_toggle(action, mainwin);
3397 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3400 MessageView *msgview = (MessageView*)mainwin->messageview;
3401 GSList *msginfo_list = NULL;
3403 g_return_if_fail(msgview != NULL);
3405 msginfo_list = summary_get_selection(mainwin->summaryview);
3406 g_return_if_fail(msginfo_list != NULL);
3407 compose_reply_from_messageview(msgview, msginfo_list, action);
3408 g_slist_free(msginfo_list);
3413 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3416 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3417 gtk_widget_show(mainwin->hbox_stat);
3418 prefs_common.show_statusbar = TRUE;
3420 gtk_widget_hide(mainwin->hbox_stat);
3421 prefs_common.show_statusbar = FALSE;
3425 static void set_layout_cb(MainWindow *mainwin, guint action,
3428 LayoutType layout_mode = action;
3429 LayoutType old_layout_mode = prefs_common.layout_mode;
3430 if (mainwin->menu_lock_count) {
3433 if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3437 if (layout_mode == prefs_common.layout_mode) {
3441 if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3442 main_window_toggle_message_view(mainwin);
3443 else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3444 main_window_toggle_message_view(mainwin);
3446 main_window_separation_change(mainwin, layout_mode);
3447 mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3448 if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3449 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3451 if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3452 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3453 mainwindow_exit_folder(mainwin);
3455 summary_relayout(mainwin->summaryview);
3456 summary_update_unread(mainwin->summaryview, NULL);
3460 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3463 offline_ask_sync = ask_sync;
3465 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3467 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3468 offline_ask_sync = TRUE;
3471 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3473 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3476 static gboolean any_folder_want_synchronise(void)
3478 GList *folderlist = folder_get_list();
3480 /* see if there are synchronised folders */
3481 for (; folderlist; folderlist = folderlist->next) {
3482 Folder *folder = (Folder *)folderlist->data;
3483 if (folder_want_synchronise(folder)) {
3491 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3494 if (!any_folder_want_synchronise())
3497 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3498 _("Do you want to synchronise your folders now?"),
3499 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3502 if (offline_ask_sync)
3503 folder_synchronise(NULL);
3506 static void online_switch_clicked (GtkButton *btn, gpointer data)
3508 MainWindow *mainwin;
3509 GtkItemFactory *ifactory;
3510 GtkCheckMenuItem *menuitem;
3512 mainwin = (MainWindow *) data;
3514 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3515 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3517 g_return_if_fail(mainwin != NULL);
3518 g_return_if_fail(menuitem != NULL);
3520 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3522 gtk_widget_hide (mainwin->online_switch);
3523 gtk_widget_show (mainwin->offline_switch);
3525 menuitem->active = TRUE;
3526 inc_autocheck_timer_remove();
3529 if (prefs_common.work_offline)
3531 mainwindow_check_synchronise(mainwin, TRUE);
3532 prefs_common.work_offline = TRUE;
3533 imap_disconnect_all();
3534 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3537 if (!prefs_common.work_offline)
3540 gtk_widget_hide (mainwin->offline_switch);
3541 gtk_widget_show (mainwin->online_switch);
3543 menuitem->active = FALSE;
3544 prefs_common.work_offline = FALSE;
3545 inc_autocheck_timer_set();
3546 refresh_resolvers();
3547 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3551 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3554 addressbook_open(NULL);
3557 static void log_window_show_cb(MainWindow *mainwin, guint action,
3560 log_window_show(mainwin->logwin);
3563 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3566 log_window_show(mainwin->filtering_debugwin);
3569 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3575 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3577 summary_move_to(mainwin->summaryview);
3580 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3582 summary_copy_to(mainwin->summaryview);
3585 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3587 summary_delete(mainwin->summaryview);
3590 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3592 summary_delete_trash(mainwin->summaryview);
3595 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3597 summary_cancel(mainwin->summaryview);
3600 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3602 summary_open_msg(mainwin->summaryview);
3605 static void view_source_cb(MainWindow *mainwin, guint action,
3608 summary_view_source(mainwin->summaryview);
3611 static void show_all_header_cb(MainWindow *mainwin, guint action,
3614 if (mainwin->menu_lock_count) return;
3615 mainwin->summaryview->messageview->all_headers =
3616 GTK_CHECK_MENU_ITEM(widget)->active;
3617 summary_display_msg_selected(mainwin->summaryview,
3618 GTK_CHECK_MENU_ITEM(widget)->active);
3621 #define SET_CHECK_MENU_ACTIVE(path, active) \
3623 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3624 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3627 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3630 GtkWidget *menuitem;
3631 GtkItemFactory *ifactory = mainwin->menu_factory;
3633 if (mainwin->menu_lock_count) return;
3635 prefs_common.hide_quotes =
3636 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3638 mainwin->menu_lock_count++;
3639 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3640 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3641 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3642 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3643 mainwin->menu_lock_count--;
3645 summary_redisplay_msg(mainwin->summaryview);
3648 #undef SET_CHECK_MENU_ACTIVE
3649 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3651 summary_mark(mainwin->summaryview);
3654 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3656 summary_unmark(mainwin->summaryview);
3659 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3662 summary_mark_as_unread(mainwin->summaryview);
3665 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3668 summary_mark_as_read(mainwin->summaryview);
3671 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3674 summary_mark_all_read(mainwin->summaryview);
3677 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3680 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3683 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3686 summary_ignore_thread(mainwin->summaryview);
3689 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3692 summary_unignore_thread(mainwin->summaryview);
3695 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3698 summary_msgs_lock(mainwin->summaryview);
3701 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3704 summary_msgs_unlock(mainwin->summaryview);
3708 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3710 summary_reedit(mainwin->summaryview);
3713 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3715 if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3716 summary_display_msg_selected(mainwin->summaryview,
3717 mainwin->messageview->mimeview->textview->show_all_headers);
3719 messageview_list_urls(mainwin->messageview);
3722 static void add_address_cb(MainWindow *mainwin, guint action,
3725 summary_add_address(mainwin->summaryview);
3728 static void set_charset_cb(MainWindow *mainwin, guint action,
3733 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3734 str = conv_get_charset_str((CharSet)action);
3736 g_free(mainwin->messageview->forced_charset);
3737 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3738 procmime_force_charset(str);
3740 summary_redisplay_msg(mainwin->summaryview);
3742 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3746 static void set_decode_cb(MainWindow *mainwin, guint action,
3749 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3750 mainwin->messageview->forced_encoding = (EncodingType)action;
3752 summary_redisplay_msg(mainwin->summaryview);
3754 debug_print("forced encoding: %d\n", action);
3758 static void hide_read_messages (MainWindow *mainwin, guint action,
3761 if (!mainwin->summaryview->folder_item
3762 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3764 summary_toggle_show_read_messages(mainwin->summaryview);
3767 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3769 gboolean threaded = FALSE;
3770 if (mainwin->menu_lock_count) return;
3771 if (!mainwin->summaryview->folder_item) return;
3773 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3775 mainwin->summaryview->folder_item->threaded = threaded;
3777 mainwin->summaryview->threaded = threaded;
3779 summary_show(mainwin->summaryview,
3780 mainwin->summaryview->folder_item);
3783 static void expand_threads_cb(MainWindow *mainwin, guint action,
3786 summary_expand_threads(mainwin->summaryview);
3789 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3792 summary_collapse_threads(mainwin->summaryview);
3795 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3798 prefs_summary_column_open();
3801 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3804 prefs_folder_column_open();
3807 static void sort_summary_cb(MainWindow *mainwin, guint action,
3810 FolderItem *item = mainwin->summaryview->folder_item;
3811 GtkWidget *menuitem;
3813 if (mainwin->menu_lock_count) return;
3815 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3816 menuitem = gtk_item_factory_get_item
3817 (mainwin->menu_factory, "/View/Sort/Ascending");
3818 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3819 GTK_CHECK_MENU_ITEM(menuitem)->active
3820 ? SORT_ASCENDING : SORT_DESCENDING);
3821 item->sort_key = action;
3825 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3828 FolderItem *item = mainwin->summaryview->folder_item;
3830 if (mainwin->menu_lock_count) return;
3832 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3833 summary_sort(mainwin->summaryview,
3834 item->sort_key, (FolderSortType)action);
3837 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3840 summary_attract_by_subject(mainwin->summaryview);
3843 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3848 item = folderview_get_selected_item(mainwin->folderview);
3850 main_window_cursor_wait(mainwin);
3851 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3853 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3854 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3856 STATUSBAR_POP(mainwin);
3857 main_window_cursor_normal(mainwin);
3867 static void deldup_all(FolderItem *item, gpointer _data)
3869 struct DelDupsData *data = _data;
3872 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3874 data->dups += result;
3879 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3882 struct DelDupsData data = {0, 0};
3884 main_window_cursor_wait(mainwin);
3885 folder_func_to_all_folders(deldup_all, &data);
3886 main_window_cursor_normal(mainwin);
3888 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3889 "Deleted %d duplicate messages in %d folders.\n",
3891 data.dups, data.folders);
3894 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3896 summary_filter(mainwin->summaryview, (gboolean)action);
3899 static void execute_summary_cb(MainWindow *mainwin, guint action,
3902 summary_execute(mainwin->summaryview);
3905 static void update_summary_cb(MainWindow *mainwin, guint action,
3909 FolderView *folderview = mainwin->folderview;
3911 if (!mainwin->summaryview->folder_item) return;
3912 if (!folderview->opened) return;
3914 folder_update_op_count();
3916 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3917 folderview->opened);
3920 folder_item_scan(fitem);
3921 summary_show(mainwin->summaryview, fitem);
3924 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3926 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3929 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3931 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3934 static void prev_unread_cb(MainWindow *mainwin, guint action,
3937 summary_select_prev_unread(mainwin->summaryview);
3940 static void next_unread_cb(MainWindow *mainwin, guint action,
3943 summary_select_next_unread(mainwin->summaryview);
3946 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3948 summary_select_prev_new(mainwin->summaryview);
3951 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3953 summary_select_next_new(mainwin->summaryview);
3956 static void prev_marked_cb(MainWindow *mainwin, guint action,
3959 summary_select_prev_marked(mainwin->summaryview);
3962 static void next_marked_cb(MainWindow *mainwin, guint action,
3965 summary_select_next_marked(mainwin->summaryview);
3968 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3971 summary_select_prev_labeled(mainwin->summaryview);
3974 static void next_labeled_cb(MainWindow *mainwin, guint action,
3977 summary_select_next_labeled(mainwin->summaryview);
3980 static void last_read_cb(MainWindow *mainwin, guint action,
3983 summary_select_last_read(mainwin->summaryview);
3986 static void parent_cb(MainWindow *mainwin, guint action,
3989 summary_select_parent(mainwin->summaryview);
3992 static void goto_folder_cb(MainWindow *mainwin, guint action,
3995 FolderItem *to_folder;
3997 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
4000 folderview_select(mainwin->folderview, to_folder);
4003 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
4006 folderview_select_next_unread(mainwin->folderview, FALSE);
4009 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4011 messageview_copy_clipboard(mainwin->messageview);
4014 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4016 MessageView *msgview = mainwin->messageview;
4018 if (messageview_is_visible(msgview) &&
4019 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
4020 messageview_select_all(mainwin->messageview);
4022 summary_select_all(mainwin->summaryview);
4025 static void select_thread_cb(MainWindow *mainwin, guint action,
4028 summary_select_thread(mainwin->summaryview, FALSE);
4031 static void delete_thread_cb(MainWindow *mainwin, guint action,
4034 summary_select_thread(mainwin->summaryview, TRUE);
4037 static void create_filter_cb(MainWindow *mainwin, guint action,
4040 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4043 static void create_processing_cb(MainWindow *mainwin, guint action,
4046 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4049 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
4052 prefs_filtering_open(&pre_global_processing,
4053 _("Processing rules to apply before folder rules"),
4054 MANUAL_ANCHOR_PROCESSING,
4058 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
4061 prefs_filtering_open(&post_global_processing,
4062 _("Processing rules to apply after folder rules"),
4063 MANUAL_ANCHOR_PROCESSING,
4067 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
4070 prefs_filtering_open(&filtering_rules,
4071 _("Filtering configuration"),
4072 MANUAL_ANCHOR_FILTERING,
4076 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4079 prefs_template_open();
4082 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4085 prefs_actions_open(mainwin);
4088 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4091 prefs_tags_open(mainwin);
4094 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4097 ssl_manager_open(mainwin);
4100 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4104 new_account_cb(mainwin, 0, widget);
4106 account_open(cur_account);
4110 static void new_account_cb(MainWindow *mainwin, guint action,
4113 account_edit_open();
4114 if (!compose_get_compose_list()) account_add();
4117 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4119 FolderItem *item = NULL;
4120 cur_account = (PrefsAccount *)data;
4122 if (!mainwindow_get_mainwindow())
4124 main_window_show_cur_account(mainwindow_get_mainwindow());
4125 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4126 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4127 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4128 item = folderview_get_selected_item(
4129 mainwindow_get_mainwindow()->folderview);
4131 toolbar_set_compose_button
4132 (mainwindow_get_mainwindow()->toolbar,
4133 FOLDER_TYPE(item->folder) == F_NEWS ?
4134 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4138 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4140 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4141 PrefsAccount *account = (PrefsAccount *)data;
4143 inc_account_mail(mainwin, account);
4146 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4148 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4149 PrefsAccount *account = (PrefsAccount *)data;
4150 FolderItem *item = mainwin->summaryview->folder_item;
4152 compose_new_with_folderitem(account, item, NULL);
4155 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4160 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4162 pluginwindow_create();
4165 static void manual_open_cb(MainWindow *mainwin, guint action,
4168 manual_open((ManualType)action, NULL);
4171 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4176 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4178 MainWindow *mainwin = (MainWindow *)data;
4182 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4183 LOCAL_FOLDER(folder)->rootpath,
4187 str = g_strdup_printf(_("Scanning folder %s ..."),
4188 LOCAL_FOLDER(folder)->rootpath);
4190 STATUSBAR_PUSH(mainwin, str);
4191 STATUSBAR_POP(mainwin);
4195 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4198 SummaryView *summary;
4200 g_return_val_if_fail(data, FALSE);
4201 if (!g_list_find(mainwin_list, data))
4203 summary = ((MainWindow *)data)->summaryview;
4204 g_return_val_if_fail(summary, FALSE);
4206 if (GTK_CLIST(summary->ctree)->selection &&
4207 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4213 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4216 is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4220 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4223 if (!claws_is_starting()
4224 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4225 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4227 if (iconified_count > 0)
4228 hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4231 if (state->new_window_state == 0)
4232 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4236 gboolean mainwindow_is_obscured(void)
4241 #define BREAK_ON_MODIFIER_KEY() \
4242 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
4244 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
4247 MainWindow *mainwin = (MainWindow*) data;
4249 if (!mainwin || !event)
4252 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
4254 lastkey = event->keyval;
4258 switch (event->keyval) {
4259 case GDK_Q: /* Quit */
4260 BREAK_ON_MODIFIER_KEY();
4262 app_exit_cb(mainwin, 0, NULL);
4265 if (mainwin->folderview && mainwin->summaryview
4266 && ((!mainwin->summaryview->displayed
4267 && !mainwin->summaryview->selected)
4268 || (mainwin->summaryview->folder_item
4269 && mainwin->summaryview->folder_item->total_msgs == 0))) {
4270 g_signal_stop_emission_by_name(G_OBJECT(widget),
4272 folderview_select_next_unread(mainwin->folderview, TRUE);
4277 if (maemo_mainwindow_is_fullscreen(widget)) {
4278 gtk_window_unfullscreen(GTK_WINDOW(widget));
4280 gtk_window_fullscreen(GTK_WINDOW(widget));
4290 #undef BREAK_ON_MODIFIER_KEY
4293 * Harvest addresses for selected folder.
4295 static void addr_harvest_cb( MainWindow *mainwin,
4299 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4303 * Harvest addresses for selected messages in summary view.
4305 static void addr_harvest_msg_cb( MainWindow *mainwin,
4309 summary_harvest_address( mainwin->summaryview );
4313 *\brief get a MainWindow
4315 *\return MainWindow * The first mainwindow in the mainwin_list
4317 MainWindow *mainwindow_get_mainwindow(void)
4319 if (mainwin_list && mainwin_list->data)
4320 return (MainWindow *)(mainwin_list->data);
4325 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4327 ProgressData *data = (ProgressData *) source;
4328 MainWindow *mainwin = (MainWindow *) userdata;
4330 switch (data->cmd) {
4331 case PROGRESS_COMMAND_START:
4332 case PROGRESS_COMMAND_STOP:
4333 gtk_progress_bar_set_fraction
4334 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4336 case PROGRESS_COMMAND_SET_PERCENTAGE:
4337 gtk_progress_bar_set_fraction
4338 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4341 while (gtk_events_pending()) gtk_main_iteration ();
4346 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4348 mainwindow_check_synchronise(mainwin, FALSE);
4351 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4353 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4356 void mainwindow_jump_to(const gchar *target, gboolean popup)
4360 FolderItem *item = NULL;
4362 MainWindow *mainwin = mainwindow_get_mainwindow();
4368 printf("not initialized\n");
4372 tmp = g_strdup(target);
4374 if ((p = strstr(tmp, "\r")) != NULL)
4376 if ((p = strstr(tmp, "\n")) != NULL)
4379 if ((item = folder_find_item_from_identifier(tmp))) {
4380 printf("selecting folder '%s'\n", tmp);
4381 folderview_select(mainwin->folderview, item);
4383 main_window_popup(mainwin);
4388 msg = strrchr(tmp, G_DIR_SEPARATOR);
4391 if ((item = folder_find_item_from_identifier(tmp))) {
4392 printf("selecting folder '%s'\n", tmp);
4393 folderview_select(mainwin->folderview, item);
4395 printf("'%s' not found\n", tmp);
4397 if (item && msg && atoi(msg)) {
4398 printf("selecting message %d\n", atoi(msg));
4399 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4400 summary_display_msg_selected(mainwin->summaryview, FALSE);
4402 main_window_popup(mainwin);
4405 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4406 MsgInfo *msginfo = NULL;
4408 msg[strlen(msg)-1] = '\0';
4409 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4411 printf("selecting message %s\n", msg);
4412 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4413 summary_display_msg_selected(mainwin->summaryview, FALSE);
4415 main_window_popup(mainwin);
4417 procmsg_msginfo_free(msginfo);
4420 printf("'%s' not found\n", msg);
4423 printf("'%s' not found\n", msg);
4426 printf("'%s' not found\n", tmp);
4432 void mainwindow_exit_folder(MainWindow *mainwin) {
4433 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4434 folderview_close_opened(mainwin->folderview);
4435 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4437 mainwin->in_folder = FALSE;
4440 void mainwindow_enter_folder(MainWindow *mainwin) {
4441 if (prefs_common.layout_mode == SMALL_LAYOUT) {
4442 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4444 mainwin->in_folder = TRUE;
4448 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4451 gtk_window_get_size(GTK_WINDOW(widget), &w, &h);
4455 void maemo_window_full_screen_if_needed (GtkWindow *window)
4457 if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4458 gtk_window_fullscreen(GTK_WINDOW(window));
4462 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4464 g_signal_connect(G_OBJECT(window), "key_press_event",
4465 G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());