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