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