cf65fe9f2ce73db403dd3b1378dbf49146abbe57
[claws.git] / src / mainwindow.c
1 /*
2    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3    Copyright (C) 1999-2007 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 MAEMO
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 MAEMO
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 MAEMO
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 #ifdef USE_OPENSSL
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 MAEMO
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/_Work offline"),            "<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 MAEMO
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 MAEMO
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 MAEMO
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/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
858         {N_("/_Tools/_Harvest addresses/from _Folder..."),
859                                                 NULL, addr_harvest_cb, 0, NULL},
860         {N_("/_Tools/_Harvest addresses/from _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 processing 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 #ifdef USE_OPENSSL
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 Log"),           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 void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1233 {
1234         GtkWidget *label_menuitem;
1235         GtkWidget *menu;
1236         GtkWidget *item;
1237         GSList *cur = tags_get_list();
1238         GSList *orig = cur;
1239         gboolean existing_tags = FALSE;
1240
1241         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1242                                                    "/Message/Tags");
1243         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1244                          G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1245                            mainwin);
1246
1247         gtk_widget_show(label_menuitem);
1248
1249         menu = gtk_menu_new();
1250
1251         /* create tags menu items */
1252         for (; cur; cur = cur->next) {
1253                 gint id = GPOINTER_TO_INT(cur->data);
1254                 const gchar *tag = tags_get_tag(id);
1255
1256                 item = gtk_check_menu_item_new_with_label(tag);
1257                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1258                 g_signal_connect(G_OBJECT(item), "activate",
1259                                  G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1260                                  GINT_TO_POINTER(id));
1261                 g_object_set_data(G_OBJECT(item), "mainwin",
1262                                   mainwin);
1263                 g_object_set_data(G_OBJECT(item), "tag_id",
1264                                   GINT_TO_POINTER(id));
1265                 gtk_widget_show(item);
1266                 existing_tags = TRUE;
1267         }
1268         if (existing_tags) {
1269                 /* separator */
1270                 item = gtk_menu_item_new();
1271                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1272                 gtk_widget_show(item);
1273         }
1274
1275         item = gtk_menu_item_new_with_label(_("Apply tags..."));
1276         gtk_widget_add_accelerator(item, "activate", 
1277                    mainwin->menu_factory->accel_group, 
1278                    GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
1279                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1280         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1281         g_signal_connect(G_OBJECT(item), "activate",
1282                          G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1283                          NULL);
1284         g_object_set_data(G_OBJECT(item), "mainwin",
1285                           mainwin);
1286         gtk_widget_show(item);
1287
1288         g_slist_free(orig);
1289         gtk_widget_show(menu);
1290         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1291         mainwin->tags_menu = menu;
1292 }
1293 #ifndef MAEMO
1294 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1295                                     MainWindow *mainwindow)
1296 {
1297         if (evt && evt->button == 1) {
1298                 log_window_show_error(mainwindow->logwin);
1299                 gtk_widget_hide(mainwindow->warning_btn);
1300         }
1301         return FALSE;
1302 }
1303
1304 static gboolean warning_visi_notify(GtkWidget *widget,
1305                                        GdkEventVisibility *event,
1306                                        MainWindow *mainwindow)
1307 {
1308         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1309         return FALSE;
1310 }
1311
1312 static gboolean warning_leave_notify(GtkWidget *widget,
1313                                       GdkEventCrossing *event,
1314                                       MainWindow *mainwindow)
1315 {
1316         gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1317         return FALSE;
1318 }
1319
1320 static gboolean warning_enter_notify(GtkWidget *widget,
1321                                       GdkEventCrossing *event,
1322                                       MainWindow *mainwindow)
1323 {
1324         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1325         return FALSE;
1326 }
1327 #endif
1328 void mainwindow_show_error(void)
1329 {
1330         MainWindow *mainwin = mainwindow_get_mainwindow();
1331         gtk_widget_show(mainwin->warning_btn);
1332 }
1333
1334 void mainwindow_clear_error(MainWindow *mainwin)
1335 {
1336         gtk_widget_hide(mainwin->warning_btn);
1337 }
1338
1339 MainWindow *main_window_create()
1340 {
1341         MainWindow *mainwin;
1342         GtkWidget *window;
1343         GtkWidget *vbox;
1344         GtkWidget *menubar;
1345         GtkWidget *handlebox;
1346         GtkWidget *vbox_body;
1347 #ifndef MAEMO
1348         GtkWidget *hbox_stat;
1349         GtkWidget *statusbar;
1350         GtkWidget *progressbar;
1351         GtkWidget *statuslabel;
1352         GtkWidget *ac_button;
1353         GtkWidget *ac_label;
1354         GtkWidget *online_pixmap;
1355         GtkWidget *offline_pixmap;
1356         GtkTooltips *tips;
1357         GtkWidget *warning_icon;
1358         GtkWidget *warning_btn;
1359 #endif
1360         GtkWidget *online_switch;
1361         GtkWidget *offline_switch;
1362         FolderView *folderview;
1363         SummaryView *summaryview;
1364         MessageView *messageview;
1365         GdkColormap *colormap;
1366         GdkColor color[4];
1367         gboolean success[4];
1368         GtkItemFactory *ifactory;
1369         GtkWidget *ac_menu;
1370         GtkWidget *menuitem;
1371         gint i;
1372         guint n_menu_entries;
1373
1374         static GdkGeometry geometry;
1375
1376         debug_print("Creating main window...\n");
1377         mainwin = g_new0(MainWindow, 1);
1378
1379         /* main window */
1380         window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1381         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1382         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1383 #ifdef MAEMO
1384         prefs_common.layout_mode = SMALL_LAYOUT;
1385 #endif
1386         if (!geometry.min_height) {
1387                 geometry.min_width = 320;
1388                 geometry.min_height = 200;
1389         }
1390         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1391                                       GDK_HINT_MIN_SIZE);
1392
1393         g_signal_connect(G_OBJECT(window), "delete_event",
1394                          G_CALLBACK(main_window_close_cb), mainwin);
1395         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1396         g_signal_connect(G_OBJECT(window), "focus_in_event",
1397                          G_CALLBACK(mainwindow_focus_in_event),
1398                          mainwin);
1399         g_signal_connect(G_OBJECT(window), "key_press_event",
1400                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1401
1402         gtk_widget_realize(window);
1403         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1404         
1405
1406         gtkut_widget_set_app_icon(window);
1407
1408         vbox = gtk_vbox_new(FALSE, 0);
1409         gtk_widget_show(vbox);
1410         gtk_container_add(GTK_CONTAINER(window), vbox);
1411
1412         /* menu bar */
1413         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1414         menubar = menubar_create(window, mainwin_entries, 
1415                                  n_menu_entries, "<Main>", mainwin);
1416         gtk_widget_show(menubar);
1417
1418 #ifndef MAEMO
1419         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1420 #endif
1421
1422         ifactory = gtk_item_factory_from_widget(menubar);
1423
1424 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1425         main_create_mailing_list_menu (mainwin, NULL); */
1426
1427         if (prefs_common.toolbar_detachable) {
1428                 handlebox = gtk_handle_box_new();
1429                 gtk_widget_show(handlebox);
1430                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1431                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1432                                  G_CALLBACK(toolbar_child_attached), mainwin);
1433                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1434                                  G_CALLBACK(toolbar_child_detached), mainwin);
1435         } else {
1436                 handlebox = gtk_hbox_new(FALSE, 0);
1437                 gtk_widget_show(handlebox);
1438                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1439         }
1440         /* link window to mainwin->window to avoid gdk warnings */
1441         mainwin->window       = window;
1442         mainwin_list = g_list_append(mainwin_list, mainwin);
1443         
1444 #ifdef MAEMO
1445         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1446                                           window, 
1447                                           (gpointer)mainwin);
1448 #else
1449         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1450                                           handlebox, 
1451                                           (gpointer)mainwin);
1452 #endif
1453         toolbar_set_learn_button
1454                 (mainwin->toolbar,
1455                  LEARN_SPAM);
1456
1457         /* vbox that contains body */
1458         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1459         gtk_widget_show(vbox_body);
1460         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1461         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1462
1463 #ifndef MAEMO
1464         hbox_stat = gtk_hbox_new(FALSE, 2);
1465         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1466
1467         tips = gtk_tooltips_new();
1468
1469         warning_icon = gtk_image_new_from_stock
1470                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1471         warning_btn = gtk_event_box_new();
1472         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1473         
1474         mainwin->warning_btn      = warning_btn;
1475         
1476         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1477                          G_CALLBACK(warning_icon_pressed),
1478                          (gpointer) mainwin);
1479         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1480                          G_CALLBACK(warning_visi_notify), mainwin);
1481         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1482                          G_CALLBACK(warning_visi_notify), mainwin);
1483         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1484                          G_CALLBACK(warning_leave_notify), mainwin);
1485         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1486                          G_CALLBACK(warning_enter_notify), mainwin);
1487
1488         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1489
1490         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1491                              _("Some error(s) happened. Click here to view log."), NULL);
1492         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1493
1494         statusbar = statusbar_create();
1495         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1496
1497         progressbar = gtk_progress_bar_new();
1498         gtk_widget_set_size_request(progressbar, 120, 1);
1499         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1500
1501         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1502         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1503         online_switch = gtk_button_new ();
1504         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1505                              _("You are online. Click the icon to go offline"), NULL);
1506         offline_switch = gtk_button_new ();
1507         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1508                              _("You are offline. Click the icon to go online"),
1509                              NULL);
1510         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1511         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1512         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1513         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1514         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1515         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1516         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1517         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1518         
1519         statuslabel = gtk_label_new("");
1520         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1521
1522         ac_button = gtk_button_new();
1523         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1524                              ac_button, _("Select account"), NULL);
1525         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1526         gtk_widget_set_size_request(ac_button, -1, 0);
1527         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1528         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1529                          G_CALLBACK(ac_label_button_pressed), mainwin);
1530
1531         ac_label = gtk_label_new("");
1532         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1533
1534         gtk_widget_show_all(hbox_stat);
1535
1536         gtk_widget_hide(offline_switch);
1537         gtk_widget_hide(warning_btn);
1538 #else
1539         online_switch = gtk_button_new ();
1540         offline_switch = gtk_button_new ();
1541         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1542         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1543 #endif
1544         /* create views */
1545         mainwin->folderview  = folderview  = folderview_create();
1546         mainwin->summaryview = summaryview = summary_create();
1547         mainwin->messageview = messageview = messageview_create(mainwin);
1548
1549         /* init log instances data before creating log views */
1550         set_log_title(LOG_PROTOCOL, _("Network log"));
1551         set_log_prefs(LOG_PROTOCOL,
1552                         &prefs_common.logwin_width,
1553                         &prefs_common.logwin_height);
1554         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1555         set_log_prefs(LOG_DEBUG_FILTERING,
1556                         &prefs_common.filtering_debugwin_width,
1557                         &prefs_common.filtering_debugwin_height);
1558
1559         /* setup log windows */
1560         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1561         log_window_init(mainwin->logwin);
1562
1563         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1564         log_window_set_clipping(mainwin->logwin,
1565                                 prefs_common.cliplog,
1566                                 prefs_common.loglength);
1567
1568         log_window_init(mainwin->filtering_debugwin);
1569         log_window_set_clipping(mainwin->filtering_debugwin,
1570                                 prefs_common.filtering_debug_cliplog,
1571                                 prefs_common.filtering_debug_loglength);
1572         if (prefs_common.enable_filtering_debug)
1573                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1574         else
1575                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1576
1577         folderview->mainwin      = mainwin;
1578         folderview->summaryview  = summaryview;
1579
1580         summaryview->mainwin     = mainwin;
1581         summaryview->folderview  = folderview;
1582         summaryview->messageview = messageview;
1583         summaryview->window      = window;
1584
1585         mainwin->vbox           = vbox;
1586         mainwin->menubar        = menubar;
1587         mainwin->menu_factory   = ifactory;
1588         mainwin->handlebox      = handlebox;
1589         mainwin->vbox_body      = vbox_body;
1590         mainwin->online_switch  = online_switch;
1591         mainwin->offline_switch    = offline_switch;
1592 #ifndef MAEMO
1593         messageview->statusbar  = statusbar;
1594         mainwin->statusbar      = statusbar;
1595         mainwin->hbox_stat      = hbox_stat;
1596         mainwin->progressbar    = progressbar;
1597         mainwin->statuslabel    = statuslabel;
1598         mainwin->online_pixmap  = online_pixmap;
1599         mainwin->offline_pixmap = offline_pixmap;
1600         mainwin->ac_button      = ac_button;
1601         mainwin->ac_label       = ac_label;
1602         /* set context IDs for status bar */
1603         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1604                 (GTK_STATUSBAR(statusbar), "Main Window");
1605         mainwin->folderview_cid = gtk_statusbar_get_context_id
1606                 (GTK_STATUSBAR(statusbar), "Folder View");
1607         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1608                 (GTK_STATUSBAR(statusbar), "Summary View");
1609         mainwin->messageview_cid = gtk_statusbar_get_context_id
1610                 (GTK_STATUSBAR(statusbar), "Message View");
1611         messageview->statusbar_cid = mainwin->messageview_cid;
1612
1613 #else
1614         messageview->statusbar  = NULL;
1615         mainwin->statusbar      = NULL;
1616         mainwin->hbox_stat      = NULL;
1617         /* mainwin->progressbar is set in toolbar.c */
1618         mainwin->statuslabel    = NULL;
1619         mainwin->online_pixmap  = NULL;
1620         mainwin->offline_pixmap = NULL;
1621         mainwin->ac_button      = NULL;
1622         mainwin->ac_label       = NULL;
1623 #endif
1624         
1625         /* allocate colors for summary view and folder view */
1626         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1627         summaryview->color_marked.blue = (guint16)65535;
1628
1629         summaryview->color_dim.red = summaryview->color_dim.green =
1630                 summaryview->color_dim.blue = COLOR_DIM;
1631
1632         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1633                                        &folderview->color_new);
1634
1635         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1636                                        &folderview->color_op);
1637
1638         summaryview->color_important.red = 0;
1639         summaryview->color_important.green = 0;
1640         summaryview->color_important.blue = (guint16)65535;
1641
1642         color[0] = summaryview->color_marked;
1643         color[1] = summaryview->color_dim;
1644         color[2] = folderview->color_new;
1645         color[3] = folderview->color_op;
1646
1647         colormap = gdk_drawable_get_colormap(window->window);
1648         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1649         for (i = 0; i < 4; i++) {
1650                 if (success[i] == FALSE)
1651                         g_warning("MainWindow: color allocation %d failed\n", i);
1652         }
1653
1654         debug_print("done.\n");
1655
1656         messageview->visible = prefs_common.msgview_visible;
1657
1658         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1659
1660         g_signal_connect(G_OBJECT(window), "size_allocate",
1661                          G_CALLBACK(main_window_size_allocate_cb),
1662                          mainwin);
1663
1664         /* set menu items */
1665         menuitem = gtk_item_factory_get_item
1666                 (ifactory, "/View/Character encoding/Auto detect");
1667         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1668
1669         switch (prefs_common.toolbar_style) {
1670         case TOOLBAR_NONE:
1671                 menuitem = gtk_item_factory_get_item
1672                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1673                 break;
1674         case TOOLBAR_ICON:
1675                 menuitem = gtk_item_factory_get_item
1676                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1677                 break;
1678         case TOOLBAR_TEXT:
1679                 menuitem = gtk_item_factory_get_item
1680                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1681                 break;
1682         case TOOLBAR_BOTH:
1683                 menuitem = gtk_item_factory_get_item
1684                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1685                 break;
1686         case TOOLBAR_BOTH_HORIZ:
1687                 menuitem = gtk_item_factory_get_item
1688                         (ifactory,
1689                          "/View/Show or hide/Toolbar/Text beside icons");
1690         }
1691         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1692
1693 #ifndef MAEMO
1694         gtk_widget_hide(mainwin->hbox_stat);
1695         menuitem = gtk_item_factory_get_item
1696                 (ifactory, "/View/Show or hide/Status bar");
1697         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1698                                        prefs_common.show_statusbar);
1699 #endif  
1700         menuitem = gtk_item_factory_get_item
1701                 (ifactory, "/View/Show or hide/Column headers");
1702         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1703                                        prefs_common.show_col_headers);
1704         /* set account selection menu */
1705         ac_menu = gtk_item_factory_get_widget
1706                 (ifactory, "/Configuration/Change current account");
1707         mainwin->ac_menu = ac_menu;
1708
1709         toolbar_main_set_sensitive(mainwin);
1710
1711         /* create actions menu */
1712         main_window_update_actions_menu(mainwin);
1713
1714         main_create_mailing_list_menu (mainwin, NULL);
1715
1716         /* attach accel groups to main window */
1717 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1718         gtk_window_add_accel_group                                      \
1719                 (GTK_WINDOW(win),                                       \
1720                  gtk_item_factory_from_widget(menu)->accel_group);      \
1721         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1722                         "accel_activate",                               \
1723                         G_CALLBACK(main_window_accel_activate), mainwin);
1724                          
1725         
1726         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1727         
1728         /* connect the accelerators for equivalent 
1729            menu items in different menus             */
1730         menu_connect_identical_items();
1731
1732 #ifndef MAEMO
1733         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1734 #endif
1735
1736         g_signal_connect(G_OBJECT(window), "window_state_event",
1737                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1738         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1739                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1740         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1741
1742         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1743             prefs_common.layout_mode == SMALL_LAYOUT) {
1744                 summary_relayout(mainwin->summaryview); 
1745         }
1746         summary_update_unread(mainwin->summaryview, NULL);
1747         
1748         gtk_widget_show(mainwin->window);
1749
1750         /* initialize views */
1751         folderview_init(folderview);
1752         summary_init(summaryview);
1753         messageview_init(messageview);
1754 #ifdef USE_OPENSSL
1755         sslcertwindow_register_hook();
1756 #endif
1757         mainwin->lock_count = 0;
1758         mainwin->menu_lock_count = 0;
1759         mainwin->cursor_count = 0;
1760
1761         mainwin->progressindicator_hook =
1762                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1763
1764         if (!watch_cursor)
1765                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1766         if (!hand_cursor)
1767                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1768
1769         /* init work_offline */
1770         if (prefs_common.work_offline)
1771                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1772
1773         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1774         mainwindow_tags_menu_create(mainwin, FALSE);
1775         
1776         return mainwin;
1777 }
1778
1779 void main_window_destroy(MainWindow *mainwin)
1780 {
1781         /* TODO : destroy other component */
1782         messageview_destroy(mainwin->messageview);
1783         mainwin->messageview = NULL;    
1784 }
1785
1786 void main_window_update_actions_menu(MainWindow *mainwin)
1787 {
1788         GtkItemFactory *ifactory;
1789
1790         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1791         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1792 }
1793
1794 void main_window_cursor_wait(MainWindow *mainwin)
1795 {
1796
1797         if (mainwin->cursor_count == 0) {
1798                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1799                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1800         }
1801         
1802         mainwin->cursor_count++;
1803
1804         gdk_flush();
1805 }
1806
1807 void main_window_cursor_normal(MainWindow *mainwin)
1808 {
1809         if (mainwin->cursor_count)
1810                 mainwin->cursor_count--;
1811
1812         if (mainwin->cursor_count == 0) {
1813                 gdk_window_set_cursor(mainwin->window->window, NULL);
1814                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1815         }
1816         gdk_flush();
1817 }
1818
1819 /* lock / unlock the user-interface */
1820 void main_window_lock(MainWindow *mainwin)
1821 {
1822         if (mainwin->lock_count == 0 && mainwin->ac_button)
1823                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1824
1825         mainwin->lock_count++;
1826
1827         main_window_set_menu_sensitive(mainwin);
1828         toolbar_main_set_sensitive(mainwin);
1829 }
1830
1831 void main_window_unlock(MainWindow *mainwin)
1832 {
1833         if (mainwin->lock_count)
1834                 mainwin->lock_count--;
1835
1836         main_window_set_menu_sensitive(mainwin);
1837         toolbar_main_set_sensitive(mainwin);
1838
1839         if (mainwin->lock_count == 0 && mainwin->ac_button)
1840                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1841 }
1842
1843 static void main_window_menu_callback_block(MainWindow *mainwin)
1844 {
1845         mainwin->menu_lock_count++;
1846 }
1847
1848 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1849 {
1850         if (mainwin->menu_lock_count)
1851                 mainwin->menu_lock_count--;
1852 }
1853
1854 static guint prefs_tag = 0;
1855
1856 void main_window_reflect_prefs_all(void)
1857 {
1858         main_window_reflect_prefs_all_real(FALSE);
1859 }
1860
1861 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1862 {
1863         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1864         GList *cur;
1865         MainWindow *mainwin;
1866 #ifndef MAEMO
1867         GtkWidget *pixmap;
1868 #endif
1869         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1870                 mainwin = (MainWindow *)cur->data;
1871
1872                 main_window_show_cur_account(mainwin);
1873                 main_window_set_menu_sensitive(mainwin);
1874                 toolbar_main_set_sensitive(mainwin);
1875
1876                 /* pixmap themes */
1877                 if (pixmap_theme_changed) {
1878                         toolbar_update(TOOLBAR_MAIN, mainwin);
1879                         messageview_reflect_prefs_pixmap_theme();
1880                         compose_reflect_prefs_pixmap_theme();
1881                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1882                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1883 #ifndef MAEMO
1884                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1885                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1886                                              mainwin->online_pixmap);
1887                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1888                         gtk_widget_show(pixmap);
1889                         mainwin->online_pixmap = pixmap;
1890                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1891                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1892                                              mainwin->offline_pixmap);
1893                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1894                         gtk_widget_show(pixmap);
1895                         mainwin->offline_pixmap = pixmap;
1896 #endif
1897                 }
1898                 
1899                 headerview_set_font(mainwin->messageview->headerview);
1900                 headerview_set_visibility(mainwin->messageview->headerview,
1901                                           prefs_common.display_header_pane);
1902                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1903                 folderview_reflect_prefs();
1904                 summary_reflect_prefs();
1905 #ifndef MAEMO
1906                 summary_redisplay_msg(mainwin->summaryview);
1907 #endif
1908                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1909                         if (mainwin->in_folder) {
1910                                 mainwindow_enter_folder(mainwin);
1911                         } else {
1912                                 mainwindow_exit_folder(mainwin);
1913                         }
1914                 }
1915         }
1916         prefs_tag = 0;
1917         return FALSE;
1918 }
1919
1920 void main_window_reflect_prefs_all_now(void)
1921 {
1922         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1923 }
1924
1925 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1926 {
1927         GtkMenuShell *menu;
1928         GList *cur;
1929
1930         /* re-create colorlabel submenu */
1931         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1932         g_return_if_fail(menu != NULL);
1933
1934         /* clear items. get item pointers. */
1935         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1936                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1937         }
1938         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1939         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1940
1941 }
1942
1943 void main_window_reflect_tags_changes(MainWindow *mainwin)
1944 {
1945         GtkMenuShell *menu;
1946         GList *cur;
1947
1948         /* re-create tags submenu */
1949         menu = GTK_MENU_SHELL(mainwin->tags_menu);
1950         g_return_if_fail(menu != NULL);
1951
1952         /* clear items. get item pointers. */
1953         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1954                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1955         }
1956         mainwindow_tags_menu_create(mainwin, TRUE);
1957         summary_reflect_tags_changes(mainwin->summaryview);
1958
1959 }
1960
1961 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1962 {
1963         if (prefs_tag == 0 || pixmap_theme_changed) {
1964                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1965                                                 GINT_TO_POINTER(pixmap_theme_changed));
1966         }
1967 }
1968
1969 void main_window_set_summary_column(void)
1970 {
1971         GList *cur;
1972         MainWindow *mainwin;
1973
1974         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1975                 mainwin = (MainWindow *)cur->data;
1976                 summary_set_column_order(mainwin->summaryview);
1977         }
1978 }
1979
1980 void main_window_set_folder_column(void)
1981 {
1982         GList *cur;
1983         MainWindow *mainwin;
1984
1985         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1986                 mainwin = (MainWindow *)cur->data;
1987                 folderview_set_column_order(mainwin->folderview);
1988         }
1989 }
1990
1991 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1992                                                   GList *account_list)
1993 {
1994         GList *cur_ac, *cur_item;
1995         GtkWidget *menuitem;
1996         PrefsAccount *ac_prefs;
1997
1998         /* destroy all previous menu item */
1999         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
2000         while (cur_item != NULL) {
2001                 GList *next = cur_item->next;
2002                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2003                 cur_item = next;
2004         }
2005
2006         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2007                 ac_prefs = (PrefsAccount *)cur_ac->data;
2008
2009                 menuitem = gtk_menu_item_new_with_label
2010                         (ac_prefs->account_name
2011                          ? ac_prefs->account_name : _("Untitled"));
2012                 gtk_widget_show(menuitem);
2013                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
2014                 g_signal_connect(G_OBJECT(menuitem), "activate",
2015                                  G_CALLBACK(account_selector_menu_cb),
2016                                  ac_prefs);
2017         }
2018 }
2019
2020 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2021                                                  GList *account_list)
2022 {
2023         GList *cur_ac, *cur_item;
2024         GtkWidget *menu;
2025         GtkWidget *menuitem;
2026         PrefsAccount *ac_prefs;
2027
2028         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
2029                                            "/Message/Receive");
2030
2031         /* search for separator */
2032         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2033              cur_item = cur_item->next) {
2034                 if (GTK_BIN(cur_item->data)->child == NULL) {
2035                         cur_item = cur_item->next;
2036                         break;
2037                 }
2038         }
2039
2040         /* destroy all previous menu item */
2041         while (cur_item != NULL) {
2042                 GList *next = cur_item->next;
2043                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2044                 cur_item = next;
2045         }
2046
2047         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2048                 ac_prefs = (PrefsAccount *)cur_ac->data;
2049
2050                 menuitem = gtk_menu_item_new_with_label
2051                         (ac_prefs->account_name ? ac_prefs->account_name
2052                          : _("Untitled"));
2053                 gtk_widget_show(menuitem);
2054                 gtk_menu_append(GTK_MENU(menu), menuitem);
2055                 g_signal_connect(G_OBJECT(menuitem), "activate",
2056                                  G_CALLBACK(account_receive_menu_cb),
2057                                  ac_prefs);
2058         }
2059 }
2060
2061 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2062                                                        GList *account_list)
2063 {
2064         GList *cur_ac;
2065         GtkWidget *menuitem;
2066         PrefsAccount *ac_prefs;
2067         GtkWidget *menu = NULL;
2068
2069         if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2070                 return;
2071
2072         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2073         if (menu)
2074                 gtk_widget_destroy(menu);
2075         menu = gtk_menu_new();
2076
2077         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2078                 ac_prefs = (PrefsAccount *)cur_ac->data;
2079
2080                 menuitem = gtk_menu_item_new_with_label
2081                         (ac_prefs->account_name
2082                          ? ac_prefs->account_name : _("Untitled"));
2083                 gtk_widget_show(menuitem);
2084                 gtk_menu_append(GTK_MENU(menu), menuitem);
2085                 g_signal_connect(G_OBJECT(menuitem), "activate",
2086                                  G_CALLBACK(account_receive_menu_cb),
2087                                  ac_prefs);
2088         }
2089         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2090 }
2091
2092 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2093                                                        GList *account_list)
2094 {
2095 #ifndef MAEMO
2096         GList *cur_ac;
2097         GtkWidget *menuitem;
2098         PrefsAccount *ac_prefs;
2099         GtkWidget *menu = NULL;
2100
2101         if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2102                 return;
2103
2104         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2105         if (menu)
2106                 gtk_widget_destroy(menu);
2107         menu = gtk_menu_new();
2108
2109         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2110                 ac_prefs = (PrefsAccount *)cur_ac->data;
2111
2112                 menuitem = gtk_menu_item_new_with_label
2113                         (ac_prefs->account_name
2114                          ? ac_prefs->account_name : _("Untitled"));
2115                 gtk_widget_show(menuitem);
2116                 gtk_menu_append(GTK_MENU(menu), menuitem);
2117                 g_signal_connect(G_OBJECT(menuitem), "activate",
2118                                  G_CALLBACK(account_compose_menu_cb),
2119                                  ac_prefs);
2120         }
2121         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2122 #endif
2123 }
2124
2125 void main_window_set_account_menu(GList *account_list)
2126 {
2127         GList *cur;
2128         MainWindow *mainwin;
2129
2130         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2131                 mainwin = (MainWindow *)cur->data;
2132                 main_window_set_account_selector_menu(mainwin, account_list);
2133                 main_window_set_account_receive_menu(mainwin, account_list);
2134                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2135                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2136         }
2137         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2138 }
2139
2140 void main_window_set_account_menu_only_toolbar(GList *account_list)
2141 {
2142         GList *cur;
2143         MainWindow *mainwin;
2144
2145         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2146                 mainwin = (MainWindow *)cur->data;
2147                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2148                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2149         }
2150 }
2151
2152 static void main_window_show_cur_account(MainWindow *mainwin)
2153 {
2154         gchar *buf;
2155         gchar *ac_name;
2156
2157         ac_name = g_strdup(cur_account
2158                            ? (cur_account->account_name
2159                               ? cur_account->account_name : _("Untitled"))
2160                            : _("none"));
2161
2162         if (cur_account)
2163                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2164         else
2165                 buf = g_strdup(PROG_VERSION);
2166         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2167         g_free(buf);
2168
2169         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2170         if (mainwin->ac_button)
2171                 gtk_widget_queue_resize(mainwin->ac_button);
2172
2173         g_free(ac_name);
2174 }
2175 #ifndef MAEMO
2176 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2177 {
2178         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2179         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2180         GtkWidget *message_wid = mainwin->messageview->vbox;
2181
2182         if (layout_mode == prefs_common.layout_mode) 
2183                 return;
2184
2185         debug_print("Changing window separation type from %d to %d\n",
2186                     prefs_common.layout_mode, layout_mode);
2187
2188         /* remove widgets from those containers */
2189         gtk_widget_ref(folder_wid);
2190         gtk_widget_ref(summary_wid);
2191         gtk_widget_ref(message_wid);
2192         gtkut_container_remove
2193                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2194         gtkut_container_remove
2195                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2196         gtkut_container_remove
2197                 (GTK_CONTAINER(message_wid->parent), message_wid);
2198
2199         gtk_widget_hide(mainwin->window);
2200         main_window_set_widgets(mainwin, layout_mode);
2201         gtk_widget_show(mainwin->window);
2202
2203         gtk_widget_unref(folder_wid);
2204         gtk_widget_unref(summary_wid);
2205         gtk_widget_unref(message_wid);
2206 }
2207 #endif
2208 void mainwindow_reset_paned(GtkPaned *paned)
2209 {
2210                 gint min, max, mid;
2211
2212                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2213                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2214                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2215                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2216
2217 GTK_EVENTS_FLUSH();
2218                 g_object_get (G_OBJECT(paned),
2219                                 "min-position",
2220                                 &min, NULL);
2221                 g_object_get (G_OBJECT(paned),
2222                                 "max-position",
2223                                 &max, NULL);
2224                 mid = (min+max)/2;
2225                 gtk_paned_set_position(GTK_PANED(paned), mid);
2226 }
2227
2228 static void mainwin_paned_show_first(GtkPaned *paned)
2229 {
2230                 gint max;
2231                 g_object_get (G_OBJECT(paned),
2232                                 "max-position",
2233                                 &max, NULL);
2234
2235                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2236                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2237                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2238                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2239                 gtk_paned_set_position(GTK_PANED(paned), max);
2240 }
2241
2242 static void mainwin_paned_show_last(GtkPaned *paned)
2243 {
2244                 gint min;
2245                 g_object_get (G_OBJECT(paned),
2246                                 "min-position",
2247                                 &min, NULL);
2248
2249                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2250                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2251                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2252                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2253                 gtk_paned_set_position(GTK_PANED(paned), min);
2254 }
2255
2256 void main_window_toggle_message_view(MainWindow *mainwin)
2257 {
2258         SummaryView *summaryview = mainwin->summaryview;
2259         GtkWidget *ppaned = NULL;
2260         GtkWidget *container = NULL;
2261         
2262         switch (prefs_common.layout_mode) {
2263         case NORMAL_LAYOUT:
2264         case VERTICAL_LAYOUT:
2265         case SMALL_LAYOUT:
2266                 ppaned = mainwin->vpaned;
2267                 container = mainwin->hpaned;
2268                 if (ppaned->parent != NULL) {
2269                         mainwin->messageview->visible = FALSE;
2270                         summaryview->displayed = NULL;
2271                         gtk_widget_ref(ppaned);
2272                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2273                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2274                 } else {
2275                         mainwin->messageview->visible = TRUE;
2276                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2277                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2278                         gtk_widget_unref(ppaned);
2279                 }
2280                 break;
2281         case WIDE_LAYOUT:
2282                 ppaned = mainwin->hpaned;
2283                 container = mainwin->vpaned;
2284                 if (mainwin->messageview->vbox->parent != NULL) {
2285                         mainwin->messageview->visible = FALSE;
2286                         summaryview->displayed = NULL;
2287                         gtk_widget_ref(mainwin->messageview->vbox);
2288                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2289                 } else {
2290                         mainwin->messageview->visible = TRUE;
2291                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2292                         gtk_widget_unref(mainwin->messageview->vbox);
2293                 }
2294                 break;
2295         case WIDE_MSGLIST_LAYOUT:
2296                 g_warning("can't hide messageview in this wide msglist layout");
2297                 break;
2298         }
2299
2300         if (messageview_is_visible(mainwin->messageview))
2301                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2302                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2303         else
2304                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2305                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2306
2307         if (mainwin->messageview->visible == FALSE)
2308                 messageview_clear(mainwin->messageview);
2309
2310         main_window_set_menu_sensitive(mainwin);
2311
2312         prefs_common.msgview_visible = mainwin->messageview->visible;
2313
2314         if (messageview_is_visible(mainwin->messageview)) {
2315                 gtk_widget_queue_resize(mainwin->hpaned);
2316                 gtk_widget_queue_resize(mainwin->vpaned);
2317         }
2318         summary_grab_focus(summaryview);
2319 }
2320
2321 void main_window_get_size(MainWindow *mainwin)
2322 {
2323         GtkAllocation *allocation;
2324
2325         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2326                 debug_print("called after messageview "
2327                             "has been deallocated!\n");
2328                 return;
2329         }
2330
2331         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2332
2333         if (allocation->width > 1 && allocation->height > 1) {
2334                 prefs_common.summaryview_width = allocation->width;
2335
2336                 if (messageview_is_visible(mainwin->messageview))
2337                         prefs_common.summaryview_height = allocation->height;
2338
2339                 prefs_common.mainview_width = allocation->width;
2340         }
2341
2342         allocation = &mainwin->window->allocation;
2343         if (allocation->width > 1 && allocation->height > 1) {
2344                 prefs_common.mainview_height = allocation->height;
2345                 prefs_common.mainwin_width   = allocation->width;
2346                 prefs_common.mainwin_height  = allocation->height;
2347         }
2348
2349         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2350         if (allocation->width > 1 && allocation->height > 1) {
2351                 prefs_common.folderview_width  = allocation->width;
2352                 prefs_common.folderview_height = allocation->height;
2353         }
2354
2355         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2356         if (allocation->width > 1 && allocation->height > 1) {
2357                 prefs_common.msgview_width = allocation->width;
2358                 prefs_common.msgview_height = allocation->height;
2359         }
2360
2361 /*      debug_print("summaryview size: %d x %d\n",
2362                     prefs_common.summaryview_width,
2363                     prefs_common.summaryview_height);
2364         debug_print("folderview size: %d x %d\n",
2365                     prefs_common.folderview_width,
2366                     prefs_common.folderview_height);
2367         debug_print("messageview size: %d x %d\n",
2368                     prefs_common.msgview_width,
2369                     prefs_common.msgview_height); */
2370 }
2371
2372 void main_window_get_position(MainWindow *mainwin)
2373 {
2374         gint x, y;
2375
2376         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2377
2378         prefs_common.mainview_x = x;
2379         prefs_common.mainview_y = y;
2380         prefs_common.mainwin_x = x;
2381         prefs_common.mainwin_y = y;
2382
2383         debug_print("main window position: %d, %d\n", x, y);
2384 }
2385
2386 void main_window_progress_on(MainWindow *mainwin)
2387 {
2388         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2389 }
2390
2391 void main_window_progress_off(MainWindow *mainwin)
2392 {
2393         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2394         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2395 }
2396
2397 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2398 {
2399         gchar buf[32];
2400
2401         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2402         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2403         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2404                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2405 }
2406
2407 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2408 {
2409         if (confirm && procmsg_have_trashed_mails_fast()) {
2410                 if (alertpanel(_("Empty trash"),
2411                                _("Delete all messages in trash folders?"),
2412                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2413                     != G_ALERTALTERNATE)
2414                         return;
2415                 manage_window_focus_in(mainwin->window, NULL, NULL);
2416         }
2417
2418         procmsg_empty_all_trash();
2419
2420         if (mainwin->summaryview->folder_item &&
2421             mainwin->summaryview->folder_item->stype == F_TRASH)
2422                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2423 }
2424
2425 void main_window_add_mailbox(MainWindow *mainwin)
2426 {
2427         gchar *path;
2428         Folder *folder;
2429
2430         path = input_dialog(_("Add mailbox"),
2431                             _("Input the location of mailbox.\n"
2432                               "If an existing mailbox is specified, it will be\n"
2433                               "scanned automatically."),
2434                             "Mail");
2435         if (!path) return;
2436         if (folder_find_from_path(path)) {
2437                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2438                 g_free(path);
2439                 return;
2440         }
2441         folder = folder_new(folder_get_class_from_string("mh"), 
2442                             !strcmp(path, "Mail") ? _("Mailbox") : 
2443                             g_path_get_basename(path), path);
2444         g_free(path);
2445
2446         if (folder->klass->create_tree(folder) < 0) {
2447                 alertpanel_error(_("Creation of the mailbox failed.\n"
2448                                    "Maybe some files already exist, or you don't have the permission to write there."));
2449                 folder_destroy(folder);
2450                 return;
2451         }
2452
2453         folder_add(folder);
2454         folder_set_ui_func(folder, scan_tree_func, mainwin);
2455         folder_scan_tree(folder, TRUE);
2456         folder_set_ui_func(folder, NULL, NULL);
2457 }
2458
2459 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2460 {
2461         SensitiveCond state = 0;
2462         SummarySelection selection;
2463         FolderItem *item = mainwin->summaryview->folder_item;
2464         GList *account_list = account_get_list();
2465         GSList *tmp;
2466         
2467         selection = summary_get_selection_type(mainwin->summaryview);
2468
2469         if (mainwin->lock_count == 0 && !claws_is_starting())
2470                 state |= M_UNLOCKED;
2471         if (selection != SUMMARY_NONE)
2472                 state |= M_MSG_EXIST;
2473         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2474                 state |= M_EXEC;
2475                 /*              if (item->folder->type != F_NEWS) */
2476                 state |= M_ALLOW_DELETE;
2477
2478                 if (prefs_common.immediate_exec == 0
2479                     && mainwin->lock_count == 0)
2480                         state |= M_DELAY_EXEC;
2481
2482                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2483                     || selection != SUMMARY_NONE)
2484                         state |= M_HIDE_READ_MSG;
2485         }               
2486         if (mainwin->summaryview->threaded)
2487                 state |= M_THREADED;
2488         else
2489                 state |= M_UNTHREADED;  
2490         if (selection == SUMMARY_SELECTED_SINGLE ||
2491             selection == SUMMARY_SELECTED_MULTIPLE)
2492                 state |= M_TARGET_EXIST;
2493         if (selection == SUMMARY_SELECTED_SINGLE)
2494                 state |= M_SINGLE_TARGET_EXIST;
2495         if (mainwin->summaryview->folder_item &&
2496             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2497                 state |= M_NEWS;
2498         else
2499                 state |= M_NOT_NEWS;
2500         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2501                 state |= M_ACTIONS_EXIST;
2502
2503         tmp = tags_get_list();
2504         if (tmp && g_slist_length(tmp))
2505                 state |= M_TAGS_EXIST;
2506         g_slist_free(tmp);
2507
2508         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2509                 state |= M_HAVE_QUEUED_MAILS;
2510
2511         if (selection == SUMMARY_SELECTED_SINGLE &&
2512             (item &&
2513              (folder_has_parent_of_type(item, F_DRAFT) ||
2514               folder_has_parent_of_type(item, F_OUTBOX) ||
2515               folder_has_parent_of_type(item, F_QUEUE))))
2516                 state |= M_ALLOW_REEDIT;
2517         if (cur_account)
2518                 state |= M_HAVE_ACCOUNT;
2519         
2520         if (any_folder_want_synchronise())
2521                 state |= M_WANT_SYNC;
2522
2523         if (item && item->prefs->processing && selection != SUMMARY_NONE)
2524                 state |= M_HAVE_PROCESSING;
2525
2526         for ( ; account_list != NULL; account_list = account_list->next) {
2527                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2528                         state |= M_HAVE_NEWS_ACCOUNT;
2529                         break;
2530                 }
2531         }
2532         
2533         if (procmsg_spam_can_learn() &&
2534             (mainwin->summaryview->folder_item &&
2535              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2536              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2537                 state |= M_CAN_LEARN_SPAM;
2538         }
2539
2540         if (inc_is_active())
2541                 state |= M_INC_ACTIVE;
2542         if (imap_cancel_all_enabled())
2543                 state |= M_INC_ACTIVE;
2544
2545         if (mainwin->summaryview->deleted > 0 ||
2546             mainwin->summaryview->moved > 0 ||
2547             mainwin->summaryview->copied > 0)
2548                 state |= M_DELAY_EXEC;
2549
2550         return state;
2551 }
2552
2553
2554
2555 void main_window_set_menu_sensitive(MainWindow *mainwin)
2556 {
2557         GtkItemFactory *ifactory = mainwin->menu_factory;
2558         SensitiveCond state;
2559         gboolean sensitive;
2560         GtkWidget *menu;
2561         GtkWidget *menuitem;
2562         SummaryView *summaryview;
2563         gchar *menu_path;
2564         gint i;
2565         GList *cur_item;
2566
2567         static const struct {
2568                 gchar *const entry;
2569                 SensitiveCond cond;
2570         } entry[] = {
2571                 {"/File/Save as...", M_TARGET_EXIST},
2572                 {"/File/Print..."  , M_TARGET_EXIST},
2573                 {"/File/Synchronise folders", M_WANT_SYNC},
2574                 {"/File/Exit"      , M_UNLOCKED},
2575
2576                 {"/Edit/Select thread"             , M_TARGET_EXIST},
2577                 {"/Edit/Delete thread"             , M_TARGET_EXIST},
2578                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2579
2580                 {"/View/Set displayed columns/in Folder list..."
2581                                                    , M_UNLOCKED}, 
2582                 {"/View/Sort"                      , M_EXEC},
2583                 {"/View/Thread view"               , M_EXEC},
2584                 {"/View/Expand all threads"        , M_MSG_EXIST},
2585                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2586                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2587                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2588                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2589                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2590                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2591                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2592                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2593                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2594                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2595                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2596                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2597                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2598                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2599                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2600
2601                 {"/Message/Receive/Get from current account"
2602                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2603                 {"/Message/Receive/Get from all accounts"
2604                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2605                 {"/Message/Receive/Cancel receiving"
2606                                                  , M_INC_ACTIVE},
2607                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2608                 {"/Message/Compose an email message", M_HAVE_ACCOUNT},
2609                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2610                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2611                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2612                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2613                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2614                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2615                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2616                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2617                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2618                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2619                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2620                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2621                 {"/Message/Mark"                  , M_TARGET_EXIST},
2622                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2623                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2624                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2625                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2626                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2627                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2628                 {"/Message/Color label"           , M_TARGET_EXIST},
2629                 {"/Message/Tags"                  , M_TARGET_EXIST},
2630                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2631
2632                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2633                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2634                 {"/Tools/Harvest addresses/from Messages..."
2635                                                        , M_TARGET_EXIST},
2636                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2637                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2638                 {"/Tools/Run folder processing rules"  , M_HAVE_PROCESSING},
2639                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2640                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2641                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2642                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2643                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2644                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2645
2646                 {"/Configuration", M_UNLOCKED},
2647                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2648                 {"/Configuration/Create new account...", M_UNLOCKED},
2649                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2650
2651                 {NULL, 0}
2652         };
2653
2654         state = main_window_get_current_state(mainwin);
2655
2656         for (i = 0; entry[i].entry != NULL; i++) {
2657                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2658                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2659         }
2660
2661         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2662
2663         /* search for separator */
2664         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2665              cur_item = cur_item->next) {
2666                 if (GTK_BIN(cur_item->data)->child == NULL) {
2667                         cur_item = cur_item->next;
2668                         break;
2669                 }
2670         }
2671
2672         for (; cur_item != NULL; cur_item = cur_item->next) {
2673                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2674                                          (M_UNLOCKED & state) != 0);
2675         }
2676
2677         main_window_menu_callback_block(mainwin);
2678
2679 #define SET_CHECK_MENU_ACTIVE(path, active) \
2680 { \
2681         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2682         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2683 }
2684
2685         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2686                               messageview_is_visible(mainwin->messageview));
2687
2688         summaryview = mainwin->summaryview;
2689         menu_path = "/View/Sort/Don't sort";
2690
2691         switch (summaryview->sort_key) {
2692         case SORT_BY_NUMBER:
2693                 menu_path = "/View/Sort/by number"; break;
2694         case SORT_BY_SIZE:
2695                 menu_path = "/View/Sort/by Size"; break;
2696         case SORT_BY_DATE:
2697                 menu_path = "/View/Sort/by Date"; break;
2698         case SORT_BY_THREAD_DATE:
2699                 menu_path = "/View/Sort/by Thread date"; break;
2700         case SORT_BY_FROM:
2701                 menu_path = "/View/Sort/by From"; break;
2702         case SORT_BY_TO:
2703                 menu_path = "/View/Sort/by To"; break;
2704         case SORT_BY_SUBJECT:
2705                 menu_path = "/View/Sort/by Subject"; break;
2706         case SORT_BY_LABEL:
2707                 menu_path = "/View/Sort/by color label"; break;
2708         case SORT_BY_MARK:
2709                 menu_path = "/View/Sort/by mark"; break;
2710         case SORT_BY_STATUS:
2711                 menu_path = "/View/Sort/by status"; break;
2712         case SORT_BY_MIME:
2713                 menu_path = "/View/Sort/by attachment"; break;
2714         case SORT_BY_SCORE:
2715                 menu_path = "/View/Sort/by score"; break;
2716         case SORT_BY_LOCKED:
2717                 menu_path = "/View/Sort/by locked"; break;
2718         case SORT_BY_TAGS:
2719                 menu_path = "/View/Sort/by tag"; break;
2720         case SORT_BY_NONE:
2721         default:
2722                 menu_path = "/View/Sort/Don't sort"; break;
2723         }
2724         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2725
2726         if (summaryview->sort_type == SORT_ASCENDING) {
2727                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2728         } else {
2729                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2730         }
2731
2732         if (summaryview->sort_key != SORT_BY_NONE) {
2733                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2734                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2735         } else {
2736                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2737                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2738         }
2739
2740         if (mainwin->messageview 
2741         &&  mainwin->messageview->mimeview
2742         &&  mainwin->messageview->mimeview->textview)
2743                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2744                               mainwin->messageview->mimeview->textview->show_all_headers);
2745         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2746         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2747         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2748         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2749         if (prefs_common.hide_quotes == 1)
2750                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2751         if (prefs_common.hide_quotes == 2)
2752                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2753         if (prefs_common.hide_quotes == 3)
2754                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2755
2756 #undef SET_CHECK_MENU_ACTIVE
2757
2758         main_window_menu_callback_unblock(mainwin);
2759 }
2760
2761 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2762 {
2763         GtkItemFactory *ifactory;
2764         gint is_menu = 0;
2765         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2766         
2767         if (msginfo) 
2768                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2769         if (is_menu)
2770                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2771                                 (ifactory,"/Message/Mailing-List"), TRUE);
2772         else
2773                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2774                                 (ifactory,"/Message/Mailing-List"), FALSE);
2775 }
2776
2777 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2778 {
2779         gint menu_nb = 0;
2780         GtkWidget *menuitem;
2781         
2782         if (!msginfo || !msginfo->extradata) {
2783                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2784                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2785                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2786                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2787                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2788                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2789                 return 0;
2790         }
2791                 
2792         /* Mailing list post */
2793         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2794                 g_free(msginfo->extradata->list_post);
2795                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2796         }
2797         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2798                 
2799         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2800  
2801         /* Mailing list help */
2802         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2803         
2804         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2805
2806         /* Mailing list subscribe */
2807         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2808         
2809         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2810                 
2811         /* Mailing list unsubscribe */
2812         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2813         
2814         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2815         
2816         /* Mailing list view archive */
2817         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2818         
2819         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2820         
2821         /* Mailing list contact owner */
2822         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2823         
2824         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2825         
2826         return menu_nb;
2827 }
2828
2829 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2830 {
2831         GtkWidget *item, *menu;
2832         const gchar *url_pt ;
2833         gchar url_decoded[BUFFSIZE];
2834         GList *amenu, *alist;
2835         gint menu_nb = 0;
2836         
2837         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2838         
2839         /* First delete old submenu */
2840         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2841         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2842                 alist = amenu->next;
2843                 item = GTK_WIDGET (amenu->data);
2844                 gtk_widget_destroy (item);
2845                 amenu = alist;
2846         }
2847         if (list_header) {
2848                 for (url_pt = list_header; url_pt && *url_pt;) {
2849                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2850                         item = NULL;
2851                         if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
2852                                 item = gtk_menu_item_new_with_label ((url_decoded));
2853                                 g_signal_connect(G_OBJECT(item), "activate",
2854                                                  G_CALLBACK(mailing_list_compose),
2855                                                  NULL);
2856                         }
2857                         else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
2858                                  !g_ascii_strncasecmp(url_decoded, "https:",6)) {
2859
2860                                 item = gtk_menu_item_new_with_label ((url_decoded));
2861                                 g_signal_connect(G_OBJECT(item), "activate",
2862                                                  G_CALLBACK(mailing_list_open_uri),
2863                                                  NULL);
2864                         } 
2865                         if (item) {
2866                                 gtk_menu_append (GTK_MENU(menu), item);
2867                                 gtk_widget_show (item);
2868                                 menu_nb++;
2869                         }
2870                 }
2871         }
2872         if (menu_nb)
2873                 gtk_widget_set_sensitive (menuitem, TRUE);
2874         else
2875                 gtk_widget_set_sensitive (menuitem, FALSE);
2876                 
2877
2878         return menu_nb;
2879 }
2880
2881 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2882 {
2883         gchar tmp[BUFFSIZE];
2884         const gchar *buf;
2885         gint i = 0;
2886         buf = *buffer;
2887         gboolean with_plus = TRUE;
2888
2889         if (buf == 0x00) {
2890                 *url_decoded = '\0';
2891                 *buffer = NULL;
2892                 return;
2893         }
2894         /* Ignore spaces, comments  and tabs () */
2895         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2896                 if (*buf == '(')
2897                         for (;*buf != ')' && *buf != 0x00; buf++);
2898         
2899         /* First non space and non comment must be a < */
2900         if (*buf =='<' ) {
2901                 buf++;
2902                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2903                         with_plus = FALSE;
2904                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2905                 buf++;
2906         }
2907         else  {
2908                 *buffer = NULL;
2909                 *url_decoded = '\0';
2910                 return;
2911         }
2912         
2913         tmp[i]       = 0x00;
2914         *url_decoded = '\0';
2915         *buffer = NULL;
2916         
2917         if (i == maxlen) {
2918                 return;
2919         }
2920         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2921
2922         /* Prepare the work for the next url in the list */
2923         /* after the closing bracket >, ignore space, comments and tabs */
2924         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2925                 if (*buf == '(')
2926                         for (;*buf != ')' && *buf != 0x00; buf++);
2927                         
2928         if (!buf || !*buf) {
2929                 *buffer = NULL;
2930                 return;
2931         }
2932
2933         /* now first non space, non comment must be a comma */
2934         if (*buf != ',')
2935                 for (;*buf != 0x00; buf++);
2936         else
2937                 buf++;
2938         *buffer = buf;
2939 }
2940         
2941 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2942 {
2943         gchar *mailto;
2944
2945         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2946         compose_new(NULL, mailto+7, NULL);
2947 }
2948  
2949  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2950 {
2951  
2952         gchar *mailto;
2953  
2954         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2955         open_uri (mailto, prefs_common.uri_cmd);
2956
2957         
2958 void main_window_popup(MainWindow *mainwin)
2959 {
2960         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2961                 main_window_show(mainwin);
2962
2963         gtkut_window_popup(mainwin->window);
2964         if (prefs_common.layout_mode == SMALL_LAYOUT) {
2965                 if (mainwin->in_folder) {
2966                         mainwindow_enter_folder(mainwin);
2967                 } else {
2968                         mainwindow_exit_folder(mainwin);
2969                 }
2970         }
2971 }
2972
2973 void main_window_show(MainWindow *mainwin)
2974 {
2975         gtk_widget_show(mainwin->window);
2976         gtk_widget_show(mainwin->vbox_body);
2977
2978         gtk_widget_set_uposition(mainwin->window,
2979                                  prefs_common.mainwin_x,
2980                                  prefs_common.mainwin_y);
2981
2982         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2983                              prefs_common.folderview_width,
2984                              prefs_common.folderview_height);
2985         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2986                              prefs_common.summaryview_width,
2987                              prefs_common.summaryview_height);
2988         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2989                              prefs_common.msgview_width,
2990                              prefs_common.msgview_height);
2991 }
2992
2993 void main_window_hide(MainWindow *mainwin)
2994 {
2995         main_window_get_size(mainwin);
2996         main_window_get_position(mainwin);
2997
2998         gtk_widget_hide(mainwin->window);
2999         gtk_widget_hide(mainwin->vbox_body);
3000 }
3001
3002 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
3003 {
3004         GtkWidget *folderwin = NULL;
3005         GtkWidget *messagewin = NULL;
3006         GtkWidget *hpaned;
3007         GtkWidget *vpaned;
3008         GtkWidget *vbox_body = mainwin->vbox_body;
3009         GtkItemFactory *ifactory = mainwin->menu_factory;
3010         GtkWidget *menuitem;
3011         gboolean first_set = (mainwin->hpaned == NULL);
3012         debug_print("Setting widgets... ");
3013
3014         if (layout_mode == SMALL_LAYOUT && first_set) {
3015                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3016                                     prefs_common.folderview_width,
3017                                     prefs_common.folderview_height);
3018                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3019                                     0,0);
3020                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3021                                     0,0);
3022         } else {
3023                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3024                                     prefs_common.folderview_width,
3025                                     prefs_common.folderview_height);
3026                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3027                                     prefs_common.summaryview_width,
3028                                     prefs_common.summaryview_height);
3029                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3030                                     prefs_common.msgview_width,
3031                                     prefs_common.msgview_height);
3032         }
3033
3034 #ifndef MAEMO
3035         mainwin->messageview->statusbar = mainwin->statusbar;
3036         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3037 #endif
3038         /* clean top-most container */
3039         if (mainwin->hpaned) {
3040                 if (mainwin->hpaned->parent == mainwin->vpaned)
3041                         gtk_widget_destroy(mainwin->vpaned);
3042                 else
3043                         gtk_widget_destroy(mainwin->hpaned);
3044         }
3045
3046         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
3047                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3048         switch (layout_mode) {
3049         case VERTICAL_LAYOUT:
3050         case NORMAL_LAYOUT:
3051         case SMALL_LAYOUT:
3052                 hpaned = gtk_hpaned_new();
3053                 if (layout_mode == VERTICAL_LAYOUT)
3054                         vpaned = gtk_hpaned_new();
3055                 else
3056                         vpaned = gtk_vpaned_new();
3057                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3058                 gtk_paned_add1(GTK_PANED(hpaned),
3059                                GTK_WIDGET_PTR(mainwin->folderview));
3060                 gtk_widget_show(hpaned);
3061                 gtk_widget_queue_resize(hpaned);
3062
3063                 if (messageview_is_visible(mainwin->messageview)) {
3064                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3065                         gtk_paned_add1(GTK_PANED(vpaned),
3066                                        GTK_WIDGET_PTR(mainwin->summaryview));
3067                 } else {
3068                         gtk_paned_add2(GTK_PANED(hpaned),
3069                                        GTK_WIDGET_PTR(mainwin->summaryview));
3070                         gtk_widget_ref(vpaned);
3071                 }
3072                 gtk_paned_add2(GTK_PANED(vpaned),
3073                                GTK_WIDGET_PTR(mainwin->messageview));
3074                 gtk_widget_show(vpaned);
3075                 if (layout_mode == SMALL_LAYOUT && first_set) {
3076                         mainwin_paned_show_first(GTK_PANED(hpaned));
3077                 }
3078                 gtk_widget_queue_resize(vpaned);
3079                 break;
3080         case WIDE_LAYOUT:
3081                 vpaned = gtk_vpaned_new();
3082                 hpaned = gtk_hpaned_new();
3083                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3084                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3085
3086                 gtk_paned_add1(GTK_PANED(hpaned),
3087                                GTK_WIDGET_PTR(mainwin->folderview));
3088                 gtk_paned_add2(GTK_PANED(hpaned),
3089                                GTK_WIDGET_PTR(mainwin->summaryview));
3090
3091                 gtk_widget_show(hpaned);
3092                 gtk_widget_queue_resize(hpaned);
3093
3094                 if (messageview_is_visible(mainwin->messageview)) {
3095                         gtk_paned_add2(GTK_PANED(vpaned),
3096                                GTK_WIDGET_PTR(mainwin->messageview));   
3097                 } else {
3098                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3099                 }
3100                 gtk_widget_show(vpaned);
3101                 gtk_widget_queue_resize(vpaned);
3102                 break;
3103         case WIDE_MSGLIST_LAYOUT:
3104                 vpaned = gtk_vpaned_new();
3105                 hpaned = gtk_hpaned_new();
3106                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3107
3108                 gtk_paned_add1(GTK_PANED(vpaned),
3109                                GTK_WIDGET_PTR(mainwin->summaryview));
3110                 gtk_paned_add1(GTK_PANED(hpaned),
3111                                GTK_WIDGET_PTR(mainwin->folderview));
3112
3113                 gtk_widget_show(hpaned);
3114                 gtk_widget_queue_resize(hpaned);
3115
3116                 if (messageview_is_visible(mainwin->messageview)) {
3117                         gtk_paned_add2(GTK_PANED(hpaned),
3118                                GTK_WIDGET_PTR(mainwin->messageview));   
3119                 } else {
3120                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3121                 }
3122                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3123
3124                 gtk_widget_show(vpaned);
3125                 gtk_widget_queue_resize(vpaned);
3126                 break;
3127         default:
3128                 g_warning("Unknown layout");
3129                 return;
3130         }
3131
3132         mainwin->hpaned = hpaned;
3133         mainwin->vpaned = vpaned;
3134
3135         if (layout_mode == SMALL_LAYOUT) {
3136                 if (mainwin->messageview->visible)
3137                         main_window_toggle_message_view(mainwin);
3138         } 
3139
3140         if (layout_mode == SMALL_LAYOUT && first_set) {
3141                 gtk_widget_realize(mainwin->window);
3142                 gtk_widget_realize(mainwin->folderview->ctree);
3143                 gtk_widget_realize(mainwin->summaryview->hbox);
3144                 gtk_widget_realize(mainwin->summaryview->hbox_l);
3145                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3146                                     prefs_common.folderview_width,
3147                                     prefs_common.folderview_height);
3148                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3149                                     0,0);
3150                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3151                                     0,0);
3152                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3153                                 prefs_common.mainwin_width,
3154                                 prefs_common.mainwin_height);
3155                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3156         } 
3157         /* remove headerview if not in prefs */
3158         headerview_set_visibility(mainwin->messageview->headerview,
3159                                   prefs_common.display_header_pane);
3160
3161         if (messageview_is_visible(mainwin->messageview))
3162                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3163                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3164         else
3165                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3166                               GTK_ARROW_UP, GTK_SHADOW_OUT);
3167
3168         gtk_window_move(GTK_WINDOW(mainwin->window),
3169                         prefs_common.mainwin_x,
3170                         prefs_common.mainwin_y);
3171
3172         gtk_widget_queue_resize(vbox_body);
3173         gtk_widget_queue_resize(mainwin->vbox);
3174         gtk_widget_queue_resize(mainwin->window);
3175         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3176          * and mimeview icon list/ctree lose track of their visibility states */
3177         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
3178                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3179         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
3180                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3181         if (mainwin->messageview->mimeview->ctree_mode)
3182                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3183         else 
3184                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3185
3186         prefs_common.layout_mode = layout_mode;
3187
3188         menuitem = gtk_item_factory_get_item
3189                 (ifactory, "/View/Show or hide/Message view");
3190         gtk_check_menu_item_set_active
3191                 (GTK_CHECK_MENU_ITEM(menuitem),
3192                  messageview_is_visible(mainwin->messageview));
3193
3194 #define SET_CHECK_MENU_ACTIVE(path, active) \
3195 { \
3196         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3197         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3198 }
3199
3200 #ifndef MAEMO
3201         switch (prefs_common.layout_mode) {
3202         case NORMAL_LAYOUT:
3203                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3204                 break;
3205         case VERTICAL_LAYOUT:
3206                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3207                 break;
3208         case WIDE_LAYOUT:
3209                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3210                 break;
3211         case WIDE_MSGLIST_LAYOUT:
3212                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3213                 break;
3214         case SMALL_LAYOUT:
3215                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3216                 break;
3217         }
3218 #endif
3219 #undef SET_CHECK_MENU_ACTIVE
3220
3221         if (folderwin) {
3222                 g_signal_connect
3223                         (G_OBJECT(folderwin), "size_allocate",
3224                          G_CALLBACK(folder_window_size_allocate_cb),
3225                          mainwin);
3226         }
3227         if (messagewin) {
3228                 g_signal_connect
3229                         (G_OBJECT(messagewin), "size_allocate",
3230                          G_CALLBACK(message_window_size_allocate_cb),
3231                          mainwin);
3232         }
3233
3234         debug_print("done.\n");
3235 }
3236
3237 void main_window_destroy_all(void)
3238 {
3239         while (mainwin_list != NULL) {
3240                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3241                 
3242                 /* free toolbar stuff */
3243                 toolbar_clear_list(TOOLBAR_MAIN);
3244                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3245                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3246
3247                 mainwin->folderview->mainwin = NULL;
3248                 mainwin->summaryview->mainwin = NULL;
3249                 mainwin->messageview->mainwin = NULL;
3250
3251                 g_free(mainwin->toolbar);
3252                 g_free(mainwin);
3253                 
3254                 mainwin_list = g_list_remove(mainwin_list, mainwin);
3255         }
3256         g_list_free(mainwin_list);
3257         mainwin_list = NULL;
3258 }
3259
3260 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3261                                    gpointer data)
3262 {
3263         gtk_widget_set_size_request(child, 1, -1);
3264 }
3265
3266 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3267                                    gpointer data)
3268 {
3269         gtk_widget_set_size_request(child, -1, -1);
3270 }
3271 #ifndef MAEMO
3272 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3273                                     gpointer data)
3274 {
3275         MainWindow *mainwin = (MainWindow *)data;
3276
3277         if (!event) return FALSE;
3278
3279         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3280         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3281                           widget);
3282
3283         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3284                        menu_button_position, widget,
3285                        event->button, event->time);
3286
3287         return TRUE;
3288 }
3289 #endif
3290 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3291                                  gpointer data)
3292 {
3293         MainWindow *mainwin = (MainWindow *)data;
3294         gboolean close_allowed = TRUE;
3295
3296         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3297
3298         if (close_allowed && mainwin->lock_count == 0)
3299                 app_exit_cb(data, 0, widget);
3300
3301         return TRUE;
3302 }
3303
3304 static void main_window_size_allocate_cb(GtkWidget *widget,
3305                                          GtkAllocation *allocation,
3306                                          gpointer data)
3307 {
3308         MainWindow *mainwin = (MainWindow *)data;
3309         main_window_get_size(mainwin);
3310 }
3311
3312 static void folder_window_size_allocate_cb(GtkWidget *widget,
3313                                            GtkAllocation *allocation,
3314                                            gpointer data)
3315 {
3316         MainWindow *mainwin = (MainWindow *)data;
3317
3318         main_window_get_size(mainwin);
3319 }
3320
3321 static void message_window_size_allocate_cb(GtkWidget *widget,
3322                                             GtkAllocation *allocation,
3323                                             gpointer data)
3324 {
3325         MainWindow *mainwin = (MainWindow *)data;
3326
3327         main_window_get_size(mainwin);
3328 }
3329
3330 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3331                            GtkWidget *widget)
3332 {
3333         main_window_add_mailbox(mainwin);
3334 }
3335
3336 static void update_folderview_cb(MainWindow *mainwin, guint action,
3337                                  GtkWidget *widget)
3338 {
3339         summary_show(mainwin->summaryview, NULL);
3340         folderview_check_new_all();
3341 }
3342
3343 static void foldersort_cb(MainWindow *mainwin, guint action,
3344                            GtkWidget *widget)
3345 {
3346         foldersort_open();
3347 }
3348
3349 static void import_mbox_cb(MainWindow *mainwin, guint action,
3350                            GtkWidget *widget)
3351 {
3352         /* only notify if import has failed */
3353         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3354                 alertpanel_error(_("Mbox import has failed."));
3355         }
3356 }
3357
3358 static void export_mbox_cb(MainWindow *mainwin, guint action,
3359                            GtkWidget *widget)
3360 {
3361         /* only notify if export has failed */
3362         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3363                 alertpanel_error(_("Export to mbox has failed."));
3364         }
3365 }
3366
3367 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3368                                 GtkWidget *widget)
3369 {
3370         /* only notify if export has failed */
3371         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3372                 alertpanel_error(_("Export to mbox has failed."));
3373         }
3374 }
3375
3376 static void empty_trash_cb(MainWindow *mainwin, guint action,
3377                            GtkWidget *widget)
3378 {
3379         main_window_empty_trash(mainwin, TRUE);
3380 }
3381
3382 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3383 {
3384         summary_save_as(mainwin->summaryview);
3385 }
3386
3387 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3388 {
3389         summary_print(mainwin->summaryview);
3390 }
3391
3392 #if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
3393 static void page_setup_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3394 {
3395         MainWindow *mainwindow;
3396         GtkWindow *win;
3397
3398         mainwindow = mainwindow_get_mainwindow();
3399         win = (mainwindow ? GTK_WINDOW(mainwindow->window) : NULL);
3400
3401         printing_page_setup(win);
3402 }
3403 #endif
3404
3405 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3406 {
3407         if (prefs_common.confirm_on_exit) {
3408                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3409                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3410                     != G_ALERTALTERNATE)
3411                         return;
3412                 manage_window_focus_in(mainwin->window, NULL, NULL);
3413         }
3414
3415         app_will_exit(widget, mainwin);
3416 }
3417
3418 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3419 {
3420         if (action == 1)
3421                 summary_search(mainwin->summaryview);
3422         else
3423                 message_search(mainwin->messageview);
3424 }
3425
3426 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3427 {
3428         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3429 }
3430
3431 static void toggle_message_cb(MainWindow *mainwin, guint action,
3432                               GtkWidget *widget)
3433 {
3434         gboolean active;
3435
3436         active = GTK_CHECK_MENU_ITEM(widget)->active;
3437
3438         if (active != messageview_is_visible(mainwin->messageview))
3439                 summary_toggle_view(mainwin->summaryview);
3440 }
3441
3442 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3443                               GtkWidget *widget)
3444 {
3445         toolbar_toggle(action, mainwin);
3446 }
3447
3448 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3449                           GtkWidget *widget)
3450 {
3451         MessageView *msgview = (MessageView*)mainwin->messageview;
3452         GSList *msginfo_list = NULL;
3453
3454         g_return_if_fail(msgview != NULL);
3455
3456         msginfo_list = summary_get_selection(mainwin->summaryview);
3457         g_return_if_fail(msginfo_list != NULL);
3458         compose_reply_from_messageview(msgview, msginfo_list, action);
3459         g_slist_free(msginfo_list);
3460 }
3461
3462 static void toggle_col_headers_cb(MainWindow *mainwin, guint action,
3463                                 GtkWidget *widget)
3464 {
3465         FolderView *folderview = mainwin->folderview;
3466         SummaryView *summaryview = mainwin->summaryview;
3467
3468         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3469                 gtk_clist_column_titles_show(GTK_CLIST(folderview->ctree));
3470                 gtk_clist_column_titles_show(GTK_CLIST(summaryview->ctree));
3471                 prefs_common.show_col_headers = TRUE;
3472         } else {
3473                 gtk_clist_column_titles_hide(GTK_CLIST(folderview->ctree));
3474                 gtk_clist_column_titles_hide(GTK_CLIST(summaryview->ctree));
3475                 prefs_common.show_col_headers = FALSE;
3476         }
3477 }
3478
3479 #ifndef MAEMO
3480 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3481                                 GtkWidget *widget)
3482 {
3483         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3484                 gtk_widget_show(mainwin->hbox_stat);
3485                 prefs_common.show_statusbar = TRUE;
3486         } else {
3487                 gtk_widget_hide(mainwin->hbox_stat);
3488                 prefs_common.show_statusbar = FALSE;
3489         }
3490 }
3491
3492 static void set_layout_cb(MainWindow *mainwin, guint action,
3493                                GtkWidget *widget)
3494 {
3495         LayoutType layout_mode = action;
3496         LayoutType old_layout_mode = prefs_common.layout_mode;
3497         if (mainwin->menu_lock_count) {
3498                 return;
3499         }
3500         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3501                 return;
3502         }
3503         
3504         if (layout_mode == prefs_common.layout_mode) {
3505                 return;
3506         }
3507         
3508         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3509                 main_window_toggle_message_view(mainwin);
3510         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3511                 main_window_toggle_message_view(mainwin);
3512
3513         main_window_separation_change(mainwin, layout_mode);
3514         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3515         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3516                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3517         }
3518         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3519                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3520                 mainwindow_exit_folder(mainwin);
3521         }
3522         summary_relayout(mainwin->summaryview); 
3523         summary_update_unread(mainwin->summaryview, NULL);
3524 }
3525 #endif
3526
3527 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3528                                         gboolean ask_sync)
3529 {
3530         offline_ask_sync = ask_sync;
3531         if (offline)
3532                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3533         else
3534                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3535         offline_ask_sync = TRUE;
3536 }
3537
3538 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3539 {
3540         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3541 }
3542
3543 static gboolean any_folder_want_synchronise(void)
3544 {
3545         GList *folderlist = folder_get_list();
3546
3547         /* see if there are synchronised folders */
3548         for (; folderlist; folderlist = folderlist->next) {
3549                 Folder *folder = (Folder *)folderlist->data;
3550                 if (folder_want_synchronise(folder)) {
3551                         return TRUE;
3552                 }
3553         }
3554         
3555         return FALSE;
3556 }
3557
3558 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3559 {
3560         
3561         if (!any_folder_want_synchronise())
3562                 return;
3563
3564         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3565                         _("Do you want to synchronise your folders now?"),
3566                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3567                 return;
3568         
3569         if (offline_ask_sync)
3570                 folder_synchronise(NULL);
3571 }
3572
3573 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3574 {
3575         MainWindow *mainwin;
3576         GtkItemFactory *ifactory;
3577         GtkCheckMenuItem *menuitem;
3578
3579         mainwin = (MainWindow *) data;
3580         
3581         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3582         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3583         
3584         g_return_if_fail(mainwin != NULL);
3585         g_return_if_fail(menuitem != NULL);
3586         
3587         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3588 #ifndef MAEMO
3589                 gtk_widget_hide (mainwin->online_switch);
3590                 gtk_widget_show (mainwin->offline_switch);
3591 #endif
3592                 menuitem->active = TRUE;
3593                 inc_autocheck_timer_remove();
3594                         
3595                 /* go offline */
3596                 if (prefs_common.work_offline)
3597                         return;
3598                 mainwindow_check_synchronise(mainwin, TRUE);
3599                 prefs_common.work_offline = TRUE;
3600                 imap_disconnect_all();
3601                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3602         } else {
3603                 /*go online */
3604                 if (!prefs_common.work_offline)
3605                         return;
3606 #ifndef MAEMO
3607                 gtk_widget_hide (mainwin->offline_switch);
3608                 gtk_widget_show (mainwin->online_switch);
3609 #endif
3610                 menuitem->active = FALSE;
3611                 prefs_common.work_offline = FALSE;
3612                 inc_autocheck_timer_set();
3613                 refresh_resolvers();
3614                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3615         }
3616 }
3617
3618 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3619                                 GtkWidget *widget)
3620 {
3621         addressbook_open(NULL);
3622 }
3623
3624 static void log_window_show_cb(MainWindow *mainwin, guint action,
3625                                GtkWidget *widget)
3626 {
3627         log_window_show(mainwin->logwin);
3628 }
3629
3630 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3631                                GtkWidget *widget)
3632 {
3633         log_window_show(mainwin->filtering_debugwin);
3634 }
3635
3636 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3637 {
3638         inc_cancel_all();
3639         imap_cancel_all();
3640 }
3641
3642 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3643 {
3644         summary_move_to(mainwin->summaryview);
3645 }
3646
3647 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3648 {
3649         summary_copy_to(mainwin->summaryview);
3650 }
3651
3652 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3653 {
3654         summary_delete(mainwin->summaryview);
3655 }
3656
3657 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3658 {
3659         summary_delete_trash(mainwin->summaryview);
3660 }
3661
3662 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3663 {
3664         summary_cancel(mainwin->summaryview);
3665 }
3666
3667 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3668 {
3669         summary_open_msg(mainwin->summaryview);
3670 }
3671
3672 static void view_source_cb(MainWindow *mainwin, guint action,
3673                            GtkWidget *widget)
3674 {
3675         summary_view_source(mainwin->summaryview);
3676 }
3677
3678 static void show_all_header_cb(MainWindow *mainwin, guint action,
3679                                GtkWidget *widget)
3680 {
3681         if (mainwin->menu_lock_count) return;
3682         mainwin->summaryview->messageview->all_headers = 
3683                         GTK_CHECK_MENU_ITEM(widget)->active;
3684         summary_display_msg_selected(mainwin->summaryview,
3685                                      GTK_CHECK_MENU_ITEM(widget)->active);
3686 }
3687
3688 #define SET_CHECK_MENU_ACTIVE(path, active) \
3689 { \
3690         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3691         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3692 }
3693
3694 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3695                                GtkWidget *widget)
3696 {
3697         GtkWidget *menuitem;
3698         GtkItemFactory *ifactory = mainwin->menu_factory;
3699
3700         if (mainwin->menu_lock_count) return;
3701
3702         prefs_common.hide_quotes = 
3703                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3704
3705         mainwin->menu_lock_count++;
3706         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3707         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3708         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3709         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3710         mainwin->menu_lock_count--;
3711
3712         summary_redisplay_msg(mainwin->summaryview);
3713 }
3714
3715 #undef SET_CHECK_MENU_ACTIVE
3716 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3717 {
3718         summary_mark(mainwin->summaryview);
3719 }
3720
3721 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3722 {
3723         summary_unmark(mainwin->summaryview);
3724 }
3725
3726 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3727                               GtkWidget *widget)
3728 {
3729         summary_mark_as_unread(mainwin->summaryview);
3730 }
3731
3732 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3733                             GtkWidget *widget)
3734 {
3735         summary_mark_as_read(mainwin->summaryview);
3736 }
3737
3738 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3739                              GtkWidget *widget)
3740 {
3741         summary_mark_all_read(mainwin->summaryview);
3742 }
3743
3744 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3745                              GtkWidget *widget)
3746 {
3747         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3748 }
3749
3750 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3751                             GtkWidget *widget)
3752 {
3753         summary_ignore_thread(mainwin->summaryview);
3754 }
3755
3756 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3757                             GtkWidget *widget)
3758 {
3759         summary_unignore_thread(mainwin->summaryview);
3760 }
3761
3762 static void watch_thread_cb(MainWindow *mainwin, guint action,
3763                             GtkWidget *widget)
3764 {
3765         summary_watch_thread(mainwin->summaryview);
3766 }
3767
3768 static void unwatch_thread_cb(MainWindow *mainwin, guint action,
3769                             GtkWidget *widget)
3770 {
3771         summary_unwatch_thread(mainwin->summaryview);
3772 }
3773
3774 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3775                             GtkWidget *widget)
3776 {
3777         summary_msgs_lock(mainwin->summaryview);
3778 }
3779
3780 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3781                             GtkWidget *widget)
3782 {
3783         summary_msgs_unlock(mainwin->summaryview);
3784 }
3785
3786
3787 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3788 {
3789         summary_reedit(mainwin->summaryview);
3790 }
3791
3792 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3793 {
3794         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3795                 summary_display_msg_selected(mainwin->summaryview, 
3796                         mainwin->messageview->mimeview->textview->show_all_headers);
3797         }
3798         messageview_list_urls(mainwin->messageview);
3799 }
3800
3801 static void add_address_cb(MainWindow *mainwin, guint action,
3802                            GtkWidget *widget)
3803 {
3804         summary_add_address(mainwin->summaryview);
3805 }
3806
3807 static void set_charset_cb(MainWindow *mainwin, guint action,
3808                            GtkWidget *widget)
3809 {
3810         const gchar *str;
3811
3812         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3813                 str = conv_get_charset_str((CharSet)action);
3814                 
3815                 g_free(mainwin->messageview->forced_charset);
3816                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3817                 procmime_force_charset(str);
3818                 
3819                 summary_redisplay_msg(mainwin->summaryview);
3820                 
3821                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3822         }
3823 }
3824
3825 static void set_decode_cb(MainWindow *mainwin, guint action,
3826                            GtkWidget *widget)
3827 {
3828         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3829                 mainwin->messageview->forced_encoding = (EncodingType)action;
3830                 
3831                 summary_redisplay_msg(mainwin->summaryview);
3832                 
3833                 debug_print("forced encoding: %d\n", action);
3834         }
3835 }
3836
3837 static void hide_read_messages (MainWindow *mainwin, guint action,
3838                                 GtkWidget *widget)
3839 {
3840         if (!mainwin->summaryview->folder_item
3841             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3842                 return;
3843         summary_toggle_show_read_messages(mainwin->summaryview);
3844 }
3845
3846 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3847 {
3848         gboolean threaded = FALSE;
3849         if (mainwin->menu_lock_count) return;
3850         if (!mainwin->summaryview->folder_item) return;
3851
3852         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3853
3854         mainwin->summaryview->folder_item->threaded = threaded; 
3855
3856         mainwin->summaryview->threaded = threaded;
3857
3858         summary_show(mainwin->summaryview, 
3859                         mainwin->summaryview->folder_item);
3860 }
3861
3862 static void expand_threads_cb(MainWindow *mainwin, guint action,
3863                               GtkWidget *widget)
3864 {
3865         summary_expand_threads(mainwin->summaryview);
3866 }
3867
3868 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3869                                 GtkWidget *widget)
3870 {
3871         summary_collapse_threads(mainwin->summaryview);
3872 }
3873
3874 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3875                                 GtkWidget *widget)
3876 {
3877         prefs_summary_column_open();
3878 }
3879
3880 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3881                                 GtkWidget *widget)
3882 {
3883         prefs_folder_column_open();
3884 }
3885
3886 static void sort_summary_cb(MainWindow *mainwin, guint action,
3887                             GtkWidget *widget)
3888 {
3889         FolderItem *item = mainwin->summaryview->folder_item;
3890         GtkWidget *menuitem;
3891
3892         if (mainwin->menu_lock_count) return;
3893
3894         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3895                 menuitem = gtk_item_factory_get_item
3896                         (mainwin->menu_factory, "/View/Sort/Ascending");
3897                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3898                              GTK_CHECK_MENU_ITEM(menuitem)->active
3899                              ? SORT_ASCENDING : SORT_DESCENDING);
3900                 item->sort_key = action;
3901         }
3902 }
3903
3904 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3905                                  GtkWidget *widget)
3906 {
3907         FolderItem *item = mainwin->summaryview->folder_item;
3908
3909         if (mainwin->menu_lock_count) return;
3910
3911         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3912                 summary_sort(mainwin->summaryview,
3913                              item->sort_key, (FolderSortType)action);
3914 }
3915
3916 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3917                                   GtkWidget *widget)
3918 {
3919         summary_attract_by_subject(mainwin->summaryview);
3920 }
3921
3922 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3923                                  GtkWidget *widget)
3924 {
3925         FolderItem *item;
3926
3927         item = folderview_get_selected_item(mainwin->folderview);
3928         if (item) {
3929                 main_window_cursor_wait(mainwin);
3930                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3931
3932                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3933                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3934
3935                 STATUSBAR_POP(mainwin);
3936                 main_window_cursor_normal(mainwin);
3937         }
3938 }
3939
3940 struct DelDupsData
3941 {
3942         guint   dups;
3943         guint   folders;
3944 };
3945
3946 static void deldup_all(FolderItem *item, gpointer _data)
3947 {
3948         struct DelDupsData *data = _data;
3949         gint result;
3950         
3951         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3952         if (result >= 0) {
3953                 data->dups += result;
3954                 data->folders += 1;
3955         }
3956 }
3957
3958 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3959                                  GtkWidget *widget)
3960 {
3961         struct DelDupsData data = {0, 0};
3962
3963         main_window_cursor_wait(mainwin);
3964         folder_func_to_all_folders(deldup_all, &data);
3965         main_window_cursor_normal(mainwin);
3966         
3967         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3968                                    "Deleted %d duplicate messages in %d folders.\n",
3969                                    data.dups),
3970                           data.dups, data.folders);
3971 }
3972
3973 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3974 {
3975         summary_filter(mainwin->summaryview, (gboolean)action);
3976 }
3977
3978 static void process_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3979 {
3980         FolderItem *item = mainwin->summaryview->folder_item;   
3981         g_return_if_fail(item != NULL);
3982
3983         folder_item_apply_processing(item);     
3984 }
3985
3986 static void execute_summary_cb(MainWindow *mainwin, guint action,
3987                                GtkWidget *widget)
3988 {
3989         summary_execute(mainwin->summaryview);
3990 }
3991
3992 static void update_summary_cb(MainWindow *mainwin, guint action,
3993                               GtkWidget *widget)
3994 {
3995         FolderItem *fitem;
3996         FolderView *folderview = mainwin->folderview;
3997
3998         if (!mainwin->summaryview->folder_item) return;
3999         if (!folderview->opened) return;
4000
4001         folder_update_op_count();
4002
4003         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
4004                                             folderview->opened);
4005         if (!fitem) return;
4006
4007         folder_item_scan(fitem);
4008         summary_show(mainwin->summaryview, fitem);
4009 }
4010
4011 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4012 {
4013         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
4014 }
4015
4016 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4017 {
4018         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
4019 }
4020
4021 static void prev_unread_cb(MainWindow *mainwin, guint action,
4022                            GtkWidget *widget)
4023 {
4024         summary_select_prev_unread(mainwin->summaryview);
4025 }
4026
4027 static void next_unread_cb(MainWindow *mainwin, guint action,
4028                            GtkWidget *widget)
4029 {
4030         summary_select_next_unread(mainwin->summaryview);
4031 }
4032
4033 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4034 {
4035         summary_select_prev_new(mainwin->summaryview);
4036 }
4037
4038 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4039 {
4040         summary_select_next_new(mainwin->summaryview);
4041 }
4042
4043 static void prev_marked_cb(MainWindow *mainwin, guint action,
4044                            GtkWidget *widget)
4045 {
4046         summary_select_prev_marked(mainwin->summaryview);
4047 }
4048
4049 static void next_marked_cb(MainWindow *mainwin, guint action,
4050                            GtkWidget *widget)
4051 {
4052         summary_select_next_marked(mainwin->summaryview);
4053 }
4054
4055 static void prev_labeled_cb(MainWindow *mainwin, guint action,
4056                             GtkWidget *widget)
4057 {
4058         summary_select_prev_labeled(mainwin->summaryview);
4059 }
4060
4061 static void next_labeled_cb(MainWindow *mainwin, guint action,
4062                             GtkWidget *widget)
4063 {
4064         summary_select_next_labeled(mainwin->summaryview);
4065 }
4066
4067 static void last_read_cb(MainWindow *mainwin, guint action,
4068                             GtkWidget *widget)
4069 {
4070         summary_select_last_read(mainwin->summaryview);
4071 }
4072
4073 static void parent_cb(MainWindow *mainwin, guint action,
4074                             GtkWidget *widget)
4075 {
4076         summary_select_parent(mainwin->summaryview);
4077 }
4078
4079 static void goto_folder_cb(MainWindow *mainwin, guint action,
4080                            GtkWidget *widget)
4081 {
4082         FolderItem *to_folder;
4083
4084         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
4085
4086         if (to_folder)
4087                 folderview_select(mainwin->folderview, to_folder);
4088 }
4089
4090 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
4091                            GtkWidget *widget)
4092 {
4093         folderview_select_next_unread(mainwin->folderview, FALSE);
4094 }
4095
4096 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4097 {
4098         messageview_copy_clipboard(mainwin->messageview);
4099 }
4100
4101 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4102 {
4103         MessageView *msgview = mainwin->messageview;
4104
4105         if (messageview_is_visible(msgview) &&
4106                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
4107                 messageview_select_all(mainwin->messageview);
4108         else
4109                 summary_select_all(mainwin->summaryview);
4110 }
4111
4112 static void select_thread_cb(MainWindow *mainwin, guint action,
4113                              GtkWidget *widget)
4114 {
4115         summary_select_thread(mainwin->summaryview, FALSE);
4116 }
4117
4118 static void delete_thread_cb(MainWindow *mainwin, guint action,
4119                              GtkWidget *widget)
4120 {
4121         summary_select_thread(mainwin->summaryview, TRUE);
4122 }
4123
4124 static void create_filter_cb(MainWindow *mainwin, guint action,
4125                              GtkWidget *widget)
4126 {
4127         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4128 }
4129
4130 static void create_processing_cb(MainWindow *mainwin, guint action,
4131                              GtkWidget *widget)
4132 {
4133         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4134 }
4135
4136 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
4137                                          GtkWidget *widget)
4138 {
4139         prefs_filtering_open(&pre_global_processing,
4140                              _("Processing rules to apply before folder rules"),
4141                              MANUAL_ANCHOR_PROCESSING,
4142                              NULL, NULL, FALSE);
4143 }
4144
4145 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
4146                                           GtkWidget *widget)
4147 {
4148         prefs_filtering_open(&post_global_processing,
4149                              _("Processing rules to apply after folder rules"),
4150                              MANUAL_ANCHOR_PROCESSING,
4151                              NULL, NULL, FALSE);
4152 }
4153
4154 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
4155                                     GtkWidget *widget)
4156 {
4157         prefs_filtering_open(&filtering_rules,
4158                              _("Filtering configuration"),
4159                              MANUAL_ANCHOR_FILTERING,
4160                              NULL, NULL, TRUE);
4161 }
4162
4163 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4164                                    GtkWidget *widget)
4165 {
4166         prefs_template_open();
4167 }
4168
4169 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4170                                   GtkWidget *widget)
4171 {
4172         prefs_actions_open(mainwin);
4173 }
4174
4175 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4176                                   GtkWidget *widget)
4177 {
4178         prefs_tags_open(mainwin);
4179 }
4180 #ifdef USE_OPENSSL
4181 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4182                                   GtkWidget *widget)
4183 {
4184         ssl_manager_open(mainwin);
4185 }
4186 #endif
4187 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4188                                   GtkWidget *widget)
4189 {
4190         if (!cur_account) {
4191                 new_account_cb(mainwin, 0, widget);
4192         } else {
4193                 account_open(cur_account);
4194         }
4195 }
4196
4197 static void new_account_cb(MainWindow *mainwin, guint action,
4198                            GtkWidget *widget)
4199 {
4200         account_edit_open();
4201         if (!compose_get_compose_list()) account_add();
4202 }
4203
4204 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4205 {
4206         FolderItem *item = NULL;
4207         cur_account = (PrefsAccount *)data;
4208         
4209         if (!mainwindow_get_mainwindow())
4210                 return;
4211         main_window_show_cur_account(mainwindow_get_mainwindow());
4212         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4213         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4214         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4215         item = folderview_get_selected_item(
4216                         mainwindow_get_mainwindow()->folderview);
4217         if (item) {
4218                 toolbar_set_compose_button
4219                         (mainwindow_get_mainwindow()->toolbar,
4220                          FOLDER_TYPE(item->folder) == F_NEWS ? 
4221                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4222         }
4223 }
4224
4225 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4226 {
4227         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4228         PrefsAccount *account = (PrefsAccount *)data;
4229
4230         inc_account_mail(mainwin, account);
4231 }
4232 #ifndef MAEMO
4233 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4234 {
4235         PrefsAccount *account = (PrefsAccount *)data;
4236
4237         compose_new_with_folderitem(account, NULL, NULL);
4238 }
4239 #endif
4240 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4241 {
4242         prefs_gtk_open();
4243 }
4244
4245 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4246 {
4247         pluginwindow_create();
4248 }
4249
4250 static void manual_open_cb(MainWindow *mainwin, guint action,
4251                            GtkWidget *widget)
4252 {
4253         manual_open((ManualType)action, NULL);
4254 }
4255
4256 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4257 {
4258         legend_show();
4259 }
4260
4261 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4262 {
4263         MainWindow *mainwin = (MainWindow *)data;
4264         gchar *str;
4265
4266         if (item->path)
4267                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4268                                       LOCAL_FOLDER(folder)->rootpath,
4269                                       G_DIR_SEPARATOR,
4270                                       item->path);
4271         else
4272                 str = g_strdup_printf(_("Scanning folder %s ..."),
4273                                       LOCAL_FOLDER(folder)->rootpath);
4274
4275         STATUSBAR_PUSH(mainwin, str);
4276         STATUSBAR_POP(mainwin);
4277         g_free(str);
4278 }
4279
4280 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4281                                           gpointer data)
4282 {
4283         SummaryView *summary;
4284
4285         g_return_val_if_fail(data, FALSE);
4286         if (!g_list_find(mainwin_list, data))
4287                 return TRUE;
4288         summary = ((MainWindow *)data)->summaryview;
4289         g_return_val_if_fail(summary, FALSE);
4290
4291         if (GTK_CLIST(summary->ctree)->selection && 
4292             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4293                 return FALSE;
4294
4295         return FALSE;
4296 }
4297
4298 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4299                                           gpointer data)
4300 {
4301         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4302         return FALSE;
4303 }
4304
4305 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4306                                           gpointer data)
4307 {
4308         if (!claws_is_starting()
4309                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4310                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4311
4312                 if (iconified_count > 0)
4313                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4314                 iconified_count++;
4315         }
4316         if (state->new_window_state == 0)
4317                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4318         return FALSE;
4319 }
4320
4321 gboolean mainwindow_is_obscured(void)
4322 {
4323         return is_obscured;
4324 }
4325
4326 #define BREAK_ON_MODIFIER_KEY() \
4327         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
4328
4329 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
4330                                     gpointer data)
4331 {
4332         MainWindow *mainwin = (MainWindow*) data;
4333         
4334         if (!mainwin || !event) 
4335                 return FALSE;
4336
4337         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
4338         {
4339                 lastkey = event->keyval;
4340                 return FALSE;
4341         }
4342
4343         switch (event->keyval) {
4344         case GDK_Q:             /* Quit */
4345                 BREAK_ON_MODIFIER_KEY();
4346
4347                 app_exit_cb(mainwin, 0, NULL);
4348                 return FALSE;
4349         case GDK_space:
4350                 if (mainwin->folderview && mainwin->summaryview
4351                     && ((!mainwin->summaryview->displayed
4352                         && !mainwin->summaryview->selected) 
4353                         || (mainwin->summaryview->folder_item
4354                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
4355                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
4356                                        "key_press_event");
4357                         folderview_select_next_unread(mainwin->folderview, TRUE);
4358                 }
4359                 break;
4360 #ifdef MAEMO
4361         case GDK_F6:
4362                 if (maemo_mainwindow_is_fullscreen(widget)) {
4363                         gtk_window_unfullscreen(GTK_WINDOW(widget));
4364                 } else {
4365                         gtk_window_fullscreen(GTK_WINDOW(widget));
4366                 }
4367                 break;
4368         case GDK_Escape:
4369                 if (mainwin->summaryview && 
4370                     mainwin->summaryview->ext_messageview && 
4371                     mainwin->summaryview->ext_messageview->window && 
4372                     widget == mainwin->summaryview->ext_messageview->window) {
4373                         messageview_destroy(mainwin->summaryview->ext_messageview);
4374                 }
4375                 break;
4376 #endif
4377         default:
4378                 break;
4379         }
4380         return FALSE;
4381 }
4382
4383 #undef BREAK_ON_MODIFIER_KEY
4384
4385 /*
4386  * Harvest addresses for selected folder.
4387  */
4388 static void addr_harvest_cb( MainWindow *mainwin,
4389                             guint action,
4390                             GtkWidget *widget )
4391 {
4392         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4393 }
4394
4395 /*
4396  * Harvest addresses for selected messages in summary view.
4397  */
4398 static void addr_harvest_msg_cb( MainWindow *mainwin,
4399                             guint action,
4400                             GtkWidget *widget )
4401 {
4402         summary_harvest_address( mainwin->summaryview );
4403 }
4404
4405 /*!
4406  *\brief        get a MainWindow
4407  *
4408  *\return       MainWindow * The first mainwindow in the mainwin_list
4409  */
4410 MainWindow *mainwindow_get_mainwindow(void)
4411 {
4412         if (mainwin_list && mainwin_list->data)
4413                 return (MainWindow *)(mainwin_list->data);
4414         else
4415                 return NULL;
4416 }
4417
4418 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4419 {
4420         ProgressData *data = (ProgressData *) source;
4421         MainWindow *mainwin = (MainWindow *) userdata;
4422
4423         switch (data->cmd) {
4424         case PROGRESS_COMMAND_START:
4425         case PROGRESS_COMMAND_STOP:
4426                 gtk_progress_bar_set_fraction
4427                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4428                 break;
4429         case PROGRESS_COMMAND_SET_PERCENTAGE:
4430                 gtk_progress_bar_set_fraction
4431                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4432                 break;          
4433         }
4434         while (gtk_events_pending()) gtk_main_iteration ();
4435
4436         return FALSE;
4437 }
4438
4439 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4440 {
4441         mainwindow_check_synchronise(mainwin, FALSE);
4442 }
4443
4444 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4445 {
4446         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4447 }
4448
4449 void mainwindow_jump_to(const gchar *target, gboolean popup)
4450 {
4451         gchar *tmp = NULL;
4452         gchar *p = NULL;
4453         FolderItem *item = NULL;
4454         gchar *msg = NULL;
4455         MainWindow *mainwin = mainwindow_get_mainwindow();
4456         
4457         if (!target)
4458                 return;
4459                 
4460         if (!mainwin) {
4461                 g_print("not initialized\n");
4462                 return;
4463         }
4464
4465         tmp = g_strdup(target);
4466         
4467         if ((p = strstr(tmp, "\r")) != NULL)
4468                 *p = '\0';
4469         if ((p = strstr(tmp, "\n")) != NULL)
4470                 *p = '\0';
4471
4472         if ((item = folder_find_item_from_identifier(tmp))) {
4473                 g_print("selecting folder '%s'\n", tmp);
4474                 folderview_select(mainwin->folderview, item);
4475                 if (popup)
4476                         main_window_popup(mainwin);
4477                 g_free(tmp);
4478                 return;
4479         }
4480         
4481         msg = strrchr(tmp, G_DIR_SEPARATOR);
4482         if (msg) {
4483                 *msg++ = '\0';
4484                 if ((item = folder_find_item_from_identifier(tmp))) {
4485                         g_print("selecting folder '%s'\n", tmp);
4486                         folderview_select(mainwin->folderview, item);
4487                 } else {
4488                         g_print("'%s' not found\n", tmp);
4489                 }
4490                 if (item && msg && atoi(msg)) {
4491                         g_print("selecting message %d\n", atoi(msg));
4492                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4493                         summary_display_msg_selected(mainwin->summaryview, FALSE);
4494                         if (popup)
4495                                 main_window_popup(mainwin);
4496                         g_free(tmp);
4497                         return;
4498                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4499                         MsgInfo *msginfo = NULL;
4500                         msg++;
4501                         msg[strlen(msg)-1] = '\0';
4502                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4503                         if (msginfo) {
4504                                 g_print("selecting message %s\n", msg);
4505                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4506                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4507                                 if (popup)
4508                                         main_window_popup(mainwin);
4509                                 g_free(tmp);
4510                                 procmsg_msginfo_free(msginfo);
4511                                 return;
4512                         } else {
4513                                 g_print("'%s' not found\n", msg);
4514                         }
4515                 } else {
4516                         g_print("'%s' not found\n", msg);
4517                 }
4518         } else {
4519                 g_print("'%s' not found\n", tmp);
4520         }
4521         
4522         g_free(tmp);
4523 }
4524
4525 void mainwindow_exit_folder(MainWindow *mainwin) {
4526         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4527                 folderview_close_opened(mainwin->folderview);
4528                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4529         }
4530         mainwin->in_folder = FALSE;
4531 }
4532
4533 void mainwindow_enter_folder(MainWindow *mainwin) {
4534         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4535                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4536         }
4537         mainwin->in_folder = TRUE;
4538 }
4539
4540 #ifdef MAEMO
4541 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4542 {
4543         gint w, h;
4544         gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
4545         return (w == 800);
4546 }
4547
4548 void maemo_window_full_screen_if_needed (GtkWindow *window)
4549 {
4550         if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4551                 gtk_window_fullscreen(GTK_WINDOW(window));
4552         }
4553 }
4554
4555 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4556 {
4557         g_signal_connect(G_OBJECT(window), "key_press_event",
4558                          G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
4559 }
4560 #endif