922da321186c178cb27ab1378b0b55268077a8a5
[claws.git] / src / mainwindow.c
1 /*
2    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3    Copyright (C) 1999-2011 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
27 #include "main.h"
28 #include "mainwindow.h"
29 #include "folderview.h"
30 #include "foldersel.h"
31 #include "summaryview.h"
32 #include "summary_search.h"
33 #include "messageview.h"
34 #include "message_search.h"
35 #include "headerview.h"
36 #include "menu.h"
37 #include "stock_pixmap.h"
38 #include "folder.h"
39 #include "inc.h"
40 #include "log.h"
41 #include "compose.h"
42 #include "procmsg.h"
43 #include "import.h"
44 #include "export.h"
45 #include "edittags.h"
46 #include "prefs_common.h"
47 #include "prefs_actions.h"
48 #include "prefs_filtering.h"
49 #include "prefs_account.h"
50 #include "prefs_summary_column.h"
51 #include "prefs_folder_column.h"
52 #include "prefs_template.h"
53 #include "action.h"
54 #include "account.h"
55 #include "addressbook.h"
56 #include "logwindow.h"
57 #include "manage_window.h"
58 #include "alertpanel.h"
59 #include "statusbar.h"
60 #include "inputdialog.h"
61 #include "utils.h"
62 #include "gtkutils.h"
63 #include "codeconv.h"
64 #include "about.h"
65 #include "manual.h"
66 #include "version.h"
67 #include "ssl_manager.h"
68 #include "sslcertwindow.h"
69 #include "prefs_gtk.h"
70 #include "pluginwindow.h"
71 #include "hooks.h"
72 #include "progressindicator.h"
73 #include "localfolder.h"
74 #include "filtering.h"
75 #include "folderutils.h"
76 #include "foldersort.h"
77 #include "icon_legend.h"
78 #include "colorlabel.h"
79 #include "tags.h"
80 #include "textview.h"
81 #include "imap.h"
82 #include "socket.h"
83 #include "printing.h"
84 #ifdef G_OS_WIN32
85 #include "w32lib.h"
86 #endif
87
88 #define AC_LABEL_WIDTH  240
89
90 /* list of all instantiated MainWindow */
91 static GList *mainwin_list = NULL;
92
93 static GdkCursor *watch_cursor = NULL;
94 static GdkCursor *hand_cursor = NULL;
95
96 static gint iconified_count = 0;
97
98 static void main_window_menu_callback_block     (MainWindow     *mainwin);
99 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
100
101 static void main_window_show_cur_account        (MainWindow     *mainwin);
102 #ifndef GENERIC_UMPC
103 static void main_window_separation_change       (MainWindow     *mainwin,
104                                                  LayoutType      layout_mode);
105 #endif
106 static void main_window_set_widgets             (MainWindow     *mainwin,
107                                                  LayoutType      layout_mode);
108
109 static void toolbar_child_attached              (GtkWidget      *widget,
110                                                  GtkWidget      *child,
111                                                  gpointer        data);
112 static void toolbar_child_detached              (GtkWidget      *widget,
113                                                  GtkWidget      *child,
114                                                  gpointer        data);
115 #ifndef GENERIC_UMPC
116 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
117                                                  GdkEventButton *event,
118                                                  gpointer        data);
119 #endif
120 static gint main_window_close_cb                (GtkWidget      *widget,
121                                                  GdkEventAny    *event,
122                                                  gpointer        data);
123
124 static void main_window_size_allocate_cb        (GtkWidget      *widget,
125                                                  GtkAllocation  *allocation,
126                                                  gpointer        data);
127 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
128                                                  GtkAllocation  *allocation,
129                                                  gpointer        data);
130 static void message_window_size_allocate_cb     (GtkWidget      *widget,
131                                                  GtkAllocation  *allocation,
132                                                  gpointer        data);
133
134 static void update_folderview_cb (GtkAction     *action,
135                                   gpointer       data);
136 static void add_mailbox_cb       (GtkAction     *action,
137                                   gpointer       data);
138 static void foldersort_cb        (GtkAction     *action,
139                                   gpointer       data);
140 static void import_mbox_cb       (GtkAction     *action,
141                                   gpointer       data);
142 static void export_mbox_cb       (GtkAction     *action,
143                                   gpointer       data);
144 static void export_list_mbox_cb  (GtkAction     *action,
145                                   gpointer       data);
146 static void empty_trash_cb       (GtkAction     *action,
147                                   gpointer       data);
148 static void save_as_cb           (GtkAction     *action,
149                                   gpointer       data);
150 static void page_setup_cb        (GtkAction     *action,
151                                   gpointer       data);
152 static void print_cb             (GtkAction     *action,
153                                   gpointer       data);
154 static void app_exit_cb          (GtkAction     *action,
155                                   gpointer       data);
156
157
158 static void search_cb            (GtkAction     *action,
159                                   gpointer       data);
160 static void search_folder_cb     (GtkAction     *action,
161                                   gpointer       data);
162
163 static void toggle_message_cb    (GtkAction     *action,
164                                   gpointer       data);
165 static void toggle_toolbar_cb    (GtkAction *action, GtkRadioAction *current, gpointer data);
166 static void toggle_col_headers_cb(GtkAction     *action,
167                                   gpointer       data);
168 #ifndef GENERIC_UMPC
169 static void toggle_statusbar_cb  (GtkAction     *action,
170                                   gpointer       data);
171 static void set_layout_cb        (GtkAction *action, GtkRadioAction *current, gpointer data);
172 #endif
173 static void addressbook_open_cb (GtkAction      *action,
174                                   gpointer       data);
175 static void log_window_show_cb  (GtkAction      *action,
176                                   gpointer       data);
177 static void filtering_debug_window_show_cb      (GtkAction      *action,
178                                   gpointer       data);
179
180 static void inc_cancel_cb               (GtkAction      *action,
181                                   gpointer       data);
182
183 static void open_msg_cb                 (GtkAction      *action,
184                                   gpointer       data);
185
186 static void view_source_cb              (GtkAction      *action,
187                                   gpointer       data);
188
189 static void show_all_header_cb          (GtkAction      *action,
190                                   gpointer       data);
191 static void toggle_fullscreen_cb        (GtkAction      *action,
192                                   gpointer       data);
193
194 static void hide_quotes_cb(GtkAction    *action,
195                                   gpointer       data);
196
197 static void move_to_cb                  (GtkAction      *action,
198                                   gpointer       data);
199 static void copy_to_cb                  (GtkAction      *action,
200                                   gpointer       data);
201 static void delete_cb                   (GtkAction      *action,
202                                   gpointer       data);
203 static void delete_trash_cb                     (GtkAction      *action,
204                                   gpointer       data);
205
206 static void cancel_cb                   (GtkAction      *action,
207                                   gpointer       data);
208
209 static void mark_cb                     (GtkAction      *action,
210                                   gpointer       data);
211 static void unmark_cb                   (GtkAction      *action,
212                                   gpointer       data);
213
214 static void mark_as_unread_cb           (GtkAction      *action,
215                                   gpointer       data);
216 static void mark_as_read_cb             (GtkAction      *action,
217                                   gpointer       data);
218 static void mark_all_read_cb            (GtkAction      *action,
219                                   gpointer       data);
220 static void mark_as_spam_cb             (GtkAction      *action,
221                                   gpointer       data);
222 static void mark_as_ham_cb              (GtkAction      *action,
223                                   gpointer       data);
224
225 static void ignore_thread_cb            (GtkAction      *action,
226                                   gpointer       data);
227 static void unignore_thread_cb          (GtkAction      *action,
228                                   gpointer       data);
229 static void watch_thread_cb             (GtkAction      *action,
230                                   gpointer       data);
231 static void unwatch_thread_cb           (GtkAction      *action,
232                                   gpointer       data);
233 static void lock_msgs_cb                (GtkAction      *action,
234                                   gpointer       data);
235 static void unlock_msgs_cb              (GtkAction      *action,
236                                   gpointer       data);
237
238 static void reedit_cb                   (GtkAction      *action,
239                                   gpointer       data);
240
241 static void add_address_cb              (GtkAction      *action,
242                                   gpointer       data);
243
244 static void set_charset_cb              (GtkAction *action, GtkRadioAction *current, gpointer data);
245
246 static void set_decode_cb               (GtkAction *action, GtkRadioAction *current, gpointer data);
247
248 static void hide_read_messages   (GtkAction     *action,
249                                   gpointer       data);
250 static void hide_read_threads   (GtkAction      *action,
251                                   gpointer       data);
252 static void hide_del_messages   (GtkAction      *action,
253                                   gpointer       data);
254
255 static void thread_cb            (GtkAction     *action,
256                                   gpointer       data);
257 static void expand_threads_cb    (GtkAction     *action,
258                                   gpointer       data);
259 static void collapse_threads_cb  (GtkAction     *action,
260                                   gpointer       data);
261
262 static void set_summary_display_item_cb  (GtkAction     *action,
263                                   gpointer       data);
264 static void set_folder_display_item_cb   (GtkAction     *action,
265                                   gpointer       data);
266 static void sort_summary_cb      (GtkAction *action, GtkRadioAction *current, gpointer data);
267 static void sort_summary_type_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
268 static void attract_by_subject_cb(GtkAction     *action,
269                                   gpointer       data);
270
271 static void delete_duplicated_cb (GtkAction     *action,
272                                   gpointer       data);
273 static void delete_duplicated_all_cb (GtkAction *action,
274                                   gpointer       data);
275 static void filter_cb            (GtkAction     *action,
276                                   gpointer       data);
277 static void filter_list_cb       (GtkAction     *action,
278                                   gpointer       data);
279 static void process_cb           (GtkAction     *action,
280                                   gpointer       data);
281 static void execute_summary_cb   (GtkAction     *action,
282                                   gpointer       data);
283 static void expunge_summary_cb   (GtkAction     *action,
284                                   gpointer       data);
285 static void update_summary_cb    (GtkAction     *action,
286                                   gpointer       data);
287
288 static void prev_cb              (GtkAction     *action,
289                                   gpointer       data);
290 static void next_cb              (GtkAction     *action,
291                                   gpointer       data);
292 static void next_unread_cb       (GtkAction     *action,
293                                   gpointer       data);
294 static void prev_unread_cb       (GtkAction     *action,
295                                   gpointer       data);
296
297 static void prev_new_cb          (GtkAction     *action,
298                                   gpointer       data);
299 static void next_new_cb          (GtkAction     *action,
300                                   gpointer       data);
301 static void prev_marked_cb       (GtkAction     *action,
302                                   gpointer       data);
303 static void next_marked_cb       (GtkAction     *action,
304                                   gpointer       data);
305 static void prev_labeled_cb      (GtkAction     *action,
306                                   gpointer       data);
307 static void next_labeled_cb      (GtkAction     *action,
308                                   gpointer       data);
309 static void prev_history_cb      (GtkAction     *action,
310                                   gpointer       data);
311 static void next_history_cb      (GtkAction     *action,
312                                   gpointer       data);
313 static void parent_cb            (GtkAction     *action,
314                                   gpointer       data);
315
316 static void goto_folder_cb       (GtkAction     *action,
317                                   gpointer       data);
318 static void goto_unread_folder_cb(GtkAction     *action,
319                                   gpointer       data);
320
321 static void scroll_prev_line_cb  (GtkAction      *action,
322                                   gpointer        data);
323 static void scroll_next_line_cb  (GtkAction      *action,
324                                   gpointer        data);
325 static void scroll_prev_page_cb  (GtkAction      *action,
326                                   gpointer        data);
327 static void scroll_next_page_cb  (GtkAction      *action,
328                                   gpointer        data);
329
330 static void copy_cb              (GtkAction     *action,
331                                   gpointer       data);
332 static void allsel_cb            (GtkAction     *action,
333                                   gpointer       data);
334 static void select_thread_cb     (GtkAction     *action,
335                                   gpointer       data);
336 static void delete_thread_cb     (GtkAction     *action,
337                                   gpointer       data);
338
339 static void create_filter_cb     (GtkAction     *action,
340                                   gpointer       data);
341 static void create_processing_cb (GtkAction     *action,
342                                   gpointer       data);
343 static void open_urls_cb         (GtkAction     *action,
344                                   gpointer       data);
345
346 static void prefs_template_open_cb      (GtkAction      *action,
347                                   gpointer       data);
348 static void prefs_actions_open_cb       (GtkAction      *action,
349                                   gpointer       data);
350 static void prefs_tags_open_cb          (GtkAction      *action,
351                                   gpointer       data);
352 static void prefs_account_open_cb       (GtkAction      *action,
353                                   gpointer       data);
354
355 static void prefs_pre_processing_open_cb  (GtkAction    *action,
356                                   gpointer       data);
357
358 static void prefs_post_processing_open_cb (GtkAction    *action,
359                                   gpointer       data);
360
361 static void prefs_filtering_open_cb     (GtkAction      *action,
362                                   gpointer       data);
363 #ifdef USE_GNUTLS
364 static void ssl_manager_open_cb         (GtkAction      *action,
365                                   gpointer       data);
366 #endif
367 static void new_account_cb       (GtkAction     *action,
368                                   gpointer       data);
369
370 static void account_selector_menu_cb     (GtkMenuItem   *menuitem,
371                                           gpointer       data);
372 static void account_receive_menu_cb      (GtkMenuItem   *menuitem,
373                                           gpointer       data);
374 #ifndef GENERIC_UMPC
375 static void account_compose_menu_cb      (GtkMenuItem   *menuitem,
376                                           gpointer       data);
377 #endif
378 static void prefs_open_cb       (GtkAction      *action,
379                                   gpointer       data);
380 static void plugins_open_cb     (GtkAction      *action,
381                                   gpointer       data);
382
383 static void online_switch_clicked(GtkButton     *btn, 
384                                   gpointer data);
385
386 static void manual_open_cb       (GtkAction     *action,
387                                   gpointer       data);
388 static void manual_faq_open_cb   (GtkAction     *action,
389                                   gpointer       data);
390
391 static void legend_open_cb       (GtkAction     *action,
392                                   gpointer       data);
393
394 #ifdef G_OS_WIN32
395 static void set_default_client_cb (GtkAction    *action,
396                                   gpointer       data);
397 #endif
398
399 static void scan_tree_func       (Folder        *folder,
400                                   FolderItem    *item,
401                                   gpointer       data);
402                                   
403 static void toggle_work_offline_cb(GtkAction    *action,
404                                   gpointer       data);
405
406 static void addr_harvest_cb      ( GtkAction    *action,
407                                   gpointer       data );
408
409 static void addr_harvest_msg_cb  ( GtkAction    *action,
410                                   gpointer       data );
411 static void sync_cb              ( GtkAction    *action,
412                                   gpointer       data );
413
414 static void forget_session_passwords_cb (GtkAction      *action,
415                                          gpointer        data );
416
417 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
418                                                  GdkEventFocus  *focus,
419                                                  gpointer        data);
420 static gboolean mainwindow_visibility_event_cb  (GtkWidget      *widget, 
421                                                  GdkEventVisibility     *state,
422                                                  gpointer        data);
423 static gboolean mainwindow_state_event_cb       (GtkWidget      *widget, 
424                                                  GdkEventWindowState    *state,
425                                                  gpointer        data);
426 static void main_window_reply_cb                        (GtkAction      *action,
427                                   gpointer       data);
428 static gboolean mainwindow_progressindicator_hook       (gpointer        source,
429                                                  gpointer        userdata);
430
431 static gint mailing_list_create_submenu(MainWindow *mainwindow,
432                                        MsgInfo *msginfo);
433
434 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
435         
436 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
437
438 static void mailing_list_compose(GtkWidget *w, gpointer *data);
439  
440 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
441 #define  SEPARATE_ACTION 500 
442 static void mainwindow_quicksearch              (GtkAction      *action,
443                                   gpointer       data);
444 static gboolean any_folder_want_synchronise(void);
445
446 #define DO_ACTION(name, act)    { if (!strcmp(a_name, name)) action = act; }
447
448 static void mainwindow_nothing_cb          (GtkAction *action, gpointer data)
449 {
450
451 }
452
453 static void about_cb(GtkAction *gaction, gpointer data)
454 {
455         about_show();
456 }
457
458 static void     mw_inc_mail_cb                  (GtkAction *gaction, gpointer data)
459 {
460         inc_mail_cb(data, 0, NULL);
461 }
462 static void     mw_inc_all_account_mail_cb              (GtkAction *gaction, gpointer data)
463 {
464         inc_all_account_mail_cb(data, 0, NULL);
465 }
466 static void     mw_send_queue_cb                        (GtkAction *gaction, gpointer data)
467 {
468         send_queue_cb(data, 0, NULL);
469 }
470 static void     mw_compose_mail_cb                      (GtkAction *gaction, gpointer data)
471 {
472         compose_mail_cb(data, 0, NULL);
473 }
474 static void     mw_compose_news_cb                      (GtkAction *gaction, gpointer data)
475 {
476         compose_news_cb(data, 0, NULL);
477 }
478
479 static GtkActionEntry mainwin_entries[] =
480 {
481         {"Menu",                                NULL, "Menu" },
482 /* menus */
483         {"File",                                NULL, N_("_File") },
484         {"Edit",                                NULL, N_("_Edit") },
485         {"View",                                NULL, N_("_View") },
486         {"Message",                             NULL, N_("_Message") },
487         {"Tools",                               NULL, N_("_Tools") },
488         {"Configuration",                       NULL, N_("_Configuration") },
489         {"Help",                                NULL, N_("_Help") },
490
491 /* File menu */
492         {"File/AddMailbox",                     NULL, N_("_Add mailbox") },
493         {"File/AddMailbox/MH",                  NULL, N_("MH..."), NULL, NULL, G_CALLBACK(add_mailbox_cb) },
494         {"File/---",                            NULL, "---" },
495
496         {"File/SortMailboxes",                  NULL, N_("Change mailbox order..."), NULL, NULL, G_CALLBACK(foldersort_cb) },
497
498         /* {"File/---",                         NULL, "---" }, */
499         {"File/ImportMbox",                     NULL, N_("_Import mbox file..."), NULL, NULL, G_CALLBACK(import_mbox_cb) },
500         {"File/ExportMbox",                     NULL, N_("_Export to mbox file..."), NULL, NULL, G_CALLBACK(export_mbox_cb) },
501         {"File/ExportSelMbox",                  NULL, N_("_Export selected to mbox file..."), NULL, NULL, G_CALLBACK(export_list_mbox_cb) },
502         /* {"File/---",                         NULL, "---" }, */
503         {"File/EmptyTrashes",                   NULL, N_("Empty all _Trash folders"), "<shift>D", NULL, G_CALLBACK(empty_trash_cb) },
504         /* {"File/---",                         NULL, "---" }, */
505
506         {"File/SaveAs",                         NULL, N_("_Save as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
507
508         {"File/PageSetup",                      NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
509         {"File/Print",                          NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
510         /* {"File/---",                         NULL, "---" }, */
511         {"File/SynchroniseFolders",             NULL, N_("Synchronise folders"), "<control><shift>S", NULL, G_CALLBACK(sync_cb) }, 
512         /* {"File/---",                         NULL, "---" }, */
513         {"File/Exit",                           NULL, N_("E_xit"), "<control>Q", NULL, G_CALLBACK(app_exit_cb) }, 
514
515 /* Edit menu */
516         {"Edit/Copy",                           NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(copy_cb) }, 
517         {"Edit/SelectAll",                      NULL, N_("Select _all"), "<control>A", NULL, G_CALLBACK(allsel_cb) }, 
518         {"Edit/SelectThread",                   NULL, N_("Select _thread"), NULL, NULL, G_CALLBACK(select_thread_cb) }, 
519         {"Edit/DeleteThread",                   NULL, N_("_Delete thread"), NULL, NULL, G_CALLBACK(delete_thread_cb) }, 
520         {"Edit/---",                            NULL, "---" },
521         {"Edit/Find",                           NULL, N_("_Find in current message..."), "<control>F", NULL, G_CALLBACK(search_cb) },
522         {"Edit/SearchFolder",                   NULL, N_("_Search folder..."), "<shift><control>F", NULL, G_CALLBACK(search_folder_cb) },
523         {"Edit/QuickSearch",                    NULL, N_("_Quick search"), "slash", NULL, G_CALLBACK(mainwindow_quicksearch) },
524
525 /* View menu */
526         {"View/ShowHide",                       NULL, N_("Show or hi_de") },
527         {"View/ShowHide/Toolbar",               NULL, N_("_Toolbar") },
528
529         {"View/SetColumns",                     NULL, N_("Set displayed _columns") },
530         {"View/SetColumns/Folderlist",          NULL, N_("in _Folder list..."), NULL, NULL, G_CALLBACK(set_folder_display_item_cb) },
531         {"View/SetColumns/Messagelist",         NULL, N_("in _Message list..."), NULL, NULL, G_CALLBACK(set_summary_display_item_cb) },
532         {"View/---",                            NULL, "---" },
533
534
535 #ifndef GENERIC_UMPC
536         {"View/Layout",                         NULL, N_("La_yout") },
537
538 #endif
539         {"View/Sort",                           NULL, N_("_Sort") },
540         {"View/Sort/---",                       NULL, "---" }, 
541         {"View/Sort/AttractSubj",               NULL, N_("_Attract by subject"), NULL, NULL, G_CALLBACK(attract_by_subject_cb) }, 
542
543         {"View/ExpandThreads",                  NULL, N_("E_xpand all threads"), NULL, NULL, G_CALLBACK(expand_threads_cb) }, 
544         {"View/CollapseThreads",                NULL, N_("Co_llapse all threads"), NULL, NULL, G_CALLBACK(collapse_threads_cb) }, 
545
546         {"View/Goto",                           NULL, N_("_Go to") },
547         {"View/Goto/Prev",                      NULL, N_("_Previous message"), "P", NULL, G_CALLBACK(prev_cb) },
548         {"View/Goto/Next",                      NULL, N_("_Next message"), "N", NULL, G_CALLBACK(next_cb) },
549         {"View/Goto/---",                       NULL, "---", NULL, NULL, NULL },
550         {"View/Goto/PrevUnread",                NULL, N_("P_revious unread message"), "<shift>P", NULL, G_CALLBACK(prev_unread_cb) },
551         {"View/Goto/NextUnread",                NULL, N_("N_ext unread message"), "<shift>N", NULL, G_CALLBACK(next_unread_cb) },
552         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
553         {"View/Goto/PrevNew",                   NULL, N_("Previous ne_w message"), NULL, NULL, G_CALLBACK(prev_new_cb) },
554         {"View/Goto/NextNew",                   NULL, N_("Ne_xt new message"), NULL, NULL, G_CALLBACK(next_new_cb) },
555         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
556         {"View/Goto/PrevMarked",                NULL, N_("Previous _marked message"), NULL, NULL, G_CALLBACK(prev_marked_cb) },
557         {"View/Goto/NextMarked",                NULL, N_("Next m_arked message"), NULL, NULL, G_CALLBACK(next_marked_cb) },
558         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
559         {"View/Goto/PrevLabeled",               NULL, N_("Previous _labeled message"), NULL, NULL, G_CALLBACK(prev_labeled_cb) },
560         {"View/Goto/NextLabeled",               NULL, N_("Next la_beled message"), NULL, NULL, G_CALLBACK(next_labeled_cb) },
561         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
562         {"View/Goto/PrevHistory",               NULL, N_("Previous opened message"), "<alt>Left", NULL, G_CALLBACK(prev_history_cb) },
563         {"View/Goto/NextHistory",               NULL, N_("Next opened message"), "<alt>Right", NULL, G_CALLBACK(next_history_cb) },
564         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
565         {"View/Goto/ParentMessage",             NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
566         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
567         {"View/Goto/NextUnreadFolder",          NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
568         {"View/Goto/OtherFolder",               NULL, N_("_Other folder..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
569
570         /* {"View/Scroll/---",                  NULL, "---", NULL, NULL, NULL }, */
571         {"View/Scroll",                         NULL, N_("Message scroll") },
572         {"View/Scroll/PrevLine",                NULL, N_("Previous line"), NULL, NULL, G_CALLBACK(scroll_prev_line_cb) },
573         {"View/Scroll/NextLine",                NULL, N_("Next line"), NULL, NULL, G_CALLBACK(scroll_next_line_cb) },
574         {"View/Scroll/PrevPage",                NULL, N_("Previous page"), NULL, NULL, G_CALLBACK(scroll_prev_page_cb) },
575         {"View/Scroll/NextPage",                NULL, N_("Next page"), NULL, NULL, G_CALLBACK(scroll_next_page_cb) },
576
577         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
578         {"View/Encoding",                       NULL, N_("Character _encoding") }, /* set_charset_cb */
579         {"View/Encoding/---",                   NULL, "---" },
580 #define ENC_ACTION(cs_char,c_char,string) \
581         { "View/Encoding/" cs_char, NULL, N_(string), NULL, NULL, c_char }
582
583         {"View/Encoding/Western",               NULL, N_("Western European") },
584         {"View/Encoding/Baltic",                NULL, N_("Baltic") },
585         {"View/Encoding/Hebrew",                NULL, N_("Hebrew") },
586         {"View/Encoding/Arabic",                NULL, N_("Arabic") },
587         {"View/Encoding/Cyrillic",              NULL, N_("Cyrillic") },
588         {"View/Encoding/Japanese",              NULL, N_("Japanese") },
589         {"View/Encoding/Chinese",               NULL, N_("Chinese") },
590         {"View/Encoding/Korean",                NULL, N_("Korean") },
591         {"View/Encoding/Thai",                  NULL, N_("Thai") },
592
593         {"View/Decode",                         NULL, N_("Decode") }, /* set_decode_cb */
594         {"View/Decode/---",                     NULL, "---" },
595
596 #define DEC_ACTION(cs_type,c_type,string) \
597         { "View/Decode/" cs_type, NULL, N_(string), NULL, NULL, c_type }
598
599         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
600         {"View/OpenNewWindow",                  NULL, N_("Open in new _window"), "<control><alt>N", NULL, G_CALLBACK(open_msg_cb) },
601         {"View/MessageSource",                  NULL, N_("Mess_age source"), "<control>U", NULL, G_CALLBACK(view_source_cb) },
602         {"View/Quotes",                         NULL, N_("Quotes") }, 
603         /* {"View/---",                         NULL, "---", NULL, NULL, NULL }, */
604         {"View/UpdateSummary",                  NULL, N_("_Update summary"), "<control><alt>U", NULL, G_CALLBACK(update_summary_cb) },
605
606 /* Message menu */
607         {"Message/Receive",                     NULL, N_("Recei_ve") },
608         {"Message/Receive/CurrentAccount",      NULL, N_("Get from _current account"), "<control>I", NULL, G_CALLBACK(mw_inc_mail_cb) },
609         {"Message/Receive/AllAccounts",         NULL, N_("Get from _all accounts"), "<shift><control>I", NULL, G_CALLBACK(mw_inc_all_account_mail_cb) },
610         {"Message/Receive/CancelReceiving",     NULL, N_("Cancel receivin_g"), NULL, NULL, G_CALLBACK(inc_cancel_cb) },
611         {"Message/Receive/---",                 NULL, "---" },
612         {"Message/Receive/PlaceHolder",         NULL, "PlaceHolder,", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
613         {"Message/SendQueue",                   NULL, N_("_Send queued messages"), NULL, NULL, G_CALLBACK(mw_send_queue_cb) },
614
615         {"Message/---",                         NULL, "---" },
616
617         {"Message/ComposeEmail",                NULL, N_("Compose a_n email message"), "<control>M", NULL, G_CALLBACK(mw_compose_mail_cb) },
618         {"Message/ComposeNews",                 NULL, N_("Compose a news message"), NULL, NULL, G_CALLBACK(mw_compose_news_cb) },
619
620         {"Message/Reply",                       NULL, N_("_Reply"), "<control>R", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY */
621         {"Message/ReplyTo",                     NULL, N_("Repl_y to") }, 
622         {"Message/ReplyTo/All",                 NULL, N_("_all"), "<control><shift>R", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_ALL */
623         {"Message/ReplyTo/Sender",              NULL, N_("_sender"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_SENDER */
624         {"Message/ReplyTo/List",                NULL, N_("mailing _list"), "<control>L", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REPLY_TO_LIST */
625         {"Message/FollowupReply",               NULL, N_("Follow-up and reply to"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FOLLOWUP_AND_REPLY_TO */
626         /*{"Message/---",                       NULL, "---" },*/
627
628         {"Message/Forward",                     NULL, N_("_Forward"), "<control><alt>F", NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FORWARD_INLINE */
629         {"Message/ForwardAtt",                  NULL, N_("For_ward as attachment"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_FORWARD_AS_ATTACH */
630         {"Message/Redirect",                    NULL, N_("Redirec_t"), NULL, NULL, G_CALLBACK(main_window_reply_cb) }, /* COMPOSE_REDIRECT */
631
632         {"Message/MailingList",                 NULL, N_("Mailing-_List") }, 
633         {"Message/MailingList/Post",            NULL, N_("Post") }, 
634         {"Message/MailingList/Post/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
635         {"Message/MailingList/Help",            NULL, N_("Help") }, 
636         {"Message/MailingList/Help/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
637         {"Message/MailingList/Subscribe",       NULL, N_("Subscribe") }, 
638         {"Message/MailingList/Subscribe/PlaceHolder",   NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
639         {"Message/MailingList/Unsubscribe",     NULL, N_("Unsubscribe") }, 
640         {"Message/MailingList/Unsubscribe/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
641         {"Message/MailingList/ViewArchive",     NULL, N_("View archive") }, 
642         {"Message/MailingList/ViewArchive/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
643         {"Message/MailingList/ContactOwner",    NULL, N_("Contact owner") }, 
644         {"Message/MailingList/ContactOwner/PlaceHolder",        NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
645         /*{"Message/---",                       NULL, "---" },*/
646
647         {"Message/Move",                        NULL, N_("M_ove..."), "<control>O", NULL, G_CALLBACK(move_to_cb) },
648         {"Message/Copy",                        NULL, N_("_Copy..."), "<shift><control>O", NULL, G_CALLBACK(copy_to_cb) },
649         {"Message/Trash",                       NULL, N_("Move to _trash"), "<control>D", NULL, G_CALLBACK(delete_trash_cb) },
650         {"Message/Delete",                      NULL, N_("_Delete..."), NULL, NULL, G_CALLBACK(delete_cb) },
651         {"Message/CancelNews",                  NULL, N_("Cancel a news message"), NULL, NULL, G_CALLBACK(cancel_cb) },
652         /*{"Message/---",                       NULL, "---" },*/
653         
654         {"Message/Mark",                        NULL, N_("_Mark") },
655         {"Message/Mark/Mark",                   NULL, N_("_Mark"), "<shift>asterisk", NULL, G_CALLBACK(mark_cb) },
656         {"Message/Mark/Unmark",                 NULL, N_("_Unmark"), "U", NULL, G_CALLBACK(unmark_cb) },
657         {"Message/Mark/---",                    NULL, "---", NULL, NULL, NULL },
658
659         {"Message/Mark/MarkUnread",             NULL, N_("Mark as unr_ead"), "<shift>exclam", NULL, G_CALLBACK(mark_as_unread_cb) },
660         {"Message/Mark/MarkRead",               NULL, N_("Mark as rea_d"), NULL, NULL, G_CALLBACK(mark_as_read_cb) },
661         {"Message/Mark/MarkAllRead",            NULL, N_("Mark all read"), NULL, NULL, G_CALLBACK(mark_all_read_cb) },
662         {"Message/Mark/IgnoreThread",           NULL, N_("Ignore thread"), NULL, NULL, G_CALLBACK(ignore_thread_cb) },
663         {"Message/Mark/UnignoreThread",         NULL, N_("Unignore thread"), NULL, NULL, G_CALLBACK(unignore_thread_cb) },
664         {"Message/Mark/WatchThread",            NULL, N_("Watch thread"), NULL, NULL, G_CALLBACK(watch_thread_cb) },
665         {"Message/Mark/UnwatchThread",          NULL, N_("Unwatch thread"), NULL, NULL, G_CALLBACK(unwatch_thread_cb) },
666         /* separation */
667
668         {"Message/Mark/MarkSpam",               NULL, N_("Mark as _spam"), NULL, NULL, G_CALLBACK(mark_as_spam_cb) },
669         {"Message/Mark/MarkHam",                NULL, N_("Mark as _ham"), NULL, NULL, G_CALLBACK(mark_as_ham_cb) },
670         /* separation */
671
672         {"Message/Mark/Lock",                   NULL, N_("Lock"), NULL, NULL, G_CALLBACK(lock_msgs_cb) },
673         {"Message/Mark/Unlock",                 NULL, N_("Unlock"), NULL, NULL, G_CALLBACK(unlock_msgs_cb) },
674
675         {"Message/ColorLabel",                  NULL, N_("Color la_bel") },
676         {"Message/Tags",                        NULL, N_("Ta_gs") },
677         /*{"Message/---",                       NULL, "---" },*/
678
679         {"Message/Reedit",                      NULL, N_("Re-_edit"), NULL, NULL, G_CALLBACK(reedit_cb) },
680
681 /* Tools menu */
682
683         {"Tools/AddressBook",                   NULL, N_("_Address book"), "<control><shift>A", NULL, G_CALLBACK(addressbook_open_cb) }, 
684         {"Tools/AddSenderToAB",                 NULL, N_("Add sender to address boo_k"), NULL, NULL, G_CALLBACK(add_address_cb) }, 
685
686         {"Tools/CollectAddresses",              NULL, N_("C_ollect addresses") }, 
687         {"Tools/CollectAddresses/FromFolder",   NULL, N_("from Current _folder..."), NULL, NULL, G_CALLBACK(addr_harvest_cb) }, 
688         {"Tools/CollectAddresses/FromSelected", NULL, N_("from Selected _messages..."), NULL, NULL, G_CALLBACK(addr_harvest_msg_cb) }, 
689         {"Tools/---",                           NULL, "---", NULL, NULL, NULL },
690
691         {"Tools/FilterFolder",                  NULL, N_("_Filter all messages in folder"), NULL, NULL, G_CALLBACK(filter_cb) }, 
692         {"Tools/FilterSelected",                NULL, N_("Filter _selected messages"), NULL, NULL, G_CALLBACK(filter_list_cb) }, 
693         {"Tools/RunProcessing",                 NULL, N_("Run folder pr_ocessing rules"), NULL, NULL, G_CALLBACK(process_cb) }, 
694
695         {"Tools/CreateFilterRule",              NULL, N_("_Create filter rule") },
696         {"Tools/CreateFilterRule/Automatically",NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_AUTO */
697         {"Tools/CreateFilterRule/ByFrom",       NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_FROM */
698         {"Tools/CreateFilterRule/ByTo",         NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_TO     */
699         {"Tools/CreateFilterRule/BySubject",    NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_SUBJECT */
700
701         {"Tools/CreateProcessingRule",          NULL, N_("Create processing rule") },
702         {"Tools/CreateProcessingRule/Automatically",    NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
703         {"Tools/CreateProcessingRule/ByFrom",   NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
704         {"Tools/CreateProcessingRule/ByTo",     NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
705         {"Tools/CreateProcessingRule/BySubject",NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
706         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
707
708         {"Tools/ListUrls",                      NULL, N_("List _URLs..."), "<control><shift>U", NULL, G_CALLBACK(open_urls_cb) }, 
709
710         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
711         {"Tools/Actions",                       NULL, N_("Actio_ns") },
712         {"Tools/Actions/PlaceHolder",           NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
713         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
714
715         {"Tools/CheckNewMessages",              NULL, N_("Ch_eck for new messages in all folders"), NULL, NULL, G_CALLBACK(update_folderview_cb) }, 
716         {"Tools/DeleteDuplicates",              NULL, N_("Delete du_plicated messages") },
717         {"Tools/DeleteDuplicates/SelFolder",    NULL, N_("In selected folder"), NULL, NULL, G_CALLBACK(delete_duplicated_cb) },
718         {"Tools/DeleteDuplicates/AllFolders",   NULL, N_("In all folders"), NULL, NULL, G_CALLBACK(delete_duplicated_all_cb) },
719         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
720
721         {"Tools/Execute",                       NULL, N_("E_xecute"), "X", NULL, G_CALLBACK(execute_summary_cb) }, 
722         {"Tools/Expunge",                       NULL, N_("Exp_unge"), "<control>E", NULL, G_CALLBACK(expunge_summary_cb) }, 
723 #ifdef USE_GNUTLS
724         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
725         {"Tools/SSLCertificates",               NULL, N_("SSL cer_tificates"), NULL, NULL, G_CALLBACK(ssl_manager_open_cb) }, 
726 #endif
727         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
728 #ifndef G_OS_WIN32
729         {"Tools/FilteringLog",                  NULL, N_("Filtering Lo_g"), NULL, NULL, G_CALLBACK(filtering_debug_window_show_cb) }, 
730 #endif
731         {"Tools/NetworkLog",                    NULL, N_("Network _Log"), "<shift><control>L", NULL, G_CALLBACK(log_window_show_cb) }, 
732         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
733         {"Tools/ForgetSessionPasswords",                NULL, N_("_Forget all session passwords"), NULL, NULL, G_CALLBACK(forget_session_passwords_cb) }, 
734
735 /* Configuration menu */        
736         {"Configuration/ChangeAccount",         NULL, N_("C_hange current account") },
737         {"Configuration/ChangeAccount/PlaceHolder",     NULL, "Placeholder", NULL, NULL, G_CALLBACK(mainwindow_nothing_cb) },
738         {"Configuration/AccountPrefs",          NULL, N_("_Preferences for current account..."), NULL, NULL, G_CALLBACK(prefs_account_open_cb) },
739         {"Configuration/CreateAccount",         NULL, N_("Create _new account..."), NULL, NULL, G_CALLBACK(new_account_cb) },
740         {"Configuration/EditAccounts",          NULL, N_("_Edit accounts..."), NULL, NULL, G_CALLBACK(account_edit_open) },
741         {"Configuration/---",                   NULL, "---", NULL, NULL, NULL }, 
742
743         {"Configuration/Preferences",           NULL, N_("P_references..."), NULL, NULL, G_CALLBACK(prefs_open_cb) },
744         {"Configuration/PreProcessing",         NULL, N_("Pre-pr_ocessing..."), NULL, NULL, G_CALLBACK(prefs_pre_processing_open_cb) },
745         {"Configuration/PostProcessing",        NULL, N_("Post-pro_cessing..."), NULL, NULL, G_CALLBACK(prefs_post_processing_open_cb) },
746         {"Configuration/Filtering",             NULL, N_("_Filtering..."), NULL, NULL, G_CALLBACK(prefs_filtering_open_cb) },
747         {"Configuration/Templates",             NULL, N_("_Templates..."), NULL, NULL, G_CALLBACK(prefs_template_open_cb) },
748         {"Configuration/Actions",               NULL, N_("_Actions..."), NULL, NULL, G_CALLBACK(prefs_actions_open_cb) },
749         {"Configuration/Tags",                  NULL, N_("Tag_s..."), NULL, NULL, G_CALLBACK(prefs_tags_open_cb) },
750         /*{"Configuration/---",                 NULL, "---", NULL, NULL, NULL }, */
751         {"Configuration/Plugins",               NULL, N_("Plu_gins..."), NULL, NULL, G_CALLBACK(plugins_open_cb) },
752
753 /* Help menu */
754         {"Help/Manual",                         NULL, N_("_Manual"), NULL, NULL, G_CALLBACK(manual_open_cb) }, 
755         {"Help/FAQ",                            NULL, N_("_Online User-contributed FAQ"), NULL, NULL, G_CALLBACK(manual_faq_open_cb) }, 
756         {"Help/IconLegend",                     NULL, N_("Icon _Legend"), NULL, NULL, G_CALLBACK(legend_open_cb) }, 
757 #ifdef G_OS_WIN32
758         {"Help/SetDefault",                     NULL, N_("Set as default client"), NULL, NULL, G_CALLBACK(set_default_client_cb) }, 
759 #endif
760         {"Help/---",                            NULL, "---" }, 
761         {"Help/About",                          NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_cb) }, 
762 };
763
764 static GtkToggleActionEntry mainwin_toggle_entries[] = {
765         {"File/OfflineMode",                    NULL, N_("Offline _mode"), "<control>W", NULL, G_CALLBACK(toggle_work_offline_cb) }, /*toggle*/
766         {"View/ShowHide/MessageView",           NULL, N_("_Message view"), "V", NULL, G_CALLBACK(toggle_message_cb) }, /* toggle */
767 #ifndef GENERIC_UMPC
768         {"View/ShowHide/StatusBar",             NULL, N_("Status _bar"), NULL, NULL, G_CALLBACK(toggle_statusbar_cb) }, /* toggle */
769 #endif
770         {"View/ShowHide/ColumnHeaders",         NULL, N_("Column headers"), NULL, NULL, G_CALLBACK(toggle_col_headers_cb) }, /* toggle */
771         {"View/ThreadView",                     NULL, N_("Th_read view"), "<control>T", NULL, G_CALLBACK(thread_cb) }, /* toggle */
772         {"View/HideReadThreads",                NULL, N_("Hide read threads"), NULL, NULL, G_CALLBACK(hide_read_threads) }, /* toggle */
773         {"View/HideReadMessages",               NULL, N_("_Hide read messages"), NULL, NULL, G_CALLBACK(hide_read_messages) }, /* toggle */
774         {"View/HideDelMessages",                NULL, N_("Hide deleted messages"), NULL, NULL, G_CALLBACK(hide_del_messages) }, /* toggle */
775 #ifndef MAEMO
776         {"View/FullScreen",                     NULL, N_("_Fullscreen"), "F11", NULL, G_CALLBACK(toggle_fullscreen_cb) }, /* toggle */
777 #endif
778         {"View/AllHeaders",                     NULL, N_("Show all _headers"), "<control>H", NULL, G_CALLBACK(show_all_header_cb) }, /* toggle */
779         {"View/Quotes/CollapseAll",             NULL, N_("_Collapse all"), "<control><shift>Q", NULL, G_CALLBACK(hide_quotes_cb) }, /* 1 toggle */
780         {"View/Quotes/Collapse2",               NULL, N_("Collapse from level _2"), NULL, NULL, G_CALLBACK(hide_quotes_cb) }, /* 2 toggle */
781         {"View/Quotes/Collapse3",               NULL, N_("Collapse from level _3"), NULL, NULL, G_CALLBACK(hide_quotes_cb) }, /* 3 toggle */
782 };
783
784 static GtkRadioActionEntry mainwin_showhide_radio_entries[] = { /* toggle_toolbar_cb */
785         {"View/ShowHide/Toolbar/TextBelowIcon", NULL, N_("Text _below icons"), NULL, NULL, TOOLBAR_BOTH }, /* radio TOOLBAR_BOTH */
786         {"View/ShowHide/Toolbar/TextBesideIcon",NULL, N_("Text be_side icons"), NULL, NULL, TOOLBAR_BOTH_HORIZ }, /* radio TOOLBAR_BOTH_HORIZ */
787         {"View/ShowHide/Toolbar/IconOnly",      NULL, N_("_Icons only"), NULL, NULL, TOOLBAR_ICON }, /* radio TOOLBAR_ICON */
788         {"View/ShowHide/Toolbar/TextOnly",      NULL, N_("_Text only"), NULL, NULL, TOOLBAR_TEXT }, /* radio TOOLBAR_TEXT */
789 #ifndef GENERIC_UMPC
790         {"View/ShowHide/Toolbar/Hide",          NULL, N_("_Hide"), NULL, NULL, TOOLBAR_NONE }, /* radio TOOLBAR_NONE */
791 #endif
792 };
793 #ifndef GENERIC_UMPC
794 static GtkRadioActionEntry mainwin_layout_radio_entries[] = { /* set_layout_cb */
795         {"View/Layout/Standard",                NULL, N_("_Standard"), NULL, NULL, NORMAL_LAYOUT }, /* radio NORMAL_LAYOUT */
796         {"View/Layout/ThreeColumns",            NULL, N_("_Three columns"), NULL, NULL, VERTICAL_LAYOUT }, /* radio VERTICAL_LAYOUT */
797         {"View/Layout/WideMessage",             NULL, N_("_Wide message"), NULL, NULL, WIDE_LAYOUT }, /* radio WIDE_LAYOUT */
798         {"View/Layout/WideMessageList",         NULL, N_("W_ide message list"), NULL, NULL, WIDE_MSGLIST_LAYOUT }, /* radio WIDE_MSGLIST_LAYOUT */
799         {"View/Layout/SmallScreen",             NULL, N_("S_mall screen"), NULL, NULL, SMALL_LAYOUT }, /* radio SMALL_LAYOUT */
800 };
801 #endif
802 static GtkRadioActionEntry mainwin_sort_radio_entries[] = { /* sort_summary_cb */
803         {"View/Sort/Number",                    NULL, N_("by _Number"), NULL, NULL, SORT_BY_NUMBER }, /* radio SORT_BY_NUMBER */
804         {"View/Sort/Size",                      NULL, N_("by S_ize"), NULL, NULL, SORT_BY_SIZE }, /* radio SORT_BY_SIZE */
805         {"View/Sort/Date",                      NULL, N_("by _Date"), NULL, NULL, SORT_BY_DATE }, /* radio SORT_BY_DATE */
806         {"View/Sort/ThreadDate",                NULL, N_("by Thread date"), NULL, NULL, SORT_BY_THREAD_DATE }, /* radio SORT_BY_THREAD_DATE */
807         {"View/Sort/From",                      NULL, N_("by _From"), NULL, NULL, SORT_BY_FROM }, /* radio SORT_BY_FROM */
808         {"View/Sort/To",                        NULL, N_("by _To"), NULL, NULL, SORT_BY_TO }, /* radio SORT_BY_TO */
809         {"View/Sort/Subject",                   NULL, N_("by S_ubject"), NULL, NULL, SORT_BY_SUBJECT }, /* radio SORT_BY_SUBJECT */
810         {"View/Sort/Color",                     NULL, N_("by _Color label"), NULL, NULL, SORT_BY_LABEL }, /* radio SORT_BY_LABEL */
811         {"View/Sort/Tag",                       NULL, N_("by Tag"), NULL, NULL, SORT_BY_TAGS }, /* radio SORT_BY_TAGS */
812         {"View/Sort/Mark",                      NULL, N_("by _Mark"), NULL, NULL, SORT_BY_MARK }, /* radio SORT_BY_MARK */
813         {"View/Sort/Status",                    NULL, N_("by _Status"), NULL, NULL, SORT_BY_STATUS }, /* radio SORT_BY_STATUS */
814         {"View/Sort/Attachment",                NULL, N_("by A_ttachment"), NULL, NULL, SORT_BY_MIME }, /* radio SORT_BY_MIME */
815         {"View/Sort/Score",                     NULL, N_("by Score"), NULL, NULL, SORT_BY_SCORE }, /* radio SORT_BY_SCORE */
816         {"View/Sort/Locked",                    NULL, N_("by Locked"), NULL, NULL, SORT_BY_LOCKED }, /* radio SORT_BY_LOCKED */
817         {"View/Sort/DontSort",                  NULL, N_("D_on't sort"), NULL, NULL, SORT_BY_NONE }, /* radio SORT_BY_NONE */
818 };
819
820 static GtkRadioActionEntry mainwin_sorttype_radio_entries[] = { /* sort_summary_type_cb */
821         {"View/Sort/Ascending",                 NULL, N_("Ascending"), NULL, NULL, SORT_ASCENDING }, /* radio SORT_ASCENDING */
822         {"View/Sort/Descending",                NULL, N_("Descending"), NULL, NULL, SORT_DESCENDING }, /* radio SORT_DESCENDING */
823 };
824
825 static GtkRadioActionEntry mainwin_radio_enc_entries[] =
826 {
827         ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO set_charset_cb */
828         ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO set_charset_cb */
829         ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO set_charset_cb */
830         ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO set_charset_cb */
831         ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO set_charset_cb */
832         ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO set_charset_cb */
833         ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO set_charset_cb */
834         ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO set_charset_cb */
835         ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO set_charset_cb */
836         ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO set_charset_cb */
837         ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO set_charset_cb */
838         ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO set_charset_cb */
839         ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO set_charset_cb */
840         ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO set_charset_cb */
841         ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
842         ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
843         ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
844         ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
845         ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
846         ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
847         ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
848         ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
849         ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
850         ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
851         ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
852         ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
853         ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
854         ENC_ACTION("Chinese/"CS_EUC_TW, C_EUC_TW, "EUC-_TW"), /* RADIO set_charset_cb */
855         ENC_ACTION("Korean/"CS_EUC_KR, C_EUC_KR, "_EUC-KR"), /* RADIO set_charset_cb */
856         ENC_ACTION("Korean/"CS_ISO_2022_KR, C_ISO_2022_KR, "_ISO-2022-KR"), /* RADIO set_charset_cb */
857         ENC_ACTION("Thai/"CS_TIS_620, C_TIS_620, "_TIS-620-KR"), /* RADIO set_charset_cb */
858         ENC_ACTION("Thai/"CS_WINDOWS_874, C_WINDOWS_874, "_Windows-874"), /* RADIO set_charset_cb */
859 };
860
861 static GtkRadioActionEntry mainwin_radio_dec_entries[] =
862 {
863         DEC_ACTION("AutoDetect", 0, N_("_Auto detect")),        /* set_decode_cb */
864         /* --- */
865         DEC_ACTION("8bit", ENC_8BIT, "_8bit"),
866         DEC_ACTION("QP", ENC_QUOTED_PRINTABLE, "_Quoted printable"),
867         DEC_ACTION("B64", ENC_BASE64, "_Base64"),
868         DEC_ACTION("Uuencode", ENC_X_UUENCODE, "_Uuencode"),
869 };
870
871 static gboolean offline_ask_sync = TRUE;
872 static guint lastkey;
873 static gboolean is_obscured = FALSE;
874
875 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
876                                             GObject *arg1,
877                                             guint value,
878                                             GdkModifierType mod,
879                                             gpointer user_data) 
880 {
881         MainWindow *mainwin = (MainWindow *)user_data;
882
883         if (mainwin->summaryview &&
884             mainwin->summaryview->quicksearch &&
885             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
886             (mod == 0 || mod == GDK_SHIFT_MASK)) {
887                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
888                 return TRUE;
889         }
890         return FALSE;
891 }
892
893 #define N_COLOR_LABELS colorlabel_get_color_count()
894
895 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
896                                                           gpointer data)
897 {
898         MainWindow *mainwin;
899         GtkMenuShell *menu;
900         GtkCheckMenuItem **items;
901         gint n;
902         GList *children, *cur;
903         GSList *sel;
904
905         mainwin = (MainWindow *)data;
906         cm_return_if_fail(mainwin != NULL);
907
908         sel = summary_get_selection(mainwin->summaryview);
909         if (!sel) return;
910
911         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
912         cm_return_if_fail(menu != NULL);
913
914         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
915
916         /* NOTE: don't return prematurely because we set the "dont_toggle"
917          * state for check menu items. This would be bad! */
918         g_object_set_data(G_OBJECT(menu), "dont_toggle",
919                           GINT_TO_POINTER(1));
920
921         /* clear items. get item pointers. */
922         children = gtk_container_get_children(GTK_CONTAINER(menu));
923         for (n = 0, cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
924                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
925                         gtk_check_menu_item_set_active
926                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
927                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
928                         n++;
929                 }
930         }
931
932         g_list_free(children);
933
934         if (n == (N_COLOR_LABELS + 1)) {
935                 /* iterate all messages and set the state of the appropriate
936                  * items */
937                 for (; sel != NULL; sel = sel->next) {
938                         MsgInfo *msginfo;
939                         gint clabel;
940
941                         msginfo = (MsgInfo *)sel->data;
942                         if (msginfo) {
943                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
944                                 if (!gtk_check_menu_item_get_active(items[clabel]))
945                                         gtk_check_menu_item_set_active
946                                                 (items[clabel], TRUE);
947                         }
948                 }
949         } else
950                 g_warning("invalid number of color elements (%d)\n", n);
951
952         g_slist_free(sel);
953         /* reset "dont_toggle" state */
954         g_object_set_data(G_OBJECT(menu), "dont_toggle",
955                           GINT_TO_POINTER(0));
956 }
957
958 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
959                                                      gpointer data)
960 {
961         guint color = GPOINTER_TO_UINT(data);
962         MainWindow *mainwin;
963
964         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
965         cm_return_if_fail(mainwin != NULL);
966
967         /* "dont_toggle" state set? */
968         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
969                                 "dont_toggle"))
970                 return;
971
972         summary_set_colorlabel(mainwin->summaryview, color, NULL);
973 }
974
975 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
976                                                           gpointer data)
977 {
978         MainWindow *mainwin;
979         GtkMenuShell *menu;
980         GList *children, *cur;
981         GSList *sel;
982         GHashTable *menu_table = g_hash_table_new_full(
983                                         g_direct_hash,
984                                         g_direct_equal,
985                                         NULL, NULL);
986         GHashTable *menu_allsel_table = g_hash_table_new_full(
987                                         g_direct_hash,
988                                         g_direct_equal,
989                                         NULL, NULL);
990         gint sel_len;
991         mainwin = (MainWindow *)data;
992         cm_return_if_fail(mainwin != NULL);
993
994         sel = summary_get_selection(mainwin->summaryview);
995         if (!sel) return;
996
997         menu = GTK_MENU_SHELL(mainwin->tags_menu);
998         cm_return_if_fail(menu != NULL);
999
1000         /* NOTE: don't return prematurely because we set the "dont_toggle"
1001          * state for check menu items */
1002         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1003                           GINT_TO_POINTER(1));
1004
1005         /* clear items. get item pointers. */
1006         children = gtk_container_get_children(GTK_CONTAINER(menu));
1007         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
1008                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1009                         gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1010                                 "tag_id"));
1011                         gtk_check_menu_item_set_active
1012                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1013                                 
1014                         g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1015                         g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1016                 }
1017         }
1018
1019         g_list_free(children);
1020
1021         /* iterate all messages and set the state of the appropriate
1022          * items */
1023         sel_len = 0;
1024         for (; sel != NULL; sel = sel->next) {
1025                 MsgInfo *msginfo;
1026                 GSList *tags = NULL;
1027                 GtkCheckMenuItem *item;
1028                 msginfo = (MsgInfo *)sel->data;
1029                 sel_len++;
1030                 if (msginfo) {
1031                         tags =  msginfo->tags;
1032                         if (!tags)
1033                                 continue;
1034
1035                         for (; tags; tags = tags->next) {
1036                                 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1037                                 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1038                                 if (item && !gtk_check_menu_item_get_active(item)) {
1039                                         gtk_check_menu_item_set_active
1040                                                 (item, TRUE);
1041                                 }
1042                                 num_checked++;
1043                                 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1044                         }
1045                 }
1046         }
1047
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                         gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1054                         if (num_checked < sel_len && num_checked > 0)
1055                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1056                         else
1057                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1058                 }
1059         }
1060         g_list_free(children);
1061         g_slist_free(sel);
1062         g_hash_table_destroy(menu_table);
1063         g_hash_table_destroy(menu_allsel_table);
1064         /* reset "dont_toggle" state */
1065         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1066                           GINT_TO_POINTER(0));
1067 }
1068
1069 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1070                                                      gpointer data)
1071 {
1072         gint id = GPOINTER_TO_INT(data);
1073         gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1074         MainWindow *mainwin;
1075
1076         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1077         cm_return_if_fail(mainwin != NULL);
1078
1079         /* "dont_toggle" state set? */
1080         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1081                                 "dont_toggle"))
1082                 return;
1083
1084         if (!set)
1085                 id = -id;
1086         summary_set_tag(mainwin->summaryview, id, NULL);
1087 }
1088
1089 void mainwin_accel_changed_cb (GtkAccelGroup *accelgroup, guint keyval, GdkModifierType modifier,
1090                                   GClosure *closure, GtkMenuItem *item)
1091 {
1092         GList *closures = gtk_widget_list_accel_closures(GTK_WIDGET(item));
1093         GList *cur;
1094         for (cur = closures; cur; cur = cur->next) {
1095                 if (closure == cur->data) {
1096                         GtkLabel *label = g_object_get_data(G_OBJECT(item), "accel_label");
1097                         gchar *new_accel;
1098                         
1099                         if (keyval == GDK_KEY_BackSpace) {
1100                                 const gchar *accel_path;
1101                                 accel_path = gtk_menu_item_get_accel_path(item);
1102                                 keyval = 0; modifier = 0;
1103                                 gtk_accel_map_change_entry (accel_path, keyval, modifier, TRUE);
1104                         }
1105                         new_accel = gtk_accelerator_get_label(keyval, modifier);
1106                         gtk_label_set_text(label, new_accel);
1107                         g_free(new_accel);
1108                 }
1109         }
1110 }
1111
1112 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1113 {
1114         GtkWidget *label_menuitem;
1115         GtkWidget *menu;
1116         GtkWidget *item;
1117         gint i;
1118         gchar *accel_path = NULL;
1119
1120         label_menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/ColorLabel");
1121         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1122                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1123                            mainwin);
1124         gtk_widget_show(label_menuitem);
1125
1126         menu = gtk_menu_new();
1127         gtk_menu_set_accel_group (GTK_MENU (menu), 
1128                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1129
1130         /* create sub items. for the menu item activation callback we pass the
1131          * index of label_colors[] as data parameter. for the None color we
1132          * pass an invalid (high) value. also we attach a data pointer so we
1133          * can always get back the Mainwindow pointer. */
1134
1135         item = gtk_check_menu_item_new_with_label(_("None"));
1136         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1137         g_signal_connect(G_OBJECT(item), "activate",
1138                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1139                            GUINT_TO_POINTER(0));
1140         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1141         gtk_widget_show(item);
1142
1143         accel_path = g_strdup_printf("<ClawsColorLabels>/None");
1144         gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1145         g_free(accel_path);
1146         gtk_accel_map_add_entry("<ClawsColorLabels>/None", GDK_0, GDK_CONTROL_MASK);
1147
1148         item = gtk_menu_item_new();
1149         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1150         gtk_widget_show(item);
1151
1152         /* create pixmap/label menu items */
1153         for (i = 0; i < N_COLOR_LABELS; i++) {
1154                 item = colorlabel_create_check_color_menu_item(
1155                         i, refresh, MAINWIN_COLORMENU);
1156                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1157                 g_signal_connect(G_OBJECT(item), "activate",
1158                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1159                                  GUINT_TO_POINTER(i + 1));
1160                 g_object_set_data(G_OBJECT(item), "mainwin",
1161                                   mainwin);
1162                 gtk_widget_show(item);
1163                 accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i+1);
1164                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1165                 if (i < 9)
1166                         gtk_accel_map_add_entry(accel_path, GDK_1+i, GDK_CONTROL_MASK);
1167                 g_free(accel_path);
1168                 g_signal_connect (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
1169                         "accel-changed", G_CALLBACK (mainwin_accel_changed_cb), item);
1170
1171
1172         }
1173         gtk_widget_show(menu);
1174         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1175         mainwin->colorlabel_menu = menu;
1176 }
1177
1178 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1179                                                      gpointer data)
1180 {
1181         MainWindow *mainwin;
1182
1183         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1184         cm_return_if_fail(mainwin != NULL);
1185
1186         /* "dont_toggle" state set? */
1187         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1188                                 "dont_toggle"))
1189                 return;
1190         
1191         tag_apply_open(summary_get_selection(mainwin->summaryview));    
1192 }
1193
1194 static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b)
1195 {
1196         gint id_a = GPOINTER_TO_INT(a);
1197         gint id_b = GPOINTER_TO_INT(b);
1198         const gchar *tag_a = tags_get_tag(id_a);
1199         const gchar *tag_b = tags_get_tag(id_b);
1200         
1201                 
1202         if (tag_a == NULL)
1203                 return tag_b == NULL ? 0:1;
1204         
1205         if (tag_b == NULL)
1206                 return tag_a == NULL ? 0:1;
1207  
1208         return g_utf8_collate(tag_a, tag_b);
1209 }
1210
1211 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1212 {
1213         GtkWidget *label_menuitem;
1214         GtkWidget *menu;
1215         GtkWidget *item;
1216         GSList *cur = tags_get_list();
1217         GSList *orig = NULL;
1218         gboolean existing_tags = FALSE;
1219         gchar *accel_path;
1220         cur = orig = g_slist_sort(cur, mainwin_tag_cmp_list);
1221
1222         label_menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Tags");
1223         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1224                          G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1225                            mainwin);
1226
1227         gtk_widget_show(label_menuitem);
1228
1229         menu = gtk_menu_new();
1230         gtk_menu_set_accel_group (GTK_MENU (menu), 
1231                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1232
1233         /* create tags menu items */
1234         for (; cur; cur = cur->next) {
1235                 gint id = GPOINTER_TO_INT(cur->data);
1236                 const gchar *tag = tags_get_tag(id);
1237
1238                 item = gtk_check_menu_item_new_with_label(tag);
1239                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1240                 g_signal_connect(G_OBJECT(item), "activate",
1241                                  G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1242                                  GINT_TO_POINTER(id));
1243                 g_object_set_data(G_OBJECT(item), "mainwin",
1244                                   mainwin);
1245                 g_object_set_data(G_OBJECT(item), "tag_id",
1246                                   GINT_TO_POINTER(id));
1247                 gtk_widget_show(item);
1248                 accel_path = g_strconcat("<ClawsTags>/",tag, NULL);
1249                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1250                 g_free(accel_path);
1251                 existing_tags = TRUE;
1252         }
1253         if (existing_tags) {
1254                 /* separator */
1255                 item = gtk_menu_item_new();
1256                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1257                 gtk_widget_show(item);
1258         }
1259
1260         item = gtk_menu_item_new_with_label(_("Apply tags..."));
1261         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1262         g_signal_connect(G_OBJECT(item), "activate",
1263                          G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1264                          NULL);
1265         g_object_set_data(G_OBJECT(item), "mainwin",
1266                           mainwin);
1267         gtk_widget_show(item);
1268         accel_path = g_strdup_printf("<ClawsTags>/ApplyTags");
1269         gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
1270         g_free(accel_path);
1271         gtk_accel_map_add_entry("<ClawsTags>/ApplyTags", GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK);
1272
1273         g_slist_free(orig);
1274         gtk_widget_show(menu);
1275         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1276         mainwin->tags_menu = menu;
1277 }
1278 #ifndef GENERIC_UMPC
1279 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1280                                     MainWindow *mainwindow)
1281 {
1282         if (evt && evt->button == 1) {
1283                 log_window_show_error(mainwindow->logwin);
1284                 gtk_widget_hide(mainwindow->warning_btn);
1285         }
1286         return FALSE;
1287 }
1288
1289 static gboolean warning_visi_notify(GtkWidget *widget,
1290                                        GdkEventVisibility *event,
1291                                        MainWindow *mainwindow)
1292 {
1293         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), hand_cursor);
1294         return FALSE;
1295 }
1296
1297 static gboolean warning_leave_notify(GtkWidget *widget,
1298                                       GdkEventCrossing *event,
1299                                       MainWindow *mainwindow)
1300 {
1301         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), NULL);
1302         return FALSE;
1303 }
1304
1305 static gboolean warning_enter_notify(GtkWidget *widget,
1306                                       GdkEventCrossing *event,
1307                                       MainWindow *mainwindow)
1308 {
1309         gdk_window_set_cursor(gtk_widget_get_window(mainwindow->warning_btn), hand_cursor);
1310         return FALSE;
1311 }
1312 #endif
1313 void mainwindow_show_error(void)
1314 {
1315         MainWindow *mainwin = mainwindow_get_mainwindow();
1316         gtk_widget_show(mainwin->warning_btn);
1317 }
1318
1319 void mainwindow_clear_error(MainWindow *mainwin)
1320 {
1321         gtk_widget_hide(mainwin->warning_btn);
1322 }
1323
1324 #define BREAK_ON_MODIFIER_KEY() \
1325         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
1326
1327 static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
1328                                     gpointer data)
1329 {
1330         MainWindow *mainwin = (MainWindow*) data;
1331         
1332         if (!mainwin || !event) 
1333                 return FALSE;
1334
1335         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
1336         {
1337                 lastkey = event->keyval;
1338                 return FALSE;
1339         }
1340
1341         switch (event->keyval) {
1342         case GDK_KEY_Q:             /* Quit */
1343 #ifndef MAEMO
1344                 BREAK_ON_MODIFIER_KEY();
1345
1346                 if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
1347                         app_exit_cb(NULL, mainwin);
1348                 }
1349 #endif
1350                 return FALSE;
1351         case GDK_KEY_space:
1352                 BREAK_ON_MODIFIER_KEY();
1353                 if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
1354                         if (mainwin->folderview != NULL && mainwin->summaryview != NULL
1355                             && ((!mainwin->summaryview->displayed
1356                                 && !mainwin->summaryview->selected) 
1357                                 || (mainwin->summaryview->folder_item
1358                                     && mainwin->summaryview->folder_item->total_msgs == 0))) {
1359                                 g_signal_stop_emission_by_name(G_OBJECT(widget), 
1360                                                "key_press_event");
1361                                 folderview_select_next_unread(mainwin->folderview, TRUE);
1362                         }
1363                 }
1364                 break;
1365
1366 #ifdef MAEMO
1367         case GDK_KEY_F6:
1368                 if (maemo_mainwindow_is_fullscreen(widget)) {
1369                         gtk_window_unfullscreen(GTK_WINDOW(widget));
1370                 } else {
1371                         gtk_window_fullscreen(GTK_WINDOW(widget));
1372                 }
1373                 break;
1374         case GDK_KEY_F7:
1375                 {
1376                         PangoFontDescription *font_desc;
1377                         int size;
1378                         font_desc = pango_font_description_from_string(prefs_common.normalfont);
1379                         size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
1380                         if (size < 30) {
1381                                 size++; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
1382                                 g_free(prefs_common.normalfont); 
1383                                 prefs_common.normalfont = pango_font_description_to_string(font_desc);
1384                                 main_window_reflect_prefs_all();
1385                         }
1386                         pango_font_description_free(font_desc);
1387                         font_desc = pango_font_description_from_string(prefs_common.textfont);
1388                         size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
1389                         if (size < 30) {
1390                                 size++; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
1391                                 g_free(prefs_common.textfont); 
1392                                 prefs_common.textfont = pango_font_description_to_string(font_desc);
1393                                 main_window_reflect_prefs_all();
1394                         }
1395                         pango_font_description_free(font_desc);
1396                 }
1397                 break;
1398         case GDK_KEY_F8:
1399                 {
1400                         PangoFontDescription *font_desc;
1401                         int size;
1402                         font_desc = pango_font_description_from_string(prefs_common.normalfont);
1403                         size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
1404                         if (size > 5) {
1405                                 size--; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
1406                                 g_free(prefs_common.normalfont); 
1407                                 prefs_common.normalfont = pango_font_description_to_string(font_desc);
1408                                 main_window_reflect_prefs_all();
1409                         }
1410                         pango_font_description_free(font_desc);
1411                         font_desc = pango_font_description_from_string(prefs_common.textfont);
1412                         size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
1413                         if (size > 5) {
1414                                 size--; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
1415                                 g_free(prefs_common.textfont); 
1416                                 prefs_common.textfont = pango_font_description_to_string(font_desc);
1417                                 main_window_reflect_prefs_all();
1418                         }
1419                         pango_font_description_free(font_desc);
1420                 }
1421                 break;
1422         case GDK_KEY_Escape:
1423                 if (mainwin->summaryview && 
1424                     mainwin->summaryview->ext_messageview && 
1425                     mainwin->summaryview->ext_messageview->window && 
1426                     widget == mainwin->summaryview->ext_messageview->window) {
1427                         messageview_destroy(mainwin->summaryview->ext_messageview);
1428                 }
1429                 break;
1430 #endif
1431         default:
1432                 break;
1433         }
1434         return FALSE;
1435 }
1436
1437 #undef BREAK_ON_MODIFIER_KEY
1438
1439 #ifdef MAEMO
1440 void mainwindow_maemo_led_set(gboolean state) {
1441         static gint last_state = -1;
1442         if (last_state == state)
1443                 return;
1444         last_state = (gint)state;
1445         if (prefs_common.maemo_show_led) {
1446                 if(state) {
1447                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1448                         "--dest=com.nokia.mce "
1449                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
1450                         "string:PatternCommunicationEvent", TRUE);
1451                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1452                         "--dest=com.nokia.mce "
1453                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
1454                         "string:PatternCommunicationEmail", TRUE);
1455                 } else {
1456                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1457                         "--dest=com.nokia.mce "
1458                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
1459                         "string:PatternCommunicationEvent", TRUE);
1460                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1461                         "--dest=com.nokia.mce "
1462                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
1463                         "string:PatternCommunicationEmail", TRUE);
1464                 }
1465         } 
1466 }
1467
1468 static void led_update(FolderItem *removed_item)
1469 {
1470         guint new, unread, unreadmarked, marked, total, replied;
1471         guint forwarded, locked, ignored, watched;
1472
1473         folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
1474                                 &replied, &forwarded, &locked, &ignored,
1475                                 &watched);
1476         if (removed_item) {
1477                 total -= removed_item->total_msgs;
1478                 new -= removed_item->new_msgs;
1479                 unread -= removed_item->unread_msgs;
1480         }
1481
1482         if (new > 0)
1483                 mainwindow_maemo_led_set(TRUE);
1484         else
1485                 mainwindow_maemo_led_set(FALSE);
1486 }
1487
1488 static gboolean maemo_folder_item_update_hook(gpointer source, gpointer data)
1489 {
1490         led_update(NULL);
1491
1492         return FALSE;
1493 }
1494
1495 static gboolean maemo_folder_update_hook(gpointer source, gpointer data)
1496 {
1497         FolderUpdateData *hookdata;
1498         hookdata = source;
1499         if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
1500                 led_update(hookdata->item);
1501         else
1502                 led_update(NULL);
1503
1504         return FALSE;
1505 }
1506
1507 static void main_window_install_maemo_hooks(MainWindow *mainwin)
1508 {
1509         gint maemo_item_hook_id, maemo_folder_hook_id;
1510         
1511         maemo_item_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, maemo_folder_item_update_hook, NULL);
1512         if (maemo_item_hook_id == -1) {
1513                 goto err_out_item;
1514         }
1515
1516         maemo_folder_hook_id = hooks_register_hook (FOLDER_UPDATE_HOOKLIST, maemo_folder_update_hook, NULL);
1517         if (maemo_folder_hook_id == -1) {
1518                 goto err_out_folder;
1519         }
1520         
1521         return;
1522
1523 err_out_folder:
1524         hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, maemo_item_hook_id);
1525 err_out_item:
1526         return;
1527 }
1528 #endif
1529
1530 MainWindow *main_window_create()
1531 {
1532         MainWindow *mainwin;
1533         GtkWidget *window;
1534         GtkWidget *vbox;
1535         GtkWidget *menubar;
1536         GtkWidget *handlebox;
1537         GtkWidget *vbox_body;
1538         GtkWidget *menuitem;
1539 #ifndef GENERIC_UMPC
1540         GtkWidget *hbox_stat;
1541         GtkWidget *statusbar;
1542         GtkWidget *progressbar;
1543         GtkWidget *statuslabel;
1544         GtkWidget *ac_button;
1545         GtkWidget *ac_label;
1546         GtkWidget *online_pixmap;
1547         GtkWidget *offline_pixmap;
1548         GtkWidget *warning_icon;
1549         GtkWidget *warning_btn;
1550 #endif
1551         GtkWidget *online_switch;
1552         GtkWidget *offline_switch;
1553         FolderView *folderview;
1554         SummaryView *summaryview;
1555         MessageView *messageview;
1556 #if !GTK_CHECK_VERSION(3, 0, 0)
1557         GdkColormap *colormap;
1558         gboolean success[4];
1559 #endif
1560         GdkColor color[4];
1561         GtkWidget *ac_menu;
1562         gint i;
1563
1564         static GdkGeometry geometry;
1565
1566         debug_print("Creating main window...\n");
1567         mainwin = g_new0(MainWindow, 1);
1568
1569         /* main window */
1570         window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1571         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1572         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1573 #ifdef GENERIC_UMPC
1574         prefs_common.layout_mode = SMALL_LAYOUT;
1575 #endif
1576         if (!geometry.min_height) {
1577                 geometry.min_width = 320;
1578                 geometry.min_height = 200;
1579         }
1580         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1581                                       GDK_HINT_MIN_SIZE);
1582
1583         g_signal_connect(G_OBJECT(window), "delete_event",
1584                          G_CALLBACK(main_window_close_cb), mainwin);
1585         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1586         g_signal_connect(G_OBJECT(window), "focus_in_event",
1587                          G_CALLBACK(mainwindow_focus_in_event),
1588                          mainwin);
1589         g_signal_connect(G_OBJECT(window), "key_press_event",
1590                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1591
1592         gtk_widget_realize(window);
1593         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1594         
1595
1596         gtkut_widget_set_app_icon(window);
1597
1598         vbox = gtk_vbox_new(FALSE, 0);
1599         gtk_widget_show(vbox);
1600         gtk_container_add(GTK_CONTAINER(window), vbox);
1601
1602         /* menu bar */
1603
1604         mainwin->ui_manager = gtk_ui_manager_new();
1605         mainwin->action_group = cm_menu_create_action_group_full(mainwin->ui_manager,"Menu", mainwin_entries,
1606                         G_N_ELEMENTS(mainwin_entries), (gpointer)mainwin);
1607         gtk_action_group_add_toggle_actions(mainwin->action_group, mainwin_toggle_entries,
1608                         G_N_ELEMENTS(mainwin_toggle_entries), (gpointer)mainwin);
1609         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_showhide_radio_entries,
1610                         G_N_ELEMENTS(mainwin_showhide_radio_entries), C_AUTO, G_CALLBACK(toggle_toolbar_cb), (gpointer)mainwin);
1611 #ifndef GENERIC_UMPC
1612         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_layout_radio_entries,
1613                         G_N_ELEMENTS(mainwin_layout_radio_entries), C_AUTO, G_CALLBACK(set_layout_cb), (gpointer)mainwin);
1614 #endif
1615         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_sort_radio_entries,
1616                         G_N_ELEMENTS(mainwin_sort_radio_entries), C_AUTO, G_CALLBACK(sort_summary_cb), (gpointer)mainwin);
1617         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_sorttype_radio_entries,
1618                         G_N_ELEMENTS(mainwin_sorttype_radio_entries), C_AUTO, G_CALLBACK(sort_summary_type_cb), (gpointer)mainwin);
1619         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_radio_enc_entries,
1620                         G_N_ELEMENTS(mainwin_radio_enc_entries), C_AUTO, G_CALLBACK(set_charset_cb), (gpointer)mainwin);
1621         gtk_action_group_add_radio_actions(mainwin->action_group, mainwin_radio_dec_entries,
1622                         G_N_ELEMENTS(mainwin_radio_dec_entries), C_AUTO, G_CALLBACK(set_decode_cb), (gpointer)mainwin);
1623
1624 #ifndef MAEMO
1625         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
1626 #else
1627         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_POPUP)
1628 #endif
1629         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
1630         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
1631         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "View", "View", GTK_UI_MANAGER_MENU)
1632         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
1633         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Tools", "Tools", GTK_UI_MANAGER_MENU)
1634         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Configuration", "Configuration", GTK_UI_MANAGER_MENU)
1635         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu", "Help", "Help", GTK_UI_MANAGER_MENU)
1636
1637 /* File menu */
1638         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "AddMailbox", "File/AddMailbox", GTK_UI_MANAGER_MENU)
1639         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File/AddMailbox", "MH", "File/AddMailbox/MH", GTK_UI_MANAGER_MENUITEM)
1640         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
1641         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SortMailboxes", "File/SortMailboxes", GTK_UI_MANAGER_MENUITEM)
1642         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator2", "File/---", GTK_UI_MANAGER_SEPARATOR)
1643         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ImportMbox", "File/ImportMbox", GTK_UI_MANAGER_MENUITEM)
1644         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ExportMbox", "File/ExportMbox", GTK_UI_MANAGER_MENUITEM)
1645         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "ExportSelMbox", "File/ExportSelMbox", GTK_UI_MANAGER_MENUITEM)
1646         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator3", "File/---", GTK_UI_MANAGER_SEPARATOR)
1647         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "EmptyTrashes", "File/EmptyTrashes", GTK_UI_MANAGER_MENUITEM)
1648         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator4", "File/---", GTK_UI_MANAGER_SEPARATOR)
1649         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
1650         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
1651         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
1652         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator5", "File/---", GTK_UI_MANAGER_SEPARATOR)
1653         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "OfflineMode", "File/OfflineMode", GTK_UI_MANAGER_MENUITEM)
1654         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "SynchroniseFolders", "File/SynchroniseFolders", GTK_UI_MANAGER_MENUITEM)
1655         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
1656         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/File", "Exit", "File/Exit", GTK_UI_MANAGER_MENUITEM)
1657
1658 /* Edit menu */
1659         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Copy", "Edit/Copy", GTK_UI_MANAGER_MENUITEM)
1660         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SelectAll", "Edit/SelectAll", GTK_UI_MANAGER_MENUITEM)
1661         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SelectThread", "Edit/SelectThread", GTK_UI_MANAGER_MENUITEM)
1662         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "DeleteThread", "Edit/DeleteThread", GTK_UI_MANAGER_MENUITEM)
1663         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Separator1", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
1664         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "Find", "Edit/Find", GTK_UI_MANAGER_MENUITEM)
1665         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "SearchFolder", "Edit/SearchFolder", GTK_UI_MANAGER_MENUITEM)
1666         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Edit", "QuickSearch", "Edit/QuickSearch", GTK_UI_MANAGER_MENUITEM)
1667
1668 /* View menu */
1669         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ShowHide", "View/ShowHide", GTK_UI_MANAGER_MENU)
1670         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "Toolbar", "View/ShowHide/Toolbar", GTK_UI_MANAGER_MENU)
1671         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextBelowIcon", "View/ShowHide/Toolbar/TextBelowIcon", GTK_UI_MANAGER_MENUITEM)
1672         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextBesideIcon", "View/ShowHide/Toolbar/TextBesideIcon", GTK_UI_MANAGER_MENUITEM)
1673         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "IconOnly", "View/ShowHide/Toolbar/IconOnly", GTK_UI_MANAGER_MENUITEM)
1674         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "TextOnly", "View/ShowHide/Toolbar/TextOnly", GTK_UI_MANAGER_MENUITEM)
1675 #ifndef GENERIC_UMPC
1676         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar", "Hide", "View/ShowHide/Toolbar/Hide", GTK_UI_MANAGER_MENUITEM)
1677 #endif
1678         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "MessageView", "View/ShowHide/MessageView", GTK_UI_MANAGER_MENUITEM)
1679 #ifndef GENERIC_UMPC
1680         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "StatusBar", "View/ShowHide/StatusBar", GTK_UI_MANAGER_MENUITEM)
1681 #endif
1682         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/ShowHide", "ColumnHeaders", "View/ShowHide/ColumnHeaders", GTK_UI_MANAGER_MENUITEM)
1683         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "SetColumns", "View/SetColumns", GTK_UI_MANAGER_MENU)
1684         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/SetColumns", "Folderlist", "View/SetColumns/Folderlist", GTK_UI_MANAGER_MENUITEM)
1685         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/SetColumns", "Messagelist", "View/SetColumns/Messagelist", GTK_UI_MANAGER_MENUITEM)
1686         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator1", "View/---", GTK_UI_MANAGER_SEPARATOR)
1687
1688 #ifndef MAEMO
1689         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "FullScreen", "View/FullScreen", GTK_UI_MANAGER_MENUITEM)
1690 #endif
1691 #ifndef GENERIC_UMPC
1692         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Layout", "View/Layout", GTK_UI_MANAGER_MENU)
1693         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "Standard", "View/Layout/Standard", GTK_UI_MANAGER_MENUITEM)
1694         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "ThreeColumns", "View/Layout/ThreeColumns", GTK_UI_MANAGER_MENUITEM)
1695         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "WideMessage", "View/Layout/WideMessage", GTK_UI_MANAGER_MENUITEM)
1696         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "WideMessageList", "View/Layout/WideMessageList", GTK_UI_MANAGER_MENUITEM)
1697         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Layout", "SmallScreen", "View/Layout/SmallScreen", GTK_UI_MANAGER_MENUITEM)
1698         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator2", "View/---", GTK_UI_MANAGER_SEPARATOR)
1699 #endif
1700
1701         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Sort", "View/Sort", GTK_UI_MANAGER_MENU)
1702         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Number", "View/Sort/Number", GTK_UI_MANAGER_MENUITEM)
1703         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Size", "View/Sort/Size", GTK_UI_MANAGER_MENUITEM)
1704         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Date", "View/Sort/Date", GTK_UI_MANAGER_MENUITEM)
1705         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "ThreadDate", "View/Sort/ThreadDate", GTK_UI_MANAGER_MENUITEM)
1706         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "From", "View/Sort/From", GTK_UI_MANAGER_MENUITEM)
1707         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "To", "View/Sort/To", GTK_UI_MANAGER_MENUITEM)
1708         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Subject", "View/Sort/Subject", GTK_UI_MANAGER_MENUITEM)
1709         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Color", "View/Sort/Color", GTK_UI_MANAGER_MENUITEM)
1710         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Tag", "View/Sort/Tag", GTK_UI_MANAGER_MENUITEM)
1711         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Mark", "View/Sort/Mark", GTK_UI_MANAGER_MENUITEM)
1712         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Status", "View/Sort/Status", GTK_UI_MANAGER_MENUITEM)
1713         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Attachment", "View/Sort/Attachment", GTK_UI_MANAGER_MENUITEM)
1714         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Score", "View/Sort/Score", GTK_UI_MANAGER_MENUITEM)
1715         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Locked", "View/Sort/Locked", GTK_UI_MANAGER_MENUITEM)
1716         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "DontSort", "View/Sort/DontSort", GTK_UI_MANAGER_MENUITEM)
1717         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Separator1", "View/Sort/---", GTK_UI_MANAGER_SEPARATOR)
1718         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Ascending", "View/Sort/Ascending", GTK_UI_MANAGER_MENUITEM)
1719         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Descending", "View/Sort/Descending", GTK_UI_MANAGER_MENUITEM)
1720         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "Separator2", "View/Sort/---", GTK_UI_MANAGER_SEPARATOR)
1721         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Sort", "AttractSubj", "View/Sort/AttractSubj", GTK_UI_MANAGER_MENUITEM)
1722
1723         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ThreadView", "View/ThreadView", GTK_UI_MANAGER_MENUITEM)
1724         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "ExpandThreads", "View/ExpandThreads", GTK_UI_MANAGER_MENUITEM)
1725         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "CollapseThreads", "View/CollapseThreads", GTK_UI_MANAGER_MENUITEM)
1726         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideReadThreads", "View/HideReadThreads", GTK_UI_MANAGER_MENUITEM)
1727         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideReadMessages", "View/HideReadMessages", GTK_UI_MANAGER_MENUITEM)
1728         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "HideDelMessages", "View/HideDelMessages", GTK_UI_MANAGER_MENUITEM)
1729         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator3", "View/---", GTK_UI_MANAGER_SEPARATOR)
1730
1731         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Goto", "View/Goto", GTK_UI_MANAGER_MENU)
1732         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Prev", "View/Goto/Prev", GTK_UI_MANAGER_MENUITEM)
1733         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Next", "View/Goto/Next", GTK_UI_MANAGER_MENUITEM)
1734         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator1", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1735         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevUnread", "View/Goto/PrevUnread", GTK_UI_MANAGER_MENUITEM)
1736         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextUnread", "View/Goto/NextUnread", GTK_UI_MANAGER_MENUITEM)
1737         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator2", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1738         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevNew", "View/Goto/PrevNew", GTK_UI_MANAGER_MENUITEM)
1739         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextNew", "View/Goto/NextNew", GTK_UI_MANAGER_MENUITEM)
1740         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator3", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1741         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevMarked", "View/Goto/PrevMarked", GTK_UI_MANAGER_MENUITEM)
1742         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextMarked", "View/Goto/NextMarked", GTK_UI_MANAGER_MENUITEM)
1743         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator4", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1744         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevLabeled", "View/Goto/PrevLabeled", GTK_UI_MANAGER_MENUITEM)
1745         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextLabeled", "View/Goto/NextLabeled", GTK_UI_MANAGER_MENUITEM)
1746         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator5", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1747         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "PrevHistory", "View/Goto/PrevHistory", GTK_UI_MANAGER_MENUITEM)
1748         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextHistory", "View/Goto/NextHistory", GTK_UI_MANAGER_MENUITEM)
1749         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator6", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1750         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
1751         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
1752         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
1753         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Goto", "OtherFolder", "View/Goto/OtherFolder", GTK_UI_MANAGER_MENUITEM)
1754         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Scroll", "View/Scroll", GTK_UI_MANAGER_MENU)
1755         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "PrevLine", "View/Scroll/PrevLine", GTK_UI_MANAGER_MENUITEM)
1756         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "NextLine", "View/Scroll/NextLine", GTK_UI_MANAGER_MENUITEM)
1757         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "PrevPage", "View/Scroll/PrevPage", GTK_UI_MANAGER_MENUITEM)
1758         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Scroll", "NextPage", "View/Scroll/NextPage", GTK_UI_MANAGER_MENUITEM)
1759         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator4", "View/---", GTK_UI_MANAGER_SEPARATOR)
1760
1761         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Encoding", "View/Encoding", GTK_UI_MANAGER_MENU)
1762         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_AUTO, "View/Encoding/"CS_AUTO, GTK_UI_MANAGER_MENUITEM)
1763         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Separator1", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
1764         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_US_ASCII, "View/Encoding/"CS_US_ASCII, GTK_UI_MANAGER_MENUITEM)
1765         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_UTF_8, "View/Encoding/"CS_UTF_8, GTK_UI_MANAGER_MENUITEM)
1766         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Separator2", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
1767
1768         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Western", "View/Encoding/Western", GTK_UI_MANAGER_MENU)
1769         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)
1770         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)
1771         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Western", CS_WINDOWS_1252, "View/Encoding/Western/"CS_WINDOWS_1252, GTK_UI_MANAGER_MENUITEM)
1772
1773         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_2, "View/Encoding/"CS_ISO_8859_2, GTK_UI_MANAGER_MENUITEM)
1774
1775         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Baltic", "View/Encoding/Baltic", GTK_UI_MANAGER_MENU)
1776         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)
1777         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)
1778
1779         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_7, "View/Encoding/"CS_ISO_8859_7, GTK_UI_MANAGER_MENUITEM)
1780
1781         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Hebrew", "View/Encoding/Hebrew", GTK_UI_MANAGER_MENU)
1782         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)
1783         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Hebrew", CS_WINDOWS_1255, "View/Encoding/Hebrew/"CS_WINDOWS_1255, GTK_UI_MANAGER_MENUITEM)
1784
1785         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Arabic", "View/Encoding/Arabic", GTK_UI_MANAGER_MENU)
1786         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)
1787         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Arabic", CS_WINDOWS_1256, "View/Encoding/Arabic/"CS_WINDOWS_1256, GTK_UI_MANAGER_MENUITEM)
1788
1789         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_9, "View/Encoding/"CS_ISO_8859_9, GTK_UI_MANAGER_MENUITEM)
1790
1791         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
1792         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)
1793         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
1794         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
1795         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
1796
1797         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Japanese", "View/Encoding/Japanese", GTK_UI_MANAGER_MENU)
1798         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)
1799         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)
1800         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_EUC_JP, "View/Encoding/Japanese/"CS_EUC_JP, GTK_UI_MANAGER_MENUITEM)
1801         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
1802
1803         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
1804         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
1805         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
1806         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
1807         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
1808         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Chinese", CS_EUC_TW, "View/Encoding/Chinese/"CS_EUC_TW, GTK_UI_MANAGER_MENUITEM)
1809
1810         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Korean", "View/Encoding/Korean", GTK_UI_MANAGER_MENU)
1811         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Korean", CS_EUC_KR, "View/Encoding/Korean/"CS_EUC_KR, GTK_UI_MANAGER_MENUITEM)
1812         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)
1813
1814         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding", "Thai", "View/Encoding/Thai", GTK_UI_MANAGER_MENU)
1815         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Thai", CS_TIS_620, "View/Encoding/Thai/"CS_TIS_620, GTK_UI_MANAGER_MENUITEM)
1816         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Encoding/Thai", CS_WINDOWS_874, "View/Encoding/Thai/"CS_WINDOWS_874, GTK_UI_MANAGER_MENUITEM)
1817
1818         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Decode", "View/Decode", GTK_UI_MANAGER_MENU)
1819         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "AutoDetect", "View/Decode/AutoDetect", GTK_UI_MANAGER_MENUITEM)
1820         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "Separator1", "View/Decode/---", GTK_UI_MANAGER_SEPARATOR)
1821         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "8bit", "View/Decode/8bit", GTK_UI_MANAGER_MENUITEM)
1822         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "QP", "View/Decode/QP", GTK_UI_MANAGER_MENUITEM)
1823         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "B64", "View/Decode/B64", GTK_UI_MANAGER_MENUITEM)
1824         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Decode", "Uuencode", "View/Decode/Uuencode", GTK_UI_MANAGER_MENUITEM)
1825         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator5", "View/---", GTK_UI_MANAGER_SEPARATOR)
1826
1827         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
1828         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
1829         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
1830         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Quotes", "View/Quotes", GTK_UI_MANAGER_MENU)
1831         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "CollapseAll", "View/Quotes/CollapseAll", GTK_UI_MANAGER_MENUITEM)
1832         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "Collapse2", "View/Quotes/Collapse2", GTK_UI_MANAGER_MENUITEM)
1833         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View/Quotes", "Collapse3", "View/Quotes/Collapse3", GTK_UI_MANAGER_MENUITEM)
1834         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "Separator6", "View/---", GTK_UI_MANAGER_SEPARATOR)
1835         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/View", "UpdateSummary", "View/UpdateSummary", GTK_UI_MANAGER_MENUITEM)
1836
1837 /* Message menu */
1838         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Receive", "Message/Receive", GTK_UI_MANAGER_MENU)
1839         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "CurrentAccount", "Message/Receive/CurrentAccount", GTK_UI_MANAGER_MENUITEM)
1840         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "AllAccounts", "Message/Receive/AllAccounts", GTK_UI_MANAGER_MENUITEM)
1841         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "CancelReceiving", "Message/Receive/CancelReceiving", GTK_UI_MANAGER_MENUITEM)
1842         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "Separator1", "Message/Receive/---", GTK_UI_MANAGER_SEPARATOR)
1843         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Receive", "PlaceHolder", "Message/Receive/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1844         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "SendQueue", "Message/SendQueue", GTK_UI_MANAGER_MENUITEM)
1845         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1846
1847         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ComposeEmail", "Message/ComposeEmail", GTK_UI_MANAGER_MENUITEM)
1848         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ComposeNews", "Message/ComposeNews", GTK_UI_MANAGER_MENUITEM)
1849         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
1850         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ReplyTo", "Message/ReplyTo", GTK_UI_MANAGER_MENU)
1851         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
1852         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
1853         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/ReplyTo", "List", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
1854         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "FollowupReply", "Message/FollowupReply", GTK_UI_MANAGER_MENUITEM)
1855         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1856
1857         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
1858         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
1859         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
1860         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "MailingList", "Message/MailingList", GTK_UI_MANAGER_MENU)
1861         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Post", "Message/MailingList/Post", GTK_UI_MANAGER_MENU)
1862         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Help", "Message/MailingList/Help", GTK_UI_MANAGER_MENU)
1863         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Subscribe", "Message/MailingList/Subscribe", GTK_UI_MANAGER_MENU)
1864         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "Unsubscribe", "Message/MailingList/Unsubscribe", GTK_UI_MANAGER_MENU)
1865         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "ViewArchive", "Message/MailingList/ViewArchive", GTK_UI_MANAGER_MENU)
1866         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList", "ContactOwner", "Message/MailingList/ContactOwner", GTK_UI_MANAGER_MENU)
1867         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Post", "PlaceHolder", "Message/MailingList/Post/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1868         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Help", "PlaceHolder", "Message/MailingList/Help/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1869         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Subscribe", "PlaceHolder", "Message/MailingList/Subscribe/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1870         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/Unsubscribe", "PlaceHolder", "Message/MailingList/Unsubscribe/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1871         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/ViewArchive", "PlaceHolder", "Message/MailingList/ViewArchive/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1872         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/MailingList/ContactOwner", "PlaceHolder", "Message/MailingList/ContactOwner/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1873         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1874
1875         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
1876         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
1877         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
1878         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
1879         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "CancelNews", "Message/CancelNews", GTK_UI_MANAGER_MENUITEM)
1880         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1881
1882         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Mark", "Message/Mark", GTK_UI_MANAGER_MENU)
1883         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
1884         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
1885         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1886         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
1887         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
1888         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
1889         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
1890         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
1891         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
1892         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
1893         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1894         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
1895         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
1896         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
1897         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
1898         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
1899         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "ColorLabel", "Message/ColorLabel", GTK_UI_MANAGER_MENUITEM)
1900         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Tags", "Message/Tags", GTK_UI_MANAGER_MENUITEM)
1901         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator5", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1902
1903         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Reedit", "Message/Reedit", GTK_UI_MANAGER_MENUITEM)
1904         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Message", "Separator6", "Message/---", GTK_UI_MANAGER_SEPARATOR)
1905
1906 /* Tools menu */
1907         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
1908         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
1909         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CollectAddresses", "Tools/CollectAddresses", GTK_UI_MANAGER_MENU)
1910         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CollectAddresses", "FromFolder", "Tools/CollectAddresses/FromFolder", GTK_UI_MANAGER_MENUITEM)
1911         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CollectAddresses", "FromSelected", "Tools/CollectAddresses/FromSelected", GTK_UI_MANAGER_MENUITEM)
1912         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1913
1914         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilterFolder", "Tools/FilterFolder", GTK_UI_MANAGER_MENUITEM)
1915         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilterSelected", "Tools/FilterSelected", GTK_UI_MANAGER_MENUITEM)
1916         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "RunProcessing", "Tools/RunProcessing", GTK_UI_MANAGER_MENUITEM)
1917         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CreateFilterRule", "Tools/CreateFilterRule", GTK_UI_MANAGER_MENU)
1918         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
1919         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
1920         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
1921         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
1922
1923         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CreateProcessingRule", "Tools/CreateProcessingRule", GTK_UI_MANAGER_MENU)
1924         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
1925         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
1926         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
1927         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
1928         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1929         
1930         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "ListUrls", "Tools/ListUrls", GTK_UI_MANAGER_MENUITEM)
1931         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator3", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1932
1933         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Actions", "Tools/Actions", GTK_UI_MANAGER_MENU)
1934         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/Actions", "PlaceHolder", "Tools/Actions/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1935         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator4", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1936
1937         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "CheckNewMessages", "Tools/CheckNewMessages", GTK_UI_MANAGER_MENUITEM)
1938         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "DeleteDuplicates", "Tools/DeleteDuplicates", GTK_UI_MANAGER_MENU)
1939         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/DeleteDuplicates", "SelFolder", "Tools/DeleteDuplicates/SelFolder", GTK_UI_MANAGER_MENUITEM)
1940         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools/DeleteDuplicates", "AllFolders", "Tools/DeleteDuplicates/AllFolders", GTK_UI_MANAGER_MENUITEM)
1941         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1942
1943         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Execute", "Tools/Execute", GTK_UI_MANAGER_MENUITEM)
1944         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Expunge", "Tools/Expunge", GTK_UI_MANAGER_MENUITEM)
1945 #ifdef USE_GNUTLS
1946         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator6", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1947         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "SSLCertificates", "Tools/SSLCertificates", GTK_UI_MANAGER_MENUITEM)
1948 #endif
1949         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator7", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1950 #ifndef G_OS_WIN32
1951         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilteringLog", "Tools/FilteringLog", GTK_UI_MANAGER_MENUITEM)
1952 #endif
1953         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "NetworkLog", "Tools/NetworkLog", GTK_UI_MANAGER_MENUITEM)
1954         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator8", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1955         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "ForgetSessionPasswords", "Tools/ForgetSessionPasswords", GTK_UI_MANAGER_MENUITEM)
1956         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator9", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
1957
1958 /* Configuration menu */
1959         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "ChangeAccount", "Configuration/ChangeAccount", GTK_UI_MANAGER_MENU)
1960         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration/ChangeAccount", "PlaceHolder", "Configuration/ChangeAccount/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
1961         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "AccountPrefs", "Configuration/AccountPrefs", GTK_UI_MANAGER_MENUITEM)
1962         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "CreateAccount", "Configuration/CreateAccount", GTK_UI_MANAGER_MENUITEM)
1963         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "EditAccounts", "Configuration/EditAccounts", GTK_UI_MANAGER_MENUITEM)
1964         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Separator1", "Configuration/---", GTK_UI_MANAGER_SEPARATOR)
1965
1966         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Preferences", "Configuration/Preferences", GTK_UI_MANAGER_MENUITEM)
1967         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "PreProcessing", "Configuration/PreProcessing", GTK_UI_MANAGER_MENUITEM)
1968         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "PostProcessing", "Configuration/PostProcessing", GTK_UI_MANAGER_MENUITEM)
1969         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Filtering", "Configuration/Filtering", GTK_UI_MANAGER_MENUITEM)
1970         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Templates", "Configuration/Templates", GTK_UI_MANAGER_MENUITEM)
1971         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Actions", "Configuration/Actions", GTK_UI_MANAGER_MENUITEM)
1972         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Tags", "Configuration/Tags", GTK_UI_MANAGER_MENUITEM)
1973
1974         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Separator2", "Configuration/---", GTK_UI_MANAGER_SEPARATOR)
1975         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Configuration", "Plugins", "Configuration/Plugins", GTK_UI_MANAGER_MENUITEM)
1976
1977 /* Help menu */
1978         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Manual", "Help/Manual", GTK_UI_MANAGER_MENUITEM)
1979         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "FAQ", "Help/FAQ", GTK_UI_MANAGER_MENUITEM)
1980         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "IconLegend", "Help/IconLegend", GTK_UI_MANAGER_MENUITEM)
1981 #ifdef G_OS_WIN32
1982         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator1", "Help/---", GTK_UI_MANAGER_SEPARATOR)
1983         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "SetDefault", "Help/SetDefault", GTK_UI_MANAGER_MENUITEM)
1984 #endif
1985         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "Separator2", "Help/---", GTK_UI_MANAGER_SEPARATOR)
1986         MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
1987
1988
1989         menubar = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu");
1990         gtk_widget_show_all(menubar);
1991         gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(mainwin->ui_manager));
1992
1993 #ifndef MAEMO
1994         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1995 #else
1996         hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
1997 #endif
1998
1999         if (prefs_common.toolbar_detachable) {
2000                 handlebox = gtk_handle_box_new();
2001                 gtk_widget_show(handlebox);
2002                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2003                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
2004                                  G_CALLBACK(toolbar_child_attached), mainwin);
2005                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
2006                                  G_CALLBACK(toolbar_child_detached), mainwin);
2007         } else {
2008                 handlebox = gtk_hbox_new(FALSE, 0);
2009                 gtk_widget_show(handlebox);
2010                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2011         }
2012         /* link window to mainwin->window to avoid gdk warnings */
2013         mainwin->window       = window;
2014         mainwin_list = g_list_append(mainwin_list, mainwin);
2015         
2016 #ifdef MAEMO
2017         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
2018                                           window, 
2019                                           (gpointer)mainwin);
2020 #else
2021         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
2022                                           handlebox, 
2023                                           (gpointer)mainwin);
2024 #endif
2025         toolbar_set_learn_button
2026                 (mainwin->toolbar,
2027                  LEARN_SPAM);
2028
2029         /* vbox that contains body */
2030         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
2031         gtk_widget_show(vbox_body);
2032         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
2033         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
2034
2035 #ifndef GENERIC_UMPC
2036         hbox_stat = gtk_hbox_new(FALSE, 2);
2037         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
2038
2039         warning_icon = gtk_image_new_from_stock
2040                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
2041         warning_btn = gtk_event_box_new();
2042         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
2043         
2044         mainwin->warning_btn      = warning_btn;
2045         
2046         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
2047                          G_CALLBACK(warning_icon_pressed),
2048                          (gpointer) mainwin);
2049         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
2050                          G_CALLBACK(warning_visi_notify), mainwin);
2051         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
2052                          G_CALLBACK(warning_leave_notify), mainwin);
2053         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
2054                          G_CALLBACK(warning_enter_notify), mainwin);
2055
2056         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
2057
2058         CLAWS_SET_TIP(warning_btn, 
2059                              _("Some error(s) happened. Click here to view log."));
2060         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
2061
2062         statusbar = statusbar_create();
2063         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
2064
2065         progressbar = gtk_progress_bar_new();
2066         gtk_widget_set_size_request(progressbar, 120, 1);
2067         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
2068
2069         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
2070         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
2071         online_switch = gtk_button_new ();
2072         gtkut_widget_set_can_focus(online_switch, FALSE);
2073         CLAWS_SET_TIP(online_switch, 
2074                              _("You are online. Click the icon to go offline"));
2075         offline_switch = gtk_button_new ();
2076         CLAWS_SET_TIP(offline_switch, 
2077                              _("You are offline. Click the icon to go online"));
2078         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
2079         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
2080         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
2081         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
2082         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
2083         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
2084         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
2085         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
2086         
2087         statuslabel = gtk_label_new("");
2088         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
2089
2090         ac_button = gtk_button_new();
2091         CLAWS_SET_TIP(ac_button, _("Select account"));
2092         gtkut_widget_set_can_focus(ac_button, FALSE);
2093         gtk_widget_set_size_request(ac_button, -1, 0);
2094         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
2095         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
2096                          G_CALLBACK(ac_label_button_pressed), mainwin);
2097
2098         ac_label = gtk_label_new("");
2099         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
2100
2101         gtk_widget_show_all(hbox_stat);
2102
2103         gtk_widget_hide(offline_switch);
2104         gtk_widget_hide(progressbar);
2105         gtk_widget_hide(warning_btn);
2106 #else
2107         online_switch = gtk_button_new ();
2108         offline_switch = gtk_button_new ();
2109         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
2110         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
2111 #endif
2112         /* create views */
2113         mainwin->folderview  = folderview  = folderview_create();
2114         mainwin->summaryview = summaryview = summary_create(mainwin);
2115         mainwin->messageview = messageview = messageview_create(mainwin);
2116
2117         /* init log instances data before creating log views */
2118         set_log_title(LOG_PROTOCOL, _("Network log"));
2119         set_log_prefs(LOG_PROTOCOL,
2120                         &prefs_common.logwin_width,
2121                         &prefs_common.logwin_height);
2122         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
2123         set_log_prefs(LOG_DEBUG_FILTERING,
2124                         &prefs_common.filtering_debugwin_width,
2125                         &prefs_common.filtering_debugwin_height);
2126
2127         /* setup log windows */
2128         mainwin->logwin = log_window_create(LOG_PROTOCOL);
2129         log_window_init(mainwin->logwin);
2130
2131         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
2132         log_window_set_clipping(mainwin->logwin,
2133                                 prefs_common.cliplog,
2134                                 prefs_common.loglength);
2135
2136         log_window_init(mainwin->filtering_debugwin);
2137         log_window_set_clipping(mainwin->filtering_debugwin,
2138                                 prefs_common.filtering_debug_cliplog,
2139                                 prefs_common.filtering_debug_loglength);
2140         if (prefs_common.enable_filtering_debug)
2141                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
2142         else
2143                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
2144
2145         folderview->mainwin      = mainwin;
2146         folderview->summaryview  = summaryview;
2147
2148         summaryview->mainwin     = mainwin;
2149         summaryview->folderview  = folderview;
2150         summaryview->messageview = messageview;
2151         summaryview->window      = window;
2152
2153         mainwin->vbox           = vbox;
2154         mainwin->menubar        = menubar;
2155         mainwin->handlebox      = handlebox;
2156         mainwin->vbox_body      = vbox_body;
2157         mainwin->online_switch  = online_switch;
2158         mainwin->offline_switch    = offline_switch;
2159 #ifndef GENERIC_UMPC
2160         messageview->statusbar  = statusbar;
2161         mainwin->statusbar      = statusbar;
2162         mainwin->hbox_stat      = hbox_stat;
2163         mainwin->progressbar    = progressbar;
2164         mainwin->statuslabel    = statuslabel;
2165         mainwin->online_pixmap  = online_pixmap;
2166         mainwin->offline_pixmap = offline_pixmap;
2167         mainwin->ac_button      = ac_button;
2168         mainwin->ac_label       = ac_label;
2169         /* set context IDs for status bar */
2170         mainwin->mainwin_cid = gtk_statusbar_get_context_id
2171                 (GTK_STATUSBAR(statusbar), "Main Window");
2172         mainwin->folderview_cid = gtk_statusbar_get_context_id
2173                 (GTK_STATUSBAR(statusbar), "Folder View");
2174         mainwin->summaryview_cid = gtk_statusbar_get_context_id
2175                 (GTK_STATUSBAR(statusbar), "Summary View");
2176         mainwin->messageview_cid = gtk_statusbar_get_context_id
2177                 (GTK_STATUSBAR(statusbar), "Message View");
2178         messageview->statusbar_cid = mainwin->messageview_cid;
2179
2180 #else
2181         messageview->statusbar  = NULL;
2182         mainwin->statusbar      = NULL;
2183         mainwin->hbox_stat      = NULL;
2184         /* mainwin->progressbar is set in toolbar.c */
2185         mainwin->statuslabel    = NULL;
2186         mainwin->online_pixmap  = NULL;
2187         mainwin->offline_pixmap = NULL;
2188         mainwin->ac_button      = NULL;
2189         mainwin->ac_label       = NULL;
2190 #endif
2191         
2192         /* allocate colors for summary view and folder view */
2193         summaryview->color_marked.red = summaryview->color_marked.green = 0;
2194         summaryview->color_marked.blue = (guint16)65535;
2195
2196         summaryview->color_dim.red = summaryview->color_dim.green =
2197                 summaryview->color_dim.blue = COLOR_DIM;
2198
2199         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
2200                                        &folderview->color_new);
2201
2202         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
2203                                        &folderview->color_op);
2204
2205         summaryview->color_important.red = 0;
2206         summaryview->color_important.green = 0;
2207         summaryview->color_important.blue = (guint16)65535;
2208
2209         color[0] = summaryview->color_marked;
2210         color[1] = summaryview->color_dim;
2211         color[2] = folderview->color_new;
2212         color[3] = folderview->color_op;
2213
2214 #if !GTK_CHECK_VERSION(3, 0, 0)
2215         colormap = gdk_drawable_get_colormap(gtk_widget_get_window(window));
2216         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
2217         for (i = 0; i < 4; i++) {
2218                 if (success[i] == FALSE)
2219                         g_warning("MainWindow: color allocation %d failed\n", i);
2220         }
2221 #endif
2222
2223         debug_print("done.\n");
2224
2225         messageview->visible = prefs_common.msgview_visible;
2226
2227         main_window_set_widgets(mainwin, prefs_common.layout_mode);
2228
2229         g_signal_connect(G_OBJECT(window), "size_allocate",
2230                          G_CALLBACK(main_window_size_allocate_cb),
2231                          mainwin);
2232
2233         /* set menu items */
2234         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Encoding/"CS_AUTO, TRUE);
2235
2236         menuitem = NULL;
2237         switch (prefs_common.toolbar_style) {
2238         case TOOLBAR_NONE:
2239                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/Hide");
2240                 break;
2241         case TOOLBAR_ICON:
2242                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/IconOnly");
2243                 break;
2244         case TOOLBAR_TEXT:
2245                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextOnly");
2246                 break;
2247         case TOOLBAR_BOTH:
2248                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextBelowIcon");
2249                 break;
2250         case TOOLBAR_BOTH_HORIZ:
2251                 menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/Toolbar/TextBesideIcon");
2252         }
2253         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2254
2255         toolbar_set_style(mainwin->toolbar->toolbar, 
2256                           mainwin->handlebox, 
2257                           prefs_common.toolbar_style);
2258 #ifndef GENERIC_UMPC
2259         gtk_widget_hide(mainwin->hbox_stat);
2260         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/StatusBar");
2261         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2262                                        prefs_common.show_statusbar);
2263 #endif  
2264         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/View/ShowHide/ColumnHeaders");
2265         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2266                                        prefs_common.show_col_headers);
2267         /* set account selection menu */
2268         ac_menu = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Configuration/ChangeAccount");
2269         mainwin->ac_menu = ac_menu;
2270
2271         toolbar_main_set_sensitive(mainwin);
2272
2273         /* create actions menu */
2274         main_window_update_actions_menu(mainwin);
2275
2276         main_create_mailing_list_menu (mainwin, NULL);
2277
2278         /* attach accel groups to main window */
2279 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
2280         gtk_window_add_accel_group                                      \
2281                 (GTK_WINDOW(win),                                       \
2282                  gtk_ui_manager_get_accel_group(gtkut_ui_manager()));   \
2283         g_signal_connect(G_OBJECT(gtk_ui_manager_get_accel_group(gtkut_ui_manager())), \
2284                         "accel_activate",                               \
2285                         G_CALLBACK(main_window_accel_activate), mainwin);
2286
2287         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
2288         
2289         g_signal_connect(G_OBJECT(window), "window_state_event",
2290                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
2291         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
2292                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
2293         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
2294
2295         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
2296             prefs_common.layout_mode == SMALL_LAYOUT) {
2297                 summary_relayout(mainwin->summaryview); 
2298         }
2299         summary_update_unread(mainwin->summaryview, NULL);
2300         
2301         /* initialize views */
2302         folderview_init(folderview);
2303         summary_init(summaryview);
2304         messageview_init(messageview);
2305 #ifdef USE_GNUTLS
2306         sslcertwindow_register_hook();
2307 #endif
2308         mainwin->lock_count = 0;
2309         mainwin->menu_lock_count = 0;
2310         mainwin->cursor_count = 0;
2311
2312         mainwin->progressindicator_hook =
2313                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
2314
2315         if (!watch_cursor)
2316                 watch_cursor = gdk_cursor_new(GDK_WATCH);
2317         if (!hand_cursor)
2318                 hand_cursor = gdk_cursor_new(GDK_HAND2);
2319
2320         /* init work_offline */
2321         if (prefs_common.work_offline)
2322                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
2323
2324         mainwindow_colorlabel_menu_create(mainwin, FALSE);
2325         mainwindow_tags_menu_create(mainwin, FALSE);
2326
2327 #ifdef MAEMO
2328         main_window_install_maemo_hooks(mainwin);
2329 #endif
2330 #ifndef MAEMO
2331         if (prefs_common.mainwin_fullscreen) {
2332                 cm_toggle_menu_set_active_full(mainwin->ui_manager, 
2333                         "Menu/View/FullScreen",
2334                         TRUE);
2335         }
2336 #endif
2337         return mainwin;
2338 }
2339
2340 void main_window_update_actions_menu(MainWindow *mainwin)
2341 {
2342         action_update_mainwin_menu(mainwin->ui_manager, "/Menu/Tools/Actions", mainwin);
2343 }
2344
2345 void main_window_cursor_wait(MainWindow *mainwin)
2346 {
2347
2348         if (mainwin->cursor_count == 0) {
2349                 gdk_window_set_cursor(gtk_widget_get_window(mainwin->window), watch_cursor);
2350                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
2351         }
2352         
2353         mainwin->cursor_count++;
2354
2355         gdk_flush();
2356 }
2357
2358 void main_window_cursor_normal(MainWindow *mainwin)
2359 {
2360         if (mainwin->cursor_count)
2361                 mainwin->cursor_count--;
2362
2363         if (mainwin->cursor_count == 0) {
2364                 gdk_window_set_cursor(gtk_widget_get_window(mainwin->window), NULL);
2365                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
2366         }
2367         gdk_flush();
2368 }
2369
2370 /* lock / unlock the user-interface */
2371 void main_window_lock(MainWindow *mainwin)
2372 {
2373         if (mainwin->lock_count == 0 && mainwin->ac_button)
2374                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
2375
2376         mainwin->lock_count++;
2377
2378         main_window_set_menu_sensitive(mainwin);
2379         toolbar_main_set_sensitive(mainwin);
2380 }
2381
2382 void main_window_unlock(MainWindow *mainwin)
2383 {
2384         if (mainwin->lock_count)
2385                 mainwin->lock_count--;
2386
2387         main_window_set_menu_sensitive(mainwin);
2388         toolbar_main_set_sensitive(mainwin);
2389
2390         if (mainwin->lock_count == 0 && mainwin->ac_button)
2391                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
2392 }
2393
2394 static void main_window_menu_callback_block(MainWindow *mainwin)
2395 {
2396         mainwin->menu_lock_count++;
2397 }
2398
2399 static void main_window_menu_callback_unblock(MainWindow *mainwin)
2400 {
2401         if (mainwin->menu_lock_count)
2402                 mainwin->menu_lock_count--;
2403 }
2404
2405 static guint prefs_tag = 0;
2406
2407 void main_window_reflect_prefs_all(void)
2408 {
2409         main_window_reflect_prefs_all_real(FALSE);
2410 }
2411
2412 static gboolean reflect_prefs_timeout_cb(gpointer data) 
2413 {
2414         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
2415         GList *cur;
2416         MainWindow *mainwin;
2417 #ifndef GENERIC_UMPC
2418         GtkWidget *pixmap;
2419 #endif
2420         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2421                 mainwin = (MainWindow *)cur->data;
2422
2423                 main_window_show_cur_account(mainwin);
2424                 main_window_set_menu_sensitive(mainwin);
2425                 toolbar_main_set_sensitive(mainwin);
2426
2427                 /* pixmap themes */
2428                 if (pixmap_theme_changed) {
2429                         toolbar_update(TOOLBAR_MAIN, mainwin);
2430                         messageview_reflect_prefs_pixmap_theme();
2431                         compose_reflect_prefs_pixmap_theme();
2432                         folderview_reinit_fonts(mainwin->folderview);
2433                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
2434                         foldersel_reflect_prefs_pixmap_theme();
2435                         addressbook_reflect_prefs_pixmap_theme();
2436 #ifndef GENERIC_UMPC
2437                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
2438                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
2439                                              mainwin->online_pixmap);
2440                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
2441                         gtk_widget_show(pixmap);
2442                         mainwin->online_pixmap = pixmap;
2443                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
2444                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
2445                                              mainwin->offline_pixmap);
2446                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
2447                         gtk_widget_show(pixmap);
2448                         mainwin->offline_pixmap = pixmap;
2449 #endif
2450                         hooks_invoke(THEME_CHANGED_HOOKLIST, NULL);
2451                 }
2452                 
2453                 headerview_set_font(mainwin->messageview->headerview);
2454                 headerview_set_visibility(mainwin->messageview->headerview,
2455                                           prefs_common.display_header_pane);
2456                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
2457                 folderview_reflect_prefs();
2458                 summary_reflect_prefs();
2459 #ifndef GENERIC_UMPC
2460                 summary_redisplay_msg(mainwin->summaryview);
2461 #endif
2462                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2463                         if (mainwin->in_folder) {
2464                                 mainwindow_enter_folder(mainwin);
2465                         } else {
2466                                 mainwindow_exit_folder(mainwin);
2467                         }
2468                 }
2469         }
2470         prefs_tag = 0;
2471         return FALSE;
2472 }
2473
2474 void main_window_reflect_prefs_all_now(void)
2475 {
2476         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
2477 }
2478
2479 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
2480 {
2481         GtkMenuShell *menu;
2482         GList *children, *cur;
2483
2484         /* re-create colorlabel submenu */
2485         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
2486         cm_return_if_fail(menu != NULL);
2487
2488         /* clear items. get item pointers. */
2489         children = gtk_container_get_children(GTK_CONTAINER(menu));
2490         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2491                 g_signal_handlers_disconnect_matched
2492                          (gtk_ui_manager_get_accel_group(mainwin->ui_manager), 
2493                          G_SIGNAL_MATCH_DATA|G_SIGNAL_MATCH_FUNC,
2494                          0, 0, NULL, mainwin_accel_changed_cb, cur->data);
2495                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2496         }
2497         g_list_free(children);
2498         mainwindow_colorlabel_menu_create(mainwin, TRUE);
2499         summary_reflect_prefs_custom_colors(mainwin->summaryview);
2500         folderview_reinit_fonts(mainwin->folderview);
2501 }
2502
2503 static gint tags_tag = 0;
2504 static gboolean main_window_reflect_tags_changes_real(gpointer data)
2505 {
2506         GtkMenuShell *menu;
2507         GList *children, *cur;
2508         MainWindow *mainwin = (MainWindow *)data;
2509
2510         if (summary_is_locked(mainwin->summaryview)) {
2511                 tags_tag = 0;
2512                 return TRUE;
2513         }
2514         /* re-create tags submenu */
2515         menu = GTK_MENU_SHELL(mainwin->tags_menu);
2516         cm_return_val_if_fail(menu != NULL, FALSE);
2517
2518         /* clear items. get item pointers. */
2519         children = gtk_container_get_children(GTK_CONTAINER(menu));
2520         for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2521                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2522         }
2523         g_list_free(children);
2524         mainwindow_tags_menu_create(mainwin, TRUE);
2525         summary_reflect_tags_changes(mainwin->summaryview);
2526         
2527         tags_tag = 0;
2528         return FALSE;
2529 }
2530
2531 void main_window_reflect_tags_changes(MainWindow *mainwin)
2532 {
2533         if (tags_tag == 0) {
2534                 tags_tag = g_timeout_add(100, main_window_reflect_tags_changes_real, 
2535                                                 mainwin);
2536         }
2537 }
2538
2539 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
2540 {
2541         if (prefs_tag == 0) {
2542                 prefs_tag = g_timeout_add(100, reflect_prefs_timeout_cb, 
2543                                                 GINT_TO_POINTER(pixmap_theme_changed));
2544         }
2545 }
2546
2547 void main_window_set_summary_column(void)
2548 {
2549         GList *cur;
2550         MainWindow *mainwin;
2551
2552         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2553                 mainwin = (MainWindow *)cur->data;
2554                 summary_set_column_order(mainwin->summaryview);
2555         }
2556 }
2557
2558 void main_window_set_folder_column(void)
2559 {
2560         GList *cur;
2561         MainWindow *mainwin;
2562
2563         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2564                 mainwin = (MainWindow *)cur->data;
2565                 folderview_set_column_order(mainwin->folderview);
2566         }
2567 }
2568
2569 static void main_window_set_account_selector_menu(MainWindow *mainwin,
2570                                                   GList *account_list)
2571 {
2572         GList *cur_ac;
2573         GtkWidget *menuitem;
2574         PrefsAccount *ac_prefs;
2575         GtkWidget *menu;
2576         gchar *accel_path;
2577
2578         menu = gtk_menu_new();
2579         gtk_menu_set_accel_group (GTK_MENU (menu), 
2580                 gtk_ui_manager_get_accel_group(mainwin->ui_manager));
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_selector_menu_cb),
2592                                  ac_prefs);
2593                 accel_path = g_strconcat("<Actions>/Menu/Configuration/ChangeAccount/",(ac_prefs->account_name
2594                          ? ac_prefs->account_name : _("Untitled")), NULL );
2595                 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), accel_path);
2596                 g_free(accel_path);
2597         }
2598         gtk_menu_item_set_submenu(GTK_MENU_ITEM(mainwin->ac_menu), menu);
2599 }
2600
2601 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2602                                                  GList *account_list)
2603 {
2604         GList *children, *child;
2605         GtkWidget *menu;
2606         GtkWidget *menuitem;
2607         PrefsAccount *ac_prefs;
2608
2609         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
2610                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive")));
2611
2612         /* search for separator */
2613         children = gtk_container_get_children(GTK_CONTAINER(menu));
2614         for (child = children; child != NULL; child = child->next) {
2615                 if (child->data == gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive/Separator1")) {
2616                         child = child->next;
2617                         break;
2618                 }
2619         }
2620
2621         /* destroy all previous menu item */
2622         while (child != NULL) {
2623                 gtk_widget_destroy(GTK_WIDGET(child->data));
2624                 child = child->next;
2625         }
2626
2627         g_list_free(children);
2628
2629         for (child = account_list; child != NULL; child = child->next) {
2630                 ac_prefs = (PrefsAccount *)child->data;
2631
2632                 if (ac_prefs->protocol == A_NONE)
2633                         continue;
2634
2635                 menuitem = gtk_menu_item_new_with_label
2636                         (ac_prefs->account_name ? ac_prefs->account_name
2637                          : _("Untitled"));
2638                 gtk_widget_show(menuitem);
2639                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2640                 g_signal_connect(G_OBJECT(menuitem), "activate",
2641                                  G_CALLBACK(account_receive_menu_cb),
2642                                  ac_prefs);
2643         }
2644 }
2645
2646 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2647                                                        GList *account_list)
2648 {
2649         GList *cur_ac;
2650         GtkWidget *menuitem;
2651         PrefsAccount *ac_prefs;
2652         GtkWidget *menu = NULL;
2653
2654         if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2655                 return;
2656
2657         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2658         if (menu)
2659                 gtk_widget_destroy(menu);
2660         menu = gtk_menu_new();
2661
2662         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2663                 ac_prefs = (PrefsAccount *)cur_ac->data;
2664
2665                 if (ac_prefs->protocol == A_NONE)
2666                         continue;
2667
2668                 menuitem = gtk_menu_item_new_with_label
2669                         (ac_prefs->account_name
2670                          ? ac_prefs->account_name : _("Untitled"));
2671                 gtk_widget_show(menuitem);
2672                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2673                 g_signal_connect(G_OBJECT(menuitem), "activate",
2674                                  G_CALLBACK(account_receive_menu_cb),
2675                                  ac_prefs);
2676         }
2677         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2678 }
2679
2680 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2681                                                        GList *account_list)
2682 {
2683 #ifndef GENERIC_UMPC
2684         GList *cur_ac;
2685         GtkWidget *menuitem;
2686         PrefsAccount *ac_prefs;
2687         GtkWidget *menu = NULL;
2688
2689         if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2690                 return;
2691
2692         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2693         if (menu)
2694                 gtk_widget_destroy(menu);
2695         menu = gtk_menu_new();
2696
2697         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2698                 ac_prefs = (PrefsAccount *)cur_ac->data;
2699
2700                 menuitem = gtk_menu_item_new_with_label
2701                         (ac_prefs->account_name
2702                          ? ac_prefs->account_name : _("Untitled"));
2703                 gtk_widget_show(menuitem);
2704                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
2705                 g_signal_connect(G_OBJECT(menuitem), "activate",
2706                                  G_CALLBACK(account_compose_menu_cb),
2707                                  ac_prefs);
2708         }
2709         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2710 #endif
2711 }
2712
2713 void main_window_set_account_menu(GList *account_list)
2714 {
2715         GList *cur;
2716         MainWindow *mainwin;
2717
2718         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2719                 mainwin = (MainWindow *)cur->data;
2720                 main_window_set_account_selector_menu(mainwin, account_list);
2721                 main_window_set_account_receive_menu(mainwin, account_list);
2722                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2723                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2724         }
2725         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2726 }
2727
2728 void main_window_set_account_menu_only_toolbar(GList *account_list)
2729 {
2730         GList *cur;
2731         MainWindow *mainwin;
2732
2733         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2734                 mainwin = (MainWindow *)cur->data;
2735                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2736                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2737         }
2738 }
2739
2740 static void main_window_show_cur_account(MainWindow *mainwin)
2741 {
2742         gchar *buf;
2743         gchar *ac_name;
2744
2745         ac_name = g_strdup(cur_account
2746                            ? (cur_account->account_name
2747                               ? cur_account->account_name : _("Untitled"))
2748                            : _("none"));
2749
2750         if (cur_account)
2751                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2752         else
2753                 buf = g_strdup(PROG_VERSION);
2754         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2755         g_free(buf);
2756
2757         if (mainwin->ac_label)
2758                 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2759         if (mainwin->ac_button)
2760                 gtk_widget_queue_resize(mainwin->ac_button);
2761
2762         g_free(ac_name);
2763 }
2764 #ifndef GENERIC_UMPC
2765 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2766 {
2767         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2768         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2769         GtkWidget *message_wid = mainwin->messageview->vbox;
2770
2771         if (layout_mode == prefs_common.layout_mode) 
2772                 return;
2773
2774         debug_print("Changing window separation type from %d to %d\n",
2775                     prefs_common.layout_mode, layout_mode);
2776
2777         /* remove widgets from those containers */
2778         g_object_ref(folder_wid);
2779         g_object_ref(summary_wid);
2780         g_object_ref(message_wid);
2781         gtkut_container_remove
2782                 (GTK_CONTAINER(gtk_widget_get_parent(folder_wid)), folder_wid);
2783         gtkut_container_remove
2784                 (GTK_CONTAINER(gtk_widget_get_parent(summary_wid)), summary_wid);
2785         gtkut_container_remove
2786                 (GTK_CONTAINER(gtk_widget_get_parent(message_wid)), message_wid);
2787
2788         gtk_widget_hide(mainwin->window);
2789         main_window_set_widgets(mainwin, layout_mode);
2790         gtk_widget_show(mainwin->window);
2791
2792         g_object_unref(folder_wid);
2793         g_object_unref(summary_wid);
2794         g_object_unref(message_wid);
2795 }
2796 #endif
2797 void mainwindow_reset_paned(GtkPaned *paned)
2798 {
2799                 gint min, max, mid;
2800
2801                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2802                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2803                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2804                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2805
2806 GTK_EVENTS_FLUSH();
2807                 g_object_get (G_OBJECT(paned),
2808                                 "min-position",
2809                                 &min, NULL);
2810                 g_object_get (G_OBJECT(paned),
2811                                 "max-position",
2812                                 &max, NULL);
2813                 mid = (min+max)/2;
2814                 gtk_paned_set_position(GTK_PANED(paned), mid);
2815 }
2816
2817 static void mainwin_paned_show_first(GtkPaned *paned)
2818 {
2819                 gint max;
2820                 g_object_get (G_OBJECT(paned),
2821                                 "max-position",
2822                                 &max, NULL);
2823
2824                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2825                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2826                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2827                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2828                 gtk_paned_set_position(GTK_PANED(paned), max);
2829 }
2830
2831 static void mainwin_paned_show_last(GtkPaned *paned)
2832 {
2833                 gint min;
2834                 g_object_get (G_OBJECT(paned),
2835                                 "min-position",
2836                                 &min, NULL);
2837
2838                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2839                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2840                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2841                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2842                 gtk_paned_set_position(GTK_PANED(paned), min);
2843 }
2844
2845 void main_window_toggle_message_view(MainWindow *mainwin)
2846 {
2847         SummaryView *summaryview = mainwin->summaryview;
2848         GtkWidget *ppaned = NULL;
2849         GtkWidget *container = NULL;
2850
2851         switch (prefs_common.layout_mode) {
2852         case NORMAL_LAYOUT:
2853         case VERTICAL_LAYOUT:
2854         case SMALL_LAYOUT:
2855                 ppaned = mainwin->vpaned;
2856                 container = mainwin->hpaned;
2857                 if (gtk_widget_get_parent(ppaned) != NULL) {
2858                         mainwin->messageview->visible = FALSE;
2859                         summaryview->displayed = NULL;
2860                         g_object_ref(ppaned);
2861                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2862                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2863                 } else {
2864                         mainwin->messageview->visible = TRUE;
2865                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2866                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2867                         g_object_unref(ppaned);
2868                 }
2869                 break;
2870         case WIDE_LAYOUT:
2871                 ppaned = mainwin->hpaned;
2872                 container = mainwin->vpaned;
2873                 if (gtk_widget_get_parent(mainwin->messageview->vbox) != NULL) {
2874                         mainwin->messageview->visible = FALSE;
2875                         summaryview->displayed = NULL;
2876                         g_object_ref(mainwin->messageview->vbox);
2877                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2878                 } else {
2879                         mainwin->messageview->visible = TRUE;
2880                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2881                         g_object_unref(mainwin->messageview->vbox);
2882                 }
2883                 break;
2884         case WIDE_MSGLIST_LAYOUT:
2885                 g_warning("can't hide messageview in this wide msglist layout");
2886                 break;
2887         }
2888
2889         if (messageview_is_visible(mainwin->messageview))
2890                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2891                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2892         else
2893                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2894                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2895
2896         if (mainwin->messageview->visible == FALSE)
2897                 messageview_clear(mainwin->messageview);
2898
2899         main_window_set_menu_sensitive(mainwin);
2900
2901         prefs_common.msgview_visible = mainwin->messageview->visible;
2902
2903         if (messageview_is_visible(mainwin->messageview)) {
2904                 gtk_widget_queue_resize(mainwin->hpaned);
2905                 gtk_widget_queue_resize(mainwin->vpaned);
2906         }
2907         summary_grab_focus(summaryview);
2908         if (!summary_is_list(summaryview)) {
2909                 summary_show(summaryview, summaryview->folder_item);
2910         }
2911 }
2912
2913 void main_window_get_size(MainWindow *mainwin)
2914 {
2915         GtkAllocation allocation;
2916
2917         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2918                 debug_print("called after messageview "
2919                             "has been deallocated!\n");
2920                 return;
2921         }
2922
2923         if (prefs_common.mainwin_fullscreen) {
2924                 debug_print("mainwin in full screen state. "
2925                             "Keeping original settings\n");
2926         }
2927
2928         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->summaryview), &allocation);
2929         if (allocation.width > 1 && allocation.height > 1 && !prefs_common.mainwin_fullscreen) {
2930                 prefs_common.summaryview_width = allocation.width;
2931
2932                 if (messageview_is_visible(mainwin->messageview))
2933                         prefs_common.summaryview_height = allocation.height;
2934
2935                 prefs_common.mainview_width = allocation.width;
2936         }
2937
2938         gtk_widget_get_allocation(mainwin->window, &allocation);
2939         if (allocation.width > 1 && allocation.height > 1 &&
2940             !prefs_common.mainwin_maximised && !prefs_common.mainwin_fullscreen) {
2941                 prefs_common.mainview_height = allocation.height;
2942                 prefs_common.mainwin_width   = allocation.width;
2943                 prefs_common.mainwin_height  = allocation.height;
2944         }
2945
2946         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->folderview), &allocation);
2947         if (allocation.width > 1 && allocation.height > 1 &&
2948             !prefs_common.mainwin_fullscreen) {
2949                 prefs_common.folderview_width  = allocation.width;
2950                 prefs_common.folderview_height = allocation.height;
2951         }
2952         
2953         gtk_widget_get_allocation(GTK_WIDGET_PTR(mainwin->messageview), &allocation);
2954         if (allocation.width > 1 && allocation.height > 1 &&
2955             !prefs_common.mainwin_fullscreen) {
2956                 prefs_common.msgview_width = allocation.width;
2957                 prefs_common.msgview_height = allocation.height;
2958         }
2959
2960 /*      debug_print("summaryview size: %d x %d\n",
2961                     prefs_common.summaryview_width,
2962                     prefs_common.summaryview_height);
2963         debug_print("folderview size: %d x %d\n",
2964                     prefs_common.folderview_width,
2965                     prefs_common.folderview_height);
2966         debug_print("messageview size: %d x %d\n",
2967                     prefs_common.msgview_width,
2968                     prefs_common.msgview_height); */
2969 }
2970
2971 void main_window_get_position(MainWindow *mainwin)
2972 {
2973         gint x, y;
2974
2975         if (prefs_common.mainwin_maximised || prefs_common.mainwin_fullscreen)
2976                 return;
2977
2978         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2979
2980         prefs_common.mainview_x = x;
2981         prefs_common.mainview_y = y;
2982         prefs_common.mainwin_x = x;
2983         prefs_common.mainwin_y = y;
2984
2985         debug_print("main window position: %d, %d\n", x, y);
2986 }
2987
2988 void main_window_progress_on(MainWindow *mainwin)
2989 {
2990         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2991 }
2992
2993 void main_window_progress_off(MainWindow *mainwin)
2994 {
2995         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2996         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2997 }
2998
2999 gboolean main_window_empty_trash(MainWindow *mainwin, gboolean confirm, gboolean for_quit)
3000 {
3001         if (confirm && procmsg_have_trashed_mails_fast()) {
3002                 AlertValue val;
3003                 
3004                 if (for_quit)
3005                         val = alertpanel(_("Empty trash"),
3006                                _("Delete all messages in trash folders?"),
3007                                GTK_STOCK_NO, "+" GTK_STOCK_YES, _("Don't quit"));
3008                 else
3009                         val = alertpanel(_("Empty trash"),
3010                                _("Delete all messages in trash folders?"),
3011                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
3012                 if (val == G_ALERTALTERNATE) {
3013                         debug_print("will empty trash\n");
3014                 } else if (val == G_ALERTDEFAULT) {
3015                         debug_print("will not empty trash\n");
3016                         return TRUE;
3017                 } else {
3018                         return FALSE; /* cancel exit */
3019                 }
3020                 manage_window_focus_in(mainwin->window, NULL, NULL);
3021         }
3022
3023         procmsg_empty_all_trash();
3024
3025         if (mainwin->summaryview->folder_item &&
3026             mainwin->summaryview->folder_item->stype == F_TRASH)
3027                 gtk_widget_grab_focus(mainwin->folderview->ctree);
3028         return TRUE;
3029 }
3030
3031 static void main_window_add_mailbox(MainWindow *mainwin)
3032 {
3033         gchar *path;
3034         Folder *folder;
3035
3036         path = input_dialog(_("Add mailbox"),
3037                             _("Input the location of mailbox.\n"
3038                               "If an existing mailbox is specified, it will be\n"
3039                               "scanned automatically."),
3040                             "Mail");
3041         if (!path) return;
3042         if (folder_find_from_path(path)) {
3043                 alertpanel_error(_("The mailbox '%s' already exists."), path);
3044                 g_free(path);
3045                 return;
3046         }
3047         folder = folder_new(folder_get_class_from_string("mh"), 
3048                             !strcmp(path, "Mail") ? _("Mailbox") : 
3049                             g_path_get_basename(path), path);
3050         g_free(path);
3051
3052         if (folder->klass->create_tree(folder) < 0) {
3053                 alertpanel_error(_("Creation of the mailbox failed.\n"
3054                                    "Maybe some files already exist, or you don't have the permission to write there."));
3055                 folder_destroy(folder);
3056                 return;
3057         }
3058
3059         folder_add(folder);
3060         folder_set_ui_func(folder, scan_tree_func, mainwin);
3061         folder_scan_tree(folder, TRUE);
3062         folder_set_ui_func(folder, NULL, NULL);
3063 }
3064
3065 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
3066 {
3067         SensitiveCond state = 0;
3068         SummarySelection selection;
3069         FolderItem *item = mainwin->summaryview->folder_item;
3070         GList *account_list = account_get_list();
3071         GSList *tmp;
3072         
3073         selection = summary_get_selection_type(mainwin->summaryview);
3074
3075         if (mainwin->lock_count == 0 && !claws_is_starting())
3076                 state |= M_UNLOCKED;
3077         if (selection != SUMMARY_NONE)
3078                 state |= M_MSG_EXIST;
3079         if (item && item->path && folder_item_parent(item) && !item->no_select) {
3080                 state |= M_EXEC;
3081                 /*              if (item->folder->type != F_NEWS) */
3082                 state |= M_ALLOW_DELETE;
3083
3084                 if (prefs_common.immediate_exec == 0
3085                     && mainwin->lock_count == 0)
3086                         state |= M_DELAY_EXEC;
3087
3088                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
3089                     || selection != SUMMARY_NONE)
3090                         state |= M_HIDE_READ_MSG;
3091
3092                 if ((selection == SUMMARY_NONE && item->hide_read_threads)
3093                     || selection != SUMMARY_NONE)
3094                         state |= M_HIDE_READ_THREADS;
3095         }               
3096         if (mainwin->summaryview->threaded)
3097                 state |= M_THREADED;
3098         else
3099                 state |= M_UNTHREADED;  
3100         if (selection == SUMMARY_SELECTED_SINGLE ||
3101             selection == SUMMARY_SELECTED_MULTIPLE)
3102                 state |= M_TARGET_EXIST;
3103         if (selection == SUMMARY_SELECTED_SINGLE)
3104                 state |= M_SINGLE_TARGET_EXIST;
3105         if (mainwin->summaryview->folder_item &&
3106             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
3107                 state |= M_NEWS;
3108         else
3109                 state |= M_NOT_NEWS;
3110         if (mainwin->summaryview->folder_item &&
3111             (mainwin->summaryview->folder_item->stype != F_TRASH ||
3112              !folder_has_parent_of_type(mainwin->summaryview->folder_item, F_TRASH)))
3113                 state |= M_NOT_TRASH;
3114
3115         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
3116                 state |= M_ACTIONS_EXIST;
3117
3118         tmp = tags_get_list();
3119         if (tmp && g_slist_length(tmp))
3120                 state |= M_TAGS_EXIST;
3121         g_slist_free(tmp);
3122
3123         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
3124                 state |= M_HAVE_QUEUED_MAILS;
3125
3126         if (selection == SUMMARY_SELECTED_SINGLE &&
3127             (item &&
3128              (folder_has_parent_of_type(item, F_DRAFT) ||
3129               folder_has_parent_of_type(item, F_OUTBOX) ||
3130               folder_has_parent_of_type(item, F_QUEUE))))
3131                 state |= M_ALLOW_REEDIT;
3132         if (cur_account)
3133                 state |= M_HAVE_ACCOUNT;
3134         
3135         if (cur_account && cur_account->protocol != A_NONE)
3136                 state |= M_HAVE_RETRIEVABLE_ACCOUNT;
3137
3138         if (any_folder_want_synchronise())
3139                 state |= M_WANT_SYNC;
3140
3141         if (item && item->prefs->processing && selection != SUMMARY_NONE)
3142                 state |= M_HAVE_PROCESSING;
3143
3144         if (g_list_length(account_list) > 1)
3145                 state |= M_HAVE_MULTI_ACCOUNT;
3146
3147         for ( ; account_list != NULL; account_list = account_list->next) {
3148                 if (((PrefsAccount*)account_list->data)->protocol != A_NONE) {
3149                         state |= M_HAVE_ANY_RETRIEVABLE_ACCOUNT;
3150                         break;
3151                 }
3152         }
3153
3154         for ( ; account_list != NULL; account_list = account_list->next) {
3155                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
3156                         state |= M_HAVE_NEWS_ACCOUNT;
3157                         break;
3158                 }
3159         }
3160         
3161         if (procmsg_spam_can_learn() &&
3162             (mainwin->summaryview->folder_item &&
3163              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
3164              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
3165                 state |= M_CAN_LEARN_SPAM;
3166         }
3167
3168         if (mainwin->summaryview->folder_item) {
3169                 state |= M_FOLDER_SELECTED;
3170         }
3171
3172         if (inc_is_active())
3173                 state |= M_INC_ACTIVE;
3174         if (imap_cancel_all_enabled())
3175                 state |= M_INC_ACTIVE;
3176
3177         if (mainwin->summaryview->deleted > 0)
3178                 state |= M_DELETED_EXISTS;
3179
3180         if (mainwin->summaryview->deleted > 0 ||
3181             mainwin->summaryview->moved > 0 ||
3182             mainwin->summaryview->copied > 0)
3183                 state |= M_DELAY_EXEC;
3184
3185         if (summary_is_list(mainwin->summaryview))
3186                 state |= M_SUMMARY_ISLIST;
3187
3188         if (prefs_common.layout_mode != SMALL_LAYOUT || mainwin->in_folder)
3189                 state |= M_IN_MSGLIST;
3190
3191         for (account_list = account_get_list(); account_list != NULL; account_list = account_list->next) {
3192                 PrefsAccount *account = account_list->data;
3193                 if (account->session_passwd || account->session_smtp_passwd) {
3194                         state |= M_SESSION_PASSWORDS;
3195                         break;
3196                 }
3197         }
3198
3199         return state;
3200 }
3201
3202
3203
3204 void main_window_set_menu_sensitive(MainWindow *mainwin)
3205 {
3206         SensitiveCond state;
3207         gboolean sensitive;
3208         SummaryView *summaryview;
3209         gchar *menu_path;
3210         GtkWidget *menu;
3211         GList *children, *cur_item;
3212         gint i;
3213
3214         static const struct {
3215                 gchar *const entry;
3216                 SensitiveCond cond;
3217         } entry[] = {
3218                 {"Menu/File/SaveAs", M_TARGET_EXIST},
3219                 {"Menu/File/Print"  , M_TARGET_EXIST},
3220                 {"Menu/File/SynchroniseFolders", M_WANT_SYNC},
3221                 {"Menu/File/Exit"      , M_UNLOCKED},
3222
3223                 {"Menu/Edit/SelectThread"                  , M_TARGET_EXIST|M_SUMMARY_ISLIST},
3224                 {"Menu/Edit/DeleteThread"                  , M_TARGET_EXIST|M_SUMMARY_ISLIST},
3225                 {"Menu/Edit/Find", M_SINGLE_TARGET_EXIST},
3226                 {"Menu/Edit/QuickSearch",                    M_IN_MSGLIST},
3227
3228                 {"Menu/View/SetColumns/Folderlist"      , M_UNLOCKED|M_SUMMARY_ISLIST}, 
3229                 {"Menu/View/Sort"                      , M_EXEC|M_SUMMARY_ISLIST},
3230                 {"Menu/View/ThreadView"               , M_EXEC|M_SUMMARY_ISLIST},
3231                 {"Menu/View/ExpandThreads"        , M_MSG_EXIST|M_SUMMARY_ISLIST},
3232                 {"Menu/View/CollapseThreads"      , M_MSG_EXIST|M_SUMMARY_ISLIST},
3233                 {"Menu/View/HideReadThreads"       , M_HIDE_READ_THREADS|M_SUMMARY_ISLIST},
3234                 {"Menu/View/HideReadMessages"      , M_HIDE_READ_MSG|M_SUMMARY_ISLIST},
3235                 {"Menu/View/HideDelMessages"       , M_SUMMARY_ISLIST},
3236                 {"Menu/View/Goto/Prev"        , M_MSG_EXIST},
3237                 {"Menu/View/Goto/Next"        , M_MSG_EXIST},
3238                 {"Menu/View/Goto/PrevUnread" , M_MSG_EXIST},
3239                 {"Menu/View/Goto/PrevNew"    , M_MSG_EXIST},
3240                 {"Menu/View/Goto/PrevMarked" , M_MSG_EXIST},
3241                 {"Menu/View/Goto/PrevLabeled", M_MSG_EXIST},
3242                 {"Menu/View/Goto/NextLabeled", M_MSG_EXIST},
3243                 {"Menu/View/Goto/ParentMessage"      , M_SINGLE_TARGET_EXIST},
3244                 {"Menu/View/OpenNewWindow"        , M_SINGLE_TARGET_EXIST},
3245                 {"Menu/View/MessageSource"            , M_SINGLE_TARGET_EXIST},
3246                 {"Menu/View/AllHeaders"                    , M_SINGLE_TARGET_EXIST},
3247                 {"Menu/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
3248
3249                 {"Menu/Message/Receive/CurrentAccount"
3250                                                  , M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_RETRIEVABLE_ACCOUNT},
3251                 {"Menu/Message/Receive/AllAccounts"
3252                                                  , M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_ANY_RETRIEVABLE_ACCOUNT},
3253                 {"Menu/Message/Receive/CancelReceiving"
3254                                                  , M_INC_ACTIVE},
3255                 {"Menu/Message/SendQueue"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
3256                 {"Menu/Message/ComposeEmail", M_HAVE_ACCOUNT},
3257                 {"Menu/Message/ComposeNews", M_HAVE_NEWS_ACCOUNT},
3258                 {"Menu/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
3259                 {"Menu/Message/ReplyTo"              , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
3260                 {"Menu/Message/FollowupReply", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS|M_SUMMARY_ISLIST},
3261                 {"Menu/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
3262                 {"Menu/Message/ForwardAtt" , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
3263                 {"Menu/Message/Redirect"                  , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
3264                 {"Menu/Message/Move"              , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
3265                 {"Menu/Message/Copy"              , M_TARGET_EXIST|M_EXEC},
3266                 {"Menu/Message/Trash"     , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS|M_NOT_TRASH},
3267                 {"Menu/Message/Delete"            , M_TARGET_EXIST|M_ALLOW_DELETE},
3268                 {"Menu/Message/CancelNews" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
3269                 {"Menu/Message/Mark"              , M_TARGET_EXIST|M_SUMMARY_ISLIST},
3270                 {"Menu/Message/Mark/MarkSpam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
3271                 {"Menu/Message/Mark/MarkHam"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
3272                 {"Menu/Message/Mark/IgnoreThread"    , M_TARGET_EXIST},
3273                 {"Menu/Message/Mark/UnignoreThread"  , M_TARGET_EXIST},
3274                 {"Menu/Message/Mark/Lock"         , M_TARGET_EXIST},
3275                 {"Menu/Message/Mark/Unlock"       , M_TARGET_EXIST},
3276                 {"Menu/Message/ColorLabel"                , M_TARGET_EXIST},
3277                 {"Menu/Message/Tags"              , M_TARGET_EXIST},
3278                 {"Menu/Message/Reedit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
3279
3280                 {"Menu/Tools/AddSenderToAB"   , M_SINGLE_TARGET_EXIST},
3281                 {"Menu/Tools/CollectAddresses"            , M_FOLDER_SELECTED},
3282                 {"Menu/Tools/CollectAddresses/FromFolder"
3283                                                        , M_FOLDER_SELECTED},
3284                 {"Menu/Tools/CollectAddresses/FromSelected"
3285                                                        , M_TARGET_EXIST},
3286                 {"Menu/Tools/FilterFolder", M_MSG_EXIST|M_EXEC},
3287                 {"Menu/Tools/FilterSelected"     , M_TARGET_EXIST|M_EXEC},
3288                 {"Menu/Tools/RunProcessing"  , M_HAVE_PROCESSING},
3289                 {"Menu/Tools/CreateFilterRule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
3290                 {"Menu/Tools/CreateProcessingRule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
3291                 {"Menu/Tools/ListUrls"                 , M_TARGET_EXIST},
3292                 {"Menu/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
3293                 {"Menu/Tools/Execute"                      , M_DELAY_EXEC},
3294                 {"Menu/Tools/Expunge"                      , M_DELETED_EXISTS},
3295                 {"Menu/Tools/ForgetSessionPasswords"       , M_SESSION_PASSWORDS},
3296                 {"Menu/Tools/DeleteDuplicates/SelFolder"   , M_MSG_EXIST|M_ALLOW_DELETE},
3297
3298                 {"Menu/Configuration", M_UNLOCKED},
3299                 {"Menu/Configuration/ChangeAccount", M_HAVE_MULTI_ACCOUNT},
3300                 {"Menu/Configuration/AccountPrefs", M_UNLOCKED},
3301                 {"Menu/Configuration/CreateAccount", M_UNLOCKED},
3302                 {"Menu/Configuration/EditAccounts", M_UNLOCKED},
3303
3304                 {NULL, 0}
3305         };
3306
3307         state = main_window_get_current_state(mainwin);
3308
3309         for (i = 0; entry[i].entry != NULL; i++) {
3310                 sensitive = ((entry[i].cond & state) == entry[i].cond);
3311                 cm_menu_set_sensitive_full(mainwin->ui_manager, entry[i].entry, sensitive);
3312         }
3313
3314         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
3315                 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive")));
3316
3317         children = gtk_container_get_children(GTK_CONTAINER(menu));
3318         for (cur_item = children; cur_item != NULL; cur_item = cur_item->next) {
3319                 if (cur_item->data == gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/Receive/Separator1")) {
3320                         cur_item = cur_item->next;
3321                         break;
3322                 }
3323         }
3324
3325         for (; cur_item != NULL; cur_item = cur_item->next) {
3326                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
3327                                          (M_UNLOCKED & state) != 0);
3328         }
3329
3330         g_list_free(children);
3331
3332         main_window_menu_callback_block(mainwin);
3333
3334         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/ShowHide/MessageView",
3335                               messageview_is_visible(mainwin->messageview));
3336
3337         summaryview = mainwin->summaryview;
3338         menu_path = "Menu/View/Sort/DontSort";
3339
3340         switch (summaryview->sort_key) {
3341         case SORT_BY_NUMBER:
3342                 menu_path = "Menu/View/Sort/Number"; break;
3343         case SORT_BY_SIZE:
3344                 menu_path = "Menu/View/Sort/Size"; break;
3345         case SORT_BY_DATE:
3346                 menu_path = "Menu/View/Sort/Date"; break;
3347         case SORT_BY_THREAD_DATE:
3348                 menu_path = "Menu/View/Sort/ThreadDate"; break;
3349         case SORT_BY_FROM:
3350                 menu_path = "Menu/View/Sort/From"; break;
3351         case SORT_BY_TO:
3352                 menu_path = "Menu/View/Sort/To"; break;
3353         case SORT_BY_SUBJECT:
3354                 menu_path = "Menu/View/Sort/Subject"; break;
3355         case SORT_BY_LABEL:
3356                 menu_path = "Menu/View/Sort/Color"; break;
3357         case SORT_BY_MARK:
3358                 menu_path = "Menu/View/Sort/Mark"; break;
3359         case SORT_BY_STATUS:
3360                 menu_path = "Menu/View/Sort/Status"; break;
3361         case SORT_BY_MIME:
3362                 menu_path = "Menu/View/Sort/Attachment"; break;
3363         case SORT_BY_SCORE:
3364                 menu_path = "Menu/View/Sort/Score"; break;
3365         case SORT_BY_LOCKED:
3366                 menu_path = "Menu/View/Sort/Locked"; break;
3367         case SORT_BY_TAGS:
3368                 menu_path = "Menu/View/Sort/Tag"; break;
3369         case SORT_BY_NONE:
3370         default:
3371                 menu_path = "Menu/View/Sort/DontSort"; break;
3372         }
3373         cm_toggle_menu_set_active_full(mainwin->ui_manager, menu_path, TRUE);
3374
3375         if (summaryview->sort_type == SORT_ASCENDING) {
3376                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", TRUE);
3377         } else {
3378                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Sort/Descending", TRUE);
3379         }
3380
3381         if (summaryview->sort_key != SORT_BY_NONE) {
3382                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", TRUE);
3383                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", TRUE);
3384         } else {
3385                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Ascending", FALSE);
3386                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", FALSE);
3387         }
3388
3389         if (mainwin->messageview 
3390         &&  mainwin->messageview->mimeview
3391         &&  mainwin->messageview->mimeview->textview)
3392                 cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/AllHeaders",
3393                                                 prefs_common.show_all_headers);
3394         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/ThreadView", (state & M_THREADED) != 0);
3395         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/ExpandThreads", (state & M_THREADED) != 0);
3396         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/CollapseThreads", (state & M_THREADED) != 0);
3397         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadThreads", (state & M_THREADED) != 0);
3398         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
3399         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
3400         cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
3401
3402         if (mainwin->summaryview->folder_item && mainwin->summaryview->folder_item->hide_read_msgs)
3403                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadThreads", FALSE);
3404         if (mainwin->summaryview->folder_item && mainwin->summaryview->folder_item->hide_read_threads)
3405                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/HideReadMessages", FALSE);
3406
3407         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/PrevHistory",
3408                 messageview_nav_has_prev(mainwin->messageview));
3409         cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Goto/NextHistory",
3410                 messageview_nav_has_next(mainwin->messageview));
3411
3412         main_window_menu_callback_unblock(mainwin);
3413 }
3414
3415 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
3416 {
3417         gint is_menu = 0;
3418         
3419         if (msginfo) 
3420                 is_menu = mailing_list_create_submenu (mainwin, msginfo);
3421         if (is_menu)
3422                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList", TRUE);
3423         else
3424                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList", FALSE);
3425 }
3426
3427 static gint mailing_list_create_submenu (MainWindow *mainwin, MsgInfo *msginfo)
3428 {
3429         gint menu_nb = 0;
3430         GtkWidget *menuitem;
3431         
3432         if (!msginfo || !msginfo->extradata) {
3433                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Post", FALSE);
3434                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Help", FALSE);
3435                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Subscribe", FALSE);
3436                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/Unsubscribe", FALSE);
3437                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/ViewArchive", FALSE);
3438                 cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/MailingList/ContactOwner", FALSE);
3439                 return 0;
3440         }
3441                 
3442         /* Mailing list post */
3443         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
3444                 g_free(msginfo->extradata->list_post);
3445                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
3446         }
3447         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Post");
3448                 
3449         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
3450  
3451         /* Mailing list help */
3452         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Help");
3453         
3454         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
3455
3456         /* Mailing list subscribe */
3457         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Subscribe");
3458         
3459         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
3460                 
3461         /* Mailing list unsubscribe */
3462         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/Unsubscribe");
3463         
3464         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
3465         
3466         /* Mailing list view archive */
3467         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/ViewArchive");
3468         
3469         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
3470         
3471         /* Mailing list contact owner */
3472         menuitem = gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu/Message/MailingList/ContactOwner");
3473         
3474         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
3475         
3476         return menu_nb;
3477 }
3478
3479 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
3480 {
3481         GtkWidget *item, *menu;
3482         const gchar *url_pt ;
3483         gchar url_decoded[BUFFSIZE];
3484         GList *children, *amenu;
3485         gint menu_nb = 0;
3486         
3487         menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menuitem));
3488         
3489         /* First delete old submenu */
3490         /* FIXME: we can optimize this, and only change/add/delete necessary items */
3491         children = gtk_container_get_children(GTK_CONTAINER(menu));
3492         for (amenu = children; amenu; amenu = amenu->next) {
3493                 item = GTK_WIDGET (amenu->data);
3494                 gtk_widget_destroy (item);
3495         }
3496         g_list_free(children);
3497         if (list_header) {
3498                 for (url_pt = list_header; url_pt && *url_pt;) {
3499                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
3500                         item = NULL;
3501                         if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
3502                                 item = gtk_menu_item_new_with_label ((url_decoded));
3503                                 g_signal_connect(G_OBJECT(item), "activate",
3504                                                  G_CALLBACK(mailing_list_compose),
3505                                                  NULL);
3506                         }
3507                         else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
3508                                  !g_ascii_strncasecmp(url_decoded, "https:",6)) {
3509
3510                                 item = gtk_menu_item_new_with_label ((url_decoded));
3511                                 g_signal_connect(G_OBJECT(item), "activate",
3512                                                  G_CALLBACK(mailing_list_open_uri),
3513                                                  NULL);
3514                         } 
3515                         if (item) {
3516                                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3517                                 gtk_widget_show (item);
3518                                 menu_nb++;
3519                         }
3520                 }
3521         }
3522         if (menu_nb)
3523                 gtk_widget_set_sensitive (menuitem, TRUE);
3524         else
3525                 gtk_widget_set_sensitive (menuitem, FALSE);
3526                 
3527
3528         return menu_nb;
3529 }
3530
3531 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
3532 {
3533         gchar tmp[BUFFSIZE];
3534         const gchar *buf;
3535         gint i = 0;
3536         buf = *buffer;
3537         gboolean with_plus = TRUE;
3538
3539         if (buf == 0x00) {
3540                 *url_decoded = '\0';
3541                 *buffer = NULL;
3542                 return;
3543         }
3544         /* Ignore spaces, comments  and tabs () */
3545         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
3546                 if (*buf == '(')
3547                         for (;*buf != ')' && *buf != 0x00; buf++);
3548         
3549         /* First non space and non comment must be a < */
3550         if (*buf =='<' ) {
3551                 buf++;
3552                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
3553                         with_plus = FALSE;
3554                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
3555                 buf++;
3556         }
3557         else  {
3558                 *buffer = NULL;
3559                 *url_decoded = '\0';
3560                 return;
3561         }
3562         
3563         tmp[i]       = 0x00;
3564         *url_decoded = '\0';
3565         *buffer = NULL;
3566         
3567         if (i == maxlen) {
3568                 return;
3569         }
3570         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
3571
3572         /* Prepare the work for the next url in the list */
3573         /* after the closing bracket >, ignore space, comments and tabs */
3574         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
3575                 if (*buf == '(')
3576                         for (;*buf != ')' && *buf != 0x00; buf++);
3577                         
3578         if (!buf || !*buf) {
3579                 *buffer = NULL;
3580                 return;
3581         }
3582
3583         /* now first non space, non comment must be a comma */
3584         if (*buf != ',')
3585                 for (;*buf != 0x00; buf++);
3586         else
3587                 buf++;
3588         *buffer = buf;
3589 }
3590         
3591 static void mailing_list_compose (GtkWidget *w, gpointer *data)
3592 {
3593         const gchar *mailto;
3594         PrefsAccount *account = NULL;
3595         FolderItem   *folder_item = NULL;
3596
3597         mailto = gtk_label_get_text(GTK_LABEL (gtk_bin_get_child(GTK_BIN((w)))));
3598         if (mainwindow_get_mainwindow()) {
3599                 folder_item = mainwindow_get_mainwindow()->summaryview->folder_item;
3600                 if (folder_item && folder_item->prefs && folder_item->prefs->enable_default_account)
3601                         account = account_find_from_id(folder_item->prefs->default_account);
3602                 if (folder_item && !account)
3603                         account = account_find_from_item(folder_item);
3604         }
3605         if (mailto)
3606                 compose_new_with_folderitem(account, folder_item, mailto+7);
3607 }
3608  
3609  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
3610 {
3611  
3612         const gchar *mailto;
3613  
3614         mailto = gtk_label_get_text(GTK_LABEL (gtk_bin_get_child(GTK_BIN((w)))));
3615         if (mailto)
3616                 open_uri (mailto, prefs_common_get_uri_cmd());
3617
3618