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