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