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