rename the 'Unread' column to 'Status'
[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 _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/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/C_hange current account"),
673                                                 NULL, NULL, 0, "<Branch>"},
674         {N_("/_Configuration/_Preferences for current account..."),
675                                                 NULL, prefs_account_open_cb, 0, NULL},
676         {N_("/_Configuration/Create _new account..."),
677                                                 NULL, new_account_cb, 0, NULL},
678         {N_("/_Configuration/_Edit accounts..."),
679                                                 NULL, account_edit_open, 0, NULL},
680         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
681         {N_("/_Configuration/_Common preferences..."),
682                                                 NULL, prefs_common_open_cb, 0, NULL},
683         {N_("/_Configuration/_Scoring..."),
684                                                 NULL, prefs_scoring_open_cb, 0, NULL},
685         {N_("/_Configuration/_Filtering..."),
686                                                 NULL, prefs_filtering_open_cb, 0, NULL},
687         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
688         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
689         {N_("/_Configuration/_Other Preferences..."),  NULL, prefs_open_cb, 0, NULL},
690         {N_("/_Configuration/Plugins..."),      NULL, plugins_open_cb, 0, NULL},
691
692         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
693         {N_("/_Help/_Manual (Local)"),          NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
694         {N_("/_Help/_Manual (Sylpheed Doc Homepage)"),
695                                                 NULL, manual_open_cb, MANUAL_MANUAL_SYLDOC, NULL},
696         {N_("/_Help/_FAQ (Local)"),             NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
697         {N_("/_Help/_FAQ (Sylpheed Doc Homepage)"),
698                                                 NULL, manual_open_cb, MANUAL_FAQ_SYLDOC, NULL},
699         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
700         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
701 };
702
703 MainWindow *main_window_create(SeparateType type)
704 {
705         MainWindow *mainwin;
706         GtkWidget *window;
707         GtkWidget *vbox;
708         GtkWidget *menubar;
709         GtkWidget *handlebox;
710         GtkWidget *vbox_body;
711         GtkWidget *hbox_stat;
712         GtkWidget *statusbar;
713         GtkWidget *progressbar;
714         GtkWidget *statuslabel;
715         GtkWidget *ac_button;
716         GtkWidget *ac_label;
717         GtkWidget *online_pixmap;
718         GtkWidget *offline_pixmap;
719         GtkWidget *online_switch;
720         GtkWidget *offline_switch;
721
722         FolderView *folderview;
723         SummaryView *summaryview;
724         MessageView *messageview;
725         GdkColormap *colormap;
726         GdkColor color[4];
727         gboolean success[4];
728         GtkItemFactory *ifactory;
729         GtkWidget *ac_menu;
730         GtkWidget *menuitem;
731         gint i;
732         guint n_menu_entries;
733
734         static GdkGeometry geometry;
735
736         debug_print("Creating main window...\n");
737         mainwin = g_new0(MainWindow, 1);
738
739         /* main window */
740         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
741         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
742         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
743         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
744
745         if (!geometry.min_height) {
746                 geometry.min_width = 320;
747                 geometry.min_height = 200;
748         }
749         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
750                                       GDK_HINT_MIN_SIZE);
751
752         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
753                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
754         MANAGE_WINDOW_SIGNALS_CONNECT(window);
755         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
756                            GTK_SIGNAL_FUNC(mainwindow_focus_in_event),
757                            mainwin);
758         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
759                                 GTK_SIGNAL_FUNC(mainwindow_key_pressed), mainwin);
760
761         gtk_widget_realize(window);
762         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
763         
764
765         gtkut_widget_set_app_icon(window);
766
767         vbox = gtk_vbox_new(FALSE, 0);
768         gtk_widget_show(vbox);
769         gtk_container_add(GTK_CONTAINER(window), vbox);
770
771         /* menu bar */
772         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
773         menubar = menubar_create(window, mainwin_entries, 
774                                  n_menu_entries, "<Main>", mainwin);
775         gtk_widget_show(menubar);
776         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
777         ifactory = gtk_item_factory_from_widget(menubar);
778
779         menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
780         menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
781
782         handlebox = gtk_handle_box_new();
783         gtk_widget_show(handlebox);
784         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
785
786         /* link window to mainwin->window to avoid gdk warnings */
787         mainwin->window       = window;
788         
789         /* create toolbar */
790         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
791                                           handlebox, 
792                                           (gpointer)mainwin);
793
794         /* vbox that contains body */
795         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
796         gtk_widget_show(vbox_body);
797         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
798         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
799
800         hbox_stat = gtk_hbox_new(FALSE, 2);
801         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
802
803         statusbar = statusbar_create();
804         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
805
806         progressbar = gtk_progress_bar_new();
807         gtk_widget_set_usize(progressbar, 120, 1);
808         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
809
810         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
811         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
812         online_switch = gtk_button_new ();
813         offline_switch = gtk_button_new ();
814         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
815         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
816         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
817         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
818         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
819         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
820         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
821         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
822         
823         statuslabel = gtk_label_new("");
824         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
825
826         ac_button = gtk_button_new();
827         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
828         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
829         gtk_widget_set_usize(ac_button, -1, 1);
830         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
831         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
832                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
833
834         ac_label = gtk_label_new("");
835         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
836
837         gtk_widget_show_all(hbox_stat);
838
839         gtk_widget_hide(offline_switch);
840         /* create views */
841         mainwin->folderview  = folderview  = folderview_create();
842         mainwin->summaryview = summaryview = summary_create();
843         mainwin->messageview = messageview = messageview_create(mainwin);
844         mainwin->logwin      = log_window_create();
845
846         folderview->mainwin      = mainwin;
847         folderview->summaryview  = summaryview;
848
849         summaryview->mainwin     = mainwin;
850         summaryview->folderview  = folderview;
851         summaryview->messageview = messageview;
852         summaryview->window      = window;
853
854         mainwin->vbox         = vbox;
855         mainwin->menubar      = menubar;
856         mainwin->menu_factory = ifactory;
857         mainwin->handlebox    = handlebox;
858         mainwin->vbox_body    = vbox_body;
859         mainwin->hbox_stat    = hbox_stat;
860         mainwin->statusbar    = statusbar;
861         mainwin->progressbar  = progressbar;
862         mainwin->statuslabel  = statuslabel;
863         mainwin->ac_button    = ac_button;
864         mainwin->ac_label     = ac_label;
865         
866         mainwin->online_switch     = online_switch;
867         mainwin->offline_switch    = offline_switch;
868         mainwin->online_pixmap     = online_pixmap;
869         mainwin->offline_pixmap    = offline_pixmap;
870         
871         /* set context IDs for status bar */
872         mainwin->mainwin_cid = gtk_statusbar_get_context_id
873                 (GTK_STATUSBAR(statusbar), "Main Window");
874         mainwin->folderview_cid = gtk_statusbar_get_context_id
875                 (GTK_STATUSBAR(statusbar), "Folder View");
876         mainwin->summaryview_cid = gtk_statusbar_get_context_id
877                 (GTK_STATUSBAR(statusbar), "Summary View");
878
879         /* allocate colors for summary view and folder view */
880         summaryview->color_marked.red = summaryview->color_marked.green = 0;
881         summaryview->color_marked.blue = (guint16)65535;
882
883         summaryview->color_dim.red = summaryview->color_dim.green =
884                 summaryview->color_dim.blue = COLOR_DIM;
885
886         folderview->color_new.red = (guint16)55000;
887         folderview->color_new.green = folderview->color_new.blue = 15000;
888
889         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
890                                        &folderview->color_op);
891
892         summaryview->color_important.red = 0;
893         summaryview->color_important.green = 0;
894         summaryview->color_important.blue = (guint16)65535;
895
896         color[0] = summaryview->color_marked;
897         color[1] = summaryview->color_dim;
898         color[2] = folderview->color_new;
899         color[3] = folderview->color_op;
900
901         colormap = gdk_window_get_colormap(window->window);
902         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
903         for (i = 0; i < 4; i++) {
904                 if (success[i] == FALSE)
905                         g_warning("MainWindow: color allocation %d failed\n", i);
906         }
907
908         debug_print("done.\n");
909
910         messageview->visible = TRUE;
911
912         main_window_set_widgets(mainwin, type);
913
914         /* set menu items */
915         menuitem = gtk_item_factory_get_item
916                 (ifactory, "/View/Code set/Auto detect");
917         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
918
919         switch (prefs_common.toolbar_style) {
920         case TOOLBAR_NONE:
921                 menuitem = gtk_item_factory_get_item
922                         (ifactory, "/View/Show or hide/Toolbar/None");
923                 break;
924         case TOOLBAR_ICON:
925                 menuitem = gtk_item_factory_get_item
926                         (ifactory, "/View/Show or hide/Toolbar/Icon");
927                 break;
928         case TOOLBAR_TEXT:
929                 menuitem = gtk_item_factory_get_item
930                         (ifactory, "/View/Show or hide/Toolbar/Text");
931                 break;
932         case TOOLBAR_BOTH:
933                 menuitem = gtk_item_factory_get_item
934                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
935         }
936         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
937
938         gtk_widget_hide(mainwin->hbox_stat);
939         menuitem = gtk_item_factory_get_item
940                 (ifactory, "/View/Show or hide/Status bar");
941         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
942                                        prefs_common.show_statusbar);
943         
944         gtk_widget_hide(GTK_WIDGET(mainwin->summaryview->hbox_search));
945         
946         if (prefs_common.show_searchbar) {
947                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainwin->summaryview->toggle_search), TRUE);
948                 if (prefs_common.summary_quicksearch_type != S_SEARCH_EXTENDED)
949                         gtk_widget_hide(summaryview->search_description);
950         }
951
952         /* set account selection menu */
953         ac_menu = gtk_item_factory_get_widget
954                 (ifactory, "/Configuration/Change current account");
955         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
956                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
957         mainwin->ac_menu = ac_menu;
958
959         toolbar_main_set_sensitive(mainwin);
960
961         /* create actions menu */
962         update_mainwin_actions_menu(ifactory, mainwin);
963
964         /* attach accel groups to main window */
965 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)        \
966         gtk_window_add_accel_group                      \
967                 (GTK_WINDOW(win),                       \
968                  gtk_item_factory_from_widget(menu)->accel_group)                
969         
970         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu,mainwin->window);
971         
972         /* connect the accelerators for equivalent 
973            menu items in different menus             */
974         menu_connect_identical_items();
975
976
977         
978         /* show main window */
979         gtk_widget_set_uposition(mainwin->window,
980                                  prefs_common.mainwin_x,
981                                  prefs_common.mainwin_y);
982         gtk_widget_set_usize(window, prefs_common.mainwin_width,
983                              prefs_common.mainwin_height);
984         gtk_widget_show(mainwin->window);
985
986         /* initialize views */
987         folderview_init(folderview);
988         summary_init(summaryview);
989         messageview_init(messageview);
990         log_window_init(mainwin->logwin);
991 #ifdef USE_OPENSSL
992         sslcertwindow_register_hook();
993 #endif
994         mainwin->lock_count = 0;
995         mainwin->menu_lock_count = 0;
996         mainwin->cursor_count = 0;
997
998         if (!watch_cursor)
999                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1000
1001         mainwin_list = g_list_append(mainwin_list, mainwin);
1002
1003         /* init work_offline */
1004         if (prefs_common.work_offline)
1005                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1006
1007         return mainwin;
1008 }
1009
1010 void main_window_cursor_wait(MainWindow *mainwin)
1011 {
1012
1013         if (mainwin->cursor_count == 0)
1014                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1015
1016         mainwin->cursor_count++;
1017
1018         gdk_flush();
1019 }
1020
1021 void main_window_cursor_normal(MainWindow *mainwin)
1022 {
1023         if (mainwin->cursor_count)
1024                 mainwin->cursor_count--;
1025
1026         if (mainwin->cursor_count == 0)
1027                 gdk_window_set_cursor(mainwin->window->window, NULL);
1028
1029         gdk_flush();
1030 }
1031
1032 /* lock / unlock the user-interface */
1033 void main_window_lock(MainWindow *mainwin)
1034 {
1035         if (mainwin->lock_count == 0)
1036                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1037
1038         mainwin->lock_count++;
1039
1040         main_window_set_menu_sensitive(mainwin);
1041         toolbar_main_set_sensitive(mainwin);
1042 }
1043
1044 void main_window_unlock(MainWindow *mainwin)
1045 {
1046         if (mainwin->lock_count)
1047                 mainwin->lock_count--;
1048
1049         main_window_set_menu_sensitive(mainwin);
1050         toolbar_main_set_sensitive(mainwin);
1051
1052         if (mainwin->lock_count == 0)
1053                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1054 }
1055
1056 static void main_window_menu_callback_block(MainWindow *mainwin)
1057 {
1058         mainwin->menu_lock_count++;
1059 }
1060
1061 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1062 {
1063         if (mainwin->menu_lock_count)
1064                 mainwin->menu_lock_count--;
1065 }
1066
1067 void main_window_reflect_prefs_all(void)
1068 {
1069         main_window_reflect_prefs_all_real(FALSE);
1070 }
1071
1072 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1073 {
1074         GList *cur;
1075         MainWindow *mainwin;
1076         GtkWidget *pixmap;
1077
1078         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1079                 mainwin = (MainWindow *)cur->data;
1080
1081                 main_window_show_cur_account(mainwin);
1082                 main_window_set_menu_sensitive(mainwin);
1083                 toolbar_main_set_sensitive(mainwin);
1084
1085                 /* pixmap themes */
1086                 if (pixmap_theme_changed) {
1087                         toolbar_update(TOOLBAR_MAIN, mainwin);
1088                         messageview_reflect_prefs_pixmap_theme();
1089                         compose_reflect_prefs_pixmap_theme();
1090                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1091                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1092
1093                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
1094                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1095                                              mainwin->online_pixmap);
1096                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1097                         gtk_widget_show(pixmap);
1098                         mainwin->online_pixmap = pixmap;
1099                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
1100                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1101                                              mainwin->offline_pixmap);
1102                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1103                         gtk_widget_show(pixmap);
1104                         mainwin->offline_pixmap = pixmap;
1105                 }
1106                 
1107                 summary_redisplay_msg(mainwin->summaryview);
1108                 headerview_set_visibility(mainwin->messageview->headerview,
1109                                           prefs_common.display_header_pane);
1110         }
1111 }
1112
1113 void main_window_set_summary_column(void)
1114 {
1115         GList *cur;
1116         MainWindow *mainwin;
1117
1118         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1119                 mainwin = (MainWindow *)cur->data;
1120                 summary_set_column_order(mainwin->summaryview);
1121         }
1122 }
1123
1124 void main_window_set_account_menu(GList *account_list)
1125 {
1126         GList *cur, *cur_ac, *cur_item;
1127         GtkWidget *menuitem;
1128         MainWindow *mainwin;
1129         PrefsAccount *ac_prefs;
1130
1131         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1132                 mainwin = (MainWindow *)cur->data;
1133
1134                 /* destroy all previous menu item */
1135                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1136                 while (cur_item != NULL) {
1137                         GList *next = cur_item->next;
1138                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1139                         cur_item = next;
1140                 }
1141
1142                 for (cur_ac = account_list; cur_ac != NULL;
1143                      cur_ac = cur_ac->next) {
1144                         ac_prefs = (PrefsAccount *)cur_ac->data;
1145
1146                         menuitem = gtk_menu_item_new_with_label
1147                                 (ac_prefs->account_name
1148                                  ? ac_prefs->account_name : _("Untitled"));
1149                         gtk_widget_show(menuitem);
1150                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1151                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1152                                            GTK_SIGNAL_FUNC(account_menu_cb),
1153                                            ac_prefs);
1154                 }
1155         }
1156 }
1157
1158 static void main_window_show_cur_account(MainWindow *mainwin)
1159 {
1160         gchar *buf;
1161         gchar *ac_name;
1162
1163         ac_name = g_strdup(cur_account
1164                            ? (cur_account->account_name
1165                               ? cur_account->account_name : _("Untitled"))
1166                            : _("none"));
1167
1168         if (cur_account)
1169                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1170         else
1171                 buf = g_strdup(PROG_VERSION);
1172         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1173         g_free(buf);
1174
1175         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1176         gtk_widget_queue_resize(mainwin->ac_button);
1177
1178         g_free(ac_name);
1179 }
1180
1181 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1182 {
1183         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1184         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1185         //GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1186         GtkWidget *message_wid = mainwin->messageview->vbox;
1187
1188         debug_print("Changing window separation type from %d to %d\n",
1189                     mainwin->type, type);
1190
1191         if (mainwin->type == type) return;
1192
1193         /* remove widgets from those containers */
1194         gtk_widget_ref(folder_wid);
1195         gtk_widget_ref(summary_wid);
1196         gtk_widget_ref(message_wid);
1197         gtkut_container_remove
1198                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1199         gtkut_container_remove
1200                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1201         gtkut_container_remove
1202                 (GTK_CONTAINER(message_wid->parent), message_wid);
1203
1204         /* clean containers */
1205         switch (mainwin->type) {
1206         case SEPARATE_NONE:
1207                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1208                 break;
1209         case SEPARATE_FOLDER:
1210                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1211                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1212                 break;
1213         case SEPARATE_MESSAGE:
1214                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1215                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1216                 break;
1217         case SEPARATE_BOTH:
1218                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1219                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1220                 break;
1221         }
1222
1223         gtk_widget_hide(mainwin->window);
1224         main_window_set_widgets(mainwin, type);
1225         gtk_widget_show(mainwin->window);
1226
1227         gtk_widget_unref(folder_wid);
1228         gtk_widget_unref(summary_wid);
1229         gtk_widget_unref(message_wid);
1230 }
1231
1232 void main_window_toggle_message_view(MainWindow *mainwin)
1233 {
1234         SummaryView *summaryview = mainwin->summaryview;
1235         union CompositeWin *cwin = &mainwin->win;
1236         GtkWidget *vpaned = NULL;
1237         GtkWidget *container = NULL;
1238         GtkWidget *msgwin = NULL;
1239
1240         switch (mainwin->type) {
1241         case SEPARATE_NONE:
1242                 vpaned = cwin->sep_none.vpaned;
1243                 container = cwin->sep_none.hpaned;
1244                 break;
1245         case SEPARATE_FOLDER:
1246                 vpaned = cwin->sep_folder.vpaned;
1247                 container = mainwin->vbox_body;
1248                 break;
1249         case SEPARATE_MESSAGE:
1250                 msgwin = mainwin->win.sep_message.messagewin;
1251                 break;
1252         case SEPARATE_BOTH:
1253                 msgwin = mainwin->win.sep_both.messagewin;
1254                 break;
1255         }
1256
1257         if (msgwin) {
1258                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1259                         gtk_widget_hide(msgwin);
1260                         mainwin->messageview->visible = FALSE;
1261                         summaryview->displayed = NULL;
1262                 } else {
1263                         gtk_widget_show(msgwin);
1264                         mainwin->messageview->visible = TRUE;
1265                 }
1266         } else if (vpaned->parent != NULL) {
1267                 mainwin->messageview->visible = FALSE;
1268                 summaryview->displayed = NULL;
1269                 gtk_widget_ref(vpaned);
1270                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1271                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1272                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1273                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1274         } else {
1275                 mainwin->messageview->visible = TRUE;
1276                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1277                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1278                 gtk_widget_unref(vpaned);
1279                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1280                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1281         }
1282
1283         main_window_set_menu_sensitive(mainwin);
1284
1285         gtk_widget_grab_focus(summaryview->ctree);
1286 }
1287
1288 void main_window_get_size(MainWindow *mainwin)
1289 {
1290         GtkAllocation *allocation;
1291
1292         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1293
1294         prefs_common.summaryview_width  = allocation->width;
1295
1296         if ((mainwin->type == SEPARATE_NONE ||
1297              mainwin->type == SEPARATE_FOLDER) &&
1298             messageview_is_visible(mainwin->messageview))
1299                 prefs_common.summaryview_height = allocation->height;
1300
1301         prefs_common.mainview_width     = allocation->width;
1302
1303         allocation = &mainwin->window->allocation;
1304
1305         prefs_common.mainview_height = allocation->height;
1306         prefs_common.mainwin_width   = allocation->width;
1307         prefs_common.mainwin_height  = allocation->height;
1308
1309         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1310
1311         prefs_common.folderview_width  = allocation->width;
1312         prefs_common.folderview_height = allocation->height;
1313 }
1314
1315 void main_window_get_position(MainWindow *mainwin)
1316 {
1317         gint x, y;
1318
1319         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1320
1321         prefs_common.mainview_x = x;
1322         prefs_common.mainview_y = y;
1323         prefs_common.mainwin_x = x;
1324         prefs_common.mainwin_y = y;
1325
1326         debug_print("window position: x = %d, y = %d\n", x, y);
1327 }
1328
1329 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1330 {
1331         GList *list;
1332         guint has_trash;
1333         Folder *folder;
1334
1335         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1336                 folder = FOLDER(list->data);
1337                 if (folder && folder->trash && folder->trash->total > 0)
1338                         has_trash++;
1339         }
1340
1341         if (!has_trash) return;
1342         
1343         if (confirm) {
1344                 if (alertpanel(_("Empty trash"),
1345                                _("Empty all messages in trash?"),
1346                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1347                         return;
1348                 manage_window_focus_in(mainwin->window, NULL, NULL);
1349         }
1350
1351         procmsg_empty_trash();
1352
1353         if (mainwin->summaryview->folder_item &&
1354             mainwin->summaryview->folder_item->stype == F_TRASH)
1355                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1356 }
1357
1358 void main_window_add_mailbox(MainWindow *mainwin)
1359 {
1360         gchar *path;
1361         Folder *folder;
1362
1363         path = input_dialog(_("Add mailbox"),
1364                             _("Input the location of mailbox.\n"
1365                               "If the existing mailbox is specified, it will be\n"
1366                               "scanned automatically."),
1367                             "Mail");
1368         if (!path) return;
1369         if (folder_find_from_path(path)) {
1370                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1371                 g_free(path);
1372                 return;
1373         }
1374         if (!strcmp(path, "Mail"))
1375                 folder = folder_new(F_MH, _("Mailbox"), path);
1376         else
1377                 folder = folder_new(F_MH, g_basename(path), path);
1378         g_free(path);
1379
1380         if (folder->create_tree(folder) < 0) {
1381                 alertpanel_error(_("Creation of the mailbox failed.\n"
1382                                    "Maybe some files already exist, or you don't have the permission to write there."));
1383                 folder_destroy(folder);
1384                 return;
1385         }
1386
1387         folder_add(folder);
1388         folder_set_ui_func(folder, scan_tree_func, mainwin);
1389         folder_scan_tree(folder);
1390         folder_set_ui_func(folder, NULL, NULL);
1391
1392         folderview_set(mainwin->folderview);
1393 }
1394
1395 void main_window_add_mbox(MainWindow *mainwin)
1396 {
1397         gchar *path;
1398         Folder *folder;
1399         FolderItem * item;
1400
1401         path = input_dialog(_("Add mbox mailbox"),
1402                             _("Input the location of mailbox."),
1403                             "mail");
1404
1405         if (!path) return;
1406
1407         if (folder_find_from_path(path)) {
1408                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1409                 g_free(path);
1410                 return;
1411         }
1412
1413         /*
1414         if (!strcmp(path, "Mail"))
1415                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1416                 else
1417         */
1418
1419         folder = folder_new(F_MBOX, g_basename(path), path);
1420         g_free(path);
1421
1422         if (folder->create_tree(folder) < 0) {
1423                 alertpanel_error(_("Creation of the mailbox failed."));
1424                 folder_destroy(folder);
1425                 return;
1426         }
1427
1428         folder_add(folder);
1429
1430         item = folder_item_new(folder, folder->name, NULL);
1431         item->folder = folder;
1432         folder->node = g_node_new(item);
1433
1434         folder_create_folder(item, "inbox");
1435         folder_create_folder(item, "outbox");
1436         folder_create_folder(item, "queue");
1437         folder_create_folder(item, "draft");
1438         folder_create_folder(item, "trash");
1439
1440         folderview_set(mainwin->folderview);
1441 }
1442
1443 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1444 {
1445         SensitiveCond state = 0;
1446         SummarySelection selection;
1447         FolderItem *item = mainwin->summaryview->folder_item;
1448         GList *account_list = account_get_list();
1449         
1450         selection = summary_get_selection_type(mainwin->summaryview);
1451
1452         if (mainwin->lock_count == 0)
1453                 state |= M_UNLOCKED;
1454         if (selection != SUMMARY_NONE)
1455                 state |= M_MSG_EXIST;
1456         if (item && item->path && item->parent && !item->no_select) {
1457                 state |= M_EXEC;
1458                 /*              if (item->folder->type != F_NEWS) */
1459                 state |= M_ALLOW_DELETE;
1460
1461                 if (prefs_common.immediate_exec == 0
1462                     && mainwin->lock_count == 0)
1463                         state |= M_DELAY_EXEC;
1464
1465                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1466                     || selection != SUMMARY_NONE)
1467                         state |= M_HIDE_READ_MSG;       
1468         }               
1469         if (mainwin->summaryview->threaded)
1470                 state |= M_THREADED;
1471         else
1472                 state |= M_UNTHREADED;  
1473         if (selection == SUMMARY_SELECTED_SINGLE ||
1474             selection == SUMMARY_SELECTED_MULTIPLE)
1475                 state |= M_TARGET_EXIST;
1476         if (selection == SUMMARY_SELECTED_SINGLE)
1477                 state |= M_SINGLE_TARGET_EXIST;
1478         if (mainwin->summaryview->folder_item &&
1479             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1480                 state |= M_NEWS;
1481         else
1482                 state |= M_NOT_NEWS;
1483         if (selection == SUMMARY_SELECTED_SINGLE &&
1484             (item &&
1485              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1486               item->stype == F_QUEUE)))
1487                 state |= M_ALLOW_REEDIT;
1488         if (cur_account)
1489                 state |= M_HAVE_ACCOUNT;
1490         
1491         for ( ; account_list != NULL; account_list = account_list->next) {
1492                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1493                         state |= M_HAVE_NEWS_ACCOUNT;
1494                         break;
1495                 }
1496         }
1497
1498         if (inc_is_active())
1499                 state |= M_INC_ACTIVE;
1500
1501         return state;
1502 }
1503
1504
1505
1506 void main_window_set_menu_sensitive(MainWindow *mainwin)
1507 {
1508         GtkItemFactory *ifactory = mainwin->menu_factory;
1509         SensitiveCond state;
1510         gboolean sensitive;
1511         GtkWidget *menuitem;
1512         SummaryView *summaryview;
1513         gchar *menu_path;
1514         gint i;
1515
1516         static const struct {
1517                 gchar *const entry;
1518                 SensitiveCond cond;
1519         } entry[] = {
1520                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1521                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1522                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1523                 {"/File/Folder"                               , M_UNLOCKED},
1524                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1525                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1526                 {"/File/Empty trash"                          , M_UNLOCKED},
1527                 {"/File/Work offline"                         , M_UNLOCKED},
1528
1529                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1530                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1531                 /* {"/File/Close"  , M_UNLOCKED}, */
1532                 {"/File/Exit"      , M_UNLOCKED},
1533
1534                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1535
1536                 {"/View/Sort"                      , M_EXEC},
1537                 {"/View/Thread view"               , M_EXEC},
1538                 {"/View/Expand all threads"        , M_MSG_EXIST},
1539                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1540                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1541                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1542                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1543                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1544                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1545                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1546                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1547                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1548                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1549                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1550                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1551                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1552                 {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
1553                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1554
1555                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1556                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1557                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1558                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1559                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1560                 {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1561                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1562                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1563                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1564                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1565                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1566                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1567                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
1568                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
1569                 {"/Message/Mark"                  , M_TARGET_EXIST},
1570
1571                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1572                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1573                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1574                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1575                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1576                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1577                 {"/Tools/Execute"                   , M_DELAY_EXEC},
1578                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1579
1580                 {"/Configuration", M_UNLOCKED},
1581
1582                 {NULL, 0}
1583         };
1584
1585         state = main_window_get_current_state(mainwin);
1586
1587         for (i = 0; entry[i].entry != NULL; i++) {
1588                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1589                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1590         }
1591
1592         main_window_menu_callback_block(mainwin);
1593
1594 #define SET_CHECK_MENU_ACTIVE(path, active) \
1595 { \
1596         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1597         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1598 }
1599
1600         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1601                               messageview_is_visible(mainwin->messageview));
1602
1603         summaryview = mainwin->summaryview;
1604         menu_path = "/View/Sort/Don't sort";
1605
1606         switch (summaryview->sort_key) {
1607         case SORT_BY_NUMBER:
1608                 menu_path = "/View/Sort/by number"; break;
1609         case SORT_BY_SIZE:
1610                 menu_path = "/View/Sort/by size"; break;
1611         case SORT_BY_DATE:
1612                 menu_path = "/View/Sort/by date"; break;
1613         case SORT_BY_FROM:
1614                 menu_path = "/View/Sort/by from"; break;
1615         case SORT_BY_TO:
1616                 menu_path = "/View/Sort/by recipient"; break;
1617         case SORT_BY_SUBJECT:
1618                 menu_path = "/View/Sort/by subject"; break;
1619         case SORT_BY_LABEL:
1620                 menu_path = "/View/Sort/by color label"; break;
1621         case SORT_BY_MARK:
1622                 menu_path = "/View/Sort/by mark"; break;
1623         case SORT_BY_STATUS:
1624                 menu_path = "/View/Sort/by status"; break;
1625         case SORT_BY_MIME:
1626                 menu_path = "/View/Sort/by attachment"; break;
1627         case SORT_BY_SCORE:
1628                 menu_path = "/View/Sort/by score"; break;
1629         case SORT_BY_LOCKED:
1630                 menu_path = "/View/Sort/by locked"; break;
1631         case SORT_BY_NONE:
1632         default:
1633                 menu_path = "/View/Sort/Don't sort"; break;
1634         }
1635         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1636
1637         if (summaryview->sort_type == SORT_ASCENDING) {
1638                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1639         } else {
1640                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1641         }
1642
1643         if (summaryview->sort_key != SORT_BY_NONE) {
1644                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1645                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1646         } else {
1647                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1648                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1649         }
1650
1651         SET_CHECK_MENU_ACTIVE("/View/Show all headers",
1652                               mainwin->messageview->textview->show_all_headers);
1653         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1654
1655 #undef SET_CHECK_MENU_ACTIVE
1656
1657         main_window_menu_callback_unblock(mainwin);
1658 }
1659
1660 void main_window_popup(MainWindow *mainwin)
1661 {
1662         gtkut_window_popup(mainwin->window);
1663
1664         switch (mainwin->type) {
1665         case SEPARATE_FOLDER:
1666                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
1667                 break;
1668         case SEPARATE_MESSAGE:
1669                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
1670                 break;
1671         case SEPARATE_BOTH:
1672                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
1673                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
1674                 break;
1675         default:
1676                 break;
1677         }
1678 }
1679
1680 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1681 {
1682         GtkWidget *folderwin = NULL;
1683         GtkWidget *messagewin = NULL;
1684         GtkWidget *hpaned;
1685         GtkWidget *vpaned;
1686         GtkWidget *vbox_body = mainwin->vbox_body;
1687         GtkItemFactory *ifactory = mainwin->menu_factory;
1688         GtkWidget *menuitem;
1689         GtkItemFactory *msgview_ifactory;
1690
1691         debug_print("Setting widgets...");
1692
1693         /* create separated window(s) if needed */
1694         if (type & SEPARATE_FOLDER) {
1695                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1696                 gtk_window_set_title(GTK_WINDOW(folderwin),
1697                                      _("Sylpheed - Folder View"));
1698                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1699                                        "folder_view", "Sylpheed");
1700                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1701                                       TRUE, TRUE, FALSE);
1702                 gtk_widget_set_usize(folderwin, -1,
1703                                      prefs_common.mainview_height);
1704                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1705                                                BORDER_WIDTH);
1706                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1707                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1708                                    mainwin);
1709         }
1710         if (type & SEPARATE_MESSAGE) {
1711                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1712                 gtk_window_set_title(GTK_WINDOW(messagewin),
1713                                      _("Sylpheed - Message View"));
1714                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1715                                        "message_view", "Sylpheed");
1716                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1717                                       TRUE, TRUE, FALSE);
1718                 gtk_widget_set_usize
1719                         (messagewin, prefs_common.mainview_width,
1720                          prefs_common.mainview_height
1721                          - prefs_common.summaryview_height
1722                          + DEFAULT_HEADERVIEW_HEIGHT);
1723                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1724                                                BORDER_WIDTH);
1725                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1726                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1727                                    mainwin);
1728         }
1729
1730         switch (type) {
1731         case SEPARATE_NONE:
1732                 hpaned = gtk_hpaned_new();
1733                 gtk_widget_show(hpaned);
1734                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1735                 gtk_paned_add1(GTK_PANED(hpaned),
1736                                GTK_WIDGET_PTR(mainwin->folderview));
1737
1738                 vpaned = gtk_vpaned_new();
1739                 if (messageview_is_visible(mainwin->messageview)) {
1740                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1741                         gtk_paned_add1(GTK_PANED(vpaned),
1742                                        GTK_WIDGET_PTR(mainwin->summaryview));
1743                 } else {
1744                         gtk_paned_add2(GTK_PANED(hpaned),
1745                                        GTK_WIDGET_PTR(mainwin->summaryview));
1746                         gtk_widget_ref(vpaned);
1747                 }
1748                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1749                                      prefs_common.summaryview_width,
1750                                      prefs_common.summaryview_height);
1751                 gtk_paned_add2(GTK_PANED(vpaned),
1752                                GTK_WIDGET_PTR(mainwin->messageview));
1753                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1754                                      prefs_common.mainview_width, -1);
1755                 gtk_widget_set_usize(mainwin->window,
1756                                      prefs_common.folderview_width +
1757                                      prefs_common.mainview_width,
1758                                      prefs_common.mainwin_height);
1759                 gtk_widget_show_all(vpaned);
1760
1761                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1762                  * lose track of its visibility state */
1763                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1764                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1765
1766                 mainwin->win.sep_none.hpaned = hpaned;
1767                 mainwin->win.sep_none.vpaned = vpaned;
1768                 
1769                 /* remove headerview if not in prefs */
1770                 headerview_set_visibility(mainwin->messageview->headerview,
1771                                           prefs_common.display_header_pane);
1772                 break;
1773         case SEPARATE_FOLDER:
1774                 vpaned = gtk_vpaned_new();
1775                 if (messageview_is_visible(mainwin->messageview)) {
1776                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1777                                            TRUE, TRUE, 0);
1778                         gtk_paned_add1(GTK_PANED(vpaned),
1779                                        GTK_WIDGET_PTR(mainwin->summaryview));
1780                 } else {
1781                         gtk_box_pack_start(GTK_BOX(vbox_body),
1782                                            GTK_WIDGET_PTR(mainwin->summaryview),
1783                                            TRUE, TRUE, 0);
1784                         gtk_widget_ref(vpaned);
1785                 }
1786                 gtk_paned_add2(GTK_PANED(vpaned),
1787                                GTK_WIDGET_PTR(mainwin->messageview));
1788                 gtk_widget_show_all(vpaned);
1789                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1790                                      prefs_common.summaryview_width,
1791                                      prefs_common.summaryview_height);
1792                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1793                                      prefs_common.mainview_width, -1);
1794                 gtk_widget_set_usize(mainwin->window,
1795                                      prefs_common.mainview_width,
1796                                      prefs_common.mainview_height);
1797
1798                 gtk_container_add(GTK_CONTAINER(folderwin),
1799                                   GTK_WIDGET_PTR(mainwin->folderview));
1800
1801                 mainwin->win.sep_folder.folderwin = folderwin;
1802                 mainwin->win.sep_folder.vpaned    = vpaned;
1803
1804                 gtk_widget_show_all(folderwin);
1805                 
1806                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1807                  * lose track of its visibility state */
1808                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1809                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1810                 
1811                 /* remove headerview if not in prefs */
1812                 headerview_set_visibility(mainwin->messageview->headerview,
1813                                           prefs_common.display_header_pane);
1814                 
1815                 break;
1816         case SEPARATE_MESSAGE:
1817                 hpaned = gtk_hpaned_new();
1818                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1819
1820                 gtk_paned_add1(GTK_PANED(hpaned),
1821                                GTK_WIDGET_PTR(mainwin->folderview));
1822                 gtk_paned_add2(GTK_PANED(hpaned),
1823                                GTK_WIDGET_PTR(mainwin->summaryview));
1824                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1825                                      prefs_common.summaryview_width,
1826                                      prefs_common.summaryview_height);
1827                 gtk_widget_set_usize(mainwin->window,
1828                                      prefs_common.folderview_width +
1829                                      prefs_common.mainview_width,
1830                                      prefs_common.mainwin_height);
1831                 gtk_widget_show_all(hpaned);
1832
1833                 messageview_add_toolbar(mainwin->messageview, messagewin);
1834                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
1835                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
1836
1837                 mainwin->win.sep_message.messagewin = messagewin;
1838                 mainwin->win.sep_message.hpaned     = hpaned;
1839
1840                 gtk_widget_show_all(messagewin);
1841                 
1842                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1843                  * lose track of its visibility state */
1844                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1845                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1846                 break;
1847         case SEPARATE_BOTH:
1848                 gtk_box_pack_start(GTK_BOX(vbox_body),
1849                                    GTK_WIDGET_PTR(mainwin->summaryview),
1850                                    TRUE, TRUE, 0);
1851                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1852                                      prefs_common.summaryview_width,
1853                                      prefs_common.summaryview_height);
1854                 gtk_widget_set_usize(mainwin->window,
1855                                      prefs_common.mainview_width,
1856                                      prefs_common.mainwin_height);
1857                 gtk_container_add(GTK_CONTAINER(folderwin),
1858                                   GTK_WIDGET_PTR(mainwin->folderview));
1859                 gtk_container_add(GTK_CONTAINER(messagewin),
1860                                   GTK_WIDGET_PTR(mainwin->messageview));
1861
1862                 mainwin->win.sep_both.folderwin = folderwin;
1863                 mainwin->win.sep_both.messagewin = messagewin;
1864
1865                 gtk_widget_show_all(folderwin);
1866                 gtk_widget_show_all(messagewin);
1867
1868                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1869                  * lose track of its visibility state */
1870                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1871                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1872                 break;
1873         }
1874
1875         /* rehide quick search if necessary */
1876         if (!prefs_common.show_searchbar)
1877                 gtk_widget_hide(mainwin->summaryview->hbox_search);
1878         
1879         mainwin->type = type;
1880
1881         mainwin->messageview->visible = TRUE;
1882
1883         /* toggle menu state */
1884         menuitem = gtk_item_factory_get_item
1885                 (ifactory, "/View/Show or hide/Folder tree");
1886         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1887         menuitem = gtk_item_factory_get_item
1888                 (ifactory, "/View/Show or hide/Message view");
1889         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1890
1891         menuitem = gtk_item_factory_get_item
1892                 (ifactory, "/View/Separate folder tree");
1893         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1894                                        ((type & SEPARATE_FOLDER) != 0));
1895         menuitem = gtk_item_factory_get_item
1896                 (ifactory, "/View/Separate message view");
1897         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1898                                        ((type & SEPARATE_MESSAGE) != 0));
1899
1900         debug_print("done.\n");
1901 }
1902
1903 void main_window_destroy_all(void)
1904 {
1905         while (mainwin_list != NULL) {
1906                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
1907                 
1908                 /* free toolbar stuff */
1909                 toolbar_clear_list(TOOLBAR_MAIN);
1910                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
1911                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
1912
1913                 g_free(mainwin->toolbar);
1914                 g_free(mainwin);
1915                 
1916                 mainwin_list = g_list_remove(mainwin_list, mainwin);
1917         }
1918         g_list_free(mainwin_list);
1919 }
1920
1921 #if 0
1922 static void toolbar_account_button_pressed(GtkWidget *widget,
1923                                            GdkEventButton *event,
1924                                            gpointer data)
1925 {
1926         MainWindow *mainwin = (MainWindow *)data;
1927
1928         if (!event) return;
1929         if (event->button != 3) return;
1930
1931         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1932         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1933                             widget);
1934
1935         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1936                        menu_button_position, widget,
1937                        event->button, event->time);
1938 }
1939 #endif
1940
1941 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1942                                     gpointer data)
1943 {
1944         MainWindow *mainwin = (MainWindow *)data;
1945
1946         if (!event) return;
1947
1948         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1949         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1950                             widget);
1951
1952         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1953                        menu_button_position, widget,
1954                        event->button, event->time);
1955 }
1956
1957 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1958 {
1959         MainWindow *mainwin = (MainWindow *)data;
1960         GtkWidget *button;
1961
1962         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1963         if (!button) return;
1964         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1965         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1966         manage_window_focus_in(mainwin->window, NULL, NULL);
1967 }
1968
1969 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1970                                  gpointer data)
1971 {
1972         MainWindow *mainwin = (MainWindow *)data;
1973
1974         if (mainwin->lock_count == 0)
1975                 app_exit_cb(data, 0, widget);
1976
1977         return TRUE;
1978 }
1979
1980 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1981                                    gpointer data)
1982 {
1983         MainWindow *mainwin = (MainWindow *)data;
1984         GtkWidget *menuitem;
1985
1986         menuitem = gtk_item_factory_get_item
1987                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1988         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1989
1990         return TRUE;
1991 }
1992
1993 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1994                                     gpointer data)
1995 {
1996         MainWindow *mainwin = (MainWindow *)data;
1997         GtkWidget *menuitem;
1998
1999         menuitem = gtk_item_factory_get_item
2000                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2001         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2002
2003         return TRUE;
2004 }
2005
2006 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2007                            GtkWidget *widget)
2008 {
2009         main_window_add_mailbox(mainwin);
2010 }
2011
2012 static void add_mbox_cb(MainWindow *mainwin, guint action,
2013                         GtkWidget *widget)
2014 {
2015         main_window_add_mbox(mainwin);
2016 }
2017
2018 static void update_folderview_cb(MainWindow *mainwin, guint action,
2019                                  GtkWidget *widget)
2020 {
2021         summary_show(mainwin->summaryview, NULL);
2022         folderview_check_new_all();
2023 }
2024
2025 static void new_folder_cb(MainWindow *mainwin, guint action,
2026                           GtkWidget *widget)
2027 {
2028         folderview_new_folder(mainwin->folderview);
2029 }
2030
2031 static void rename_folder_cb(MainWindow *mainwin, guint action,
2032                              GtkWidget *widget)
2033 {
2034         folderview_rename_folder(mainwin->folderview);
2035 }
2036
2037 static void delete_folder_cb(MainWindow *mainwin, guint action,
2038                              GtkWidget *widget)
2039 {
2040         folderview_delete_folder(mainwin->folderview);
2041 }
2042
2043 static void import_mbox_cb(MainWindow *mainwin, guint action,
2044                            GtkWidget *widget)
2045 {
2046         import_mbox(mainwin->summaryview->folder_item);
2047 }
2048
2049 static void export_mbox_cb(MainWindow *mainwin, guint action,
2050                            GtkWidget *widget)
2051 {
2052         export_mbox(mainwin->summaryview->folder_item);
2053 }
2054
2055 static void empty_trash_cb(MainWindow *mainwin, guint action,
2056                            GtkWidget *widget)
2057 {
2058         main_window_empty_trash(mainwin, TRUE);
2059 }
2060
2061 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2062 {
2063         summary_save_as(mainwin->summaryview);
2064 }
2065
2066 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2067 {
2068         summary_print(mainwin->summaryview);
2069 }
2070
2071 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2072 {
2073         if (prefs_common.confirm_on_exit) {
2074                 if (alertpanel(_("Exit"), _("Exit this program?"),
2075                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2076                         return;
2077                 manage_window_focus_in(mainwin->window, NULL, NULL);
2078         }
2079
2080         app_will_exit(widget, mainwin);
2081 }
2082
2083 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2084 {
2085         if (action == 1)
2086                 summary_search(mainwin->summaryview);
2087         else
2088                 message_search(mainwin->messageview);
2089 }
2090
2091 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2092                              GtkWidget *widget)
2093 {
2094         gboolean active;
2095
2096         active = GTK_CHECK_MENU_ITEM(widget)->active;
2097
2098         switch (mainwin->type) {
2099         case SEPARATE_NONE:
2100         case SEPARATE_MESSAGE:
2101 #if 0
2102                 if (active)
2103                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2104                 else
2105                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2106 #endif
2107                 break;
2108         case SEPARATE_FOLDER:
2109                 debug_print("separate folder\n");
2110                 if (active)
2111                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2112                 else
2113                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2114                 break;
2115         case SEPARATE_BOTH:
2116                 if (active)
2117                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2118                 else
2119                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2120                 break;
2121         }
2122 }
2123
2124 static void toggle_message_cb(MainWindow *mainwin, guint action,
2125                               GtkWidget *widget)
2126 {
2127         gboolean active;
2128
2129         active = GTK_CHECK_MENU_ITEM(widget)->active;
2130
2131         if (active != messageview_is_visible(mainwin->messageview))
2132                 summary_toggle_view(mainwin->summaryview);
2133 }
2134
2135 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2136                               GtkWidget *widget)
2137 {
2138         toolbar_toggle(action, mainwin);
2139 }
2140
2141 /* END Toolbar Stuff */
2142
2143 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2144                                 GtkWidget *widget)
2145 {
2146         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2147                 gtk_widget_show(mainwin->hbox_stat);
2148                 prefs_common.show_statusbar = TRUE;
2149         } else {
2150                 gtk_widget_hide(mainwin->hbox_stat);
2151                 prefs_common.show_statusbar = FALSE;
2152         }
2153 }
2154
2155 static void separate_widget_cb(MainWindow *mainwin, guint action,
2156                                GtkWidget *widget)
2157 {
2158         SeparateType type;
2159
2160         if (GTK_CHECK_MENU_ITEM(widget)->active)
2161                 type = mainwin->type | action;
2162         else
2163                 type = mainwin->type & ~action;
2164
2165         main_window_separation_change(mainwin, type);
2166
2167         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2168         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2169 }
2170
2171 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline)
2172 {
2173         if (offline)
2174                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2175         else
2176                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
2177 }
2178
2179 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
2180 {
2181         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active);
2182 }
2183
2184 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2185 {
2186         MainWindow *mainwin;
2187         GtkItemFactory *ifactory;
2188         GtkCheckMenuItem *menuitem;
2189
2190         mainwin = (MainWindow *) data;
2191         
2192         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2193         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2194         
2195         g_return_if_fail(mainwin != NULL);
2196         g_return_if_fail(menuitem != NULL);
2197         
2198         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2199                 /* go offline */
2200                 gtk_widget_hide (mainwin->online_switch);
2201                 gtk_widget_show (mainwin->offline_switch);
2202                 menuitem->active = TRUE;
2203                 prefs_common.work_offline = TRUE;
2204                 inc_autocheck_timer_remove();           
2205         } else {
2206                 /*go online */
2207                 gtk_widget_hide (mainwin->offline_switch);
2208                 gtk_widget_show (mainwin->online_switch);
2209                 menuitem->active = FALSE;
2210                 prefs_common.work_offline = FALSE;
2211                 inc_autocheck_timer_set();
2212         }
2213 }
2214
2215 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2216                                 GtkWidget *widget)
2217 {
2218         addressbook_open(NULL);
2219 }
2220
2221 static void log_window_show_cb(MainWindow *mainwin, guint action,
2222                                GtkWidget *widget)
2223 {
2224         log_window_show(mainwin->logwin);
2225 }
2226
2227 static void sel_download_cb(MainWindow *mainwin, guint action,
2228                                GtkWidget *widget)
2229 {
2230         selective_download(mainwin);
2231 }
2232
2233 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2234 {
2235         inc_cancel_all();
2236 }
2237
2238 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2239 {
2240         summary_move_to(mainwin->summaryview);
2241 }
2242
2243 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2244 {
2245         summary_copy_to(mainwin->summaryview);
2246 }
2247
2248 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2249 {
2250         summary_delete(mainwin->summaryview);
2251 }
2252
2253 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2254 {
2255         summary_cancel(mainwin->summaryview);
2256 }
2257
2258 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2259 {
2260         summary_open_msg(mainwin->summaryview);
2261 }
2262
2263 static void view_source_cb(MainWindow *mainwin, guint action,
2264                            GtkWidget *widget)
2265 {
2266         summary_view_source(mainwin->summaryview);
2267 }
2268
2269 static void show_all_header_cb(MainWindow *mainwin, guint action,
2270                                GtkWidget *widget)
2271 {
2272         if (mainwin->menu_lock_count) return;
2273         summary_display_msg_selected(mainwin->summaryview,
2274                                      GTK_CHECK_MENU_ITEM(widget)->active);
2275 }
2276
2277 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2278 {
2279         summary_reedit(mainwin->summaryview);
2280 }
2281
2282 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2283 {
2284         summary_mark(mainwin->summaryview);
2285 }
2286
2287 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2288 {
2289         summary_unmark(mainwin->summaryview);
2290 }
2291
2292 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2293                               GtkWidget *widget)
2294 {
2295         summary_mark_as_unread(mainwin->summaryview);
2296 }
2297
2298 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2299                             GtkWidget *widget)
2300 {
2301         summary_mark_as_read(mainwin->summaryview);
2302 }
2303
2304 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2305                              GtkWidget *widget)
2306 {
2307         summary_mark_all_read(mainwin->summaryview);
2308 }
2309
2310 static void add_address_cb(MainWindow *mainwin, guint action,
2311                            GtkWidget *widget)
2312 {
2313         summary_add_address(mainwin->summaryview);
2314 }
2315
2316 static void set_charset_cb(MainWindow *mainwin, guint action,
2317                            GtkWidget *widget)
2318 {
2319         const gchar *str;
2320
2321         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2322                 str = conv_get_charset_str((CharSet)action);
2323                 g_free(prefs_common.force_charset);
2324                 prefs_common.force_charset = str ? g_strdup(str) : NULL;
2325
2326                 summary_redisplay_msg(mainwin->summaryview);
2327                 
2328                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2329         }
2330 }
2331
2332 static void hide_read_messages (MainWindow *mainwin, guint action,
2333                                 GtkWidget *widget)
2334 {
2335         if (!mainwin->summaryview->folder_item
2336             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2337                 return;
2338         summary_toggle_show_read_messages(mainwin->summaryview);
2339 }
2340
2341 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2342 {
2343         if (mainwin->menu_lock_count) return;
2344         if (!mainwin->summaryview->folder_item) return;
2345
2346         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2347                 summary_thread_build(mainwin->summaryview);
2348 /*              mainwin->summaryview->folder_item->threaded = TRUE; */
2349         } else {
2350                 summary_unthread(mainwin->summaryview);
2351 /*              mainwin->summaryview->folder_item->threaded = FALSE; */
2352         }
2353 }
2354
2355 static void expand_threads_cb(MainWindow *mainwin, guint action,
2356                               GtkWidget *widget)
2357 {
2358         summary_expand_threads(mainwin->summaryview);
2359 }
2360
2361 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2362                                 GtkWidget *widget)
2363 {
2364         summary_collapse_threads(mainwin->summaryview);
2365 }
2366
2367 static void set_display_item_cb(MainWindow *mainwin, guint action,
2368                                 GtkWidget *widget)
2369 {
2370         prefs_summary_column_open();
2371 }
2372
2373 static void sort_summary_cb(MainWindow *mainwin, guint action,
2374                             GtkWidget *widget)
2375 {
2376         FolderItem *item = mainwin->summaryview->folder_item;
2377         GtkWidget *menuitem;
2378
2379         if (mainwin->menu_lock_count) return;
2380
2381         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
2382                 menuitem = gtk_item_factory_get_item
2383                         (mainwin->menu_factory, "/View/Sort/Ascending");
2384                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2385                              GTK_CHECK_MENU_ITEM(menuitem)->active
2386                              ? SORT_ASCENDING : SORT_DESCENDING);
2387         }
2388 }
2389
2390 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2391                                  GtkWidget *widget)
2392 {
2393         FolderItem *item = mainwin->summaryview->folder_item;
2394
2395         if (mainwin->menu_lock_count) return;
2396
2397         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
2398                 summary_sort(mainwin->summaryview,
2399                              item->sort_key, (FolderSortType)action);
2400 }
2401
2402 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2403                                   GtkWidget *widget)
2404 {
2405         summary_attract_by_subject(mainwin->summaryview);
2406 }
2407
2408 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2409                                  GtkWidget *widget)
2410 {
2411         summary_delete_duplicated(mainwin->summaryview);
2412 }
2413
2414 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2415 {
2416         summary_filter(mainwin->summaryview);
2417 }
2418
2419 static void execute_summary_cb(MainWindow *mainwin, guint action,
2420                                GtkWidget *widget)
2421 {
2422         summary_execute(mainwin->summaryview);
2423 }
2424
2425 static void update_summary_cb(MainWindow *mainwin, guint action,
2426                               GtkWidget *widget)
2427 {
2428         FolderItem *fitem;
2429         FolderView *folderview = mainwin->folderview;
2430
2431         if (!mainwin->summaryview->folder_item) return;
2432         if (!folderview->opened) return;
2433
2434         folder_update_op_count();
2435
2436         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2437                                             folderview->opened);
2438         if (!fitem) return;
2439
2440         folder_item_scan(fitem);
2441         summary_show(mainwin->summaryview, fitem);
2442 }
2443
2444 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2445 {
2446         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2447 }
2448
2449 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2450 {
2451         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2452 }
2453
2454 static void prev_unread_cb(MainWindow *mainwin, guint action,
2455                            GtkWidget *widget)
2456 {
2457         summary_select_prev_unread(mainwin->summaryview);
2458 }
2459
2460 static void next_unread_cb(MainWindow *mainwin, guint action,
2461                            GtkWidget *widget)
2462 {
2463         summary_select_next_unread(mainwin->summaryview);
2464 }
2465
2466 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2467 {
2468         summary_select_prev_new(mainwin->summaryview);
2469 }
2470
2471 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2472 {
2473         summary_select_next_new(mainwin->summaryview);
2474 }
2475
2476 static void prev_marked_cb(MainWindow *mainwin, guint action,
2477                            GtkWidget *widget)
2478 {
2479         summary_select_prev_marked(mainwin->summaryview);
2480 }
2481
2482 static void next_marked_cb(MainWindow *mainwin, guint action,
2483                            GtkWidget *widget)
2484 {
2485         summary_select_next_marked(mainwin->summaryview);
2486 }
2487
2488 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2489                             GtkWidget *widget)
2490 {
2491         summary_select_prev_labeled(mainwin->summaryview);
2492 }
2493
2494 static void next_labeled_cb(MainWindow *mainwin, guint action,
2495                             GtkWidget *widget)
2496 {
2497         summary_select_next_labeled(mainwin->summaryview);
2498 }
2499
2500 static void goto_folder_cb(MainWindow *mainwin, guint action,
2501                            GtkWidget *widget)
2502 {
2503         FolderItem *to_folder;
2504
2505         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2506
2507         if (to_folder)
2508                 folderview_select(mainwin->folderview, to_folder);
2509 }
2510
2511 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2512 {
2513         messageview_copy_clipboard(mainwin->messageview);
2514 }
2515
2516 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2517 {
2518         MessageView *msgview = mainwin->messageview;
2519
2520         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2521                 summary_select_all(mainwin->summaryview);
2522         else if (messageview_is_visible(msgview) &&
2523                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2524                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2525                 messageview_select_all(mainwin->messageview);
2526 }
2527
2528 static void select_thread_cb(MainWindow *mainwin, guint action,
2529                              GtkWidget *widget)
2530 {
2531         summary_select_thread(mainwin->summaryview);
2532 }
2533
2534 static void create_filter_cb(MainWindow *mainwin, guint action,
2535                              GtkWidget *widget)
2536 {
2537         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2538 }
2539
2540 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2541                                  GtkWidget *widget)
2542 {
2543         prefs_common_open();
2544 }
2545
2546 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2547                                   GtkWidget *widget)
2548 {
2549         prefs_scoring_open(NULL);
2550 }
2551
2552 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2553                                     GtkWidget *widget)
2554 {
2555         prefs_filtering_open(NULL, NULL, NULL);
2556 }
2557
2558 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2559                                    GtkWidget *widget)
2560 {
2561         prefs_template_open();
2562 }
2563
2564 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2565                                   GtkWidget *widget)
2566 {
2567         prefs_actions_open(mainwin);
2568 }
2569 #ifdef USE_OPENSSL
2570 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
2571                                   GtkWidget *widget)
2572 {
2573         ssl_manager_open(mainwin);
2574 }
2575 #endif
2576 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2577                                   GtkWidget *widget)
2578 {
2579         if (!cur_account) {
2580                 new_account_cb(mainwin, 0, widget);
2581         } else {
2582                 account_open(cur_account);
2583         }
2584 }
2585
2586 static void new_account_cb(MainWindow *mainwin, guint action,
2587                            GtkWidget *widget)
2588 {
2589         account_edit_open();
2590         if (!compose_get_compose_list()) account_add();
2591 }
2592
2593 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2594 {
2595         cur_account = (PrefsAccount *)data;
2596         main_window_reflect_prefs_all();
2597 }
2598
2599 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
2600 {
2601         prefs_gtk_open();
2602 }
2603
2604 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
2605 {
2606         pluginwindow_create();
2607 }
2608
2609 static void manual_open_cb(MainWindow *mainwin, guint action,
2610                            GtkWidget *widget)
2611 {
2612         manual_open((ManualType)action);
2613 }
2614
2615 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2616 {
2617         MainWindow *mainwin = (MainWindow *)data;
2618         gchar *str;
2619
2620         if (item->path)
2621                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2622                                       LOCAL_FOLDER(folder)->rootpath,
2623                                       G_DIR_SEPARATOR,
2624                                       item->path);
2625         else
2626                 str = g_strdup_printf(_("Scanning folder %s ..."),
2627                                       LOCAL_FOLDER(folder)->rootpath);
2628
2629         STATUSBAR_PUSH(mainwin, str);
2630         STATUSBAR_POP(mainwin);
2631         g_free(str);
2632 }
2633
2634 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
2635                                           gpointer data)
2636 {
2637         SummaryView *summary;
2638
2639         g_return_val_if_fail(data, FALSE);
2640         summary = ((MainWindow *)data)->summaryview;
2641         g_return_val_if_fail(summary, FALSE);
2642         if (summary->selected != summary->displayed)
2643                 summary_select_node(summary, summary->displayed, FALSE, TRUE);
2644         return FALSE;
2645 }
2646
2647 #define BREAK_ON_MODIFIER_KEY() \
2648         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2649
2650 void mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
2651                                     gpointer data)
2652 {
2653         MainWindow *mainwin = (MainWindow*) data;
2654         
2655         if (!mainwin || !event) return;
2656                 
2657         switch (event->keyval) {
2658         case GDK_Q:             /* Quit */
2659                 BREAK_ON_MODIFIER_KEY();
2660
2661                 app_exit_cb(mainwin, 0, NULL);
2662                 return;
2663         case GDK_space:
2664                 if (mainwin->folderview && mainwin->summaryview
2665                     && !mainwin->summaryview->displayed) {
2666                         summary_lock(mainwin->summaryview);
2667                         folderview_select_next_unread(mainwin->folderview);
2668                         summary_unlock(mainwin->summaryview);
2669                 }
2670                 break;
2671         default:
2672                 break;
2673         }
2674 }
2675
2676 #undef BREAK_ON_MODIFIER_KEY
2677
2678 /*
2679  * Harvest addresses for selected folder.
2680  */
2681 static void addr_harvest_cb( MainWindow *mainwin,
2682                             guint action,
2683                             GtkWidget *widget )
2684 {
2685         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2686 }
2687
2688 /*
2689  * Harvest addresses for selected messages in summary view.
2690  */
2691 static void addr_harvest_msg_cb( MainWindow *mainwin,
2692                             guint action,
2693                             GtkWidget *widget )
2694 {
2695         summary_harvest_address( mainwin->summaryview );
2696 }
2697
2698 /*!
2699  *\brief        get a MainWindow
2700  *
2701  *\return       MainWindow * The first mainwindow in the mainwin_list
2702  */
2703 MainWindow *mainwindow_get_mainwindow(void)
2704 {
2705         if (mainwin_list && mainwin_list->data)
2706                 return (MainWindow *)(mainwin_list->data);
2707         else
2708                 return NULL;
2709 }
2710
2711 /*
2712 * End of Source.
2713 */
2714