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