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