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