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