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