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