Readded custom widget support in alertpanel lost in last sync
[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                 if (prefs_common.immediate_exec)
1059                         gtk_widget_hide(mainwin->toolbar->exec_btn);
1060                 else
1061                         gtk_widget_show(mainwin->toolbar->exec_btn);
1062
1063                 summary_redisplay_msg(mainwin->summaryview);
1064                 headerview_set_visibility(mainwin->messageview->headerview,
1065                                           prefs_common.display_header_pane);
1066         }
1067 }
1068
1069 void main_window_set_summary_column(void)
1070 {
1071         GList *cur;
1072         MainWindow *mainwin;
1073
1074         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1075                 mainwin = (MainWindow *)cur->data;
1076                 summary_set_column_order(mainwin->summaryview);
1077         }
1078 }
1079
1080 void main_window_set_account_menu(GList *account_list)
1081 {
1082         GList *cur, *cur_ac, *cur_item;
1083         GtkWidget *menuitem;
1084         MainWindow *mainwin;
1085         PrefsAccount *ac_prefs;
1086
1087         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1088                 mainwin = (MainWindow *)cur->data;
1089
1090                 /* destroy all previous menu item */
1091                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1092                 while (cur_item != NULL) {
1093                         GList *next = cur_item->next;
1094                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1095                         cur_item = next;
1096                 }
1097
1098                 for (cur_ac = account_list; cur_ac != NULL;
1099                      cur_ac = cur_ac->next) {
1100                         ac_prefs = (PrefsAccount *)cur_ac->data;
1101
1102                         menuitem = gtk_menu_item_new_with_label
1103                                 (ac_prefs->account_name
1104                                  ? ac_prefs->account_name : _("Untitled"));
1105                         gtk_widget_show(menuitem);
1106                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1107                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1108                                            GTK_SIGNAL_FUNC(account_menu_cb),
1109                                            ac_prefs);
1110                 }
1111         }
1112 }
1113
1114 static void main_window_show_cur_account(MainWindow *mainwin)
1115 {
1116         gchar *buf;
1117         gchar *ac_name;
1118
1119         ac_name = g_strdup(cur_account
1120                            ? (cur_account->account_name
1121                               ? cur_account->account_name : _("Untitled"))
1122                            : _("none"));
1123
1124         if (cur_account)
1125                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1126         else
1127                 buf = g_strdup(PROG_VERSION);
1128         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1129         g_free(buf);
1130
1131         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1132         gtk_widget_queue_resize(mainwin->ac_button);
1133
1134         g_free(ac_name);
1135 }
1136
1137 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1138 {
1139         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1140         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1141         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1142
1143         debug_print("Changing window separation type from %d to %d\n",
1144                     mainwin->type, type);
1145
1146         if (mainwin->type == type) return;
1147
1148         /* remove widgets from those containers */
1149         gtk_widget_ref(folder_wid);
1150         gtk_widget_ref(summary_wid);
1151         gtk_widget_ref(message_wid);
1152         gtkut_container_remove
1153                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1154         gtkut_container_remove
1155                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1156         gtkut_container_remove
1157                 (GTK_CONTAINER(message_wid->parent), message_wid);
1158
1159         /* clean containers */
1160         switch (mainwin->type) {
1161         case SEPARATE_NONE:
1162                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1163                 break;
1164         case SEPARATE_FOLDER:
1165                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1166                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1167                 break;
1168         case SEPARATE_MESSAGE:
1169                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1170                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1171                 break;
1172         case SEPARATE_BOTH:
1173                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1174                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1175                 break;
1176         }
1177
1178         gtk_widget_hide(mainwin->window);
1179         main_window_set_widgets(mainwin, type);
1180         gtk_widget_show(mainwin->window);
1181
1182         gtk_widget_unref(folder_wid);
1183         gtk_widget_unref(summary_wid);
1184         gtk_widget_unref(message_wid);
1185 }
1186
1187 void main_window_toggle_message_view(MainWindow *mainwin)
1188 {
1189         SummaryView *summaryview = mainwin->summaryview;
1190         union CompositeWin *cwin = &mainwin->win;
1191         GtkWidget *vpaned = NULL;
1192         GtkWidget *container = NULL;
1193         GtkWidget *msgwin = NULL;
1194
1195         switch (mainwin->type) {
1196         case SEPARATE_NONE:
1197                 vpaned = cwin->sep_none.vpaned;
1198                 container = cwin->sep_none.hpaned;
1199                 break;
1200         case SEPARATE_FOLDER:
1201                 vpaned = cwin->sep_folder.vpaned;
1202                 container = mainwin->vbox_body;
1203                 break;
1204         case SEPARATE_MESSAGE:
1205                 msgwin = mainwin->win.sep_message.messagewin;
1206                 break;
1207         case SEPARATE_BOTH:
1208                 msgwin = mainwin->win.sep_both.messagewin;
1209                 break;
1210         }
1211
1212         if (msgwin) {
1213                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1214                         gtk_widget_hide(msgwin);
1215                         mainwin->messageview->visible = FALSE;
1216                         summaryview->displayed = NULL;
1217                 } else {
1218                         gtk_widget_show(msgwin);
1219                         mainwin->messageview->visible = TRUE;
1220                 }
1221         } else if (vpaned->parent != NULL) {
1222                 mainwin->messageview->visible = FALSE;
1223                 summaryview->displayed = NULL;
1224                 gtk_widget_ref(vpaned);
1225                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1226                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1227                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1228                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1229         } else {
1230                 mainwin->messageview->visible = TRUE;
1231                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1232                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1233                 gtk_widget_unref(vpaned);
1234                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1235                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1236         }
1237
1238         main_window_set_menu_sensitive(mainwin);
1239
1240         gtk_widget_grab_focus(summaryview->ctree);
1241 }
1242
1243 void main_window_get_size(MainWindow *mainwin)
1244 {
1245         GtkAllocation *allocation;
1246
1247         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1248
1249         prefs_common.summaryview_width  = allocation->width;
1250
1251         if ((mainwin->type == SEPARATE_NONE ||
1252              mainwin->type == SEPARATE_FOLDER) &&
1253             messageview_is_visible(mainwin->messageview))
1254                 prefs_common.summaryview_height = allocation->height;
1255
1256         prefs_common.mainview_width     = allocation->width;
1257
1258         allocation = &mainwin->window->allocation;
1259
1260         prefs_common.mainview_height = allocation->height;
1261         prefs_common.mainwin_width   = allocation->width;
1262         prefs_common.mainwin_height  = allocation->height;
1263
1264         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1265
1266         prefs_common.folderview_width  = allocation->width;
1267         prefs_common.folderview_height = allocation->height;
1268 }
1269
1270 void main_window_get_position(MainWindow *mainwin)
1271 {
1272         gint x, y;
1273
1274         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1275
1276         prefs_common.mainview_x = x;
1277         prefs_common.mainview_y = y;
1278         prefs_common.mainwin_x = x;
1279         prefs_common.mainwin_y = y;
1280
1281         debug_print("window position: x = %d, y = %d\n", x, y);
1282 }
1283
1284 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1285 {
1286         GList *list;
1287         guint has_trash;
1288         Folder *folder;
1289
1290         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1291                 folder = FOLDER(list->data);
1292                 if (folder && folder->trash && folder->trash->total > 0)
1293                         has_trash++;
1294         }
1295
1296         if (!has_trash) return;
1297         
1298         if (confirm) {
1299                 if (alertpanel(_("Empty trash"),
1300                                _("Empty all messages in trash?"),
1301                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1302                         return;
1303                 manage_window_focus_in(mainwin->window, NULL, NULL);
1304         }
1305
1306         procmsg_empty_trash();
1307
1308         for (list = folder_get_list(); list != NULL; list = list->next) {
1309                 folder = list->data;
1310                 if (folder && folder->trash) {
1311                         folderview_update_item(folder->trash, TRUE);
1312                 }
1313         }
1314
1315         if (mainwin->summaryview->folder_item &&
1316             mainwin->summaryview->folder_item->stype == F_TRASH)
1317                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1318 }
1319
1320 void main_window_add_mailbox(MainWindow *mainwin)
1321 {
1322         gchar *path;
1323         Folder *folder;
1324
1325         path = input_dialog(_("Add mailbox"),
1326                             _("Input the location of mailbox.\n"
1327                               "If the existing mailbox is specified, it will be\n"
1328                               "scanned automatically."),
1329                             "Mail");
1330         if (!path) return;
1331         if (folder_find_from_path(path)) {
1332                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1333                 g_free(path);
1334                 return;
1335         }
1336         if (!strcmp(path, "Mail"))
1337                 folder = folder_new(F_MH, _("Mailbox"), path);
1338         else
1339                 folder = folder_new(F_MH, g_basename(path), path);
1340         g_free(path);
1341
1342         if (folder->create_tree(folder) < 0) {
1343                 alertpanel_error(_("Creation of the mailbox failed.\n"
1344                                    "Maybe some files already exist, or you don't have the permission to write there."));
1345                 folder_destroy(folder);
1346                 return;
1347         }
1348
1349         folder_add(folder);
1350         folder_set_ui_func(folder, scan_tree_func, mainwin);
1351         folder_scan_tree(folder);
1352         folder_set_ui_func(folder, NULL, NULL);
1353
1354         folderview_set(mainwin->folderview);
1355 }
1356
1357 void main_window_add_mbox(MainWindow *mainwin)
1358 {
1359         gchar *path;
1360         Folder *folder;
1361         FolderItem * item;
1362
1363         path = input_dialog(_("Add mbox mailbox"),
1364                             _("Input the location of mailbox."),
1365                             "mail");
1366
1367         if (!path) return;
1368
1369         if (folder_find_from_path(path)) {
1370                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1371                 g_free(path);
1372                 return;
1373         }
1374
1375         /*
1376         if (!strcmp(path, "Mail"))
1377                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1378                 else
1379         */
1380
1381         folder = folder_new(F_MBOX, g_basename(path), path);
1382         g_free(path);
1383
1384         if (folder->create_tree(folder) < 0) {
1385                 alertpanel_error(_("Creation of the mailbox failed."));
1386                 folder_destroy(folder);
1387                 return;
1388         }
1389
1390         folder_add(folder);
1391
1392         item = folder_item_new(folder, folder->name, NULL);
1393         item->folder = folder;
1394         folder->node = g_node_new(item);
1395
1396         folder->create_folder(folder, item, "inbox");
1397         folder->create_folder(folder, item, "outbox");
1398         folder->create_folder(folder, item, "queue");
1399         folder->create_folder(folder, item, "draft");
1400         folder->create_folder(folder, item, "trash");
1401
1402         folderview_set(mainwin->folderview);
1403 }
1404
1405 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1406 {
1407         SensitiveCond state = 0;
1408         SummarySelection selection;
1409         FolderItem *item = mainwin->summaryview->folder_item;
1410         GList *account_list = account_get_list();
1411         
1412         selection = summary_get_selection_type(mainwin->summaryview);
1413
1414         if (mainwin->lock_count == 0)
1415                 state |= M_UNLOCKED;
1416         if (selection != SUMMARY_NONE)
1417                 state |= M_MSG_EXIST;
1418         if (item && item->path && item->parent && !item->no_select) {
1419                 state |= M_EXEC;
1420                 /*              if (item->folder->type != F_NEWS) */
1421                 state |= M_ALLOW_DELETE;
1422
1423                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1424                     || selection != SUMMARY_NONE)
1425                         state |= M_HIDE_READ_MSG;       
1426         }               
1427         if (mainwin->summaryview->threaded)
1428                 state |= M_THREADED;
1429         else
1430                 state |= M_UNTHREADED;  
1431         if (selection == SUMMARY_SELECTED_SINGLE ||
1432             selection == SUMMARY_SELECTED_MULTIPLE)
1433                 state |= M_TARGET_EXIST;
1434         if (selection == SUMMARY_SELECTED_SINGLE)
1435                 state |= M_SINGLE_TARGET_EXIST;
1436         if (mainwin->summaryview->folder_item &&
1437             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1438                 state |= M_NEWS;
1439         if (selection == SUMMARY_SELECTED_SINGLE &&
1440             (item &&
1441              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1442               item->stype == F_QUEUE)))
1443                 state |= M_ALLOW_REEDIT;
1444         if (cur_account)
1445                 state |= M_HAVE_ACCOUNT;
1446         
1447         for ( ; account_list != NULL; account_list = account_list->next) {
1448                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1449                         state |= M_HAVE_NEWS_ACCOUNT;
1450                         break;
1451                 }
1452         }
1453
1454         if (inc_is_active())
1455                 state |= M_INC_ACTIVE;
1456
1457         return state;
1458 }
1459
1460
1461
1462 void main_window_set_menu_sensitive(MainWindow *mainwin)
1463 {
1464         GtkItemFactory *ifactory = mainwin->menu_factory;
1465         SensitiveCond state;
1466         gboolean sensitive;
1467         GtkWidget *menuitem;
1468         SummaryView *summaryview;
1469         gchar *menu_path;
1470         gint i;
1471
1472         static const struct {
1473                 gchar *const entry;
1474                 SensitiveCond cond;
1475         } entry[] = {
1476                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1477                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1478                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1479                 {"/File/Folder"                               , M_UNLOCKED},
1480                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1481                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1482                 {"/File/Empty trash"                          , M_UNLOCKED},
1483                 {"/File/Work offline"                         , M_UNLOCKED},
1484
1485                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1486                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1487                 /* {"/File/Close"  , M_UNLOCKED}, */
1488                 {"/File/Exit"      , M_UNLOCKED},
1489
1490                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1491                 {"/View/Sort"                      , M_EXEC},
1492                 {"/View/Thread view"               , M_EXEC},
1493                 {"/View/Expand all threads"        , M_MSG_EXIST},
1494                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1495                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1496                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1497                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1498                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1499                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1500                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1501                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1502                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1503                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1504                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1505                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1506                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1507                 {"/View/Show all header"           , M_SINGLE_TARGET_EXIST},
1508                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1509
1510                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1511                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1512                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1513                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1514                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1515                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1516                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1517                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1518                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1519                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1520                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1521                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1522                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1523                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1524                 {"/Message/Mark"                  , M_TARGET_EXIST},
1525
1526                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1527                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1528                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1529                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1530                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1531                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1532                 {"/Tools/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1533                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1534
1535                 {"/Configuration", M_UNLOCKED},
1536
1537                 {NULL, 0}
1538         };
1539
1540         state = main_window_get_current_state(mainwin);
1541
1542         for (i = 0; entry[i].entry != NULL; i++) {
1543                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1544                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1545         }
1546
1547         main_window_menu_callback_block(mainwin);
1548
1549 #define SET_CHECK_MENU_ACTIVE(path, active) \
1550 { \
1551         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1552         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1553 }
1554
1555         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1556                               messageview_is_visible(mainwin->messageview));
1557
1558         summaryview = mainwin->summaryview;
1559         menu_path = "/View/Sort/Don't sort";
1560
1561         switch (summaryview->sort_key) {
1562         case SORT_BY_NUMBER:
1563                 menu_path = "/View/Sort/by number"; break;
1564         case SORT_BY_SIZE:
1565                 menu_path = "/View/Sort/by size"; break;
1566         case SORT_BY_DATE:
1567                 menu_path = "/View/Sort/by date"; break;
1568         case SORT_BY_FROM:
1569                 menu_path = "/View/Sort/by from"; break;
1570         case SORT_BY_SUBJECT:
1571                 menu_path = "/View/Sort/by subject"; break;
1572         case SORT_BY_LABEL:
1573                 menu_path = "/View/Sort/by color label"; break;
1574         case SORT_BY_MARK:
1575                 menu_path = "/View/Sort/by mark"; break;
1576         case SORT_BY_UNREAD:
1577                 menu_path = "/View/Sort/by unread"; break;
1578         case SORT_BY_MIME:
1579                 menu_path = "/View/Sort/by attachment"; break;
1580         case SORT_BY_SCORE:
1581                 menu_path = "/View/Sort/by score"; break;
1582         case SORT_BY_LOCKED:
1583                 menu_path = "/View/Sort/by locked"; break;
1584         case SORT_BY_NONE:
1585         default:
1586                 menu_path = "/View/Sort/Don't sort"; break;
1587         }
1588         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1589
1590         if (summaryview->sort_type == SORT_ASCENDING) {
1591                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1592         } else {
1593                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1594         }
1595
1596         if (summaryview->sort_key != SORT_BY_NONE) {
1597                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1598                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1599         } else {
1600                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1601                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1602         }
1603
1604         SET_CHECK_MENU_ACTIVE("/View/Show all header",
1605                               mainwin->messageview->textview->show_all_headers);
1606         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1607
1608 #undef SET_CHECK_MENU_ACTIVE
1609
1610         main_window_menu_callback_unblock(mainwin);
1611 }
1612
1613 void main_window_popup(MainWindow *mainwin)
1614 {
1615         gint x, y;
1616         gint sx, sy;
1617         GtkWidget *widget;
1618
1619         gdk_window_get_origin(mainwin->window->window, &x, &y);
1620         sx = gdk_screen_width();
1621         sy = gdk_screen_height();
1622         x %= sx; if (x < 0) x = 0;
1623         y %= sy; if (y < 0) y = 0;
1624         gdk_window_move(mainwin->window->window, x, y);
1625         gdk_window_raise(mainwin->window->window);
1626         gdk_window_show(mainwin->window->window);
1627
1628         debug_print("window position: x = %d, y = %d\n", x, y);
1629
1630         switch (mainwin->type) {
1631         case SEPARATE_FOLDER:
1632                 widget = mainwin->win.sep_folder.folderwin;
1633                 gdk_window_get_origin(widget->window, &x, &y);
1634                 x %= sx; if (x < 0) x = 0;
1635                 y %= sy; if (y < 0) y = 0;
1636                 gdk_window_move(widget->window, x, y);
1637                 gdk_window_raise(widget->window);
1638                 break;
1639         case SEPARATE_MESSAGE:
1640                 widget = mainwin->win.sep_message.messagewin;
1641                 gdk_window_get_origin(widget->window, &x, &y);
1642                 x %= sx; if (x < 0) x = 0;
1643                 y %= sy; if (y < 0) y = 0;
1644                 gdk_window_move(widget->window, x, y);
1645                 gdk_window_raise(widget->window);
1646                 break;
1647         case SEPARATE_BOTH:
1648                 widget = mainwin->win.sep_both.folderwin;
1649                 gdk_window_get_origin(widget->window, &x, &y);
1650                 x %= sx; if (x < 0) x = 0;
1651                 y %= sy; if (y < 0) y = 0;
1652                 gdk_window_move(widget->window, x, y);
1653                 gdk_window_raise(widget->window);
1654                 widget = mainwin->win.sep_both.messagewin;
1655                 gdk_window_get_origin(widget->window, &x, &y);
1656                 x %= sx; if (x < 0) x = 0;
1657                 y %= sy; if (y < 0) y = 0;
1658                 gdk_window_move(widget->window, x, y);
1659                 gdk_window_raise(widget->window);
1660                 break;
1661         default:
1662                 break;
1663         }
1664 }
1665
1666 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1667 {
1668         GtkWidget *folderwin = NULL;
1669         GtkWidget *messagewin = NULL;
1670         GtkWidget *hpaned;
1671         GtkWidget *vpaned;
1672         GtkWidget *vbox_body = mainwin->vbox_body;
1673         GtkItemFactory *ifactory = mainwin->menu_factory;
1674         GtkWidget *menuitem;
1675
1676         debug_print("Setting widgets...");
1677
1678         /* create separated window(s) if needed */
1679         if (type & SEPARATE_FOLDER) {
1680                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1681                 gtk_window_set_title(GTK_WINDOW(folderwin),
1682                                      _("Sylpheed - Folder View"));
1683                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1684                                        "folder_view", "Sylpheed");
1685                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1686                                       TRUE, TRUE, FALSE);
1687                 gtk_widget_set_usize(folderwin, -1,
1688                                      prefs_common.mainview_height);
1689                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1690                                                BORDER_WIDTH);
1691                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1692                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1693                                    mainwin);
1694         }
1695         if (type & SEPARATE_MESSAGE) {
1696                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1697                 gtk_window_set_title(GTK_WINDOW(messagewin),
1698                                      _("Sylpheed - Message View"));
1699                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1700                                        "message_view", "Sylpheed");
1701                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1702                                       TRUE, TRUE, FALSE);
1703                 gtk_widget_set_usize
1704                         (messagewin, prefs_common.mainview_width,
1705                          prefs_common.mainview_height
1706                          - prefs_common.summaryview_height
1707                          + DEFAULT_HEADERVIEW_HEIGHT);
1708                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1709                                                BORDER_WIDTH);
1710                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1711                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1712                                    mainwin);
1713         }
1714
1715         switch (type) {
1716         case SEPARATE_NONE:
1717                 hpaned = gtk_hpaned_new();
1718                 gtk_widget_show(hpaned);
1719                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1720                 gtk_paned_add1(GTK_PANED(hpaned),
1721                                GTK_WIDGET_PTR(mainwin->folderview));
1722
1723                 vpaned = gtk_vpaned_new();
1724                 if (messageview_is_visible(mainwin->messageview)) {
1725                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1726                         gtk_paned_add1(GTK_PANED(vpaned),
1727                                        GTK_WIDGET_PTR(mainwin->summaryview));
1728                 } else {
1729                         gtk_paned_add2(GTK_PANED(hpaned),
1730                                        GTK_WIDGET_PTR(mainwin->summaryview));
1731                         gtk_widget_ref(vpaned);
1732                 }
1733                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1734                                      prefs_common.summaryview_width,
1735                                      prefs_common.summaryview_height);
1736                 gtk_paned_add2(GTK_PANED(vpaned),
1737                                GTK_WIDGET_PTR(mainwin->messageview));
1738                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1739                                      prefs_common.mainview_width, -1);
1740                 gtk_widget_set_usize(mainwin->window,
1741                                      prefs_common.folderview_width +
1742                                      prefs_common.mainview_width,
1743                                      prefs_common.mainwin_height);
1744                 gtk_widget_show_all(vpaned);
1745
1746                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1747                  * lose track of its visibility state */
1748                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1749                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1750
1751                 mainwin->win.sep_none.hpaned = hpaned;
1752                 mainwin->win.sep_none.vpaned = vpaned;
1753                 break;
1754         case SEPARATE_FOLDER:
1755                 vpaned = gtk_vpaned_new();
1756                 if (messageview_is_visible(mainwin->messageview)) {
1757                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1758                                            TRUE, TRUE, 0);
1759                         gtk_paned_add1(GTK_PANED(vpaned),
1760                                        GTK_WIDGET_PTR(mainwin->summaryview));
1761                 } else {
1762                         gtk_box_pack_start(GTK_BOX(vbox_body),
1763                                            GTK_WIDGET_PTR(mainwin->summaryview),
1764                                            TRUE, TRUE, 0);
1765                         gtk_widget_ref(vpaned);
1766                 }
1767                 gtk_paned_add2(GTK_PANED(vpaned),
1768                                GTK_WIDGET_PTR(mainwin->messageview));
1769                 gtk_widget_show_all(vpaned);
1770                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1771                                      prefs_common.summaryview_width,
1772                                      prefs_common.summaryview_height);
1773                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1774                                      prefs_common.mainview_width, -1);
1775                 gtk_widget_set_usize(mainwin->window,
1776                                      prefs_common.mainview_width,
1777                                      prefs_common.mainview_height);
1778
1779                 gtk_container_add(GTK_CONTAINER(folderwin),
1780                                   GTK_WIDGET_PTR(mainwin->folderview));
1781
1782                 mainwin->win.sep_folder.folderwin = folderwin;
1783                 mainwin->win.sep_folder.vpaned    = vpaned;
1784
1785                 gtk_widget_show_all(folderwin);
1786                 
1787                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1788                  * lose track of its visibility state */
1789                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1790                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1791                 break;
1792         case SEPARATE_MESSAGE:
1793                 hpaned = gtk_hpaned_new();
1794                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1795
1796                 gtk_paned_add1(GTK_PANED(hpaned),
1797                                GTK_WIDGET_PTR(mainwin->folderview));
1798                 gtk_paned_add2(GTK_PANED(hpaned),
1799                                GTK_WIDGET_PTR(mainwin->summaryview));
1800                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1801                                      prefs_common.summaryview_width,
1802                                      prefs_common.summaryview_height);
1803                 gtk_widget_set_usize(mainwin->window,
1804                                      prefs_common.folderview_width +
1805                                      prefs_common.mainview_width,
1806                                      prefs_common.mainwin_height);
1807                 gtk_widget_show_all(hpaned);
1808                 gtk_container_add(GTK_CONTAINER(messagewin),
1809                                   GTK_WIDGET_PTR(mainwin->messageview));
1810
1811                 mainwin->win.sep_message.messagewin = messagewin;
1812                 mainwin->win.sep_message.hpaned     = hpaned;
1813
1814                 gtk_widget_show_all(messagewin);
1815                 
1816                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1817                  * lose track of its visibility state */
1818                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1819                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1820                 break;
1821         case SEPARATE_BOTH:
1822                 gtk_box_pack_start(GTK_BOX(vbox_body),
1823                                    GTK_WIDGET_PTR(mainwin->summaryview),
1824                                    TRUE, TRUE, 0);
1825                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1826                                      prefs_common.summaryview_width,
1827                                      prefs_common.summaryview_height);
1828                 gtk_widget_set_usize(mainwin->window,
1829                                      prefs_common.mainview_width,
1830                                      prefs_common.mainwin_height);
1831                 gtk_container_add(GTK_CONTAINER(folderwin),
1832                                   GTK_WIDGET_PTR(mainwin->folderview));
1833                 gtk_container_add(GTK_CONTAINER(messagewin),
1834                                   GTK_WIDGET_PTR(mainwin->messageview));
1835
1836                 mainwin->win.sep_both.folderwin = folderwin;
1837                 mainwin->win.sep_both.messagewin = messagewin;
1838
1839                 gtk_widget_show_all(folderwin);
1840                 gtk_widget_show_all(messagewin);
1841
1842                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1843                  * lose track of its visibility state */
1844                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1845                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1846                 break;
1847         }
1848
1849         mainwin->type = type;
1850
1851         mainwin->messageview->visible = TRUE;
1852
1853         /* toggle menu state */
1854         menuitem = gtk_item_factory_get_item
1855                 (ifactory, "/View/Show or hide/Folder tree");
1856         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1857         menuitem = gtk_item_factory_get_item
1858                 (ifactory, "/View/Show or hide/Message view");
1859         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1860
1861         menuitem = gtk_item_factory_get_item
1862                 (ifactory, "/View/Separate folder tree");
1863         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1864                                        ((type & SEPARATE_FOLDER) != 0));
1865         menuitem = gtk_item_factory_get_item
1866                 (ifactory, "/View/Separate message view");
1867         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1868                                        ((type & SEPARATE_MESSAGE) != 0));
1869
1870         debug_print("done.\n");
1871 }
1872
1873 #if 0
1874 static void toolbar_account_button_pressed(GtkWidget *widget,
1875                                            GdkEventButton *event,
1876                                            gpointer data)
1877 {
1878         MainWindow *mainwin = (MainWindow *)data;
1879
1880         if (!event) return;
1881         if (event->button != 3) return;
1882
1883         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1884         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1885                             widget);
1886
1887         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1888                        menu_button_position, widget,
1889                        event->button, event->time);
1890 }
1891 #endif
1892
1893 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1894                                     gpointer data)
1895 {
1896         MainWindow *mainwin = (MainWindow *)data;
1897
1898         if (!event) return;
1899
1900         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1901         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1902                             widget);
1903
1904         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1905                        menu_button_position, widget,
1906                        event->button, event->time);
1907 }
1908
1909 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1910 {
1911         MainWindow *mainwin = (MainWindow *)data;
1912         GtkWidget *button;
1913
1914         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1915         if (!button) return;
1916         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1917         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1918         manage_window_focus_in(mainwin->window, NULL, NULL);
1919 }
1920
1921 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1922                                  gpointer data)
1923 {
1924         MainWindow *mainwin = (MainWindow *)data;
1925
1926         if (mainwin->lock_count == 0)
1927                 app_exit_cb(data, 0, widget);
1928
1929         return TRUE;
1930 }
1931
1932 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1933                                    gpointer data)
1934 {
1935         MainWindow *mainwin = (MainWindow *)data;
1936         GtkWidget *menuitem;
1937
1938         menuitem = gtk_item_factory_get_item
1939                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1940         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1941
1942         return TRUE;
1943 }
1944
1945 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1946                                     gpointer data)
1947 {
1948         MainWindow *mainwin = (MainWindow *)data;
1949         GtkWidget *menuitem;
1950
1951         menuitem = gtk_item_factory_get_item
1952                 (mainwin->menu_factory, "/View/Show or hide/Message view");
1953         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1954
1955         return TRUE;
1956 }
1957
1958 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1959                            GtkWidget *widget)
1960 {
1961         main_window_add_mailbox(mainwin);
1962 }
1963
1964 static void add_mbox_cb(MainWindow *mainwin, guint action,
1965                         GtkWidget *widget)
1966 {
1967         main_window_add_mbox(mainwin);
1968 }
1969
1970 static void update_folderview_cb(MainWindow *mainwin, guint action,
1971                                  GtkWidget *widget)
1972 {
1973         summary_show(mainwin->summaryview, NULL);
1974         folderview_check_new_all();
1975 }
1976
1977 static void new_folder_cb(MainWindow *mainwin, guint action,
1978                           GtkWidget *widget)
1979 {
1980         folderview_new_folder(mainwin->folderview);
1981 }
1982
1983 static void rename_folder_cb(MainWindow *mainwin, guint action,
1984                              GtkWidget *widget)
1985 {
1986         folderview_rename_folder(mainwin->folderview);
1987 }
1988
1989 static void delete_folder_cb(MainWindow *mainwin, guint action,
1990                              GtkWidget *widget)
1991 {
1992         folderview_delete_folder(mainwin->folderview);
1993 }
1994
1995 static void import_mbox_cb(MainWindow *mainwin, guint action,
1996                            GtkWidget *widget)
1997 {
1998         import_mbox(mainwin->summaryview->folder_item);
1999 }
2000
2001 static void export_mbox_cb(MainWindow *mainwin, guint action,
2002                            GtkWidget *widget)
2003 {
2004         export_mbox(mainwin->summaryview->folder_item);
2005 }
2006
2007 static void empty_trash_cb(MainWindow *mainwin, guint action,
2008                            GtkWidget *widget)
2009 {
2010         main_window_empty_trash(mainwin, TRUE);
2011 }
2012
2013 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2014 {
2015         summary_save_as(mainwin->summaryview);
2016 }
2017
2018 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2019 {
2020         summary_print(mainwin->summaryview);
2021 }
2022
2023 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2024 {
2025         if (prefs_common.confirm_on_exit) {
2026                 if (alertpanel(_("Exit"), _("Exit this program?"),
2027                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2028                         return;
2029                 manage_window_focus_in(mainwin->window, NULL, NULL);
2030         }
2031
2032         app_will_exit(widget, mainwin);
2033 }
2034
2035 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2036 {
2037         if (action == 1)
2038                 summary_search(mainwin->summaryview);
2039         else
2040                 message_search(mainwin->messageview);
2041 }
2042
2043 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2044                              GtkWidget *widget)
2045 {
2046         gboolean active;
2047
2048         active = GTK_CHECK_MENU_ITEM(widget)->active;
2049
2050         switch (mainwin->type) {
2051         case SEPARATE_NONE:
2052         case SEPARATE_MESSAGE:
2053 #if 0
2054                 if (active)
2055                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2056                 else
2057                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2058 #endif
2059                 break;
2060         case SEPARATE_FOLDER:
2061                 debug_print("separate folder\n");
2062                 if (active)
2063                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2064                 else
2065                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2066                 break;
2067         case SEPARATE_BOTH:
2068                 if (active)
2069                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2070                 else
2071                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2072                 break;
2073         }
2074 }
2075
2076 static void toggle_message_cb(MainWindow *mainwin, guint action,
2077                               GtkWidget *widget)
2078 {
2079         gboolean active;
2080
2081         active = GTK_CHECK_MENU_ITEM(widget)->active;
2082
2083         if (active != messageview_is_visible(mainwin->messageview))
2084                 summary_toggle_view(mainwin->summaryview);
2085 }
2086
2087 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2088                               GtkWidget *widget)
2089 {
2090         switch ((ToolbarStyle)action) {
2091         case TOOLBAR_NONE:
2092                 gtk_widget_hide(mainwin->handlebox);
2093         case TOOLBAR_ICON:
2094                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2095                                       GTK_TOOLBAR_ICONS);
2096                 break;
2097         case TOOLBAR_TEXT:
2098                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2099                                       GTK_TOOLBAR_TEXT);
2100                 break;
2101         case TOOLBAR_BOTH:
2102                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2103                                       GTK_TOOLBAR_BOTH);
2104                 break;
2105         }
2106
2107         if (action != TOOLBAR_NONE) {
2108                 gtk_widget_show(mainwin->handlebox);
2109                 gtk_widget_queue_resize(mainwin->handlebox);
2110         }
2111
2112         mainwin->toolbar_style = (ToolbarStyle)action;
2113         prefs_common.toolbar_style = (ToolbarStyle)action;
2114 }
2115
2116 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2117                                 GtkWidget *widget)
2118 {
2119         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2120                 gtk_widget_show(mainwin->hbox_stat);
2121                 prefs_common.show_statusbar = TRUE;
2122         } else {
2123                 gtk_widget_hide(mainwin->hbox_stat);
2124                 prefs_common.show_statusbar = FALSE;
2125         }
2126 }
2127
2128 static void separate_widget_cb(MainWindow *mainwin, guint action,
2129                                GtkWidget *widget)
2130 {
2131         SeparateType type;
2132
2133         if (GTK_CHECK_MENU_ITEM(widget)->active)
2134                 type = mainwin->type | action;
2135         else
2136                 type = mainwin->type & ~action;
2137
2138         main_window_separation_change(mainwin, type);
2139
2140         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2141         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2142 }
2143
2144 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2145 {
2146         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2147                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2148         } else {
2149                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);           
2150         }
2151 }
2152
2153 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2154 {
2155         MainWindow *mainwin;
2156         GtkItemFactory *ifactory;
2157         GtkCheckMenuItem *menuitem;
2158
2159         mainwin = (MainWindow *) data;
2160         
2161         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2162         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2163         
2164         g_return_if_fail(mainwin != NULL);
2165         g_return_if_fail(menuitem != NULL);
2166         
2167         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2168                 /* go offline */
2169                 gtk_widget_hide (mainwin->online_switch);
2170                 gtk_widget_show (mainwin->offline_switch);
2171                 menuitem->active = TRUE;
2172                 prefs_common.work_offline = TRUE;
2173                 inc_autocheck_timer_remove();           
2174         } else {
2175                 /*go online */
2176                 gtk_widget_hide (mainwin->offline_switch);
2177                 gtk_widget_show (mainwin->online_switch);
2178                 menuitem->active = FALSE;
2179                 prefs_common.work_offline = FALSE;
2180                 inc_autocheck_timer_set();
2181         }
2182 }
2183
2184 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2185                                 GtkWidget *widget)
2186 {
2187         addressbook_open(NULL);
2188 }
2189
2190 static void log_window_show_cb(MainWindow *mainwin, guint action,
2191                                GtkWidget *widget)
2192 {
2193         log_window_show(mainwin->logwin);
2194 }
2195
2196 static void sel_download_cb(MainWindow *mainwin, guint action,
2197                                GtkWidget *widget)
2198 {
2199         selective_download(mainwin);
2200 }
2201
2202 static void prefs_toolbar_cb(MainWindow *mainwin, guint action,
2203                                GtkWidget *widget)
2204 {
2205         prefs_toolbar();
2206 }
2207
2208
2209 void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2210 {
2211         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2212 }
2213
2214 void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2215                                     GtkWidget *widget)
2216 {
2217         inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2218 }
2219
2220 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2221 {
2222         inc_cancel_all();
2223 }
2224
2225 void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2226 {
2227         GList *list;
2228
2229         if (prefs_common.work_offline)
2230                 if (alertpanel(_("Offline warning"), 
2231                                _("You're working offline. Override?"),
2232                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2233                 return;
2234
2235         for (list = folder_get_list(); list != NULL; list = list->next) {
2236                 Folder *folder = list->data;
2237
2238                 if (folder->queue) {
2239                         if (procmsg_send_queue
2240                                 (folder->queue, prefs_common.savemsg) < 0)
2241                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2242                         statusbar_pop_all();
2243                         folder_item_scan(folder->queue);
2244                         folderview_update_item(folder->queue, TRUE);
2245                 }
2246         }
2247 }
2248
2249 void compose_mail_cb(MainWindow *mainwin, guint action,
2250                             GtkWidget *widget)
2251 {
2252         PrefsAccount * ac;
2253         GList * list;
2254         GList * cur;
2255
2256         if (mainwin->summaryview->folder_item) {
2257                 ac = mainwin->summaryview->folder_item->folder->account;
2258                 if (ac && ac->protocol != A_NNTP) {
2259                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2260                         return;
2261                 }
2262         }
2263
2264         if(cur_account && (cur_account->protocol != A_NNTP)) {
2265                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2266                 return;
2267         }
2268
2269         list = account_get_list();
2270         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2271                 ac = (PrefsAccount *) cur->data;
2272                 if (ac->protocol != A_NNTP) {
2273                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2274                         return;
2275                 }
2276         }
2277 }
2278
2279 void compose_news_cb(MainWindow *mainwin, guint action,
2280                             GtkWidget *widget)
2281 {
2282         PrefsAccount * ac = NULL;
2283         GList * list;
2284         GList * cur;
2285
2286         if (mainwin->summaryview->folder_item) {
2287                 ac = mainwin->summaryview->folder_item->folder->account;
2288                 if (ac && ac->protocol == A_NNTP) {
2289                         compose_new(ac,
2290                                     mainwin->summaryview->folder_item->path,
2291                                     NULL);
2292                         return;
2293                 }
2294         }
2295
2296         list = account_get_list();
2297         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2298                 ac = (PrefsAccount *) cur->data;
2299                 if (ac->protocol == A_NNTP) {
2300                         compose_new(ac, NULL, NULL);
2301                         return;
2302                 }
2303         }
2304 }
2305
2306 void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2307 {
2308         summary_reply(mainwin->summaryview, (ComposeMode)action);
2309 }
2310
2311 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2312 {
2313         summary_move_to(mainwin->summaryview);
2314 }
2315
2316 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2317 {
2318         summary_copy_to(mainwin->summaryview);
2319 }
2320
2321 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2322 {
2323         summary_delete(mainwin->summaryview);
2324 }
2325
2326 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2327 {
2328         summary_open_msg(mainwin->summaryview);
2329 }
2330
2331 static void view_source_cb(MainWindow *mainwin, guint action,
2332                            GtkWidget *widget)
2333 {
2334         summary_view_source(mainwin->summaryview);
2335 }
2336
2337 static void show_all_header_cb(MainWindow *mainwin, guint action,
2338                                GtkWidget *widget)
2339 {
2340         if (mainwin->menu_lock_count) return;
2341         summary_display_msg_selected(mainwin->summaryview,
2342                                      GTK_CHECK_MENU_ITEM(widget)->active);
2343 }
2344
2345 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2346 {
2347         summary_reedit(mainwin->summaryview);
2348 }
2349
2350 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2351 {
2352         summary_mark(mainwin->summaryview);
2353 }
2354
2355 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2356 {
2357         summary_unmark(mainwin->summaryview);
2358 }
2359
2360 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2361                               GtkWidget *widget)
2362 {
2363         summary_mark_as_unread(mainwin->summaryview);
2364 }
2365
2366 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2367                             GtkWidget *widget)
2368 {
2369         summary_mark_as_read(mainwin->summaryview);
2370 }
2371
2372 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2373                              GtkWidget *widget)
2374 {
2375         summary_mark_all_read(mainwin->summaryview);
2376 }
2377
2378 static void add_address_cb(MainWindow *mainwin, guint action,
2379                            GtkWidget *widget)
2380 {
2381         summary_add_address(mainwin->summaryview);
2382 }
2383
2384 static void set_charset_cb(MainWindow *mainwin, guint action,
2385                            GtkWidget *widget)
2386 {
2387         const gchar *str;
2388
2389         str = conv_get_charset_str((CharSet)action);
2390         g_free(prefs_common.force_charset);
2391         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2392
2393         summary_redisplay_msg(mainwin->summaryview);
2394
2395         debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2396 }
2397
2398 static void hide_read_messages (MainWindow *mainwin, guint action,
2399                                 GtkWidget *widget)
2400 {
2401         if (!mainwin->summaryview->folder_item
2402             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2403                 return;
2404         summary_toggle_show_read_messages(mainwin->summaryview);
2405 }
2406
2407 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2408 {
2409         if (mainwin->menu_lock_count) return;
2410         if (!mainwin->summaryview->folder_item) return;
2411
2412         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2413                 summary_thread_build(mainwin->summaryview);
2414 /*              mainwin->summaryview->folder_item->threaded = TRUE; */
2415         } else {
2416                 summary_unthread(mainwin->summaryview);
2417 /*              mainwin->summaryview->folder_item->threaded = FALSE; */
2418         }
2419 }
2420
2421 static void expand_threads_cb(MainWindow *mainwin, guint action,
2422                               GtkWidget *widget)
2423 {
2424         summary_expand_threads(mainwin->summaryview);
2425 }
2426
2427 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2428                                 GtkWidget *widget)
2429 {
2430         summary_collapse_threads(mainwin->summaryview);
2431 }
2432
2433 static void set_display_item_cb(MainWindow *mainwin, guint action,
2434                                 GtkWidget *widget)
2435 {
2436         prefs_summary_column_open();
2437 }
2438
2439 static void sort_summary_cb(MainWindow *mainwin, guint action,
2440                             GtkWidget *widget)
2441 {
2442         FolderItem *item = mainwin->summaryview->folder_item;
2443         GtkWidget *menuitem;
2444
2445         if (mainwin->menu_lock_count) return;
2446         if (item) {
2447                 menuitem = gtk_item_factory_get_item
2448                         (mainwin->menu_factory, "/View/Sort/Ascending");
2449                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2450                              GTK_CHECK_MENU_ITEM(menuitem)->active
2451                              ? SORT_ASCENDING : SORT_DESCENDING);
2452         }
2453 }
2454
2455 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2456                                  GtkWidget *widget)
2457 {
2458         FolderItem *item = mainwin->summaryview->folder_item;
2459
2460         if (mainwin->menu_lock_count) return;
2461         if (item)
2462                 summary_sort(mainwin->summaryview,
2463                              item->sort_key, (FolderSortType)action);
2464 }
2465
2466 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2467                                   GtkWidget *widget)
2468 {
2469         summary_attract_by_subject(mainwin->summaryview);
2470 }
2471
2472 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2473                                  GtkWidget *widget)
2474 {
2475         summary_delete_duplicated(mainwin->summaryview);
2476 }
2477
2478 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2479 {
2480         summary_filter(mainwin->summaryview);
2481 }
2482
2483 static void execute_summary_cb(MainWindow *mainwin, guint action,
2484                                GtkWidget *widget)
2485 {
2486         summary_execute(mainwin->summaryview);
2487 }
2488
2489 static void update_summary_cb(MainWindow *mainwin, guint action,
2490                               GtkWidget *widget)
2491 {
2492         FolderItem *fitem;
2493         FolderView *folderview = mainwin->folderview;
2494
2495         if (!mainwin->summaryview->folder_item) return;
2496         if (!folderview->opened) return;
2497
2498         folder_update_op_count();
2499
2500         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2501                                             folderview->opened);
2502         if (!fitem) return;
2503
2504         folder_item_scan(fitem);
2505         summary_show(mainwin->summaryview, fitem);
2506 }
2507
2508 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2509 {
2510         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2511 }
2512
2513 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2514 {
2515         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2516 }
2517
2518 static void prev_unread_cb(MainWindow *mainwin, guint action,
2519                            GtkWidget *widget)
2520 {
2521         summary_select_prev_unread(mainwin->summaryview);
2522 }
2523
2524 void next_unread_cb(MainWindow *mainwin, guint action,
2525                            GtkWidget *widget)
2526 {
2527         summary_select_next_unread(mainwin->summaryview);
2528 }
2529
2530 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2531 {
2532         summary_select_prev_new(mainwin->summaryview);
2533 }
2534
2535 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2536 {
2537         summary_select_next_new(mainwin->summaryview);
2538 }
2539
2540 static void prev_marked_cb(MainWindow *mainwin, guint action,
2541                            GtkWidget *widget)
2542 {
2543         summary_select_prev_marked(mainwin->summaryview);
2544 }
2545
2546 static void next_marked_cb(MainWindow *mainwin, guint action,
2547                            GtkWidget *widget)
2548 {
2549         summary_select_next_marked(mainwin->summaryview);
2550 }
2551
2552 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2553                             GtkWidget *widget)
2554 {
2555         summary_select_prev_labeled(mainwin->summaryview);
2556 }
2557
2558 static void next_labeled_cb(MainWindow *mainwin, guint action,
2559                             GtkWidget *widget)
2560 {
2561         summary_select_next_labeled(mainwin->summaryview);
2562 }
2563
2564 static void goto_folder_cb(MainWindow *mainwin, guint action,
2565                            GtkWidget *widget)
2566 {
2567         FolderItem *to_folder;
2568
2569         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2570
2571         if (to_folder)
2572                 folderview_select(mainwin->folderview, to_folder);
2573 }
2574
2575 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2576 {
2577         messageview_copy_clipboard(mainwin->messageview);
2578 }
2579
2580 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2581 {
2582         MessageView *msgview = mainwin->messageview;
2583
2584         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2585                 summary_select_all(mainwin->summaryview);
2586         else if (messageview_is_visible(msgview) &&
2587                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2588                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2589                 messageview_select_all(mainwin->messageview);
2590 }
2591
2592 static void selthread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2593 {
2594         if (messageview_is_visible(mainwin->summaryview->messageview))
2595                 summary_select_thread(mainwin->summaryview);
2596 }
2597
2598 static void create_filter_cb(MainWindow *mainwin, guint action,
2599                              GtkWidget *widget)
2600 {
2601         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2602 }
2603
2604 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2605                                  GtkWidget *widget)
2606 {
2607         prefs_common_open();
2608 }
2609
2610 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2611                                  GtkWidget *widget)
2612 {
2613         prefs_filter_open(NULL, NULL);
2614 }
2615
2616 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2617                                   GtkWidget *widget)
2618 {
2619         prefs_scoring_open(NULL);
2620 }
2621
2622 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2623                                     GtkWidget *widget)
2624 {
2625         prefs_filtering_open(NULL, NULL, NULL);
2626 }
2627
2628 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2629                                    GtkWidget *widget)
2630 {
2631         prefs_template_open();
2632 }
2633
2634 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2635                                   GtkWidget *widget)
2636 {
2637         prefs_actions_open(mainwin);
2638 }
2639
2640 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2641                                   GtkWidget *widget)
2642 {
2643         if (!cur_account) {
2644                 new_account_cb(mainwin, 0, widget);
2645         } else {
2646                 gboolean prev_default = cur_account->is_default;
2647
2648                 prefs_account_open(cur_account);
2649                 if (!prev_default && cur_account->is_default)
2650                         account_set_as_default(cur_account);
2651                 account_save_config_all();
2652                 account_set_menu();
2653                 main_window_reflect_prefs_all();
2654         }
2655 }
2656
2657 static void new_account_cb(MainWindow *mainwin, guint action,
2658                            GtkWidget *widget)
2659 {
2660         account_edit_open();
2661         if (!compose_get_compose_list()) account_add();
2662 }
2663
2664 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2665 {
2666         cur_account = (PrefsAccount *)data;
2667         main_window_reflect_prefs_all();
2668 }
2669
2670 static void manual_open_cb(MainWindow *mainwin, guint action,
2671                            GtkWidget *widget)
2672 {
2673         manual_open((ManualLang)action);
2674 }
2675
2676 static void faq_open_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2677 {
2678         faq_open((ManualLang)action);
2679 }
2680
2681 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2682 {
2683         MainWindow *mainwin = (MainWindow *)data;
2684         gchar *str;
2685
2686         if (item->path)
2687                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2688                                       LOCAL_FOLDER(folder)->rootpath,
2689                                       G_DIR_SEPARATOR,
2690                                       item->path);
2691         else
2692                 str = g_strdup_printf(_("Scanning folder %s ..."),
2693                                       LOCAL_FOLDER(folder)->rootpath);
2694
2695         STATUSBAR_PUSH(mainwin, str);
2696         STATUSBAR_POP(mainwin);
2697         g_free(str);
2698 }
2699
2700 #define BREAK_ON_MODIFIER_KEY() \
2701         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2702
2703 static void key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
2704 {
2705         MainWindow *mainwin = (MainWindow*) data;
2706         
2707         if (!mainwin || !event) return;
2708                 
2709         switch (event->keyval) {
2710         case GDK_Q:             /* Quit */
2711                 BREAK_ON_MODIFIER_KEY();
2712
2713                 app_exit_cb(mainwin, 0, NULL);
2714                 return;
2715         default:
2716                 break;
2717         }
2718 }
2719
2720 #undef BREAK_ON_MODIFIER_KEY
2721
2722 static void set_toolbar_style(MainWindow *mainwin)
2723 {
2724         switch (prefs_common.toolbar_style) {
2725         case TOOLBAR_NONE:
2726                 gtk_widget_hide(mainwin->handlebox);
2727                 break;
2728         case TOOLBAR_ICON:
2729                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2730                                       GTK_TOOLBAR_ICONS);
2731                 break;
2732         case TOOLBAR_TEXT:
2733                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2734                                       GTK_TOOLBAR_TEXT);
2735                 break;
2736         case TOOLBAR_BOTH:
2737                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2738                                       GTK_TOOLBAR_BOTH);
2739                 break;
2740         }
2741         
2742         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
2743                 gtk_widget_show(mainwin->handlebox);
2744                 gtk_widget_queue_resize(mainwin->handlebox);
2745         }
2746 }
2747
2748 /*
2749  * Harvest addresses for selected folder.
2750  */
2751 static void addr_harvest_cb( MainWindow *mainwin,
2752                             guint action,
2753                             GtkWidget *widget )
2754 {
2755         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2756 }
2757
2758 /*
2759  * Harvest addresses for selected messages in summary view.
2760  */
2761 static void addr_harvest_msg_cb( MainWindow *mainwin,
2762                             guint action,
2763                             GtkWidget *widget )
2764 {
2765         summary_harvest_address( mainwin->summaryview );
2766 }
2767
2768 /*
2769 * End of Source.
2770 */
2771