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