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