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