2008-05-07 [colin] 3.4.0cvs29
[claws.git] / src / mainwindow.c
1 /*
2    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3    Copyright (C) 1999-2008 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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 GENERIC_UMPC
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 (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
1383                         if (mainwin->folderview && mainwin->summaryview
1384                             && ((!mainwin->summaryview->displayed
1385                                 && !mainwin->summaryview->selected) 
1386                                 || (mainwin->summaryview->folder_item
1387                                     && mainwin->summaryview->folder_item->total_msgs == 0))) {
1388                                 g_signal_stop_emission_by_name(G_OBJECT(widget), 
1389                                                "key_press_event");
1390                                 folderview_select_next_unread(mainwin->folderview, TRUE);
1391                         }
1392                 }
1393                 break;
1394 #ifdef MAEMO
1395         case GDK_F6:
1396                 if (maemo_mainwindow_is_fullscreen(widget)) {
1397                         gtk_window_unfullscreen(GTK_WINDOW(widget));
1398                 } else {
1399                         gtk_window_fullscreen(GTK_WINDOW(widget));
1400                 }
1401                 break;
1402         case GDK_Escape:
1403                 if (mainwin->summaryview && 
1404                     mainwin->summaryview->ext_messageview && 
1405                     mainwin->summaryview->ext_messageview->window && 
1406                     widget == mainwin->summaryview->ext_messageview->window) {
1407                         messageview_destroy(mainwin->summaryview->ext_messageview);
1408                 }
1409                 break;
1410 #endif
1411         default:
1412                 break;
1413         }
1414         return FALSE;
1415 }
1416
1417 #undef BREAK_ON_MODIFIER_KEY
1418
1419 #ifdef MAEMO
1420 void mainwindow_maemo_led_set(gboolean state) {
1421         static gint last_state = -1;
1422         if (last_state == state)
1423                 return;
1424         last_state = (gint)state;
1425         if (prefs_common.maemo_show_led) {
1426                 if(state) {
1427                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1428                         "--dest=com.nokia.mce "
1429                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
1430                         "string:PatternCommunicationEvent", TRUE);
1431                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1432                         "--dest=com.nokia.mce "
1433                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
1434                         "string:PatternCommunicationEmail", TRUE);
1435                 } else {
1436                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1437                         "--dest=com.nokia.mce "
1438                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
1439                         "string:PatternCommunicationEvent", TRUE);
1440                   execute_command_line("/usr/bin/dbus-send --system --type=method_call "
1441                         "--dest=com.nokia.mce "
1442                         "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
1443                         "string:PatternCommunicationEmail", TRUE);
1444                 }
1445         } 
1446 }
1447
1448 static void led_update(FolderItem *removed_item)
1449 {
1450         guint new, unread, unreadmarked, marked, total, replied;
1451         guint forwarded, locked, ignored, watched;
1452
1453         folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
1454                                 &replied, &forwarded, &locked, &ignored,
1455                                 &watched);
1456         if (removed_item) {
1457                 total -= removed_item->total_msgs;
1458                 new -= removed_item->new_msgs;
1459                 unread -= removed_item->unread_msgs;
1460         }
1461
1462         if (new > 0)
1463                 mainwindow_maemo_led_set(TRUE);
1464         else
1465                 mainwindow_maemo_led_set(FALSE);
1466 }
1467
1468 static gboolean maemo_folder_item_update_hook(gpointer source, gpointer data)
1469 {
1470         led_update(NULL);
1471
1472         return FALSE;
1473 }
1474
1475 static gboolean maemo_folder_update_hook(gpointer source, gpointer data)
1476 {
1477         FolderUpdateData *hookdata;
1478         hookdata = source;
1479         if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
1480                 led_update(hookdata->item);
1481         else
1482                 led_update(NULL);
1483
1484         return FALSE;
1485 }
1486
1487 static void main_window_install_maemo_hooks(MainWindow *mainwin)
1488 {
1489         gint maemo_item_hook_id, maemo_folder_hook_id;
1490         
1491         maemo_item_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, maemo_folder_item_update_hook, NULL);
1492         if (maemo_item_hook_id == -1) {
1493                 goto err_out_item;
1494         }
1495
1496         maemo_folder_hook_id = hooks_register_hook (FOLDER_UPDATE_HOOKLIST, maemo_folder_update_hook, NULL);
1497         if (maemo_folder_hook_id == -1) {
1498                 goto err_out_folder;
1499         }
1500         
1501         return;
1502
1503 err_out_folder:
1504         hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, maemo_item_hook_id);
1505 err_out_item:
1506         return;
1507 }
1508 #endif
1509
1510 MainWindow *main_window_create()
1511 {
1512         MainWindow *mainwin;
1513         GtkWidget *window;
1514         GtkWidget *vbox;
1515         GtkWidget *menubar;
1516         GtkWidget *handlebox;
1517         GtkWidget *vbox_body;
1518 #ifndef GENERIC_UMPC
1519         GtkWidget *hbox_stat;
1520         GtkWidget *statusbar;
1521         GtkWidget *progressbar;
1522         GtkWidget *statuslabel;
1523         GtkWidget *ac_button;
1524         GtkWidget *ac_label;
1525         GtkWidget *online_pixmap;
1526         GtkWidget *offline_pixmap;
1527         GtkTooltips *tips;
1528         GtkWidget *warning_icon;
1529         GtkWidget *warning_btn;
1530 #endif
1531         GtkWidget *online_switch;
1532         GtkWidget *offline_switch;
1533         FolderView *folderview;
1534         SummaryView *summaryview;
1535         MessageView *messageview;
1536         GdkColormap *colormap;
1537         GdkColor color[4];
1538         gboolean success[4];
1539         GtkItemFactory *ifactory;
1540         GtkWidget *ac_menu;
1541         GtkWidget *menuitem;
1542         gint i;
1543         guint n_menu_entries;
1544
1545         static GdkGeometry geometry;
1546
1547         debug_print("Creating main window...\n");
1548         mainwin = g_new0(MainWindow, 1);
1549
1550         /* main window */
1551         window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
1552         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1553         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1554 #ifdef GENERIC_UMPC
1555         prefs_common.layout_mode = SMALL_LAYOUT;
1556 #endif
1557         if (!geometry.min_height) {
1558                 geometry.min_width = 320;
1559                 geometry.min_height = 200;
1560         }
1561         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1562                                       GDK_HINT_MIN_SIZE);
1563
1564         g_signal_connect(G_OBJECT(window), "delete_event",
1565                          G_CALLBACK(main_window_close_cb), mainwin);
1566         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1567         g_signal_connect(G_OBJECT(window), "focus_in_event",
1568                          G_CALLBACK(mainwindow_focus_in_event),
1569                          mainwin);
1570         g_signal_connect(G_OBJECT(window), "key_press_event",
1571                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1572
1573         gtk_widget_realize(window);
1574         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1575         
1576
1577         gtkut_widget_set_app_icon(window);
1578
1579         vbox = gtk_vbox_new(FALSE, 0);
1580         gtk_widget_show(vbox);
1581         gtk_container_add(GTK_CONTAINER(window), vbox);
1582
1583         /* menu bar */
1584         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1585         menubar = menubar_create(window, mainwin_entries, 
1586                                  n_menu_entries, "<Main>", mainwin);
1587         gtk_widget_show(menubar);
1588
1589 #ifndef MAEMO
1590         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1591 #endif
1592
1593         ifactory = gtk_item_factory_from_widget(menubar);
1594
1595 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1596         main_create_mailing_list_menu (mainwin, NULL); */
1597
1598         if (prefs_common.toolbar_detachable) {
1599                 handlebox = gtk_handle_box_new();
1600                 gtk_widget_show(handlebox);
1601                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1602                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1603                                  G_CALLBACK(toolbar_child_attached), mainwin);
1604                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1605                                  G_CALLBACK(toolbar_child_detached), mainwin);
1606         } else {
1607                 handlebox = gtk_hbox_new(FALSE, 0);
1608                 gtk_widget_show(handlebox);
1609                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1610         }
1611         /* link window to mainwin->window to avoid gdk warnings */
1612         mainwin->window       = window;
1613         mainwin_list = g_list_append(mainwin_list, mainwin);
1614         
1615 #ifdef MAEMO
1616         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1617                                           window, 
1618                                           (gpointer)mainwin);
1619 #else
1620         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1621                                           handlebox, 
1622                                           (gpointer)mainwin);
1623 #endif
1624         toolbar_set_learn_button
1625                 (mainwin->toolbar,
1626                  LEARN_SPAM);
1627
1628         /* vbox that contains body */
1629         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1630         gtk_widget_show(vbox_body);
1631         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1632         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1633
1634 #ifndef GENERIC_UMPC
1635         hbox_stat = gtk_hbox_new(FALSE, 2);
1636         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1637
1638         tips = gtk_tooltips_new();
1639
1640         warning_icon = gtk_image_new_from_stock
1641                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1642         warning_btn = gtk_event_box_new();
1643         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1644         
1645         mainwin->warning_btn      = warning_btn;
1646         
1647         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1648                          G_CALLBACK(warning_icon_pressed),
1649                          (gpointer) mainwin);
1650         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1651                          G_CALLBACK(warning_visi_notify), mainwin);
1652         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1653                          G_CALLBACK(warning_visi_notify), mainwin);
1654         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1655                          G_CALLBACK(warning_leave_notify), mainwin);
1656         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1657                          G_CALLBACK(warning_enter_notify), mainwin);
1658
1659         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1660
1661         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1662                              _("Some error(s) happened. Click here to view log."), NULL);
1663         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1664
1665         statusbar = statusbar_create();
1666         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1667
1668         progressbar = gtk_progress_bar_new();
1669         gtk_widget_set_size_request(progressbar, 120, 1);
1670         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1671
1672         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1673         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1674         online_switch = gtk_button_new ();
1675         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1676                              _("You are online. Click the icon to go offline"), NULL);
1677         offline_switch = gtk_button_new ();
1678         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1679                              _("You are offline. Click the icon to go online"),
1680                              NULL);
1681         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1682         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1683         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1684         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1685         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1686         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1687         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1688         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1689         
1690         statuslabel = gtk_label_new("");
1691         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1692
1693         ac_button = gtk_button_new();
1694         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1695                              ac_button, _("Select account"), NULL);
1696         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1697         gtk_widget_set_size_request(ac_button, -1, 0);
1698         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1699         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1700                          G_CALLBACK(ac_label_button_pressed), mainwin);
1701
1702         ac_label = gtk_label_new("");
1703         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1704
1705         gtk_widget_show_all(hbox_stat);
1706
1707         gtk_widget_hide(offline_switch);
1708         gtk_widget_hide(warning_btn);
1709 #else
1710         online_switch = gtk_button_new ();
1711         offline_switch = gtk_button_new ();
1712         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1713         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1714 #endif
1715         /* create views */
1716         mainwin->folderview  = folderview  = folderview_create();
1717         mainwin->summaryview = summaryview = summary_create();
1718         mainwin->messageview = messageview = messageview_create(mainwin);
1719
1720         /* init log instances data before creating log views */
1721         set_log_title(LOG_PROTOCOL, _("Network log"));
1722         set_log_prefs(LOG_PROTOCOL,
1723                         &prefs_common.logwin_width,
1724                         &prefs_common.logwin_height);
1725         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1726         set_log_prefs(LOG_DEBUG_FILTERING,
1727                         &prefs_common.filtering_debugwin_width,
1728                         &prefs_common.filtering_debugwin_height);
1729
1730         /* setup log windows */
1731         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1732         log_window_init(mainwin->logwin);
1733
1734         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1735         log_window_set_clipping(mainwin->logwin,
1736                                 prefs_common.cliplog,
1737                                 prefs_common.loglength);
1738
1739         log_window_init(mainwin->filtering_debugwin);
1740         log_window_set_clipping(mainwin->filtering_debugwin,
1741                                 prefs_common.filtering_debug_cliplog,
1742                                 prefs_common.filtering_debug_loglength);
1743         if (prefs_common.enable_filtering_debug)
1744                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1745         else
1746                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1747
1748         folderview->mainwin      = mainwin;
1749         folderview->summaryview  = summaryview;
1750
1751         summaryview->mainwin     = mainwin;
1752         summaryview->folderview  = folderview;
1753         summaryview->messageview = messageview;
1754         summaryview->window      = window;
1755
1756         mainwin->vbox           = vbox;
1757         mainwin->menubar        = menubar;
1758         mainwin->menu_factory   = ifactory;
1759         mainwin->handlebox      = handlebox;
1760         mainwin->vbox_body      = vbox_body;
1761         mainwin->online_switch  = online_switch;
1762         mainwin->offline_switch    = offline_switch;
1763 #ifndef GENERIC_UMPC
1764         messageview->statusbar  = statusbar;
1765         mainwin->statusbar      = statusbar;
1766         mainwin->hbox_stat      = hbox_stat;
1767         mainwin->progressbar    = progressbar;
1768         mainwin->statuslabel    = statuslabel;
1769         mainwin->online_pixmap  = online_pixmap;
1770         mainwin->offline_pixmap = offline_pixmap;
1771         mainwin->ac_button      = ac_button;
1772         mainwin->ac_label       = ac_label;
1773         /* set context IDs for status bar */
1774         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1775                 (GTK_STATUSBAR(statusbar), "Main Window");
1776         mainwin->folderview_cid = gtk_statusbar_get_context_id
1777                 (GTK_STATUSBAR(statusbar), "Folder View");
1778         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1779                 (GTK_STATUSBAR(statusbar), "Summary View");
1780         mainwin->messageview_cid = gtk_statusbar_get_context_id
1781                 (GTK_STATUSBAR(statusbar), "Message View");
1782         messageview->statusbar_cid = mainwin->messageview_cid;
1783
1784 #else
1785         messageview->statusbar  = NULL;
1786         mainwin->statusbar      = NULL;
1787         mainwin->hbox_stat      = NULL;
1788         /* mainwin->progressbar is set in toolbar.c */
1789         mainwin->statuslabel    = NULL;
1790         mainwin->online_pixmap  = NULL;
1791         mainwin->offline_pixmap = NULL;
1792         mainwin->ac_button      = NULL;
1793         mainwin->ac_label       = NULL;
1794 #endif
1795         
1796         /* allocate colors for summary view and folder view */
1797         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1798         summaryview->color_marked.blue = (guint16)65535;
1799
1800         summaryview->color_dim.red = summaryview->color_dim.green =
1801                 summaryview->color_dim.blue = COLOR_DIM;
1802
1803         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1804                                        &folderview->color_new);
1805
1806         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1807                                        &folderview->color_op);
1808
1809         summaryview->color_important.red = 0;
1810         summaryview->color_important.green = 0;
1811         summaryview->color_important.blue = (guint16)65535;
1812
1813         color[0] = summaryview->color_marked;
1814         color[1] = summaryview->color_dim;
1815         color[2] = folderview->color_new;
1816         color[3] = folderview->color_op;
1817
1818         colormap = gdk_drawable_get_colormap(window->window);
1819         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1820         for (i = 0; i < 4; i++) {
1821                 if (success[i] == FALSE)
1822                         g_warning("MainWindow: color allocation %d failed\n", i);
1823         }
1824
1825         debug_print("done.\n");
1826
1827         messageview->visible = prefs_common.msgview_visible;
1828
1829         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1830
1831         g_signal_connect(G_OBJECT(window), "size_allocate",
1832                          G_CALLBACK(main_window_size_allocate_cb),
1833                          mainwin);
1834
1835         /* set menu items */
1836         menuitem = gtk_item_factory_get_item
1837                 (ifactory, "/View/Character encoding/Auto detect");
1838         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1839
1840         switch (prefs_common.toolbar_style) {
1841         case TOOLBAR_NONE:
1842                 menuitem = gtk_item_factory_get_item
1843                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1844                 break;
1845         case TOOLBAR_ICON:
1846                 menuitem = gtk_item_factory_get_item
1847                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1848                 break;
1849         case TOOLBAR_TEXT:
1850                 menuitem = gtk_item_factory_get_item
1851                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1852                 break;
1853         case TOOLBAR_BOTH:
1854                 menuitem = gtk_item_factory_get_item
1855                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1856                 break;
1857         case TOOLBAR_BOTH_HORIZ:
1858                 menuitem = gtk_item_factory_get_item
1859                         (ifactory,
1860                          "/View/Show or hide/Toolbar/Text beside icons");
1861         }
1862         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1863
1864 #ifndef GENERIC_UMPC
1865         gtk_widget_hide(mainwin->hbox_stat);
1866         menuitem = gtk_item_factory_get_item
1867                 (ifactory, "/View/Show or hide/Status bar");
1868         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1869                                        prefs_common.show_statusbar);
1870 #endif  
1871         menuitem = gtk_item_factory_get_item
1872                 (ifactory, "/View/Show or hide/Column headers");
1873         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1874                                        prefs_common.show_col_headers);
1875         /* set account selection menu */
1876         ac_menu = gtk_item_factory_get_widget
1877                 (ifactory, "/Configuration/Change current account");
1878         mainwin->ac_menu = ac_menu;
1879
1880         toolbar_main_set_sensitive(mainwin);
1881
1882         /* create actions menu */
1883         main_window_update_actions_menu(mainwin);
1884
1885         main_create_mailing_list_menu (mainwin, NULL);
1886
1887         /* attach accel groups to main window */
1888 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1889         gtk_window_add_accel_group                                      \
1890                 (GTK_WINDOW(win),                                       \
1891                  gtk_item_factory_from_widget(menu)->accel_group);      \
1892         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1893                         "accel_activate",                               \
1894                         G_CALLBACK(main_window_accel_activate), mainwin);
1895                          
1896         
1897         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1898         
1899         /* connect the accelerators for equivalent 
1900            menu items in different menus             */
1901         menu_connect_identical_items();
1902
1903 #ifndef GENERIC_UMPC
1904         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1905 #endif
1906
1907         g_signal_connect(G_OBJECT(window), "window_state_event",
1908                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1909         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1910                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1911         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1912
1913         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1914             prefs_common.layout_mode == SMALL_LAYOUT) {
1915                 summary_relayout(mainwin->summaryview); 
1916         }
1917         summary_update_unread(mainwin->summaryview, NULL);
1918         
1919         gtk_widget_show(mainwin->window);
1920
1921         /* initialize views */
1922         folderview_init(folderview);
1923         summary_init(summaryview);
1924         messageview_init(messageview);
1925 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
1926         sslcertwindow_register_hook();
1927 #endif
1928         mainwin->lock_count = 0;
1929         mainwin->menu_lock_count = 0;
1930         mainwin->cursor_count = 0;
1931
1932         mainwin->progressindicator_hook =
1933                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1934
1935         if (!watch_cursor)
1936                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1937         if (!hand_cursor)
1938                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1939
1940         /* init work_offline */
1941         if (prefs_common.work_offline)
1942                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1943
1944         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1945         mainwindow_tags_menu_create(mainwin, FALSE);
1946
1947 #ifdef MAEMO
1948         main_window_install_maemo_hooks(mainwin);
1949 #endif
1950         return mainwin;
1951 }
1952
1953 void main_window_update_actions_menu(MainWindow *mainwin)
1954 {
1955         GtkItemFactory *ifactory;
1956
1957         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1958         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1959 }
1960
1961 void main_window_cursor_wait(MainWindow *mainwin)
1962 {
1963
1964         if (mainwin->cursor_count == 0) {
1965                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1966                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1967         }
1968         
1969         mainwin->cursor_count++;
1970
1971         gdk_flush();
1972 }
1973
1974 void main_window_cursor_normal(MainWindow *mainwin)
1975 {
1976         if (mainwin->cursor_count)
1977                 mainwin->cursor_count--;
1978
1979         if (mainwin->cursor_count == 0) {
1980                 gdk_window_set_cursor(mainwin->window->window, NULL);
1981                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1982         }
1983         gdk_flush();
1984 }
1985
1986 /* lock / unlock the user-interface */
1987 void main_window_lock(MainWindow *mainwin)
1988 {
1989         if (mainwin->lock_count == 0 && mainwin->ac_button)
1990                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1991
1992         mainwin->lock_count++;
1993
1994         main_window_set_menu_sensitive(mainwin);
1995         toolbar_main_set_sensitive(mainwin);
1996 }
1997
1998 void main_window_unlock(MainWindow *mainwin)
1999 {
2000         if (mainwin->lock_count)
2001                 mainwin->lock_count--;
2002
2003         main_window_set_menu_sensitive(mainwin);
2004         toolbar_main_set_sensitive(mainwin);
2005
2006         if (mainwin->lock_count == 0 && mainwin->ac_button)
2007                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
2008 }
2009
2010 static void main_window_menu_callback_block(MainWindow *mainwin)
2011 {
2012         mainwin->menu_lock_count++;
2013 }
2014
2015 static void main_window_menu_callback_unblock(MainWindow *mainwin)
2016 {
2017         if (mainwin->menu_lock_count)
2018                 mainwin->menu_lock_count--;
2019 }
2020
2021 static guint prefs_tag = 0;
2022
2023 void main_window_reflect_prefs_all(void)
2024 {
2025         main_window_reflect_prefs_all_real(FALSE);
2026 }
2027
2028 static gboolean reflect_prefs_timeout_cb(gpointer data) 
2029 {
2030         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
2031         GList *cur;
2032         MainWindow *mainwin;
2033 #ifndef GENERIC_UMPC
2034         GtkWidget *pixmap;
2035 #endif
2036         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2037                 mainwin = (MainWindow *)cur->data;
2038
2039                 main_window_show_cur_account(mainwin);
2040                 main_window_set_menu_sensitive(mainwin);
2041                 toolbar_main_set_sensitive(mainwin);
2042
2043                 /* pixmap themes */
2044                 if (pixmap_theme_changed) {
2045                         toolbar_update(TOOLBAR_MAIN, mainwin);
2046                         messageview_reflect_prefs_pixmap_theme();
2047                         compose_reflect_prefs_pixmap_theme();
2048                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
2049                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
2050 #ifndef GENERIC_UMPC
2051                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
2052                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
2053                                              mainwin->online_pixmap);
2054                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
2055                         gtk_widget_show(pixmap);
2056                         mainwin->online_pixmap = pixmap;
2057                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
2058                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
2059                                              mainwin->offline_pixmap);
2060                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
2061                         gtk_widget_show(pixmap);
2062                         mainwin->offline_pixmap = pixmap;
2063 #endif
2064                 }
2065                 
2066                 headerview_set_font(mainwin->messageview->headerview);
2067                 headerview_set_visibility(mainwin->messageview->headerview,
2068                                           prefs_common.display_header_pane);
2069                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
2070                 folderview_reflect_prefs();
2071                 summary_reflect_prefs();
2072 #ifndef GENERIC_UMPC
2073                 summary_redisplay_msg(mainwin->summaryview);
2074 #endif
2075                 if (prefs_common.layout_mode == SMALL_LAYOUT) {
2076                         if (mainwin->in_folder) {
2077                                 mainwindow_enter_folder(mainwin);
2078                         } else {
2079                                 mainwindow_exit_folder(mainwin);
2080                         }
2081                 }
2082         }
2083         prefs_tag = 0;
2084         return FALSE;
2085 }
2086
2087 void main_window_reflect_prefs_all_now(void)
2088 {
2089         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
2090 }
2091
2092 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
2093 {
2094         GtkMenuShell *menu;
2095         GList *cur;
2096
2097         /* re-create colorlabel submenu */
2098         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
2099         g_return_if_fail(menu != NULL);
2100
2101         /* clear items. get item pointers. */
2102         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
2103                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
2104         }
2105         mainwindow_colorlabel_menu_create(mainwin, TRUE);
2106         summary_reflect_prefs_custom_colors(mainwin->summaryview);
2107
2108 }
2109
2110 static gint tags_tag = 0;
2111 static gboolean main_window_reflect_tags_changes_real(gpointer data)
2112 {
2113         GtkMenuShell *menu;
2114         GList *cur;
2115         MainWindow *mainwin = (MainWindow *)data;
2116
2117         if (summary_is_locked(mainwin->summaryview)) {
2118                 tags_tag = 0;
2119                 return TRUE;
2120         }
2121         /* re-create tags submenu */
2122         menu = GTK_MENU_SHELL(mainwin->tags_menu);
2123         g_return_val_if_fail(menu != NULL, FALSE);
2124
2125         /* clear items. get item pointers. */
2126         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
2127                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
2128         }
2129         mainwindow_tags_menu_create(mainwin, TRUE);
2130         summary_reflect_tags_changes(mainwin->summaryview);
2131         
2132         tags_tag = 0;
2133         return FALSE;
2134 }
2135
2136 void main_window_reflect_tags_changes(MainWindow *mainwin)
2137 {
2138         if (tags_tag == 0) {
2139                 tags_tag = g_timeout_add(100, main_window_reflect_tags_changes_real, 
2140                                                 mainwin);
2141         }
2142 }
2143
2144 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
2145 {
2146         if (prefs_tag == 0 || pixmap_theme_changed) {
2147                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
2148                                                 GINT_TO_POINTER(pixmap_theme_changed));
2149         }
2150 }
2151
2152 void main_window_set_summary_column(void)
2153 {
2154         GList *cur;
2155         MainWindow *mainwin;
2156
2157         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2158                 mainwin = (MainWindow *)cur->data;
2159                 summary_set_column_order(mainwin->summaryview);
2160         }
2161 }
2162
2163 void main_window_set_folder_column(void)
2164 {
2165         GList *cur;
2166         MainWindow *mainwin;
2167
2168         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2169                 mainwin = (MainWindow *)cur->data;
2170                 folderview_set_column_order(mainwin->folderview);
2171         }
2172 }
2173
2174 static void main_window_set_account_selector_menu(MainWindow *mainwin,
2175                                                   GList *account_list)
2176 {
2177         GList *cur_ac, *cur_item;
2178         GtkWidget *menuitem;
2179         PrefsAccount *ac_prefs;
2180
2181         /* destroy all previous menu item */
2182         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
2183         while (cur_item != NULL) {
2184                 GList *next = cur_item->next;
2185                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2186                 cur_item = next;
2187         }
2188
2189         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2190                 ac_prefs = (PrefsAccount *)cur_ac->data;
2191
2192                 menuitem = gtk_menu_item_new_with_label
2193                         (ac_prefs->account_name
2194                          ? ac_prefs->account_name : _("Untitled"));
2195                 gtk_widget_show(menuitem);
2196                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
2197                 g_signal_connect(G_OBJECT(menuitem), "activate",
2198                                  G_CALLBACK(account_selector_menu_cb),
2199                                  ac_prefs);
2200         }
2201 }
2202
2203 static void main_window_set_account_receive_menu(MainWindow *mainwin,
2204                                                  GList *account_list)
2205 {
2206         GList *cur_ac, *cur_item;
2207         GtkWidget *menu;
2208         GtkWidget *menuitem;
2209         PrefsAccount *ac_prefs;
2210
2211         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
2212                                            "/Message/Receive");
2213
2214         /* search for separator */
2215         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2216              cur_item = cur_item->next) {
2217                 if (GTK_BIN(cur_item->data)->child == NULL) {
2218                         cur_item = cur_item->next;
2219                         break;
2220                 }
2221         }
2222
2223         /* destroy all previous menu item */
2224         while (cur_item != NULL) {
2225                 GList *next = cur_item->next;
2226                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2227                 cur_item = next;
2228         }
2229
2230         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2231                 ac_prefs = (PrefsAccount *)cur_ac->data;
2232
2233                 menuitem = gtk_menu_item_new_with_label
2234                         (ac_prefs->account_name ? ac_prefs->account_name
2235                          : _("Untitled"));
2236                 gtk_widget_show(menuitem);
2237                 gtk_menu_append(GTK_MENU(menu), menuitem);
2238                 g_signal_connect(G_OBJECT(menuitem), "activate",
2239                                  G_CALLBACK(account_receive_menu_cb),
2240                                  ac_prefs);
2241         }
2242 }
2243
2244 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
2245                                                        GList *account_list)
2246 {
2247         GList *cur_ac;
2248         GtkWidget *menuitem;
2249         PrefsAccount *ac_prefs;
2250         GtkWidget *menu = NULL;
2251
2252         if (mainwin->toolbar->getall_btn == NULL) /* button doesn't exist */
2253                 return;
2254
2255         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
2256         if (menu)
2257                 gtk_widget_destroy(menu);
2258         menu = gtk_menu_new();
2259
2260         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2261                 ac_prefs = (PrefsAccount *)cur_ac->data;
2262
2263                 menuitem = gtk_menu_item_new_with_label
2264                         (ac_prefs->account_name
2265                          ? ac_prefs->account_name : _("Untitled"));
2266                 gtk_widget_show(menuitem);
2267                 gtk_menu_append(GTK_MENU(menu), menuitem);
2268                 g_signal_connect(G_OBJECT(menuitem), "activate",
2269                                  G_CALLBACK(account_receive_menu_cb),
2270                                  ac_prefs);
2271         }
2272         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
2273 }
2274
2275 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
2276                                                        GList *account_list)
2277 {
2278 #ifndef GENERIC_UMPC
2279         GList *cur_ac;
2280         GtkWidget *menuitem;
2281         PrefsAccount *ac_prefs;
2282         GtkWidget *menu = NULL;
2283
2284         if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
2285                 return;
2286
2287         menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
2288         if (menu)
2289                 gtk_widget_destroy(menu);
2290         menu = gtk_menu_new();
2291
2292         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2293                 ac_prefs = (PrefsAccount *)cur_ac->data;
2294
2295                 menuitem = gtk_menu_item_new_with_label
2296                         (ac_prefs->account_name
2297                          ? ac_prefs->account_name : _("Untitled"));
2298                 gtk_widget_show(menuitem);
2299                 gtk_menu_append(GTK_MENU(menu), menuitem);
2300                 g_signal_connect(G_OBJECT(menuitem), "activate",
2301                                  G_CALLBACK(account_compose_menu_cb),
2302                                  ac_prefs);
2303         }
2304         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
2305 #endif
2306 }
2307
2308 void main_window_set_account_menu(GList *account_list)
2309 {
2310         GList *cur;
2311         MainWindow *mainwin;
2312
2313         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2314                 mainwin = (MainWindow *)cur->data;
2315                 main_window_set_account_selector_menu(mainwin, account_list);
2316                 main_window_set_account_receive_menu(mainwin, account_list);
2317                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2318                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2319         }
2320         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2321 }
2322
2323 void main_window_set_account_menu_only_toolbar(GList *account_list)
2324 {
2325         GList *cur;
2326         MainWindow *mainwin;
2327
2328         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2329                 mainwin = (MainWindow *)cur->data;
2330                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2331                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2332         }
2333 }
2334
2335 static void main_window_show_cur_account(MainWindow *mainwin)
2336 {
2337         gchar *buf;
2338         gchar *ac_name;
2339
2340         ac_name = g_strdup(cur_account
2341                            ? (cur_account->account_name
2342                               ? cur_account->account_name : _("Untitled"))
2343                            : _("none"));
2344
2345         if (cur_account)
2346                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2347         else
2348                 buf = g_strdup(PROG_VERSION);
2349         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2350         g_free(buf);
2351
2352         if (mainwin->ac_label)
2353                 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2354         if (mainwin->ac_button)
2355                 gtk_widget_queue_resize(mainwin->ac_button);
2356
2357         g_free(ac_name);
2358 }
2359 #ifndef GENERIC_UMPC
2360 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2361 {
2362         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2363         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2364         GtkWidget *message_wid = mainwin->messageview->vbox;
2365
2366         if (layout_mode == prefs_common.layout_mode) 
2367                 return;
2368
2369         debug_print("Changing window separation type from %d to %d\n",
2370                     prefs_common.layout_mode, layout_mode);
2371
2372         /* remove widgets from those containers */
2373         gtk_widget_ref(folder_wid);
2374         gtk_widget_ref(summary_wid);
2375         gtk_widget_ref(message_wid);
2376         gtkut_container_remove
2377                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2378         gtkut_container_remove
2379                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2380         gtkut_container_remove
2381                 (GTK_CONTAINER(message_wid->parent), message_wid);
2382
2383         gtk_widget_hide(mainwin->window);
2384         main_window_set_widgets(mainwin, layout_mode);
2385         gtk_widget_show(mainwin->window);
2386
2387         gtk_widget_unref(folder_wid);
2388         gtk_widget_unref(summary_wid);
2389         gtk_widget_unref(message_wid);
2390 }
2391 #endif
2392 void mainwindow_reset_paned(GtkPaned *paned)
2393 {
2394                 gint min, max, mid;
2395
2396                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2397                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2398                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2399                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2400
2401 GTK_EVENTS_FLUSH();
2402                 g_object_get (G_OBJECT(paned),
2403                                 "min-position",
2404                                 &min, NULL);
2405                 g_object_get (G_OBJECT(paned),
2406                                 "max-position",
2407                                 &max, NULL);
2408                 mid = (min+max)/2;
2409                 gtk_paned_set_position(GTK_PANED(paned), mid);
2410 }
2411
2412 static void mainwin_paned_show_first(GtkPaned *paned)
2413 {
2414                 gint max;
2415                 g_object_get (G_OBJECT(paned),
2416                                 "max-position",
2417                                 &max, NULL);
2418
2419                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2420                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2421                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2422                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2423                 gtk_paned_set_position(GTK_PANED(paned), max);
2424 }
2425
2426 static void mainwin_paned_show_last(GtkPaned *paned)
2427 {
2428                 gint min;
2429                 g_object_get (G_OBJECT(paned),
2430                                 "min-position",
2431                                 &min, NULL);
2432
2433                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2434                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2435                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2436                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2437                 gtk_paned_set_position(GTK_PANED(paned), min);
2438 }
2439
2440 void main_window_toggle_message_view(MainWindow *mainwin)
2441 {
2442         SummaryView *summaryview = mainwin->summaryview;
2443         GtkWidget *ppaned = NULL;
2444         GtkWidget *container = NULL;
2445         
2446         switch (prefs_common.layout_mode) {
2447         case NORMAL_LAYOUT:
2448         case VERTICAL_LAYOUT:
2449         case SMALL_LAYOUT:
2450                 ppaned = mainwin->vpaned;
2451                 container = mainwin->hpaned;
2452                 if (ppaned->parent != NULL) {
2453                         mainwin->messageview->visible = FALSE;
2454                         summaryview->displayed = NULL;
2455                         gtk_widget_ref(ppaned);
2456                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2457                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2458                 } else {
2459                         mainwin->messageview->visible = TRUE;
2460                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2461                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2462                         gtk_widget_unref(ppaned);
2463                 }
2464                 break;
2465         case WIDE_LAYOUT:
2466                 ppaned = mainwin->hpaned;
2467                 container = mainwin->vpaned;
2468                 if (mainwin->messageview->vbox->parent != NULL) {
2469                         mainwin->messageview->visible = FALSE;
2470                         summaryview->displayed = NULL;
2471                         gtk_widget_ref(mainwin->messageview->vbox);
2472                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2473                 } else {
2474                         mainwin->messageview->visible = TRUE;
2475                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2476                         gtk_widget_unref(mainwin->messageview->vbox);
2477                 }
2478                 break;
2479         case WIDE_MSGLIST_LAYOUT:
2480                 g_warning("can't hide messageview in this wide msglist layout");
2481                 break;
2482         }
2483
2484         if (messageview_is_visible(mainwin->messageview))
2485                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2486                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2487         else
2488                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2489                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2490
2491         if (mainwin->messageview->visible == FALSE)
2492                 messageview_clear(mainwin->messageview);
2493
2494         main_window_set_menu_sensitive(mainwin);
2495
2496         prefs_common.msgview_visible = mainwin->messageview->visible;
2497
2498         if (messageview_is_visible(mainwin->messageview)) {
2499                 gtk_widget_queue_resize(mainwin->hpaned);
2500                 gtk_widget_queue_resize(mainwin->vpaned);
2501         }
2502         summary_grab_focus(summaryview);
2503         if (!summary_is_list(summaryview)) {
2504                 summary_show(summaryview, summaryview->folder_item);
2505         }
2506 }
2507
2508 void main_window_get_size(MainWindow *mainwin)
2509 {
2510         GtkAllocation *allocation;
2511
2512         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2513                 debug_print("called after messageview "
2514                             "has been deallocated!\n");
2515                 return;
2516         }
2517
2518         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2519
2520         if (allocation->width > 1 && allocation->height > 1) {
2521                 prefs_common.summaryview_width = allocation->width;
2522
2523                 if (messageview_is_visible(mainwin->messageview))
2524                         prefs_common.summaryview_height = allocation->height;
2525
2526                 prefs_common.mainview_width = allocation->width;
2527         }
2528
2529         allocation = &mainwin->window->allocation;
2530         if (allocation->width > 1 && allocation->height > 1 &&
2531             !prefs_common.mainwin_maximised) {
2532                 prefs_common.mainview_height = allocation->height;
2533                 prefs_common.mainwin_width   = allocation->width;
2534                 prefs_common.mainwin_height  = allocation->height;
2535         }
2536
2537         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2538         if (allocation->width > 1 && allocation->height > 1) {
2539                 prefs_common.folderview_width  = allocation->width;
2540                 prefs_common.folderview_height = allocation->height;
2541         }
2542
2543         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2544         if (allocation->width > 1 && allocation->height > 1) {
2545                 prefs_common.msgview_width = allocation->width;
2546                 prefs_common.msgview_height = allocation->height;
2547         }
2548
2549 /*      debug_print("summaryview size: %d x %d\n",
2550                     prefs_common.summaryview_width,
2551                     prefs_common.summaryview_height);
2552         debug_print("folderview size: %d x %d\n",
2553                     prefs_common.folderview_width,
2554                     prefs_common.folderview_height);
2555         debug_print("messageview size: %d x %d\n",
2556                     prefs_common.msgview_width,
2557                     prefs_common.msgview_height); */
2558 }
2559
2560 void main_window_get_position(MainWindow *mainwin)
2561 {
2562         gint x, y;
2563
2564         if (prefs_common.mainwin_maximised)
2565                 return;
2566
2567         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2568
2569         prefs_common.mainview_x = x;
2570         prefs_common.mainview_y = y;
2571         prefs_common.mainwin_x = x;
2572         prefs_common.mainwin_y = y;
2573
2574         debug_print("main window position: %d, %d\n", x, y);
2575 }
2576
2577 void main_window_progress_on(MainWindow *mainwin)
2578 {
2579         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2580 }
2581
2582 void main_window_progress_off(MainWindow *mainwin)
2583 {
2584         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2585         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2586 }
2587
2588 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2589 {
2590         if (confirm && procmsg_have_trashed_mails_fast()) {
2591                 if (alertpanel(_("Empty trash"),
2592                                _("Delete all messages in trash folders?"),
2593                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2594                     != G_ALERTALTERNATE)
2595                         return;
2596                 manage_window_focus_in(mainwin->window, NULL, NULL);
2597         }
2598
2599         procmsg_empty_all_trash();
2600
2601         if (mainwin->summaryview->folder_item &&
2602             mainwin->summaryview->folder_item->stype == F_TRASH)
2603                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2604 }
2605
2606 static void main_window_add_mailbox(MainWindow *mainwin)
2607 {
2608         gchar *path;
2609         Folder *folder;
2610
2611         path = input_dialog(_("Add mailbox"),
2612                             _("Input the location of mailbox.\n"
2613                               "If an existing mailbox is specified, it will be\n"
2614                               "scanned automatically."),
2615                             "Mail");
2616         if (!path) return;
2617         if (folder_find_from_path(path)) {
2618                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2619                 g_free(path);
2620                 return;
2621         }
2622         folder = folder_new(folder_get_class_from_string("mh"), 
2623                             !strcmp(path, "Mail") ? _("Mailbox") : 
2624                             g_path_get_basename(path), path);
2625         g_free(path);
2626
2627         if (folder->klass->create_tree(folder) < 0) {
2628                 alertpanel_error(_("Creation of the mailbox failed.\n"
2629                                    "Maybe some files already exist, or you don't have the permission to write there."));
2630                 folder_destroy(folder);
2631                 return;
2632         }
2633
2634         folder_add(folder);
2635         folder_set_ui_func(folder, scan_tree_func, mainwin);
2636         folder_scan_tree(folder, TRUE);
2637         folder_set_ui_func(folder, NULL, NULL);
2638 }
2639
2640 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2641 {
2642         SensitiveCond state = 0;
2643         SummarySelection selection;
2644         FolderItem *item = mainwin->summaryview->folder_item;
2645         GList *account_list = account_get_list();
2646         GSList *tmp;
2647         
2648         selection = summary_get_selection_type(mainwin->summaryview);
2649
2650         if (mainwin->lock_count == 0 && !claws_is_starting())
2651                 state |= M_UNLOCKED;
2652         if (selection != SUMMARY_NONE)
2653                 state |= M_MSG_EXIST;
2654         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2655                 state |= M_EXEC;
2656                 /*              if (item->folder->type != F_NEWS) */
2657                 state |= M_ALLOW_DELETE;
2658
2659                 if (prefs_common.immediate_exec == 0
2660                     && mainwin->lock_count == 0)
2661                         state |= M_DELAY_EXEC;
2662
2663                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2664                     || selection != SUMMARY_NONE)
2665                         state |= M_HIDE_READ_MSG;
2666         }               
2667         if (mainwin->summaryview->threaded)
2668                 state |= M_THREADED;
2669         else
2670                 state |= M_UNTHREADED;  
2671         if (selection == SUMMARY_SELECTED_SINGLE ||
2672             selection == SUMMARY_SELECTED_MULTIPLE)
2673                 state |= M_TARGET_EXIST;
2674         if (selection == SUMMARY_SELECTED_SINGLE)
2675                 state |= M_SINGLE_TARGET_EXIST;
2676         if (mainwin->summaryview->folder_item &&
2677             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2678                 state |= M_NEWS;
2679         else
2680                 state |= M_NOT_NEWS;
2681         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2682                 state |= M_ACTIONS_EXIST;
2683
2684         tmp = tags_get_list();
2685         if (tmp && g_slist_length(tmp))
2686                 state |= M_TAGS_EXIST;
2687         g_slist_free(tmp);
2688
2689         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2690                 state |= M_HAVE_QUEUED_MAILS;
2691
2692         if (selection == SUMMARY_SELECTED_SINGLE &&
2693             (item &&
2694              (folder_has_parent_of_type(item, F_DRAFT) ||
2695               folder_has_parent_of_type(item, F_OUTBOX) ||
2696               folder_has_parent_of_type(item, F_QUEUE))))
2697                 state |= M_ALLOW_REEDIT;
2698         if (cur_account)
2699                 state |= M_HAVE_ACCOUNT;
2700         
2701         if (any_folder_want_synchronise())
2702                 state |= M_WANT_SYNC;
2703
2704         if (item && item->prefs->processing && selection != SUMMARY_NONE)
2705                 state |= M_HAVE_PROCESSING;
2706
2707         for ( ; account_list != NULL; account_list = account_list->next) {
2708                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2709                         state |= M_HAVE_NEWS_ACCOUNT;
2710                         break;
2711                 }
2712         }
2713         
2714         if (procmsg_spam_can_learn() &&
2715             (mainwin->summaryview->folder_item &&
2716              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2717              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2718                 state |= M_CAN_LEARN_SPAM;
2719         }
2720
2721         if (inc_is_active())
2722                 state |= M_INC_ACTIVE;
2723         if (imap_cancel_all_enabled())
2724                 state |= M_INC_ACTIVE;
2725
2726         if (mainwin->summaryview->deleted > 0 ||
2727             mainwin->summaryview->moved > 0 ||
2728             mainwin->summaryview->copied > 0)
2729                 state |= M_DELAY_EXEC;
2730
2731         if (summary_is_list(mainwin->summaryview))
2732                 state |= M_SUMMARY_ISLIST;
2733
2734         return state;
2735 }
2736
2737
2738
2739 void main_window_set_menu_sensitive(MainWindow *mainwin)
2740 {
2741         GtkItemFactory *ifactory = mainwin->menu_factory;
2742         SensitiveCond state;
2743         gboolean sensitive;
2744         GtkWidget *menu;
2745         GtkWidget *menuitem;
2746         SummaryView *summaryview;
2747         gchar *menu_path;
2748         gint i;
2749         GList *cur_item;
2750
2751         static const struct {
2752                 gchar *const entry;
2753                 SensitiveCond cond;
2754         } entry[] = {
2755                 {"/File/Save as...", M_TARGET_EXIST},
2756                 {"/File/Print..."  , M_TARGET_EXIST},
2757                 {"/File/Synchronise folders", M_WANT_SYNC},
2758                 {"/File/Exit"      , M_UNLOCKED},
2759
2760                 {"/Edit/Select thread"             , M_TARGET_EXIST|M_SUMMARY_ISLIST},
2761                 {"/Edit/Delete thread"             , M_TARGET_EXIST|M_SUMMARY_ISLIST},
2762                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2763
2764                 {"/View/Set displayed columns/in Folder list..."
2765                                                    , M_UNLOCKED|M_SUMMARY_ISLIST}, 
2766                 {"/View/Sort"                      , M_EXEC|M_SUMMARY_ISLIST},
2767                 {"/View/Thread view"               , M_EXEC|M_SUMMARY_ISLIST},
2768                 {"/View/Expand all threads"        , M_MSG_EXIST|M_SUMMARY_ISLIST},
2769                 {"/View/Collapse all threads"      , M_MSG_EXIST|M_SUMMARY_ISLIST},
2770                 {"/View/Hide read messages"        , M_HIDE_READ_MSG|M_SUMMARY_ISLIST},
2771                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2772                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2773                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2774                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2775                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2776                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2777                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2778                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2779                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2780                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2781                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2782                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2783                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2784
2785                 {"/Message/Receive/Get from current account"
2786                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2787                 {"/Message/Receive/Get from all accounts"
2788                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2789                 {"/Message/Receive/Cancel receiving"
2790                                                  , M_INC_ACTIVE},
2791                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2792                 {"/Message/Compose an email message", M_HAVE_ACCOUNT},
2793                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2794                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
2795                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
2796                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS|M_SUMMARY_ISLIST},
2797                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
2798                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
2799                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
2800                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2801                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2802                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2803                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2804                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2805                 {"/Message/Mark"                  , M_TARGET_EXIST|M_SUMMARY_ISLIST},
2806                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2807                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2808                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2809                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2810                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2811                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2812                 {"/Message/Color label"           , M_TARGET_EXIST},
2813                 {"/Message/Tags"                  , M_TARGET_EXIST},
2814                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2815
2816                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2817                 {"/Tools/Harvest addresses"            , M_MSG_EXIST|M_SUMMARY_ISLIST},
2818                 {"/Tools/Harvest addresses/from Messages..."
2819                                                        , M_TARGET_EXIST},
2820                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2821                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2822                 {"/Tools/Run folder processing rules"  , M_HAVE_PROCESSING},
2823                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2824                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2825                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2826                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2827                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2828                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2829
2830                 {"/Configuration", M_UNLOCKED},
2831                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2832                 {"/Configuration/Create new account...", M_UNLOCKED},
2833                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2834
2835                 {NULL, 0}
2836         };
2837
2838         state = main_window_get_current_state(mainwin);
2839
2840         for (i = 0; entry[i].entry != NULL; i++) {
2841                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2842                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2843         }
2844
2845         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2846
2847         /* search for separator */
2848         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2849              cur_item = cur_item->next) {
2850                 if (GTK_BIN(cur_item->data)->child == NULL) {
2851                         cur_item = cur_item->next;
2852                         break;
2853                 }
2854         }
2855
2856         for (; cur_item != NULL; cur_item = cur_item->next) {
2857                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2858                                          (M_UNLOCKED & state) != 0);
2859         }
2860
2861         main_window_menu_callback_block(mainwin);
2862
2863 #define SET_CHECK_MENU_ACTIVE(path, active) \
2864 { \
2865         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2866         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2867 }
2868
2869         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2870                               messageview_is_visible(mainwin->messageview));
2871
2872         summaryview = mainwin->summaryview;
2873         menu_path = "/View/Sort/Don't sort";
2874
2875         switch (summaryview->sort_key) {
2876         case SORT_BY_NUMBER:
2877                 menu_path = "/View/Sort/by number"; break;
2878         case SORT_BY_SIZE:
2879                 menu_path = "/View/Sort/by Size"; break;
2880         case SORT_BY_DATE:
2881                 menu_path = "/View/Sort/by Date"; break;
2882         case SORT_BY_THREAD_DATE:
2883                 menu_path = "/View/Sort/by Thread date"; break;
2884         case SORT_BY_FROM:
2885                 menu_path = "/View/Sort/by From"; break;
2886         case SORT_BY_TO:
2887                 menu_path = "/View/Sort/by To"; break;
2888         case SORT_BY_SUBJECT:
2889                 menu_path = "/View/Sort/by Subject"; break;
2890         case SORT_BY_LABEL:
2891                 menu_path = "/View/Sort/by color label"; break;
2892         case SORT_BY_MARK:
2893                 menu_path = "/View/Sort/by mark"; break;
2894         case SORT_BY_STATUS:
2895                 menu_path = "/View/Sort/by status"; break;
2896         case SORT_BY_MIME:
2897                 menu_path = "/View/Sort/by attachment"; break;
2898         case SORT_BY_SCORE:
2899                 menu_path = "/View/Sort/by score"; break;
2900         case SORT_BY_LOCKED:
2901                 menu_path = "/View/Sort/by locked"; break;
2902         case SORT_BY_TAGS:
2903                 menu_path = "/View/Sort/by tag"; break;
2904         case SORT_BY_NONE:
2905         default:
2906                 menu_path = "/View/Sort/Don't sort"; break;
2907         }
2908         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2909
2910         if (summaryview->sort_type == SORT_ASCENDING) {
2911                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2912         } else {
2913                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2914         }
2915
2916         if (summaryview->sort_key != SORT_BY_NONE) {
2917                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2918                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2919         } else {
2920                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2921                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2922         }
2923
2924         if (mainwin->messageview 
2925         &&  mainwin->messageview->mimeview
2926         &&  mainwin->messageview->mimeview->textview)
2927                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2928                               mainwin->messageview->mimeview->textview->show_all_headers);
2929         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2930         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2931         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2932         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2933         if (prefs_common.hide_quotes == 1)
2934                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2935         if (prefs_common.hide_quotes == 2)
2936                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2937         if (prefs_common.hide_quotes == 3)
2938                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2939
2940 #undef SET_CHECK_MENU_ACTIVE
2941
2942         main_window_menu_callback_unblock(mainwin);
2943 }
2944
2945 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2946 {
2947         GtkItemFactory *ifactory;
2948         gint is_menu = 0;
2949         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2950         
2951         if (msginfo) 
2952                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2953         if (is_menu)
2954                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2955                                 (ifactory,"/Message/Mailing-List"), TRUE);
2956         else
2957                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2958                                 (ifactory,"/Message/Mailing-List"), FALSE);
2959 }
2960
2961 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2962 {
2963         gint menu_nb = 0;
2964         GtkWidget *menuitem;
2965         
2966         if (!msginfo || !msginfo->extradata) {
2967                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2968                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2969                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2970                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2971                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2972                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2973                 return 0;
2974         }
2975                 
2976         /* Mailing list post */
2977         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2978                 g_free(msginfo->extradata->list_post);
2979                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2980         }
2981         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2982                 
2983         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2984  
2985         /* Mailing list help */
2986         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2987         
2988         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2989
2990         /* Mailing list subscribe */
2991         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2992         
2993         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2994                 
2995         /* Mailing list unsubscribe */
2996         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2997         
2998         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2999         
3000         /* Mailing list view archive */
3001         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
3002         
3003         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
3004         
3005         /* Mailing list contact owner */
3006         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
3007         
3008         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
3009         
3010         return menu_nb;
3011 }
3012
3013 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
3014 {
3015         GtkWidget *item, *menu;
3016         const gchar *url_pt ;
3017         gchar url_decoded[BUFFSIZE];
3018         GList *amenu, *alist;
3019         gint menu_nb = 0;
3020         
3021         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
3022         
3023         /* First delete old submenu */
3024         /* FIXME: we can optimize this, and only change/add/delete necessary items */
3025         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
3026                 alist = amenu->next;
3027                 item = GTK_WIDGET (amenu->data);
3028                 gtk_widget_destroy (item);
3029                 amenu = alist;
3030         }
3031         if (list_header) {
3032                 for (url_pt = list_header; url_pt && *url_pt;) {
3033                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
3034                         item = NULL;
3035                         if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
3036                                 item = gtk_menu_item_new_with_label ((url_decoded));
3037                                 g_signal_connect(G_OBJECT(item), "activate",
3038                                                  G_CALLBACK(mailing_list_compose),
3039                                                  NULL);
3040                         }
3041                         else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
3042                                  !g_ascii_strncasecmp(url_decoded, "https:",6)) {
3043
3044                                 item = gtk_menu_item_new_with_label ((url_decoded));
3045                                 g_signal_connect(G_OBJECT(item), "activate",
3046                                                  G_CALLBACK(mailing_list_open_uri),
3047                                                  NULL);
3048                         } 
3049                         if (item) {
3050                                 gtk_menu_append (GTK_MENU(menu), item);
3051                                 gtk_widget_show (item);
3052                                 menu_nb++;
3053                         }
3054                 }
3055         }
3056         if (menu_nb)
3057                 gtk_widget_set_sensitive (menuitem, TRUE);
3058         else
3059                 gtk_widget_set_sensitive (menuitem, FALSE);
3060                 
3061
3062         return menu_nb;
3063 }
3064
3065 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
3066 {
3067         gchar tmp[BUFFSIZE];
3068         const gchar *buf;
3069         gint i = 0;
3070         buf = *buffer;
3071         gboolean with_plus = TRUE;
3072
3073         if (buf == 0x00) {
3074                 *url_decoded = '\0';
3075                 *buffer = NULL;
3076                 return;
3077         }
3078         /* Ignore spaces, comments  and tabs () */
3079         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
3080                 if (*buf == '(')
3081                         for (;*buf != ')' && *buf != 0x00; buf++);
3082         
3083         /* First non space and non comment must be a < */
3084         if (*buf =='<' ) {
3085                 buf++;
3086                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
3087                         with_plus = FALSE;
3088                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
3089                 buf++;
3090         }
3091         else  {
3092                 *buffer = NULL;
3093                 *url_decoded = '\0';
3094                 return;
3095         }
3096         
3097         tmp[i]       = 0x00;
3098         *url_decoded = '\0';
3099         *buffer = NULL;
3100         
3101         if (i == maxlen) {
3102                 return;
3103         }
3104         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
3105
3106         /* Prepare the work for the next url in the list */
3107         /* after the closing bracket >, ignore space, comments and tabs */
3108         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
3109                 if (*buf == '(')
3110                         for (;*buf != ')' && *buf != 0x00; buf++);
3111                         
3112         if (!buf || !*buf) {
3113                 *buffer = NULL;
3114                 return;
3115         }
3116
3117         /* now first non space, non comment must be a comma */
3118         if (*buf != ',')
3119                 for (;*buf != 0x00; buf++);
3120         else
3121                 buf++;
3122         *buffer = buf;
3123 }
3124         
3125 static void mailing_list_compose (GtkWidget *w, gpointer *data)
3126 {
3127         gchar *mailto;
3128
3129         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
3130         compose_new(NULL, mailto+7, NULL);
3131 }
3132  
3133  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
3134 {
3135  
3136         gchar *mailto;
3137  
3138         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
3139         open_uri (mailto, prefs_common_get_uri_cmd());
3140
3141         
3142 void main_window_popup(MainWindow *mainwin)
3143 {
3144         static gboolean first_start = TRUE;
3145
3146         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
3147                 main_window_show(mainwin);
3148
3149         if (prefs_common.mainwin_maximised)
3150                 gtk_window_maximize(GTK_WINDOW(mainwin->window));
3151
3152         if (first_start) {
3153                 gtk_window_deiconify(GTK_WINDOW(mainwin->window));
3154                 first_start = FALSE;
3155         } else {
3156                 gtkut_window_popup(mainwin->window);
3157         }
3158         if (prefs_common.layout_mode == SMALL_LAYOUT) {
3159                 if (mainwin->in_folder) {
3160                         mainwindow_enter_folder(mainwin);
3161                 } else {
3162                         mainwindow_exit_folder(mainwin);
3163                 }
3164         }
3165 }
3166
3167 void main_window_show(MainWindow *mainwin)
3168 {
3169         gtk_widget_show(mainwin->window);
3170         gtk_widget_show(mainwin->vbox_body);
3171 #ifndef GENERIC_UMPC
3172         gtk_widget_set_uposition(mainwin->window,
3173                                  prefs_common.mainwin_x,
3174                                  prefs_common.mainwin_y);
3175
3176         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3177                              prefs_common.folderview_width,
3178                              prefs_common.folderview_height);
3179         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3180                              prefs_common.summaryview_width,
3181                              prefs_common.summaryview_height);
3182         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3183                              prefs_common.msgview_width,
3184                              prefs_common.msgview_height);
3185 #endif
3186 }
3187
3188 void main_window_hide(MainWindow *mainwin)
3189 {
3190         main_window_get_size(mainwin);
3191         main_window_get_position(mainwin);
3192
3193         gtk_widget_hide(mainwin->window);
3194         gtk_widget_hide(mainwin->vbox_body);
3195 }
3196
3197 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
3198 {
3199         GtkWidget *folderwin = NULL;
3200         GtkWidget *messagewin = NULL;
3201         GtkWidget *hpaned;
3202         GtkWidget *vpaned;
3203         GtkWidget *vbox_body = mainwin->vbox_body;
3204         GtkItemFactory *ifactory = mainwin->menu_factory;
3205         GtkWidget *menuitem;
3206         gboolean first_set = (mainwin->hpaned == NULL);
3207         debug_print("Setting widgets... ");
3208
3209         if (layout_mode == SMALL_LAYOUT && first_set) {
3210                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3211                                     prefs_common.folderview_width,
3212                                     prefs_common.folderview_height);
3213                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3214                                     0,0);
3215                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3216                                     0,0);
3217         } else {
3218                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3219                                     prefs_common.folderview_width,
3220                                     prefs_common.folderview_height);
3221                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3222                                     prefs_common.summaryview_width,
3223                                     prefs_common.summaryview_height);
3224                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3225                                     prefs_common.msgview_width,
3226                                     prefs_common.msgview_height);
3227         }
3228
3229 #ifndef GENERIC_UMPC
3230         mainwin->messageview->statusbar = mainwin->statusbar;
3231         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3232 #endif
3233         /* clean top-most container */
3234         if (mainwin->hpaned) {
3235                 if (mainwin->hpaned->parent == mainwin->vpaned)
3236                         gtk_widget_destroy(mainwin->vpaned);
3237                 else
3238                         gtk_widget_destroy(mainwin->hpaned);
3239         }
3240
3241         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
3242                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
3243         switch (layout_mode) {
3244         case VERTICAL_LAYOUT:
3245         case NORMAL_LAYOUT:
3246         case SMALL_LAYOUT:
3247                 hpaned = gtk_hpaned_new();
3248                 if (layout_mode == VERTICAL_LAYOUT)
3249                         vpaned = gtk_hpaned_new();
3250                 else
3251                         vpaned = gtk_vpaned_new();
3252                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
3253                 gtk_paned_add1(GTK_PANED(hpaned),
3254                                GTK_WIDGET_PTR(mainwin->folderview));
3255                 gtk_widget_show(hpaned);
3256                 gtk_widget_queue_resize(hpaned);
3257
3258                 if (messageview_is_visible(mainwin->messageview)) {
3259                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
3260                         gtk_paned_add1(GTK_PANED(vpaned),
3261                                        GTK_WIDGET_PTR(mainwin->summaryview));
3262                 } else {
3263                         gtk_paned_add2(GTK_PANED(hpaned),
3264                                        GTK_WIDGET_PTR(mainwin->summaryview));
3265                         gtk_widget_ref(vpaned);
3266                 }
3267                 gtk_paned_add2(GTK_PANED(vpaned),
3268                                GTK_WIDGET_PTR(mainwin->messageview));
3269                 gtk_widget_show(vpaned);
3270                 if (layout_mode == SMALL_LAYOUT && first_set) {
3271                         mainwin_paned_show_first(GTK_PANED(hpaned));
3272                 }
3273                 gtk_widget_queue_resize(vpaned);
3274                 break;
3275         case WIDE_LAYOUT:
3276                 vpaned = gtk_vpaned_new();
3277                 hpaned = gtk_hpaned_new();
3278                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3279                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
3280
3281                 gtk_paned_add1(GTK_PANED(hpaned),
3282                                GTK_WIDGET_PTR(mainwin->folderview));
3283                 gtk_paned_add2(GTK_PANED(hpaned),
3284                                GTK_WIDGET_PTR(mainwin->summaryview));
3285
3286                 gtk_widget_show(hpaned);
3287                 gtk_widget_queue_resize(hpaned);
3288
3289                 if (messageview_is_visible(mainwin->messageview)) {
3290                         gtk_paned_add2(GTK_PANED(vpaned),
3291                                GTK_WIDGET_PTR(mainwin->messageview));   
3292                 } else {
3293                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3294                 }
3295                 gtk_widget_show(vpaned);
3296                 gtk_widget_queue_resize(vpaned);
3297                 break;
3298         case WIDE_MSGLIST_LAYOUT:
3299                 vpaned = gtk_vpaned_new();
3300                 hpaned = gtk_hpaned_new();
3301                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3302
3303                 gtk_paned_add1(GTK_PANED(vpaned),
3304                                GTK_WIDGET_PTR(mainwin->summaryview));
3305                 gtk_paned_add1(GTK_PANED(hpaned),
3306                                GTK_WIDGET_PTR(mainwin->folderview));
3307
3308                 gtk_widget_show(hpaned);
3309                 gtk_widget_queue_resize(hpaned);
3310
3311                 if (messageview_is_visible(mainwin->messageview)) {
3312                         gtk_paned_add2(GTK_PANED(hpaned),
3313                                GTK_WIDGET_PTR(mainwin->messageview));   
3314                 } else {
3315                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3316                 }
3317                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3318
3319                 gtk_widget_show(vpaned);
3320                 gtk_widget_queue_resize(vpaned);
3321                 break;
3322         default:
3323                 g_warning("Unknown layout");
3324                 return;
3325         }
3326
3327         mainwin->hpaned = hpaned;
3328         mainwin->vpaned = vpaned;
3329
3330         if (layout_mode == SMALL_LAYOUT) {
3331                 if (mainwin->messageview->visible)
3332                         main_window_toggle_message_view(mainwin);
3333         } 
3334
3335         if (layout_mode == SMALL_LAYOUT && first_set) {
3336                 gtk_widget_realize(mainwin->window);
3337                 gtk_widget_realize(mainwin->folderview->ctree);
3338                 gtk_widget_realize(mainwin->summaryview->hbox);
3339                 gtk_widget_realize(mainwin->summaryview->hbox_l);
3340                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3341                                     prefs_common.folderview_width,
3342                                     prefs_common.folderview_height);
3343                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3344                                     0,0);
3345                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3346                                     0,0);
3347                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3348                                 prefs_common.mainwin_width,
3349                                 prefs_common.mainwin_height);
3350                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3351         } 
3352         /* remove headerview if not in prefs */
3353         headerview_set_visibility(mainwin->messageview->headerview,
3354                                   prefs_common.display_header_pane);
3355
3356         if (messageview_is_visible(mainwin->messageview))
3357                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3358                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3359         else
3360                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3361                               GTK_ARROW_UP, GTK_SHADOW_OUT);
3362
3363         gtk_window_move(GTK_WINDOW(mainwin->window),
3364                         prefs_common.mainwin_x,
3365                         prefs_common.mainwin_y);
3366
3367         gtk_widget_queue_resize(vbox_body);
3368         gtk_widget_queue_resize(mainwin->vbox);
3369         gtk_widget_queue_resize(mainwin->window);
3370         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3371          * and mimeview icon list/ctree lose track of their visibility states */
3372         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
3373                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3374         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
3375                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3376         if (mainwin->messageview->mimeview->ctree_mode)
3377                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3378         else 
3379                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3380
3381         prefs_common.layout_mode = layout_mode;
3382
3383         menuitem = gtk_item_factory_get_item
3384                 (ifactory, "/View/Show or hide/Message view");
3385         gtk_check_menu_item_set_active
3386                 (GTK_CHECK_MENU_ITEM(menuitem),
3387                  messageview_is_visible(mainwin->messageview));
3388
3389 #define SET_CHECK_MENU_ACTIVE(path, active) \
3390 { \
3391         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3392         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3393 }
3394
3395 #ifndef GENERIC_UMPC
3396         switch (prefs_common.layout_mode) {
3397         case NORMAL_LAYOUT:
3398                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3399                 break;
3400         case VERTICAL_LAYOUT:
3401                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3402                 break;
3403         case WIDE_LAYOUT:
3404                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3405                 break;
3406         case WIDE_MSGLIST_LAYOUT:
3407                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3408                 break;
3409         case SMALL_LAYOUT:
3410                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3411                 break;
3412         }
3413 #endif
3414 #undef SET_CHECK_MENU_ACTIVE
3415
3416         if (folderwin) {
3417                 g_signal_connect
3418                         (G_OBJECT(folderwin), "size_allocate",
3419                          G_CALLBACK(folder_window_size_allocate_cb),
3420                          mainwin);
3421         }
3422         if (messagewin) {
3423                 g_signal_connect
3424                         (G_OBJECT(messagewin), "size_allocate",
3425                          G_CALLBACK(message_window_size_allocate_cb),
3426                          mainwin);
3427         }
3428
3429         debug_print("done.\n");
3430 }
3431
3432 void main_window_destroy_all(void)
3433 {
3434         while (mainwin_list != NULL) {
3435                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3436                 
3437                 /* free toolbar stuff */
3438                 toolbar_clear_list(TOOLBAR_MAIN);
3439                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3440                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3441
3442                 summaryview_destroy(mainwin->summaryview);
3443                 mainwin->folderview->mainwin = NULL;
3444                 mainwin->summaryview->mainwin = NULL;
3445                 mainwin->messageview->mainwin = NULL;
3446
3447                 g_free(mainwin->toolbar);
3448                 g_free(mainwin);
3449                 
3450                 mainwin_list = g_list_remove(mainwin_list, mainwin);
3451         }
3452         g_list_free(mainwin_list);
3453         mainwin_list = NULL;
3454 }
3455
3456 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3457                                    gpointer data)
3458 {
3459         gtk_widget_set_size_request(child, 1, -1);
3460 }
3461
3462 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3463                                    gpointer data)
3464 {
3465         gtk_widget_set_size_request(child, -1, -1);
3466 }
3467 #ifndef GENERIC_UMPC
3468 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3469                                     gpointer data)
3470 {
3471         MainWindow *mainwin = (MainWindow *)data;
3472
3473         if (!event) return FALSE;
3474
3475         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3476         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3477                           widget);
3478
3479         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3480                        menu_button_position, widget,
3481                        event->button, event->time);
3482
3483         return TRUE;
3484 }
3485 #endif
3486 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3487                                  gpointer data)
3488 {
3489         MainWindow *mainwin = (MainWindow *)data;
3490         gboolean close_allowed = TRUE;
3491
3492         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3493
3494         if (close_allowed && mainwin->lock_count == 0)
3495                 app_exit_cb(data, 0, widget);
3496
3497         return TRUE;
3498 }
3499
3500 static void main_window_size_allocate_cb(GtkWidget *widget,
3501                                          GtkAllocation *allocation,
3502                                          gpointer data)
3503 {
3504         MainWindow *mainwin = (MainWindow *)data;
3505         main_window_get_size(mainwin);
3506 }
3507
3508 static void folder_window_size_allocate_cb(GtkWidget *widget,
3509                                            GtkAllocation *allocation,
3510                                            gpointer data)
3511 {
3512         MainWindow *mainwin = (MainWindow *)data;
3513
3514         main_window_get_size(mainwin);
3515 }
3516
3517 static void message_window_size_allocate_cb(GtkWidget *widget,
3518                                             GtkAllocation *allocation,
3519                                             gpointer data)
3520 {
3521         MainWindow *mainwin = (MainWindow *)data;
3522
3523         main_window_get_size(mainwin);
3524 }
3525
3526 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3527                            GtkWidget *widget)
3528 {
3529         main_window_add_mailbox(mainwin);
3530 }
3531
3532 static void update_folderview_cb(MainWindow *mainwin, guint action,
3533                                  GtkWidget *widget)
3534 {
3535         summary_show(mainwin->summaryview, NULL);
3536         folderview_check_new_all();
3537 }
3538
3539 static void foldersort_cb(MainWindow *mainwin, guint action,
3540                            GtkWidget *widget)
3541 {
3542         foldersort_open();
3543 }
3544
3545 static void import_mbox_cb(MainWindow *mainwin, guint action,
3546                            GtkWidget *widget)
3547 {
3548         /* only notify if import has failed */
3549         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3550                 alertpanel_error(_("Mbox import has failed."));
3551         }
3552 }
3553
3554 static void export_mbox_cb(MainWindow *mainwin, guint action,
3555                            GtkWidget *widget)
3556 {
3557         /* only notify if export has failed */
3558         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3559                 alertpanel_error(_("Export to mbox has failed."));
3560         }
3561 }
3562
3563 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3564                                 GtkWidget *widget)
3565 {
3566         /* only notify if export has failed */
3567         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3568                 alertpanel_error(_("Export to mbox has failed."));
3569         }
3570 }
3571
3572 static void empty_trash_cb(MainWindow *mainwin, guint action,
3573                            GtkWidget *widget)
3574 {
3575         main_window_empty_trash(mainwin, TRUE);
3576 }
3577
3578 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3579 {
3580         summary_save_as(mainwin->summaryview);
3581 }
3582
3583 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3584 {
3585         summary_print(mainwin->summaryview);
3586 }
3587
3588 #if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
3589 static void page_setup_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3590 {
3591         MainWindow *mainwindow;
3592         GtkWindow *win;
3593
3594         mainwindow = mainwindow_get_mainwindow();
3595         win = (mainwindow ? GTK_WINDOW(mainwindow->window) : NULL);
3596
3597         printing_page_setup(win);
3598 }
3599 #endif
3600
3601 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3602 {
3603         if (prefs_common.confirm_on_exit) {
3604                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3605                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3606                     != G_ALERTALTERNATE)
3607                         return;
3608                 manage_window_focus_in(mainwin->window, NULL, NULL);
3609         }
3610
3611         app_will_exit(widget, mainwin);
3612 }
3613
3614 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3615 {
3616         if (action == 1)
3617                 summary_search(mainwin->summaryview);
3618         else
3619                 message_search(mainwin->messageview);
3620 }
3621
3622 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3623 {
3624         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3625 }
3626
3627 static void toggle_message_cb(MainWindow *mainwin, guint action,
3628                               GtkWidget *widget)
3629 {
3630         gboolean active;
3631
3632         active = GTK_CHECK_MENU_ITEM(widget)->active;
3633
3634         if (active != messageview_is_visible(mainwin->messageview))
3635                 summary_toggle_view(mainwin->summaryview);
3636 }
3637
3638 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3639                               GtkWidget *widget)
3640 {
3641         toolbar_toggle(action, mainwin);
3642 }
3643
3644 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3645                           GtkWidget *widget)
3646 {
3647         MessageView *msgview = (MessageView*)mainwin->messageview;
3648         GSList *msginfo_list = NULL;
3649
3650         g_return_if_fail(msgview != NULL);
3651
3652         msginfo_list = summary_get_selection(mainwin->summaryview);
3653         g_return_if_fail(msginfo_list != NULL);
3654         compose_reply_from_messageview(msgview, msginfo_list, action);
3655         g_slist_free(msginfo_list);
3656 }
3657
3658 static void toggle_col_headers_cb(MainWindow *mainwin, guint action,
3659                                 GtkWidget *widget)
3660 {
3661         FolderView *folderview = mainwin->folderview;
3662         SummaryView *summaryview = mainwin->summaryview;
3663
3664         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3665                 gtk_clist_column_titles_show(GTK_CLIST(folderview->ctree));
3666                 gtk_clist_column_titles_show(GTK_CLIST(summaryview->ctree));
3667                 prefs_common.show_col_headers = TRUE;
3668         } else {
3669                 gtk_clist_column_titles_hide(GTK_CLIST(folderview->ctree));
3670                 gtk_clist_column_titles_hide(GTK_CLIST(summaryview->ctree));
3671                 prefs_common.show_col_headers = FALSE;
3672         }
3673 }
3674
3675 #ifndef GENERIC_UMPC
3676 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3677                                 GtkWidget *widget)
3678 {
3679         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3680                 gtk_widget_show(mainwin->hbox_stat);
3681                 prefs_common.show_statusbar = TRUE;
3682         } else {
3683                 gtk_widget_hide(mainwin->hbox_stat);
3684                 prefs_common.show_statusbar = FALSE;
3685         }
3686 }
3687
3688 static void set_layout_cb(MainWindow *mainwin, guint action,
3689                                GtkWidget *widget)
3690 {
3691         LayoutType layout_mode = action;
3692         LayoutType old_layout_mode = prefs_common.layout_mode;
3693         if (mainwin->menu_lock_count) {
3694                 return;
3695         }
3696         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3697                 return;
3698         }
3699         
3700         if (layout_mode == prefs_common.layout_mode) {
3701                 return;
3702         }
3703         
3704         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3705                 main_window_toggle_message_view(mainwin);
3706         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3707                 main_window_toggle_message_view(mainwin);
3708
3709         main_window_separation_change(mainwin, layout_mode);
3710         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3711         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3712                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3713         }
3714         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3715                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3716                 mainwindow_exit_folder(mainwin);
3717         }
3718         summary_relayout(mainwin->summaryview); 
3719         summary_update_unread(mainwin->summaryview, NULL);
3720 }
3721 #endif
3722
3723 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3724                                         gboolean ask_sync)
3725 {
3726         offline_ask_sync = ask_sync;
3727         if (offline)
3728                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3729         else
3730                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3731         offline_ask_sync = TRUE;
3732 }
3733
3734 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3735 {
3736         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3737 }
3738
3739 static gboolean any_folder_want_synchronise(void)
3740 {
3741         GList *folderlist = folder_get_list();
3742
3743         /* see if there are synchronised folders */
3744         for (; folderlist; folderlist = folderlist->next) {
3745                 Folder *folder = (Folder *)folderlist->data;
3746                 if (folder_want_synchronise(folder)) {
3747                         return TRUE;
3748                 }
3749         }
3750         
3751         return FALSE;
3752 }
3753
3754 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3755 {
3756         
3757         if (!any_folder_want_synchronise())
3758                 return;
3759
3760         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3761                         _("Do you want to synchronise your folders now?"),
3762                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3763                 return;
3764         
3765         if (offline_ask_sync)
3766                 folder_synchronise(NULL);
3767 }
3768
3769 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3770 {
3771         MainWindow *mainwin;
3772         GtkItemFactory *ifactory;
3773         GtkCheckMenuItem *menuitem;
3774         gboolean have_connectivity;
3775
3776 #ifdef HAVE_NETWORKMANAGER
3777         have_connectivity = networkmanager_is_online(NULL); 
3778 #else
3779         have_connectivity = TRUE;
3780 #endif
3781
3782         mainwin = (MainWindow *) data;
3783         
3784         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3785         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3786         
3787         g_return_if_fail(mainwin != NULL);
3788         g_return_if_fail(menuitem != NULL);
3789         
3790         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3791 #ifndef GENERIC_UMPC
3792                 gtk_widget_hide (mainwin->online_switch);
3793                 gtk_widget_show (mainwin->offline_switch);
3794 #endif
3795                 menuitem->active = TRUE;
3796                 inc_autocheck_timer_remove();
3797                         
3798                 /* go offline */
3799                 if (prefs_common.work_offline)
3800                         return;
3801
3802                 if(have_connectivity)
3803                         mainwindow_check_synchronise(mainwin, TRUE);
3804                 prefs_common.work_offline = TRUE;
3805                 imap_disconnect_all();
3806                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3807         } else {
3808                 /*go online */
3809                 if (!prefs_common.work_offline)
3810                         return;
3811 #ifndef GENERIC_UMPC
3812                 gtk_widget_hide (mainwin->offline_switch);
3813                 gtk_widget_show (mainwin->online_switch);
3814 #endif
3815                 menuitem->active = FALSE;
3816                 prefs_common.work_offline = FALSE;
3817                 inc_autocheck_timer_set();
3818                 refresh_resolvers();
3819                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3820         }
3821 }
3822
3823 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3824                                 GtkWidget *widget)
3825 {
3826         addressbook_open(NULL);
3827 }
3828
3829 static void log_window_show_cb(MainWindow *mainwin, guint action,
3830                                GtkWidget *widget)
3831 {
3832         log_window_show(mainwin->logwin);
3833 }
3834
3835 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3836                                GtkWidget *widget)
3837 {
3838         log_window_show(mainwin->filtering_debugwin);
3839 }
3840
3841 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3842 {
3843         inc_cancel_all();
3844         imap_cancel_all();
3845 }
3846
3847 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3848 {
3849         summary_move_to(mainwin->summaryview);
3850 }
3851
3852 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3853 {
3854         summary_copy_to(mainwin->summaryview);
3855 }
3856
3857 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3858 {
3859         summary_delete(mainwin->summaryview);
3860 }
3861
3862 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3863 {
3864         summary_delete_trash(mainwin->summaryview);
3865 }
3866
3867 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3868 {
3869         summary_cancel(mainwin->summaryview);
3870 }
3871
3872 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3873 {
3874         summary_open_msg(mainwin->summaryview);
3875 }
3876
3877 static void view_source_cb(MainWindow *mainwin, guint action,
3878                            GtkWidget *widget)
3879 {
3880         summary_view_source(mainwin->summaryview);
3881 }
3882
3883 static void show_all_header_cb(MainWindow *mainwin, guint action,
3884                                GtkWidget *widget)
3885 {
3886         if (mainwin->menu_lock_count) return;
3887         mainwin->summaryview->messageview->all_headers = 
3888                         GTK_CHECK_MENU_ITEM(widget)->active;
3889         summary_display_msg_selected(mainwin->summaryview,
3890                                      GTK_CHECK_MENU_ITEM(widget)->active);
3891 }
3892
3893 #define SET_CHECK_MENU_ACTIVE(path, active) \
3894 { \
3895         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3896         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3897 }
3898
3899 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3900                                GtkWidget *widget)
3901 {
3902         GtkWidget *menuitem;
3903         GtkItemFactory *ifactory = mainwin->menu_factory;
3904
3905         if (mainwin->menu_lock_count) return;
3906
3907         prefs_common.hide_quotes = 
3908                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3909
3910         mainwin->menu_lock_count++;
3911         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3912         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3913         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3914         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3915         mainwin->menu_lock_count--;
3916
3917         summary_redisplay_msg(mainwin->summaryview);
3918 }
3919
3920 #undef SET_CHECK_MENU_ACTIVE
3921 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3922 {
3923         summary_mark(mainwin->summaryview);
3924 }
3925
3926 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3927 {
3928         summary_unmark(mainwin->summaryview);
3929 }
3930
3931 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3932                               GtkWidget *widget)
3933 {
3934         summary_mark_as_unread(mainwin->summaryview);
3935 }
3936
3937 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3938                             GtkWidget *widget)
3939 {
3940         summary_mark_as_read(mainwin->summaryview);
3941 }
3942
3943 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3944                              GtkWidget *widget)
3945 {
3946         summary_mark_all_read(mainwin->summaryview);
3947 }
3948
3949 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3950                              GtkWidget *widget)
3951 {
3952         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3953 }
3954
3955 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3956                             GtkWidget *widget)
3957 {
3958         summary_ignore_thread(mainwin->summaryview);
3959 }
3960
3961 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3962                             GtkWidget *widget)
3963 {
3964         summary_unignore_thread(mainwin->summaryview);
3965 }
3966
3967 static void watch_thread_cb(MainWindow *mainwin, guint action,
3968                             GtkWidget *widget)
3969 {
3970         summary_watch_thread(mainwin->summaryview);
3971 }
3972
3973 static void unwatch_thread_cb(MainWindow *mainwin, guint action,
3974                             GtkWidget *widget)
3975 {
3976         summary_unwatch_thread(mainwin->summaryview);
3977 }
3978
3979 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3980                             GtkWidget *widget)
3981 {
3982         summary_msgs_lock(mainwin->summaryview);
3983 }
3984
3985 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3986                             GtkWidget *widget)
3987 {
3988         summary_msgs_unlock(mainwin->summaryview);
3989 }
3990
3991
3992 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3993 {
3994         summary_reedit(mainwin->summaryview);
3995 }
3996
3997 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3998 {
3999         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
4000                 summary_display_msg_selected(mainwin->summaryview, 
4001                         mainwin->messageview->mimeview->textview->show_all_headers);
4002         }
4003         messageview_list_urls(mainwin->messageview);
4004 }
4005
4006 static void add_address_cb(MainWindow *mainwin, guint action,
4007                            GtkWidget *widget)
4008 {
4009         summary_add_address(mainwin->summaryview);
4010 }
4011
4012 static void set_charset_cb(MainWindow *mainwin, guint action,
4013                            GtkWidget *widget)
4014 {
4015         const gchar *str;
4016
4017         if (GTK_CHECK_MENU_ITEM(widget)->active) {
4018                 str = conv_get_charset_str((CharSet)action);
4019                 
4020                 g_free(mainwin->messageview->forced_charset);
4021                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
4022                 procmime_force_charset(str);
4023                 
4024                 summary_redisplay_msg(mainwin->summaryview);
4025                 
4026                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
4027         }
4028 }
4029
4030 static void set_decode_cb(MainWindow *mainwin, guint action,
4031                            GtkWidget *widget)
4032 {
4033         if (GTK_CHECK_MENU_ITEM(widget)->active) {
4034                 mainwin->messageview->forced_encoding = (EncodingType)action;
4035                 
4036                 summary_redisplay_msg(mainwin->summaryview);
4037                 
4038                 debug_print("forced encoding: %d\n", action);
4039         }
4040 }
4041
4042 static void hide_read_messages (MainWindow *mainwin, guint action,
4043                                 GtkWidget *widget)
4044 {
4045         if (!mainwin->summaryview->folder_item
4046             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
4047                 return;
4048         summary_toggle_show_read_messages(mainwin->summaryview);
4049 }
4050
4051 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4052 {
4053         gboolean threaded = FALSE;
4054         if (mainwin->menu_lock_count) return;
4055         if (!mainwin->summaryview->folder_item) return;
4056
4057         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
4058
4059         mainwin->summaryview->folder_item->threaded = threaded; 
4060
4061         mainwin->summaryview->threaded = threaded;
4062
4063         summary_show(mainwin->summaryview, 
4064                         mainwin->summaryview->folder_item);
4065 }
4066
4067 static void expand_threads_cb(MainWindow *mainwin, guint action,
4068                               GtkWidget *widget)
4069 {
4070         summary_expand_threads(mainwin->summaryview);
4071 }
4072
4073 static void collapse_threads_cb(MainWindow *mainwin, guint action,
4074                                 GtkWidget *widget)
4075 {
4076         summary_collapse_threads(mainwin->summaryview);
4077 }
4078
4079 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
4080                                 GtkWidget *widget)
4081 {
4082         prefs_summary_column_open();
4083 }
4084
4085 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
4086                                 GtkWidget *widget)
4087 {
4088         prefs_folder_column_open();
4089 }
4090
4091 static void sort_summary_cb(MainWindow *mainwin, guint action,
4092                             GtkWidget *widget)
4093 {
4094         FolderItem *item = mainwin->summaryview->folder_item;
4095         GtkWidget *menuitem;
4096
4097         if (mainwin->menu_lock_count) return;
4098
4099         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
4100                 menuitem = gtk_item_factory_get_item
4101                         (mainwin->menu_factory, "/View/Sort/Ascending");
4102                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
4103                              GTK_CHECK_MENU_ITEM(menuitem)->active
4104                              ? SORT_ASCENDING : SORT_DESCENDING);
4105                 item->sort_key = action;
4106         }
4107 }
4108
4109 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
4110                                  GtkWidget *widget)
4111 {
4112         FolderItem *item = mainwin->summaryview->folder_item;
4113
4114         if (mainwin->menu_lock_count) return;
4115
4116         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
4117                 summary_sort(mainwin->summaryview,
4118                              item->sort_key, (FolderSortType)action);
4119 }
4120
4121 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
4122                                   GtkWidget *widget)
4123 {
4124         summary_attract_by_subject(mainwin->summaryview);
4125 }
4126
4127 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
4128                                  GtkWidget *widget)
4129 {
4130         FolderItem *item;
4131
4132         item = folderview_get_selected_item(mainwin->folderview);
4133         if (item) {
4134                 main_window_cursor_wait(mainwin);
4135                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
4136
4137                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
4138                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
4139
4140                 STATUSBAR_POP(mainwin);
4141                 main_window_cursor_normal(mainwin);
4142         }
4143 }
4144
4145 struct DelDupsData
4146 {
4147         guint   dups;
4148         guint   folders;
4149 };
4150
4151 static void deldup_all(FolderItem *item, gpointer _data)
4152 {
4153         struct DelDupsData *data = _data;
4154         gint result;
4155         
4156         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
4157         if (result >= 0) {
4158                 data->dups += result;
4159                 data->folders += 1;
4160         }
4161 }
4162
4163 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
4164                                  GtkWidget *widget)
4165 {
4166         struct DelDupsData data = {0, 0};
4167
4168         main_window_cursor_wait(mainwin);
4169         folder_func_to_all_folders(deldup_all, &data);
4170         main_window_cursor_normal(mainwin);
4171         
4172         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
4173                                    "Deleted %d duplicate messages in %d folders.\n",
4174                                    data.dups),
4175                           data.dups, data.folders);
4176 }
4177
4178 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4179 {
4180         summary_filter(mainwin->summaryview, (gboolean)action);
4181 }
4182
4183 static void process_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4184 {
4185         FolderItem *item = mainwin->summaryview->folder_item;   
4186         g_return_if_fail(item != NULL);
4187
4188         item->processing_pending = TRUE;
4189         folder_item_apply_processing(item);     
4190         item->processing_pending = FALSE;
4191 }
4192
4193 static void execute_summary_cb(MainWindow *mainwin, guint action,
4194                                GtkWidget *widget)
4195 {
4196         summary_execute(mainwin->summaryview);
4197 }
4198
4199 static void update_summary_cb(MainWindow *mainwin, guint action,
4200                               GtkWidget *widget)
4201 {
4202         FolderItem *fitem;
4203         FolderView *folderview = mainwin->folderview;
4204
4205         if (!mainwin->summaryview->folder_item) return;
4206         if (!folderview->opened) return;
4207
4208         folder_update_op_count();
4209
4210         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
4211                                             folderview->opened);
4212         if (!fitem) return;
4213
4214         folder_item_scan(fitem);
4215         summary_show(mainwin->summaryview, fitem);
4216 }
4217
4218 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4219 {
4220         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
4221 }
4222
4223 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4224 {
4225         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
4226 }
4227
4228 static void prev_unread_cb(MainWindow *mainwin, guint action,
4229                            GtkWidget *widget)
4230 {
4231         summary_select_prev_unread(mainwin->summaryview);
4232 }
4233
4234 static void next_unread_cb(MainWindow *mainwin, guint action,
4235                            GtkWidget *widget)
4236 {
4237         summary_select_next_unread(mainwin->summaryview);
4238 }
4239
4240 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4241 {
4242         summary_select_prev_new(mainwin->summaryview);
4243 }
4244
4245 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4246 {
4247         summary_select_next_new(mainwin->summaryview);
4248 }
4249
4250 static void prev_marked_cb(MainWindow *mainwin, guint action,
4251                            GtkWidget *widget)
4252 {
4253         summary_select_prev_marked(mainwin->summaryview);
4254 }
4255
4256 static void next_marked_cb(MainWindow *mainwin, guint action,
4257                            GtkWidget *widget)
4258 {
4259         summary_select_next_marked(mainwin->summaryview);
4260 }
4261
4262 static void prev_labeled_cb(MainWindow *mainwin, guint action,
4263                             GtkWidget *widget)
4264 {
4265         summary_select_prev_labeled(mainwin->summaryview);
4266 }
4267
4268 static void next_labeled_cb(MainWindow *mainwin, guint action,
4269                             GtkWidget *widget)
4270 {
4271         summary_select_next_labeled(mainwin->summaryview);
4272 }
4273
4274 static void last_read_cb(MainWindow *mainwin, guint action,
4275                             GtkWidget *widget)
4276 {
4277         summary_select_last_read(mainwin->summaryview);
4278 }
4279
4280 static void parent_cb(MainWindow *mainwin, guint action,
4281                             GtkWidget *widget)
4282 {
4283         summary_select_parent(mainwin->summaryview);
4284 }
4285
4286 static void goto_folder_cb(MainWindow *mainwin, guint action,
4287                            GtkWidget *widget)
4288 {
4289         FolderItem *to_folder;
4290
4291         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE);
4292
4293         if (to_folder)
4294                 folderview_select(mainwin->folderview, to_folder);
4295 }
4296
4297 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
4298                            GtkWidget *widget)
4299 {
4300         folderview_select_next_unread(mainwin->folderview, FALSE);
4301 }
4302
4303 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4304 {
4305         messageview_copy_clipboard(mainwin->messageview);
4306 }
4307
4308 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4309 {
4310         MessageView *msgview = mainwin->messageview;
4311
4312         if (messageview_is_visible(msgview) &&
4313                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
4314                 messageview_select_all(mainwin->messageview);
4315         else
4316                 summary_select_all(mainwin->summaryview);
4317 }
4318
4319 static void select_thread_cb(MainWindow *mainwin, guint action,
4320                              GtkWidget *widget)
4321 {
4322         summary_select_thread(mainwin->summaryview, FALSE);
4323 }
4324
4325 static void delete_thread_cb(MainWindow *mainwin, guint action,
4326                              GtkWidget *widget)
4327 {
4328         summary_select_thread(mainwin->summaryview, TRUE);
4329 }
4330
4331 static void create_filter_cb(MainWindow *mainwin, guint action,
4332                              GtkWidget *widget)
4333 {
4334         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
4335 }
4336
4337 static void create_processing_cb(MainWindow *mainwin, guint action,
4338                              GtkWidget *widget)
4339 {
4340         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
4341 }
4342
4343 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
4344                                          GtkWidget *widget)
4345 {
4346         prefs_filtering_open(&pre_global_processing,
4347                              _("Processing rules to apply before folder rules"),
4348                              MANUAL_ANCHOR_PROCESSING,
4349                              NULL, NULL, FALSE);
4350 }
4351
4352 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
4353                                           GtkWidget *widget)
4354 {
4355         prefs_filtering_open(&post_global_processing,
4356                              _("Processing rules to apply after folder rules"),
4357                              MANUAL_ANCHOR_PROCESSING,
4358                              NULL, NULL, FALSE);
4359 }
4360
4361 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
4362                                     GtkWidget *widget)
4363 {
4364         prefs_filtering_open(&filtering_rules,
4365                              _("Filtering configuration"),
4366                              MANUAL_ANCHOR_FILTERING,
4367                              NULL, NULL, TRUE);
4368 }
4369
4370 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4371                                    GtkWidget *widget)
4372 {
4373         prefs_template_open();
4374 }
4375
4376 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4377                                   GtkWidget *widget)
4378 {
4379         prefs_actions_open(mainwin);
4380 }
4381
4382 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4383                                   GtkWidget *widget)
4384 {
4385         GSList * list = summary_get_selected_msg_list(mainwin->summaryview);
4386         tag_apply_open(list);
4387 }
4388 #if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
4389 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4390                                   GtkWidget *widget)
4391 {
4392         ssl_manager_open(mainwin);
4393 }
4394 #endif
4395 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4396                                   GtkWidget *widget)
4397 {
4398         if (!cur_account) {
4399                 new_account_cb(mainwin, 0, widget);
4400         } else {
4401                 account_open(cur_account);
4402         }
4403 }
4404
4405 static void new_account_cb(MainWindow *mainwin, guint action,
4406                            GtkWidget *widget)
4407 {
4408         account_edit_open();
4409         if (!compose_get_compose_list()) account_add();
4410 }
4411
4412 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4413 {
4414         FolderItem *item = NULL;
4415         cur_account = (PrefsAccount *)data;
4416         
4417         if (!mainwindow_get_mainwindow())
4418                 return;
4419         main_window_show_cur_account(mainwindow_get_mainwindow());
4420         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4421         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4422         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4423         item = folderview_get_selected_item(
4424                         mainwindow_get_mainwindow()->folderview);
4425         if (item) {
4426                 toolbar_set_compose_button
4427                         (mainwindow_get_mainwindow()->toolbar,
4428                          FOLDER_TYPE(item->folder) == F_NEWS ? 
4429                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4430         }
4431 }
4432
4433 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4434 {
4435         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4436         PrefsAccount *account = (PrefsAccount *)data;
4437
4438         inc_account_mail(mainwin, account);
4439 }
4440 #ifndef GENERIC_UMPC
4441 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4442 {
4443         PrefsAccount *account = (PrefsAccount *)data;
4444
4445         compose_new_with_folderitem(account, NULL, NULL);
4446 }
4447 #endif
4448 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4449 {
4450         prefs_gtk_open();
4451 }
4452
4453 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4454 {
4455         pluginwindow_create();
4456 }
4457
4458 static void manual_open_cb(MainWindow *mainwin, guint action,
4459                            GtkWidget *widget)
4460 {
4461         manual_open((ManualType)action, NULL);
4462 }
4463
4464 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4465 {
4466         legend_show();
4467 }
4468
4469 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4470 {
4471         MainWindow *mainwin = (MainWindow *)data;
4472         gchar *str;
4473
4474         if (item->path)
4475                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4476                                       LOCAL_FOLDER(folder)->rootpath,
4477                                       G_DIR_SEPARATOR,
4478                                       item->path);
4479         else
4480                 str = g_strdup_printf(_("Scanning folder %s ..."),
4481                                       LOCAL_FOLDER(folder)->rootpath);
4482
4483         STATUSBAR_PUSH(mainwin, str);
4484         STATUSBAR_POP(mainwin);
4485         g_free(str);
4486 }
4487
4488 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4489                                           gpointer data)
4490 {
4491         SummaryView *summary;
4492
4493         g_return_val_if_fail(data, FALSE);
4494         if (!g_list_find(mainwin_list, data))
4495                 return TRUE;
4496         summary = ((MainWindow *)data)->summaryview;
4497         g_return_val_if_fail(summary, FALSE);
4498
4499         if (GTK_CLIST(summary->ctree)->selection && 
4500             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4501                 return FALSE;
4502
4503         return FALSE;
4504 }
4505
4506 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4507                                           gpointer data)
4508 {
4509         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4510         return FALSE;
4511 }
4512
4513 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4514                                           gpointer data)
4515 {
4516         if (!claws_is_starting()
4517                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4518                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4519
4520                 if (iconified_count > 0)
4521                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4522                 iconified_count++;
4523         } else if (!claws_is_starting()) {
4524                 prefs_common.mainwin_maximised = 
4525                         ((state->new_window_state&GDK_WINDOW_STATE_MAXIMIZED) != 0);
4526         }
4527         if (state->new_window_state == 0)
4528                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4529         return FALSE;
4530 }
4531
4532 gboolean mainwindow_is_obscured(void)
4533 {
4534         return is_obscured;
4535 }
4536
4537 /*
4538  * Harvest addresses for selected folder.
4539  */
4540 static void addr_harvest_cb( MainWindow *mainwin,
4541                             guint action,
4542                             GtkWidget *widget )
4543 {
4544         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4545 }
4546
4547 /*
4548  * Harvest addresses for selected messages in summary view.
4549  */
4550 static void addr_harvest_msg_cb( MainWindow *mainwin,
4551                             guint action,
4552                             GtkWidget *widget )
4553 {
4554         summary_harvest_address( mainwin->summaryview );
4555 }
4556
4557 /*!
4558  *\brief        get a MainWindow
4559  *
4560  *\return       MainWindow * The first mainwindow in the mainwin_list
4561  */
4562 MainWindow *mainwindow_get_mainwindow(void)
4563 {
4564         if (mainwin_list && mainwin_list->data)
4565                 return (MainWindow *)(mainwin_list->data);
4566         else
4567                 return NULL;
4568 }
4569
4570 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4571 {
4572         ProgressData *data = (ProgressData *) source;
4573         MainWindow *mainwin = (MainWindow *) userdata;
4574
4575         switch (data->cmd) {
4576         case PROGRESS_COMMAND_START:
4577         case PROGRESS_COMMAND_STOP:
4578                 gtk_progress_bar_set_fraction
4579                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4580                 break;
4581         case PROGRESS_COMMAND_SET_PERCENTAGE:
4582                 gtk_progress_bar_set_fraction
4583                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4584                 break;          
4585         }
4586         while (gtk_events_pending()) gtk_main_iteration ();
4587
4588         return FALSE;
4589 }
4590
4591 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4592 {
4593         mainwindow_check_synchronise(mainwin, FALSE);
4594 }
4595
4596 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4597 {
4598         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4599 }
4600
4601 void mainwindow_jump_to(const gchar *target, gboolean popup)
4602 {
4603         gchar *tmp = NULL;
4604         gchar *p = NULL;
4605         FolderItem *item = NULL;
4606         gchar *msg = NULL;
4607         MainWindow *mainwin = mainwindow_get_mainwindow();
4608         gchar *from_uri = NULL;
4609         if (!target)
4610                 return;
4611                 
4612         if (!mainwin) {
4613                 g_print("not initialized\n");
4614                 return;
4615         }
4616
4617         if ((from_uri = g_filename_from_uri(target, NULL, NULL)) != NULL)
4618                 tmp = from_uri;
4619         else
4620                 tmp = g_strdup(target);
4621         
4622         if ((p = strstr(tmp, "\r")) != NULL)
4623                 *p = '\0';
4624         if ((p = strstr(tmp, "\n")) != NULL)
4625                 *p = '\0';
4626
4627         if ((item = folder_find_item_from_identifier(tmp))) {
4628                 g_print("selecting folder '%s'\n", tmp);
4629                 folderview_select(mainwin->folderview, item);
4630                 if (popup)
4631                         main_window_popup(mainwin);
4632                 g_free(tmp);
4633                 return;
4634         }
4635         
4636         msg = strrchr(tmp, G_DIR_SEPARATOR);
4637         if (msg) {
4638                 *msg++ = '\0';
4639                 if ((item = folder_find_item_from_identifier(tmp))) {
4640                         g_print("selecting folder '%s'\n", tmp);
4641                         folderview_select(mainwin->folderview, item);
4642                 } else if ((item = folder_find_item_from_real_path(tmp))) {
4643                         g_print("selecting folder '%s'\n", tmp);
4644                         folderview_select(mainwin->folderview, item);
4645                 } else {
4646                         g_print("'%s' not found\n", tmp);
4647                 }
4648                 if (item && msg && atoi(msg)) {
4649                         g_print("selecting message %d\n", atoi(msg));
4650                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4651                         summary_display_msg_selected(mainwin->summaryview, FALSE);
4652                         if (popup)
4653                                 main_window_popup(mainwin);
4654                         g_free(tmp);
4655                         return;
4656                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4657                         MsgInfo *msginfo = NULL;
4658                         msg++;
4659                         msg[strlen(msg)-1] = '\0';
4660                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4661                         if (msginfo) {
4662                                 g_print("selecting message %s\n", msg);
4663                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4664                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4665                                 if (popup)
4666                                         main_window_popup(mainwin);
4667                                 g_free(tmp);
4668                                 procmsg_msginfo_free(msginfo);
4669                                 return;
4670                         } else {
4671                                 g_print("'%s' not found\n", msg);
4672                         }
4673                 } else {
4674                         g_print("'%s' not found\n", msg);
4675                 }
4676         } else {
4677                 g_print("'%s' not found\n", tmp);
4678         }
4679         
4680         g_free(tmp);
4681 }
4682
4683 void mainwindow_exit_folder(MainWindow *mainwin) {
4684         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4685                 folderview_close_opened(mainwin->folderview);
4686                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4687                 gtk_widget_grab_focus(mainwin->folderview->ctree);
4688         }
4689         mainwin->in_folder = FALSE;
4690 }
4691
4692 void mainwindow_enter_folder(MainWindow *mainwin) {
4693         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4694                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4695         }
4696         mainwin->in_folder = TRUE;
4697 }
4698
4699 #ifdef MAEMO
4700 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4701 {
4702         gint w, h;
4703         gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
4704         return (w == 800);
4705 }
4706
4707 void maemo_window_full_screen_if_needed (GtkWindow *window)
4708 {
4709         if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4710                 gtk_window_fullscreen(GTK_WINDOW(window));
4711         }
4712 }
4713
4714 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4715 {
4716         g_signal_connect(G_OBJECT(window), "key_press_event",
4717                          G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
4718 }
4719 #endif