2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkstatusbar.h>
32 #include <gtk/gtkprogressbar.h>
33 #include <gtk/gtkhpaned.h>
34 #include <gtk/gtkvpaned.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkmenu.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkhandlebox.h>
41 #include <gtk/gtktoolbar.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtktooltips.h>
47 #include "mainwindow.h"
48 #include "folderview.h"
49 #include "foldersel.h"
50 #include "summaryview.h"
51 #include "summary_search.h"
52 #include "messageview.h"
53 #include "message_search.h"
54 #include "headerview.h"
56 #include "stock_pixmap.h"
64 #include "prefs_common.h"
65 #include "prefs_actions.h"
66 #include "prefs_filtering.h"
67 #include "prefs_account.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_folder_column.h"
70 #include "prefs_template.h"
73 #include "addressbook.h"
74 #include "logwindow.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "inputdialog.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefs_gtk.h"
88 #include "pluginwindow.h"
90 #include "progressindicator.h"
91 #include "localfolder.h"
92 #include "filtering.h"
93 #include "folderutils.h"
94 #include "foldersort.h"
95 #include "icon_legend.h"
96 #include "colorlabel.h"
101 #define AC_LABEL_WIDTH 240
103 /* list of all instantiated MainWindow */
104 static GList *mainwin_list = NULL;
106 static GdkCursor *watch_cursor = NULL;
107 static GdkCursor *hand_cursor = NULL;
109 static void main_window_menu_callback_block (MainWindow *mainwin);
110 static void main_window_menu_callback_unblock (MainWindow *mainwin);
112 static void main_window_show_cur_account (MainWindow *mainwin);
114 static void main_window_separation_change (MainWindow *mainwin,
115 LayoutType layout_mode);
117 static void main_window_set_widgets (MainWindow *mainwin,
118 LayoutType layout_mode);
120 static void toolbar_child_attached (GtkWidget *widget,
123 static void toolbar_child_detached (GtkWidget *widget,
127 static gboolean ac_label_button_pressed (GtkWidget *widget,
128 GdkEventButton *event,
131 static gint main_window_close_cb (GtkWidget *widget,
135 static void main_window_size_allocate_cb (GtkWidget *widget,
136 GtkAllocation *allocation,
138 static void folder_window_size_allocate_cb (GtkWidget *widget,
139 GtkAllocation *allocation,
141 static void message_window_size_allocate_cb (GtkWidget *widget,
142 GtkAllocation *allocation,
145 static void update_folderview_cb (MainWindow *mainwin,
148 static void add_mailbox_cb (MainWindow *mainwin,
151 static void foldersort_cb (MainWindow *mainwin,
154 static void import_mbox_cb (MainWindow *mainwin,
157 static void export_mbox_cb (MainWindow *mainwin,
160 static void export_list_mbox_cb (MainWindow *mainwin,
163 static void empty_trash_cb (MainWindow *mainwin,
167 static void save_as_cb (MainWindow *mainwin,
170 static void print_cb (MainWindow *mainwin,
173 static void app_exit_cb (MainWindow *mainwin,
177 static void search_cb (MainWindow *mainwin,
181 static void toggle_message_cb (MainWindow *mainwin,
184 static void toggle_toolbar_cb (MainWindow *mainwin,
187 static void toggle_statusbar_cb (MainWindow *mainwin,
190 static void set_layout_cb (MainWindow *mainwin,
194 static void addressbook_open_cb (MainWindow *mainwin,
197 static void log_window_show_cb (MainWindow *mainwin,
201 static void inc_cancel_cb (MainWindow *mainwin,
205 static void open_msg_cb (MainWindow *mainwin,
209 static void view_source_cb (MainWindow *mainwin,
213 static void show_all_header_cb (MainWindow *mainwin,
217 static void hide_quotes_cb(MainWindow *mainwin,
221 static void move_to_cb (MainWindow *mainwin,
224 static void copy_to_cb (MainWindow *mainwin,
227 static void delete_cb (MainWindow *mainwin,
230 static void delete_trash_cb (MainWindow *mainwin,
234 static void cancel_cb (MainWindow *mainwin,
238 static void mark_cb (MainWindow *mainwin,
241 static void unmark_cb (MainWindow *mainwin,
245 static void mark_as_unread_cb (MainWindow *mainwin,
248 static void mark_as_read_cb (MainWindow *mainwin,
251 static void mark_all_read_cb (MainWindow *mainwin,
254 static void mark_as_spam_cb (MainWindow *mainwin,
258 static void ignore_thread_cb (MainWindow *mainwin,
261 static void unignore_thread_cb (MainWindow *mainwin,
264 static void lock_msgs_cb (MainWindow *mainwin,
267 static void unlock_msgs_cb (MainWindow *mainwin,
271 static void reedit_cb (MainWindow *mainwin,
275 static void add_address_cb (MainWindow *mainwin,
279 static void set_charset_cb (MainWindow *mainwin,
283 static void set_decode_cb (MainWindow *mainwin,
287 static void hide_read_messages (MainWindow *mainwin,
291 static void thread_cb (MainWindow *mainwin,
294 static void expand_threads_cb (MainWindow *mainwin,
297 static void collapse_threads_cb (MainWindow *mainwin,
301 static void set_summary_display_item_cb (MainWindow *mainwin,
304 static void set_folder_display_item_cb (MainWindow *mainwin,
307 static void sort_summary_cb (MainWindow *mainwin,
310 static void sort_summary_type_cb (MainWindow *mainwin,
313 static void attract_by_subject_cb(MainWindow *mainwin,
317 static void delete_duplicated_cb (MainWindow *mainwin,
320 static void delete_duplicated_all_cb (MainWindow *mainwin,
323 static void filter_cb (MainWindow *mainwin,
326 static void execute_summary_cb (MainWindow *mainwin,
329 static void update_summary_cb (MainWindow *mainwin,
333 static void prev_cb (MainWindow *mainwin,
336 static void next_cb (MainWindow *mainwin,
339 static void next_unread_cb (MainWindow *mainwin,
342 static void prev_unread_cb (MainWindow *mainwin,
346 static void prev_new_cb (MainWindow *mainwin,
349 static void next_new_cb (MainWindow *mainwin,
352 static void prev_marked_cb (MainWindow *mainwin,
355 static void next_marked_cb (MainWindow *mainwin,
358 static void prev_labeled_cb (MainWindow *mainwin,
361 static void next_labeled_cb (MainWindow *mainwin,
364 static void last_read_cb (MainWindow *mainwin,
367 static void parent_cb (MainWindow *mainwin,
371 static void goto_folder_cb (MainWindow *mainwin,
374 static void goto_unread_folder_cb(MainWindow *mainwin,
378 static void copy_cb (MainWindow *mainwin,
381 static void allsel_cb (MainWindow *mainwin,
384 static void select_thread_cb (MainWindow *mainwin,
387 static void delete_thread_cb (MainWindow *mainwin,
391 static void create_filter_cb (MainWindow *mainwin,
394 static void create_processing_cb (MainWindow *mainwin,
398 static void prefs_template_open_cb (MainWindow *mainwin,
401 static void prefs_actions_open_cb (MainWindow *mainwin,
404 static void prefs_account_open_cb (MainWindow *mainwin,
408 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
412 static void prefs_post_processing_open_cb (MainWindow *mainwin,
416 static void prefs_filtering_open_cb (MainWindow *mainwin,
420 static void ssl_manager_open_cb (MainWindow *mainwin,
424 static void new_account_cb (MainWindow *mainwin,
428 static void account_selector_menu_cb (GtkMenuItem *menuitem,
430 static void account_receive_menu_cb (GtkMenuItem *menuitem,
432 static void account_compose_menu_cb (GtkMenuItem *menuitem,
435 static void prefs_open_cb (GtkMenuItem *menuitem,
437 static void plugins_open_cb (GtkMenuItem *menuitem,
440 static void online_switch_clicked(GtkButton *btn,
443 static void manual_open_cb (MainWindow *mainwin,
447 static void legend_open_cb (GtkMenuItem *menuitem,
450 static void scan_tree_func (Folder *folder,
454 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
456 static void addr_harvest_cb ( MainWindow *mainwin,
460 static void addr_harvest_msg_cb ( MainWindow *mainwin,
463 static void sync_cb ( MainWindow *mainwin,
467 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
468 GdkEventFocus *focus,
470 static gboolean mainwindow_visibility_event_cb (GtkWidget *widget,
471 GdkEventVisibility *state,
473 static void main_window_reply_cb (MainWindow *mainwin,
476 static gboolean mainwindow_progressindicator_hook (gpointer source,
479 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
482 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
484 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
486 static void mailing_list_compose(GtkWidget *w, gpointer *data);
488 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
489 #define SEPARATE_ACTION 500
490 static void mainwindow_quicksearch (MainWindow *mainwin,
493 static gboolean any_folder_want_synchronise(void);
495 static GtkItemFactoryEntry mainwin_entries[] =
497 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
498 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
499 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
500 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
501 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
502 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
503 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
504 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
505 {N_("/_File/Exp_ort selected to mbox file..."),
506 NULL, export_list_mbox_cb, 0, NULL},
507 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
509 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
510 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
511 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
512 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
514 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
515 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
516 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
517 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
519 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
520 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
521 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
522 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
523 {N_("/_Edit/_Delete thread"), NULL, delete_thread_cb, 0, NULL},
524 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
525 {N_("/_Edit/_Find in current message..."),
526 "<control>F", search_cb, 0, NULL},
527 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
528 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
529 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
531 {N_("/_View/Show or hi_de/_Message view"),
532 "V", toggle_message_cb, 0, "<ToggleItem>"},
533 {N_("/_View/Show or hi_de/_Toolbar"),
534 NULL, NULL, 0, "<Branch>"},
535 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
536 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
537 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
538 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
539 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
540 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
541 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
542 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
543 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
544 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
545 {N_("/_View/Show or hi_de/Status _bar"),
546 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
547 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
548 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
549 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
551 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
552 {N_("/_View/La_yout"), NULL, NULL, 0, "<Branch>"},
553 {N_("/_View/Layout/_Standard"), NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
554 {N_("/_View/Layout/_Three columns"), NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
555 {N_("/_View/Layout/_Wide message"), NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
556 {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
557 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
558 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
559 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
560 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
561 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
562 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
563 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
564 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
565 {N_("/_View/_Sort/by _color label"),
566 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
567 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
568 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
569 {N_("/_View/_Sort/by a_ttachment"),
570 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
571 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
572 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
573 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
574 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
575 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
576 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
577 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
578 {N_("/_View/_Sort/_Attract by subject"),
579 NULL, attract_by_subject_cb, 0, NULL},
580 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
581 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
582 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
583 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
585 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
586 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
587 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
588 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
589 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
590 {N_("/_View/_Go to/P_revious unread message"),
591 "<shift>P", prev_unread_cb, 0, NULL},
592 {N_("/_View/_Go to/N_ext unread message"),
593 "<shift>N", next_unread_cb, 0, NULL},
594 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
595 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
596 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
597 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
598 {N_("/_View/_Go to/Previous _marked message"),
599 NULL, prev_marked_cb, 0, NULL},
600 {N_("/_View/_Go to/Next m_arked message"),
601 NULL, next_marked_cb, 0, NULL},
602 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
603 {N_("/_View/_Go to/Previous _labeled message"),
604 NULL, prev_labeled_cb, 0, NULL},
605 {N_("/_View/_Go to/Next la_beled message"),
606 NULL, next_labeled_cb, 0, NULL},
607 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
608 {N_("/_View/_Go to/Last read message"),
609 NULL, last_read_cb, 0, NULL},
610 {N_("/_View/_Go to/Parent message"),
611 "<control>Up", parent_cb, 0, NULL},
612 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
613 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
614 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
615 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
617 #define ENC_SEPARATOR \
618 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
619 #define ENC_ACTION(action) \
620 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
622 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
623 {N_("/_View/Character _encoding/_Auto detect"),
624 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
625 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
627 ENC_ACTION(C_US_ASCII)},
628 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
629 ENC_ACTION(C_UTF_8)},
632 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
633 ENC_ACTION(C_ISO_8859_1)},
634 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
635 ENC_ACTION(C_ISO_8859_15)},
636 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
637 ENC_ACTION(C_WINDOWS_1252)},
640 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
641 ENC_ACTION(C_ISO_8859_2)},
644 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
645 ENC_ACTION(C_ISO_8859_13)},
646 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
647 ENC_ACTION(C_ISO_8859_4)},
650 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
651 ENC_ACTION(C_ISO_8859_7)},
654 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
655 ENC_ACTION(C_ISO_8859_8)},
656 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
657 ENC_ACTION(C_CP1255)},
660 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
661 ENC_ACTION(C_ISO_8859_6)},
662 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
663 ENC_ACTION(C_CP1256)},
666 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
667 ENC_ACTION(C_ISO_8859_9)},
670 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
671 ENC_ACTION(C_ISO_8859_5)},
672 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
673 ENC_ACTION(C_KOI8_R)},
674 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
675 ENC_ACTION(C_KOI8_U)},
676 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
677 ENC_ACTION(C_CP1251)},
680 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
681 ENC_ACTION(C_ISO_2022_JP)},
682 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
683 ENC_ACTION(C_ISO_2022_JP_2)},
684 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
685 ENC_ACTION(C_EUC_JP)},
686 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
687 ENC_ACTION(C_SHIFT_JIS)},
690 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
691 ENC_ACTION(C_GB2312)},
692 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
694 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
696 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
697 ENC_ACTION(C_EUC_TW)},
698 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
699 ENC_ACTION(C_ISO_2022_CN)},
702 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
703 ENC_ACTION(C_EUC_KR)},
704 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
705 ENC_ACTION(C_ISO_2022_KR)},
708 {N_("/_View/Character _encoding/Thai (TIS-620)"),
709 ENC_ACTION(C_TIS_620)},
710 {N_("/_View/Character _encoding/Thai (Windows-874)"),
711 ENC_ACTION(C_WINDOWS_874)},
716 #define DEC_SEPARATOR \
717 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
718 #define DEC_ACTION(action) \
719 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
720 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
721 {N_("/_View/Decode/_Auto detect"),
722 NULL, set_decode_cb, 0, "<RadioItem>"},
723 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
724 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
725 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
726 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
727 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
732 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
734 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
735 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
736 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
737 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
738 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
739 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
740 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
741 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
743 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
744 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
745 {N_("/_Message/Recei_ve/Get from _current account"),
746 "<control>I", inc_mail_cb, 0, NULL},
747 {N_("/_Message/Recei_ve/Get from _all accounts"),
748 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
749 {N_("/_Message/Recei_ve/Cancel receivin_g"),
750 NULL, inc_cancel_cb, 0, NULL},
751 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
753 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
754 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
755 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
756 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
757 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
759 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
760 {N_("/_Message/Repl_y to/mailing _list"),
761 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
762 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
763 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
764 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
765 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
766 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
768 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
769 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
770 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
771 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
772 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
773 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
774 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
776 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
777 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
778 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
779 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
780 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
781 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
782 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
783 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
784 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
785 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
786 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
787 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
788 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
789 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
790 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
791 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
792 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
793 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
794 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
795 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
796 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
797 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
798 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
799 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
800 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
802 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
803 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
804 {N_("/_Tools/Add sender to address boo_k"),
805 NULL, add_address_cb, 0, NULL},
806 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
807 {N_("/_Tools/_Harvest addresses/from _Folder..."),
808 NULL, addr_harvest_cb, 0, NULL},
809 {N_("/_Tools/_Harvest addresses/from _Messages..."),
810 NULL, addr_harvest_msg_cb, 0, NULL},
811 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
812 {N_("/_Tools/_Filter all messages in folder"),
813 NULL, filter_cb, 0, NULL},
814 {N_("/_Tools/Filter _selected messages"),
815 NULL, filter_cb, 1, NULL},
816 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
817 {N_("/_Tools/_Create filter rule/_Automatically"),
818 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
819 {N_("/_Tools/_Create filter rule/by _From"),
820 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
821 {N_("/_Tools/_Create filter rule/by _To"),
822 NULL, create_filter_cb, FILTER_BY_TO, NULL},
823 {N_("/_Tools/_Create filter rule/by _Subject"),
824 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
825 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
826 {N_("/_Tools/C_reate processing rule/_Automatically"),
827 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
828 {N_("/_Tools/C_reate processing rule/by _From"),
829 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
830 {N_("/_Tools/C_reate processing rule/by _To"),
831 NULL, create_processing_cb, FILTER_BY_TO, NULL},
832 {N_("/_Tools/C_reate processing rule/by _Subject"),
833 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
834 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
835 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
836 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
837 {N_("/_Tools/Ch_eck for new messages in all folders"),
838 NULL, update_folderview_cb, 0, NULL},
839 {N_("/_Tools/Delete du_plicated messages"),
840 NULL, NULL, 0, "<Branch>"},
841 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
842 NULL, delete_duplicated_cb, 0, NULL},
843 {N_("/_Tools/Delete du_plicated messages/In all folders"),
844 NULL, delete_duplicated_all_cb, 0, NULL},
845 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
846 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
848 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
849 {N_("/_Tools/SSL cer_tificates..."),
850 NULL, ssl_manager_open_cb, 0, NULL},
852 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
853 {N_("/_Tools/_Log window"), "<shift><control>L", log_window_show_cb, 0, NULL},
855 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
856 {N_("/_Configuration/C_hange current account"),
857 NULL, NULL, 0, "<Branch>"},
858 {N_("/_Configuration/_Preferences for current account..."),
859 NULL, prefs_account_open_cb, 0, NULL},
860 {N_("/_Configuration/Create _new account..."),
861 NULL, new_account_cb, 0, NULL},
862 {N_("/_Configuration/_Edit accounts..."),
863 NULL, account_edit_open, 0, NULL},
864 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
865 {N_("/_Configuration/P_references..."),
866 NULL, prefs_open_cb, 0, NULL},
867 {N_("/_Configuration/Pre-pr_ocessing..."),
868 NULL, prefs_pre_processing_open_cb, 0, NULL},
869 {N_("/_Configuration/Post-pro_cessing..."),
870 NULL, prefs_post_processing_open_cb, 0, NULL},
871 {N_("/_Configuration/_Filtering..."),
872 NULL, prefs_filtering_open_cb, 0, NULL},
873 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
874 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
875 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
877 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
878 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
879 {N_("/_Help/_Online User-contributed FAQ"),
880 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
881 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
882 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
883 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
886 static gboolean offline_ask_sync = TRUE;
887 static guint lastkey;
888 static gboolean is_obscured = FALSE;
890 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
896 MainWindow *mainwin = (MainWindow *)user_data;
898 if (mainwin->summaryview &&
899 mainwin->summaryview->quicksearch &&
900 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
901 (mod == 0 || mod == GDK_SHIFT_MASK)) {
902 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
908 #define N_COLOR_LABELS colorlabel_get_color_count()
910 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
915 GtkCheckMenuItem **items;
920 mainwin = (MainWindow *)data;
921 g_return_if_fail(mainwin != NULL);
923 sel = summary_get_selection(mainwin->summaryview);
926 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
927 g_return_if_fail(menu != NULL);
929 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
931 /* NOTE: don't return prematurely because we set the "dont_toggle"
932 * state for check menu items */
933 g_object_set_data(G_OBJECT(menu), "dont_toggle",
936 /* clear items. get item pointers. */
937 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
938 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
939 gtk_check_menu_item_set_active
940 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
941 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
946 if (n == (N_COLOR_LABELS + 1)) {
947 /* iterate all messages and set the state of the appropriate
949 for (; sel != NULL; sel = sel->next) {
953 msginfo = (MsgInfo *)sel->data;
955 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
956 if (!items[clabel]->active)
957 gtk_check_menu_item_set_active
958 (items[clabel], TRUE);
962 g_warning("invalid number of color elements (%d)\n", n);
964 /* reset "dont_toggle" state */
965 g_object_set_data(G_OBJECT(menu), "dont_toggle",
969 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
972 guint color = GPOINTER_TO_UINT(data);
975 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
976 g_return_if_fail(mainwin != NULL);
978 /* "dont_toggle" state set? */
979 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
983 summary_set_colorlabel(mainwin->summaryview, color, NULL);
986 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
988 GtkWidget *label_menuitem;
993 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
994 "/Message/Color label");
995 g_signal_connect(G_OBJECT(label_menuitem), "activate",
996 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
998 gtk_widget_show(label_menuitem);
1000 menu = gtk_menu_new();
1002 /* create sub items. for the menu item activation callback we pass the
1003 * index of label_colors[] as data parameter. for the None color we
1004 * pass an invalid (high) value. also we attach a data pointer so we
1005 * can always get back the Mainwindow pointer. */
1007 item = gtk_check_menu_item_new_with_label(_("None"));
1008 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1009 g_signal_connect(G_OBJECT(item), "activate",
1010 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1011 GUINT_TO_POINTER(0));
1012 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1013 gtk_widget_show(item);
1015 gtk_widget_add_accelerator(item, "activate",
1016 mainwin->menu_factory->accel_group,
1017 GDK_0, GDK_CONTROL_MASK,
1018 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1020 item = gtk_menu_item_new();
1021 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1022 gtk_widget_show(item);
1024 /* create pixmap/label menu items */
1025 for (i = 0; i < N_COLOR_LABELS; i++) {
1026 item = colorlabel_create_check_color_menu_item(
1027 i, refresh, MAINWIN_COLORMENU);
1028 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1029 g_signal_connect(G_OBJECT(item), "activate",
1030 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1031 GUINT_TO_POINTER(i + 1));
1032 g_object_set_data(G_OBJECT(item), "mainwin",
1034 gtk_widget_show(item);
1035 gtk_widget_add_accelerator(item, "activate",
1036 mainwin->menu_factory->accel_group,
1037 GDK_1+i, GDK_CONTROL_MASK,
1038 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1041 gtk_widget_show(menu);
1042 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1043 mainwin->colorlabel_menu = menu;
1046 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1047 MainWindow *mainwindow)
1049 if (evt && evt->button == 1) {
1050 log_window_show_error(mainwindow->logwin);
1051 gtk_widget_hide(mainwindow->warning_btn);
1056 static gboolean warning_visi_notify(GtkWidget *widget,
1057 GdkEventVisibility *event,
1058 MainWindow *mainwindow)
1060 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1064 static gboolean warning_leave_notify(GtkWidget *widget,
1065 GdkEventCrossing *event,
1066 MainWindow *mainwindow)
1068 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1072 static gboolean warning_enter_notify(GtkWidget *widget,
1073 GdkEventCrossing *event,
1074 MainWindow *mainwindow)
1076 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1080 void mainwindow_show_error(void)
1082 MainWindow *mainwin = mainwindow_get_mainwindow();
1083 gtk_widget_show(mainwin->warning_btn);
1086 void mainwindow_clear_error(MainWindow *mainwin)
1088 gtk_widget_hide(mainwin->warning_btn);
1091 MainWindow *main_window_create()
1093 MainWindow *mainwin;
1097 GtkWidget *handlebox;
1098 GtkWidget *vbox_body;
1099 GtkWidget *hbox_stat;
1100 GtkWidget *statusbar;
1101 GtkWidget *progressbar;
1102 GtkWidget *statuslabel;
1103 GtkWidget *ac_button;
1104 GtkWidget *ac_label;
1105 GtkWidget *online_pixmap;
1106 GtkWidget *offline_pixmap;
1107 GtkWidget *online_switch;
1108 GtkWidget *offline_switch;
1110 GtkWidget *warning_icon;
1111 GtkWidget *warning_btn;
1113 FolderView *folderview;
1114 SummaryView *summaryview;
1115 MessageView *messageview;
1116 GdkColormap *colormap;
1118 gboolean success[4];
1119 GtkItemFactory *ifactory;
1121 GtkWidget *menuitem;
1123 guint n_menu_entries;
1125 static GdkGeometry geometry;
1127 debug_print("Creating main window...\n");
1128 mainwin = g_new0(MainWindow, 1);
1131 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1132 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1133 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1135 if (!geometry.min_height) {
1136 geometry.min_width = 320;
1137 geometry.min_height = 200;
1139 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1142 g_signal_connect(G_OBJECT(window), "delete_event",
1143 G_CALLBACK(main_window_close_cb), mainwin);
1144 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1145 g_signal_connect(G_OBJECT(window), "focus_in_event",
1146 G_CALLBACK(mainwindow_focus_in_event),
1148 g_signal_connect(G_OBJECT(window), "key_press_event",
1149 G_CALLBACK(mainwindow_key_pressed), mainwin);
1151 gtk_widget_realize(window);
1152 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1155 gtkut_widget_set_app_icon(window);
1157 vbox = gtk_vbox_new(FALSE, 0);
1158 gtk_widget_show(vbox);
1159 gtk_container_add(GTK_CONTAINER(window), vbox);
1162 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1163 menubar = menubar_create(window, mainwin_entries,
1164 n_menu_entries, "<Main>", mainwin);
1165 gtk_widget_show(menubar);
1166 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1167 ifactory = gtk_item_factory_from_widget(menubar);
1169 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1170 main_create_mailing_list_menu (mainwin, NULL); */
1172 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1174 if (prefs_common.toolbar_detachable) {
1175 handlebox = gtk_handle_box_new();
1176 gtk_widget_show(handlebox);
1177 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1178 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1179 G_CALLBACK(toolbar_child_attached), mainwin);
1180 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1181 G_CALLBACK(toolbar_child_detached), mainwin);
1183 handlebox = gtk_hbox_new(FALSE, 0);
1184 gtk_widget_show(handlebox);
1185 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1187 /* link window to mainwin->window to avoid gdk warnings */
1188 mainwin->window = window;
1190 /* create toolbar */
1191 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1194 toolbar_set_learn_button
1198 /* vbox that contains body */
1199 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1200 gtk_widget_show(vbox_body);
1201 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1202 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1204 hbox_stat = gtk_hbox_new(FALSE, 2);
1205 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1207 tips = gtk_tooltips_new();
1209 warning_icon = gtk_image_new_from_stock
1210 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1211 warning_btn = gtk_event_box_new();
1212 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1214 mainwin->warning_btn = warning_btn;
1216 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1217 G_CALLBACK(warning_icon_pressed),
1218 (gpointer) mainwin);
1219 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1220 G_CALLBACK(warning_visi_notify), mainwin);
1221 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1222 G_CALLBACK(warning_visi_notify), mainwin);
1223 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1224 G_CALLBACK(warning_leave_notify), mainwin);
1225 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1226 G_CALLBACK(warning_enter_notify), mainwin);
1228 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1230 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1231 _("Some error(s) happened. Click here to view log."), NULL);
1232 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1234 statusbar = statusbar_create();
1235 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1237 progressbar = gtk_progress_bar_new();
1238 gtk_widget_set_size_request(progressbar, 120, 1);
1239 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1241 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1242 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1243 online_switch = gtk_button_new ();
1244 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1245 _("You are online. Click the icon to go offline"), NULL);
1246 offline_switch = gtk_button_new ();
1247 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1248 _("You are offline. Click the icon to go online"),
1250 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1251 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1252 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1253 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1254 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1255 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1256 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1257 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1259 statuslabel = gtk_label_new("");
1260 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1262 ac_button = gtk_button_new();
1263 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1264 ac_button, _("Select account"), NULL);
1265 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1266 gtk_widget_set_size_request(ac_button, -1, 0);
1267 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1268 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1269 G_CALLBACK(ac_label_button_pressed), mainwin);
1271 ac_label = gtk_label_new("");
1272 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1274 gtk_widget_show_all(hbox_stat);
1276 gtk_widget_hide(offline_switch);
1277 gtk_widget_hide(warning_btn);
1279 mainwin->folderview = folderview = folderview_create();
1280 mainwin->summaryview = summaryview = summary_create();
1281 mainwin->messageview = messageview = messageview_create(mainwin);
1282 mainwin->logwin = log_window_create();
1284 log_window_init(mainwin->logwin);
1285 log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1286 prefs_common.loglength);
1288 folderview->mainwin = mainwin;
1289 folderview->summaryview = summaryview;
1291 summaryview->mainwin = mainwin;
1292 summaryview->folderview = folderview;
1293 summaryview->messageview = messageview;
1294 summaryview->window = window;
1296 messageview->statusbar = statusbar;
1297 mainwin->vbox = vbox;
1298 mainwin->menubar = menubar;
1299 mainwin->menu_factory = ifactory;
1300 mainwin->handlebox = handlebox;
1301 mainwin->vbox_body = vbox_body;
1302 mainwin->hbox_stat = hbox_stat;
1303 mainwin->statusbar = statusbar;
1304 mainwin->progressbar = progressbar;
1305 mainwin->statuslabel = statuslabel;
1306 mainwin->online_switch = online_switch;
1307 mainwin->online_pixmap = online_pixmap;
1308 mainwin->offline_pixmap = offline_pixmap;
1309 mainwin->ac_button = ac_button;
1310 mainwin->ac_label = ac_label;
1311 mainwin->offline_switch = offline_switch;
1313 /* set context IDs for status bar */
1314 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1315 (GTK_STATUSBAR(statusbar), "Main Window");
1316 mainwin->folderview_cid = gtk_statusbar_get_context_id
1317 (GTK_STATUSBAR(statusbar), "Folder View");
1318 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1319 (GTK_STATUSBAR(statusbar), "Summary View");
1320 mainwin->messageview_cid = gtk_statusbar_get_context_id
1321 (GTK_STATUSBAR(statusbar), "Message View");
1323 messageview->statusbar_cid = mainwin->messageview_cid;
1325 /* allocate colors for summary view and folder view */
1326 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1327 summaryview->color_marked.blue = (guint16)65535;
1329 summaryview->color_dim.red = summaryview->color_dim.green =
1330 summaryview->color_dim.blue = COLOR_DIM;
1332 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1333 &folderview->color_new);
1335 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1336 &folderview->color_op);
1338 summaryview->color_important.red = 0;
1339 summaryview->color_important.green = 0;
1340 summaryview->color_important.blue = (guint16)65535;
1342 color[0] = summaryview->color_marked;
1343 color[1] = summaryview->color_dim;
1344 color[2] = folderview->color_new;
1345 color[3] = folderview->color_op;
1347 colormap = gdk_drawable_get_colormap(window->window);
1348 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1349 for (i = 0; i < 4; i++) {
1350 if (success[i] == FALSE)
1351 g_warning("MainWindow: color allocation %d failed\n", i);
1354 debug_print("done.\n");
1356 messageview->visible = prefs_common.msgview_visible;
1358 main_window_set_widgets(mainwin, prefs_common.layout_mode);
1360 g_signal_connect(G_OBJECT(window), "size_allocate",
1361 G_CALLBACK(main_window_size_allocate_cb),
1364 /* set menu items */
1365 menuitem = gtk_item_factory_get_item
1366 (ifactory, "/View/Character encoding/Auto detect");
1367 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1369 switch (prefs_common.toolbar_style) {
1371 menuitem = gtk_item_factory_get_item
1372 (ifactory, "/View/Show or hide/Toolbar/Hide");
1375 menuitem = gtk_item_factory_get_item
1376 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1379 menuitem = gtk_item_factory_get_item
1380 (ifactory, "/View/Show or hide/Toolbar/Text only");
1383 menuitem = gtk_item_factory_get_item
1384 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1386 case TOOLBAR_BOTH_HORIZ:
1387 menuitem = gtk_item_factory_get_item
1389 "/View/Show or hide/Toolbar/Text beside icons");
1391 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1393 gtk_widget_hide(mainwin->hbox_stat);
1394 menuitem = gtk_item_factory_get_item
1395 (ifactory, "/View/Show or hide/Status bar");
1396 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1397 prefs_common.show_statusbar);
1399 /* set account selection menu */
1400 ac_menu = gtk_item_factory_get_widget
1401 (ifactory, "/Configuration/Change current account");
1402 mainwin->ac_menu = ac_menu;
1404 toolbar_main_set_sensitive(mainwin);
1406 /* create actions menu */
1407 main_window_update_actions_menu(mainwin);
1409 main_create_mailing_list_menu (mainwin, NULL);
1411 /* attach accel groups to main window */
1412 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1413 gtk_window_add_accel_group \
1415 gtk_item_factory_from_widget(menu)->accel_group); \
1416 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1418 G_CALLBACK(main_window_accel_activate), mainwin);
1421 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1423 /* connect the accelerators for equivalent
1424 menu items in different menus */
1425 menu_connect_identical_items();
1427 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1429 g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1430 G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1431 gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1433 if (prefs_common.layout_mode == VERTICAL_LAYOUT)
1434 summary_relayout(mainwin->summaryview);
1436 gtk_widget_show(mainwin->window);
1438 /* initialize views */
1439 folderview_init(folderview);
1440 summary_init(summaryview);
1441 messageview_init(messageview);
1443 sslcertwindow_register_hook();
1445 mainwin->lock_count = 0;
1446 mainwin->menu_lock_count = 0;
1447 mainwin->cursor_count = 0;
1449 mainwin->progressindicator_hook =
1450 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1453 watch_cursor = gdk_cursor_new(GDK_WATCH);
1455 hand_cursor = gdk_cursor_new(GDK_HAND2);
1457 mainwin_list = g_list_append(mainwin_list, mainwin);
1459 /* init work_offline */
1460 if (prefs_common.work_offline)
1461 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1463 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1468 void main_window_destroy(MainWindow *mainwin)
1470 /* TODO : destroy other component */
1471 messageview_destroy(mainwin->messageview);
1472 mainwin->messageview = NULL;
1475 void main_window_update_actions_menu(MainWindow *mainwin)
1477 GtkItemFactory *ifactory;
1479 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1480 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1483 void main_window_cursor_wait(MainWindow *mainwin)
1486 if (mainwin->cursor_count == 0) {
1487 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1488 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1491 mainwin->cursor_count++;
1496 void main_window_cursor_normal(MainWindow *mainwin)
1498 if (mainwin->cursor_count)
1499 mainwin->cursor_count--;
1501 if (mainwin->cursor_count == 0) {
1502 gdk_window_set_cursor(mainwin->window->window, NULL);
1503 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1508 /* lock / unlock the user-interface */
1509 void main_window_lock(MainWindow *mainwin)
1511 if (mainwin->lock_count == 0)
1512 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1514 mainwin->lock_count++;
1516 main_window_set_menu_sensitive(mainwin);
1517 toolbar_main_set_sensitive(mainwin);
1520 void main_window_unlock(MainWindow *mainwin)
1522 if (mainwin->lock_count)
1523 mainwin->lock_count--;
1525 main_window_set_menu_sensitive(mainwin);
1526 toolbar_main_set_sensitive(mainwin);
1528 if (mainwin->lock_count == 0)
1529 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1532 static void main_window_menu_callback_block(MainWindow *mainwin)
1534 mainwin->menu_lock_count++;
1537 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1539 if (mainwin->menu_lock_count)
1540 mainwin->menu_lock_count--;
1543 static guint prefs_tag = 0;
1545 void main_window_reflect_prefs_all(void)
1547 main_window_reflect_prefs_all_real(FALSE);
1550 static gboolean reflect_prefs_timeout_cb(gpointer data)
1552 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1554 MainWindow *mainwin;
1557 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1558 mainwin = (MainWindow *)cur->data;
1560 main_window_show_cur_account(mainwin);
1561 main_window_set_menu_sensitive(mainwin);
1562 toolbar_main_set_sensitive(mainwin);
1565 if (pixmap_theme_changed) {
1566 toolbar_update(TOOLBAR_MAIN, mainwin);
1567 messageview_reflect_prefs_pixmap_theme();
1568 compose_reflect_prefs_pixmap_theme();
1569 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1570 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1572 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1573 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1574 mainwin->online_pixmap);
1575 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1576 gtk_widget_show(pixmap);
1577 mainwin->online_pixmap = pixmap;
1578 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1579 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1580 mainwin->offline_pixmap);
1581 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1582 gtk_widget_show(pixmap);
1583 mainwin->offline_pixmap = pixmap;
1586 headerview_set_font(mainwin->messageview->headerview);
1587 headerview_set_visibility(mainwin->messageview->headerview,
1588 prefs_common.display_header_pane);
1589 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1590 folderview_reflect_prefs();
1591 summary_reflect_prefs();
1592 summary_redisplay_msg(mainwin->summaryview);
1598 void main_window_reflect_prefs_all_now(void)
1600 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1603 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1608 /* re-create colorlabel submenu */
1609 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1610 g_return_if_fail(menu != NULL);
1612 /* clear items. get item pointers. */
1613 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1614 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1616 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1617 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1621 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1623 if (prefs_tag == 0 || pixmap_theme_changed) {
1624 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1625 GINT_TO_POINTER(pixmap_theme_changed));
1629 void main_window_set_summary_column(void)
1632 MainWindow *mainwin;
1634 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1635 mainwin = (MainWindow *)cur->data;
1636 summary_set_column_order(mainwin->summaryview);
1640 void main_window_set_folder_column(void)
1643 MainWindow *mainwin;
1645 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1646 mainwin = (MainWindow *)cur->data;
1647 folderview_set_column_order(mainwin->folderview);
1651 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1652 GList *account_list)
1654 GList *cur_ac, *cur_item;
1655 GtkWidget *menuitem;
1656 PrefsAccount *ac_prefs;
1658 /* destroy all previous menu item */
1659 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1660 while (cur_item != NULL) {
1661 GList *next = cur_item->next;
1662 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1666 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1667 ac_prefs = (PrefsAccount *)cur_ac->data;
1669 menuitem = gtk_menu_item_new_with_label
1670 (ac_prefs->account_name
1671 ? ac_prefs->account_name : _("Untitled"));
1672 gtk_widget_show(menuitem);
1673 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1674 g_signal_connect(G_OBJECT(menuitem), "activate",
1675 G_CALLBACK(account_selector_menu_cb),
1680 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1681 GList *account_list)
1683 GList *cur_ac, *cur_item;
1685 GtkWidget *menuitem;
1686 PrefsAccount *ac_prefs;
1688 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1689 "/Message/Receive");
1691 /* search for separator */
1692 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1693 cur_item = cur_item->next) {
1694 if (GTK_BIN(cur_item->data)->child == NULL) {
1695 cur_item = cur_item->next;
1700 /* destroy all previous menu item */
1701 while (cur_item != NULL) {
1702 GList *next = cur_item->next;
1703 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1707 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1708 ac_prefs = (PrefsAccount *)cur_ac->data;
1710 menuitem = gtk_menu_item_new_with_label
1711 (ac_prefs->account_name ? ac_prefs->account_name
1713 gtk_widget_show(menuitem);
1714 gtk_menu_append(GTK_MENU(menu), menuitem);
1715 g_signal_connect(G_OBJECT(menuitem), "activate",
1716 G_CALLBACK(account_receive_menu_cb),
1721 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1722 GList *account_list)
1724 GList *cur_ac, *cur_item;
1725 GtkWidget *menuitem;
1726 PrefsAccount *ac_prefs;
1727 GtkWidget *menu = NULL;
1729 if (mainwin->toolbar->getall_btn == NULL
1730 || mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1733 menu = mainwin->toolbar->getall_combo->menu;
1735 /* destroy all previous menu item */
1736 cur_item = GTK_MENU_SHELL(menu)->children;
1737 while (cur_item != NULL) {
1738 GList *next = cur_item->next;
1739 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1743 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1744 ac_prefs = (PrefsAccount *)cur_ac->data;
1746 menuitem = gtk_menu_item_new_with_label
1747 (ac_prefs->account_name
1748 ? ac_prefs->account_name : _("Untitled"));
1749 gtk_widget_show(menuitem);
1750 gtk_menu_append(GTK_MENU(menu), menuitem);
1751 g_signal_connect(G_OBJECT(menuitem), "activate",
1752 G_CALLBACK(account_receive_menu_cb),
1757 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1758 GList *account_list)
1760 GList *cur_ac, *cur_item;
1761 GtkWidget *menuitem;
1762 PrefsAccount *ac_prefs;
1763 GtkWidget *menu = NULL;
1765 if (mainwin->toolbar->compose_mail_btn == NULL
1766 || mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1769 menu = mainwin->toolbar->compose_combo->menu;
1771 /* destroy all previous menu item */
1772 cur_item = GTK_MENU_SHELL(menu)->children;
1773 while (cur_item != NULL) {
1774 GList *next = cur_item->next;
1775 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1779 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1780 ac_prefs = (PrefsAccount *)cur_ac->data;
1782 menuitem = gtk_menu_item_new_with_label
1783 (ac_prefs->account_name
1784 ? ac_prefs->account_name : _("Untitled"));
1785 gtk_widget_show(menuitem);
1786 gtk_menu_append(GTK_MENU(menu), menuitem);
1787 g_signal_connect(G_OBJECT(menuitem), "activate",
1788 G_CALLBACK(account_compose_menu_cb),
1793 void main_window_set_account_menu(GList *account_list)
1796 MainWindow *mainwin;
1798 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1799 mainwin = (MainWindow *)cur->data;
1800 main_window_set_account_selector_menu(mainwin, account_list);
1801 main_window_set_account_receive_menu(mainwin, account_list);
1802 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1803 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1805 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
1808 void main_window_set_account_menu_only_toolbar(GList *account_list)
1811 MainWindow *mainwin;
1813 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1814 mainwin = (MainWindow *)cur->data;
1815 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1816 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1820 static void main_window_show_cur_account(MainWindow *mainwin)
1825 ac_name = g_strdup(cur_account
1826 ? (cur_account->account_name
1827 ? cur_account->account_name : _("Untitled"))
1831 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1833 buf = g_strdup(PROG_VERSION);
1834 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1837 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1838 gtk_widget_queue_resize(mainwin->ac_button);
1843 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
1845 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
1846 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1847 GtkWidget *message_wid = mainwin->messageview->vbox;
1849 if (layout_mode == prefs_common.layout_mode)
1852 debug_print("Changing window separation type from %d to %d\n",
1853 prefs_common.layout_mode, layout_mode);
1855 /* remove widgets from those containers */
1856 gtk_widget_ref(folder_wid);
1857 gtk_widget_ref(summary_wid);
1858 gtk_widget_ref(message_wid);
1859 gtkut_container_remove
1860 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1861 gtkut_container_remove
1862 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1863 gtkut_container_remove
1864 (GTK_CONTAINER(message_wid->parent), message_wid);
1866 gtk_widget_hide(mainwin->window);
1867 main_window_set_widgets(mainwin, layout_mode);
1868 gtk_widget_show(mainwin->window);
1870 gtk_widget_unref(folder_wid);
1871 gtk_widget_unref(summary_wid);
1872 gtk_widget_unref(message_wid);
1875 static void mainwin_reset_paned(GtkPaned *paned)
1878 g_object_get (G_OBJECT(paned),
1881 g_object_get (G_OBJECT(paned),
1886 gtk_paned_set_position(GTK_PANED(paned), mid);
1889 void main_window_toggle_message_view(MainWindow *mainwin)
1891 SummaryView *summaryview = mainwin->summaryview;
1892 GtkWidget *ppaned = NULL;
1893 GtkWidget *container = NULL;
1895 switch (prefs_common.layout_mode) {
1897 case VERTICAL_LAYOUT:
1898 ppaned = mainwin->vpaned;
1899 container = mainwin->hpaned;
1900 if (ppaned->parent != NULL) {
1901 mainwin->messageview->visible = FALSE;
1902 summaryview->displayed = NULL;
1903 gtk_widget_ref(ppaned);
1904 gtkut_container_remove(GTK_CONTAINER(container), ppaned);
1905 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1907 mainwin->messageview->visible = TRUE;
1908 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
1909 gtk_container_add(GTK_CONTAINER(container), ppaned);
1910 gtk_widget_unref(ppaned);
1914 ppaned = mainwin->hpaned;
1915 container = mainwin->vpaned;
1916 if (mainwin->messageview->vbox->parent != NULL) {
1917 mainwin->messageview->visible = FALSE;
1918 summaryview->displayed = NULL;
1919 gtk_widget_ref(mainwin->messageview->vbox);
1920 gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
1922 mainwin->messageview->visible = TRUE;
1923 gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
1924 gtk_widget_unref(mainwin->messageview->vbox);
1927 case WIDE_MSGLIST_LAYOUT:
1928 g_warning("can't hide messageview in this wide msglist layout");
1932 if (messageview_is_visible(mainwin->messageview))
1933 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1934 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1936 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1937 GTK_ARROW_UP, GTK_SHADOW_OUT);
1939 if (mainwin->messageview->visible == FALSE)
1940 messageview_clear(mainwin->messageview);
1942 main_window_set_menu_sensitive(mainwin);
1944 prefs_common.msgview_visible = mainwin->messageview->visible;
1946 if (messageview_is_visible(mainwin->messageview)) {
1947 gtk_widget_queue_resize(mainwin->hpaned);
1948 gtk_widget_queue_resize(mainwin->vpaned);
1950 summary_grab_focus(summaryview);
1953 void main_window_get_size(MainWindow *mainwin)
1955 GtkAllocation *allocation;
1957 if (mainwin_list == NULL || mainwin->messageview == NULL) {
1958 debug_print("called after messageview "
1959 "has been deallocated!\n");
1963 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1965 if (allocation->width > 1 && allocation->height > 1) {
1966 prefs_common.summaryview_width = allocation->width;
1968 if (messageview_is_visible(mainwin->messageview))
1969 prefs_common.summaryview_height = allocation->height;
1971 prefs_common.mainview_width = allocation->width;
1974 allocation = &mainwin->window->allocation;
1975 if (allocation->width > 1 && allocation->height > 1) {
1976 prefs_common.mainview_height = allocation->height;
1977 prefs_common.mainwin_width = allocation->width;
1978 prefs_common.mainwin_height = allocation->height;
1981 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1982 if (allocation->width > 1 && allocation->height > 1) {
1983 prefs_common.folderview_width = allocation->width;
1984 prefs_common.folderview_height = allocation->height;
1987 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
1988 if (allocation->width > 1 && allocation->height > 1) {
1989 prefs_common.msgview_width = allocation->width;
1990 prefs_common.msgview_height = allocation->height;
1993 /* debug_print("summaryview size: %d x %d\n",
1994 prefs_common.summaryview_width,
1995 prefs_common.summaryview_height);
1996 debug_print("folderview size: %d x %d\n",
1997 prefs_common.folderview_width,
1998 prefs_common.folderview_height);
1999 debug_print("messageview size: %d x %d\n",
2000 prefs_common.msgview_width,
2001 prefs_common.msgview_height); */
2004 void main_window_get_position(MainWindow *mainwin)
2008 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2010 prefs_common.mainview_x = x;
2011 prefs_common.mainview_y = y;
2012 prefs_common.mainwin_x = x;
2013 prefs_common.mainwin_y = y;
2015 debug_print("main window position: %d, %d\n", x, y);
2018 void main_window_progress_on(MainWindow *mainwin)
2020 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2023 void main_window_progress_off(MainWindow *mainwin)
2025 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2026 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2029 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2033 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2034 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2035 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2036 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2039 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2042 if (alertpanel(_("Empty trash"),
2043 _("Delete all messages in trash folders?"),
2044 GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
2045 != G_ALERTALTERNATE)
2047 manage_window_focus_in(mainwin->window, NULL, NULL);
2050 procmsg_empty_all_trash();
2052 if (mainwin->summaryview->folder_item &&
2053 mainwin->summaryview->folder_item->stype == F_TRASH)
2054 gtk_widget_grab_focus(mainwin->folderview->ctree);
2057 void main_window_add_mailbox(MainWindow *mainwin)
2062 path = input_dialog(_("Add mailbox"),
2063 _("Input the location of mailbox.\n"
2064 "If the existing mailbox is specified, it will be\n"
2065 "scanned automatically."),
2068 if (folder_find_from_path(path)) {
2069 alertpanel_error(_("The mailbox '%s' already exists."), path);
2073 folder = folder_new(folder_get_class_from_string("mh"),
2074 !strcmp(path, "Mail") ? _("Mailbox") :
2075 g_path_get_basename(path), path);
2078 if (folder->klass->create_tree(folder) < 0) {
2079 alertpanel_error(_("Creation of the mailbox failed.\n"
2080 "Maybe some files already exist, or you don't have the permission to write there."));
2081 folder_destroy(folder);
2086 folder_set_ui_func(folder, scan_tree_func, mainwin);
2087 folder_scan_tree(folder, TRUE);
2088 folder_set_ui_func(folder, NULL, NULL);
2091 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2093 SensitiveCond state = 0;
2094 SummarySelection selection;
2095 FolderItem *item = mainwin->summaryview->folder_item;
2096 GList *account_list = account_get_list();
2098 selection = summary_get_selection_type(mainwin->summaryview);
2100 if (mainwin->lock_count == 0)
2101 state |= M_UNLOCKED;
2102 if (selection != SUMMARY_NONE)
2103 state |= M_MSG_EXIST;
2104 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2106 /* if (item->folder->type != F_NEWS) */
2107 state |= M_ALLOW_DELETE;
2109 if (prefs_common.immediate_exec == 0
2110 && mainwin->lock_count == 0)
2111 state |= M_DELAY_EXEC;
2113 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2114 || selection != SUMMARY_NONE)
2115 state |= M_HIDE_READ_MSG;
2117 if (mainwin->summaryview->threaded)
2118 state |= M_THREADED;
2120 state |= M_UNTHREADED;
2121 if (selection == SUMMARY_SELECTED_SINGLE ||
2122 selection == SUMMARY_SELECTED_MULTIPLE)
2123 state |= M_TARGET_EXIST;
2124 if (selection == SUMMARY_SELECTED_SINGLE)
2125 state |= M_SINGLE_TARGET_EXIST;
2126 if (mainwin->summaryview->folder_item &&
2127 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2130 state |= M_NOT_NEWS;
2131 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2132 state |= M_ACTIONS_EXIST;
2134 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2135 state |= M_HAVE_QUEUED_MAILS;
2137 if (selection == SUMMARY_SELECTED_SINGLE &&
2139 (folder_has_parent_of_type(item, F_DRAFT) ||
2140 folder_has_parent_of_type(item, F_OUTBOX) ||
2141 folder_has_parent_of_type(item, F_QUEUE))))
2142 state |= M_ALLOW_REEDIT;
2144 state |= M_HAVE_ACCOUNT;
2146 if (any_folder_want_synchronise())
2147 state |= M_WANT_SYNC;
2149 for ( ; account_list != NULL; account_list = account_list->next) {
2150 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2151 state |= M_HAVE_NEWS_ACCOUNT;
2156 if (procmsg_spam_can_learn() &&
2157 (mainwin->summaryview->folder_item &&
2158 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2159 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2160 state |= M_CAN_LEARN_SPAM;
2163 if (inc_is_active())
2164 state |= M_INC_ACTIVE;
2166 if (mainwin->summaryview->deleted > 0 ||
2167 mainwin->summaryview->moved > 0 ||
2168 mainwin->summaryview->copied > 0)
2169 state |= M_DELAY_EXEC;
2176 void main_window_set_menu_sensitive(MainWindow *mainwin)
2178 GtkItemFactory *ifactory = mainwin->menu_factory;
2179 SensitiveCond state;
2182 GtkWidget *menuitem;
2183 SummaryView *summaryview;
2188 static const struct {
2192 {"/File/Save as...", M_TARGET_EXIST},
2193 {"/File/Print..." , M_TARGET_EXIST},
2194 {"/File/Synchronise folders", M_WANT_SYNC},
2195 {"/File/Exit" , M_UNLOCKED},
2197 {"/Edit/Select thread" , M_SINGLE_TARGET_EXIST},
2198 {"/Edit/Delete thread" , M_SINGLE_TARGET_EXIST},
2199 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2201 {"/View/Set displayed columns/in Folder list..."
2203 {"/View/Sort" , M_EXEC},
2204 {"/View/Thread view" , M_EXEC},
2205 {"/View/Expand all threads" , M_MSG_EXIST},
2206 {"/View/Collapse all threads" , M_MSG_EXIST},
2207 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2208 {"/View/Go to/Previous message" , M_MSG_EXIST},
2209 {"/View/Go to/Next message" , M_MSG_EXIST},
2210 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2211 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2212 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2213 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2214 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2215 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2216 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2217 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2218 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2219 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2220 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2222 {"/Message/Receive/Get from current account"
2223 , M_HAVE_ACCOUNT|M_UNLOCKED},
2224 {"/Message/Receive/Get from all accounts"
2225 , M_HAVE_ACCOUNT|M_UNLOCKED},
2226 {"/Message/Receive/Cancel receiving"
2228 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2229 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2230 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2231 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2232 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2233 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2234 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2235 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2236 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2237 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2238 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2239 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2240 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2241 {"/Message/Mark" , M_TARGET_EXIST},
2242 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2243 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2244 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2245 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2246 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2247 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2248 {"/Message/Color label" , M_TARGET_EXIST},
2249 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2251 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2252 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2253 {"/Tools/Harvest addresses/from Messages..."
2255 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2256 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2257 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2258 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2259 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2260 {"/Tools/Execute" , M_DELAY_EXEC},
2261 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2263 {"/Configuration", M_UNLOCKED},
2268 state = main_window_get_current_state(mainwin);
2270 for (i = 0; entry[i].entry != NULL; i++) {
2271 sensitive = ((entry[i].cond & state) == entry[i].cond);
2272 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2275 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2277 /* search for separator */
2278 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2279 cur_item = cur_item->next) {
2280 if (GTK_BIN(cur_item->data)->child == NULL) {
2281 cur_item = cur_item->next;
2286 for (; cur_item != NULL; cur_item = cur_item->next) {
2287 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2288 (M_UNLOCKED & state) != 0);
2291 main_window_menu_callback_block(mainwin);
2293 #define SET_CHECK_MENU_ACTIVE(path, active) \
2295 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2296 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2299 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2300 messageview_is_visible(mainwin->messageview));
2302 summaryview = mainwin->summaryview;
2303 menu_path = "/View/Sort/Don't sort";
2305 switch (summaryview->sort_key) {
2306 case SORT_BY_NUMBER:
2307 menu_path = "/View/Sort/by number"; break;
2309 menu_path = "/View/Sort/by Size"; break;
2311 menu_path = "/View/Sort/by Date"; break;
2313 menu_path = "/View/Sort/by From"; break;
2315 menu_path = "/View/Sort/by To"; break;
2316 case SORT_BY_SUBJECT:
2317 menu_path = "/View/Sort/by Subject"; break;
2319 menu_path = "/View/Sort/by color label"; break;
2321 menu_path = "/View/Sort/by mark"; break;
2322 case SORT_BY_STATUS:
2323 menu_path = "/View/Sort/by status"; break;
2325 menu_path = "/View/Sort/by attachment"; break;
2327 menu_path = "/View/Sort/by score"; break;
2328 case SORT_BY_LOCKED:
2329 menu_path = "/View/Sort/by locked"; break;
2332 menu_path = "/View/Sort/Don't sort"; break;
2334 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2336 if (summaryview->sort_type == SORT_ASCENDING) {
2337 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2339 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2342 if (summaryview->sort_key != SORT_BY_NONE) {
2343 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2344 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2346 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2347 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2350 if (mainwin->messageview
2351 && mainwin->messageview->mimeview
2352 && mainwin->messageview->mimeview->textview)
2353 SET_CHECK_MENU_ACTIVE("/View/All headers",
2354 mainwin->messageview->mimeview->textview->show_all_headers);
2355 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2356 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2357 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2358 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2359 if (prefs_common.hide_quotes == 1)
2360 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2361 if (prefs_common.hide_quotes == 2)
2362 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2363 if (prefs_common.hide_quotes == 3)
2364 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2366 #undef SET_CHECK_MENU_ACTIVE
2368 main_window_menu_callback_unblock(mainwin);
2371 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2373 GtkItemFactory *ifactory;
2375 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2378 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2380 gtk_widget_set_sensitive (gtk_item_factory_get_item
2381 (ifactory,"/Message/Mailing-List"), TRUE);
2383 gtk_widget_set_sensitive (gtk_item_factory_get_item
2384 (ifactory,"/Message/Mailing-List"), FALSE);
2387 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2390 GtkWidget *menuitem;
2392 if (!msginfo || !msginfo->extradata) {
2393 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2394 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2395 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2396 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2397 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2398 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2402 /* Mailing list post */
2403 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2404 g_free(msginfo->extradata->list_post);
2405 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2407 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2409 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2411 /* Mailing list help */
2412 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2414 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2416 /* Mailing list subscribe */
2417 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2419 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2421 /* Mailing list unsubscribe */
2422 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2424 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2426 /* Mailing list view archive */
2427 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2429 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2431 /* Mailing list contact owner */
2432 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2434 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2439 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2441 GtkWidget *item, *menu;
2442 const gchar *url_pt ;
2443 gchar url_decoded[BUFFSIZE];
2444 GList *amenu, *alist;
2447 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2449 /* First delete old submenu */
2450 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2451 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2452 alist = amenu->next;
2453 item = GTK_WIDGET (amenu->data);
2454 gtk_widget_destroy (item);
2458 for (url_pt = list_header; url_pt && *url_pt;) {
2459 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2461 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2462 item = gtk_menu_item_new_with_label ((url_decoded));
2463 g_signal_connect(G_OBJECT(item), "activate",
2464 G_CALLBACK(mailing_list_compose),
2467 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2468 !g_strncasecmp (url_decoded, "https:",6)) {
2470 item = gtk_menu_item_new_with_label ((url_decoded));
2471 g_signal_connect(G_OBJECT(item), "activate",
2472 G_CALLBACK(mailing_list_open_uri),
2476 gtk_menu_append (GTK_MENU(menu), item);
2477 gtk_widget_show (item);
2483 gtk_widget_set_sensitive (menuitem, TRUE);
2485 gtk_widget_set_sensitive (menuitem, FALSE);
2491 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2493 gchar tmp[BUFFSIZE];
2499 *url_decoded = '\0';
2503 /* Ignore spaces, comments and tabs () */
2504 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2506 for (;*buf != ')' && *buf != 0x00; buf++);
2508 /* First non space and non comment must be a < */
2511 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2516 *url_decoded = '\0';
2521 *url_decoded = '\0';
2527 decode_uri (url_decoded, (const gchar *)tmp);
2529 /* Prepare the work for the next url in the list */
2530 /* after the closing bracket >, ignore space, comments and tabs */
2531 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2533 for (;*buf != ')' && *buf != 0x00; buf++);
2535 if (!buf || !*buf) {
2540 /* now first non space, non comment must be a comma */
2542 for (;*buf != 0x00; buf++);
2548 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2552 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2553 compose_new(NULL, mailto+7, NULL);
2556 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2561 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2562 open_uri (mailto, prefs_common.uri_cmd);
2565 void main_window_popup(MainWindow *mainwin)
2567 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2568 main_window_show(mainwin);
2570 gtkut_window_popup(mainwin->window);
2573 void main_window_show(MainWindow *mainwin)
2575 gtk_widget_show(mainwin->window);
2576 gtk_widget_show(mainwin->vbox_body);
2578 gtk_widget_set_uposition(mainwin->window,
2579 prefs_common.mainwin_x,
2580 prefs_common.mainwin_y);
2582 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2583 prefs_common.folderview_width,
2584 prefs_common.folderview_height);
2585 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2586 prefs_common.summaryview_width,
2587 prefs_common.summaryview_height);
2588 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2589 prefs_common.msgview_width,
2590 prefs_common.msgview_height);
2593 void main_window_hide(MainWindow *mainwin)
2595 main_window_get_size(mainwin);
2596 main_window_get_position(mainwin);
2598 gtk_widget_hide(mainwin->window);
2599 gtk_widget_hide(mainwin->vbox_body);
2602 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2604 GtkWidget *folderwin = NULL;
2605 GtkWidget *messagewin = NULL;
2608 GtkWidget *vbox_body = mainwin->vbox_body;
2609 GtkItemFactory *ifactory = mainwin->menu_factory;
2610 GtkWidget *menuitem;
2612 debug_print("Setting widgets... ");
2614 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2615 prefs_common.folderview_width,
2616 prefs_common.folderview_height);
2617 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2618 prefs_common.summaryview_width,
2619 prefs_common.summaryview_height);
2620 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2621 prefs_common.msgview_width,
2622 prefs_common.msgview_height);
2624 mainwin->messageview->statusbar = mainwin->statusbar;
2625 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2627 /* clean top-most container */
2628 if (mainwin->hpaned) {
2629 if (mainwin->hpaned->parent == mainwin->vpaned)
2630 gtk_widget_destroy(mainwin->vpaned);
2632 gtk_widget_destroy(mainwin->hpaned);
2635 menu_set_sensitive(ifactory, "/View/Show or hide/Message view", (layout_mode != WIDE_MSGLIST_LAYOUT));
2636 switch (layout_mode) {
2637 case VERTICAL_LAYOUT:
2639 hpaned = gtk_hpaned_new();
2640 if (layout_mode == VERTICAL_LAYOUT)
2641 vpaned = gtk_hpaned_new();
2643 vpaned = gtk_vpaned_new();
2644 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2645 gtk_paned_add1(GTK_PANED(hpaned),
2646 GTK_WIDGET_PTR(mainwin->folderview));
2647 gtk_widget_show(hpaned);
2648 gtk_widget_queue_resize(hpaned);
2650 if (messageview_is_visible(mainwin->messageview)) {
2651 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2652 gtk_paned_add1(GTK_PANED(vpaned),
2653 GTK_WIDGET_PTR(mainwin->summaryview));
2655 gtk_paned_add2(GTK_PANED(hpaned),
2656 GTK_WIDGET_PTR(mainwin->summaryview));
2657 gtk_widget_ref(vpaned);
2659 gtk_paned_add2(GTK_PANED(vpaned),
2660 GTK_WIDGET_PTR(mainwin->messageview));
2661 gtk_widget_show(vpaned);
2662 gtk_widget_queue_resize(vpaned);
2665 vpaned = gtk_vpaned_new();
2666 hpaned = gtk_hpaned_new();
2667 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2668 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2670 gtk_paned_add1(GTK_PANED(hpaned),
2671 GTK_WIDGET_PTR(mainwin->folderview));
2672 gtk_paned_add2(GTK_PANED(hpaned),
2673 GTK_WIDGET_PTR(mainwin->summaryview));
2675 gtk_widget_show(hpaned);
2676 gtk_widget_queue_resize(hpaned);
2678 if (messageview_is_visible(mainwin->messageview)) {
2679 gtk_paned_add2(GTK_PANED(vpaned),
2680 GTK_WIDGET_PTR(mainwin->messageview));
2682 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2684 gtk_widget_show(vpaned);
2685 gtk_widget_queue_resize(vpaned);
2687 case WIDE_MSGLIST_LAYOUT:
2688 vpaned = gtk_vpaned_new();
2689 hpaned = gtk_hpaned_new();
2690 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2692 gtk_paned_add1(GTK_PANED(vpaned),
2693 GTK_WIDGET_PTR(mainwin->summaryview));
2694 gtk_paned_add1(GTK_PANED(hpaned),
2695 GTK_WIDGET_PTR(mainwin->folderview));
2697 gtk_widget_show(hpaned);
2698 gtk_widget_queue_resize(hpaned);
2700 if (messageview_is_visible(mainwin->messageview)) {
2701 gtk_paned_add2(GTK_PANED(hpaned),
2702 GTK_WIDGET_PTR(mainwin->messageview));
2704 gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2706 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
2708 gtk_widget_show(vpaned);
2709 gtk_widget_queue_resize(vpaned);
2712 g_warning("Unknown layout");
2716 mainwin->hpaned = hpaned;
2717 mainwin->vpaned = vpaned;
2719 /* remove headerview if not in prefs */
2720 headerview_set_visibility(mainwin->messageview->headerview,
2721 prefs_common.display_header_pane);
2723 if (messageview_is_visible(mainwin->messageview))
2724 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2725 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2727 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2728 GTK_ARROW_UP, GTK_SHADOW_OUT);
2730 gtk_window_move(GTK_WINDOW(mainwin->window),
2731 prefs_common.mainwin_x,
2732 prefs_common.mainwin_y);
2734 gtk_widget_queue_resize(vbox_body);
2735 gtk_widget_queue_resize(mainwin->vbox);
2736 gtk_widget_queue_resize(mainwin->window);
2737 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2738 * and mimeview icon list/ctree lose track of their visibility states */
2739 if (!noticeview_is_visible(mainwin->messageview->noticeview))
2740 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2741 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
2742 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2743 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2744 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2746 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2748 prefs_common.layout_mode = layout_mode;
2750 menuitem = gtk_item_factory_get_item
2751 (ifactory, "/View/Show or hide/Message view");
2752 gtk_check_menu_item_set_active
2753 (GTK_CHECK_MENU_ITEM(menuitem),
2754 messageview_is_visible(mainwin->messageview));
2756 #define SET_CHECK_MENU_ACTIVE(path, active) \
2758 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2759 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2762 switch (prefs_common.layout_mode) {
2764 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
2766 case VERTICAL_LAYOUT:
2767 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
2770 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
2772 case WIDE_MSGLIST_LAYOUT:
2773 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
2776 #undef SET_CHECK_MENU_ACTIVE
2780 (G_OBJECT(folderwin), "size_allocate",
2781 G_CALLBACK(folder_window_size_allocate_cb),
2786 (G_OBJECT(messagewin), "size_allocate",
2787 G_CALLBACK(message_window_size_allocate_cb),
2791 debug_print("done.\n");
2794 void main_window_destroy_all(void)
2796 while (mainwin_list != NULL) {
2797 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2799 /* free toolbar stuff */
2800 toolbar_clear_list(TOOLBAR_MAIN);
2801 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2802 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2804 mainwin->folderview->mainwin = NULL;
2805 mainwin->summaryview->mainwin = NULL;
2806 mainwin->messageview->mainwin = NULL;
2808 g_free(mainwin->toolbar);
2811 mainwin_list = g_list_remove(mainwin_list, mainwin);
2813 g_list_free(mainwin_list);
2814 mainwin_list = NULL;
2817 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2820 gtk_widget_set_size_request(child, 1, -1);
2823 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2826 gtk_widget_set_size_request(child, -1, -1);
2829 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2832 MainWindow *mainwin = (MainWindow *)data;
2834 if (!event) return FALSE;
2836 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2837 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2840 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2841 menu_button_position, widget,
2842 event->button, event->time);
2847 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2850 MainWindow *mainwin = (MainWindow *)data;
2851 gboolean close_allowed = TRUE;
2853 hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
2855 if (close_allowed && mainwin->lock_count == 0)
2856 app_exit_cb(data, 0, widget);
2861 static void main_window_size_allocate_cb(GtkWidget *widget,
2862 GtkAllocation *allocation,
2865 MainWindow *mainwin = (MainWindow *)data;
2867 main_window_get_size(mainwin);
2870 static void folder_window_size_allocate_cb(GtkWidget *widget,
2871 GtkAllocation *allocation,
2874 MainWindow *mainwin = (MainWindow *)data;
2876 main_window_get_size(mainwin);
2879 static void message_window_size_allocate_cb(GtkWidget *widget,
2880 GtkAllocation *allocation,
2883 MainWindow *mainwin = (MainWindow *)data;
2885 main_window_get_size(mainwin);
2888 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2891 main_window_add_mailbox(mainwin);
2894 static void update_folderview_cb(MainWindow *mainwin, guint action,
2897 summary_show(mainwin->summaryview, NULL);
2898 folderview_check_new_all();
2901 static void foldersort_cb(MainWindow *mainwin, guint action,
2907 static void import_mbox_cb(MainWindow *mainwin, guint action,
2910 /* only notify if import has failed */
2911 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2912 alertpanel_error(_("Mbox import has failed."));
2916 static void export_mbox_cb(MainWindow *mainwin, guint action,
2919 /* only notify if export has failed */
2920 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2921 alertpanel_error(_("Export to mbox has failed."));
2925 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2928 /* only notify if export has failed */
2929 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
2930 alertpanel_error(_("Export to mbox has failed."));
2934 static void empty_trash_cb(MainWindow *mainwin, guint action,
2937 main_window_empty_trash(mainwin, TRUE);
2940 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2942 summary_save_as(mainwin->summaryview);
2945 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2947 summary_print(mainwin->summaryview);
2950 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2952 if (prefs_common.confirm_on_exit) {
2953 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
2954 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
2955 != G_ALERTALTERNATE)
2957 manage_window_focus_in(mainwin->window, NULL, NULL);
2960 app_will_exit(widget, mainwin);
2963 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2966 summary_search(mainwin->summaryview);
2968 message_search(mainwin->messageview);
2971 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
2973 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
2976 static void toggle_message_cb(MainWindow *mainwin, guint action,
2981 active = GTK_CHECK_MENU_ITEM(widget)->active;
2983 if (active != messageview_is_visible(mainwin->messageview))
2984 summary_toggle_view(mainwin->summaryview);
2987 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2990 toolbar_toggle(action, mainwin);
2993 static void main_window_reply_cb(MainWindow *mainwin, guint action,
2996 MessageView *msgview = (MessageView*)mainwin->messageview;
2997 GSList *msginfo_list = NULL;
2999 g_return_if_fail(msgview != NULL);
3001 msginfo_list = summary_get_selection(mainwin->summaryview);
3002 g_return_if_fail(msginfo_list != NULL);
3003 compose_reply_from_messageview(msgview, msginfo_list, action);
3004 g_slist_free(msginfo_list);
3008 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3011 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3012 gtk_widget_show(mainwin->hbox_stat);
3013 prefs_common.show_statusbar = TRUE;
3015 gtk_widget_hide(mainwin->hbox_stat);
3016 prefs_common.show_statusbar = FALSE;
3020 static void set_layout_cb(MainWindow *mainwin, guint action,
3023 LayoutType layout_mode = action;
3025 if (mainwin->menu_lock_count) {
3028 if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3032 if (layout_mode == prefs_common.layout_mode) {
3036 if (!mainwin->messageview->visible)
3037 main_window_toggle_message_view(mainwin);
3039 main_window_separation_change(mainwin, layout_mode);
3041 mainwin_reset_paned(GTK_PANED(mainwin->vpaned));
3042 summary_relayout(mainwin->summaryview);
3045 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3048 offline_ask_sync = ask_sync;
3050 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3052 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3053 offline_ask_sync = TRUE;
3056 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3058 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3061 static gboolean any_folder_want_synchronise(void)
3063 GList *folderlist = folder_get_list();
3065 /* see if there are synchronised folders */
3066 for (; folderlist; folderlist = folderlist->next) {
3067 Folder *folder = (Folder *)folderlist->data;
3068 if (folder_want_synchronise(folder)) {
3076 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3079 if (!any_folder_want_synchronise())
3082 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3083 _("Do you want to synchronise your folders now?"),
3084 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3087 folder_synchronise(NULL);
3090 static void online_switch_clicked (GtkButton *btn, gpointer data)
3092 MainWindow *mainwin;
3093 GtkItemFactory *ifactory;
3094 GtkCheckMenuItem *menuitem;
3096 mainwin = (MainWindow *) data;
3098 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3099 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3101 g_return_if_fail(mainwin != NULL);
3102 g_return_if_fail(menuitem != NULL);
3104 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3105 gtk_widget_hide (mainwin->online_switch);
3106 gtk_widget_show (mainwin->offline_switch);
3107 menuitem->active = TRUE;
3108 inc_autocheck_timer_remove();
3111 if (prefs_common.work_offline)
3113 mainwindow_check_synchronise(mainwin, TRUE);
3114 prefs_common.work_offline = TRUE;
3115 imap_disconnect_all();
3116 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3119 if (!prefs_common.work_offline)
3121 gtk_widget_hide (mainwin->offline_switch);
3122 gtk_widget_show (mainwin->online_switch);
3123 menuitem->active = FALSE;
3124 prefs_common.work_offline = FALSE;
3125 inc_autocheck_timer_set();
3126 refresh_resolvers();
3127 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3131 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3134 addressbook_open(NULL);
3137 static void log_window_show_cb(MainWindow *mainwin, guint action,
3140 log_window_show(mainwin->logwin);
3143 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3148 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3150 summary_move_to(mainwin->summaryview);
3153 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3155 summary_copy_to(mainwin->summaryview);
3158 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3160 summary_delete(mainwin->summaryview);
3163 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3165 summary_delete_trash(mainwin->summaryview);
3168 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3170 summary_cancel(mainwin->summaryview);
3173 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3175 summary_open_msg(mainwin->summaryview);
3178 static void view_source_cb(MainWindow *mainwin, guint action,
3181 summary_view_source(mainwin->summaryview);
3184 static void show_all_header_cb(MainWindow *mainwin, guint action,
3187 if (mainwin->menu_lock_count) return;
3188 mainwin->summaryview->messageview->all_headers =
3189 GTK_CHECK_MENU_ITEM(widget)->active;
3190 summary_display_msg_selected(mainwin->summaryview,
3191 GTK_CHECK_MENU_ITEM(widget)->active);
3194 #define SET_CHECK_MENU_ACTIVE(path, active) \
3196 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3197 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3200 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3203 GtkWidget *menuitem;
3204 GtkItemFactory *ifactory = mainwin->menu_factory;
3206 if (mainwin->menu_lock_count) return;
3208 prefs_common.hide_quotes =
3209 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3211 mainwin->menu_lock_count++;
3212 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3213 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3214 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3215 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3216 mainwin->menu_lock_count--;
3218 summary_redisplay_msg(mainwin->summaryview);
3221 #undef SET_CHECK_MENU_ACTIVE
3222 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3224 summary_mark(mainwin->summaryview);
3227 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3229 summary_unmark(mainwin->summaryview);
3232 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3235 summary_mark_as_unread(mainwin->summaryview);
3238 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3241 summary_mark_as_read(mainwin->summaryview);
3244 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3247 summary_mark_all_read(mainwin->summaryview);
3250 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3253 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3256 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3259 summary_ignore_thread(mainwin->summaryview);
3262 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3265 summary_unignore_thread(mainwin->summaryview);
3268 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3271 summary_msgs_lock(mainwin->summaryview);
3274 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3277 summary_msgs_unlock(mainwin->summaryview);
3281 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3283 summary_reedit(mainwin->summaryview);
3286 static void add_address_cb(MainWindow *mainwin, guint action,
3289 summary_add_address(mainwin->summaryview);
3292 static void set_charset_cb(MainWindow *mainwin, guint action,
3297 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3298 str = conv_get_charset_str((CharSet)action);
3300 g_free(mainwin->messageview->forced_charset);
3301 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3302 procmime_force_charset(str);
3304 summary_redisplay_msg(mainwin->summaryview);
3306 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3310 static void set_decode_cb(MainWindow *mainwin, guint action,
3313 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3314 mainwin->messageview->forced_encoding = (EncodingType)action;
3316 summary_redisplay_msg(mainwin->summaryview);
3318 debug_print("forced encoding: %d\n", action);
3322 static void hide_read_messages (MainWindow *mainwin, guint action,
3325 if (!mainwin->summaryview->folder_item
3326 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3328 summary_toggle_show_read_messages(mainwin->summaryview);
3331 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3333 gboolean threaded = FALSE;
3334 if (mainwin->menu_lock_count) return;
3335 if (!mainwin->summaryview->folder_item) return;
3337 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3339 mainwin->summaryview->folder_item->threaded = threaded;
3341 mainwin->summaryview->threaded = threaded;
3343 summary_show(mainwin->summaryview,
3344 mainwin->summaryview->folder_item);
3347 static void expand_threads_cb(MainWindow *mainwin, guint action,
3350 summary_expand_threads(mainwin->summaryview);
3353 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3356 summary_collapse_threads(mainwin->summaryview);
3359 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3362 prefs_summary_column_open();
3365 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3368 prefs_folder_column_open();
3371 static void sort_summary_cb(MainWindow *mainwin, guint action,
3374 FolderItem *item = mainwin->summaryview->folder_item;
3375 GtkWidget *menuitem;
3377 if (mainwin->menu_lock_count) return;
3379 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3380 menuitem = gtk_item_factory_get_item
3381 (mainwin->menu_factory, "/View/Sort/Ascending");
3382 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3383 GTK_CHECK_MENU_ITEM(menuitem)->active
3384 ? SORT_ASCENDING : SORT_DESCENDING);
3385 item->sort_key = action;
3389 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3392 FolderItem *item = mainwin->summaryview->folder_item;
3394 if (mainwin->menu_lock_count) return;
3396 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3397 summary_sort(mainwin->summaryview,
3398 item->sort_key, (FolderSortType)action);
3401 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3404 summary_attract_by_subject(mainwin->summaryview);
3407 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3412 item = folderview_get_selected_item(mainwin->folderview);
3414 main_window_cursor_wait(mainwin);
3415 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3417 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3418 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3420 STATUSBAR_POP(mainwin);
3421 main_window_cursor_normal(mainwin);
3431 static void deldup_all(FolderItem *item, gpointer _data)
3433 struct DelDupsData *data = _data;
3436 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3438 data->dups += result;
3443 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3446 struct DelDupsData data = {0, 0};
3448 main_window_cursor_wait(mainwin);
3449 folder_func_to_all_folders(deldup_all, &data);
3450 main_window_cursor_normal(mainwin);
3452 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3453 "Deleted %d duplicate messages in %d folders.\n",
3455 data.dups, data.folders);
3458 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3460 summary_filter(mainwin->summaryview, (gboolean)action);
3463 static void execute_summary_cb(MainWindow *mainwin, guint action,
3466 summary_execute(mainwin->summaryview);
3469 static void update_summary_cb(MainWindow *mainwin, guint action,
3473 FolderView *folderview = mainwin->folderview;
3475 if (!mainwin->summaryview->folder_item) return;
3476 if (!folderview->opened) return;
3478 folder_update_op_count();
3480 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3481 folderview->opened);
3484 folder_item_scan(fitem);
3485 summary_show(mainwin->summaryview, fitem);
3488 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3490 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3493 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3495 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3498 static void prev_unread_cb(MainWindow *mainwin, guint action,
3501 summary_select_prev_unread(mainwin->summaryview);
3504 static void next_unread_cb(MainWindow *mainwin, guint action,
3507 summary_select_next_unread(mainwin->summaryview);
3510 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3512 summary_select_prev_new(mainwin->summaryview);
3515 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3517 summary_select_next_new(mainwin->summaryview);
3520 static void prev_marked_cb(MainWindow *mainwin, guint action,
3523 summary_select_prev_marked(mainwin->summaryview);
3526 static void next_marked_cb(MainWindow *mainwin, guint action,
3529 summary_select_next_marked(mainwin->summaryview);
3532 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3535 summary_select_prev_labeled(mainwin->summaryview);
3538 static void next_labeled_cb(MainWindow *mainwin, guint action,
3541 summary_select_next_labeled(mainwin->summaryview);
3544 static void last_read_cb(MainWindow *mainwin, guint action,
3547 summary_select_last_read(mainwin->summaryview);
3550 static void parent_cb(MainWindow *mainwin, guint action,
3553 summary_select_parent(mainwin->summaryview);
3556 static void goto_folder_cb(MainWindow *mainwin, guint action,
3559 FolderItem *to_folder;
3561 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3564 folderview_select(mainwin->folderview, to_folder);
3567 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3570 folderview_select_next_unread(mainwin->folderview, FALSE);
3573 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3575 messageview_copy_clipboard(mainwin->messageview);
3578 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3580 MessageView *msgview = mainwin->messageview;
3582 if (messageview_is_visible(msgview) &&
3583 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3584 messageview_select_all(mainwin->messageview);
3586 summary_select_all(mainwin->summaryview);
3589 static void select_thread_cb(MainWindow *mainwin, guint action,
3592 summary_select_thread(mainwin->summaryview, FALSE);
3595 static void delete_thread_cb(MainWindow *mainwin, guint action,
3598 summary_select_thread(mainwin->summaryview, TRUE);
3601 static void create_filter_cb(MainWindow *mainwin, guint action,
3604 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3607 static void create_processing_cb(MainWindow *mainwin, guint action,
3610 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3613 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3616 prefs_filtering_open(&pre_global_processing,
3617 _("Processing rules to apply before folder rules"),
3618 MANUAL_ANCHOR_PROCESSING,
3622 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3625 prefs_filtering_open(&post_global_processing,
3626 _("Processing rules to apply after folder rules"),
3627 MANUAL_ANCHOR_PROCESSING,
3631 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3634 prefs_filtering_open(&filtering_rules,
3635 _("Filtering configuration"),
3636 MANUAL_ANCHOR_FILTERING,
3640 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3643 prefs_template_open();
3646 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3649 prefs_actions_open(mainwin);
3652 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3655 ssl_manager_open(mainwin);
3658 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3662 new_account_cb(mainwin, 0, widget);
3664 account_open(cur_account);
3668 static void new_account_cb(MainWindow *mainwin, guint action,
3671 account_edit_open();
3672 if (!compose_get_compose_list()) account_add();
3675 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3677 FolderItem *item = NULL;
3678 cur_account = (PrefsAccount *)data;
3680 if (!mainwindow_get_mainwindow())
3682 main_window_show_cur_account(mainwindow_get_mainwindow());
3683 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3684 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3685 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3686 item = folderview_get_selected_item(
3687 mainwindow_get_mainwindow()->folderview);
3689 toolbar_set_compose_button
3690 (mainwindow_get_mainwindow()->toolbar,
3691 FOLDER_TYPE(item->folder) == F_NEWS ?
3692 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3696 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3698 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3699 PrefsAccount *account = (PrefsAccount *)data;
3701 inc_account_mail(mainwin, account);
3704 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3706 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3707 PrefsAccount *account = (PrefsAccount *)data;
3708 FolderItem *item = mainwin->summaryview->folder_item;
3710 compose_new_with_folderitem(account, item, NULL);
3713 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3718 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3720 pluginwindow_create();
3723 static void manual_open_cb(MainWindow *mainwin, guint action,
3726 manual_open((ManualType)action, NULL);
3729 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3734 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3736 MainWindow *mainwin = (MainWindow *)data;
3740 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3741 LOCAL_FOLDER(folder)->rootpath,
3745 str = g_strdup_printf(_("Scanning folder %s ..."),
3746 LOCAL_FOLDER(folder)->rootpath);
3748 STATUSBAR_PUSH(mainwin, str);
3749 STATUSBAR_POP(mainwin);
3753 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3756 SummaryView *summary;
3758 g_return_val_if_fail(data, FALSE);
3759 if (!g_list_find(mainwin_list, data))
3761 summary = ((MainWindow *)data)->summaryview;
3762 g_return_val_if_fail(summary, FALSE);
3764 if (GTK_CLIST(summary->ctree)->selection &&
3765 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3771 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
3774 is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
3778 gboolean mainwindow_is_obscured(void)
3783 #define BREAK_ON_MODIFIER_KEY() \
3784 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3786 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3789 MainWindow *mainwin = (MainWindow*) data;
3791 if (!mainwin || !event)
3794 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3796 lastkey = event->keyval;
3800 switch (event->keyval) {
3801 case GDK_Q: /* Quit */
3802 BREAK_ON_MODIFIER_KEY();
3804 app_exit_cb(mainwin, 0, NULL);
3807 if (mainwin->folderview && mainwin->summaryview
3808 && ((!mainwin->summaryview->displayed
3809 && !mainwin->summaryview->selected)
3810 || (mainwin->summaryview->folder_item
3811 && mainwin->summaryview->folder_item->total_msgs == 0))) {
3812 g_signal_stop_emission_by_name(G_OBJECT(widget),
3814 folderview_select_next_unread(mainwin->folderview, TRUE);
3823 #undef BREAK_ON_MODIFIER_KEY
3826 * Harvest addresses for selected folder.
3828 static void addr_harvest_cb( MainWindow *mainwin,
3832 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3836 * Harvest addresses for selected messages in summary view.
3838 static void addr_harvest_msg_cb( MainWindow *mainwin,
3842 summary_harvest_address( mainwin->summaryview );
3846 *\brief get a MainWindow
3848 *\return MainWindow * The first mainwindow in the mainwin_list
3850 MainWindow *mainwindow_get_mainwindow(void)
3852 if (mainwin_list && mainwin_list->data)
3853 return (MainWindow *)(mainwin_list->data);
3858 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3860 ProgressData *data = (ProgressData *) source;
3861 MainWindow *mainwin = (MainWindow *) userdata;
3863 switch (data->cmd) {
3864 case PROGRESS_COMMAND_START:
3865 case PROGRESS_COMMAND_STOP:
3866 gtk_progress_bar_set_fraction
3867 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
3869 case PROGRESS_COMMAND_SET_PERCENTAGE:
3870 gtk_progress_bar_set_fraction
3871 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
3874 while (gtk_events_pending()) gtk_main_iteration ();
3879 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3881 mainwindow_check_synchronise(mainwin, FALSE);
3884 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
3886 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
3889 void mainwindow_jump_to(const gchar *target)
3893 FolderItem *item = NULL;
3895 MainWindow *mainwin = mainwindow_get_mainwindow();
3901 printf("not initialized\n");
3905 tmp = g_strdup(target);
3907 if ((p = strstr(tmp, "\r")) != NULL)
3909 if ((p = strstr(tmp, "\n")) != NULL)
3912 if ((item = folder_find_item_from_identifier(tmp))) {
3913 printf("selecting folder '%s'\n", tmp);
3914 folderview_select(mainwin->folderview, item);
3915 main_window_popup(mainwin);
3920 msg = strrchr(tmp, G_DIR_SEPARATOR);
3923 if ((item = folder_find_item_from_identifier(tmp))) {
3924 printf("selecting folder '%s'\n", tmp);
3925 folderview_select(mainwin->folderview, item);
3927 printf("'%s' not found\n", tmp);
3929 if (item && msg && atoi(msg)) {
3930 printf("selecting message %d\n", atoi(msg));
3931 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
3932 summary_display_msg_selected(mainwin->summaryview, FALSE);
3933 main_window_popup(mainwin);
3936 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
3937 MsgInfo *msginfo = NULL;
3939 msg[strlen(msg)-1] = '\0';
3940 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
3942 printf("selecting message %s\n", msg);
3943 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
3944 summary_display_msg_selected(mainwin->summaryview, FALSE);
3945 main_window_popup(mainwin);
3947 procmsg_msginfo_free(msginfo);
3950 printf("'%s' not found\n", msg);
3953 printf("'%s' not found\n", msg);
3956 printf("'%s' not found\n", tmp);