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