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