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