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