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