some tweaks, please see Changelog
[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         /* Message view and Folder tree are always shown at startup
893          * make that in the menu visible */
894         menuitem = gtk_item_factory_get_item(ifactory, "/View/Message view");
895         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
896         menuitem = gtk_item_factory_get_item(ifactory, "/View/Folder tree");
897         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
898         
899         /* set the check of the SEPARATE_xxx menu items. we also need the main window
900          * as a property and pass the action type to the callback */
901         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_FOLDER);
902         g_assert(menuitem);
903         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_FOLDER);
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_FOLDER));
907
908         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_MESSAGE);
909         g_assert(menuitem);
910         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_MESSAGE);
911         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
912         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
913                                            GUINT_TO_POINTER(SEPARATE_MESSAGE));
914
915
916         menu_set_sensitive(ifactory, "/Summary/Thread view",
917                            prefs_common.enable_thread ? FALSE : TRUE);
918         menu_set_sensitive(ifactory, "/Summary/Unthread view",
919                            prefs_common.enable_thread ? TRUE : FALSE);
920         
921         /*main_window_set_thread_option(mainwin);*/
922
923
924         /* set account selection menu */
925         ac_menu = gtk_item_factory_get_widget
926                 (ifactory, "/Configuration/Change current account");
927         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
928                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
929         mainwin->ac_menu = ac_menu;
930
931         main_window_set_toolbar_sensitive(mainwin);
932
933         /* show main window */
934         gtk_widget_set_uposition(mainwin->window,
935                                  prefs_common.mainwin_x,
936                                  prefs_common.mainwin_y);
937         gtk_widget_set_usize(window, prefs_common.mainwin_width,
938                              prefs_common.mainwin_height);
939                              
940         gtk_widget_show(mainwin->window);
941
942         /* initialize views */
943         folderview_init(folderview);
944         summary_init(summaryview);
945         messageview_init(messageview);
946         header_window_init(mainwin->headerwin);
947         log_window_init(mainwin->logwin);
948
949
950         mainwin->lock_count = 0;
951         mainwin->cursor_count = 0;
952
953         if (!watch_cursor)
954                 watch_cursor = gdk_cursor_new(GDK_WATCH);
955
956         mainwin_list = g_list_append(mainwin_list, mainwin);
957
958         return mainwin;
959 }
960
961 void main_window_cursor_wait(MainWindow *mainwin)
962 {
963
964         if (mainwin->cursor_count == 0)
965                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
966
967         mainwin->cursor_count++;
968
969         gdk_flush();
970 }
971
972 void main_window_cursor_normal(MainWindow *mainwin)
973 {
974         if (mainwin->cursor_count)
975                 mainwin->cursor_count--;
976
977         if (mainwin->cursor_count == 0)
978                 gdk_window_set_cursor(mainwin->window->window, NULL);
979
980         gdk_flush();
981 }
982
983 /* lock / unlock the user-interface */
984 void main_window_lock(MainWindow *mainwin)
985 {
986         if (mainwin->lock_count == 0)
987                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
988
989         mainwin->lock_count++;
990
991         main_window_set_menu_sensitive(mainwin);
992         main_window_set_toolbar_sensitive(mainwin);
993 }
994
995 void main_window_unlock(MainWindow *mainwin)
996 {
997         if (mainwin->lock_count)
998                 mainwin->lock_count--;
999
1000         main_window_set_menu_sensitive(mainwin);
1001         main_window_set_toolbar_sensitive(mainwin);
1002
1003         if (mainwin->lock_count == 0)
1004                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1005 }
1006
1007 void main_window_reflect_prefs_all(void)
1008 {
1009         GList *cur;
1010         MainWindow *mainwin;
1011
1012         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1013                 mainwin = (MainWindow *)cur->data;
1014
1015                 main_window_show_cur_account(mainwin);
1016                 main_window_set_menu_sensitive(mainwin);
1017                 main_window_set_toolbar_sensitive(mainwin);
1018
1019                 if (prefs_common.immediate_exec)
1020                         gtk_widget_hide(mainwin->exec_btn);
1021                 else
1022                         gtk_widget_show(mainwin->exec_btn);
1023
1024                 summary_redisplay_msg(mainwin->summaryview);
1025                 headerview_set_visibility(mainwin->messageview->headerview,
1026                                           prefs_common.display_header_pane);
1027         }
1028 }
1029
1030 void main_window_set_summary_column(void)
1031 {
1032         GList *cur;
1033         MainWindow *mainwin;
1034
1035         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1036                 mainwin = (MainWindow *)cur->data;
1037                 summary_set_column_order(mainwin->summaryview);
1038         }
1039 }
1040
1041 void main_window_set_account_menu(GList *account_list)
1042 {
1043         GList *cur, *cur_ac, *cur_item;
1044         GtkWidget *menuitem;
1045         MainWindow *mainwin;
1046         PrefsAccount *ac_prefs;
1047
1048         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1049                 mainwin = (MainWindow *)cur->data;
1050
1051                 /* destroy all previous menu item */
1052                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1053                 while (cur_item != NULL) {
1054                         GList *next = cur_item->next;
1055                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1056                         cur_item = next;
1057                 }
1058
1059                 for (cur_ac = account_list; cur_ac != NULL;
1060                      cur_ac = cur_ac->next) {
1061                         ac_prefs = (PrefsAccount *)cur_ac->data;
1062
1063                         menuitem = gtk_menu_item_new_with_label
1064                                 (ac_prefs->account_name
1065                                  ? ac_prefs->account_name : _("Untitled"));
1066                         gtk_widget_show(menuitem);
1067                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1068                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1069                                            GTK_SIGNAL_FUNC(account_menu_cb),
1070                                            ac_prefs);
1071                 }
1072         }
1073 }
1074
1075 static void main_window_show_cur_account(MainWindow *mainwin)
1076 {
1077         gchar *buf;
1078         gchar *ac_name;
1079
1080         ac_name = g_strdup(cur_account
1081                            ? (cur_account->account_name
1082                               ? cur_account->account_name : _("Untitled"))
1083                            : _("none"));
1084
1085         if (cur_account)
1086                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1087         else
1088                 buf = g_strdup(PROG_VERSION);
1089         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1090         g_free(buf);
1091
1092         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1093         gtk_widget_queue_resize(mainwin->ac_button);
1094
1095         g_free(ac_name);
1096 }
1097
1098 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1099 {
1100         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1101         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1102         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1103
1104         if (mainwin->type == type) return;
1105
1106         /* remove widgets from those containers */
1107         gtk_widget_ref(folder_wid);
1108         gtk_widget_ref(summary_wid);
1109         gtk_widget_ref(message_wid);
1110         gtkut_container_remove
1111                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1112         gtkut_container_remove
1113                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1114         gtkut_container_remove
1115                 (GTK_CONTAINER(message_wid->parent), message_wid);
1116
1117         /* clean containers */
1118         switch (mainwin->type) {
1119         case SEPARATE_NONE:
1120                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1121                 break;
1122         case SEPARATE_FOLDER:
1123                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1124                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1125                 break;
1126         case SEPARATE_MESSAGE:
1127                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1128                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1129                 break;
1130         case SEPARATE_BOTH:
1131                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1132                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1133                 break;
1134         }
1135
1136         gtk_widget_hide(mainwin->window);
1137         main_window_set_widgets(mainwin, type);
1138         gtk_widget_show(mainwin->window);
1139
1140         gtk_widget_unref(folder_wid);
1141         gtk_widget_unref(summary_wid);
1142         gtk_widget_unref(message_wid);
1143 }
1144
1145 void main_window_get_size(MainWindow *mainwin)
1146 {
1147         GtkAllocation *allocation;
1148
1149         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1150
1151         prefs_common.summaryview_width  = allocation->width;
1152
1153         if (mainwin->summaryview->msg_is_toggled_on)
1154                 prefs_common.summaryview_height = allocation->height;
1155
1156         prefs_common.mainview_width     = allocation->width;
1157
1158         allocation = &mainwin->window->allocation;
1159
1160         prefs_common.mainview_height = allocation->height;
1161         prefs_common.mainwin_width   = allocation->width;
1162         prefs_common.mainwin_height  = allocation->height;
1163
1164         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1165
1166         prefs_common.folderview_width  = allocation->width;
1167         prefs_common.folderview_height = allocation->height;
1168 }
1169
1170 void main_window_get_position(MainWindow *mainwin)
1171 {
1172         gint x, y;
1173
1174         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1175
1176         prefs_common.mainview_x = x;
1177         prefs_common.mainview_y = y;
1178         prefs_common.mainwin_x = x;
1179         prefs_common.mainwin_y = y;
1180
1181         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1182 }
1183
1184 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1185 {
1186         GList *list;
1187         gboolean hasTrash = 0;
1188
1189         for (list = folder_get_list(); list != NULL; list = list->next) {
1190                 Folder *folder;
1191
1192                 folder = list->data;
1193                 if (folder->trash) {
1194                         hasTrash = (folder->trash->total > 0);
1195                 }
1196         }
1197
1198         if (!hasTrash) {
1199           return;
1200         }
1201  
1202         if (confirm) {
1203                 if (alertpanel(_("Empty trash"),
1204                                _("Empty all messages in trash?"),
1205                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1206                         return;
1207                 manage_window_focus_in(mainwin->window, NULL, NULL);
1208         }
1209
1210         procmsg_empty_trash();
1211
1212         for (list = folder_get_list(); list != NULL; list = list->next) {
1213                 Folder *folder;
1214
1215                 folder = list->data;
1216                 if (folder->trash) {
1217                         folder_item_scan(folder->trash);
1218                         folderview_update_item(folder->trash, TRUE);
1219                 }
1220         }
1221
1222         if (mainwin->summaryview->folder_item &&
1223             mainwin->summaryview->folder_item->stype == F_TRASH)
1224                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1225 }
1226
1227 void main_window_add_mailbox(MainWindow *mainwin)
1228 {
1229         gchar *path;
1230         Folder *folder;
1231
1232         path = input_dialog(_("Add mailbox"),
1233                             _("Input the location of mailbox.\n"
1234                               "If the existing mailbox is specified, it will be\n"
1235                               "scanned automatically."),
1236                             "Mail");
1237         if (!path) return;
1238         if (folder_find_from_path(path)) {
1239                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1240                 g_free(path);
1241                 return;
1242         }
1243         if (!strcmp(path, "Mail"))
1244                 folder = folder_new(F_MH, _("Mailbox"), path);
1245         else
1246                 folder = folder_new(F_MH, g_basename(path), path);
1247         g_free(path);
1248
1249         if (folder->create_tree(folder) < 0) {
1250                 alertpanel_error(_("Creation of the mailbox failed.\n"
1251                                    "Maybe some files already exist, or you don't have the permission to write there."));
1252                 folder_destroy(folder);
1253                 return;
1254         }
1255
1256         folder_add(folder);
1257         folder_set_ui_func(folder, scan_tree_func, mainwin);
1258         folder->scan_tree(folder);
1259         folder_set_ui_func(folder, NULL, NULL);
1260
1261         folderview_set(mainwin->folderview);
1262 }
1263
1264 void main_window_add_mbox(MainWindow *mainwin)
1265 {
1266         gchar *path;
1267         Folder *folder;
1268         FolderItem * item;
1269
1270         path = input_dialog(_("Add mbox mailbox"),
1271                             _("Input the location of mailbox."),
1272                             "mail");
1273
1274         if (!path) return;
1275
1276         if (folder_find_from_path(path)) {
1277                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1278                 g_free(path);
1279                 return;
1280         }
1281
1282         /*
1283         if (!strcmp(path, "Mail"))
1284                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1285                 else
1286         */
1287
1288         folder = folder_new(F_MBOX, g_basename(path), path);
1289         g_free(path);
1290
1291         if (folder->create_tree(folder) < 0) {
1292                 alertpanel_error(_("Creation of the mailbox failed."));
1293                 folder_destroy(folder);
1294                 return;
1295         }
1296
1297         folder_add(folder);
1298
1299         item = folder_item_new(folder->name, NULL);
1300         item->folder = folder;
1301         folder->node = g_node_new(item);
1302
1303         folder->create_folder(folder, item, "inbox");
1304         folder->create_folder(folder, item, "outbox");
1305         folder->create_folder(folder, item, "queue");
1306         folder->create_folder(folder, item, "draft");
1307         folder->create_folder(folder, item, "trash");
1308
1309         folderview_set(mainwin->folderview);
1310 }
1311
1312 typedef enum
1313 {
1314         M_UNLOCKED            = 1 << 0,
1315         M_MSG_EXIST           = 1 << 1,
1316         M_TARGET_EXIST        = 1 << 2,
1317         M_SINGLE_TARGET_EXIST = 1 << 3,
1318         M_EXEC                = 1 << 4,
1319         M_ALLOW_REEDIT        = 1 << 5,
1320         M_HAVE_ACCOUNT        = 1 << 6,
1321         M_THREADED            = 1 << 7,
1322         M_UNTHREADED          = 1 << 8,
1323         M_NEWS                = 1 << 9,
1324         M_HAVE_NEWS_ACCOUNT   = 1 << 10
1325 } SensitiveCond;
1326
1327 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1328 {
1329         SensitiveCond state = 0;
1330         SummarySelection selection;
1331         FolderItem *item = mainwin->summaryview->folder_item;
1332         GList *account_list = account_get_list();
1333         
1334         selection = summary_get_selection_type(mainwin->summaryview);
1335
1336         if (mainwin->lock_count == 0)
1337                 state |= M_UNLOCKED;
1338         if (selection != SUMMARY_NONE)
1339                 state |= M_MSG_EXIST;
1340         if (item) {
1341                 if (item->threaded)
1342                         state |= M_THREADED;
1343                 else
1344                         state |= M_UNTHREADED;  
1345         }               
1346         if (selection == SUMMARY_SELECTED_SINGLE ||
1347             selection == SUMMARY_SELECTED_MULTIPLE)
1348                 state |= M_TARGET_EXIST;
1349         if (selection == SUMMARY_SELECTED_SINGLE)
1350                 state |= M_SINGLE_TARGET_EXIST;
1351         if (item && item->folder->type != F_NEWS)
1352                 state |= M_EXEC;
1353         if (mainwin->summaryview->folder_item &&
1354             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1355                 state |= M_NEWS;
1356         if (selection == SUMMARY_SELECTED_SINGLE &&
1357             (item &&
1358              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1359               item->stype == F_QUEUE)))
1360                 state |= M_ALLOW_REEDIT;
1361         if (cur_account)
1362                 state |= M_HAVE_ACCOUNT;
1363         
1364         for ( ; account_list != NULL; account_list = account_list->next) {
1365                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1366                         state |= M_HAVE_NEWS_ACCOUNT;
1367                         break;
1368                 }
1369         }
1370
1371         return state;
1372 }
1373
1374 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1375 {
1376         SensitiveCond state;
1377     gboolean sensitive;
1378         gint i;
1379
1380         const struct {
1381                 GtkWidget *widget;
1382                 SensitiveCond cond;
1383         } entry[] = {
1384                 {mainwin->get_btn         , M_HAVE_ACCOUNT|M_UNLOCKED},
1385                 {mainwin->getall_btn      , M_HAVE_ACCOUNT|M_UNLOCKED},
1386                 {mainwin->compose_mail_btn, M_HAVE_ACCOUNT},
1387                 {mainwin->compose_news_btn, M_HAVE_NEWS_ACCOUNT},
1388                 {mainwin->reply_btn       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1389                 {mainwin->replyall_btn    , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1390                 {mainwin->replysender_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1391                 {mainwin->fwd_btn         , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1392                 /* {mainwin->prefs_btn      , M_UNLOCKED},
1393                 {mainwin->account_btn    , M_UNLOCKED}, */
1394                 {mainwin->next_btn        , M_MSG_EXIST},
1395                 {mainwin->delete_btn      , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1396                 {mainwin->exec_btn        , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1397                 {NULL, 0}
1398         };
1399
1400         state = main_window_get_current_state(mainwin);
1401
1402         for (i = 0; entry[i].widget != NULL; i++) {
1403                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1404                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1405         }
1406
1407         activate_compose_button(mainwin, 
1408                         prefs_common.toolbar_style,
1409                         mainwin->compose_btn_type);
1410 }
1411
1412 void main_window_set_menu_sensitive(MainWindow *mainwin)
1413 {
1414         GtkItemFactory *ifactory;
1415         SensitiveCond state;
1416         gboolean sensitive;
1417         gint i;
1418
1419         static const struct {
1420                 gchar *const entry;
1421                 SensitiveCond cond;
1422         } entry[] = {
1423                 {"/File/Add mailbox..."        , M_UNLOCKED},
1424                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1425                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1426                 {"/File/Folder"                , M_UNLOCKED},
1427                 {"/File/Import mbox file..."   , M_UNLOCKED},
1428                 {"/File/Export to mbox file...", M_UNLOCKED},
1429                 {"/File/Empty trash"           , M_UNLOCKED},
1430                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1431                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1432 /*              {"/File/Close", M_UNLOCKED},*/
1433                 {"/File/Exit" , M_UNLOCKED},
1434
1435                 {"/View/Show all header"      , M_SINGLE_TARGET_EXIST},
1436                 {"/View/View source"          , M_SINGLE_TARGET_EXIST},
1437
1438                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1439                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1440 /*              {"/Message/Compose new message"   , M_HAVE_ACCOUNT}, */
1441                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1442                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1443                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1444                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1445                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1446                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1447                 {"/Message/Bounce"                , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1448                 {"/Message/Open in new window"    , M_SINGLE_TARGET_EXIST},
1449                 {"/Message/Re-edit", M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1450                 {"/Message/Move...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1451                 {"/Message/Copy...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1452                 {"/Message/Delete" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1453                 {"/Message/Mark"   , M_TARGET_EXIST},
1454
1455                 {"/Summary/Delete duplicated messages", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1456                 {"/Summary/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1457                 {"/Summary/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1458                 {"/Summary/Go to"                     , M_MSG_EXIST},
1459                 {"/Summary/Go to/Prev message"        , M_MSG_EXIST},
1460                 {"/Summary/Go to/Next message"        , M_MSG_EXIST},
1461                 {"/Summary/Go to/Next unread message" , M_MSG_EXIST},
1462                 {"/Summary/Go to/Prev marked message" , M_MSG_EXIST},
1463                 {"/Summary/Go to/Next marked message" , M_MSG_EXIST},
1464                 {"/Summary/Go to/Prev labeled message", M_MSG_EXIST},
1465                 {"/Summary/Go to/Next labeled message", M_MSG_EXIST},
1466                 {"/Summary/Sort"                      , M_MSG_EXIST},
1467                 {"/Summary/Thread view"               , M_UNTHREADED},
1468                 {"/Summary/Unthread view"             , M_THREADED},
1469
1470                 {"/Configuration", M_UNLOCKED},
1471
1472                 {NULL, 0}
1473         };
1474         
1475         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1476         state = main_window_get_current_state(mainwin);
1477
1478         for (i = 0; entry[i].entry != NULL; i++) {
1479                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1480                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1481         }
1482 }
1483
1484 void main_window_popup(MainWindow *mainwin)
1485 {
1486         gint x, y;
1487         gint sx, sy;
1488         GtkWidget *widget;
1489
1490         gdk_window_get_origin(mainwin->window->window, &x, &y);
1491         sx = gdk_screen_width();
1492         sy = gdk_screen_height();
1493         x %= sx; if (x < 0) x = 0;
1494         y %= sy; if (y < 0) y = 0;
1495         gdk_window_move(mainwin->window->window, x, y);
1496         gdk_window_raise(mainwin->window->window);
1497         gdk_window_show(mainwin->window->window);
1498
1499         debug_print("window position: x = %d, y = %d\n", x, y);
1500
1501         switch (mainwin->type) {
1502         case SEPARATE_FOLDER:
1503                 widget = mainwin->win.sep_folder.folderwin;
1504                 gdk_window_get_origin(widget->window, &x, &y);
1505                 x %= sx; if (x < 0) x = 0;
1506                 y %= sy; if (y < 0) y = 0;
1507                 gdk_window_move(widget->window, x, y);
1508                 gdk_window_raise(widget->window);
1509                 break;
1510         case SEPARATE_MESSAGE:
1511                 widget = mainwin->win.sep_message.messagewin;
1512                 gdk_window_get_origin(widget->window, &x, &y);
1513                 x %= sx; if (x < 0) x = 0;
1514                 y %= sy; if (y < 0) y = 0;
1515                 gdk_window_move(widget->window, x, y);
1516                 gdk_window_raise(widget->window);
1517                 break;
1518         case SEPARATE_BOTH:
1519                 widget = mainwin->win.sep_both.folderwin;
1520                 gdk_window_get_origin(widget->window, &x, &y);
1521                 x %= sx; if (x < 0) x = 0;
1522                 y %= sy; if (y < 0) y = 0;
1523                 gdk_window_move(widget->window, x, y);
1524                 gdk_window_raise(widget->window);
1525                 widget = mainwin->win.sep_both.messagewin;
1526                 gdk_window_get_origin(widget->window, &x, &y);
1527                 x %= sx; if (x < 0) x = 0;
1528                 y %= sy; if (y < 0) y = 0;
1529                 gdk_window_move(widget->window, x, y);
1530                 gdk_window_raise(widget->window);
1531                 break;
1532         default:
1533                 break;
1534         }
1535 }
1536
1537 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1538 {
1539         GtkWidget *folderwin = NULL;
1540         GtkWidget *messagewin = NULL;
1541         GtkWidget *hpaned;
1542         GtkWidget *vpaned;
1543         GtkWidget *vbox_body = mainwin->vbox_body;
1544         GtkItemFactory *ifactory=gtk_item_factory_from_widget(mainwin->menubar);
1545
1546         debug_print(_("Setting widgets..."));
1547
1548         /* create separated window(s) if needed */
1549         if (type & SEPARATE_FOLDER) {
1550                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1551                 gtk_window_set_title(GTK_WINDOW(folderwin), _("Sylpheed - folder view"));
1552                 gtk_window_set_wmclass(GTK_WINDOW(folderwin), "separate folderview", "Sylpheed");
1553                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1554                                       TRUE, TRUE, FALSE);
1555                 gtk_widget_set_usize(folderwin, -1,
1556                                      prefs_common.mainview_height);
1557                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1558                                                BORDER_WIDTH);
1559                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1560                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1561                                    NULL);
1562         }
1563         if (type & SEPARATE_MESSAGE) {
1564                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1565                 gtk_window_set_title(GTK_WINDOW(messagewin), _("Sylpheed - message view"));
1566                 gtk_window_set_wmclass(GTK_WINDOW(messagewin), "separate messageview", "Sylpheed");
1567                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1568                                       TRUE, TRUE, FALSE);
1569                 gtk_widget_set_usize
1570                         (messagewin, prefs_common.mainview_width,
1571                          prefs_common.mainview_height
1572                          - prefs_common.summaryview_height
1573                          + DEFAULT_HEADERVIEW_HEIGHT);
1574                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1575                                                BORDER_WIDTH);
1576                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1577                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1578                                    NULL);
1579         }
1580
1581         switch (type) {
1582         case SEPARATE_NONE:
1583                 hpaned = gtk_hpaned_new();
1584                 gtk_widget_show(hpaned);
1585                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1586                 gtk_paned_add1(GTK_PANED(hpaned),
1587                                GTK_WIDGET_PTR(mainwin->folderview));
1588
1589                 vpaned = gtk_vpaned_new();
1590                 if (mainwin->summaryview->msg_is_toggled_on) {
1591                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1592                         gtk_paned_add1(GTK_PANED(vpaned),
1593                                        GTK_WIDGET_PTR(mainwin->summaryview));
1594                 } else {
1595                         gtk_paned_add2(GTK_PANED(hpaned),
1596                                        GTK_WIDGET_PTR(mainwin->summaryview));
1597                         gtk_widget_ref(vpaned);
1598                 }
1599                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1600                                      prefs_common.summaryview_width,
1601                                      prefs_common.summaryview_height);
1602                 gtk_paned_add2(GTK_PANED(vpaned),
1603                                GTK_WIDGET_PTR(mainwin->messageview));
1604                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1605                                      prefs_common.mainview_width, -1);
1606                 gtk_widget_set_usize(mainwin->window,
1607                                      prefs_common.folderview_width +
1608                                      prefs_common.mainview_width,
1609                                      prefs_common.mainwin_height);
1610                 gtk_widget_show_all(vpaned);
1611
1612                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1613                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1614                 
1615                 mainwin->win.sep_none.hpaned = hpaned;
1616                 mainwin->win.sep_none.vpaned = vpaned;
1617                 break;
1618         case SEPARATE_FOLDER:
1619                 vpaned = gtk_vpaned_new();
1620                 if (mainwin->summaryview->msg_is_toggled_on) {
1621                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1622                                            TRUE, TRUE, 0);
1623                         gtk_paned_add1(GTK_PANED(vpaned),
1624                                        GTK_WIDGET_PTR(mainwin->summaryview));
1625                 } else {
1626                         gtk_box_pack_start(GTK_BOX(vbox_body),
1627                                            GTK_WIDGET_PTR(mainwin->summaryview),
1628                                            TRUE, TRUE, 0);
1629                         gtk_widget_ref(vpaned);
1630                 }
1631                 gtk_paned_add2(GTK_PANED(vpaned),
1632                                GTK_WIDGET_PTR(mainwin->messageview));
1633                 gtk_widget_show_all(vpaned);
1634                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1635                                      prefs_common.summaryview_width,
1636                                      prefs_common.summaryview_height);
1637                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1638                                      prefs_common.mainview_width, -1);
1639                 gtk_widget_set_usize(mainwin->window,
1640                                      prefs_common.mainview_width,
1641                                      prefs_common.mainview_height);
1642
1643                 gtk_container_add(GTK_CONTAINER(folderwin),
1644                                   GTK_WIDGET_PTR(mainwin->folderview));
1645
1646                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1647                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1648                 
1649                 mainwin->win.sep_folder.folderwin = folderwin;
1650                 mainwin->win.sep_folder.vpaned    = vpaned;
1651
1652                 gtk_widget_show_all(folderwin);
1653                 break;
1654         case SEPARATE_MESSAGE:
1655                 hpaned = gtk_hpaned_new();
1656                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1657
1658                 gtk_paned_add1(GTK_PANED(hpaned),
1659                                GTK_WIDGET_PTR(mainwin->folderview));
1660                 gtk_paned_add2(GTK_PANED(hpaned),
1661                                GTK_WIDGET_PTR(mainwin->summaryview));
1662                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1663                                      prefs_common.summaryview_width,
1664                                      prefs_common.summaryview_height);
1665                 gtk_widget_set_usize(mainwin->window,
1666                                      prefs_common.folderview_width +
1667                                      prefs_common.mainview_width,
1668                                      prefs_common.mainwin_height);
1669                 gtk_widget_show_all(hpaned);
1670                 gtk_container_add(GTK_CONTAINER(messagewin),
1671                                   GTK_WIDGET_PTR(mainwin->messageview));
1672         
1673                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1674                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1675
1676                 mainwin->win.sep_message.messagewin = messagewin;
1677                 mainwin->win.sep_message.hpaned     = hpaned;
1678
1679                 gtk_widget_show_all(messagewin);
1680                 break;
1681         case SEPARATE_BOTH:
1682                 gtk_box_pack_start(GTK_BOX(vbox_body),
1683                                    GTK_WIDGET_PTR(mainwin->summaryview),
1684                                    TRUE, TRUE, 0);
1685                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1686                                      prefs_common.summaryview_width,
1687                                      prefs_common.summaryview_height);
1688                 gtk_widget_set_usize(mainwin->window,
1689                                      prefs_common.mainview_width,
1690                                      prefs_common.mainwin_height);
1691                 gtk_container_add(GTK_CONTAINER(folderwin),
1692                                   GTK_WIDGET_PTR(mainwin->folderview));
1693                 gtk_container_add(GTK_CONTAINER(messagewin),
1694                                   GTK_WIDGET_PTR(mainwin->messageview));
1695
1696                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1697                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1698         
1699                 mainwin->win.sep_both.folderwin = folderwin;
1700                 mainwin->win.sep_both.messagewin = messagewin;
1701
1702                 gtk_widget_show_all(folderwin);
1703                 gtk_widget_show_all(messagewin);
1704                 break;
1705         }
1706
1707         mainwin->type = type;
1708
1709         debug_print(_("done.\n"));
1710 }
1711
1712 #include "pixmaps/stock_mail_receive.xpm"
1713 #include "pixmaps/stock_mail_receive_all.xpm"
1714 #include "pixmaps/stock_mail_compose.xpm"
1715 #include "pixmaps/stock_news_compose.xpm"
1716 #include "pixmaps/stock_mail_reply.xpm"
1717 #include "pixmaps/stock_mail_reply_to_all.xpm"
1718 #include "pixmaps/stock_mail_reply_to_author.xpm"
1719 #include "pixmaps/stock_mail_forward.xpm"
1720 #include "pixmaps/stock_mail_send.xpm"
1721 #include "pixmaps/stock_preferences.xpm"
1722 #include "pixmaps/stock_properties.xpm"
1723 #include "pixmaps/stock_down_arrow.xpm"
1724 #include "pixmaps/stock_close.xpm"
1725 #include "pixmaps/stock_exec.xpm"
1726
1727 #define CREATE_TOOLBAR_ICON(xpm_d) \
1728 { \
1729         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1730                                             &container->style->white, \
1731                                             xpm_d); \
1732         icon_wid = gtk_pixmap_new(icon, mask); \
1733 }
1734
1735 static void main_window_toolbar_create(MainWindow *mainwin,
1736                                        GtkWidget *container)
1737 {
1738         GtkWidget *toolbar;
1739         GdkPixmap *icon;
1740         GdkBitmap *mask;
1741         GtkWidget *icon_wid;
1742         GtkWidget *get_btn;
1743         GtkWidget *getall_btn;
1744         GtkWidget *compose_mail_btn;
1745         GtkWidget *compose_news_btn;
1746         GtkWidget *reply_btn;
1747         GtkWidget *replyall_btn;
1748         GtkWidget *replysender_btn;
1749         GtkWidget *fwd_btn;
1750         GtkWidget *send_btn;
1751         /*
1752         GtkWidget *prefs_btn;
1753         GtkWidget *account_btn;
1754         */
1755         GtkWidget *next_btn;
1756         GtkWidget *delete_btn;
1757         GtkWidget *exec_btn;
1758         
1759         GtkTooltips *tooltips;
1760
1761         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1762                                   GTK_TOOLBAR_BOTH);
1763         gtk_container_add(GTK_CONTAINER(container), toolbar);
1764         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1765         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1766         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1767                                     GTK_TOOLBAR_SPACE_LINE);
1768
1769         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1770         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1771                                           _("Get"),
1772                                           _("Get new mail from current account"),
1773                                           "Get",
1774                                           icon_wid, toolbar_inc_cb, mainwin);
1775         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1776         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1777                                              _("Get all"),
1778                                              _("Get new mail from all accounts"),
1779                                              "Get all",
1780                                              icon_wid,
1781                                              toolbar_inc_all_cb,
1782                                              mainwin);
1783
1784         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1785
1786         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1787         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1788                                            _("Send"),
1789                                            _("Send queued message(s)"),
1790                                            "Send",
1791                                            icon_wid,
1792                                            toolbar_send_cb,
1793                                            mainwin);
1794
1795         /* insert compose mail button widget */                                    
1796
1797         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1798         compose_mail_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1799                                               _("Email"),
1800                                               _("Compose an email message"),
1801                                               "New",
1802                                               icon_wid,
1803                                               toolbar_compose_mail_cb,
1804                                               mainwin);
1805
1806         /* insert compose news button widget */
1807
1808         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1809         compose_news_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1810                                               _("News"),
1811                                               _("Compose a news message"),
1812                                               "New",
1813                                               icon_wid,
1814                                               toolbar_compose_news_cb,
1815                                               mainwin);
1816
1817         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1818         
1819         /* reply button */
1820         
1821         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1822         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1823                                             _("Reply"),
1824                                             _("Reply to the message - Right button: more options"),
1825                                             "Reply",
1826                                             icon_wid,
1827                                             toolbar_reply_cb,
1828                                             mainwin);
1829
1830         /* replyall button */
1831         
1832         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1833         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1834                                                _("All"),
1835                                                _("Reply to all - Right button: more options"),
1836                                                "Reply to all",
1837                                                icon_wid,
1838                                                toolbar_reply_to_all_cb,
1839                                                mainwin);
1840
1841         /* reply to sender button */
1842         
1843         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1844         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1845                                                   _("Sender"),
1846                                                   _("Reply to sender - Right button: more options"),
1847                                                   "Reply to sender",
1848                                                   icon_wid,
1849                                                   toolbar_reply_to_sender_cb,
1850                                                   mainwin);
1851
1852         /* forward button */
1853         
1854         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1855         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1856                                           _("Forward"),
1857                                           _("Forward the message - Right button: more options"),
1858                                           "Fwd",
1859                                           icon_wid,
1860                                           toolbar_forward_cb,
1861                                           mainwin);
1862
1863         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1864
1865         CREATE_TOOLBAR_ICON(stock_close_xpm);
1866         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1867                                           _("Delete"),
1868                                           _("Delete the message"),
1869                                           "Delete",
1870                                           icon_wid,
1871                                           toolbar_delete_cb,
1872                                           mainwin);
1873
1874         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1875         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1876                                            _("Execute"),
1877                                            _("Execute marked process"),
1878                                            "Execute",
1879                                            icon_wid,
1880                                            toolbar_exec_cb,
1881                                            mainwin);
1882
1883         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1884         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1885                                            _("Next"),
1886                                            _("Next unread message"),
1887                                            "Next unread",
1888                                            icon_wid,
1889                                            toolbar_next_unread_cb,
1890                                            mainwin);
1891
1892         /*
1893         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1894
1895         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1896         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1897                                             _("Prefs"),
1898                                             _("Common preference"),
1899                                             "Prefs",
1900                                             icon_wid,
1901                                             toolbar_prefs_cb,
1902                                             mainwin);
1903         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1904         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1905                                               _("Account"),
1906                                               _("Account setting"),
1907                                               "Account",
1908                                               icon_wid,
1909                                               toolbar_account_cb,
1910                                               mainwin);
1911         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1912                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1913                            mainwin);
1914         */
1915
1916         gtk_signal_connect(GTK_OBJECT(reply_btn), "button_press_event",
1917                 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1918                 mainwin);
1919         
1920         gtk_signal_connect(GTK_OBJECT(replyall_btn), "button_press_event",
1921                 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1922                 mainwin);
1923         
1924         gtk_signal_connect(GTK_OBJECT(replysender_btn), "button_press_event",
1925                 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1926                 mainwin);
1927         
1928         gtk_signal_connect(GTK_OBJECT(fwd_btn), "button_press_event",
1929                 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1930                 mainwin);
1931         
1932
1933         mainwin->toolbar                         = toolbar;
1934         mainwin->get_btn                         = get_btn;
1935         mainwin->getall_btn                      = getall_btn;
1936         mainwin->compose_mail_btn                = compose_mail_btn;
1937         mainwin->compose_news_btn                = compose_news_btn;
1938         mainwin->reply_btn                       = reply_btn;
1939         mainwin->replyall_btn                    = replyall_btn;
1940         mainwin->replysender_btn                 = replysender_btn;
1941         mainwin->fwd_btn         = fwd_btn;
1942         mainwin->send_btn        = send_btn;
1943         /*
1944         mainwin->prefs_btn       = prefs_btn;
1945         mainwin->account_btn     = account_btn;
1946         */
1947         mainwin->next_btn        = next_btn;
1948         mainwin->delete_btn      = delete_btn;
1949         mainwin->exec_btn        = exec_btn;
1950
1951         gtk_widget_show_all(toolbar);
1952 }
1953
1954 /* callback functions */
1955 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1956 {
1957         MainWindow *mainwindow = (MainWindow *) data;
1958         
1959         if (!event) return;
1960
1961         if (event->button == 3)
1962                 gtk_menu_popup(GTK_MENU(mainwindow->reply_popup), NULL, NULL, NULL,     NULL, 1, 0);
1963 }
1964
1965 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1966 {
1967         MainWindow *mainwindow = (MainWindow *) data;
1968         
1969         if (!event) return;
1970
1971         if (event->button == 3)
1972                 gtk_menu_popup(GTK_MENU(mainwindow->replyall_popup), NULL, NULL, NULL,  NULL, 1, 0);
1973 }
1974
1975 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1976 {
1977         MainWindow *mainwindow = (MainWindow *) data;
1978         GtkWidget *replysender_menu, *replysender_item;
1979
1980         if (!event) return;
1981
1982         if (event->button == 3)
1983                 gtk_menu_popup(GTK_MENU(mainwindow->replysender_popup), NULL, NULL, NULL,       NULL, 1, 0);
1984 }
1985
1986 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1987 {
1988         MainWindow *mainwindow = (MainWindow *) data;
1989         
1990         if (!event) return;
1991
1992         if (event->button == 3)
1993                 gtk_menu_popup(GTK_MENU(mainwindow->fwd_popup), NULL, NULL, NULL,       NULL, 1, 0);
1994 }
1995
1996 static void toolbar_inc_cb      (GtkWidget      *widget,
1997                                  gpointer        data)
1998 {
1999         MainWindow *mainwin = (MainWindow *)data;
2000
2001         inc_mail_cb(mainwin, 0, NULL);
2002 }
2003
2004 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2005                                  gpointer        data)
2006 {
2007         MainWindow *mainwin = (MainWindow *)data;
2008
2009         inc_all_account_mail_cb(mainwin, 0, NULL);
2010 }
2011
2012 static void toolbar_send_cb     (GtkWidget      *widget,
2013                                  gpointer        data)
2014 {
2015         MainWindow *mainwin = (MainWindow *)data;
2016
2017         send_queue_cb(mainwin, 0, NULL);
2018 }
2019
2020 static void toolbar_compose_cb  (GtkWidget      *widget,
2021                                  gpointer        data)
2022 {
2023         MainWindow *mainwin = (MainWindow *)data;
2024
2025         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
2026                 compose_cb(mainwin, 0, NULL);
2027         else
2028                 compose_news_cb(mainwin, 0, NULL);
2029 }
2030
2031 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2032                                  gpointer        data)
2033 {
2034         MainWindow *mainwin = (MainWindow *)data;
2035
2036         compose_news_cb(mainwin, 0, NULL);
2037 }
2038
2039 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2040                                  gpointer        data)
2041 {
2042         MainWindow *mainwin = (MainWindow *)data;
2043
2044         compose_mail_cb(mainwin, 0, NULL);
2045 }
2046
2047 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
2048 {
2049         MainWindow *mainwin = (MainWindow *)data;
2050
2051         reply_cb(mainwin, 
2052                  prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2053                  : COMPOSE_REPLY_WITHOUT_QUOTE,
2054                  NULL);
2055 }
2056
2057 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
2058 {
2059         MainWindow *mainwin = (MainWindow *)data;
2060
2061         reply_cb(mainwin, 
2062                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2063                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2064                  NULL);
2065 }
2066
2067
2068 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
2069 {
2070         MainWindow *mainwin = (MainWindow *)data;
2071
2072         reply_cb(mainwin, 
2073                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2074                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2075                  NULL);
2076 }
2077
2078 static void toolbar_forward_cb  (GtkWidget      *widget,
2079                                  gpointer        data)
2080 {
2081         MainWindow *mainwin = (MainWindow *)data;
2082
2083         if (prefs_common.forward_as_attachment)
2084                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2085         else
2086                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2087 }
2088
2089 static void toolbar_delete_cb   (GtkWidget      *widget,
2090                                  gpointer        data)
2091 {
2092         MainWindow *mainwin = (MainWindow *)data;
2093
2094         summary_delete(mainwin->summaryview);
2095 }
2096
2097 static void toolbar_exec_cb     (GtkWidget      *widget,
2098                                  gpointer        data)
2099 {
2100         MainWindow *mainwin = (MainWindow *)data;
2101
2102         summary_execute(mainwin->summaryview);
2103 }
2104
2105 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2106                                          gpointer        data)
2107 {
2108         MainWindow *mainwin = (MainWindow *)data;
2109
2110         next_unread_cb(mainwin, 0, NULL);
2111 }
2112
2113 static void toolbar_prefs_cb    (GtkWidget      *widget,
2114                                  gpointer        data)
2115 {
2116         prefs_common_open();
2117 }
2118
2119 static void toolbar_account_cb  (GtkWidget      *widget,
2120                                  gpointer        data)
2121 {
2122         MainWindow *mainwin = (MainWindow *)data;
2123
2124         prefs_account_open_cb(mainwin, 0, NULL);
2125 }
2126
2127 static void toolbar_account_button_pressed(GtkWidget *widget,
2128                                            GdkEventButton *event,
2129                                            gpointer data)
2130 {
2131         MainWindow *mainwin = (MainWindow *)data;
2132
2133         if (!event) return;
2134         if (event->button != 3) return;
2135
2136         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2137         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2138                             widget);
2139
2140         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2141                        menu_button_position, widget,
2142                        event->button, event->time);
2143 }
2144
2145 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2146                                     gpointer data)
2147 {
2148         MainWindow *mainwin = (MainWindow *)data;
2149
2150         if (!event) return;
2151
2152         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2153         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2154                             widget);
2155
2156         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2157                        menu_button_position, widget,
2158                        event->button, event->time);
2159 }
2160
2161 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2162 {
2163         MainWindow *mainwin = (MainWindow *)data;
2164         GtkWidget *button;
2165
2166         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2167         if (!button) return;
2168         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2169         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2170         manage_window_focus_in(mainwin->window, NULL, NULL);
2171 }
2172
2173 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2174                                  gpointer data)
2175 {
2176         MainWindow *mainwin = (MainWindow *)data;
2177
2178         if (mainwin->lock_count == 0)
2179                 app_exit_cb(data, 0, widget);
2180
2181         return TRUE;
2182 }
2183
2184 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2185                            GtkWidget *widget)
2186 {
2187         main_window_add_mailbox(mainwin);
2188 }
2189
2190 static void add_mbox_cb(MainWindow *mainwin, guint action,
2191                         GtkWidget *widget)
2192 {
2193         main_window_add_mbox(mainwin);
2194 }
2195
2196 static void update_folderview_cb(MainWindow *mainwin, guint action,
2197                                  GtkWidget *widget)
2198 {
2199         summary_show(mainwin->summaryview, NULL, FALSE);
2200         folderview_update_all();
2201 }
2202
2203 static void new_folder_cb(MainWindow *mainwin, guint action,
2204                           GtkWidget *widget)
2205 {
2206         folderview_new_folder(mainwin->folderview);
2207 }
2208
2209 static void rename_folder_cb(MainWindow *mainwin, guint action,
2210                              GtkWidget *widget)
2211 {
2212         folderview_rename_folder(mainwin->folderview);
2213 }
2214
2215 static void delete_folder_cb(MainWindow *mainwin, guint action,
2216                              GtkWidget *widget)
2217 {
2218         folderview_delete_folder(mainwin->folderview);
2219 }
2220
2221 static void import_mbox_cb(MainWindow *mainwin, guint action,
2222                            GtkWidget *widget)
2223 {
2224         import_mbox(mainwin->summaryview->folder_item);
2225 }
2226
2227 static void export_mbox_cb(MainWindow *mainwin, guint action,
2228                            GtkWidget *widget)
2229 {
2230         export_mbox(mainwin->summaryview->folder_item);
2231 }
2232
2233 static void empty_trash_cb(MainWindow *mainwin, guint action,
2234                            GtkWidget *widget)
2235 {
2236         main_window_empty_trash(mainwin, TRUE);
2237 }
2238
2239 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2240 {
2241         summary_save_as(mainwin->summaryview);
2242 }
2243
2244 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2245 {
2246         summary_print(mainwin->summaryview);
2247 }
2248
2249 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2250 {
2251         if (prefs_common.confirm_on_exit) {
2252                 if (alertpanel(_("Exit"), _("Exit this program?"),
2253                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2254                         return;
2255                 manage_window_focus_in(mainwin->window, NULL, NULL);
2256         }
2257
2258         app_will_exit(widget, mainwin);
2259 }
2260
2261 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2262 {
2263         if (action == 1)
2264                 summary_search(mainwin->summaryview);
2265         else
2266                 message_search(mainwin->messageview);
2267 }
2268
2269 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2270                              GtkWidget *widget)
2271 {
2272         switch (mainwin->type) {
2273         case SEPARATE_NONE:
2274         case SEPARATE_MESSAGE:
2275                 break;
2276         case SEPARATE_FOLDER:
2277                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2278                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2279                 else
2280                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2281                 break;
2282         case SEPARATE_BOTH:
2283                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2284                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2285                 else
2286                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2287                 break;
2288         }
2289 }
2290
2291 static void toggle_message_cb(MainWindow *mainwin, guint action,
2292                               GtkWidget *widget)
2293 {
2294         switch (mainwin->type) {
2295         case SEPARATE_NONE:
2296         case SEPARATE_FOLDER:
2297                 break;
2298         case SEPARATE_MESSAGE:
2299                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2300                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2301                 else
2302                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2303                 break;
2304         case SEPARATE_BOTH:
2305                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2306                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2307                 else
2308                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2309                 break;
2310         }
2311 }
2312
2313 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2314                               GtkWidget *widget)
2315 {
2316 /*      activate_compose_button(mainwin, (ToolbarStyle)action, 
2317                         mainwin->compose_btn_type);
2318         set_toolbar_reply_button(mainwin, (ToolbarStyle)action);
2319         set_toolbar_replyall_button(mainwin, (ToolbarStyle)action);
2320         set_toolbar_replysender_button(mainwin, (ToolbarStyle)action);
2321         set_toolbar_forward_button(mainwin, (ToolbarStyle)action);*/
2322         
2323         switch ((ToolbarStyle)action) {
2324         case TOOLBAR_NONE:
2325                 gtk_widget_hide(mainwin->handlebox);
2326         case TOOLBAR_ICON:
2327                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2328                                       GTK_TOOLBAR_ICONS);
2329                 break;
2330         case TOOLBAR_TEXT:
2331                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2332                                       GTK_TOOLBAR_TEXT);
2333                 break;
2334         case TOOLBAR_BOTH:
2335                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2336                                       GTK_TOOLBAR_BOTH);
2337                 break;
2338         }
2339
2340         if (action != TOOLBAR_NONE) {
2341                 gtk_widget_show(mainwin->handlebox);
2342                 gtk_widget_queue_resize(mainwin->handlebox);
2343         }
2344
2345         mainwin->toolbar_style = (ToolbarStyle)action;
2346         prefs_common.toolbar_style = (ToolbarStyle)action;
2347 }
2348
2349 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2350                                 GtkWidget *widget)
2351 {
2352         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2353                 gtk_widget_show(mainwin->hbox_stat);
2354                 prefs_common.show_statusbar = TRUE;
2355         } else {
2356                 gtk_widget_hide(mainwin->hbox_stat);
2357                 prefs_common.show_statusbar = FALSE;
2358         }
2359 }
2360
2361 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action, GtkWidget *widget)
2362
2363 {
2364         MainWindow *mainwin;
2365         SeparateType type;
2366
2367         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2368         g_return_if_fail(mainwin != NULL);
2369
2370         type = mainwin->type ^ action;
2371         main_window_separation_change(mainwin, type);
2372
2373         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2374         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2375 }
2376
2377 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2378                                 GtkWidget *widget)
2379 {
2380         addressbook_open(NULL);
2381 }
2382
2383 static void log_window_show_cb(MainWindow *mainwin, guint action,
2384                                GtkWidget *widget)
2385 {
2386         log_window_show(mainwin->logwin);
2387 }
2388
2389 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2390 {
2391         inc_mail(mainwin);
2392 }
2393
2394 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2395                                     GtkWidget *widget)
2396 {
2397         inc_all_account_mail(mainwin);
2398 }
2399
2400 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2401 {
2402         GList *list;
2403
2404         if (procmsg_send_queue() < 0)
2405                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2406
2407         statusbar_pop_all();
2408
2409         for (list = folder_get_list(); list != NULL; list = list->next) {
2410                 Folder *folder;
2411
2412                 folder = list->data;
2413                 if (folder->queue) {
2414                         folder_item_scan(folder->queue);
2415                         folderview_update_item(folder->queue, TRUE);
2416                 }
2417         }
2418 }
2419
2420 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2421 {
2422         if (mainwin->summaryview->folder_item) {
2423                 if (mainwin->summaryview->folder_item->folder->account != NULL
2424                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2425                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2426                 else
2427                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2428         }
2429         else
2430                 compose_new(NULL);
2431 }
2432
2433 static void compose_mail_cb(MainWindow *mainwin, guint action,
2434                             GtkWidget *widget)
2435 {
2436         PrefsAccount * ac;
2437         GList * list;
2438         GList * cur;
2439
2440         if (mainwin->summaryview->folder_item) {
2441                 ac = mainwin->summaryview->folder_item->folder->account;
2442                 if (ac && ac->protocol != A_NNTP) {
2443                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2444                         return;
2445                 }
2446         }
2447
2448         if(cur_account && (cur_account->protocol != A_NNTP)) {
2449                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2450                 return;
2451         }
2452
2453         list = account_get_list();
2454         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2455                 ac = (PrefsAccount *) cur->data;
2456                 if (ac->protocol != A_NNTP) {
2457                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2458                         return;
2459                 }
2460         }
2461 }
2462
2463 static void compose_news_cb(MainWindow *mainwin, guint action,
2464                             GtkWidget *widget)
2465 {
2466         PrefsAccount * ac = NULL;
2467         GList * list;
2468         GList * cur;
2469
2470         if (mainwin->summaryview->folder_item) {
2471                 ac = mainwin->summaryview->folder_item->folder->account;
2472                 if (ac && ac->protocol == A_NNTP) {
2473                         compose_new_with_recipient
2474                                 (ac, mainwin->summaryview->folder_item->path);
2475                         return;
2476                 }
2477         }
2478
2479         list = account_get_list();
2480         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2481                 ac = (PrefsAccount *) cur->data;
2482                 if (ac->protocol == A_NNTP) {
2483                         compose_new(ac);
2484                         return;
2485                 }
2486         }
2487 }
2488
2489 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2490 {
2491         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2492         MsgInfo *msginfo;
2493
2494         msginfo = gtk_ctree_node_get_row_data
2495                 (GTK_CTREE(mainwin->summaryview->ctree),
2496                  mainwin->summaryview->selected);
2497
2498         if (!msginfo) return;
2499
2500         switch (action) {
2501         case COMPOSE_REPLY:
2502                 compose_reply(msginfo, prefs_common.reply_with_quote,
2503                               FALSE, FALSE);
2504                 break;
2505         case COMPOSE_REPLY_WITH_QUOTE:
2506                 compose_reply(msginfo, TRUE, FALSE, FALSE);
2507                 break;
2508         case COMPOSE_REPLY_WITHOUT_QUOTE:
2509                 compose_reply(msginfo, FALSE, FALSE, FALSE);
2510                 break;
2511         case COMPOSE_REPLY_TO_SENDER:
2512                 compose_reply(msginfo, prefs_common.reply_with_quote,
2513                               FALSE, TRUE);
2514                 break;
2515         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
2516                 compose_reply(msginfo, TRUE, FALSE, TRUE);
2517                 break;
2518         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
2519                 compose_reply(msginfo, FALSE, FALSE, TRUE);
2520                 break;
2521         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2522                 compose_followup_and_reply_to(msginfo,
2523                                               prefs_common.reply_with_quote,
2524                                               FALSE, TRUE);
2525                 break;
2526         case COMPOSE_REPLY_TO_ALL:
2527                 compose_reply(msginfo, prefs_common.reply_with_quote,
2528                               TRUE, TRUE);
2529                 break;
2530         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
2531                 compose_reply(msginfo, TRUE, TRUE, TRUE);
2532                 break;
2533         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
2534                 compose_reply(msginfo, FALSE, TRUE, TRUE);
2535                 break;
2536         case COMPOSE_FORWARD:
2537                 if (prefs_common.forward_as_attachment) {
2538                         reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, widget);
2539                         return;
2540                 } else {
2541                         reply_cb(mainwin, COMPOSE_FORWARD_INLINE, widget);
2542                         return;
2543                 }
2544                 break;
2545         case COMPOSE_FORWARD_INLINE:
2546                 if (!sel->next) {
2547                         compose_forward(NULL, msginfo, FALSE);
2548                         break;
2549                 }
2550                 /* if (sel->next) FALL_THROUGH */
2551         case COMPOSE_FORWARD_AS_ATTACH:
2552                 {
2553                         GSList *msginfo_list = NULL;
2554                         for ( ; sel != NULL; sel = sel->next)
2555                                 msginfo_list = g_slist_append(msginfo_list, 
2556                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2557                                                 GTK_CTREE_NODE(sel->data)));
2558                         compose_forward_multiple(NULL, msginfo_list);
2559                         g_slist_free(msginfo_list);
2560                 }                       
2561                 break;
2562         case COMPOSE_BOUNCE:
2563                         compose_bounce(NULL, msginfo);
2564                         break;
2565         default:
2566                 g_warning("reply_cb(): invalid action type: %d\n", action);
2567         }
2568
2569         summary_set_marks_selected(mainwin->summaryview);
2570 }
2571
2572 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2573 {
2574         summary_move_to(mainwin->summaryview);
2575 }
2576
2577 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2578 {
2579         summary_copy_to(mainwin->summaryview);
2580 }
2581
2582 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2583 {
2584         summary_delete(mainwin->summaryview);
2585 }
2586
2587 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2588 {
2589         summary_open_msg(mainwin->summaryview);
2590 }
2591
2592 static void view_source_cb(MainWindow *mainwin, guint action,
2593                            GtkWidget *widget)
2594 {
2595         summary_view_source(mainwin->summaryview);
2596 }
2597
2598 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2599 {
2600         summary_reedit(mainwin->summaryview);
2601 }
2602
2603 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2604 {
2605         summary_mark(mainwin->summaryview);
2606 }
2607
2608 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2609 {
2610         summary_unmark(mainwin->summaryview);
2611 }
2612
2613 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2614                               GtkWidget *widget)
2615 {
2616         summary_mark_as_unread(mainwin->summaryview);
2617 }
2618
2619 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2620                             GtkWidget *widget)
2621 {
2622         summary_mark_as_read(mainwin->summaryview);
2623 }
2624
2625 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2626                              GtkWidget *widget)
2627 {
2628         summary_mark_all_read(mainwin->summaryview);
2629 }
2630
2631 static void add_address_cb(MainWindow *mainwin, guint action,
2632                            GtkWidget *widget)
2633 {
2634         summary_add_address(mainwin->summaryview);
2635 }
2636
2637 static void set_charset_cb(MainWindow *mainwin, guint action,
2638                            GtkWidget *widget)
2639 {
2640         const gchar *str;
2641
2642         str = conv_get_charset_str((CharSet)action);
2643         g_free(prefs_common.force_charset);
2644         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2645
2646         summary_redisplay_msg(mainwin->summaryview);
2647
2648         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2649 }
2650
2651 static void hide_read_messages (MainWindow *mainwin, guint action,
2652                                 GtkWidget *widget)
2653 {
2654         if (!mainwin->summaryview->folder_item
2655             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2656                 return;
2657         summary_toggle_show_read_messages(mainwin->summaryview);
2658 }
2659
2660 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2661 {
2662         GtkItemFactory *ifactory;
2663
2664         if (!mainwin->summaryview->folder_item) return;
2665
2666         ifactory = gtk_item_factory_from_widget(widget);
2667
2668         if (0 == action) {
2669                 summary_thread_build(mainwin->summaryview);
2670                 mainwin->summaryview->folder_item->threaded = TRUE;
2671                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2672                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2673         } else {
2674                 summary_unthread(mainwin->summaryview);
2675                 mainwin->summaryview->folder_item->threaded = FALSE;
2676                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2677                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2678         }
2679 }
2680
2681 static void set_display_item_cb(MainWindow *mainwin, guint action,
2682                                 GtkWidget *widget)
2683 {
2684         prefs_summary_column_open();
2685 }
2686
2687 static void sort_summary_cb(MainWindow *mainwin, guint action,
2688                             GtkWidget *widget)
2689 {
2690         summary_sort(mainwin->summaryview, (SummarySortType)action);
2691 }
2692
2693 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2694                                   GtkWidget *widget)
2695 {
2696         summary_attract_by_subject(mainwin->summaryview);
2697 }
2698
2699 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2700                                  GtkWidget *widget)
2701 {
2702         summary_delete_duplicated(mainwin->summaryview);
2703 }
2704
2705 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2706 {
2707         summary_filter(mainwin->summaryview);
2708 }
2709
2710 static void execute_summary_cb(MainWindow *mainwin, guint action,
2711                                GtkWidget *widget)
2712 {
2713         summary_execute(mainwin->summaryview);
2714 }
2715
2716 static void update_summary_cb(MainWindow *mainwin, guint action,
2717                               GtkWidget *widget)
2718 {
2719         FolderItem *fitem;
2720         FolderView *folderview = mainwin->folderview;
2721
2722         if (!mainwin->summaryview->folder_item) return;
2723         if (!folderview->opened) return;
2724
2725         folder_update_op_count();
2726
2727         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2728                                             folderview->opened);
2729         if (!fitem) return;
2730
2731         summary_show(mainwin->summaryview, fitem, TRUE);
2732 }
2733
2734 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2735 {
2736         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2737 }
2738
2739 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2740 {
2741         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2742 }
2743
2744 static void prev_unread_cb(MainWindow *mainwin, guint action,
2745                            GtkWidget *widget)
2746 {
2747         summary_select_prev_unread(mainwin->summaryview);
2748 }
2749
2750 static void next_unread_cb(MainWindow *mainwin, guint action,
2751                            GtkWidget *widget)
2752 {
2753         summary_select_next_unread(mainwin->summaryview);
2754 }
2755
2756 static void prev_marked_cb(MainWindow *mainwin, guint action,
2757                            GtkWidget *widget)
2758 {
2759         summary_select_prev_marked(mainwin->summaryview);
2760 }
2761
2762 static void next_marked_cb(MainWindow *mainwin, guint action,
2763                            GtkWidget *widget)
2764 {
2765         summary_select_next_marked(mainwin->summaryview);
2766 }
2767
2768 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2769                             GtkWidget *widget)
2770 {
2771         summary_select_prev_labeled(mainwin->summaryview);
2772 }
2773
2774 static void next_labeled_cb(MainWindow *mainwin, guint action,
2775                             GtkWidget *widget)
2776 {
2777         summary_select_next_labeled(mainwin->summaryview);
2778 }
2779
2780 static void goto_folder_cb(MainWindow *mainwin, guint action,
2781                            GtkWidget *widget)
2782 {
2783         FolderItem *to_folder;
2784
2785         to_folder = foldersel_folder_sel(NULL, NULL);
2786
2787         if (to_folder)
2788                 folderview_select(mainwin->folderview, to_folder);
2789 }
2790
2791 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2792 {
2793         messageview_copy_clipboard(mainwin->messageview);
2794 }
2795
2796 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2797 {
2798         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2799                 summary_select_all(mainwin->summaryview);
2800         else if (mainwin->summaryview->msg_is_toggled_on &&
2801                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2802                 messageview_select_all(mainwin->messageview);
2803 }
2804
2805 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2806                                  GtkWidget *widget)
2807 {
2808         prefs_common_open();
2809 }
2810
2811 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2812                                  GtkWidget *widget)
2813 {
2814         prefs_filter_open();
2815 }
2816
2817 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2818                                   GtkWidget *widget)
2819 {
2820         prefs_scoring_open(NULL);
2821 }
2822
2823 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2824                                     GtkWidget *widget)
2825 {
2826         prefs_filtering_open(NULL);
2827 }
2828
2829 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2830                                    GtkWidget *widget)
2831 {
2832         prefs_template_open();
2833 }
2834
2835 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2836                                   GtkWidget *widget)
2837 {
2838         if (!cur_account) {
2839                 new_account_cb(mainwin, 0, widget);
2840         } else {
2841                 gboolean prev_default = cur_account->is_default;
2842
2843                 prefs_account_open(cur_account);
2844                 if (!prev_default && cur_account->is_default)
2845                         account_set_as_default(cur_account);
2846                 account_save_config_all();
2847                 account_set_menu();
2848                 main_window_reflect_prefs_all();
2849         }
2850 }
2851
2852 static void new_account_cb(MainWindow *mainwin, guint action,
2853                            GtkWidget *widget)
2854 {
2855         account_edit_open();
2856         if (!compose_get_compose_list()) account_add();
2857 }
2858
2859 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2860 {
2861         cur_account = (PrefsAccount *)data;
2862         main_window_reflect_prefs_all();
2863 }
2864
2865 static void manual_open_cb(MainWindow *mainwin, guint action,
2866                            GtkWidget *widget)
2867 {
2868         manual_open((ManualLang)action);
2869 }
2870
2871 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2872 {
2873         MainWindow *mainwin = (MainWindow *)data;
2874         gchar *str;
2875
2876         if (item->path)
2877                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2878                                       LOCAL_FOLDER(folder)->rootpath,
2879                                       G_DIR_SEPARATOR,
2880                                       item->path);
2881         else
2882                 str = g_strdup_printf(_("Scanning folder %s ..."),
2883                                       LOCAL_FOLDER(folder)->rootpath);
2884
2885         STATUSBAR_PUSH(mainwin, str);
2886         STATUSBAR_POP(mainwin);
2887         g_free(str);
2888 }
2889
2890 static void activate_compose_button (MainWindow *mainwin,
2891                                 ToolbarStyle style,
2892                                 ComposeButtonType type)
2893 {
2894         SensitiveCond state = main_window_get_current_state(mainwin);
2895
2896         if (style == TOOLBAR_NONE) 
2897                 return;
2898
2899         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2900                 : mainwin->compose_news_btn);
2901         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2902                 : mainwin->compose_mail_btn);
2903         mainwin->compose_btn_type = type;       
2904 }
2905
2906 void main_window_toolbar_set_compose_button(MainWindow *mainwin, ComposeButtonType compose_btn_type)
2907 {
2908         if (mainwin->compose_btn_type != compose_btn_type)
2909                 activate_compose_button(mainwin, 
2910                                         prefs_common.toolbar_style,
2911                                         compose_btn_type);
2912 }