12191d54109f111c9f0af04c0527fd24bb6ca134
[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                 /* pixmap themes */
1086                 gtk_container_remove(GTK_CONTAINER(mainwin->handlebox), GTK_WIDGET(mainwin->toolbar));
1087                 mainwin->toolbar = NULL;
1088                 main_window_toolbar_create(mainwin, mainwin->handlebox);
1089                 set_toolbar_style(mainwin);
1090                 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1091                 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1092
1093                 if (prefs_common.immediate_exec)
1094                         gtk_widget_hide(mainwin->exec_btn);
1095                 else
1096                         gtk_widget_show(mainwin->exec_btn);
1097
1098                 activate_compose_button(mainwin, prefs_common.toolbar_style, mainwin->compose_btn_type);
1099
1100                 summary_redisplay_msg(mainwin->summaryview);
1101                 headerview_set_visibility(mainwin->messageview->headerview,
1102                                           prefs_common.display_header_pane);
1103         }
1104 }
1105
1106 void main_window_set_summary_column(void)
1107 {
1108         GList *cur;
1109         MainWindow *mainwin;
1110
1111         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1112                 mainwin = (MainWindow *)cur->data;
1113                 summary_set_column_order(mainwin->summaryview);
1114         }
1115 }
1116
1117 void main_window_set_account_menu(GList *account_list)
1118 {
1119         GList *cur, *cur_ac, *cur_item;
1120         GtkWidget *menuitem;
1121         MainWindow *mainwin;
1122         PrefsAccount *ac_prefs;
1123
1124         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1125                 mainwin = (MainWindow *)cur->data;
1126
1127                 /* destroy all previous menu item */
1128                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1129                 while (cur_item != NULL) {
1130                         GList *next = cur_item->next;
1131                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1132                         cur_item = next;
1133                 }
1134
1135                 for (cur_ac = account_list; cur_ac != NULL;
1136                      cur_ac = cur_ac->next) {
1137                         ac_prefs = (PrefsAccount *)cur_ac->data;
1138
1139                         menuitem = gtk_menu_item_new_with_label
1140                                 (ac_prefs->account_name
1141                                  ? ac_prefs->account_name : _("Untitled"));
1142                         gtk_widget_show(menuitem);
1143                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1144                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1145                                            GTK_SIGNAL_FUNC(account_menu_cb),
1146                                            ac_prefs);
1147                 }
1148         }
1149 }
1150
1151 static void main_window_show_cur_account(MainWindow *mainwin)
1152 {
1153         gchar *buf;
1154         gchar *ac_name;
1155
1156         ac_name = g_strdup(cur_account
1157                            ? (cur_account->account_name
1158                               ? cur_account->account_name : _("Untitled"))
1159                            : _("none"));
1160
1161         if (cur_account)
1162                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1163         else
1164                 buf = g_strdup(PROG_VERSION);
1165         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1166         g_free(buf);
1167
1168         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1169         gtk_widget_queue_resize(mainwin->ac_button);
1170
1171         g_free(ac_name);
1172 }
1173
1174 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1175 {
1176         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1177         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1178         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1179
1180         if (mainwin->type == type) return;
1181
1182         /* remove widgets from those containers */
1183         gtk_widget_ref(folder_wid);
1184         gtk_widget_ref(summary_wid);
1185         gtk_widget_ref(message_wid);
1186         gtkut_container_remove
1187                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1188         gtkut_container_remove
1189                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1190         gtkut_container_remove
1191                 (GTK_CONTAINER(message_wid->parent), message_wid);
1192
1193         /* clean containers */
1194         switch (mainwin->type) {
1195         case SEPARATE_NONE:
1196                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1197                 break;
1198         case SEPARATE_FOLDER:
1199                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1200                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1201                 break;
1202         case SEPARATE_MESSAGE:
1203                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1204                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1205                 break;
1206         case SEPARATE_BOTH:
1207                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1208                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1209                 break;
1210         }
1211
1212         gtk_widget_hide(mainwin->window);
1213         main_window_set_widgets(mainwin, type);
1214         gtk_widget_show(mainwin->window);
1215
1216         gtk_widget_unref(folder_wid);
1217         gtk_widget_unref(summary_wid);
1218         gtk_widget_unref(message_wid);
1219 }
1220
1221 void main_window_get_size(MainWindow *mainwin)
1222 {
1223         GtkAllocation *allocation;
1224
1225         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1226
1227         prefs_common.summaryview_width  = allocation->width;
1228
1229         if (mainwin->summaryview->msg_is_toggled_on)
1230                 prefs_common.summaryview_height = allocation->height;
1231
1232         prefs_common.mainview_width     = allocation->width;
1233
1234         allocation = &mainwin->window->allocation;
1235
1236         prefs_common.mainview_height = allocation->height;
1237         prefs_common.mainwin_width   = allocation->width;
1238         prefs_common.mainwin_height  = allocation->height;
1239
1240         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1241
1242         prefs_common.folderview_width  = allocation->width;
1243         prefs_common.folderview_height = allocation->height;
1244 }
1245
1246 void main_window_get_position(MainWindow *mainwin)
1247 {
1248         gint x, y;
1249
1250         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1251
1252         prefs_common.mainview_x = x;
1253         prefs_common.mainview_y = y;
1254         prefs_common.mainwin_x = x;
1255         prefs_common.mainwin_y = y;
1256
1257         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1258 }
1259
1260 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1261 {
1262         GList *list;
1263         guint has_trash;
1264         Folder *folder;
1265
1266         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1267                 folder = FOLDER(list->data);
1268                 if (folder && folder->trash && folder->trash->total > 0)
1269                         has_trash++;
1270         }
1271
1272         if (!has_trash) return;
1273         
1274         if (confirm) {
1275                 if (alertpanel(_("Empty trash"),
1276                                _("Empty all messages in trash?"),
1277                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1278                         return;
1279                 manage_window_focus_in(mainwin->window, NULL, NULL);
1280         }
1281
1282         procmsg_empty_trash();
1283
1284         for (list = folder_get_list(); list != NULL; list = list->next) {
1285                 folder = list->data;
1286                 if (folder && folder->trash && folder->trash->total != 0) {
1287                         folder_item_scan(folder->trash);
1288                         folderview_update_item(folder->trash, TRUE);
1289                 }
1290         }
1291
1292         if (mainwin->summaryview->folder_item &&
1293             mainwin->summaryview->folder_item->stype == F_TRASH)
1294                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1295 }
1296
1297 void main_window_add_mailbox(MainWindow *mainwin)
1298 {
1299         gchar *path;
1300         Folder *folder;
1301
1302         path = input_dialog(_("Add mailbox"),
1303                             _("Input the location of mailbox.\n"
1304                               "If the existing mailbox is specified, it will be\n"
1305                               "scanned automatically."),
1306                             "Mail");
1307         if (!path) return;
1308         if (folder_find_from_path(path)) {
1309                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1310                 g_free(path);
1311                 return;
1312         }
1313         if (!strcmp(path, "Mail"))
1314                 folder = folder_new(F_MH, _("Mailbox"), path);
1315         else
1316                 folder = folder_new(F_MH, g_basename(path), path);
1317         g_free(path);
1318
1319         if (folder->create_tree(folder) < 0) {
1320                 alertpanel_error(_("Creation of the mailbox failed.\n"
1321                                    "Maybe some files already exist, or you don't have the permission to write there."));
1322                 folder_destroy(folder);
1323                 return;
1324         }
1325
1326         folder_add(folder);
1327         folder_set_ui_func(folder, scan_tree_func, mainwin);
1328         folder->scan_tree(folder);
1329         folder_set_ui_func(folder, NULL, NULL);
1330
1331         folderview_set(mainwin->folderview);
1332 }
1333
1334 void main_window_add_mbox(MainWindow *mainwin)
1335 {
1336         gchar *path;
1337         Folder *folder;
1338         FolderItem * item;
1339
1340         path = input_dialog(_("Add mbox mailbox"),
1341                             _("Input the location of mailbox."),
1342                             "mail");
1343
1344         if (!path) return;
1345
1346         if (folder_find_from_path(path)) {
1347                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1348                 g_free(path);
1349                 return;
1350         }
1351
1352         /*
1353         if (!strcmp(path, "Mail"))
1354                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1355                 else
1356         */
1357
1358         folder = folder_new(F_MBOX, g_basename(path), path);
1359         g_free(path);
1360
1361         if (folder->create_tree(folder) < 0) {
1362                 alertpanel_error(_("Creation of the mailbox failed."));
1363                 folder_destroy(folder);
1364                 return;
1365         }
1366
1367         folder_add(folder);
1368
1369         item = folder_item_new(folder->name, NULL);
1370         item->folder = folder;
1371         folder->node = g_node_new(item);
1372
1373         folder->create_folder(folder, item, "inbox");
1374         folder->create_folder(folder, item, "outbox");
1375         folder->create_folder(folder, item, "queue");
1376         folder->create_folder(folder, item, "draft");
1377         folder->create_folder(folder, item, "trash");
1378
1379         folderview_set(mainwin->folderview);
1380 }
1381
1382 typedef enum
1383 {
1384         M_UNLOCKED            = 1 << 0,
1385         M_MSG_EXIST           = 1 << 1,
1386         M_TARGET_EXIST        = 1 << 2,
1387         M_SINGLE_TARGET_EXIST = 1 << 3,
1388         M_EXEC                = 1 << 4,
1389         M_ALLOW_REEDIT        = 1 << 5,
1390         M_HAVE_ACCOUNT        = 1 << 6,
1391         M_THREADED            = 1 << 7,
1392         M_UNTHREADED          = 1 << 8,
1393         M_ALLOW_DELETE        = 1 << 9,
1394         M_NEWS                = 1 << 10,
1395         M_HAVE_NEWS_ACCOUNT   = 1 << 11,
1396         M_HIDE_READ_MSG       = 1 << 12
1397 } SensitiveCond;
1398
1399 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1400 {
1401         SensitiveCond state = 0;
1402         SummarySelection selection;
1403         FolderItem *item = mainwin->summaryview->folder_item;
1404         GList *account_list = account_get_list();
1405         
1406         selection = summary_get_selection_type(mainwin->summaryview);
1407
1408         if (mainwin->lock_count == 0)
1409                 state |= M_UNLOCKED;
1410         if (selection != SUMMARY_NONE)
1411                 state |= M_MSG_EXIST;
1412         if (item) {
1413                 state |= M_EXEC;
1414                 if (item->threaded)
1415                         state |= M_THREADED;
1416                 else
1417                         state |= M_UNTHREADED;  
1418                 if (item->folder->type != F_NEWS)
1419                         state |= M_ALLOW_DELETE;
1420
1421                 if (selection == SUMMARY_NONE && item->hide_read_msgs
1422                     || selection != SUMMARY_NONE)
1423                         state |= M_HIDE_READ_MSG;       
1424         }               
1425         if (selection == SUMMARY_SELECTED_SINGLE ||
1426             selection == SUMMARY_SELECTED_MULTIPLE)
1427                 state |= M_TARGET_EXIST;
1428         if (selection == SUMMARY_SELECTED_SINGLE)
1429                 state |= M_SINGLE_TARGET_EXIST;
1430         if (mainwin->summaryview->folder_item &&
1431             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1432                 state |= M_NEWS;
1433         if (selection == SUMMARY_SELECTED_SINGLE &&
1434             (item &&
1435              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1436               item->stype == F_QUEUE)))
1437                 state |= M_ALLOW_REEDIT;
1438         if (cur_account)
1439                 state |= M_HAVE_ACCOUNT;
1440         
1441         for ( ; account_list != NULL; account_list = account_list->next) {
1442                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1443                         state |= M_HAVE_NEWS_ACCOUNT;
1444                         break;
1445                 }
1446         }
1447
1448         return state;
1449 }
1450
1451 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1452 {
1453         SensitiveCond state;
1454         gboolean sensitive;
1455         gint i;
1456
1457         struct {
1458                 GtkWidget *widget;
1459                 SensitiveCond cond;
1460         } entry[11];
1461
1462         entry[0].widget  = mainwin->get_btn;
1463         entry[0].cond    = M_HAVE_ACCOUNT|M_UNLOCKED;
1464         entry[1].widget  = mainwin->getall_btn;
1465         entry[1].cond    = M_HAVE_ACCOUNT|M_UNLOCKED;
1466         entry[2].widget  = mainwin->compose_news_btn;
1467         entry[2].cond    = M_HAVE_NEWS_ACCOUNT;
1468         entry[3].widget  = mainwin->reply_btn;
1469         entry[3].cond    = M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST;
1470         entry[4].widget  = mainwin->replyall_btn;
1471         entry[4].cond    = M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST;
1472         entry[5].widget  = mainwin->replysender_btn;
1473         entry[5].cond    = M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST;
1474         entry[6].widget  = mainwin->fwd_btn;
1475         entry[6].cond    = M_HAVE_ACCOUNT|M_TARGET_EXIST;
1476 /*      entry[6].widget  = mainwin->prefs_btn;
1477         entry[6].cond    = M_UNLOCKED;
1478         entry[7].widget  = mainwin->account_btn;
1479         entry[7].cond    = M_UNLOCKED; */
1480         entry[7].widget  = mainwin->next_btn;
1481         entry[7].cond    = M_MSG_EXIST;
1482         entry[8].widget  = mainwin->delete_btn;
1483         entry[8].cond    = M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED;
1484         entry[9].widget = mainwin->exec_btn;
1485         entry[9].cond   = M_MSG_EXIST|M_EXEC|M_UNLOCKED;
1486         entry[10].widget = NULL;
1487         entry[10].cond   = 0;
1488
1489         state = main_window_get_current_state(mainwin);
1490
1491         for (i = 0; entry[i].widget != NULL; i++) {
1492                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1493                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1494         }
1495
1496         activate_compose_button(mainwin, 
1497                         prefs_common.toolbar_style,
1498                         mainwin->compose_btn_type);
1499 }
1500
1501 void main_window_set_menu_sensitive(MainWindow *mainwin)
1502 {
1503         GtkItemFactory *ifactory;
1504         SensitiveCond state;
1505         gboolean sensitive;
1506         gint i;
1507
1508         static const struct {
1509                 gchar *const entry;
1510                 SensitiveCond cond;
1511         } entry[] = {
1512                 {"/File/Add mailbox..."        , M_UNLOCKED},
1513                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1514                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1515                 {"/File/Folder"                , M_UNLOCKED},
1516                 {"/File/Import mbox file..."   , M_UNLOCKED},
1517                 {"/File/Export to mbox file...", M_UNLOCKED},
1518                 {"/File/Empty trash"           , M_UNLOCKED},
1519                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1520                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1521                 /* {"/File/Close", M_UNLOCKED}, */
1522                 {"/File/Exit" , M_UNLOCKED},
1523
1524                 {"/Edit/Actions"                   , M_MSG_EXIST},
1525                 {"/View/Sort"                      , M_MSG_EXIST},
1526                 {"/View/Thread view"               , M_UNTHREADED},
1527                 {"/View/Unthread view"             , M_THREADED},
1528                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1529                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1530                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1531                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1532                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1533                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1534                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1535                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1536                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1537                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1538                 {"/View/Show all header"           , M_SINGLE_TARGET_EXIST},
1539                 {"/View/View source"               , M_SINGLE_TARGET_EXIST},
1540
1541                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1542                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1543                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1544                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1545                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1546                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1547                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1548                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1549                 {"/Message/Bounce"                , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1550                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1551                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1552                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1553                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1554                 {"/Message/Mark"                  , M_TARGET_EXIST},
1555                 {"/Message/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1556
1557                 {"/Tool/Add sender to address book", M_SINGLE_TARGET_EXIST},
1558                 {"/Tool/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1559                 {"/Tool/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1560                 {"/Tool/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1561
1562                 {"/Configuration", M_UNLOCKED},
1563
1564                 {NULL, 0}
1565         };
1566
1567         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1568         state = main_window_get_current_state(mainwin);
1569
1570         for (i = 0; entry[i].entry != NULL; i++) {
1571                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1572                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1573         }
1574 }
1575
1576 void main_window_popup(MainWindow *mainwin)
1577 {
1578         gint x, y;
1579         gint sx, sy;
1580         GtkWidget *widget;
1581
1582         gdk_window_get_origin(mainwin->window->window, &x, &y);
1583         sx = gdk_screen_width();
1584         sy = gdk_screen_height();
1585         x %= sx; if (x < 0) x = 0;
1586         y %= sy; if (y < 0) y = 0;
1587         gdk_window_move(mainwin->window->window, x, y);
1588         gdk_window_raise(mainwin->window->window);
1589         gdk_window_show(mainwin->window->window);
1590
1591         debug_print("window position: x = %d, y = %d\n", x, y);
1592
1593         switch (mainwin->type) {
1594         case SEPARATE_FOLDER:
1595                 widget = mainwin->win.sep_folder.folderwin;
1596                 gdk_window_get_origin(widget->window, &x, &y);
1597                 x %= sx; if (x < 0) x = 0;
1598                 y %= sy; if (y < 0) y = 0;
1599                 gdk_window_move(widget->window, x, y);
1600                 gdk_window_raise(widget->window);
1601                 break;
1602         case SEPARATE_MESSAGE:
1603                 widget = mainwin->win.sep_message.messagewin;
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_BOTH:
1611                 widget = mainwin->win.sep_both.folderwin;
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                 widget = mainwin->win.sep_both.messagewin;
1618                 gdk_window_get_origin(widget->window, &x, &y);
1619                 x %= sx; if (x < 0) x = 0;
1620                 y %= sy; if (y < 0) y = 0;
1621                 gdk_window_move(widget->window, x, y);
1622                 gdk_window_raise(widget->window);
1623                 break;
1624         default:
1625                 break;
1626         }
1627 }
1628
1629 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1630 {
1631         GtkWidget *folderwin = NULL;
1632         GtkWidget *messagewin = NULL;
1633         GtkWidget *hpaned;
1634         GtkWidget *vpaned;
1635         GtkWidget *vbox_body = mainwin->vbox_body;
1636         GtkItemFactory *ifactory=gtk_item_factory_from_widget(mainwin->menubar);
1637         GtkWidget *menuitem;
1638
1639         debug_print(_("Setting widgets..."));
1640
1641         /* create separated window(s) if needed */
1642         if (type & SEPARATE_FOLDER) {
1643                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1644                 gtk_window_set_title(GTK_WINDOW(folderwin),
1645                                      _("Sylpheed - Folder View"));
1646                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1647                                        "folder_view", "Sylpheed");
1648                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1649                                       TRUE, TRUE, FALSE);
1650                 gtk_widget_set_usize(folderwin, -1,
1651                                      prefs_common.mainview_height);
1652                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1653                                                BORDER_WIDTH);
1654                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1655                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1656                                    NULL);
1657         }
1658         if (type & SEPARATE_MESSAGE) {
1659                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1660                 gtk_window_set_title(GTK_WINDOW(messagewin),
1661                                      _("Sylpheed - Message View"));
1662                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1663                                        "message_view", "Sylpheed");
1664                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1665                                       TRUE, TRUE, FALSE);
1666                 gtk_widget_set_usize
1667                         (messagewin, prefs_common.mainview_width,
1668                          prefs_common.mainview_height
1669                          - prefs_common.summaryview_height
1670                          + DEFAULT_HEADERVIEW_HEIGHT);
1671                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1672                                                BORDER_WIDTH);
1673                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1674                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1675                                    NULL);
1676         }
1677
1678         switch (type) {
1679         case SEPARATE_NONE:
1680                 hpaned = gtk_hpaned_new();
1681                 gtk_widget_show(hpaned);
1682                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1683                 gtk_paned_add1(GTK_PANED(hpaned),
1684                                GTK_WIDGET_PTR(mainwin->folderview));
1685
1686                 vpaned = gtk_vpaned_new();
1687                 if (mainwin->summaryview->msg_is_toggled_on) {
1688                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1689                         gtk_paned_add1(GTK_PANED(vpaned),
1690                                        GTK_WIDGET_PTR(mainwin->summaryview));
1691                 } else {
1692                         gtk_paned_add2(GTK_PANED(hpaned),
1693                                        GTK_WIDGET_PTR(mainwin->summaryview));
1694                         gtk_widget_ref(vpaned);
1695                 }
1696                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1697                                      prefs_common.summaryview_width,
1698                                      prefs_common.summaryview_height);
1699                 gtk_paned_add2(GTK_PANED(vpaned),
1700                                GTK_WIDGET_PTR(mainwin->messageview));
1701                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1702                                      prefs_common.mainview_width, -1);
1703                 gtk_widget_set_usize(mainwin->window,
1704                                      prefs_common.folderview_width +
1705                                      prefs_common.mainview_width,
1706                                      prefs_common.mainwin_height);
1707                 gtk_widget_show_all(vpaned);
1708
1709                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1710                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1711                 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1712                 menu_set_sensitive(ifactory, "/View/Expand Message View", TRUE);
1713                 menuitem = gtk_item_factory_get_widget(ifactory, "/View/Expand Message View");
1714                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1715                 
1716                 mainwin->win.sep_none.hpaned = hpaned;
1717                 mainwin->win.sep_none.vpaned = vpaned;
1718                 break;
1719         case SEPARATE_FOLDER:
1720                 vpaned = gtk_vpaned_new();
1721                 if (mainwin->summaryview->msg_is_toggled_on) {
1722                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1723                                            TRUE, TRUE, 0);
1724                         gtk_paned_add1(GTK_PANED(vpaned),
1725                                        GTK_WIDGET_PTR(mainwin->summaryview));
1726                 } else {
1727                         gtk_box_pack_start(GTK_BOX(vbox_body),
1728                                            GTK_WIDGET_PTR(mainwin->summaryview),
1729                                            TRUE, TRUE, 0);
1730                         gtk_widget_ref(vpaned);
1731                 }
1732                 gtk_paned_add2(GTK_PANED(vpaned),
1733                                GTK_WIDGET_PTR(mainwin->messageview));
1734                 gtk_widget_show_all(vpaned);
1735                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1736                                      prefs_common.summaryview_width,
1737                                      prefs_common.summaryview_height);
1738                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1739                                      prefs_common.mainview_width, -1);
1740                 gtk_widget_set_usize(mainwin->window,
1741                                      prefs_common.mainview_width,
1742                                      prefs_common.mainview_height);
1743
1744                 gtk_container_add(GTK_CONTAINER(folderwin),
1745                                   GTK_WIDGET_PTR(mainwin->folderview));
1746
1747                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1748                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1749                 
1750                 mainwin->win.sep_folder.folderwin = folderwin;
1751                 mainwin->win.sep_folder.vpaned    = vpaned;
1752
1753                 gtk_widget_show_all(folderwin);
1754                 break;
1755         case SEPARATE_MESSAGE:
1756                 hpaned = gtk_hpaned_new();
1757                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1758
1759                 gtk_paned_add1(GTK_PANED(hpaned),
1760                                GTK_WIDGET_PTR(mainwin->folderview));
1761                 gtk_paned_add2(GTK_PANED(hpaned),
1762                                GTK_WIDGET_PTR(mainwin->summaryview));
1763                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1764                                      prefs_common.summaryview_width,
1765                                      prefs_common.summaryview_height);
1766                 gtk_widget_set_usize(mainwin->window,
1767                                      prefs_common.folderview_width +
1768                                      prefs_common.mainview_width,
1769                                      prefs_common.mainwin_height);
1770                 gtk_widget_show_all(hpaned);
1771                 gtk_container_add(GTK_CONTAINER(messagewin),
1772                                   GTK_WIDGET_PTR(mainwin->messageview));
1773         
1774                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1775                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1776                 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1777                 menu_set_sensitive(ifactory, "/View/Expand Message View", FALSE);
1778                 
1779                 mainwin->win.sep_message.messagewin = messagewin;
1780                 mainwin->win.sep_message.hpaned     = hpaned;
1781
1782                 gtk_widget_show_all(messagewin);
1783                 break;
1784         case SEPARATE_BOTH:
1785                 gtk_box_pack_start(GTK_BOX(vbox_body),
1786                                    GTK_WIDGET_PTR(mainwin->summaryview),
1787                                    TRUE, TRUE, 0);
1788                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1789                                      prefs_common.summaryview_width,
1790                                      prefs_common.summaryview_height);
1791                 gtk_widget_set_usize(mainwin->window,
1792                                      prefs_common.mainview_width,
1793                                      prefs_common.mainwin_height);
1794                 gtk_container_add(GTK_CONTAINER(folderwin),
1795                                   GTK_WIDGET_PTR(mainwin->folderview));
1796                 gtk_container_add(GTK_CONTAINER(messagewin),
1797                                   GTK_WIDGET_PTR(mainwin->messageview));
1798
1799                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1800                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1801         
1802                 mainwin->win.sep_both.folderwin = folderwin;
1803                 mainwin->win.sep_both.messagewin = messagewin;
1804
1805                 gtk_widget_show_all(folderwin);
1806                 gtk_widget_show_all(messagewin);
1807                 break;
1808         }
1809
1810         mainwin->type = type;
1811
1812         debug_print(_("done.\n"));
1813 }
1814
1815 static void main_window_toolbar_create(MainWindow *mainwin,
1816                                        GtkWidget *container)
1817 {
1818         GtkWidget *toolbar;
1819         GtkWidget *icon_wid;
1820         GtkWidget *get_btn;
1821         GtkWidget *getall_btn;
1822         GtkWidget *compose_mail_btn;
1823         GtkWidget *compose_news_btn;
1824         GtkWidget *reply_btn;
1825         GtkWidget *replyall_btn;
1826         GtkWidget *replysender_btn;
1827         GtkWidget *fwd_btn;
1828         GtkWidget *send_btn;
1829         /*
1830         GtkWidget *prefs_btn;
1831         GtkWidget *account_btn;
1832         */
1833         GtkWidget *next_btn;
1834         GtkWidget *delete_btn;
1835         GtkWidget *exec_btn;
1836         
1837         GtkTooltips *tooltips;
1838
1839         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1840                                   GTK_TOOLBAR_BOTH);
1841         gtk_container_add(GTK_CONTAINER(container), toolbar);
1842         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1843         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1844         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1845                                     GTK_TOOLBAR_SPACE_LINE);
1846
1847         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE);
1848         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1849                                           _("Get"),
1850                                           _("Get new mail from current account"),
1851                                           "Get",
1852                                           icon_wid, toolbar_inc_cb, mainwin);
1853         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE_ALL);
1854         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1855                                              _("Get all"),
1856                                              _("Get new mail from all accounts"),
1857                                              "Get all",
1858                                              icon_wid,
1859                                              toolbar_inc_all_cb,
1860                                              mainwin);
1861
1862         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1863
1864         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
1865         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1866                                            _("Send"),
1867                                            _("Send queued message(s)"),
1868                                            "Send",
1869                                            icon_wid,
1870                                            toolbar_send_cb,
1871                                            mainwin);
1872
1873         /* insert compose mail button widget */                                    
1874         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
1875         compose_mail_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1876                                               _("Email"),
1877                                               _("Compose an email message"),
1878                                               "New",
1879                                               icon_wid,
1880                                               toolbar_compose_mail_cb,
1881                                               mainwin);
1882
1883         /* insert compose news button widget */
1884         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1885         compose_news_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1886                                               _("News"),
1887                                               _("Compose a news message"),
1888                                               "New",
1889                                               icon_wid,
1890                                               toolbar_compose_news_cb,
1891                                               mainwin);
1892
1893         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1894         
1895         /* reply button */
1896         
1897         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY);
1898         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1899                                             _("Reply"),
1900                                             _("Reply to the message - Right button: more options"),
1901                                             "Reply",
1902                                             icon_wid,
1903                                             toolbar_reply_cb,
1904                                             mainwin);
1905
1906         /* replyall button */
1907
1908         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_ALL);
1909         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1910                                                _("All"),
1911                                                _("Reply to all - Right button: more options"),
1912                                                "Reply to all",
1913                                                icon_wid,
1914                                                toolbar_reply_to_all_cb,
1915                                                mainwin);
1916
1917         /* reply to sender button */
1918         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR);
1919         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1920                                                   _("Sender"),
1921                                                   _("Reply to sender - Right button: more options"),
1922                                                   "Reply to sender",
1923                                                   icon_wid,
1924                                                   toolbar_reply_to_sender_cb,
1925                                                   mainwin);
1926
1927         /* forward button */
1928         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_FORWARD);
1929         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1930                                           _("Forward"),
1931                                           _("Forward the message - Right button: more options"),
1932                                           "Fwd",
1933                                           icon_wid,
1934                                           toolbar_forward_cb,
1935                                           mainwin);
1936
1937         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1938
1939         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_CLOSE);
1940         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1941                                           _("Delete"),
1942                                           _("Delete the message"),
1943                                           "Delete",
1944                                           icon_wid,
1945                                           toolbar_delete_cb,
1946                                           mainwin);
1947
1948         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
1949         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1950                                            _("Execute"),
1951                                            _("Execute marked process"),
1952                                            "Execute",
1953                                            icon_wid,
1954                                            toolbar_exec_cb,
1955                                            mainwin);
1956
1957         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_DOWN_ARROW);
1958         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1959                                            _("Next"),
1960                                            _("Next unread message"),
1961                                            "Next unread",
1962                                            icon_wid,
1963                                            toolbar_next_unread_cb,
1964                                            mainwin);
1965
1966         /*
1967         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1968
1969         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PREFERENCES);
1970         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1971                                             _("Prefs"),
1972                                             _("Common preference"),
1973                                             "Prefs",
1974                                             icon_wid,
1975                                             toolbar_prefs_cb,
1976                                             mainwin);
1977         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PROPERTIES);
1978         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1979                                               _("Account"),
1980                                               _("Account setting"),
1981                                               "Account",
1982                                               icon_wid,
1983                                               toolbar_account_cb,
1984                                               mainwin);
1985         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1986                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1987                            mainwin);
1988         */
1989
1990         gtk_signal_connect(GTK_OBJECT(reply_btn), "button_press_event",
1991                 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1992                 mainwin);
1993         
1994         gtk_signal_connect(GTK_OBJECT(replyall_btn), "button_press_event",
1995                 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1996                 mainwin);
1997         
1998         gtk_signal_connect(GTK_OBJECT(replysender_btn), "button_press_event",
1999                 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
2000                 mainwin);
2001         
2002         gtk_signal_connect(GTK_OBJECT(fwd_btn), "button_press_event",
2003                 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
2004                 mainwin);
2005         
2006
2007         mainwin->toolbar                         = toolbar;
2008         mainwin->get_btn                         = get_btn;
2009         mainwin->getall_btn                      = getall_btn;
2010         mainwin->compose_mail_btn                = compose_mail_btn;
2011         mainwin->compose_news_btn                = compose_news_btn;
2012         mainwin->reply_btn                       = reply_btn;
2013         mainwin->replyall_btn                    = replyall_btn;
2014         mainwin->replysender_btn                 = replysender_btn;
2015         mainwin->fwd_btn         = fwd_btn;
2016         mainwin->send_btn        = send_btn;
2017         /*
2018         mainwin->prefs_btn       = prefs_btn;
2019         mainwin->account_btn     = account_btn;
2020         */
2021         mainwin->next_btn        = next_btn;
2022         mainwin->delete_btn      = delete_btn;
2023         mainwin->exec_btn        = exec_btn;
2024
2025         gtk_widget_show_all(toolbar);
2026 }
2027
2028 /* callback functions */
2029 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2030 {
2031         MainWindow *mainwindow = (MainWindow *) data;
2032         
2033         if (!event) return;
2034
2035         if (event->button == 3) {
2036                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2037                 gtk_menu_popup(GTK_MENU(mainwindow->reply_popup), NULL, NULL,
2038                        menu_button_position, widget,
2039                        event->button, event->time);
2040         }
2041 }
2042
2043 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2044 {
2045         MainWindow *mainwin = (MainWindow *)data;
2046
2047         gtk_button_set_relief(GTK_BUTTON(mainwin->reply_btn), GTK_RELIEF_NONE);
2048         manage_window_focus_in(mainwin->window, NULL, NULL);
2049 }
2050
2051 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2052 {
2053         MainWindow *mainwindow = (MainWindow *) data;
2054         
2055         if (!event) return;
2056
2057         if (event->button == 3) {
2058                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2059                 gtk_menu_popup(GTK_MENU(mainwindow->replyall_popup), NULL, NULL,
2060                        menu_button_position, widget,
2061                        event->button, event->time);
2062         }
2063 }
2064
2065 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2066 {
2067         MainWindow *mainwin = (MainWindow *)data;
2068
2069         gtk_button_set_relief(GTK_BUTTON(mainwin->replyall_btn), GTK_RELIEF_NONE);
2070         manage_window_focus_in(mainwin->window, NULL, NULL);
2071 }
2072
2073 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2074 {
2075         MainWindow *mainwindow = (MainWindow *) data;
2076         GtkWidget *replysender_menu, *replysender_item;
2077
2078         if (!event) return;
2079
2080         if (event->button == 3) {
2081                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2082                 gtk_menu_popup(GTK_MENU(mainwindow->replysender_popup), NULL, NULL,
2083                        menu_button_position, widget,
2084                        event->button, event->time);
2085         }
2086 }
2087
2088 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2089 {
2090         MainWindow *mainwin = (MainWindow *)data;
2091
2092         gtk_button_set_relief(GTK_BUTTON(mainwin->replysender_btn), GTK_RELIEF_NONE);
2093         manage_window_focus_in(mainwin->window, NULL, NULL);
2094 }
2095
2096 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2097 {
2098         MainWindow *mainwindow = (MainWindow *) data;
2099         
2100         if (!event) return;
2101
2102         if (event->button == 3) {
2103                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2104                 gtk_menu_popup(GTK_MENU(mainwindow->fwd_popup), NULL, NULL,
2105                        menu_button_position, widget,
2106                        event->button, event->time);
2107         }
2108 }
2109
2110 static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2111 {
2112         MainWindow *mainwin = (MainWindow *)data;
2113
2114         gtk_button_set_relief(GTK_BUTTON(mainwin->fwd_btn), GTK_RELIEF_NONE);
2115         manage_window_focus_in(mainwin->window, NULL, NULL);
2116 }
2117
2118 static void toolbar_inc_cb      (GtkWidget      *widget,
2119                                  gpointer        data)
2120 {
2121         MainWindow *mainwin = (MainWindow *)data;
2122
2123         inc_mail_cb(mainwin, 0, NULL);
2124 }
2125
2126 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2127                                  gpointer        data)
2128 {
2129         MainWindow *mainwin = (MainWindow *)data;
2130
2131         inc_all_account_mail_cb(mainwin, 0, NULL);
2132 }
2133
2134 static void toolbar_send_cb     (GtkWidget      *widget,
2135                                  gpointer        data)
2136 {
2137         MainWindow *mainwin = (MainWindow *)data;
2138
2139         send_queue_cb(mainwin, 0, NULL);
2140 }
2141
2142 static void toolbar_compose_cb  (GtkWidget      *widget,
2143                                  gpointer        data)
2144 {
2145         MainWindow *mainwin = (MainWindow *)data;
2146
2147         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
2148                 compose_cb(mainwin, 0, NULL);
2149         else
2150                 compose_news_cb(mainwin, 0, NULL);
2151 }
2152
2153 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2154                                  gpointer        data)
2155 {
2156         MainWindow *mainwin = (MainWindow *)data;
2157
2158         compose_news_cb(mainwin, 0, NULL);
2159 }
2160
2161 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2162                                  gpointer        data)
2163 {
2164         MainWindow *mainwin = (MainWindow *)data;
2165
2166         compose_mail_cb(mainwin, 0, NULL);
2167 }
2168
2169 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
2170 {
2171         MainWindow *mainwin = (MainWindow *)data;
2172
2173         reply_cb(mainwin, 
2174                  prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2175                  : COMPOSE_REPLY_WITHOUT_QUOTE,
2176                  NULL);
2177 }
2178
2179 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
2180 {
2181         MainWindow *mainwin = (MainWindow *)data;
2182
2183         reply_cb(mainwin, 
2184                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2185                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2186                  NULL);
2187 }
2188
2189
2190 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
2191 {
2192         MainWindow *mainwin = (MainWindow *)data;
2193
2194         reply_cb(mainwin, 
2195                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2196                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2197                  NULL);
2198 }
2199
2200 static void toolbar_forward_cb  (GtkWidget      *widget,
2201                                  gpointer        data)
2202 {
2203         MainWindow *mainwin = (MainWindow *)data;
2204
2205         if (prefs_common.forward_as_attachment)
2206                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2207         else
2208                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2209 }
2210
2211 static void toolbar_delete_cb   (GtkWidget      *widget,
2212                                  gpointer        data)
2213 {
2214         MainWindow *mainwin = (MainWindow *)data;
2215
2216         summary_delete(mainwin->summaryview);
2217 }
2218
2219 static void toolbar_exec_cb     (GtkWidget      *widget,
2220                                  gpointer        data)
2221 {
2222         MainWindow *mainwin = (MainWindow *)data;
2223
2224         summary_execute(mainwin->summaryview);
2225 }
2226
2227 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2228                                          gpointer        data)
2229 {
2230         MainWindow *mainwin = (MainWindow *)data;
2231
2232         next_unread_cb(mainwin, 0, NULL);
2233 }
2234
2235 static void toolbar_prefs_cb    (GtkWidget      *widget,
2236                                  gpointer        data)
2237 {
2238         prefs_common_open();
2239 }
2240
2241 static void toolbar_account_cb  (GtkWidget      *widget,
2242                                  gpointer        data)
2243 {
2244         MainWindow *mainwin = (MainWindow *)data;
2245
2246         prefs_account_open_cb(mainwin, 0, NULL);
2247 }
2248
2249 static void toolbar_account_button_pressed(GtkWidget *widget,
2250                                            GdkEventButton *event,
2251                                            gpointer data)
2252 {
2253         MainWindow *mainwin = (MainWindow *)data;
2254
2255         if (!event) return;
2256         if (event->button != 3) return;
2257
2258         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2259         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2260                             widget);
2261
2262         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2263                        menu_button_position, widget,
2264                        event->button, event->time);
2265 }
2266
2267 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2268                                     gpointer data)
2269 {
2270         MainWindow *mainwin = (MainWindow *)data;
2271
2272         if (!event) return;
2273
2274         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2275         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2276                             widget);
2277
2278         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2279                        menu_button_position, widget,
2280                        event->button, event->time);
2281 }
2282
2283 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2284 {
2285         MainWindow *mainwin = (MainWindow *)data;
2286         GtkWidget *button;
2287
2288         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2289         if (!button) return;
2290         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2291         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2292         manage_window_focus_in(mainwin->window, NULL, NULL);
2293 }
2294
2295 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2296                                  gpointer data)
2297 {
2298         MainWindow *mainwin = (MainWindow *)data;
2299
2300         if (mainwin->lock_count == 0)
2301                 app_exit_cb(data, 0, widget);
2302
2303         return TRUE;
2304 }
2305
2306 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2307                            GtkWidget *widget)
2308 {
2309         main_window_add_mailbox(mainwin);
2310 }
2311
2312 static void add_mbox_cb(MainWindow *mainwin, guint action,
2313                         GtkWidget *widget)
2314 {
2315         main_window_add_mbox(mainwin);
2316 }
2317
2318 static void update_folderview_cb(MainWindow *mainwin, guint action,
2319                                  GtkWidget *widget)
2320 {
2321         summary_show(mainwin->summaryview, NULL, FALSE);
2322         folderview_update_all();
2323 }
2324
2325 static void new_folder_cb(MainWindow *mainwin, guint action,
2326                           GtkWidget *widget)
2327 {
2328         folderview_new_folder(mainwin->folderview);
2329 }
2330
2331 static void rename_folder_cb(MainWindow *mainwin, guint action,
2332                              GtkWidget *widget)
2333 {
2334         folderview_rename_folder(mainwin->folderview);
2335 }
2336
2337 static void delete_folder_cb(MainWindow *mainwin, guint action,
2338                              GtkWidget *widget)
2339 {
2340         folderview_delete_folder(mainwin->folderview);
2341 }
2342
2343 static void import_mbox_cb(MainWindow *mainwin, guint action,
2344                            GtkWidget *widget)
2345 {
2346         import_mbox(mainwin->summaryview->folder_item);
2347 }
2348
2349 static void export_mbox_cb(MainWindow *mainwin, guint action,
2350                            GtkWidget *widget)
2351 {
2352         export_mbox(mainwin->summaryview->folder_item);
2353 }
2354
2355 static void empty_trash_cb(MainWindow *mainwin, guint action,
2356                            GtkWidget *widget)
2357 {
2358         main_window_empty_trash(mainwin, TRUE);
2359 }
2360
2361 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2362 {
2363         summary_save_as(mainwin->summaryview);
2364 }
2365
2366 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2367 {
2368         summary_print(mainwin->summaryview);
2369 }
2370
2371 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2372 {
2373         if (prefs_common.confirm_on_exit) {
2374                 if (alertpanel(_("Exit"), _("Exit this program?"),
2375                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2376                         return;
2377                 manage_window_focus_in(mainwin->window, NULL, NULL);
2378         }
2379
2380         app_will_exit(widget, mainwin);
2381 }
2382
2383 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2384 {
2385         if (action == 1)
2386                 summary_search(mainwin->summaryview);
2387         else
2388                 message_search(mainwin->messageview);
2389 }
2390
2391 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2392                              GtkWidget *widget)
2393 {
2394         switch (mainwin->type) {
2395         case SEPARATE_NONE:
2396         case SEPARATE_MESSAGE:
2397                 break;
2398         case SEPARATE_FOLDER:
2399                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2400                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2401                 else
2402                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2403                 break;
2404         case SEPARATE_BOTH:
2405                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2406                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2407                 else
2408                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2409                 break;
2410         }
2411 }
2412
2413 static void toggle_message_cb(MainWindow *mainwin, guint action,
2414                               GtkWidget *widget)
2415 {
2416         switch (mainwin->type) {
2417         case SEPARATE_NONE:
2418         case SEPARATE_FOLDER:
2419                 break;
2420         case SEPARATE_MESSAGE:
2421                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2422                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2423                 else
2424                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2425                 break;
2426         case SEPARATE_BOTH:
2427                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2428                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2429                 else
2430                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2431                 break;
2432         }
2433 }
2434
2435 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2436                               GtkWidget *widget)
2437 {
2438 /*      activate_compose_button(mainwin, (ToolbarStyle)action, 
2439                         mainwin->compose_btn_type);
2440         set_toolbar_reply_button(mainwin, (ToolbarStyle)action);
2441         set_toolbar_replyall_button(mainwin, (ToolbarStyle)action);
2442         set_toolbar_replysender_button(mainwin, (ToolbarStyle)action);
2443         set_toolbar_forward_button(mainwin, (ToolbarStyle)action);*/
2444         
2445         mainwin->toolbar_style = (ToolbarStyle)action;
2446         prefs_common.toolbar_style = (ToolbarStyle)action;
2447         
2448         set_toolbar_style(mainwin);
2449 }
2450
2451 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2452                                 GtkWidget *widget)
2453 {
2454         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2455                 gtk_widget_show(mainwin->hbox_stat);
2456                 prefs_common.show_statusbar = TRUE;
2457         } else {
2458                 gtk_widget_hide(mainwin->hbox_stat);
2459                 prefs_common.show_statusbar = FALSE;
2460         }
2461 }
2462
2463 static void toggle_expand_summaryview_cb(MainWindow *mainwin, guint action,     GtkWidget *widget)
2464 {
2465         summary_toggle_view_real(mainwin->summaryview);
2466 }
2467
2468 static void toggle_expand_messageview_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2469 {
2470         messageview_toggle_view_real(mainwin->messageview);
2471 }
2472
2473 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action, GtkWidget *widget)
2474
2475 {
2476         MainWindow *mainwin;
2477         SeparateType type;
2478
2479         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2480         g_return_if_fail(mainwin != NULL);
2481
2482         type = mainwin->type ^ action;
2483         main_window_separation_change(mainwin, type);
2484
2485         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2486         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2487 }
2488
2489 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2490                                 GtkWidget *widget)
2491 {
2492         addressbook_open(NULL);
2493 }
2494
2495 static void log_window_show_cb(MainWindow *mainwin, guint action,
2496                                GtkWidget *widget)
2497 {
2498         log_window_show(mainwin->logwin);
2499 }
2500
2501 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2502 {
2503         inc_mail(mainwin);
2504 }
2505
2506 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2507                                     GtkWidget *widget)
2508 {
2509         inc_all_account_mail(mainwin);
2510 }
2511
2512 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2513 {
2514         GList *list;
2515
2516         if (procmsg_send_queue() < 0)
2517                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2518
2519         statusbar_pop_all();
2520
2521         for (list = folder_get_list(); list != NULL; list = list->next) {
2522                 Folder *folder;
2523
2524                 folder = list->data;
2525                 if (folder->queue) {
2526                         folder_item_scan(folder->queue);
2527                         folderview_update_item(folder->queue, TRUE);
2528                 }
2529         }
2530 }
2531
2532 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2533 {
2534         if (mainwin->summaryview->folder_item) {
2535                 if (mainwin->summaryview->folder_item->folder->account != NULL
2536                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2537                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2538                 else
2539                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2540         }
2541         else
2542                 compose_new(NULL);
2543 }
2544
2545 static void compose_mail_cb(MainWindow *mainwin, guint action,
2546                             GtkWidget *widget)
2547 {
2548         PrefsAccount * ac;
2549         GList * list;
2550         GList * cur;
2551
2552         if (mainwin->summaryview->folder_item) {
2553                 ac = mainwin->summaryview->folder_item->folder->account;
2554                 if (ac && ac->protocol != A_NNTP) {
2555                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2556                         return;
2557                 }
2558         }
2559
2560         if(cur_account && (cur_account->protocol != A_NNTP)) {
2561                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2562                 return;
2563         }
2564
2565         list = account_get_list();
2566         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2567                 ac = (PrefsAccount *) cur->data;
2568                 if (ac->protocol != A_NNTP) {
2569                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2570                         return;
2571                 }
2572         }
2573 }
2574
2575 static void compose_news_cb(MainWindow *mainwin, guint action,
2576                             GtkWidget *widget)
2577 {
2578         PrefsAccount * ac = NULL;
2579         GList * list;
2580         GList * cur;
2581
2582         if (mainwin->summaryview->folder_item) {
2583                 ac = mainwin->summaryview->folder_item->folder->account;
2584                 if (ac && ac->protocol == A_NNTP) {
2585                         compose_new_with_recipient
2586                                 (ac, mainwin->summaryview->folder_item->path);
2587                         return;
2588                 }
2589         }
2590
2591         list = account_get_list();
2592         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2593                 ac = (PrefsAccount *) cur->data;
2594                 if (ac->protocol == A_NNTP) {
2595                         compose_new(ac);
2596                         return;
2597                 }
2598         }
2599 }
2600
2601 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2602 {
2603         summary_reply(mainwin->summaryview, (ComposeMode)action);
2604 }
2605
2606 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2607 {
2608         summary_move_to(mainwin->summaryview);
2609 }
2610
2611 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2612 {
2613         summary_copy_to(mainwin->summaryview);
2614 }
2615
2616 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2617 {
2618         summary_delete(mainwin->summaryview);
2619 }
2620
2621 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2622 {
2623         summary_open_msg(mainwin->summaryview);
2624 }
2625
2626 static void view_source_cb(MainWindow *mainwin, guint action,
2627                            GtkWidget *widget)
2628 {
2629         summary_view_source(mainwin->summaryview);
2630 }
2631
2632 static void show_all_header_cb(MainWindow *mainwin, guint action,
2633                                GtkWidget *widget)
2634 {
2635         summary_display_msg_selected(mainwin->summaryview, TRUE);
2636 }
2637
2638 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2639 {
2640         summary_reedit(mainwin->summaryview);
2641 }
2642
2643 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2644 {
2645         summary_mark(mainwin->summaryview);
2646 }
2647
2648 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2649 {
2650         summary_unmark(mainwin->summaryview);
2651 }
2652
2653 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2654                               GtkWidget *widget)
2655 {
2656         summary_mark_as_unread(mainwin->summaryview);
2657 }
2658
2659 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2660                             GtkWidget *widget)
2661 {
2662         summary_mark_as_read(mainwin->summaryview);
2663 }
2664
2665 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2666                              GtkWidget *widget)
2667 {
2668         summary_mark_all_read(mainwin->summaryview);
2669 }
2670
2671 static void add_address_cb(MainWindow *mainwin, guint action,
2672                            GtkWidget *widget)
2673 {
2674         summary_add_address(mainwin->summaryview);
2675 }
2676
2677 static void set_charset_cb(MainWindow *mainwin, guint action,
2678                            GtkWidget *widget)
2679 {
2680         const gchar *str;
2681
2682         str = conv_get_charset_str((CharSet)action);
2683         g_free(prefs_common.force_charset);
2684         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2685
2686         summary_redisplay_msg(mainwin->summaryview);
2687
2688         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2689 }
2690
2691 static void hide_read_messages (MainWindow *mainwin, guint action,
2692                                 GtkWidget *widget)
2693 {
2694         if (!mainwin->summaryview->folder_item
2695             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2696                 return;
2697         summary_toggle_show_read_messages(mainwin->summaryview);
2698 }
2699
2700 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2701 {
2702         GtkItemFactory *ifactory;
2703
2704         if (!mainwin->summaryview->folder_item) return;
2705
2706         ifactory = gtk_item_factory_from_widget(widget);
2707
2708         if (0 == action) {
2709                 summary_thread_build(mainwin->summaryview);
2710                 mainwin->summaryview->folder_item->threaded = TRUE;
2711                 menu_set_sensitive(ifactory, "/View/Thread view",   FALSE);
2712                 menu_set_sensitive(ifactory, "/View/Unthread view", TRUE);
2713         } else {
2714                 summary_unthread(mainwin->summaryview);
2715                 mainwin->summaryview->folder_item->threaded = FALSE;
2716                 menu_set_sensitive(ifactory, "/View/Thread view",   TRUE);
2717                 menu_set_sensitive(ifactory, "/View/Unthread view", FALSE);
2718         }
2719 }
2720
2721 static void set_display_item_cb(MainWindow *mainwin, guint action,
2722                                 GtkWidget *widget)
2723 {
2724         prefs_summary_column_open();
2725 }
2726
2727 static void sort_summary_cb(MainWindow *mainwin, guint action,
2728                             GtkWidget *widget)
2729 {
2730         summary_sort(mainwin->summaryview, (SummarySortType)action);
2731 }
2732
2733 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2734                                   GtkWidget *widget)
2735 {
2736         summary_attract_by_subject(mainwin->summaryview);
2737 }
2738
2739 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2740                                  GtkWidget *widget)
2741 {
2742         summary_delete_duplicated(mainwin->summaryview);
2743 }
2744
2745 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2746 {
2747         summary_filter(mainwin->summaryview);
2748 }
2749
2750 static void execute_summary_cb(MainWindow *mainwin, guint action,
2751                                GtkWidget *widget)
2752 {
2753         summary_execute(mainwin->summaryview);
2754 }
2755
2756 static void update_summary_cb(MainWindow *mainwin, guint action,
2757                               GtkWidget *widget)
2758 {
2759         FolderItem *fitem;
2760         FolderView *folderview = mainwin->folderview;
2761
2762         if (!mainwin->summaryview->folder_item) return;
2763         if (!folderview->opened) return;
2764
2765         folder_update_op_count();
2766
2767         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2768                                             folderview->opened);
2769         if (!fitem) return;
2770
2771         summary_show(mainwin->summaryview, fitem, TRUE);
2772 }
2773
2774 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2775 {
2776         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2777 }
2778
2779 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2780 {
2781         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2782 }
2783
2784 static void prev_unread_cb(MainWindow *mainwin, guint action,
2785                            GtkWidget *widget)
2786 {
2787         summary_select_prev_unread(mainwin->summaryview);
2788 }
2789
2790 static void next_unread_cb(MainWindow *mainwin, guint action,
2791                            GtkWidget *widget)
2792 {
2793         summary_select_next_unread(mainwin->summaryview);
2794 }
2795
2796 static void prev_marked_cb(MainWindow *mainwin, guint action,
2797                            GtkWidget *widget)
2798 {
2799         summary_select_prev_marked(mainwin->summaryview);
2800 }
2801
2802 static void next_marked_cb(MainWindow *mainwin, guint action,
2803                            GtkWidget *widget)
2804 {
2805         summary_select_next_marked(mainwin->summaryview);
2806 }
2807
2808 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2809                             GtkWidget *widget)
2810 {
2811         summary_select_prev_labeled(mainwin->summaryview);
2812 }
2813
2814 static void next_labeled_cb(MainWindow *mainwin, guint action,
2815                             GtkWidget *widget)
2816 {
2817         summary_select_next_labeled(mainwin->summaryview);
2818 }
2819
2820 static void goto_folder_cb(MainWindow *mainwin, guint action,
2821                            GtkWidget *widget)
2822 {
2823         FolderItem *to_folder;
2824
2825         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2826
2827         if (to_folder)
2828                 folderview_select(mainwin->folderview, to_folder);
2829 }
2830
2831 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2832 {
2833         messageview_copy_clipboard(mainwin->messageview);
2834 }
2835
2836 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2837 {
2838         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2839                 summary_select_all(mainwin->summaryview);
2840         else if (mainwin->summaryview->msg_is_toggled_on &&
2841                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2842                 messageview_select_all(mainwin->messageview);
2843 }
2844
2845 static void create_filter_cb(MainWindow *mainwin, guint action,
2846                              GtkWidget *widget)
2847 {
2848         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2849 }
2850
2851 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2852                                  GtkWidget *widget)
2853 {
2854         prefs_common_open();
2855 }
2856
2857 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2858                                  GtkWidget *widget)
2859 {
2860         prefs_filter_open(NULL, NULL);
2861 }
2862
2863 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2864                                   GtkWidget *widget)
2865 {
2866         prefs_scoring_open(NULL);
2867 }
2868
2869 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2870                                     GtkWidget *widget)
2871 {
2872         prefs_filtering_open(NULL);
2873 }
2874
2875 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2876                                    GtkWidget *widget)
2877 {
2878         prefs_template_open();
2879 }
2880
2881 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2882                                   GtkWidget *widget)
2883 {
2884         prefs_actions_open(mainwin);
2885 }
2886
2887 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2888                                   GtkWidget *widget)
2889 {
2890         if (!cur_account) {
2891                 new_account_cb(mainwin, 0, widget);
2892         } else {
2893                 gboolean prev_default = cur_account->is_default;
2894
2895                 prefs_account_open(cur_account);
2896                 if (!prev_default && cur_account->is_default)
2897                         account_set_as_default(cur_account);
2898                 account_save_config_all();
2899                 account_set_menu();
2900                 main_window_reflect_prefs_all();
2901         }
2902 }
2903
2904 static void new_account_cb(MainWindow *mainwin, guint action,
2905                            GtkWidget *widget)
2906 {
2907         account_edit_open();
2908         if (!compose_get_compose_list()) account_add();
2909 }
2910
2911 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2912 {
2913         cur_account = (PrefsAccount *)data;
2914         main_window_reflect_prefs_all();
2915 }
2916
2917 static void manual_open_cb(MainWindow *mainwin, guint action,
2918                            GtkWidget *widget)
2919 {
2920         manual_open((ManualLang)action);
2921 }
2922
2923 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2924 {
2925         MainWindow *mainwin = (MainWindow *)data;
2926         gchar *str;
2927
2928         if (item->path)
2929                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2930                                       LOCAL_FOLDER(folder)->rootpath,
2931                                       G_DIR_SEPARATOR,
2932                                       item->path);
2933         else
2934                 str = g_strdup_printf(_("Scanning folder %s ..."),
2935                                       LOCAL_FOLDER(folder)->rootpath);
2936
2937         STATUSBAR_PUSH(mainwin, str);
2938         STATUSBAR_POP(mainwin);
2939         g_free(str);
2940 }
2941
2942 static void activate_compose_button (MainWindow *mainwin,
2943                                 ToolbarStyle style,
2944                                 ComposeButtonType type)
2945 {
2946         SensitiveCond state = main_window_get_current_state(mainwin);
2947
2948         if (style == TOOLBAR_NONE) 
2949                 return;
2950
2951         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2952                 : mainwin->compose_news_btn);
2953         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2954                 : mainwin->compose_mail_btn);
2955         mainwin->compose_btn_type = type;       
2956 }
2957
2958 void main_window_toolbar_set_compose_button(MainWindow *mainwin, ComposeButtonType compose_btn_type)
2959 {
2960         if (mainwin->compose_btn_type != compose_btn_type)
2961                 activate_compose_button(mainwin, 
2962                                         prefs_common.toolbar_style,
2963                                         compose_btn_type);
2964 }
2965
2966 static void menuitem_expandsummaryview_statechanged (GtkWidget *widget, GtkStateType state, gpointer data)
2967 {
2968         MainWindow *mainwin = (MainWindow*) data;
2969         
2970         if (!mainwin) return;
2971                 
2972         gtk_widget_set_sensitive(GTK_WIDGET(mainwin->summaryview->toggle_view_btn), GTK_WIDGET_IS_SENSITIVE(widget));
2973 }
2974
2975 #define BREAK_ON_MODIFIER_KEY() \
2976         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2977
2978 static void key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
2979 {
2980         MainWindow *mainwin = (MainWindow*) data;
2981         
2982         if (!mainwin || !event) return;
2983                 
2984         switch (event->keyval) {
2985         case GDK_Q:             /* Quit */
2986                 BREAK_ON_MODIFIER_KEY();
2987
2988                 app_exit_cb(mainwin, 0, NULL);
2989                 return;
2990         default:
2991                 break;
2992         }
2993 }
2994
2995 #undef BREAK_ON_MODIFIER_KEY
2996
2997 static void set_toolbar_style(MainWindow *mainwin)
2998 {
2999         switch (prefs_common.toolbar_style) {
3000         case TOOLBAR_NONE:
3001                 gtk_widget_hide(mainwin->handlebox);
3002                 break;
3003         case TOOLBAR_ICON:
3004                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
3005                                       GTK_TOOLBAR_ICONS);
3006                 break;
3007         case TOOLBAR_TEXT:
3008                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
3009                                       GTK_TOOLBAR_TEXT);
3010                 break;
3011         case TOOLBAR_BOTH:
3012                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
3013                                       GTK_TOOLBAR_BOTH);
3014                 break;
3015         }
3016         
3017         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
3018                 gtk_widget_show(mainwin->handlebox);
3019                 gtk_widget_queue_resize(mainwin->handlebox);
3020         }
3021 }
3022