AddressKeeper: improve preferences panel
[claws.git] / src / mainwindow.c
1 /*
2    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3    Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "defs.h"
20
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtk.h>
25 #include <string.h>
26 #include <stdarg.h>
27
28 #include "main.h"
29 #include "mainwindow.h"
30 #include "folderview.h"
31 #include "folder_item_prefs.h"
32 #include "foldersel.h"
33 #include "summaryview.h"
34 #include "summary_search.h"
35 #include "messageview.h"
36 #include "mimeview.h"
37 #include "message_search.h"
38 #include "headerview.h"
39 #include "menu.h"
40 #include "stock_pixmap.h"
41 #include "folder.h"
42 #include "inc.h"
43 #include "log.h"
44 #include "compose.h"
45 #include "procmsg.h"
46 #include "import.h"
47 #include "export.h"
48 #include "edittags.h"
49 #include "prefs_common.h"
50 #include "prefs_actions.h"
51 #include "prefs_filtering.h"
52 #include "prefs_account.h"
53 #include "prefs_summary_column.h"
54 #include "prefs_folder_column.h"
55 #include "prefs_template.h"
56 #include "action.h"
57 #include "account.h"
58 #ifndef USE_NEW_ADDRBOOK
59         #include "addressbook.h"
60 #else
61         #include "addressbook-dbus.h"
62 #endif
63 #include "logwindow.h"
64 #include "manage_window.h"
65 #include "alertpanel.h"
66 #include "statusbar.h"
67 #include "inputdialog.h"
68 #include "utils.h"
69 #include "gtkutils.h"
70 #include "codeconv.h"
71 #include "about.h"
72 #include "manual.h"
73 #include "version.h"
74 #include "ssl_manager.h"
75 #include "sslcertwindow.h"
76 #include "prefs_gtk.h"
77 #include "pluginwindow.h"
78 #include "hooks.h"
79 #include "progressindicator.h"
80 #include "localfolder.h"
81 #include "filtering.h"
82 #include "folderutils.h"
83 #include "foldersort.h"
84 #include "icon_legend.h"
85 #include "colorlabel.h"
86 #include "tags.h"
87 #include "textview.h"
88 #include "imap.h"
89 #include "news.h"
90 #include "socket.h"
91 #include "printing.h"
92 #include "send_message.h"
93 #ifdef G_OS_WIN32
94 #include "w32lib.h"
95 #endif
96
97 #define AC_LABEL_WIDTH  240
98
99 /* list of all instantiated MainWindow */
100 static GList *mainwin_list = NULL;
101
102 static GdkCursor *watch_cursor = NULL;
103 static GdkCursor *hand_cursor = NULL;
104
105 static gint iconified_count = 0;
106
107 static void main_window_menu_callback_block     (MainWindow     *mainwin);
108 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
109
110 static void main_window_show_cur_account        (MainWindow     *mainwin);
111 #ifndef GENERIC_UMPC
112 static void main_window_separation_change       (MainWindow     *mainwin,
113                                                  LayoutType      layout_mode);
114 #endif
115 static void main_window_set_widgets             (MainWindow     *mainwin,
116                                                  LayoutType      layout_mode);
117
118 static void toolbar_child_attached              (GtkWidget      *widget,
119                                                  GtkWidget      *child,
120                                                  gpointer        data);
121 static void toolbar_child_detached              (GtkWidget      *widget,
122                                                  GtkWidget      *child,
123                                                  gpointer        data);
124 #ifndef GENERIC_UMPC
125 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
126                                                  GdkEventButton *event,
127                                                  gpointer        data);
128 #endif
129 static gint main_window_close_cb                (GtkWidget      *widget,
130                                                  GdkEventAny    *event,
131                                                  gpointer        data);
132
133 static void main_window_size_allocate_cb        (GtkWidget      *widget,
134                                                  GtkAllocation  *allocation,
135                                                  gpointer        data);
136 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
137                                                  GtkAllocation  *allocation,
138                                                  gpointer        data);
139 static void message_window_size_allocate_cb     (GtkWidget      *widget,
140                                                  GtkAllocation  *allocation,
141                                                  gpointer        data);
142
143 static void update_folderview_cb (GtkAction     *action,
144                                   gpointer       data);
145 static void add_mailbox_cb       (GtkAction     *action,
146                                   gpointer       data);
147 static void foldersort_cb        (GtkAction     *action,
148                                   gpointer       data);
149 static void import_mbox_cb       (GtkAction     *action,
150                                   gpointer       data);
151 static void export_mbox_cb       (GtkAction     *action,
152                                   gpointer       data);
153 static void export_list_mbox_cb  (GtkAction     *action,
154                                   gpointer       data);
155 static void empty_trash_cb       (GtkAction     *action,
156                                   gpointer       data);
157 static void save_as_cb           (GtkAction     *action,
158                                   gpointer       data);
159 static void page_setup_cb        (GtkAction     *action,
160                                   gpointer       data);
161 static void print_cb             (GtkAction     *action,
162                                   gpointer       data);
163 static void app_exit_cb          (GtkAction     *action,
164                                   gpointer       data);
165
166
167 static void search_cb            (GtkAction     *action,
168                                   gpointer       data);
169 static void search_folder_cb     (GtkAction     *action,
170                                   gpointer       data);
171
172 static void toggle_message_cb    (GtkAction     *action,
173                                   gpointer       data);
174 static void toggle_toolbar_cb    (GtkAction *action, GtkRadioAction *current, gpointer data);
175 static void toggle_col_headers_cb(GtkAction     *action,
176                                   gpointer       data);
177 #ifndef GENERIC_UMPC
178 static void toggle_statusbar_cb  (GtkAction     *action,
179                                   gpointer       data);
180 static void set_layout_cb        (GtkAction *action, GtkRadioAction *current, gpointer data);
181 #endif
182 static void addressbook_open_cb (GtkAction      *action,
183                                   gpointer       data);
184 static void log_window_show_cb  (GtkAction      *action,
185                                   gpointer       data);
186 static void filtering_debug_window_show_cb      (GtkAction      *action,
187                                   gpointer       data);
188
189 static void inc_cancel_cb               (GtkAction      *action,
190                                   gpointer       data);
191 static void send_cancel_cb              (GtkAction      *action,
192                                   gpointer       data);
193
194 static void open_msg_cb                 (GtkAction      *action,
195                                   gpointer       data);
196
197 static void view_source_cb              (GtkAction      *action,
198                                   gpointer       data);
199
200 static void show_all_header_cb          (GtkAction      *action,
201                                   gpointer       data);
202 static void toggle_fullscreen_cb        (GtkAction      *action,
203                                   gpointer       data);
204 static void toggle_menubar_cb   (GtkAction      *action,
205                                   gpointer       data);
206
207 static void hide_quotes_cb(GtkAction    *action,
208                                   gpointer       data);
209
210 static void move_to_cb                  (GtkAction      *action,
211                                   gpointer       data);
212 static void copy_to_cb                  (GtkAction      *action,
213                                   gpointer       data);
214 static void delete_cb                   (GtkAction      *action,
215                                   gpointer       data);
216 static void delete_trash_cb                     (GtkAction      *action,
217                                   gpointer       data);
218
219 static void cancel_cb                   (GtkAction      *action,
220                                   gpointer       data);
221
222 static void mark_cb                     (GtkAction      *action,
223                                   gpointer       data);
224 static void unmark_cb                   (GtkAction      *action,
225                                   gpointer       data);
226
227 static void mark_as_unread_cb           (GtkAction      *action,
228                                   gpointer       data);
229 static void mark_as_read_cb             (GtkAction      *action,
230                                   gpointer       data);
231 static void mark_all_read_cb            (GtkAction      *action,
232                                   gpointer       data);
233 static void mark_as_spam_cb             (GtkAction      *action,
234                                   gpointer       data);
235 static void mark_as_ham_cb              (GtkAction      *action,
236                                   gpointer       data);
237
238 static void ignore_thread_cb            (GtkAction      *action,
239                                   gpointer       data);
240 static void unignore_thread_cb          (GtkAction      *action,
241                                   gpointer       data);
242 static void watch_thread_cb             (GtkAction      *action,
243                                   gpointer       data);
244 static void unwatch_thread_cb           (GtkAction      *action,
245                                   gpointer       data);
246 static void lock_msgs_cb                (GtkAction      *action,
247                                   gpointer       data);
248 static void unlock_msgs_cb              (GtkAction      *action,
249                                   gpointer       data);
250
251 static void reedit_cb                   (GtkAction      *action,
252                                   gpointer       data);
253
254 static void add_address_cb              (GtkAction      *action,
255                                   gpointer       data);
256
257 static void set_charset_cb              (GtkAction *action, GtkRadioAction *current, gpointer data);
258
259 static void set_decode_cb               (GtkAction *action, GtkRadioAction *current, gpointer data);
260
261 static void hide_read_messages   (GtkAction     *action,
262                                   gpointer       data);
263 static void hide_read_threads   (GtkAction      *action,
264                                   gpointer       data);
265 static void hide_del_messages   (GtkAction      *action,
266                                   gpointer       data);
267
268 static void thread_cb            (GtkAction     *action,
269                                   gpointer       data);
270 static void expand_threads_cb    (GtkAction     *action,
271                                   gpointer       data);
272 static void collapse_threads_cb  (GtkAction     *action,
273                                   gpointer       data);
274
275 static void set_summary_display_item_cb  (GtkAction     *action,
276                                   gpointer       data);
277 static void set_folder_display_item_cb   (GtkAction     *action,
278                                   gpointer       data);
279 static void sort_summary_cb      (GtkAction *action, GtkRadioAction *current, gpointer data);
280 static void sort_summary_type_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
281 static void attract_by_subject_cb(GtkAction     *action,
282                                   gpointer       data);
283
284 static void delete_duplicated_cb (GtkAction     *action,
285                                   gpointer       data);
286 static void delete_duplicated_all_cb (GtkAction *action,
287                                   gpointer       data);
288 static void filter_cb            (GtkAction     *action,
289                                   gpointer       data);
290 static void filter_list_cb       (GtkAction     *action,
291                                   gpointer       data);
292 static void process_cb           (GtkAction     *action,
293                                   gpointer       data);
294 static void execute_summary_cb   (GtkAction     *action,
295                                   gpointer       data);
296 static void expunge_summary_cb   (GtkAction     *action,
297                                   gpointer       data);
298 static void update_summary_cb    (GtkAction     *action,
299                                   gpointer       data);
300
301 static void prev_cb              (GtkAction     *action,
302                                   gpointer       data);
303 static void next_cb              (GtkAction     *action,
304                                   gpointer       data);
305 static void next_unread_cb       (GtkAction     *action,
306                                   gpointer       data);
307 static void prev_unread_cb       (GtkAction     *action,
308                                   gpointer       data);
309
310 static void prev_new_cb          (GtkAction     *action,
311                                   gpointer       data);
312 static void next_new_cb          (GtkAction     *action,
313                                   gpointer       data);
314 static void prev_marked_cb       (GtkAction     *action,
315                                   gpointer       data);
316 static void next_marked_cb       (GtkAction     *action,
317                                   gpointer       data);
318 static void prev_labeled_cb      (GtkAction     *action,
319                                   gpointer       data);
320 static void next_labeled_cb      (GtkAction     *action,
321                                   gpointer       data);
322 static void prev_history_cb      (GtkAction     *action,
323                                   gpointer       data);
324 static void next_history_cb      (GtkAction     *action,
325                                   gpointer       data);
326 static void parent_cb            (GtkAction     *action,
327                                   gpointer       data);
328
329 static void goto_folder_cb       (GtkAction     *action,
330                                   gpointer       data);
331 static void goto_unread_folder_cb(GtkAction     *action,
332                                   gpointer       data);
333
334 static void scroll_prev_line_cb  (GtkAction      *action,
335                                   gpointer        data);
336 static void scroll_next_line_cb  (GtkAction      *action,
337                                   gpointer        data);
338 static void scroll_prev_page_cb  (GtkAction      *action,
339                                   gpointer        data);
340 static void scroll_next_page_cb  (GtkAction      *action,
341                                   gpointer        data);
342
343 static void copy_cb              (GtkAction     *action,
344                                   gpointer       data);
345 static void allsel_cb            (GtkAction     *action,
346                                   gpointer       data);
347 static void select_thread_cb     (GtkAction     *action,
348                                   gpointer       data);
349 static void delete_thread_cb     (GtkAction     *action,
350                                   gpointer       data);
351
352 static void create_filter_cb     (GtkAction     *action,
353                                   gpointer       data);
354 static void create_processing_cb (GtkAction     *action,
355                                   gpointer       data);
356 static void open_urls_cb         (GtkAction     *action,
357                                   gpointer       data);
358
359 static void prefs_template_open_cb      (GtkAction      *action,
360                                   gpointer       data);
361 static void prefs_actions_open_cb       (GtkAction      *action,
362                                   gpointer       data);
363 static void prefs_tags_open_cb          (GtkAction      *action,
364                                   gpointer       data);
365 static void prefs_account_open_cb       (GtkAction      *action,
366                                   gpointer       data);
367
368 static void prefs_pre_processing_open_cb  (GtkAction    *action,
369                                   gpointer       data);
370
371 static void prefs_post_processing_open_cb (GtkAction    *action,
372                                   gpointer       data);
373
374 static void prefs_filtering_open_cb     (GtkAction      *action,
375                                   gpointer       data);
376 #ifdef USE_GNUTLS
377 static void ssl_manager_open_cb         (GtkAction      *action,
378                                   gpointer       data);
379 #endif
380 static void new_account_cb       (GtkAction     *action,
381                                   gpointer       data);
382
383 static void account_selector_menu_cb     (GtkMenuItem   *menuitem,
384                                           gpointer       data);
385 static void account_receive_menu_cb      (GtkMenuItem   *menuitem,
386                                           gpointer       data);
387 #ifndef GENERIC_UMPC
388 static void account_compose_menu_cb      (GtkMenuItem   *menuitem,
389                                           gpointer       data);
390 #endif
391 static void prefs_open_cb       (GtkAction      *action,
392                                   gpointer       data);
393 static void plugins_open_cb     (GtkAction      *action,
394                                   gpointer       data);
395
396 static void online_switch_clicked(GtkButton     *btn, 
397                                   gpointer data);
398
399 static void manual_open_cb       (GtkAction     *action,
400                                   gpointer       data);
401 static void manual_faq_open_cb   (GtkAction     *action,
402                                   gpointer       data);
403
404 static void legend_open_cb       (GtkAction     *action,
405                                   gpointer       data);
406
407 #ifdef G_OS_WIN32
408 static void set_default_client_cb (GtkAction    *action,
409                                   gpointer       data);
410 #endif
411
412 static void scan_tree_func       (Folder        *folder,
413                                   FolderItem    *item,
414                                   gpointer       data);
415                                   
416 static void toggle_work_offline_cb(GtkAction    *action,
417                                   gpointer       data);
418
419 static void addr_harvest_cb      ( GtkAction    *action,
420                                   gpointer       data );
421
422 static void addr_harvest_msg_cb  ( GtkAction    *action,
423                                   gpointer       data );
424 static void sync_cb              ( GtkAction    *action,
425                                   gpointer       data );
426
427 static void forget_session_passwords_cb (GtkAction      *action,
428                                          gpointer        data );
429
430 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
431                                                  GdkEventFocus  *focus,
432                                                  gpointer        data);
433 static gboolean mainwindow_visibility_event_cb  (GtkWidget      *widget, 
434                                                  GdkEventVisibility     *state,
435                                                  gpointer        data);
436 static gboolean mainwindow_state_event_cb       (GtkWidget      *widget, 
437                                                  GdkEventWindowState    *state,
438                                                  gpointer        data);
439 static void main_window_reply_cb                        (GtkAction      *action,
440                                   gpointer       data);
441 static gboolean mainwindow_progressindicator_hook       (gpointer        source,
442                                                  gpointer        userdata);
443
444 static gint mailing_list_create_submenu(MainWindow *mainwindow,
445                                        MsgInfo *msginfo);
446
447 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
448         
449 static void get_url_part(const gchar **buf, gchar *url_decoded);
450
451 static void mailing_list_compose(GtkWidget *w, gpointer *data);
452  
453 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
454 #define  SEPARATE_ACTION 500 
455 static void mainwindow_quicksearch              (GtkAction      *action,
456                                   gpointer       data);
457 static gboolean any_folder_want_synchronise(void);
458
459 static void save_part_as_cb(GtkAction *action, gpointer data);
460 static void view_part_as_text_cb(GtkAction *action, gpointer data);
461 static void open_part_cb(GtkAction *action, gpointer data);
462 #ifndef G_OS_WIN32
463 static void open_part_with_cb(GtkAction *action, gpointer data);
464 #endif
465 static void check_signature_cb(GtkAction *action, gpointer data);
466 static void goto_next_part_cb(GtkAction *action, gpointer data);
467 static void goto_prev_part_cb(GtkAction *action, gpointer data);
468 #define DO_ACTION(name, act)    { if (!strcmp(a_name, name)) action = act; }
469
470 static void mainwindow_nothing_cb          (GtkAction *action, gpointer data)
471 {
472
473 }
474
475 static void about_cb(GtkAction *gaction, gpointer data)
476 {
477         about_show();
478 }
479
480 static void     mw_inc_mail_cb                  (GtkAction *gaction, gpointer data)
481 {
482         inc_mail_cb(data, 0, NULL);
483 }
484 static void     mw_inc_all_account_mail_cb              (GtkAction *gaction, gpointer data)
485 {
486         inc_all_account_mail_cb(data, 0, NULL);
487 }
488 static void     mw_send_queue_cb                        (GtkAction *gaction, gpointer data)
489 {
490         send_queue_cb(data, 0, NULL);
491 }
492 static void     mw_compose_mail_cb                      (GtkAction *gaction, gpointer data)
493 {
494         compose_mail_cb(data, 0, NULL);
495 }
496 static void     mw_compose_news_cb                      (GtkAction *gaction, gpointer data)
497 {
498         compose_news_cb(data, 0, NULL);
499 }
500
501 static GtkActionEntry mainwin_entries[] =
502 {
503         {"Menu",                                NULL, "Menu" },
504 /* menus */
505         {"File",                                NULL, N_("_File") },
506         {"Edit",                                NULL, N_("_Edit") },
507         {"View",                                NULL, N_("_View") },
508         {"Message",                             NULL, N_("_Message") },
509         {"Tools",                               NULL, N_("_Tools") },
510         {"Configuration",                       NULL, N_("_Configuration") },
511         {"Help",                                NULL, N_("_Help") },
512
513 /* File menu */
514         {"File/AddMailbox",                     NULL, N_("_Add mailbox") },
515         {"File/AddMailbox/MH",                  NULL, N_("MH..."), NULL, NULL, G_CALLBACK(add_mailbox_cb) },
516         {"File/---",                            NULL, "---" },
517
518         {"File/SortMailboxes",                  NULL, N_("Change mailbox order..."), NULL, NULL, G_CALLBACK(foldersort_cb) },
519
520         /* {"File/---",                         NULL, "---" }, */
521         {"File/ImportMbox",                     NULL, N_("_Import mbox file..."), NULL, NULL, G_CALLBACK(import_mbox_cb) },
522         {"File/ExportMbox",                     NULL, N_("_Export to mbox file..."), NULL, NULL, G_CALLBACK(export_mbox_cb) },
523         {"File/ExportSelMbox",                  NULL, N_("_Export selected to mbox file..."), NULL, NULL, G_CALLBACK(export_list_mbox_cb) },
524         /* {"File/---",                         NULL, "---" }, */
525         {"File/EmptyTrashes",                   NULL, N_("Empty all _Trash folders"), "<shift>D", NULL, G_CALLBACK(empty_trash_cb) },
526         /* {"File/---",                         NULL, "---" }, */
527
528         {"File/SaveAs",                         NULL, N_("_Save email as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
529         {"File/SavePartAs",                     NULL, N_("_Save part as..."), "Y", NULL, G_CALLBACK(save_part_as_cb) },
530         /* {"File/---",                         NULL, "---" }, */
531
532         {"File/PageSetup",                      NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
533         {"File/Print",                          NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
534         /* {"File/---",                         NULL, "---" }, */
535         {"File/SynchroniseFolders",             NULL, N_("Synchronise folders"), "<control><shift>S", NULL, G_CALLBACK(sync_cb) }, 
536         /* {"File/---",                         NULL, "---" }, */
537         {"File/Exit",                           NULL, N_("E_xit"), "<control>Q", NULL, G_CALLBACK(app_exit_cb) }, 
538
539 /* Edit menu */
540         {"Edit/Copy",                           NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(copy_cb) }, 
541         {"Edit/SelectAll",                      NULL, N_("Select _all"), "<control>A", NULL, G_CALLBACK(allsel_cb) }, 
542         {"Edit/SelectThread",                   NULL, N_("Select _thread"), NULL, NULL, G_CALLBACK(select_thread_cb) }, 
543         {"Edit/DeleteThread",                   NULL, N_("_Delete thread"), NULL, NULL, G_CALLBACK(delete_thread_cb) }, 
544         {"Edit/---",                            NULL, "---" },
545         {"Edit/Find",                           NULL, N_("_Find in current message..."), "<control>F", NULL, G_CALLBACK(search_cb) },
546         {"Edit/SearchFolder",                   NULL, N_("_Search folder..."), "<shift><control>F", NULL, G_CALLBACK(search_folder_cb) },
547         {"Edit/QuickSearch",                    NULL, N_("_Quick search"), "slash", NULL, G_CALLBACK(mainwindow_quicksearch) },
548
549 /* View menu */
550         {"View/ShowHide",                       NULL, N_("Show or hi_de") },
551         {"View/ShowHide/Toolbar",               NULL, N_("_Toolbar") },
552
553         {"View/SetColumns",                     NULL, N_("Set displayed _columns") },
554         {"View/SetColumns/Folderlist",          NULL, N_("In _folder list..."), NULL, NULL, G_CALLBACK(set_folder_display_item_cb) },
555         {"View/SetColumns/Messagelist",         NULL, N_("In _message list..."), NULL, NULL, G_CALLBACK(set_summary_display_item_cb) },
556         {"View/---",                            NULL, "---" },
557
558
559 #ifndef GENERIC_UMPC
560         {"View/Layout",                         NULL, N_("La_yout") },
561
562 #endif
563         {"View/Sort",                           NULL, N_("_Sort") },
564         {"View/Sort/---",                       NULL, "---" }, 
565         {"View/Sort/AttractSubj",               NULL, N_("_Attract by subject"), NULL, NULL, G_CALLBACK(attract_by_subject_cb) }, 
566
567         {"View/ExpandThreads",                  NULL, N_("E_xpand all threads"), NULL, NULL, G_CALLBACK(expand_threads_cb) }, 
568         {"View/CollapseThreads",                NULL, N_("Co_llapse all threads"), NULL, NULL, G_CALLBACK(collapse_threads_cb) }, 
569
570         {"View/Goto",                           NULL, N_("_Go to") },
571         {"View/Goto/Prev",                      NULL, N_("_Previous message"), "P", NULL, G_CALLBACK(prev_cb) },
572         {"View/Goto/Next",                      NULL, N_("_Next message"), "N", NULL, G_CALLBACK(next_cb) },
573         {"View/Goto/---",                       NULL, "---", NULL, NULL, NULL },
574         {"View/Goto/PrevUnread",                NULL, N_("P_revious unread message"), "<shift>P", NULL, G_CALLBACK(prev_unread_cb) },
575         {"View/Goto/NextUnread",                NULL, N_("N_ext unread message"), "<shift>N", NULL, G_CALLBACK(next_unread_cb) },
576         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
577         {"View/Goto/PrevNew",                   NULL, N_("Previous ne_w message"), NULL, NULL, G_CALLBACK(prev_new_cb) },
578         {"View/Goto/NextNew",                   NULL, N_("Ne_xt new message"), NULL, NULL, G_CALLBACK(next_new_cb) },
579         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
580         {"View/Goto/PrevMarked",                NULL, N_("Previous _marked message"), NULL, NULL, G_CALLBACK(prev_marked_cb) },
581         {"View/Goto/NextMarked",                NULL, N_("Next m_arked message"), NULL, NULL, G_CALLBACK(next_marked_cb) },
582         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
583         {"View/Goto/PrevLabeled",               NULL, N_("Previous _labeled message"), NULL, NULL, G_CALLBACK(prev_labeled_cb) },
584         {"View/Goto/NextLabeled",               NULL, N_("Next la_beled message"), NULL, NULL, G_CALLBACK(next_labeled_cb) },
585         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
586         {"View/Goto/PrevHistory",               NULL, N_("Previous opened message"), "<alt>Left", NULL, G_CALLBACK(prev_history_cb) },
587         {"View/Goto/NextHistory",               NULL, N_("Next opened message"), "<alt>Right", NULL, G_CALLBACK(next_history_cb) },
588         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
589         {"View/Goto/ParentMessage",             NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
590         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
591         {"View/Goto/NextUnreadFolder",          NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
592         {"View/Goto/OtherFolder",               NULL, N_("_Other folder..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
593         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
594         {"View/Goto/NextPart",                  NULL, N_("Next part"), "A", NULL, G_CALLBACK(goto_next_part_cb) },
595         {"View/Goto/PrevPart",                  NULL, N_("Previous part"), "Z", NULL, G_CALLBACK(goto_prev_part_cb) },
596
597         /* {"View/Scroll/---",                  NULL, "---", NULL, NULL, NULL }, */
598         {"View/Scroll",                         NULL, N_("Message scroll") },
599         {"View/Scroll/PrevLine",                NULL, N_("Previous line"), NULL, NULL, G_CALLBACK(scroll_prev_line_cb) },
600         {"View/Scroll/NextLine",                NULL, N_("Next line"), NULL, NULL, G_CALLBACK(scroll_next_line_cb) },
601         {"View/Scroll/PrevPage",                NULL, N_("Previous page"), NULL, NULL, G_CALLBACK(scroll_prev_page_cb) },
602         {"View/Scroll/NextPage",                NULL, N_("Next page"), NULL, NULL, G_CALLBACK(scroll_next_page_cb) },
603
604         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
605         {"View/Encoding",                       NULL, N_("Character _encoding") }, /* set_charset_cb */
606         {"View/Encoding/---",                   NULL, "---" },
607 #define ENC_ACTION(cs_char,c_char,string) \
608         { "View/Encoding/" cs_char, NULL, N_(string), NULL, NULL, c_char }
609
610         {"View/Encoding/Western",               NULL, N_("Western European") },
611         {"View/Encoding/Baltic",                NULL, N_("Baltic") },
612         {"View/Encoding/Hebrew",                NULL, N_("Hebrew") },
613         {"View/Encoding/Arabic",                NULL, N_("Arabic") },
614         {"View/Encoding/Cyrillic",              NULL, N_("Cyrillic") },
615         {"View/Encoding/Japanese",              NULL, N_("Japanese") },
616         {"View/Encoding/Chinese",               NULL, N_("Chinese") },
617         {"View/Encoding/Korean",                NULL, N_("Korean") },
618         {"View/Encoding/Thai",                  NULL, N_("Thai") },
619
620         {"View/Decode",                         NULL, N_("Decode") }, /* set_decode_cb */
621         {"View/Decode/---",                     NULL, "---" },
622
623 #define DEC_ACTION(cs_type,c_type,string) \
624         { "View/Decode/" cs_type, NULL, N_(string), NULL, NULL, c_type }
625
626         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
627         {"View/OpenNewWindow",                  NULL, N_("Open in new _window"), "<control><alt>N", NULL, G_CALLBACK(open_msg_cb) },
628         {"View/MessageSource",                  NULL, N_("Mess_age source"), "<control>U", NULL, G_CALLBACK(view_source_cb) },
629         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
630         {"View/Part",                           NULL, N_("Message part") },
631         {"View/Part/AsText",                    NULL, N_("View as text"), "T", NULL, G_CALLBACK(view_part_as_text_cb) },
632         {"View/Part/Open",                      NULL, N_("Open"), "L", NULL, G_CALLBACK(open_part_cb) },
633 #ifndef G_OS_WIN32
634         {"View/Part/OpenWith",                  NULL, N_("Open with..."), "O", NULL, G_CALLBACK(open_part_with_cb) },
635 #endif
636         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
637
638         {"View/Quotes",                         NULL, N_("Quotes") }, 
639         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
640         {"View/UpdateSummary",                  NULL, N_("_Update summary"), "<control><alt>U", NULL, G_CALLBACK(update_summary_cb) },
641
642 /* Message menu */
643         {"Message/Receive",                     NULL, N_("Recei_ve") },
644         {"Message/Receive/CurrentAccount",      NULL, N_("Get from _current account"), "<control>I", NULL, G_CALLBACK(mw_inc_mail_cb) },
645         {"Message/Receive/AllAccounts",         NULL, N_("Get from _all accounts"), "<shift><control>I", NULL, G_CALLBACK(mw_inc_all_account_mail_cb) },
646         {"Message/Receive/CancelReceiving",     NULL, N_("Cancel receivin_g"), NULL, NULL, G_CALLBACK(inc_cancel_cb) },
647         {"Message/Receive/---",                 NULL, "---" },
648         {"Message/Receive/PlaceHolder",         NULL, "PlaceHolder,", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
649         {"Message/SendQueue",                   NULL, N_("_Send queued messages"), NULL, NULL, G_CALLBACK(mw_send_queue_cb) },
650         {"Message/CancelSending",       NULL, N_("Cancel sending"), NULL, NULL, G_CALLBACK(send_cancel_cb) },
651
652         {"Message/---",                         NULL, "---" },
653
654         {"Message/ComposeEmail",                NULL, N_("Compose a_n email message"), "<control>M", NULL, G_CALLBACK(mw_compose_mail_cb) },
655         {"Message/ComposeNews",                 NULL, N_("Compose a news message"), NULL, NULL, G_CALLBACK(mw_compose_news_cb) },
656
657         {"Message/Reply",                       NULL, N_("_Reply"), "<control>R", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY */
658         {"Message/ReplyTo",                     NULL, N_("Repl_y to") }, 
659         {"Message/ReplyTo/All",                 NULL, N_("_All"), "<control><shift>R", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_ALL */
660         {"Message/ReplyTo/Sender",              NULL, N_("_Sender"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_SENDER */
661         {"Message/ReplyTo/List",                NULL, N_("Mailing _list"), "<control>L", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_LIST */
662         {"Message/FollowupReply",               NULL, N_("Follow-up and reply to"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FOLLOWUP_AND_REPLY_TO */
663         /*{"Message/---",                       NULL, "---" },*/
664
665         {"Message/Forward",                     NULL, N_("_Forward"), "<control><alt>F", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FORWARD_INLINE */
666         {"Message/ForwardAtt",                  NULL, N_("For_ward as attachment"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FORWARD_AS_ATTACH */
667         {"Message/Redirect",                    NULL, N_("Redirec_t"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REDIRECT */
668
669         {"Message/MailingList",                 NULL, N_("Mailing-_List") }, 
670         {"Message/MailingList/Post",            NULL, N_("Post") }, 
671         {"Message/MailingList/Post/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
672         {"Message/MailingList/Help",            NULL, N_("Help") }, 
673         {"Message/MailingList/Help/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
674         {"Message/MailingList/Subscribe",       NULL, N_("Subscribe") }, 
675         {"Message/MailingList/Subscribe/PlaceHolder",   NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
676         {"Message/MailingList/Unsubscribe",     NULL, N_("Unsubscribe") }, 
677         {"Message/MailingList/Unsubscribe/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
678         {"Message/MailingList/ViewArchive",     NULL, N_("View archive") }, 
679         {"Message/MailingList/ViewArchive/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
680         {"Message/MailingList/ContactOwner",    NULL, N_("Contact owner") }, 
681         {"Message/MailingList/ContactOwner/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
682         /* separation */
683
684         {"Message/Move",                        NULL, N_("M_ove..."), "<control>O", NULL, G_CALLBACK(move_to_cb) },
685         {"Message/Copy",                        NULL, N_("_Copy..."), "<shift><control>O", NULL, G_CALLBACK(copy_to_cb) },
686         {"Message/Trash",                       NULL, N_("Move to _trash"), "<control>D", NULL, G_CALLBACK(delete_trash_cb) },
687         {"Message/Delete",                      NULL, N_("_Delete..."), NULL, NULL, G_CALLBACK(delete_cb) },
688         {"Message/CancelNews",                  NULL, N_("Cancel a news message"), NULL, NULL, G_CALLBACK(cancel_cb) },
689         /* separation */
690         
691         {"Message/Mark",                        NULL, N_("_Mark") },
692         {"Message/Mark/Mark",                   NULL, N_("_Mark"), "<shift>asterisk", NULL, G_CALLBACK(mark_cb) },
693         {"Message/Mark/Unmark",                 NULL, N_("_Unmark"), "U", NULL, G_CALLBACK(unmark_cb) },
694         {"Message/Mark/---",                    NULL, "---", NULL, NULL, NULL },
695
696         {"Message/Mark/MarkUnread",             NULL, N_("Mark as unr_ead"), "<shift>exclam", NULL, G_CALLBACK(mark_as_unread_cb) },
697         {"Message/Mark/MarkRead",               NULL, N_("Mark as rea_d"), NULL, NULL, G_CALLBACK(mark_as_read_cb) },
698         /* separation */
699         {"Message/Mark/MarkAllRead",            NULL, N_("Mark all read"), NULL, NULL, G_CALLBACK(mark_all_read_cb) },
700         /* separation */
701         {"Message/Mark/IgnoreThread",           NULL, N_("Ignore thread"), NULL, NULL, G_CALLBACK(ignore_thread_cb) },
702         {"Message/Mark/UnignoreThread",         NULL, N_("Unignore thread"), NULL, NULL, G_CALLBACK(unignore_thread_cb) },
703         {"Message/Mark/WatchThread",            NULL, N_("Watch thread"), NULL, NULL, G_CALLBACK(watch_thread_cb) },
704         {"Message/Mark/UnwatchThread",          NULL, N_("Unwatch thread"), NULL, NULL, G_CALLBACK(unwatch_thread_cb) },
705         /* separation */
706
707         {"Message/Mark/MarkSpam",               NULL, N_("Mark as _spam"), NULL, NULL, G_CALLBACK(mark_as_spam_cb) },
708         {"Message/Mark/MarkHam",                NULL, N_("Mark as _ham"), NULL, NULL, G_CALLBACK(mark_as_ham_cb) },
709         /* separation */
710
711         {"Message/Mark/Lock",                   NULL, N_("Lock"), NULL, NULL, G_CALLBACK(lock_msgs_cb) },
712         {"Message/Mark/Unlock",                 NULL, N_("Unlock"), NULL, NULL, G_CALLBACK(unlock_msgs_cb) },
713
714         {"Message/ColorLabel",                  NULL, N_("Color la_bel") },
715         {"Message/Tags",                        NULL, N_("Ta_gs") },
716         /*{"Message/---",                       NULL, "---" },*/
717
718         {"Message/Reedit",                      NULL, N_("Re-_edit"), NULL, NULL, G_CALLBACK(reedit_cb) },
719         /*{"Message/---",                       NULL, "---" },*/
720
721         {"Message/CheckSignature",              NULL, N_("Check signature"), "C", NULL, G_CALLBACK(check_signature_cb) },
722
723 /* Tools menu */
724
725         {"Tools/AddressBook",                   NULL, N_("_Address book"), "<control><shift>A", NULL, G_CALLBACK(addressbook_open_cb) }, 
726         {"Tools/AddSenderToAB",                 NULL, N_("Add sender to address boo_k"), NULL, NULL, G_CALLBACK(add_address_cb) }, 
727
728         {"Tools/CollectAddresses",              NULL, N_("C_ollect addresses") }, 
729         {"Tools/CollectAddresses/FromFolder",   NULL, N_("From current _folder..."), NULL, NULL, G_CALLBACK(addr_harvest_cb) }, 
730         {"Tools/CollectAddresses/FromSelected", NULL, N_("From selected _messages..."), NULL, NULL, G_CALLBACK(addr_harvest_msg_cb) }, 
731         {"Tools/---",                           NULL, "---", NULL, NULL, NULL },
732
733         {"Tools/FilterFolder",                  NULL, N_("_Filter all messages in folder"), NULL, NULL, G_CALLBACK(filter_cb) }, 
734         {"Tools/FilterSelected",                NULL, N_("Filter _selected messages"), NULL, NULL, G_CALLBACK(filter_list_cb) }, 
735         {"Tools/RunProcessing",                 NULL, N_("Run folder pr_ocessing rules"), NULL, NULL, G_CALLBACK(process_cb) }, 
736
737         {"Tools/CreateFilterRule",              NULL, N_("_Create filter rule") },
738         {"Tools/CreateFilterRule/Automatically",NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_AUTO */
739         {"Tools/CreateFilterRule/ByFrom",       NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_FROM */
740         {"Tools/CreateFilterRule/ByTo",         NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_TO     */
741         {"Tools/CreateFilterRule/BySubject",    NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_SUBJECT */
742
743         {"Tools/CreateProcessingRule",          NULL, N_("Create processing rule") },
744         {"Tools/CreateProcessingRule/Automatically",    NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
745         {"Tools/CreateProcessingRule/ByFrom",   NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
746         {"Tools/CreateProcessingRule/ByTo",     NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
747         {"Tools/CreateProcessingRule/BySubject",NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
748         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
749
750         {"Tools/ListUrls",                      NULL, N_("List _URLs..."), "<control><shift>U", NULL, G_CALLBACK(open_urls_cb) }, 
751
752         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
753         {"Tools/Actions",                       NULL, N_("Actio_ns") },
754         {"Tools/Actions/PlaceHolder",           NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
755         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
756
757         {"Tools/CheckNewMessages",              NULL, N_("Ch_eck for new messages in all folders"), NULL, NULL, G_CALLBACK(update_folderview_cb) }, 
758         {"Tools/DeleteDuplicates",              NULL, N_("Delete du_plicated messages") },
759         {"Tools/DeleteDuplicates/SelFolder",    NULL, N_("In selected folder"), NULL, NULL, G_CALLBACK(delete_duplicated_cb) },
760         {"Tools/DeleteDuplicates/AllFolders",   NULL, N_("In all folders"), NULL, NULL, G_CALLBACK(delete_duplicated_all_cb) },
761         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
762
763         {"Tools/Execute",                       NULL, N_("E_xecute"), "X", NULL, G_CALLBACK(execute_summary_cb) }, 
764         {"Tools/Expunge",                       NULL, N_("Exp_unge"), "<control>E", NULL, G_CALLBACK(expunge_summary_cb) }, 
765 #ifdef USE_GNUTLS
766         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
767         {"Tools/SSLCertificates",               NULL, N_("SSL cer_tificates"), NULL, NULL, G_CALLBACK(ssl_manager_open_cb) }, 
768 #endif
769         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
770 #ifndef G_OS_WIN32
771         {"Tools/FilteringLog",                  NULL, N_("Filtering Lo_g"), NULL, NULL, G_CALLBACK(filtering_debug_window_show_cb) }, 
772 #endif
773         {"Tools/NetworkLog",                    NULL, N_("Network _Log"), "<shift><control>L", NULL, G_CALLBACK(log_window_show_cb) }, 
774         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
775         {"Tools/ForgetSessionPasswords",                NULL, N_("_Forget all session passwords"), NULL, NULL, G_CALLBACK(forget_session_passwords_cb) }, 
776
777 /* Configuration menu */        
778         {"Configuration/ChangeAccount",         NULL, N_("C_hange current account") },
779         {"Configuration/ChangeAccount/PlaceHolder",     NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
780         {"Configuration/AccountPrefs",          NULL, N_("_Preferences for current account..."), NULL, NULL, G_CALLBACK(prefs_account_open_cb) },
781         {"Configuration/CreateAccount",         NULL, N_("Create _new account..."), NULL, NULL, G_CALLBACK(new_account_cb) },
782         {"Configuration/EditAccounts",          NULL, N_("_Edit accounts..."), NULL, NULL, G_CALLBACK(account_edit_open) },
783         {"Configuration/---",                   NULL, "---", NULL, NULL, NULL }, 
784
785         {"Configuration/Preferences",           NULL, N_("P_references..."), NULL, NULL, G_CALLBACK(prefs_open_cb) },
786         {"Configuration/PreProcessing",         NULL, N_("Pre-pr_ocessing..."), NULL, NULL, G_CALLBACK(prefs_pre_processing_open_cb) },
787         {"Configuration/PostProcessing",        NULL, N_("Post-pro_cessing..."), NULL, NULL, G_CALLBACK(prefs_post_processing_open_cb) },
788         {"Configuration/Filtering",             NULL, N_("_Filtering..."), NULL, NULL, G_CALLBACK(prefs_filtering_open_cb) },
789         {"Configuration/Templates",             NULL, N_("_Templates..."), NULL, NULL, G_CALLBACK(prefs_template_open_cb) },
790         {"Configuration/Actions",               NULL, N_("_Actions..."), NULL, NULL, G_CALLBACK(prefs_actions_open_cb) },
791         {"Configuration/Tags",                  NULL, N_("Tag_s..."), NULL, NULL, G_CALLBACK(prefs_tags_open_cb) },
792         /*{"Configuration/---",                 NULL, "---", NULL, NULL, NULL }, */
793         {"Configuration/Plugins",               NULL, N_("Plu_gins..."), NULL, NULL, G_CALLBACK(plugins_open_cb) },
794
795 /* Help menu */
796         {"Help/Manual",                         NULL, N_("_Manual"), NULL, NULL, G_CALLBACK(manual_open_cb) }, 
797         {"Help/FAQ",                            NULL, N_("_Online User-contributed FAQ"), NULL, NULL, G_CALLBACK(manual_faq_open_cb) }, 
798         {"Help/IconLegend",                     NULL, N_("Icon _Legend"), NULL, NULL, G_CALLBACK(legend_open_cb) }, 
799 #ifdef G_OS_WIN32
800         {"Help/SetDefault",                     NULL, N_("Set as default client"), NULL, NULL, G_CALLBACK(set_default_client_cb) }, 
801 #endif
802         {"Help/---",                            NULL, "---" }, 
803         {"Help/About",                          NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_cb) }, 
804 };
805
806 static GtkToggleActionEntry mainwin_toggle_entries[] = {
807         {"File/OfflineMode",                    NULL, N_("Offline _mode"), "<control>W", NULL, G_CALLBACK(toggle_work_offline_cb) }, /*toggle*/
808         {"View/ShowHide/MenuBar",               NULL, N_("Men_ubar"), "F12", NULL, G_CALLBACK(toggle_menubar_cb) }, /* toggle */
809         {"View/ShowHide/MessageView",           NULL, N_("_Message view"), "V", NULL, G_CALLBACK(toggle_message_cb) }, /* toggle */
810 #ifndef GENERIC_UMPC
811         {"View/ShowHide/StatusBar",             NULL, N_("Status _bar"), NULL, NULL, G_CALLBACK(toggle_statusbar_cb) }, /* toggle */
812 #endif
813         {"View/ShowHide/ColumnHeaders",         NULL, N_("Column headers"), NULL, NULL, G_CALLBACK(toggle_col_headers_cb) }, /* toggle */
814         {"View/ThreadView",                     NULL, N_("Th_read view"), "<control>T", NULL, G_CALLBACK(thread_cb) }, /* toggle */
815         {"View/HideReadThreads",                NULL, N_("Hide read threads"), NULL, NULL, G_CALLBACK(hide_read_threads) }, /* toggle */
816         {"View/HideReadMessages",               NULL, N_("_Hide read messages"), NULL, NULL, G_CALLBACK(hide_read_messages) }, /* toggle */
817         {"View/HideDelMessages",                NULL, N_("Hide deleted messages"), NULL, NULL, G_CALLBACK(hide_del_messages) }, /* toggle */
818         {"View/FullScreen",                     NULL, N_("_Fullscreen"), "F11", NULL, G_CALLBACK(toggle_fullscreen_cb) }, /* toggle */
819         {"View/AllHeaders",                     NULL, N_("Show all _headers"), "<control>H", NULL, G_CALLBACK(show_all_header_cb) }, /* toggle */
820         {"View/Quotes/CollapseAll",             NULL, N_("_Collapse all"), "<control><shift>Q", NULL, G_CALLBACK(hide_quotes_cb) }, /* 1 toggle */
821         {"View/Quotes/Collapse2",               NULL, N_("Collapse from level _2"), NULL, NULL, G_CALLBACK(hide_quotes_cb) }, /* 2 toggle */
822         {"View/Quotes/Collapse3",               NULL, N_("Collapse from level _3"), NULL, NULL, G_CALLBACK(hide_quotes_cb) }, /* 3 toggle */
823 };
824
825 static GtkRadioActionEntry mainwin_showhide_radio_entries[] = { /* toggle_toolbar_cb */
826         {"View/ShowHide/Toolbar/TextBelowIcon", NULL, N_("Text _below icons"), NULL, NULL, TOOLBAR_BOTH }, /* radio TOOLBAR_BOTH */
827         {"View/ShowHide/Toolbar/TextBesideIcon",NULL, N_("Text be_side icons"), NULL, NULL, TOOLBAR_BOTH_HORIZ }, /* radio TOOLBAR_BOTH_HORIZ */
828         {"View/ShowHide/Toolbar/IconOnly",      NULL, N_("_Icons only"), NULL, NULL, TOOLBAR_ICON }, /* radio TOOLBAR_ICON */
829         {"View/ShowHide/Toolbar/TextOnly",      NULL, N_("_Text only"), NULL, NULL, TOOLBAR_TEXT }, /* radio TOOLBAR_TEXT */
830 #ifndef GENERIC_UMPC
831         {"View/ShowHide/Toolbar/Hide",          NULL, N_("_Hide"), NULL, NULL, TOOLBAR_NONE }, /* radio TOOLBAR_NONE */
832 #endif
833 };
834 #ifndef GENERIC_UMPC
835 static GtkRadioActionEntry mainwin_layout_radio_entries[] = { /* set_layout_cb */
836         {"View/Layout/Standard",                NULL, N_("_Standard"), NULL, NULL, NORMAL_LAYOUT }, /* radio NORMAL_LAYOUT */
837         {"View/Layout/ThreeColumns",            NULL, N_("_Three columns"), NULL, NULL, VERTICAL_LAYOUT }, /* radio VERTICAL_LAYOUT */
838         {"View/Layout/WideMessage",             NULL, N_("_Wide message"), NULL, NULL, WIDE_LAYOUT }, /* radio WIDE_LAYOUT */
839         {"View/Layout/WideMessageList",         NULL, N_("W_ide message list"), NULL, NULL, WIDE_MSGLIST_LAYOUT }, /* radio WIDE_MSGLIST_LAYOUT */
840         {"View/Layout/SmallScreen",             NULL, N_("S_mall screen"), NULL, NULL, SMALL_LAYOUT }, /* radio SMALL_LAYOUT */
841 };
842 #endif
843 static GtkRadioActionEntry mainwin_sort_radio_entries[] = { /* sort_summary_cb */
844         {"View/Sort/Number",                    NULL, N_("By _number"), NULL, NULL, SORT_BY_NUMBER }, /* radio SORT_BY_NUMBER */
845         {"View/Sort/Size",                      NULL, N_("By s_ize"), NULL, NULL, SORT_BY_SIZE }, /* radio SORT_BY_SIZE */
846         {"View/Sort/Date",                      NULL, N_("By _date"), NULL, NULL, SORT_BY_DATE }, /* radio SORT_BY_DATE */
847         {"View/Sort/ThreadDate",                NULL, N_("By thread date"), NULL, NULL, SORT_BY_THREAD_DATE }, /* radio SORT_BY_THREAD_DATE */
848         {"View/Sort/From",                      NULL, N_("By _From"), NULL, NULL, SORT_BY_FROM }, /* radio SORT_BY_FROM */
849         {"View/Sort/To",                        NULL, N_("By _To"), NULL, NULL, SORT_BY_TO }, /* radio SORT_BY_TO */
850         {"View/Sort/Subject",                   NULL, N_("By s_ubject"), NULL, NULL, SORT_BY_SUBJECT }, /* radio SORT_BY_SUBJECT */
851         {"View/Sort/Color",                     NULL, N_("By _color label"), NULL, NULL, SORT_BY_LABEL }, /* radio SORT_BY_LABEL */
852         {"View/Sort/Tag",                       NULL, N_("By tag"), NULL, NULL, SORT_BY_TAGS }, /* radio SORT_BY_TAGS */
853         {"View/Sort/Mark",                      NULL, N_("By _mark"), NULL, NULL, SORT_BY_MARK }, /* radio SORT_BY_MARK */
854         {"View/Sort/Status",                    NULL, N_("By _status"), NULL, NULL, SORT_BY_STATUS }, /* radio SORT_BY_STATUS */
855         {"View/Sort/Attachment",                NULL, N_("By a_ttachment"), NULL, NULL, SORT_BY_MIME }, /* radio SORT_BY_MIME */
856         {"View/Sort/Score",                     NULL, N_("By score"), NULL, NULL, SORT_BY_SCORE }, /* radio SORT_BY_SCORE */
857         {"View/Sort/Locked",                    NULL, N_("By locked"), NULL, NULL, SORT_BY_LOCKED }, /* radio SORT_BY_LOCKED */
858         {"View/Sort/DontSort",                  NULL, N_("D_on't sort"), NULL, NULL, SORT_BY_NONE }, /* radio SORT_BY_NONE */
859 };
860
861 static GtkRadioActionEntry mainwin_sorttype_radio_entries[] = { /* sort_summary_type_cb */
862         {"View/Sort/Ascending",                 NULL, N_("Ascending"), NULL, NULL, SORT_ASCENDING }, /* radio SORT_ASCENDING */
863         {"View/Sort/Descending",                NULL, N_("Descending"), NULL, NULL, SORT_DESCENDING }, /* radio SORT_DESCENDING */
864 };
865
866 static GtkRadioActionEntry mainwin_radio_enc_entries[] =
867 {
868         ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO set_charset_cb */
869         ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO set_charset_cb */
870         ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO set_charset_cb */
871         ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO set_charset_cb */
872         ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO set_charset_cb */
873         ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO set_charset_cb */
874         ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO set_charset_cb */
875         ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO set_charset_cb */
876         ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO set_charset_cb */
877         ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO set_charset_cb */
878         ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO set_charset_cb */
879         ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO set_charset_cb */
880         ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO set_charset_cb */
881         ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO set_charset_cb */
882         ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
883         ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
884         ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
885         ENC_ACTION("Cyrillic/"CS_MACCYR, C_MACCYR, "MAC_CYR"), /* RADIO set_charset_cb */
886         ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
887         ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
888         ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
889         ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
890         ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
891         ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
892         ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
893         ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
894         ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
895         ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
896         ENC_ACTION("Chinese/"CS_EUC_TW, C_EUC_TW, "EUC-_TW"), /* RADIO set_charset_cb */
897         ENC_ACTION("Korean/"CS_EUC_KR, C_EUC_KR, "_EUC-KR"), /* RADIO set_charset_cb */
898         ENC_ACTION("Korean/"CS_ISO_2022_KR, C_ISO_2022_KR, "_ISO-2022-KR"), /* RADIO set_charset_cb */
899         ENC_ACTION("Thai/"CS_TIS_620, C_TIS_620, "_TIS-620-KR"), /* RADIO set_charset_cb */
900         ENC_ACTION("Thai/"CS_WINDOWS_874, C_WINDOWS_874, "_Windows-874"), /* RADIO set_charset_cb */
901 };
902
903 static GtkRadioActionEntry mainwin_radio_dec_entries[] =
904 {
905         DEC_ACTION("AutoDetect", 0, N_("_Auto detect")),        /* set_decode_cb */
906         /* --- */
907         DEC_ACTION("8bit", ENC_8BIT, "_8bit"),
908         DEC_ACTION("QP", ENC_QUOTED_PRINTABLE, "_Quoted printable"),
909         DEC_ACTION("B64", ENC_BASE64, "_Base64"),
910         DEC_ACTION("Uuencode", ENC_X_UUENCODE, "_Uuencode"),
911 };
912
913 static gboolean offline_ask_sync = TRUE;
914 static guint lastkey;
915 static gboolean is_obscured = FALSE;
916
917 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
918                                             GObject *arg1,
919                                             guint value,
920                                             GdkModifierType mod,
921                                             gpointer user_data) 
922 {
923         MainWindow *mainwin = (MainWindow *)user_data;
924
925         if (mainwin->summaryview &&
926             mainwin->summaryview->quicksearch &&
927             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
928             (mod == 0 || mod == GDK_SHIFT_MASK)) {
929                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
930                 return TRUE;
931         }
932         return FALSE;
933 }
934
935 #define N_COLOR_LABELS colorlabel_get_color_count()
936
937 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
938                                                           gpointer data)
939 {
940         MainWindow *mainwin;
941         GtkMenuShell *menu;
942         GtkCheckMenuItem **items;
943         gint n;
944         GList *children, *cur;
945         GSList *sel;
946
947         mainwin = (MainWindow *)data;
948         cm_return_if_fail(mainwin != NULL);
949
950         sel = summary_get_selection(mainwin->summaryview);
951         if (!sel) return;
952
953         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
954         cm_return_if_fail(menu != NULL);
955
956         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
957
958         /* NOTE: don't return prematurely because we set the "dont_toggle"
959          * state for check menu items. This would be bad! */
960         g_object_set_data(G_OBJECT(menu), "dont_toggle",
961                           GINT_TO_POINTER(1));
962
963         /* clear items. get item pointers. */
964         children = gtk_container_get_children(GTK_CONTAINER(menu));
965         for (n = 0, cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
966                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
967                         gtk_check_menu_item_set_active
968                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
969                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
970                         n++;
971                 }
972         }
973
974         g_list_free(children);
975
976         if (n == (N_COLOR_LABELS + 1)) {
977                 /* iterate all messages and set the state of the appropriate
978                  * items */
979                 for (; sel != NULL; sel = sel->next) {
980                         MsgInfo *msginfo;
981                         gint clabel;
982
983                         msginfo = (MsgInfo *)sel->data;
984                         if (msginfo) {
985                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
986                                 if (!gtk_check_menu_item_get_active(items[clabel]))
987                                         gtk_check_menu_item_set_active
988                                                 (items[clabel], TRUE);
989                         }
990                 }
991         } else
992                 g_warning("invalid number of color elements (%d)\n", n);
993
994         g_slist_free(sel);
995         /* reset "dont_toggle" state */
996         g_object_set_data(G_OBJECT(menu), "dont_toggle",
997                           GINT_TO_POINTER(0));
998 }
999
1000 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
1001                                                      gpointer data)
1002 {
1003         guint color = GPOINTER_TO_UINT(data);
1004         MainWindow *mainwin;
1005
1006         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1007         cm_return_if_fail(mainwin != NULL);
1008
1009         /* "dont_toggle" state set? */
1010         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
1011                                 "dont_toggle"))
1012                 return;
1013
1014         summary_set_colorlabel(mainwin->summaryview, color, NULL);
1015 }
1016
1017 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
1018                                                           gpointer data)
1019 {
1020         MainWindow *mainwin;
1021         GtkMenuShell *menu;
1022         GList *children, *cur;
1023         GSList *sel;
1024         GHashTable *menu_table = g_hash_table_new_full(
1025                                         g_direct_hash,
1026                                         g_direct_equal,
1027                                         NULL, NULL);
1028         GHashTable *menu_allsel_table = g_hash_table_new_full(
1029                                         g_direct_hash,
1030                                         g_direct_equal,
1031                                         NULL, NULL);
1032         gint sel_len;
1033         mainwin = (MainWindow *)data;
1034         cm_return_if_fail(mainwin != NULL);
1035
1036         sel = summary_get_selection(mainwin->summaryview);
1037         if (!sel) return;
1038
1039         menu = GTK_MENU_SHELL(mainwin->tags_menu);
1040         cm_return_if_fail(menu != NULL);
1041
1042         /* NOTE: don't return prematurely because we set the "dont_toggle"
1043          * state for check menu items */
1044         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1045                           GINT_TO_POINTER(1));
1046
1047         /* clear items. get item pointers. */
1048         children = gtk_container_get_children(GTK_CONTAINER(menu));
1049         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
1050                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1051                         gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1052                                 "tag_id"));
1053                         gtk_check_menu_item_set_active
1054                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1055                                 
1056                         g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1057                         g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1058                 }
1059         }
1060
1061         g_list_free(children);
1062
1063         /* iterate all messages and set the state of the appropriate
1064          * items */
1065         sel_len = 0;
1066         for (; sel != NULL; sel = sel->next) {
1067                 MsgInfo *msginfo;
1068                 GSList *tags = NULL;
1069                 GtkCheckMenuItem *item;
1070                 msginfo = (MsgInfo *)sel->data;
1071                 sel_len++;
1072                 if (msginfo) {
1073                         tags =  msginfo->tags;
1074                         if (!tags)
1075                                 continue;
1076
1077                         for (; tags; tags = tags->next) {
1078                                 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1079                                 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1080                                 if (item && !gtk_check_menu_item_get_active(item)) {
1081                                         gtk_check_menu_item_set_active
1082                                                 (item, TRUE);
1083                                 }
1084                                 num_checked++;
1085                                 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1086                         }
1087                 }
1088         }
1089
1090         children = gtk_container_get_children(GTK_CONTAINER(menu));
1091         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
1092                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1093                         gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1094                                 "tag_id"));
1095                         gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1096                         if (num_checked < sel_len && num_checked > 0)
1097                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1098                         else
1099                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1100                 }
1101         }
1102         g_list_free(children);
1103         g_slist_free(sel);
1104         g_hash_table_destroy(menu_table);
1105         g_hash_table_destroy(menu_allsel_table);
1106         /* reset "dont_toggle" state */
1107         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1108                           GINT_TO_POINTER(0));
1109 }
1110
1111 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1112                                                      gpointer data)
1113 {
1114         gint id = GPOINTER_TO_INT(data);
1115         gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1116         MainWindow *mainwin;
1117
1118         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1119         cm_return_if_fail(mainwin != NULL);
1120
1121         /* "dont_toggle" state set? */
1122         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1123                                 "dont_toggle"))
1124                 return;
1125
1126         if (!set)
1127                 id = -id;
1128         summary_set_tag(mainwin->summaryview, id, NULL);
1129 }
1130
1131 void mainwin_accel_changed_cb (GtkAccelGroup *accelgroup, guint keyval, GdkModifierType modifier,
1132                                   GClosure *closure, GtkMenuItem *item)
1133 {
1134         GList *closures = gtk_widget_list_accel_closures(GTK_WIDGET(item));
1135         GList *cur;
1136         for (cur = closures; cur; cur = cur->next) {
1137                 if (closure == cur->data) {
1138                         GtkLabel *label = g_object_get_data(G_OBJECT(item), "accel_label");
1139                         gchar *new_accel;
1140                         
1141                         if (keyval == GDK_KEY_Delete) {
1142                                 const gchar *accel_path;
1143                                 accel_path = gtk_menu_item_get_accel_path(item);
1144                                 keyval = 0; modifier = 0;
1145                                 gtk_accel_map_change_entry (accel_path, keyval, modifier, TRUE);
1146                         }
1147                         new_accel = gtk_accelerator_get_label(keyval, modifier);
1148                         gtk_label_set_text(label, new_accel);
1149                         g_free(new_accel);
1150                 }
1151         }
1152         g_list_free(closures);
1153 }
1154
1155 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1156 {
1157         GtkWidget *label_menuitem;
1158         GtkWidget *menu;
1159         GtkWidget *item;
1160         gint i;
1161         gchar *accel_path = NULL;
1162
1163         label_menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/ColorLabel");
1164         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1165                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1166                            mainwin);
1167         gtk_widget_show(label_menuitem);
1168
1169         menu = gtk_menu_new();
1170         gtk_menu_set_accel_group (GTK_MENU (menu), 
1171                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1172
1173         /* create sub items. for the menu item activation callback we pass the
1174          * index of label_colors[] as data parameter. for the None color we
1175          * pass an invalid (high) value. also we attach a data pointer so we
1176          * can always get back the Mainwindow pointer. */
1177
1178         item = gtk_check_menu_item_new_with_label(_("None"));
1179         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1180         g_signal_connect(G_OBJECT(item), "activate",
1181                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1182                            GUINT_TO_POINTER(0));
1183         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1184         gtk_widget_show(item);
1185
1186         accel_path = g_strdup_printf("<ClawsColorLabels>/None");
1187         gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1188         g_free(accel_path);
1189         gtk_accel_map_add_entry("<ClawsColorLabels>/None", GDK_KEY_0, GDK_CONTROL_MASK);
1190         item = gtk_menu_item_new();
1191         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1192         gtk_widget_show(item);
1193
1194         /* create pixmap/label menu items */
1195         for (i = 0; i < N_COLOR_LABELS; i++) {
1196                 item = colorlabel_create_check_color_menu_item(
1197                         i, refresh, MAINWIN_COLORMENU);
1198                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1199                 g_signal_connect(G_OBJECT(item), "activate",
1200                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1201                                  GUINT_TO_POINTER(i + 1));
1202                 g_object_set_data(G_OBJECT(item), "mainwin",
1203                                   mainwin);
1204                 gtk_widget_show(item);
1205                 accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i+1);
1206                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1207                 if (i < 9)
1208                         gtk_accel_map_add_entry(accel_path, GDK_KEY_1+i, GDK_CONTROL_MASK);
1209                 g_free(accel_path);
1210                 g_signal_connect (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
1211                         "accel-changed", G_CALLBACK (mainwin_accel_changed_cb), item);
1212
1213
1214         }
1215         gtk_widget_show(menu);
1216         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1217         mainwin->colorlabel_menu = menu;
1218 }
1219
1220 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1221                                                      gpointer data)
1222 {
1223         MainWindow *mainwin;
1224
1225         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1226         cm_return_if_fail(mainwin != NULL);
1227
1228         /* "dont_toggle" state set? */
1229         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1230                                 "dont_toggle"))
1231                 return;
1232         
1233         tag_apply_open(summary_get_selection(mainwin->summaryview));    
1234 }
1235
1236 static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b)
1237 {
1238         gint id_a = GPOINTER_TO_INT(a);
1239         gint id_b = GPOINTER_TO_INT(b);
1240         const gchar *tag_a = tags_get_tag(id_a);
1241         const gchar *tag_b = tags_get_tag(id_b);
1242         
1243                 
1244         if (tag_a == NULL)
1245                 return tag_b == NULL ? 0:1;
1246         
1247         if (tag_b == NULL)
1248                 return 1;
1249  
1250         return g_utf8_collate(tag_a, tag_b);
1251 }
1252
1253 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1254 {
1255         GtkWidget *label_menuitem;
1256         GtkWidget *menu;
1257         GtkWidget *item;
1258         GSList *cur = tags_get_list();
1259         GSList *orig = NULL;
1260         gboolean existing_tags = FALSE;
1261         gchar *accel_path;
1262         cur = orig = g_slist_sort(cur, mainwin_tag_cmp_list);
1263
1264         label_menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Tags");
1265         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1266                          G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1267                            mainwin);
1268
1269         gtk_widget_show(label_menuitem);
1270
1271         menu = gtk_menu_new();
1272         gtk_menu_set_accel_group (GTK_MENU (menu), 
1273                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1274
1275         /* create tags menu items */
1276         for (; cur; cur = cur->next) {
1277                 gint id = GPOINTER_TO_INT(cur->data);
1278                 const gchar *tag = tags_get_tag(id);
1279
1280                 item = gtk_check_menu_item_new_with_label(tag);
1281                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1282                 g_signal_connect(G_OBJECT(item), "activate",
1283                                  G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1284                                  GINT_TO_POINTER(id));
1285                 g_object_set_data(G_OBJECT(item), "mainwin",
1286                                   mainwin);
1287                 g_object_set_data(G_OBJECT(item), "tag_id",
1288                                   GINT_TO_POINTER(id));
1289                 gtk_widget_show(item);
1290                 accel_path = g_strconcat("<ClawsTags>/",tag, NULL);
1291                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1292                 g_free(accel_path);
1293                 existing_tags = TRUE;
1294         }
1295         if (existing_tags) {
1296                 /* separator */
1297                 item = gtk_menu_item_new();
1298                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1299                 gtk_widget_show(item);
1300         }
1301
1302         item = gtk_menu_item_new_with_label(_("Apply tags..."));
1303         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1304         g_signal_connect(G_OBJECT(item), "activate",
1305                          G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1306                          NULL);
1307         g_object_set_data(G_OBJECT(item), "mainwin",
1308                           mainwin);
1309         gtk_widget_show(item);
1310         accel_path = g_strdup_printf("<ClawsTags>/ApplyTags");
1311         gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1312         g_free(accel_path);
1313         gtk_accel_map_add_entry("<ClawsTags>/ApplyTags", GDK_KEY_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK);
1314         g_slist_free(orig);
1315         gtk_widget_show(menu);
1316         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1317         mainwin->tags_menu = menu;
1318 }
1319 #ifndef GENERIC_UMPC
1320 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1321                                     MainWindow *mainwindow)
1322 {
1323         if (evt && evt->button == 1) {
1324                 log_window_show_error(mainwindow->logwin);
1325                 gtk_widget_hide(mainwindow->warning_btn);
1326         }
1327         return FALSE;
1328 }
1329
1330 static gboolean warning_visi_notify(GtkWidget *widget,
1331                                        GdkEventVisibility *event,
1332                                        MainWindow *mainwindow)
1333 {
1334         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), hand_cursor);
1335         return FALSE;
1336 }
1337
1338 static gboolean warning_leave_notify(GtkWidget *widget,
1339                                       GdkEventCrossing *event,
1340                                       MainWindow *mainwindow)
1341 {
1342         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), NULL);
1343         return FALSE;
1344 }
1345
1346 static gboolean warning_enter_notify(GtkWidget *widget,
1347                                       GdkEventCrossing *event,
1348                                       MainWindow *mainwindow)
1349 {
1350         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), hand_cursor);
1351         return FALSE;
1352 }
1353 #endif
1354 void mainwindow_show_error(void)
1355 {
1356         MainWindow *mainwin = mainwindow_get_mainwindow();
1357         gtk_widget_show(mainwin->warning_btn);
1358 }
1359
1360 void mainwindow_clear_error(MainWindow *mainwin)
1361 {
1362         gtk_widget_hide(mainwin->warning_btn);
1363 }
1364
1365 #define BREAK_ON_MODIFIER_KEY() \
1366         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
1367
1368 static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
1369                                     gpointer data)
1370 {
1371         MainWindow *mainwin = (MainWindow*) data;
1372         
1373         if (!mainwin || !event) 
1374                 return FALSE;
1375
1376         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
1377         {
1378                 lastkey = event->keyval;
1379                 return FALSE;
1380         }
1381
1382         switch (event->keyval) {
1383         case GDK_KEY_Q:             /* Quit */
1384                 BREAK_ON_MODIFIER_KEY();
1385
1386                 if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
1387                         app_exit_cb(NULL, mainwin);
1388                 }
1389                 return FALSE;
1390         case GDK_KEY_space:
1391                 BREAK_ON_MODIFIER_KEY();
1392                 if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
1393                         if (mainwin->folderview != NULL && mainwin->summaryview != NULL
1394                             && ((!mainwin->summaryview->displayed
1395                                 && !mainwin->summaryview->selected) 
1396                                 || (mainwin->summaryview->folder_item
1397                                     && mainwin->summaryview->folder_item->total_msgs == 0))) {
1398                                 g_signal_stop_emission_by_name(G_OBJECT(widget), 
1399                                                "key_press_event");
1400                                 folderview_select_next_with_flag(mainwin->folderview, MSG_UNREAD, TRUE);
1401                         }
1402                 }
1403                 break;
1404         default:
1405                 break;
1406         }
1407         return FALSE;
1408 }
1409
1410 #undef BREAK_ON_MODIFIER_KEY
1411
1412 MainWindow *main_window_create()
1413 {
1414         MainWindow *mainwin;
1415         GtkWidget *window;
1416         GtkWidget *vbox;
1417         GtkWidget *menubar;
1418         GtkWidget *handlebox;
1419         GtkWidget *vbox_body;
1420         GtkWidget *menuitem;
1421 #ifndef GENERIC_UMPC
1422         GtkWidget *hbox_stat;
1423         GtkWidget *statusbar;
1424         GtkWidget *progressbar;
1425         GtkWidget *statuslabel;
1426         GtkWidget *ac_button;
1427         GtkWidget *ac_label;
1428         GtkWidget *online_pixmap;
1429         GtkWidget *offline_pixmap;
1430         GtkWidget *warning_icon;
1431         GtkWidget *warning_btn;
1432 #endif
1433         GtkWidget *online_switch;
1434         GtkWidget *offline_switch;
1435         FolderView *folderview;
1436         SummaryView *summaryview;
1437         MessageView *messageview;
1438 #if !GTK_CHECK_VERSION(3, 0, 0)
1439         GdkColormap *colormap;
1440         gboolean success[4];
1441 #endif
1442         GdkColor color[4];
1443         GtkWidget *ac_menu;
1444         gint i;
1445
1446         static GdkGeometry geometry;
1447
1448         debug_print("Creating main window...\n");
1449         mainwin = g_new0(MainWindow, 1);
1450
1451         /* main window */
1452         window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1453         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION_FRIENDLY);
1454         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1455 #ifdef GENERIC_UMPC
1456         prefs_common.layout_mode = SMALL_LAYOUT;
1457 #endif
1458         if (!geometry.min_height) {
1459                 geometry.min_width = 320;
1460                 geometry.min_height = 200;
1461         }
1462         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1463                                       GDK_HINT_MIN_SIZE);
1464
1465         g_signal_connect(G_OBJECT(window), "delete_event",
1466                          G_CALLBACK(main_window_close_cb), mainwin);
1467         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1468         g_signal_connect(G_OBJECT(window), "focus_in_event",
1469                          G_CALLBACK(mainwindow_focus_in_event),
1470                          mainwin);
1471         g_signal_connect(G_OBJECT(window), "key_press_event",
1472                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1473
1474         gtk_widget_realize(window);
1475         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1476         
1477
1478         gtkut_widget_set_app_icon(window);
1479
1480         vbox = gtk_vbox_new(FALSE, 0);
1481         gtk_widget_show(vbox);
1482         gtk_container_add(GTK_CONTAINER(window), vbox);
1483
1484         /* menu bar */
1485
1486         mainwin->ui_manager = gtk_ui_manager_new();
1487         mainwin->action_group = cm_menu_create_action_group_full(mainwin->ui_manager,"Menu", mainwin_entries,
1488                         G_N_ELEMENTS(mainwin_entries), (gpointer)mainwin);
1489         gtk_action_group_add_toggle_actions(mainwin->action_group, mainwin_toggle_entries,
1490                         G_N_ELEMENTS(mainwin_toggle_entries), (gpointer)mainwin);
1491         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_showhide_radio_entries,
1492                         G_N_ELEMENTS(mainwin_showhide_radio_entries), C_AUTO, G_CALLBACK(toggle_toolbar_cb), (gpointer)mainwin);
1493 #ifndef GENERIC_UMPC
1494         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_layout_radio_entries,
1495                         G_N_ELEMENTS(mainwin_layout_radio_entries), C_AUTO, G_CALLBACK(set_layout_cb), (gpointer)mainwin);
1496 #endif
1497         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_sort_radio_entries,
1498                         G_N_ELEMENTS(mainwin_sort_radio_entries), C_AUTO, G_CALLBACK(sort_summary_cb), (gpointer)mainwin);
1499         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_sorttype_radio_entries,
1500                         G_N_ELEMENTS(mainwin_sorttype_radio_entries), C_AUTO, G_CALLBACK(sort_summary_type_cb), (gpointer)mainwin);
1501         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_radio_enc_entries,
1502                         G_N_ELEMENTS(mainwin_radio_enc_entries), C_AUTO, G_CALLBACK(set_charset_cb), (gpointer)mainwin);
1503         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_radio_dec_entries,
1504                         G_N_ELEMENTS(mainwin_radio_dec_entries), C_AUTO, G_CALLBACK(set_decode_cb), (gpointer)mainwin);
1505
1506         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
1507         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
1508         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
1509         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "View", "View", GTK_UI_MANAGER_MENU)
1510         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
1511         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Tools", "Tools", GTK_UI_MANAGER_MENU)
1512         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Configuration", "Configuration", GTK_UI_MANAGER_MENU)
1513         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Help", "Help", GTK_UI_MANAGER_MENU)
1514
1515 /* File menu */
1516         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "AddMailbox", "File/AddMailbox", GTK_UI_MANAGER_MENU)
1517         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File/AddMailbox", "MH", "File/AddMailbox/MH", GTK_UI_MANAGER_MENUITEM)
1518         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
1519         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SortMailboxes", "File/SortMailboxes", GTK_UI_MANAGER_MENUITEM)
1520         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator2", "File/---", GTK_UI_MANAGER_SEPARATOR)
1521         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ImportMbox", "File/ImportMbox", GTK_UI_MANAGER_MENUITEM)
1522         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ExportMbox", "File/ExportMbox", GTK_UI_MANAGER_MENUITEM)
1523         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ExportSelMbox", "File/ExportSelMbox", GTK_UI_MANAGER_MENUITEM)
1524         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator3", "File/---", GTK_UI_MANAGER_SEPARATOR)
1525         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "EmptyTrashes", "File/EmptyTrashes", GTK_UI_MANAGER_MENUITEM)
1526         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator4", "File/---", GTK_UI_MANAGER_SEPARATOR)
1527         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
1528         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SavePartAs", "File/SavePartAs", GTK_UI_MANAGER_MENUITEM)
1529         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator5", "File/---", GTK_UI_MANAGER_SEPARATOR)
1530         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
1531         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
1532         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
1533         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "OfflineMode", "File/OfflineMode", GTK_UI_MANAGER_MENUITEM)
1534         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SynchroniseFolders", "File/SynchroniseFolders", GTK_UI_MANAGER_MENUITEM)
1535         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator7", "File/---", GTK_UI_MANAGER_SEPARATOR)
1536         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Exit", "File/Exit", GTK_UI_MANAGER_MENUITEM)
1537
1538 /* Edit menu */
1539         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Copy", "Edit/Copy", GTK_UI_MANAGER_MENUITEM)
1540         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SelectAll", "Edit/SelectAll", GTK_UI_MANAGER_MENUITEM)
1541         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SelectThread", "Edit/SelectThread", GTK_UI_MANAGER_MENUITEM)
1542         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "DeleteThread", "Edit/DeleteThread", GTK_UI_MANAGER_MENUITEM)
1543         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Separator1", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
1544         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Find", "Edit/Find", GTK_UI_MANAGER_MENUITEM)
1545         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SearchFolder", "Edit/SearchFolder", GTK_UI_MANAGER_MENUITEM)
1546         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "QuickSearch", "Edit/QuickSearch", GTK_UI_MANAGER_MENUITEM)
1547
1548 /* View menu */
1549         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ShowHide", "View/ShowHide", GTK_UI_MANAGER_MENU)
1550         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "MenuBar", "View/ShowHide/MenuBar", GTK_UI_MANAGER_MENUITEM)
1551         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "Toolbar", "View/ShowHide/Toolbar", GTK_UI_MANAGER_MENU)
1552         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextBelowIcon", "View/ShowHide/Toolbar/TextBelowIcon", GTK_UI_MANAGER_MENUITEM)
1553         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextBesideIcon", "View/ShowHide/Toolbar/TextBesideIcon", GTK_UI_MANAGER_MENUITEM)
1554         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "IconOnly", "View/ShowHide/Toolbar/IconOnly", GTK_UI_MANAGER_MENUITEM)
1555         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextOnly", "View/ShowHide/Toolbar/TextOnly", GTK_UI_MANAGER_MENUITEM)
1556 #ifndef GENERIC_UMPC
1557         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "Hide", "View/ShowHide/Toolbar/Hide", GTK_UI_MANAGER_MENUITEM)
1558 #endif
1559         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "MessageView", "View/ShowHide/MessageView", GTK_UI_MANAGER_MENUITEM)
1560 #ifndef GENERIC_UMPC
1561         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "StatusBar", "View/ShowHide/StatusBar", GTK_UI_MANAGER_MENUITEM)
1562 #endif
1563         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "ColumnHeaders", "View/ShowHide/ColumnHeaders", GTK_UI_MANAGER_MENUITEM)
1564         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "SetColumns", "View/SetColumns", GTK_UI_MANAGER_MENU)
1565         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/SetColumns", "Folderlist", "View/SetColumns/Folderlist", GTK_UI_MANAGER_MENUITEM)
1566         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/SetColumns", "Messagelist", "View/SetColumns/Messagelist", GTK_UI_MANAGER_MENUITEM)
1567         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator1", "View/---", GTK_UI_MANAGER_SEPARATOR)
1568
1569         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "FullScreen", "View/FullScreen", GTK_UI_MANAGER_MENUITEM)
1570 #ifndef GENERIC_UMPC
1571         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Layout", "View/Layout", GTK_UI_MANAGER_MENU)
1572         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "Standard", "View/Layout/Standard", GTK_UI_MANAGER_MENUITEM)
1573         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "ThreeColumns", "View/Layout/ThreeColumns", GTK_UI_MANAGER_MENUITEM)
1574         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "WideMessage", "View/Layout/WideMessage", GTK_UI_MANAGER_MENUITEM)
1575         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "WideMessageList", "View/Layout/WideMessageList", GTK_UI_MANAGER_MENUITEM)
1576         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "SmallScreen", "View/Layout/SmallScreen", GTK_UI_MANAGER_MENUITEM)
1577         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator2", "View/---", GTK_UI_MANAGER_SEPARATOR)
1578 #endif
1579
1580         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Sort", "View/Sort", GTK_UI_MANAGER_MENU)
1581         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Number", "View/Sort/Number", GTK_UI_MANAGER_MENUITEM)
1582         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Size", "View/Sort/Size", GTK_UI_MANAGER_MENUITEM)
1583         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Date", "View/Sort/Date", GTK_UI_MANAGER_MENUITEM)
1584         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "ThreadDate", "View/Sort/ThreadDate", GTK_UI_MANAGER_MENUITEM)
1585         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "From", "View/Sort/From", GTK_UI_MANAGER_MENUITEM)
1586         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "To", "View/Sort/To", GTK_UI_MANAGER_MENUITEM)
1587         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Subject", "View/Sort/Subject", GTK_UI_MANAGER_MENUITEM)
1588         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Color", "View/Sort/Color", GTK_UI_MANAGER_MENUITEM)
1589         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Tag", "View/Sort/Tag", GTK_UI_MANAGER_MENUITEM)
1590         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Mark", "View/Sort/Mark", GTK_UI_MANAGER_MENUITEM)
1591         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Status", "View/Sort/Status", GTK_UI_MANAGER_MENUITEM)
1592         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Attachment", "View/Sort/Attachment", GTK_UI_MANAGER_MENUITEM)
1593         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Score", "View/Sort/Score", GTK_UI_MANAGER_MENUITEM)
1594         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Locked", "View/Sort/Locked", GTK_UI_MANAGER_MENUITEM)
1595         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "DontSort", "View/Sort/DontSort", GTK_UI_MANAGER_MENUITEM)
1596         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Separator1", "View/Sort/---", GTK_UI_MANAGER_SEPARATOR)
1597         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Ascending", "View/Sort/Ascending", GTK_UI_MANAGER_MENUITEM)
1598         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Descending", "View/Sort/Descending", GTK_UI_MANAGER_MENUITEM)
1599         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Separator2", "View/Sort/---", GTK_UI_MANAGER_SEPARATOR)
1600         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "AttractSubj", "View/Sort/AttractSubj", GTK_UI_MANAGER_MENUITEM)
1601
1602         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ThreadView", "View/ThreadView", GTK_UI_MANAGER_MENUITEM)
1603         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ExpandThreads", "View/ExpandThreads", GTK_UI_MANAGER_MENUITEM)
1604         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "CollapseThreads", "View/CollapseThreads", GTK_UI_MANAGER_MENUITEM)
1605         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideReadThreads", "View/HideReadThreads", GTK_UI_MANAGER_MENUITEM)
1606         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideReadMessages", "View/HideReadMessages", GTK_UI_MANAGER_MENUITEM)
1607         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideDelMessages", "View/HideDelMessages", GTK_UI_MANAGER_MENUITEM)
1608         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator3", "View/---", GTK_UI_MANAGER_SEPARATOR)
1609
1610         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Goto", "View/Goto", GTK_UI_MANAGER_MENU)
1611         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Prev", "View/Goto/Prev", GTK_UI_MANAGER_MENUITEM)
1612         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Next", "View/Goto/Next", GTK_UI_MANAGER_MENUITEM)
1613         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator1", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1614         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevUnread", "View/Goto/PrevUnread", GTK_UI_MANAGER_MENUITEM)
1615         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextUnread", "View/Goto/NextUnread", GTK_UI_MANAGER_MENUITEM)
1616         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator2", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1617         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevNew", "View/Goto/PrevNew", GTK_UI_MANAGER_MENUITEM)
1618         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextNew", "View/Goto/NextNew", GTK_UI_MANAGER_MENUITEM)
1619         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator3", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1620         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevMarked", "View/Goto/PrevMarked", GTK_UI_MANAGER_MENUITEM)
1621         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextMarked", "View/Goto/NextMarked", GTK_UI_MANAGER_MENUITEM)
1622         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator4", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1623         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevLabeled", "View/Goto/PrevLabeled", GTK_UI_MANAGER_MENUITEM)
1624         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextLabeled", "View/Goto/NextLabeled", GTK_UI_MANAGER_MENUITEM)
1625         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator5", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1626         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevHistory", "View/Goto/PrevHistory", GTK_UI_MANAGER_MENUITEM)
1627         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextHistory", "View/Goto/NextHistory", GTK_UI_MANAGER_MENUITEM)
1628         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator6", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1629         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
1630         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1631         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
1632         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "OtherFolder", "View/Goto/OtherFolder", GTK_UI_MANAGER_MENUITEM)
1633         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator8", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1634         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextPart", "View/Goto/NextPart", GTK_UI_MANAGER_MENUITEM)
1635         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevPart", "View/Goto/PrevPart", GTK_UI_MANAGER_MENUITEM)
1636         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Scroll", "View/Scroll", GTK_UI_MANAGER_MENU)
1637         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "PrevLine", "View/Scroll/PrevLine", GTK_UI_MANAGER_MENUITEM)
1638         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "NextLine", "View/Scroll/NextLine", GTK_UI_MANAGER_MENUITEM)
1639         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "PrevPage", "View/Scroll/PrevPage", GTK_UI_MANAGER_MENUITEM)
1640         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "NextPage", "View/Scroll/NextPage", GTK_UI_MANAGER_MENUITEM)
1641         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator4", "View/---", GTK_UI_MANAGER_SEPARATOR)
1642
1643         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Encoding", "View/Encoding", GTK_UI_MANAGER_MENU)
1644         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_AUTO, "View/Encoding/"CS_AUTO, GTK_UI_MANAGER_MENUITEM)
1645         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Separator1", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
1646         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_US_ASCII, "View/Encoding/"CS_US_ASCII, GTK_UI_MANAGER_MENUITEM)
1647         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_UTF_8, "View/Encoding/"CS_UTF_8, GTK_UI_MANAGER_MENUITEM)
1648         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Separator2", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
1649
1650         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Western", "View/Encoding/Western", GTK_UI_MANAGER_MENU)
1651         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Western", CS_ISO_8859_1, "View/Encoding/Western/"CS_ISO_8859_1, GTK_UI_MANAGER_MENUITEM)
1652         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Western", CS_ISO_8859_15, "View/Encoding/Western/"CS_ISO_8859_15, GTK_UI_MANAGER_MENUITEM)
1653         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Western", CS_WINDOWS_1252, "View/Encoding/Western/"CS_WINDOWS_1252, GTK_UI_MANAGER_MENUITEM)
1654
1655         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_2, "View/Encoding/"CS_ISO_8859_2, GTK_UI_MANAGER_MENUITEM)
1656
1657         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Baltic", "View/Encoding/Baltic", GTK_UI_MANAGER_MENU)
1658         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Baltic", CS_ISO_8859_13, "View/Encoding/Baltic/"CS_ISO_8859_13, GTK_UI_MANAGER_MENUITEM)
1659         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Baltic", CS_ISO_8859_4, "View/Encoding/Baltic/"CS_ISO_8859_4, GTK_UI_MANAGER_MENUITEM)
1660
1661         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_7, "View/Encoding/"CS_ISO_8859_7, GTK_UI_MANAGER_MENUITEM)
1662
1663         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Hebrew", "View/Encoding/Hebrew", GTK_UI_MANAGER_MENU)
1664         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Hebrew", CS_ISO_8859_8, "View/Encoding/Hebrew/"CS_ISO_8859_8, GTK_UI_MANAGER_MENUITEM)
1665         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Hebrew", CS_WINDOWS_1255, "View/Encoding/Hebrew/"CS_WINDOWS_1255, GTK_UI_MANAGER_MENUITEM)
1666
1667         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Arabic", "View/Encoding/Arabic", GTK_UI_MANAGER_MENU)
1668         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Arabic", CS_ISO_8859_6, "View/Encoding/Arabic/"CS_ISO_8859_6, GTK_UI_MANAGER_MENUITEM)
1669         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Arabic", CS_WINDOWS_1256, "View/Encoding/Arabic/"CS_WINDOWS_1256, GTK_UI_MANAGER_MENUITEM)
1670
1671         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_9, "View/Encoding/"CS_ISO_8859_9, GTK_UI_MANAGER_MENUITEM)
1672
1673         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
1674         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_ISO_8859_5, "View/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
1675         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
1676         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_MACCYR, "View/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
1677         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
1678         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
1679
1680         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Japanese", "View/Encoding/Japanese", GTK_UI_MANAGER_MENU)
1681         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_ISO_2022_JP, "View/Encoding/Japanese/"CS_ISO_2022_JP, GTK_UI_MANAGER_MENUITEM)
1682         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_ISO_2022_JP_2, "View/Encoding/Japanese/"CS_ISO_2022_JP_2, GTK_UI_MANAGER_MENUITEM)
1683         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_EUC_JP, "View/Encoding/Japanese/"CS_EUC_JP, GTK_UI_MANAGER_MENUITEM)
1684         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
1685
1686         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
1687         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
1688         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
1689         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
1690         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
1691         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_EUC_TW, "View/Encoding/Chinese/"CS_EUC_TW, GTK_UI_MANAGER_MENUITEM)
1692
1693         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Korean", "View/Encoding/Korean", GTK_UI_MANAGER_MENU)
1694         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Korean", CS_EUC_KR, "View/Encoding/Korean/"CS_EUC_KR, GTK_UI_MANAGER_MENUITEM)
1695         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Korean", CS_ISO_2022_KR, "View/Encoding/Korean/"CS_ISO_2022_KR, GTK_UI_MANAGER_MENUITEM)
1696
1697         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Thai", "View/Encoding/Thai", GTK_UI_MANAGER_MENU)
1698         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Thai", CS_TIS_620, "View/Encoding/Thai/"CS_TIS_620, GTK_UI_MANAGER_MENUITEM)
1699         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Thai", CS_WINDOWS_874, "View/Encoding/Thai/"CS_WINDOWS_874, GTK_UI_MANAGER_MENUITEM)
1700
1701         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Decode", "View/Decode", GTK_UI_MANAGER_MENU)
1702         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "AutoDetect", "View/Decode/AutoDetect", GTK_UI_MANAGER_MENUITEM)
1703         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "Separator1", "View/Decode/---", GTK_UI_MANAGER_SEPARATOR)
1704         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "8bit", "View/Decode/8bit", GTK_UI_MANAGER_MENUITEM)
1705         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "QP", "View/Decode/QP", GTK_UI_MANAGER_MENUITEM)
1706         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "B64", "View/Decode/B64", GTK_UI_MANAGER_MENUITEM)
1707         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "Uuencode", "View/Decode/Uuencode", GTK_UI_MANAGER_MENUITEM)
1708         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator5", "View/---", GTK_UI_MANAGER_SEPARATOR)
1709
1710         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
1711         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
1712         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
1713         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Quotes", "View/Quotes", GTK_UI_MANAGER_MENU)
1714         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "CollapseAll", "View/Quotes/CollapseAll", GTK_UI_MANAGER_MENUITEM)
1715         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "Collapse2", "View/Quotes/Collapse2", GTK_UI_MANAGER_MENUITEM)
1716         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "Collapse3", "View/Quotes/Collapse3", GTK_UI_MANAGER_MENUITEM)
1717         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Part", "View/Part", GTK_UI_MANAGER_MENU)
1718         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Part", "AsText", "View/Part/AsText", GTK_UI_MANAGER_MENUITEM)
1719         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Part", "Open", "View/Part/Open", GTK_UI_MANAGER_MENUITEM)
1720 #ifndef G_OS_WIN32
1721         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Part", "OpenWith", "View/Part/OpenWith", GTK_UI_MANAGER_MENUITEM)
1722 #endif
1723         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator8", "View/---", GTK_UI_MANAGER_SEPARATOR)
1724         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "UpdateSummary", "View/UpdateSummary", GTK_UI_MANAGER_MENUITEM)
1725
1726 /* Message menu */
1727         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Receive", "Message/Receive", GTK_UI_MANAGER_MENU)
1728         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "CurrentAccount", "Message/Receive/CurrentAccount", GTK_UI_MANAGER_MENUITEM)
1729         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "AllAccounts", "Message/Receive/AllAccounts", GTK_UI_MANAGER_MENUITEM)
1730         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "CancelReceiving", "Message/Receive/CancelReceiving", GTK_UI_MANAGER_MENUITEM)
1731         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "Separator1", "Message/Receive/---", GTK_UI_MANAGER_SEPARATOR)
1732         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "PlaceHolder", "Message/Receive/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1733         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "SendQueue", "Message/SendQueue", GTK_UI_MANAGER_MENUITEM)
1734         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "CancelSending", "Message/CancelSending", GTK_UI_MANAGER_MENUITEM)
1735         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1736
1737         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ComposeEmail", "Message/ComposeEmail", GTK_UI_MANAGER_MENUITEM)
1738         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ComposeNews", "Message/ComposeNews", GTK_UI_MANAGER_MENUITEM)
1739         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
1740         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ReplyTo", "Message/ReplyTo", GTK_UI_MANAGER_MENU)
1741         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
1742         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
1743         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "List", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
1744         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "FollowupReply", "Message/FollowupReply", GTK_UI_MANAGER_MENUITEM)
1745         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1746
1747         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
1748         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
1749         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
1750         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "MailingList", "Message/MailingList", GTK_UI_MANAGER_MENU)
1751         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Post", "Message/MailingList/Post", GTK_UI_MANAGER_MENU)
1752         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Help", "Message/MailingList/Help", GTK_UI_MANAGER_MENU)
1753         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Subscribe", "Message/MailingList/Subscribe", GTK_UI_MANAGER_MENU)
1754         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Unsubscribe", "Message/MailingList/Unsubscribe", GTK_UI_MANAGER_MENU)
1755         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "ViewArchive", "Message/MailingList/ViewArchive", GTK_UI_MANAGER_MENU)
1756         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "ContactOwner", "Message/MailingList/ContactOwner", GTK_UI_MANAGER_MENU)
1757         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Post", "PlaceHolder", "Message/MailingList/Post/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1758         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Help", "PlaceHolder", "Message/MailingList/Help/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1759         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Subscribe", "PlaceHolder", "Message/MailingList/Subscribe/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1760         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Unsubscribe", "PlaceHolder", "Message/MailingList/Unsubscribe/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1761         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/ViewArchive", "PlaceHolder", "Message/MailingList/ViewArchive/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1762         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/ContactOwner", "PlaceHolder", "Message/MailingList/ContactOwner/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1763         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1764
1765         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
1766         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
1767         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
1768         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
1769         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "CancelNews", "Message/CancelNews", GTK_UI_MANAGER_MENUITEM)
1770         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1771
1772         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Mark", "Message/Mark", GTK_UI_MANAGER_MENU)
1773         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
1774         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
1775         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1776         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
1777         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
1778         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1779         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
1780         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1781         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
1782         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
1783         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
1784         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
1785         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator4", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1786         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
1787         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
1788         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator5", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1789         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
1790         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
1791         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ColorLabel", "Message/ColorLabel", GTK_UI_MANAGER_MENUITEM)
1792         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Tags", "Message/Tags", GTK_UI_MANAGER_MENUITEM)
1793         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator5", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1794
1795         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Reedit", "Message/Reedit", GTK_UI_MANAGER_MENUITEM)
1796         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator6", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1797         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "CheckSignature", "Message/CheckSignature", GTK_UI_MANAGER_MENUITEM)
1798
1799 /* Tools menu */
1800         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
1801         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
1802         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CollectAddresses", "Tools/CollectAddresses", GTK_UI_MANAGER_MENU)
1803         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CollectAddresses", "FromFolder", "Tools/CollectAddresses/FromFolder", GTK_UI_MANAGER_MENUITEM)
1804         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CollectAddresses", "FromSelected", "Tools/CollectAddresses/FromSelected", GTK_UI_MANAGER_MENUITEM)
1805         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1806
1807         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilterFolder", "Tools/FilterFolder", GTK_UI_MANAGER_MENUITEM)
1808         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilterSelected", "Tools/FilterSelected", GTK_UI_MANAGER_MENUITEM)
1809         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "RunProcessing", "Tools/RunProcessing", GTK_UI_MANAGER_MENUITEM)
1810         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CreateFilterRule", "Tools/CreateFilterRule", GTK_UI_MANAGER_MENU)
1811         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
1812         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
1813         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
1814         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
1815
1816         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CreateProcessingRule", "Tools/CreateProcessingRule", GTK_UI_MANAGER_MENU)
1817         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
1818         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
1819         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
1820         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
1821         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1822         
1823         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "ListUrls", "Tools/ListUrls", GTK_UI_MANAGER_MENUITEM)
1824         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator3", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1825
1826         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Actions", "Tools/Actions", GTK_UI_MANAGER_MENU)
1827         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/Actions", "PlaceHolder", "Tools/Actions/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1828         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator4", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1829
1830         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CheckNewMessages", "Tools/CheckNewMessages", GTK_UI_MANAGER_MENUITEM)
1831         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "DeleteDuplicates", "Tools/DeleteDuplicates", GTK_UI_MANAGER_MENU)
1832         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/DeleteDuplicates", "SelFolder", "Tools/DeleteDuplicates/SelFolder", GTK_UI_MANAGER_MENUITEM)
1833         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/DeleteDuplicates", "AllFolders", "Tools/DeleteDuplicates/AllFolders", GTK_UI_MANAGER_MENUITEM)
1834         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1835
1836         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Execute", "Tools/Execute", GTK_UI_MANAGER_MENUITEM)
1837         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Expunge", "Tools/Expunge", GTK_UI_MANAGER_MENUITEM)
1838 #ifdef USE_GNUTLS
1839         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator6", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1840         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "SSLCertificates", "Tools/SSLCertificates", GTK_UI_MANAGER_MENUITEM)
1841 #endif
1842         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator7", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1843 #ifndef G_OS_WIN32
1844         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilteringLog", "Tools/FilteringLog", GTK_UI_MANAGER_MENUITEM)
1845 #endif
1846         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "NetworkLog", "Tools/NetworkLog", GTK_UI_MANAGER_MENUITEM)
1847         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator8", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1848         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "ForgetSessionPasswords", "Tools/ForgetSessionPasswords", GTK_UI_MANAGER_MENUITEM)
1849         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator9", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1850
1851 /* Configuration menu */
1852         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "ChangeAccount", "Configuration/ChangeAccount", GTK_UI_MANAGER_MENU)
1853         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration/ChangeAccount", "PlaceHolder", "Configuration/ChangeAccount/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1854         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "AccountPrefs", "Configuration/AccountPrefs", GTK_UI_MANAGER_MENUITEM)
1855         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "CreateAccount", "Configuration/CreateAccount", GTK_UI_MANAGER_MENUITEM)
1856         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "EditAccounts", "Configuration/EditAccounts", GTK_UI_MANAGER_MENUITEM)
1857         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Separator1", "Configuration/---", GTK_UI_MANAGER_SEPARATOR)
1858
1859         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Preferences", "Configuration/Preferences", GTK_UI_MANAGER_MENUITEM)
1860         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "PreProcessing", "Configuration/PreProcessing", GTK_UI_MANAGER_MENUITEM)
1861         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "PostProcessing", "Configuration/PostProcessing", GTK_UI_MANAGER_MENUITEM)
1862         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Filtering", "Configuration/Filtering", GTK_UI_MANAGER_MENUITEM)
1863         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Templates", "Configuration/Templates", GTK_UI_MANAGER_MENUITEM)
1864         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Actions", "Configuration/Actions", GTK_UI_MANAGER_MENUITEM)
1865         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Tags", "Configuration/Tags", GTK_UI_MANAGER_MENUITEM)
1866
1867         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Separator2", "Configuration/---", GTK_UI_MANAGER_SEPARATOR)
1868         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Plugins", "Configuration/Plugins", GTK_UI_MANAGER_MENUITEM)
1869
1870 /* Help menu */
1871         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Manual", "Help/Manual", GTK_UI_MANAGER_MENUITEM)
1872         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "FAQ", "Help/FAQ", GTK_UI_MANAGER_MENUITEM)
1873         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "IconLegend", "Help/IconLegend", GTK_UI_MANAGER_MENUITEM)
1874 #ifdef G_OS_WIN32
1875         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator1", "Help/---", GTK_UI_MANAGER_SEPARATOR)
1876         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "SetDefault", "Help/SetDefault", GTK_UI_MANAGER_MENUITEM)
1877 #endif
1878         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator2", "Help/---", GTK_UI_MANAGER_SEPARATOR)
1879         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
1880
1881
1882         menubar = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu");
1883         if (prefs_common.mainwin_menubar)
1884                 gtk_widget_show_all(menubar);
1885         else
1886                 gtk_widget_hide(menubar);
1887         gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1888
1889         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1890
1891         if (prefs_common.toolbar_detachable) {
1892                 handlebox = gtk_handle_box_new();
1893                 gtk_widget_show(handlebox);
1894                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1895                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1896                                  G_CALLBACK(toolbar_child_attached), mainwin);
1897                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1898                                  G_CALLBACK(toolbar_child_detached), mainwin);
1899         } else {
1900                 handlebox = gtk_hbox_new(FALSE, 0);
1901                 gtk_widget_show(handlebox);
1902                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1903         }
1904         /* link window to mainwin->window to avoid gdk warnings */
1905         mainwin->window       = window;
1906         mainwin_list = g_list_append(mainwin_list, mainwin);
1907         
1908         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1909                                           handlebox, 
1910                                           (gpointer)mainwin);
1911         toolbar_set_learn_button
1912                 (mainwin->toolbar,
1913                  LEARN_SPAM);
1914
1915         /* vbox that contains body */
1916         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1917         gtk_widget_show(vbox_body);
1918         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1919         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1920
1921 #ifndef GENERIC_UMPC
1922         hbox_stat = gtk_hbox_new(FALSE, 2);
1923         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1924
1925         warning_icon = gtk_image_new_from_stock
1926                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1927         warning_btn = gtk_event_box_new();
1928         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1929         
1930         mainwin->warning_btn      = warning_btn;
1931         
1932         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1933                          G_CALLBACK(warning_icon_pressed),
1934                          (gpointer) mainwin);
1935         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1936                          G_CALLBACK(warning_visi_notify), mainwin);
1937         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1938                          G_CALLBACK(warning_leave_notify), mainwin);
1939         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1940                          G_CALLBACK(warning_enter_notify), mainwin);
1941
1942         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1943
1944         CLAWS_SET_TIP(warning_btn, 
1945                              _("Some error(s) happened. Click here to view log."));
1946         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1947
1948         statusbar = statusbar_create();
1949         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1950
1951         progressbar = gtk_progress_bar_new();
1952         gtk_widget_set_size_request(progressbar, 120, 1);
1953         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1954
1955         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1956         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1957         online_switch = gtk_button_new ();
1958         gtkut_widget_set_can_focus(online_switch, FALSE);
1959         CLAWS_SET_TIP(online_switch, 
1960                              _("You are online. Click the icon to go offline"));
1961         offline_switch = gtk_button_new ();
1962         CLAWS_SET_TIP(offline_switch, 
1963                              _("You are offline. Click the icon to go online"));
1964         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1965         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1966         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1967         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1968         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1969         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1970         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1971         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1972         
1973         statuslabel = gtk_label_new("");
1974         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1975
1976         ac_button = gtk_button_new();
1977         CLAWS_SET_TIP(ac_button, _("Select account"));
1978         gtkut_widget_set_can_focus(ac_button, FALSE);
1979         gtk_widget_set_size_request(ac_button, -1, 0);
1980         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1981         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1982                          G_CALLBACK(ac_label_button_pressed), mainwin);
1983
1984         ac_label = gtk_label_new("");
1985         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1986
1987         gtk_widget_show_all(hbox_stat);
1988
1989         gtk_widget_hide(offline_switch);
1990         gtk_widget_hide(progressbar);
1991         gtk_widget_hide(warning_btn);
1992 #else
1993         online_switch = gtk_button_new ();
1994         offline_switch = gtk_button_new ();
1995         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1996         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1997 #endif
1998         /* create views */
1999         mainwin->folderview  = folderview  = folderview_create();
2000         mainwin->summaryview = summaryview = summary_create(mainwin);
2001         mainwin->messageview = messageview = messageview_create(mainwin);
2002
2003         /* init log instances data before creating log views */
2004         set_log_title(LOG_PROTOCOL, _("Network log"));
2005         set_log_prefs(LOG_PROTOCOL,
2006                         &prefs_common.logwin_width,
2007                         &prefs_common.logwin_height);
2008         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/Processing debug log"));
2009         set_log_prefs(LOG_DEBUG_FILTERING,
2010                         &prefs_common.filtering_debugwin_width,
2011                         &prefs_common.filtering_debugwin_height);
2012
2013         /* setup log windows */
2014         mainwin->logwin = log_window_create(LOG_PROTOCOL);
2015         log_window_init(mainwin->logwin);
2016
2017         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
2018         log_window_set_clipping(mainwin->logwin,
2019                                 prefs_common.cliplog,
2020                                 prefs_common.loglength);
2021
2022         log_window_init(mainwin->filtering_debugwin);
2023         log_window_set_clipping(mainwin->filtering_debugwin,
2024                                 prefs_common.filtering_debug_cliplog,
2025                                 prefs_common.filtering_debug_loglength);
2026         if (prefs_common.enable_filtering_debug)
2027                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
2028         else
2029                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
2030
2031         folderview->mainwin      = mainwin;
2032         folderview->summaryview  = summaryview;
2033
2034         summaryview->mainwin     = mainwin;
2035         summaryview->folderview  = folderview;
2036         summaryview->messageview = messageview;
2037         summaryview->window      = window;
2038
2039         mainwin->vbox           = vbox;
2040         mainwin->menubar        = menubar;
2041         mainwin->handlebox      = handlebox;
2042         mainwin->vbox_body      = vbox_body;
2043         mainwin->online_switch  = online_switch;
2044         mainwin->offline_switch    = offline_switch;
2045 #ifndef GENERIC_UMPC
2046         messageview->statusbar  = statusbar;
2047         mainwin->statusbar      = statusbar;
2048         mainwin->hbox_stat      = hbox_stat;
2049         mainwin->progressbar    = progressbar;
2050         mainwin->statuslabel    = statuslabel;
2051         mainwin->online_pixmap  = online_pixmap;
2052         mainwin->offline_pixmap = offline_pixmap;
2053         mainwin->ac_button      = ac_button;
2054         mainwin->ac_label       = ac_label;
2055         /* set context IDs for status bar */
2056         mainwin->mainwin_cid = gtk_statusbar_get_context_id
2057                 (GTK_STATUSBAR(statusbar), "Main Window");
2058         mainwin->folderview_cid = gtk_statusbar_get_context_id
2059                 (GTK_STATUSBAR(statusbar), "Folder View");
2060         mainwin->summaryview_cid = gtk_statusbar_get_context_id
2061                 (GTK_STATUSBAR(statusbar), "Summary View");
2062         mainwin->messageview_cid = gtk_statusbar_get_context_id
2063                 (GTK_STATUSBAR(statusbar), "Message View");
2064         messageview->statusbar_cid = mainwin->messageview_cid;
2065
2066 #else
2067         messageview->statusbar  = NULL;
2068         mainwin->statusbar      = NULL;
2069         mainwin->hbox_stat      = NULL;
2070         /* mainwin->progressbar is set in toolbar.c */
2071         mainwin->statuslabel    = NULL;
2072         mainwin->online_pixmap  = NULL;
2073         mainwin->offline_pixmap = NULL;
2074         mainwin->ac_button      = NULL;
2075         mainwin->ac_label       = NULL;
2076 #endif
2077         
2078         /* allocate colors for summary view and folder view */
2079         summaryview->color_marked.red = summaryview->color_marked.green = 0;
2080         summaryview->color_marked.blue = (guint16)65535;
2081
2082         summaryview->color_dim.red = summaryview->color_dim.green =
2083                 summaryview->color_dim.blue = COLOR_DIM;
2084
2085         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
2086                                        &folderview->color_new);
2087
2088         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
2089                                        &folderview->color_op);
2090
2091         summaryview->color_important.red = 0;
2092         summaryview->color_important.green = 0;
2093         summaryview->color_important.blue = (guint16)65535;
2094
2095         color[0] = summaryview->color_marked;
2096         color[1] = summaryview->color_dim;
2097         color[2] = folderview->color_new;
2098         color[3] = folderview->color_op;
2099
2100 #if !GTK_CHECK_VERSION(3, 0, 0)
2101         colormap = gdk_drawable_get_colormap(gtk_widget_get_window(window));
2102         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
2103         for (i = 0; i < 4; i++) {
2104                 if (success[i] == FALSE)
2105                         g_warning("MainWindow: color allocation %d failed\n", i);
2106         }
2107 #endif
2108
2109         debug_print("done.\n");
2110
2111         messageview->visible = prefs_common.msgview_visible;
2112
2113         main_window_set_widgets(mainwin, prefs_common.layout_mode);
2114
2115         g_signal_connect(G_OBJECT(window), "size_allocate",
2116                          G_CALLBACK(main_window_size_allocate_cb),
2117                          mainwin);
2118
2119         /* set menu items */
2120         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Encoding/"CS_AUTO, TRUE);
2121
2122         menuitem = NULL;
2123         switch (prefs_common.toolbar_style) {
2124         case TOOLBAR_NONE:
2125                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/Hide");
2126                 break;
2127         case TOOLBAR_ICON:
2128                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/IconOnly");
2129                 break;
2130         case TOOLBAR_TEXT:
2131                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextOnly");
2132                 break;
2133         case TOOLBAR_BOTH:
2134                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextBelowIcon");
2135                 break;
2136         case TOOLBAR_BOTH_HORIZ:
2137                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextBesideIcon");
2138         }
2139         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2140
2141         toolbar_set_style(mainwin->toolbar->toolbar, 
2142                           mainwin->handlebox, 
2143                           prefs_common.toolbar_style);
2144 #ifndef GENERIC_UMPC
2145         gtk_widget_hide(mainwin->hbox_stat);
2146         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/StatusBar");
2147         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2148                                        prefs_common.show_statusbar);
2149 #endif  
2150         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/ColumnHeaders");
2151         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2152                                        prefs_common.show_col_headers);
2153         /* set account selection menu */
2154         ac_menu = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Configuration/ChangeAccount");
2155         mainwin->ac_menu = ac_menu;
2156
2157         toolbar_main_set_sensitive(mainwin);
2158
2159         /* create actions menu */
2160         main_window_update_actions_menu(mainwin);
2161
2162         main_create_mailing_list_menu (mainwin, NULL);
2163
2164         /* attach accel groups to main window */
2165 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
2166         gtk_window_add_accel_group                                      \
2167                 (GTK_WINDOW(win),                                       \
2168                  gtk_ui_manager_get_accel_group(gtkut_ui_manager()));   \
2169         g_signal_connect(G_OBJECT(gtk_ui_manager_get_accel_group(gtkut_ui_manager())), \
2170                         "accel_activate",                               \
2171                         G_CALLBACK(main_window_accel_activate), mainwin);
2172
2173         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
2174         
2175         g_signal_connect(G_OBJECT(window), "window_state_event",
2176                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
2177         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
2178                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
2179         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
2180
2181         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
2182             prefs_common.layout_mode == SMALL_LAYOUT) {
2183                 summary_relayout(mainwin->summaryview); 
2184         }
2185         summary_update_unread(mainwin->summaryview, NULL);
2186         
2187         /* initialize views */
2188         folderview_init(folderview);
2189         summary_init(summaryview);
2190         messageview_init(messageview);
2191 #ifdef USE_GNUTLS
2192         sslcertwindow_register_hook();
2193 #endif
2194         mainwin->lock_count = 0;
2195         mainwin->menu_lock_count = 0;
2196         mainwin->cursor_count = 0;
2197
2198         mainwin->progressindicator_hook =
2199                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
2200
2201         if (!watch_cursor)
2202                 watch_cursor = gdk_cursor_new(GDK_WATCH);
2203         if (!hand_cursor)
2204                 hand_cursor = gdk_cursor_new(GDK_HAND2);
2205
2206         /* init work_offline */
2207         if (prefs_common.work_offline)
2208                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
2209
2210         mainwindow_colorlabel_menu_create(mainwin, FALSE);
2211         mainwindow_tags_menu_create(mainwin, FALSE);
2212
2213         if (prefs_common.mainwin_fullscreen) {
2214                 cm_toggle_menu_set_active_full(mainwin->ui_manager, 
2215                         "Menu/View/FullScreen",
2216                         TRUE);
2217         }
2218         if (prefs_common.mainwin_menubar)
2219                 cm_toggle_menu_set_active_full(mainwin->ui_manager,"Menu/View/ShowHide/MenuBar", TRUE);
2220         
2221         return mainwin;
2222 }
2223
2224 void main_window_update_actions_menu(MainWindow *mainwin)
2225 {
2226         action_update_mainwin_menu(mainwin->ui_manager, "/Menu/Tools/Actions", mainwin);
2227 }
2228
2229 void main_window_cursor_wait(MainWindow *mainwin)
2230 {
2231
2232         if (mainwin->cursor_count == 0) {
2233                 gdk_window_set_cursor(gtk_widget_get_window(mainwin->window), watch_cursor);
2234                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
2235         }
2236         
2237         mainwin->cursor_count++;
2238
2239         gdk_flush();
2240 }
2241
2242 void main_window_cursor_normal(MainWindow *mainwin)
2243 {
2244         if (mainwin->cursor_count)
2245                 mainwin->cursor_count--;
2246
2247         if (mainwin->cursor_count == 0) {
2248                 gdk_window_set_cursor(gtk_widget_get_window(mainwin->window), NULL);
2249                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
2250         }
2251         gdk_flush();
2252 }
2253
2254 /* lock / unlock the user-interface */
2255 void main_window_lock(MainWindow *mainwin)
2256 {
2257         if (mainwin->lock_count == 0 && mainwin->ac_button)
2258                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
2259
2260         mainwin->lock_count++;
2261
2262         main_window_set_menu_sensitive(mainwin);
2263         toolbar_main_set_sensitive(mainwin);
2264 }
2265
2266 void main_window_unlock(MainWindow *mainwin)
2267 {
2268         if (mainwin->lock_count)
2269                 mainwin->lock_count--;
2270
2271         main_window_set_menu_sensitive(mainwin);
2272         toolbar_main_set_sensitive(mainwin);
2273
2274         if (mainwin->lock_count == 0 && mainwin->ac_button)
2275                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
2276 }
2277
2278 static void main_window_menu_callback_block(MainWindow *mainwin)
2279 {
2280         mainwin->menu_lock_count++;
2281 }
2282
2283 static void main_window_menu_callback_unblock(MainWindow *mainwin)
2284 {
2285         if (mainwin->menu_lock_count)
2286                 mainwin->menu_lock_count--;
2287 }
2288
2289 static guint prefs_tag = 0;
2290
2291 void main_window_reflect_prefs_all(void)
2292 {
2293         main_window_reflect_prefs_all_real(FALSE);
2294 }
2295
2296 static gboolean reflect_prefs_timeout_cb(gpointer data) 
2297 {
2298         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
2299         GList *cur;
2300         MainWindow *mainwin;
2301 #ifndef GENERIC_UMPC
2302         GtkWidget *pixmap;
2303 #endif
2304         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2305                 mainwin = (MainWindow *)cur->data;
2306
2307                 main_window_show_cur_account(mainwin);
2308                 main_window_set_menu_sensitive(mainwin);
2309                 toolbar_main_set_sensitive(mainwin);
2310
2311                 /* pixmap themes */
2312                 if (pixmap_theme_changed) {
2313                         toolbar_update(TOOLBAR_MAIN, mainwin);
2314                         messageview_reflect_prefs_pixmap_theme();
2315                         compose_reflect_prefs_pixmap_theme();
2316                         folderview_reinit_fonts(mainwin->folderview);
2317                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
2318                         foldersel_reflect_prefs_pixmap_theme();
2319 #ifndef USE_NEW_ADDRBOOK
2320                         addressbook_reflect_prefs_pixmap_theme();
2321 #endif
2322 #ifndef GENERIC_UMPC
2323                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
2324                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
2325                                              mainwin->online_pixmap);
2326                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
2327                         gtk_widget_show(pixmap);
2328                         mainwin->online_pixmap = pixmap;
2329                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
2330                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
2331                                              mainwin->offline_pixmap);
2332                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
2333                         gtk_widget_show(pixmap);
2334                         mainwin->offline_pixmap = pixmap;
2335 #endif
2336                         hooks_invoke(THEME_CHANGED_HOOKLIST, NULL);
2337                 }
2338                 
2339                 headerview_set_font(mainwin->messageview->headerview);
2340                 headerview_set_visibility(mainwin->messageview->headerview,
2341                                           prefs_common.display_header_pane);
2342                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
2343                 folderview_reflect_prefs();
2344                 summary_reflect_prefs();
2345 #ifndef GENERIC_UMPC
2346                 summary_redisplay_msg(mainwin->summaryview);
2347 #endif
2348                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2349                         if (mainwin->in_folder) {
2350                                 mainwindow_enter_folder(mainwin);
2351                         } else {
2352                                 mainwindow_exit_folder(mainwin);
2353                         }
2354                 }
2355         }
2356         prefs_tag = 0;
2357         return FALSE;
2358 }
2359
2360 void main_window_reflect_prefs_all_now(void)
2361 {
2362         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
2363 }
2364
2365 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
2366 {
2367         GtkMenuShell *menu;
2368         GList *children, *cur;
2369
2370         /* re-create colorlabel submenu */
2371         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
2372         cm_return_if_fail(menu != NULL);
2373
2374         /* clear items. get item pointers. */
2375         children = gtk_container_get_children(GTK_CONTAINER(menu));
2376         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2377                 g_signal_handlers_disconnect_matched
2378                          (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
2379                          G_SIGNAL_MATCH_DATA|G_SIGNAL_MATCH_FUNC,
2380                          0, 0, NULL, mainwin_accel_changed_cb, cur->data);
2381                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2382         }
2383         g_list_free(children);
2384         mainwindow_colorlabel_menu_create(mainwin, TRUE);
2385         summary_reflect_prefs_custom_colors(mainwin->summaryview);
2386         folderview_reinit_fonts(mainwin->folderview);
2387 }
2388
2389 static gint tags_tag = 0;
2390 static gboolean main_window_reflect_tags_changes_real(gpointer data)
2391 {
2392         GtkMenuShell *menu;
2393         GList *children, *cur;
2394         MainWindow *mainwin = (MainWindow *)data;
2395
2396         if (summary_is_locked(mainwin->summaryview)) {
2397                 return TRUE;
2398         }
2399         /* re-create tags submenu */
2400         menu = GTK_MENU_SHELL(mainwin->tags_menu);
2401         cm_return_val_if_fail(menu != NULL, FALSE);
2402
2403         /* clear items. get item pointers. */
2404         children = gtk_container_get_children(GTK_CONTAINER(menu));
2405         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2406                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2407         }
2408         g_list_free(children);
2409         mainwindow_tags_menu_create(mainwin, TRUE);
2410         summary_reflect_tags_changes(mainwin->summaryview);
2411         
2412         tags_tag = 0;
2413         return FALSE;
2414 }
2415
2416 void main_window_reflect_tags_changes(MainWindow *mainwin)
2417 {
2418         if (tags_tag == 0) {
2419                 tags_tag = g_timeout_add(100, main_window_reflect_tags_changes_real, 
2420                                                 mainwin);
2421         }
2422 }
2423
2424 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
2425 {
2426         if (prefs_tag == 0) {
2427                 prefs_tag = g_timeout_add(100, reflect_prefs_timeout_cb, 
2428                                                 GINT_TO_POINTER(pixmap_theme_changed));
2429         }
2430 }
2431
2432 void main_window_set_summary_column(void)
2433 {
2434         GList *cur;
2435         MainWindow *mainwin;
2436
2437         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2438                 mainwin = (MainWindow *)cur->data;
2439                 summary_set_column_order(mainwin->summaryview);
2440         }
2441 }
2442
2443 void main_window_set_folder_column(void)
2444 {
2445         GList *cur;
2446         MainWindow *mainwin;
2447
2448         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2449                 mainwin = (MainWindow *)cur->data;
2450                 folderview_set_column_order(mainwin->folderview);
2451         }
2452 }
2453
2454 static void main_window_set_account_selector_menu(MainWindow *mainwin,
2455                                                   GList *account_list)
2456 {
2457         GList *cur_ac;
2458         GtkWidget *menuitem;
2459         PrefsAccount *ac_prefs;
2460         GtkWidget *menu;
2461         gchar *accel_path;
2462
2463         menu = gtk_menu_new();
2464         gtk_menu_set_accel_group (GTK_MENU (menu), 
2465                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
2466
2467         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2468                 ac_prefs = (PrefsAccount *)cur_ac->data;
2469
2470                 menuitem = gtk_menu_item_new_with_label
2471                         (ac_prefs->account_name
2472                          ? ac_prefs->account_name : _("Untitled"));
2473                 gtk_widget_show(menuitem);
2474                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2475                 g_signal_connect(G_OBJECT(menuitem), "activate",
2476                                  G_CALLBACK(account_selector_menu_cb),
2477                                  ac_prefs);
2478                 accel_path = g_strconcat("<Actions>/Menu/Configuration/ChangeAccount/",(ac_prefs->account_name
2479                          ? ac_prefs->account_name : _("Untitled")), NULL );
2480                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), accel_path);
2481                 g_free(accel_path);
2482         }
2483         gtk_menu_item_set_submenu(GTK_MENU_ITEM(mainwin->ac_menu), menu);
2484 }
2485
2486 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2487                                                  GList *account_list)
2488 {
2489         GList *children, *child;
2490         GtkWidget *menu;
2491         GtkWidget *menuitem;
2492         PrefsAccount *ac_prefs;
2493
2494         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
2495                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive")));
2496
2497         /* search for separator */
2498         children = gtk_container_get_children(GTK_CONTAINER(menu));
2499         for (child = children; child != NULL; child = child->next) {
2500                 if (child->data == gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive/Separator1")) {
2501                         child = child->next;
2502                         break;
2503                 }
2504         }
2505
2506         /* destroy all previous menu item */
2507         while (child != NULL) {
2508                 gtk_widget_destroy(GTK_WIDGET(child->data));
2509                 child = child->next;
2510         }
2511
2512         g_list_free(children);
2513
2514         for (child = account_list; child != NULL; child = child->next) {
2515                 ac_prefs = (PrefsAccount *)child->data;
2516
2517                 if (ac_prefs->protocol == A_NONE)
2518                         continue;
2519
2520                 menuitem = gtk_menu_item_new_with_label
2521                         (ac_prefs->account_name ? ac_prefs->account_name
2522                          : _("Untitled"));
2523                 gtk_widget_show(menuitem);
2524                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2525                 g_signal_connect(G_OBJECT(menuitem), "activate",
2526                                  G_CALLBACK(account_receive_menu_cb),
2527                                  ac_prefs);
2528         }
2529 }
2530
2531 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2532                                                        GList *account_list)
2533 {
2534         GList *cur_ac;
2535         GtkWidget *menuitem;
2536         PrefsAccount *ac_prefs;
2537         GtkWidget *menu = NULL;
2538
2539         if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2540                 return;
2541
2542         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2543         if (menu)
2544                 gtk_widget_destroy(menu);
2545         menu = gtk_menu_new();
2546
2547         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2548                 ac_prefs = (PrefsAccount *)cur_ac->data;
2549
2550                 if (ac_prefs->protocol == A_NONE)
2551                         continue;
2552
2553                 menuitem = gtk_menu_item_new_with_label
2554                         (ac_prefs->account_name
2555                          ? ac_prefs->account_name : _("Untitled"));
2556                 gtk_widget_show(menuitem);
2557                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2558                 g_signal_connect(G_OBJECT(menuitem), "activate",
2559                                  G_CALLBACK(account_receive_menu_cb),
2560                                  ac_prefs);
2561         }
2562         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2563 }
2564
2565 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2566                                                        GList *account_list)
2567 {
2568 #ifndef GENERIC_UMPC
2569         GList *cur_ac;
2570         GtkWidget *menuitem;
2571         PrefsAccount *ac_prefs;
2572         GtkWidget *menu = NULL;
2573
2574         if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2575                 return;
2576
2577         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2578         if (menu)
2579                 gtk_widget_destroy(menu);
2580         menu = gtk_menu_new();
2581
2582         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2583                 ac_prefs = (PrefsAccount *)cur_ac->data;
2584
2585                 menuitem = gtk_menu_item_new_with_label
2586                         (ac_prefs->account_name
2587                          ? ac_prefs->account_name : _("Untitled"));
2588                 gtk_widget_show(menuitem);
2589                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2590                 g_signal_connect(G_OBJECT(menuitem), "activate",
2591                                  G_CALLBACK(account_compose_menu_cb),
2592                                  ac_prefs);
2593         }
2594         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2595 #endif
2596 }
2597
2598 void main_window_set_account_menu(GList *account_list)
2599 {
2600         GList *cur;
2601         MainWindow *mainwin;
2602
2603         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2604                 mainwin = (MainWindow *)cur->data;
2605                 main_window_set_account_selector_menu(mainwin, account_list);
2606                 main_window_set_account_receive_menu(mainwin, account_list);
2607                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2608                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2609         }
2610         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2611 }
2612
2613 void main_window_set_account_menu_only_toolbar(GList *account_list)
2614 {
2615         GList *cur;
2616         MainWindow *mainwin;
2617
2618         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2619                 mainwin = (MainWindow *)cur->data;
2620                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2621                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2622         }
2623 }
2624
2625 static void main_window_show_cur_account(MainWindow *mainwin)
2626 {
2627         gchar *buf;
2628         gchar *ac_name;
2629
2630         ac_name = g_strdup(cur_account
2631                            ? (cur_account->account_name
2632                               ? cur_account->account_name : _("Untitled"))
2633                            : _("none"));
2634
2635         if (cur_account)
2636                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION_FRIENDLY);
2637         else
2638                 buf = g_strdup(PROG_VERSION_FRIENDLY);
2639         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2640         g_free(buf);
2641
2642         if (mainwin->ac_label)
2643                 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2644         if (mainwin->ac_button)
2645                 gtk_widget_queue_resize(mainwin->ac_button);
2646
2647         g_free(ac_name);
2648 }
2649 #ifndef GENERIC_UMPC
2650 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2651 {
2652         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2653         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2654         GtkWidget *message_wid = mainwin->messageview->vbox;
2655
2656         if (layout_mode == prefs_common.layout_mode) 
2657                 return;
2658
2659         debug_print("Changing window separation type from %d to %d\n",
2660                     prefs_common.layout_mode, layout_mode);
2661
2662         /* remove widgets from those containers */
2663         g_object_ref(folder_wid);
2664         g_object_ref(summary_wid);
2665         g_object_ref(message_wid);
2666         gtkut_container_remove
2667                 (GTK_CONTAINER(gtk_widget_get_parent(folder_wid)), folder_wid);
2668         gtkut_container_remove
2669                 (GTK_CONTAINER(gtk_widget_get_parent(summary_wid)), summary_wid);
2670         gtkut_container_remove
2671                 (GTK_CONTAINER(gtk_widget_get_parent(message_wid)), message_wid);
2672
2673         gtk_widget_hide(mainwin->window);
2674         main_window_set_widgets(mainwin, layout_mode);
2675         gtk_widget_show(mainwin->window);
2676
2677         g_object_unref(folder_wid);
2678         g_object_unref(summary_wid);
2679         g_object_unref(message_wid);
2680 }
2681 #endif
2682 void mainwindow_reset_paned(GtkPaned *paned)
2683 {
2684                 gint min, max, mid;
2685
2686                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2687                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2688                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2689                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2690
2691 GTK_EVENTS_FLUSH();
2692                 g_object_get (G_OBJECT(paned),
2693                                 "min-position",
2694                                 &min, NULL);
2695                 g_object_get (G_OBJECT(paned),
2696                                 "max-position",
2697                                 &max, NULL);
2698                 mid = (min+max)/2;
2699                 gtk_paned_set_position(GTK_PANED(paned), mid);
2700 }
2701
2702 static void mainwin_paned_show_first(GtkPaned *paned)
2703 {
2704                 gint max;
2705                 g_object_get (G_OBJECT(paned),
2706                                 "max-position",
2707                                 &max, NULL);
2708
2709                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2710                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2711                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2712                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2713                 gtk_paned_set_position(GTK_PANED(paned), max);
2714 }
2715
2716 static void mainwin_paned_show_last(GtkPaned *paned)
2717 {
2718                 gint min;
2719                 g_object_get (G_OBJECT(paned),
2720                                 "min-position",
2721                                 &min, NULL);
2722
2723                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2724                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2725                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2726                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2727                 gtk_paned_set_position(GTK_PANED(paned), min);
2728 }
2729
2730 void main_window_toggle_message_view(MainWindow *mainwin)
2731 {
2732         SummaryView *summaryview = mainwin->summaryview;
2733         GtkWidget *ppaned = NULL;
2734         GtkWidget *container = NULL;
2735
2736         switch (prefs_common.layout_mode) {
2737         case NORMAL_LAYOUT:
2738         case VERTICAL_LAYOUT:
2739         case SMALL_LAYOUT:
2740                 ppaned = mainwin->vpaned;
2741                 container = mainwin->hpaned;
2742                 if (gtk_widget_get_parent(ppaned) != NULL) {
2743                         mainwin->messageview->visible = FALSE;
2744                         summaryview->displayed = NULL;
2745                         g_object_ref(ppaned);
2746                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2747                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2748                 } else {
2749                         mainwin->messageview->visible = TRUE;
2750                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2751                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2752                         g_object_unref(ppaned);
2753                 }
2754                 break;
2755         case WIDE_LAYOUT:
2756                 container = mainwin->vpaned;
2757                 if (gtk_widget_get_parent(mainwin->messageview->vbox) != NULL) {
2758                         mainwin->messageview->visible = FALSE;
2759                         summaryview->displayed = NULL;
2760                         g_object_ref(mainwin->messageview->vbox);
2761                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2762                 } else {
2763                         mainwin->messageview->visible = TRUE;
2764                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2765                         g_object_unref(mainwin->messageview->vbox);
2766                 }
2767                 break;
2768         case WIDE_MSGLIST_LAYOUT:
2769                 g_warning("can't hide messageview in this wide msglist layout");
2770                 break;
2771         }
2772
2773         if (messageview_is_visible(mainwin->messageview))
2774                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2775                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2776         else
2777                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2778                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2779
2780         if (mainwin->messageview->visible == FALSE)
2781                 messageview_clear(mainwin->messageview);
2782
2783         main_window_set_menu_sensitive(mainwin);
2784
2785         prefs_common.msgview_visible = mainwin->messageview->visible;
2786
2787         if (messageview_is_visible(mainwin->messageview)) {
2788                 gtk_widget_queue_resize(mainwin->hpaned);
2789                 gtk_widget_queue_resize(mainwin->vpaned);
2790         }
2791         summary_grab_focus(summaryview);
2792         if (!summary_is_list(summaryview)) {
2793                 summary_show(summaryview, summaryview->folder_item);
2794         }
2795 }
2796
2797 void main_window_get_size(MainWindow *mainwin)
2798 {
2799         GtkAllocation allocation;
2800
2801         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2802                 debug_print("called after messageview "
2803                             "has been deallocated!\n");
2804                 return;
2805         }
2806
2807         if (prefs_common.mainwin_fullscreen) {
2808                 debug_print("mainwin in full screen state. "
2809                             "Keeping original settings\n");
2810         }
2811
2812         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->summaryview), &allocation);
2813         if (allocation.width > 1 && allocation.height > 1 && !prefs_common.mainwin_fullscreen) {
2814                 prefs_common.summaryview_width = allocation.width;
2815
2816                 if (messageview_is_visible(mainwin->messageview))
2817                         prefs_common.summaryview_height = allocation.height;
2818
2819                 prefs_common.mainview_width = allocation.width;
2820         }
2821
2822         gtk_widget_get_allocation(mainwin->window, &allocation);
2823         if (allocation.width > 1 && allocation.height > 1 &&
2824             !prefs_common.mainwin_maximised && !prefs_common.mainwin_fullscreen) {
2825                 prefs_common.mainview_height = allocation.height;
2826                 prefs_common.mainwin_width   = allocation.width;
2827                 prefs_common.mainwin_height  = allocation.height;
2828         }
2829
2830         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->folderview), &allocation);
2831         if (allocation.width > 1 && allocation.height > 1 &&
2832             !prefs_common.mainwin_fullscreen) {
2833                 prefs_common.folderview_width  = allocation.width;
2834                 prefs_common.folderview_height = allocation.height;
2835         }
2836         
2837         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->messageview), &allocation);
2838         if (allocation.width > 1 && allocation.height > 1 &&
2839             !prefs_common.mainwin_fullscreen) {
2840                 prefs_common.msgview_width = allocation.width;
2841                 prefs_common.msgview_height = allocation.height;
2842         }
2843
2844 /*      debug_print("summaryview size: %d x %d\n",
2845                     prefs_common.summaryview_width,
2846                     prefs_common.summaryview_height);
2847         debug_print("folderview size: %d x %d\n",
2848                     prefs_common.folderview_width,
2849                     prefs_common.folderview_height);
2850         debug_print("messageview size: %d x %d\n",
2851                     prefs_common.msgview_width,
2852                     prefs_common.msgview_height); */
2853 }
2854
2855 void main_window_get_position(MainWindow *mainwin)
2856 {
2857         gint x, y;
2858
2859         if (prefs_common.mainwin_maximised || prefs_common.mainwin_fullscreen)
2860                 return;
2861
2862         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2863
2864         prefs_common.mainview_x = x;
2865         prefs_common.mainview_y = y;
2866         prefs_common.mainwin_x = x;
2867         prefs_common.mainwin_y = y;
2868
2869         debug_print("main window position: %d, %d\n", x, y);
2870 }
2871
2872 void main_window_progress_on(MainWindow *mainwin)
2873 {
2874         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2875 }
2876
2877 void main_window_progress_off(MainWindow *mainwin)
2878 {
2879         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2880         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2881 }
2882
2883 gboolean main_window_empty_trash(MainWindow *mainwin, gboolean confirm, gboolean for_quit)
2884 {
2885         if (confirm && procmsg_have_trashed_mails_fast()) {
2886                 AlertValue val;
2887                 
2888                 if (for_quit)
2889                         val = alertpanel(_("Empty trash"),
2890                                _("Delete all messages in trash folders?"),
2891                                GTK_STOCK_NO, "+" GTK_STOCK_YES, _("Don't quit"));
2892                 else
2893                         val = alertpanel(_("Empty trash"),
2894                                _("Delete all messages in trash folders?"),
2895                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
2896                 if (val == G_ALERTALTERNATE) {
2897                         debug_print("will empty trash\n");
2898                 } else if (val == G_ALERTDEFAULT) {
2899                         debug_print("will not empty trash\n");
2900                         return TRUE;
2901                 } else {
2902                         return FALSE; /* cancel exit */
2903                 }
2904                 manage_window_focus_in(mainwin->window, NULL, NULL);
2905         }
2906
2907         procmsg_empty_all_trash();
2908
2909         if (mainwin->summaryview->folder_item &&
2910             mainwin->summaryview->folder_item->stype == F_TRASH)
2911                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2912         return TRUE;
2913 }
2914
2915 static void main_window_add_mailbox(MainWindow *mainwin)
2916 {
2917         gchar *path;
2918         Folder *folder;
2919
2920         path = input_dialog(_("Add mailbox"),
2921                             _("Input the location of mailbox.\n"
2922                               "If an existing mailbox is specified, it will be\n"
2923                               "scanned automatically."),
2924                             "Mail");
2925         if (!path) return;
2926         if (folder_find_from_path(path)) {
2927                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2928                 g_free(path);
2929                 return;
2930         }
2931         folder = folder_new(folder_get_class_from_string("mh"), 
2932                             !strcmp(path, "Mail") ? _("Mailbox") : 
2933                             g_path_get_basename(path), path);
2934         g_free(path);
2935
2936         if (folder->klass->create_tree(folder) < 0) {
2937                 alertpanel_error(_("Creation of the mailbox failed.\n"
2938                                    "Maybe some files already exist, or you don't have the permission to write there."));
2939                 folder_destroy(folder);
2940                 return;
2941         }
2942
2943         folder_add(folder);
2944         folder_set_ui_func(folder, scan_tree_func, mainwin);
2945         folder_scan_tree(folder, TRUE);
2946         folder_set_ui_func(folder, NULL, NULL);
2947 }
2948
2949 SensitiveCondMask main_window_get_current_state(MainWindow *mainwin)
2950 {
2951         SensitiveCondMask state = 0;
2952         SummarySelection selection;
2953         FolderItem *item = mainwin->summaryview->folder_item;
2954         GList *account_list = account_get_list();
2955         GSList *tmp;
2956         
2957         selection = summary_get_selection_type(mainwin->summaryview);
2958
2959 #define UPDATE_STATE(...) \
2960         do { \
2961                 state |= main_window_get_mask(__VA_ARGS__, -1); \
2962         } while (0)
2963
2964         if (mainwin->lock_count == 0 && !claws_is_starting())
2965                 UPDATE_STATE(M_UNLOCKED);
2966         if (selection != SUMMARY_NONE)
2967                 UPDATE_STATE(M_MSG_EXIST);
2968         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2969                 UPDATE_STATE(M_EXEC);
2970                 /*              if (item->folder->type != F_NEWS) */
2971                 UPDATE_STATE(M_ALLOW_DELETE);
2972
2973                 if (prefs_common.immediate_exec == 0
2974                     && mainwin->lock_count == 0)
2975                         UPDATE_STATE(M_DELAY_EXEC);
2976
2977                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2978                     || selection != SUMMARY_NONE)
2979                         UPDATE_STATE(M_HIDE_READ_MSG);
2980
2981                 if ((selection == SUMMARY_NONE && item->hide_read_threads)
2982                     || selection != SUMMARY_NONE)
2983                         UPDATE_STATE(M_HIDE_READ_THREADS);
2984         }               
2985         if (mainwin->summaryview->threaded)
2986                 UPDATE_STATE(M_THREADED);
2987         else
2988                 UPDATE_STATE(M_UNTHREADED);
2989         if (selection == SUMMARY_SELECTED_SINGLE ||
2990             selection == SUMMARY_SELECTED_MULTIPLE)
2991                 UPDATE_STATE(M_TARGET_EXIST);
2992         if (selection == SUMMARY_SELECTED_SINGLE)
2993                 UPDATE_STATE(M_SINGLE_TARGET_EXIST);
2994         if (mainwin->summaryview->folder_item &&
2995             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2996                 UPDATE_STATE(M_NEWS);
2997         else
2998                 UPDATE_STATE(M_NOT_NEWS);
2999         if (mainwin->summaryview->folder_item &&
3000             (mainwin->summaryview->folder_item->stype != F_TRASH ||
3001              !folder_has_parent_of_type(mainwin->summaryview->folder_item, F_TRASH)))
3002                 UPDATE_STATE(M_NOT_TRASH);
3003
3004         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
3005                 UPDATE_STATE(M_ACTIONS_EXIST);
3006
3007         tmp = tags_get_list();
3008         if (tmp && g_slist_length(tmp))
3009                 UPDATE_STATE(M_TAGS_EXIST);
3010         g_slist_free(tmp);
3011
3012         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
3013                 UPDATE_STATE(M_HAVE_QUEUED_MAILS);
3014
3015         if (selection == SUMMARY_SELECTED_SINGLE &&
3016             (item &&
3017              (folder_has_parent_of_type(item, F_DRAFT) ||
3018               folder_has_parent_of_type(item, F_OUTBOX) ||
3019               folder_has_parent_of_type(item, F_QUEUE))))
3020                 UPDATE_STATE(M_ALLOW_REEDIT);
3021         if (cur_account)
3022                 UPDATE_STATE(M_HAVE_ACCOUNT);
3023         
3024         if (cur_account && cur_account->protocol != A_NONE)
3025                 UPDATE_STATE(M_HAVE_RETRIEVABLE_ACCOUNT);
3026
3027         if (any_folder_want_synchronise())
3028                 UPDATE_STATE(M_WANT_SYNC);
3029
3030         if (item && item->prefs->processing && selection != SUMMARY_NONE)
3031                 UPDATE_STATE(M_HAVE_PROCESSING);
3032
3033         if (g_list_length(account_list) > 1)
3034                 UPDATE_STATE(M_HAVE_MULTI_ACCOUNT);
3035
3036         for (account_list = account_get_list(); account_list != NULL; account_list = account_list->next) {
3037                 if (((PrefsAccount*)account_list->data)->protocol != A_NONE) {
3038                         UPDATE_STATE(M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
3039                         break;
3040                 }
3041         }
3042
3043         for (account_list = account_get_list(); account_list != NULL; account_list = account_list->next) {
3044                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
3045                         UPDATE_STATE(M_HAVE_NEWS_ACCOUNT);
3046                         break;
3047                 }
3048         }
3049         
3050         if (procmsg_spam_can_learn() &&
3051             (mainwin->summaryview->folder_item &&
3052              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
3053              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
3054                 UPDATE_STATE(M_CAN_LEARN_SPAM);
3055         }
3056
3057         if (mainwin->summaryview->folder_item) {
3058                 UPDATE_STATE(M_FOLDER_SELECTED);
3059         }
3060
3061         if (inc_is_active())
3062                 UPDATE_STATE(M_INC_ACTIVE);
3063         if (imap_cancel_all_enabled())
3064                 UPDATE_STATE(M_INC_ACTIVE);
3065
3066         if (send_is_active() | procmsg_is_sending())
3067                 UPDATE_STATE(M_SEND_ACTIVE);
3068
3069         if (mainwin->summaryview->deleted > 0)
3070                 UPDATE_STATE(M_DELETED_EXISTS);
3071
3072         if (mainwin->summaryview->deleted > 0 ||
3073             mainwin->summaryview->moved > 0 ||
3074             mainwin->summaryview->copied > 0)
3075                 UPDATE_STATE(M_DELAY_EXEC);
3076
3077         if (summary_is_list(mainwin->summaryview))
3078                 UPDATE_STATE(M_SUMMARY_ISLIST);
3079
3080         if (prefs_common.layout_mode != SMALL_LAYOUT || mainwin->in_folder)
3081                 UPDATE_STATE(M_IN_MSGLIST);
3082
3083         for (account_list = account_get_list(); account_list != NULL; account_list = account_list->next) {
3084                 PrefsAccount *account = account_list->data;
3085                 if (account->session_passwd || account->session_smtp_passwd) {
3086                         UPDATE_STATE(M_SESSION_PASSWORDS);
3087                         break;
3088                 }
3089         }
3090 #undef UPDATE_STATE
3091
3092         return state;
3093 }
3094
3095 SensitiveCondMask main_window_get_mask(SensitiveCond cond, ...)
3096 {
3097         va_list args;
3098         gint i;
3099         SensitiveCondMask value;
3100         static SensitiveCondMask SensitiveCond_table[M_MAX_RESERVED];
3101         static gboolean first_time = TRUE;
3102
3103         if (first_time) {
3104                 for (i = 0; i < M_MAX_RESERVED; i++)
3105                         SensitiveCond_table[i] = (SensitiveCondMask) ((SensitiveCondMask)1 << i);
3106                 first_time = FALSE;
3107         }
3108
3109         value = 0;
3110
3111         va_start(args, cond); 
3112         for (i = (gint) cond; i >= 0; i = va_arg(args, gint))
3113                 value |= SensitiveCond_table[i];
3114         va_end(args);
3115
3116         return value;
3117 }
3118
3119 void main_window_set_menu_sensitive(MainWindow *mainwin)
3120 {
3121         SensitiveCondMask state;
3122         gboolean sensitive;
3123         SummaryView *summaryview;
3124         gchar *menu_path;
3125         GtkWidget *menu;
3126         GList *children, *cur_item;
3127         gint i;
3128         gboolean mimepart_selected = FALSE;
3129
3130 #define N_ENTRIES 83
3131         static struct {
3132                 const gchar *entry;
3133                 SensitiveCondMask cond;
3134         } entry[N_ENTRIES];
3135
3136         i = 0;
3137 #define FILL_TABLE(entry_str, ...) \
3138 do { \
3139         entry[i].entry = (const gchar *) entry_str; entry[i++].cond = main_window_get_mask(__VA_ARGS__, -1); \
3140 } while (0)
3141
3142         FILL_TABLE("Menu/File/SaveAs", M_TARGET_EXIST);
3143         FILL_TABLE("Menu/File/SavePartAs", M_SINGLE_TARGET_EXIST);
3144         FILL_TABLE("Menu/File/Print", M_TARGET_EXIST);
3145         FILL_TABLE("Menu/File/SynchroniseFolders", M_WANT_SYNC);
3146         FILL_TABLE("Menu/File/Exit", M_UNLOCKED);
3147
3148         FILL_TABLE("Menu/Edit/SelectThread", M_TARGET_EXIST, M_SUMMARY_ISLIST);
3149         FILL_TABLE("Menu/Edit/DeleteThread", M_TARGET_EXIST, M_SUMMARY_ISLIST);
3150         FILL_TABLE("Menu/Edit/Find", M_SINGLE_TARGET_EXIST);
3151         FILL_TABLE("Menu/Edit/QuickSearch", M_IN_MSGLIST);
3152         FILL_TABLE("Menu/Edit/SearchFolder", M_TARGET_EXIST, M_SUMMARY_ISLIST);
3153
3154         FILL_TABLE("Menu/View/SetColumns/Folderlist", M_UNLOCKED, M_SUMMARY_ISLIST);
3155         FILL_TABLE("Menu/View/Sort", M_EXEC, M_SUMMARY_ISLIST);
3156         FILL_TABLE("Menu/View/ThreadView", M_EXEC, M_SUMMARY_ISLIST);
3157         FILL_TABLE("Menu/View/ExpandThreads", M_MSG_EXIST, M_SUMMARY_ISLIST);
3158         FILL_TABLE("Menu/View/CollapseThreads", M_MSG_EXIST, M_SUMMARY_ISLIST);
3159         FILL_TABLE("Menu/View/HideReadThreads", M_HIDE_READ_THREADS, M_SUMMARY_ISLIST);
3160         FILL_TABLE("Menu/View/HideReadMessages", M_HIDE_READ_MSG, M_SUMMARY_ISLIST);
3161         FILL_TABLE("Menu/View/HideDelMessages", M_SUMMARY_ISLIST);
3162         FILL_TABLE("Menu/View/Goto/Prev", M_MSG_EXIST);
3163         FILL_TABLE("Menu/View/Goto/Next", M_MSG_EXIST);
3164         FILL_TABLE("Menu/View/Goto/PrevUnread", M_MSG_EXIST);
3165         FILL_TABLE("Menu/View/Goto/PrevNew", M_MSG_EXIST);
3166         FILL_TABLE("Menu/View/Goto/PrevMarked", M_MSG_EXIST);
3167         FILL_TABLE("Menu/View/Goto/PrevLabeled", M_MSG_EXIST);
3168         FILL_TABLE("Menu/View/Goto/NextLabeled", M_MSG_EXIST);
3169         FILL_TABLE("Menu/View/Goto/ParentMessage", M_SINGLE_TARGET_EXIST);
3170         FILL_TABLE("Menu/View/Goto/NextPart", M_SINGLE_TARGET_EXIST);
3171         FILL_TABLE("Menu/View/Goto/PrevPart", M_SINGLE_TARGET_EXIST);
3172         FILL_TABLE("Menu/View/OpenNewWindow", M_SINGLE_TARGET_EXIST);
3173         FILL_TABLE("Menu/View/MessageSource", M_SINGLE_TARGET_EXIST);
3174         FILL_TABLE("Menu/View/Part", M_SINGLE_TARGET_EXIST);
3175         FILL_TABLE("Menu/View/AllHeaders", M_SINGLE_TARGET_EXIST);
3176         FILL_TABLE("Menu/View/Quotes", M_SINGLE_TARGET_EXIST);
3177
3178         FILL_TABLE("Menu/Message/Receive/CurrentAccount", M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_RETRIEVABLE_ACCOUNT);
3179         FILL_TABLE("Menu/Message/Receive/AllAccounts", M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
3180         FILL_TABLE("Menu/Message/Receive/CancelReceiving", M_INC_ACTIVE);
3181         FILL_TABLE("Menu/Message/SendQueue", M_HAVE_ACCOUNT, M_HAVE_QUEUED_MAILS);
3182         FILL_TABLE("Menu/Message/CancelSending", M_SEND_ACTIVE);
3183         FILL_TABLE("Menu/Message/ComposeEmail", M_HAVE_ACCOUNT);
3184         FILL_TABLE("Menu/Message/ComposeNews", M_HAVE_NEWS_ACCOUNT);
3185         FILL_TABLE("Menu/Message/Reply", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
3186         FILL_TABLE("Menu/Message/ReplyTo", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
3187         FILL_TABLE("Menu/Message/FollowupReply", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_NEWS, M_SUMMARY_ISLIST);
3188         FILL_TABLE("Menu/Message/Forward", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
3189         FILL_TABLE("Menu/Message/ForwardAtt", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
3190         FILL_TABLE("Menu/Message/Redirect", M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
3191         FILL_TABLE("Menu/Message/Move", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
3192         FILL_TABLE("Menu/Message/Copy", M_TARGET_EXIST, M_EXEC);
3193         FILL_TABLE("Menu/Message/Trash", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS, M_NOT_TRASH);
3194         FILL_TABLE("Menu/Message/Delete", M_TARGET_EXIST, M_ALLOW_DELETE);
3195         FILL_TABLE("Menu/Message/CancelNews", M_TARGET_EXIST, M_ALLOW_DELETE, M_NEWS);
3196         FILL_TABLE("Menu/Message/Mark", M_TARGET_EXIST, M_SUMMARY_ISLIST);
3197         FILL_TABLE("Menu/Message/Mark/MarkSpam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
3198         FILL_TABLE("Menu/Message/Mark/MarkHam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
3199         FILL_TABLE("Menu/Message/Mark/IgnoreThread", M_TARGET_EXIST);
3200         FILL_TABLE("Menu/Message/Mark/UnignoreThread", M_TARGET_EXIST);
3201         FILL_TABLE("Menu/Message/Mark/Lock", M_TARGET_EXIST);
3202         FILL_TABLE("Menu/Message/Mark/Unlock", M_TARGET_EXIST);
3203         FILL_TABLE("Menu/Message/ColorLabel", M_TARGET_EXIST);
3204         FILL_TABLE("Menu/Message/Tags", M_TARGET_EXIST);
3205         FILL_TABLE("Menu/Message/Reedit", M_HAVE_ACCOUNT, M_ALLOW_REEDIT);
3206         FILL_TABLE("Menu/Message/CheckSignature", M_SINGLE_TARGET_EXIST);
3207
3208         FILL_TABLE("Menu/Tools/AddSenderToAB", M_SINGLE_TARGET_EXIST);
3209         FILL_TABLE("Menu/Tools/CollectAddresses", M_FOLDER_SELECTED);
3210         FILL_TABLE("Menu/Tools/CollectAddresses/FromFolder", M_FOLDER_SELECTED);
3211         FILL_TABLE("Menu/Tools/CollectAddresses/FromSelected", M_TARGET_EXIST);
3212         FILL_TABLE("Menu/Tools/FilterFolder", M_MSG_EXIST, M_EXEC);
3213         FILL_TABLE("Menu/Tools/FilterSelected", M_TARGET_EXIST, M_EXEC);
3214         FILL_TABLE("Menu/Tools/RunProcessing", M_HAVE_PROCESSING);
3215         FILL_TABLE("Menu/Tools/CreateFilterRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
3216         FILL_TABLE("Menu/Tools/CreateProcessingRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
3217         FILL_TABLE("Menu/Tools/ListUrls", M_TARGET_EXIST);
3218         FILL_TABLE("Menu/Tools/Actions", M_TARGET_EXIST, M_ACTIONS_EXIST);
3219         FILL_TABLE("Menu/Tools/Execute", M_DELAY_EXEC);
3220         FILL_TABLE("Menu/Tools/Expunge", M_DELETED_EXISTS);
3221         FILL_TABLE("Menu/Tools/ForgetSessionPasswords", M_SESSION_PASSWORDS);
3222         FILL_TABLE("Menu/Tools/DeleteDuplicates/SelFolder", M_MSG_EXIST, M_ALLOW_DELETE);
3223
3224         FILL_TABLE("Menu/Configuration", M_UNLOCKED);
3225         FILL_TABLE("Menu/Configuration/ChangeAccount", M_HAVE_MULTI_ACCOUNT);
3226         FILL_TABLE("Menu/Configuration/AccountPrefs", M_UNLOCKED);
3227         FILL_TABLE("Menu/Configuration/CreateAccount", M_UNLOCKED);
3228         FILL_TABLE("Menu/Configuration/EditAccounts", M_UNLOCKED);
3229         FILL_TABLE(NULL, -1);
3230 #undef FILL_TABLE
3231         if (i > N_ENTRIES)
3232                 g_error("main window menu entry table overrun (%d/%d)", i, N_ENTRIES);
3233 #undef ENTRIES
3234
3235         state = main_window_get_current_state(mainwin);
3236
3237         for (i = 0; entry[i].entry != NULL; i++) {
3238                 sensitive = ((entry[i].cond & state) == entry[i].cond);
3239                 cm_menu_set_sensitive_full(mainwin->ui_manager, entry[i].entry, sensitive);
3240         }
3241
3242         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
3243                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive")));
3244
3245         children = gtk_container_get_children(GTK_CONTAINER(menu));
3246         for (cur_item = children; cur_item != NULL; cur_item = cur_item->next) {
3247                 if (cur_item->data == gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive/Separator1")) {
3248                         cur_item = cur_item->next;
3249                         break;
3250                 }
3251         }
3252
3253         for (; cur_item != NULL; cur_item = cur_item->next) {
3254                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
3255                                          (main_window_get_mask(M_UNLOCKED, -1) & state) != 0);
3256         }
3257
3258         g_list_free(children);
3259
3260         main_window_menu_callback_block(mainwin);
3261
3262         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/ShowHide/MessageView",
3263                               messageview_is_visible(mainwin->messageview));
3264
3265         summaryview = mainwin->summaryview;
3266
3267         switch (summaryview->sort_key) {
3268         case SORT_BY_NUMBER:
3269                 menu_path = "Menu/View/Sort/Number"; break;
3270         case SORT_BY_SIZE:
3271                 menu_path = "Menu/View/Sort/Size"; break;
3272         case SORT_BY_DATE:
3273                 menu_path = "Menu/View/Sort/Date"; break;
3274         case SORT_BY_THREAD_DATE:
3275                 menu_path = "Menu/View/Sort/ThreadDate"; break;
3276         case SORT_BY_FROM:
3277                 menu_path = "Menu/View/Sort/From"; break;
3278         case SORT_BY_TO:
3279                 menu_path = "Menu/View/Sort/To"; break;
3280         case SORT_BY_SUBJECT:
3281                 menu_path = "Menu/View/Sort/Subject"; break;
3282         case SORT_BY_LABEL:
3283                 menu_path = "Menu/View/Sort/Color"; break;
3284         case SORT_BY_MARK:
3285                 menu_path = "Menu/View/Sort/Mark"; break;
3286         case SORT_BY_STATUS:
3287                 menu_path = "Menu/View/Sort/Status"; break;
3288         case SORT_BY_MIME:
3289                 menu_path = "Menu/View/Sort/Attachment"; break;
3290         case SORT_BY_SCORE:
3291                 menu_path = "Menu/View/Sort/Score"; break;
3292         case SORT_BY_LOCKED:
3293                 menu_path = "Menu/View/Sort/Locked"; break;
3294         case SORT_BY_TAGS:
3295                 menu_path = "Menu/View/Sort/Tag"; break;
3296         case SORT_BY_NONE:
3297         default:
3298                 menu_path = "Menu/View/Sort/DontSort"; break;
3299         }
3300         cm_toggle_menu_set_active_full(mainwin->ui_manager, menu_path, TRUE);
3301
3302         if (summaryview->sort_type == SORT_ASCENDING) {
3303                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", TRUE);
3304         } else {
3305                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Sort/Descending", TRUE);
3306         }
3307
3308         if (summaryview->sort_key != SORT_BY_NONE) {
3309                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", TRUE);
3310                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", TRUE);
3311         } else {
3312                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", FALSE);
3313                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", FALSE);
3314         }
3315
3316         if (mainwin->messageview
3317         &&  mainwin->messageview->mimeview
3318         &&  mainwin->messageview->mimeview->textview)
3319                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/AllHeaders",
3320                                                 prefs_common.show_all_headers);
3321         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/ThreadView", (state & main_window_get_mask(M_THREADED, -1)) != 0);
3322         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/ExpandThreads", (state & main_window_get_mask(M_THREADED, -1)) != 0);
3323         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/CollapseThreads", (state & main_window_get_mask(M_THREADED, -1)) != 0);
3324         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadThreads", (state & main_window_get_mask(M_THREADED, -1)) != 0);
3325         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
3326         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
3327         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
3328
3329         if (mainwin->summaryview->folder_item && !mainwin->summaryview->folder_item->threaded)
3330                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/HideReadThreads", FALSE);
3331         if ((mainwin->summaryview->folder_item && mainwin->summaryview->folder_item->hide_read_msgs) ||
3332             quicksearch_has_sat_predicate(mainwin->summaryview->quicksearch))
3333                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadThreads", FALSE);
3334         if ((mainwin->summaryview->folder_item && mainwin->summaryview->folder_item->hide_read_threads) ||
3335             quicksearch_has_sat_predicate(mainwin->summaryview->quicksearch))
3336                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadMessages", FALSE);
3337         if (quicksearch_has_sat_predicate(mainwin->summaryview->quicksearch))
3338                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideDelMessages", FALSE);
3339
3340         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/PrevHistory",
3341                 messageview_nav_has_prev(mainwin->messageview));
3342         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/NextHistory",
3343                 messageview_nav_has_next(mainwin->messageview));
3344
3345         if (mainwin->messageview 
3346         &&  mainwin->messageview->mimeview)
3347                 mimepart_selected = !mimeview_tree_is_empty(mainwin->messageview->mimeview);
3348
3349         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/File/SavePartAs", mimepart_selected);
3350         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/NextPart", mimepart_selected);
3351         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/PrevPart", mimepart_selected);
3352         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Part", mimepart_selected);
3353         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/CheckSignature", 
3354                                    mimepart_selected && mainwin->messageview->mimeview->signed_part);
3355
3356         main_window_menu_callback_unblock(mainwin);
3357 }
3358
3359 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
3360 {
3361         gint is_menu = 0;
3362         
3363         if (msginfo) 
3364                 is_menu = mailing_list_create_submenu (mainwin, msginfo);
3365         if (is_menu)
3366                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList", TRUE);
3367         else
3368                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList", FALSE);
3369 }
3370
3371 static gint mailing_list_create_submenu (MainWindow *mainwin, MsgInfo *msginfo)
3372 {
3373         gint menu_nb = 0;
3374         GtkWidget *menuitem;
3375         
3376         if (!msginfo || !msginfo->extradata) {
3377                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Post", FALSE);
3378                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Help", FALSE);
3379                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Subscribe", FALSE);
3380                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Unsubscribe", FALSE);
3381                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/ViewArchive", FALSE);
3382                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/ContactOwner", FALSE);
3383                 return 0;
3384         }
3385                 
3386         /* Mailing list post */
3387         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
3388                 g_free(msginfo->extradata->list_post);
3389                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
3390         }
3391         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Post");
3392                 
3393         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
3394  
3395         /* Mailing list help */
3396         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Help");
3397         
3398         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
3399
3400         /* Mailing list subscribe */
3401         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Subscribe");
3402         
3403         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
3404                 
3405         /* Mailing list unsubscribe */
3406         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Unsubscribe");
3407         
3408         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
3409         
3410         /* Mailing list view archive */
3411         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/ViewArchive");
3412         
3413         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
3414         
3415         /* Mailing list contact owner */
3416         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/ContactOwner");
3417         
3418         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
3419         
3420         return menu_nb;
3421 }
3422
3423 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
3424 {
3425         GtkWidget *item, *menu;
3426         const gchar *url_pt ;
3427         gchar url_decoded[BUFFSIZE];
3428         GList *children, *amenu;
3429         gint menu_nb = 0;
3430         
3431         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuitem));
3432         
3433         /* First delete old submenu */
3434         /* FIXME: we can optimize this, and only change/add/delete necessary items */
3435         children = gtk_container_get_children(GTK_CONTAINER(menu));
3436         for (amenu = children; amenu; amenu = amenu->next) {
3437                 item = GTK_WIDGET (amenu->data);
3438                 gtk_widget_destroy (item);
3439         }
3440         g_list_free(children);
3441         if (list_header) {
3442                 for (url_pt = list_header; url_pt && *url_pt;) {
3443                         get_url_part (&url_pt, url_decoded);
3444                         item = NULL;
3445                         if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
3446                                 item = cm_menu_item_new_label_from_url ((url_decoded));
3447                                 g_signal_connect(G_OBJECT(item), "activate",
3448                                                  G_CALLBACK(mailing_list_compose),
3449                                                  NULL);
3450                         }
3451                         else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
3452                                  !g_ascii_strncasecmp(url_decoded, "https:",6)) {
3453
3454                                 item = cm_menu_item_new_label_from_url ((url_decoded));
3455                                 g_signal_connect(G_OBJECT(item), "activate",
3456                                                  G_CALLBACK(mailing_list_open_uri),
3457                                                  NULL);
3458                         } 
3459                         if (item) {
3460                                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3461                                 gtk_widget_show (item);
3462                                 menu_nb++;
3463                         }
3464                 }
3465         }
3466         if (menu_nb)
3467                 gtk_widget_set_sensitive (menuitem, TRUE);
3468         else
3469                 gtk_widget_set_sensitive (menuitem, FALSE);
3470                 
3471
3472         return menu_nb;
3473 }
3474
3475 static void get_url_part (const gchar **buffer, gchar *url_decoded)
3476 {
3477         gchar tmp[BUFFSIZE];
3478         const gchar *buf;
3479         gint i = 0;
3480         buf = *buffer;
3481         gboolean with_plus = TRUE;
3482
3483         if (buf == 0x00) {
3484                 *url_decoded = '\0';
3485                 *buffer = NULL;
3486                 return;
3487         }
3488         /* Ignore spaces, comments  and tabs () */
3489         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
3490                 if (*buf == '(')
3491                         for (;*buf != ')' && *buf != 0x00; buf++);
3492         
3493         /* First non space and non comment must be a < */
3494         if (*buf =='<' ) {
3495                 buf++;
3496                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
3497                         with_plus = FALSE;
3498                 for (i = 0;
3499                      *buf != '>' && *buf != 0x00 && i < BUFFSIZE;
3500                         tmp[i++] = *(buf++));
3501                 buf++;
3502         }
3503         else  {
3504                 *buffer = NULL;
3505                 *url_decoded = '\0';
3506                 return;
3507         }
3508         
3509         *url_decoded = '\0';
3510         *buffer = NULL;
3511         
3512         if (i == BUFFSIZE) {
3513                 return;
3514         }
3515         tmp[i] = 0x00;
3516         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
3517
3518         /* Prepare the work for the next url in the list */
3519         /* after the closing bracket >, ignore space, comments and tabs */
3520         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
3521                 if (*buf == '(')
3522                         for (;*buf != ')' && *buf != 0x00; buf++);
3523                         
3524         if (!buf || !*buf) {
3525                 *buffer = NULL;
3526                 return;
3527         }
3528
3529         /* now first non space, non comment must be a comma */
3530         if (*buf != ',')
3531                 for (;*buf != 0x00; buf++);
3532         else
3533                 buf++;
3534         *buffer = buf;
3535 }
3536         
3537 static void mailing_list_compose (GtkWidget *w, gpointer *data)
3538 {
3539         const gchar *mailto;
3540         PrefsAccount *account = NULL;
3541         FolderItem   *folder_item = NULL;
3542
3543         mailto = gtk_label_get_text(GTK_LABEL (gtk_bin_get_child(GTK_BIN((w)))));
3544         if (mainwindow_get_mainwindow()) {
3545                 folder_item = mainwindow_get_mainwindow()->summaryview->folder_item;
3546                 if (folder_item && folder_item->prefs && folder_item->prefs->enable_default_account)
3547                         account = account_find_from_id(folder_item->prefs->default_account);
3548                 if (folder_item && !account)
3549                         account = account_find_from_item(folder_item);
3550         }
3551         if (mailto)
3552                 compose_new_with_folderitem(account, folder_item, mailto+7);
3553 }
3554  
3555  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
3556 {
3557  
3558         const gchar *mailto;
3559  
3560         mailto = gtk_label_get_text(GTK_LABEL (gtk_bin_get_child(GTK_BIN((w)))));
3561         if (mailto)
3562                 open_uri (mailto, prefs_common_get_uri_cmd());
3563
3564         
3565 static void fix_folderview_scroll(MainWindow *mainwin)
3566 {
3567         static gboolean fix_done = FALSE;
3568
3569         if (fix_done)
3570                 return;
3571
3572         gtk_widget_queue_resize(mainwin->folderview->ctree);
3573
3574         fix_done = TRUE;
3575 }
3576
3577 void main_window_popup(MainWindow *mainwin)
3578 {
3579         static gboolean first_start = TRUE;
3580
3581         if (!gtk_widget_get_visible(GTK_WIDGET(mainwin->window)))
3582                 main_window_show(mainwin);
3583
3584         if (prefs_common.mainwin_maximised)
3585                 gtk_window_maximize(GTK_WINDOW(mainwin->window));
3586
3587         if (first_start) {
3588                 first_start = FALSE;
3589         } else {
3590                 gtkut_window_popup(mainwin->window);
3591         }
3592
3593         if (prefs_common.layout_mode == SMALL_LAYOUT) {
3594                 if (mainwin->in_folder) {
3595                         mainwindow_enter_folder(mainwin);
3596                 } else {
3597                         mainwindow_exit_folder(mainwin);
3598                 }
3599         }
3600         fix_folderview_scroll(mainwin);
3601 }
3602
3603 void main_window_show(MainWindow *mainwin)
3604 {
3605         gtk_widget_show(mainwin->window);
3606         gtk_widget_show(mainwin->vbox_body);
3607 #ifndef GENERIC_UMPC
3608         gtk_window_move(GTK_WINDOW(mainwin->window),
3609                                  prefs_common.mainwin_x,
3610                                  prefs_common.mainwin_y);
3611         
3612         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3613                              prefs_common.folderview_width,
3614                              prefs_common.folderview_height);
3615         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3616                              prefs_common.summaryview_width,
3617                              prefs_common.summaryview_height);
3618         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3619                              prefs_common.msgview_width,
3620                              prefs_common.msgview_height);
3621 #endif
3622 }
3623
3624 void main_window_hide(MainWindow *mainwin)
3625 {
3626         main_window_get_size(mainwin);
3627         main_window_get_position(mainwin);
3628
3629         gtk_widget_hide(mainwin->window);
3630         gtk_widget_hide(mainwin->vbox_body);
3631 }
3632
3633 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
3634 {
3635         GtkWidget *folderwin = NULL;
3636         GtkWidget *messagewin = NULL;
3637         GtkWidget *hpaned;
3638         GtkWidget *vpaned;
3639         GtkWidget *vbox_body = mainwin->vbox_body;
3640         gboolean first_set = (mainwin->hpaned == NULL);
3641         debug_print("Setting widgets... ");
3642
3643 #ifndef GENERIC_UMPC
3644         mainwin->messageview->statusbar = mainwin->statusbar;
3645         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3646 #endif
3647         /* clean top-most container */
3648         if (mainwin->hpaned) {
3649                 if (gtk_widget_get_parent(mainwin->hpaned) == mainwin->vpaned)
3650                         gtk_widget_destroy(mainwin->vpaned);
3651                 else
3652                         gtk_widget_destroy(mainwin->hpaned);
3653         }
3654
3655         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/ShowHide/MessageView", 
3656                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3657         switch (layout_mode) {
3658         case VERTICAL_LAYOUT:
3659         case NORMAL_LAYOUT:
3660         case SMALL_LAYOUT:
3661                 hpaned = gtk_hpaned_new();
3662                 if (layout_mode == VERTICAL_LAYOUT)
3663                         vpaned = gtk_hpaned_new();
3664                 else
3665                         vpaned = gtk_vpaned_new();
3666                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3667                 gtk_paned_add1(GTK_PANED(hpaned),
3668                                GTK_WIDGET_PTR(mainwin->folderview));
3669                 gtk_widget_show(hpaned);
3670                 gtk_widget_queue_resize(hpaned);
3671
3672                 if (messageview_is_visible(mainwin->messageview)) {
3673                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3674                         gtk_paned_pack1(GTK_PANED(vpaned),
3675                                        GTK_WIDGET_PTR(mainwin->summaryview), TRUE, TRUE);
3676                 } else {
3677                         gtk_paned_add2(GTK_PANED(hpaned),
3678                                        GTK_WIDGET_PTR(mainwin->summaryview));
3679                         g_object_ref(vpaned);
3680                 }
3681                 gtk_paned_add2(GTK_PANED(vpaned),
3682                                GTK_WIDGET_PTR(mainwin->messageview));
3683                 gtk_widget_show(vpaned);
3684                 if (layout_mode == SMALL_LAYOUT && first_set) {
3685                         mainwin_paned_show_first(GTK_PANED(hpaned));
3686                 }
3687                 gtk_widget_queue_resize(vpaned);
3688                 break;
3689         case WIDE_LAYOUT:
3690                 vpaned = gtk_vpaned_new();
3691                 hpaned = gtk_hpaned_new();
3692                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3693                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3694
3695                 gtk_paned_add1(GTK_PANED(hpaned),
3696                                GTK_WIDGET_PTR(mainwin->folderview));
3697                 gtk_paned_add2(GTK_PANED(hpaned),
3698                                GTK_WIDGET_PTR(mainwin->summaryview));
3699
3700                 gtk_widget_show(hpaned);
3701                 gtk_widget_queue_resize(hpaned);
3702
3703                 if (messageview_is_visible(mainwin->messageview)) {
3704                         gtk_paned_add2(GTK_PANED(vpaned),
3705                                GTK_WIDGET_PTR(mainwin->messageview));   
3706                 } else {
3707                         g_object_ref(GTK_WIDGET_PTR(mainwin->messageview));
3708                 }
3709                 gtk_widget_show(vpaned);
3710                 gtk_widget_queue_resize(vpaned);
3711                 break;
3712         case WIDE_MSGLIST_LAYOUT:
3713                 vpaned = gtk_vpaned_new();
3714                 hpaned = gtk_hpaned_new();
3715                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3716
3717                 gtk_paned_add1(GTK_PANED(vpaned),
3718                                GTK_WIDGET_PTR(mainwin->summaryview));
3719                 gtk_paned_add1(GTK_PANED(hpaned),
3720                                GTK_WIDGET_PTR(mainwin->folderview));
3721
3722                 gtk_widget_show(hpaned);
3723                 gtk_widget_queue_resize(hpaned);
3724
3725                 if (messageview_is_visible(mainwin->messageview)) {
3726                         gtk_paned_add2(GTK_PANED(hpaned),
3727                                GTK_WIDGET_PTR(mainwin->messageview));   
3728                 } else {
3729                         g_object_ref(GTK_WIDGET_PTR(mainwin->messageview));
3730                 }
3731                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3732
3733                 gtk_widget_show(vpaned);
3734                 gtk_widget_queue_resize(vpaned);
3735                 break;
3736         default:
3737                 g_warning("Unknown layout");
3738                 return;
3739         }
3740
3741         mainwin->hpaned = hpaned;
3742         mainwin->vpaned = vpaned;
3743
3744         if (layout_mode == SMALL_LAYOUT) {
3745                 if (mainwin->messageview->visible)
3746                         main_window_toggle_message_view(mainwin);
3747         } 
3748
3749         if (layout_mode == SMALL_LAYOUT && first_set) {
3750                 gtk_widget_realize(mainwin->window);
3751                 gtk_widget_realize(mainwin->folderview->ctree);
3752                 gtk_widget_realize(mainwin->summaryview->hbox);
3753                 gtk_widget_realize(mainwin->summaryview->hbox_l);
3754                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3755                                     prefs_common.folderview_width,
3756                                     prefs_common.folderview_height);
3757                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3758                                     0,0);
3759                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3760                                     0,0);
3761                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3762                                 prefs_common.mainwin_width,
3763                                 prefs_common.mainwin_height);
3764                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3765         } else {
3766                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3767                                     prefs_common.folderview_width,
3768                                     prefs_common.folderview_height);
3769                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3770                                     prefs_common.summaryview_width,
3771                                     prefs_common.summaryview_height);
3772                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3773                                     prefs_common.msgview_width,
3774                                     prefs_common.msgview_height);
3775                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3776                                     prefs_common.mainwin_width,
3777                                     prefs_common.mainwin_height);
3778         } 
3779         /* remove headerview if not in prefs */
3780         headerview_set_visibility(mainwin->messageview->headerview,
3781                                   prefs_common.display_header_pane);
3782
3783         if (messageview_is_visible(mainwin->messageview))
3784                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3785                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3786         else
3787                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3788                               GTK_ARROW_UP, GTK_SHADOW_OUT);
3789
3790         gtk_window_move(GTK_WINDOW(mainwin->window),
3791                         prefs_common.mainwin_x,
3792                         prefs_common.mainwin_y);
3793
3794         gtk_widget_queue_resize(vbox_body);
3795         gtk_widget_queue_resize(mainwin->vbox);
3796         gtk_widget_queue_resize(mainwin->window);
3797         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3798          * and mimeview icon list/ctree lose track of their visibility states */
3799         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
3800                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3801         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
3802                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3803         if (mainwin->messageview->mimeview->ctree_mode)
3804                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3805         else 
3806                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3807
3808         prefs_common.layout_mode = layout_mode;
3809
3810         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/ShowHide/MessageView", 
3811                  messageview_is_visible(mainwin->messageview));
3812
3813 #ifndef GENERIC_UMPC
3814         switch (prefs_common.layout_mode) {
3815         case NORMAL_LAYOUT:
3816                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Layout/Standard", TRUE);
3817                 break;
3818         case VERTICAL_LAYOUT:
3819                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Layout/ThreeColumns", TRUE);
3820                 break;
3821         case WIDE_LAYOUT:
3822                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Layout/WideMessage", TRUE);
3823                 break;
3824         case WIDE_MSGLIST_LAYOUT:
3825                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Layout/WideMessageList", TRUE);
3826                 break;
3827         case SMALL_LAYOUT:
3828                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Layout/SmallScreen", TRUE);
3829                 break;
3830         }
3831 #endif
3832
3833         if (folderwin) {
3834                 g_signal_connect
3835                         (G_OBJECT(folderwin), "size_allocate",
3836                          G_CALLBACK(folder_window_size_allocate_cb),
3837                          mainwin);
3838         }
3839         if (messagewin) {
3840                 g_signal_connect
3841                         (G_OBJECT(messagewin), "size_allocate",
3842                          G_CALLBACK(message_window_size_allocate_cb),
3843                          mainwin);
3844         }
3845
3846         debug_print("done.\n");
3847 }
3848
3849 void main_window_destroy_all(void)
3850 {
3851         while (mainwin_list != NULL) {
3852                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3853
3854                 /* free toolbar stuff */
3855                 toolbar_clear_list(TOOLBAR_MAIN);
3856                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3857                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3858
3859                 summaryview_destroy(mainwin->summaryview);
3860                 mainwin->folderview->mainwin = NULL;
3861                 mainwin->summaryview->mainwin = NULL;
3862                 mainwin->messageview->mainwin = NULL;
3863
3864                 g_free(mainwin->toolbar);
3865                 g_free(mainwin);
3866                 
3867                 mainwin_list = g_list_remove(mainwin_list, mainwin);
3868         }
3869         g_list_free(mainwin_list);
3870         mainwin_list = NULL;
3871 }
3872
3873 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3874                                    gpointer data)
3875 {
3876         gtk_widget_set_size_request(child, 1, -1);
3877 }
3878
3879 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3880                                    gpointer data)
3881 {
3882         gtk_widget_set_size_request(child, -1, -1);
3883 }
3884 #ifndef GENERIC_UMPC
3885 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3886                                     gpointer data)
3887 {
3888         MainWindow *mainwin = (MainWindow *)data;
3889         GtkWidget *menu = NULL;
3890         
3891         if (!event) return FALSE;
3892
3893         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3894         
3895         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(mainwin->ac_menu));
3896
3897         gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
3898                        menu_button_position, widget,
3899                        event->button, event->time);
3900
3901         return TRUE;
3902 }
3903 #endif
3904 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3905                                  gpointer data)
3906 {
3907         MainWindow *mainwin = (MainWindow *)data;
3908         gboolean close_allowed = TRUE;
3909
3910         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3911
3912         if (close_allowed && mainwin->lock_count == 0)
3913                 app_exit_cb(NULL, data);
3914
3915         return TRUE;
3916 }
3917
3918 static void main_window_size_allocate_cb(GtkWidget *widget,
3919                                          GtkAllocation *allocation,
3920                                          gpointer data)
3921 {
3922         MainWindow *mainwin = (MainWindow *)data;
3923         main_window_get_size(mainwin);
3924 }
3925
3926 static void folder_window_size_allocate_cb(GtkWidget *widget,
3927                                            GtkAllocation *allocation,
3928                                            gpointer data)
3929 {
3930         MainWindow *mainwin = (MainWindow *)data;
3931
3932         main_window_get_size(mainwin);
3933 }
3934
3935 static void message_window_size_allocate_cb(GtkWidget *widget,
3936                                             GtkAllocation *allocation,
3937                                             gpointer data)
3938 {
3939         MainWindow *mainwin = (MainWindow *)data;
3940
3941         main_window_get_size(mainwin);
3942 }
3943
3944 static void add_mailbox_cb(GtkAction *action, gpointer data)
3945 {
3946         MainWindow *mainwin = (MainWindow *)data;
3947         main_window_add_mailbox(mainwin);
3948 }
3949
3950 static void update_folderview_cb(GtkAction *action, gpointer data)
3951 {
3952         MainWindow *mainwin = (MainWindow *)data;
3953         summary_show(mainwin->summaryview, NULL);
3954         folderview_check_new_all();
3955 }
3956
3957 static void foldersort_cb(GtkAction *action, gpointer data)
3958 {
3959         foldersort_open();
3960 }
3961
3962 static void import_mbox_cb(GtkAction *action, gpointer data)
3963 {
3964         MainWindow *mainwin = (MainWindow *)data;
3965         /* only notify if import has failed */
3966         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3967                 alertpanel_error(_("Mbox import has failed."));
3968         }
3969 }
3970
3971 static void export_mbox_cb(GtkAction *action, gpointer data)
3972 {
3973         MainWindow *mainwin = (MainWindow *)data;
3974         /* only notify if export has failed */
3975         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3976                 alertpanel_error(_("Export to mbox has failed."));
3977         }
3978 }
3979
3980 static void export_list_mbox_cb(GtkAction *action, gpointer data)
3981 {
3982         MainWindow *mainwin = (MainWindow *)data;
3983         /* only notify if export has failed */
3984         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3985                 alertpanel_error(_("Export to mbox has failed."));
3986         }
3987 }
3988
3989 static void empty_trash_cb(GtkAction *action, gpointer data)
3990 {
3991         MainWindow *mainwin = (MainWindow *)data;
3992         main_window_empty_trash(mainwin, TRUE, FALSE);
3993 }
3994
3995 static void save_as_cb(GtkAction *action, gpointer data)
3996 {
3997         MainWindow *mainwin = (MainWindow *)data;
3998         summary_save_as(mainwin->summaryview);
3999 }
4000
4001 static void print_cb(GtkAction *action, gpointer data)
4002 {
4003         MainWindow *mainwin = (MainWindow *)data;
4004         summary_print(mainwin->summaryview);
4005 }
4006
4007 static void page_setup_cb(GtkAction *action, gpointer data)
4008 {
4009         MainWindow *mainwin = (MainWindow *)data;
4010         GtkWindow *win;
4011
4012         win = (mainwin ? GTK_WINDOW(mainwin->window) : NULL);
4013
4014         printing_page_setup(win);
4015 }
4016
4017 static void app_exit_cb(GtkAction *action, gpointer data)
4018 {
4019         MainWindow *mainwin = (MainWindow *)data;
4020         if (prefs_common.clean_on_exit) {
4021                 if (!main_window_empty_trash(mainwin, prefs_common.ask_on_clean, TRUE))
4022                         return;
4023         }
4024
4025         if (prefs_common.confirm_on_exit) {
4026                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
4027                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
4028                     != G_ALERTALTERNATE)
4029                         return;
4030                 manage_window_focus_in(mainwin->window, NULL, NULL);
4031         }
4032
4033         app_will_exit(NULL, mainwin);
4034 }
4035
4036 static void search_cb(GtkAction *action, gpointer data)
4037 {
4038         MainWindow *mainwin = (MainWindow *)data;
4039         message_search(mainwin->messageview);
4040 }
4041
4042 static void search_folder_cb(GtkAction *action, gpointer data)
4043 {
4044         MainWindow *mainwin = (MainWindow *)data;
4045         FolderItem *item = mainwin->summaryview->folder_item;
4046         cm_return_if_fail(item != NULL);
4047         summary_search(mainwin->summaryview);
4048 }
4049
4050 static void mainwindow_quicksearch(GtkAction *action, gpointer data)
4051 {
4052         MainWindow *mainwin = (MainWindow *)data;
4053         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
4054 }
4055
4056 static void toggle_message_cb(GtkAction *action, gpointer data)
4057 {
4058         MainWindow *mainwin = (MainWindow *)data;
4059         gboolean active;
4060
4061         active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4062
4063         if (active != messageview_is_visible(mainwin->messageview))
4064                 summary_toggle_view(mainwin->summaryview);
4065 }
4066
4067 static void toggle_toolbar_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
4068 {
4069         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4070         MainWindow *mainwin = (MainWindow *)data;
4071         toolbar_toggle(value, mainwin);
4072 }
4073
4074 static void main_window_reply_cb(GtkAction *gaction, gpointer data)
4075 {
4076         MainWindow *mainwin = (MainWindow *)data;
4077         MessageView *msgview = (MessageView*)mainwin->messageview;
4078         GSList *msginfo_list = NULL;
4079         gint action = COMPOSE_REPLY;
4080         const gchar *a_name = gtk_action_get_name(gaction);
4081
4082         DO_ACTION("Message/Reply", COMPOSE_REPLY);
4083         DO_ACTION("Message/ReplyTo/All", COMPOSE_REPLY_TO_ALL);
4084         DO_ACTION("Message/ReplyTo/Sender", COMPOSE_REPLY_TO_SENDER);
4085         DO_ACTION("Message/ReplyTo/List", COMPOSE_REPLY_TO_LIST);
4086         DO_ACTION("Message/Forward", COMPOSE_FORWARD_INLINE);
4087         DO_ACTION("Message/ForwardAtt", COMPOSE_FORWARD_AS_ATTACH);
4088         DO_ACTION("Message/Redirect", COMPOSE_REDIRECT);
4089         DO_ACTION("Message/FollowupReply", COMPOSE_FOLLOWUP_AND_REPLY_TO);
4090
4091         cm_return_if_fail(msgview != NULL);
4092
4093         msginfo_list = summary_get_selection(mainwin->summaryview);
4094         cm_return_if_fail(msginfo_list != NULL);
4095         compose_reply_from_messageview(msgview, msginfo_list, action);
4096         g_slist_free(msginfo_list);
4097 }
4098
4099 static void toggle_col_headers_cb(GtkAction *gaction, gpointer data)
4100 {
4101         MainWindow *mainwin = (MainWindow *)data;
4102         FolderView *folderview = mainwin->folderview;
4103         SummaryView *summaryview = mainwin->summaryview;
4104         MimeView *mimeview = mainwin->messageview->mimeview;
4105
4106         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (gaction))) {
4107                 gtk_cmclist_column_titles_show(GTK_CMCLIST(folderview->ctree));
4108                 gtk_cmclist_column_titles_show(GTK_CMCLIST(summaryview->ctree));
4109                 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mimeview->ctree), TRUE);
4110                 prefs_common.show_col_headers = TRUE;
4111         } else {
4112                 gtk_cmclist_column_titles_hide(GTK_CMCLIST(folderview->ctree));
4113                 gtk_cmclist_column_titles_hide(GTK_CMCLIST(summaryview->ctree));
4114                 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mimeview->ctree), FALSE);               
4115                 prefs_common.show_col_headers = FALSE;
4116         }
4117 }
4118
4119 #ifndef GENERIC_UMPC
4120 static void toggle_statusbar_cb(GtkAction *gaction, gpointer data)
4121 {
4122         MainWindow *mainwin = (MainWindow *)data;
4123         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (gaction))) {
4124                 gtk_widget_show(mainwin->hbox_stat);
4125                 prefs_common.show_statusbar = TRUE;
4126         } else {
4127                 gtk_widget_hide(mainwin->hbox_stat);
4128                 prefs_common.show_statusbar = FALSE;
4129         }
4130 }
4131
4132 static void set_layout_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
4133 {
4134         MainWindow *mainwin = (MainWindow *)data;
4135         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4136         LayoutType layout_mode = value;
4137         LayoutType old_layout_mode = prefs_common.layout_mode;
4138         if (mainwin->menu_lock_count) {
4139                 return;
4140         }
4141         if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current))) {
4142                 return;
4143         }
4144         
4145         if (layout_mode == prefs_common.layout_mode) {
4146                 return;
4147         }
4148         
4149         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
4150                 main_window_toggle_message_view(mainwin);
4151         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
4152                 main_window_toggle_message_view(mainwin);
4153
4154         main_window_separation_change(mainwin, layout_mode);
4155         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
4156         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
4157                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
4158                 if (layout_mode == VERTICAL_LAYOUT)
4159                         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
4160         }
4161         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
4162                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4163                 mainwindow_exit_folder(mainwin);
4164         }
4165         summary_relayout(mainwin->summaryview); 
4166         summary_update_unread(mainwin->summaryview, NULL);
4167 }
4168 #endif
4169
4170 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
4171                                         gboolean ask_sync)
4172 {
4173         static gboolean switching = FALSE;
4174
4175         if (switching)
4176                 return;
4177
4178         switching = TRUE;
4179
4180         offline_ask_sync = ask_sync;
4181         if (offline)
4182                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
4183         else
4184                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
4185         offline_ask_sync = TRUE;
4186
4187         switching = FALSE;
4188 }
4189
4190 static void toggle_work_offline_cb (GtkAction *action, gpointer data)
4191 {
4192         MainWindow *mainwin = (MainWindow *)data;
4193         main_window_toggle_work_offline(mainwin, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)), TRUE);
4194 }
4195
4196 static gboolean any_folder_want_synchronise(void)
4197 {
4198         GList *folderlist = folder_get_list();
4199
4200         /* see if there are synchronised folders */
4201         for (; folderlist; folderlist = folderlist->next) {
4202                 Folder *folder = (Folder *)folderlist->data;
4203                 if (folder_want_synchronise(folder)) {
4204                         return TRUE;
4205                 }
4206         }
4207         
4208         return FALSE;
4209 }
4210
4211 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
4212 {
4213         
4214         if (!any_folder_want_synchronise())
4215                 return;
4216
4217         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
4218                         _("Do you want to synchronise your folders now?"),
4219                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
4220                 return;
4221         
4222         if (offline_ask_sync)
4223                 folder_synchronise(NULL);
4224 }
4225
4226 static void online_switch_clicked (GtkButton *btn, gpointer data) 
4227 {
4228         MainWindow *mainwin;
4229         gboolean have_connectivity;
4230
4231 #ifdef HAVE_NETWORKMANAGER_SUPPORT
4232         have_connectivity = networkmanager_is_online(NULL); 
4233 #else
4234         have_connectivity = TRUE;
4235 #endif
4236
4237         mainwin = (MainWindow *) data;
4238         
4239         cm_return_if_fail(mainwin != NULL);
4240         
4241         if (btn == GTK_BUTTON(mainwin->online_switch)) {
4242 #ifndef GENERIC_UMPC
4243                 gtk_widget_hide (mainwin->online_switch);
4244                 gtk_widget_show (mainwin->offline_switch);
4245 #endif
4246                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/File/OfflineMode", TRUE);
4247
4248                 inc_autocheck_timer_remove();
4249                         
4250                 /* go offline */
4251                 if (prefs_common.work_offline)
4252                         return;
4253
4254                 if(have_connectivity)
4255                         mainwindow_check_synchronise(mainwin, TRUE);
4256                 prefs_common.work_offline = TRUE;
4257                 imap_disconnect_all(have_connectivity);
4258                 nntp_disconnect_all(have_connectivity);
4259                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
4260         } else {
4261                 /*go online */
4262                 if (!prefs_common.work_offline)
4263                         return;
4264 #ifndef GENERIC_UMPC
4265                 gtk_widget_hide (mainwin->offline_switch);
4266                 gtk_widget_show (mainwin->online_switch);
4267 #endif
4268                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/File/OfflineMode", FALSE);
4269                 prefs_common.work_offline = FALSE;
4270                 inc_autocheck_timer_set();
4271                 refresh_resolvers();
4272                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
4273         }
4274 }
4275
4276 static void addressbook_open_cb(GtkAction *action, gpointer data)
4277 {
4278 #ifndef USE_NEW_ADDRBOOK
4279         addressbook_open(NULL);
4280 #else
4281         GError* error = NULL;
4282         
4283         addressbook_dbus_open(FALSE, &error);
4284         if (error) {
4285                 g_warning("Failed to open address book");
4286                 g_warning("%s", error->message);
4287                 g_error_free(error);
4288         }
4289 #endif
4290 }
4291
4292 static void log_window_show_cb(GtkAction *action, gpointer data)
4293 {
4294         MainWindow *mainwin = (MainWindow *)data;
4295         log_window_show(mainwin->logwin);
4296 }
4297
4298 static void filtering_debug_window_show_cb(GtkAction *action, gpointer data)
4299 {
4300         MainWindow *mainwin = (MainWindow *)data;
4301         log_window_show(mainwin->filtering_debugwin);
4302 }
4303
4304 static void inc_cancel_cb(GtkAction *action, gpointer data)
4305 {
4306         inc_cancel_all();
4307         imap_cancel_all();
4308 }
4309
4310 static void send_cancel_cb(GtkAction *action, gpointer data)
4311 {
4312         send_cancel();
4313 }
4314
4315 static void move_to_cb(GtkAction *action, gpointer data)
4316 {
4317         MainWindow *mainwin = (MainWindow *)data;
4318         summary_move_to(mainwin->summaryview);
4319 }
4320
4321 static void copy_to_cb(GtkAction *action, gpointer data)
4322 {
4323         MainWindow *mainwin = (MainWindow *)data;
4324         summary_copy_to(mainwin->summaryview);
4325 }
4326
4327 static void delete_cb(GtkAction *action, gpointer data)
4328 {
4329         MainWindow *mainwin = (MainWindow *)data;
4330         summary_delete(mainwin->summaryview);
4331 }
4332
4333 static void delete_trash_cb(GtkAction *action, gpointer data)
4334 {
4335         MainWindow *mainwin = (MainWindow *)data;
4336         summary_delete_trash(mainwin->summaryview);
4337 }
4338
4339 static void cancel_cb(GtkAction *action, gpointer data)
4340 {
4341         MainWindow *mainwin = (MainWindow *)data;
4342         summary_cancel(mainwin->summaryview);
4343 }
4344
4345 static void open_msg_cb(GtkAction *action, gpointer data)
4346 {
4347         MainWindow *mainwin = (MainWindow *)data;
4348         summary_open_msg(mainwin->summaryview);
4349 }
4350
4351 static void view_source_cb(GtkAction *action, gpointer data)
4352 {
4353         MainWindow *mainwin = (MainWindow *)data;
4354         summary_view_source(mainwin->summaryview);
4355 }
4356
4357 static void show_all_header_cb(GtkAction *action, gpointer data)
4358 {
4359         MainWindow *mainwin = (MainWindow *)data;
4360         if (mainwin->menu_lock_count) return;
4361         prefs_common.show_all_headers = 
4362                         gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4363         summary_display_msg_selected(mainwin->summaryview,
4364                                      gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
4365 }
4366
4367 static void toggle_fullscreen_cb(GtkAction *action, gpointer data)
4368 {
4369         MainWindow *mainwin = (MainWindow *)data;
4370         if (mainwin->menu_lock_count) return;
4371         if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
4372                 gtk_window_unfullscreen(GTK_WINDOW(mainwin->window));
4373                 prefs_common.mainwin_fullscreen = FALSE;
4374         }
4375         else {
4376                 prefs_common.mainwin_fullscreen = TRUE;
4377                 gtk_window_fullscreen(GTK_WINDOW(mainwin->window));
4378         }
4379 }
4380
4381 static void toggle_menubar_cb(GtkAction *action, gpointer data)
4382 {
4383         MainWindow *mainwin = (MainWindow *)data;
4384         if (mainwin->menu_lock_count) return;
4385         if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
4386                 gtk_widget_hide(GTK_WIDGET(mainwin->menubar));
4387                 prefs_common.mainwin_menubar = FALSE;
4388         } else {
4389                 gtk_widget_show(GTK_WIDGET(mainwin->menubar));
4390                 prefs_common.mainwin_menubar = TRUE;
4391         }
4392 }
4393
4394 static void hide_quotes_cb(GtkAction *action, gpointer data)
4395 {
4396         MainWindow *mainwin = (MainWindow *)data;
4397
4398         if (mainwin->menu_lock_count) return;
4399
4400         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
4401                 const gchar *a_name = gtk_action_get_name(GTK_ACTION(action));
4402                 if (!strcmp(a_name, "View/Quotes/CollapseAll")) prefs_common.hide_quotes = 1;
4403                 else if (!strcmp(a_name, "View/Quotes/Collapse2")) prefs_common.hide_quotes = 2;
4404                 else if (!strcmp(a_name, "View/Quotes/Collapse3")) prefs_common.hide_quotes = 3;
4405         } else
4406                 prefs_common.hide_quotes = 0;
4407
4408         mainwin->menu_lock_count++;
4409         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
4410         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
4411         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
4412         mainwin->menu_lock_count--;
4413
4414         summary_redisplay_msg(mainwin->summaryview);
4415 }
4416
4417 static void mark_cb(GtkAction *action, gpointer data)
4418 {
4419         MainWindow *mainwin = (MainWindow *)data;
4420         summary_mark(mainwin->summaryview);
4421 }
4422
4423 static void unmark_cb(GtkAction *action, gpointer data)
4424 {
4425         MainWindow *mainwin = (MainWindow *)data;
4426         summary_unmark(mainwin->summaryview);
4427 }
4428
4429 static void mark_as_unread_cb(GtkAction *action, gpointer data)
4430 {
4431         MainWindow *mainwin = (MainWindow *)data;
4432         summary_mark_as_unread(mainwin->summaryview);
4433 }
4434
4435 static void mark_as_read_cb(GtkAction *action, gpointer data)
4436 {
4437         MainWindow *mainwin = (MainWindow *)data;
4438         summary_mark_as_read(mainwin->summaryview);
4439 }
4440
4441 static void mark_all_read_cb(GtkAction *action, gpointer data)
4442 {
4443         MainWindow *mainwin = (MainWindow *)data;
4444         summary_mark_all_read(mainwin->summaryview);
4445 }
4446
4447 static void mark_as_spam_cb(GtkAction *action, gpointer data)
4448 {
4449         MainWindow *mainwin = (MainWindow *)data;
4450         summary_mark_as_spam(mainwin->summaryview, TRUE, NULL);
4451 }
4452
4453 static void mark_as_ham_cb(GtkAction *action, gpointer data)
4454 {
4455         MainWindow *mainwin = (MainWindow *)data;
4456         summary_mark_as_spam(mainwin->summaryview, FALSE, NULL);
4457 }
4458
4459 static void ignore_thread_cb(GtkAction *action, gpointer data)
4460 {
4461         MainWindow *mainwin = (MainWindow *)data;
4462         summary_ignore_thread(mainwin->summaryview);
4463 }
4464
4465 static void unignore_thread_cb(GtkAction *action, gpointer data)
4466 {
4467         MainWindow *mainwin = (MainWindow *)data;
4468         summary_unignore_thread(mainwin->summaryview);
4469 }
4470
4471 static void watch_thread_cb(GtkAction *action, gpointer data)
4472 {
4473         MainWindow *mainwin = (MainWindow *)data;
4474         summary_watch_thread(mainwin->summaryview);
4475 }
4476
4477 static void unwatch_thread_cb(GtkAction *action, gpointer data)
4478 {
4479         MainWindow *mainwin = (MainWindow *)data;
4480         summary_unwatch_thread(mainwin->summaryview);
4481 }
4482
4483 static void lock_msgs_cb(GtkAction *action, gpointer data)
4484 {
4485         MainWindow *mainwin = (MainWindow *)data;
4486         summary_msgs_lock(mainwin->summaryview);
4487 }
4488
4489 static void unlock_msgs_cb(GtkAction *action, gpointer data)
4490 {
4491         MainWindow *mainwin = (MainWindow *)data;
4492         summary_msgs_unlock(mainwin->summaryview);
4493 }
4494
4495
4496 static void reedit_cb(GtkAction *action, gpointer data)
4497 {
4498         MainWindow *mainwin = (MainWindow *)data;
4499         summary_reedit(mainwin->summaryview);
4500 }
4501
4502 static void open_urls_cb(GtkAction *action, gpointer data)
4503 {
4504         MainWindow *mainwin = (MainWindow *)data;
4505         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
4506                 summary_display_msg_selected(mainwin->summaryview, 
4507                                              prefs_common.show_all_headers);
4508         }
4509         messageview_list_urls(mainwin->messageview);
4510 }
4511
4512 static void add_address_cb(GtkAction *action, gpointer data)
4513 {
4514         MainWindow *mainwin = (MainWindow *)data;
4515         summary_add_address(mainwin->summaryview);
4516 }
4517
4518 static void set_charset_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
4519 {
4520         MainWindow *mainwin = (MainWindow *)data;
4521         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4522         const gchar *str;
4523
4524         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current))) {
4525                 str = conv_get_charset_str((CharSet)value);
4526                 
4527                 g_free(mainwin->messageview->forced_charset);
4528                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
4529                 procmime_force_charset(str);
4530                 
4531                 summary_redisplay_msg(mainwin->summaryview);
4532                 
4533                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
4534         }
4535 }
4536
4537 static void set_decode_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
4538 {
4539         MainWindow *mainwin = (MainWindow *)data;
4540         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4541         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current))) {
4542                 mainwin->messageview->forced_encoding = (EncodingType)value;
4543                 
4544                 summary_redisplay_msg(mainwin->summaryview);
4545                 
4546                 debug_print("forced encoding: %d\n", value);
4547         }
4548 }
4549
4550 static void hide_read_messages (GtkAction *action, gpointer data)
4551 {
4552         MainWindow *mainwin = (MainWindow *)data;
4553         GtkWidget *menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/HideReadMessages");
4554         if (!mainwin->summaryview->folder_item
4555             || g_object_get_data(G_OBJECT(menuitem), "dont_toggle"))
4556                 return;
4557         summary_toggle_show_read_messages(mainwin->summaryview);
4558 }
4559
4560 static void hide_del_messages (GtkAction *action, gpointer data)
4561 {
4562         MainWindow *mainwin = (MainWindow *)data;
4563         GtkWidget *menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/HideDelMessages");
4564         if (!mainwin->summaryview->folder_item
4565             || g_object_get_data(G_OBJECT(menuitem), "dont_toggle"))
4566                 return;
4567         summary_toggle_show_del_messages(mainwin->summaryview);
4568 }
4569
4570 static void hide_read_threads (GtkAction *action, gpointer data)
4571 {
4572         MainWindow *mainwin = (MainWindow *)data;
4573         GtkWidget *menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/HideReadThreads");
4574         if (!mainwin->summaryview->folder_item
4575             || g_object_get_data(G_OBJECT(menuitem), "dont_toggle"))
4576                 return;
4577         summary_toggle_show_read_threads(mainwin->summaryview);
4578 }
4579
4580 static void thread_cb(GtkAction *action, gpointer data)
4581 {
4582         MainWindow *mainwin = (MainWindow *)data;
4583         gboolean threaded = FALSE;
4584         if (mainwin->menu_lock_count) return;
4585         if (!mainwin->summaryview->folder_item) return;
4586
4587         threaded = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
4588
4589         mainwin->summaryview->folder_item->threaded = threaded; 
4590
4591         mainwin->summaryview->threaded = threaded;
4592
4593         summary_show(mainwin->summaryview, 
4594                         mainwin->summaryview->folder_item);
4595 }
4596
4597 static void expand_threads_cb(GtkAction *action, gpointer data)
4598 {
4599         MainWindow *mainwin = (MainWindow *)data;
4600         summary_expand_threads(mainwin->summaryview);
4601 }
4602
4603 static void collapse_threads_cb(GtkAction *action, gpointer data)
4604 {
4605         MainWindow *mainwin = (MainWindow *)data;
4606         summary_collapse_threads(mainwin->summaryview);
4607 }
4608
4609 static void set_summary_display_item_cb(GtkAction *action, gpointer data)
4610 {
4611         prefs_summary_column_open();
4612 }
4613
4614 static void set_folder_display_item_cb(GtkAction *action, gpointer data)
4615 {
4616         prefs_folder_column_open();
4617 }
4618
4619 static void sort_summary_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
4620 {
4621         MainWindow *mainwin = (MainWindow *)data;
4622         FolderItem *item = mainwin->summaryview->folder_item;
4623         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4624
4625         if (mainwin->menu_lock_count) return;
4626
4627         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item) {
4628                 summary_sort(mainwin->summaryview, (FolderSortKey)value,
4629                              item->sort_type);
4630                 item->sort_key = value;
4631         }
4632 }
4633
4634 static void sort_summary_type_cb(GtkAction *gaction, GtkRadioAction *current, gpointer data)
4635 {
4636         MainWindow *mainwin = (MainWindow *)data;
4637         FolderItem *item = mainwin->summaryview->folder_item;
4638         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
4639
4640         if (mainwin->menu_lock_count) return;
4641
4642         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item)
4643                 summary_sort(mainwin->summaryview,
4644                              item->sort_key, (FolderSortType)value);
4645 }
4646
4647 static void attract_by_subject_cb(GtkAction *action, gpointer data)
4648 {
4649         MainWindow *mainwin = (MainWindow *)data;
4650         summary_attract_by_subject(mainwin->summaryview);
4651 }
4652
4653 static void delete_duplicated_cb(GtkAction *action, gpointer data)
4654 {
4655         MainWindow *mainwin = (MainWindow *)data;
4656         FolderItem *item;
4657
4658         item = folderview_get_selected_item(mainwin->folderview);
4659         if (item) {
4660                 main_window_cursor_wait(mainwin);
4661                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
4662
4663                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
4664                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
4665
4666                 STATUSBAR_POP(mainwin);
4667                 main_window_cursor_normal(mainwin);
4668         }
4669 }
4670
4671 struct DelDupsData
4672 {
4673         guint   dups;
4674         guint   folders;
4675 };
4676
4677 static void deldup_all(FolderItem *item, gpointer _data)
4678 {
4679         struct DelDupsData *data = _data;
4680         gint result;
4681         
4682         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
4683         if (result >= 0) {
4684                 data->dups += result;
4685                 data->folders += 1;
4686         }
4687 }
4688
4689 static void delete_duplicated_all_cb(GtkAction *action, gpointer mw)
4690 {
4691         MainWindow *mainwin = (MainWindow *)mw;
4692         struct DelDupsData data = {0, 0};
4693
4694         main_window_cursor_wait(mainwin);
4695         folder_func_to_all_folders(deldup_all, &data);
4696         main_window_cursor_normal(mainwin);
4697         
4698         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
4699                                    "Deleted %d duplicate messages in %d folders.\n",
4700                                    data.dups),
4701                           data.dups, data.folders);
4702 }
4703
4704 static void filter_cb(GtkAction *action, gpointer data)
4705 {
4706         MainWindow *mainwin = (MainWindow *)data;
4707         summary_filter(mainwin->summaryview, FALSE);
4708 }
4709
4710 static void filter_list_cb(GtkAction *action, gpointer data)
4711 {
4712         MainWindow *mainwin = (MainWindow *)data;
4713         summary_filter(mainwin->summaryview, TRUE);
4714 }
4715
4716 static void process_cb(GtkAction *action, gpointer data)
4717 {
4718         MainWindow *mainwin = (MainWindow *)data;
4719         FolderItem *item = mainwin->summaryview->folder_item;   
4720         cm_return_if_fail(item != NULL);
4721
4722         item->processing_pending = TRUE;
4723         folder_item_apply_processing(item);     
4724         item->processing_pending = FALSE;
4725 }
4726
4727 static void execute_summary_cb(GtkAction *action, gpointer data)
4728 {
4729         MainWindow *mainwin = (MainWindow *)data;
4730         summary_execute(mainwin->summaryview);
4731 }
4732
4733 static void expunge_summary_cb(GtkAction *action, gpointer data)
4734 {
4735         MainWindow *mainwin = (MainWindow *)data;
4736         summary_expunge(mainwin->summaryview);
4737 }
4738
4739 static void update_summary_cb(GtkAction *action, gpointer data)
4740 {
4741         MainWindow *mainwin = (MainWindow *)data;
4742         FolderItem *fitem;
4743         FolderView *folderview = mainwin->folderview;
4744
4745         if (!mainwin->summaryview->folder_item) return;
4746         if (!folderview->opened) return;
4747
4748         folder_update_op_count();
4749
4750         fitem = gtk_cmctree_node_get_row_data(GTK_CMCTREE(folderview->ctree),
4751                                             folderview->opened);
4752         if (!fitem) return;
4753
4754         folder_item_scan(fitem);
4755         summary_show(mainwin->summaryview, fitem);
4756 }
4757
4758 static void prev_cb(GtkAction *action, gpointer data)
4759 {
4760         MainWindow *mainwin = (MainWindow *)data;
4761         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
4762 }
4763
4764 static void next_cb(GtkAction *action, gpointer data)
4765 {
4766         MainWindow *mainwin = (MainWindow *)data;
4767         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
4768 }
4769
4770 static void prev_unread_cb(GtkAction *action, gpointer data)
4771 {
4772         MainWindow *mainwin = (MainWindow *)data;
4773         summary_select_prev_unread(mainwin->summaryview);
4774 }
4775
4776 static void next_unread_cb(GtkAction *action, gpointer data)
4777 {
4778         MainWindow *mainwin = (MainWindow *)data;
4779         summary_select_next_unread(mainwin->summaryview);
4780 }
4781
4782 static void prev_new_cb(GtkAction *action, gpointer data)
4783 {
4784         MainWindow *mainwin = (MainWindow *)data;
4785         summary_select_prev_new(mainwin->summaryview);
4786 }
4787
4788 static void next_new_cb(GtkAction *action, gpointer data)
4789 {
4790         MainWindow *mainwin = (MainWindow *)data;
4791         summary_select_next_new(mainwin->summaryview);
4792 }
4793
4794 static void prev_marked_cb(GtkAction *action, gpointer data)
4795 {
4796         MainWindow *mainwin = (MainWindow *)data;
4797         summary_select_prev_marked(mainwin->summaryview);
4798 }
4799
4800 static void next_marked_cb(GtkAction *action, gpointer data)
4801 {
4802         MainWindow *mainwin = (MainWindow *)data;
4803         summary_select_next_marked(mainwin->summaryview);
4804 }
4805
4806 static void prev_labeled_cb(GtkAction *action, gpointer data)
4807 {
4808         MainWindow *mainwin = (MainWindow *)data;
4809         summary_select_prev_labeled(mainwin->summaryview);
4810 }
4811
4812 static void next_labeled_cb(GtkAction *action, gpointer data)
4813 {
4814         MainWindow *mainwin = (MainWindow *)data;
4815         summary_select_next_labeled(mainwin->summaryview);
4816 }
4817
4818 static void prev_history_cb(GtkAction *action, gpointer data)
4819 {
4820         MainWindow *mainwin = (MainWindow *)data;
4821         MsgInfo *info = messageview_nav_get_prev(mainwin->messageview);
4822         if (info) {
4823                 if (info->folder != mainwin->summaryview->folder_item)
4824                         folderview_select(mainwin->folderview, info->folder);
4825                 summary_display_by_msgnum(mainwin->summaryview, info->msgnum);
4826                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4827                 procmsg_msginfo_free(info);
4828                 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4829                 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4830         }
4831 }
4832
4833 static void next_history_cb(GtkAction *action, gpointer data)
4834 {
4835         MainWindow *mainwin = (MainWindow *)data;
4836         MsgInfo *info = messageview_nav_get_next(mainwin->messageview);
4837         if (info) {
4838                 if (info->folder != mainwin->summaryview->folder_item)
4839                         folderview_select(mainwin->folderview, info->folder);
4840                 summary_display_by_msgnum(mainwin->summaryview, info->msgnum);
4841                 procmsg_msginfo_free(info);
4842                 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4843                 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4844         }
4845 }
4846
4847 static void parent_cb(GtkAction *action, gpointer data)
4848 {
4849         MainWindow *mainwin = (MainWindow *)data;
4850         summary_select_parent(mainwin->summaryview);
4851 }
4852
4853 static void goto_folder_cb(GtkAction *action, gpointer data)
4854 {
4855         MainWindow *mainwin = (MainWindow *)data;
4856         FolderItem *to_folder;
4857
4858         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE);
4859
4860         if (to_folder)
4861                 folderview_select(mainwin->folderview, to_folder);
4862 }
4863
4864 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
4865 {
4866         MainWindow *mainwin = (MainWindow *)data;
4867         folderview_select_next_with_flag(mainwin->folderview, MSG_UNREAD, FALSE);
4868 }
4869
4870 static void scroll_prev_line_cb(GtkAction *action, gpointer data)
4871 {
4872         MainWindow *mainwin = (MainWindow *)data;
4873         mimeview_scroll_one_line(mainwin->messageview->mimeview,TRUE);
4874 }
4875
4876 static void scroll_next_line_cb(GtkAction *action, gpointer data)
4877 {
4878         MainWindow *mainwin = (MainWindow *)data;
4879         mimeview_scroll_one_line(mainwin->messageview->mimeview,FALSE);
4880 }
4881
4882 static void scroll_prev_page_cb(GtkAction *action, gpointer data)
4883 {
4884         MainWindow *mainwin = (MainWindow *)data;
4885         mimeview_scroll_page(mainwin->messageview->mimeview,TRUE);
4886 }
4887
4888 static void scroll_next_page_cb(GtkAction *action, gpointer data)
4889 {
4890         MainWindow *mainwin = (MainWindow *)data;
4891         mimeview_scroll_page(mainwin->messageview->mimeview,FALSE);
4892 }
4893
4894 static void copy_cb(GtkAction *action, gpointer data)
4895 {
4896         MainWindow *mainwin = (MainWindow *)data;
4897         messageview_copy_clipboard(mainwin->messageview);
4898 }
4899
4900 static void allsel_cb(GtkAction *action, gpointer data)
4901 {
4902         MainWindow *mainwin = (MainWindow *)data;
4903         MessageView *msgview = mainwin->messageview;
4904
4905         if (messageview_is_visible(msgview) &&
4906                  (gtk_widget_has_focus(msgview->mimeview->textview->text)))
4907                 messageview_select_all(mainwin->messageview);
4908         else
4909                 summary_select_all(mainwin->summaryview);
4910 }
4911
4912 static void select_thread_cb(GtkAction *action, gpointer data)
4913 {
4914         MainWindow *mainwin = (MainWindow *)data;
4915         summary_select_thread(mainwin->summaryview, FALSE);
4916 }
4917
4918 static void delete_thread_cb(GtkAction *action, gpointer data)
4919 {
4920         MainWindow *mainwin = (MainWindow *)data;
4921         summary_select_thread(mainwin->summaryview, TRUE);
4922 }
4923
4924 static void create_filter_cb(GtkAction *gaction, gpointer data)
4925 {
4926         MainWindow *mainwin = (MainWindow *)data;
4927         const gchar *a_name = gtk_action_get_name(gaction);
4928         gint action = -1;
4929
4930         DO_ACTION("Tools/CreateFilterRule/Automatically", FILTER_BY_AUTO);
4931         DO_ACTION("Tools/CreateFilterRule/ByFrom", FILTER_BY_FROM);
4932         DO_ACTION("Tools/CreateFilterRule/ByTo", FILTER_BY_TO);
4933         DO_ACTION("Tools/CreateFilterRule/BySubject", FILTER_BY_SUBJECT);
4934         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4935 }
4936
4937 static void create_processing_cb(GtkAction *gaction, gpointer data)
4938 {
4939         MainWindow *mainwin = (MainWindow *)data;
4940         const gchar *a_name = gtk_action_get_name(gaction);
4941         gint action = -1;
4942
4943         DO_ACTION("Tools/CreateProcessingRule/Automatically", FILTER_BY_AUTO);
4944         DO_ACTION("Tools/CreateProcessingRule/ByFrom", FILTER_BY_FROM);
4945         DO_ACTION("Tools/CreateProcessingRule/ByTo", FILTER_BY_TO);
4946         DO_ACTION("Tools/CreateProcessingRule/BySubject", FILTER_BY_SUBJECT);
4947         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4948 }
4949
4950 static void prefs_pre_processing_open_cb(GtkAction *action, gpointer data)
4951 {
4952         prefs_filtering_open(&pre_global_processing,
4953                              _("Processing rules to apply before folder rules"),
4954                              MANUAL_ANCHOR_PROCESSING,
4955                              NULL, NULL, FALSE);
4956 }
4957
4958 static void prefs_post_processing_open_cb(GtkAction *action, gpointer data)
4959 {
4960         prefs_filtering_open(&post_global_processing,
4961                              _("Processing rules to apply after folder rules"),
4962                              MANUAL_ANCHOR_PROCESSING,
4963                              NULL, NULL, FALSE);
4964 }
4965
4966 static void prefs_filtering_open_cb(GtkAction *action, gpointer data)
4967 {
4968         prefs_filtering_open(&filtering_rules,
4969                              _("Filtering configuration"),
4970                              MANUAL_ANCHOR_FILTERING,
4971                              NULL, NULL, TRUE);
4972 }
4973
4974 static void prefs_template_open_cb(GtkAction *action, gpointer data)
4975 {
4976         prefs_template_open();
4977 }
4978
4979 static void prefs_actions_open_cb(GtkAction *action, gpointer data)
4980 {
4981         MainWindow *mainwin = (MainWindow *)data;
4982         prefs_actions_open(mainwin);
4983 }
4984
4985 static void prefs_tags_open_cb(GtkAction *action, gpointer data)
4986 {
4987         MainWindow *mainwin = (MainWindow *)data;
4988         GSList * list = summary_get_selected_msg_list(mainwin->summaryview);
4989         tag_apply_open(list);
4990 }
4991 #ifdef USE_GNUTLS
4992 static void ssl_manager_open_cb(GtkAction *action, gpointer data)
4993 {
4994         MainWindow *mainwin = (MainWindow *)data;
4995         ssl_manager_open(mainwin);
4996 }
4997 #endif
4998 static void prefs_account_open_cb(GtkAction *action, gpointer data)
4999 {
5000         MainWindow *mainwin = (MainWindow *)data;
5001         if (!cur_account) {
5002                 new_account_cb(NULL, mainwin);
5003         } else {
5004                 account_open(cur_account);
5005         }
5006 }
5007
5008 static void new_account_cb(GtkAction *action, gpointer data)
5009 {
5010         account_edit_open(NULL, NULL);
5011         if (!compose_get_compose_list()) account_add();
5012 }
5013
5014 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
5015 {
5016         FolderItem *item = NULL;
5017         cur_account = (PrefsAccount *)data;
5018         
5019         if (!mainwindow_get_mainwindow())
5020                 return;
5021         main_window_show_cur_account(mainwindow_get_mainwindow());
5022         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
5023         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
5024         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
5025         item = folderview_get_selected_item(
5026                         mainwindow_get_mainwindow()->folderview);
5027         if (item) {
5028                 toolbar_set_compose_button
5029                         (mainwindow_get_mainwindow()->toolbar,
5030                          FOLDER_TYPE(item->folder) == F_NEWS ? 
5031                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
5032         }
5033 }
5034
5035 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
5036 {
5037         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
5038         PrefsAccount *account = (PrefsAccount *)data;
5039
5040         inc_account_mail(mainwin, account);
5041 }
5042 #ifndef GENERIC_UMPC
5043 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
5044 {
5045         PrefsAccount *account = (PrefsAccount *)data;
5046
5047         compose_new_with_folderitem(account, NULL, NULL);
5048 }
5049 #endif
5050 static void prefs_open_cb(GtkAction *action, gpointer data)
5051 {
5052         prefs_gtk_open();
5053 }
5054
5055 static void plugins_open_cb(GtkAction *action, gpointer data)
5056 {
5057         pluginwindow_create();
5058 }
5059
5060 static void manual_open_cb(GtkAction *action, gpointer data)
5061 {
5062         manual_open(MANUAL_MANUAL_CLAWS, NULL);
5063 }
5064
5065 static void manual_faq_open_cb(GtkAction *action, gpointer data)
5066 {
5067         manual_open(MANUAL_FAQ_CLAWS, NULL);
5068 }
5069
5070 static void legend_open_cb(GtkAction *action, gpointer data)
5071 {
5072         legend_show();
5073 }
5074
5075 #ifdef G_OS_WIN32
5076 static void set_default_client_cb(GtkAction *action, gpointer data)
5077 {
5078         char exename[MAX_PATH];
5079         gchar *binary_icon = NULL;
5080         gchar *binary_compose = NULL;
5081         gchar *binary_run = NULL;
5082         int r = 0;
5083         if ( !GetModuleFileNameA (0, exename, sizeof (exename)) ) {
5084                 alertpanel_error(_("Can not register as default client: impossible to get executable path."));
5085                 return;
5086         }
5087         binary_icon = g_strconcat(exename, ",0", NULL);
5088         binary_compose = g_strconcat(exename, " --compose %1", NULL);
5089         binary_run = g_strconcat(exename, NULL);
5090
5091         /* Try to set the Mail Start menu item to Claws. It may fail if we're not root; we don't care */
5092         r = write_w32_registry_string("HKLM", "Software\\Clients\\Mail", 
5093                         "", "Claws Mail");
5094         
5095         r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", 
5096                                 "", "Claws Mail");
5097         if (!r)
5098                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", 
5099                                 "DLLPath", "");
5100         if (!r)
5101                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
5102                                 "", "URL:MailTo-Protocol");
5103         if (!r)
5104                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
5105                                 "URL Protocol", "");
5106         if (!r)
5107                 r = write_w32_registry_dword ("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
5108                                 "EditFlags", 2);
5109         if (!r)
5110                 r = write_w32_registry_string ("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", 
5111                                 "FriendlyTypeName", "Claws-Mail URL");
5112         if (!r)
5113                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\DefaultIcon", 
5114                                 "", binary_icon);
5115         if (!r)
5116                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\shell\\open\\command", 
5117                                 "", binary_compose);
5118         if (!r)
5119                 r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\shell\\open\\command", 
5120                                 "", binary_run);
5121         
5122         if (!r)
5123                 r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", 
5124                                 "", "URL:MailTo-Protocol");
5125         if (!r)
5126                 r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", 
5127                                 "URL Protocol", "");
5128         if (!r)
5129                 r = write_w32_registry_dword ("HKCU", "Software\\Classes\\mailto", 
5130                                 "EditFlags", 2);
5131         if (!r)
5132                 r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", 
5133                                 "FriendlyTypeName", "Claws-Mail URL");
5134         if (!r)
5135                 r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\DefaultIcon", 
5136                                 "", binary_icon);
5137         if (!r)
5138                 r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\shell\\open\\command", 
5139                                 "", binary_compose);
5140         
5141         if (!r) {
5142                 SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Software\\Clients\\Mail");
5143                 alertpanel_notice(_("Claws Mail has been registered as default client."));
5144         } else {
5145                 alertpanel_error(_("Can not register as default client: impossible to write to the registry."));
5146         }
5147         g_free(binary_icon);
5148         g_free(binary_compose);
5149         g_free(binary_run);
5150 }
5151 #endif
5152
5153 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
5154 {
5155         MainWindow *mainwin = (MainWindow *)data;
5156         gchar *str;
5157
5158         if (item->path)
5159                 str = g_strdup_printf(_("Scanning folder %s%c%s..."),
5160                                       LOCAL_FOLDER(folder)->rootpath,
5161                                       G_DIR_SEPARATOR,
5162                                       item->path);
5163         else
5164                 str = g_strdup_printf(_("Scanning folder %s..."),
5165                                       LOCAL_FOLDER(folder)->rootpath);
5166
5167         STATUSBAR_PUSH(mainwin, str);
5168         STATUSBAR_POP(mainwin);
5169         g_free(str);
5170 }
5171
5172 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
5173                                           gpointer data)
5174 {
5175         SummaryView *summary;
5176
5177         cm_return_val_if_fail(data, FALSE);
5178         if (!g_list_find(mainwin_list, data))
5179                 return TRUE;
5180         summary = ((MainWindow *)data)->summaryview;
5181         cm_return_val_if_fail(summary, FALSE);
5182
5183         if (GTK_CMCLIST(summary->ctree)->selection && 
5184             g_list_length(GTK_CMCLIST(summary->ctree)->selection) > 1)
5185                 return FALSE;
5186
5187         return FALSE;
5188 }
5189
5190 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
5191                                           gpointer data)
5192 {
5193         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
5194         return FALSE;
5195 }
5196
5197 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
5198                                           gpointer data)
5199 {
5200         if (!claws_is_starting()
5201                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
5202                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
5203
5204                 if (iconified_count > 0)
5205                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
5206                 iconified_count++;
5207         } else if (!claws_is_starting()) {
5208                 prefs_common.mainwin_maximised = 
5209                         ((state->new_window_state&GDK_WINDOW_STATE_MAXIMIZED) != 0);
5210         }
5211         if (state->new_window_state == 0)
5212                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
5213         return FALSE;
5214 }
5215
5216 gboolean mainwindow_is_obscured(void)
5217 {
5218         return is_obscured;
5219 }
5220
5221 /*
5222  * Harvest addresses for selected folder.
5223  */
5224 static void addr_harvest_cb( GtkAction *action, gpointer data)
5225 {
5226         MainWindow *mainwin = (MainWindow *)data;
5227
5228         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
5229 }
5230
5231 /*
5232  * Harvest addresses for selected messages in summary view.
5233  */
5234 static void addr_harvest_msg_cb( GtkAction *action, gpointer data)
5235 {
5236         MainWindow *mainwin = (MainWindow *)data;
5237         summary_harvest_address( mainwin->summaryview );
5238 }
5239
5240 /*!
5241  *\brief        get a MainWindow
5242  *
5243  *\return       MainWindow * The first mainwindow in the mainwin_list
5244  */
5245 MainWindow *mainwindow_get_mainwindow(void)
5246 {
5247         if (mainwin_list && mainwin_list->data)
5248                 return (MainWindow *)(mainwin_list->data);
5249         else
5250                 return NULL;
5251 }
5252
5253 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
5254 {
5255         ProgressData *data = (ProgressData *) source;
5256         MainWindow *mainwin = (MainWindow *) userdata;
5257
5258         switch (data->cmd) {
5259         case PROGRESS_COMMAND_START:
5260         case PROGRESS_COMMAND_STOP:
5261                 gtk_progress_bar_set_fraction
5262                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
5263                 break;
5264         case PROGRESS_COMMAND_SET_PERCENTAGE:
5265                 gtk_progress_bar_set_fraction
5266                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
5267                 break;          
5268         }
5269         while (gtk_events_pending()) gtk_main_iteration ();
5270
5271         return FALSE;
5272 }
5273
5274 static void sync_cb(GtkAction *action, gpointer data)
5275 {
5276         MainWindow *mainwin = (MainWindow *)data;
5277         mainwindow_check_synchronise(mainwin, FALSE);
5278 }
5279
5280 static void forget_session_passwords_cb(GtkAction *action, gpointer data)
5281 {
5282         MainWindow *mainwin = (MainWindow *)data;
5283         GList *list = NULL;
5284         gint fgtn = 0;
5285         gint accs = 0;
5286
5287         main_window_lock(mainwin);
5288         for (list = account_get_list(); list != NULL; list = list->next) {
5289                 PrefsAccount *account = list->data;
5290                 if (account->session_passwd) {
5291                         g_free(account->session_passwd);
5292                         account->session_passwd = NULL;
5293                         ++fgtn;
5294                 }
5295                 if (account->session_smtp_passwd) {
5296                         g_free(account->session_smtp_passwd);
5297                         account->session_smtp_passwd = NULL;
5298                         ++fgtn;
5299                 }
5300                 ++accs;
5301         }
5302         main_window_unlock(mainwin);
5303         alertpanel_notice(ngettext("Forgotten %d password in %d accounts.\n",
5304                                    "Forgotten %d passwords in %d accounts.\n",
5305                                    fgtn), fgtn, accs);  
5306 }
5307
5308 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
5309 {
5310         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
5311 }
5312
5313 void mainwindow_jump_to(const gchar *target, gboolean popup)
5314 {
5315         gchar *tmp = NULL;
5316         gchar *p = NULL;
5317         FolderItem *item = NULL;
5318         gchar *msg = NULL;
5319         MainWindow *mainwin = mainwindow_get_mainwindow();
5320         gchar *from_uri = NULL;
5321         if (!target)
5322                 return;
5323                 
5324         if (!mainwin) {
5325                 g_print("not initialized\n");
5326                 return;
5327         }
5328
5329         if ((from_uri = g_filename_from_uri(target, NULL, NULL)) != NULL)
5330                 tmp = from_uri;
5331         else
5332                 tmp = g_strdup(target);
5333         
5334         if ((p = strstr(tmp, "\r")) != NULL)
5335                 *p = '\0';
5336         if ((p = strstr(tmp, "\n")) != NULL)
5337                 *p = '\0';
5338
5339         if ((item = folder_find_item_from_identifier(tmp))) {
5340                 g_print("selecting folder '%s'\n", tmp);
5341                 folderview_select(mainwin->folderview, item);
5342                 if (popup)
5343                         main_window_popup(mainwin);
5344                 g_free(tmp);
5345                 return;
5346         }
5347         
5348         msg = strrchr(tmp, G_DIR_SEPARATOR);
5349         if (msg) {
5350                 *msg++ = '\0';
5351                 if ((item = folder_find_item_from_identifier(tmp))) {
5352                         g_print("selecting folder '%s'\n", tmp);
5353                         folderview_select(mainwin->folderview, item);
5354                 } else if ((item = folder_find_item_from_real_path(tmp))) {
5355                         g_print("selecting folder '%s'\n", tmp);
5356                         folderview_select(mainwin->folderview, item);
5357                 } else {
5358                         g_print("'%s' not found\n", tmp);
5359                 }
5360                 if (item && msg && atoi(msg)) {
5361                         g_print("selecting message %d\n", atoi(msg));
5362                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
5363                         summary_display_msg_selected(mainwin->summaryview, FALSE);
5364                         if (popup)
5365                                 main_window_popup(mainwin);
5366                         g_free(tmp);
5367                         return;
5368                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
5369                         MsgInfo *msginfo = NULL;
5370                         msg++;
5371                         msg[strlen(msg)-1] = '\0';
5372                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
5373                         if (msginfo) {
5374                                 g_print("selecting message %s\n", msg);
5375                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
5376                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
5377                                 if (popup)
5378                                         main_window_popup(mainwin);
5379                                 g_free(tmp);
5380                                 procmsg_msginfo_free(msginfo);
5381                                 return;
5382                         } else {
5383                                 g_print("'%s' not found\n", msg);
5384                         }
5385                 } else {
5386                         g_print("'%s' not found\n", msg);
5387                 }
5388         } else {
5389                 g_print("'%s' not found\n", tmp);
5390         }
5391         
5392         g_free(tmp);
5393 }
5394
5395 void mainwindow_exit_folder(MainWindow *mainwin) {
5396         if (prefs_common.layout_mode == SMALL_LAYOUT) {
5397                 folderview_close_opened(mainwin->folderview);
5398                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
5399                 gtk_widget_grab_focus(mainwin->folderview->ctree);
5400         }
5401         mainwin->in_folder = FALSE;
5402         main_window_set_menu_sensitive(mainwin);
5403 }
5404
5405 void mainwindow_enter_folder(MainWindow *mainwin) {
5406         if (prefs_common.layout_mode == SMALL_LAYOUT) {
5407                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
5408         }
5409         mainwin->in_folder = TRUE;
5410         main_window_set_menu_sensitive(mainwin);
5411 }
5412
5413 static void save_part_as_cb(GtkAction *action, gpointer data)
5414 {
5415         MainWindow *mainwin = (MainWindow *)data;
5416
5417         if (mainwin->messageview 
5418         &&  mainwin->messageview->mimeview)
5419                 mimeview_save_as(mainwin->messageview->mimeview);
5420 }
5421
5422 static void view_part_as_text_cb(GtkAction *action, gpointer data)
5423 {
5424         MainWindow *mainwin = (MainWindow *)data;
5425
5426         if (mainwin->messageview 
5427         &&  mainwin->messageview->mimeview)
5428                 mimeview_display_as_text(mainwin->messageview->mimeview);
5429 }
5430
5431 static void open_part_cb(GtkAction *action, gpointer data)
5432 {
5433         MainWindow *mainwin = (MainWindow *)data;
5434
5435         if (mainwin->messageview 
5436         &&  mainwin->messageview->mimeview)
5437                 mimeview_launch(mainwin->messageview->mimeview, NULL);
5438 }
5439 #ifndef G_OS_WIN32
5440 static void open_part_with_cb(GtkAction *action, gpointer data)
5441 {
5442         MainWindow *mainwin = (MainWindow *)data;
5443
5444         if (mainwin->messageview 
5445         &&  mainwin->messageview->mimeview)
5446                 mimeview_open_with(mainwin->messageview->mimeview);
5447 }
5448 #endif
5449 static void check_signature_cb(GtkAction *action, gpointer data)
5450 {
5451         MainWindow *mainwin = (MainWindow *)data;
5452
5453         if (mainwin->messageview 
5454         &&  mainwin->messageview->mimeview)
5455                 mimeview_check_signature(mainwin->messageview->mimeview);
5456 }
5457
5458 static void goto_next_part_cb(GtkAction *action, gpointer data)
5459 {
5460         MainWindow *mainwin = (MainWindow *)data;
5461
5462         if (mainwin->messageview 
5463         &&  mainwin->messageview->mimeview)
5464                 mimeview_select_next_part(mainwin->messageview->mimeview);
5465 }
5466
5467 static void goto_prev_part_cb(GtkAction *action, gpointer data)
5468 {
5469         MainWindow *mainwin = (MainWindow *)data;
5470
5471         if (mainwin->messageview 
5472         &&  mainwin->messageview->mimeview)
5473                 mimeview_select_prev_part(mainwin->messageview->mimeview);
5474 }