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