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