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