03cc613066df2024582adbab358caebdb92f7890
[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
1147         if (confirm) {
1148                 if (alertpanel(_("Empty trash"),
1149                                _("Empty all messages in trash?"),
1150                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1151                         return;
1152                 manage_window_focus_in(mainwin->window, NULL, NULL);
1153         }
1154
1155         procmsg_empty_trash();
1156
1157         for (list = folder_get_list(); list != NULL; list = list->next) {
1158                 Folder *folder;
1159
1160                 folder = list->data;
1161                 if (folder->trash) {
1162                         folder_item_scan(folder->trash);
1163                         folderview_update_item(folder->trash, TRUE);
1164                 }
1165         }
1166
1167         if (mainwin->summaryview->folder_item &&
1168             mainwin->summaryview->folder_item->stype == F_TRASH)
1169                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1170 }
1171
1172 void main_window_add_mailbox(MainWindow *mainwin)
1173 {
1174         gchar *path;
1175         Folder *folder;
1176
1177         path = input_dialog(_("Add mailbox"),
1178                             _("Input the location of mailbox.\n"
1179                               "If the existing mailbox is specified, it will be\n"
1180                               "scanned automatically."),
1181                             "Mail");
1182         if (!path) return;
1183         if (folder_find_from_path(path)) {
1184                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1185                 g_free(path);
1186                 return;
1187         }
1188         if (!strcmp(path, "Mail"))
1189                 folder = folder_new(F_MH, _("Mailbox"), path);
1190         else
1191                 folder = folder_new(F_MH, g_basename(path), path);
1192         g_free(path);
1193
1194         if (folder->create_tree(folder) < 0) {
1195                 alertpanel_error(_("Creation of the mailbox failed.\n"
1196                                    "Maybe some files already exist, or you don't have the permission to write there."));
1197                 folder_destroy(folder);
1198                 return;
1199         }
1200
1201         folder_add(folder);
1202         folder_set_ui_func(folder, scan_tree_func, mainwin);
1203         folder->scan_tree(folder);
1204         folder_set_ui_func(folder, NULL, NULL);
1205
1206         folderview_set(mainwin->folderview);
1207 }
1208
1209 void main_window_add_mbox(MainWindow *mainwin)
1210 {
1211         gchar *path;
1212         Folder *folder;
1213         FolderItem * item;
1214
1215         path = input_dialog(_("Add mbox mailbox"),
1216                             _("Input the location of mailbox."),
1217                             "mail");
1218
1219         if (!path) return;
1220
1221         if (folder_find_from_path(path)) {
1222                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1223                 g_free(path);
1224                 return;
1225         }
1226
1227         /*
1228         if (!strcmp(path, "Mail"))
1229                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1230                 else
1231         */
1232
1233         folder = folder_new(F_MBOX, g_basename(path), path);
1234         g_free(path);
1235
1236         if (folder->create_tree(folder) < 0) {
1237                 alertpanel_error(_("Creation of the mailbox failed."));
1238                 folder_destroy(folder);
1239                 return;
1240         }
1241
1242         folder_add(folder);
1243
1244         item = folder_item_new(folder->name, NULL);
1245         item->folder = folder;
1246         folder->node = g_node_new(item);
1247
1248         folder->create_folder(folder, item, "inbox");
1249         folder->create_folder(folder, item, "outbox");
1250         folder->create_folder(folder, item, "queue");
1251         folder->create_folder(folder, item, "draft");
1252         folder->create_folder(folder, item, "trash");
1253
1254         folderview_set(mainwin->folderview);
1255 }
1256
1257 typedef enum
1258 {
1259         M_UNLOCKED            = 1 << 0,
1260         M_MSG_EXIST           = 1 << 1,
1261         M_TARGET_EXIST        = 1 << 2,
1262         M_SINGLE_TARGET_EXIST = 1 << 3,
1263         M_EXEC                = 1 << 4,
1264         M_ALLOW_REEDIT        = 1 << 5,
1265         M_HAVE_ACCOUNT        = 1 << 6,
1266         M_THREADED            = 1 << 7,
1267         M_UNTHREADED          = 1 << 8,
1268         M_NEWS                = 1 << 9
1269 } SensitiveCond;
1270
1271 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1272 {
1273         SensitiveCond state = 0;
1274         SummarySelection selection;
1275         FolderItem *item = mainwin->summaryview->folder_item;
1276
1277         selection = summary_get_selection_type(mainwin->summaryview);
1278
1279         if (mainwin->lock_count == 0)
1280                 state |= M_UNLOCKED;
1281         if (selection != SUMMARY_NONE)
1282                 state |= M_MSG_EXIST;
1283         if (item) {
1284                 if (item->threaded)
1285                         state |= M_THREADED;
1286                 else
1287                         state |= M_UNTHREADED;  
1288         }               
1289         if (selection == SUMMARY_SELECTED_SINGLE ||
1290             selection == SUMMARY_SELECTED_MULTIPLE)
1291                 state |= M_TARGET_EXIST;
1292         if (selection == SUMMARY_SELECTED_SINGLE)
1293                 state |= M_SINGLE_TARGET_EXIST;
1294         if (item && item->folder->type != F_NEWS)
1295                 state |= M_EXEC;
1296         if (mainwin->summaryview->folder_item &&
1297             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1298                 state |= M_NEWS;
1299         if (selection == SUMMARY_SELECTED_SINGLE &&
1300             (item &&
1301              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1302               item->stype == F_QUEUE)))
1303                 state |= M_ALLOW_REEDIT;
1304         if (cur_account)
1305                 state |= M_HAVE_ACCOUNT;
1306
1307         return state;
1308 }
1309
1310 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1311 {
1312         SensitiveCond state;
1313         gboolean sensitive;
1314         gint i;
1315
1316         const struct {
1317                 GtkWidget *widget;
1318                 SensitiveCond cond;
1319         } entry[] = {
1320                 {mainwin->get_btn         , M_HAVE_ACCOUNT|M_UNLOCKED},
1321                 {mainwin->getall_btn      , M_HAVE_ACCOUNT|M_UNLOCKED},
1322                 {mainwin->compose_mail_btn, M_HAVE_ACCOUNT},
1323                 {mainwin->compose_news_btn, M_HAVE_ACCOUNT},
1324                 {mainwin->reply_btn       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1325                 {mainwin->reply_quote_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1326                 {mainwin->replyall_btn    , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1327                 {mainwin->replyall_quote_btn    , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1328                 {mainwin->replysender_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1329                 {mainwin->replysender_quote_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1330                 {mainwin->fwd_btn         , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1331                 /* {mainwin->prefs_btn      , M_UNLOCKED},
1332                 {mainwin->account_btn    , M_UNLOCKED}, */
1333                 {mainwin->next_btn        , M_MSG_EXIST},
1334                 {mainwin->delete_btn      , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1335                 {mainwin->exec_btn        , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1336                 {NULL, 0}
1337         };
1338
1339         state = main_window_get_current_state(mainwin);
1340
1341         for (i = 0; entry[i].widget != NULL; i++) {
1342                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1343                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1344         }
1345 }
1346
1347 void main_window_set_menu_sensitive(MainWindow *mainwin)
1348 {
1349         GtkItemFactory *ifactory;
1350         SensitiveCond state;
1351         gboolean sensitive;
1352         gint i;
1353
1354         static const struct {
1355                 gchar *const entry;
1356                 SensitiveCond cond;
1357         } entry[] = {
1358                 {"/File/Add mailbox..."        , M_UNLOCKED},
1359                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1360                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1361                 {"/File/Folder"                , M_UNLOCKED},
1362                 {"/File/Import mbox file..."   , M_UNLOCKED},
1363                 {"/File/Export to mbox file...", M_UNLOCKED},
1364                 {"/File/Empty trash"           , M_UNLOCKED},
1365                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1366                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1367                 {"/File/Close", M_UNLOCKED},
1368                 {"/File/Exit" , M_UNLOCKED},
1369
1370                 {"/View/Show all header"      , M_SINGLE_TARGET_EXIST},
1371                 {"/View/View source"          , M_SINGLE_TARGET_EXIST},
1372
1373                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1374                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1375 /*              {"/Message/Compose new message"   , M_HAVE_ACCOUNT}, */
1376                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1377                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1378                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1379                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1380                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1381                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1382                 {"/Message/Open in new window"    , M_SINGLE_TARGET_EXIST},
1383                 {"/Message/Re-edit", M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1384                 {"/Message/Move...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1385                 {"/Message/Copy...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1386                 {"/Message/Delete" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1387                 {"/Message/Mark"   , M_TARGET_EXIST},
1388
1389                 {"/Summary/Delete duplicated messages", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1390                 {"/Summary/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1391                 {"/Summary/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1392                 {"/Summary/Go to"                     , M_MSG_EXIST},
1393                 {"/Summary/Go to/Prev message"        , M_MSG_EXIST},
1394                 {"/Summary/Go to/Next message"        , M_MSG_EXIST},
1395                 {"/Summary/Go to/Next unread message" , M_MSG_EXIST},
1396                 {"/Summary/Go to/Prev marked message" , M_MSG_EXIST},
1397                 {"/Summary/Go to/Next marked message" , M_MSG_EXIST},
1398                 {"/Summary/Go to/Prev labeled message", M_MSG_EXIST},
1399                 {"/Summary/Go to/Next labeled message", M_MSG_EXIST},
1400                 {"/Summary/Sort"                      , M_MSG_EXIST},
1401                 {"/Summary/Thread view"               , M_UNTHREADED},
1402                 {"/Summary/Unthread view"             , M_THREADED},
1403
1404                 {"/Configuration", M_UNLOCKED},
1405
1406                 {NULL, 0}
1407         };
1408
1409         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1410         state = main_window_get_current_state(mainwin);
1411
1412         for (i = 0; entry[i].entry != NULL; i++) {
1413                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1414                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1415         }
1416 }
1417
1418 void main_window_popup(MainWindow *mainwin)
1419 {
1420         gint x, y;
1421         gint sx, sy;
1422         GtkWidget *widget;
1423
1424         gdk_window_get_origin(mainwin->window->window, &x, &y);
1425         sx = gdk_screen_width();
1426         sy = gdk_screen_height();
1427         x %= sx; if (x < 0) x = 0;
1428         y %= sy; if (y < 0) y = 0;
1429         gdk_window_move(mainwin->window->window, x, y);
1430         gdk_window_raise(mainwin->window->window);
1431         gdk_window_show(mainwin->window->window);
1432
1433         debug_print("window position: x = %d, y = %d\n", x, y);
1434
1435         switch (mainwin->type) {
1436         case SEPARATE_FOLDER:
1437                 widget = mainwin->win.sep_folder.folderwin;
1438                 gdk_window_get_origin(widget->window, &x, &y);
1439                 x %= sx; if (x < 0) x = 0;
1440                 y %= sy; if (y < 0) y = 0;
1441                 gdk_window_move(widget->window, x, y);
1442                 gdk_window_raise(widget->window);
1443                 break;
1444         case SEPARATE_MESSAGE:
1445                 widget = mainwin->win.sep_message.messagewin;
1446                 gdk_window_get_origin(widget->window, &x, &y);
1447                 x %= sx; if (x < 0) x = 0;
1448                 y %= sy; if (y < 0) y = 0;
1449                 gdk_window_move(widget->window, x, y);
1450                 gdk_window_raise(widget->window);
1451                 break;
1452         case SEPARATE_BOTH:
1453                 widget = mainwin->win.sep_both.folderwin;
1454                 gdk_window_get_origin(widget->window, &x, &y);
1455                 x %= sx; if (x < 0) x = 0;
1456                 y %= sy; if (y < 0) y = 0;
1457                 gdk_window_move(widget->window, x, y);
1458                 gdk_window_raise(widget->window);
1459                 widget = mainwin->win.sep_both.messagewin;
1460                 gdk_window_get_origin(widget->window, &x, &y);
1461                 x %= sx; if (x < 0) x = 0;
1462                 y %= sy; if (y < 0) y = 0;
1463                 gdk_window_move(widget->window, x, y);
1464                 gdk_window_raise(widget->window);
1465                 break;
1466         default:
1467                 break;
1468         }
1469 }
1470
1471 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1472 {
1473         GtkWidget *folderwin = NULL;
1474         GtkWidget *messagewin = NULL;
1475         GtkWidget *hpaned;
1476         GtkWidget *vpaned;
1477         GtkWidget *vbox_body = mainwin->vbox_body;
1478
1479         debug_print(_("Setting widgets..."));
1480
1481         /* create separated window(s) if needed */
1482         if (type & SEPARATE_FOLDER) {
1483                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1484                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1485                                       TRUE, TRUE, FALSE);
1486                 gtk_widget_set_usize(folderwin, -1,
1487                                      prefs_common.mainview_height);
1488                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1489                                                BORDER_WIDTH);
1490                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1491                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1492                                    NULL);
1493         }
1494         if (type & SEPARATE_MESSAGE) {
1495                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1496                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1497                                       TRUE, TRUE, FALSE);
1498                 gtk_widget_set_usize
1499                         (messagewin, prefs_common.mainview_width,
1500                          prefs_common.mainview_height
1501                          - prefs_common.summaryview_height
1502                          + DEFAULT_HEADERVIEW_HEIGHT);
1503                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1504                                                BORDER_WIDTH);
1505                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1506                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1507                                    NULL);
1508         }
1509
1510         switch (type) {
1511         case SEPARATE_NONE:
1512                 hpaned = gtk_hpaned_new();
1513                 gtk_widget_show(hpaned);
1514                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1515                 gtk_paned_add1(GTK_PANED(hpaned),
1516                                GTK_WIDGET_PTR(mainwin->folderview));
1517
1518                 vpaned = gtk_vpaned_new();
1519                 if (mainwin->summaryview->msg_is_toggled_on) {
1520                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1521                         gtk_paned_add1(GTK_PANED(vpaned),
1522                                        GTK_WIDGET_PTR(mainwin->summaryview));
1523                 } else {
1524                         gtk_paned_add2(GTK_PANED(hpaned),
1525                                        GTK_WIDGET_PTR(mainwin->summaryview));
1526                         gtk_widget_ref(vpaned);
1527                 }
1528                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1529                                      prefs_common.summaryview_width,
1530                                      prefs_common.summaryview_height);
1531                 gtk_paned_add2(GTK_PANED(vpaned),
1532                                GTK_WIDGET_PTR(mainwin->messageview));
1533                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1534                                      prefs_common.mainview_width, -1);
1535                 gtk_widget_set_usize(mainwin->window,
1536                                      prefs_common.folderview_width +
1537                                      prefs_common.mainview_width,
1538                                      prefs_common.mainwin_height);
1539                 gtk_widget_show_all(vpaned);
1540
1541                 mainwin->win.sep_none.hpaned = hpaned;
1542                 mainwin->win.sep_none.vpaned = vpaned;
1543                 break;
1544         case SEPARATE_FOLDER:
1545                 vpaned = gtk_vpaned_new();
1546                 if (mainwin->summaryview->msg_is_toggled_on) {
1547                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1548                                            TRUE, TRUE, 0);
1549                         gtk_paned_add1(GTK_PANED(vpaned),
1550                                        GTK_WIDGET_PTR(mainwin->summaryview));
1551                 } else {
1552                         gtk_box_pack_start(GTK_BOX(vbox_body),
1553                                            GTK_WIDGET_PTR(mainwin->summaryview),
1554                                            TRUE, TRUE, 0);
1555                         gtk_widget_ref(vpaned);
1556                 }
1557                 gtk_paned_add2(GTK_PANED(vpaned),
1558                                GTK_WIDGET_PTR(mainwin->messageview));
1559                 gtk_widget_show_all(vpaned);
1560                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1561                                      prefs_common.summaryview_width,
1562                                      prefs_common.summaryview_height);
1563                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1564                                      prefs_common.mainview_width, -1);
1565                 gtk_widget_set_usize(mainwin->window,
1566                                      prefs_common.mainview_width,
1567                                      prefs_common.mainview_height);
1568
1569                 gtk_container_add(GTK_CONTAINER(folderwin),
1570                                   GTK_WIDGET_PTR(mainwin->folderview));
1571
1572                 mainwin->win.sep_folder.folderwin = folderwin;
1573                 mainwin->win.sep_folder.vpaned    = vpaned;
1574
1575                 gtk_widget_show_all(folderwin);
1576                 break;
1577         case SEPARATE_MESSAGE:
1578                 hpaned = gtk_hpaned_new();
1579                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1580
1581                 gtk_paned_add1(GTK_PANED(hpaned),
1582                                GTK_WIDGET_PTR(mainwin->folderview));
1583                 gtk_paned_add2(GTK_PANED(hpaned),
1584                                GTK_WIDGET_PTR(mainwin->summaryview));
1585                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1586                                      prefs_common.summaryview_width,
1587                                      prefs_common.summaryview_height);
1588                 gtk_widget_set_usize(mainwin->window,
1589                                      prefs_common.folderview_width +
1590                                      prefs_common.mainview_width,
1591                                      prefs_common.mainwin_height);
1592                 gtk_widget_show_all(hpaned);
1593                 gtk_container_add(GTK_CONTAINER(messagewin),
1594                                   GTK_WIDGET_PTR(mainwin->messageview));
1595
1596                 mainwin->win.sep_message.messagewin = messagewin;
1597                 mainwin->win.sep_message.hpaned     = hpaned;
1598
1599                 gtk_widget_show_all(messagewin);
1600                 break;
1601         case SEPARATE_BOTH:
1602                 gtk_box_pack_start(GTK_BOX(vbox_body),
1603                                    GTK_WIDGET_PTR(mainwin->summaryview),
1604                                    TRUE, TRUE, 0);
1605                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1606                                      prefs_common.summaryview_width,
1607                                      prefs_common.summaryview_height);
1608                 gtk_widget_set_usize(mainwin->window,
1609                                      prefs_common.mainview_width,
1610                                      prefs_common.mainwin_height);
1611                 gtk_container_add(GTK_CONTAINER(folderwin),
1612                                   GTK_WIDGET_PTR(mainwin->folderview));
1613                 gtk_container_add(GTK_CONTAINER(messagewin),
1614                                   GTK_WIDGET_PTR(mainwin->messageview));
1615
1616                 mainwin->win.sep_both.folderwin = folderwin;
1617                 mainwin->win.sep_both.messagewin = messagewin;
1618
1619                 gtk_widget_show_all(folderwin);
1620                 gtk_widget_show_all(messagewin);
1621                 break;
1622         }
1623
1624         mainwin->type = type;
1625
1626         debug_print(_("done.\n"));
1627 }
1628
1629 #include "pixmaps/stock_mail_receive.xpm"
1630 #include "pixmaps/stock_mail_receive_all.xpm"
1631 #include "pixmaps/stock_mail_compose.xpm"
1632 #include "pixmaps/stock_news_compose.xpm"
1633 #include "pixmaps/stock_mail_reply.xpm"
1634 #include "pixmaps/stock_mail_reply_quote.xpm"
1635 #include "pixmaps/stock_mail_reply_to_all.xpm"
1636 #include "pixmaps/stock_mail_reply_to_all_quote.xpm"
1637 #include "pixmaps/stock_mail_reply_to_author.xpm"
1638 #include "pixmaps/stock_mail_reply_to_author_quote.xpm"
1639 #include "pixmaps/stock_mail_forward.xpm"
1640 #include "pixmaps/stock_mail_send.xpm"
1641 #include "pixmaps/stock_preferences.xpm"
1642 #include "pixmaps/stock_properties.xpm"
1643 #include "pixmaps/stock_down_arrow.xpm"
1644 #include "pixmaps/stock_close.xpm"
1645 #include "pixmaps/stock_exec.xpm"
1646
1647 #define CREATE_TOOLBAR_ICON(xpm_d) \
1648 { \
1649         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1650                                             &container->style->white, \
1651                                             xpm_d); \
1652         icon_wid = gtk_pixmap_new(icon, mask); \
1653 }
1654
1655 static void main_window_toolbar_create(MainWindow *mainwin,
1656                                        GtkWidget *container)
1657 {
1658         GtkWidget *toolbar;
1659         GdkPixmap *icon;
1660         GdkBitmap *mask;
1661         GtkWidget *icon_wid;
1662         GtkWidget *get_btn;
1663         GtkWidget *getall_btn;
1664         GtkWidget *compose_mail_btn;
1665         GtkWidget *compose_news_btn;
1666         GtkWidget *compose_mail_btn_plain;
1667         GtkWidget *compose_news_btn_plain;
1668         GtkWidget *reply_btn;
1669         GtkWidget *reply_quote_btn;
1670         GtkWidget *replyall_btn;
1671         GtkWidget *replyall_quote_btn;
1672         GtkWidget *replysender_btn;
1673         GtkWidget *replysender_quote_btn;
1674         GtkWidget *fwd_btn;
1675         GtkWidget *send_btn;
1676         /*
1677         GtkWidget *prefs_btn;
1678         GtkWidget *account_btn;
1679         */
1680         GtkWidget *next_btn;
1681         GtkWidget *delete_btn;
1682         GtkWidget *exec_btn;
1683         GtkWidget *compose_type_btn;
1684         GtkWidget *compose_type_arrow;
1685         GtkWidget *compose_box;
1686         GtkWidget *compose_label;
1687         GtkTooltips *tooltips;
1688
1689         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1690                                   GTK_TOOLBAR_BOTH);
1691         gtk_container_add(GTK_CONTAINER(container), toolbar);
1692         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1693         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1694         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1695                                     GTK_TOOLBAR_SPACE_LINE);
1696
1697         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1698         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1699                                           _("Get"),
1700                                           _("Get new mail from current account"),
1701                                           "Get",
1702                                           icon_wid, toolbar_inc_cb, mainwin);
1703         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1704         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1705                                              _("Get all"),
1706                                              _("Get new mail from all accounts"),
1707                                              "Get all",
1708                                              icon_wid,
1709                                              toolbar_inc_all_cb,
1710                                              mainwin);
1711
1712         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1713
1714         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1715         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1716                                            _("Send"),
1717                                            _("Send queued message(s)"),
1718                                            "Send",
1719                                            icon_wid,
1720                                            toolbar_send_cb,
1721                                            mainwin);
1722
1723         /* to implement Leandro's "combined" compose buttons, we create
1724          * two sets of compose buttons, one for normal (text + icon) 
1725          * toolbar, and one for both text-only and icon-only toolbar;
1726          * we switch between those sets. */
1727
1728         /* insert compose mail button widget */                                    
1729
1730         compose_mail_btn = gtk_button_new();
1731         gtk_widget_show(compose_mail_btn);
1732         tooltips = gtk_tooltips_new();
1733         gtk_tooltips_set_tip(tooltips, compose_mail_btn, 
1734                                                  _("Compose email message"),
1735                                                  _("email"));
1736         compose_box = gtk_vbox_new(0, 0);
1737         gtk_widget_show(compose_box);
1738         
1739         gtk_container_add(GTK_CONTAINER(compose_mail_btn), compose_box);
1740         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1741         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1742
1743         compose_label = gtk_label_new(_("Email"));
1744         gtk_widget_show(compose_label);
1745         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1746         
1747         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_mail_btn), GTK_CAN_FOCUS);
1748         gtk_button_set_relief(GTK_BUTTON(compose_mail_btn), GTK_RELIEF_NONE);
1749         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_mail_btn,
1750                 NULL, NULL);
1751
1752         /* insert compose news button widget */
1753
1754         compose_news_btn = gtk_button_new();
1755         gtk_widget_show(compose_news_btn);
1756         tooltips = gtk_tooltips_new();
1757         gtk_tooltips_set_tip(tooltips, compose_news_btn,
1758                                                  _("Compose news article"),
1759                                                  _("news"));
1760         compose_box = gtk_vbox_new(0, 0);
1761         gtk_widget_show(compose_box);
1762         
1763         gtk_container_add(GTK_CONTAINER(compose_news_btn), compose_box);
1764         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1765         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1766
1767         compose_label = gtk_label_new(_("News"));
1768         gtk_widget_show(compose_label);
1769         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1770         
1771         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_news_btn), GTK_CAN_FOCUS);
1772         gtk_button_set_relief(GTK_BUTTON(compose_news_btn), GTK_RELIEF_NONE);
1773         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_news_btn,
1774                 NULL, NULL);
1775         
1776         /* insert compose btn plain */
1777         
1778         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1779         compose_mail_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1780                                               _("Email"),
1781                                               _("Compose an email message"),
1782                                               "New",
1783                                               icon_wid,
1784                                               toolbar_compose_mail_cb,
1785                                               mainwin);
1786
1787         /* insert compose btn plain */
1788
1789         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1790         compose_news_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1791                                               _("News"),
1792                                               _("Compose a news message"),
1793                                               "New",
1794                                               icon_wid,
1795                                               toolbar_compose_news_cb,
1796                                               mainwin);
1797
1798         /* insert compose button type widget */
1799         
1800         compose_type_btn = gtk_button_new();
1801         gtk_widget_show(compose_type_btn);
1802         
1803         compose_type_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1804         gtk_widget_show(compose_type_arrow);
1805         
1806         gtk_container_add(GTK_CONTAINER(compose_type_btn), compose_type_arrow);
1807
1808         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_type_btn), GTK_CAN_FOCUS);
1809         gtk_button_set_relief(GTK_BUTTON(compose_type_btn), GTK_RELIEF_NONE);
1810
1811         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_type_btn,
1812                 NULL, NULL);
1813
1814         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1815         
1816         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1817         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1818                                             _("Reply"),
1819                                             _("Reply to the message"),
1820                                             "Reply",
1821                                             icon_wid,
1822                                             toolbar_reply_cb,
1823                                             mainwin);
1824         CREATE_TOOLBAR_ICON(stock_mail_reply_quote_xpm);
1825         reply_quote_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1826                                             _("Reply"),
1827                                             _("Reply to the message quoting it"),
1828                                             "Reply quoting",
1829                                             icon_wid,
1830                                             toolbar_reply_quote_cb,
1831                                             mainwin);
1832         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1833         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1834                                                _("All"),
1835                                                _("Reply to all"),
1836                                                "Reply to all",
1837                                                icon_wid,
1838                                                toolbar_reply_to_all_cb,
1839                                                mainwin);
1840         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_quote_xpm);
1841         replyall_quote_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1842                                                _("All"),
1843                                                _("Reply to all quoting the message"),
1844                                                "Reply to all quoting",
1845                                                icon_wid,
1846                                                toolbar_reply_to_all_quote_cb,
1847                                                mainwin);
1848         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1849         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1850                                                   _("Sender"),
1851                                                   _("Reply to sender"),
1852                                                   "Reply to sender",
1853                                                   icon_wid,
1854                                                   toolbar_reply_to_sender_cb,
1855                                                   mainwin);
1856         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_quote_xpm);
1857         replysender_quote_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1858                                                   _("Sender"),
1859                                                   _("Reply to sender quoting the message"),
1860                                                   "Reply to sender quoting",
1861                                                   icon_wid,
1862                                                   toolbar_reply_to_sender_quote_cb,
1863                                                   mainwin);
1864         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1865         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1866                                           _("Forward"),
1867                                           _("Forward the message"),
1868                                           "Fwd",
1869                                           icon_wid,
1870                                           toolbar_forward_cb,
1871                                           mainwin);
1872
1873         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1874
1875         CREATE_TOOLBAR_ICON(stock_close_xpm);
1876         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1877                                           _("Delete"),
1878                                           _("Delete the message"),
1879                                           "Delete",
1880                                           icon_wid,
1881                                           toolbar_delete_cb,
1882                                           mainwin);
1883
1884         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1885         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1886                                            _("Execute"),
1887                                            _("Execute marked process"),
1888                                            "Execute",
1889                                            icon_wid,
1890                                            toolbar_exec_cb,
1891                                            mainwin);
1892
1893         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1894         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1895                                            _("Next"),
1896                                            _("Next unread message"),
1897                                            "Next unread",
1898                                            icon_wid,
1899                                            toolbar_next_unread_cb,
1900                                            mainwin);
1901
1902         /*
1903         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1904
1905         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1906         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1907                                             _("Prefs"),
1908                                             _("Common preference"),
1909                                             "Prefs",
1910                                             icon_wid,
1911                                             toolbar_prefs_cb,
1912                                             mainwin);
1913         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1914         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1915                                               _("Account"),
1916                                               _("Account setting"),
1917                                               "Account",
1918                                               icon_wid,
1919                                               toolbar_account_cb,
1920                                               mainwin);
1921         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1922                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1923                            mainwin);
1924         */
1925
1926         gtk_signal_connect(GTK_OBJECT(compose_type_btn), "clicked",
1927                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_cb),
1928                 mainwin);
1929
1930         gtk_signal_connect(GTK_OBJECT(compose_mail_btn), "clicked",
1931                 GTK_SIGNAL_FUNC(toolbar_compose_mail_cb),
1932                 mainwin);
1933
1934         gtk_signal_connect(GTK_OBJECT(compose_news_btn), "clicked",
1935                 GTK_SIGNAL_FUNC(toolbar_compose_news_cb),
1936                 mainwin);
1937
1938         mainwin->toolbar         = toolbar;
1939         mainwin->get_btn         = get_btn;
1940         mainwin->getall_btn      = getall_btn;
1941         mainwin->compose_mail_btn = compose_mail_btn;
1942         mainwin->compose_news_btn = compose_news_btn;
1943         mainwin->compose_mail_btn_plain = compose_mail_btn_plain;
1944         mainwin->compose_news_btn_plain = compose_news_btn_plain;
1945         mainwin->reply_btn       = reply_btn;
1946         mainwin->reply_quote_btn = reply_quote_btn;
1947         mainwin->replyall_btn    = replyall_btn;
1948         mainwin->replyall_quote_btn     = replyall_quote_btn;
1949         mainwin->replysender_btn = replysender_btn;
1950         mainwin->replysender_quote_btn  = replysender_quote_btn;
1951         mainwin->fwd_btn         = fwd_btn;
1952         mainwin->send_btn        = send_btn;
1953         /*
1954         mainwin->prefs_btn       = prefs_btn;
1955         mainwin->account_btn     = account_btn;
1956         */
1957         mainwin->next_btn        = next_btn;
1958         mainwin->delete_btn      = delete_btn;
1959         mainwin->exec_btn        = exec_btn;
1960
1961         gtk_widget_show_all(toolbar);
1962
1963         /* activate Leandro menu system */
1964         activate_compose_button(mainwin, 
1965                                 prefs_common.toolbar_style,
1966                                 mainwin->compose_btn_type);
1967 }
1968
1969 /* callback functions */
1970
1971 static void toolbar_popup_compose_type_cb       (GtkWidget      *widget,
1972                                  gpointer data)
1973 {
1974         MainWindow *mainwindow = (MainWindow *) data;
1975         GtkWidget *compose_menu, *compose_item;
1976
1977         g_return_if_fail(mainwindow != NULL);
1978         
1979         compose_menu = gtk_menu_new();
1980         
1981         compose_item = gtk_menu_item_new_with_label(_("Email message"));
1982         gtk_widget_show(compose_item);
1983         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1984         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1985                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1986                 mainwindow);
1987         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_MAIL));            
1988         
1989         compose_item = gtk_menu_item_new_with_label(_("News article"));
1990         gtk_widget_show(compose_item);
1991         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1992         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1993                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1994                 mainwindow);
1995         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_NEWS));            
1996                 
1997         gtk_menu_popup(GTK_MENU(compose_menu), NULL, NULL, NULL,
1998                 NULL, 1, 0);
1999 }
2000
2001 static void toolbar_popup_compose_type_set(GtkWidget *widget, gpointer data)
2002 {
2003         ComposeButtonType compose_type = GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(widget), "entry") );
2004         MainWindow *mainwindow = (MainWindow *) data;
2005
2006         mainwindow->compose_btn_type = compose_type;
2007
2008         activate_compose_button(mainwindow, prefs_common.toolbar_style, mainwindow->compose_btn_type);
2009 }       
2010
2011 static void toolbar_inc_cb      (GtkWidget      *widget,
2012                                  gpointer        data)
2013 {
2014         MainWindow *mainwin = (MainWindow *)data;
2015
2016         inc_mail_cb(mainwin, 0, NULL);
2017 }
2018
2019 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2020                                  gpointer        data)
2021 {
2022         MainWindow *mainwin = (MainWindow *)data;
2023
2024         inc_all_account_mail_cb(mainwin, 0, NULL);
2025 }
2026
2027 static void toolbar_send_cb     (GtkWidget      *widget,
2028                                  gpointer        data)
2029 {
2030         MainWindow *mainwin = (MainWindow *)data;
2031
2032         send_queue_cb(mainwin, 0, NULL);
2033 }
2034
2035 static void toolbar_compose_cb  (GtkWidget      *widget,
2036                                  gpointer        data)
2037 {
2038         MainWindow *mainwin = (MainWindow *)data;
2039
2040         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
2041                 compose_cb(mainwin, 0, NULL);
2042         else
2043                 compose_news_cb(mainwin, 0, NULL);
2044 }
2045
2046 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2047                                  gpointer        data)
2048 {
2049         MainWindow *mainwin = (MainWindow *)data;
2050
2051         compose_news_cb(mainwin, 0, NULL);
2052 }
2053
2054 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2055                                  gpointer        data)
2056 {
2057         MainWindow *mainwin = (MainWindow *)data;
2058
2059         compose_mail_cb(mainwin, 0, NULL);
2060 }
2061
2062 static void toolbar_reply_cb    (GtkWidget      *widget,
2063                                  gpointer        data)
2064 {
2065         MainWindow *mainwin = (MainWindow *)data;
2066
2067         reply_cb(mainwin, COMPOSE_REPLY, NULL);
2068 }
2069
2070 static void toolbar_reply_quote_cb      (GtkWidget *widget, 
2071                                          gpointer data)
2072 {
2073         MainWindow *mainwin = (MainWindow *)data;
2074
2075         reply_cb(mainwin, COMPOSE_REPLY_WITH_QUOTE, NULL);
2076 }
2077
2078 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
2079                                          gpointer        data)
2080 {
2081         MainWindow *mainwin = (MainWindow *)data;
2082
2083         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
2084 }
2085
2086 static void toolbar_reply_to_all_quote_cb       (GtkWidget *widget, 
2087                                                  gpointer data)
2088 {
2089         MainWindow *mainwin = (MainWindow *)data;
2090         
2091         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL);
2092 }
2093
2094 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
2095                                          gpointer        data)
2096 {
2097         MainWindow *mainwin = (MainWindow *)data;
2098
2099         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER, NULL);
2100 }
2101
2102 static void toolbar_reply_to_sender_quote_cb    (GtkWidget *widget, 
2103                                                  gpointer data)
2104 {
2105         MainWindow *mainwin = (MainWindow *)data;
2106
2107         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL);
2108 }
2109
2110 static void toolbar_forward_cb  (GtkWidget      *widget,
2111                                  gpointer        data)
2112 {
2113         MainWindow *mainwin = (MainWindow *)data;
2114
2115         if (prefs_common.forward_as_attachment)
2116                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2117         else
2118                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2119 }
2120
2121 static void toolbar_delete_cb   (GtkWidget      *widget,
2122                                  gpointer        data)
2123 {
2124         MainWindow *mainwin = (MainWindow *)data;
2125
2126         summary_delete(mainwin->summaryview);
2127 }
2128
2129 static void toolbar_exec_cb     (GtkWidget      *widget,
2130                                  gpointer        data)
2131 {
2132         MainWindow *mainwin = (MainWindow *)data;
2133
2134         summary_execute(mainwin->summaryview);
2135 }
2136
2137 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2138                                          gpointer        data)
2139 {
2140         MainWindow *mainwin = (MainWindow *)data;
2141
2142         next_unread_cb(mainwin, 0, NULL);
2143 }
2144
2145 static void toolbar_prefs_cb    (GtkWidget      *widget,
2146                                  gpointer        data)
2147 {
2148         prefs_common_open();
2149 }
2150
2151 static void toolbar_account_cb  (GtkWidget      *widget,
2152                                  gpointer        data)
2153 {
2154         MainWindow *mainwin = (MainWindow *)data;
2155
2156         prefs_account_open_cb(mainwin, 0, NULL);
2157 }
2158
2159 static void toolbar_account_button_pressed(GtkWidget *widget,
2160                                            GdkEventButton *event,
2161                                            gpointer data)
2162 {
2163         MainWindow *mainwin = (MainWindow *)data;
2164
2165         if (!event) return;
2166         if (event->button != 3) return;
2167
2168         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2169         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2170                             widget);
2171
2172         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2173                        menu_button_position, widget,
2174                        event->button, event->time);
2175 }
2176
2177 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2178                                     gpointer data)
2179 {
2180         MainWindow *mainwin = (MainWindow *)data;
2181
2182         if (!event) return;
2183
2184         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2185         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2186                             widget);
2187
2188         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2189                        menu_button_position, widget,
2190                        event->button, event->time);
2191 }
2192
2193 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2194 {
2195         MainWindow *mainwin = (MainWindow *)data;
2196         GtkWidget *button;
2197
2198         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2199         if (!button) return;
2200         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2201         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2202         manage_window_focus_in(mainwin->window, NULL, NULL);
2203 }
2204
2205 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2206                                  gpointer data)
2207 {
2208         MainWindow *mainwin = (MainWindow *)data;
2209
2210         if (mainwin->lock_count == 0)
2211                 app_exit_cb(data, 0, widget);
2212
2213         return TRUE;
2214 }
2215
2216 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2217                            GtkWidget *widget)
2218 {
2219         main_window_add_mailbox(mainwin);
2220 }
2221
2222 static void add_mbox_cb(MainWindow *mainwin, guint action,
2223                         GtkWidget *widget)
2224 {
2225         main_window_add_mbox(mainwin);
2226 }
2227
2228 static void update_folderview_cb(MainWindow *mainwin, guint action,
2229                                  GtkWidget *widget)
2230 {
2231         summary_show(mainwin->summaryview, NULL, FALSE);
2232         folderview_update_all();
2233 }
2234
2235 static void new_folder_cb(MainWindow *mainwin, guint action,
2236                           GtkWidget *widget)
2237 {
2238         folderview_new_folder(mainwin->folderview);
2239 }
2240
2241 static void rename_folder_cb(MainWindow *mainwin, guint action,
2242                              GtkWidget *widget)
2243 {
2244         folderview_rename_folder(mainwin->folderview);
2245 }
2246
2247 static void delete_folder_cb(MainWindow *mainwin, guint action,
2248                              GtkWidget *widget)
2249 {
2250         folderview_delete_folder(mainwin->folderview);
2251 }
2252
2253 static void import_mbox_cb(MainWindow *mainwin, guint action,
2254                            GtkWidget *widget)
2255 {
2256         import_mbox(mainwin->summaryview->folder_item);
2257 }
2258
2259 static void export_mbox_cb(MainWindow *mainwin, guint action,
2260                            GtkWidget *widget)
2261 {
2262         export_mbox(mainwin->summaryview->folder_item);
2263 }
2264
2265 static void empty_trash_cb(MainWindow *mainwin, guint action,
2266                            GtkWidget *widget)
2267 {
2268         main_window_empty_trash(mainwin, TRUE);
2269 }
2270
2271 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2272 {
2273         summary_save_as(mainwin->summaryview);
2274 }
2275
2276 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2277 {
2278         summary_print(mainwin->summaryview);
2279 }
2280
2281 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2282 {
2283         if (prefs_common.confirm_on_exit) {
2284                 if (alertpanel(_("Exit"), _("Exit this program?"),
2285                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2286                         return;
2287                 manage_window_focus_in(mainwin->window, NULL, NULL);
2288         }
2289
2290         app_will_exit(widget, mainwin);
2291 }
2292
2293 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2294 {
2295         if (action == 1)
2296                 summary_search(mainwin->summaryview);
2297         else
2298                 message_search(mainwin->messageview);
2299 }
2300
2301 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2302                              GtkWidget *widget)
2303 {
2304         switch (mainwin->type) {
2305         case SEPARATE_NONE:
2306         case SEPARATE_MESSAGE:
2307                 break;
2308         case SEPARATE_FOLDER:
2309                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2310                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2311                 else
2312                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2313                 break;
2314         case SEPARATE_BOTH:
2315                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2316                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2317                 else
2318                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2319                 break;
2320         }
2321 }
2322
2323 static void toggle_message_cb(MainWindow *mainwin, guint action,
2324                               GtkWidget *widget)
2325 {
2326         switch (mainwin->type) {
2327         case SEPARATE_NONE:
2328         case SEPARATE_FOLDER:
2329                 break;
2330         case SEPARATE_MESSAGE:
2331                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2332                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2333                 else
2334                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2335                 break;
2336         case SEPARATE_BOTH:
2337                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2338                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2339                 else
2340                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2341                 break;
2342         }
2343 }
2344
2345 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2346                               GtkWidget *widget)
2347 {
2348         activate_compose_button(mainwin, (ToolbarStyle)action, 
2349                         mainwin->compose_btn_type);
2350         
2351         switch ((ToolbarStyle)action) {
2352         case TOOLBAR_NONE:
2353                 gtk_widget_hide(mainwin->handlebox);
2354         case TOOLBAR_ICON:
2355                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2356                                       GTK_TOOLBAR_ICONS);
2357                 break;
2358         case TOOLBAR_TEXT:
2359                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2360                                       GTK_TOOLBAR_TEXT);
2361                 break;
2362         case TOOLBAR_BOTH:
2363                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2364                                       GTK_TOOLBAR_BOTH);
2365                 break;
2366         }
2367
2368         if (action != TOOLBAR_NONE) {
2369                 gtk_widget_show(mainwin->handlebox);
2370                 gtk_widget_queue_resize(mainwin->handlebox);
2371         }
2372
2373         mainwin->toolbar_style = (ToolbarStyle)action;
2374         prefs_common.toolbar_style = (ToolbarStyle)action;
2375 }
2376
2377 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2378                                 GtkWidget *widget)
2379 {
2380         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2381                 gtk_widget_show(mainwin->hbox_stat);
2382                 prefs_common.show_statusbar = TRUE;
2383         } else {
2384                 gtk_widget_hide(mainwin->hbox_stat);
2385                 prefs_common.show_statusbar = FALSE;
2386         }
2387 }
2388
2389 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action, GtkWidget *widget)
2390
2391 {
2392         MainWindow *mainwin;
2393         SeparateType type;
2394
2395         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2396         g_return_if_fail(mainwin != NULL);
2397
2398         type = mainwin->type ^ action;
2399         main_window_separation_change(mainwin, type);
2400
2401         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2402         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2403 }
2404
2405 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2406                                 GtkWidget *widget)
2407 {
2408         addressbook_open(NULL);
2409 }
2410
2411 static void log_window_show_cb(MainWindow *mainwin, guint action,
2412                                GtkWidget *widget)
2413 {
2414         log_window_show(mainwin->logwin);
2415 }
2416
2417 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2418 {
2419         inc_mail(mainwin);
2420 }
2421
2422 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2423                                     GtkWidget *widget)
2424 {
2425         inc_all_account_mail(mainwin);
2426 }
2427
2428 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2429 {
2430         GList *list;
2431
2432         if (procmsg_send_queue() < 0)
2433                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2434
2435         statusbar_pop_all();
2436
2437         for (list = folder_get_list(); list != NULL; list = list->next) {
2438                 Folder *folder;
2439
2440                 folder = list->data;
2441                 if (folder->queue) {
2442                         folder_item_scan(folder->queue);
2443                         folderview_update_item(folder->queue, TRUE);
2444                 }
2445         }
2446 }
2447
2448 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2449 {
2450         if (mainwin->summaryview->folder_item) {
2451                 if (mainwin->summaryview->folder_item->folder->account != NULL
2452                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2453                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2454                 else
2455                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2456         }
2457         else
2458                 compose_new(NULL);
2459 }
2460
2461 static void compose_mail_cb(MainWindow *mainwin, guint action,
2462                             GtkWidget *widget)
2463 {
2464         PrefsAccount * ac;
2465         GList * list;
2466         GList * cur;
2467
2468         if (mainwin->summaryview->folder_item) {
2469                 ac = mainwin->summaryview->folder_item->folder->account;
2470                 if (ac && ac->protocol != A_NNTP) {
2471                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2472                         return;
2473                 }
2474         }
2475
2476         if(cur_account && (cur_account->protocol != A_NNTP)) {
2477                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2478                 return;
2479         }
2480
2481         list = account_get_list();
2482         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2483                 ac = (PrefsAccount *) cur->data;
2484                 if (ac->protocol != A_NNTP) {
2485                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2486                         return;
2487                 }
2488         }
2489 }
2490
2491 static void compose_news_cb(MainWindow *mainwin, guint action,
2492                             GtkWidget *widget)
2493 {
2494         PrefsAccount * ac = NULL;
2495         GList * list;
2496         GList * cur;
2497
2498         if (mainwin->summaryview->folder_item) {
2499                 ac = mainwin->summaryview->folder_item->folder->account;
2500                 if (ac && ac->protocol == A_NNTP) {
2501                         compose_new_with_recipient
2502                                 (ac, mainwin->summaryview->folder_item->path);
2503                         return;
2504                 }
2505         }
2506
2507         list = account_get_list();
2508         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2509                 ac = (PrefsAccount *) cur->data;
2510                 if (ac->protocol == A_NNTP) {
2511                         compose_new(ac);
2512                         return;
2513                 }
2514         }
2515 }
2516
2517 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2518 {
2519         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2520         MsgInfo *msginfo;
2521
2522         msginfo = gtk_ctree_node_get_row_data
2523                 (GTK_CTREE(mainwin->summaryview->ctree),
2524                  mainwin->summaryview->selected);
2525
2526         if (!msginfo) return;
2527
2528         switch (action) {
2529         case COMPOSE_REPLY:
2530                 compose_reply(msginfo, prefs_common.reply_with_quote,
2531                               FALSE, FALSE);
2532                 break;
2533         case COMPOSE_REPLY_WITH_QUOTE:
2534                 compose_reply(msginfo, TRUE, FALSE, FALSE);
2535                 break;
2536         case COMPOSE_REPLY_WITHOUT_QUOTE:
2537                 compose_reply(msginfo, FALSE, FALSE, FALSE);
2538                 break;
2539         case COMPOSE_REPLY_TO_SENDER:
2540                 compose_reply(msginfo, prefs_common.reply_with_quote,
2541                               FALSE, TRUE);
2542                 break;
2543         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
2544                 compose_reply(msginfo, TRUE, FALSE, TRUE);
2545                 break;
2546         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
2547                 compose_reply(msginfo, FALSE, FALSE, TRUE);
2548                 break;
2549         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2550                 compose_followup_and_reply_to(msginfo,
2551                                               prefs_common.reply_with_quote,
2552                                               FALSE, TRUE);
2553                 break;
2554         case COMPOSE_REPLY_TO_ALL:
2555                 compose_reply(msginfo, prefs_common.reply_with_quote,
2556                               TRUE, TRUE);
2557                 break;
2558         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
2559                 compose_reply(msginfo, TRUE, TRUE, FALSE);
2560                 break;
2561         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
2562                 compose_reply(msginfo, FALSE, TRUE, FALSE);
2563                 break;
2564         case COMPOSE_FORWARD:
2565                 if (!sel->next) {
2566                         compose_forward(NULL, msginfo, FALSE);
2567                         break;
2568                 }
2569                 /* if (sel->next) FALL_THROUGH */
2570         case COMPOSE_FORWARD_AS_ATTACH:
2571                 {
2572                         GSList *msginfo_list = NULL;
2573                         for ( ; sel != NULL; sel = sel->next)
2574                                 msginfo_list = g_slist_append(msginfo_list, 
2575                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2576                                                 GTK_CTREE_NODE(sel->data)));
2577                         compose_forward_multiple(NULL, msginfo_list);
2578                         g_slist_free(msginfo_list);
2579                 }                       
2580                 break;
2581         case COMPOSE_BOUNCE:
2582                         compose_bounce(NULL, msginfo);
2583                         break;
2584         default:
2585                 g_warning("reply_cb(): invalid action type: %d\n", action);
2586         }
2587
2588         summary_set_marks_selected(mainwin->summaryview);
2589 }
2590
2591 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2592 {
2593         summary_move_to(mainwin->summaryview);
2594 }
2595
2596 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2597 {
2598         summary_copy_to(mainwin->summaryview);
2599 }
2600
2601 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2602 {
2603         summary_delete(mainwin->summaryview);
2604 }
2605
2606 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2607 {
2608         summary_open_msg(mainwin->summaryview);
2609 }
2610
2611 static void view_source_cb(MainWindow *mainwin, guint action,
2612                            GtkWidget *widget)
2613 {
2614         summary_view_source(mainwin->summaryview);
2615 }
2616
2617 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2618 {
2619         summary_reedit(mainwin->summaryview);
2620 }
2621
2622 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2623 {
2624         summary_mark(mainwin->summaryview);
2625 }
2626
2627 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2628 {
2629         summary_unmark(mainwin->summaryview);
2630 }
2631
2632 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2633                               GtkWidget *widget)
2634 {
2635         summary_mark_as_unread(mainwin->summaryview);
2636 }
2637
2638 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2639                             GtkWidget *widget)
2640 {
2641         summary_mark_as_read(mainwin->summaryview);
2642 }
2643
2644 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2645                              GtkWidget *widget)
2646 {
2647         summary_mark_all_read(mainwin->summaryview);
2648 }
2649
2650 static void add_address_cb(MainWindow *mainwin, guint action,
2651                            GtkWidget *widget)
2652 {
2653         summary_add_address(mainwin->summaryview);
2654 }
2655
2656 static void set_charset_cb(MainWindow *mainwin, guint action,
2657                            GtkWidget *widget)
2658 {
2659         const gchar *str;
2660
2661         str = conv_get_charset_str((CharSet)action);
2662         g_free(prefs_common.force_charset);
2663         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2664
2665         summary_redisplay_msg(mainwin->summaryview);
2666
2667         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2668 }
2669
2670 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2671 {
2672         GtkItemFactory *ifactory;
2673
2674         if (!mainwin->summaryview->folder_item) return;
2675
2676         ifactory = gtk_item_factory_from_widget(widget);
2677
2678         if (0 == action) {
2679                 summary_thread_build(mainwin->summaryview);
2680                 mainwin->summaryview->folder_item->threaded = TRUE;
2681                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2682                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2683         } else {
2684                 summary_unthread(mainwin->summaryview);
2685                 mainwin->summaryview->folder_item->threaded = FALSE;
2686                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2687                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2688         }
2689 }
2690
2691 static void set_display_item_cb(MainWindow *mainwin, guint action,
2692                                 GtkWidget *widget)
2693 {
2694         prefs_summary_column_open();
2695 }
2696
2697 static void sort_summary_cb(MainWindow *mainwin, guint action,
2698                             GtkWidget *widget)
2699 {
2700         summary_sort(mainwin->summaryview, (SummarySortType)action);
2701 }
2702
2703 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2704                                   GtkWidget *widget)
2705 {
2706         summary_attract_by_subject(mainwin->summaryview);
2707 }
2708
2709 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2710                                  GtkWidget *widget)
2711 {
2712         summary_delete_duplicated(mainwin->summaryview);
2713 }
2714
2715 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2716 {
2717         summary_filter(mainwin->summaryview);
2718 }
2719
2720 static void execute_summary_cb(MainWindow *mainwin, guint action,
2721                                GtkWidget *widget)
2722 {
2723         summary_execute(mainwin->summaryview);
2724 }
2725
2726 static void update_summary_cb(MainWindow *mainwin, guint action,
2727                               GtkWidget *widget)
2728 {
2729         FolderItem *fitem;
2730         FolderView *folderview = mainwin->folderview;
2731
2732         if (!mainwin->summaryview->folder_item) return;
2733         if (!folderview->opened) return;
2734
2735         folder_update_op_count();
2736
2737         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2738                                             folderview->opened);
2739         if (!fitem) return;
2740
2741         summary_show(mainwin->summaryview, fitem, TRUE);
2742 }
2743
2744 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2745 {
2746         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2747 }
2748
2749 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2750 {
2751         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2752 }
2753
2754 static void prev_unread_cb(MainWindow *mainwin, guint action,
2755                            GtkWidget *widget)
2756 {
2757         summary_select_prev_unread(mainwin->summaryview);
2758 }
2759
2760 static void next_unread_cb(MainWindow *mainwin, guint action,
2761                            GtkWidget *widget)
2762 {
2763         summary_select_next_unread(mainwin->summaryview);
2764 }
2765
2766 static void prev_marked_cb(MainWindow *mainwin, guint action,
2767                            GtkWidget *widget)
2768 {
2769         summary_select_prev_marked(mainwin->summaryview);
2770 }
2771
2772 static void next_marked_cb(MainWindow *mainwin, guint action,
2773                            GtkWidget *widget)
2774 {
2775         summary_select_next_marked(mainwin->summaryview);
2776 }
2777
2778 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2779                             GtkWidget *widget)
2780 {
2781         summary_select_prev_labeled(mainwin->summaryview);
2782 }
2783
2784 static void next_labeled_cb(MainWindow *mainwin, guint action,
2785                             GtkWidget *widget)
2786 {
2787         summary_select_next_labeled(mainwin->summaryview);
2788 }
2789
2790 static void goto_folder_cb(MainWindow *mainwin, guint action,
2791                            GtkWidget *widget)
2792 {
2793         FolderItem *to_folder;
2794
2795         to_folder = foldersel_folder_sel(NULL, NULL);
2796
2797         if (to_folder)
2798                 folderview_select(mainwin->folderview, to_folder);
2799 }
2800
2801 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2802 {
2803         messageview_copy_clipboard(mainwin->messageview);
2804 }
2805
2806 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2807 {
2808         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2809                 summary_select_all(mainwin->summaryview);
2810         else if (mainwin->summaryview->msg_is_toggled_on &&
2811                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2812                 messageview_select_all(mainwin->messageview);
2813 }
2814
2815 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2816                                  GtkWidget *widget)
2817 {
2818         prefs_common_open();
2819 }
2820
2821 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2822                                  GtkWidget *widget)
2823 {
2824         prefs_filter_open();
2825 }
2826
2827 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2828                                   GtkWidget *widget)
2829 {
2830         prefs_scoring_open(NULL);
2831 }
2832
2833 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2834                                     GtkWidget *widget)
2835 {
2836         prefs_filtering_open(NULL);
2837 }
2838
2839 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2840                                    GtkWidget *widget)
2841 {
2842         prefs_template_open();
2843 }
2844
2845 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2846                                   GtkWidget *widget)
2847 {
2848         if (!cur_account) {
2849                 new_account_cb(mainwin, 0, widget);
2850         } else {
2851                 gboolean prev_default = cur_account->is_default;
2852
2853                 prefs_account_open(cur_account);
2854                 if (!prev_default && cur_account->is_default)
2855                         account_set_as_default(cur_account);
2856                 account_save_config_all();
2857                 account_set_menu();
2858                 main_window_reflect_prefs_all();
2859         }
2860 }
2861
2862 static void new_account_cb(MainWindow *mainwin, guint action,
2863                            GtkWidget *widget)
2864 {
2865         account_edit_open();
2866         if (!compose_get_compose_list()) account_add();
2867 }
2868
2869 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2870 {
2871         cur_account = (PrefsAccount *)data;
2872         main_window_reflect_prefs_all();
2873 }
2874
2875 static void manual_open_cb(MainWindow *mainwin, guint action,
2876                            GtkWidget *widget)
2877 {
2878         manual_open((ManualLang)action);
2879 }
2880
2881 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2882 {
2883         MainWindow *mainwin = (MainWindow *)data;
2884         gchar *str;
2885
2886         if (item->path)
2887                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2888                                       LOCAL_FOLDER(folder)->rootpath,
2889                                       G_DIR_SEPARATOR,
2890                                       item->path);
2891         else
2892                 str = g_strdup_printf(_("Scanning folder %s ..."),
2893                                       LOCAL_FOLDER(folder)->rootpath);
2894
2895         STATUSBAR_PUSH(mainwin, str);
2896         STATUSBAR_POP(mainwin);
2897         g_free(str);
2898 }
2899
2900 static void activate_compose_button (MainWindow *mainwin,
2901                                 ToolbarStyle style,
2902                                 ComposeButtonType type)
2903 {
2904         if (style == TOOLBAR_NONE) 
2905                 return;
2906
2907         if (style == TOOLBAR_BOTH) {
2908                 gtk_widget_hide(mainwin->compose_mail_btn_plain);
2909                 gtk_widget_hide(mainwin->compose_news_btn_plain);
2910                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2911                         : mainwin->compose_news_btn);
2912                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2913                         : mainwin->compose_mail_btn);
2914                 mainwin->compose_btn_type = type;       
2915         }
2916         else {
2917                 gtk_widget_hide(mainwin->compose_news_btn);
2918                 gtk_widget_hide(mainwin->compose_mail_btn);
2919                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn_plain 
2920                         : mainwin->compose_news_btn_plain);
2921                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn_plain
2922                         : mainwin->compose_mail_btn_plain);
2923                 mainwin->compose_btn_type = type;               
2924         }
2925 }
2926
2927 void main_window_toolbar_set_compose_button(MainWindow *mainwin, ComposeButtonType compose_btn_type)
2928 {
2929         if (mainwin->compose_btn_type != compose_btn_type)
2930                 activate_compose_button(mainwin, 
2931                                         prefs_common.toolbar_style,
2932                                         compose_btn_type);
2933 }
2934
2935 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
2936 {
2937         MainWindow *mainwin = (MainWindow *)data;
2938         
2939         if (!mainwin) return;
2940         if (event && (event->keyval == GDK_Control_L) || (event->keyval == GDK_Control_R)) {
2941                 main_window_set_toolbar_reply_buttons(mainwin, TRUE);
2942         }
2943 }
2944
2945 static void key_released(GtkWidget *widget, GdkEventKey *event, gpointer data)
2946 {
2947         MainWindow *mainwin = (MainWindow *)data;
2948         
2949         if (!mainwin) return;
2950         if (event && (event->keyval == GDK_Control_L) || (event->keyval == GDK_Control_R)) {
2951                 main_window_set_toolbar_reply_buttons(mainwin, FALSE);
2952         }
2953 }
2954
2955 void main_window_set_toolbar_reply_buttons(MainWindow *mainwin, gboolean keymod)
2956 {
2957         gboolean quote = (prefs_common.reply_with_quote ^ keymod);
2958         
2959         gtk_widget_hide(quote ? mainwin->reply_btn : mainwin->reply_quote_btn);
2960         gtk_widget_show(!quote ? mainwin->reply_btn : mainwin->reply_quote_btn);
2961         gtk_widget_hide(quote ? mainwin->replyall_btn : mainwin->replyall_quote_btn);
2962         gtk_widget_show(!quote ? mainwin->replyall_btn : mainwin->replyall_quote_btn);
2963         gtk_widget_hide(quote ? mainwin->replysender_btn : mainwin->replysender_quote_btn);
2964         gtk_widget_show(!quote ? mainwin->replysender_btn : mainwin->replysender_quote_btn);
2965 }
2966
2967 static void focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data)
2968 {
2969         MainWindow *mainwin = (MainWindow *)data;
2970         
2971         main_window_set_toolbar_reply_buttons(mainwin, FALSE);
2972
2973 }