2007-11-20 [colin] 3.1.0cvs11
[claws.git] / src / mainwindow.c
1 /*
2    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3    Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "defs.h"
20
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <gtk/gtktooltips.h>
43 #include <string.h>
44
45 #include "main.h"
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
54 #include "menu.h"
55 #include "stock_pixmap.h"
56 #include "folder.h"
57 #include "inc.h"
58 #include "log.h"
59 #include "compose.h"
60 #include "procmsg.h"
61 #include "import.h"
62 #include "export.h"
63 #include "edittags.h"
64 #include "prefs_common.h"
65 #include "prefs_actions.h"
66 #include "prefs_filtering.h"
67 #include "prefs_account.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_folder_column.h"
70 #include "prefs_template.h"
71 #include "action.h"
72 #include "account.h"
73 #include "addressbook.h"
74 #include "logwindow.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "inputdialog.h"
79 #include "utils.h"
80 #include "gtkutils.h"
81 #include "codeconv.h"
82 #include "about.h"
83 #include "manual.h"
84 #include "version.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefs_gtk.h"
88 #include "pluginwindow.h"
89 #include "hooks.h"
90 #include "progressindicator.h"
91 #include "localfolder.h"
92 #include "filtering.h"
93 #include "folderutils.h"
94 #include "foldersort.h"
95 #include "icon_legend.h"
96 #include "colorlabel.h"
97 #include "tags.h"
98 #include "textview.h"
99 #include "imap.h"
100 #include "socket.h"
101 #include "printing.h"
102
103 #define AC_LABEL_WIDTH  240
104
105 /* list of all instantiated MainWindow */
106 static GList *mainwin_list = NULL;
107
108 static GdkCursor *watch_cursor = NULL;
109 static GdkCursor *hand_cursor = NULL;
110
111 static gint iconified_count = 0;
112
113 static void main_window_menu_callback_block     (MainWindow     *mainwin);
114 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
115
116 static void main_window_show_cur_account        (MainWindow     *mainwin);
117 #ifndef MAEMO
118 static void main_window_separation_change       (MainWindow     *mainwin,
119                                                  LayoutType      layout_mode);
120 #endif
121 static void main_window_set_widgets             (MainWindow     *mainwin,
122                                                  LayoutType      layout_mode);
123
124 static void toolbar_child_attached              (GtkWidget      *widget,
125                                                  GtkWidget      *child,
126                                                  gpointer        data);
127 static void toolbar_child_detached              (GtkWidget      *widget,
128                                                  GtkWidget      *child,
129                                                  gpointer        data);
130 #ifndef MAEMO
131 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
132                                                  GdkEventButton *event,
133                                                  gpointer        data);
134 #endif
135 static gint main_window_close_cb                (GtkWidget      *widget,
136                                                  GdkEventAny    *event,
137                                                  gpointer        data);
138
139 static void main_window_size_allocate_cb        (GtkWidget      *widget,
140                                                  GtkAllocation  *allocation,
141                                                  gpointer        data);
142 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
143                                                  GtkAllocation  *allocation,
144                                                  gpointer        data);
145 static void message_window_size_allocate_cb     (GtkWidget      *widget,
146                                                  GtkAllocation  *allocation,
147                                                  gpointer        data);
148
149 static void update_folderview_cb (MainWindow    *mainwin,
150                                   guint          action,
151                                   GtkWidget     *widget);
152 static void add_mailbox_cb       (MainWindow    *mainwin,
153                                   guint          action,
154                                   GtkWidget     *widget);
155 static void foldersort_cb        (MainWindow    *mainwin,
156                                   guint          action,
157                                   GtkWidget     *widget);
158 static void import_mbox_cb       (MainWindow    *mainwin,
159                                   guint          action,
160                                   GtkWidget     *widget);
161 static void export_mbox_cb       (MainWindow    *mainwin,
162                                   guint          action,
163                                   GtkWidget     *widget);
164 static void export_list_mbox_cb  (MainWindow    *mainwin, 
165                                   guint          action,
166                                   GtkWidget     *widget);
167 static void empty_trash_cb       (MainWindow    *mainwin,
168                                   guint          action,
169                                   GtkWidget     *widget);
170
171 static void save_as_cb           (MainWindow    *mainwin,
172                                   guint          action,
173                                   GtkWidget     *widget);
174 #if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
175 static void page_setup_cb        (MainWindow    *mainwin,
176                                   guint          action,
177                                   GtkWidget     *widget);
178 #endif
179
180 static void print_cb             (MainWindow    *mainwin,
181                                   guint          action,
182                                   GtkWidget     *widget);
183 static void app_exit_cb          (MainWindow    *mainwin,
184                                   guint          action,
185                                   GtkWidget     *widget);
186
187 static void search_cb            (MainWindow    *mainwin,
188                                   guint          action,
189                                   GtkWidget     *widget);
190
191 static void toggle_message_cb    (MainWindow    *mainwin,
192                                   guint          action,
193                                   GtkWidget     *widget);
194 static void toggle_toolbar_cb    (MainWindow    *mainwin,
195                                   guint          action,
196                                   GtkWidget     *widget);
197 static void toggle_col_headers_cb(MainWindow    *mainwin,
198                                   guint          action,
199                                   GtkWidget     *widget);
200 #ifndef MAEMO
201 static void toggle_statusbar_cb  (MainWindow    *mainwin,
202                                   guint          action,
203                                   GtkWidget     *widget);
204 static void set_layout_cb        (MainWindow    *mainwin,
205                                   guint          action,
206                                   GtkWidget     *widget);
207 #endif
208 static void addressbook_open_cb (MainWindow     *mainwin,
209                                  guint           action,
210                                  GtkWidget      *widget);
211 static void log_window_show_cb  (MainWindow     *mainwin,
212                                  guint           action,
213                                  GtkWidget      *widget);
214 static void filtering_debug_window_show_cb      (MainWindow     *mainwin,
215                                  guint           action,
216                                  GtkWidget      *widget);
217
218 static void inc_cancel_cb               (MainWindow     *mainwin,
219                                          guint           action,
220                                          GtkWidget      *widget);
221
222 static void open_msg_cb                 (MainWindow     *mainwin,
223                                          guint           action,
224                                          GtkWidget      *widget);
225
226 static void view_source_cb              (MainWindow     *mainwin,
227                                          guint           action,
228                                          GtkWidget      *widget);
229
230 static void show_all_header_cb          (MainWindow     *mainwin,
231                                          guint           action,
232                                          GtkWidget      *widget);
233
234 static void hide_quotes_cb(MainWindow   *mainwin,
235                                          guint           action,
236                                          GtkWidget      *widget);
237
238 static void move_to_cb                  (MainWindow     *mainwin,
239                                          guint           action,
240                                          GtkWidget      *widget);
241 static void copy_to_cb                  (MainWindow     *mainwin,
242                                          guint           action,
243                                          GtkWidget      *widget);
244 static void delete_cb                   (MainWindow     *mainwin,
245                                          guint           action,
246                                          GtkWidget      *widget);
247 static void delete_trash_cb                     (MainWindow     *mainwin,
248                                          guint           action,
249                                          GtkWidget      *widget);
250
251 static void cancel_cb                   (MainWindow     *mainwin,
252                                          guint           action,
253                                          GtkWidget      *widget);
254
255 static void mark_cb                     (MainWindow     *mainwin,
256                                          guint           action,
257                                          GtkWidget      *widget);
258 static void unmark_cb                   (MainWindow     *mainwin,
259                                          guint           action,
260                                          GtkWidget      *widget);
261
262 static void mark_as_unread_cb           (MainWindow     *mainwin,
263                                          guint           action,
264                                          GtkWidget      *widget);
265 static void mark_as_read_cb             (MainWindow     *mainwin,
266                                          guint           action,
267                                          GtkWidget      *widget);
268 static void mark_all_read_cb            (MainWindow     *mainwin,
269                                          guint           action,
270                                          GtkWidget      *widget);
271 static void mark_as_spam_cb             (MainWindow     *mainwin, 
272                                          guint           action,
273                                          GtkWidget      *widget);
274
275 static void ignore_thread_cb            (MainWindow     *mainwin, 
276                                          guint           action,
277                                          GtkWidget      *widget);
278 static void unignore_thread_cb          (MainWindow     *mainwin, 
279                                          guint           action,
280                                          GtkWidget      *widget);
281 static void watch_thread_cb             (MainWindow     *mainwin, 
282                                          guint           action,
283                                          GtkWidget      *widget);
284 static void unwatch_thread_cb           (MainWindow     *mainwin, 
285                                          guint           action,
286                                          GtkWidget      *widget);
287 static void lock_msgs_cb                (MainWindow     *mainwin, 
288                                          guint           action,
289                                          GtkWidget      *widget);
290 static void unlock_msgs_cb              (MainWindow     *mainwin, 
291                                          guint           action,
292                                          GtkWidget      *widget);
293
294 static void reedit_cb                   (MainWindow     *mainwin,
295                                          guint           action,
296                                          GtkWidget      *widget);
297
298 static void add_address_cb              (MainWindow     *mainwin,
299                                          guint           action,
300                                          GtkWidget      *widget);
301
302 static void set_charset_cb              (MainWindow     *mainwin,
303                                          guint           action,
304                                          GtkWidget      *widget);
305
306 static void set_decode_cb               (MainWindow     *mainwin,
307                                          guint           action,
308                                          GtkWidget      *widget);
309
310 static void hide_read_messages   (MainWindow    *mainwin,
311                                   guint          action,
312                                   GtkWidget     *widget);
313
314 static void thread_cb            (MainWindow    *mainwin,
315                                   guint          action,
316                                   GtkWidget     *widget);
317 static void expand_threads_cb    (MainWindow    *mainwin,
318                                   guint          action,
319                                   GtkWidget     *widget);
320 static void collapse_threads_cb  (MainWindow    *mainwin,
321                                   guint          action,
322                                   GtkWidget     *widget);
323
324 static void set_summary_display_item_cb  (MainWindow    *mainwin,
325                                   guint          action,
326                                   GtkWidget     *widget);
327 static void set_folder_display_item_cb   (MainWindow    *mainwin,
328                                   guint          action,
329                                   GtkWidget     *widget);
330 static void sort_summary_cb      (MainWindow    *mainwin,
331                                   guint          action,
332                                   GtkWidget     *widget);
333 static void sort_summary_type_cb (MainWindow    *mainwin,
334                                   guint          action,
335                                   GtkWidget     *widget);
336 static void attract_by_subject_cb(MainWindow    *mainwin,
337                                   guint          action,
338                                   GtkWidget     *widget);
339
340 static void delete_duplicated_cb (MainWindow    *mainwin,
341                                   guint          action,
342                                   GtkWidget     *widget);
343 static void delete_duplicated_all_cb (MainWindow        *mainwin,
344                                   guint          action,
345                                   GtkWidget     *widget);
346 static void filter_cb            (MainWindow    *mainwin,
347                                   guint          action,
348                                   GtkWidget     *widget);
349 static void process_cb           (MainWindow    *mainwin,
350                                   guint          action,
351                                   GtkWidget     *widget);
352 static void execute_summary_cb   (MainWindow    *mainwin,
353                                   guint          action,
354                                   GtkWidget     *widget);
355 static void update_summary_cb    (MainWindow    *mainwin,
356                                   guint          action,
357                                   GtkWidget     *widget);
358
359 static void prev_cb              (MainWindow    *mainwin,
360                                   guint          action,
361                                   GtkWidget     *widget);
362 static void next_cb              (MainWindow    *mainwin,
363                                   guint          action,
364                                   GtkWidget     *widget);
365 static void next_unread_cb       (MainWindow    *mainwin,
366                                   guint          action,
367                                   GtkWidget     *widget);
368 static void prev_unread_cb       (MainWindow    *mainwin,
369                                   guint          action,
370                                   GtkWidget     *widget);
371
372 static void prev_new_cb          (MainWindow    *mainwin,
373                                   guint          action,
374                                   GtkWidget     *widget);
375 static void next_new_cb          (MainWindow    *mainwin,
376                                   guint          action,
377                                   GtkWidget     *widget);
378 static void prev_marked_cb       (MainWindow    *mainwin,
379                                   guint          action,
380                                   GtkWidget     *widget);
381 static void next_marked_cb       (MainWindow    *mainwin,
382                                   guint          action,
383                                   GtkWidget     *widget);
384 static void prev_labeled_cb      (MainWindow    *mainwin,
385                                   guint          action,
386                                   GtkWidget     *widget);
387 static void next_labeled_cb      (MainWindow    *mainwin,
388                                   guint          action,
389                                   GtkWidget     *widget);
390 static void last_read_cb         (MainWindow    *mainwin,
391                                   guint          action,
392                                   GtkWidget     *widget);
393 static void parent_cb            (MainWindow    *mainwin,
394                                   guint          action,
395                                   GtkWidget     *widget);
396
397 static void goto_folder_cb       (MainWindow    *mainwin,
398                                   guint          action,
399                                   GtkWidget     *widget);
400 static void goto_unread_folder_cb(MainWindow    *mainwin,
401                                   guint          action,
402                                   GtkWidget     *widget);
403
404 static void copy_cb              (MainWindow    *mainwin,
405                                   guint          action,
406                                   GtkWidget     *widget);
407 static void allsel_cb            (MainWindow    *mainwin,
408                                   guint          action,
409                                   GtkWidget     *widget);
410 static void select_thread_cb     (MainWindow    *mainwin,
411                                   guint          action,
412                                   GtkWidget     *widget);
413 static void delete_thread_cb     (MainWindow    *mainwin,
414                                   guint          action,
415                                   GtkWidget     *widget);
416
417 static void create_filter_cb     (MainWindow    *mainwin,
418                                   guint          action,
419                                   GtkWidget     *widget);
420 static void create_processing_cb (MainWindow    *mainwin,
421                                   guint          action,
422                                   GtkWidget     *widget);
423 static void open_urls_cb         (MainWindow    *mainwin,
424                                   guint          action,
425                                   GtkWidget     *widget);
426
427 static void prefs_template_open_cb      (MainWindow     *mainwin,
428                                          guint           action,
429                                          GtkWidget      *widget);
430 static void prefs_actions_open_cb       (MainWindow     *mainwin,
431                                          guint           action,
432                                          GtkWidget      *widget);
433 static void prefs_tags_open_cb          (MainWindow     *mainwin,
434                                          guint           action,
435                                          GtkWidget      *widget);
436 static void prefs_account_open_cb       (MainWindow     *mainwin,
437                                          guint           action,
438                                          GtkWidget      *widget);
439
440 static void prefs_pre_processing_open_cb  (MainWindow   *mainwin,
441                                            guint         action,
442                                            GtkWidget    *widget);
443
444 static void prefs_post_processing_open_cb (MainWindow   *mainwin,
445                                            guint         action,
446                                            GtkWidget    *widget);
447
448 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
449                                          guint           action,
450                                          GtkWidget      *widget);
451 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
452 static void ssl_manager_open_cb         (MainWindow     *mainwin,
453                                          guint           action,
454                                          GtkWidget      *widget);
455 #endif
456 static void new_account_cb       (MainWindow    *mainwin,
457                                   guint          action,
458                                   GtkWidget     *widget);
459
460 static void account_selector_menu_cb     (GtkMenuItem   *menuitem,
461                                           gpointer       data);
462 static void account_receive_menu_cb      (GtkMenuItem   *menuitem,
463                                           gpointer       data);
464 #ifndef MAEMO
465 static void account_compose_menu_cb      (GtkMenuItem   *menuitem,
466                                           gpointer       data);
467 #endif
468 static void prefs_open_cb       (GtkMenuItem    *menuitem,
469                                  gpointer        data);
470 static void plugins_open_cb     (GtkMenuItem    *menuitem,
471                                  gpointer        data);
472
473 static void online_switch_clicked(GtkButton     *btn, 
474                                   gpointer data);
475
476 static void manual_open_cb       (MainWindow    *mainwin,
477                                   guint          action,
478                                   GtkWidget     *widget);
479
480 static void legend_open_cb       (GtkMenuItem   *menuitem,
481                                   gpointer       data);
482
483 static void scan_tree_func       (Folder        *folder,
484                                   FolderItem    *item,
485                                   gpointer       data);
486                                   
487 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
488
489 static void addr_harvest_cb      ( MainWindow  *mainwin,
490                                    guint       action,
491                                    GtkWidget   *widget );
492
493 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
494                                    guint       action,
495                                    GtkWidget   *widget );
496 static void sync_cb              ( MainWindow *mainwin, 
497                                    guint action, 
498                                    GtkWidget *widget );
499
500 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
501                                                  GdkEventFocus  *focus,
502                                                  gpointer        data);
503 static gboolean mainwindow_visibility_event_cb  (GtkWidget      *widget, 
504                                                  GdkEventVisibility     *state,
505                                                  gpointer        data);
506 static gboolean mainwindow_state_event_cb       (GtkWidget      *widget, 
507                                                  GdkEventWindowState    *state,
508                                                  gpointer        data);
509 static void main_window_reply_cb                        (MainWindow     *mainwin, 
510                                                  guint           action,
511                                                  GtkWidget      *widget);
512 static gboolean mainwindow_progressindicator_hook       (gpointer        source,
513                                                  gpointer        userdata);
514
515 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
516                                        MsgInfo *msginfo);
517
518 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
519         
520 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
521
522 static void mailing_list_compose(GtkWidget *w, gpointer *data);
523  
524 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
525 #define  SEPARATE_ACTION 500 
526 static void mainwindow_quicksearch              (MainWindow     *mainwin, 
527                                                  guint           action, 
528                                                  GtkWidget      *widget);
529 static gboolean any_folder_want_synchronise(void);
530
531 static GtkItemFactoryEntry mainwin_entries[] =
532 {
533         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
534         {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
535         {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
536         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
537         {N_("/_File/Change folder order..."),   NULL, foldersort_cb,  0, NULL},
538         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
539         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
540         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
541         {N_("/_File/Exp_ort selected to mbox file..."), 
542                                                 NULL, export_list_mbox_cb, 0, NULL},
543         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
544         {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
545         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
546         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
547 #if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
548         {N_("/_File/Page setup..."),            NULL, page_setup_cb, 0, NULL},
549 #endif
550         {N_("/_File/_Print..."),                "<control>P", print_cb, 0, NULL},
551         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
552         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
553         {N_("/_File/Synchronise folders"),      "<control><shift>S", sync_cb, 0, NULL},
554         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
555         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
556         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
557
558         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
559         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
560         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
561         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
562         {N_("/_Edit/_Delete thread"),           NULL, delete_thread_cb, 0, NULL},
563         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
564         {N_("/_Edit/_Find in current message..."),
565                                                 "<control>F", search_cb, 0, NULL},
566         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
567         {N_("/_Edit/_Quick search"),            "slash", mainwindow_quicksearch, 0, NULL},
568         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
569         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
570         {N_("/_View/Show or hi_de/_Toolbar"),
571                                                 NULL, NULL, 0, "<Branch>"},
572         {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
573                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
574         {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
575                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
576         {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
577                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
578         {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
579                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
580 #ifndef MAEMO
581         {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
582                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
583 #endif
584         {N_("/_View/Show or hi_de/_Message view"),
585                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
586 #ifndef MAEMO
587         {N_("/_View/Show or hi_de/Status _bar"),
588                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
589 #endif
590         {N_("/_View/Show or hi_de/Column headers"),
591                                                 NULL, toggle_col_headers_cb, 0, "<ToggleItem>"},
592         {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
593         {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
594         {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
595
596         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
597 #ifndef MAEMO
598         {N_("/_View/La_yout"),                  NULL, NULL, 0, "<Branch>"},
599         {N_("/_View/Layout/_Standard"),         NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
600         {N_("/_View/Layout/_Three columns"),    NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
601         {N_("/_View/Layout/_Wide message"),     NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
602         {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
603         {N_("/_View/Layout/S_mall screen"),     NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
604         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
605 #endif
606         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
607         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
608         {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
609         {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
610         {N_("/_View/_Sort/by Thread date"),     NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
611         {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
612         {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
613         {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
614         {N_("/_View/_Sort/by _color label"),    NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
615         {N_("/_View/_Sort/by tag"),             NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
616         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
617         {N_("/_View/_Sort/by _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
618         {N_("/_View/_Sort/by a_ttachment"),
619                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
620         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
621         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
622         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
623         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
624         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
625         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
626         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
627         {N_("/_View/_Sort/_Attract by subject"),
628                                                 NULL, attract_by_subject_cb, 0, NULL},
629         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
630         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
631         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
632         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
633
634         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
635         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
636         {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
637         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
638         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
639         {N_("/_View/_Go to/P_revious unread message"),
640                                                 "<shift>P", prev_unread_cb, 0, NULL},
641         {N_("/_View/_Go to/N_ext unread message"),
642                                                 "<shift>N", next_unread_cb, 0, NULL},
643         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
644         {N_("/_View/_Go to/Previous ne_w message"),     NULL, prev_new_cb, 0, NULL},
645         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
646         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
647         {N_("/_View/_Go to/Previous _marked message"),
648                                                 NULL, prev_marked_cb, 0, NULL},
649         {N_("/_View/_Go to/Next m_arked message"),
650                                                 NULL, next_marked_cb, 0, NULL},
651         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
652         {N_("/_View/_Go to/Previous _labeled message"),
653                                                 NULL, prev_labeled_cb, 0, NULL},
654         {N_("/_View/_Go to/Next la_beled message"),
655                                                 NULL, next_labeled_cb, 0, NULL},
656         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
657         {N_("/_View/_Go to/Last read message"),
658                                                 NULL, last_read_cb, 0, NULL},
659         {N_("/_View/_Go to/Parent message"),
660                                                 "<control>Up", parent_cb, 0, NULL},
661         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
662         {N_("/_View/_Go to/Next unread _folder"),       "<shift>G", goto_unread_folder_cb, 0, NULL},
663         {N_("/_View/_Go to/_Other folder..."),  "G", goto_folder_cb, 0, NULL},
664         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
665
666 #define ENC_SEPARATOR \
667         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"}
668 #define ENC_ACTION(action) \
669          NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
670
671         {N_("/_View/Character _encoding"),              NULL, NULL, 0, "<Branch>"},
672         {N_("/_View/Character _encoding/_Auto detect"),
673          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
674         ENC_SEPARATOR,
675
676         {N_("/_View/Character _encoding/7bit ASCII (US-ASC_II)"),
677          ENC_ACTION(C_US_ASCII)},
678         {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
679          ENC_ACTION(C_UTF_8)},
680         ENC_SEPARATOR,
681
682         {N_("/_View/Character _encoding/Western European"),NULL, NULL, 0, "<Branch>"},
683         {N_("/_View/Character _encoding/Western European/ISO-8859-_1"),
684          ENC_ACTION(C_ISO_8859_1)},
685         {N_("/_View/Character _encoding/Western European/ISO-8859-15"),
686          ENC_ACTION(C_ISO_8859_15)},
687         {N_("/_View/Character _encoding/Western European/Windows-1252"),
688          ENC_ACTION(C_WINDOWS_1252)},
689
690         {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
691          ENC_ACTION(C_ISO_8859_2)},
692
693         {N_("/_View/Character _encoding/Baltic"),       NULL, NULL, 0, "<Branch>"},
694         {N_("/_View/Character _encoding/Baltic/ISO-8859-13"),
695          ENC_ACTION(C_ISO_8859_13)},
696         {N_("/_View/Character _encoding/Baltic/ISO-8859-_4"),
697          ENC_ACTION(C_ISO_8859_4)},
698
699         {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
700          ENC_ACTION(C_ISO_8859_7)},
701
702         {N_("/_View/Character _encoding/Hebrew"),       NULL, NULL, 0, "<Branch>"},
703         {N_("/_View/Character _encoding/Hebrew/ISO-8859-_8"),
704          ENC_ACTION(C_ISO_8859_8)},
705         {N_("/_View/Character _encoding/Hebrew/Windows-1255"),
706          ENC_ACTION(C_CP1255)},
707
708         {N_("/_View/Character _encoding/Arabic"),       NULL, NULL, 0, "<Branch>"},
709         {N_("/_View/Character _encoding/Arabic/ISO-8859-_6"),
710          ENC_ACTION(C_ISO_8859_6)},
711         {N_("/_View/Character _encoding/Arabic/Windows-1256"),
712          ENC_ACTION(C_CP1256)},
713
714         {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
715          ENC_ACTION(C_ISO_8859_9)},
716
717         {N_("/_View/Character _encoding/Cyrillic"),     NULL, NULL, 0, "<Branch>"},
718         {N_("/_View/Character _encoding/Cyrillic/ISO-8859-_5"),
719          ENC_ACTION(C_ISO_8859_5)},
720         {N_("/_View/Character _encoding/Cyrillic/KOI8-_R"),
721          ENC_ACTION(C_KOI8_R)},
722         {N_("/_View/Character _encoding/Cyrillic/KOI8-U"),
723          ENC_ACTION(C_KOI8_U)},
724         {N_("/_View/Character _encoding/Cyrillic/Windows-1251"),
725          ENC_ACTION(C_CP1251)},
726
727         {N_("/_View/Character _encoding/Japanese"),     NULL, NULL, 0, "<Branch>"},
728         {N_("/_View/Character _encoding/Japanese/ISO-2022-_JP"),
729          ENC_ACTION(C_ISO_2022_JP)},
730         {N_("/_View/Character _encoding/Japanese/ISO-2022-JP-2"),
731          ENC_ACTION(C_ISO_2022_JP_2)},
732         {N_("/_View/Character _encoding/Japanese/_EUC-JP"),
733          ENC_ACTION(C_EUC_JP)},
734         {N_("/_View/Character _encoding/Japanese/_Shift__JIS"),
735          ENC_ACTION(C_SHIFT_JIS)},
736
737         {N_("/_View/Character _encoding/Chinese"),      NULL, NULL, 0, "<Branch>"},
738         {N_("/_View/Character _encoding/Chinese/Simplified (_GB2312)"),
739          ENC_ACTION(C_GB2312)},
740         {N_("/_View/Character _encoding/Chinese/Simplified (GBK)"),
741          ENC_ACTION(C_GBK)},
742         {N_("/_View/Character _encoding/Chinese/Traditional (_Big5)"),
743          ENC_ACTION(C_BIG5)},
744         {N_("/_View/Character _encoding/Chinese/Traditional (EUC-_TW)"),
745          ENC_ACTION(C_EUC_TW)},
746         {N_("/_View/Character _encoding/Chinese/ISO-2022-_CN"),
747          ENC_ACTION(C_ISO_2022_CN)},
748
749         {N_("/_View/Character _encoding/Korean"),       NULL, NULL, 0, "<Branch>"},
750         {N_("/_View/Character _encoding/Korean/EUC-_KR"),
751          ENC_ACTION(C_EUC_KR)},
752         {N_("/_View/Character _encoding/Korean/ISO-2022-KR"),
753          ENC_ACTION(C_ISO_2022_KR)},
754
755         {N_("/_View/Character _encoding/Thai"),         NULL, NULL, 0, "<Branch>"},
756         {N_("/_View/Character _encoding/Thai/TIS-620"),
757          ENC_ACTION(C_TIS_620)},
758         {N_("/_View/Character _encoding/Thai/Windows-874"),
759          ENC_ACTION(C_WINDOWS_874)},
760
761 #undef ENC_SEPARATOR
762 #undef ENC_ACTION
763
764 #define DEC_SEPARATOR \
765         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"}
766 #define DEC_ACTION(action) \
767          NULL, set_decode_cb, action, "/View/Decode/Auto detect"
768         {N_("/_View/Decode"),           NULL, NULL, 0, "<Branch>"},
769         {N_("/_View/Decode/_Auto detect"),
770          NULL, set_decode_cb, 0, "<RadioItem>"},
771         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"},
772         {N_("/_View/Decode/_8bit"),             DEC_ACTION(ENC_8BIT)},
773         {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
774         {N_("/_View/Decode/_Base64"),           DEC_ACTION(ENC_BASE64)},
775         {N_("/_View/Decode/_Uuencode"),         DEC_ACTION(ENC_X_UUENCODE)},
776
777 #undef DEC_SEPARATOR
778 #undef DEC_ACTION
779
780         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
781         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
782         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
783         {N_("/_View/All headers"),              "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
784         {N_("/_View/Quotes"),                   NULL, NULL, 0, "<Branch>"},
785         {N_("/_View/Quotes/_Fold all"),         "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
786         {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
787         {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
788         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
789         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
790
791         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
792         {N_("/_Message/Recei_ve"),              NULL, NULL, 0, "<Branch>"},
793         {N_("/_Message/Recei_ve/Get from _current account"),
794                                                 "<control>I",   inc_mail_cb, 0, NULL},
795         {N_("/_Message/Recei_ve/Get from _all accounts"),
796                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
797         {N_("/_Message/Recei_ve/Cancel receivin_g"),
798                                                 NULL, inc_cancel_cb, 0, NULL},
799         {N_("/_Message/Recei_ve/---"),          NULL, NULL, 0, "<Separator>"},
800         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
801         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
802         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
803         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
804         {N_("/_Message/_Reply"),                "<control>R",   main_window_reply_cb, COMPOSE_REPLY, NULL},
805         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
806         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
807         {N_("/_Message/Repl_y to/_sender"),     NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
808         {N_("/_Message/Repl_y to/mailing _list"),
809                                                 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
810         {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
811         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
812         {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
813         {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
814         {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
815
816         {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
817         {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
818         {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
819         {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
820         {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
821         {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
822         {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
823         
824         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
825         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
826         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
827         {N_("/_Message/Move to _trash"),        "<control>D", delete_trash_cb,  0, NULL},
828         {N_("/_Message/_Delete..."),            NULL, delete_cb,  0, NULL},
829         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
830         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
831         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
832         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
833         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
834         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
835         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
836         {N_("/_Message/_Mark/Mark as rea_d"),   NULL, mark_as_read_cb, 0, NULL},
837         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
838         {N_("/_Message/_Mark/Ignore thread"),   NULL, ignore_thread_cb, 0, NULL},
839         {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
840         {N_("/_Message/_Mark/Watch thread"),    NULL, watch_thread_cb, 0, NULL},
841         {N_("/_Message/_Mark/Unwatch thread"),  NULL, unwatch_thread_cb, 0, NULL},
842         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
843         {N_("/_Message/_Mark/Mark as _spam"),   NULL, mark_as_spam_cb, 1, NULL},
844         {N_("/_Message/_Mark/Mark as _ham"),    NULL, mark_as_spam_cb, 0, NULL},
845         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
846         {N_("/_Message/_Mark/Lock"),            NULL, lock_msgs_cb, 0, NULL},
847         {N_("/_Message/_Mark/Unlock"),          NULL, unlock_msgs_cb, 0, NULL},
848         {N_("/_Message/Color la_bel"),          NULL, NULL,            0, NULL},
849         {N_("/_Message/T_ags"),                 NULL, NULL,            0, NULL},
850         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
851         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
852
853         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
854         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
855         {N_("/_Tools/Add sender to address boo_k"),
856                                                 NULL, add_address_cb, 0, NULL},
857         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
858         {N_("/_Tools/_Harvest addresses/from _Folder..."),
859                                                 NULL, addr_harvest_cb, 0, NULL},
860         {N_("/_Tools/_Harvest addresses/from _Messages..."),
861                                                 NULL, addr_harvest_msg_cb, 0, NULL},
862         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
863         {N_("/_Tools/_Filter all messages in folder"),
864                                                 NULL, filter_cb, 0, NULL},
865         {N_("/_Tools/Filter _selected messages"),
866                                                 NULL, filter_cb, 1, NULL},
867         {N_("/_Tools/Run folder processing rules"),
868                                                 NULL, process_cb, 0, NULL},
869         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
870         {N_("/_Tools/_Create filter rule/_Automatically"),
871                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
872         {N_("/_Tools/_Create filter rule/by _From"),
873                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
874         {N_("/_Tools/_Create filter rule/by _To"),
875                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
876         {N_("/_Tools/_Create filter rule/by _Subject"),
877                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
878         {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
879         {N_("/_Tools/C_reate processing rule/_Automatically"),
880                                                 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
881         {N_("/_Tools/C_reate processing rule/by _From"),
882                                                 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
883         {N_("/_Tools/C_reate processing rule/by _To"),
884                                                 NULL, create_processing_cb, FILTER_BY_TO, NULL},
885         {N_("/_Tools/C_reate processing rule/by _Subject"),
886                                                 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
887         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
888         {N_("/_Tools/List _URLs..."),           "<shift><control>U", open_urls_cb, 0, NULL},
889         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
890         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
891         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
892         {N_("/_Tools/Ch_eck for new messages in all folders"),
893                                                 NULL, update_folderview_cb, 0, NULL},
894         {N_("/_Tools/Delete du_plicated messages"),
895                                                 NULL, NULL, 0, "<Branch>"},
896         {N_("/_Tools/Delete du_plicated messages/In selected folder"),
897                                                 NULL, delete_duplicated_cb,   0, NULL},
898         {N_("/_Tools/Delete du_plicated messages/In all folders"),
899                                                 NULL, delete_duplicated_all_cb,   0, NULL},
900         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
901         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
902 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
903         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
904         {N_("/_Tools/SSL cer_tificates..."),    
905                                                 NULL, ssl_manager_open_cb, 0, NULL},
906 #endif
907         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
908         {N_("/_Tools/Filtering Log"),           NULL, filtering_debug_window_show_cb, 0, NULL},
909         {N_("/_Tools/Network _Log"),            "<shift><control>L", log_window_show_cb, 0, NULL},
910
911         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
912         {N_("/_Configuration/C_hange current account"),
913                                                 NULL, NULL, 0, "<Branch>"},
914         {N_("/_Configuration/_Preferences for current account..."),
915                                                 NULL, prefs_account_open_cb, 0, NULL},
916         {N_("/_Configuration/Create _new account..."),
917                                                 NULL, new_account_cb, 0, NULL},
918         {N_("/_Configuration/_Edit accounts..."),
919                                                 NULL, account_edit_open, 0, NULL},
920         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
921         {N_("/_Configuration/P_references..."),
922                                                 NULL, prefs_open_cb, 0, NULL},
923         {N_("/_Configuration/Pre-pr_ocessing..."),
924                                                 NULL, prefs_pre_processing_open_cb, 0, NULL},
925         {N_("/_Configuration/Post-pro_cessing..."),
926                                                 NULL, prefs_post_processing_open_cb, 0, NULL},
927         {N_("/_Configuration/_Filtering..."),
928                                                 NULL, prefs_filtering_open_cb, 0, NULL},
929         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
930         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
931         {N_("/_Configuration/Tag_s..."),        NULL, prefs_tags_open_cb, 0, NULL},
932         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
933         {N_("/_Configuration/Plu_gins..."),     NULL, plugins_open_cb, 0, NULL},
934
935         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
936         {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_CLAWS, NULL},
937         {N_("/_Help/_Online User-contributed FAQ"),     
938                                                 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
939         {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
940         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
941         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
942 };
943
944 static gboolean offline_ask_sync = TRUE;
945 static guint lastkey;
946 static gboolean is_obscured = FALSE;
947
948 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
949                                             GObject *arg1,
950                                             guint value,
951                                             GdkModifierType mod,
952                                             gpointer user_data) 
953 {
954         MainWindow *mainwin = (MainWindow *)user_data;
955
956         if (mainwin->summaryview &&
957             mainwin->summaryview->quicksearch &&
958             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
959             (mod == 0 || mod == GDK_SHIFT_MASK)) {
960                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
961                 return TRUE;
962         }
963         return FALSE;
964 }
965
966 #define N_COLOR_LABELS colorlabel_get_color_count()
967
968 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
969                                                           gpointer data)
970 {
971         MainWindow *mainwin;
972         GtkMenuShell *menu;
973         GtkCheckMenuItem **items;
974         gint n;
975         GList *cur;
976         GSList *sel;
977
978         mainwin = (MainWindow *)data;
979         g_return_if_fail(mainwin != NULL);
980
981         sel = summary_get_selection(mainwin->summaryview);
982         if (!sel) return;
983
984         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
985         g_return_if_fail(menu != NULL);
986
987         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
988
989         /* NOTE: don't return prematurely because we set the "dont_toggle"
990          * state for check menu items */
991         g_object_set_data(G_OBJECT(menu), "dont_toggle",
992                           GINT_TO_POINTER(1));
993
994         /* clear items. get item pointers. */
995         for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
996                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
997                         gtk_check_menu_item_set_active
998                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
999                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
1000                         n++;
1001                 }
1002         }
1003
1004         if (n == (N_COLOR_LABELS + 1)) {
1005                 /* iterate all messages and set the state of the appropriate
1006                  * items */
1007                 for (; sel != NULL; sel = sel->next) {
1008                         MsgInfo *msginfo;
1009                         gint clabel;
1010
1011                         msginfo = (MsgInfo *)sel->data;
1012                         if (msginfo) {
1013                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
1014                                 if (!items[clabel]->active)
1015                                         gtk_check_menu_item_set_active
1016                                                 (items[clabel], TRUE);
1017                         }
1018                 }
1019         } else
1020                 g_warning("invalid number of color elements (%d)\n", n);
1021
1022         g_slist_free(sel);
1023         /* reset "dont_toggle" state */
1024         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1025                           GINT_TO_POINTER(0));
1026 }
1027
1028 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
1029                                                      gpointer data)
1030 {
1031         guint color = GPOINTER_TO_UINT(data);
1032         MainWindow *mainwin;
1033
1034         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1035         g_return_if_fail(mainwin != NULL);
1036
1037         /* "dont_toggle" state set? */
1038         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
1039                                 "dont_toggle"))
1040                 return;
1041
1042         summary_set_colorlabel(mainwin->summaryview, color, NULL);
1043 }
1044
1045 static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
1046                                                           gpointer data)
1047 {
1048         MainWindow *mainwin;
1049         GtkMenuShell *menu;
1050         GList *cur;
1051         GSList *sel;
1052         GHashTable *menu_table = g_hash_table_new_full(
1053                                         g_direct_hash,
1054                                         g_direct_equal,
1055                                         NULL, NULL);
1056         GHashTable *menu_allsel_table = g_hash_table_new_full(
1057                                         g_direct_hash,
1058                                         g_direct_equal,
1059                                         NULL, NULL);
1060         gint sel_len;
1061         mainwin = (MainWindow *)data;
1062         g_return_if_fail(mainwin != NULL);
1063
1064         sel = summary_get_selection(mainwin->summaryview);
1065         if (!sel) return;
1066
1067         menu = GTK_MENU_SHELL(mainwin->tags_menu);
1068         g_return_if_fail(menu != NULL);
1069
1070         /* NOTE: don't return prematurely because we set the "dont_toggle"
1071          * state for check menu items */
1072         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1073                           GINT_TO_POINTER(1));
1074
1075         /* clear items. get item pointers. */
1076         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1077                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1078                         gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1079                                 "tag_id"));
1080                         gtk_check_menu_item_set_active
1081                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1082                                 
1083                         g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
1084                         g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
1085                 }
1086         }
1087
1088         /* iterate all messages and set the state of the appropriate
1089          * items */
1090         sel_len = 0;
1091         for (; sel != NULL; sel = sel->next) {
1092                 MsgInfo *msginfo;
1093                 GSList *tags = NULL;
1094                 gint id;
1095                 GtkCheckMenuItem *item;
1096                 msginfo = (MsgInfo *)sel->data;
1097                 sel_len++;
1098                 if (msginfo) {
1099                         tags =  msginfo->tags;
1100                         if (!tags)
1101                                 continue;
1102
1103                         for (; tags; tags = tags->next) {
1104                                 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
1105                                 id = GPOINTER_TO_INT(tags->data);
1106                                 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
1107                                 if (item && !item->active) {
1108                                         gtk_check_menu_item_set_active
1109                                                 (item, TRUE);
1110                                 }
1111                                 num_checked++;
1112                                 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
1113                         }
1114                 }
1115         }
1116
1117         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1118                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
1119                         gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
1120                                 "tag_id"));
1121                         gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
1122                         if (num_checked < sel_len && num_checked > 0)
1123                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
1124                         else
1125                                 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
1126                 }
1127         }
1128         g_slist_free(sel);
1129         g_hash_table_destroy(menu_table);
1130         g_hash_table_destroy(menu_allsel_table);
1131         /* reset "dont_toggle" state */
1132         g_object_set_data(G_OBJECT(menu), "dont_toggle",
1133                           GINT_TO_POINTER(0));
1134 }
1135
1136 static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
1137                                                      gpointer data)
1138 {
1139         gint id = GPOINTER_TO_INT(data);
1140         gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
1141         MainWindow *mainwin;
1142
1143         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1144         g_return_if_fail(mainwin != NULL);
1145
1146         /* "dont_toggle" state set? */
1147         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1148                                 "dont_toggle"))
1149                 return;
1150
1151         if (!set)
1152                 id = -id;
1153         summary_set_tag(mainwin->summaryview, id, NULL);
1154 }
1155
1156 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1157 {
1158         GtkWidget *label_menuitem;
1159         GtkWidget *menu;
1160         GtkWidget *item;
1161         gint i;
1162
1163         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1164                                                    "/Message/Color label");
1165         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1166                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1167                            mainwin);
1168         gtk_widget_show(label_menuitem);
1169
1170         menu = gtk_menu_new();
1171
1172         /* create sub items. for the menu item activation callback we pass the
1173          * index of label_colors[] as data parameter. for the None color we
1174          * pass an invalid (high) value. also we attach a data pointer so we
1175          * can always get back the Mainwindow pointer. */
1176
1177         item = gtk_check_menu_item_new_with_label(_("None"));
1178         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1179         g_signal_connect(G_OBJECT(item), "activate",
1180                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1181                            GUINT_TO_POINTER(0));
1182         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1183         gtk_widget_show(item);
1184
1185         gtk_widget_add_accelerator(item, "activate", 
1186                                    mainwin->menu_factory->accel_group, 
1187                                    GDK_0, GDK_CONTROL_MASK,
1188                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1189
1190         item = gtk_menu_item_new();
1191         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1192         gtk_widget_show(item);
1193
1194         /* create pixmap/label menu items */
1195         for (i = 0; i < N_COLOR_LABELS; i++) {
1196                 item = colorlabel_create_check_color_menu_item(
1197                         i, refresh, MAINWIN_COLORMENU);
1198                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1199                 g_signal_connect(G_OBJECT(item), "activate",
1200                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1201                                  GUINT_TO_POINTER(i + 1));
1202                 g_object_set_data(G_OBJECT(item), "mainwin",
1203                                   mainwin);
1204                 gtk_widget_show(item);
1205                 if (i < 9)
1206                         gtk_widget_add_accelerator(item, "activate", 
1207                                    mainwin->menu_factory->accel_group, 
1208                                    GDK_1+i, GDK_CONTROL_MASK,
1209                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1210         }
1211         gtk_widget_show(menu);
1212         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1213         mainwin->colorlabel_menu = menu;
1214 }
1215
1216 static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
1217                                                      gpointer data)
1218 {
1219         MainWindow *mainwin;
1220
1221         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
1222         g_return_if_fail(mainwin != NULL);
1223
1224         /* "dont_toggle" state set? */
1225         if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
1226                                 "dont_toggle"))
1227                 return;
1228         
1229         tag_apply_open(summary_get_selection(mainwin->summaryview));    
1230 }
1231
1232 static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b)
1233 {
1234         gint id_a = GPOINTER_TO_INT(a);
1235         gint id_b = GPOINTER_TO_INT(b);
1236         const gchar *tag_a = tags_get_tag(id_a);
1237         const gchar *tag_b = tags_get_tag(id_b);
1238         
1239                 
1240         if (tag_a == NULL)
1241                 return tag_b == NULL ? 0:1;
1242         
1243         if (tag_b == NULL)
1244                 return tag_a == NULL ? 0:1;
1245  
1246         return g_utf8_collate(tag_a, tag_b);
1247 }
1248
1249 static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
1250 {
1251         GtkWidget *label_menuitem;
1252         GtkWidget *menu;
1253         GtkWidget *item;
1254         GSList *cur = tags_get_list();
1255         GSList *orig = NULL;
1256         gboolean existing_tags = FALSE;
1257
1258         cur = orig = g_slist_sort(cur, mainwin_tag_cmp_list);
1259
1260         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1261                                                    "/Message/Tags");
1262         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1263                          G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
1264                            mainwin);
1265
1266         gtk_widget_show(label_menuitem);
1267
1268         menu = gtk_menu_new();
1269
1270         /* create tags menu items */
1271         for (; cur; cur = cur->next) {
1272                 gint id = GPOINTER_TO_INT(cur->data);
1273                 const gchar *tag = tags_get_tag(id);
1274
1275                 item = gtk_check_menu_item_new_with_label(tag);
1276                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1277                 g_signal_connect(G_OBJECT(item), "activate",
1278                                  G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
1279                                  GINT_TO_POINTER(id));
1280                 g_object_set_data(G_OBJECT(item), "mainwin",
1281                                   mainwin);
1282                 g_object_set_data(G_OBJECT(item), "tag_id",
1283                                   GINT_TO_POINTER(id));
1284                 gtk_widget_show(item);
1285                 existing_tags = TRUE;
1286         }
1287         if (existing_tags) {
1288                 /* separator */
1289                 item = gtk_menu_item_new();
1290                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1291                 gtk_widget_show(item);
1292         }
1293
1294         item = gtk_menu_item_new_with_label(_("Apply tags..."));
1295         gtk_widget_add_accelerator(item, "activate", 
1296                    mainwin->menu_factory->accel_group, 
1297                    GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
1298                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1299         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1300         g_signal_connect(G_OBJECT(item), "activate",
1301                          G_CALLBACK(mainwindow_tags_menu_item_apply_tags_activate_cb),
1302                          NULL);
1303         g_object_set_data(G_OBJECT(item), "mainwin",
1304                           mainwin);
1305         gtk_widget_show(item);
1306
1307         g_slist_free(orig);
1308         gtk_widget_show(menu);
1309         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1310         mainwin->tags_menu = menu;
1311 }
1312 #ifndef MAEMO
1313 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1314                                     MainWindow *mainwindow)
1315 {
1316         if (evt && evt->button == 1) {
1317                 log_window_show_error(mainwindow->logwin);
1318                 gtk_widget_hide(mainwindow->warning_btn);
1319         }
1320         return FALSE;
1321 }
1322
1323 static gboolean warning_visi_notify(GtkWidget *widget,
1324                                        GdkEventVisibility *event,
1325                                        MainWindow *mainwindow)
1326 {
1327         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1328         return FALSE;
1329 }
1330
1331 static gboolean warning_leave_notify(GtkWidget *widget,
1332                                       GdkEventCrossing *event,
1333                                       MainWindow *mainwindow)
1334 {
1335         gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1336         return FALSE;
1337 }
1338
1339 static gboolean warning_enter_notify(GtkWidget *widget,
1340                                       GdkEventCrossing *event,
1341                                       MainWindow *mainwindow)
1342 {
1343         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1344         return FALSE;
1345 }
1346 #endif
1347 void mainwindow_show_error(void)
1348 {
1349         MainWindow *mainwin = mainwindow_get_mainwindow();
1350         gtk_widget_show(mainwin->warning_btn);
1351 }
1352
1353 void mainwindow_clear_error(MainWindow *mainwin)
1354 {
1355         gtk_widget_hide(mainwin->warning_btn);
1356 }
1357
1358 #define BREAK_ON_MODIFIER_KEY() \
1359         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
1360
1361 static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
1362                                     gpointer data)
1363 {
1364         MainWindow *mainwin = (MainWindow*) data;
1365         
1366         if (!mainwin || !event) 
1367                 return FALSE;
1368
1369         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
1370         {
1371                 lastkey = event->keyval;
1372                 return FALSE;
1373         }
1374
1375         switch (event->keyval) {
1376         case GDK_Q:             /* Quit */
1377                 BREAK_ON_MODIFIER_KEY();
1378
1379                 app_exit_cb(mainwin, 0, NULL);
1380                 return FALSE;
1381         case GDK_space:
1382                 if (mainwin->folderview && mainwin->summaryview
1383                     && ((!mainwin->summaryview->displayed
1384                         && !mainwin->summaryview->selected) 
1385                         || (mainwin->summaryview->folder_item
1386                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
1387                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
1388                                        "key_press_event");
1389                         folderview_select_next_unread(mainwin->folderview, TRUE);
1390                 }
1391                 break;
1392 #ifdef MAEMO
1393         case GDK_F6:
1394                 if (maemo_mainwindow_is_fullscreen(widget)) {
1395                         gtk_window_unfullscreen(GTK_WINDOW(widget));
1396                 } else {
1397                         gtk_window_fullscreen(GTK_WINDOW(widget));
1398                 }
1399                 break;
1400         case GDK_Escape:
1401                 if (mainwin->summaryview && 
1402                     mainwin->summaryview->ext_messageview && 
1403                     mainwin->summaryview->ext_messageview->window && 
1404                     widget == mainwin->summaryview->ext_messageview->window) {
1405                         messageview_destroy(mainwin->summaryview->ext_messageview);
1406                 }
1407                 break;
1408 #endif
1409         default:
1410                 break;
1411         }
1412         return FALSE;
1413 }
1414
1415 #undef BREAK_ON_MODIFIER_KEY
1416
1417 MainWindow *main_window_create()
1418 {
1419         MainWindow *mainwin;
1420         GtkWidget *window;
1421         GtkWidget *vbox;
1422         GtkWidget *menubar;
1423         GtkWidget *handlebox;
1424         GtkWidget *vbox_body;
1425 #ifndef MAEMO
1426         GtkWidget *hbox_stat;
1427         GtkWidget *statusbar;
1428         GtkWidget *progressbar;
1429         GtkWidget *statuslabel;
1430         GtkWidget *ac_button;
1431         GtkWidget *ac_label;
1432         GtkWidget *online_pixmap;
1433         GtkWidget *offline_pixmap;
1434         GtkTooltips *tips;
1435         GtkWidget *warning_icon;
1436         GtkWidget *warning_btn;
1437 #endif
1438         GtkWidget *online_switch;
1439         GtkWidget *offline_switch;
1440         FolderView *folderview;
1441         SummaryView *summaryview;
1442         MessageView *messageview;
1443         GdkColormap *colormap;
1444         GdkColor color[4];
1445         gboolean success[4];
1446         GtkItemFactory *ifactory;
1447         GtkWidget *ac_menu;
1448         GtkWidget *menuitem;
1449         gint i;
1450         guint n_menu_entries;
1451
1452         static GdkGeometry geometry;
1453
1454         debug_print("Creating main window...\n");
1455         mainwin = g_new0(MainWindow, 1);
1456
1457         /* main window */
1458         window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1459         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1460         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1461 #ifdef MAEMO
1462         prefs_common.layout_mode = SMALL_LAYOUT;
1463 #endif
1464         if (!geometry.min_height) {
1465                 geometry.min_width = 320;
1466                 geometry.min_height = 200;
1467         }
1468         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1469                                       GDK_HINT_MIN_SIZE);
1470
1471         g_signal_connect(G_OBJECT(window), "delete_event",
1472                          G_CALLBACK(main_window_close_cb), mainwin);
1473         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1474         g_signal_connect(G_OBJECT(window), "focus_in_event",
1475                          G_CALLBACK(mainwindow_focus_in_event),
1476                          mainwin);
1477         g_signal_connect(G_OBJECT(window), "key_press_event",
1478                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1479
1480         gtk_widget_realize(window);
1481         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1482         
1483
1484         gtkut_widget_set_app_icon(window);
1485
1486         vbox = gtk_vbox_new(FALSE, 0);
1487         gtk_widget_show(vbox);
1488         gtk_container_add(GTK_CONTAINER(window), vbox);
1489
1490         /* menu bar */
1491         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1492         menubar = menubar_create(window, mainwin_entries, 
1493                                  n_menu_entries, "<Main>", mainwin);
1494         gtk_widget_show(menubar);
1495
1496 #ifndef MAEMO
1497         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1498 #endif
1499
1500         ifactory = gtk_item_factory_from_widget(menubar);
1501
1502 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1503         main_create_mailing_list_menu (mainwin, NULL); */
1504
1505         if (prefs_common.toolbar_detachable) {
1506                 handlebox = gtk_handle_box_new();
1507                 gtk_widget_show(handlebox);
1508                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1509                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1510                                  G_CALLBACK(toolbar_child_attached), mainwin);
1511                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1512                                  G_CALLBACK(toolbar_child_detached), mainwin);
1513         } else {
1514                 handlebox = gtk_hbox_new(FALSE, 0);
1515                 gtk_widget_show(handlebox);
1516                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1517         }
1518         /* link window to mainwin->window to avoid gdk warnings */
1519         mainwin->window       = window;
1520         mainwin_list = g_list_append(mainwin_list, mainwin);
1521         
1522 #ifdef MAEMO
1523         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1524                                           window, 
1525                                           (gpointer)mainwin);
1526 #else
1527         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1528                                           handlebox, 
1529                                           (gpointer)mainwin);
1530 #endif
1531         toolbar_set_learn_button
1532                 (mainwin->toolbar,
1533                  LEARN_SPAM);
1534
1535         /* vbox that contains body */
1536         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1537         gtk_widget_show(vbox_body);
1538         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1539         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1540
1541 #ifndef MAEMO
1542         hbox_stat = gtk_hbox_new(FALSE, 2);
1543         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1544
1545         tips = gtk_tooltips_new();
1546
1547         warning_icon = gtk_image_new_from_stock
1548                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1549         warning_btn = gtk_event_box_new();
1550         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1551         
1552         mainwin->warning_btn      = warning_btn;
1553         
1554         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1555                          G_CALLBACK(warning_icon_pressed),
1556                          (gpointer) mainwin);
1557         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1558                          G_CALLBACK(warning_visi_notify), mainwin);
1559         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1560                          G_CALLBACK(warning_visi_notify), mainwin);
1561         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1562                          G_CALLBACK(warning_leave_notify), mainwin);
1563         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1564                          G_CALLBACK(warning_enter_notify), mainwin);
1565
1566         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1567
1568         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1569                              _("Some error(s) happened. Click here to view log."), NULL);
1570         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1571
1572         statusbar = statusbar_create();
1573         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1574
1575         progressbar = gtk_progress_bar_new();
1576         gtk_widget_set_size_request(progressbar, 120, 1);
1577         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1578
1579         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1580         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1581         online_switch = gtk_button_new ();
1582         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1583                              _("You are online. Click the icon to go offline"), NULL);
1584         offline_switch = gtk_button_new ();
1585         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1586                              _("You are offline. Click the icon to go online"),
1587                              NULL);
1588         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1589         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1590         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1591         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1592         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1593         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1594         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1595         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1596         
1597         statuslabel = gtk_label_new("");
1598         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1599
1600         ac_button = gtk_button_new();
1601         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1602                              ac_button, _("Select account"), NULL);
1603         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1604         gtk_widget_set_size_request(ac_button, -1, 0);
1605         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1606         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1607                          G_CALLBACK(ac_label_button_pressed), mainwin);
1608
1609         ac_label = gtk_label_new("");
1610         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1611
1612         gtk_widget_show_all(hbox_stat);
1613
1614         gtk_widget_hide(offline_switch);
1615         gtk_widget_hide(warning_btn);
1616 #else
1617         online_switch = gtk_button_new ();
1618         offline_switch = gtk_button_new ();
1619         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1620         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1621 #endif
1622         /* create views */
1623         mainwin->folderview  = folderview  = folderview_create();
1624         mainwin->summaryview = summaryview = summary_create();
1625         mainwin->messageview = messageview = messageview_create(mainwin);
1626
1627         /* init log instances data before creating log views */
1628         set_log_title(LOG_PROTOCOL, _("Network log"));
1629         set_log_prefs(LOG_PROTOCOL,
1630                         &prefs_common.logwin_width,
1631                         &prefs_common.logwin_height);
1632         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1633         set_log_prefs(LOG_DEBUG_FILTERING,
1634                         &prefs_common.filtering_debugwin_width,
1635                         &prefs_common.filtering_debugwin_height);
1636
1637         /* setup log windows */
1638         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1639         log_window_init(mainwin->logwin);
1640
1641         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1642         log_window_set_clipping(mainwin->logwin,
1643                                 prefs_common.cliplog,
1644                                 prefs_common.loglength);
1645
1646         log_window_init(mainwin->filtering_debugwin);
1647         log_window_set_clipping(mainwin->filtering_debugwin,
1648                                 prefs_common.filtering_debug_cliplog,
1649                                 prefs_common.filtering_debug_loglength);
1650         if (prefs_common.enable_filtering_debug)
1651                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1652         else
1653                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1654
1655         folderview->mainwin      = mainwin;
1656         folderview->summaryview  = summaryview;
1657
1658         summaryview->mainwin     = mainwin;
1659         summaryview->folderview  = folderview;
1660         summaryview->messageview = messageview;
1661         summaryview->window      = window;
1662
1663         mainwin->vbox           = vbox;
1664         mainwin->menubar        = menubar;
1665         mainwin->menu_factory   = ifactory;
1666         mainwin->handlebox      = handlebox;
1667         mainwin->vbox_body      = vbox_body;
1668         mainwin->online_switch  = online_switch;
1669         mainwin->offline_switch    = offline_switch;
1670 #ifndef MAEMO
1671         messageview->statusbar  = statusbar;
1672         mainwin->statusbar      = statusbar;
1673         mainwin->hbox_stat      = hbox_stat;
1674         mainwin->progressbar    = progressbar;
1675         mainwin->statuslabel    = statuslabel;
1676         mainwin->online_pixmap  = online_pixmap;
1677         mainwin->offline_pixmap = offline_pixmap;
1678         mainwin->ac_button      = ac_button;
1679         mainwin->ac_label       = ac_label;
1680         /* set context IDs for status bar */
1681         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1682                 (GTK_STATUSBAR(statusbar), "Main Window");
1683         mainwin->folderview_cid = gtk_statusbar_get_context_id
1684                 (GTK_STATUSBAR(statusbar), "Folder View");
1685         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1686                 (GTK_STATUSBAR(statusbar), "Summary View");
1687         mainwin->messageview_cid = gtk_statusbar_get_context_id
1688                 (GTK_STATUSBAR(statusbar), "Message View");
1689         messageview->statusbar_cid = mainwin->messageview_cid;
1690
1691 #else
1692         messageview->statusbar  = NULL;
1693         mainwin->statusbar      = NULL;
1694         mainwin->hbox_stat      = NULL;
1695         /* mainwin->progressbar is set in toolbar.c */
1696         mainwin->statuslabel    = NULL;
1697         mainwin->online_pixmap  = NULL;
1698         mainwin->offline_pixmap = NULL;
1699         mainwin->ac_button      = NULL;
1700         mainwin->ac_label       = NULL;
1701 #endif
1702         
1703         /* allocate colors for summary view and folder view */
1704         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1705         summaryview->color_marked.blue = (guint16)65535;
1706
1707         summaryview->color_dim.red = summaryview->color_dim.green =
1708                 summaryview->color_dim.blue = COLOR_DIM;
1709
1710         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1711                                        &folderview->color_new);
1712
1713         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1714                                        &folderview->color_op);
1715
1716         summaryview->color_important.red = 0;
1717         summaryview->color_important.green = 0;
1718         summaryview->color_important.blue = (guint16)65535;
1719
1720         color[0] = summaryview->color_marked;
1721         color[1] = summaryview->color_dim;
1722         color[2] = folderview->color_new;
1723         color[3] = folderview->color_op;
1724
1725         colormap = gdk_drawable_get_colormap(window->window);
1726         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1727         for (i = 0; i < 4; i++) {
1728                 if (success[i] == FALSE)
1729                         g_warning("MainWindow: color allocation %d failed\n", i);
1730         }
1731
1732         debug_print("done.\n");
1733
1734         messageview->visible = prefs_common.msgview_visible;
1735
1736         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1737
1738         g_signal_connect(G_OBJECT(window), "size_allocate",
1739                          G_CALLBACK(main_window_size_allocate_cb),
1740                          mainwin);
1741
1742         /* set menu items */
1743         menuitem = gtk_item_factory_get_item
1744                 (ifactory, "/View/Character encoding/Auto detect");
1745         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1746
1747         switch (prefs_common.toolbar_style) {
1748         case TOOLBAR_NONE:
1749                 menuitem = gtk_item_factory_get_item
1750                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1751                 break;
1752         case TOOLBAR_ICON:
1753                 menuitem = gtk_item_factory_get_item
1754                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1755                 break;
1756         case TOOLBAR_TEXT:
1757                 menuitem = gtk_item_factory_get_item
1758                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1759                 break;
1760         case TOOLBAR_BOTH:
1761                 menuitem = gtk_item_factory_get_item
1762                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1763                 break;
1764         case TOOLBAR_BOTH_HORIZ:
1765                 menuitem = gtk_item_factory_get_item
1766                         (ifactory,
1767                          "/View/Show or hide/Toolbar/Text beside icons");
1768         }
1769         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1770
1771 #ifndef MAEMO
1772         gtk_widget_hide(mainwin->hbox_stat);
1773         menuitem = gtk_item_factory_get_item
1774                 (ifactory, "/View/Show or hide/Status bar");
1775         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1776                                        prefs_common.show_statusbar);
1777 #endif  
1778         menuitem = gtk_item_factory_get_item
1779                 (ifactory, "/View/Show or hide/Column headers");
1780         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1781                                        prefs_common.show_col_headers);
1782         /* set account selection menu */
1783         ac_menu = gtk_item_factory_get_widget
1784                 (ifactory, "/Configuration/Change current account");
1785         mainwin->ac_menu = ac_menu;
1786
1787         toolbar_main_set_sensitive(mainwin);
1788
1789         /* create actions menu */
1790         main_window_update_actions_menu(mainwin);
1791
1792         main_create_mailing_list_menu (mainwin, NULL);
1793
1794         /* attach accel groups to main window */
1795 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1796         gtk_window_add_accel_group                                      \
1797                 (GTK_WINDOW(win),                                       \
1798                  gtk_item_factory_from_widget(menu)->accel_group);      \
1799         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1800                         "accel_activate",                               \
1801                         G_CALLBACK(main_window_accel_activate), mainwin);
1802                          
1803         
1804         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1805         
1806         /* connect the accelerators for equivalent 
1807            menu items in different menus             */
1808         menu_connect_identical_items();
1809
1810 #ifndef MAEMO
1811         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1812 #endif
1813
1814         g_signal_connect(G_OBJECT(window), "window_state_event",
1815                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1816         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1817                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1818         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1819
1820         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1821             prefs_common.layout_mode == SMALL_LAYOUT) {
1822                 summary_relayout(mainwin->summaryview); 
1823         }
1824         summary_update_unread(mainwin->summaryview, NULL);
1825         
1826         gtk_widget_show(mainwin->window);
1827
1828         /* initialize views */
1829         folderview_init(folderview);
1830         summary_init(summaryview);
1831         messageview_init(messageview);
1832 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
1833         sslcertwindow_register_hook();
1834 #endif
1835         mainwin->lock_count = 0;
1836         mainwin->menu_lock_count = 0;
1837         mainwin->cursor_count = 0;
1838
1839         mainwin->progressindicator_hook =
1840                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1841
1842         if (!watch_cursor)
1843                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1844         if (!hand_cursor)
1845                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1846
1847         /* init work_offline */
1848         if (prefs_common.work_offline)
1849                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1850
1851         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1852         mainwindow_tags_menu_create(mainwin, FALSE);
1853         
1854         return mainwin;
1855 }
1856
1857 void main_window_update_actions_menu(MainWindow *mainwin)
1858 {
1859         GtkItemFactory *ifactory;
1860
1861         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1862         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1863 }
1864
1865 void main_window_cursor_wait(MainWindow *mainwin)
1866 {
1867
1868         if (mainwin->cursor_count == 0) {
1869                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1870                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1871         }
1872         
1873         mainwin->cursor_count++;
1874
1875         gdk_flush();
1876 }
1877
1878 void main_window_cursor_normal(MainWindow *mainwin)
1879 {
1880         if (mainwin->cursor_count)
1881                 mainwin->cursor_count--;
1882
1883         if (mainwin->cursor_count == 0) {
1884                 gdk_window_set_cursor(mainwin->window->window, NULL);
1885                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1886         }
1887         gdk_flush();
1888 }
1889
1890 /* lock / unlock the user-interface */
1891 void main_window_lock(MainWindow *mainwin)
1892 {
1893         if (mainwin->lock_count == 0 && mainwin->ac_button)
1894                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1895
1896         mainwin->lock_count++;
1897
1898         main_window_set_menu_sensitive(mainwin);
1899         toolbar_main_set_sensitive(mainwin);
1900 }
1901
1902 void main_window_unlock(MainWindow *mainwin)
1903 {
1904         if (mainwin->lock_count)
1905                 mainwin->lock_count--;
1906
1907         main_window_set_menu_sensitive(mainwin);
1908         toolbar_main_set_sensitive(mainwin);
1909
1910         if (mainwin->lock_count == 0 && mainwin->ac_button)
1911                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1912 }
1913
1914 static void main_window_menu_callback_block(MainWindow *mainwin)
1915 {
1916         mainwin->menu_lock_count++;
1917 }
1918
1919 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1920 {
1921         if (mainwin->menu_lock_count)
1922                 mainwin->menu_lock_count--;
1923 }
1924
1925 static guint prefs_tag = 0;
1926
1927 void main_window_reflect_prefs_all(void)
1928 {
1929         main_window_reflect_prefs_all_real(FALSE);
1930 }
1931
1932 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1933 {
1934         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1935         GList *cur;
1936         MainWindow *mainwin;
1937 #ifndef MAEMO
1938         GtkWidget *pixmap;
1939 #endif
1940         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1941                 mainwin = (MainWindow *)cur->data;
1942
1943                 main_window_show_cur_account(mainwin);
1944                 main_window_set_menu_sensitive(mainwin);
1945                 toolbar_main_set_sensitive(mainwin);
1946
1947                 /* pixmap themes */
1948                 if (pixmap_theme_changed) {
1949                         toolbar_update(TOOLBAR_MAIN, mainwin);
1950                         messageview_reflect_prefs_pixmap_theme();
1951                         compose_reflect_prefs_pixmap_theme();
1952                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1953                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1954 #ifndef MAEMO
1955                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1956                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1957                                              mainwin->online_pixmap);
1958                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1959                         gtk_widget_show(pixmap);
1960                         mainwin->online_pixmap = pixmap;
1961                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1962                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1963                                              mainwin->offline_pixmap);
1964                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1965                         gtk_widget_show(pixmap);
1966                         mainwin->offline_pixmap = pixmap;
1967 #endif
1968                 }
1969                 
1970                 headerview_set_font(mainwin->messageview->headerview);
1971                 headerview_set_visibility(mainwin->messageview->headerview,
1972                                           prefs_common.display_header_pane);
1973                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1974                 folderview_reflect_prefs();
1975                 summary_reflect_prefs();
1976 #ifndef MAEMO
1977                 summary_redisplay_msg(mainwin->summaryview);
1978 #endif
1979                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1980                         if (mainwin->in_folder) {
1981                                 mainwindow_enter_folder(mainwin);
1982                         } else {
1983                                 mainwindow_exit_folder(mainwin);
1984                         }
1985                 }
1986         }
1987         prefs_tag = 0;
1988         return FALSE;
1989 }
1990
1991 void main_window_reflect_prefs_all_now(void)
1992 {
1993         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1994 }
1995
1996 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1997 {
1998         GtkMenuShell *menu;
1999         GList *cur;
2000
2001         /* re-create colorlabel submenu */
2002         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
2003         g_return_if_fail(menu != NULL);
2004
2005         /* clear items. get item pointers. */
2006         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
2007                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
2008         }
2009         mainwindow_colorlabel_menu_create(mainwin, TRUE);
2010         summary_reflect_prefs_custom_colors(mainwin->summaryview);
2011
2012 }
2013
2014 void main_window_reflect_tags_changes(MainWindow *mainwin)
2015 {
2016         GtkMenuShell *menu;
2017         GList *cur;
2018
2019         /* re-create tags submenu */
2020         menu = GTK_MENU_SHELL(mainwin->tags_menu);
2021         g_return_if_fail(menu != NULL);
2022
2023         /* clear items. get item pointers. */
2024         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
2025                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
2026         }
2027         mainwindow_tags_menu_create(mainwin, TRUE);
2028         summary_reflect_tags_changes(mainwin->summaryview);
2029
2030 }
2031
2032 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
2033 {
2034         if (prefs_tag == 0 || pixmap_theme_changed) {
2035                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
2036                                                 GINT_TO_POINTER(pixmap_theme_changed));
2037         }
2038 }
2039
2040 void main_window_set_summary_column(void)
2041 {
2042         GList *cur;
2043         MainWindow *mainwin;
2044
2045         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2046                 mainwin = (MainWindow *)cur->data;
2047                 summary_set_column_order(mainwin->summaryview);
2048         }
2049 }
2050
2051 void main_window_set_folder_column(void)
2052 {
2053         GList *cur;
2054         MainWindow *mainwin;
2055
2056         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2057                 mainwin = (MainWindow *)cur->data;
2058                 folderview_set_column_order(mainwin->folderview);
2059         }
2060 }
2061
2062 static void main_window_set_account_selector_menu(MainWindow *mainwin,
2063                                                   GList *account_list)
2064 {
2065         GList *cur_ac, *cur_item;
2066         GtkWidget *menuitem;
2067         PrefsAccount *ac_prefs;
2068
2069         /* destroy all previous menu item */
2070         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
2071         while (cur_item != NULL) {
2072                 GList *next = cur_item->next;
2073                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2074                 cur_item = next;
2075         }
2076
2077         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2078                 ac_prefs = (PrefsAccount *)cur_ac->data;
2079
2080                 menuitem = gtk_menu_item_new_with_label
2081                         (ac_prefs->account_name
2082                          ? ac_prefs->account_name : _("Untitled"));
2083                 gtk_widget_show(menuitem);
2084                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
2085                 g_signal_connect(G_OBJECT(menuitem), "activate",
2086                                  G_CALLBACK(account_selector_menu_cb),
2087                                  ac_prefs);
2088         }
2089 }
2090
2091 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2092                                                  GList *account_list)
2093 {
2094         GList *cur_ac, *cur_item;
2095         GtkWidget *menu;
2096         GtkWidget *menuitem;
2097         PrefsAccount *ac_prefs;
2098
2099         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
2100                                            "/Message/Receive");
2101
2102         /* search for separator */
2103         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2104              cur_item = cur_item->next) {
2105                 if (GTK_BIN(cur_item->data)->child == NULL) {
2106                         cur_item = cur_item->next;
2107                         break;
2108                 }
2109         }
2110
2111         /* destroy all previous menu item */
2112         while (cur_item != NULL) {
2113                 GList *next = cur_item->next;
2114                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2115                 cur_item = next;
2116         }
2117
2118         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2119                 ac_prefs = (PrefsAccount *)cur_ac->data;
2120
2121                 menuitem = gtk_menu_item_new_with_label
2122                         (ac_prefs->account_name ? ac_prefs->account_name
2123                          : _("Untitled"));
2124                 gtk_widget_show(menuitem);
2125                 gtk_menu_append(GTK_MENU(menu), menuitem);
2126                 g_signal_connect(G_OBJECT(menuitem), "activate",
2127                                  G_CALLBACK(account_receive_menu_cb),
2128                                  ac_prefs);
2129         }
2130 }
2131
2132 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2133                                                        GList *account_list)
2134 {
2135         GList *cur_ac;
2136         GtkWidget *menuitem;
2137         PrefsAccount *ac_prefs;
2138         GtkWidget *menu = NULL;
2139
2140         if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2141                 return;
2142
2143         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2144         if (menu)
2145                 gtk_widget_destroy(menu);
2146         menu = gtk_menu_new();
2147
2148         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2149                 ac_prefs = (PrefsAccount *)cur_ac->data;
2150
2151                 menuitem = gtk_menu_item_new_with_label
2152                         (ac_prefs->account_name
2153                          ? ac_prefs->account_name : _("Untitled"));
2154                 gtk_widget_show(menuitem);
2155                 gtk_menu_append(GTK_MENU(menu), menuitem);
2156                 g_signal_connect(G_OBJECT(menuitem), "activate",
2157                                  G_CALLBACK(account_receive_menu_cb),
2158                                  ac_prefs);
2159         }
2160         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2161 }
2162
2163 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2164                                                        GList *account_list)
2165 {
2166 #ifndef MAEMO
2167         GList *cur_ac;
2168         GtkWidget *menuitem;
2169         PrefsAccount *ac_prefs;
2170         GtkWidget *menu = NULL;
2171
2172         if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2173                 return;
2174
2175         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2176         if (menu)
2177                 gtk_widget_destroy(menu);
2178         menu = gtk_menu_new();
2179
2180         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2181                 ac_prefs = (PrefsAccount *)cur_ac->data;
2182
2183                 menuitem = gtk_menu_item_new_with_label
2184                         (ac_prefs->account_name
2185                          ? ac_prefs->account_name : _("Untitled"));
2186                 gtk_widget_show(menuitem);
2187                 gtk_menu_append(GTK_MENU(menu), menuitem);
2188                 g_signal_connect(G_OBJECT(menuitem), "activate",
2189                                  G_CALLBACK(account_compose_menu_cb),
2190                                  ac_prefs);
2191         }
2192         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2193 #endif
2194 }
2195
2196 void main_window_set_account_menu(GList *account_list)
2197 {
2198         GList *cur;
2199         MainWindow *mainwin;
2200
2201         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2202                 mainwin = (MainWindow *)cur->data;
2203                 main_window_set_account_selector_menu(mainwin, account_list);
2204                 main_window_set_account_receive_menu(mainwin, account_list);
2205                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2206                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2207         }
2208         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2209 }
2210
2211 void main_window_set_account_menu_only_toolbar(GList *account_list)
2212 {
2213         GList *cur;
2214         MainWindow *mainwin;
2215
2216         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2217                 mainwin = (MainWindow *)cur->data;
2218                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2219                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2220         }
2221 }
2222
2223 static void main_window_show_cur_account(MainWindow *mainwin)
2224 {
2225         gchar *buf;
2226         gchar *ac_name;
2227
2228         ac_name = g_strdup(cur_account
2229                            ? (cur_account->account_name
2230                               ? cur_account->account_name : _("Untitled"))
2231                            : _("none"));
2232
2233         if (cur_account)
2234                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2235         else
2236                 buf = g_strdup(PROG_VERSION);
2237         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2238         g_free(buf);
2239
2240         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2241         if (mainwin->ac_button)
2242                 gtk_widget_queue_resize(mainwin->ac_button);
2243
2244         g_free(ac_name);
2245 }
2246 #ifndef MAEMO
2247 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2248 {
2249         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2250         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2251         GtkWidget *message_wid = mainwin->messageview->vbox;
2252
2253         if (layout_mode == prefs_common.layout_mode) 
2254                 return;
2255
2256         debug_print("Changing window separation type from %d to %d\n",
2257                     prefs_common.layout_mode, layout_mode);
2258
2259         /* remove widgets from those containers */
2260         gtk_widget_ref(folder_wid);
2261         gtk_widget_ref(summary_wid);
2262         gtk_widget_ref(message_wid);
2263         gtkut_container_remove
2264                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2265         gtkut_container_remove
2266                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2267         gtkut_container_remove
2268                 (GTK_CONTAINER(message_wid->parent), message_wid);
2269
2270         gtk_widget_hide(mainwin->window);
2271         main_window_set_widgets(mainwin, layout_mode);
2272         gtk_widget_show(mainwin->window);
2273
2274         gtk_widget_unref(folder_wid);
2275         gtk_widget_unref(summary_wid);
2276         gtk_widget_unref(message_wid);
2277 }
2278 #endif
2279 void mainwindow_reset_paned(GtkPaned *paned)
2280 {
2281                 gint min, max, mid;
2282
2283                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2284                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2285                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2286                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2287
2288 GTK_EVENTS_FLUSH();
2289                 g_object_get (G_OBJECT(paned),
2290                                 "min-position",
2291                                 &min, NULL);
2292                 g_object_get (G_OBJECT(paned),
2293                                 "max-position",
2294                                 &max, NULL);
2295                 mid = (min+max)/2;
2296                 gtk_paned_set_position(GTK_PANED(paned), mid);
2297 }
2298
2299 static void mainwin_paned_show_first(GtkPaned *paned)
2300 {
2301                 gint max;
2302                 g_object_get (G_OBJECT(paned),
2303                                 "max-position",
2304                                 &max, NULL);
2305
2306                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2307                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2308                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2309                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2310                 gtk_paned_set_position(GTK_PANED(paned), max);
2311 }
2312
2313 static void mainwin_paned_show_last(GtkPaned *paned)
2314 {
2315                 gint min;
2316                 g_object_get (G_OBJECT(paned),
2317                                 "min-position",
2318                                 &min, NULL);
2319
2320                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2321                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2322                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2323                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2324                 gtk_paned_set_position(GTK_PANED(paned), min);
2325 }
2326
2327 void main_window_toggle_message_view(MainWindow *mainwin)
2328 {
2329         SummaryView *summaryview = mainwin->summaryview;
2330         GtkWidget *ppaned = NULL;
2331         GtkWidget *container = NULL;
2332         
2333         switch (prefs_common.layout_mode) {
2334         case NORMAL_LAYOUT:
2335         case VERTICAL_LAYOUT:
2336         case SMALL_LAYOUT:
2337                 ppaned = mainwin->vpaned;
2338                 container = mainwin->hpaned;
2339                 if (ppaned->parent != NULL) {
2340                         mainwin->messageview->visible = FALSE;
2341                         summaryview->displayed = NULL;
2342                         gtk_widget_ref(ppaned);
2343                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2344                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2345                 } else {
2346                         mainwin->messageview->visible = TRUE;
2347                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2348                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2349                         gtk_widget_unref(ppaned);
2350                 }
2351                 break;
2352         case WIDE_LAYOUT:
2353                 ppaned = mainwin->hpaned;
2354                 container = mainwin->vpaned;
2355                 if (mainwin->messageview->vbox->parent != NULL) {
2356                         mainwin->messageview->visible = FALSE;
2357                         summaryview->displayed = NULL;
2358                         gtk_widget_ref(mainwin->messageview->vbox);
2359                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2360                 } else {
2361                         mainwin->messageview->visible = TRUE;
2362                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2363                         gtk_widget_unref(mainwin->messageview->vbox);
2364                 }
2365                 break;
2366         case WIDE_MSGLIST_LAYOUT:
2367                 g_warning("can't hide messageview in this wide msglist layout");
2368                 break;
2369         }
2370
2371         if (messageview_is_visible(mainwin->messageview))
2372                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2373                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2374         else
2375                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2376                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2377
2378         if (mainwin->messageview->visible == FALSE)
2379                 messageview_clear(mainwin->messageview);
2380
2381         main_window_set_menu_sensitive(mainwin);
2382
2383         prefs_common.msgview_visible = mainwin->messageview->visible;
2384
2385         if (messageview_is_visible(mainwin->messageview)) {
2386                 gtk_widget_queue_resize(mainwin->hpaned);
2387                 gtk_widget_queue_resize(mainwin->vpaned);
2388         }
2389         summary_grab_focus(summaryview);
2390 }
2391
2392 void main_window_get_size(MainWindow *mainwin)
2393 {
2394         GtkAllocation *allocation;
2395
2396         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2397                 debug_print("called after messageview "
2398                             "has been deallocated!\n");
2399                 return;
2400         }
2401
2402         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2403
2404         if (allocation->width > 1 && allocation->height > 1) {
2405                 prefs_common.summaryview_width = allocation->width;
2406
2407                 if (messageview_is_visible(mainwin->messageview))
2408                         prefs_common.summaryview_height = allocation->height;
2409
2410                 prefs_common.mainview_width = allocation->width;
2411         }
2412
2413         allocation = &mainwin->window->allocation;
2414         if (allocation->width > 1 && allocation->height > 1) {
2415                 prefs_common.mainview_height = allocation->height;
2416                 prefs_common.mainwin_width   = allocation->width;
2417                 prefs_common.mainwin_height  = allocation->height;
2418         }
2419
2420         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2421         if (allocation->width > 1 && allocation->height > 1) {
2422                 prefs_common.folderview_width  = allocation->width;
2423                 prefs_common.folderview_height = allocation->height;
2424         }
2425
2426         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2427         if (allocation->width > 1 && allocation->height > 1) {
2428                 prefs_common.msgview_width = allocation->width;
2429                 prefs_common.msgview_height = allocation->height;
2430         }
2431
2432 /*      debug_print("summaryview size: %d x %d\n",
2433                     prefs_common.summaryview_width,
2434                     prefs_common.summaryview_height);
2435         debug_print("folderview size: %d x %d\n",
2436                     prefs_common.folderview_width,
2437                     prefs_common.folderview_height);
2438         debug_print("messageview size: %d x %d\n",
2439                     prefs_common.msgview_width,
2440                     prefs_common.msgview_height); */
2441 }
2442
2443 void main_window_get_position(MainWindow *mainwin)
2444 {
2445         gint x, y;
2446
2447         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2448
2449         prefs_common.mainview_x = x;
2450         prefs_common.mainview_y = y;
2451         prefs_common.mainwin_x = x;
2452         prefs_common.mainwin_y = y;
2453
2454         debug_print("main window position: %d, %d\n", x, y);
2455 }
2456
2457 void main_window_progress_on(MainWindow *mainwin)
2458 {
2459         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2460 }
2461
2462 void main_window_progress_off(MainWindow *mainwin)
2463 {
2464         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2465         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2466 }
2467
2468 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2469 {
2470         if (confirm && procmsg_have_trashed_mails_fast()) {
2471                 if (alertpanel(_("Empty trash"),
2472                                _("Delete all messages in trash folders?"),
2473                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2474                     != G_ALERTALTERNATE)
2475                         return;
2476                 manage_window_focus_in(mainwin->window, NULL, NULL);
2477         }
2478
2479         procmsg_empty_all_trash();
2480
2481         if (mainwin->summaryview->folder_item &&
2482             mainwin->summaryview->folder_item->stype == F_TRASH)
2483                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2484 }
2485
2486 static void main_window_add_mailbox(MainWindow *mainwin)
2487 {
2488         gchar *path;
2489         Folder *folder;
2490
2491         path = input_dialog(_("Add mailbox"),
2492                             _("Input the location of mailbox.\n"
2493                               "If an existing mailbox is specified, it will be\n"
2494                               "scanned automatically."),
2495                             "Mail");
2496         if (!path) return;
2497         if (folder_find_from_path(path)) {
2498                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2499                 g_free(path);
2500                 return;
2501         }
2502         folder = folder_new(folder_get_class_from_string("mh"), 
2503                             !strcmp(path, "Mail") ? _("Mailbox") : 
2504                             g_path_get_basename(path), path);
2505         g_free(path);
2506
2507         if (folder->klass->create_tree(folder) < 0) {
2508                 alertpanel_error(_("Creation of the mailbox failed.\n"
2509                                    "Maybe some files already exist, or you don't have the permission to write there."));
2510                 folder_destroy(folder);
2511                 return;
2512         }
2513
2514         folder_add(folder);
2515         folder_set_ui_func(folder, scan_tree_func, mainwin);
2516         folder_scan_tree(folder, TRUE);
2517         folder_set_ui_func(folder, NULL, NULL);
2518 }
2519
2520 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2521 {
2522         SensitiveCond state = 0;
2523         SummarySelection selection;
2524         FolderItem *item = mainwin->summaryview->folder_item;
2525         GList *account_list = account_get_list();
2526         GSList *tmp;
2527         
2528         selection = summary_get_selection_type(mainwin->summaryview);
2529
2530         if (mainwin->lock_count == 0 && !claws_is_starting())
2531                 state |= M_UNLOCKED;
2532         if (selection != SUMMARY_NONE)
2533                 state |= M_MSG_EXIST;
2534         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2535                 state |= M_EXEC;
2536                 /*              if (item->folder->type != F_NEWS) */
2537                 state |= M_ALLOW_DELETE;
2538
2539                 if (prefs_common.immediate_exec == 0
2540                     && mainwin->lock_count == 0)
2541                         state |= M_DELAY_EXEC;
2542
2543                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2544                     || selection != SUMMARY_NONE)
2545                         state |= M_HIDE_READ_MSG;
2546         }               
2547         if (mainwin->summaryview->threaded)
2548                 state |= M_THREADED;
2549         else
2550                 state |= M_UNTHREADED;  
2551         if (selection == SUMMARY_SELECTED_SINGLE ||
2552             selection == SUMMARY_SELECTED_MULTIPLE)
2553                 state |= M_TARGET_EXIST;
2554         if (selection == SUMMARY_SELECTED_SINGLE)
2555                 state |= M_SINGLE_TARGET_EXIST;
2556         if (mainwin->summaryview->folder_item &&
2557             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2558                 state |= M_NEWS;
2559         else
2560                 state |= M_NOT_NEWS;
2561         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2562                 state |= M_ACTIONS_EXIST;
2563
2564         tmp = tags_get_list();
2565         if (tmp && g_slist_length(tmp))
2566                 state |= M_TAGS_EXIST;
2567         g_slist_free(tmp);
2568
2569         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2570                 state |= M_HAVE_QUEUED_MAILS;
2571
2572         if (selection == SUMMARY_SELECTED_SINGLE &&
2573             (item &&
2574              (folder_has_parent_of_type(item, F_DRAFT) ||
2575               folder_has_parent_of_type(item, F_OUTBOX) ||
2576               folder_has_parent_of_type(item, F_QUEUE))))
2577                 state |= M_ALLOW_REEDIT;
2578         if (cur_account)
2579                 state |= M_HAVE_ACCOUNT;
2580         
2581         if (any_folder_want_synchronise())
2582                 state |= M_WANT_SYNC;
2583
2584         if (item && item->prefs->processing && selection != SUMMARY_NONE)
2585                 state |= M_HAVE_PROCESSING;
2586
2587         for ( ; account_list != NULL; account_list = account_list->next) {
2588                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2589                         state |= M_HAVE_NEWS_ACCOUNT;
2590                         break;
2591                 }
2592         }
2593         
2594         if (procmsg_spam_can_learn() &&
2595             (mainwin->summaryview->folder_item &&
2596              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2597              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2598                 state |= M_CAN_LEARN_SPAM;
2599         }
2600
2601         if (inc_is_active())
2602                 state |= M_INC_ACTIVE;
2603         if (imap_cancel_all_enabled())
2604                 state |= M_INC_ACTIVE;
2605
2606         if (mainwin->summaryview->deleted > 0 ||
2607             mainwin->summaryview->moved > 0 ||
2608             mainwin->summaryview->copied > 0)
2609                 state |= M_DELAY_EXEC;
2610
2611         return state;
2612 }
2613
2614
2615
2616 void main_window_set_menu_sensitive(MainWindow *mainwin)
2617 {
2618         GtkItemFactory *ifactory = mainwin->menu_factory;
2619         SensitiveCond state;
2620         gboolean sensitive;
2621         GtkWidget *menu;
2622         GtkWidget *menuitem;
2623         SummaryView *summaryview;
2624         gchar *menu_path;
2625         gint i;
2626         GList *cur_item;
2627
2628         static const struct {
2629                 gchar *const entry;
2630                 SensitiveCond cond;
2631         } entry[] = {
2632                 {"/File/Save as...", M_TARGET_EXIST},
2633                 {"/File/Print..."  , M_TARGET_EXIST},
2634                 {"/File/Synchronise folders", M_WANT_SYNC},
2635                 {"/File/Exit"      , M_UNLOCKED},
2636
2637                 {"/Edit/Select thread"             , M_TARGET_EXIST},
2638                 {"/Edit/Delete thread"             , M_TARGET_EXIST},
2639                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2640
2641                 {"/View/Set displayed columns/in Folder list..."
2642                                                    , M_UNLOCKED}, 
2643                 {"/View/Sort"                      , M_EXEC},
2644                 {"/View/Thread view"               , M_EXEC},
2645                 {"/View/Expand all threads"        , M_MSG_EXIST},
2646                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2647                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2648                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2649                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2650                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2651                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2652                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2653                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2654                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2655                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2656                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2657                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2658                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2659                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2660                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2661
2662                 {"/Message/Receive/Get from current account"
2663                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2664                 {"/Message/Receive/Get from all accounts"
2665                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2666                 {"/Message/Receive/Cancel receiving"
2667                                                  , M_INC_ACTIVE},
2668                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2669                 {"/Message/Compose an email message", M_HAVE_ACCOUNT},
2670                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2671                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2672                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2673                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2674                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2675                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2676                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2677                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2678                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2679                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2680                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2681                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2682                 {"/Message/Mark"                  , M_TARGET_EXIST},
2683                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2684                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2685                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2686                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2687                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2688                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2689                 {"/Message/Color label"           , M_TARGET_EXIST},
2690                 {"/Message/Tags"                  , M_TARGET_EXIST},
2691                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2692
2693                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2694                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2695                 {"/Tools/Harvest addresses/from Messages..."
2696                                                        , M_TARGET_EXIST},
2697                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2698                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2699                 {"/Tools/Run folder processing rules"  , M_HAVE_PROCESSING},
2700                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2701                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2702                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2703                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2704                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2705                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2706
2707                 {"/Configuration", M_UNLOCKED},
2708                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2709                 {"/Configuration/Create new account...", M_UNLOCKED},
2710                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2711
2712                 {NULL, 0}
2713         };
2714
2715         state = main_window_get_current_state(mainwin);
2716
2717         for (i = 0; entry[i].entry != NULL; i++) {
2718                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2719                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2720         }
2721
2722         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2723
2724         /* search for separator */
2725         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2726              cur_item = cur_item->next) {
2727                 if (GTK_BIN(cur_item->data)->child == NULL) {
2728                         cur_item = cur_item->next;
2729                         break;
2730                 }
2731         }
2732
2733         for (; cur_item != NULL; cur_item = cur_item->next) {
2734                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2735                                          (M_UNLOCKED & state) != 0);
2736         }
2737
2738         main_window_menu_callback_block(mainwin);
2739
2740 #define SET_CHECK_MENU_ACTIVE(path, active) \
2741 { \
2742         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2743         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2744 }
2745
2746         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2747                               messageview_is_visible(mainwin->messageview));
2748
2749         summaryview = mainwin->summaryview;
2750         menu_path = "/View/Sort/Don't sort";
2751
2752         switch (summaryview->sort_key) {
2753         case SORT_BY_NUMBER:
2754                 menu_path = "/View/Sort/by number"; break;
2755         case SORT_BY_SIZE:
2756                 menu_path = "/View/Sort/by Size"; break;
2757         case SORT_BY_DATE:
2758                 menu_path = "/View/Sort/by Date"; break;
2759         case SORT_BY_THREAD_DATE:
2760                 menu_path = "/View/Sort/by Thread date"; break;
2761         case SORT_BY_FROM:
2762                 menu_path = "/View/Sort/by From"; break;
2763         case SORT_BY_TO:
2764                 menu_path = "/View/Sort/by To"; break;
2765         case SORT_BY_SUBJECT:
2766                 menu_path = "/View/Sort/by Subject"; break;
2767         case SORT_BY_LABEL:
2768                 menu_path = "/View/Sort/by color label"; break;
2769         case SORT_BY_MARK:
2770                 menu_path = "/View/Sort/by mark"; break;
2771         case SORT_BY_STATUS:
2772                 menu_path = "/View/Sort/by status"; break;
2773         case SORT_BY_MIME:
2774                 menu_path = "/View/Sort/by attachment"; break;
2775         case SORT_BY_SCORE:
2776                 menu_path = "/View/Sort/by score"; break;
2777         case SORT_BY_LOCKED:
2778                 menu_path = "/View/Sort/by locked"; break;
2779         case SORT_BY_TAGS:
2780                 menu_path = "/View/Sort/by tag"; break;
2781         case SORT_BY_NONE:
2782         default:
2783                 menu_path = "/View/Sort/Don't sort"; break;
2784         }
2785         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2786
2787         if (summaryview->sort_type == SORT_ASCENDING) {
2788                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2789         } else {
2790                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2791         }
2792
2793         if (summaryview->sort_key != SORT_BY_NONE) {
2794                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2795                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2796         } else {
2797                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2798                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2799         }
2800
2801         if (mainwin->messageview 
2802         &&  mainwin->messageview->mimeview
2803         &&  mainwin->messageview->mimeview->textview)
2804                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2805                               mainwin->messageview->mimeview->textview->show_all_headers);
2806         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2807         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2808         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2809         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2810         if (prefs_common.hide_quotes == 1)
2811                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2812         if (prefs_common.hide_quotes == 2)
2813                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2814         if (prefs_common.hide_quotes == 3)
2815                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2816
2817 #undef SET_CHECK_MENU_ACTIVE
2818
2819         main_window_menu_callback_unblock(mainwin);
2820 }
2821
2822 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2823 {
2824         GtkItemFactory *ifactory;
2825         gint is_menu = 0;
2826         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2827         
2828         if (msginfo) 
2829                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2830         if (is_menu)
2831                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2832                                 (ifactory,"/Message/Mailing-List"), TRUE);
2833         else
2834                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2835                                 (ifactory,"/Message/Mailing-List"), FALSE);
2836 }
2837
2838 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2839 {
2840         gint menu_nb = 0;
2841         GtkWidget *menuitem;
2842         
2843         if (!msginfo || !msginfo->extradata) {
2844                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2845                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2846                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2847                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2848                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2849                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2850                 return 0;
2851         }
2852                 
2853         /* Mailing list post */
2854         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2855                 g_free(msginfo->extradata->list_post);
2856                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2857         }
2858         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2859                 
2860         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2861  
2862         /* Mailing list help */
2863         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2864         
2865         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2866
2867         /* Mailing list subscribe */
2868         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2869         
2870         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2871                 
2872         /* Mailing list unsubscribe */
2873         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2874         
2875         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2876         
2877         /* Mailing list view archive */
2878         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2879         
2880         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2881         
2882         /* Mailing list contact owner */
2883         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2884         
2885         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2886         
2887         return menu_nb;
2888 }
2889
2890 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2891 {
2892         GtkWidget *item, *menu;
2893         const gchar *url_pt ;
2894         gchar url_decoded[BUFFSIZE];
2895         GList *amenu, *alist;
2896         gint menu_nb = 0;
2897         
2898         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2899         
2900         /* First delete old submenu */
2901         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2902         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2903                 alist = amenu->next;
2904                 item = GTK_WIDGET (amenu->data);
2905                 gtk_widget_destroy (item);
2906                 amenu = alist;
2907         }
2908         if (list_header) {
2909                 for (url_pt = list_header; url_pt && *url_pt;) {
2910                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2911                         item = NULL;
2912                         if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
2913                                 item = gtk_menu_item_new_with_label ((url_decoded));
2914                                 g_signal_connect(G_OBJECT(item), "activate",
2915                                                  G_CALLBACK(mailing_list_compose),
2916                                                  NULL);
2917                         }
2918                         else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
2919                                  !g_ascii_strncasecmp(url_decoded, "https:",6)) {
2920
2921                                 item = gtk_menu_item_new_with_label ((url_decoded));
2922                                 g_signal_connect(G_OBJECT(item), "activate",
2923                                                  G_CALLBACK(mailing_list_open_uri),
2924                                                  NULL);
2925                         } 
2926                         if (item) {
2927                                 gtk_menu_append (GTK_MENU(menu), item);
2928                                 gtk_widget_show (item);
2929                                 menu_nb++;
2930                         }
2931                 }
2932         }
2933         if (menu_nb)
2934                 gtk_widget_set_sensitive (menuitem, TRUE);
2935         else
2936                 gtk_widget_set_sensitive (menuitem, FALSE);
2937                 
2938
2939         return menu_nb;
2940 }
2941
2942 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2943 {
2944         gchar tmp[BUFFSIZE];
2945         const gchar *buf;
2946         gint i = 0;
2947         buf = *buffer;
2948         gboolean with_plus = TRUE;
2949
2950         if (buf == 0x00) {
2951                 *url_decoded = '\0';
2952                 *buffer = NULL;
2953                 return;
2954         }
2955         /* Ignore spaces, comments  and tabs () */
2956         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2957                 if (*buf == '(')
2958                         for (;*buf != ')' && *buf != 0x00; buf++);
2959         
2960         /* First non space and non comment must be a < */
2961         if (*buf =='<' ) {
2962                 buf++;
2963                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2964                         with_plus = FALSE;
2965                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2966                 buf++;
2967         }
2968         else  {
2969                 *buffer = NULL;
2970                 *url_decoded = '\0';
2971                 return;
2972         }
2973         
2974         tmp[i]       = 0x00;
2975         *url_decoded = '\0';
2976         *buffer = NULL;
2977         
2978         if (i == maxlen) {
2979                 return;
2980         }
2981         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2982
2983         /* Prepare the work for the next url in the list */
2984         /* after the closing bracket >, ignore space, comments and tabs */
2985         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2986                 if (*buf == '(')
2987                         for (;*buf != ')' && *buf != 0x00; buf++);
2988                         
2989         if (!buf || !*buf) {
2990                 *buffer = NULL;
2991                 return;
2992         }
2993
2994         /* now first non space, non comment must be a comma */
2995         if (*buf != ',')
2996                 for (;*buf != 0x00; buf++);
2997         else
2998                 buf++;
2999         *buffer = buf;
3000 }
3001         
3002 static void mailing_list_compose (GtkWidget *w, gpointer *data)
3003 {
3004         gchar *mailto;
3005
3006         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
3007         compose_new(NULL, mailto+7, NULL);
3008 }
3009  
3010  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
3011 {
3012  
3013         gchar *mailto;
3014  
3015         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
3016         open_uri (mailto, prefs_common.uri_cmd);
3017
3018         
3019 void main_window_popup(MainWindow *mainwin)
3020 {
3021         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
3022                 main_window_show(mainwin);
3023
3024         gtkut_window_popup(mainwin->window);
3025         if (prefs_common.layout_mode == SMALL_LAYOUT) {
3026                 if (mainwin->in_folder) {
3027                         mainwindow_enter_folder(mainwin);
3028                 } else {
3029                         mainwindow_exit_folder(mainwin);
3030                 }
3031         }
3032 }
3033
3034 void main_window_show(MainWindow *mainwin)
3035 {
3036         gtk_widget_show(mainwin->window);
3037         gtk_widget_show(mainwin->vbox_body);
3038
3039         gtk_widget_set_uposition(mainwin->window,
3040                                  prefs_common.mainwin_x,
3041                                  prefs_common.mainwin_y);
3042
3043         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3044                              prefs_common.folderview_width,
3045                              prefs_common.folderview_height);
3046         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3047                              prefs_common.summaryview_width,
3048                              prefs_common.summaryview_height);
3049         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3050                              prefs_common.msgview_width,
3051                              prefs_common.msgview_height);
3052 }
3053
3054 void main_window_hide(MainWindow *mainwin)
3055 {
3056         main_window_get_size(mainwin);
3057         main_window_get_position(mainwin);
3058
3059         gtk_widget_hide(mainwin->window);
3060         gtk_widget_hide(mainwin->vbox_body);
3061 }
3062
3063 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
3064 {
3065         GtkWidget *folderwin = NULL;
3066         GtkWidget *messagewin = NULL;
3067         GtkWidget *hpaned;
3068         GtkWidget *vpaned;
3069         GtkWidget *vbox_body = mainwin->vbox_body;
3070         GtkItemFactory *ifactory = mainwin->menu_factory;
3071         GtkWidget *menuitem;
3072         gboolean first_set = (mainwin->hpaned == NULL);
3073         debug_print("Setting widgets... ");
3074
3075         if (layout_mode == SMALL_LAYOUT && first_set) {
3076                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3077                                     prefs_common.folderview_width,
3078                                     prefs_common.folderview_height);
3079                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3080                                     0,0);
3081                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3082                                     0,0);
3083         } else {
3084                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3085                                     prefs_common.folderview_width,
3086                                     prefs_common.folderview_height);
3087                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3088                                     prefs_common.summaryview_width,
3089                                     prefs_common.summaryview_height);
3090                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3091                                     prefs_common.msgview_width,
3092                                     prefs_common.msgview_height);
3093         }
3094
3095 #ifndef MAEMO
3096         mainwin->messageview->statusbar = mainwin->statusbar;
3097         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3098 #endif
3099         /* clean top-most container */
3100         if (mainwin->hpaned) {
3101                 if (mainwin->hpaned->parent == mainwin->vpaned)
3102                         gtk_widget_destroy(mainwin->vpaned);
3103                 else
3104                         gtk_widget_destroy(mainwin->hpaned);
3105         }
3106
3107         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
3108                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3109         switch (layout_mode) {
3110         case VERTICAL_LAYOUT:
3111         case NORMAL_LAYOUT:
3112         case SMALL_LAYOUT:
3113                 hpaned = gtk_hpaned_new();
3114                 if (layout_mode == VERTICAL_LAYOUT)
3115                         vpaned = gtk_hpaned_new();
3116                 else
3117                         vpaned = gtk_vpaned_new();
3118                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3119                 gtk_paned_add1(GTK_PANED(hpaned),
3120                                GTK_WIDGET_PTR(mainwin->folderview));
3121                 gtk_widget_show(hpaned);
3122                 gtk_widget_queue_resize(hpaned);
3123
3124                 if (messageview_is_visible(mainwin->messageview)) {
3125                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3126                         gtk_paned_add1(GTK_PANED(vpaned),
3127                                        GTK_WIDGET_PTR(mainwin->summaryview));
3128                 } else {
3129                         gtk_paned_add2(GTK_PANED(hpaned),
3130                                        GTK_WIDGET_PTR(mainwin->summaryview));
3131                         gtk_widget_ref(vpaned);
3132                 }
3133                 gtk_paned_add2(GTK_PANED(vpaned),
3134                                GTK_WIDGET_PTR(mainwin->messageview));
3135                 gtk_widget_show(vpaned);
3136                 if (layout_mode == SMALL_LAYOUT && first_set) {
3137                         mainwin_paned_show_first(GTK_PANED(hpaned));
3138                 }
3139                 gtk_widget_queue_resize(vpaned);
3140                 break;
3141         case WIDE_LAYOUT:
3142                 vpaned = gtk_vpaned_new();
3143                 hpaned = gtk_hpaned_new();
3144                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3145                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3146
3147                 gtk_paned_add1(GTK_PANED(hpaned),
3148                                GTK_WIDGET_PTR(mainwin->folderview));
3149                 gtk_paned_add2(GTK_PANED(hpaned),
3150                                GTK_WIDGET_PTR(mainwin->summaryview));
3151
3152                 gtk_widget_show(hpaned);
3153                 gtk_widget_queue_resize(hpaned);
3154
3155                 if (messageview_is_visible(mainwin->messageview)) {
3156                         gtk_paned_add2(GTK_PANED(vpaned),
3157                                GTK_WIDGET_PTR(mainwin->messageview));   
3158                 } else {
3159                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3160                 }
3161                 gtk_widget_show(vpaned);
3162                 gtk_widget_queue_resize(vpaned);
3163                 break;
3164         case WIDE_MSGLIST_LAYOUT:
3165                 vpaned = gtk_vpaned_new();
3166                 hpaned = gtk_hpaned_new();
3167                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3168
3169                 gtk_paned_add1(GTK_PANED(vpaned),
3170                                GTK_WIDGET_PTR(mainwin->summaryview));
3171                 gtk_paned_add1(GTK_PANED(hpaned),
3172                                GTK_WIDGET_PTR(mainwin->folderview));
3173
3174                 gtk_widget_show(hpaned);
3175                 gtk_widget_queue_resize(hpaned);
3176
3177                 if (messageview_is_visible(mainwin->messageview)) {
3178                         gtk_paned_add2(GTK_PANED(hpaned),
3179                                GTK_WIDGET_PTR(mainwin->messageview));   
3180                 } else {
3181                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3182                 }