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