2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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"
63 #include "prefs_common.h"
64 #include "prefs_actions.h"
65 #include "prefs_filtering.h"
66 #include "prefs_account.h"
67 #include "prefs_summary_column.h"
68 #include "prefs_folder_column.h"
69 #include "prefs_template.h"
72 #include "addressbook.h"
73 #include "logwindow.h"
74 #include "manage_window.h"
75 #include "alertpanel.h"
76 #include "statusbar.h"
77 #include "inputdialog.h"
84 #include "ssl_manager.h"
85 #include "sslcertwindow.h"
86 #include "prefs_gtk.h"
87 #include "pluginwindow.h"
89 #include "progressindicator.h"
90 #include "localfolder.h"
91 #include "filtering.h"
92 #include "folderutils.h"
93 #include "foldersort.h"
94 #include "icon_legend.h"
95 #include "colorlabel.h"
100 #define AC_LABEL_WIDTH 240
102 /* list of all instantiated MainWindow */
103 static GList *mainwin_list = NULL;
105 static GdkCursor *watch_cursor = NULL;
107 static void main_window_menu_callback_block (MainWindow *mainwin);
108 static void main_window_menu_callback_unblock (MainWindow *mainwin);
110 static void main_window_show_cur_account (MainWindow *mainwin);
112 static void main_window_set_widgets (MainWindow *mainwin,
115 static void toolbar_child_attached (GtkWidget *widget,
118 static void toolbar_child_detached (GtkWidget *widget,
122 static gboolean ac_label_button_pressed (GtkWidget *widget,
123 GdkEventButton *event,
126 static gint main_window_close_cb (GtkWidget *widget,
129 static gint folder_window_close_cb (GtkWidget *widget,
132 static gint message_window_close_cb (GtkWidget *widget,
136 static void main_window_size_allocate_cb (GtkWidget *widget,
137 GtkAllocation *allocation,
139 static void folder_window_size_allocate_cb (GtkWidget *widget,
140 GtkAllocation *allocation,
142 static void message_window_size_allocate_cb (GtkWidget *widget,
143 GtkAllocation *allocation,
146 static void update_folderview_cb (MainWindow *mainwin,
149 static void add_mailbox_cb (MainWindow *mainwin,
152 static void foldersort_cb (MainWindow *mainwin,
155 static void import_mbox_cb (MainWindow *mainwin,
158 static void export_mbox_cb (MainWindow *mainwin,
161 static void export_list_mbox_cb (MainWindow *mainwin,
164 static void empty_trash_cb (MainWindow *mainwin,
168 static void save_as_cb (MainWindow *mainwin,
171 static void print_cb (MainWindow *mainwin,
174 static void app_exit_cb (MainWindow *mainwin,
178 static void search_cb (MainWindow *mainwin,
182 static void toggle_folder_cb (MainWindow *mainwin,
185 static void toggle_message_cb (MainWindow *mainwin,
188 static void toggle_toolbar_cb (MainWindow *mainwin,
191 static void toggle_statusbar_cb (MainWindow *mainwin,
194 static void separate_widget_cb (MainWindow *mainwin,
198 static void addressbook_open_cb (MainWindow *mainwin,
201 static void log_window_show_cb (MainWindow *mainwin,
205 static void inc_cancel_cb (MainWindow *mainwin,
209 static void open_msg_cb (MainWindow *mainwin,
213 static void view_source_cb (MainWindow *mainwin,
217 static void show_all_header_cb (MainWindow *mainwin,
221 static void hide_quotes_cb(MainWindow *mainwin,
225 static void move_to_cb (MainWindow *mainwin,
228 static void copy_to_cb (MainWindow *mainwin,
231 static void delete_cb (MainWindow *mainwin,
234 static void delete_trash_cb (MainWindow *mainwin,
238 static void cancel_cb (MainWindow *mainwin,
242 static void mark_cb (MainWindow *mainwin,
245 static void unmark_cb (MainWindow *mainwin,
249 static void mark_as_unread_cb (MainWindow *mainwin,
252 static void mark_as_read_cb (MainWindow *mainwin,
255 static void mark_all_read_cb (MainWindow *mainwin,
258 static void mark_as_spam_cb (MainWindow *mainwin,
262 static void reedit_cb (MainWindow *mainwin,
266 static void add_address_cb (MainWindow *mainwin,
270 static void set_charset_cb (MainWindow *mainwin,
274 static void set_decode_cb (MainWindow *mainwin,
278 static void hide_read_messages (MainWindow *mainwin,
282 static void thread_cb (MainWindow *mainwin,
285 static void expand_threads_cb (MainWindow *mainwin,
288 static void collapse_threads_cb (MainWindow *mainwin,
292 static void set_summary_display_item_cb (MainWindow *mainwin,
295 static void set_folder_display_item_cb (MainWindow *mainwin,
298 static void sort_summary_cb (MainWindow *mainwin,
301 static void sort_summary_type_cb (MainWindow *mainwin,
304 static void attract_by_subject_cb(MainWindow *mainwin,
308 static void delete_duplicated_cb (MainWindow *mainwin,
311 static void delete_duplicated_all_cb (MainWindow *mainwin,
314 static void filter_cb (MainWindow *mainwin,
317 static void execute_summary_cb (MainWindow *mainwin,
320 static void update_summary_cb (MainWindow *mainwin,
324 static void prev_cb (MainWindow *mainwin,
327 static void next_cb (MainWindow *mainwin,
330 static void next_unread_cb (MainWindow *mainwin,
333 static void prev_unread_cb (MainWindow *mainwin,
337 static void prev_new_cb (MainWindow *mainwin,
340 static void next_new_cb (MainWindow *mainwin,
343 static void prev_marked_cb (MainWindow *mainwin,
346 static void next_marked_cb (MainWindow *mainwin,
349 static void prev_labeled_cb (MainWindow *mainwin,
352 static void next_labeled_cb (MainWindow *mainwin,
355 static void last_read_cb (MainWindow *mainwin,
358 static void parent_cb (MainWindow *mainwin,
362 static void goto_folder_cb (MainWindow *mainwin,
365 static void goto_unread_folder_cb(MainWindow *mainwin,
369 static void copy_cb (MainWindow *mainwin,
372 static void allsel_cb (MainWindow *mainwin,
375 static void select_thread_cb (MainWindow *mainwin,
379 static void create_filter_cb (MainWindow *mainwin,
382 static void create_processing_cb (MainWindow *mainwin,
386 static void prefs_template_open_cb (MainWindow *mainwin,
389 static void prefs_actions_open_cb (MainWindow *mainwin,
392 static void prefs_account_open_cb (MainWindow *mainwin,
396 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
400 static void prefs_post_processing_open_cb (MainWindow *mainwin,
404 static void prefs_filtering_open_cb (MainWindow *mainwin,
408 static void ssl_manager_open_cb (MainWindow *mainwin,
412 static void new_account_cb (MainWindow *mainwin,
416 static void account_selector_menu_cb (GtkMenuItem *menuitem,
418 static void account_receive_menu_cb (GtkMenuItem *menuitem,
420 static void account_compose_menu_cb (GtkMenuItem *menuitem,
423 static void prefs_open_cb (GtkMenuItem *menuitem,
425 static void plugins_open_cb (GtkMenuItem *menuitem,
428 static void online_switch_clicked(GtkButton *btn,
431 static void manual_open_cb (MainWindow *mainwin,
435 static void legend_open_cb (GtkMenuItem *menuitem,
438 static void scan_tree_func (Folder *folder,
442 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
444 static void addr_harvest_cb ( MainWindow *mainwin,
448 static void addr_harvest_msg_cb ( MainWindow *mainwin,
451 static void sync_cb ( MainWindow *mainwin,
455 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
456 GdkEventFocus *focus,
458 void main_window_reply_cb (MainWindow *mainwin,
461 gboolean mainwindow_progressindicator_hook (gpointer source,
464 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
467 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
469 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
471 static void mailing_list_compose(GtkWidget *w, gpointer *data);
473 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
474 #define SEPARATE_ACTION 500
475 static void mainwindow_quicksearch (MainWindow *mainwin,
479 static GtkItemFactoryEntry mainwin_entries[] =
481 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
482 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
483 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
484 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
485 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
486 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
487 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
488 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
489 {N_("/_File/Exp_ort selected to mbox file..."),
490 NULL, export_list_mbox_cb, 0, NULL},
491 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
492 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
493 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
494 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
495 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
496 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
497 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
498 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
499 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
500 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
501 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
503 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
504 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
505 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
506 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
507 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_Edit/_Find in current message..."),
509 "<control>F", search_cb, 0, NULL},
510 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
511 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
512 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
513 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
514 {N_("/_View/Show or hi_de/_Folder tree"),
515 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
516 {N_("/_View/Show or hi_de/_Message view"),
517 "V", toggle_message_cb, 0, "<ToggleItem>"},
518 {N_("/_View/Show or hi_de/_Toolbar"),
519 NULL, NULL, 0, "<Branch>"},
520 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
521 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
522 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
523 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
524 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
525 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
526 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
527 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
528 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
529 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
530 {N_("/_View/Show or hi_de/Status _bar"),
531 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
532 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
533 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
534 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
536 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
537 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
538 {N_("/_View/Separate _message view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
539 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
540 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
542 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
543 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
544 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
545 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
546 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
547 {N_("/_View/_Sort/by _color label"),
548 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
549 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
550 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
551 {N_("/_View/_Sort/by a_ttachment"),
552 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
553 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
554 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
555 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
556 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
557 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
558 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
559 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
560 {N_("/_View/_Sort/_Attract by subject"),
561 NULL, attract_by_subject_cb, 0, NULL},
562 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
563 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
564 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
565 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
567 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
568 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
569 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
570 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
571 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
572 {N_("/_View/_Go to/P_revious unread message"),
573 "<shift>P", prev_unread_cb, 0, NULL},
574 {N_("/_View/_Go to/N_ext unread message"),
575 "<shift>N", next_unread_cb, 0, NULL},
576 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
577 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
578 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
579 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
580 {N_("/_View/_Go to/Previous _marked message"),
581 NULL, prev_marked_cb, 0, NULL},
582 {N_("/_View/_Go to/Next m_arked message"),
583 NULL, next_marked_cb, 0, NULL},
584 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
585 {N_("/_View/_Go to/Previous _labeled message"),
586 NULL, prev_labeled_cb, 0, NULL},
587 {N_("/_View/_Go to/Next la_beled message"),
588 NULL, next_labeled_cb, 0, NULL},
589 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
590 {N_("/_View/_Go to/Last read message"),
591 NULL, last_read_cb, 0, NULL},
592 {N_("/_View/_Go to/Parent message"),
593 "<control>Up", parent_cb, 0, NULL},
594 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
595 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
596 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
597 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
599 #define ENC_SEPARATOR \
600 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
601 #define ENC_ACTION(action) \
602 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
604 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
605 {N_("/_View/Character _encoding/_Auto detect"),
606 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
607 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
608 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
609 ENC_ACTION(C_US_ASCII)},
610 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
611 ENC_ACTION(C_UTF_8)},
614 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
615 ENC_ACTION(C_ISO_8859_1)},
616 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
617 ENC_ACTION(C_ISO_8859_15)},
618 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
619 ENC_ACTION(C_WINDOWS_1252)},
622 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
623 ENC_ACTION(C_ISO_8859_2)},
626 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
627 ENC_ACTION(C_ISO_8859_13)},
628 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
629 ENC_ACTION(C_ISO_8859_4)},
632 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
633 ENC_ACTION(C_ISO_8859_7)},
636 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
637 ENC_ACTION(C_ISO_8859_8)},
638 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
639 ENC_ACTION(C_CP1255)},
642 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
643 ENC_ACTION(C_ISO_8859_6)},
644 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
645 ENC_ACTION(C_CP1256)},
648 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
649 ENC_ACTION(C_ISO_8859_9)},
652 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
653 ENC_ACTION(C_ISO_8859_5)},
654 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
655 ENC_ACTION(C_KOI8_R)},
656 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
657 ENC_ACTION(C_KOI8_U)},
658 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
659 ENC_ACTION(C_CP1251)},
662 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
663 ENC_ACTION(C_ISO_2022_JP)},
664 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
665 ENC_ACTION(C_ISO_2022_JP_2)},
666 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
667 ENC_ACTION(C_EUC_JP)},
668 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
669 ENC_ACTION(C_SHIFT_JIS)},
672 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
673 ENC_ACTION(C_GB2312)},
674 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
676 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
678 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
679 ENC_ACTION(C_EUC_TW)},
680 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
681 ENC_ACTION(C_ISO_2022_CN)},
684 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
685 ENC_ACTION(C_EUC_KR)},
686 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
687 ENC_ACTION(C_ISO_2022_KR)},
690 {N_("/_View/Character _encoding/Thai (TIS-620)"),
691 ENC_ACTION(C_TIS_620)},
692 {N_("/_View/Character _encoding/Thai (Windows-874)"),
693 ENC_ACTION(C_WINDOWS_874)},
698 #define DEC_SEPARATOR \
699 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
700 #define DEC_ACTION(action) \
701 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
702 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
703 {N_("/_View/Decode/_Auto detect"),
704 NULL, set_decode_cb, 0, "<RadioItem>"},
705 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
706 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
707 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
708 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
709 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
714 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
715 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
716 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
717 {N_("/_View/Show all headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
718 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
719 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
720 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
721 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
722 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
725 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
726 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
727 {N_("/_Message/Recei_ve/Get from _current account"),
728 "<control>I", inc_mail_cb, 0, NULL},
729 {N_("/_Message/Recei_ve/Get from _all accounts"),
730 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
731 {N_("/_Message/Recei_ve/Cancel receivin_g"),
732 NULL, inc_cancel_cb, 0, NULL},
733 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
735 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
736 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
737 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
738 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
739 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
741 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
742 {N_("/_Message/Repl_y to/mailing _list"),
743 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
744 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
745 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
746 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
747 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
748 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
750 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
751 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
752 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
753 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
754 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
755 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
756 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
759 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
760 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
761 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
762 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
763 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
764 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
765 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
766 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
767 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
768 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
769 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
770 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
771 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
772 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
773 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
774 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
775 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
776 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
777 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
779 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
780 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
781 {N_("/_Tools/Add sender to address boo_k"),
782 NULL, add_address_cb, 0, NULL},
783 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
784 {N_("/_Tools/_Harvest addresses/from _Folder..."),
785 NULL, addr_harvest_cb, 0, NULL},
786 {N_("/_Tools/_Harvest addresses/from _Messages..."),
787 NULL, addr_harvest_msg_cb, 0, NULL},
788 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
789 {N_("/_Tools/_Filter all messages in folder"),
790 NULL, filter_cb, 0, NULL},
791 {N_("/_Tools/Filter _selected messages"),
792 NULL, filter_cb, 1, NULL},
793 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
794 {N_("/_Tools/_Create filter rule/_Automatically"),
795 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
796 {N_("/_Tools/_Create filter rule/by _From"),
797 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
798 {N_("/_Tools/_Create filter rule/by _To"),
799 NULL, create_filter_cb, FILTER_BY_TO, NULL},
800 {N_("/_Tools/_Create filter rule/by _Subject"),
801 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
802 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
803 {N_("/_Tools/C_reate processing rule/_Automatically"),
804 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
805 {N_("/_Tools/C_reate processing rule/by _From"),
806 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
807 {N_("/_Tools/C_reate processing rule/by _To"),
808 NULL, create_processing_cb, FILTER_BY_TO, NULL},
809 {N_("/_Tools/C_reate processing rule/by _Subject"),
810 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
811 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
812 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
813 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
814 {N_("/_Tools/Ch_eck for new messages in all folders"),
815 NULL, update_folderview_cb, 0, NULL},
816 {N_("/_Tools/Delete du_plicated messages"),
817 NULL, NULL, 0, "<Branch>"},
818 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
819 NULL, delete_duplicated_cb, 0, NULL},
820 {N_("/_Tools/Delete du_plicated messages/In all folders"),
821 NULL, delete_duplicated_all_cb, 0, NULL},
822 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
823 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
825 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
826 {N_("/_Tools/SSL cer_tificates..."),
827 NULL, ssl_manager_open_cb, 0, NULL},
829 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
830 {N_("/_Tools/_Log window"), "<shift><control>L", log_window_show_cb, 0, NULL},
832 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
833 {N_("/_Configuration/C_hange current account"),
834 NULL, NULL, 0, "<Branch>"},
835 {N_("/_Configuration/_Preferences for current account..."),
836 NULL, prefs_account_open_cb, 0, NULL},
837 {N_("/_Configuration/Create _new account..."),
838 NULL, new_account_cb, 0, NULL},
839 {N_("/_Configuration/_Edit accounts..."),
840 NULL, account_edit_open, 0, NULL},
841 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
842 {N_("/_Configuration/P_references..."),
843 NULL, prefs_open_cb, 0, NULL},
844 {N_("/_Configuration/Pre-pr_ocessing..."),
845 NULL, prefs_pre_processing_open_cb, 0, NULL},
846 {N_("/_Configuration/Post-pro_cessing..."),
847 NULL, prefs_post_processing_open_cb, 0, NULL},
848 {N_("/_Configuration/_Filtering..."),
849 NULL, prefs_filtering_open_cb, 0, NULL},
850 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
851 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
852 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
854 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
855 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
856 {N_("/_Help/_Online User-contributed FAQ"),
857 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
858 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
859 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
860 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
863 static gboolean offline_ask_sync = TRUE;
864 static guint lastkey;
866 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
872 MainWindow *mainwin = (MainWindow *)user_data;
874 if (mainwin->summaryview &&
875 mainwin->summaryview->quicksearch &&
876 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
877 (mod == 0 || mod == GDK_SHIFT_MASK)) {
878 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
884 #define N_COLOR_LABELS colorlabel_get_color_count()
886 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
891 GtkCheckMenuItem **items;
895 mainwin = (MainWindow *)data;
896 g_return_if_fail(mainwin != NULL);
898 sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
901 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
902 g_return_if_fail(menu != NULL);
904 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
906 /* NOTE: don't return prematurely because we set the "dont_toggle"
907 * state for check menu items */
908 g_object_set_data(G_OBJECT(menu), "dont_toggle",
911 /* clear items. get item pointers. */
912 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
913 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
914 gtk_check_menu_item_set_active
915 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
916 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
921 if (n == (N_COLOR_LABELS + 1)) {
922 /* iterate all messages and set the state of the appropriate
924 for (; sel != NULL; sel = sel->next) {
928 msginfo = gtk_ctree_node_get_row_data
929 (GTK_CTREE(mainwin->summaryview->ctree),
930 GTK_CTREE_NODE(sel->data));
932 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
933 if (!items[clabel]->active)
934 gtk_check_menu_item_set_active
935 (items[clabel], TRUE);
939 g_warning("invalid number of color elements (%d)\n", n);
941 /* reset "dont_toggle" state */
942 g_object_set_data(G_OBJECT(menu), "dont_toggle",
946 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
949 guint color = GPOINTER_TO_UINT(data);
952 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
953 g_return_if_fail(mainwin != NULL);
955 /* "dont_toggle" state set? */
956 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
960 summary_set_colorlabel(mainwin->summaryview, color, NULL);
963 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
965 GtkWidget *label_menuitem;
970 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
971 "/Message/Color label");
972 g_signal_connect(G_OBJECT(label_menuitem), "activate",
973 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
975 gtk_widget_show(label_menuitem);
977 menu = gtk_menu_new();
979 /* create sub items. for the menu item activation callback we pass the
980 * index of label_colors[] as data parameter. for the None color we
981 * pass an invalid (high) value. also we attach a data pointer so we
982 * can always get back the Mainwindow pointer. */
984 item = gtk_check_menu_item_new_with_label(_("None"));
985 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
986 g_signal_connect(G_OBJECT(item), "activate",
987 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
988 GUINT_TO_POINTER(0));
989 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
990 gtk_widget_show(item);
992 gtk_widget_add_accelerator(item, "activate",
993 mainwin->menu_factory->accel_group,
994 GDK_0, GDK_CONTROL_MASK,
995 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
997 item = gtk_menu_item_new();
998 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
999 gtk_widget_show(item);
1001 /* create pixmap/label menu items */
1002 for (i = 0; i < N_COLOR_LABELS; i++) {
1003 item = colorlabel_create_check_color_menu_item(
1004 i, refresh, MAINWIN_COLORMENU);
1005 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1006 g_signal_connect(G_OBJECT(item), "activate",
1007 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1008 GUINT_TO_POINTER(i + 1));
1009 g_object_set_data(G_OBJECT(item), "mainwin",
1011 gtk_widget_show(item);
1012 gtk_widget_add_accelerator(item, "activate",
1013 mainwin->menu_factory->accel_group,
1014 GDK_1+i, GDK_CONTROL_MASK,
1015 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1018 gtk_widget_show(menu);
1019 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1020 mainwin->colorlabel_menu = menu;
1024 MainWindow *main_window_create(SeparateType type)
1026 MainWindow *mainwin;
1030 GtkWidget *handlebox;
1031 GtkWidget *vbox_body;
1032 GtkWidget *hbox_stat;
1033 GtkWidget *statusbar;
1034 GtkWidget *progressbar;
1035 GtkWidget *statuslabel;
1036 GtkWidget *ac_button;
1037 GtkWidget *ac_label;
1038 GtkWidget *online_pixmap;
1039 GtkWidget *offline_pixmap;
1040 GtkWidget *online_switch;
1041 GtkWidget *offline_switch;
1042 GtkTooltips *offline_tip;
1043 GtkTooltips *online_tip;
1044 GtkTooltips *sel_ac_tip;
1046 FolderView *folderview;
1047 SummaryView *summaryview;
1048 MessageView *messageview;
1049 GdkColormap *colormap;
1051 gboolean success[4];
1052 GtkItemFactory *ifactory;
1054 GtkWidget *menuitem;
1056 guint n_menu_entries;
1058 static GdkGeometry geometry;
1060 debug_print("Creating main window...\n");
1061 mainwin = g_new0(MainWindow, 1);
1064 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1065 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1066 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1068 if (!geometry.min_height) {
1069 geometry.min_width = 320;
1070 geometry.min_height = 200;
1072 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1075 g_signal_connect(G_OBJECT(window), "delete_event",
1076 G_CALLBACK(main_window_close_cb), mainwin);
1077 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1078 g_signal_connect(G_OBJECT(window), "focus_in_event",
1079 G_CALLBACK(mainwindow_focus_in_event),
1081 g_signal_connect(G_OBJECT(window), "key_press_event",
1082 G_CALLBACK(mainwindow_key_pressed), mainwin);
1084 gtk_widget_realize(window);
1085 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1088 gtkut_widget_set_app_icon(window);
1090 vbox = gtk_vbox_new(FALSE, 0);
1091 gtk_widget_show(vbox);
1092 gtk_container_add(GTK_CONTAINER(window), vbox);
1095 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1096 menubar = menubar_create(window, mainwin_entries,
1097 n_menu_entries, "<Main>", mainwin);
1098 gtk_widget_show(menubar);
1099 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1100 ifactory = gtk_item_factory_from_widget(menubar);
1102 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1103 main_create_mailing_list_menu (mainwin, NULL); */
1105 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1107 if (prefs_common.toolbar_detachable) {
1108 handlebox = gtk_handle_box_new();
1109 gtk_widget_show(handlebox);
1110 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1111 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1112 G_CALLBACK(toolbar_child_attached), mainwin);
1113 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1114 G_CALLBACK(toolbar_child_detached), mainwin);
1116 handlebox = gtk_hbox_new(FALSE, 0);
1117 gtk_widget_show(handlebox);
1118 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1120 /* link window to mainwin->window to avoid gdk warnings */
1121 mainwin->window = window;
1123 /* create toolbar */
1124 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1127 toolbar_set_learn_button
1131 /* vbox that contains body */
1132 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1133 gtk_widget_show(vbox_body);
1134 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1135 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1137 hbox_stat = gtk_hbox_new(FALSE, 2);
1138 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1140 statusbar = statusbar_create();
1141 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1143 progressbar = gtk_progress_bar_new();
1144 gtk_widget_set_size_request(progressbar, 120, 1);
1145 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1147 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1148 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1149 online_tip = gtk_tooltips_new();
1150 online_switch = gtk_button_new ();
1151 gtk_tooltips_set_tip(GTK_TOOLTIPS(online_tip),online_switch,
1152 _("You are online. Click the icon to go offline"), NULL);
1153 offline_tip = gtk_tooltips_new();
1154 offline_switch = gtk_button_new ();
1155 gtk_tooltips_set_tip(GTK_TOOLTIPS(offline_tip),offline_switch,
1156 _("You are offline. Click the icon to go online"),
1158 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1159 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1160 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1161 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1162 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1163 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1164 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1165 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1167 statuslabel = gtk_label_new("");
1168 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1170 sel_ac_tip = gtk_tooltips_new();
1171 ac_button = gtk_button_new();
1172 gtk_tooltips_set_tip(GTK_TOOLTIPS(sel_ac_tip),
1173 ac_button, _("Select account"), NULL);
1174 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1175 gtk_widget_set_size_request(ac_button, -1, 0);
1176 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1177 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1178 G_CALLBACK(ac_label_button_pressed), mainwin);
1180 ac_label = gtk_label_new("");
1181 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1183 gtk_widget_show_all(hbox_stat);
1185 gtk_widget_hide(offline_switch);
1187 mainwin->folderview = folderview = folderview_create();
1188 mainwin->summaryview = summaryview = summary_create();
1189 mainwin->messageview = messageview = messageview_create(mainwin);
1190 mainwin->logwin = log_window_create();
1192 folderview->mainwin = mainwin;
1193 folderview->summaryview = summaryview;
1195 summaryview->mainwin = mainwin;
1196 summaryview->folderview = folderview;
1197 summaryview->messageview = messageview;
1198 summaryview->window = window;
1200 messageview->statusbar = statusbar;
1201 mainwin->vbox = vbox;
1202 mainwin->menubar = menubar;
1203 mainwin->menu_factory = ifactory;
1204 mainwin->handlebox = handlebox;
1205 mainwin->vbox_body = vbox_body;
1206 mainwin->hbox_stat = hbox_stat;
1207 mainwin->statusbar = statusbar;
1208 mainwin->progressbar = progressbar;
1209 mainwin->statuslabel = statuslabel;
1210 mainwin->online_switch = online_switch;
1211 mainwin->online_pixmap = online_pixmap;
1212 mainwin->offline_pixmap = offline_pixmap;
1213 mainwin->ac_button = ac_button;
1214 mainwin->ac_label = ac_label;
1215 mainwin->offline_switch = offline_switch;
1217 /* set context IDs for status bar */
1218 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1219 (GTK_STATUSBAR(statusbar), "Main Window");
1220 mainwin->folderview_cid = gtk_statusbar_get_context_id
1221 (GTK_STATUSBAR(statusbar), "Folder View");
1222 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1223 (GTK_STATUSBAR(statusbar), "Summary View");
1224 mainwin->messageview_cid = gtk_statusbar_get_context_id
1225 (GTK_STATUSBAR(statusbar), "Message View");
1227 messageview->statusbar_cid = mainwin->messageview_cid;
1229 /* allocate colors for summary view and folder view */
1230 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1231 summaryview->color_marked.blue = (guint16)65535;
1233 summaryview->color_dim.red = summaryview->color_dim.green =
1234 summaryview->color_dim.blue = COLOR_DIM;
1236 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1237 &folderview->color_new);
1239 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1240 &folderview->color_op);
1242 summaryview->color_important.red = 0;
1243 summaryview->color_important.green = 0;
1244 summaryview->color_important.blue = (guint16)65535;
1246 color[0] = summaryview->color_marked;
1247 color[1] = summaryview->color_dim;
1248 color[2] = folderview->color_new;
1249 color[3] = folderview->color_op;
1251 colormap = gdk_drawable_get_colormap(window->window);
1252 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1253 for (i = 0; i < 4; i++) {
1254 if (success[i] == FALSE)
1255 g_warning("MainWindow: color allocation %d failed\n", i);
1258 debug_print("done.\n");
1260 messageview->visible = prefs_common.msgview_visible;
1262 main_window_set_widgets(mainwin, type);
1264 g_signal_connect(G_OBJECT(window), "size_allocate",
1265 G_CALLBACK(main_window_size_allocate_cb),
1268 /* set menu items */
1269 menuitem = gtk_item_factory_get_item
1270 (ifactory, "/View/Character encoding/Auto detect");
1271 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1273 switch (prefs_common.toolbar_style) {
1275 menuitem = gtk_item_factory_get_item
1276 (ifactory, "/View/Show or hide/Toolbar/Hide");
1279 menuitem = gtk_item_factory_get_item
1280 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1283 menuitem = gtk_item_factory_get_item
1284 (ifactory, "/View/Show or hide/Toolbar/Text only");
1287 menuitem = gtk_item_factory_get_item
1288 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1290 case TOOLBAR_BOTH_HORIZ:
1291 menuitem = gtk_item_factory_get_item
1293 "/View/Show or hide/Toolbar/Text beside icons");
1295 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1297 gtk_widget_hide(mainwin->hbox_stat);
1298 menuitem = gtk_item_factory_get_item
1299 (ifactory, "/View/Show or hide/Status bar");
1300 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1301 prefs_common.show_statusbar);
1303 /* set account selection menu */
1304 ac_menu = gtk_item_factory_get_widget
1305 (ifactory, "/Configuration/Change current account");
1306 mainwin->ac_menu = ac_menu;
1308 toolbar_main_set_sensitive(mainwin);
1310 /* create actions menu */
1311 main_window_update_actions_menu(mainwin);
1313 main_create_mailing_list_menu (mainwin, NULL);
1315 /* attach accel groups to main window */
1316 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1317 gtk_window_add_accel_group \
1319 gtk_item_factory_from_widget(menu)->accel_group); \
1320 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1322 G_CALLBACK(main_window_accel_activate), mainwin);
1325 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1327 /* connect the accelerators for equivalent
1328 menu items in different menus */
1329 menu_connect_identical_items();
1332 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1334 gtk_widget_show(mainwin->window);
1336 /* initialize views */
1337 folderview_init(folderview);
1338 summary_init(summaryview);
1339 messageview_init(messageview);
1340 log_window_init(mainwin->logwin);
1341 log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1342 prefs_common.loglength);
1344 sslcertwindow_register_hook();
1346 mainwin->lock_count = 0;
1347 mainwin->menu_lock_count = 0;
1348 mainwin->cursor_count = 0;
1350 mainwin->progressindicator_hook =
1351 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1354 watch_cursor = gdk_cursor_new(GDK_WATCH);
1356 mainwin_list = g_list_append(mainwin_list, mainwin);
1358 /* init work_offline */
1359 if (prefs_common.work_offline)
1360 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1362 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1367 void main_window_destroy(MainWindow *mainwin)
1369 /* TODO : destroy other component */
1370 messageview_destroy(mainwin->messageview);
1371 mainwin->messageview = NULL;
1374 void main_window_update_actions_menu(MainWindow *mainwin)
1376 GtkItemFactory *ifactory;
1378 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1379 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1382 void main_window_cursor_wait(MainWindow *mainwin)
1385 if (mainwin->cursor_count == 0) {
1386 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1387 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1390 mainwin->cursor_count++;
1395 void main_window_cursor_normal(MainWindow *mainwin)
1397 if (mainwin->cursor_count)
1398 mainwin->cursor_count--;
1400 if (mainwin->cursor_count == 0) {
1401 gdk_window_set_cursor(mainwin->window->window, NULL);
1402 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1407 /* lock / unlock the user-interface */
1408 void main_window_lock(MainWindow *mainwin)
1410 if (mainwin->lock_count == 0)
1411 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1413 mainwin->lock_count++;
1415 main_window_set_menu_sensitive(mainwin);
1416 toolbar_main_set_sensitive(mainwin);
1419 void main_window_unlock(MainWindow *mainwin)
1421 if (mainwin->lock_count)
1422 mainwin->lock_count--;
1424 main_window_set_menu_sensitive(mainwin);
1425 toolbar_main_set_sensitive(mainwin);
1427 if (mainwin->lock_count == 0)
1428 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1431 static void main_window_menu_callback_block(MainWindow *mainwin)
1433 mainwin->menu_lock_count++;
1436 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1438 if (mainwin->menu_lock_count)
1439 mainwin->menu_lock_count--;
1442 static guint prefs_tag = 0;
1444 void main_window_reflect_prefs_all(void)
1446 main_window_reflect_prefs_all_real(FALSE);
1449 static gboolean reflect_prefs_timeout_cb(gpointer data)
1451 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1453 MainWindow *mainwin;
1456 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1457 mainwin = (MainWindow *)cur->data;
1459 main_window_show_cur_account(mainwin);
1460 main_window_set_menu_sensitive(mainwin);
1461 toolbar_main_set_sensitive(mainwin);
1464 if (pixmap_theme_changed) {
1465 toolbar_update(TOOLBAR_MAIN, mainwin);
1466 messageview_reflect_prefs_pixmap_theme();
1467 compose_reflect_prefs_pixmap_theme();
1468 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1469 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1471 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1472 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1473 mainwin->online_pixmap);
1474 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1475 gtk_widget_show(pixmap);
1476 mainwin->online_pixmap = pixmap;
1477 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1478 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1479 mainwin->offline_pixmap);
1480 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1481 gtk_widget_show(pixmap);
1482 mainwin->offline_pixmap = pixmap;
1485 headerview_set_font(mainwin->messageview->headerview);
1486 headerview_set_visibility(mainwin->messageview->headerview,
1487 prefs_common.display_header_pane);
1488 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1489 folderview_reflect_prefs();
1490 summary_reflect_prefs();
1491 summary_redisplay_msg(mainwin->summaryview);
1497 void main_window_reflect_prefs_all_now(void)
1499 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1502 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1507 /* re-create colorlabel submenu */
1508 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1509 g_return_if_fail(menu != NULL);
1511 /* clear items. get item pointers. */
1512 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1513 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1515 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1516 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1520 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1522 if (prefs_tag == 0 || pixmap_theme_changed) {
1523 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1524 GINT_TO_POINTER(pixmap_theme_changed));
1528 void main_window_set_summary_column(void)
1531 MainWindow *mainwin;
1533 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1534 mainwin = (MainWindow *)cur->data;
1535 summary_set_column_order(mainwin->summaryview);
1539 void main_window_set_folder_column(void)
1542 MainWindow *mainwin;
1544 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1545 mainwin = (MainWindow *)cur->data;
1546 folderview_set_column_order(mainwin->folderview);
1550 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1551 GList *account_list)
1553 GList *cur_ac, *cur_item;
1554 GtkWidget *menuitem;
1555 PrefsAccount *ac_prefs;
1557 /* destroy all previous menu item */
1558 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1559 while (cur_item != NULL) {
1560 GList *next = cur_item->next;
1561 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1565 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1566 ac_prefs = (PrefsAccount *)cur_ac->data;
1568 menuitem = gtk_menu_item_new_with_label
1569 (ac_prefs->account_name
1570 ? ac_prefs->account_name : _("Untitled"));
1571 gtk_widget_show(menuitem);
1572 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1573 g_signal_connect(G_OBJECT(menuitem), "activate",
1574 G_CALLBACK(account_selector_menu_cb),
1579 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1580 GList *account_list)
1582 GList *cur_ac, *cur_item;
1584 GtkWidget *menuitem;
1585 PrefsAccount *ac_prefs;
1587 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1588 "/Message/Receive");
1590 /* search for separator */
1591 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1592 cur_item = cur_item->next) {
1593 if (GTK_BIN(cur_item->data)->child == NULL) {
1594 cur_item = cur_item->next;
1599 /* destroy all previous menu item */
1600 while (cur_item != NULL) {
1601 GList *next = cur_item->next;
1602 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1606 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1607 ac_prefs = (PrefsAccount *)cur_ac->data;
1609 menuitem = gtk_menu_item_new_with_label
1610 (ac_prefs->account_name ? ac_prefs->account_name
1612 gtk_widget_show(menuitem);
1613 gtk_menu_append(GTK_MENU(menu), menuitem);
1614 g_signal_connect(G_OBJECT(menuitem), "activate",
1615 G_CALLBACK(account_receive_menu_cb),
1620 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1621 GList *account_list)
1623 GList *cur_ac, *cur_item;
1624 GtkWidget *menuitem;
1625 PrefsAccount *ac_prefs;
1626 GtkWidget *menu = NULL;
1628 if (mainwin->toolbar->getall_btn == NULL
1629 || mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1632 menu = mainwin->toolbar->getall_combo->menu;
1634 /* destroy all previous menu item */
1635 cur_item = GTK_MENU_SHELL(menu)->children;
1636 while (cur_item != NULL) {
1637 GList *next = cur_item->next;
1638 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1642 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1643 ac_prefs = (PrefsAccount *)cur_ac->data;
1645 menuitem = gtk_menu_item_new_with_label
1646 (ac_prefs->account_name
1647 ? ac_prefs->account_name : _("Untitled"));
1648 gtk_widget_show(menuitem);
1649 gtk_menu_append(GTK_MENU(menu), menuitem);
1650 g_signal_connect(G_OBJECT(menuitem), "activate",
1651 G_CALLBACK(account_receive_menu_cb),
1656 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1657 GList *account_list)
1659 GList *cur_ac, *cur_item;
1660 GtkWidget *menuitem;
1661 PrefsAccount *ac_prefs;
1662 GtkWidget *menu = NULL;
1664 if (mainwin->toolbar->compose_mail_btn == NULL
1665 || mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1668 menu = mainwin->toolbar->compose_combo->menu;
1670 /* destroy all previous menu item */
1671 cur_item = GTK_MENU_SHELL(menu)->children;
1672 while (cur_item != NULL) {
1673 GList *next = cur_item->next;
1674 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1678 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1679 ac_prefs = (PrefsAccount *)cur_ac->data;
1681 menuitem = gtk_menu_item_new_with_label
1682 (ac_prefs->account_name
1683 ? ac_prefs->account_name : _("Untitled"));
1684 gtk_widget_show(menuitem);
1685 gtk_menu_append(GTK_MENU(menu), menuitem);
1686 g_signal_connect(G_OBJECT(menuitem), "activate",
1687 G_CALLBACK(account_compose_menu_cb),
1692 void main_window_set_account_menu(GList *account_list)
1695 MainWindow *mainwin;
1697 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1698 mainwin = (MainWindow *)cur->data;
1699 main_window_set_account_selector_menu(mainwin, account_list);
1700 main_window_set_account_receive_menu(mainwin, account_list);
1701 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1702 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1706 void main_window_set_account_menu_only_toolbar(GList *account_list)
1709 MainWindow *mainwin;
1711 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1712 mainwin = (MainWindow *)cur->data;
1713 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1714 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1718 static void main_window_show_cur_account(MainWindow *mainwin)
1723 ac_name = g_strdup(cur_account
1724 ? (cur_account->account_name
1725 ? cur_account->account_name : _("Untitled"))
1729 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1731 buf = g_strdup(PROG_VERSION);
1732 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1735 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1736 gtk_widget_queue_resize(mainwin->ac_button);
1741 GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
1743 switch (mainwin->type) {
1744 case SEPARATE_FOLDER:
1745 return mainwin->win.sep_folder.folderwin;
1747 return mainwin->win.sep_both.folderwin;
1753 GtkWidget *main_window_get_message_window(MainWindow *mainwin)
1755 switch (mainwin->type) {
1756 case SEPARATE_MESSAGE:
1757 return mainwin->win.sep_message.messagewin;
1759 return mainwin->win.sep_both.messagewin;
1765 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1767 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
1768 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1769 /* GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); */
1770 GtkWidget *message_wid = mainwin->messageview->vbox;
1772 debug_print("Changing window separation type from %d to %d\n",
1773 mainwin->type, type);
1775 if (mainwin->type == type) return;
1777 /* remove widgets from those containers */
1778 gtk_widget_ref(folder_wid);
1779 gtk_widget_ref(summary_wid);
1780 gtk_widget_ref(message_wid);
1781 gtkut_container_remove
1782 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1783 gtkut_container_remove
1784 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1785 gtkut_container_remove
1786 (GTK_CONTAINER(message_wid->parent), message_wid);
1788 /* clean containers */
1789 switch (mainwin->type) {
1791 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1793 case SEPARATE_FOLDER:
1794 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1795 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1797 case SEPARATE_MESSAGE:
1798 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1799 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1802 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1803 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1807 gtk_widget_hide(mainwin->window);
1808 main_window_set_widgets(mainwin, type);
1809 gtk_widget_show(mainwin->window);
1811 gtk_widget_unref(folder_wid);
1812 gtk_widget_unref(summary_wid);
1813 gtk_widget_unref(message_wid);
1816 void main_window_toggle_message_view(MainWindow *mainwin)
1818 SummaryView *summaryview = mainwin->summaryview;
1819 union CompositeWin *cwin = &mainwin->win;
1820 GtkWidget *vpaned = NULL;
1821 GtkWidget *container = NULL;
1822 GtkWidget *msgwin = NULL;
1824 switch (mainwin->type) {
1826 vpaned = cwin->sep_none.vpaned;
1827 container = cwin->sep_none.hpaned;
1829 case SEPARATE_FOLDER:
1830 vpaned = cwin->sep_folder.vpaned;
1831 container = mainwin->vbox_body;
1833 case SEPARATE_MESSAGE:
1834 msgwin = mainwin->win.sep_message.messagewin;
1837 msgwin = mainwin->win.sep_both.messagewin;
1842 if (GTK_WIDGET_VISIBLE(msgwin)) {
1843 gtk_widget_hide(msgwin);
1844 mainwin->messageview->visible = FALSE;
1845 summaryview->displayed = NULL;
1847 gtk_widget_show(msgwin);
1848 mainwin->messageview->visible = TRUE;
1850 } else if (vpaned->parent != NULL) {
1851 mainwin->messageview->visible = FALSE;
1852 summaryview->displayed = NULL;
1853 gtk_widget_ref(vpaned);
1854 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1855 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1857 mainwin->messageview->visible = TRUE;
1858 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1859 gtk_container_add(GTK_CONTAINER(container), vpaned);
1860 gtk_widget_unref(vpaned);
1863 if (messageview_is_visible(mainwin->messageview))
1864 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1865 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1867 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1868 GTK_ARROW_UP, GTK_SHADOW_OUT);
1870 if (mainwin->messageview->visible == FALSE)
1871 messageview_clear(mainwin->messageview);
1873 main_window_set_menu_sensitive(mainwin);
1875 prefs_common.msgview_visible = mainwin->messageview->visible;
1877 gtk_widget_grab_focus(summaryview->ctree);
1880 void main_window_get_size(MainWindow *mainwin)
1882 GtkAllocation *allocation;
1884 if (mainwin_list == NULL || mainwin->messageview == NULL) {
1885 debug_print("called after messageview "
1886 "has been deallocated!\n");
1890 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1892 if (allocation->width > 1 && allocation->height > 1) {
1893 prefs_common.summaryview_width = allocation->width;
1895 if ((mainwin->type == SEPARATE_NONE ||
1896 mainwin->type == SEPARATE_FOLDER) &&
1897 messageview_is_visible(mainwin->messageview))
1898 prefs_common.summaryview_height = allocation->height;
1900 prefs_common.mainview_width = allocation->width;
1903 allocation = &mainwin->window->allocation;
1904 if (allocation->width > 1 && allocation->height > 1) {
1905 prefs_common.mainview_height = allocation->height;
1906 prefs_common.mainwin_width = allocation->width;
1907 prefs_common.mainwin_height = allocation->height;
1910 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1911 if (allocation->width > 1 && allocation->height > 1) {
1912 prefs_common.folderview_width = allocation->width;
1913 prefs_common.folderview_height = allocation->height;
1916 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
1917 if (allocation->width > 1 && allocation->height > 1) {
1918 prefs_common.msgview_width = allocation->width;
1919 prefs_common.msgview_height = allocation->height;
1922 /* debug_print("summaryview size: %d x %d\n",
1923 prefs_common.summaryview_width,
1924 prefs_common.summaryview_height);
1925 debug_print("folderview size: %d x %d\n",
1926 prefs_common.folderview_width,
1927 prefs_common.folderview_height);
1928 debug_print("messageview size: %d x %d\n",
1929 prefs_common.msgview_width,
1930 prefs_common.msgview_height); */
1933 void main_window_get_position(MainWindow *mainwin)
1938 gtkut_widget_get_uposition(mainwin->window, &x, &y);
1940 prefs_common.mainview_x = x;
1941 prefs_common.mainview_y = y;
1942 prefs_common.mainwin_x = x;
1943 prefs_common.mainwin_y = y;
1945 debug_print("main window position: %d, %d\n", x, y);
1947 window = main_window_get_folder_window(mainwin);
1949 gtkut_widget_get_uposition(window, &x, &y);
1950 prefs_common.folderwin_x = x;
1951 prefs_common.folderwin_y = y;
1952 debug_print("folder window position: %d, %d\n", x, y);
1954 window = main_window_get_message_window(mainwin);
1956 gtkut_widget_get_uposition(window, &x, &y);
1957 prefs_common.main_msgwin_x = x;
1958 prefs_common.main_msgwin_y = y;
1959 debug_print("message window position: %d, %d\n", x, y);
1963 void main_window_progress_on(MainWindow *mainwin)
1965 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
1968 void main_window_progress_off(MainWindow *mainwin)
1970 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
1971 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
1974 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
1978 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
1979 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
1980 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
1981 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
1984 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1987 if (alertpanel(_("Empty trash"),
1988 _("Delete all messages in trash folders?"),
1989 GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
1990 != G_ALERTALTERNATE)
1992 manage_window_focus_in(mainwin->window, NULL, NULL);
1995 procmsg_empty_all_trash();
1997 if (mainwin->summaryview->folder_item &&
1998 mainwin->summaryview->folder_item->stype == F_TRASH)
1999 gtk_widget_grab_focus(mainwin->folderview->ctree);
2002 void main_window_add_mailbox(MainWindow *mainwin)
2007 path = input_dialog(_("Add mailbox"),
2008 _("Input the location of mailbox.\n"
2009 "If the existing mailbox is specified, it will be\n"
2010 "scanned automatically."),
2013 if (folder_find_from_path(path)) {
2014 alertpanel_error(_("The mailbox '%s' already exists."), path);
2018 folder = folder_new(folder_get_class_from_string("mh"),
2019 !strcmp(path, "Mail") ? _("Mailbox") :
2020 g_path_get_basename(path), path);
2023 if (folder->klass->create_tree(folder) < 0) {
2024 alertpanel_error(_("Creation of the mailbox failed.\n"
2025 "Maybe some files already exist, or you don't have the permission to write there."));
2026 folder_destroy(folder);
2031 folder_set_ui_func(folder, scan_tree_func, mainwin);
2032 folder_scan_tree(folder, TRUE);
2033 folder_set_ui_func(folder, NULL, NULL);
2036 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2038 SensitiveCond state = 0;
2039 SummarySelection selection;
2040 FolderItem *item = mainwin->summaryview->folder_item;
2041 GList *account_list = account_get_list();
2043 selection = summary_get_selection_type(mainwin->summaryview);
2045 if (mainwin->lock_count == 0)
2046 state |= M_UNLOCKED;
2047 if (selection != SUMMARY_NONE)
2048 state |= M_MSG_EXIST;
2049 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2051 /* if (item->folder->type != F_NEWS) */
2052 state |= M_ALLOW_DELETE;
2054 if (prefs_common.immediate_exec == 0
2055 && mainwin->lock_count == 0)
2056 state |= M_DELAY_EXEC;
2058 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2059 || selection != SUMMARY_NONE)
2060 state |= M_HIDE_READ_MSG;
2062 if (mainwin->summaryview->threaded)
2063 state |= M_THREADED;
2065 state |= M_UNTHREADED;
2066 if (selection == SUMMARY_SELECTED_SINGLE ||
2067 selection == SUMMARY_SELECTED_MULTIPLE)
2068 state |= M_TARGET_EXIST;
2069 if (selection == SUMMARY_SELECTED_SINGLE)
2070 state |= M_SINGLE_TARGET_EXIST;
2071 if (mainwin->summaryview->folder_item &&
2072 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2075 state |= M_NOT_NEWS;
2076 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2077 state |= M_ACTIONS_EXIST;
2079 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2080 state |= M_HAVE_QUEUED_MAILS;
2082 if (selection == SUMMARY_SELECTED_SINGLE &&
2084 (folder_has_parent_of_type(item, F_DRAFT) ||
2085 folder_has_parent_of_type(item, F_OUTBOX) ||
2086 folder_has_parent_of_type(item, F_QUEUE))))
2087 state |= M_ALLOW_REEDIT;
2089 state |= M_HAVE_ACCOUNT;
2091 for ( ; account_list != NULL; account_list = account_list->next) {
2092 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2093 state |= M_HAVE_NEWS_ACCOUNT;
2098 if (procmsg_spam_can_learn()) {
2099 state |= M_CAN_LEARN_SPAM;
2102 if (inc_is_active())
2103 state |= M_INC_ACTIVE;
2105 if (mainwin->summaryview->deleted > 0 ||
2106 mainwin->summaryview->moved > 0 ||
2107 mainwin->summaryview->copied > 0)
2108 state |= M_DELAY_EXEC;
2115 void main_window_set_menu_sensitive(MainWindow *mainwin)
2117 GtkItemFactory *ifactory = mainwin->menu_factory;
2118 SensitiveCond state;
2121 GtkWidget *menuitem;
2122 SummaryView *summaryview;
2127 static const struct {
2131 {"/File/Save as...", M_TARGET_EXIST},
2132 {"/File/Print..." , M_TARGET_EXIST},
2133 {"/File/Exit" , M_UNLOCKED},
2135 {"/Edit/Select thread" , M_SINGLE_TARGET_EXIST},
2137 {"/View/Sort" , M_EXEC},
2138 {"/View/Thread view" , M_EXEC},
2139 {"/View/Expand all threads" , M_MSG_EXIST},
2140 {"/View/Collapse all threads" , M_MSG_EXIST},
2141 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2142 {"/View/Go to/Previous message" , M_MSG_EXIST},
2143 {"/View/Go to/Next message" , M_MSG_EXIST},
2144 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2145 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2146 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2147 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2148 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2149 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2150 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2151 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2152 {"/View/Show all headers" , M_SINGLE_TARGET_EXIST},
2153 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2154 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2156 {"/Message/Receive/Get from current account"
2157 , M_HAVE_ACCOUNT|M_UNLOCKED},
2158 {"/Message/Receive/Get from all accounts"
2159 , M_HAVE_ACCOUNT|M_UNLOCKED},
2160 {"/Message/Receive/Cancel receiving"
2162 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2163 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2164 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2165 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2166 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2167 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2168 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2169 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2170 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2171 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2172 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2173 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2174 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2175 {"/Message/Mark" , M_TARGET_EXIST},
2176 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2177 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2178 {"/Message/Color label" , M_TARGET_EXIST},
2179 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2181 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2182 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2183 {"/Tools/Harvest addresses/from Messages..."
2185 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2186 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2187 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2188 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2189 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2190 {"/Tools/Execute" , M_DELAY_EXEC},
2191 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2193 {"/Configuration", M_UNLOCKED},
2198 state = main_window_get_current_state(mainwin);
2200 for (i = 0; entry[i].entry != NULL; i++) {
2201 sensitive = ((entry[i].cond & state) == entry[i].cond);
2202 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2205 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2207 /* search for separator */
2208 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2209 cur_item = cur_item->next) {
2210 if (GTK_BIN(cur_item->data)->child == NULL) {
2211 cur_item = cur_item->next;
2216 for (; cur_item != NULL; cur_item = cur_item->next) {
2217 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2218 (M_UNLOCKED & state) != 0);
2221 main_window_menu_callback_block(mainwin);
2223 #define SET_CHECK_MENU_ACTIVE(path, active) \
2225 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2226 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2229 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2230 messageview_is_visible(mainwin->messageview));
2232 summaryview = mainwin->summaryview;
2233 menu_path = "/View/Sort/Don't sort";
2235 switch (summaryview->sort_key) {
2236 case SORT_BY_NUMBER:
2237 menu_path = "/View/Sort/by number"; break;
2239 menu_path = "/View/Sort/by Size"; break;
2241 menu_path = "/View/Sort/by Date"; break;
2243 menu_path = "/View/Sort/by From"; break;
2245 menu_path = "/View/Sort/by To"; break;
2246 case SORT_BY_SUBJECT:
2247 menu_path = "/View/Sort/by Subject"; break;
2249 menu_path = "/View/Sort/by color label"; break;
2251 menu_path = "/View/Sort/by mark"; break;
2252 case SORT_BY_STATUS:
2253 menu_path = "/View/Sort/by status"; break;
2255 menu_path = "/View/Sort/by attachment"; break;
2257 menu_path = "/View/Sort/by score"; break;
2258 case SORT_BY_LOCKED:
2259 menu_path = "/View/Sort/by locked"; break;
2262 menu_path = "/View/Sort/Don't sort"; break;
2264 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2266 if (summaryview->sort_type == SORT_ASCENDING) {
2267 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2269 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2272 if (summaryview->sort_key != SORT_BY_NONE) {
2273 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2274 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2276 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2277 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2280 if (mainwin->messageview
2281 && mainwin->messageview->mimeview
2282 && mainwin->messageview->mimeview->textview)
2283 SET_CHECK_MENU_ACTIVE("/View/Show all headers",
2284 mainwin->messageview->mimeview->textview->show_all_headers);
2285 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2286 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2287 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2288 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2289 if (prefs_common.hide_quotes == 1)
2290 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2291 if (prefs_common.hide_quotes == 2)
2292 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2293 if (prefs_common.hide_quotes == 3)
2294 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2296 #undef SET_CHECK_MENU_ACTIVE
2298 main_window_menu_callback_unblock(mainwin);
2301 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2303 GtkItemFactory *ifactory;
2305 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2308 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2310 gtk_widget_set_sensitive (gtk_item_factory_get_item
2311 (ifactory,"/Message/Mailing-List"), TRUE);
2313 gtk_widget_set_sensitive (gtk_item_factory_get_item
2314 (ifactory,"/Message/Mailing-List"), FALSE);
2317 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2320 GtkWidget *menuitem;
2322 if (!msginfo || !msginfo->extradata) {
2323 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2324 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2325 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2326 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2327 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2328 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2332 /* Mailing list post */
2333 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2334 g_free(msginfo->extradata->list_post);
2335 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2337 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2339 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2341 /* Mailing list help */
2342 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2344 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2346 /* Mailing list subscribe */
2347 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2349 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2351 /* Mailing list unsubscribe */
2352 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2354 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2356 /* Mailing list view archive */
2357 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2359 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2361 /* Mailing list contact owner */
2362 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2364 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2369 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2371 GtkWidget *item, *menu;
2372 const gchar *url_pt ;
2373 gchar url_decoded[BUFFSIZE];
2374 GList *amenu, *alist;
2377 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2379 /* First delete old submenu */
2380 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2381 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2382 alist = amenu->next;
2383 item = GTK_WIDGET (amenu->data);
2384 gtk_widget_destroy (item);
2388 for (url_pt = list_header; url_pt && *url_pt;) {
2389 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2391 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2392 item = gtk_menu_item_new_with_label ((url_decoded));
2393 gtk_signal_connect (GTK_OBJECT(item), "activate",
2394 GTK_SIGNAL_FUNC(mailing_list_compose), NULL);
2396 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2397 !g_strncasecmp (url_decoded, "https:",6)) {
2399 item = gtk_menu_item_new_with_label ((url_decoded));
2400 gtk_signal_connect (GTK_OBJECT(item), "activate",
2401 GTK_SIGNAL_FUNC(mailing_list_open_uri), NULL);
2404 gtk_menu_append (GTK_MENU(menu), item);
2405 gtk_widget_show (item);
2411 gtk_widget_set_sensitive (menuitem, TRUE);
2413 gtk_widget_set_sensitive (menuitem, FALSE);
2419 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2421 gchar tmp[BUFFSIZE];
2427 *url_decoded = '\0';
2431 /* Ignore spaces, comments and tabs () */
2432 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2434 for (;*buf != ')' && *buf != 0x00; buf++);
2436 /* First non space and non comment must be a < */
2439 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2444 *url_decoded = '\0';
2449 *url_decoded = '\0';
2455 decode_uri (url_decoded, (const gchar *)tmp);
2457 /* Prepare the work for the next url in the list */
2458 /* after the closing bracket >, ignore space, comments and tabs */
2459 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2461 for (;*buf != ')' && *buf != 0x00; buf++);
2463 if (!buf || !*buf) {
2468 /* now first non space, non comment must be a comma */
2470 for (;*buf != 0x00; buf++);
2476 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2480 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2481 compose_new(NULL, mailto+7, NULL);
2484 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2489 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2490 open_uri (mailto, prefs_common.uri_cmd);
2493 void main_window_popup(MainWindow *mainwin)
2495 gtkut_window_popup(mainwin->window);
2497 switch (mainwin->type) {
2498 case SEPARATE_FOLDER:
2499 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
2501 case SEPARATE_MESSAGE:
2502 gtkut_window_popup(mainwin->win.sep_message.messagewin);
2505 gtkut_window_popup(mainwin->win.sep_both.folderwin);
2506 gtkut_window_popup(mainwin->win.sep_both.messagewin);
2513 void main_window_show(MainWindow *mainwin)
2515 gtk_widget_show(mainwin->window);
2516 gtk_widget_show(mainwin->vbox_body);
2518 gtk_widget_set_uposition(mainwin->window,
2519 prefs_common.mainwin_x,
2520 prefs_common.mainwin_y);
2522 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2523 prefs_common.folderview_width,
2524 prefs_common.folderview_height);
2525 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2526 prefs_common.summaryview_width,
2527 prefs_common.summaryview_height);
2528 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2529 prefs_common.msgview_width,
2530 prefs_common.msgview_height);
2532 if (mainwin->type & SEPARATE_FOLDER) {
2533 GtkWidget *folderwin;
2535 folderwin = main_window_get_folder_window(mainwin);
2536 gtk_widget_show(folderwin);
2537 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
2538 prefs_common.folderwin_y);
2541 if (mainwin->type & SEPARATE_MESSAGE) {
2542 GtkWidget *messagewin;
2544 messagewin = main_window_get_message_window(mainwin);
2545 gtk_widget_show(messagewin);
2546 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
2547 prefs_common.main_msgwin_y);
2551 void main_window_hide(MainWindow *mainwin)
2553 main_window_get_size(mainwin);
2554 main_window_get_position(mainwin);
2556 gtk_widget_hide(mainwin->window);
2557 gtk_widget_hide(mainwin->vbox_body);
2559 if (mainwin->type & SEPARATE_FOLDER) {
2560 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2563 if (mainwin->type & SEPARATE_MESSAGE) {
2564 gtk_widget_hide(mainwin->win.sep_message.messagewin);
2568 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
2570 GtkWidget *folderwin = NULL;
2571 GtkWidget *messagewin = NULL;
2574 GtkWidget *vbox_body = mainwin->vbox_body;
2575 GtkItemFactory *ifactory = mainwin->menu_factory;
2576 GtkWidget *menuitem;
2577 GtkItemFactory *msgview_ifactory;
2579 debug_print("Setting widgets... ");
2581 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2582 prefs_common.folderview_width,
2583 prefs_common.folderview_height);
2584 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2585 prefs_common.summaryview_width,
2586 prefs_common.summaryview_height);
2587 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2588 prefs_common.msgview_width,
2589 prefs_common.msgview_height);
2591 /* create separated window(s) if needed */
2592 if (type & SEPARATE_FOLDER) {
2593 static GdkGeometry folderwin_geometry;
2595 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2596 gtk_window_set_title(GTK_WINDOW(folderwin),
2597 _("Sylpheed-Claws - Folder View"));
2599 gtk_window_move(GTK_WINDOW(folderwin),
2600 prefs_common.folderwin_x,
2601 prefs_common.folderwin_y);
2603 if (!folderwin_geometry.min_height) {
2604 folderwin_geometry.min_width = 320;
2605 folderwin_geometry.min_height = 200;
2607 gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
2608 &folderwin_geometry, GDK_HINT_MIN_SIZE);
2610 gtk_widget_set_size_request(folderwin,
2611 prefs_common.folderview_width,
2612 prefs_common.folderview_height);
2614 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
2617 g_signal_connect(G_OBJECT(folderwin), "delete_event",
2618 G_CALLBACK(folder_window_close_cb),
2620 gtk_container_add(GTK_CONTAINER(folderwin),
2621 GTK_WIDGET_PTR(mainwin->folderview));
2622 gtk_widget_realize(folderwin);
2624 if (prefs_common.folderview_visible)
2625 gtk_widget_show(folderwin);
2628 if (type & SEPARATE_MESSAGE) {
2629 static GdkGeometry msgwin_geometry;
2631 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2632 gtk_window_set_title(GTK_WINDOW(messagewin),
2633 _("Sylpheed-Claws - Message View"));
2635 gtk_window_move(GTK_WINDOW(messagewin),
2636 prefs_common.main_msgwin_x,
2637 prefs_common.main_msgwin_y);
2639 if (!msgwin_geometry.min_height) {
2640 msgwin_geometry.min_width = 320;
2641 msgwin_geometry.min_height = 200;
2643 gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
2644 &msgwin_geometry, GDK_HINT_MIN_SIZE);
2646 gtk_widget_set_size_request(messagewin,
2647 prefs_common.msgwin_width,
2648 prefs_common.msgwin_height);
2650 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
2652 g_signal_connect(G_OBJECT(messagewin), "delete_event",
2653 G_CALLBACK(message_window_close_cb),
2655 if (messageview_is_visible(mainwin->messageview))
2656 gtk_widget_show(messagewin);
2658 mainwin->messageview->statusbar = mainwin->statusbar;
2659 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2664 hpaned = gtk_hpaned_new();
2665 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2666 gtk_paned_add1(GTK_PANED(hpaned),
2667 GTK_WIDGET_PTR(mainwin->folderview));
2668 gtk_widget_show(hpaned);
2669 gtk_widget_queue_resize(hpaned);
2671 vpaned = gtk_vpaned_new();
2672 if (messageview_is_visible(mainwin->messageview)) {
2673 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2674 gtk_paned_add1(GTK_PANED(vpaned),
2675 GTK_WIDGET_PTR(mainwin->summaryview));
2677 gtk_paned_add2(GTK_PANED(hpaned),
2678 GTK_WIDGET_PTR(mainwin->summaryview));
2679 gtk_widget_ref(vpaned);
2681 gtk_paned_add2(GTK_PANED(vpaned),
2682 GTK_WIDGET_PTR(mainwin->messageview));
2683 gtk_widget_show(vpaned);
2684 gtk_widget_queue_resize(vpaned);
2686 mainwin->win.sep_none.hpaned = hpaned;
2687 mainwin->win.sep_none.vpaned = vpaned;
2689 /* remove headerview if not in prefs */
2690 headerview_set_visibility(mainwin->messageview->headerview,
2691 prefs_common.display_header_pane);
2693 case SEPARATE_FOLDER:
2694 vpaned = gtk_vpaned_new();
2695 if (messageview_is_visible(mainwin->messageview)) {
2696 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
2698 gtk_paned_add1(GTK_PANED(vpaned),
2699 GTK_WIDGET_PTR(mainwin->summaryview));
2701 gtk_box_pack_start(GTK_BOX(vbox_body),
2702 GTK_WIDGET_PTR(mainwin->summaryview),
2704 gtk_widget_ref(vpaned);
2706 gtk_paned_add2(GTK_PANED(vpaned),
2707 GTK_WIDGET_PTR(mainwin->messageview));
2708 gtk_widget_show(vpaned);
2709 gtk_widget_queue_resize(vpaned);
2711 mainwin->win.sep_folder.folderwin = folderwin;
2712 mainwin->win.sep_folder.vpaned = vpaned;
2714 /* remove headerview if not in prefs */
2715 headerview_set_visibility(mainwin->messageview->headerview,
2716 prefs_common.display_header_pane);
2719 case SEPARATE_MESSAGE:
2720 hpaned = gtk_hpaned_new();
2721 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2722 gtk_paned_add1(GTK_PANED(hpaned),
2723 GTK_WIDGET_PTR(mainwin->folderview));
2724 gtk_paned_add2(GTK_PANED(hpaned),
2725 GTK_WIDGET_PTR(mainwin->summaryview));
2726 gtk_widget_show(hpaned);
2727 gtk_widget_queue_resize(hpaned);
2728 messageview_add_toolbar(mainwin->messageview, messagewin);
2729 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2730 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2732 mainwin->win.sep_message.messagewin = messagewin;
2733 mainwin->win.sep_message.hpaned = hpaned;
2735 gtk_widget_realize(messagewin);
2736 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2737 gtk_widget_show_all(messagewin);
2738 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2739 mainwin->messageview->handlebox,
2740 prefs_common.toolbar_style);
2742 /* remove headerview if not in prefs */
2743 headerview_set_visibility(mainwin->messageview->headerview,
2744 prefs_common.display_header_pane);
2748 messageview_add_toolbar(mainwin->messageview, messagewin);
2749 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2750 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2752 gtk_box_pack_start(GTK_BOX(vbox_body),
2753 GTK_WIDGET_PTR(mainwin->summaryview),
2756 mainwin->win.sep_both.folderwin = folderwin;
2757 mainwin->win.sep_both.messagewin = messagewin;
2759 gtk_widget_realize(messagewin);
2760 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2761 gtk_widget_show_all(messagewin);
2762 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2763 mainwin->messageview->handlebox,
2764 prefs_common.toolbar_style);
2766 /* remove headerview if not in prefs */
2767 headerview_set_visibility(mainwin->messageview->headerview,
2768 prefs_common.display_header_pane);
2773 if (messageview_is_visible(mainwin->messageview))
2774 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2775 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2777 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2778 GTK_ARROW_UP, GTK_SHADOW_OUT);
2780 gtk_window_move(GTK_WINDOW(mainwin->window),
2781 prefs_common.mainwin_x,
2782 prefs_common.mainwin_y);
2784 gtk_widget_queue_resize(vbox_body);
2785 gtk_widget_queue_resize(mainwin->vbox);
2786 gtk_widget_queue_resize(mainwin->window);
2787 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2788 * and mimeview icon list/ctree lose track of their visibility states */
2789 if (!noticeview_is_visible(mainwin->messageview->noticeview))
2790 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2791 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
2792 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2793 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2794 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2796 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2798 mainwin->type = type;
2801 /* toggle menu state */
2802 menuitem = gtk_item_factory_get_item
2803 (ifactory, "/View/Show or hide/Folder tree");
2804 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2805 (type & SEPARATE_FOLDER) == 0 ? TRUE :
2806 prefs_common.folderview_visible);
2807 gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2808 menuitem = gtk_item_factory_get_item
2809 (ifactory, "/View/Show or hide/Message view");
2810 gtk_check_menu_item_set_active
2811 (GTK_CHECK_MENU_ITEM(menuitem),
2812 messageview_is_visible(mainwin->messageview));
2814 menuitem = gtk_item_factory_get_item
2815 (ifactory, "/View/Separate folder tree");
2816 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2817 ((type & SEPARATE_FOLDER) != 0));
2818 menuitem = gtk_item_factory_get_item
2819 (ifactory, "/View/Separate message view");
2820 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2821 ((type & SEPARATE_MESSAGE) != 0));
2825 (G_OBJECT(folderwin), "size_allocate",
2826 G_CALLBACK(folder_window_size_allocate_cb),
2831 (G_OBJECT(messagewin), "size_allocate",
2832 G_CALLBACK(message_window_size_allocate_cb),
2836 debug_print("done.\n");
2839 void main_window_destroy_all(void)
2841 while (mainwin_list != NULL) {
2842 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2844 /* free toolbar stuff */
2845 toolbar_clear_list(TOOLBAR_MAIN);
2846 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2847 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2849 mainwin->folderview->mainwin = NULL;
2850 mainwin->summaryview->mainwin = NULL;
2851 mainwin->messageview->mainwin = NULL;
2853 g_free(mainwin->toolbar);
2856 mainwin_list = g_list_remove(mainwin_list, mainwin);
2858 g_list_free(mainwin_list);
2859 mainwin_list = NULL;
2862 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2865 gtk_widget_set_size_request(child, 1, -1);
2868 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2871 gtk_widget_set_size_request(child, -1, -1);
2874 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2877 MainWindow *mainwin = (MainWindow *)data;
2879 if (!event) return FALSE;
2881 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2882 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2885 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2886 menu_button_position, widget,
2887 event->button, event->time);
2892 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2895 MainWindow *mainwin = (MainWindow *)data;
2897 if (mainwin->lock_count == 0)
2898 app_exit_cb(data, 0, widget);
2903 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2906 MainWindow *mainwin = (MainWindow *)data;
2907 GtkWidget *menuitem;
2909 menuitem = gtk_item_factory_get_item
2910 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2911 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2916 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2919 MainWindow *mainwin = (MainWindow *)data;
2920 GtkWidget *menuitem;
2922 menuitem = gtk_item_factory_get_item
2923 (mainwin->menu_factory, "/View/Show or hide/Message view");
2924 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2926 mainwin->messageview->statusbar = mainwin->statusbar;
2927 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2932 static void main_window_size_allocate_cb(GtkWidget *widget,
2933 GtkAllocation *allocation,
2936 MainWindow *mainwin = (MainWindow *)data;
2938 main_window_get_size(mainwin);
2941 static void folder_window_size_allocate_cb(GtkWidget *widget,
2942 GtkAllocation *allocation,
2945 MainWindow *mainwin = (MainWindow *)data;
2947 main_window_get_size(mainwin);
2950 static void message_window_size_allocate_cb(GtkWidget *widget,
2951 GtkAllocation *allocation,
2954 MainWindow *mainwin = (MainWindow *)data;
2956 main_window_get_size(mainwin);
2959 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2962 main_window_add_mailbox(mainwin);
2965 static void update_folderview_cb(MainWindow *mainwin, guint action,
2968 summary_show(mainwin->summaryview, NULL);
2969 folderview_check_new_all();
2972 static void foldersort_cb(MainWindow *mainwin, guint action,
2978 static void import_mbox_cb(MainWindow *mainwin, guint action,
2981 /* only notify if import has failed */
2982 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2983 alertpanel_error(_("Mbox import has failed."));
2987 static void export_mbox_cb(MainWindow *mainwin, guint action,
2990 /* only notify if export has failed */
2991 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2992 alertpanel_error(_("Export to mbox has failed."));
2996 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2999 /* only notify if export has failed */
3000 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3001 alertpanel_error(_("Export to mbox has failed."));
3005 static void empty_trash_cb(MainWindow *mainwin, guint action,
3008 main_window_empty_trash(mainwin, TRUE);
3011 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3013 summary_save_as(mainwin->summaryview);
3016 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3018 summary_print(mainwin->summaryview);
3021 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3023 if (prefs_common.confirm_on_exit) {
3024 if (alertpanel(_("Exit"), _("Exit Sylpheed-Claws?"),
3025 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
3026 != G_ALERTALTERNATE)
3028 manage_window_focus_in(mainwin->window, NULL, NULL);
3031 app_will_exit(widget, mainwin);
3034 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3037 summary_search(mainwin->summaryview);
3039 message_search(mainwin->messageview);
3042 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3044 prefs_common.show_searchbar = TRUE;
3045 summaryview_activate_quicksearch(mainwin->summaryview);
3048 static void toggle_folder_cb(MainWindow *mainwin, guint action,
3053 active = GTK_CHECK_MENU_ITEM(widget)->active;
3055 switch (mainwin->type) {
3057 case SEPARATE_MESSAGE:
3059 case SEPARATE_FOLDER:
3060 debug_print("separate folder\n");
3062 gtk_widget_show(mainwin->win.sep_folder.folderwin);
3064 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
3068 gtk_widget_show(mainwin->win.sep_both.folderwin);
3070 gtk_widget_hide(mainwin->win.sep_both.folderwin);
3074 prefs_common.folderview_visible = active;
3077 static void toggle_message_cb(MainWindow *mainwin, guint action,
3082 active = GTK_CHECK_MENU_ITEM(widget)->active;
3084 if (active != messageview_is_visible(mainwin->messageview))
3085 summary_toggle_view(mainwin->summaryview);
3088 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3091 toolbar_toggle(action, mainwin);
3094 void main_window_reply_cb(MainWindow *mainwin, guint action,
3097 MessageView *msgview = (MessageView*)mainwin->messageview;
3098 GSList *msginfo_list = NULL;
3100 g_return_if_fail(msgview != NULL);
3102 msginfo_list = summary_get_selection(mainwin->summaryview);
3103 g_return_if_fail(msginfo_list != NULL);
3104 compose_reply_from_messageview(msgview, msginfo_list, action);
3105 g_slist_free(msginfo_list);
3109 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3112 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3113 gtk_widget_show(mainwin->hbox_stat);
3114 prefs_common.show_statusbar = TRUE;
3116 gtk_widget_hide(mainwin->hbox_stat);
3117 prefs_common.show_statusbar = FALSE;
3121 static void separate_widget_cb(MainWindow *mainwin, guint action,
3126 if (GTK_CHECK_MENU_ITEM(widget)->active)
3127 type = mainwin->type | action;
3129 type = mainwin->type & ~action;
3131 main_window_separation_change(mainwin, type);
3133 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
3134 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
3137 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3140 offline_ask_sync = ask_sync;
3142 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3144 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3145 offline_ask_sync = TRUE;
3148 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3150 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3153 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3155 GList *folderlist = folder_get_list();
3156 gboolean found = FALSE;
3158 /* see if there are synchronised folders */
3159 for (; folderlist; folderlist = folderlist->next) {
3160 Folder *folder = (Folder *)folderlist->data;
3161 if (folder_want_synchronise(folder)) {
3170 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3171 _("Do you want to synchronise your folders now?"),
3172 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3175 folder_synchronise(NULL);
3178 static void online_switch_clicked (GtkButton *btn, gpointer data)
3180 MainWindow *mainwin;
3181 GtkItemFactory *ifactory;
3182 GtkCheckMenuItem *menuitem;
3184 mainwin = (MainWindow *) data;
3186 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3187 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3189 g_return_if_fail(mainwin != NULL);
3190 g_return_if_fail(menuitem != NULL);
3192 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3193 gtk_widget_hide (mainwin->online_switch);
3194 gtk_widget_show (mainwin->offline_switch);
3195 menuitem->active = TRUE;
3196 inc_autocheck_timer_remove();
3199 if (prefs_common.work_offline)
3201 mainwindow_check_synchronise(mainwin, TRUE);
3202 prefs_common.work_offline = TRUE;
3203 imap_disconnect_all();
3206 if (!prefs_common.work_offline)
3208 gtk_widget_hide (mainwin->offline_switch);
3209 gtk_widget_show (mainwin->online_switch);
3210 menuitem->active = FALSE;
3211 prefs_common.work_offline = FALSE;
3212 inc_autocheck_timer_set();
3213 refresh_resolvers();
3217 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3220 addressbook_open(NULL);
3223 static void log_window_show_cb(MainWindow *mainwin, guint action,
3226 log_window_show(mainwin->logwin);
3229 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3234 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3236 summary_move_to(mainwin->summaryview);
3239 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3241 summary_copy_to(mainwin->summaryview);
3244 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3246 summary_delete(mainwin->summaryview);
3249 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3251 summary_delete_trash(mainwin->summaryview);
3254 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3256 summary_cancel(mainwin->summaryview);
3259 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3261 summary_open_msg(mainwin->summaryview);
3264 static void view_source_cb(MainWindow *mainwin, guint action,
3267 summary_view_source(mainwin->summaryview);
3270 static void show_all_header_cb(MainWindow *mainwin, guint action,
3273 if (mainwin->menu_lock_count) return;
3274 mainwin->summaryview->messageview->all_headers =
3275 GTK_CHECK_MENU_ITEM(widget)->active;
3276 summary_display_msg_selected(mainwin->summaryview,
3277 GTK_CHECK_MENU_ITEM(widget)->active);
3280 #define SET_CHECK_MENU_ACTIVE(path, active) \
3282 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3283 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3286 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3289 GtkWidget *menuitem;
3290 GtkItemFactory *ifactory = mainwin->menu_factory;
3292 if (mainwin->menu_lock_count) return;
3294 prefs_common.hide_quotes =
3295 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3297 mainwin->menu_lock_count++;
3298 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3299 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3300 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3301 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3302 mainwin->menu_lock_count--;
3304 summary_redisplay_msg(mainwin->summaryview);
3307 #undef SET_CHECK_MENU_ACTIVE
3308 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3310 summary_mark(mainwin->summaryview);
3313 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3315 summary_unmark(mainwin->summaryview);
3318 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3321 summary_mark_as_unread(mainwin->summaryview);
3324 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3327 summary_mark_as_read(mainwin->summaryview);
3330 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3333 summary_mark_all_read(mainwin->summaryview);
3336 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3339 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3342 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3344 summary_reedit(mainwin->summaryview);
3347 static void add_address_cb(MainWindow *mainwin, guint action,
3350 summary_add_address(mainwin->summaryview);
3353 static void set_charset_cb(MainWindow *mainwin, guint action,
3358 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3359 str = conv_get_charset_str((CharSet)action);
3361 g_free(mainwin->messageview->forced_charset);
3362 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3363 procmime_force_charset(str);
3365 summary_redisplay_msg(mainwin->summaryview);
3367 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3371 static void set_decode_cb(MainWindow *mainwin, guint action,
3374 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3375 mainwin->messageview->forced_encoding = (EncodingType)action;
3377 summary_redisplay_msg(mainwin->summaryview);
3379 debug_print("forced encoding: %d\n", action);
3383 static void hide_read_messages (MainWindow *mainwin, guint action,
3386 if (!mainwin->summaryview->folder_item
3387 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3389 summary_toggle_show_read_messages(mainwin->summaryview);
3392 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3394 gboolean threaded = FALSE;
3395 if (mainwin->menu_lock_count) return;
3396 if (!mainwin->summaryview->folder_item) return;
3398 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3400 mainwin->summaryview->folder_item->threaded = threaded;
3402 mainwin->summaryview->threaded = threaded;
3404 summary_show(mainwin->summaryview,
3405 mainwin->summaryview->folder_item);
3408 static void expand_threads_cb(MainWindow *mainwin, guint action,
3411 summary_expand_threads(mainwin->summaryview);
3414 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3417 summary_collapse_threads(mainwin->summaryview);
3420 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3423 prefs_summary_column_open();
3426 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3429 prefs_folder_column_open();
3432 static void sort_summary_cb(MainWindow *mainwin, guint action,
3435 FolderItem *item = mainwin->summaryview->folder_item;
3436 GtkWidget *menuitem;
3438 if (mainwin->menu_lock_count) return;
3440 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3441 menuitem = gtk_item_factory_get_item
3442 (mainwin->menu_factory, "/View/Sort/Ascending");
3443 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3444 GTK_CHECK_MENU_ITEM(menuitem)->active
3445 ? SORT_ASCENDING : SORT_DESCENDING);
3446 item->sort_key = action;
3450 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3453 FolderItem *item = mainwin->summaryview->folder_item;
3455 if (mainwin->menu_lock_count) return;
3457 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3458 summary_sort(mainwin->summaryview,
3459 item->sort_key, (FolderSortType)action);
3462 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3465 summary_attract_by_subject(mainwin->summaryview);
3468 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3473 item = folderview_get_selected_item(mainwin->folderview);
3475 main_window_cursor_wait(mainwin);
3476 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3478 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3479 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3481 STATUSBAR_POP(mainwin);
3482 main_window_cursor_normal(mainwin);
3492 static void deldup_all(FolderItem *item, gpointer _data)
3494 struct DelDupsData *data = _data;
3497 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3499 data->dups += result;
3504 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3507 struct DelDupsData data = {0, 0};
3509 folder_func_to_all_folders(deldup_all, &data);
3510 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3511 "Deleted %d duplicate messages in %d folders.\n",
3513 data.dups, data.folders);
3516 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3518 summary_filter(mainwin->summaryview, (gboolean)action);
3521 static void execute_summary_cb(MainWindow *mainwin, guint action,
3524 summary_execute(mainwin->summaryview);
3527 static void update_summary_cb(MainWindow *mainwin, guint action,
3531 FolderView *folderview = mainwin->folderview;
3533 if (!mainwin->summaryview->folder_item) return;
3534 if (!folderview->opened) return;
3536 folder_update_op_count();
3538 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3539 folderview->opened);
3542 folder_item_scan(fitem);
3543 summary_show(mainwin->summaryview, fitem);
3546 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3548 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3551 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3553 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3556 static void prev_unread_cb(MainWindow *mainwin, guint action,
3559 summary_select_prev_unread(mainwin->summaryview);
3562 static void next_unread_cb(MainWindow *mainwin, guint action,
3565 summary_select_next_unread(mainwin->summaryview);
3568 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3570 summary_select_prev_new(mainwin->summaryview);
3573 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3575 summary_select_next_new(mainwin->summaryview);
3578 static void prev_marked_cb(MainWindow *mainwin, guint action,
3581 summary_select_prev_marked(mainwin->summaryview);
3584 static void next_marked_cb(MainWindow *mainwin, guint action,
3587 summary_select_next_marked(mainwin->summaryview);
3590 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3593 summary_select_prev_labeled(mainwin->summaryview);
3596 static void next_labeled_cb(MainWindow *mainwin, guint action,
3599 summary_select_next_labeled(mainwin->summaryview);
3602 static void last_read_cb(MainWindow *mainwin, guint action,
3605 summary_select_last_read(mainwin->summaryview);
3608 static void parent_cb(MainWindow *mainwin, guint action,
3611 summary_select_parent(mainwin->summaryview);
3614 static void goto_folder_cb(MainWindow *mainwin, guint action,
3617 FolderItem *to_folder;
3619 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3622 folderview_select(mainwin->folderview, to_folder);
3625 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3628 folderview_select_next_unread(mainwin->folderview);
3631 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3633 messageview_copy_clipboard(mainwin->messageview);
3636 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3638 MessageView *msgview = mainwin->messageview;
3640 if (messageview_is_visible(msgview) &&
3641 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3642 messageview_select_all(mainwin->messageview);
3644 summary_select_all(mainwin->summaryview);
3647 static void select_thread_cb(MainWindow *mainwin, guint action,
3650 summary_select_thread(mainwin->summaryview);
3653 static void create_filter_cb(MainWindow *mainwin, guint action,
3656 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3659 static void create_processing_cb(MainWindow *mainwin, guint action,
3662 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3665 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3668 prefs_filtering_open(&pre_global_processing,
3669 _("Processing rules to apply before folder rules"),
3670 MANUAL_ANCHOR_PROCESSING,
3674 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3677 prefs_filtering_open(&post_global_processing,
3678 _("Processing rules to apply after folder rules"),
3679 MANUAL_ANCHOR_PROCESSING,
3683 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3686 prefs_filtering_open(&filtering_rules,
3687 _("Filtering configuration"),
3688 MANUAL_ANCHOR_FILTERING,
3692 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3695 prefs_template_open();
3698 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3701 prefs_actions_open(mainwin);
3704 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3707 ssl_manager_open(mainwin);
3710 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3714 new_account_cb(mainwin, 0, widget);
3716 account_open(cur_account);
3720 static void new_account_cb(MainWindow *mainwin, guint action,
3723 account_edit_open();
3724 if (!compose_get_compose_list()) account_add();
3727 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3729 FolderItem *item = NULL;
3730 cur_account = (PrefsAccount *)data;
3732 if (!mainwindow_get_mainwindow())
3734 main_window_show_cur_account(mainwindow_get_mainwindow());
3735 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3736 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3737 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3738 item = folderview_get_selected_item(
3739 mainwindow_get_mainwindow()->folderview);
3741 toolbar_set_compose_button
3742 (mainwindow_get_mainwindow()->toolbar,
3743 FOLDER_TYPE(item->folder) == F_NEWS ?
3744 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3748 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3750 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3751 PrefsAccount *account = (PrefsAccount *)data;
3753 inc_account_mail(mainwin, account);
3756 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3758 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3759 PrefsAccount *account = (PrefsAccount *)data;
3760 FolderItem *item = mainwin->summaryview->folder_item;
3762 compose_new_with_folderitem(account, item);
3765 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3770 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3772 pluginwindow_create();
3775 static void manual_open_cb(MainWindow *mainwin, guint action,
3778 manual_open((ManualType)action, NULL);
3781 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3786 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3788 MainWindow *mainwin = (MainWindow *)data;
3792 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3793 LOCAL_FOLDER(folder)->rootpath,
3797 str = g_strdup_printf(_("Scanning folder %s ..."),
3798 LOCAL_FOLDER(folder)->rootpath);
3800 STATUSBAR_PUSH(mainwin, str);
3801 STATUSBAR_POP(mainwin);
3805 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3808 SummaryView *summary;
3810 g_return_val_if_fail(data, FALSE);
3811 if (!g_list_find(mainwin_list, data))
3813 summary = ((MainWindow *)data)->summaryview;
3814 g_return_val_if_fail(summary, FALSE);
3816 if (GTK_CLIST(summary->ctree)->selection &&
3817 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3823 #define BREAK_ON_MODIFIER_KEY() \
3824 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3826 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3829 MainWindow *mainwin = (MainWindow*) data;
3831 if (!mainwin || !event)
3834 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3836 lastkey = event->keyval;
3840 switch (event->keyval) {
3841 case GDK_Q: /* Quit */
3842 BREAK_ON_MODIFIER_KEY();
3844 app_exit_cb(mainwin, 0, NULL);
3847 if (mainwin->folderview && mainwin->summaryview
3848 && ((!mainwin->summaryview->displayed
3849 && !mainwin->summaryview->selected)
3850 || (mainwin->summaryview->folder_item
3851 && mainwin->summaryview->folder_item->total_msgs == 0))) {
3852 g_signal_stop_emission_by_name(G_OBJECT(widget),
3854 folderview_select_next_unread(mainwin->folderview);
3863 #undef BREAK_ON_MODIFIER_KEY
3866 * Harvest addresses for selected folder.
3868 static void addr_harvest_cb( MainWindow *mainwin,
3872 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3876 * Harvest addresses for selected messages in summary view.
3878 static void addr_harvest_msg_cb( MainWindow *mainwin,
3882 summary_harvest_address( mainwin->summaryview );
3886 *\brief get a MainWindow
3888 *\return MainWindow * The first mainwindow in the mainwin_list
3890 MainWindow *mainwindow_get_mainwindow(void)
3892 if (mainwin_list && mainwin_list->data)
3893 return (MainWindow *)(mainwin_list->data);
3898 gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3900 ProgressData *data = (ProgressData *) source;
3901 MainWindow *mainwin = (MainWindow *) userdata;
3903 switch (data->cmd) {
3904 case PROGRESS_COMMAND_START:
3905 case PROGRESS_COMMAND_STOP:
3906 gtk_progress_bar_set_fraction
3907 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
3909 case PROGRESS_COMMAND_SET_PERCENTAGE:
3910 gtk_progress_bar_set_fraction
3911 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
3914 while (gtk_events_pending()) gtk_main_iteration ();
3919 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3921 mainwindow_check_synchronise(mainwin, FALSE);
3924 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
3926 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
3929 void mainwindow_jump_to(const gchar *target)
3933 FolderItem *item = NULL;
3935 MainWindow *mainwin = mainwindow_get_mainwindow();
3941 printf(_("not initialized\n"));
3945 tmp = g_strdup(target);
3947 if ((p = strstr(tmp, "\r")) != NULL)
3949 if ((p = strstr(tmp, "\n")) != NULL)
3952 if ((item = folder_find_item_from_identifier(tmp))) {
3953 printf(_("selecting folder '%s'\n"), tmp);
3954 folderview_select(mainwin->folderview, item);
3955 main_window_popup(mainwin);
3960 msg = strrchr(tmp, G_DIR_SEPARATOR);
3963 if ((item = folder_find_item_from_identifier(tmp))) {
3964 printf(_("selecting folder '%s'\n"), tmp);
3965 folderview_select(mainwin->folderview, item);
3967 if (item && msg && atoi(msg)) {
3968 printf(_("selecting message %d\n"), atoi(msg));
3969 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
3970 summary_display_msg_selected(mainwin->summaryview, FALSE);
3971 main_window_popup(mainwin);
3977 printf("'%s' not found\n", tmp);