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