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