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