sync with 0.8.8cvs5
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <string.h>
43
44 #include "intl.h"
45 #include "main.h"
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
54 #include "menu.h"
55 #include "stock_pixmap.h"
56 #include "folder.h"
57 #include "inc.h"
58 #include "compose.h"
59 #include "procmsg.h"
60 #include "import.h"
61 #include "export.h"
62 #include "prefs_common.h"
63 #include "prefs_actions.h"
64 #include "prefs_filtering.h"
65 #include "prefs_scoring.h"
66 #include "prefs_account.h"
67 #include "prefs_folder_item.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_template.h"
70 #include "account.h"
71 #include "addressbook.h"
72 #include "logwindow.h"
73 #include "manage_window.h"
74 #include "alertpanel.h"
75 #include "statusbar.h"
76 #include "inputdialog.h"
77 #include "utils.h"
78 #include "gtkutils.h"
79 #include "codeconv.h"
80 #include "about.h"
81 #include "manual.h"
82 #include "version.h"
83 #include "selective_download.h"
84 #include "ssl_manager.h"
85 #include "sslcertwindow.h"
86 #include "prefs_gtk.h"
87 #include "pluginwindow.h"
88
89 #define AC_LABEL_WIDTH  240
90
91 /* list of all instantiated MainWindow */
92 static GList *mainwin_list = NULL;
93
94 static GdkCursor *watch_cursor;
95
96 static void main_window_menu_callback_block     (MainWindow     *mainwin);
97 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
98
99 static void main_window_show_cur_account        (MainWindow     *mainwin);
100
101 static void main_window_set_widgets             (MainWindow     *mainwin,
102                                                  SeparateType    type);
103
104 #if 0
105 static void toolbar_account_button_pressed      (GtkWidget      *widget,
106                                                  GdkEventButton *event,
107                                                  gpointer        data);
108 #endif
109 static void ac_label_button_pressed             (GtkWidget      *widget,
110                                                  GdkEventButton *event,
111                                                  gpointer        data);
112 static void ac_menu_popup_closed                (GtkMenuShell   *menu_shell,
113                                                  gpointer        data);
114
115 static gint main_window_close_cb        (GtkWidget      *widget,
116                                          GdkEventAny    *event,
117                                          gpointer        data);
118 static gint folder_window_close_cb      (GtkWidget      *widget,
119                                          GdkEventAny    *event,
120                                          gpointer        data);
121 static gint message_window_close_cb     (GtkWidget      *widget,
122                                          GdkEventAny    *event,
123                                          gpointer        data);
124
125 static void add_mailbox_cb       (MainWindow    *mainwin,
126                                   guint          action,
127                                   GtkWidget     *widget);
128 static void add_mbox_cb          (MainWindow    *mainwin,
129                                   guint          action,
130                                   GtkWidget     *widget);
131 static void update_folderview_cb (MainWindow    *mainwin,
132                                   guint          action,
133                                   GtkWidget     *widget);
134 static void new_folder_cb        (MainWindow    *mainwin,
135                                   guint          action,
136                                   GtkWidget     *widget);
137 static void rename_folder_cb     (MainWindow    *mainwin,
138                                   guint          action,
139                                   GtkWidget     *widget);
140 static void delete_folder_cb     (MainWindow    *mainwin,
141                                   guint          action,
142                                   GtkWidget     *widget);
143 static void import_mbox_cb       (MainWindow    *mainwin,
144                                   guint          action,
145                                   GtkWidget     *widget);
146 static void export_mbox_cb       (MainWindow    *mainwin,
147                                   guint          action,
148                                   GtkWidget     *widget);
149 static void empty_trash_cb       (MainWindow    *mainwin,
150                                   guint          action,
151                                   GtkWidget     *widget);
152
153 static void save_as_cb           (MainWindow    *mainwin,
154                                   guint          action,
155                                   GtkWidget     *widget);
156 static void print_cb             (MainWindow    *mainwin,
157                                   guint          action,
158                                   GtkWidget     *widget);
159 static void app_exit_cb          (MainWindow    *mainwin,
160                                   guint          action,
161                                   GtkWidget     *widget);
162
163 static void search_cb            (MainWindow    *mainwin,
164                                   guint          action,
165                                   GtkWidget     *widget);
166
167 static void toggle_folder_cb     (MainWindow    *mainwin,
168                                   guint          action,
169                                   GtkWidget     *widget);
170 static void toggle_message_cb    (MainWindow    *mainwin,
171                                   guint          action,
172                                   GtkWidget     *widget);
173 static void toggle_toolbar_cb    (MainWindow    *mainwin,
174                                   guint          action,
175                                   GtkWidget     *widget);
176 static void toggle_statusbar_cb  (MainWindow    *mainwin,
177                                   guint          action,
178                                   GtkWidget     *widget);
179 static void separate_widget_cb   (MainWindow    *mainwin,
180                                   guint          action,
181                                   GtkWidget     *widget);
182
183 static void addressbook_open_cb (MainWindow     *mainwin,
184                                  guint           action,
185                                  GtkWidget      *widget);
186 static void log_window_show_cb  (MainWindow     *mainwin,
187                                  guint           action,
188                                  GtkWidget      *widget);
189 static void sel_download_cb          (MainWindow *mainwin, 
190                                  guint action,
191                                  GtkWidget *widget);
192
193 static void inc_cancel_cb               (MainWindow     *mainwin,
194                                          guint           action,
195                                          GtkWidget      *widget);
196
197 static void open_msg_cb                 (MainWindow     *mainwin,
198                                          guint           action,
199                                          GtkWidget      *widget);
200
201 static void view_source_cb              (MainWindow     *mainwin,
202                                          guint           action,
203                                          GtkWidget      *widget);
204
205 static void show_all_header_cb          (MainWindow     *mainwin,
206                                          guint           action,
207                                          GtkWidget      *widget);
208
209 static void reedit_cb                   (MainWindow     *mainwin,
210                                          guint           action,
211                                          GtkWidget      *widget);
212
213 static void move_to_cb                  (MainWindow     *mainwin,
214                                          guint           action,
215                                          GtkWidget      *widget);
216 static void copy_to_cb                  (MainWindow     *mainwin,
217                                          guint           action,
218                                          GtkWidget      *widget);
219 static void delete_cb                   (MainWindow     *mainwin,
220                                          guint           action,
221                                          GtkWidget      *widget);
222
223 static void cancel_cb                   (MainWindow     *mainwin,
224                                          guint           action,
225                                          GtkWidget      *widget);
226
227 static void mark_cb                     (MainWindow     *mainwin,
228                                          guint           action,
229                                          GtkWidget      *widget);
230 static void unmark_cb                   (MainWindow     *mainwin,
231                                          guint           action,
232                                          GtkWidget      *widget);
233
234 static void mark_as_unread_cb           (MainWindow     *mainwin,
235                                          guint           action,
236                                          GtkWidget      *widget);
237 static void mark_as_read_cb             (MainWindow     *mainwin,
238                                          guint           action,
239                                          GtkWidget      *widget);
240 static void mark_all_read_cb            (MainWindow     *mainwin,
241                                          guint           action,
242                                          GtkWidget      *widget);
243 static void add_address_cb              (MainWindow     *mainwin,
244                                          guint           action,
245                                          GtkWidget      *widget);
246
247 static void set_charset_cb              (MainWindow     *mainwin,
248                                          guint           action,
249                                          GtkWidget      *widget);
250
251 static void hide_read_messages   (MainWindow    *mainwin,
252                                   guint          action,
253                                   GtkWidget     *widget);
254
255 static void thread_cb            (MainWindow    *mainwin,
256                                   guint          action,
257                                   GtkWidget     *widget);
258 static void expand_threads_cb    (MainWindow    *mainwin,
259                                   guint          action,
260                                   GtkWidget     *widget);
261 static void collapse_threads_cb  (MainWindow    *mainwin,
262                                   guint          action,
263                                   GtkWidget     *widget);
264
265 static void set_display_item_cb  (MainWindow    *mainwin,
266                                   guint          action,
267                                   GtkWidget     *widget);
268 static void sort_summary_cb      (MainWindow    *mainwin,
269                                   guint          action,
270                                   GtkWidget     *widget);
271 static void sort_summary_type_cb (MainWindow    *mainwin,
272                                   guint          action,
273                                   GtkWidget     *widget);
274 static void attract_by_subject_cb(MainWindow    *mainwin,
275                                   guint          action,
276                                   GtkWidget     *widget);
277
278 static void delete_duplicated_cb (MainWindow    *mainwin,
279                                   guint          action,
280                                   GtkWidget     *widget);
281 static void filter_cb            (MainWindow    *mainwin,
282                                   guint          action,
283                                   GtkWidget     *widget);
284 static void execute_summary_cb   (MainWindow    *mainwin,
285                                   guint          action,
286                                   GtkWidget     *widget);
287 static void update_summary_cb    (MainWindow    *mainwin,
288                                   guint          action,
289                                   GtkWidget     *widget);
290
291 static void prev_cb              (MainWindow    *mainwin,
292                                   guint          action,
293                                   GtkWidget     *widget);
294 static void next_cb              (MainWindow    *mainwin,
295                                   guint          action,
296                                   GtkWidget     *widget);
297 static void next_unread_cb       (MainWindow    *mainwin,
298                                   guint          action,
299                                   GtkWidget     *widget);
300 static void prev_unread_cb       (MainWindow    *mainwin,
301                                   guint          action,
302                                   GtkWidget     *widget);
303
304 static void prev_new_cb          (MainWindow    *mainwin,
305                                   guint          action,
306                                   GtkWidget     *widget);
307 static void next_new_cb          (MainWindow    *mainwin,
308                                   guint          action,
309                                   GtkWidget     *widget);
310 static void prev_marked_cb       (MainWindow    *mainwin,
311                                   guint          action,
312                                   GtkWidget     *widget);
313 static void next_marked_cb       (MainWindow    *mainwin,
314                                   guint          action,
315                                   GtkWidget     *widget);
316 static void prev_labeled_cb      (MainWindow    *mainwin,
317                                   guint          action,
318                                   GtkWidget     *widget);
319 static void next_labeled_cb      (MainWindow    *mainwin,
320                                   guint          action,
321                                   GtkWidget     *widget);
322
323 static void goto_folder_cb       (MainWindow    *mainwin,
324                                   guint          action,
325                                   GtkWidget     *widget);
326
327 static void copy_cb              (MainWindow    *mainwin,
328                                   guint          action,
329                                   GtkWidget     *widget);
330 static void allsel_cb            (MainWindow    *mainwin,
331                                   guint          action,
332                                   GtkWidget     *widget);
333 static void select_thread_cb     (MainWindow    *mainwin,
334                                   guint          action,
335                                   GtkWidget     *widget);
336
337 static void create_filter_cb     (MainWindow    *mainwin,
338                                   guint          action,
339                                   GtkWidget     *widget);
340
341 static void prefs_common_open_cb        (MainWindow     *mainwin,
342                                          guint           action,
343                                          GtkWidget      *widget);
344 static void prefs_template_open_cb      (MainWindow     *mainwin,
345                                          guint           action,
346                                          GtkWidget      *widget);
347 static void prefs_actions_open_cb       (MainWindow     *mainwin,
348                                          guint           action,
349                                          GtkWidget      *widget);
350 static void prefs_account_open_cb       (MainWindow     *mainwin,
351                                          guint           action,
352                                          GtkWidget      *widget);
353 static void prefs_scoring_open_cb       (MainWindow     *mainwin,
354                                          guint           action,
355                                          GtkWidget      *widget);
356 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
357                                          guint           action,
358                                          GtkWidget      *widget);
359 #ifdef USE_OPENSSL
360 static void ssl_manager_open_cb         (MainWindow     *mainwin,
361                                          guint           action,
362                                          GtkWidget      *widget);
363 #endif
364 static void new_account_cb       (MainWindow    *mainwin,
365                                   guint          action,
366                                   GtkWidget     *widget);
367
368 static void account_menu_cb      (GtkMenuItem   *menuitem,
369                                   gpointer       data);
370
371 static void prefs_open_cb       (GtkMenuItem    *menuitem,
372                                  gpointer        data);
373 static void plugins_open_cb     (GtkMenuItem    *menuitem,
374                                  gpointer        data);
375
376 static void online_switch_clicked(GtkButton     *btn, 
377                                   gpointer data);
378
379 static void manual_open_cb       (MainWindow    *mainwin,
380                                   guint          action,
381                                   GtkWidget     *widget);
382
383 static void scan_tree_func       (Folder        *folder,
384                                   FolderItem    *item,
385                                   gpointer       data);
386                                   
387 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
388
389 static void addr_harvest_cb      ( MainWindow  *mainwin,
390                                    guint       action,
391                                    GtkWidget   *widget );
392
393 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
394                                    guint       action,
395                                    GtkWidget   *widget );
396
397 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
398                                                  GdkEventFocus  *focus,
399                                                  gpointer        data);
400
401 #define  SEPARATE_ACTION 500 
402
403 static GtkItemFactoryEntry mainwin_entries[] =
404 {
405         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
406         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
407         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
408         {N_("/_File/_Check for new messages in all folders"),
409                                                 NULL, update_folderview_cb, 0, NULL},
410         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
411         {N_("/_File/_Folder/Create _new folder..."),
412                                                 NULL, new_folder_cb, 0, NULL},
413         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
414         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
415         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
416         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
417         {N_("/_File/Empty _trash"),             "<shift>D", empty_trash_cb, 0, NULL},
418         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},                                               
419         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
420         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
421         {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
422         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
423         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
424         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
425
426         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
427         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
428         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
429         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
430         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
431         {N_("/_Edit/_Find in current message..."),
432                                                 "<control>F", search_cb, 0, NULL},
433         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
434         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
435         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
436         {N_("/_View/Show or hi_de/_Folder tree"),
437                                                 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
438         {N_("/_View/Show or hi_de/_Message view"),
439                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
440         {N_("/_View/Show or hi_de/_Toolbar"),
441                                                 NULL, NULL, 0, "<Branch>"},
442         {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
443                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
444         {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
445                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
446         {N_("/_View/Show or hi_de/_Toolbar/_Text"),
447                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
448         {N_("/_View/Show or hi_de/_Toolbar/_None"),
449                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
450         {N_("/_View/Show or hi_de/Status _bar"),
451                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
452         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
453         {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
454         {N_("/_View/Separate m_essage view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
455         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
456         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
457         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
458         {N_("/_View/_Sort/by s_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
459         {N_("/_View/_Sort/by _date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
460         {N_("/_View/_Sort/by _from"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
461         {N_("/_View/_Sort/by _recipient"),      NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
462         {N_("/_View/_Sort/by _subject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
463         {N_("/_View/_Sort/by _color label"),
464                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
465         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
466         {N_("/_View/_Sort/by _unread"),         NULL, sort_summary_cb, SORT_BY_UNREAD, "/View/Sort/by number"},
467         {N_("/_View/_Sort/by a_ttachment"),
468                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
469         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
470         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
471         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
472         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
473         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
474         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
475         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
476         {N_("/_View/_Sort/_Attract by subject"),
477                                                 NULL, attract_by_subject_cb, 0, NULL},
478         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
479         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
480         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
481         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
482         {N_("/_View/Set displayed _items..."),  NULL, set_display_item_cb, 0, NULL},
483
484         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
485         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
486         {N_("/_View/_Go to/_Prev message"),     "P", prev_cb, 0, NULL},
487         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
488         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
489         {N_("/_View/_Go to/P_rev unread message"),
490                                                 "<shift>P", prev_unread_cb, 0, NULL},
491         {N_("/_View/_Go to/N_ext unread message"),
492                                                 "<shift>N", next_unread_cb, 0, NULL},
493         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
494         {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
495         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
496         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
497         {N_("/_View/_Go to/Prev _marked message"),
498                                                 NULL, prev_marked_cb, 0, NULL},
499         {N_("/_View/_Go to/Next m_arked message"),
500                                                 NULL, next_marked_cb, 0, NULL},
501         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
502         {N_("/_View/_Go to/Prev _labeled message"),
503                                                 NULL, prev_labeled_cb, 0, NULL},
504         {N_("/_View/_Go to/Next la_beled message"),
505                                                 NULL, next_labeled_cb, 0, NULL},
506         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
507         {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
508         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
509
510 #define CODESET_SEPARATOR \
511         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
512 #define CODESET_ACTION(action) \
513          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
514
515         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
516         {N_("/_View/_Code set/_Auto detect"),
517          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
518         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
519         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
520          CODESET_ACTION(C_US_ASCII)},
521
522 #if HAVE_ICONV
523         {N_("/_View/_Code set/Unicode (_UTF-8)"),
524          CODESET_ACTION(C_UTF_8)},
525         CODESET_SEPARATOR,
526 #endif
527         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
528          CODESET_ACTION(C_ISO_8859_1)},
529         {N_("/_View/_Code set/Western European (ISO-8859-15)"),
530          CODESET_ACTION(C_ISO_8859_15)},
531         CODESET_SEPARATOR,
532 #if HAVE_ICONV
533         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
534          CODESET_ACTION(C_ISO_8859_2)},
535         CODESET_SEPARATOR,
536         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
537          CODESET_ACTION(C_ISO_8859_13)},
538         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
539          CODESET_ACTION(C_ISO_8859_4)},
540         CODESET_SEPARATOR,
541         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
542          CODESET_ACTION(C_ISO_8859_7)},
543         CODESET_SEPARATOR,
544         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
545          CODESET_ACTION(C_ISO_8859_9)},
546         CODESET_SEPARATOR,
547         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
548          CODESET_ACTION(C_ISO_8859_5)},
549         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
550          CODESET_ACTION(C_KOI8_R)},
551         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
552          CODESET_ACTION(C_WINDOWS_1251)},
553         CODESET_SEPARATOR,
554 #endif
555         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
556          CODESET_ACTION(C_ISO_2022_JP)},
557 #if HAVE_ICONV
558         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
559          CODESET_ACTION(C_ISO_2022_JP_2)},
560 #endif
561         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
562          CODESET_ACTION(C_EUC_JP)},
563         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
564          CODESET_ACTION(C_SHIFT_JIS)},
565 #if HAVE_ICONV
566         CODESET_SEPARATOR,
567         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
568          CODESET_ACTION(C_GB2312)},
569         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
570          CODESET_ACTION(C_BIG5)},
571         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
572          CODESET_ACTION(C_EUC_TW)},
573         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
574          CODESET_ACTION(C_ISO_2022_CN)},
575         CODESET_SEPARATOR,
576         {N_("/_View/_Code set/Korean (EUC-_KR)"),
577          CODESET_ACTION(C_EUC_KR)},
578         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
579          CODESET_ACTION(C_ISO_2022_KR)},
580         CODESET_SEPARATOR,
581         {N_("/_View/_Code set/Thai (TIS-620)"),
582          CODESET_ACTION(C_TIS_620)},
583         {N_("/_View/_Code set/Thai (Windows-874)"),
584          CODESET_ACTION(C_WINDOWS_874)},
585 #endif
586
587 #undef CODESET_SEPARATOR
588 #undef CODESET_ACTION
589
590         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
591         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
592         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
593         {N_("/_View/Show all _headers"),        "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
594         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
595         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
596
597         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
598         {N_("/_Message/Get new ma_il"),         "<control>I",   inc_mail_cb, 0, NULL},
599         {N_("/_Message/Get from _all accounts"),
600                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
601         {N_("/_Message/Cancel receivin_g"),     NULL, inc_cancel_cb, 0, NULL},
602         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
603         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
604         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
605         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
606         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
607         {N_("/_Message/_Reply"),                "<control>R",   reply_cb, COMPOSE_REPLY, NULL},
608         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
609         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
610         {N_("/_Message/Repl_y to/_sender"),     NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
611         {N_("/_Message/Repl_y to/mailing _list"),
612                                                 "<control>L", reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
613         {N_("/_Message/Follow-up and reply to"),NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
614         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
615         {N_("/_Message/_Forward"),              "<control><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
616         {N_("/_Message/Redirect"),              NULL, reply_cb, COMPOSE_REDIRECT, NULL},
617         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
618         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
619         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
620         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
621         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
622         {N_("/_Message/_Delete"),               "<control>D", delete_cb,  0, NULL},
623         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
624         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
625         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
626         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
627         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
628         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
629         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
630         {N_("/_Message/_Mark/Mark as rea_d"),
631                                                 NULL, mark_as_read_cb, 0, NULL},
632         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
633
634         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
635         {N_("/_Tools/_Selective download..."),  "<alt>S", sel_download_cb, 0, NULL},
636         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
637         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
638         {N_("/_Tools/Add sender to address boo_k"),
639                                                 NULL, add_address_cb, 0, NULL},
640         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
641         {N_("/_Tools/_Harvest addresses/from _Folder..."),
642                                                 NULL, addr_harvest_cb, 0, NULL},
643         {N_("/_Tools/_Harvest addresses/from _Messages..."),
644                                                 NULL, addr_harvest_msg_cb, 0, NULL},
645         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
646         {N_("/_Tools/_Filter messages"),                NULL, filter_cb, 0, NULL},
647         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
648         {N_("/_Tools/_Create filter rule/_Automatically"),
649                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
650         {N_("/_Tools/_Create filter rule/by _From"),
651                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
652         {N_("/_Tools/_Create filter rule/by _To"),
653                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
654         {N_("/_Tools/_Create filter rule/by _Subject"),
655                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
656         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
657         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
658         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
659         {N_("/_Tools/Delete du_plicated messages"),
660                                                 NULL, delete_duplicated_cb,   0, NULL},
661         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
662         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
663 #ifdef USE_OPENSSL
664         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
665         {N_("/_Tools/SSL certi_ficates..."),    
666                                                 NULL, ssl_manager_open_cb, 0, NULL},
667 #endif
668         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
669         {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
670
671         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
672         {N_("/_Configuration/_Common preferences..."),
673                                                 NULL, prefs_common_open_cb, 0, NULL},
674         {N_("/_Configuration/_Scoring..."),
675                                                 NULL, prefs_scoring_open_cb, 0, NULL},
676         {N_("/_Configuration/_Filtering..."),
677                                                 NULL, prefs_filtering_open_cb, 0, NULL},
678         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
679         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
680         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
681         {N_("/_Configuration/_Preferences for current account..."),
682                                                 NULL, prefs_account_open_cb, 0, NULL},
683         {N_("/_Configuration/Create _new account..."),
684                                                 NULL, new_account_cb, 0, NULL},
685         {N_("/_Configuration/_Edit accounts..."),
686                                                 NULL, account_edit_open, 0, NULL},
687         {N_("/_Configuration/C_hange current account"),
688                                                 NULL, NULL, 0, "<Branch>"},
689         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
690         {N_("/_Configuration/Preferences..."),  NULL, prefs_open_cb, 0, NULL},
691         {N_("/_Configuration/Plugins..."),      NULL, plugins_open_cb, 0, NULL},
692
693         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
694         {N_("/_Help/_Manual (Local)"),          NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
695         {N_("/_Help/_Manual (Sylpheed Doc Homepage)"),
696                                                 NULL, manual_open_cb, MANUAL_MANUAL_SYLDOC, NULL},
697         {N_("/_Help/_FAQ (Local)"),             NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
698         {N_("/_Help/_FAQ (Sylpheed Doc Homepage)"),
699                                                 NULL, manual_open_cb, MANUAL_FAQ_SYLDOC, NULL},
700         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
701         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
702 };
703
704 MainWindow *main_window_create(SeparateType type)
705 {
706         MainWindow *mainwin;
707         GtkWidget *window;
708         GtkWidget *vbox;
709         GtkWidget *menubar;
710         GtkWidget *handlebox;
711         GtkWidget *vbox_body;
712         GtkWidget *hbox_stat;
713         GtkWidget *statusbar;
714         GtkWidget *progressbar;
715         GtkWidget *statuslabel;
716         GtkWidget *ac_button;
717         GtkWidget *ac_label;
718         GtkWidget *online_pixmap;
719         GtkWidget *offline_pixmap;
720         GtkWidget *online_switch;
721         GtkWidget *offline_switch;
722
723         FolderView *folderview;
724         SummaryView *summaryview;
725         MessageView *messageview;
726         GdkColormap *colormap;
727         GdkColor color[4];
728         gboolean success[4];
729         GtkItemFactory *ifactory;
730         GtkWidget *ac_menu;
731         GtkWidget *menuitem;
732         gint i;
733         guint n_menu_entries;
734
735         static GdkGeometry geometry;
736
737         debug_print("Creating main window...\n");
738         mainwin = g_new0(MainWindow, 1);
739
740         /* main window */
741         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
742         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
743         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
744         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
745
746         if (!geometry.min_height) {
747                 geometry.min_width = 320;
748                 geometry.min_height = 200;
749         }
750         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
751                                       GDK_HINT_MIN_SIZE);
752
753         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
754                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
755         MANAGE_WINDOW_SIGNALS_CONNECT(window);
756         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
757                            GTK_SIGNAL_FUNC(mainwindow_focus_in_event),
758                            mainwin);
759         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
760                                 GTK_SIGNAL_FUNC(mainwindow_key_pressed), mainwin);
761
762         gtk_widget_realize(window);
763         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
764         
765
766         gtkut_widget_set_app_icon(window);
767
768         vbox = gtk_vbox_new(FALSE, 0);
769         gtk_widget_show(vbox);
770         gtk_container_add(GTK_CONTAINER(window), vbox);
771
772         /* menu bar */
773         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
774         menubar = menubar_create(window, mainwin_entries, 
775                                  n_menu_entries, "<Main>", mainwin);
776         gtk_widget_show(menubar);
777         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
778         ifactory = gtk_item_factory_from_widget(menubar);
779
780         menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
781         menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
782
783         handlebox = gtk_handle_box_new();
784         gtk_widget_show(handlebox);
785         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
786
787         /* link window to mainwin->window to avoid gdk warnings */
788         mainwin->window       = window;
789         
790         /* create toolbar */
791         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
792                                           handlebox, 
793                                           (gpointer)mainwin);
794
795         /* vbox that contains body */
796         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
797         gtk_widget_show(vbox_body);
798         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
799         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
800
801         hbox_stat = gtk_hbox_new(FALSE, 2);
802         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
803
804         statusbar = statusbar_create();
805         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
806
807         progressbar = gtk_progress_bar_new();
808         gtk_widget_set_usize(progressbar, 120, 1);
809         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
810
811         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
812         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
813         online_switch = gtk_button_new ();
814         offline_switch = gtk_button_new ();
815         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
816         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
817         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
818         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
819         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
820         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
821         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
822         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
823         
824         statuslabel = gtk_label_new("");
825         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
826
827         ac_button = gtk_button_new();
828         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
829         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
830         gtk_widget_set_usize(ac_button, -1, 1);
831         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
832         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
833                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
834
835         ac_label = gtk_label_new("");
836         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
837
838         gtk_widget_show_all(hbox_stat);
839
840         gtk_widget_hide(offline_switch);
841         /* create views */
842         mainwin->folderview  = folderview  = folderview_create();
843         mainwin->summaryview = summaryview = summary_create();
844         mainwin->messageview = messageview = messageview_create(mainwin);
845         mainwin->logwin      = log_window_create();
846
847         folderview->mainwin      = mainwin;
848         folderview->summaryview  = summaryview;
849
850         summaryview->mainwin     = mainwin;
851         summaryview->folderview  = folderview;
852         summaryview->messageview = messageview;
853         summaryview->window      = window;
854
855         mainwin->vbox         = vbox;
856         mainwin->menubar      = menubar;
857         mainwin->menu_factory = ifactory;
858         mainwin->handlebox    = handlebox;
859         mainwin->vbox_body    = vbox_body;
860         mainwin->hbox_stat    = hbox_stat;
861         mainwin->statusbar    = statusbar;
862         mainwin->progressbar  = progressbar;
863         mainwin->statuslabel  = statuslabel;
864         mainwin->ac_button    = ac_button;
865         mainwin->ac_label     = ac_label;
866         
867         mainwin->online_switch     = online_switch;
868         mainwin->offline_switch    = offline_switch;
869         mainwin->online_pixmap     = online_pixmap;
870         mainwin->offline_pixmap    = offline_pixmap;
871         
872         /* set context IDs for status bar */
873         mainwin->mainwin_cid = gtk_statusbar_get_context_id
874                 (GTK_STATUSBAR(statusbar), "Main Window");
875         mainwin->folderview_cid = gtk_statusbar_get_context_id
876                 (GTK_STATUSBAR(statusbar), "Folder View");
877         mainwin->summaryview_cid = gtk_statusbar_get_context_id
878                 (GTK_STATUSBAR(statusbar), "Summary View");
879
880         /* allocate colors for summary view and folder view */
881         summaryview->color_marked.red = summaryview->color_marked.green = 0;
882         summaryview->color_marked.blue = (guint16)65535;
883
884         summaryview->color_dim.red = summaryview->color_dim.green =
885                 summaryview->color_dim.blue = COLOR_DIM;
886
887         folderview->color_new.red = (guint16)55000;
888         folderview->color_new.green = folderview->color_new.blue = 15000;
889
890         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
891                                        &folderview->color_op);
892
893         summaryview->color_important.red = 0;
894         summaryview->color_important.green = 0;
895         summaryview->color_important.blue = (guint16)65535;
896
897         color[0] = summaryview->color_marked;
898         color[1] = summaryview->color_dim;
899         color[2] = folderview->color_new;
900         color[3] = folderview->color_op;
901
902         colormap = gdk_window_get_colormap(window->window);
903         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
904         for (i = 0; i < 4; i++) {
905                 if (success[i] == FALSE)
906                         g_warning("MainWindow: color allocation %d failed\n", i);
907         }
908
909         debug_print("done.\n");
910
911         messageview->visible = TRUE;
912
913         main_window_set_widgets(mainwin, type);
914
915         /* set menu items */
916         menuitem = gtk_item_factory_get_item
917                 (ifactory, "/View/Code set/Auto detect");
918         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
919
920         switch (prefs_common.toolbar_style) {
921         case TOOLBAR_NONE:
922                 menuitem = gtk_item_factory_get_item
923                         (ifactory, "/View/Show or hide/Toolbar/None");
924                 break;
925         case TOOLBAR_ICON:
926                 menuitem = gtk_item_factory_get_item
927                         (ifactory, "/View/Show or hide/Toolbar/Icon");
928                 break;
929         case TOOLBAR_TEXT:
930                 menuitem = gtk_item_factory_get_item
931                         (ifactory, "/View/Show or hide/Toolbar/Text");
932                 break;
933         case TOOLBAR_BOTH:
934                 menuitem = gtk_item_factory_get_item
935                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
936         }
937         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
938
939         gtk_widget_hide(mainwin->hbox_stat);
940         menuitem = gtk_item_factory_get_item
941                 (ifactory, "/View/Show or hide/Status bar");
942         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
943                                        prefs_common.show_statusbar);
944         
945         gtk_widget_hide(GTK_WIDGET(mainwin->summaryview->hbox_search));
946         
947         if (prefs_common.show_searchbar)
948                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainwin->summaryview->toggle_search), TRUE);
949
950
951         /* set account selection menu */
952         ac_menu = gtk_item_factory_get_widget
953                 (ifactory, "/Configuration/Change current account");
954         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
955                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
956         mainwin->ac_menu = ac_menu;
957
958         toolbar_main_set_sensitive(mainwin);
959
960         /* create actions menu */
961         update_mainwin_actions_menu(ifactory, mainwin);
962
963         /* attach accel groups to main window */
964 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)        \
965         gtk_window_add_accel_group                      \
966                 (GTK_WINDOW(win),                       \
967                  gtk_item_factory_from_widget(menu)->accel_group)                
968         
969         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu,mainwin->window);
970         
971         /* connect the accelerators for equivalent 
972            menu items in different menus             */
973         menu_connect_identical_items();
974
975
976         
977         /* show main window */
978         gtk_widget_set_uposition(mainwin->window,
979                                  prefs_common.mainwin_x,
980                                  prefs_common.mainwin_y);
981         gtk_widget_set_usize(window, prefs_common.mainwin_width,
982                              prefs_common.mainwin_height);
983         gtk_widget_show(mainwin->window);
984
985         /* initialize views */
986         folderview_init(folderview);
987         summary_init(summaryview);
988         messageview_init(messageview);
989         log_window_init(mainwin->logwin);
990 #ifdef USE_OPENSSL
991         sslcertwindow_register_hook();
992 #endif
993         mainwin->lock_count = 0;
994         mainwin->menu_lock_count = 0;
995         mainwin->cursor_count = 0;
996
997         if (!watch_cursor)
998                 watch_cursor = gdk_cursor_new(GDK_WATCH);
999
1000         mainwin_list = g_list_append(mainwin_list, mainwin);
1001
1002         /* init work_offline */
1003         if (prefs_common.work_offline)
1004                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1005
1006         return mainwin;
1007 }
1008
1009 void main_window_cursor_wait(MainWindow *mainwin)
1010 {
1011
1012         if (mainwin->cursor_count == 0)
1013                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1014
1015         mainwin->cursor_count++;
1016
1017         gdk_flush();
1018 }
1019
1020 void main_window_cursor_normal(MainWindow *mainwin)
1021 {
1022         if (mainwin->cursor_count)
1023                 mainwin->cursor_count--;
1024
1025         if (mainwin->cursor_count == 0)
1026                 gdk_window_set_cursor(mainwin->window->window, NULL);
1027
1028         gdk_flush();
1029 }
1030
1031 /* lock / unlock the user-interface */
1032 void main_window_lock(MainWindow *mainwin)
1033 {
1034         if (mainwin->lock_count == 0)
1035                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1036
1037         mainwin->lock_count++;
1038
1039         main_window_set_menu_sensitive(mainwin);
1040         toolbar_main_set_sensitive(mainwin);
1041 }
1042
1043 void main_window_unlock(MainWindow *mainwin)
1044 {
1045         if (mainwin->lock_count)
1046                 mainwin->lock_count--;
1047
1048         main_window_set_menu_sensitive(mainwin);
1049         toolbar_main_set_sensitive(mainwin);
1050
1051         if (mainwin->lock_count == 0)
1052                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1053 }
1054
1055 static void main_window_menu_callback_block(MainWindow *mainwin)
1056 {
1057         mainwin->menu_lock_count++;
1058 }
1059
1060 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1061 {
1062         if (mainwin->menu_lock_count)
1063                 mainwin->menu_lock_count--;
1064 }
1065
1066 void main_window_reflect_prefs_all(void)
1067 {
1068         main_window_reflect_prefs_all_real(FALSE);
1069 }
1070
1071 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1072 {
1073         GList *cur;
1074         MainWindow *mainwin;
1075         GtkWidget *pixmap;
1076
1077         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1078                 mainwin = (MainWindow *)cur->data;
1079
1080                 main_window_show_cur_account(mainwin);
1081                 main_window_set_menu_sensitive(mainwin);
1082                 toolbar_main_set_sensitive(mainwin);
1083
1084                 /* pixmap themes */
1085                 if (pixmap_theme_changed) {
1086                         toolbar_update(TOOLBAR_MAIN, mainwin);
1087                         messageview_reflect_prefs_pixmap_theme();
1088                         compose_reflect_prefs_pixmap_theme();
1089                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1090                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1091
1092                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
1093                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1094                                              mainwin->online_pixmap);
1095                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1096                         gtk_widget_show(pixmap);
1097                         mainwin->online_pixmap = pixmap;
1098                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
1099                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1100                                              mainwin->offline_pixmap);
1101                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1102                         gtk_widget_show(pixmap);
1103                         mainwin->offline_pixmap = pixmap;
1104                 }
1105                 
1106                 summary_redisplay_msg(mainwin->summaryview);
1107                 headerview_set_visibility(mainwin->messageview->headerview,
1108                                           prefs_common.display_header_pane);
1109         }
1110 }
1111
1112 void main_window_set_summary_column(void)
1113 {
1114         GList *cur;
1115         MainWindow *mainwin;
1116
1117         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1118                 mainwin = (MainWindow *)cur->data;
1119                 summary_set_column_order(mainwin->summaryview);
1120         }
1121 }
1122
1123 void main_window_set_account_menu(GList *account_list)
1124 {
1125         GList *cur, *cur_ac, *cur_item;
1126         GtkWidget *menuitem;
1127         MainWindow *mainwin;
1128         PrefsAccount *ac_prefs;
1129
1130         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1131                 mainwin = (MainWindow *)cur->data;
1132
1133                 /* destroy all previous menu item */
1134                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1135                 while (cur_item != NULL) {
1136                         GList *next = cur_item->next;
1137                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1138                         cur_item = next;
1139                 }
1140
1141                 for (cur_ac = account_list; cur_ac != NULL;
1142                      cur_ac = cur_ac->next) {
1143                         ac_prefs = (PrefsAccount *)cur_ac->data;
1144
1145                         menuitem = gtk_menu_item_new_with_label
1146                                 (ac_prefs->account_name
1147                                  ? ac_prefs->account_name : _("Untitled"));
1148                         gtk_widget_show(menuitem);
1149                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1150                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1151                                            GTK_SIGNAL_FUNC(account_menu_cb),
1152                                            ac_prefs);
1153                 }
1154         }
1155 }
1156
1157 static void main_window_show_cur_account(MainWindow *mainwin)
1158 {
1159         gchar *buf;
1160         gchar *ac_name;
1161
1162         ac_name = g_strdup(cur_account
1163                            ? (cur_account->account_name
1164                               ? cur_account->account_name : _("Untitled"))
1165                            : _("none"));
1166
1167         if (cur_account)
1168                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1169         else
1170                 buf = g_strdup(PROG_VERSION);
1171         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1172         g_free(buf);
1173
1174         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1175         gtk_widget_queue_resize(mainwin->ac_button);
1176
1177         g_free(ac_name);
1178 }
1179
1180 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1181 {
1182         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1183         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1184         //GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1185         GtkWidget *message_wid = mainwin->messageview->vbox;
1186
1187         debug_print("Changing window separation type from %d to %d\n",
1188                     mainwin->type, type);
1189
1190         if (mainwin->type == type) return;
1191
1192         /* remove widgets from those containers */
1193         gtk_widget_ref(folder_wid);
1194         gtk_widget_ref(summary_wid);
1195         gtk_widget_ref(message_wid);
1196         gtkut_container_remove
1197                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1198         gtkut_container_remove
1199                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1200         gtkut_container_remove
1201                 (GTK_CONTAINER(message_wid->parent), message_wid);
1202
1203         /* clean containers */
1204         switch (mainwin->type) {
1205         case SEPARATE_NONE:
1206                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1207                 break;
1208         case SEPARATE_FOLDER:
1209                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1210                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1211                 break;
1212         case SEPARATE_MESSAGE:
1213                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1214                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1215                 break;
1216         case SEPARATE_BOTH:
1217                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1218                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1219                 break;
1220         }
1221
1222         gtk_widget_hide(mainwin->window);
1223         main_window_set_widgets(mainwin, type);
1224         gtk_widget_show(mainwin->window);
1225
1226         gtk_widget_unref(folder_wid);
1227         gtk_widget_unref(summary_wid);
1228         gtk_widget_unref(message_wid);
1229 }
1230
1231 void main_window_toggle_message_view(MainWindow *mainwin)
1232 {
1233         SummaryView *summaryview = mainwin->summaryview;
1234         union CompositeWin *cwin = &mainwin->win;
1235         GtkWidget *vpaned = NULL;
1236         GtkWidget *container = NULL;
1237         GtkWidget *msgwin = NULL;
1238
1239         switch (mainwin->type) {
1240         case SEPARATE_NONE:
1241                 vpaned = cwin->sep_none.vpaned;
1242                 container = cwin->sep_none.hpaned;
1243                 break;
1244         case SEPARATE_FOLDER:
1245                 vpaned = cwin->sep_folder.vpaned;
1246                 container = mainwin->vbox_body;
1247                 break;
1248         case SEPARATE_MESSAGE:
1249                 msgwin = mainwin->win.sep_message.messagewin;
1250                 break;
1251         case SEPARATE_BOTH:
1252                 msgwin = mainwin->win.sep_both.messagewin;
1253                 break;
1254         }
1255
1256         if (msgwin) {
1257                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1258                         gtk_widget_hide(msgwin);
1259                         mainwin->messageview->visible = FALSE;
1260                         summaryview->displayed = NULL;
1261                 } else {
1262                         gtk_widget_show(msgwin);
1263                         mainwin->messageview->visible = TRUE;
1264                 }
1265         } else if (vpaned->parent != NULL) {
1266                 mainwin->messageview->visible = FALSE;
1267                 summaryview->displayed = NULL;
1268                 gtk_widget_ref(vpaned);
1269                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1270                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1271                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1272                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1273         } else {
1274                 mainwin->messageview->visible = TRUE;
1275                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1276                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1277                 gtk_widget_unref(vpaned);
1278                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1279                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1280         }
1281
1282         main_window_set_menu_sensitive(mainwin);
1283
1284         gtk_widget_grab_focus(summaryview->ctree);
1285 }
1286
1287 void main_window_get_size(MainWindow *mainwin)
1288 {
1289         GtkAllocation *allocation;
1290
1291         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1292
1293         prefs_common.summaryview_width  = allocation->width;
1294
1295         if ((mainwin->type == SEPARATE_NONE ||
1296              mainwin->type == SEPARATE_FOLDER) &&
1297             messageview_is_visible(mainwin->messageview))
1298                 prefs_common.summaryview_height = allocation->height;
1299
1300         prefs_common.mainview_width     = allocation->width;
1301
1302         allocation = &mainwin->window->allocation;
1303
1304         prefs_common.mainview_height = allocation->height;
1305         prefs_common.mainwin_width   = allocation->width;
1306         prefs_common.mainwin_height  = allocation->height;
1307
1308         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1309
1310         prefs_common.folderview_width  = allocation->width;
1311         prefs_common.folderview_height = allocation->height;
1312 }
1313
1314 void main_window_get_position(MainWindow *mainwin)
1315 {
1316         gint x, y;
1317
1318         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1319
1320         prefs_common.mainview_x = x;
1321         prefs_common.mainview_y = y;
1322         prefs_common.mainwin_x = x;
1323         prefs_common.mainwin_y = y;
1324
1325         debug_print("window position: x = %d, y = %d\n", x, y);
1326 }
1327
1328 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1329 {
1330         GList *list;
1331         guint has_trash;
1332         Folder *folder;
1333
1334         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1335                 folder = FOLDER(list->data);
1336                 if (folder && folder->trash && folder->trash->total > 0)
1337                         has_trash++;
1338         }
1339
1340         if (!has_trash) return;
1341         
1342         if (confirm) {
1343                 if (alertpanel(_("Empty trash"),
1344                                _("Empty all messages in trash?"),
1345                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1346                         return;
1347                 manage_window_focus_in(mainwin->window, NULL, NULL);
1348         }
1349
1350         procmsg_empty_trash();
1351
1352         if (mainwin->summaryview->folder_item &&
1353             mainwin->summaryview->folder_item->stype == F_TRASH)
1354                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1355 }
1356
1357 void main_window_add_mailbox(MainWindow *mainwin)
1358 {
1359         gchar *path;
1360         Folder *folder;
1361
1362         path = input_dialog(_("Add mailbox"),
1363                             _("Input the location of mailbox.\n"
1364                               "If the existing mailbox is specified, it will be\n"
1365                               "scanned automatically."),
1366                             "Mail");
1367         if (!path) return;
1368         if (folder_find_from_path(path)) {
1369                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1370                 g_free(path);
1371                 return;
1372         }
1373         if (!strcmp(path, "Mail"))
1374                 folder = folder_new(F_MH, _("Mailbox"), path);
1375         else
1376                 folder = folder_new(F_MH, g_basename(path), path);
1377         g_free(path);
1378
1379         if (folder->create_tree(folder) < 0) {
1380                 alertpanel_error(_("Creation of the mailbox failed.\n"
1381                                    "Maybe some files already exist, or you don't have the permission to write there."));
1382                 folder_destroy(folder);
1383                 return;
1384         }
1385
1386         folder_add(folder);
1387         folder_set_ui_func(folder, scan_tree_func, mainwin);
1388         folder_scan_tree(folder);
1389         folder_set_ui_func(folder, NULL, NULL);
1390
1391         folderview_set(mainwin->folderview);
1392 }
1393
1394 void main_window_add_mbox(MainWindow *mainwin)
1395 {
1396         gchar *path;
1397         Folder *folder;
1398         FolderItem * item;
1399
1400         path = input_dialog(_("Add mbox mailbox"),
1401                             _("Input the location of mailbox."),
1402                             "mail");
1403
1404         if (!path) return;
1405
1406         if (folder_find_from_path(path)) {
1407                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1408                 g_free(path);
1409                 return;
1410         }
1411
1412         /*
1413         if (!strcmp(path, "Mail"))
1414                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1415                 else
1416         */
1417
1418         folder = folder_new(F_MBOX, g_basename(path), path);
1419         g_free(path);
1420
1421         if (folder->create_tree(folder) < 0) {
1422                 alertpanel_error(_("Creation of the mailbox failed."));
1423                 folder_destroy(folder);
1424                 return;
1425         }
1426
1427         folder_add(folder);
1428
1429         item = folder_item_new(folder, folder->name, NULL);
1430         item->folder = folder;
1431         folder->node = g_node_new(item);
1432
1433         folder_create_folder(item, "inbox");
1434         folder_create_folder(item, "outbox");
1435         folder_create_folder(item, "queue");
1436         folder_create_folder(item, "draft");
1437         folder_create_folder(item, "trash");
1438
1439         folderview_set(mainwin->folderview);
1440 }
1441
1442 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1443 {
1444         SensitiveCond state = 0;
1445         SummarySelection selection;
1446         FolderItem *item = mainwin->summaryview->folder_item;
1447         GList *account_list = account_get_list();
1448         
1449         selection = summary_get_selection_type(mainwin->summaryview);
1450
1451         if (mainwin->lock_count == 0)
1452                 state |= M_UNLOCKED;
1453         if (selection != SUMMARY_NONE)
1454                 state |= M_MSG_EXIST;
1455         if (item && item->path && item->parent && !item->no_select) {
1456                 state |= M_EXEC;
1457                 /*              if (item->folder->type != F_NEWS) */
1458                 state |= M_ALLOW_DELETE;
1459
1460                 if (prefs_common.immediate_exec == 0
1461                     && mainwin->lock_count == 0)
1462                         state |= M_DELAY_EXEC;
1463
1464                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1465                     || selection != SUMMARY_NONE)
1466                         state |= M_HIDE_READ_MSG;       
1467         }               
1468         if (mainwin->summaryview->threaded)
1469                 state |= M_THREADED;
1470         else
1471                 state |= M_UNTHREADED;  
1472         if (selection == SUMMARY_SELECTED_SINGLE ||
1473             selection == SUMMARY_SELECTED_MULTIPLE)
1474                 state |= M_TARGET_EXIST;
1475         if (selection == SUMMARY_SELECTED_SINGLE)
1476                 state |= M_SINGLE_TARGET_EXIST;
1477         if (mainwin->summaryview->folder_item &&
1478             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1479                 state |= M_NEWS;
1480         else
1481                 state |= M_NOT_NEWS;
1482         if (selection == SUMMARY_SELECTED_SINGLE &&
1483             (item &&
1484              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1485               item->stype == F_QUEUE)))
1486                 state |= M_ALLOW_REEDIT;
1487         if (cur_account)
1488                 state |= M_HAVE_ACCOUNT;
1489         
1490         for ( ; account_list != NULL; account_list = account_list->next) {
1491                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1492                         state |= M_HAVE_NEWS_ACCOUNT;
1493                         break;
1494                 }
1495         }
1496
1497         if (inc_is_active())
1498                 state |= M_INC_ACTIVE;
1499
1500         return state;
1501 }
1502
1503
1504
1505 void main_window_set_menu_sensitive(MainWindow *mainwin)
1506 {
1507         GtkItemFactory *ifactory = mainwin->menu_factory;
1508         SensitiveCond state;
1509         gboolean sensitive;
1510         GtkWidget *menuitem;
1511         SummaryView *summaryview;
1512         gchar *menu_path;
1513         gint i;
1514
1515         static const struct {
1516                 gchar *const entry;
1517                 SensitiveCond cond;
1518         } entry[] = {
1519                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1520                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1521                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1522                 {"/File/Folder"                               , M_UNLOCKED},
1523                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1524                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1525                 {"/File/Empty trash"                          , M_UNLOCKED},
1526                 {"/File/Work offline"                         , M_UNLOCKED},
1527
1528                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1529                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1530                 /* {"/File/Close"  , M_UNLOCKED}, */
1531                 {"/File/Exit"      , M_UNLOCKED},
1532
1533                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1534
1535                 {"/View/Sort"                      , M_EXEC},
1536                 {"/View/Thread view"               , M_EXEC},
1537                 {"/View/Expand all threads"        , M_MSG_EXIST},
1538                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1539                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1540                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1541                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1542                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1543                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1544                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1545                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1546                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1547                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1548                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1549                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1550                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1551                 {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
1552                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1553
1554                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1555                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1556                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1557                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1558                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1559                 {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1560                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1561                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1562                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1563                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1564                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1565                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1566                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
1567                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
1568                 {"/Message/Mark"                  , M_TARGET_EXIST},
1569
1570                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1571                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1572                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1573                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1574                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1575                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1576                 {"/Tools/Execute"                   , M_DELAY_EXEC},
1577                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1578
1579                 {"/Configuration", M_UNLOCKED},
1580
1581                 {NULL, 0}
1582         };
1583
1584         state = main_window_get_current_state(mainwin);
1585
1586         for (i = 0; entry[i].entry != NULL; i++) {
1587                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1588                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1589         }
1590
1591         main_window_menu_callback_block(mainwin);
1592
1593 #define SET_CHECK_MENU_ACTIVE(path, active) \
1594 { \
1595         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1596         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1597 }
1598
1599         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1600                               messageview_is_visible(mainwin->messageview));
1601
1602         summaryview = mainwin->summaryview;
1603         menu_path = "/View/Sort/Don't sort";
1604
1605         switch (summaryview->sort_key) {
1606         case SORT_BY_NUMBER:
1607                 menu_path = "/View/Sort/by number"; break;
1608         case SORT_BY_SIZE:
1609                 menu_path = "/View/Sort/by size"; break;
1610         case SORT_BY_DATE:
1611                 menu_path = "/View/Sort/by date"; break;
1612         case SORT_BY_FROM:
1613                 menu_path = "/View/Sort/by from"; break;
1614         case SORT_BY_TO:
1615                 menu_path = "/View/Sort/by recipient"; break;
1616         case SORT_BY_SUBJECT:
1617                 menu_path = "/View/Sort/by subject"; break;
1618         case SORT_BY_LABEL:
1619                 menu_path = "/View/Sort/by color label"; break;
1620         case SORT_BY_MARK:
1621                 menu_path = "/View/Sort/by mark"; break;
1622         case SORT_BY_UNREAD:
1623                 menu_path = "/View/Sort/by unread"; break;
1624         case SORT_BY_MIME:
1625                 menu_path = "/View/Sort/by attachment"; break;
1626         case SORT_BY_SCORE:
1627                 menu_path = "/View/Sort/by score"; break;
1628         case SORT_BY_LOCKED:
1629                 menu_path = "/View/Sort/by locked"; break;
1630         case SORT_BY_NONE:
1631         default:
1632                 menu_path = "/View/Sort/Don't sort"; break;
1633         }
1634         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1635
1636         if (summaryview->sort_type == SORT_ASCENDING) {
1637                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1638         } else {
1639                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1640         }
1641
1642         if (summaryview->sort_key != SORT_BY_NONE) {
1643                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1644                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1645         } else {
1646                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1647                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1648         }
1649
1650         SET_CHECK_MENU_ACTIVE("/View/Show all headers",
1651                               mainwin->messageview->textview->show_all_headers);
1652         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1653
1654 #undef SET_CHECK_MENU_ACTIVE
1655
1656         main_window_menu_callback_unblock(mainwin);
1657 }
1658
1659 void main_window_popup(MainWindow *mainwin)
1660 {
1661         gtkut_window_popup(mainwin->window);
1662
1663         switch (mainwin->type) {
1664         case SEPARATE_FOLDER:
1665                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
1666                 break;
1667         case SEPARATE_MESSAGE:
1668                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
1669                 break;
1670         case SEPARATE_BOTH:
1671                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
1672                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
1673                 break;
1674         default:
1675                 break;
1676         }
1677 }
1678
1679 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1680 {
1681         GtkWidget *folderwin = NULL;
1682         GtkWidget *messagewin = NULL;
1683         GtkWidget *hpaned;
1684         GtkWidget *vpaned;
1685         GtkWidget *vbox_body = mainwin->vbox_body;
1686         GtkItemFactory *ifactory = mainwin->menu_factory;
1687         GtkWidget *menuitem;
1688         GtkItemFactory *msgview_ifactory;
1689
1690         debug_print("Setting widgets...");
1691
1692         /* create separated window(s) if needed */
1693         if (type & SEPARATE_FOLDER) {
1694                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1695                 gtk_window_set_title(GTK_WINDOW(folderwin),
1696                                      _("Sylpheed - Folder View"));
1697                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1698                                        "folder_view", "Sylpheed");
1699                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1700                                       TRUE, TRUE, FALSE);
1701                 gtk_widget_set_usize(folderwin, -1,
1702                                      prefs_common.mainview_height);
1703                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1704                                                BORDER_WIDTH);
1705                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1706                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1707                                    mainwin);
1708         }
1709         if (type & SEPARATE_MESSAGE) {
1710                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1711                 gtk_window_set_title(GTK_WINDOW(messagewin),
1712                                      _("Sylpheed - Message View"));
1713                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1714                                        "message_view", "Sylpheed");
1715                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1716                                       TRUE, TRUE, FALSE);
1717                 gtk_widget_set_usize
1718                         (messagewin, prefs_common.mainview_width,
1719                          prefs_common.mainview_height
1720                          - prefs_common.summaryview_height
1721                          + DEFAULT_HEADERVIEW_HEIGHT);
1722                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1723                                                BORDER_WIDTH);
1724                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1725                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1726                                    mainwin);
1727         }
1728
1729         switch (type) {
1730         case SEPARATE_NONE:
1731                 hpaned = gtk_hpaned_new();
1732                 gtk_widget_show(hpaned);
1733                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1734                 gtk_paned_add1(GTK_PANED(hpaned),
1735                                GTK_WIDGET_PTR(mainwin->folderview));
1736
1737                 vpaned = gtk_vpaned_new();
1738                 if (messageview_is_visible(mainwin->messageview)) {
1739                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1740                         gtk_paned_add1(GTK_PANED(vpaned),
1741                                        GTK_WIDGET_PTR(mainwin->summaryview));
1742                 } else {
1743                         gtk_paned_add2(GTK_PANED(hpaned),
1744                                        GTK_WIDGET_PTR(mainwin->summaryview));
1745                         gtk_widget_ref(vpaned);
1746                 }
1747                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1748                                      prefs_common.summaryview_width,
1749                                      prefs_common.summaryview_height);
1750                 gtk_paned_add2(GTK_PANED(vpaned),
1751                                GTK_WIDGET_PTR(mainwin->messageview));
1752                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1753                                      prefs_common.mainview_width, -1);
1754                 gtk_widget_set_usize(mainwin->window,
1755                                      prefs_common.folderview_width +
1756                                      prefs_common.mainview_width,
1757                                      prefs_common.mainwin_height);
1758                 gtk_widget_show_all(vpaned);
1759
1760                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1761                  * lose track of its visibility state */
1762                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1763                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1764
1765                 mainwin->win.sep_none.hpaned = hpaned;
1766                 mainwin->win.sep_none.vpaned = vpaned;
1767                 
1768                 /* remove headerview if not in prefs */
1769                 headerview_set_visibility(mainwin->messageview->headerview,
1770                                           prefs_common.display_header_pane);
1771                 break;
1772         case SEPARATE_FOLDER:
1773                 vpaned = gtk_vpaned_new();
1774                 if (messageview_is_visible(mainwin->messageview)) {
1775                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1776                                            TRUE, TRUE, 0);
1777                         gtk_paned_add1(GTK_PANED(vpaned),
1778                                        GTK_WIDGET_PTR(mainwin->summaryview));
1779                 } else {
1780                         gtk_box_pack_start(GTK_BOX(vbox_body),
1781                                            GTK_WIDGET_PTR(mainwin->summaryview),
1782                                            TRUE, TRUE, 0);
1783                         gtk_widget_ref(vpaned);
1784                 }
1785                 gtk_paned_add2(GTK_PANED(vpaned),
1786                                GTK_WIDGET_PTR(mainwin->messageview));
1787                 gtk_widget_show_all(vpaned);
1788                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1789                                      prefs_common.summaryview_width,
1790                                      prefs_common.summaryview_height);
1791                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1792                                      prefs_common.mainview_width, -1);
1793                 gtk_widget_set_usize(mainwin->window,
1794                                      prefs_common.mainview_width,
1795                                      prefs_common.mainview_height);
1796
1797                 gtk_container_add(GTK_CONTAINER(folderwin),
1798                                   GTK_WIDGET_PTR(mainwin->folderview));
1799
1800                 mainwin->win.sep_folder.folderwin = folderwin;
1801                 mainwin->win.sep_folder.vpaned    = vpaned;
1802
1803                 gtk_widget_show_all(folderwin);
1804                 
1805                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1806                  * lose track of its visibility state */
1807                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1808                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1809                 
1810                 /* remove headerview if not in prefs */
1811                 headerview_set_visibility(mainwin->messageview->headerview,
1812                                           prefs_common.display_header_pane);
1813                 
1814                 break;
1815         case SEPARATE_MESSAGE:
1816                 hpaned = gtk_hpaned_new();
1817                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1818
1819                 gtk_paned_add1(GTK_PANED(hpaned),
1820                                GTK_WIDGET_PTR(mainwin->folderview));
1821                 gtk_paned_add2(GTK_PANED(hpaned),
1822                                GTK_WIDGET_PTR(mainwin->summaryview));
1823                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1824                                      prefs_common.summaryview_width,
1825                                      prefs_common.summaryview_height);
1826                 gtk_widget_set_usize(mainwin->window,
1827                                      prefs_common.folderview_width +
1828                                      prefs_common.mainview_width,
1829                                      prefs_common.mainwin_height);
1830                 gtk_widget_show_all(hpaned);
1831
1832                 messageview_add_toolbar(mainwin->messageview, messagewin);
1833                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
1834                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
1835
1836                 mainwin->win.sep_message.messagewin = messagewin;
1837                 mainwin->win.sep_message.hpaned     = hpaned;
1838
1839                 gtk_widget_show_all(messagewin);
1840                 
1841                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1842                  * lose track of its visibility state */
1843                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1844                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1845                 break;
1846         case SEPARATE_BOTH:
1847                 gtk_box_pack_start(GTK_BOX(vbox_body),
1848                                    GTK_WIDGET_PTR(mainwin->summaryview),
1849                                    TRUE, TRUE, 0);
1850                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1851                                      prefs_common.summaryview_width,
1852                                      prefs_common.summaryview_height);
1853                 gtk_widget_set_usize(mainwin->window,
1854                                      prefs_common.mainview_width,
1855                                      prefs_common.mainwin_height);
1856                 gtk_container_add(GTK_CONTAINER(folderwin),
1857                                   GTK_WIDGET_PTR(mainwin->folderview));
1858                 gtk_container_add(GTK_CONTAINER(messagewin),
1859                                   GTK_WIDGET_PTR(mainwin->messageview));
1860
1861                 mainwin->win.sep_both.folderwin = folderwin;
1862                 mainwin->win.sep_both.messagewin = messagewin;
1863
1864                 gtk_widget_show_all(folderwin);
1865                 gtk_widget_show_all(messagewin);
1866
1867                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1868                  * lose track of its visibility state */
1869                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1870                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1871                 break;
1872         }
1873
1874         /* rehide quick search if necessary */
1875         if (!prefs_common.show_searchbar)
1876                 gtk_widget_hide(mainwin->summaryview->hbox_search);
1877         
1878         mainwin->type = type;
1879
1880         mainwin->messageview->visible = TRUE;
1881
1882         /* toggle menu state */
1883         menuitem = gtk_item_factory_get_item
1884                 (ifactory, "/View/Show or hide/Folder tree");
1885         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1886         menuitem = gtk_item_factory_get_item
1887                 (ifactory, "/View/Show or hide/Message view");
1888         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1889
1890         menuitem = gtk_item_factory_get_item
1891                 (ifactory, "/View/Separate folder tree");
1892         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1893                                        ((type & SEPARATE_FOLDER) != 0));
1894         menuitem = gtk_item_factory_get_item
1895                 (ifactory, "/View/Separate message view");
1896         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1897                                        ((type & SEPARATE_MESSAGE) != 0));
1898
1899         debug_print("done.\n");
1900 }
1901
1902 void main_window_destroy_all(void)
1903 {
1904         while (mainwin_list != NULL) {
1905                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
1906                 
1907                 /* free toolbar stuff */
1908                 toolbar_clear_list(TOOLBAR_MAIN);
1909                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
1910                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
1911
1912                 g_free(mainwin->toolbar);
1913                 g_free(mainwin);
1914                 
1915                 mainwin_list = g_list_remove(mainwin_list, mainwin);
1916         }
1917         g_list_free(mainwin_list);
1918 }
1919
1920 #if 0
1921 static void toolbar_account_button_pressed(GtkWidget *widget,
1922                                            GdkEventButton *event,
1923                                            gpointer data)
1924 {
1925         MainWindow *mainwin = (MainWindow *)data;
1926
1927         if (!event) return;
1928         if (event->button != 3) return;
1929
1930         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1931         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1932                             widget);
1933
1934         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1935                        menu_button_position, widget,
1936                        event->button, event->time);
1937 }
1938 #endif
1939
1940 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1941                                     gpointer data)
1942 {
1943         MainWindow *mainwin = (MainWindow *)data;
1944
1945         if (!event) return;
1946
1947         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1948         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1949                             widget);
1950
1951         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1952                        menu_button_position, widget,
1953                        event->button, event->time);
1954 }
1955
1956 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1957 {
1958         MainWindow *mainwin = (MainWindow *)data;
1959         GtkWidget *button;
1960
1961         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1962         if (!button) return;
1963         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1964         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1965         manage_window_focus_in(mainwin->window, NULL, NULL);
1966 }
1967
1968 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1969                                  gpointer data)
1970 {
1971         MainWindow *mainwin = (MainWindow *)data;
1972
1973         if (mainwin->lock_count == 0)
1974                 app_exit_cb(data, 0, widget);
1975
1976         return TRUE;
1977 }
1978
1979 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1980                                    gpointer data)
1981 {
1982         MainWindow *mainwin = (MainWindow *)data;
1983         GtkWidget *menuitem;
1984
1985         menuitem = gtk_item_factory_get_item
1986                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1987         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1988
1989         return TRUE;
1990 }
1991
1992 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1993                                     gpointer data)
1994 {
1995         MainWindow *mainwin = (MainWindow *)data;
1996         GtkWidget *menuitem;
1997
1998         menuitem = gtk_item_factory_get_item
1999                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2000         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2001
2002         return TRUE;
2003 }
2004
2005 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2006                            GtkWidget *widget)
2007 {
2008         main_window_add_mailbox(mainwin);
2009 }
2010
2011 static void add_mbox_cb(MainWindow *mainwin, guint action,
2012                         GtkWidget *widget)
2013 {
2014         main_window_add_mbox(mainwin);
2015 }
2016
2017 static void update_folderview_cb(MainWindow *mainwin, guint action,
2018                                  GtkWidget *widget)
2019 {
2020         summary_show(mainwin->summaryview, NULL);
2021         folderview_check_new_all();
2022 }
2023
2024 static void new_folder_cb(MainWindow *mainwin, guint action,
2025                           GtkWidget *widget)
2026 {
2027         folderview_new_folder(mainwin->folderview);
2028 }
2029
2030 static void rename_folder_cb(MainWindow *mainwin, guint action,
2031                              GtkWidget *widget)
2032 {
2033         folderview_rename_folder(mainwin->folderview);
2034 }
2035
2036 static void delete_folder_cb(MainWindow *mainwin, guint action,
2037                              GtkWidget *widget)
2038 {
2039         folderview_delete_folder(mainwin->folderview);
2040 }
2041
2042 static void import_mbox_cb(MainWindow *mainwin, guint action,
2043                            GtkWidget *widget)
2044 {
2045         import_mbox(mainwin->summaryview->folder_item);
2046 }
2047
2048 static void export_mbox_cb(MainWindow *mainwin, guint action,
2049                            GtkWidget *widget)
2050 {
2051         export_mbox(mainwin->summaryview->folder_item);
2052 }
2053
2054 static void empty_trash_cb(MainWindow *mainwin, guint action,
2055                            GtkWidget *widget)
2056 {
2057         main_window_empty_trash(mainwin, TRUE);
2058 }
2059
2060 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2061 {
2062         summary_save_as(mainwin->summaryview);
2063 }
2064
2065 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2066 {
2067         summary_print(mainwin->summaryview);
2068 }
2069
2070 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2071 {
2072         if (prefs_common.confirm_on_exit) {
2073                 if (alertpanel(_("Exit"), _("Exit this program?"),
2074                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2075                         return;
2076                 manage_window_focus_in(mainwin->window, NULL, NULL);
2077         }
2078
2079         app_will_exit(widget, mainwin);
2080 }
2081
2082 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2083 {
2084         if (action == 1)
2085                 summary_search(mainwin->summaryview);
2086         else
2087                 message_search(mainwin->messageview);
2088 }
2089
2090 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2091                              GtkWidget *widget)
2092 {
2093         gboolean active;
2094
2095         active = GTK_CHECK_MENU_ITEM(widget)->active;
2096
2097         switch (mainwin->type) {
2098         case SEPARATE_NONE:
2099         case SEPARATE_MESSAGE:
2100 #if 0
2101                 if (active)
2102                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2103                 else
2104                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2105 #endif
2106                 break;
2107         case SEPARATE_FOLDER:
2108                 debug_print("separate folder\n");
2109                 if (active)
2110                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2111                 else
2112                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2113                 break;
2114         case SEPARATE_BOTH:
2115                 if (active)
2116                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2117                 else
2118                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2119                 break;
2120         }
2121 }
2122
2123 static void toggle_message_cb(MainWindow *mainwin, guint action,
2124                               GtkWidget *widget)
2125 {
2126         gboolean active;
2127
2128         active = GTK_CHECK_MENU_ITEM(widget)->active;
2129
2130         if (active != messageview_is_visible(mainwin->messageview))
2131                 summary_toggle_view(mainwin->summaryview);
2132 }
2133
2134 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2135                               GtkWidget *widget)
2136 {
2137         toolbar_toggle(action, mainwin);
2138 }
2139
2140 /* END Toolbar Stuff */
2141
2142 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2143                                 GtkWidget *widget)
2144 {
2145         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2146                 gtk_widget_show(mainwin->hbox_stat);
2147                 prefs_common.show_statusbar = TRUE;
2148         } else {
2149                 gtk_widget_hide(mainwin->hbox_stat);
2150                 prefs_common.show_statusbar = FALSE;
2151         }
2152 }
2153
2154 static void separate_widget_cb(MainWindow *mainwin, guint action,
2155                                GtkWidget *widget)
2156 {
2157         SeparateType type;
2158
2159         if (GTK_CHECK_MENU_ITEM(widget)->active)
2160                 type = mainwin->type | action;
2161         else
2162                 type = mainwin->type & ~action;
2163
2164         main_window_separation_change(mainwin, type);
2165
2166         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2167         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2168 }
2169
2170 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline)
2171 {
2172         if (offline)
2173                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2174         else
2175                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
2176 }
2177
2178 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
2179 {
2180         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active);
2181 }
2182
2183 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2184 {
2185         MainWindow *mainwin;
2186         GtkItemFactory *ifactory;
2187         GtkCheckMenuItem *menuitem;
2188
2189         mainwin = (MainWindow *) data;
2190         
2191         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2192         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2193         
2194         g_return_if_fail(mainwin != NULL);
2195         g_return_if_fail(menuitem != NULL);
2196         
2197         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2198                 /* go offline */
2199                 gtk_widget_hide (mainwin->online_switch);
2200                 gtk_widget_show (mainwin->offline_switch);
2201                 menuitem->active = TRUE;
2202                 prefs_common.work_offline = TRUE;
2203                 inc_autocheck_timer_remove();           
2204         } else {
2205                 /*go online */
2206                 gtk_widget_hide (mainwin->offline_switch);
2207                 gtk_widget_show (mainwin->online_switch);
2208                 menuitem->active = FALSE;
2209                 prefs_common.work_offline = FALSE;
2210                 inc_autocheck_timer_set();
2211         }
2212 }
2213
2214 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2215                                 GtkWidget *widget)
2216 {
2217         addressbook_open(NULL);
2218 }
2219
2220 static void log_window_show_cb(MainWindow *mainwin, guint action,
2221                                GtkWidget *widget)
2222 {
2223         log_window_show(mainwin->logwin);
2224 }
2225
2226 static void sel_download_cb(MainWindow *mainwin, guint action,
2227                                GtkWidget *widget)
2228 {
2229         selective_download(mainwin);
2230 }
2231
2232 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2233 {
2234         inc_cancel_all();
2235 }
2236
2237 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2238 {
2239         summary_move_to(mainwin->summaryview);
2240 }
2241
2242 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2243 {
2244         summary_copy_to(mainwin->summaryview);
2245 }
2246
2247 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2248 {
2249         summary_delete(mainwin->summaryview);
2250 }
2251
2252 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2253 {
2254         summary_cancel(mainwin->summaryview);
2255 }
2256
2257 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2258 {
2259         summary_open_msg(mainwin->summaryview);
2260 }
2261
2262 static void view_source_cb(MainWindow *mainwin, guint action,
2263                            GtkWidget *widget)
2264 {
2265         summary_view_source(mainwin->summaryview);
2266 }
2267
2268 static void show_all_header_cb(MainWindow *mainwin, guint action,
2269                                GtkWidget *widget)
2270 {
2271         if (mainwin->menu_lock_count) return;
2272         summary_display_msg_selected(mainwin->summaryview,
2273                                      GTK_CHECK_MENU_ITEM(widget)->active);
2274 }
2275
2276 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2277 {
2278         summary_reedit(mainwin->summaryview);
2279 }
2280
2281 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2282 {
2283         summary_mark(mainwin->summaryview);
2284 }
2285
2286 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2287 {
2288         summary_unmark(mainwin->summaryview);
2289 }
2290
2291 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2292                               GtkWidget *widget)
2293 {
2294         summary_mark_as_unread(mainwin->summaryview);
2295 }
2296
2297 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2298                             GtkWidget *widget)
2299 {
2300         summary_mark_as_read(mainwin->summaryview);
2301 }
2302
2303 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2304                              GtkWidget *widget)
2305 {
2306         summary_mark_all_read(mainwin->summaryview);
2307 }
2308
2309 static void add_address_cb(MainWindow *mainwin, guint action,
2310                            GtkWidget *widget)
2311 {
2312         summary_add_address(mainwin->summaryview);
2313 }
2314
2315 static void set_charset_cb(MainWindow *mainwin, guint action,
2316                            GtkWidget *widget)
2317 {
2318         const gchar *str;
2319
2320         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2321                 str = conv_get_charset_str((CharSet)action);
2322                 g_free(prefs_common.force_charset);
2323                 prefs_common.force_charset = str ? g_strdup(str) : NULL;
2324
2325                 summary_redisplay_msg(mainwin->summaryview);
2326                 
2327                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2328         }
2329 }
2330
2331 static void hide_read_messages (MainWindow *mainwin, guint action,
2332                                 GtkWidget *widget)
2333 {
2334         if (!mainwin->summaryview->folder_item
2335             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2336                 return;
2337         summary_toggle_show_read_messages(mainwin->summaryview);
2338 }
2339
2340 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2341 {
2342         if (mainwin->menu_lock_count) return;
2343         if (!mainwin->summaryview->folder_item) return;
2344
2345         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2346                 summary_thread_build(mainwin->summaryview);
2347 /*              mainwin->summaryview->folder_item->threaded = TRUE; */
2348         } else {
2349                 summary_unthread(mainwin->summaryview);
2350 /*              mainwin->summaryview->folder_item->threaded = FALSE; */
2351         }
2352 }
2353
2354 static void expand_threads_cb(MainWindow *mainwin, guint action,
2355                               GtkWidget *widget)
2356 {
2357         summary_expand_threads(mainwin->summaryview);
2358 }
2359
2360 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2361                                 GtkWidget *widget)
2362 {
2363         summary_collapse_threads(mainwin->summaryview);
2364 }
2365
2366 static void set_display_item_cb(MainWindow *mainwin, guint action,
2367                                 GtkWidget *widget)
2368 {
2369         prefs_summary_column_open();
2370 }
2371
2372 static void sort_summary_cb(MainWindow *mainwin, guint action,
2373                             GtkWidget *widget)
2374 {
2375         FolderItem *item = mainwin->summaryview->folder_item;
2376         GtkWidget *menuitem;
2377
2378         if (mainwin->menu_lock_count) return;
2379
2380         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
2381                 menuitem = gtk_item_factory_get_item
2382                         (mainwin->menu_factory, "/View/Sort/Ascending");
2383                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2384                              GTK_CHECK_MENU_ITEM(menuitem)->active
2385                              ? SORT_ASCENDING : SORT_DESCENDING);
2386         }
2387 }
2388
2389 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2390                                  GtkWidget *widget)
2391 {
2392         FolderItem *item = mainwin->summaryview->folder_item;
2393
2394         if (mainwin->menu_lock_count) return;
2395
2396         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
2397                 summary_sort(mainwin->summaryview,
2398                              item->sort_key, (FolderSortType)action);
2399 }
2400
2401 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2402                                   GtkWidget *widget)
2403 {
2404         summary_attract_by_subject(mainwin->summaryview);
2405 }
2406
2407 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2408                                  GtkWidget *widget)
2409 {
2410         summary_delete_duplicated(mainwin->summaryview);
2411 }
2412
2413 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2414 {
2415         summary_filter(mainwin->summaryview);
2416 }
2417
2418 static void execute_summary_cb(MainWindow *mainwin, guint action,
2419                                GtkWidget *widget)
2420 {
2421         summary_execute(mainwin->summaryview);
2422 }
2423
2424 static void update_summary_cb(MainWindow *mainwin, guint action,
2425                               GtkWidget *widget)
2426 {
2427         FolderItem *fitem;
2428         FolderView *folderview = mainwin->folderview;
2429
2430         if (!mainwin->summaryview->folder_item) return;
2431         if (!folderview->opened) return;
2432
2433         folder_update_op_count();
2434
2435         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2436                                             folderview->opened);
2437         if (!fitem) return;
2438
2439         folder_item_scan(fitem);
2440         summary_show(mainwin->summaryview, fitem);
2441 }
2442
2443 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2444 {
2445         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2446 }
2447
2448 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2449 {
2450         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2451 }
2452
2453 static void prev_unread_cb(MainWindow *mainwin, guint action,
2454                            GtkWidget *widget)
2455 {
2456         summary_select_prev_unread(mainwin->summaryview);
2457 }
2458
2459 static void next_unread_cb(MainWindow *mainwin, guint action,
2460                            GtkWidget *widget)
2461 {
2462         summary_select_next_unread(mainwin->summaryview);
2463 }
2464
2465 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2466 {
2467         summary_select_prev_new(mainwin->summaryview);
2468 }
2469
2470 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2471 {
2472         summary_select_next_new(mainwin->summaryview);
2473 }
2474
2475 static void prev_marked_cb(MainWindow *mainwin, guint action,
2476                            GtkWidget *widget)
2477 {
2478         summary_select_prev_marked(mainwin->summaryview);
2479 }
2480
2481 static void next_marked_cb(MainWindow *mainwin, guint action,
2482                            GtkWidget *widget)
2483 {
2484         summary_select_next_marked(mainwin->summaryview);
2485 }
2486
2487 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2488                             GtkWidget *widget)
2489 {
2490         summary_select_prev_labeled(mainwin->summaryview);
2491 }
2492
2493 static void next_labeled_cb(MainWindow *mainwin, guint action,
2494                             GtkWidget *widget)
2495 {
2496         summary_select_next_labeled(mainwin->summaryview);
2497 }
2498
2499 static void goto_folder_cb(MainWindow *mainwin, guint action,
2500                            GtkWidget *widget)
2501 {
2502         FolderItem *to_folder;
2503
2504         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2505
2506         if (to_folder)
2507                 folderview_select(mainwin->folderview, to_folder);
2508 }
2509
2510 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2511 {
2512         messageview_copy_clipboard(mainwin->messageview);
2513 }
2514
2515 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2516 {
2517         MessageView *msgview = mainwin->messageview;
2518
2519         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2520                 summary_select_all(mainwin->summaryview);
2521         else if (messageview_is_visible(msgview) &&
2522                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2523                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2524                 messageview_select_all(mainwin->messageview);
2525 }
2526
2527 static void select_thread_cb(MainWindow *mainwin, guint action,
2528                              GtkWidget *widget)
2529 {
2530         summary_select_thread(mainwin->summaryview);
2531 }
2532
2533 static void create_filter_cb(MainWindow *mainwin, guint action,
2534                              GtkWidget *widget)
2535 {
2536         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2537 }
2538
2539 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2540                                  GtkWidget *widget)
2541 {
2542         prefs_common_open();
2543 }
2544
2545 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2546                                   GtkWidget *widget)
2547 {
2548         prefs_scoring_open(NULL);
2549 }
2550
2551 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2552                                     GtkWidget *widget)
2553 {
2554         prefs_filtering_open(NULL, NULL, NULL);
2555 }
2556
2557 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2558                                    GtkWidget *widget)
2559 {
2560         prefs_template_open();
2561 }
2562
2563 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2564                                   GtkWidget *widget)
2565 {
2566         prefs_actions_open(mainwin);
2567 }
2568 #ifdef USE_OPENSSL
2569 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
2570                                   GtkWidget *widget)
2571 {
2572         ssl_manager_open(mainwin);
2573 }
2574 #endif
2575 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2576                                   GtkWidget *widget)
2577 {
2578         if (!cur_account) {
2579                 new_account_cb(mainwin, 0, widget);
2580         } else {
2581                 account_open(cur_account);
2582         }
2583 }
2584
2585 static void new_account_cb(MainWindow *mainwin, guint action,
2586                            GtkWidget *widget)
2587 {
2588         account_edit_open();
2589         if (!compose_get_compose_list()) account_add();
2590 }
2591
2592 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2593 {
2594         cur_account = (PrefsAccount *)data;
2595         main_window_reflect_prefs_all();
2596 }
2597
2598 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
2599 {
2600         prefs_gtk_open();
2601 }
2602
2603 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
2604 {
2605         pluginwindow_create();
2606 }
2607
2608 static void manual_open_cb(MainWindow *mainwin, guint action,
2609                            GtkWidget *widget)
2610 {
2611         manual_open((ManualType)action);
2612 }
2613
2614 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2615 {
2616         MainWindow *mainwin = (MainWindow *)data;
2617         gchar *str;
2618
2619         if (item->path)
2620                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2621                                       LOCAL_FOLDER(folder)->rootpath,
2622                                       G_DIR_SEPARATOR,
2623                                       item->path);
2624         else
2625                 str = g_strdup_printf(_("Scanning folder %s ..."),
2626                                       LOCAL_FOLDER(folder)->rootpath);
2627
2628         STATUSBAR_PUSH(mainwin, str);
2629         STATUSBAR_POP(mainwin);
2630         g_free(str);
2631 }
2632
2633 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
2634                                           gpointer data)
2635 {
2636         SummaryView *summary;
2637
2638         g_return_val_if_fail(data, FALSE);
2639         summary = ((MainWindow *)data)->summaryview;
2640         g_return_val_if_fail(summary, FALSE);
2641         if (summary->selected != summary->displayed)
2642                 summary_select_node(summary, summary->displayed, FALSE, TRUE);
2643         return FALSE;
2644 }
2645
2646 #define BREAK_ON_MODIFIER_KEY() \
2647         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2648
2649 void mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
2650                                     gpointer data)
2651 {
2652         MainWindow *mainwin = (MainWindow*) data;
2653         
2654         if (!mainwin || !event) return;
2655                 
2656         switch (event->keyval) {
2657         case GDK_Q:             /* Quit */
2658                 BREAK_ON_MODIFIER_KEY();
2659
2660                 app_exit_cb(mainwin, 0, NULL);
2661                 return;
2662         case GDK_space:
2663                 if (mainwin->folderview && mainwin->summaryview
2664                     && !mainwin->summaryview->displayed) {
2665                         summary_lock(mainwin->summaryview);
2666                         folderview_select_next_unread(mainwin->folderview);
2667                         summary_unlock(mainwin->summaryview);
2668                 }
2669                 break;
2670         default:
2671                 break;
2672         }
2673 }
2674
2675 #undef BREAK_ON_MODIFIER_KEY
2676
2677 /*
2678  * Harvest addresses for selected folder.
2679  */
2680 static void addr_harvest_cb( MainWindow *mainwin,
2681                             guint action,
2682                             GtkWidget *widget )
2683 {
2684         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2685 }
2686
2687 /*
2688  * Harvest addresses for selected messages in summary view.
2689  */
2690 static void addr_harvest_msg_cb( MainWindow *mainwin,
2691                             guint action,
2692                             GtkWidget *widget )
2693 {
2694         summary_harvest_address( mainwin->summaryview );
2695 }
2696
2697 /*!
2698  *\brief        get a MainWindow
2699  *
2700  *\return       MainWindow * The first mainwindow in the mainwin_list
2701  */
2702 MainWindow *mainwindow_get_mainwindow(void)
2703 {
2704         if (mainwin_list && mainwin_list->data)
2705                 return (MainWindow *)(mainwin_list->data);
2706         else
2707                 return NULL;
2708 }
2709
2710 /*
2711 * End of Source.
2712 */
2713