Statistics
| Revision:

root / src / mainwindow.c @ 155

History | View | Annotate | Download (95.4 kB)

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