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