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