3183d9df164c8b746d1c685de83d34e24d4346d2
[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->threaded)
1424                         state |= M_THREADED;
1425                 else
1426                         state |= M_UNTHREADED;  
1427                 /*              if (item->folder->type != F_NEWS) */
1428                 state |= M_ALLOW_DELETE;
1429
1430                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1431                     || selection != SUMMARY_NONE)
1432                         state |= M_HIDE_READ_MSG;       
1433         }               
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         FolderItem *item;
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         item = mainwin->summaryview->folder_item;
1562         menu_path = "/View/Sort/Don't sort";
1563         if (item) {
1564                 switch (item->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         }
1592         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1593
1594         if (!item || item->sort_type == SORT_ASCENDING) {
1595                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1596         } else {
1597                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1598         }
1599
1600         if (item && item->sort_key != SORT_BY_NONE) {
1601                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1602                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1603         } else {
1604                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1605                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1606         }
1607
1608         SET_CHECK_MENU_ACTIVE("/View/Show all header",
1609                               mainwin->messageview->textview->show_all_headers);
1610         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1611
1612 #undef SET_CHECK_MENU_ACTIVE
1613
1614         main_window_menu_callback_unblock(mainwin);
1615 }
1616
1617 void main_window_popup(MainWindow *mainwin)
1618 {
1619         gint x, y;
1620         gint sx, sy;
1621         GtkWidget *widget;
1622
1623         gdk_window_get_origin(mainwin->window->window, &x, &y);
1624         sx = gdk_screen_width();
1625         sy = gdk_screen_height();
1626         x %= sx; if (x < 0) x = 0;
1627         y %= sy; if (y < 0) y = 0;
1628         gdk_window_move(mainwin->window->window, x, y);
1629         gdk_window_raise(mainwin->window->window);
1630         gdk_window_show(mainwin->window->window);
1631
1632         debug_print("window position: x = %d, y = %d\n", x, y);
1633
1634         switch (mainwin->type) {
1635         case SEPARATE_FOLDER:
1636                 widget = mainwin->win.sep_folder.folderwin;
1637                 gdk_window_get_origin(widget->window, &x, &y);
1638                 x %= sx; if (x < 0) x = 0;
1639                 y %= sy; if (y < 0) y = 0;
1640                 gdk_window_move(widget->window, x, y);
1641                 gdk_window_raise(widget->window);
1642                 break;
1643         case SEPARATE_MESSAGE:
1644                 widget = mainwin->win.sep_message.messagewin;
1645                 gdk_window_get_origin(widget->window, &x, &y);
1646                 x %= sx; if (x < 0) x = 0;
1647                 y %= sy; if (y < 0) y = 0;
1648                 gdk_window_move(widget->window, x, y);
1649                 gdk_window_raise(widget->window);
1650                 break;
1651         case SEPARATE_BOTH:
1652                 widget = mainwin->win.sep_both.folderwin;
1653                 gdk_window_get_origin(widget->window, &x, &y);
1654                 x %= sx; if (x < 0) x = 0;
1655                 y %= sy; if (y < 0) y = 0;
1656                 gdk_window_move(widget->window, x, y);
1657                 gdk_window_raise(widget->window);
1658                 widget = mainwin->win.sep_both.messagewin;
1659                 gdk_window_get_origin(widget->window, &x, &y);
1660                 x %= sx; if (x < 0) x = 0;
1661                 y %= sy; if (y < 0) y = 0;
1662                 gdk_window_move(widget->window, x, y);
1663                 gdk_window_raise(widget->window);
1664                 break;
1665         default:
1666                 break;
1667         }
1668 }
1669
1670 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1671 {
1672         GtkWidget *folderwin = NULL;
1673         GtkWidget *messagewin = NULL;
1674         GtkWidget *hpaned;
1675         GtkWidget *vpaned;
1676         GtkWidget *vbox_body = mainwin->vbox_body;
1677         GtkItemFactory *ifactory = mainwin->menu_factory;
1678         GtkWidget *menuitem;
1679
1680         debug_print("Setting widgets...");
1681
1682         /* create separated window(s) if needed */
1683         if (type & SEPARATE_FOLDER) {
1684                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1685                 gtk_window_set_title(GTK_WINDOW(folderwin),
1686                                      _("Sylpheed - Folder View"));
1687                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1688                                        "folder_view", "Sylpheed");
1689                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1690                                       TRUE, TRUE, FALSE);
1691                 gtk_widget_set_usize(folderwin, -1,
1692                                      prefs_common.mainview_height);
1693                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1694                                                BORDER_WIDTH);
1695                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1696                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1697                                    mainwin);
1698         }
1699         if (type & SEPARATE_MESSAGE) {
1700                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1701                 gtk_window_set_title(GTK_WINDOW(messagewin),
1702                                      _("Sylpheed - Message View"));
1703                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1704                                        "message_view", "Sylpheed");
1705                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1706                                       TRUE, TRUE, FALSE);
1707                 gtk_widget_set_usize
1708                         (messagewin, prefs_common.mainview_width,
1709                          prefs_common.mainview_height
1710                          - prefs_common.summaryview_height
1711                          + DEFAULT_HEADERVIEW_HEIGHT);
1712                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1713                                                BORDER_WIDTH);
1714                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1715                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1716                                    mainwin);
1717         }
1718
1719         switch (type) {
1720         case SEPARATE_NONE:
1721                 hpaned = gtk_hpaned_new();
1722                 gtk_widget_show(hpaned);
1723                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1724                 gtk_paned_add1(GTK_PANED(hpaned),
1725                                GTK_WIDGET_PTR(mainwin->folderview));
1726
1727                 vpaned = gtk_vpaned_new();
1728                 if (messageview_is_visible(mainwin->messageview)) {
1729                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1730                         gtk_paned_add1(GTK_PANED(vpaned),
1731                                        GTK_WIDGET_PTR(mainwin->summaryview));
1732                 } else {
1733                         gtk_paned_add2(GTK_PANED(hpaned),
1734                                        GTK_WIDGET_PTR(mainwin->summaryview));
1735                         gtk_widget_ref(vpaned);
1736                 }
1737                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1738                                      prefs_common.summaryview_width,
1739                                      prefs_common.summaryview_height);
1740                 gtk_paned_add2(GTK_PANED(vpaned),
1741                                GTK_WIDGET_PTR(mainwin->messageview));
1742                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1743                                      prefs_common.mainview_width, -1);
1744                 gtk_widget_set_usize(mainwin->window,
1745                                      prefs_common.folderview_width +
1746                                      prefs_common.mainview_width,
1747                                      prefs_common.mainwin_height);
1748                 gtk_widget_show_all(vpaned);
1749
1750                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1751                  * lose track of its visibility state */
1752                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1753                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1754
1755                 mainwin->win.sep_none.hpaned = hpaned;
1756                 mainwin->win.sep_none.vpaned = vpaned;
1757                 break;
1758         case SEPARATE_FOLDER:
1759                 vpaned = gtk_vpaned_new();
1760                 if (messageview_is_visible(mainwin->messageview)) {
1761                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1762                                            TRUE, TRUE, 0);
1763                         gtk_paned_add1(GTK_PANED(vpaned),
1764                                        GTK_WIDGET_PTR(mainwin->summaryview));
1765                 } else {
1766                         gtk_box_pack_start(GTK_BOX(vbox_body),
1767                                            GTK_WIDGET_PTR(mainwin->summaryview),
1768                                            TRUE, TRUE, 0);
1769                         gtk_widget_ref(vpaned);
1770                 }
1771                 gtk_paned_add2(GTK_PANED(vpaned),
1772                                GTK_WIDGET_PTR(mainwin->messageview));
1773                 gtk_widget_show_all(vpaned);
1774                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1775                                      prefs_common.summaryview_width,
1776                                      prefs_common.summaryview_height);
1777                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1778                                      prefs_common.mainview_width, -1);
1779                 gtk_widget_set_usize(mainwin->window,
1780                                      prefs_common.mainview_width,
1781                                      prefs_common.mainview_height);
1782
1783                 gtk_container_add(GTK_CONTAINER(folderwin),
1784                                   GTK_WIDGET_PTR(mainwin->folderview));
1785
1786                 mainwin->win.sep_folder.folderwin = folderwin;
1787                 mainwin->win.sep_folder.vpaned    = vpaned;
1788
1789                 gtk_widget_show_all(folderwin);
1790                 
1791                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1792                  * lose track of its visibility state */
1793                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1794                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1795                 break;
1796         case SEPARATE_MESSAGE:
1797                 hpaned = gtk_hpaned_new();
1798                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1799
1800                 gtk_paned_add1(GTK_PANED(hpaned),
1801                                GTK_WIDGET_PTR(mainwin->folderview));
1802                 gtk_paned_add2(GTK_PANED(hpaned),
1803                                GTK_WIDGET_PTR(mainwin->summaryview));
1804                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1805                                      prefs_common.summaryview_width,
1806                                      prefs_common.summaryview_height);
1807                 gtk_widget_set_usize(mainwin->window,
1808                                      prefs_common.folderview_width +
1809                                      prefs_common.mainview_width,
1810                                      prefs_common.mainwin_height);
1811                 gtk_widget_show_all(hpaned);
1812                 gtk_container_add(GTK_CONTAINER(messagewin),
1813                                   GTK_WIDGET_PTR(mainwin->messageview));
1814
1815                 mainwin->win.sep_message.messagewin = messagewin;
1816                 mainwin->win.sep_message.hpaned     = hpaned;
1817
1818                 gtk_widget_show_all(messagewin);
1819                 
1820                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1821                  * lose track of its visibility state */
1822                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1823                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1824                 break;
1825         case SEPARATE_BOTH:
1826                 gtk_box_pack_start(GTK_BOX(vbox_body),
1827                                    GTK_WIDGET_PTR(mainwin->summaryview),
1828                                    TRUE, TRUE, 0);
1829                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1830                                      prefs_common.summaryview_width,
1831                                      prefs_common.summaryview_height);
1832                 gtk_widget_set_usize(mainwin->window,
1833                                      prefs_common.mainview_width,
1834                                      prefs_common.mainwin_height);
1835                 gtk_container_add(GTK_CONTAINER(folderwin),
1836                                   GTK_WIDGET_PTR(mainwin->folderview));
1837                 gtk_container_add(GTK_CONTAINER(messagewin),
1838                                   GTK_WIDGET_PTR(mainwin->messageview));
1839
1840                 mainwin->win.sep_both.folderwin = folderwin;
1841                 mainwin->win.sep_both.messagewin = messagewin;
1842
1843                 gtk_widget_show_all(folderwin);
1844                 gtk_widget_show_all(messagewin);
1845
1846                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1847                  * lose track of its visibility state */
1848                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1849                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1850                 break;
1851         }
1852
1853         mainwin->type = type;
1854
1855         mainwin->messageview->visible = TRUE;
1856
1857         /* toggle menu state */
1858         menuitem = gtk_item_factory_get_item
1859                 (ifactory, "/View/Show or hide/Folder tree");
1860         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1861         menuitem = gtk_item_factory_get_item
1862                 (ifactory, "/View/Show or hide/Message view");
1863         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1864
1865         menuitem = gtk_item_factory_get_item
1866                 (ifactory, "/View/Separate folder tree");
1867         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1868                                        ((type & SEPARATE_FOLDER) != 0));
1869         menuitem = gtk_item_factory_get_item
1870                 (ifactory, "/View/Separate message view");
1871         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1872                                        ((type & SEPARATE_MESSAGE) != 0));
1873
1874         debug_print("done.\n");
1875 }
1876
1877 #if 0
1878 static void toolbar_account_button_pressed(GtkWidget *widget,
1879                                            GdkEventButton *event,
1880                                            gpointer data)
1881 {
1882         MainWindow *mainwin = (MainWindow *)data;
1883
1884         if (!event) return;
1885         if (event->button != 3) return;
1886
1887         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1888         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1889                             widget);
1890
1891         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1892                        menu_button_position, widget,
1893                        event->button, event->time);
1894 }
1895 #endif
1896
1897 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1898                                     gpointer data)
1899 {
1900         MainWindow *mainwin = (MainWindow *)data;
1901
1902         if (!event) return;
1903
1904         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1905         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1906                             widget);
1907
1908         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1909                        menu_button_position, widget,
1910                        event->button, event->time);
1911 }
1912
1913 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1914 {
1915         MainWindow *mainwin = (MainWindow *)data;
1916         GtkWidget *button;
1917
1918         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1919         if (!button) return;
1920         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1921         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1922         manage_window_focus_in(mainwin->window, NULL, NULL);
1923 }
1924
1925 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1926                                  gpointer data)
1927 {
1928         MainWindow *mainwin = (MainWindow *)data;
1929
1930         if (mainwin->lock_count == 0)
1931                 app_exit_cb(data, 0, widget);
1932
1933         return TRUE;
1934 }
1935
1936 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1937                                    gpointer data)
1938 {
1939         MainWindow *mainwin = (MainWindow *)data;
1940         GtkWidget *menuitem;
1941
1942         menuitem = gtk_item_factory_get_item
1943                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1944         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1945
1946         return TRUE;
1947 }
1948
1949 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1950                                     gpointer data)
1951 {
1952         MainWindow *mainwin = (MainWindow *)data;
1953         GtkWidget *menuitem;
1954
1955         menuitem = gtk_item_factory_get_item
1956                 (mainwin->menu_factory, "/View/Show or hide/Message view");
1957         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1958
1959         return TRUE;
1960 }
1961
1962 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1963                            GtkWidget *widget)
1964 {
1965         main_window_add_mailbox(mainwin);
1966 }
1967
1968 static void add_mbox_cb(MainWindow *mainwin, guint action,
1969                         GtkWidget *widget)
1970 {
1971         main_window_add_mbox(mainwin);
1972 }
1973
1974 static void update_folderview_cb(MainWindow *mainwin, guint action,
1975                                  GtkWidget *widget)
1976 {
1977         summary_show(mainwin->summaryview, NULL);
1978         folderview_check_new_all();
1979 }
1980
1981 static void new_folder_cb(MainWindow *mainwin, guint action,
1982                           GtkWidget *widget)
1983 {
1984         folderview_new_folder(mainwin->folderview);
1985 }
1986
1987 static void rename_folder_cb(MainWindow *mainwin, guint action,
1988                              GtkWidget *widget)
1989 {
1990         folderview_rename_folder(mainwin->folderview);
1991 }
1992
1993 static void delete_folder_cb(MainWindow *mainwin, guint action,
1994                              GtkWidget *widget)
1995 {
1996         folderview_delete_folder(mainwin->folderview);
1997 }
1998
1999 static void import_mbox_cb(MainWindow *mainwin, guint action,
2000                            GtkWidget *widget)
2001 {
2002         import_mbox(mainwin->summaryview->folder_item);
2003 }
2004
2005 static void export_mbox_cb(MainWindow *mainwin, guint action,
2006                            GtkWidget *widget)
2007 {
2008         export_mbox(mainwin->summaryview->folder_item);
2009 }
2010
2011 static void empty_trash_cb(MainWindow *mainwin, guint action,
2012                            GtkWidget *widget)
2013 {
2014         main_window_empty_trash(mainwin, TRUE);
2015 }
2016
2017 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2018 {
2019         summary_save_as(mainwin->summaryview);
2020 }
2021
2022 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2023 {
2024         summary_print(mainwin->summaryview);
2025 }
2026
2027 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2028 {
2029         if (prefs_common.confirm_on_exit) {
2030                 if (alertpanel(_("Exit"), _("Exit this program?"),
2031                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2032                         return;
2033                 manage_window_focus_in(mainwin->window, NULL, NULL);
2034         }
2035
2036         app_will_exit(widget, mainwin);
2037 }
2038
2039 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2040 {
2041         if (action == 1)
2042                 summary_search(mainwin->summaryview);
2043         else
2044                 message_search(mainwin->messageview);
2045 }
2046
2047 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2048                              GtkWidget *widget)
2049 {
2050         gboolean active;
2051
2052         active = GTK_CHECK_MENU_ITEM(widget)->active;
2053
2054         switch (mainwin->type) {
2055         case SEPARATE_NONE:
2056         case SEPARATE_MESSAGE:
2057 #if 0
2058                 if (active)
2059                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2060                 else
2061                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2062 #endif
2063                 break;
2064         case SEPARATE_FOLDER:
2065                 debug_print("separate folder\n");
2066                 if (active)
2067                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2068                 else
2069                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2070                 break;
2071         case SEPARATE_BOTH:
2072                 if (active)
2073                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2074                 else
2075                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2076                 break;
2077         }
2078 }
2079
2080 static void toggle_message_cb(MainWindow *mainwin, guint action,
2081                               GtkWidget *widget)
2082 {
2083         gboolean active;
2084
2085         active = GTK_CHECK_MENU_ITEM(widget)->active;
2086
2087         if (active != messageview_is_visible(mainwin->messageview))
2088                 summary_toggle_view(mainwin->summaryview);
2089 }
2090
2091 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2092                               GtkWidget *widget)
2093 {
2094         switch ((ToolbarStyle)action) {
2095         case TOOLBAR_NONE:
2096                 gtk_widget_hide(mainwin->handlebox);
2097         case TOOLBAR_ICON:
2098                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2099                                       GTK_TOOLBAR_ICONS);
2100                 break;
2101         case TOOLBAR_TEXT:
2102                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2103                                       GTK_TOOLBAR_TEXT);
2104                 break;
2105         case TOOLBAR_BOTH:
2106                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2107                                       GTK_TOOLBAR_BOTH);
2108                 break;
2109         }
2110
2111         if (action != TOOLBAR_NONE) {
2112                 gtk_widget_show(mainwin->handlebox);
2113                 gtk_widget_queue_resize(mainwin->handlebox);
2114         }
2115
2116         mainwin->toolbar_style = (ToolbarStyle)action;
2117         prefs_common.toolbar_style = (ToolbarStyle)action;
2118 }
2119
2120 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2121                                 GtkWidget *widget)
2122 {
2123         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2124                 gtk_widget_show(mainwin->hbox_stat);
2125                 prefs_common.show_statusbar = TRUE;
2126         } else {
2127                 gtk_widget_hide(mainwin->hbox_stat);
2128                 prefs_common.show_statusbar = FALSE;
2129         }
2130 }
2131
2132 static void toggle_searchbar_cb(MainWindow *mainwin, guint action,
2133                                 GtkWidget *widget)
2134 {
2135         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2136                 gtk_widget_show(mainwin->summaryview->hbox_search);
2137                 prefs_common.show_searchbar = TRUE;
2138         } else {
2139                 gtk_widget_hide(mainwin->summaryview->hbox_search);
2140                 prefs_common.show_searchbar = FALSE;
2141         }
2142 }
2143
2144 static void separate_widget_cb(MainWindow *mainwin, guint action,
2145                                GtkWidget *widget)
2146 {
2147         SeparateType type;
2148
2149         if (GTK_CHECK_MENU_ITEM(widget)->active)
2150                 type = mainwin->type | action;
2151         else
2152                 type = mainwin->type & ~action;
2153
2154         main_window_separation_change(mainwin, type);
2155
2156         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2157         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2158 }
2159
2160 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2161 {
2162         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2163                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2164         } else {
2165                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);           
2166         }
2167 }
2168
2169 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2170 {
2171         MainWindow *mainwin;
2172         GtkItemFactory *ifactory;
2173         GtkCheckMenuItem *menuitem;
2174
2175         mainwin = (MainWindow *) data;
2176         
2177         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2178         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2179         
2180         g_return_if_fail(mainwin != NULL);
2181         g_return_if_fail(menuitem != NULL);
2182         
2183         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2184                 /* go offline */
2185                 gtk_widget_hide (mainwin->online_switch);
2186                 gtk_widget_show (mainwin->offline_switch);
2187                 menuitem->active = TRUE;
2188                 prefs_common.work_offline = TRUE;
2189                 inc_autocheck_timer_remove();           
2190         } else {
2191                 /*go online */
2192                 gtk_widget_hide (mainwin->offline_switch);
2193                 gtk_widget_show (mainwin->online_switch);
2194                 menuitem->active = FALSE;
2195                 prefs_common.work_offline = FALSE;
2196                 inc_autocheck_timer_set();
2197         }
2198 }
2199
2200 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2201                                 GtkWidget *widget)
2202 {
2203         addressbook_open(NULL);
2204 }
2205
2206 static void log_window_show_cb(MainWindow *mainwin, guint action,
2207                                GtkWidget *widget)
2208 {
2209         log_window_show(mainwin->logwin);
2210 }
2211
2212 static void sel_download_cb(MainWindow *mainwin, guint action,
2213                                GtkWidget *widget)
2214 {
2215         selective_download(mainwin);
2216 }
2217
2218 static void prefs_toolbar_cb(MainWindow *mainwin, guint action,
2219                                GtkWidget *widget)
2220 {
2221         prefs_toolbar();
2222 }
2223
2224
2225 void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2226 {
2227         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2228 }
2229
2230 void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2231                                     GtkWidget *widget)
2232 {
2233         inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2234 }
2235
2236 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2237 {
2238         inc_cancel_all();
2239 }
2240
2241 void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2242 {
2243         GList *list;
2244
2245         if (prefs_common.work_offline)
2246                 if (alertpanel(_("Offline warning"), 
2247                                _("You're working offline. Override?"),
2248                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2249                 return;
2250
2251         for (list = folder_get_list(); list != NULL; list = list->next) {
2252                 Folder *folder = list->data;
2253
2254                 if (folder->queue) {
2255                         if (procmsg_send_queue
2256                                 (folder->queue, prefs_common.savemsg) < 0)
2257                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2258                         statusbar_pop_all();
2259                         folder_item_scan(folder->queue);
2260                         folderview_update_item(folder->queue, TRUE);
2261                 }
2262         }
2263 }
2264
2265 void compose_mail_cb(MainWindow *mainwin, guint action,
2266                             GtkWidget *widget)
2267 {
2268         PrefsAccount * ac;
2269         GList * list;
2270         GList * cur;
2271
2272         if (mainwin->summaryview->folder_item) {
2273                 ac = mainwin->summaryview->folder_item->folder->account;
2274                 if (ac && ac->protocol != A_NNTP) {
2275                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2276                         return;
2277                 }
2278         }
2279
2280         if(cur_account && (cur_account->protocol != A_NNTP)) {
2281                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2282                 return;
2283         }
2284
2285         list = account_get_list();
2286         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2287                 ac = (PrefsAccount *) cur->data;
2288                 if (ac->protocol != A_NNTP) {
2289                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2290                         return;
2291                 }
2292         }
2293 }
2294
2295 void compose_news_cb(MainWindow *mainwin, guint action,
2296                             GtkWidget *widget)
2297 {
2298         PrefsAccount * ac = NULL;
2299         GList * list;
2300         GList * cur;
2301
2302         if (mainwin->summaryview->folder_item) {
2303                 ac = mainwin->summaryview->folder_item->folder->account;
2304                 if (ac && ac->protocol == A_NNTP) {
2305                         compose_new(ac,
2306                                     mainwin->summaryview->folder_item->path,
2307                                     NULL);
2308                         return;
2309                 }
2310         }
2311
2312         list = account_get_list();
2313         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2314                 ac = (PrefsAccount *) cur->data;
2315                 if (ac->protocol == A_NNTP) {
2316                         compose_new(ac, NULL, NULL);
2317                         return;
2318                 }
2319         }
2320 }
2321
2322 void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2323 {
2324         summary_reply(mainwin->summaryview, (ComposeMode)action);
2325 }
2326
2327 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2328 {
2329         summary_move_to(mainwin->summaryview);
2330 }
2331
2332 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2333 {
2334         summary_copy_to(mainwin->summaryview);
2335 }
2336
2337 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2338 {
2339         summary_delete(mainwin->summaryview);
2340 }
2341
2342 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2343 {
2344         summary_open_msg(mainwin->summaryview);
2345 }
2346
2347 static void view_source_cb(MainWindow *mainwin, guint action,
2348                            GtkWidget *widget)
2349 {
2350         summary_view_source(mainwin->summaryview);
2351 }
2352
2353 static void show_all_header_cb(MainWindow *mainwin, guint action,
2354                                GtkWidget *widget)
2355 {
2356         if (mainwin->menu_lock_count) return;
2357         summary_display_msg_selected(mainwin->summaryview,
2358                                      GTK_CHECK_MENU_ITEM(widget)->active);
2359 }
2360
2361 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2362 {
2363         summary_reedit(mainwin->summaryview);
2364 }
2365
2366 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2367 {
2368         summary_mark(mainwin->summaryview);
2369 }
2370
2371 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2372 {
2373         summary_unmark(mainwin->summaryview);
2374 }
2375
2376 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2377                               GtkWidget *widget)
2378 {
2379         summary_mark_as_unread(mainwin->summaryview);
2380 }
2381
2382 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2383                             GtkWidget *widget)
2384 {
2385         summary_mark_as_read(mainwin->summaryview);
2386 }
2387
2388 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2389                              GtkWidget *widget)
2390 {
2391         summary_mark_all_read(mainwin->summaryview);
2392 }
2393
2394 static void add_address_cb(MainWindow *mainwin, guint action,
2395                            GtkWidget *widget)
2396 {
2397         summary_add_address(mainwin->summaryview);
2398 }
2399
2400 static void set_charset_cb(MainWindow *mainwin, guint action,
2401                            GtkWidget *widget)
2402 {
2403         const gchar *str;
2404
2405         str = conv_get_charset_str((CharSet)action);
2406         g_free(prefs_common.force_charset);
2407         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2408
2409         summary_redisplay_msg(mainwin->summaryview);
2410
2411         debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2412 }
2413
2414 static void hide_read_messages (MainWindow *mainwin, guint action,
2415                                 GtkWidget *widget)
2416 {
2417         if (!mainwin->summaryview->folder_item
2418             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2419                 return;
2420         summary_toggle_show_read_messages(mainwin->summaryview);
2421 }
2422
2423 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2424 {
2425         if (mainwin->menu_lock_count) return;
2426         if (!mainwin->summaryview->folder_item) return;
2427
2428         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2429                 summary_thread_build(mainwin->summaryview);
2430                 mainwin->summaryview->folder_item->threaded = TRUE;
2431         } else {
2432                 summary_unthread(mainwin->summaryview);
2433                 mainwin->summaryview->folder_item->threaded = FALSE;
2434         }
2435 }
2436
2437 static void expand_threads_cb(MainWindow *mainwin, guint action,
2438                               GtkWidget *widget)
2439 {
2440         summary_expand_threads(mainwin->summaryview);
2441 }
2442
2443 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2444                                 GtkWidget *widget)
2445 {
2446         summary_collapse_threads(mainwin->summaryview);
2447 }
2448
2449 static void set_display_item_cb(MainWindow *mainwin, guint action,
2450                                 GtkWidget *widget)
2451 {
2452         prefs_summary_column_open();
2453 }
2454
2455 static void sort_summary_cb(MainWindow *mainwin, guint action,
2456                             GtkWidget *widget)
2457 {
2458         FolderItem *item = mainwin->summaryview->folder_item;
2459         GtkWidget *menuitem;
2460
2461         if (mainwin->menu_lock_count) return;
2462         if (item) {
2463                 menuitem = gtk_item_factory_get_item
2464                         (mainwin->menu_factory, "/View/Sort/Ascending");
2465                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2466                              GTK_CHECK_MENU_ITEM(menuitem)->active
2467                              ? SORT_ASCENDING : SORT_DESCENDING);
2468         }
2469 }
2470
2471 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2472                                  GtkWidget *widget)
2473 {
2474         FolderItem *item = mainwin->summaryview->folder_item;
2475
2476         if (mainwin->menu_lock_count) return;
2477         if (item)
2478                 summary_sort(mainwin->summaryview,
2479                              item->sort_key, (FolderSortType)action);
2480 }
2481
2482 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2483                                   GtkWidget *widget)
2484 {
2485         summary_attract_by_subject(mainwin->summaryview);
2486 }
2487
2488 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2489                                  GtkWidget *widget)
2490 {
2491         summary_delete_duplicated(mainwin->summaryview);
2492 }
2493
2494 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2495 {
2496         summary_filter(mainwin->summaryview);
2497 }
2498
2499 static void execute_summary_cb(MainWindow *mainwin, guint action,
2500                                GtkWidget *widget)
2501 {
2502         summary_execute(mainwin->summaryview);
2503 }
2504
2505 static void update_summary_cb(MainWindow *mainwin, guint action,
2506                               GtkWidget *widget)
2507 {
2508         FolderItem *fitem;
2509         FolderView *folderview = mainwin->folderview;
2510
2511         if (!mainwin->summaryview->folder_item) return;
2512         if (!folderview->opened) return;
2513
2514         folder_update_op_count();
2515
2516         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2517                                             folderview->opened);
2518         if (!fitem) return;
2519
2520         folder_item_scan(fitem);
2521         summary_show(mainwin->summaryview, fitem);
2522 }
2523
2524 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2525 {
2526         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2527 }
2528
2529 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2530 {
2531         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2532 }
2533
2534 static void prev_unread_cb(MainWindow *mainwin, guint action,
2535                            GtkWidget *widget)
2536 {
2537         summary_select_prev_unread(mainwin->summaryview);
2538 }
2539
2540 void next_unread_cb(MainWindow *mainwin, guint action,
2541                            GtkWidget *widget)
2542 {
2543         summary_select_next_unread(mainwin->summaryview);
2544 }
2545
2546 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2547 {
2548         summary_select_prev_new(mainwin->summaryview);
2549 }
2550
2551 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2552 {
2553         summary_select_next_new(mainwin->summaryview);
2554 }
2555
2556 static void prev_marked_cb(MainWindow *mainwin, guint action,
2557                            GtkWidget *widget)
2558 {
2559         summary_select_prev_marked(mainwin->summaryview);
2560 }
2561
2562 static void next_marked_cb(MainWindow *mainwin, guint action,
2563                            GtkWidget *widget)
2564 {
2565         summary_select_next_marked(mainwin->summaryview);
2566 }
2567
2568 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2569                             GtkWidget *widget)
2570 {
2571         summary_select_prev_labeled(mainwin->summaryview);
2572 }
2573
2574 static void next_labeled_cb(MainWindow *mainwin, guint action,
2575                             GtkWidget *widget)
2576 {
2577         summary_select_next_labeled(mainwin->summaryview);
2578 }
2579
2580 static void goto_folder_cb(MainWindow *mainwin, guint action,
2581                            GtkWidget *widget)
2582 {
2583         FolderItem *to_folder;
2584
2585         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2586
2587         if (to_folder)
2588                 folderview_select(mainwin->folderview, to_folder);
2589 }
2590
2591 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2592 {
2593         messageview_copy_clipboard(mainwin->messageview);
2594 }
2595
2596 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2597 {
2598         MessageView *msgview = mainwin->messageview;
2599
2600         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2601                 summary_select_all(mainwin->summaryview);
2602         else if (messageview_is_visible(msgview) &&
2603                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2604                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2605                 messageview_select_all(mainwin->messageview);
2606 }
2607
2608 static void selthread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2609 {
2610         if (messageview_is_visible(mainwin->summaryview->messageview))
2611                 summary_select_thread(mainwin->summaryview);
2612 }
2613
2614 static void create_filter_cb(MainWindow *mainwin, guint action,
2615                              GtkWidget *widget)
2616 {
2617         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2618 }
2619
2620 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2621                                  GtkWidget *widget)
2622 {
2623         prefs_common_open();
2624 }
2625
2626 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2627                                  GtkWidget *widget)
2628 {
2629         prefs_filter_open(NULL, NULL);
2630 }
2631
2632 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2633                                   GtkWidget *widget)
2634 {
2635         prefs_scoring_open(NULL);
2636 }
2637
2638 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2639                                     GtkWidget *widget)
2640 {
2641         prefs_filtering_open(NULL, NULL, NULL);
2642 }
2643
2644 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2645                                    GtkWidget *widget)
2646 {
2647         prefs_template_open();
2648 }
2649
2650 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2651                                   GtkWidget *widget)
2652 {
2653         prefs_actions_open(mainwin);
2654 }
2655
2656 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2657                                   GtkWidget *widget)
2658 {
2659         if (!cur_account) {
2660                 new_account_cb(mainwin, 0, widget);
2661         } else {
2662                 gboolean prev_default = cur_account->is_default;
2663
2664                 prefs_account_open(cur_account);
2665                 if (!prev_default && cur_account->is_default)
2666                         account_set_as_default(cur_account);
2667                 account_save_config_all();
2668                 account_set_menu();
2669                 main_window_reflect_prefs_all();
2670         }
2671 }
2672
2673 static void new_account_cb(MainWindow *mainwin, guint action,
2674                            GtkWidget *widget)
2675 {
2676         account_edit_open();
2677         if (!compose_get_compose_list()) account_add();
2678 }
2679
2680 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2681 {
2682         cur_account = (PrefsAccount *)data;
2683         main_window_reflect_prefs_all();
2684 }
2685
2686 static void manual_open_cb(MainWindow *mainwin, guint action,
2687                            GtkWidget *widget)
2688 {
2689         manual_open((ManualLang)action);
2690 }
2691
2692 static void faq_open_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2693 {
2694         faq_open((ManualLang)action);
2695 }
2696
2697 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2698 {
2699         MainWindow *mainwin = (MainWindow *)data;
2700         gchar *str;
2701
2702         if (item->path)
2703                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2704                                       LOCAL_FOLDER(folder)->rootpath,
2705                                       G_DIR_SEPARATOR,
2706                                       item->path);
2707         else
2708                 str = g_strdup_printf(_("Scanning folder %s ..."),
2709                                       LOCAL_FOLDER(folder)->rootpath);
2710
2711         STATUSBAR_PUSH(mainwin, str);
2712         STATUSBAR_POP(mainwin);
2713         g_free(str);
2714 }
2715
2716 #define BREAK_ON_MODIFIER_KEY() \
2717         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2718
2719 static void key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
2720 {
2721         MainWindow *mainwin = (MainWindow*) data;
2722         
2723         if (!mainwin || !event) return;
2724                 
2725         switch (event->keyval) {
2726         case GDK_Q:             /* Quit */
2727                 BREAK_ON_MODIFIER_KEY();
2728
2729                 app_exit_cb(mainwin, 0, NULL);
2730                 return;
2731         default:
2732                 break;
2733         }
2734 }
2735
2736 #undef BREAK_ON_MODIFIER_KEY
2737
2738 static void set_toolbar_style(MainWindow *mainwin)
2739 {
2740         switch (prefs_common.toolbar_style) {
2741         case TOOLBAR_NONE:
2742                 gtk_widget_hide(mainwin->handlebox);
2743                 break;
2744         case TOOLBAR_ICON:
2745                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2746                                       GTK_TOOLBAR_ICONS);
2747                 break;
2748         case TOOLBAR_TEXT:
2749                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2750                                       GTK_TOOLBAR_TEXT);
2751                 break;
2752         case TOOLBAR_BOTH:
2753                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2754                                       GTK_TOOLBAR_BOTH);
2755                 break;
2756         }
2757         
2758         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
2759                 gtk_widget_show(mainwin->handlebox);
2760                 gtk_widget_queue_resize(mainwin->handlebox);
2761         }
2762 }
2763
2764 /*
2765  * Harvest addresses for selected folder.
2766  */
2767 static void addr_harvest_cb( MainWindow *mainwin,
2768                             guint action,
2769                             GtkWidget *widget )
2770 {
2771         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2772 }
2773
2774 /*
2775  * Harvest addresses for selected messages in summary view.
2776  */
2777 static void addr_harvest_msg_cb( MainWindow *mainwin,
2778                             guint action,
2779                             GtkWidget *widget )
2780 {
2781         summary_harvest_address( mainwin->summaryview );
2782 }
2783
2784 /*
2785 * End of Source.
2786 */
2787