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