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