Statistics
| Revision:

root / src / mainwindow.c @ 2164

History | View | Annotate | Download (123 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2009 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 <glib/gi18n.h>
24
#include <gdk/gdkkeysyms.h>
25
#include <gtk/gtkmain.h>
26
#include <gtk/gtkversion.h>
27
#include <gtk/gtkwindow.h>
28
#include <gtk/gtkwidget.h>
29
#include <gtk/gtksignal.h>
30
#include <gtk/gtkvbox.h>
31
#include <gtk/gtkcontainer.h>
32
#include <gtk/gtkstatusbar.h>
33
#include <gtk/gtkprogressbar.h>
34
#include <gtk/gtkhpaned.h>
35
#include <gtk/gtkvpaned.h>
36
#include <gtk/gtkcheckmenuitem.h>
37
#include <gtk/gtkitemfactory.h>
38
#include <gtk/gtkeditable.h>
39
#include <gtk/gtkmenu.h>
40
#include <gtk/gtkmenuitem.h>
41
#include <gtk/gtktoolbar.h>
42
#include <gtk/gtktoolitem.h>
43
#include <gtk/gtktoolbutton.h>
44
#include <gtk/gtkseparatortoolitem.h>
45
#include <gtk/gtkbutton.h>
46
#include <gtk/gtktooltips.h>
47
#include <gtk/gtkarrow.h>
48
#include <gtk/gtkstock.h>
49
#include <gtk/gtkimage.h>
50
#include <string.h>
51

    
52
#include "main.h"
53
#include "mainwindow.h"
54
#include "folderview.h"
55
#include "foldersel.h"
56
#include "summaryview.h"
57
#include "quick_search.h"
58
#include "query_search.h"
59
#include "messageview.h"
60
#include "mimeview.h"
61
#include "message_search.h"
62
#include "headerview.h"
63
#include "menu.h"
64
#include "stock_pixmap.h"
65
#include "folder.h"
66
#include "inc.h"
67
#include "rpop3.h"
68
#include "compose.h"
69
#include "procmsg.h"
70
#include "send_message.h"
71
#include "import.h"
72
#include "export.h"
73
#include "prefs_common.h"
74
#include "prefs_common_dialog.h"
75
#include "prefs_filter.h"
76
#include "prefs_actions.h"
77
#include "prefs_account.h"
78
#include "prefs_summary_column.h"
79
#include "prefs_template.h"
80
#include "prefs_search_folder.h"
81
#include "prefs_toolbar.h"
82
#include "plugin_manager.h"
83
#include "action.h"
84
#include "account.h"
85
#include "account_dialog.h"
86
#include "addressbook.h"
87
#include "logwindow.h"
88
#include "manage_window.h"
89
#include "alertpanel.h"
90
#include "statusbar.h"
91
#include "inputdialog.h"
92
#include "trayicon.h"
93
#include "printing.h"
94
#include "utils.h"
95
#include "gtkutils.h"
96
#include "codeconv.h"
97
#include "about.h"
98
#include "manual.h"
99
#include "update_check.h"
100
#include "version.h"
101

    
102
#define AC_LABEL_WIDTH        240
103

    
104
#define STATUSBAR_PUSH(mainwin, str) \
105
{ \
106
        gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
107
                           mainwin->mainwin_cid, str); \
108
        gtkut_widget_draw_now(mainwin->statusbar); \
109
}
110

    
111
#define STATUSBAR_POP(mainwin) \
112
{ \
113
        gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
114
                          mainwin->mainwin_cid); \
115
}
116

    
117
/* list of all instantiated MainWindow */
118
static GList *mainwin_list = NULL;
119

    
120
static GdkCursor *watch_cursor;
121

    
122
static void main_window_menu_callback_block        (MainWindow        *mainwin);
123
static void main_window_menu_callback_unblock        (MainWindow        *mainwin);
124

    
125
static void main_window_show_cur_account        (MainWindow        *mainwin);
126

    
127
static void main_window_set_toolbar_button_visibility
128
                                                (MainWindow        *mainwin);
129

    
130
static void main_window_set_widgets                (MainWindow        *mainwin,
131
                                                 LayoutType         layout,
132
                                                 SeparateType         type);
133
static GtkWidget *main_window_toolbar_create        (MainWindow        *mainwin);
134
static GtkWidget *main_window_toolbar_create_from_list
135
                                                (MainWindow        *mainwin,
136
                                                 GList                *item_list);
137
static void main_window_toolbar_toggle_menu_set_active
138
                                                (MainWindow        *mainwin,
139
                                                 ToolbarStyle         style);
140

    
141
/* callback functions */
142
static void toolbar_inc_cb                (GtkWidget        *widget,
143
                                         gpointer         data);
144
static void toolbar_inc_all_cb                (GtkWidget        *widget,
145
                                         gpointer         data);
146
static void toolbar_rpop3_cb                (GtkWidget        *widget,
147
                                         gpointer         data);
148
static void toolbar_send_cb                (GtkWidget        *widget,
149
                                         gpointer         data);
150

    
151
static void toolbar_compose_cb                (GtkWidget        *widget,
152
                                         gpointer         data);
153
static void toolbar_reply_cb                (GtkWidget        *widget,
154
                                         gpointer         data);
155
static void toolbar_reply_to_all_cb        (GtkWidget        *widget,
156
                                         gpointer         data);
157
static void toolbar_forward_cb                (GtkWidget        *widget,
158
                                         gpointer         data);
159

    
160
static void toolbar_delete_cb                (GtkWidget        *widget,
161
                                         gpointer         data);
162
static void toolbar_junk_cb                (GtkWidget        *widget,
163
                                         gpointer         data);
164
static void toolbar_notjunk_cb                (GtkWidget        *widget,
165
                                         gpointer         data);
166
static void toolbar_exec_cb                (GtkWidget        *widget,
167
                                         gpointer         data);
168

    
169
static void toolbar_next_unread_cb        (GtkWidget        *widget,
170
                                         gpointer         data);
171
static void toolbar_prev_unread_cb        (GtkWidget        *widget,
172
                                         gpointer         data);
173
static void toolbar_address_cb                (GtkWidget        *widget,
174
                                         gpointer         data);
175
static void toolbar_search_cb                (GtkWidget        *widget,
176
                                         gpointer         data);
177
static void toolbar_print_cb                (GtkWidget        *widget,
178
                                         gpointer         data);
179
static void toolbar_stop_cb                (GtkWidget        *widget,
180
                                         gpointer         data);
181
static void toolbar_prefs_common_cb        (GtkWidget        *widget,
182
                                         gpointer         data);
183
static void toolbar_prefs_account_cb        (GtkWidget        *widget,
184
                                         gpointer         data);
185

    
186
static gboolean toolbar_button_pressed        (GtkWidget        *widget,
187
                                         GdkEventButton        *event,
188
                                         gpointer         data);
189

    
190
static void online_switch_clicked                (GtkWidget        *widget,
191
                                                 gpointer         data);
192
static gboolean ac_label_button_pressed                (GtkWidget        *widget,
193
                                                 GdkEventButton        *event,
194
                                                 gpointer         data);
195
static void ac_menu_popup_closed                (GtkMenuShell        *menu_shell,
196
                                                 gpointer         data);
197

    
198
static gboolean main_window_key_pressed                (GtkWidget        *widget,
199
                                                 GdkEventKey        *event,
200
                                                 gpointer         data);
201

    
202
static gint main_window_close_cb                (GtkWidget        *widget,
203
                                                 GdkEventAny        *event,
204
                                                 gpointer         data);
205
static gint folder_window_close_cb                (GtkWidget        *widget,
206
                                                 GdkEventAny        *event,
207
                                                 gpointer         data);
208
static gint message_window_close_cb                (GtkWidget        *widget,
209
                                                 GdkEventAny        *event,
210
                                                 gpointer         data);
211

    
212
static void main_window_size_allocate_cb        (GtkWidget        *widget,
213
                                                 GtkAllocation        *allocation,
214
                                                 gpointer         data);
215
static void folder_window_size_allocate_cb        (GtkWidget        *widget,
216
                                                 GtkAllocation        *allocation,
217
                                                 gpointer         data);
218
static void message_window_size_allocate_cb        (GtkWidget        *widget,
219
                                                 GtkAllocation        *allocation,
220
                                                 gpointer         data);
221

    
222
static gboolean main_window_window_state_cb        (GtkWidget                *widget,
223
                                                 GdkEventWindowState        *event,
224
                                                 gpointer                 data);
225
static gboolean main_window_visibility_notify_cb(GtkWidget                *widget,
226
                                                 GdkEventVisibility        *event,
227
                                                 gpointer                 data);
228

    
229
static void new_folder_cb         (MainWindow        *mainwin,
230
                                  guint                 action,
231
                                  GtkWidget        *widget);
232
static void rename_folder_cb         (MainWindow        *mainwin,
233
                                  guint                 action,
234
                                  GtkWidget        *widget);
235
static void move_folder_cb         (MainWindow        *mainwin,
236
                                  guint                 action,
237
                                  GtkWidget        *widget);
238
static void delete_folder_cb         (MainWindow        *mainwin,
239
                                  guint                 action,
240
                                  GtkWidget        *widget);
241
static void update_folderview_cb (MainWindow        *mainwin,
242
                                  guint                 action,
243
                                  GtkWidget        *widget);
244

    
245
static void add_mailbox_cb         (MainWindow        *mainwin,
246
                                  guint                 action,
247
                                  GtkWidget        *widget);
248
static void remove_mailbox_cb         (MainWindow        *mainwin,
249
                                  guint                 action,
250
                                  GtkWidget        *widget);
251
static void rebuild_tree_cb         (MainWindow        *mainwin,
252
                                  guint                 action,
253
                                  GtkWidget        *widget);
254

    
255
static void import_mbox_cb         (MainWindow        *mainwin,
256
                                  guint                 action,
257
                                  GtkWidget        *widget);
258
static void export_mbox_cb         (MainWindow        *mainwin,
259
                                  guint                 action,
260
                                  GtkWidget        *widget);
261
static void empty_trash_cb         (MainWindow        *mainwin,
262
                                  guint                 action,
263
                                  GtkWidget        *widget);
264

    
265
static void save_as_cb                 (MainWindow        *mainwin,
266
                                  guint                 action,
267
                                  GtkWidget        *widget);
268
#if GTK_CHECK_VERSION(2, 10, 0)
269
static void page_setup_cb         (MainWindow        *mainwin,
270
                                  guint                 action,
271
                                  GtkWidget        *widget);
272
#endif
273
static void print_cb                 (MainWindow        *mainwin,
274
                                  guint                 action,
275
                                  GtkWidget        *widget);
276
static void toggle_offline_cb         (MainWindow        *mainwin,
277
                                  guint                 action,
278
                                  GtkWidget        *widget);
279
static void app_exit_cb                 (MainWindow        *mainwin,
280
                                  guint                 action,
281
                                  GtkWidget        *widget);
282

    
283
static void search_cb                 (MainWindow        *mainwin,
284
                                  guint                 action,
285
                                  GtkWidget        *widget);
286

    
287
static void toggle_folder_cb         (MainWindow        *mainwin,
288
                                  guint                 action,
289
                                  GtkWidget        *widget);
290
static void toggle_message_cb         (MainWindow        *mainwin,
291
                                  guint                 action,
292
                                  GtkWidget        *widget);
293
static void toggle_toolbar_cb         (MainWindow        *mainwin,
294
                                  guint                 action,
295
                                  GtkWidget        *widget);
296
static void toggle_searchbar_cb         (MainWindow        *mainwin,
297
                                  guint                 action,
298
                                  GtkWidget        *widget);
299
static void toggle_statusbar_cb         (MainWindow        *mainwin,
300
                                  guint                 action,
301
                                  GtkWidget        *widget);
302
static void toolbar_customize_cb (MainWindow        *mainwin,
303
                                  guint                 action,
304
                                  GtkWidget        *widget);
305
static void change_layout_cb         (MainWindow        *mainwin,
306
                                  guint                 action,
307
                                  GtkWidget        *widget);
308
static void separate_widget_cb         (MainWindow        *mainwin,
309
                                  guint                 action,
310
                                  GtkWidget        *widget);
311

    
312
static void addressbook_open_cb        (MainWindow        *mainwin,
313
                                 guint                 action,
314
                                 GtkWidget        *widget);
315
static void log_window_show_cb        (MainWindow        *mainwin,
316
                                 guint                 action,
317
                                 GtkWidget        *widget);
318

    
319
static void inc_mail_cb                        (MainWindow        *mainwin,
320
                                         guint                 action,
321
                                         GtkWidget        *widget);
322
static void inc_all_account_mail_cb        (MainWindow        *mainwin,
323
                                         guint                 action,
324
                                         GtkWidget        *widget);
325
static void inc_stop_cb                        (MainWindow        *mainwin,
326
                                         guint                 action,
327
                                         GtkWidget        *widget);
328

    
329
static void rpop3_cb                        (MainWindow        *mainwin,
330
                                         guint                 action,
331
                                         GtkWidget        *widget);
332

    
333
static void send_queue_cb                (MainWindow        *mainwin,
334
                                         guint                 action,
335
                                         GtkWidget        *widget);
336

    
337
static void compose_cb                        (MainWindow        *mainwin,
338
                                         guint                 action,
339
                                         GtkWidget        *widget);
340
static void reply_cb                        (MainWindow        *mainwin,
341
                                         guint                 action,
342
                                         GtkWidget        *widget);
343

    
344
static void open_msg_cb                        (MainWindow        *mainwin,
345
                                         guint                 action,
346
                                         GtkWidget        *widget);
347

    
348
static void view_source_cb                (MainWindow        *mainwin,
349
                                         guint                 action,
350
                                         GtkWidget        *widget);
351

    
352
static void show_all_header_cb                (MainWindow        *mainwin,
353
                                         guint                 action,
354
                                         GtkWidget        *widget);
355

    
356
static void move_to_cb                        (MainWindow        *mainwin,
357
                                         guint                 action,
358
                                         GtkWidget        *widget);
359
static void copy_to_cb                        (MainWindow        *mainwin,
360
                                         guint                 action,
361
                                         GtkWidget        *widget);
362
static void delete_cb                        (MainWindow        *mainwin,
363
                                         guint                 action,
364
                                         GtkWidget        *widget);
365

    
366
static void mark_cb                        (MainWindow        *mainwin,
367
                                         guint                 action,
368
                                         GtkWidget        *widget);
369
static void unmark_cb                        (MainWindow        *mainwin,
370
                                         guint                 action,
371
                                         GtkWidget        *widget);
372

    
373
static void mark_as_unread_cb                (MainWindow        *mainwin,
374
                                         guint                 action,
375
                                         GtkWidget        *widget);
376
static void mark_as_read_cb                (MainWindow        *mainwin,
377
                                         guint                 action,
378
                                         GtkWidget        *widget);
379
static void mark_thread_as_read_cb        (MainWindow        *mainwin,
380
                                         guint                 action,
381
                                         GtkWidget        *widget);
382
static void mark_all_read_cb                (MainWindow        *mainwin,
383
                                         guint                 action,
384
                                         GtkWidget        *widget);
385

    
386
static void junk_cb                        (MainWindow        *mainwin,
387
                                         guint                 action,
388
                                         GtkWidget        *widget);
389

    
390
static void reedit_cb                        (MainWindow        *mainwin,
391
                                         guint                 action,
392
                                         GtkWidget        *widget);
393

    
394
static void add_address_cb                (MainWindow        *mainwin,
395
                                         guint                 action,
396
                                         GtkWidget        *widget);
397

    
398
static void set_charset_cb                (MainWindow        *mainwin,
399
                                         guint                 action,
400
                                         GtkWidget        *widget);
401

    
402
static void thread_cb                 (MainWindow        *mainwin,
403
                                  guint                 action,
404
                                  GtkWidget        *widget);
405
static void expand_threads_cb         (MainWindow        *mainwin,
406
                                  guint                 action,
407
                                  GtkWidget        *widget);
408
static void collapse_threads_cb         (MainWindow        *mainwin,
409
                                  guint                 action,
410
                                  GtkWidget        *widget);
411

    
412
static void set_display_item_cb         (MainWindow        *mainwin,
413
                                  guint                 action,
414
                                  GtkWidget        *widget);
415
static void sort_summary_cb         (MainWindow        *mainwin,
416
                                  guint                 action,
417
                                  GtkWidget        *widget);
418
static void sort_summary_type_cb (MainWindow        *mainwin,
419
                                  guint                 action,
420
                                  GtkWidget        *widget);
421
static void attract_by_subject_cb(MainWindow        *mainwin,
422
                                  guint                 action,
423
                                  GtkWidget        *widget);
424

    
425
static void delete_duplicated_cb (MainWindow        *mainwin,
426
                                  guint                 action,
427
                                  GtkWidget        *widget);
428
static void filter_cb                 (MainWindow        *mainwin,
429
                                  guint                 action,
430
                                  GtkWidget        *widget);
431
static void filter_junk_cb         (MainWindow        *mainwin,
432
                                  guint                 action,
433
                                  GtkWidget        *widget);
434
static void execute_summary_cb         (MainWindow        *mainwin,
435
                                  guint                 action,
436
                                  GtkWidget        *widget);
437
static void update_summary_cb         (MainWindow        *mainwin,
438
                                  guint                 action,
439
                                  GtkWidget        *widget);
440

    
441
static void prev_cb                 (MainWindow        *mainwin,
442
                                  guint                 action,
443
                                  GtkWidget        *widget);
444
static void next_cb                 (MainWindow        *mainwin,
445
                                  guint                 action,
446
                                  GtkWidget        *widget);
447

    
448
static void prev_unread_cb         (MainWindow        *mainwin,
449
                                  guint                 action,
450
                                  GtkWidget        *widget);
451
static void next_unread_cb         (MainWindow        *mainwin,
452
                                  guint                 action,
453
                                  GtkWidget        *widget);
454
static void prev_new_cb                 (MainWindow        *mainwin,
455
                                  guint                 action,
456
                                  GtkWidget        *widget);
457
static void next_new_cb                 (MainWindow        *mainwin,
458
                                  guint                 action,
459
                                  GtkWidget        *widget);
460
static void prev_marked_cb         (MainWindow        *mainwin,
461
                                  guint                 action,
462
                                  GtkWidget        *widget);
463
static void next_marked_cb         (MainWindow        *mainwin,
464
                                  guint                 action,
465
                                  GtkWidget        *widget);
466
static void prev_labeled_cb         (MainWindow        *mainwin,
467
                                  guint                 action,
468
                                  GtkWidget        *widget);
469
static void next_labeled_cb         (MainWindow        *mainwin,
470
                                  guint                 action,
471
                                  GtkWidget        *widget);
472

    
473
static void goto_folder_cb         (MainWindow        *mainwin,
474
                                  guint                 action,
475
                                  GtkWidget        *widget);
476

    
477
static void copy_cb                 (MainWindow        *mainwin,
478
                                  guint                 action,
479
                                  GtkWidget        *widget);
480
static void allsel_cb                 (MainWindow        *mainwin,
481
                                  guint                 action,
482
                                  GtkWidget        *widget);
483
static void select_thread_cb         (MainWindow        *mainwin,
484
                                  guint                 action,
485
                                  GtkWidget        *widget);
486

    
487
static void create_filter_cb         (MainWindow        *mainwin,
488
                                  guint                 action,
489
                                  GtkWidget        *widget);
490

    
491
static void prefs_common_open_cb        (MainWindow        *mainwin,
492
                                         guint                 action,
493
                                         GtkWidget        *widget);
494
static void prefs_filter_open_cb        (MainWindow        *mainwin,
495
                                         guint                 action,
496
                                         GtkWidget        *widget);
497
static void prefs_template_open_cb        (MainWindow        *mainwin,
498
                                         guint                 action,
499
                                         GtkWidget        *widget);
500
static void plugin_manager_open_cb        (MainWindow        *mainwin,
501
                                         guint                 action,
502
                                         GtkWidget        *widget);
503
#ifndef G_OS_WIN32
504
static void prefs_actions_open_cb        (MainWindow        *mainwin,
505
                                         guint                 action,
506
                                         GtkWidget        *widget);
507
#endif
508
static void prefs_account_open_cb        (MainWindow        *mainwin,
509
                                         guint                 action,
510
                                         GtkWidget        *widget);
511

    
512
static void new_account_cb         (MainWindow        *mainwin,
513
                                  guint                 action,
514
                                  GtkWidget        *widget);
515

    
516
static void account_selector_menu_cb         (GtkMenuItem        *menuitem,
517
                                          gpointer         data);
518
static void account_receive_menu_cb         (GtkMenuItem        *menuitem,
519
                                          gpointer         data);
520

    
521
static void manual_open_cb         (MainWindow        *mainwin,
522
                                  guint                 action,
523
                                  GtkWidget        *widget);
524
static void faq_open_cb                 (MainWindow        *mainwin,
525
                                  guint                 action,
526
                                  GtkWidget        *widget);
527
static void help_cmdline_cb         (MainWindow        *mainwin,
528
                                  guint                 action,
529
                                  GtkWidget        *widget);
530
static void update_check_cb         (MainWindow        *mainwin,
531
                                  guint                 action,
532
                                  GtkWidget        *widget);
533

    
534
static void scan_tree_func         (Folder        *folder,
535
                                  FolderItem        *item,
536
                                  gpointer         data);
537

    
538
static GtkItemFactoryEntry mainwin_entries[] =
539
{
540
        {N_("/_File"),                                NULL, NULL, 0, "<Branch>"},
541
        {N_("/_File/_Folder"),                        NULL, NULL, 0, "<Branch>"},
542
        {N_("/_File/_Folder/Create _new folder..."),
543
                                                NULL, new_folder_cb, 0, NULL},
544
        {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
545
        {N_("/_File/_Folder/_Move folder..."),  NULL, move_folder_cb, 0, NULL},
546
        {N_("/_File/_Folder/_Delete folder"),        NULL, delete_folder_cb, 0, NULL},
547
        {N_("/_File/_Mailbox"),                        NULL, NULL, 0, "<Branch>"},
548
        {N_("/_File/_Mailbox/Add _mailbox..."),        NULL, add_mailbox_cb, 0, NULL},
549
        {N_("/_File/_Mailbox/_Remove mailbox"),        NULL, remove_mailbox_cb, 0, NULL},
550
        {N_("/_File/_Mailbox/---"),                NULL, NULL, 0, "<Separator>"},
551
        {N_("/_File/_Mailbox/_Check for new messages"),
552
                                                NULL, update_folderview_cb, 0, NULL},
553
        {N_("/_File/_Mailbox/Check for new messages in _all mailboxes"),
554
                                                NULL, update_folderview_cb, 1, NULL},
555
        {N_("/_File/_Mailbox/---"),                NULL, NULL, 0, "<Separator>"},
556
        {N_("/_File/_Mailbox/R_ebuild folder tree"),
557
                                                NULL, rebuild_tree_cb, 0, NULL},
558
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
559
        {N_("/_File/_Import mbox file..."),        NULL, import_mbox_cb, 0, NULL},
560
        {N_("/_File/_Export to mbox file..."),        NULL, export_mbox_cb, 0, NULL},
561
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
562
        {N_("/_File/Empty all _trash"),                NULL, empty_trash_cb, 0, NULL},
563
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
564
        {N_("/_File/_Save as..."),                "<control>S", save_as_cb, 0, NULL},
565
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
566
#if GTK_CHECK_VERSION(2, 10, 0)
567
        {N_("/_File/Page set_up..."),                NULL, page_setup_cb, 0, NULL},
568
#endif
569
        {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
570
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
571
        {N_("/_File/_Work offline"),                NULL, toggle_offline_cb, 0, "<ToggleItem>"},
572
        {N_("/_File/---"),                        NULL, NULL, 0, "<Separator>"},
573
        /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
574
        {N_("/_File/E_xit"),                        "<control>Q", app_exit_cb, 0, NULL},
575

    
576
        {N_("/_Edit"),                                NULL, NULL, 0, "<Branch>"},
577
        {N_("/_Edit/_Copy"),                        "<control>C", copy_cb, 0, NULL},
578
        {N_("/_Edit/Select _all"),                "<control>A", allsel_cb, 0, NULL},
579
        {N_("/_Edit/Select _thread"),                NULL, select_thread_cb, 0, NULL},
580
        {N_("/_Edit/---"),                        NULL, NULL, 0, "<Separator>"},
581
        {N_("/_Edit/_Find in current message..."),
582
                                                "<control>F", search_cb, 0, NULL},
583
        {N_("/_Edit/_Search messages..."),        "<shift><control>F", search_cb, 1, NULL},
584
        {N_("/_Edit/_Quick search"),                "<shift><control>S", search_cb, 2, NULL},
585

    
586
        {N_("/_View"),                                NULL, NULL, 0, "<Branch>"},
587
        {N_("/_View/Show or hi_de"),                NULL, NULL, 0, "<Branch>"},
588
        {N_("/_View/Show or hi_de/_Folder tree"),
589
                                                NULL, toggle_folder_cb, 0, "<ToggleItem>"},
590
        {N_("/_View/Show or hi_de/_Message view"),
591
                                                "V", toggle_message_cb, 0, "<ToggleItem>"},
592
        {N_("/_View/Show or hi_de/_Toolbar"),
593
                                                NULL, NULL, 0, "<Branch>"},
594
        {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
595
                                                NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
596
        {N_("/_View/Show or hi_de/_Toolbar/Text at the _right of icon"),
597
                                                NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Icon and text"},
598
        {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
599
                                                NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
600
        {N_("/_View/Show or hi_de/_Toolbar/_Text"),
601
                                                NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
602
        {N_("/_View/Show or hi_de/_Toolbar/_None"),
603
                                                NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
604
        {N_("/_View/Show or hi_de/_Search bar"),
605
                                                NULL, toggle_searchbar_cb, 0, "<ToggleItem>"},
606
        {N_("/_View/Show or hi_de/Status _bar"),
607
                                                NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
608
        {N_("/_View/_Customize toolbar..."),        NULL, toolbar_customize_cb, 0, NULL},
609
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
610
        {N_("/_View/Layou_t"),                        NULL, NULL, 0, "<Branch>"},
611
        {N_("/_View/Layou_t/_Normal"),                NULL, change_layout_cb, LAYOUT_NORMAL, "<RadioItem>"},
612
        {N_("/_View/Layou_t/_Vertical"),        NULL, change_layout_cb, LAYOUT_VERTICAL, "/View/Layout/Normal"},
613
        {N_("/_View/Separate f_older tree"),        NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
614
        {N_("/_View/Separate _message view"),        NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
615
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
616
        {N_("/_View/_Sort"),                        NULL, NULL, 0, "<Branch>"},
617
        {N_("/_View/_Sort/by _number"),                NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
618
        {N_("/_View/_Sort/by s_ize"),                NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
619
        {N_("/_View/_Sort/by _date"),                NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
620
        {N_("/_View/_Sort/by t_hread date"),        NULL, sort_summary_cb, SORT_BY_TDATE, "/View/Sort/by number"},
621
        {N_("/_View/_Sort/by _from"),                NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
622
        {N_("/_View/_Sort/by _recipient"),        NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
623
        {N_("/_View/_Sort/by _subject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
624
        {N_("/_View/_Sort/by _color label"),
625
                                                NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
626
        {N_("/_View/_Sort/by _mark"),                NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
627
        {N_("/_View/_Sort/by _unread"),                NULL, sort_summary_cb, SORT_BY_UNREAD, "/View/Sort/by number"},
628
        {N_("/_View/_Sort/by a_ttachment"),
629
                                                NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
630
        {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
631
        {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
632
        {N_("/_View/_Sort/Ascending"),                NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
633
        {N_("/_View/_Sort/Descending"),                NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
634
        {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
635
        {N_("/_View/_Sort/_Attract by subject"),
636
                                                NULL, attract_by_subject_cb, 0, NULL},
637
        {N_("/_View/Th_read view"),                "<control>T", thread_cb, 0, "<ToggleItem>"},
638
        {N_("/_View/E_xpand all threads"),        NULL, expand_threads_cb, 0, NULL},
639
        {N_("/_View/Co_llapse all threads"),        NULL, collapse_threads_cb, 0, NULL},
640
        {N_("/_View/Set display _item..."),        NULL, set_display_item_cb, 0, NULL},
641

    
642
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
643
        {N_("/_View/_Go to"),                        NULL, NULL, 0, "<Branch>"},
644
        {N_("/_View/_Go to/_Prev message"),        "P", prev_cb, 0, NULL},
645
        {N_("/_View/_Go to/_Next message"),        "N", next_cb, 0, NULL},
646
        {N_("/_View/_Go to/---"),                NULL, NULL, 0, "<Separator>"},
647
        {N_("/_View/_Go to/P_rev unread message"),
648
                                                "<shift>P", prev_unread_cb, 0, NULL},
649
        {N_("/_View/_Go to/N_ext unread message"),
650
                                                "<shift>N", next_unread_cb, 0, NULL},
651
        {N_("/_View/_Go to/---"),                NULL, NULL, 0, "<Separator>"},
652
        {N_("/_View/_Go to/Prev ne_w message"),        NULL, prev_new_cb, 0, NULL},
653
        {N_("/_View/_Go to/Ne_xt new message"),        NULL, next_new_cb, 0, NULL},
654
        {N_("/_View/_Go to/---"),                NULL, NULL, 0, "<Separator>"},
655
        {N_("/_View/_Go to/Prev _marked message"),
656
                                                NULL, prev_marked_cb, 0, NULL},
657
        {N_("/_View/_Go to/Next m_arked message"),
658
                                                NULL, next_marked_cb, 0, NULL},
659
        {N_("/_View/_Go to/---"),                NULL, NULL, 0, "<Separator>"},
660
        {N_("/_View/_Go to/Prev _labeled message"),
661
                                                NULL, prev_labeled_cb, 0, NULL},
662
        {N_("/_View/_Go to/Next la_beled message"),
663
                                                NULL, next_labeled_cb, 0, NULL},
664
        {N_("/_View/_Go to/---"),                NULL, NULL, 0, "<Separator>"},
665
        {N_("/_View/_Go to/Other _folder..."),        "G", goto_folder_cb, 0, NULL},
666
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
667

    
668
#define ENC_SEPARATOR \
669
        {N_("/_View/Character _encoding/---"),                NULL, NULL, 0, "<Separator>"}
670
#define ENC_ACTION(action) \
671
         NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
672

    
673
        {N_("/_View/Character _encoding"),                NULL, NULL, 0, "<Branch>"},
674
        {N_("/_View/Character _encoding/_Auto detect"),
675
         NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
676
        {N_("/_View/Character _encoding/---"),                NULL, NULL, 0, "<Separator>"},
677
        {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
678
         ENC_ACTION(C_US_ASCII)},
679
        {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
680
         ENC_ACTION(C_UTF_8)},
681
        ENC_SEPARATOR,
682

    
683
        {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
684
         ENC_ACTION(C_ISO_8859_1)},
685
        {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
686
         ENC_ACTION(C_ISO_8859_15)},
687
        {N_("/_View/Character _encoding/Western European (Windows-1252)"),
688
         ENC_ACTION(C_WINDOWS_1252)},
689
        ENC_SEPARATOR,
690

    
691
        {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
692
         ENC_ACTION(C_ISO_8859_2)},
693
        ENC_SEPARATOR,
694

    
695
        {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
696
         ENC_ACTION(C_ISO_8859_13)},
697
        {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
698
         ENC_ACTION(C_ISO_8859_4)},
699
        {N_("/_View/Character _encoding/Baltic (Windows-1257)"),
700
         ENC_ACTION(C_WINDOWS_1257)},
701
        ENC_SEPARATOR,
702

    
703
        {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
704
         ENC_ACTION(C_ISO_8859_7)},
705
        ENC_SEPARATOR,
706

    
707
        {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
708
         ENC_ACTION(C_ISO_8859_6)},
709
        {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
710
         ENC_ACTION(C_CP1256)},
711
        ENC_SEPARATOR,
712

    
713
        {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
714
         ENC_ACTION(C_ISO_8859_8)},
715
        {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
716
         ENC_ACTION(C_CP1255)},
717
        ENC_SEPARATOR,
718

    
719
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
720
         ENC_ACTION(C_ISO_8859_9)},
721
        ENC_SEPARATOR,
722

    
723
        {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
724
         ENC_ACTION(C_ISO_8859_5)},
725
        {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
726
         ENC_ACTION(C_KOI8_R)},
727
        {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
728
         ENC_ACTION(C_KOI8_U)},
729
        {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
730
         ENC_ACTION(C_CP1251)},
731
        ENC_SEPARATOR,
732

    
733
        {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
734
         ENC_ACTION(C_ISO_2022_JP)},
735
        {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
736
         ENC_ACTION(C_ISO_2022_JP_2)},
737
        {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
738
         ENC_ACTION(C_EUC_JP)},
739
        {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
740
         ENC_ACTION(C_SHIFT_JIS)},
741
        ENC_SEPARATOR,
742

    
743
        {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
744
         ENC_ACTION(C_GB2312)},
745
        {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
746
         ENC_ACTION(C_GBK)},
747
        {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
748
         ENC_ACTION(C_BIG5)},
749
        {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
750
         ENC_ACTION(C_EUC_TW)},
751
        {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
752
         ENC_ACTION(C_ISO_2022_CN)},
753
        ENC_SEPARATOR,
754

    
755
        {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
756
         ENC_ACTION(C_EUC_KR)},
757
        {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
758
         ENC_ACTION(C_ISO_2022_KR)},
759
        ENC_SEPARATOR,
760

    
761
        {N_("/_View/Character _encoding/Thai (TIS-620)"),
762
         ENC_ACTION(C_TIS_620)},
763
        {N_("/_View/Character _encoding/Thai (Windows-874)"),
764
         ENC_ACTION(C_WINDOWS_874)},
765

    
766
#undef CODESET_SEPARATOR
767
#undef CODESET_ACTION
768

    
769
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
770
        {N_("/_View/Open in new _window"),        "<control><alt>N", open_msg_cb, 0, NULL},
771
        {N_("/_View/Mess_age source"),                "<control>U", view_source_cb, 0, NULL},
772
        {N_("/_View/All _headers"),        "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
773
        {N_("/_View/---"),                        NULL, NULL, 0, "<Separator>"},
774
        {N_("/_View/_Update summary"),                "<control><alt>U", update_summary_cb,  0, NULL},
775

    
776
        {N_("/_Message"),                        NULL, NULL, 0, "<Branch>"},
777
        {N_("/_Message/Recei_ve"),                NULL, NULL, 0, "<Branch>"},
778
        {N_("/_Message/Recei_ve/Get from _current account"),
779
                                                "<control>I",        inc_mail_cb, 0, NULL},
780
        {N_("/_Message/Recei_ve/Get from _all accounts"),
781
                                                "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
782
        {N_("/_Message/Recei_ve/Stop receivin_g"),
783
                                                NULL, inc_stop_cb, 0, NULL},
784
        {N_("/_Message/Recei_ve/_Remote mailbox..."),
785
                                                NULL, rpop3_cb, 0, NULL},
786
        {N_("/_Message/Recei_ve/---"),                NULL, NULL, 0, "<Separator>"},
787
        {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
788
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
789
        {N_("/_Message/Compose _new message"),        "<control>M",        compose_cb, 0, NULL},
790
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
791
        {N_("/_Message/_Reply"),                "<control>R",         reply_cb, COMPOSE_REPLY, NULL},
792
        {N_("/_Message/Repl_y to"),                NULL, NULL, 0, "<Branch>"},
793
        {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
794
        {N_("/_Message/Repl_y to/_sender"),        NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
795
        {N_("/_Message/Repl_y to/mailing _list"),
796
                                                "<control>L", reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
797
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
798
        {N_("/_Message/_Forward"),                "<control><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
799
        {N_("/_Message/For_ward as attachment"),
800
                                                "<shift><control><alt>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
801
        {N_("/_Message/Redirec_t"),                NULL, reply_cb, COMPOSE_REDIRECT, NULL},
802
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
803
        {N_("/_Message/M_ove..."),                "<control>O", move_to_cb, 0, NULL},
804
        {N_("/_Message/_Copy..."),                "<shift><control>O", copy_to_cb, 0, NULL},
805
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
806
        {N_("/_Message/_Mark"),                        NULL, NULL, 0, "<Branch>"},
807
        {N_("/_Message/_Mark/_Mark"),                "<shift>asterisk", mark_cb, 0, NULL},
808
        {N_("/_Message/_Mark/_Unmark"),                "U", unmark_cb, 0, NULL},
809
        {N_("/_Message/_Mark/---"),                NULL, NULL, 0, "<Separator>"},
810
        {N_("/_Message/_Mark/Mark as unr_ead"),        "<shift>exclam", mark_as_unread_cb, 0, NULL},
811
        {N_("/_Message/_Mark/Mark as rea_d"),
812
                                                NULL, mark_as_read_cb, 0, NULL},
813
        {N_("/_Message/_Mark/Mark _thread as read"),
814
                                                NULL, mark_thread_as_read_cb, 0, NULL},
815
        {N_("/_Message/_Mark/Mark all _read"),        NULL, mark_all_read_cb, 0, NULL},
816
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
817
        {N_("/_Message/_Delete"),                "<control>D", delete_cb, 0, NULL},
818
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
819
        {N_("/_Message/Set as _junk mail"),        "<control>J", junk_cb, 0, NULL},
820
        {N_("/_Message/Set as not j_unk mail"),        "<shift><control>J", junk_cb, 1, NULL},
821
        {N_("/_Message/---"),                        NULL, NULL, 0, "<Separator>"},
822
        {N_("/_Message/Re-_edit"),                NULL, reedit_cb, 0, NULL},
823

    
824
        {N_("/_Tools"),                                NULL, NULL, 0, "<Branch>"},
825
        {N_("/_Tools/_Address book"),                "<shift><control>A", addressbook_open_cb, 0, NULL},
826
        {N_("/_Tools/Add sender to address boo_k..."),
827
                                                NULL, add_address_cb, 0, NULL},
828
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
829
        {N_("/_Tools/_Filter all messages in folder"),
830
                                                NULL, filter_cb, 0, NULL},
831
        {N_("/_Tools/Filter _selected messages"),
832
                                                NULL, filter_cb, 1, NULL},
833
        {N_("/_Tools/_Create filter rule"),        NULL, NULL, 0, "<Branch>"},
834
        {N_("/_Tools/_Create filter rule/_Automatically"),
835
                                                NULL, create_filter_cb, FLT_BY_AUTO, NULL},
836
        {N_("/_Tools/_Create filter rule/by _From"),
837
                                                NULL, create_filter_cb, FLT_BY_FROM, NULL},
838
        {N_("/_Tools/_Create filter rule/by _To"),
839
                                                NULL, create_filter_cb, FLT_BY_TO, NULL},
840
        {N_("/_Tools/_Create filter rule/by _Subject"),
841
                                                NULL, create_filter_cb, FLT_BY_SUBJECT, NULL},
842
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
843
        {N_("/_Tools/Filter _junk mails in folder"),
844
                                                NULL, filter_junk_cb, 0, NULL},
845
        {N_("/_Tools/Filter junk _mails in selected messages"),
846
                                                NULL, filter_junk_cb, 1, NULL},
847
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
848
#ifndef G_OS_WIN32
849
        {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
850
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
851
#endif
852
        {N_("/_Tools/Delete du_plicated messages"),
853
                                                NULL, delete_duplicated_cb,   0, NULL},
854
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
855
        {N_("/_Tools/E_xecute marked process"),        "X", execute_summary_cb, 0, NULL},
856
        {N_("/_Tools/---"),                        NULL, NULL, 0, "<Separator>"},
857
        {N_("/_Tools/_Log window"),                "<shift><control>L", log_window_show_cb, 0, NULL},
858

    
859
        {N_("/_Configuration"),                        NULL, NULL, 0, "<Branch>"},
860
        {N_("/_Configuration/_Common preferences..."),
861
                                                NULL, prefs_common_open_cb, 0, NULL},
862
        {N_("/_Configuration/_Filter settings..."),
863
                                                NULL, prefs_filter_open_cb, 0, NULL},
864
        {N_("/_Configuration/_Template..."),        NULL, prefs_template_open_cb, 0, NULL},
865
#ifndef G_OS_WIN32
866
        {N_("/_Configuration/_Actions..."),        NULL, prefs_actions_open_cb, 0, NULL},
867
#endif
868
        {N_("/_Configuration/Plug-in _manager..."),
869
                                                NULL, plugin_manager_open_cb, 0, NULL},
870
        {N_("/_Configuration/---"),                NULL, NULL, 0, "<Separator>"},
871
        {N_("/_Configuration/_Preferences for current account..."),
872
                                                NULL, prefs_account_open_cb, 0, NULL},
873
        {N_("/_Configuration/Create _new account..."),
874
                                                NULL, new_account_cb, 0, NULL},
875
        {N_("/_Configuration/_Edit accounts..."),
876
                                                NULL, account_edit_open, 0, NULL},
877
        {N_("/_Configuration/C_hange current account"),
878
                                                NULL, NULL, 0, "<Branch>"},
879

    
880
        {N_("/_Help"),                                NULL, NULL, 0, "<Branch>"},
881
        {N_("/_Help/_Manual"),                        NULL, NULL, 0, "<Branch>"},
882
        {N_("/_Help/_Manual/_English"),                NULL, manual_open_cb, MANUAL_LANG_EN, NULL},
883
        {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
884
        {N_("/_Help/_FAQ"),                        NULL, NULL, 0, "<Branch>"},
885
        {N_("/_Help/_FAQ/_English"),                NULL, faq_open_cb, MANUAL_LANG_EN, NULL},
886
        {N_("/_Help/_FAQ/_German"),                NULL, faq_open_cb, MANUAL_LANG_DE, NULL},
887
        {N_("/_Help/_FAQ/_Spanish"),                NULL, faq_open_cb, MANUAL_LANG_ES, NULL},
888
        {N_("/_Help/_FAQ/_French"),                NULL, faq_open_cb, MANUAL_LANG_FR, NULL},
889
        {N_("/_Help/_FAQ/_Italian"),                NULL, faq_open_cb, MANUAL_LANG_IT, NULL},
890
        {N_("/_Help/_Command line options"),        NULL, help_cmdline_cb, 0, NULL},
891
        {N_("/_Help/---"),                        NULL, NULL, 0, "<Separator>"},
892
        {N_("/_Help/_Update check..."),                NULL, update_check_cb, 0, NULL},
893
        {N_("/_Help/---"),                        NULL, NULL, 0, "<Separator>"},
894
        {N_("/_Help/_About"),                        NULL, about_show, 0, NULL}
895
};
896

    
897
MainWindow *main_window_create(SeparateType type)
898
{
899
        MainWindow *mainwin;
900
        GtkWidget *window;
901
        GtkWidget *vbox;
902
        GtkWidget *menubar;
903
        GtkWidget *toolbar;
904
        GtkWidget *hbox_spc;
905
        GtkWidget *vbox_body;
906
        GtkWidget *statusbar;
907
        GtkWidget *progressbar;
908
        GtkWidget *statuslabel;
909
        GtkWidget *online_hbox;
910
        GtkWidget *online_switch;
911
        GtkWidget *online_pixmap;
912
        GtkWidget *offline_pixmap;
913
        GtkTooltips *online_tip;
914
#if !GTK_CHECK_VERSION(2, 6, 0)
915
        GtkWidget *spacer_hbox;
916
#endif
917
        GtkWidget *ac_button;
918
        GtkWidget *ac_label;
919

    
920
        TrayIcon *tray_icon;
921

    
922
        FolderView *folderview;
923
        SummaryView *summaryview;
924
        MessageView *messageview;
925
        GdkColormap *colormap;
926
        GdkColor color[3];
927
        gboolean success[3];
928
        guint n_menu_entries;
929
        GtkItemFactory *ifactory;
930
        GtkWidget *ac_menu;
931
        GtkWidget *menuitem;
932
        gint i;
933

    
934
        static GdkGeometry geometry;
935

    
936
        debug_print(_("Creating main window...\n"));
937
        mainwin = g_new0(MainWindow, 1);
938

    
939
        /* main window */
940
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
941
        gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
942
        gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
943
        gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
944
        gtk_widget_add_events(window, GDK_VISIBILITY_NOTIFY_MASK);
945
        g_signal_connect(G_OBJECT(window), "key_press_event",
946
                         G_CALLBACK(main_window_key_pressed), mainwin);
947

    
948
        if (!geometry.min_height) {
949
                geometry.min_width = 320;
950
                geometry.min_height = 200;
951
        }
952
        gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
953
                                      GDK_HINT_MIN_SIZE);
954

    
955
        g_signal_connect(G_OBJECT(window), "delete_event",
956
                         G_CALLBACK(main_window_close_cb), mainwin);
957
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
958
        gtk_widget_realize(window);
959

    
960
        vbox = gtk_vbox_new(FALSE, 0);
961
        gtk_widget_show(vbox);
962
        gtk_container_add(GTK_CONTAINER(window), vbox);
963

    
964
        /* menu bar */
965
        n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
966
        menubar = menubar_create(window, mainwin_entries, 
967
                                 n_menu_entries, "<Main>", mainwin);
968
        gtk_widget_show(menubar);
969
        gtk_widget_set_size_request(menubar, 300, -1);
970
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
971
        ifactory = gtk_item_factory_from_widget(menubar);
972

    
973
        toolbar = main_window_toolbar_create(mainwin);
974
        gtk_widget_set_size_request(toolbar, 300, -1);
975
        gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
976

    
977
        hbox_spc = gtk_hbox_new(FALSE, 0);
978
        gtk_widget_show(hbox_spc);
979
        gtk_widget_set_size_request(hbox_spc, -1, BORDER_WIDTH);
980
        gtk_box_pack_start(GTK_BOX(vbox), hbox_spc, FALSE, FALSE, 0);
981

    
982
        /* vbox that contains body */
983
        vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
984
        gtk_widget_show(vbox_body);
985
        gtk_container_set_border_width(GTK_CONTAINER(vbox_body), 0);
986
        gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
987

    
988
        statusbar = statusbar_create();
989
        gtk_box_pack_end(GTK_BOX(vbox_body), statusbar, FALSE, FALSE, 0);
990

    
991
        progressbar = gtk_progress_bar_new();
992
        gtk_widget_set_size_request(progressbar, 120, 1);
993
        gtk_box_pack_start(GTK_BOX(statusbar), progressbar, FALSE, FALSE, 0);
994

    
995
        statuslabel = gtk_label_new("");
996
        gtk_box_pack_start(GTK_BOX(statusbar), statuslabel, FALSE, FALSE, 0);
997

    
998
        online_hbox = gtk_hbox_new(FALSE, 0);
999

    
1000
        online_pixmap = stock_pixbuf_widget(statusbar, STOCK_PIXMAP_ONLINE);
1001
        offline_pixmap = stock_pixbuf_widget(statusbar, STOCK_PIXMAP_OFFLINE);
1002
        gtk_box_pack_start(GTK_BOX(online_hbox), online_pixmap,
1003
                           FALSE, FALSE, 0);
1004
        gtk_box_pack_start(GTK_BOX(online_hbox), offline_pixmap,
1005
                           FALSE, FALSE, 0);
1006

    
1007
        online_switch = gtk_button_new();
1008
        gtk_button_set_relief(GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1009
        GTK_WIDGET_UNSET_FLAGS(online_switch, GTK_CAN_FOCUS);
1010
#ifdef G_OS_WIN32
1011
        gtk_widget_set_size_request(online_switch, 34, 20);
1012
#else
1013
        gtk_widget_set_size_request(online_switch, 34, 24);
1014
#endif
1015
        gtk_container_add(GTK_CONTAINER(online_switch), online_hbox);
1016
        g_signal_connect(G_OBJECT(online_switch), "clicked",
1017
                         G_CALLBACK(online_switch_clicked), mainwin);
1018
        gtk_box_pack_start(GTK_BOX(statusbar), online_switch, FALSE, FALSE, 0);
1019

    
1020
        online_tip = gtk_tooltips_new();
1021

    
1022
#if !GTK_CHECK_VERSION(2, 6, 0)
1023
        spacer_hbox = gtk_hbox_new(FALSE, 0);
1024
        gtk_box_pack_end(GTK_BOX(statusbar), spacer_hbox, FALSE, FALSE, 0);
1025
#endif
1026

    
1027
        ac_button = gtk_button_new();
1028
        gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
1029
        GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1030
        gtk_widget_set_size_request(ac_button, -1, 1);
1031
        gtk_box_pack_end(GTK_BOX(statusbar), ac_button, FALSE, FALSE, 0);
1032
        g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1033
                         G_CALLBACK(ac_label_button_pressed), mainwin);
1034

    
1035
        ac_label = gtk_label_new("");
1036
        gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1037

    
1038
        gtk_widget_show_all(statusbar);
1039

    
1040
        tray_icon = trayicon_create(mainwin);
1041
        if (tray_icon && prefs_common.show_trayicon)
1042
                trayicon_show(tray_icon);
1043

    
1044
        /* create views */
1045
        mainwin->folderview  = folderview  = folderview_create();
1046
        mainwin->summaryview = summaryview = summary_create();
1047
        mainwin->messageview = messageview = messageview_create();
1048
        mainwin->logwin      = log_window_create();
1049

    
1050
        quick_search_create(summaryview);
1051

    
1052
        folderview->mainwin      = mainwin;
1053
        folderview->summaryview  = summaryview;
1054

    
1055
        summaryview->mainwin     = mainwin;
1056
        summaryview->folderview  = folderview;
1057
        summaryview->messageview = messageview;
1058
        summaryview->window      = window;
1059

    
1060
        messageview->statusbar   = statusbar;
1061
        messageview->mainwin     = mainwin;
1062

    
1063
        mainwin->window         = window;
1064
        mainwin->vbox           = vbox;
1065
        mainwin->menubar        = menubar;
1066
        mainwin->menu_factory   = ifactory;
1067
        mainwin->toolbar        = toolbar;
1068
        mainwin->vbox_body      = vbox_body;
1069
        mainwin->statusbar      = statusbar;
1070
        mainwin->progressbar    = progressbar;
1071
        mainwin->statuslabel    = statuslabel;
1072
        mainwin->online_switch  = online_switch;
1073
        mainwin->online_pixmap  = online_pixmap;
1074
        mainwin->offline_pixmap = offline_pixmap;
1075
        mainwin->online_tip     = online_tip;
1076
        mainwin->ac_button      = ac_button;
1077
        mainwin->ac_label       = ac_label;
1078

    
1079
        mainwin->tray_icon      = tray_icon;
1080

    
1081
        /* set context IDs for status bar */
1082
        mainwin->mainwin_cid = gtk_statusbar_get_context_id
1083
                (GTK_STATUSBAR(statusbar), "Main Window");
1084
        mainwin->folderview_cid = gtk_statusbar_get_context_id
1085
                (GTK_STATUSBAR(statusbar), "Folder View");
1086
        mainwin->summaryview_cid = gtk_statusbar_get_context_id
1087
                (GTK_STATUSBAR(statusbar), "Summary View");
1088
        mainwin->messageview_cid = gtk_statusbar_get_context_id
1089
                (GTK_STATUSBAR(statusbar), "Message View");
1090

    
1091
        messageview->statusbar_cid = mainwin->messageview_cid;
1092

    
1093
        /* allocate colors for summary view and folder view */
1094
        summaryview->color_marked.red = summaryview->color_marked.green = 0;
1095
        summaryview->color_marked.blue = (guint16)65535;
1096

    
1097
        summaryview->color_dim.red = summaryview->color_dim.green =
1098
                summaryview->color_dim.blue = COLOR_DIM;
1099

    
1100
        folderview->color_new.red = (guint16)55000;
1101
        folderview->color_new.green = folderview->color_new.blue = 15000;
1102

    
1103
        folderview->color_noselect.red = folderview->color_noselect.green =
1104
                folderview->color_noselect.blue = COLOR_DIM;
1105

    
1106
        color[0] = summaryview->color_marked;
1107
        color[1] = summaryview->color_dim;
1108
        color[2] = folderview->color_new;
1109

    
1110
        colormap = gdk_window_get_colormap(window->window);
1111
        gdk_colormap_alloc_colors(colormap, color, 3, FALSE, TRUE, success);
1112
        for (i = 0; i < 3; i++) {
1113
                if (success[i] == FALSE)
1114
                        g_warning(_("MainWindow: color allocation %d failed\n"), i);
1115
        }
1116

    
1117
        messageview->visible = prefs_common.msgview_visible;
1118

    
1119
        main_window_set_widgets(mainwin, prefs_common.layout_type, type);
1120

    
1121
        if (prefs_common.mainwin_maximized)
1122
                gtk_window_maximize(GTK_WINDOW(window));
1123

    
1124
        g_signal_connect(G_OBJECT(window), "size_allocate",
1125
                         G_CALLBACK(main_window_size_allocate_cb), mainwin);
1126
        g_signal_connect(G_OBJECT(window), "window_state_event",
1127
                         G_CALLBACK(main_window_window_state_cb), mainwin);
1128
        g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1129
                         G_CALLBACK(main_window_visibility_notify_cb), mainwin);
1130

    
1131
        /* set menu items */
1132
        menuitem = gtk_item_factory_get_item
1133
                (ifactory, "/View/Character encoding/Auto detect");
1134
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1135

    
1136
        main_window_toolbar_toggle_menu_set_active
1137
                (mainwin, prefs_common.toolbar_style);
1138

    
1139
        gtk_widget_hide(GTK_WIDGET_PTR(summaryview->qsearch));
1140
        menuitem = gtk_item_factory_get_item
1141
                (ifactory, "/View/Show or hide/Search bar");
1142
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1143
                                       prefs_common.show_searchbar);
1144

    
1145
        gtk_widget_hide(mainwin->statusbar);
1146
        menuitem = gtk_item_factory_get_item
1147
                (ifactory, "/View/Show or hide/Status bar");
1148
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1149
                                       prefs_common.show_statusbar);
1150

    
1151
        /* set account selection menu */
1152
        ac_menu = gtk_item_factory_get_widget
1153
                (ifactory, "/Configuration/Change current account");
1154
        g_signal_connect(G_OBJECT(ac_menu), "selection_done",
1155
                         G_CALLBACK(ac_menu_popup_closed), mainwin);
1156
        mainwin->ac_menu = ac_menu;
1157

    
1158
        main_window_set_toolbar_sensitive(mainwin);
1159
        main_window_set_toolbar_button_visibility(mainwin);
1160

    
1161
        /* create actions menu */
1162
#ifndef G_OS_WIN32
1163
        action_update_mainwin_menu(ifactory, mainwin);
1164
#endif
1165

    
1166
        /* initialize online switch */
1167
        prefs_common.online_mode = !prefs_common.online_mode;
1168
        online_switch_clicked(online_switch, mainwin);
1169

    
1170
        /* show main window */
1171
        gtk_widget_show(mainwin->window);
1172

    
1173
#if !GTK_CHECK_VERSION(2, 6, 0)
1174
        {
1175
                gint w, h;
1176
                gdk_drawable_get_size
1177
                        (GDK_DRAWABLE(GTK_STATUSBAR(statusbar)->grip_window),
1178
                         &w, &h);
1179
                gtk_widget_set_size_request(spacer_hbox, w, -1);
1180
        }
1181
#endif
1182

    
1183
        /* initialize views */
1184
        folderview_init(folderview);
1185
        summary_init(summaryview);
1186
        messageview_init(messageview);
1187
        log_window_init(mainwin->logwin);
1188

    
1189
        mainwin->lock_count = 0;
1190
        mainwin->menu_lock_count = 0;
1191
        mainwin->cursor_count = 0;
1192

    
1193
        mainwin->window_hidden = FALSE;
1194
        mainwin->window_obscured = FALSE;
1195

    
1196
        if (!watch_cursor)
1197
                watch_cursor = gdk_cursor_new(GDK_WATCH);
1198

    
1199
        mainwin_list = g_list_append(mainwin_list, mainwin);
1200

    
1201
        debug_print(_("done.\n"));
1202

    
1203
        return mainwin;
1204
}
1205

    
1206
void main_window_cursor_wait(MainWindow *mainwin)
1207
{
1208

    
1209
        if (mainwin->cursor_count == 0)
1210
                gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1211

    
1212
        mainwin->cursor_count++;
1213

    
1214
        gdk_flush();
1215
}
1216

    
1217
void main_window_cursor_normal(MainWindow *mainwin)
1218
{
1219
        if (mainwin->cursor_count)
1220
                mainwin->cursor_count--;
1221

    
1222
        if (mainwin->cursor_count == 0)
1223
                gdk_window_set_cursor(mainwin->window->window, NULL);
1224

    
1225
        gdk_flush();
1226
}
1227

    
1228
/* lock / unlock the user-interface */
1229
void main_window_lock(MainWindow *mainwin)
1230
{
1231
        if (mainwin->lock_count == 0)
1232
                gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1233

    
1234
        mainwin->lock_count++;
1235

    
1236
        main_window_set_menu_sensitive(mainwin);
1237
        main_window_set_toolbar_sensitive(mainwin);
1238
}
1239

    
1240
void main_window_unlock(MainWindow *mainwin)
1241
{
1242
        if (mainwin->lock_count)
1243
                mainwin->lock_count--;
1244

    
1245
        main_window_set_menu_sensitive(mainwin);
1246
        main_window_set_toolbar_sensitive(mainwin);
1247

    
1248
        if (mainwin->lock_count == 0)
1249
                gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1250
}
1251

    
1252
static void main_window_menu_callback_block(MainWindow *mainwin)
1253
{
1254
        mainwin->menu_lock_count++;
1255
}
1256

    
1257
static void main_window_menu_callback_unblock(MainWindow *mainwin)
1258
{
1259
        if (mainwin->menu_lock_count)
1260
                mainwin->menu_lock_count--;
1261
}
1262

    
1263
void main_window_reflect_prefs_all(void)
1264
{
1265
        MainWindow *mainwin;
1266

    
1267
        mainwin = main_window_get();
1268

    
1269
        main_window_show_cur_account(mainwin);
1270
        main_window_set_menu_sensitive(mainwin);
1271
        main_window_set_toolbar_sensitive(mainwin);
1272
        main_window_set_toolbar_button_visibility(mainwin);
1273

    
1274
        if (mainwin->tray_icon) {
1275
                if (prefs_common.show_trayicon)
1276
                        trayicon_show(mainwin->tray_icon);
1277
                else {
1278
                        /* trayicon is automatically replaced by new one */
1279
                        trayicon_hide(mainwin->tray_icon);
1280
                }
1281
        }
1282

    
1283
        folderview_reflect_prefs(mainwin->folderview);
1284

    
1285
        headerview_set_visibility(mainwin->messageview->headerview,
1286
                                  prefs_common.display_header_pane);
1287

    
1288
        textview_reflect_prefs(mainwin->messageview->textview);
1289
        textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1290

    
1291
        summary_redisplay_msg(mainwin->summaryview);
1292
}
1293

    
1294
void main_window_set_summary_column(void)
1295
{
1296
        summary_set_column_order(main_window_get()->summaryview);
1297
}
1298

    
1299
static void main_window_set_account_selector_menu(MainWindow *mainwin,
1300
                                                  GList *account_list)
1301
{
1302
        GList *cur_ac, *cur_item;
1303
        GtkWidget *menuitem;
1304
        PrefsAccount *ac_prefs;
1305

    
1306
        /* destroy all previous menu item */
1307
        cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1308
        while (cur_item != NULL) {
1309
                GList *next = cur_item->next;
1310
                gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1311
                cur_item = next;
1312
        }
1313

    
1314
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1315
                ac_prefs = (PrefsAccount *)cur_ac->data;
1316

    
1317
                menuitem = gtk_menu_item_new_with_label
1318
                        (ac_prefs->account_name
1319
                         ? ac_prefs->account_name : _("Untitled"));
1320
                gtk_widget_show(menuitem);
1321
                gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1322
                g_signal_connect(G_OBJECT(menuitem), "activate",
1323
                                 G_CALLBACK(account_selector_menu_cb),
1324
                                 ac_prefs);
1325
        }
1326
}
1327

    
1328
static void main_window_set_account_receive_menu(MainWindow *mainwin,
1329
                                                 GList *account_list)
1330
{
1331
        GList *cur_ac, *cur_item;
1332
        GtkWidget *menu;
1333
        GtkWidget *menuitem;
1334
        PrefsAccount *ac_prefs;
1335

    
1336
        menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1337
                                           "/Message/Receive");
1338

    
1339
        /* search for separator */
1340
        for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1341
             cur_item = cur_item->next) {
1342
                if (GTK_BIN(cur_item->data)->child == NULL) {
1343
                        cur_item = cur_item->next;
1344
                        break;
1345
                }
1346
        }
1347

    
1348
        /* destroy all previous menu item */
1349
        while (cur_item != NULL) {
1350
                GList *next = cur_item->next;
1351
                gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1352
                cur_item = next;
1353
        }
1354

    
1355
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1356
                ac_prefs = (PrefsAccount *)cur_ac->data;
1357

    
1358
                menuitem = gtk_menu_item_new_with_label
1359
                        (ac_prefs->account_name ? ac_prefs->account_name
1360
                         : _("Untitled"));
1361
                gtk_widget_show(menuitem);
1362
                gtk_menu_append(GTK_MENU(menu), menuitem);
1363
                g_signal_connect(G_OBJECT(menuitem), "activate",
1364
                                 G_CALLBACK(account_receive_menu_cb),
1365
                                 ac_prefs);
1366
        }
1367
}
1368

    
1369
void main_window_set_account_menu(GList *account_list)
1370
{
1371
        MainWindow *mainwin;
1372

    
1373
        mainwin = main_window_get();
1374
        main_window_set_account_selector_menu(mainwin, account_list);
1375
        main_window_set_account_receive_menu(mainwin, account_list);
1376
}
1377

    
1378
static void main_window_show_cur_account(MainWindow *mainwin)
1379
{
1380
        gchar *buf;
1381
        gchar *ac_name;
1382

    
1383
        ac_name = g_strdup(cur_account
1384
                           ? (cur_account->account_name
1385
                              ? cur_account->account_name : _("Untitled"))
1386
                           : _("none"));
1387

    
1388
        if (cur_account)
1389
                buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1390
        else
1391
                buf = g_strdup(PROG_VERSION);
1392
        gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1393
        g_free(buf);
1394

    
1395
        gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1396
        gtk_widget_queue_resize(mainwin->ac_button);
1397

    
1398
        g_free(ac_name);
1399
}
1400

    
1401
MainWindow *main_window_get(void)
1402
{
1403
        if (mainwin_list)
1404
                return (MainWindow *)mainwin_list->data;
1405
        else
1406
                return NULL;
1407
}
1408

    
1409
GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
1410
{
1411
        switch (mainwin->type) {
1412
        case SEPARATE_FOLDER:
1413
                return mainwin->win.sep_folder.folderwin;
1414
        case SEPARATE_BOTH:
1415
                return mainwin->win.sep_both.folderwin;
1416
        default:
1417
                return NULL;
1418
        }
1419
}
1420

    
1421
GtkWidget *main_window_get_message_window(MainWindow *mainwin)
1422
{
1423
        switch (mainwin->type) {
1424
        case SEPARATE_MESSAGE:
1425
                return mainwin->win.sep_message.messagewin;
1426
        case SEPARATE_BOTH:
1427
                return mainwin->win.sep_both.messagewin;
1428
        default:
1429
                return NULL;
1430
        }
1431
}
1432

    
1433
void main_window_change_layout(MainWindow *mainwin, LayoutType layout,
1434
                               SeparateType type)
1435
{
1436
        GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1437
        GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1438
        GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1439
        GtkWidget *qsearch_wid = GTK_WIDGET_PTR(mainwin->summaryview->qsearch);
1440
        GtkWidget *vbox_summary = qsearch_wid->parent;
1441
        GtkWidget *focus_widget;
1442

    
1443
        debug_print("Changing window layout type (layout: %d -> %d, separation: %d -> %d)\n", prefs_common.layout_type, layout, mainwin->type, type);
1444

    
1445
        if (prefs_common.layout_type == layout && mainwin->type == type)
1446
                return;
1447

    
1448
        /* keep previous focus */
1449
        focus_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
1450

    
1451
        /* remove widgets from those containers */
1452
        gtk_widget_ref(folder_wid);
1453
        gtk_widget_ref(summary_wid);
1454
        gtk_widget_ref(message_wid);
1455
        gtk_widget_ref(qsearch_wid);
1456
        gtkut_container_remove
1457
                (GTK_CONTAINER(folder_wid->parent), folder_wid);
1458
        gtkut_container_remove
1459
                (GTK_CONTAINER(summary_wid->parent), summary_wid);
1460
        gtkut_container_remove
1461
                (GTK_CONTAINER(message_wid->parent), message_wid);
1462
        gtkut_container_remove
1463
                (GTK_CONTAINER(qsearch_wid->parent), qsearch_wid);
1464

    
1465
        /* clean containers */
1466
        switch (mainwin->type) {
1467
        case SEPARATE_NONE:
1468
                if (!mainwin->win.sep_none.vpaned->parent)
1469
                        gtk_widget_destroy(mainwin->win.sep_none.vpaned);
1470
                gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1471
                mainwin->win.sep_none.hpaned = NULL;
1472
                mainwin->win.sep_none.vpaned = NULL;
1473
                break;
1474
        case SEPARATE_FOLDER:
1475
                gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1476
                if (!mainwin->win.sep_folder.vpaned->parent)
1477
                        gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1478
                gtk_widget_destroy(vbox_summary);
1479
                mainwin->win.sep_folder.folderwin = NULL;
1480
                mainwin->win.sep_folder.vpaned = NULL;
1481
                break;
1482
        case SEPARATE_MESSAGE:
1483
                gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1484
                gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1485
                mainwin->win.sep_message.messagewin = NULL;
1486
                mainwin->win.sep_message.hpaned = NULL;
1487
                break;
1488
        case SEPARATE_BOTH:
1489
                gtk_widget_destroy(vbox_summary);
1490
                gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1491
                gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1492
                mainwin->win.sep_both.folderwin = NULL;
1493
                mainwin->win.sep_both.messagewin = NULL;
1494
                break;
1495
        }
1496

    
1497
        gtk_widget_hide(mainwin->window);
1498
        main_window_set_widgets(mainwin, layout, type);
1499
        gtk_widget_show(mainwin->window);
1500
        if (focus_widget)
1501
                gtk_widget_grab_focus(focus_widget);
1502

    
1503
        gtk_widget_unref(folder_wid);
1504
        gtk_widget_unref(summary_wid);
1505
        gtk_widget_unref(message_wid);
1506
        gtk_widget_unref(qsearch_wid);
1507
}
1508

    
1509
void main_window_toggle_message_view(MainWindow *mainwin)
1510
{
1511
        SummaryView *summaryview = mainwin->summaryview;
1512
        union CompositeWin *cwin = &mainwin->win;
1513
        GtkWidget *vpaned = NULL;
1514
        GtkWidget *container = NULL;
1515
        GtkWidget *msgwin = NULL;
1516
        gboolean use_vlayout = (prefs_common.layout_type == LAYOUT_VERTICAL);
1517

    
1518
        switch (mainwin->type) {
1519
        case SEPARATE_NONE:
1520
                vpaned = cwin->sep_none.vpaned;
1521
                container = GTK_WIDGET_PTR(summaryview->qsearch)->parent;
1522
                break;
1523
        case SEPARATE_FOLDER:
1524
                vpaned = cwin->sep_folder.vpaned;
1525
                container = GTK_WIDGET_PTR(summaryview->qsearch)->parent;
1526
                break;
1527
        case SEPARATE_MESSAGE:
1528
                msgwin = mainwin->win.sep_message.messagewin;
1529
                break;
1530
        case SEPARATE_BOTH:
1531
                msgwin = mainwin->win.sep_both.messagewin;
1532
                break;
1533
        }
1534

    
1535
        if (msgwin) {
1536
                /* separate message view */
1537
                if (GTK_WIDGET_VISIBLE(msgwin)) {
1538
                        gtk_widget_hide(msgwin);
1539
                        mainwin->messageview->visible = FALSE;
1540
                        summaryview->displayed = NULL;
1541
                } else {
1542
                        gtk_widget_show(msgwin);
1543
                        mainwin->messageview->visible = TRUE;
1544
                }
1545
        } else if (vpaned->parent != NULL) {
1546
                /* hide message view */
1547
                mainwin->messageview->visible = FALSE;
1548
                summaryview->displayed = NULL;
1549
                gtk_widget_ref(vpaned);
1550
                gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1551
                gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1552
                if (!use_vlayout)
1553
                        gtk_widget_hide(summaryview->hseparator);
1554
        } else {
1555
                /* show message view */
1556
                mainwin->messageview->visible = TRUE;
1557
                gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1558
                gtk_container_add(GTK_CONTAINER(container), vpaned);
1559
                gtk_widget_unref(vpaned);
1560
                if (!use_vlayout)
1561
                        gtk_widget_show(summaryview->hseparator);
1562
        }
1563

    
1564
        if (messageview_is_visible(mainwin->messageview))
1565
                gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1566
                              use_vlayout ? GTK_ARROW_RIGHT : GTK_ARROW_DOWN,
1567
                              GTK_SHADOW_OUT);
1568
        else
1569
                gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1570
                              use_vlayout ? GTK_ARROW_LEFT : GTK_ARROW_UP,
1571
                              GTK_SHADOW_OUT);
1572

    
1573
        if (mainwin->messageview->visible == FALSE)
1574
                messageview_clear(mainwin->messageview);
1575

    
1576
        main_window_set_menu_sensitive(mainwin);
1577

    
1578
        prefs_common.msgview_visible = mainwin->messageview->visible;
1579

    
1580
        gtk_widget_grab_focus(summaryview->treeview);
1581
}
1582

    
1583
void main_window_get_size(MainWindow *mainwin)
1584
{
1585
        GtkAllocation *allocation;
1586
        gboolean vlayout = (prefs_common.layout_type == LAYOUT_VERTICAL);
1587

    
1588
        allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1589
        if (allocation->width > 1 && allocation->height > 1) {
1590
                if (vlayout) {
1591
                        if (!(mainwin->type & SEPARATE_MESSAGE))
1592
                                prefs_common.summaryview_vwidth = allocation->width;
1593
                        prefs_common.summaryview_vheight = allocation->height;
1594
                } else {
1595
                        if (!prefs_common.mainwin_maximized) {
1596
                                prefs_common.summaryview_width = allocation->width;
1597
                                prefs_common.mainview_width = allocation->width;
1598
                        }
1599
                        if ((mainwin->type == SEPARATE_NONE ||
1600
                             mainwin->type == SEPARATE_FOLDER) &&
1601
                            messageview_is_visible(mainwin->messageview))
1602
                                prefs_common.summaryview_height = allocation->height;
1603
                }
1604
        }
1605

    
1606
        if (prefs_common.mainwin_maximized) {
1607
                allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1608
                if (allocation->width > 1 && allocation->height > 1)
1609
                        prefs_common.folderview_width  = allocation->width;
1610
                return;
1611
        }
1612

    
1613
        allocation = &mainwin->window->allocation;
1614
        if (allocation->width > 1 && allocation->height > 1) {
1615
                prefs_common.mainview_height = allocation->height;
1616
                prefs_common.mainwin_width   = allocation->width;
1617
                prefs_common.mainwin_height  = allocation->height;
1618
        }
1619

    
1620
        allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1621
        if (allocation->width > 1 && allocation->height > 1) {
1622
                prefs_common.folderview_width  = allocation->width;
1623
                prefs_common.folderview_height = allocation->height;
1624
        }
1625

    
1626
        allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
1627
        if (allocation->width > 1 && allocation->height > 1) {
1628
                if (vlayout) {
1629
                        prefs_common.msgview_vwidth = allocation->width;
1630
                        prefs_common.msgview_vheight = allocation->height;
1631
                } else {
1632
                        prefs_common.msgview_width = allocation->width;
1633
                        prefs_common.msgview_height = allocation->height;
1634
                }
1635
        }
1636

    
1637
#if 0
1638
        debug_print("summaryview size: %d x %d\n",
1639
                    prefs_common.summaryview_width,
1640
                    prefs_common.summaryview_height);
1641
        debug_print("mainwin size: %d x %d\n",
1642
                    prefs_common.mainwin_width,
1643
                    prefs_common.mainwin_height);
1644
        debug_print("folderview size: %d x %d\n",
1645
                    prefs_common.folderview_width,
1646
                    prefs_common.folderview_height);
1647
        debug_print("messageview size: %d x %d\n",
1648
                    prefs_common.msgview_width,
1649
                    prefs_common.msgview_height);
1650
#endif
1651
}
1652

    
1653
void main_window_get_position(MainWindow *mainwin)
1654
{
1655
        gint x, y;
1656
        GtkWidget *window;
1657

    
1658
        if (prefs_common.mainwin_maximized || mainwin->window_hidden)
1659
                return;
1660

    
1661
        gtkut_widget_get_uposition(mainwin->window, &x, &y);
1662

    
1663
        prefs_common.mainview_x = x;
1664
        prefs_common.mainview_y = y;
1665
        prefs_common.mainwin_x = x;
1666
        prefs_common.mainwin_y = y;
1667

    
1668
        debug_print("main window position: %d, %d\n", x, y);
1669

    
1670
        window = main_window_get_folder_window(mainwin);
1671
        if (window) {
1672
                gtkut_widget_get_uposition(window, &x, &y);
1673
                prefs_common.folderwin_x = x;
1674
                prefs_common.folderwin_y = y;
1675
                debug_print("folder window position: %d, %d\n", x, y);
1676
        }
1677
        window = main_window_get_message_window(mainwin);
1678
        if (window) {
1679
                gtkut_widget_get_uposition(window, &x, &y);
1680
                prefs_common.main_msgwin_x = x;
1681
                prefs_common.main_msgwin_y = y;
1682
                debug_print("message window position: %d, %d\n", x, y);
1683
        }
1684
}
1685

    
1686
void main_window_progress_on(MainWindow *mainwin)
1687
{
1688
        gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), TRUE);
1689
        gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
1690
}
1691

    
1692
void main_window_progress_off(MainWindow *mainwin)
1693
{
1694
        gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), FALSE);
1695
        gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
1696
        gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
1697
}
1698

    
1699
void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
1700
{
1701
        gchar buf[32];
1702

    
1703
        g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
1704
        gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), buf);
1705
        gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar),
1706
                                (cur == 0 && total == 0) ? 0 :
1707
                                (gfloat)cur / (gfloat)total);
1708
}
1709

    
1710
void main_window_progress_show(gint cur, gint total)
1711
{
1712
        MainWindow *mainwin;
1713

    
1714
        mainwin = main_window_get();
1715

    
1716
        if (total > 0) {
1717
                gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar),
1718
                                           TRUE);
1719
                main_window_progress_set(mainwin, cur, total);
1720
        } else
1721
                main_window_progress_off(mainwin);
1722
}
1723

    
1724
void main_window_toggle_online(MainWindow *mainwin, gboolean online)
1725
{
1726
        if (prefs_common.online_mode != online)
1727
                online_switch_clicked(mainwin->online_switch, mainwin);
1728
}
1729

    
1730
gboolean main_window_toggle_online_if_offline(MainWindow *mainwin)
1731
{
1732
        if (!prefs_common.online_mode) {
1733
                if (alertpanel(_("Offline"),
1734
                               _("You are offline. Go online?"),
1735
                               GTK_STOCK_YES, GTK_STOCK_NO, NULL)
1736
                    == G_ALERTDEFAULT)
1737
                        main_window_toggle_online(mainwin, TRUE);
1738
        }
1739

    
1740
        return prefs_common.online_mode;
1741
}
1742

    
1743
void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1744
{
1745
        GList *list;
1746

    
1747
        if (!procmsg_trash_messages_exist())
1748
                return;
1749

    
1750
        if (confirm) {
1751
                if (alertpanel(_("Empty all trash"),
1752
                               _("Delete all messages in trash folders?"),
1753
                               GTK_STOCK_YES, GTK_STOCK_NO, NULL)
1754
                    != G_ALERTDEFAULT)
1755
                        return;
1756
                manage_window_focus_in(mainwin->window, NULL, NULL);
1757
        }
1758

    
1759
        procmsg_empty_all_trash();
1760
        statusbar_pop_all();
1761
        trayicon_set_tooltip(NULL);
1762
        trayicon_set_notify(FALSE);
1763

    
1764
        for (list = folder_get_list(); list != NULL; list = list->next) {
1765
                Folder *folder;
1766

    
1767
                folder = list->data;
1768
                if (folder->trash)
1769
                        folderview_update_item(folder->trash, TRUE);
1770
        }
1771

    
1772
        if (mainwin->summaryview->folder_item &&
1773
            mainwin->summaryview->folder_item->stype == F_TRASH)
1774
                gtk_widget_grab_focus(mainwin->folderview->treeview);
1775
}
1776

    
1777
void main_window_add_mailbox(MainWindow *mainwin)
1778
{
1779
        gchar *path;
1780
        Folder *folder;
1781

    
1782
        path = input_dialog(_("Add mailbox"),
1783
                            _("Specify the location of mailbox.\n"
1784
                              "If the existing mailbox is specified, it will be\n"
1785
                              "scanned automatically."),
1786
                            "Mail");
1787
        if (!path) return;
1788
        if (folder_find_from_path(path)) {
1789
                alertpanel_error(_("The mailbox `%s' already exists."), path);
1790
                g_free(path);
1791
                return;
1792
        }
1793
        if (!strcmp(path, "Mail"))
1794
                folder = folder_new(F_MH, _("Mailbox"), path);
1795
        else
1796
                folder = folder_new(F_MH, g_basename(path), path);
1797
        g_free(path);
1798

    
1799
        if (folder->klass->create_tree(folder) < 0) {
1800
                alertpanel_error(_("Creation of the mailbox failed.\n"
1801
                                   "Maybe some files already exist, or you don't have the permission to write there."));
1802
                folder_destroy(folder);
1803
                return;
1804
        }
1805

    
1806
        folder_add(folder);
1807
        folder_set_ui_func(folder, scan_tree_func, mainwin);
1808
        folder->klass->scan_tree(folder);
1809
        folder_set_ui_func(folder, NULL, NULL);
1810

    
1811
        folderview_set(mainwin->folderview);
1812
}
1813

    
1814
void main_window_send_queue(MainWindow *mainwin)
1815
{
1816
        GList *list;
1817

    
1818
        if (!main_window_toggle_online_if_offline(mainwin))
1819
                return;
1820

    
1821
        for (list = folder_get_list(); list != NULL; list = list->next) {
1822
                Folder *folder = list->data;
1823

    
1824
                if (folder->queue) {
1825
                        gint ret;
1826

    
1827
                        ret = send_message_queue_all(folder->queue,
1828
                                                     prefs_common.savemsg,
1829
                                                     prefs_common.filter_sent);
1830
                        statusbar_pop_all();
1831
                        if (ret > 0)
1832
                                folder_item_scan(folder->queue);
1833
                }
1834
        }
1835

    
1836
        folderview_update_all_updated(TRUE);
1837
        main_window_set_menu_sensitive(mainwin);
1838
        main_window_set_toolbar_sensitive(mainwin);
1839
}
1840

    
1841
typedef enum
1842
{
1843
        M_UNLOCKED            = 1 << 0,
1844
        M_MSG_EXIST           = 1 << 1,
1845
        M_TARGET_EXIST        = 1 << 2,
1846
        M_SINGLE_TARGET_EXIST = 1 << 3,
1847
        M_EXEC                = 1 << 4,
1848
        M_ALLOW_REEDIT        = 1 << 5,
1849
        M_HAVE_ACCOUNT        = 1 << 6,
1850
        M_THREADED              = 1 << 7,
1851
        M_UNTHREADED              = 1 << 8,
1852
        M_ALLOW_DELETE              = 1 << 9,
1853
        M_INC_ACTIVE              = 1 << 10,
1854
        M_ENABLE_JUNK              = 1 << 11,
1855
        M_HAVE_QUEUED_MSG     = 1 << 12,
1856
        M_POP3_ACCOUNT              = 1 << 13,
1857

    
1858
        M_FOLDER_NEWOK              = 1 << 17,
1859
        M_FOLDER_RENOK              = 1 << 18,
1860
        M_FOLDER_MOVEOK              = 1 << 19,
1861
        M_FOLDER_DELOK              = 1 << 20,
1862
        M_MBOX_ADDOK              = 1 << 21,
1863
        M_MBOX_RMOK              = 1 << 22,
1864
        M_MBOX_CHKOK              = 1 << 23,
1865
        M_MBOX_CHKALLOK              = 1 << 24,
1866
        M_MBOX_REBUILDOK      = 1 << 25
1867
} SensitiveCond;
1868

    
1869
static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1870
{
1871
        SensitiveCond state = 0;
1872
        SummarySelection selection;
1873
        GList *list;
1874
        FolderItem *item = mainwin->summaryview->folder_item;
1875

    
1876
        selection = summary_get_selection_type(mainwin->summaryview);
1877

    
1878
        if (mainwin->lock_count == 0)
1879
                state |= M_UNLOCKED;
1880
        if (selection != SUMMARY_NONE)
1881
                state |= M_MSG_EXIST;
1882
        if (item && item->path && item->parent && !item->no_select) {
1883
                state |= M_EXEC;
1884
                if (item->threaded)
1885
                        state |= M_THREADED;
1886
                else
1887
                        state |= M_UNTHREADED;        
1888
                if (FOLDER_TYPE(item->folder) != F_NEWS)
1889
                        state |= M_ALLOW_DELETE;
1890
        }
1891
        if (selection == SUMMARY_SELECTED_SINGLE ||
1892
            selection == SUMMARY_SELECTED_MULTIPLE)
1893
                state |= M_TARGET_EXIST;
1894
        if (selection == SUMMARY_SELECTED_SINGLE)
1895
                state |= M_SINGLE_TARGET_EXIST;
1896
        if (selection == SUMMARY_SELECTED_SINGLE &&
1897
            FOLDER_ITEM_IS_SENT_FOLDER(item))
1898
                state |= M_ALLOW_REEDIT;
1899
        if (cur_account) {
1900
                state |= M_HAVE_ACCOUNT;
1901
                if (cur_account->protocol == A_POP3)
1902
                        state |= M_POP3_ACCOUNT;
1903
        }
1904

    
1905
        if (inc_is_active())
1906
                state |= M_INC_ACTIVE;
1907

    
1908
        if (prefs_common.enable_junk)
1909
                state |= M_ENABLE_JUNK;
1910

    
1911
        for (list = folder_get_list(); list != NULL; list = list->next) {
1912
                Folder *folder = list->data;
1913
                if (folder->queue && folder->queue->total > 0) {
1914
                        state |= M_HAVE_QUEUED_MSG;
1915
                        break;
1916
                }
1917
        }
1918

    
1919
        item = folderview_get_selected_item(mainwin->folderview);
1920
        if (item) {
1921
                state |= M_FOLDER_NEWOK;
1922
                if (item->parent == NULL) {
1923
                        state |= M_MBOX_RMOK;
1924
                        state |= M_MBOX_CHKOK;
1925
                }
1926
                if (FOLDER_IS_LOCAL(item->folder) ||
1927
                    FOLDER_TYPE(item->folder) == F_IMAP) {
1928
                        if (item->parent == NULL)
1929
                                state |= M_MBOX_REBUILDOK;
1930
                        else if (item->stype == F_NORMAL) {
1931
                                state |= M_FOLDER_RENOK;
1932
                                state |= M_FOLDER_DELOK;
1933
                                if (item->folder->klass->move_folder)
1934
                                        state |= M_FOLDER_MOVEOK;
1935
                        }
1936
                } else if (FOLDER_TYPE(item->folder) == F_NEWS) {
1937
                        if (item->parent != NULL)
1938
                                state |= M_FOLDER_DELOK;
1939
                }
1940
        }
1941
        state |= M_MBOX_ADDOK;
1942
        state |= M_MBOX_CHKALLOK;
1943

    
1944
        return state;
1945
}
1946

    
1947
void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1948
{
1949
        SensitiveCond state;
1950
        gboolean sensitive, prev_sensitive;
1951
        gint n;
1952
        gint i = 0;
1953

    
1954
        struct {
1955
                GtkWidget *widget;
1956
                SensitiveCond cond;
1957
        } entry[20];
1958

    
1959
#define SET_WIDGET_COND(w, c)        \
1960
{                                \
1961
        entry[i].widget = w;        \
1962
        entry[i].cond = c;        \
1963
        i++;                        \
1964
}
1965

    
1966
        SET_WIDGET_COND(mainwin->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1967
        SET_WIDGET_COND(mainwin->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1968
        SET_WIDGET_COND(mainwin->rpop3_btn,
1969
                        M_HAVE_ACCOUNT|M_UNLOCKED|M_POP3_ACCOUNT);
1970
        SET_WIDGET_COND(mainwin->send_btn, M_HAVE_ACCOUNT|M_HAVE_QUEUED_MSG);
1971
        SET_WIDGET_COND(mainwin->compose_btn, M_HAVE_ACCOUNT);
1972
        SET_WIDGET_COND(mainwin->reply_btn,
1973
                        M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1974
        SET_WIDGET_COND(mainwin->reply_combo ?
1975
                        GTK_WIDGET_PTR(mainwin->reply_combo) : NULL,
1976
                        M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1977
        SET_WIDGET_COND(mainwin->replyall_btn,
1978
                        M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1979
        SET_WIDGET_COND(mainwin->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1980
        SET_WIDGET_COND(mainwin->fwd_combo ? GTK_WIDGET_PTR(mainwin->fwd_combo)
1981
                        : NULL,
1982
                        M_HAVE_ACCOUNT|M_TARGET_EXIST);
1983
        SET_WIDGET_COND(mainwin->delete_btn,
1984
                        M_TARGET_EXIST|M_ALLOW_DELETE);
1985
        SET_WIDGET_COND(mainwin->junk_btn,
1986
                        M_TARGET_EXIST|M_ALLOW_DELETE|M_ENABLE_JUNK);
1987
        SET_WIDGET_COND(mainwin->notjunk_btn,
1988
                        M_TARGET_EXIST|M_ALLOW_DELETE|M_ENABLE_JUNK);
1989
        SET_WIDGET_COND(mainwin->exec_btn, M_MSG_EXIST|M_EXEC);
1990
        SET_WIDGET_COND(mainwin->next_btn, M_MSG_EXIST);
1991
        SET_WIDGET_COND(mainwin->prev_btn, M_MSG_EXIST);
1992
        SET_WIDGET_COND(mainwin->print_btn, M_TARGET_EXIST);
1993
        SET_WIDGET_COND(mainwin->stop_btn, M_INC_ACTIVE);
1994
        SET_WIDGET_COND(mainwin->prefs_common_btn, M_UNLOCKED);
1995
        SET_WIDGET_COND(mainwin->prefs_account_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1996

    
1997
#undef SET_WIDGET_COND
1998

    
1999
        state = main_window_get_current_state(mainwin);
2000

    
2001
        n = sizeof(entry) / sizeof(entry[0]);
2002
        for (i = 0; i < n; i++) {
2003
                if (entry[i].widget) {
2004
                        prev_sensitive =
2005
                                GTK_WIDGET_IS_SENSITIVE(entry[i].widget);
2006
                        sensitive = ((entry[i].cond & state) == entry[i].cond);
2007
                        if (prev_sensitive != sensitive) {
2008
                                /* workaround for GTK+ bug (#56070) */
2009
                                if (!prev_sensitive)
2010
                                        gtk_widget_hide(entry[i].widget);
2011
                                gtk_widget_set_sensitive(entry[i].widget,
2012
                                                         sensitive);
2013
                                if (!prev_sensitive)
2014
                                        gtk_widget_show(entry[i].widget);
2015
                        }
2016
                }
2017
        }
2018
}
2019

    
2020
static void main_window_set_toolbar_button_visibility(MainWindow *mainwin)
2021
{
2022
        GtkToolbarStyle style = GTK_TOOLBAR_BOTH_HORIZ;
2023

    
2024
        if (prefs_common.toolbar_style == TOOLBAR_NONE)
2025
                style = -1;
2026
        else if (prefs_common.toolbar_style == TOOLBAR_ICON)
2027
                style = GTK_TOOLBAR_ICONS;
2028
        else if (prefs_common.toolbar_style == TOOLBAR_TEXT)
2029
                style = GTK_TOOLBAR_TEXT;
2030
        else if (prefs_common.toolbar_style == TOOLBAR_BOTH)
2031
                style = GTK_TOOLBAR_BOTH;
2032
        else if (prefs_common.toolbar_style == TOOLBAR_BOTH_HORIZ)
2033
                style = GTK_TOOLBAR_BOTH_HORIZ;
2034

    
2035
        if (style != -1) {
2036
                gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar), style);
2037
                gtk_widget_show(mainwin->toolbar);
2038
                gtk_widget_queue_resize(mainwin->toolbar);
2039
        } else
2040
                gtk_widget_hide(mainwin->toolbar);
2041

    
2042
#if 0
2043
        if (mainwin->junk_btn) {
2044
                if (prefs_common.enable_junk)
2045
                        gtk_widget_show(mainwin->junk_btn);
2046
                else
2047
                        gtk_widget_hide(mainwin->junk_btn);
2048
        }
2049

2050
        if (mainwin->exec_btn) {
2051
                if (prefs_common.immediate_exec)
2052
                        gtk_widget_hide(mainwin->exec_btn);
2053
                else
2054
                        gtk_widget_show(mainwin->exec_btn);
2055
        }
2056
#endif
2057
}
2058

    
2059
void main_window_set_menu_sensitive(MainWindow *mainwin)
2060
{
2061
        GtkItemFactory *ifactory = mainwin->menu_factory;
2062
        SensitiveCond state;
2063
        gboolean sensitive;
2064
        GtkWidget *menu;
2065
        GtkWidget *menuitem;
2066
        FolderItem *item;
2067
        gchar *menu_path;
2068
        gint i;
2069
        GList *cur_item;
2070

    
2071
        static const struct {
2072
                gchar *const entry;
2073
                SensitiveCond cond;
2074
        } entry[] = {
2075
                {"/File/Folder/Create new folder...", M_UNLOCKED|M_FOLDER_NEWOK},
2076
                {"/File/Folder/Rename folder..."    , M_UNLOCKED|M_FOLDER_RENOK},
2077
                {"/File/Folder/Move folder..."      , M_UNLOCKED|M_FOLDER_MOVEOK},
2078
                {"/File/Folder/Delete folder"       , M_UNLOCKED|M_FOLDER_DELOK},
2079
                {"/File/Mailbox/Add mailbox..."     , M_UNLOCKED|M_MBOX_ADDOK},
2080
                {"/File/Mailbox/Remove mailbox"     , M_UNLOCKED|M_MBOX_RMOK},
2081
                {"/File/Mailbox/Check for new messages"
2082
                                                    , M_UNLOCKED|M_MBOX_CHKOK},
2083
                {"/File/Mailbox/Check for new messages in all mailboxes"
2084
                                                    , M_UNLOCKED|M_MBOX_CHKALLOK},
2085
                {"/File/Mailbox/Rebuild folder tree", M_UNLOCKED|M_MBOX_REBUILDOK},
2086
                {"/File/Import mbox file..."        , M_UNLOCKED},
2087
                {"/File/Export to mbox file..."     , M_UNLOCKED},
2088
                {"/File/Empty all trash"            , M_UNLOCKED},
2089

    
2090
                {"/File/Save as..."  , M_SINGLE_TARGET_EXIST},
2091
                {"/File/Print..."    , M_TARGET_EXIST},
2092
                {"/File/Work offline", M_UNLOCKED},
2093
                /* {"/File/Close"    , M_UNLOCKED}, */
2094
                {"/File/Exit"        , M_UNLOCKED},
2095

    
2096
                {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
2097

    
2098
                {"/View/Sort"                      , M_EXEC},
2099
                {"/View/Thread view"               , M_EXEC},
2100
                {"/View/Expand all threads"        , M_MSG_EXIST},
2101
                {"/View/Collapse all threads"      , M_MSG_EXIST},
2102
                {"/View/Go to/Prev message"        , M_MSG_EXIST},
2103
                {"/View/Go to/Next message"        , M_MSG_EXIST},
2104
                {"/View/Go to/Prev unread message" , M_MSG_EXIST},
2105
                {"/View/Go to/Next unread message" , M_MSG_EXIST},
2106
                {"/View/Go to/Prev new message"    , M_MSG_EXIST},
2107
                {"/View/Go to/Next new message"    , M_MSG_EXIST},
2108
                {"/View/Go to/Prev marked message" , M_MSG_EXIST},
2109
                {"/View/Go to/Next marked message" , M_MSG_EXIST},
2110
                {"/View/Go to/Prev labeled message", M_MSG_EXIST},
2111
                {"/View/Go to/Next labeled message", M_MSG_EXIST},
2112
                {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2113
                {"/View/All headers"          , M_SINGLE_TARGET_EXIST},
2114
                {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2115

    
2116
                {"/Message/Receive/Get from current account"
2117
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED},
2118
                {"/Message/Receive/Get from all accounts"
2119
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED},
2120
                {"/Message/Receive/Stop receiving"
2121
                                                 , M_INC_ACTIVE},
2122
                {"/Message/Receive/Remote mailbox..."
2123
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED|M_POP3_ACCOUNT},
2124
                {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MSG},
2125

    
2126
                {"/Message/Compose new message"  , M_HAVE_ACCOUNT},
2127
                {"/Message/Reply"                , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2128
                {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2129
                {"/Message/Forward"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2130
                {"/Message/Forward as attachment", M_HAVE_ACCOUNT|M_TARGET_EXIST},
2131
                {"/Message/Redirect"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2132
                {"/Message/Move..."              , M_TARGET_EXIST|M_ALLOW_DELETE},
2133
                {"/Message/Copy..."              , M_TARGET_EXIST|M_EXEC},
2134
                {"/Message/Delete"               , M_TARGET_EXIST|M_ALLOW_DELETE},
2135
                {"/Message/Mark"                 , M_TARGET_EXIST},
2136
                {"/Message/Set as junk mail"     , M_TARGET_EXIST|M_ALLOW_DELETE|M_ENABLE_JUNK},
2137
                {"/Message/Set as not junk mail" , M_TARGET_EXIST|M_ALLOW_DELETE|M_ENABLE_JUNK},
2138
                {"/Message/Re-edit"              , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2139

    
2140
                {"/Tools/Add sender to address book...", M_SINGLE_TARGET_EXIST},
2141
                {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2142
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2143
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2144
                {"/Tools/Filter junk mails in folder"  , M_MSG_EXIST|M_EXEC|M_ENABLE_JUNK},
2145
                {"/Tools/Filter junk mails in selected messages", M_TARGET_EXIST|M_EXEC|M_ENABLE_JUNK},
2146
#ifndef G_OS_WIN32
2147
                {"/Tools/Actions"                      , M_TARGET_EXIST|M_UNLOCKED},
2148
#endif
2149
                {"/Tools/Execute marked process"       , M_MSG_EXIST|M_EXEC},
2150
                {"/Tools/Delete duplicated messages"   , M_MSG_EXIST|M_ALLOW_DELETE},
2151

    
2152
                {"/Configuration/Common preferences...", M_UNLOCKED},
2153
                {"/Configuration/Filter settings...", M_UNLOCKED},
2154
                {"/Configuration/Preferences for current account...", M_UNLOCKED},
2155
                {"/Configuration/Create new account...", M_UNLOCKED},
2156
                {"/Configuration/Edit accounts...", M_UNLOCKED},
2157
                {"/Configuration/Change current account", M_UNLOCKED},
2158

    
2159
                {NULL, 0}
2160
        };
2161

    
2162
        state = main_window_get_current_state(mainwin);
2163

    
2164
        for (i = 0; entry[i].entry != NULL; i++) {
2165
                sensitive = ((entry[i].cond & state) == entry[i].cond);
2166
                menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2167
        }
2168

    
2169
        menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2170

    
2171
        /* search for separator */
2172
        for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2173
             cur_item = cur_item->next) {
2174
                if (GTK_BIN(cur_item->data)->child == NULL) {
2175
                        cur_item = cur_item->next;
2176
                        break;
2177
                }
2178
        }
2179

    
2180
        for (; cur_item != NULL; cur_item = cur_item->next) {
2181
                gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2182
                                         (M_UNLOCKED & state) != 0);
2183
        }
2184

    
2185
        main_window_menu_callback_block(mainwin);
2186

    
2187
#define SET_CHECK_MENU_ACTIVE(path, active) \
2188
{ \
2189
        menuitem = gtk_item_factory_get_widget(ifactory, path); \
2190
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2191
}
2192

    
2193
        SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2194
                              messageview_is_visible(mainwin->messageview));
2195

    
2196
        item = mainwin->summaryview->folder_item;
2197
        menu_path = "/View/Sort/Don't sort";
2198
        if (item) {
2199
                switch (item->sort_key) {
2200
                case SORT_BY_NUMBER:
2201
                        menu_path = "/View/Sort/by number"; break;
2202
                case SORT_BY_SIZE:
2203
                        menu_path = "/View/Sort/by size"; break;
2204
                case SORT_BY_DATE:
2205
                        menu_path = "/View/Sort/by date"; break;
2206
                case SORT_BY_TDATE:
2207
                        menu_path = "/View/Sort/by thread date"; break;
2208
                case SORT_BY_FROM:
2209
                        menu_path = "/View/Sort/by from"; break;
2210
                case SORT_BY_TO:
2211
                        menu_path = "/View/Sort/by recipient"; break;
2212
                case SORT_BY_SUBJECT:
2213
                        menu_path = "/View/Sort/by subject"; break;
2214
                case SORT_BY_LABEL:
2215
                        menu_path = "/View/Sort/by color label"; break;
2216
                case SORT_BY_MARK:
2217
                        menu_path = "/View/Sort/by mark"; break;
2218
                case SORT_BY_UNREAD:
2219
                        menu_path = "/View/Sort/by unread"; break;
2220
                case SORT_BY_MIME:
2221
                        menu_path = "/View/Sort/by attachment"; break;
2222
                case SORT_BY_NONE:
2223
                default:
2224
                        menu_path = "/View/Sort/Don't sort"; break;
2225
                }
2226
        }
2227
        SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2228

    
2229
        if (!item || item->sort_type == SORT_ASCENDING) {
2230
                SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2231
        } else {
2232
                SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2233
        }
2234

    
2235
        if (item && item->sort_key != SORT_BY_NONE) {
2236
                menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2237
                menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2238
                menu_set_sensitive(ifactory, "/View/Sort/Attract by subject",
2239
                                   FALSE);
2240
        } else {
2241
                menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2242
                menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2243
                menu_set_sensitive(ifactory, "/View/Sort/Attract by subject",
2244
                                   (item != NULL));
2245
        }
2246

    
2247
        SET_CHECK_MENU_ACTIVE("/View/All headers",
2248
                              mainwin->messageview->textview->show_all_headers);
2249
        SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2250

    
2251
#undef SET_CHECK_MENU_ACTIVE
2252

    
2253
        main_window_menu_callback_unblock(mainwin);
2254
}
2255

    
2256
void main_window_popup(MainWindow *mainwin)
2257
{
2258
        gtkut_window_popup(mainwin->window);
2259

    
2260
        switch (mainwin->type) {
2261
        case SEPARATE_FOLDER:
2262
                if (prefs_common.folderview_visible)
2263
                        gtkut_window_popup(mainwin->win.sep_folder.folderwin);
2264
                break;
2265
        case SEPARATE_MESSAGE:
2266
                if (messageview_is_visible(mainwin->messageview))
2267
                        gtkut_window_popup(mainwin->win.sep_message.messagewin);
2268
                break;
2269
        case SEPARATE_BOTH:
2270
                if (prefs_common.folderview_visible)
2271
                        gtkut_window_popup(mainwin->win.sep_both.folderwin);
2272
                if (messageview_is_visible(mainwin->messageview))
2273
                        gtkut_window_popup(mainwin->win.sep_both.messagewin);
2274
                break;
2275
        default:
2276
                break;
2277
        }
2278
}
2279

    
2280
static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout,
2281
                                    SeparateType type)
2282
{
2283
        GtkWidget *folderwin = NULL;
2284
        GtkWidget *messagewin = NULL;
2285
        GtkWidget *hpaned;
2286
        GtkWidget *vpaned;
2287
        GtkWidget *vbox_body = mainwin->vbox_body;
2288
        GtkWidget *vbox_summary;
2289
        GtkItemFactory *ifactory = mainwin->menu_factory;
2290
        GtkWidget *menuitem;
2291
        gboolean use_vlayout = (layout == LAYOUT_VERTICAL);
2292

    
2293
        debug_print("Setting main window widgets...\n");
2294

    
2295
        gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2296
                                    prefs_common.folderview_width,
2297
                                    prefs_common.folderview_height);
2298
        if (use_vlayout) {
2299
                gtk_widget_set_size_request
2300
                        (GTK_WIDGET_PTR(mainwin->summaryview),
2301
                         prefs_common.summaryview_vwidth,
2302
                         prefs_common.summaryview_vheight);
2303
                gtk_widget_set_size_request
2304
                        (GTK_WIDGET_PTR(mainwin->messageview),
2305
                         prefs_common.msgview_vwidth,
2306
                         prefs_common.msgview_vheight);
2307
        } else {
2308
                gtk_widget_set_size_request
2309
                        (GTK_WIDGET_PTR(mainwin->summaryview),
2310
                         prefs_common.summaryview_width,
2311
                         prefs_common.summaryview_height);
2312
                gtk_widget_set_size_request
2313
                        (GTK_WIDGET_PTR(mainwin->messageview),
2314
                         prefs_common.msgview_width,
2315
                         prefs_common.msgview_height);
2316
        }
2317

    
2318
        /* create separated window(s) if needed */
2319
        if (type & SEPARATE_FOLDER) {
2320
                folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2321
                gtk_window_set_title(GTK_WINDOW(folderwin),
2322
                                     _("Sylpheed - Folder View"));
2323
                gtk_window_set_wmclass(GTK_WINDOW(folderwin),
2324
                                       "folder_view", "Sylpheed");
2325
                gtk_window_set_policy(GTK_WINDOW(folderwin),
2326
                                      TRUE, TRUE, FALSE);
2327
                gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
2328
                                         prefs_common.folderwin_y);
2329
                gtk_container_set_border_width(GTK_CONTAINER(folderwin), 0);
2330
                g_signal_connect(G_OBJECT(folderwin), "delete_event",
2331
                                 G_CALLBACK(folder_window_close_cb), mainwin);
2332
                gtk_container_add(GTK_CONTAINER(folderwin),
2333
                                  GTK_WIDGET_PTR(mainwin->folderview));
2334
                gtk_widget_realize(folderwin);
2335
                if (prefs_common.folderview_visible)
2336
                        gtk_widget_show(folderwin);
2337
        }
2338
        if (type & SEPARATE_MESSAGE) {
2339
                messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2340
                gtk_window_set_title(GTK_WINDOW(messagewin),
2341
                                     _("Sylpheed - Message View"));
2342
                gtk_window_set_wmclass(GTK_WINDOW(messagewin),
2343
                                       "message_view", "Sylpheed");
2344
                gtk_window_set_policy(GTK_WINDOW(messagewin),
2345
                                      TRUE, TRUE, FALSE);
2346
                gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
2347
                                         prefs_common.main_msgwin_y);
2348
                gtk_container_set_border_width(GTK_CONTAINER(messagewin), 0);
2349
                g_signal_connect(G_OBJECT(messagewin), "delete_event",
2350
                                 G_CALLBACK(message_window_close_cb), mainwin);
2351
                gtk_container_add(GTK_CONTAINER(messagewin),
2352
                                  GTK_WIDGET_PTR(mainwin->messageview));
2353
                gtk_widget_realize(messagewin);
2354
                if (messageview_is_visible(mainwin->messageview))
2355
                        gtk_widget_show(messagewin);
2356
        }
2357

    
2358
        vbox_summary = gtk_vbox_new(FALSE, 1);
2359
        gtk_box_pack_start(GTK_BOX(vbox_summary),
2360
                           GTK_WIDGET_PTR(mainwin->summaryview->qsearch),
2361
                           FALSE, FALSE, 0);
2362
        gtk_widget_show(vbox_summary);
2363

    
2364
        switch (type) {
2365
        case SEPARATE_NONE:
2366
                hpaned = gtk_hpaned_new();
2367
                gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2368
                gtk_paned_add1(GTK_PANED(hpaned),
2369
                               GTK_WIDGET_PTR(mainwin->folderview));
2370
                gtk_paned_add2(GTK_PANED(hpaned), vbox_summary);
2371
                gtk_widget_show(hpaned);
2372
                gtk_widget_queue_resize(hpaned);
2373

    
2374
                if (use_vlayout) {
2375
                        vpaned = gtk_hpaned_new();
2376
                        gtk_widget_hide(mainwin->summaryview->hseparator);
2377
                } else
2378
                        vpaned = gtk_vpaned_new();
2379
                if (messageview_is_visible(mainwin->messageview)) {
2380
                        gtk_paned_add1(GTK_PANED(vpaned),
2381
                                       GTK_WIDGET_PTR(mainwin->summaryview));
2382
                        gtk_box_pack_start(GTK_BOX(vbox_summary), vpaned,
2383
                                           TRUE, TRUE, 0);
2384
                        if (!use_vlayout)
2385
                                gtk_widget_show
2386
                                        (mainwin->summaryview->hseparator);
2387
                } else {
2388
                        gtk_box_pack_start(GTK_BOX(vbox_summary),
2389
                                           GTK_WIDGET_PTR(mainwin->summaryview),
2390
                                           TRUE, TRUE, 0);
2391
                        gtk_widget_ref(vpaned);
2392
                        gtk_widget_hide(mainwin->summaryview->hseparator);
2393
                }
2394
                gtk_paned_add2(GTK_PANED(vpaned),
2395
                               GTK_WIDGET_PTR(mainwin->messageview));
2396
                gtk_widget_show(vpaned);
2397
                gtk_widget_queue_resize(vpaned);
2398

    
2399
                mainwin->win.sep_none.hpaned = hpaned;
2400
                mainwin->win.sep_none.vpaned = vpaned;
2401

    
2402
                break;
2403
        case SEPARATE_FOLDER:
2404
                gtk_box_pack_start(GTK_BOX(vbox_body), vbox_summary,
2405
                                   TRUE, TRUE, 0);
2406

    
2407
                if (use_vlayout) {
2408
                        vpaned = gtk_hpaned_new();
2409
                        gtk_widget_hide(mainwin->summaryview->hseparator);
2410
                } else
2411
                        vpaned = gtk_vpaned_new();
2412
                if (messageview_is_visible(mainwin->messageview)) {
2413
                        gtk_paned_add1(GTK_PANED(vpaned),
2414
                                       GTK_WIDGET_PTR(mainwin->summaryview));
2415
                        gtk_box_pack_start(GTK_BOX(vbox_summary), vpaned,
2416
                                           TRUE, TRUE, 0);
2417
                        if (!use_vlayout)
2418
                                gtk_widget_show
2419
                                        (mainwin->summaryview->hseparator);
2420
                } else {
2421
                        gtk_box_pack_start(GTK_BOX(vbox_summary),
2422
                                           GTK_WIDGET_PTR(mainwin->summaryview),
2423
                                           TRUE, TRUE, 0);
2424
                        gtk_widget_ref(vpaned);
2425
                        gtk_widget_hide(mainwin->summaryview->hseparator);
2426
                }
2427
                gtk_paned_add2(GTK_PANED(vpaned),
2428
                               GTK_WIDGET_PTR(mainwin->messageview));
2429
                gtk_widget_show(vpaned);
2430
                gtk_widget_queue_resize(vpaned);
2431

    
2432
                mainwin->win.sep_folder.folderwin = folderwin;
2433
                mainwin->win.sep_folder.vpaned    = vpaned;
2434

    
2435
                break;
2436
        case SEPARATE_MESSAGE:
2437
                hpaned = gtk_hpaned_new();
2438
                gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2439
                gtk_paned_add1(GTK_PANED(hpaned),
2440
                               GTK_WIDGET_PTR(mainwin->folderview));
2441
                gtk_paned_add2(GTK_PANED(hpaned), vbox_summary);
2442
                gtk_box_pack_start(GTK_BOX(vbox_summary),
2443
                                   GTK_WIDGET_PTR(mainwin->summaryview),
2444
                                   TRUE, TRUE, 0);
2445
                gtk_widget_hide(mainwin->summaryview->hseparator);
2446
                gtk_widget_show(hpaned);
2447
                gtk_widget_queue_resize(hpaned);
2448

    
2449
                mainwin->win.sep_message.messagewin = messagewin;
2450
                mainwin->win.sep_message.hpaned     = hpaned;
2451

    
2452
                break;
2453
        case SEPARATE_BOTH:
2454
                gtk_box_pack_start(GTK_BOX(vbox_body), vbox_summary,
2455
                                   TRUE, TRUE, 0);
2456
                gtk_box_pack_start(GTK_BOX(vbox_summary),
2457
                                   GTK_WIDGET_PTR(mainwin->summaryview),
2458
                                   TRUE, TRUE, 0);
2459
                gtk_widget_hide(mainwin->summaryview->hseparator);
2460

    
2461
                mainwin->win.sep_both.folderwin = folderwin;
2462
                mainwin->win.sep_both.messagewin = messagewin;
2463

    
2464
                break;
2465
        }
2466

    
2467
        if (messageview_is_visible(mainwin->messageview))
2468
                gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2469
                              use_vlayout ? GTK_ARROW_RIGHT : GTK_ARROW_DOWN,
2470
                              GTK_SHADOW_OUT);
2471
        else
2472
                gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2473
                              use_vlayout ? GTK_ARROW_LEFT : GTK_ARROW_UP,
2474
                              GTK_SHADOW_OUT);
2475

    
2476
        gtk_widget_set_uposition(mainwin->window,
2477
                                 prefs_common.mainwin_x,
2478
                                 prefs_common.mainwin_y);
2479

    
2480
        gtk_widget_queue_resize(vbox_body);
2481
        gtk_widget_queue_resize(mainwin->vbox);
2482
        gtk_widget_queue_resize(mainwin->window);
2483

    
2484
        mainwin->type = type;
2485
        prefs_common.layout_type = layout;
2486

    
2487
        /* toggle menu state */
2488
        menuitem = gtk_item_factory_get_item
2489
                (ifactory, "/View/Show or hide/Folder tree");
2490
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2491
                                       (type & SEPARATE_FOLDER) == 0 ? TRUE :
2492
                                       prefs_common.folderview_visible);
2493
        gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2494
        menuitem = gtk_item_factory_get_item
2495
                (ifactory, "/View/Show or hide/Message view");
2496
        gtk_check_menu_item_set_active
2497
                (GTK_CHECK_MENU_ITEM(menuitem),
2498
                 messageview_is_visible(mainwin->messageview));
2499

    
2500
        if (layout == LAYOUT_NORMAL) {
2501
                menuitem = gtk_item_factory_get_item
2502
                        (ifactory, "/View/Layout/Normal");
2503
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2504
                                               TRUE);
2505
        } else if (layout == LAYOUT_VERTICAL) {
2506
                menuitem = gtk_item_factory_get_item
2507
                        (ifactory, "/View/Layout/Vertical");
2508
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2509
                                               TRUE);
2510
        }
2511

    
2512
        menuitem = gtk_item_factory_get_item
2513
                (ifactory, "/View/Separate folder tree");
2514
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2515
                                       ((type & SEPARATE_FOLDER) != 0));
2516
        menuitem = gtk_item_factory_get_item
2517
                (ifactory, "/View/Separate message view");
2518
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2519
                                       ((type & SEPARATE_MESSAGE) != 0));
2520

    
2521
        if (folderwin) {
2522
                g_signal_connect
2523
                        (G_OBJECT(folderwin), "size_allocate",
2524
                         G_CALLBACK(folder_window_size_allocate_cb), mainwin);
2525
        }
2526
        if (messagewin) {
2527
                g_signal_connect
2528
                        (G_OBJECT(messagewin), "size_allocate",
2529
                         G_CALLBACK(message_window_size_allocate_cb), mainwin);
2530
        }
2531

    
2532
        debug_print("done.\n");
2533
}
2534

    
2535
static GtkItemFactoryEntry reply_entries[] =
2536
{
2537
        {N_("/_Reply"),                        NULL, reply_cb, COMPOSE_REPLY, NULL},
2538
        {N_("/Reply to _all"),                NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
2539
        {N_("/Reply to _sender"),        NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
2540
        {N_("/Reply to mailing _list"),        NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL}
2541
};
2542

    
2543
static GtkItemFactoryEntry forward_entries[] =
2544
{
2545
        {N_("/_Forward"),                NULL, reply_cb, COMPOSE_FORWARD, NULL},
2546
        {N_("/For_ward as attachment"), NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
2547
        {N_("/Redirec_t"),                NULL, reply_cb, COMPOSE_REDIRECT, NULL}
2548
};
2549

    
2550
static PrefsToolbarItem items[] =
2551
{
2552
        {T_GET,                        TRUE,        toolbar_inc_cb},
2553
        {T_GET_ALL,                TRUE,        toolbar_inc_all_cb},
2554
        {T_SEND_QUEUE,                TRUE,        toolbar_send_cb},
2555
        {T_COMPOSE,                TRUE,        toolbar_compose_cb},
2556
        {T_REPLY,                TRUE,        toolbar_reply_cb},
2557
        {T_REPLY_ALL,                TRUE,        toolbar_reply_to_all_cb},
2558
        {T_FORWARD,                TRUE,        toolbar_forward_cb},
2559
        {T_DELETE,                FALSE,        toolbar_delete_cb},
2560
        {T_JUNK,                TRUE,        toolbar_junk_cb},
2561
        {T_NOTJUNK,                FALSE,        toolbar_notjunk_cb},
2562
        {T_NEXT,                FALSE,        toolbar_next_unread_cb},
2563
        {T_PREV,                FALSE,        toolbar_prev_unread_cb},
2564
        {T_SEARCH,                FALSE,        toolbar_search_cb},
2565
        {T_PRINT,                FALSE,        toolbar_print_cb},
2566
        {T_STOP,                FALSE,        toolbar_stop_cb},
2567
        {T_ADDRESS_BOOK,        FALSE,        toolbar_address_cb},
2568
        {T_EXECUTE,                FALSE,        toolbar_exec_cb},
2569
        {T_COMMON_PREFS,        FALSE,        toolbar_prefs_common_cb},
2570
        {T_ACCOUNT_PREFS,        FALSE,        toolbar_prefs_account_cb},
2571
        {T_REMOTE_MAILBOX,        FALSE,        toolbar_rpop3_cb},
2572

    
2573
        {-1, FALSE, NULL}
2574
};
2575

    
2576
static GtkWidget *main_window_toolbar_create(MainWindow *mainwin)
2577
{
2578
        GtkWidget *toolbar;
2579
        const gchar *setting;
2580
        GList *item_list;
2581

    
2582
        if (prefs_common.main_toolbar_setting &&
2583
            *prefs_common.main_toolbar_setting != '\0')
2584
                setting = prefs_common.main_toolbar_setting;
2585
        else
2586
                setting = prefs_toolbar_get_default_main_setting_name_list();
2587

    
2588
        item_list = prefs_toolbar_get_item_list_from_name_list(setting);
2589
        toolbar = main_window_toolbar_create_from_list(mainwin, item_list);
2590
        g_list_free(item_list);
2591

    
2592
        return toolbar;
2593
}
2594

    
2595
static GtkWidget *main_window_toolbar_create_from_list(MainWindow *mainwin,
2596
                                                       GList *item_list)
2597
{
2598
        GtkWidget *toolbar;
2599
        GtkWidget *icon_wid;
2600
        GtkToolItem *toolitem;
2601
        GtkToolItem *comboitem;
2602
        ComboButton *combo;
2603
        gint n_entries;
2604
        gint i;
2605
        GList *cur;
2606

    
2607
        toolbar = gtk_toolbar_new();
2608
        gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
2609
                                    GTK_ORIENTATION_HORIZONTAL);
2610
        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
2611
        g_signal_connect(G_OBJECT(toolbar), "button_press_event",
2612
                         G_CALLBACK(toolbar_button_pressed), mainwin);
2613

    
2614
        items[0].data = &mainwin->get_btn;
2615
        items[1].data = &mainwin->getall_btn;
2616
        items[2].data = &mainwin->send_btn;
2617
        items[3].data = &mainwin->compose_btn;
2618
        items[4].data = &mainwin->reply_btn;
2619
        items[5].data = &mainwin->replyall_btn;
2620
        items[6].data = &mainwin->fwd_btn;
2621
        items[7].data = &mainwin->delete_btn;
2622
        items[8].data = &mainwin->junk_btn;
2623
        items[9].data = &mainwin->notjunk_btn;
2624
        items[10].data = &mainwin->next_btn;
2625
        items[11].data = &mainwin->prev_btn;
2626
        items[12].data = &mainwin->search_btn;
2627
        items[13].data = &mainwin->print_btn;
2628
        items[14].data = &mainwin->stop_btn;
2629
        items[15].data = &mainwin->address_btn;
2630
        items[16].data = &mainwin->exec_btn;
2631
        items[17].data = &mainwin->prefs_common_btn;
2632
        items[18].data = &mainwin->prefs_account_btn;
2633
        items[19].data = &mainwin->rpop3_btn;
2634
        for (i = 0; i <= 19; i++)
2635
                *(GtkWidget **)items[i].data = NULL;
2636
        mainwin->reply_combo = NULL;
2637
        mainwin->fwd_combo = NULL;
2638

    
2639
        for (cur = item_list; cur != NULL; cur = cur->next) {
2640
                const PrefsDisplayItem *ditem = cur->data;
2641
                PrefsToolbarItem *item;
2642
                GtkTooltips *tips;
2643
                gint width;
2644

    
2645
                if (ditem->id == T_SEPARATOR) {
2646
                        toolitem = gtk_separator_tool_item_new();
2647
                        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
2648
                        continue;
2649
                }
2650

    
2651
                for (item = items; item->id != -1; item++) {
2652
                        if (ditem->id == item->id)
2653
                                break;
2654
                }
2655
                if (item->id == -1)
2656
                        continue;
2657

    
2658
                if (ditem->stock_id) {
2659
                        icon_wid = gtk_image_new_from_stock
2660
                                (ditem->stock_id, GTK_ICON_SIZE_LARGE_TOOLBAR);
2661
                } else
2662
                        icon_wid = stock_pixbuf_widget(NULL, ditem->icon);
2663

    
2664
                toolitem = gtk_tool_button_new(icon_wid, gettext(ditem->label));
2665
                if (ditem->description) {
2666
                        tips = gtk_tooltips_new();
2667
                        gtk_tool_item_set_tooltip(toolitem, tips,
2668
                                                  gettext(ditem->description),
2669
                                                  ditem->name);
2670
                }
2671

    
2672
                gtkut_get_str_size(GTK_WIDGET(toolitem), gettext(ditem->label),
2673
                                   &width, NULL);
2674
                gtk_tool_item_set_homogeneous
2675
                        (toolitem, width < 52 ? TRUE : FALSE);
2676
                gtk_tool_item_set_is_important(toolitem, item->is_important);
2677

    
2678
                gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
2679

    
2680
                g_signal_connect(G_OBJECT(toolitem), "clicked",
2681
                                 G_CALLBACK(item->callback), mainwin);
2682
                g_signal_connect(G_OBJECT(GTK_BIN(toolitem)->child),
2683
                                 "button_press_event",
2684
                                 G_CALLBACK(toolbar_button_pressed), mainwin);
2685

    
2686
                if (ditem->id == T_REPLY) {
2687
                        n_entries = sizeof(reply_entries) /
2688
                                sizeof(reply_entries[0]);
2689
                        combo = gtkut_combo_button_create
2690
                                (GTK_WIDGET(toolitem),
2691
                                 reply_entries, n_entries, "<Reply>", mainwin);
2692
                        gtk_button_set_relief(GTK_BUTTON(combo->arrow),
2693
                                              GTK_RELIEF_NONE);
2694

    
2695
                        comboitem = gtk_tool_item_new();
2696
                        gtk_tool_item_set_homogeneous(comboitem, FALSE);
2697
                        gtk_container_add(GTK_CONTAINER(comboitem),
2698
                                          GTK_WIDGET_PTR(combo));
2699
                        if (ditem->description) {
2700
                                tips = gtk_tooltips_new();
2701
                                gtk_tool_item_set_tooltip
2702
                                        (comboitem, tips,
2703
                                         gettext(ditem->description),
2704
                                         ditem->name);
2705
                        }
2706

    
2707
                        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), comboitem, -1);
2708

    
2709
                        mainwin->reply_combo = combo;
2710
                } else if (ditem->id == T_FORWARD) {
2711
                        n_entries = sizeof(forward_entries) /
2712
                                sizeof(forward_entries[0]);
2713
                        combo = gtkut_combo_button_create
2714
                                (GTK_WIDGET(toolitem),
2715
                                 forward_entries, n_entries, "<Forward>",
2716
                                 mainwin);
2717
                        gtk_button_set_relief(GTK_BUTTON(combo->arrow),
2718
                                              GTK_RELIEF_NONE);
2719

    
2720
                        comboitem = gtk_tool_item_new();
2721
                        gtk_tool_item_set_homogeneous(comboitem, FALSE);
2722
                        gtk_container_add(GTK_CONTAINER(comboitem),
2723
                                          GTK_WIDGET_PTR(combo));
2724
                        if (ditem->description) {
2725
                                tips = gtk_tooltips_new();
2726
                                gtk_tool_item_set_tooltip
2727
                                        (comboitem, tips,
2728
                                         gettext(ditem->description),
2729
                                         ditem->name);
2730
                        }
2731

    
2732
                        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), comboitem, -1);
2733

    
2734
                        mainwin->fwd_combo = combo;
2735
                }
2736

    
2737
                *(GtkWidget **)item->data = GTK_WIDGET(toolitem);
2738
        }
2739

    
2740
        gtk_widget_show_all(toolbar);
2741

    
2742
        return toolbar;
2743
}
2744

    
2745
static void main_window_toolbar_toggle_menu_set_active(MainWindow *mainwin,
2746
                                                       ToolbarStyle style)
2747
{
2748
        GtkWidget *menuitem = NULL;
2749
        GtkItemFactory *ifactory = mainwin->menu_factory;
2750

    
2751
        switch (style) {
2752
        case TOOLBAR_NONE:
2753
                menuitem = gtk_item_factory_get_item
2754
                        (ifactory, "/View/Show or hide/Toolbar/None");
2755
                break;
2756
        case TOOLBAR_ICON:
2757
                menuitem = gtk_item_factory_get_item
2758
                        (ifactory, "/View/Show or hide/Toolbar/Icon");
2759
                break;
2760
        case TOOLBAR_TEXT:
2761
                menuitem = gtk_item_factory_get_item
2762
                        (ifactory, "/View/Show or hide/Toolbar/Text");
2763
                break;
2764
        case TOOLBAR_BOTH:
2765
                menuitem = gtk_item_factory_get_item
2766
                        (ifactory, "/View/Show or hide/Toolbar/Icon and text");
2767
                break;
2768
        case TOOLBAR_BOTH_HORIZ:
2769
                menuitem = gtk_item_factory_get_item
2770
                        (ifactory, "/View/Show or hide/Toolbar/Text at the right of icon");
2771
                break;
2772
        }
2773

    
2774
        if (menuitem)
2775
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2776
                                               TRUE);
2777
}
2778

    
2779
/* callback functions */
2780

    
2781
static void toolbar_inc_cb        (GtkWidget        *widget,
2782
                                 gpointer         data)
2783
{
2784
        MainWindow *mainwin = (MainWindow *)data;
2785

    
2786
        inc_mail_cb(mainwin, 0, NULL);
2787
}
2788

    
2789
static void toolbar_inc_all_cb        (GtkWidget        *widget,
2790
                                 gpointer         data)
2791
{
2792
        MainWindow *mainwin = (MainWindow *)data;
2793

    
2794
        inc_all_account_mail_cb(mainwin, 0, NULL);
2795
}
2796

    
2797
static void toolbar_rpop3_cb        (GtkWidget        *widget,
2798
                                 gpointer         data)
2799
{
2800
        MainWindow *mainwin = (MainWindow *)data;
2801

    
2802
        rpop3_cb(mainwin, 0, NULL);
2803
}
2804

    
2805
static void toolbar_send_cb        (GtkWidget        *widget,
2806
                                 gpointer         data)
2807
{
2808
        MainWindow *mainwin = (MainWindow *)data;
2809

    
2810
        send_queue_cb(mainwin, 0, NULL);
2811
}
2812

    
2813
static void toolbar_compose_cb        (GtkWidget        *widget,
2814
                                 gpointer         data)
2815
{
2816
        MainWindow *mainwin = (MainWindow *)data;
2817

    
2818
        compose_cb(mainwin, 0, NULL);
2819
}
2820

    
2821
static void toolbar_reply_cb        (GtkWidget        *widget,
2822
                                 gpointer         data)
2823
{
2824
        MainWindow *mainwin = (MainWindow *)data;
2825

    
2826
        if (prefs_common.default_reply_list)
2827
                reply_cb(mainwin, COMPOSE_REPLY_TO_LIST, NULL);
2828
        else
2829
                reply_cb(mainwin, COMPOSE_REPLY, NULL);
2830
}
2831

    
2832
static void toolbar_reply_to_all_cb        (GtkWidget        *widget,
2833
                                         gpointer         data)
2834
{
2835
        MainWindow *mainwin = (MainWindow *)data;
2836

    
2837
        reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
2838
}
2839

    
2840
static void toolbar_forward_cb        (GtkWidget        *widget,
2841
                                 gpointer         data)
2842
{
2843
        MainWindow *mainwin = (MainWindow *)data;
2844

    
2845
        reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2846
}
2847

    
2848
static void toolbar_delete_cb        (GtkWidget        *widget,
2849
                                 gpointer         data)
2850
{
2851
        MainWindow *mainwin = (MainWindow *)data;
2852

    
2853
        summary_delete(mainwin->summaryview);
2854
}
2855

    
2856
static void toolbar_junk_cb        (GtkWidget        *widget,
2857
                                 gpointer         data)
2858
{
2859
        MainWindow *mainwin = (MainWindow *)data;
2860

    
2861
        summary_junk(mainwin->summaryview);
2862
}
2863

    
2864
static void toolbar_notjunk_cb        (GtkWidget        *widget,
2865
                                 gpointer         data)
2866
{
2867
        MainWindow *mainwin = (MainWindow *)data;
2868

    
2869
        summary_not_junk(mainwin->summaryview);
2870
}
2871

    
2872
static void toolbar_exec_cb        (GtkWidget        *widget,
2873
                                 gpointer         data)
2874
{
2875
        MainWindow *mainwin = (MainWindow *)data;
2876

    
2877
        summary_execute(mainwin->summaryview);
2878
}
2879

    
2880
static void toolbar_next_unread_cb        (GtkWidget        *widget,
2881
                                         gpointer         data)
2882
{
2883
        MainWindow *mainwin = (MainWindow *)data;
2884

    
2885
        next_unread_cb(mainwin, 0, NULL);
2886
}
2887

    
2888
static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
2889
{
2890
        MainWindow *mainwin = (MainWindow *)data;
2891

    
2892
        prev_unread_cb(mainwin, 0, NULL);
2893
}
2894

    
2895
static void toolbar_address_cb(GtkWidget *widget, gpointer data)
2896
{
2897
        MainWindow *mainwin = (MainWindow *)data;
2898

    
2899
        addressbook_open_cb(mainwin, 0, NULL);
2900
}
2901

    
2902
static void toolbar_search_cb(GtkWidget *widget, gpointer data)
2903
{
2904
        MainWindow *mainwin = (MainWindow *)data;
2905

    
2906
        search_cb(mainwin, 1, NULL);
2907
}
2908

    
2909
static void toolbar_print_cb(GtkWidget *widget, gpointer data)
2910
{
2911
        MainWindow *mainwin = (MainWindow *)data;
2912

    
2913
        print_cb(mainwin, 0, NULL);
2914
}
2915

    
2916
static void toolbar_stop_cb(GtkWidget *widget, gpointer data)
2917
{
2918
        MainWindow *mainwin = (MainWindow *)data;
2919

    
2920
        inc_stop_cb(mainwin, 0, NULL);
2921
}
2922

    
2923
static void toolbar_prefs_common_cb(GtkWidget *widget, gpointer data)
2924
{
2925
        MainWindow *mainwin = (MainWindow *)data;
2926

    
2927
        prefs_common_open_cb(mainwin, 0, NULL);
2928
}
2929

    
2930
static void toolbar_prefs_account_cb(GtkWidget *widget, gpointer data)
2931
{
2932
        MainWindow *mainwin = (MainWindow *)data;
2933

    
2934
        prefs_account_open_cb(mainwin, 0, NULL);
2935
}
2936

    
2937
static void toolbar_toggle(GtkWidget *widget, gpointer data)
2938
{
2939
        MainWindow *mainwin = (MainWindow *)data;
2940
        ToolbarStyle style;
2941

    
2942
        if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
2943
                return;
2944

    
2945
        style = (ToolbarStyle)g_object_get_data(G_OBJECT(widget), MENU_VAL_ID);
2946
        main_window_toolbar_toggle_menu_set_active(mainwin, style);
2947
}
2948

    
2949
static void toolbar_customize(GtkWidget *widget, gpointer data)
2950
{
2951
        MainWindow *mainwin = (MainWindow *)data;
2952
        gint *visible_items;
2953
        GList *item_list = NULL;
2954
        GtkWidget *toolbar;
2955
        gint ret;
2956
        const gchar *setting;
2957

    
2958
        if (prefs_common.main_toolbar_setting &&
2959
            *prefs_common.main_toolbar_setting != '\0')
2960
                setting = prefs_common.main_toolbar_setting;
2961
        else
2962
                setting = prefs_toolbar_get_default_main_setting_name_list();
2963
        visible_items = prefs_toolbar_get_id_list_from_name_list(setting);
2964
        ret = prefs_toolbar_open(TOOLBAR_MAIN, visible_items, &item_list);
2965
        g_free(visible_items);
2966

    
2967
        if (ret == 0) {
2968
                gtk_widget_destroy(mainwin->toolbar);
2969
                toolbar = main_window_toolbar_create_from_list(mainwin,
2970
                                                               item_list);
2971
                gtk_widget_set_size_request(toolbar, 300, -1);
2972
                gtk_box_pack_start(GTK_BOX(mainwin->vbox), toolbar,
2973
                                   FALSE, FALSE, 0);
2974
                gtk_box_reorder_child(GTK_BOX(mainwin->vbox), toolbar, 1);
2975
                mainwin->toolbar = toolbar;
2976
                main_window_set_toolbar_sensitive(mainwin);
2977
                main_window_set_toolbar_button_visibility(mainwin);
2978
                g_free(prefs_common.main_toolbar_setting);
2979
                prefs_common.main_toolbar_setting =
2980
                        prefs_toolbar_get_name_list_from_item_list(item_list);
2981
                g_list_free(item_list);
2982
                prefs_common_write_config();
2983
        }
2984
}
2985

    
2986
static gboolean toolbar_button_pressed(GtkWidget *widget, GdkEventButton *event,
2987
                                       gpointer data)
2988
{
2989
        MainWindow *mainwin = (MainWindow *)data;
2990
        GtkWidget *menu;
2991
        GtkWidget *menuitem;
2992

    
2993
        if (!event) return FALSE;
2994
        if (event->button != 3) return FALSE;
2995

    
2996
        menu = gtk_menu_new();
2997
        gtk_widget_show(menu);
2998

    
2999
#define SET_TOOLBAR_MENU(text, style, widget)                                \
3000
{                                                                        \
3001
        MENUITEM_ADD_RADIO(menu, menuitem, widget, text, style);        \
3002
        if (prefs_common.toolbar_style == style)                        \
3003
                gtk_check_menu_item_set_active                                \
3004
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);                \
3005
        g_signal_connect(G_OBJECT(menuitem), "activate",                \
3006
                         G_CALLBACK(toolbar_toggle), mainwin);                \
3007
}
3008

    
3009
        SET_TOOLBAR_MENU(_("Icon _and text"), TOOLBAR_BOTH, NULL);
3010
        SET_TOOLBAR_MENU(_("Text at the _right of icon"), TOOLBAR_BOTH_HORIZ,
3011
                         menuitem);
3012
        SET_TOOLBAR_MENU(_("_Icon"), TOOLBAR_ICON, menuitem);
3013
        SET_TOOLBAR_MENU(_("_Text"), TOOLBAR_TEXT, menuitem);
3014
        SET_TOOLBAR_MENU(_("_None"), TOOLBAR_NONE, menuitem);
3015
        MENUITEM_ADD(menu, menuitem, NULL, NULL);
3016
        MENUITEM_ADD_WITH_MNEMONIC(menu, menuitem, _("_Customize toolbar..."),
3017
                                   0);
3018
        g_signal_connect(G_OBJECT(menuitem), "activate",
3019
                         G_CALLBACK(toolbar_customize), mainwin);
3020

    
3021
        g_signal_connect(G_OBJECT(menu), "selection_done",
3022
                         G_CALLBACK(gtk_widget_destroy), NULL);
3023

    
3024
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
3025
                       event->button, event->time);
3026

    
3027
        return TRUE;
3028
}
3029

    
3030
static void online_switch_clicked(GtkWidget *widget, gpointer data)
3031
{
3032
        MainWindow *mainwin = (MainWindow *)data;
3033
        GtkWidget *menuitem;
3034

    
3035
        menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
3036
                                             "/File/Work offline");
3037

    
3038
        if (prefs_common.online_mode == TRUE) {
3039
                prefs_common.online_mode = FALSE;
3040
                gtk_widget_hide(mainwin->online_pixmap);
3041
                gtk_widget_show(mainwin->offline_pixmap);
3042
                gtk_tooltips_set_tip
3043
                        (mainwin->online_tip, mainwin->online_switch,
3044
                         _("You are offline. Click the icon to go online."),
3045
                         NULL);
3046
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3047
                                               TRUE);
3048
                inc_autocheck_timer_remove();
3049
        } else {
3050
                prefs_common.online_mode = TRUE;
3051
                gtk_widget_hide(mainwin->offline_pixmap);
3052
                gtk_widget_show(mainwin->online_pixmap);
3053
                gtk_tooltips_set_tip
3054
                        (mainwin->online_tip, mainwin->online_switch,
3055
                         _("You are online. Click the icon to go offline."),
3056
                         NULL);
3057
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3058
                                               FALSE);
3059
                inc_autocheck_timer_set();
3060
        }
3061
}
3062

    
3063
static gboolean ac_label_button_pressed(GtkWidget *widget,
3064
                                        GdkEventButton *event, gpointer data)
3065
{
3066
        MainWindow *mainwin = (MainWindow *)data;
3067

    
3068
        if (!event) return FALSE;
3069

    
3070
        gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3071
        g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button", widget);
3072

    
3073
        gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3074
                       menu_button_position, widget,
3075
                       event->button, event->time);
3076

    
3077
        return TRUE;
3078
}
3079

    
3080
static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
3081
{
3082
        MainWindow *mainwin = (MainWindow *)data;
3083
        GtkWidget *button;
3084

    
3085
        button = g_object_get_data(G_OBJECT(menu_shell), "menu_button");
3086
        if (!button) return;
3087
        gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
3088
        g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button", NULL);
3089
        manage_window_focus_in(mainwin->window, NULL, NULL);
3090
}
3091

    
3092
static gboolean main_window_key_pressed(GtkWidget *widget, GdkEventKey *event,
3093
                                        gpointer data)
3094
{
3095
        MainWindow *mainwin = (MainWindow *)data;
3096

    
3097
        if (!mainwin)
3098
                return FALSE;
3099

    
3100
        if (!GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->qsearch->entry))
3101
                return FALSE;
3102

    
3103
        /* g_print("keyval: %d, state: %d\n", event->keyval, event->state); */
3104
        if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
3105
                return FALSE;
3106
        if (event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab ||
3107
            event->keyval == GDK_ISO_Left_Tab)
3108
                return FALSE;
3109

    
3110
        gtk_window_propagate_key_event(GTK_WINDOW(widget), event);
3111

    
3112
        return TRUE;
3113
}
3114

    
3115
static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3116
                                 gpointer data)
3117
{
3118
        MainWindow *mainwin = (MainWindow *)data;
3119

    
3120
        if (mainwin->lock_count == 0)
3121
                app_exit_cb(data, 0, widget);
3122

    
3123
        return TRUE;
3124
}
3125

    
3126
static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3127
                                   gpointer data)
3128
{
3129
        MainWindow *mainwin = (MainWindow *)data;
3130
        GtkWidget *menuitem;
3131

    
3132
        menuitem = gtk_item_factory_get_item
3133
                (mainwin->menu_factory, "/View/Show or hide/Folder tree");
3134
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3135

    
3136
        return TRUE;
3137
}
3138

    
3139
static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3140
                                    gpointer data)
3141
{
3142
        MainWindow *mainwin = (MainWindow *)data;
3143
        GtkWidget *menuitem;
3144

    
3145
        menuitem = gtk_item_factory_get_item
3146
                (mainwin->menu_factory, "/View/Show or hide/Message view");
3147
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3148

    
3149
        return TRUE;
3150
}
3151

    
3152
static void main_window_size_allocate_cb(GtkWidget *widget,
3153
                                         GtkAllocation *allocation,
3154
                                         gpointer data)
3155
{
3156
        MainWindow *mainwin = (MainWindow *)data;
3157

    
3158
        main_window_get_size(mainwin);
3159
}
3160

    
3161
static void folder_window_size_allocate_cb(GtkWidget *widget,
3162
                                           GtkAllocation *allocation,
3163
                                           gpointer data)
3164
{
3165
        MainWindow *mainwin = (MainWindow *)data;
3166

    
3167
        main_window_get_size(mainwin);
3168
}
3169

    
3170
static void message_window_size_allocate_cb(GtkWidget *widget,
3171
                                            GtkAllocation *allocation,
3172
                                            gpointer data)
3173
{
3174
        MainWindow *mainwin = (MainWindow *)data;
3175

    
3176
        main_window_get_size(mainwin);
3177
}
3178

    
3179
static gboolean main_window_window_state_cb(GtkWidget *widget,
3180
                                            GdkEventWindowState *event,
3181
                                            gpointer data)
3182
{
3183
        MainWindow *mainwin = (MainWindow *)data;
3184

    
3185
        if ((event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) != 0) {
3186
                if ((event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0)
3187
                        prefs_common.mainwin_maximized = TRUE;
3188
                else
3189
                        prefs_common.mainwin_maximized = FALSE;
3190
        }
3191
        if ((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) != 0) {
3192
                if ((event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) != 0)
3193
                        mainwin->window_hidden = TRUE;
3194
                else
3195
                        mainwin->window_hidden = FALSE;
3196
        }
3197
        if ((event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN) != 0) {
3198
                if ((event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN) != 0)
3199
                        mainwin->window_hidden = TRUE;
3200
                else
3201
                        mainwin->window_hidden = FALSE;
3202
        }
3203

    
3204
        if (mainwin->window_hidden &&
3205
            prefs_common.show_trayicon && prefs_common.minimize_to_tray)
3206
                gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), TRUE);
3207
        else if (!mainwin->window_hidden)
3208
                gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
3209

    
3210
        return FALSE;
3211
}
3212

    
3213
static gboolean main_window_visibility_notify_cb(GtkWidget *widget,
3214
                                                 GdkEventVisibility *event,
3215
                                                 gpointer data)
3216
{
3217
        MainWindow *mainwin = (MainWindow *)data;
3218

    
3219
        mainwin->window_obscured =
3220
                (event->state == GDK_VISIBILITY_FULLY_OBSCURED ||
3221
                 event->state == GDK_VISIBILITY_PARTIAL) ? TRUE : FALSE;
3222

    
3223
        return FALSE;
3224
}
3225

    
3226
static void new_folder_cb(MainWindow *mainwin, guint action,
3227
                          GtkWidget *widget)
3228
{
3229
        folderview_new_folder(mainwin->folderview);
3230
}
3231

    
3232
static void rename_folder_cb(MainWindow *mainwin, guint action,
3233
                             GtkWidget *widget)
3234
{
3235
        folderview_rename_folder(mainwin->folderview);
3236
}
3237

    
3238
static void move_folder_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3239
{
3240
        folderview_move_folder(mainwin->folderview);
3241
}
3242

    
3243
static void delete_folder_cb(MainWindow *mainwin, guint action,
3244
                             GtkWidget *widget)
3245
{
3246
        folderview_delete_folder(mainwin->folderview);
3247
}
3248

    
3249
static void add_mailbox_cb(MainWindow *mainwin, guint action,
3250
                           GtkWidget *widget)
3251
{
3252
        main_window_add_mailbox(mainwin);
3253
}
3254

    
3255
static void remove_mailbox_cb(MainWindow *mainwin, guint action,
3256
                              GtkWidget *widget)
3257
{
3258
        folderview_remove_mailbox(mainwin->folderview);
3259
}
3260

    
3261
static void update_folderview_cb(MainWindow *mainwin, guint action,
3262
                                 GtkWidget *widget)
3263
{
3264
        if (action == 0)
3265
                folderview_check_new_selected(mainwin->folderview);
3266
        else
3267
                folderview_check_new_all();
3268
}
3269

    
3270
static void rebuild_tree_cb(MainWindow *mainwin, guint action,
3271
                            GtkWidget *widget)
3272
{
3273
        folderview_rebuild_tree(mainwin->folderview);
3274
}
3275

    
3276
static void import_mbox_cb(MainWindow *mainwin, guint action,
3277
                           GtkWidget *widget)
3278
{
3279
        import_mbox(mainwin->summaryview->folder_item);
3280
        main_window_popup(mainwin);
3281
}
3282

    
3283
static void export_mbox_cb(MainWindow *mainwin, guint action,
3284
                           GtkWidget *widget)
3285
{
3286
        export_mbox(mainwin->summaryview->folder_item);
3287
        main_window_popup(mainwin);
3288
}
3289

    
3290
static void empty_trash_cb(MainWindow *mainwin, guint action,
3291
                           GtkWidget *widget)
3292
{
3293
        main_window_empty_trash(mainwin, TRUE);
3294
}
3295

    
3296
static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3297
{
3298
        MessageView *messageview = mainwin->messageview;
3299

    
3300
        if (messageview_get_selected_mime_part(messageview) &&
3301
            GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview))
3302
                mimeview_save_as(messageview->mimeview);
3303
        else
3304
                summary_save_as(mainwin->summaryview);
3305
}
3306

    
3307
#if GTK_CHECK_VERSION(2, 10, 0)
3308
static void page_setup_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3309
{
3310
        printing_page_setup_gtk();
3311
}
3312
#endif
3313

    
3314
static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3315
{
3316
        summary_print(mainwin->summaryview);
3317
}
3318

    
3319
static void toggle_offline_cb(MainWindow *mainwin, guint action,
3320
                              GtkWidget *widget)
3321
{
3322
        main_window_toggle_online
3323
                (mainwin, !GTK_CHECK_MENU_ITEM(widget)->active);
3324
}
3325

    
3326
static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3327
{
3328
        if (prefs_common.confirm_on_exit) {
3329
                if (alertpanel(_("Exit"), _("Exit this program?"),
3330
                               GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
3331
                    != G_ALERTDEFAULT)
3332
                        return;
3333
                manage_window_focus_in(mainwin->window, NULL, NULL);
3334
        }
3335

    
3336
        app_will_exit(FALSE);
3337
}
3338

    
3339
static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3340
{
3341
        if (action == 1) {
3342
                FolderItem *item;
3343

    
3344
                item = folderview_get_selected_item(mainwin->folderview);
3345
                if (item && item->stype == F_VIRTUAL)
3346
                        prefs_search_folder_open(item);
3347
                else
3348
                        query_search(item);
3349
        } else if (action == 2) {
3350
                if (!prefs_common.show_searchbar) {
3351
                        GtkWidget *menuitem;
3352

    
3353
                        menuitem = gtk_item_factory_get_item
3354
                                (mainwin->menu_factory,
3355
                                 "/View/Show or hide/Search bar");
3356
                        gtk_check_menu_item_set_active
3357
                                (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3358
                }
3359
                gtk_widget_grab_focus(mainwin->summaryview->qsearch->entry);
3360
        } else
3361
                message_search(mainwin->messageview);
3362
}
3363

    
3364
static void toggle_folder_cb(MainWindow *mainwin, guint action,
3365
                             GtkWidget *widget)
3366
{
3367
        gboolean active;
3368

    
3369
        active = GTK_CHECK_MENU_ITEM(widget)->active;
3370

    
3371
        switch (mainwin->type) {
3372
        case SEPARATE_NONE:
3373
        case SEPARATE_MESSAGE:
3374
#if 0
3375
                if (active)
3376
                        gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
3377
                else
3378
                        gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
3379
#endif
3380
                break;
3381
        case SEPARATE_FOLDER:
3382
                if (active)
3383
                        gtk_widget_show(mainwin->win.sep_folder.folderwin);
3384
                else
3385
                        gtk_widget_hide(mainwin->win.sep_folder.folderwin);
3386
                break;
3387
        case SEPARATE_BOTH:
3388
                if (active)
3389
                        gtk_widget_show(mainwin->win.sep_both.folderwin);
3390
                else
3391
                        gtk_widget_hide(mainwin->win.sep_both.folderwin);
3392
                break;
3393
        }
3394

    
3395
        prefs_common.folderview_visible = active;
3396
}
3397

    
3398
static void toggle_message_cb(MainWindow *mainwin, guint action,
3399
                              GtkWidget *widget)
3400
{
3401
        gboolean active;
3402

    
3403
        active = GTK_CHECK_MENU_ITEM(widget)->active;
3404

    
3405
        if (active != messageview_is_visible(mainwin->messageview))
3406
                summary_toggle_view(mainwin->summaryview);
3407
}
3408

    
3409
static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3410
                              GtkWidget *widget)
3411
{
3412
        mainwin->toolbar_style = (ToolbarStyle)action;
3413
        prefs_common.toolbar_style = (ToolbarStyle)action;
3414

    
3415
        main_window_set_toolbar_button_visibility(mainwin);
3416
}
3417

    
3418
static void toggle_searchbar_cb(MainWindow *mainwin, guint action,
3419
                                GtkWidget *widget)
3420
{
3421
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
3422
                gtk_widget_show(mainwin->summaryview->qsearch->hbox);
3423
                prefs_common.show_searchbar = TRUE;
3424
        } else {
3425
                gtk_widget_hide(mainwin->summaryview->qsearch->hbox);
3426
                summary_qsearch_reset(mainwin->summaryview);
3427
                prefs_common.show_searchbar = FALSE;
3428
        }
3429
}
3430

    
3431
static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3432
                                GtkWidget *widget)
3433
{
3434
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
3435
                gtk_widget_show(mainwin->statusbar);
3436
                prefs_common.show_statusbar = TRUE;
3437
        } else {
3438
                gtk_widget_hide(mainwin->statusbar);
3439
                prefs_common.show_statusbar = FALSE;
3440
        }
3441
}
3442

    
3443
static void toolbar_customize_cb(MainWindow *mainwin, guint action,
3444
                                 GtkWidget *widget)
3445
{
3446
        toolbar_customize(widget, mainwin);
3447
}
3448

    
3449
static void change_layout_cb(MainWindow *mainwin, guint action,
3450
                             GtkWidget *widget)
3451
{
3452
        LayoutType type = action;
3453

    
3454
        if (GTK_CHECK_MENU_ITEM(widget)->active)
3455
                main_window_change_layout(mainwin, type, mainwin->type);
3456
}
3457

    
3458
static void separate_widget_cb(MainWindow *mainwin, guint action,
3459
                               GtkWidget *widget)
3460
{
3461
        SeparateType type;
3462

    
3463
        if (GTK_CHECK_MENU_ITEM(widget)->active)
3464
                type = mainwin->type | action;
3465
        else
3466
                type = mainwin->type & ~action;
3467

    
3468
        main_window_change_layout(mainwin, prefs_common.layout_type, type);
3469

    
3470
        prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
3471
        prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
3472
}
3473

    
3474
static void addressbook_open_cb(MainWindow *mainwin, guint action,
3475
                                GtkWidget *widget)
3476
{
3477
        addressbook_open(NULL);
3478
}
3479

    
3480
static void log_window_show_cb(MainWindow *mainwin, guint action,
3481
                               GtkWidget *widget)
3482
{
3483
        log_window_show(mainwin->logwin);
3484
}
3485

    
3486
static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3487
{
3488
        inc_mail(mainwin);
3489
}
3490

    
3491
static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
3492
                                    GtkWidget *widget)
3493
{
3494
        inc_all_account_mail(mainwin, FALSE);
3495
}
3496

    
3497
static void inc_stop_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3498
{
3499
        inc_cancel_all();
3500
}
3501

    
3502
static void rpop3_cb(MainWindow        *mainwin, guint action, GtkWidget *widget)
3503
{
3504
        rpop3_account(cur_account);
3505
}
3506

    
3507
static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3508
{
3509
        main_window_send_queue(mainwin);
3510
}
3511

    
3512
static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3513
{
3514
        PrefsAccount *ac = NULL;
3515
        FolderItem *item = mainwin->summaryview->folder_item;
3516

    
3517
        if (item) {
3518
                ac = account_find_from_item(item);
3519
                if (ac && ac->protocol == A_NNTP &&
3520
                    FOLDER_TYPE(item->folder) == F_NEWS) {
3521
                        compose_new(ac, item, item->path, NULL);
3522
                        return;
3523
                }
3524
        }
3525

    
3526
        compose_new(ac, item, NULL, NULL);
3527
}
3528

    
3529
static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3530
{
3531
        summary_reply(mainwin->summaryview, (ComposeMode)action);
3532
}
3533

    
3534
static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3535
{
3536
        summary_move_to(mainwin->summaryview);
3537
}
3538

    
3539
static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3540
{
3541
        summary_copy_to(mainwin->summaryview);
3542
}
3543

    
3544
static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3545
{
3546
        summary_delete(mainwin->summaryview);
3547
}
3548

    
3549
static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3550
{
3551
        summary_open_msg(mainwin->summaryview);
3552
}
3553

    
3554
static void view_source_cb(MainWindow *mainwin, guint action,
3555
                           GtkWidget *widget)
3556
{
3557
        summary_view_source(mainwin->summaryview);
3558
}
3559

    
3560
static void show_all_header_cb(MainWindow *mainwin, guint action,
3561
                               GtkWidget *widget)
3562
{
3563
        if (mainwin->menu_lock_count) return;
3564
        summary_display_msg_selected(mainwin->summaryview, FALSE,
3565
                                     GTK_CHECK_MENU_ITEM(widget)->active);
3566
}
3567

    
3568
static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3569
{
3570
        summary_mark(mainwin->summaryview);
3571
}
3572

    
3573
static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3574
{
3575
        summary_unmark(mainwin->summaryview);
3576
}
3577

    
3578
static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3579
                              GtkWidget *widget)
3580
{
3581
        summary_mark_as_unread(mainwin->summaryview);
3582
}
3583

    
3584
static void mark_as_read_cb(MainWindow *mainwin, guint action,
3585
                            GtkWidget *widget)
3586
{
3587
        summary_mark_as_read(mainwin->summaryview);
3588
}
3589

    
3590
static void mark_thread_as_read_cb(MainWindow *mainwin, guint action,
3591
                                   GtkWidget *widget)
3592
{
3593
        summary_mark_thread_as_read(mainwin->summaryview);
3594
}
3595

    
3596
static void mark_all_read_cb(MainWindow *mainwin, guint action,
3597
                             GtkWidget *widget)
3598
{
3599
        summary_mark_all_read(mainwin->summaryview);
3600
}
3601

    
3602
static void junk_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3603
{
3604
        if (action == 0)
3605
                summary_junk(mainwin->summaryview);
3606
        else
3607
                summary_not_junk(mainwin->summaryview);
3608
}
3609

    
3610
static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3611
{
3612
        summary_reedit(mainwin->summaryview);
3613
}
3614

    
3615
static void add_address_cb(MainWindow *mainwin, guint action,
3616
                           GtkWidget *widget)
3617
{
3618
        summary_add_address(mainwin->summaryview);
3619
}
3620

    
3621
static void set_charset_cb(MainWindow *mainwin, guint action,
3622
                           GtkWidget *widget)
3623
{
3624
        const gchar *str;
3625

    
3626
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
3627
                str = conv_get_charset_str((CharSet)action);
3628
                g_free(prefs_common.force_charset);
3629
                prefs_common.force_charset = str ? g_strdup(str) : NULL;
3630

    
3631
                summary_redisplay_msg(mainwin->summaryview);
3632

    
3633
                debug_print("forced charset: %s\n",
3634
                            str ? str : "Auto-Detect");
3635
        }
3636
}
3637

    
3638
static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3639
{
3640
        if (mainwin->menu_lock_count) return;
3641
        if (!mainwin->summaryview->folder_item) return;
3642

    
3643
        if (GTK_CHECK_MENU_ITEM(widget)->active)
3644
                summary_thread_build(mainwin->summaryview);
3645
        else
3646
                summary_unthread(mainwin->summaryview);
3647
}
3648

    
3649
static void expand_threads_cb(MainWindow *mainwin, guint action,
3650
                              GtkWidget *widget)
3651
{
3652
        summary_expand_threads(mainwin->summaryview);
3653
}
3654

    
3655
static void collapse_threads_cb(MainWindow *mainwin, guint action,
3656
                                GtkWidget *widget)
3657
{
3658
        summary_collapse_threads(mainwin->summaryview);
3659
}
3660

    
3661
static void set_display_item_cb(MainWindow *mainwin, guint action,
3662
                                GtkWidget *widget)
3663
{
3664
        prefs_summary_column_open
3665
                (FOLDER_ITEM_IS_SENT_FOLDER(mainwin->summaryview->folder_item));
3666
}
3667

    
3668
static void sort_summary_cb(MainWindow *mainwin, guint action,
3669
                            GtkWidget *widget)
3670
{
3671
        FolderItem *item = mainwin->summaryview->folder_item;
3672
        GtkWidget *menuitem;
3673

    
3674
        if (mainwin->menu_lock_count) return;
3675

    
3676
        if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3677
                menuitem = gtk_item_factory_get_item
3678
                        (mainwin->menu_factory, "/View/Sort/Ascending");
3679
                summary_sort(mainwin->summaryview, (FolderSortKey)action,
3680
                             GTK_CHECK_MENU_ITEM(menuitem)->active
3681
                             ? SORT_ASCENDING : SORT_DESCENDING);
3682
        }
3683
}
3684

    
3685
static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3686
                                 GtkWidget *widget)
3687
{
3688
        FolderItem *item = mainwin->summaryview->folder_item;
3689

    
3690
        if (mainwin->menu_lock_count) return;
3691

    
3692
        if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3693
                summary_sort(mainwin->summaryview,
3694
                             item->sort_key, (FolderSortType)action);
3695
}
3696

    
3697
static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3698
                                  GtkWidget *widget)
3699
{
3700
        summary_attract_by_subject(mainwin->summaryview);
3701
}
3702

    
3703
static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3704
                                 GtkWidget *widget)
3705
{
3706
        summary_delete_duplicated(mainwin->summaryview);
3707
}
3708

    
3709
static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3710
{
3711
        summary_filter(mainwin->summaryview, (gboolean)action);
3712
}
3713

    
3714
static void filter_junk_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3715
{
3716
        summary_filter_junk(mainwin->summaryview, (gboolean)action);
3717
}
3718

    
3719
static void execute_summary_cb(MainWindow *mainwin, guint action,
3720
                               GtkWidget *widget)
3721
{
3722
        summary_execute(mainwin->summaryview);
3723
}
3724

    
3725
static void update_summary_cb(MainWindow *mainwin, guint action,
3726
                              GtkWidget *widget)
3727
{
3728
        if (!mainwin->summaryview->folder_item) return;
3729

    
3730
        summary_show(mainwin->summaryview, mainwin->summaryview->folder_item,
3731
                     TRUE);
3732
}
3733

    
3734
static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3735
{
3736
        MessageView *messageview = mainwin->messageview;
3737

    
3738
        if (messageview_get_selected_mime_part(messageview) &&
3739
            GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview) &&
3740
            mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_BACKWARD))
3741
                return;
3742

    
3743
        summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3744
}
3745

    
3746
static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3747
{
3748
        MessageView *messageview = mainwin->messageview;
3749

    
3750
        if (messageview_get_selected_mime_part(messageview) &&
3751
            GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview) &&
3752
            mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_FORWARD))
3753
                return;
3754

    
3755
        summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3756
}
3757

    
3758
static void prev_unread_cb(MainWindow *mainwin, guint action,
3759
                           GtkWidget *widget)
3760
{
3761
        summary_select_prev_unread(mainwin->summaryview);
3762
}
3763

    
3764
static void next_unread_cb(MainWindow *mainwin, guint action,
3765
                           GtkWidget *widget)
3766
{
3767
        summary_select_next_unread(mainwin->summaryview);
3768
}
3769

    
3770
static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3771
{
3772
        summary_select_prev_new(mainwin->summaryview);
3773
}
3774

    
3775
static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3776
{
3777
        summary_select_next_new(mainwin->summaryview);
3778
}
3779

    
3780
static void prev_marked_cb(MainWindow *mainwin, guint action,
3781
                           GtkWidget *widget)
3782
{
3783
        summary_select_prev_marked(mainwin->summaryview);
3784
}
3785

    
3786
static void next_marked_cb(MainWindow *mainwin, guint action,
3787
                           GtkWidget *widget)
3788
{
3789
        summary_select_next_marked(mainwin->summaryview);
3790
}
3791

    
3792
static void prev_labeled_cb(MainWindow *mainwin, guint action,
3793
                            GtkWidget *widget)
3794
{
3795
        summary_select_prev_labeled(mainwin->summaryview);
3796
}
3797

    
3798
static void next_labeled_cb(MainWindow *mainwin, guint action,
3799
                            GtkWidget *widget)
3800
{
3801
        summary_select_next_labeled(mainwin->summaryview);
3802
}
3803

    
3804
static void goto_folder_cb(MainWindow *mainwin, guint action,
3805
                           GtkWidget *widget)
3806
{
3807
        FolderItem *to_folder;
3808

    
3809
        to_folder = foldersel_folder_sel_full(NULL, FOLDER_SEL_ALL, NULL,
3810
                                              _("Select folder to open"));
3811

    
3812
        if (to_folder)
3813
                folderview_select(mainwin->folderview, to_folder);
3814
}
3815

    
3816
static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3817
{
3818
        messageview_copy_clipboard(mainwin->messageview);
3819
}
3820

    
3821
static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3822
{
3823
        MessageView *msgview = mainwin->messageview;
3824

    
3825
        if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->treeview))
3826
                summary_select_all(mainwin->summaryview);
3827
        else if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->qsearch->entry))
3828
                gtk_editable_select_region
3829
                        (GTK_EDITABLE(mainwin->summaryview->qsearch->entry),
3830
                         0, -1);
3831
        else if (messageview_is_visible(msgview) &&
3832
                 (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
3833
                  GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3834
                messageview_select_all(msgview);
3835
}
3836

    
3837
static void select_thread_cb(MainWindow *mainwin, guint action,
3838
                             GtkWidget *widget)
3839
{
3840
        summary_select_thread(mainwin->summaryview);
3841
}
3842

    
3843
static void create_filter_cb(MainWindow *mainwin, guint action,
3844
                             GtkWidget *widget)
3845
{
3846
        summary_filter_open(mainwin->summaryview, (FilterCreateType)action);
3847
}
3848

    
3849
static void prefs_common_open_cb(MainWindow *mainwin, guint action,
3850
                                 GtkWidget *widget)
3851
{
3852
        prefs_common_open();
3853
}
3854

    
3855
static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
3856
                                 GtkWidget *widget)
3857
{
3858
        prefs_filter_open(NULL, NULL, NULL);
3859
}
3860

    
3861
static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3862
                                   GtkWidget *widget)
3863
{
3864
        prefs_template_open();
3865
}
3866

    
3867
static void plugin_manager_open_cb(MainWindow *mainwin, guint action,
3868
                                   GtkWidget *widget)
3869
{
3870
        plugin_manager_open();
3871
}
3872

    
3873
#ifndef G_OS_WIN32
3874
static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3875
                                  GtkWidget *widget)
3876
{
3877
        prefs_actions_open(mainwin);
3878
}
3879
#endif
3880

    
3881
static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3882
                                  GtkWidget *widget)
3883
{
3884
        if (!cur_account) {
3885
                new_account_cb(mainwin, 0, widget);
3886
        } else {
3887
                account_open(cur_account);
3888
        }
3889
}
3890

    
3891
static void new_account_cb(MainWindow *mainwin, guint action,
3892
                           GtkWidget *widget)
3893
{
3894
        account_edit_open();
3895
        if (!compose_get_compose_list()) account_add();
3896
}
3897

    
3898
static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3899
{
3900
        MainWindow *mainwin = main_window_get();
3901

    
3902
        cur_account = (PrefsAccount *)data;
3903
        main_window_show_cur_account(mainwin);
3904
        main_window_set_menu_sensitive(mainwin);
3905
        main_window_set_toolbar_sensitive(mainwin);
3906
}
3907

    
3908
static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3909
{
3910
        PrefsAccount *account = (PrefsAccount *)data;
3911

    
3912
        inc_account_mail(main_window_get(), account);
3913
}
3914

    
3915
static void manual_open_cb(MainWindow *mainwin, guint action,
3916
                           GtkWidget *widget)
3917
{
3918
        manual_open((ManualLang)action);
3919
}
3920

    
3921
static void faq_open_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3922
{
3923
        faq_open((ManualLang)action);
3924
}
3925

    
3926
static GtkWidget *help_cmdline_window;
3927

    
3928
static void help_cmdline_ok(GtkWidget *button)
3929
{
3930
        gtk_widget_destroy(gtk_widget_get_toplevel(button));
3931
}
3932

    
3933
static gboolean help_cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event,
3934
                                         gpointer data)
3935
{
3936
        if (event && event->keyval == GDK_Escape) {
3937
                gtk_widget_destroy(widget);
3938
                return TRUE;
3939
        }
3940
        return FALSE;
3941
}
3942

    
3943
static gboolean help_cmdline_deleted(GtkWidget *widget, GdkEventAny *event,
3944
                                     gpointer data)
3945
{
3946
        return FALSE;
3947
}
3948

    
3949
static void help_cmdline_destroyed(GtkWidget *widget, gpointer data)
3950
{
3951
        help_cmdline_window = NULL;
3952
}
3953

    
3954
static void help_command_line_show(void)
3955
{
3956
        GtkWidget *window;
3957
        GtkWidget *vbox;
3958
        GtkWidget *vbox2;
3959
        GtkWidget *hbox;
3960
        GtkWidget *label;
3961
        GtkWidget *hbbox;
3962
        GtkWidget *ok_btn;
3963

    
3964
        if (help_cmdline_window) {
3965
                gtk_window_present(GTK_WINDOW(help_cmdline_window));
3966
                return;
3967
        }
3968

    
3969
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3970
        gtk_window_set_title(GTK_WINDOW(window), _("Command line options"));
3971
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3972
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3973
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
3974
        help_cmdline_window = window;
3975

    
3976
        vbox = gtk_vbox_new(FALSE, 8);
3977
        gtk_container_add(GTK_CONTAINER(window), vbox);
3978

    
3979
        vbox2 = gtk_vbox_new(FALSE, 8);
3980
        gtk_container_set_border_width(GTK_CONTAINER(vbox2), 8);
3981
        gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0);
3982

    
3983
        label = gtk_label_new(_("Usage: sylpheed [OPTION]..."));
3984
        gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
3985
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
3986
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3987

    
3988
        hbox = gtk_hbox_new(FALSE, 16);
3989
        gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
3990

    
3991
        label = gtk_label_new(_("--compose [address]\n"
3992
                                "--attach file1 [file2]...\n"
3993
                                "--receive\n"
3994
                                "--receive-all\n"
3995
                                "--send\n"
3996
                                "--status [folder]...\n"
3997
                                "--status-full [folder]...\n"
3998
                                "--open folderid/msgnum\n"
3999
                                "--configdir dirname\n"
4000
                                "--exit\n"
4001
                                "--debug\n"
4002
                                "--help\n"
4003
                                "--version"));
4004
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4005
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
4006
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4007

    
4008
        label = gtk_label_new(_("open composition window\n"
4009
                                "open composition window with specified files attached\n"
4010
                                "receive new messages\n"
4011
                                "receive new messages of all accounts\n"
4012
                                "send all queued messages\n"
4013
                                "show the total number of messages\n"
4014
                                "show the status of each folder\n"
4015
                                "open message in new window\n"
4016
                                "specify directory which stores configuration files\n"
4017
                                "exit Sylpheed\n"
4018
                                "debug mode\n"
4019
                                "display this help and exit\n"
4020
                                "output version information and exit"));
4021
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4022
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
4023
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4024

    
4025
        gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
4026
                                      NULL, NULL, NULL, NULL);
4027
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
4028
        gtk_widget_grab_default(ok_btn);
4029

    
4030
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
4031
                         G_CALLBACK(help_cmdline_ok), NULL);
4032
        g_signal_connect(G_OBJECT(window), "key_press_event",
4033
                         G_CALLBACK(help_cmdline_key_pressed), NULL);
4034
        g_signal_connect(G_OBJECT(window), "delete_event",
4035
                         G_CALLBACK(help_cmdline_deleted), NULL);
4036
        g_signal_connect(G_OBJECT(window), "destroy",
4037
                         G_CALLBACK(help_cmdline_destroyed), NULL);
4038

    
4039
        gtk_widget_show_all(window);
4040
}
4041

    
4042
static void help_cmdline_cb(MainWindow *mainwin, guint action,
4043
                            GtkWidget *widget)
4044
{
4045
        help_command_line_show();
4046
}
4047

    
4048
static void update_check_cb(MainWindow *mainwin, guint action,
4049
                            GtkWidget *widget)
4050
{
4051
        update_check(TRUE);
4052
}
4053

    
4054
static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4055
{
4056
        MainWindow *mainwin = (MainWindow *)data;
4057
        gchar *str;
4058

    
4059
        if (item->path)
4060
                str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4061
                                      LOCAL_FOLDER(folder)->rootpath,
4062
                                      G_DIR_SEPARATOR,
4063
                                      item->path);
4064
        else
4065
                str = g_strdup_printf(_("Scanning folder %s ..."),
4066
                                      LOCAL_FOLDER(folder)->rootpath);
4067

    
4068
        STATUSBAR_PUSH(mainwin, str);
4069
        STATUSBAR_POP(mainwin);
4070
        g_free(str);
4071
}