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