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