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