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