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