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