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