add 'Mark all read', remove 'Add sender to address book'
[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/_Mark/Mark all read"),   NULL, mark_all_read_cb, 0, NULL},                                                
554         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
555         {N_("/_Message/Open in new _window"),   "<shift><control>N", open_msg_cb, 0, NULL},
556
557         {N_("/_Summary"),                       NULL, NULL, 0, "<Branch>"},
558         {N_("/_Summary/_Delete duplicated messages"),
559                                                 NULL, delete_duplicated_cb,   0, NULL},
560         {N_("/_Summary/_Filter messages"),      NULL, filter_cb, 0, NULL},
561         {N_("/_Summary/E_xecute"),              "<alt>X", execute_summary_cb, 0, NULL},
562         {N_("/_Summary/_Update"),               "<alt>U", update_summary_cb,  0, NULL},
563         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
564         {N_("/_Summary/Go _to"),                NULL, NULL, 0, "<Branch>"},
565         {N_("/_Summary/Go _to/_Prev message"),  NULL, prev_cb, 0, NULL},
566         {N_("/_Summary/Go _to/_Next message"),  NULL, next_cb, 0, NULL},
567         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
568         {N_("/_Summary/Go _to/P_rev unread message"),
569                                                 NULL, prev_unread_cb, 0, NULL},
570         {N_("/_Summary/Go _to/N_ext unread message"),
571                                                 NULL, next_unread_cb, 0, NULL},
572         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
573         {N_("/_Summary/Go _to/Prev _marked message"),
574                                                 NULL, prev_marked_cb, 0, NULL},
575         {N_("/_Summary/Go _to/Next m_arked message"),
576                                                 NULL, next_marked_cb, 0, NULL},
577         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
578         {N_("/_Summary/Go _to/Prev _labeled message"),
579                                                 NULL, prev_labeled_cb, 0, NULL},
580         {N_("/_Summary/Go _to/Next la_beled message"),
581                                                 NULL, next_labeled_cb, 0, NULL},
582         {N_("/_Summary/_Go to other folder..."),"<alt>G", goto_folder_cb, 0, NULL},
583         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
584         {N_("/_Summary/_Sort"),                 NULL, NULL, 0, "<Branch>"},
585         {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
586         {N_("/_Summary/_Sort/Sort by s_ize"),   NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
587         {N_("/_Summary/_Sort/Sort by _date"),   NULL, sort_summary_cb, SORT_BY_DATE, NULL},
588         {N_("/_Summary/_Sort/Sort by _from"),   NULL, sort_summary_cb, SORT_BY_FROM, NULL},
589         {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
590         {N_("/_Summary/_Sort/Sort by _color label"),
591                                                 NULL, sort_summary_cb, SORT_BY_LABEL, NULL},
592         {N_("/_Summary/_Sort/Sort by _mark"),   NULL, sort_summary_cb, SORT_BY_MARK, NULL},
593         {N_("/_Summary/_Sort/Sort by _unread"), NULL, sort_summary_cb, SORT_BY_UNREAD, NULL},
594         {N_("/_Summary/_Sort/Sort by a_ttachment"),
595                                                 NULL, sort_summary_cb, SORT_BY_MIME, NULL},
596         {N_("/_Summary/_Sort/---"),             NULL, NULL, 0, "<Separator>"},
597         {N_("/_Summary/_Sort/_Attract by subject"),
598                                                 NULL, attract_by_subject_cb, 0, NULL},
599         {N_("/_Summary/_Thread view"),          "<control>T",        thread_cb, 0, NULL},
600         {N_("/_Summary/Unt_hread view"),        "<shift><control>T", thread_cb, 1, NULL},
601         {N_("/_Summary/Set display _item..."),  NULL, set_display_item_cb, 0, NULL},
602
603         {N_("/_Tool"),                          NULL, NULL, 0, "<Branch>"},
604         {N_("/_Tool/_Address book"),            "<alt>A", addressbook_open_cb, 0, NULL},
605         {N_("/_Tool/_Log window"),              "<alt>L", log_window_show_cb, 0, NULL},
606
607         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
608         {N_("/_Configuration/_Common preferences..."),
609                                                 NULL, prefs_common_open_cb, 0, NULL},
610         {N_("/_Configuration/_Filter setting..."),
611                                                 NULL, prefs_filter_open_cb, 0, NULL},
612         {N_("/_Configuration/_Scoring ..."),
613                                                 NULL, prefs_scoring_open_cb, 0, NULL},
614         {N_("/_Configuration/_Filtering ..."),
615                                                 NULL, prefs_filtering_open_cb, 0, NULL},
616         {N_("/_Configuration/_Template..."),    NULL, prefs_template_open_cb, 0, NULL},
617         {N_("/_Configuration/_Preferences for current account..."),
618                                                 NULL, prefs_account_open_cb, 0, NULL},
619         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
620         {N_("/_Configuration/Create _new account..."),
621                                                 NULL, new_account_cb, 0, NULL},
622         {N_("/_Configuration/_Edit accounts..."),
623                                                 NULL, account_edit_open, 0, NULL},
624         {N_("/_Configuration/C_hange current account"),
625                                                 NULL, NULL, 0, "<Branch>"},
626
627         {N_("/_Help"),                          NULL, NULL, 0, "<LastBranch>"},
628         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
629         {N_("/_Help/_Manual/_English"),         NULL, manual_open_cb, MANUAL_LANG_EN, NULL},
630         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
631         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
632         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
633 };
634
635 MainWindow *main_window_create(SeparateType type)
636 {
637         MainWindow *mainwin;
638         GtkWidget *window;
639         GtkWidget *vbox;
640         GtkWidget *menubar;
641         GtkWidget *handlebox;
642         GtkWidget *vbox_body;
643         GtkWidget *hbox_stat;
644         GtkWidget *statusbar;
645         GtkWidget *progressbar;
646         GtkWidget *statuslabel;
647         GtkWidget *ac_button;
648         GtkWidget *ac_label;
649
650         FolderView *folderview;
651         SummaryView *summaryview;
652         MessageView *messageview;
653         GdkColormap *colormap;
654         GdkColor color[4];
655         gboolean success[4];
656         guint n_menu_entries;
657         GtkItemFactory *ifactory;
658         GtkWidget *ac_menu;
659         GtkWidget *menuitem;
660         gint i;
661
662         debug_print(_("Creating main window...\n"));
663         mainwin = g_new0(MainWindow, 1);
664
665         /* main window */
666         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
667         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
668         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
669         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
670                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
671         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
672                            GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
673         gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
674                            GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
675
676         gtk_widget_realize(window);
677
678         gtkut_widget_set_app_icon(window);
679
680         vbox = gtk_vbox_new(FALSE, 0);
681         gtk_widget_show(vbox);
682         gtk_container_add(GTK_CONTAINER(window), vbox);
683
684         /* menu bar */
685         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
686         menubar = menubar_create(window, mainwin_entries, 
687                                  n_menu_entries, "<Main>", mainwin);
688         gtk_widget_show(menubar);
689         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
690
691         handlebox = gtk_handle_box_new();
692         gtk_widget_show(handlebox);
693         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
694
695         main_window_toolbar_create(mainwin, handlebox);
696
697         /* vbox that contains body */
698         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
699         gtk_widget_show(vbox_body);
700         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
701         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
702
703         hbox_stat = gtk_hbox_new(FALSE, 2);
704         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
705
706         statusbar = statusbar_create();
707         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
708
709         progressbar = gtk_progress_bar_new();
710         gtk_widget_set_usize(progressbar, 120, 1);
711         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
712
713         statuslabel = gtk_label_new("");
714         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
715
716         ac_button = gtk_button_new();
717         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
718         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
719         gtk_widget_set_usize(ac_button, -1, 1);
720         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
721         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
722                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
723
724         ac_label = gtk_label_new("");
725         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
726
727         gtk_widget_show_all(hbox_stat);
728
729         /* create views */
730         mainwin->folderview  = folderview  = folderview_create();
731         mainwin->summaryview = summaryview = summary_create();
732         mainwin->messageview = messageview = messageview_create();
733         mainwin->headerwin   = header_window_create();
734         mainwin->logwin      = log_window_create();
735
736         folderview->mainwin      = mainwin;
737         folderview->summaryview  = summaryview;
738
739         summaryview->mainwin     = mainwin;
740         summaryview->folderview  = folderview;
741         summaryview->messageview = messageview;
742         summaryview->headerwin   = mainwin->headerwin;
743         summaryview->window      = window;
744
745         messageview->mainwin     = mainwin;
746
747         mainwin->window      = window;
748         mainwin->vbox        = vbox;
749         mainwin->menubar     = menubar;
750         mainwin->handlebox   = handlebox;
751         mainwin->vbox_body   = vbox_body;
752         mainwin->hbox_stat   = hbox_stat;
753         mainwin->statusbar   = statusbar;
754         mainwin->progressbar = progressbar;
755         mainwin->statuslabel = statuslabel;
756         mainwin->ac_button   = ac_button;
757         mainwin->ac_label    = ac_label;
758
759         /* set context IDs for status bar */
760         mainwin->mainwin_cid = gtk_statusbar_get_context_id
761                 (GTK_STATUSBAR(statusbar), "Main Window");
762         mainwin->folderview_cid = gtk_statusbar_get_context_id
763                 (GTK_STATUSBAR(statusbar), "Folder View");
764         mainwin->summaryview_cid = gtk_statusbar_get_context_id
765                 (GTK_STATUSBAR(statusbar), "Summary View");
766
767         /* allocate colors for summary view and folder view */
768         summaryview->color_marked.red = summaryview->color_marked.green = 0;
769         summaryview->color_marked.blue = (guint16)65535;
770
771         summaryview->color_dim.red = summaryview->color_dim.green =
772                 summaryview->color_dim.blue = COLOR_DIM;
773
774         folderview->color_new.red = (guint16)55000;
775         folderview->color_new.green = folderview->color_new.blue = 15000;
776
777         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
778                                        &folderview->color_op);
779
780         summaryview->color_important.red = 0;
781         summaryview->color_marked.green = 0;
782         summaryview->color_important.blue = (guint16)65535;
783
784         color[0] = summaryview->color_marked;
785         color[1] = summaryview->color_dim;
786         color[2] = folderview->color_new;
787         color[3] = folderview->color_op;
788
789         colormap = gdk_window_get_colormap(window->window);
790         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
791         for (i = 0; i < 4; i++) {
792                 if (success[i] == FALSE)
793                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
794         }
795
796         debug_print(_("done.\n"));
797
798         main_window_set_widgets(mainwin, type);
799
800         /* set menu items */
801         ifactory = gtk_item_factory_from_widget(menubar);
802         menuitem = gtk_item_factory_get_item
803                 (ifactory, "/View/Code set/Auto detect");
804         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
805
806         switch (prefs_common.toolbar_style) {
807         case TOOLBAR_NONE:
808                 menuitem = gtk_item_factory_get_item
809                         (ifactory, "/View/Toolbar/None");
810                 break;
811         case TOOLBAR_ICON:
812                 menuitem = gtk_item_factory_get_item
813                         (ifactory, "/View/Toolbar/Icon");
814                 break;
815         case TOOLBAR_TEXT:
816                 menuitem = gtk_item_factory_get_item
817                         (ifactory, "/View/Toolbar/Text");
818                 break;
819         case TOOLBAR_BOTH:
820                 menuitem = gtk_item_factory_get_item
821                         (ifactory, "/View/Toolbar/Icon and text");
822         }
823         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
824
825         gtk_widget_hide(mainwin->hbox_stat);
826         menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
827         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
828                                        prefs_common.show_statusbar);
829
830         /* set the check of the SEPARATE_xxx menu items. we also need the main window
831          * as a property and pass the action type to the callback */
832         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_FOLDER);
833         g_assert(menuitem);
834         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_FOLDER);
835         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
836         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
837                                            GUINT_TO_POINTER(SEPARATE_FOLDER));
838
839         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_MESSAGE);
840         g_assert(menuitem);
841         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_MESSAGE);
842         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
843         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
844                                            GUINT_TO_POINTER(SEPARATE_MESSAGE));
845
846
847         menu_set_sensitive(ifactory, "/Summary/Thread view",
848                            prefs_common.enable_thread ? FALSE : TRUE);
849         menu_set_sensitive(ifactory, "/Summary/Unthread view",
850                            prefs_common.enable_thread ? TRUE : FALSE);
851         
852         /*main_window_set_thread_option(mainwin);*/
853
854
855         /* set account selection menu */
856         ac_menu = gtk_item_factory_get_widget
857                 (ifactory, "/Configuration/Change current account");
858         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
859                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
860         mainwin->ac_menu = ac_menu;
861
862         main_window_set_toolbar_sensitive(mainwin);
863
864         /* show main window */
865         gtk_widget_set_uposition(mainwin->window,
866                                  prefs_common.mainwin_x,
867                                  prefs_common.mainwin_y);
868         gtk_widget_set_usize(window, prefs_common.mainwin_width,
869                              prefs_common.mainwin_height);
870                              
871         gtk_widget_show(mainwin->window);
872
873         /* initialize views */
874         folderview_init(folderview);
875         summary_init(summaryview);
876         messageview_init(messageview);
877         header_window_init(mainwin->headerwin);
878         log_window_init(mainwin->logwin);
879
880
881         mainwin->lock_count = 0;
882         mainwin->cursor_count = 0;
883
884         if (!watch_cursor)
885                 watch_cursor = gdk_cursor_new(GDK_WATCH);
886
887         mainwin_list = g_list_append(mainwin_list, mainwin);
888
889         return mainwin;
890 }
891
892 void main_window_cursor_wait(MainWindow *mainwin)
893 {
894
895         if (mainwin->cursor_count == 0)
896                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
897
898         mainwin->cursor_count++;
899
900         gdk_flush();
901 }
902
903 void main_window_cursor_normal(MainWindow *mainwin)
904 {
905         if (mainwin->cursor_count)
906                 mainwin->cursor_count--;
907
908         if (mainwin->cursor_count == 0)
909                 gdk_window_set_cursor(mainwin->window->window, NULL);
910
911         gdk_flush();
912 }
913
914 /* lock / unlock the user-interface */
915 void main_window_lock(MainWindow *mainwin)
916 {
917         if (mainwin->lock_count == 0)
918                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
919
920         mainwin->lock_count++;
921
922         main_window_set_menu_sensitive(mainwin);
923         main_window_set_toolbar_sensitive(mainwin);
924 }
925
926 void main_window_unlock(MainWindow *mainwin)
927 {
928         if (mainwin->lock_count)
929                 mainwin->lock_count--;
930
931         main_window_set_menu_sensitive(mainwin);
932         main_window_set_toolbar_sensitive(mainwin);
933
934         if (mainwin->lock_count == 0)
935                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
936 }
937
938 void main_window_reflect_prefs_all(void)
939 {
940         GList *cur;
941         MainWindow *mainwin;
942
943         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
944                 mainwin = (MainWindow *)cur->data;
945
946                 main_window_show_cur_account(mainwin);
947                 main_window_set_menu_sensitive(mainwin);
948                 main_window_set_toolbar_sensitive(mainwin);
949
950                 if (prefs_common.immediate_exec)
951                         gtk_widget_hide(mainwin->exec_btn);
952                 else
953                         gtk_widget_show(mainwin->exec_btn);
954
955                 summary_redisplay_msg(mainwin->summaryview);
956                 headerview_set_visibility(mainwin->messageview->headerview,
957                                           prefs_common.display_header_pane);
958         }
959 }
960
961 void main_window_set_summary_column(void)
962 {
963         GList *cur;
964         MainWindow *mainwin;
965
966         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
967                 mainwin = (MainWindow *)cur->data;
968                 summary_set_column_order(mainwin->summaryview);
969         }
970 }
971
972 void main_window_set_account_menu(GList *account_list)
973 {
974         GList *cur, *cur_ac, *cur_item;
975         GtkWidget *menuitem;
976         MainWindow *mainwin;
977         PrefsAccount *ac_prefs;
978
979         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
980                 mainwin = (MainWindow *)cur->data;
981
982                 /* destroy all previous menu item */
983                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
984                 while (cur_item != NULL) {
985                         GList *next = cur_item->next;
986                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
987                         cur_item = next;
988                 }
989
990                 for (cur_ac = account_list; cur_ac != NULL;
991                      cur_ac = cur_ac->next) {
992                         ac_prefs = (PrefsAccount *)cur_ac->data;
993
994                         menuitem = gtk_menu_item_new_with_label
995                                 (ac_prefs->account_name
996                                  ? ac_prefs->account_name : _("Untitled"));
997                         gtk_widget_show(menuitem);
998                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
999                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1000                                            GTK_SIGNAL_FUNC(account_menu_cb),
1001                                            ac_prefs);
1002                 }
1003         }
1004 }
1005
1006 static void main_window_show_cur_account(MainWindow *mainwin)
1007 {
1008         gchar *buf;
1009         gchar *ac_name;
1010
1011         ac_name = g_strdup(cur_account
1012                            ? (cur_account->account_name
1013                               ? cur_account->account_name : _("Untitled"))
1014                            : _("none"));
1015
1016         if (cur_account)
1017                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1018         else
1019                 buf = g_strdup(PROG_VERSION);
1020         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1021         g_free(buf);
1022
1023         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1024         gtk_widget_queue_resize(mainwin->ac_button);
1025
1026         g_free(ac_name);
1027 }
1028
1029 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1030 {
1031         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1032         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1033         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1034
1035         if (mainwin->type == type) return;
1036
1037         /* remove widgets from those containers */
1038         gtk_widget_ref(folder_wid);
1039         gtk_widget_ref(summary_wid);
1040         gtk_widget_ref(message_wid);
1041         gtk_container_remove
1042                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1043         gtk_container_remove
1044                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1045         gtk_container_remove
1046                 (GTK_CONTAINER(message_wid->parent), message_wid);
1047
1048         /* clean containers */
1049         switch (mainwin->type) {
1050         case SEPARATE_NONE:
1051                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1052                 break;
1053         case SEPARATE_FOLDER:
1054                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1055                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1056                 break;
1057         case SEPARATE_MESSAGE:
1058                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1059                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1060                 break;
1061         case SEPARATE_BOTH:
1062                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1063                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1064                 break;
1065         }
1066
1067         gtk_widget_hide(mainwin->window);
1068         main_window_set_widgets(mainwin, type);
1069         gtk_widget_show(mainwin->window);
1070
1071         gtk_widget_unref(folder_wid);
1072         gtk_widget_unref(summary_wid);
1073         gtk_widget_unref(message_wid);
1074 }
1075
1076 void main_window_get_size(MainWindow *mainwin)
1077 {
1078         GtkAllocation *allocation;
1079
1080         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1081
1082         prefs_common.summaryview_width  = allocation->width;
1083
1084         if (mainwin->summaryview->msg_is_toggled_on)
1085                 prefs_common.summaryview_height = allocation->height;
1086
1087         prefs_common.mainview_width     = allocation->width;
1088
1089         allocation = &mainwin->window->allocation;
1090
1091         prefs_common.mainview_height = allocation->height;
1092         prefs_common.mainwin_width   = allocation->width;
1093         prefs_common.mainwin_height  = allocation->height;
1094
1095         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1096
1097         prefs_common.folderview_width  = allocation->width;
1098         prefs_common.folderview_height = allocation->height;
1099 }
1100
1101 void main_window_get_position(MainWindow *mainwin)
1102 {
1103         gint x, y;
1104
1105         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1106
1107         prefs_common.mainview_x = x;
1108         prefs_common.mainview_y = y;
1109         prefs_common.mainwin_x = x;
1110         prefs_common.mainwin_y = y;
1111
1112         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1113 }
1114
1115 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1116 {
1117         GList *list;
1118
1119         if (confirm) {
1120                 if (alertpanel(_("Empty trash"),
1121                                _("Empty all messages in trash?"),
1122                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1123                         return;
1124                 manage_window_focus_in(mainwin->window, NULL, NULL);
1125         }
1126
1127         procmsg_empty_trash();
1128
1129         for (list = folder_get_list(); list != NULL; list = list->next) {
1130                 Folder *folder;
1131
1132                 folder = list->data;
1133                 if (folder->trash) {
1134                         folder_item_scan(folder->trash);
1135                         folderview_update_item(folder->trash, TRUE);
1136                 }
1137         }
1138
1139         if (mainwin->summaryview->folder_item &&
1140             mainwin->summaryview->folder_item->stype == F_TRASH)
1141                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1142 }
1143
1144 void main_window_add_mailbox(MainWindow *mainwin)
1145 {
1146         gchar *path;
1147         Folder *folder;
1148
1149         path = input_dialog(_("Add mailbox"),
1150                             _("Input the location of mailbox.\n"
1151                               "If the existing mailbox is specified, it will be\n"
1152                               "scanned automatically."),
1153                             "Mail");
1154         if (!path) return;
1155         if (folder_find_from_path(path)) {
1156                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1157                 g_free(path);
1158                 return;
1159         }
1160         if (!strcmp(path, "Mail"))
1161                 folder = folder_new(F_MH, _("Mailbox"), path);
1162         else
1163                 folder = folder_new(F_MH, g_basename(path), path);
1164         g_free(path);
1165
1166         if (folder->create_tree(folder) < 0) {
1167                 alertpanel_error(_("Creation of the mailbox failed.\n"
1168                                    "Maybe some files already exist, or you don't have the permission to write there."));
1169                 folder_destroy(folder);
1170                 return;
1171         }
1172
1173         folder_add(folder);
1174         folder_set_ui_func(folder, scan_tree_func, mainwin);
1175         folder->scan_tree(folder);
1176         folder_set_ui_func(folder, NULL, NULL);
1177
1178         folderview_set(mainwin->folderview);
1179 }
1180
1181 void main_window_add_mbox(MainWindow *mainwin)
1182 {
1183         gchar *path;
1184         Folder *folder;
1185         FolderItem * item;
1186
1187         path = input_dialog(_("Add mbox mailbox"),
1188                             _("Input the location of mailbox."),
1189                             "mail");
1190
1191         if (!path) return;
1192
1193         if (folder_find_from_path(path)) {
1194                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1195                 g_free(path);
1196                 return;
1197         }
1198
1199         /*
1200         if (!strcmp(path, "Mail"))
1201                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1202                 else
1203         */
1204
1205         folder = folder_new(F_MBOX, g_basename(path), path);
1206         g_free(path);
1207
1208         if (folder->create_tree(folder) < 0) {
1209                 alertpanel_error(_("Creation of the mailbox failed."));
1210                 folder_destroy(folder);
1211                 return;
1212         }
1213
1214         folder_add(folder);
1215
1216         item = folder_item_new(folder->name, NULL);
1217         item->folder = folder;
1218         folder->node = g_node_new(item);
1219
1220         folder->create_folder(folder, item, "inbox");
1221         folder->create_folder(folder, item, "outbox");
1222         folder->create_folder(folder, item, "queue");
1223         folder->create_folder(folder, item, "draft");
1224         folder->create_folder(folder, item, "trash");
1225
1226         folderview_set(mainwin->folderview);
1227 }
1228
1229 typedef enum
1230 {
1231         M_UNLOCKED            = 1 << 0,
1232         M_MSG_EXIST           = 1 << 1,
1233         M_TARGET_EXIST        = 1 << 2,
1234         M_SINGLE_TARGET_EXIST = 1 << 3,
1235         M_EXEC                = 1 << 4,
1236         M_ALLOW_REEDIT        = 1 << 5,
1237         M_HAVE_ACCOUNT        = 1 << 6,
1238         M_THREADED            = 1 << 7,
1239         M_UNTHREADED          = 1 << 8,
1240         M_NEWS                = 1 << 9
1241 } SensitiveCond;
1242
1243 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1244 {
1245         SensitiveCond state = 0;
1246         SummarySelection selection;
1247         FolderItem *item = mainwin->summaryview->folder_item;
1248
1249         selection = summary_get_selection_type(mainwin->summaryview);
1250
1251         if (mainwin->lock_count == 0)
1252                 state |= M_UNLOCKED;
1253         if (selection != SUMMARY_NONE)
1254                 state |= M_MSG_EXIST;
1255         if (item) {
1256                 if (item->threaded)
1257                         state |= M_THREADED;
1258                 else
1259                         state |= M_UNTHREADED;  
1260         }               
1261         if (selection == SUMMARY_SELECTED_SINGLE ||
1262             selection == SUMMARY_SELECTED_MULTIPLE)
1263                 state |= M_TARGET_EXIST;
1264         if (selection == SUMMARY_SELECTED_SINGLE)
1265                 state |= M_SINGLE_TARGET_EXIST;
1266         if (item && item->folder->type != F_NEWS)
1267                 state |= M_EXEC;
1268         if (mainwin->summaryview->folder_item &&
1269             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1270                 state |= M_NEWS;
1271         if (selection == SUMMARY_SELECTED_SINGLE &&
1272             (item &&
1273              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1274               item->stype == F_QUEUE)))
1275                 state |= M_ALLOW_REEDIT;
1276         if (cur_account)
1277                 state |= M_HAVE_ACCOUNT;
1278
1279         return state;
1280 }
1281
1282 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1283 {
1284         SensitiveCond state;
1285         gboolean sensitive;
1286         gint i;
1287
1288         const struct {
1289                 GtkWidget *widget;
1290                 SensitiveCond cond;
1291         } entry[] = {
1292                 {mainwin->get_btn         , M_HAVE_ACCOUNT|M_UNLOCKED},
1293                 {mainwin->getall_btn      , M_HAVE_ACCOUNT|M_UNLOCKED},
1294                 {mainwin->compose_mail_btn, M_HAVE_ACCOUNT},
1295                 {mainwin->compose_news_btn, M_HAVE_ACCOUNT},
1296                 {mainwin->reply_btn       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1297                 {mainwin->replyall_btn    , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1298                 {mainwin->replysender_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1299                 {mainwin->fwd_btn         , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1300                 /* {mainwin->prefs_btn      , M_UNLOCKED},
1301                 {mainwin->account_btn    , M_UNLOCKED}, */
1302                 {mainwin->next_btn        , M_MSG_EXIST},
1303                 {mainwin->delete_btn      , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1304                 {mainwin->exec_btn        , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1305                 {NULL, 0}
1306         };
1307
1308         state = main_window_get_current_state(mainwin);
1309
1310         for (i = 0; entry[i].widget != NULL; i++) {
1311                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1312                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1313         }
1314 }
1315
1316 void main_window_set_menu_sensitive(MainWindow *mainwin)
1317 {
1318         GtkItemFactory *ifactory;
1319         SensitiveCond state;
1320         gboolean sensitive;
1321         gint i;
1322
1323         static const struct {
1324                 gchar *const entry;
1325                 SensitiveCond cond;
1326         } entry[] = {
1327                 {"/File/Add mailbox..."        , M_UNLOCKED},
1328                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1329                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1330                 {"/File/Folder"                , M_UNLOCKED},
1331                 {"/File/Import mbox file..."   , M_UNLOCKED},
1332                 {"/File/Export to mbox file...", M_UNLOCKED},
1333                 {"/File/Empty trash"           , M_UNLOCKED},
1334                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1335                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1336                 {"/File/Close", M_UNLOCKED},
1337                 {"/File/Exit" , M_UNLOCKED},
1338
1339                 {"/View/Show all header"      , M_SINGLE_TARGET_EXIST},
1340                 {"/View/View source"          , M_SINGLE_TARGET_EXIST},
1341
1342                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1343                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1344 /*              {"/Message/Compose new message"   , M_HAVE_ACCOUNT}, */
1345                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1346                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1347                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1348                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1349                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1350                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1351                 {"/Message/Open in new window"    , M_SINGLE_TARGET_EXIST},
1352                 {"/Message/Re-edit", M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1353                 {"/Message/Move...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1354                 {"/Message/Copy...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1355                 {"/Message/Delete" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1356                 {"/Message/Mark"   , M_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 }