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