2007-01-25 [paul] 2.7.1cvs2-stable
[claws.git] / src / mainwindow.c
blob24b12a8ff37f53d0e2a0e75313232877910e0355
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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.
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.
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.
20 #include "defs.h"
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>
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 "log.h"
60 #include "compose.h"
61 #include "procmsg.h"
62 #include "import.h"
63 #include "export.h"
64 #include "prefs_common.h"
65 #include "prefs_actions.h"
66 #include "prefs_filtering.h"
67 #include "prefs_account.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_folder_column.h"
70 #include "prefs_template.h"
71 #include "action.h"
72 #include "account.h"
73 #include "addressbook.h"
74 #include "logwindow.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "inputdialog.h"
79 #include "utils.h"
80 #include "gtkutils.h"
81 #include "codeconv.h"
82 #include "about.h"
83 #include "manual.h"
84 #include "version.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefs_gtk.h"
88 #include "pluginwindow.h"
89 #include "hooks.h"
90 #include "progressindicator.h"
91 #include "localfolder.h"
92 #include "filtering.h"
93 #include "folderutils.h"
94 #include "foldersort.h"
95 #include "icon_legend.h"
96 #include "colorlabel.h"
97 #include "textview.h"
98 #include "imap.h"
99 #include "socket.h"
101 #define AC_LABEL_WIDTH 240
103 /* list of all instantiated MainWindow */
104 static GList *mainwin_list = NULL;
106 static GdkCursor *watch_cursor = NULL;
107 static GdkCursor *hand_cursor = NULL;
109 static void main_window_menu_callback_block (MainWindow *mainwin);
110 static void main_window_menu_callback_unblock (MainWindow *mainwin);
112 static void main_window_show_cur_account (MainWindow *mainwin);
114 static void main_window_set_widgets (MainWindow *mainwin,
115 SeparateType type);
117 static void toolbar_child_attached (GtkWidget *widget,
118 GtkWidget *child,
119 gpointer data);
120 static void toolbar_child_detached (GtkWidget *widget,
121 GtkWidget *child,
122 gpointer data);
124 static gboolean ac_label_button_pressed (GtkWidget *widget,
125 GdkEventButton *event,
126 gpointer data);
128 static gint main_window_close_cb (GtkWidget *widget,
129 GdkEventAny *event,
130 gpointer data);
131 static gint folder_window_close_cb (GtkWidget *widget,
132 GdkEventAny *event,
133 gpointer data);
134 static gint message_window_close_cb (GtkWidget *widget,
135 GdkEventAny *event,
136 gpointer data);
138 static void main_window_size_allocate_cb (GtkWidget *widget,
139 GtkAllocation *allocation,
140 gpointer data);
141 static void folder_window_size_allocate_cb (GtkWidget *widget,
142 GtkAllocation *allocation,
143 gpointer data);
144 static void message_window_size_allocate_cb (GtkWidget *widget,
145 GtkAllocation *allocation,
146 gpointer data);
148 static void update_folderview_cb (MainWindow *mainwin,
149 guint action,
150 GtkWidget *widget);
151 static void add_mailbox_cb (MainWindow *mainwin,
152 guint action,
153 GtkWidget *widget);
154 static void foldersort_cb (MainWindow *mainwin,
155 guint action,
156 GtkWidget *widget);
157 static void import_mbox_cb (MainWindow *mainwin,
158 guint action,
159 GtkWidget *widget);
160 static void export_mbox_cb (MainWindow *mainwin,
161 guint action,
162 GtkWidget *widget);
163 static void export_list_mbox_cb (MainWindow *mainwin,
164 guint action,
165 GtkWidget *widget);
166 static void empty_trash_cb (MainWindow *mainwin,
167 guint action,
168 GtkWidget *widget);
170 static void save_as_cb (MainWindow *mainwin,
171 guint action,
172 GtkWidget *widget);
173 static void print_cb (MainWindow *mainwin,
174 guint action,
175 GtkWidget *widget);
176 static void app_exit_cb (MainWindow *mainwin,
177 guint action,
178 GtkWidget *widget);
180 static void search_cb (MainWindow *mainwin,
181 guint action,
182 GtkWidget *widget);
184 static void toggle_folder_cb (MainWindow *mainwin,
185 guint action,
186 GtkWidget *widget);
187 static void toggle_message_cb (MainWindow *mainwin,
188 guint action,
189 GtkWidget *widget);
190 static void toggle_toolbar_cb (MainWindow *mainwin,
191 guint action,
192 GtkWidget *widget);
193 static void toggle_statusbar_cb (MainWindow *mainwin,
194 guint action,
195 GtkWidget *widget);
196 static void separate_widget_cb (MainWindow *mainwin,
197 guint action,
198 GtkWidget *widget);
200 static void addressbook_open_cb (MainWindow *mainwin,
201 guint action,
202 GtkWidget *widget);
203 static void log_window_show_cb (MainWindow *mainwin,
204 guint action,
205 GtkWidget *widget);
207 static void inc_cancel_cb (MainWindow *mainwin,
208 guint action,
209 GtkWidget *widget);
211 static void open_msg_cb (MainWindow *mainwin,
212 guint action,
213 GtkWidget *widget);
215 static void view_source_cb (MainWindow *mainwin,
216 guint action,
217 GtkWidget *widget);
219 static void show_all_header_cb (MainWindow *mainwin,
220 guint action,
221 GtkWidget *widget);
223 static void hide_quotes_cb(MainWindow *mainwin,
224 guint action,
225 GtkWidget *widget);
227 static void move_to_cb (MainWindow *mainwin,
228 guint action,
229 GtkWidget *widget);
230 static void copy_to_cb (MainWindow *mainwin,
231 guint action,
232 GtkWidget *widget);
233 static void delete_cb (MainWindow *mainwin,
234 guint action,
235 GtkWidget *widget);
236 static void delete_trash_cb (MainWindow *mainwin,
237 guint action,
238 GtkWidget *widget);
240 static void cancel_cb (MainWindow *mainwin,
241 guint action,
242 GtkWidget *widget);
244 static void mark_cb (MainWindow *mainwin,
245 guint action,
246 GtkWidget *widget);
247 static void unmark_cb (MainWindow *mainwin,
248 guint action,
249 GtkWidget *widget);
251 static void mark_as_unread_cb (MainWindow *mainwin,
252 guint action,
253 GtkWidget *widget);
254 static void mark_as_read_cb (MainWindow *mainwin,
255 guint action,
256 GtkWidget *widget);
257 static void mark_all_read_cb (MainWindow *mainwin,
258 guint action,
259 GtkWidget *widget);
260 static void mark_as_spam_cb (MainWindow *mainwin,
261 guint action,
262 GtkWidget *widget);
264 static void ignore_thread_cb (MainWindow *mainwin,
265 guint action,
266 GtkWidget *widget);
267 static void unignore_thread_cb (MainWindow *mainwin,
268 guint action,
269 GtkWidget *widget);
270 static void lock_msgs_cb (MainWindow *mainwin,
271 guint action,
272 GtkWidget *widget);
273 static void unlock_msgs_cb (MainWindow *mainwin,
274 guint action,
275 GtkWidget *widget);
277 static void reedit_cb (MainWindow *mainwin,
278 guint action,
279 GtkWidget *widget);
281 static void add_address_cb (MainWindow *mainwin,
282 guint action,
283 GtkWidget *widget);
285 static void set_charset_cb (MainWindow *mainwin,
286 guint action,
287 GtkWidget *widget);
289 static void set_decode_cb (MainWindow *mainwin,
290 guint action,
291 GtkWidget *widget);
293 static void hide_read_messages (MainWindow *mainwin,
294 guint action,
295 GtkWidget *widget);
297 static void thread_cb (MainWindow *mainwin,
298 guint action,
299 GtkWidget *widget);
300 static void expand_threads_cb (MainWindow *mainwin,
301 guint action,
302 GtkWidget *widget);
303 static void collapse_threads_cb (MainWindow *mainwin,
304 guint action,
305 GtkWidget *widget);
307 static void set_summary_display_item_cb (MainWindow *mainwin,
308 guint action,
309 GtkWidget *widget);
310 static void set_folder_display_item_cb (MainWindow *mainwin,
311 guint action,
312 GtkWidget *widget);
313 static void sort_summary_cb (MainWindow *mainwin,
314 guint action,
315 GtkWidget *widget);
316 static void sort_summary_type_cb (MainWindow *mainwin,
317 guint action,
318 GtkWidget *widget);
319 static void attract_by_subject_cb(MainWindow *mainwin,
320 guint action,
321 GtkWidget *widget);
323 static void delete_duplicated_cb (MainWindow *mainwin,
324 guint action,
325 GtkWidget *widget);
326 static void delete_duplicated_all_cb (MainWindow *mainwin,
327 guint action,
328 GtkWidget *widget);
329 static void filter_cb (MainWindow *mainwin,
330 guint action,
331 GtkWidget *widget);
332 static void execute_summary_cb (MainWindow *mainwin,
333 guint action,
334 GtkWidget *widget);
335 static void update_summary_cb (MainWindow *mainwin,
336 guint action,
337 GtkWidget *widget);
339 static void prev_cb (MainWindow *mainwin,
340 guint action,
341 GtkWidget *widget);
342 static void next_cb (MainWindow *mainwin,
343 guint action,
344 GtkWidget *widget);
345 static void next_unread_cb (MainWindow *mainwin,
346 guint action,
347 GtkWidget *widget);
348 static void prev_unread_cb (MainWindow *mainwin,
349 guint action,
350 GtkWidget *widget);
352 static void prev_new_cb (MainWindow *mainwin,
353 guint action,
354 GtkWidget *widget);
355 static void next_new_cb (MainWindow *mainwin,
356 guint action,
357 GtkWidget *widget);
358 static void prev_marked_cb (MainWindow *mainwin,
359 guint action,
360 GtkWidget *widget);
361 static void next_marked_cb (MainWindow *mainwin,
362 guint action,
363 GtkWidget *widget);
364 static void prev_labeled_cb (MainWindow *mainwin,
365 guint action,
366 GtkWidget *widget);
367 static void next_labeled_cb (MainWindow *mainwin,
368 guint action,
369 GtkWidget *widget);
370 static void last_read_cb (MainWindow *mainwin,
371 guint action,
372 GtkWidget *widget);
373 static void parent_cb (MainWindow *mainwin,
374 guint action,
375 GtkWidget *widget);
377 static void goto_folder_cb (MainWindow *mainwin,
378 guint action,
379 GtkWidget *widget);
380 static void goto_unread_folder_cb(MainWindow *mainwin,
381 guint action,
382 GtkWidget *widget);
384 static void copy_cb (MainWindow *mainwin,
385 guint action,
386 GtkWidget *widget);
387 static void allsel_cb (MainWindow *mainwin,
388 guint action,
389 GtkWidget *widget);
390 static void select_thread_cb (MainWindow *mainwin,
391 guint action,
392 GtkWidget *widget);
394 static void create_filter_cb (MainWindow *mainwin,
395 guint action,
396 GtkWidget *widget);
397 static void create_processing_cb (MainWindow *mainwin,
398 guint action,
399 GtkWidget *widget);
401 static void prefs_template_open_cb (MainWindow *mainwin,
402 guint action,
403 GtkWidget *widget);
404 static void prefs_actions_open_cb (MainWindow *mainwin,
405 guint action,
406 GtkWidget *widget);
407 static void prefs_account_open_cb (MainWindow *mainwin,
408 guint action,
409 GtkWidget *widget);
411 static void prefs_pre_processing_open_cb (MainWindow *mainwin,
412 guint action,
413 GtkWidget *widget);
415 static void prefs_post_processing_open_cb (MainWindow *mainwin,
416 guint action,
417 GtkWidget *widget);
419 static void prefs_filtering_open_cb (MainWindow *mainwin,
420 guint action,
421 GtkWidget *widget);
422 #ifdef USE_OPENSSL
423 static void ssl_manager_open_cb (MainWindow *mainwin,
424 guint action,
425 GtkWidget *widget);
426 #endif
427 static void new_account_cb (MainWindow *mainwin,
428 guint action,
429 GtkWidget *widget);
431 static void account_selector_menu_cb (GtkMenuItem *menuitem,
432 gpointer data);
433 static void account_receive_menu_cb (GtkMenuItem *menuitem,
434 gpointer data);
435 static void account_compose_menu_cb (GtkMenuItem *menuitem,
436 gpointer data);
438 static void prefs_open_cb (GtkMenuItem *menuitem,
439 gpointer data);
440 static void plugins_open_cb (GtkMenuItem *menuitem,
441 gpointer data);
443 static void online_switch_clicked(GtkButton *btn,
444 gpointer data);
446 static void manual_open_cb (MainWindow *mainwin,
447 guint action,
448 GtkWidget *widget);
450 static void legend_open_cb (GtkMenuItem *menuitem,
451 gpointer data);
453 static void scan_tree_func (Folder *folder,
454 FolderItem *item,
455 gpointer data);
457 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
459 static void addr_harvest_cb ( MainWindow *mainwin,
460 guint action,
461 GtkWidget *widget );
463 static void addr_harvest_msg_cb ( MainWindow *mainwin,
464 guint action,
465 GtkWidget *widget );
466 static void sync_cb ( MainWindow *mainwin,
467 guint action,
468 GtkWidget *widget );
470 static gboolean mainwindow_focus_in_event (GtkWidget *widget,
471 GdkEventFocus *focus,
472 gpointer data);
473 void main_window_reply_cb (MainWindow *mainwin,
474 guint action,
475 GtkWidget *widget);
476 gboolean mainwindow_progressindicator_hook (gpointer source,
477 gpointer userdata);
479 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
480 MsgInfo *msginfo);
482 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
484 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
486 static void mailing_list_compose(GtkWidget *w, gpointer *data);
488 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
489 #define SEPARATE_ACTION 500
490 static void mainwindow_quicksearch (MainWindow *mainwin,
491 guint action,
492 GtkWidget *widget);
493 static gboolean any_folder_want_synchronise(void);
495 static GtkItemFactoryEntry mainwin_entries[] =
497 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
498 {N_("/_File/_Add mailbox"), NULL, NULL, 0, "<Branch>"},
499 {N_("/_File/_Add mailbox/MH..."), NULL, add_mailbox_cb, 0, NULL},
500 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
501 {N_("/_File/Change folder order..."), NULL, foldersort_cb, 0, NULL},
502 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
503 {N_("/_File/_Import mbox file..."), NULL, import_mbox_cb, 0, NULL},
504 {N_("/_File/_Export to mbox file..."), NULL, export_mbox_cb, 0, NULL},
505 {N_("/_File/Exp_ort selected to mbox file..."),
506 NULL, export_list_mbox_cb, 0, NULL},
507 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
509 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
510 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
511 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
512 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_File/_Work offline"), "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
514 {N_("/_File/Synchronise folders"), "<control><shift>S", sync_cb, 0, NULL},
515 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
516 /* {N_("/_File/_Close"), "<alt>W", app_exit_cb, 0, NULL}, */
517 {N_("/_File/E_xit"), "<control>Q", app_exit_cb, 0, NULL},
519 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
520 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
521 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
522 {N_("/_Edit/Select _thread"), NULL, select_thread_cb, 0, NULL},
523 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Edit/_Find in current message..."),
525 "<control>F", search_cb, 0, NULL},
526 {N_("/_Edit/_Search folder..."), "<shift><control>F", search_cb, 1, NULL},
527 {N_("/_Edit/_Quick search"), "slash", mainwindow_quicksearch, 0, NULL},
528 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
529 {N_("/_View/Show or hi_de"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_View/Show or hi_de/_Folder tree"),
531 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
532 {N_("/_View/Show or hi_de/_Message view"),
533 "V", toggle_message_cb, 0, "<ToggleItem>"},
534 {N_("/_View/Show or hi_de/_Toolbar"),
535 NULL, NULL, 0, "<Branch>"},
536 {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
537 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
538 {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
539 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
540 {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
541 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
542 {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
543 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
544 {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
545 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
546 {N_("/_View/Show or hi_de/Status _bar"),
547 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
548 {N_("/_View/Set displayed _columns"), NULL, NULL, 0, "<Branch>"},
549 {N_("/_View/Set displayed _columns/in _Folder list..."), NULL, set_folder_display_item_cb, 0, NULL},
550 {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
552 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
553 {N_("/_View/Separate f_older tree"), NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
554 {N_("/_View/Separate _message view"), NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
555 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
556 {N_("/_View/_Sort"), NULL, NULL, 0, "<Branch>"},
557 {N_("/_View/_Sort/by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
558 {N_("/_View/_Sort/by S_ize"), NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
559 {N_("/_View/_Sort/by _Date"), NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
560 {N_("/_View/_Sort/by _From"), NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
561 {N_("/_View/_Sort/by _To"), NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
562 {N_("/_View/_Sort/by S_ubject"), NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
563 {N_("/_View/_Sort/by _color label"),
564 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
565 {N_("/_View/_Sort/by _mark"), NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
566 {N_("/_View/_Sort/by _status"), NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
567 {N_("/_View/_Sort/by a_ttachment"),
568 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
569 {N_("/_View/_Sort/by score"), NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
570 {N_("/_View/_Sort/by locked"), NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
571 {N_("/_View/_Sort/D_on't sort"), NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
572 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
573 {N_("/_View/_Sort/Ascending"), NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
574 {N_("/_View/_Sort/Descending"), NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
575 {N_("/_View/_Sort/---"), NULL, NULL, 0, "<Separator>"},
576 {N_("/_View/_Sort/_Attract by subject"),
577 NULL, attract_by_subject_cb, 0, NULL},
578 {N_("/_View/Th_read view"), "<control>T", thread_cb, 0, "<ToggleItem>"},
579 {N_("/_View/E_xpand all threads"), NULL, expand_threads_cb, 0, NULL},
580 {N_("/_View/Co_llapse all threads"), NULL, collapse_threads_cb, 0, NULL},
581 {N_("/_View/_Hide read messages"), NULL, hide_read_messages, 0, "<ToggleItem>"},
583 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
584 {N_("/_View/_Go to"), NULL, NULL, 0, "<Branch>"},
585 {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
586 {N_("/_View/_Go to/_Next message"), "N", next_cb, 0, NULL},
587 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
588 {N_("/_View/_Go to/P_revious unread message"),
589 "<shift>P", prev_unread_cb, 0, NULL},
590 {N_("/_View/_Go to/N_ext unread message"),
591 "<shift>N", next_unread_cb, 0, NULL},
592 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
593 {N_("/_View/_Go to/Previous ne_w message"), NULL, prev_new_cb, 0, NULL},
594 {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
595 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
596 {N_("/_View/_Go to/Previous _marked message"),
597 NULL, prev_marked_cb, 0, NULL},
598 {N_("/_View/_Go to/Next m_arked message"),
599 NULL, next_marked_cb, 0, NULL},
600 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
601 {N_("/_View/_Go to/Previous _labeled message"),
602 NULL, prev_labeled_cb, 0, NULL},
603 {N_("/_View/_Go to/Next la_beled message"),
604 NULL, next_labeled_cb, 0, NULL},
605 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_View/_Go to/Last read message"),
607 NULL, last_read_cb, 0, NULL},
608 {N_("/_View/_Go to/Parent message"),
609 "<control>Up", parent_cb, 0, NULL},
610 {N_("/_View/_Go to/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_View/_Go to/Next unread _folder"), "<shift>G", goto_unread_folder_cb, 0, NULL},
612 {N_("/_View/_Go to/_Other folder..."), "G", goto_folder_cb, 0, NULL},
613 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
615 #define ENC_SEPARATOR \
616 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
617 #define ENC_ACTION(action) \
618 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
620 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
621 {N_("/_View/Character _encoding/_Auto detect"),
622 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
623 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
625 ENC_ACTION(C_US_ASCII)},
626 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
627 ENC_ACTION(C_UTF_8)},
628 ENC_SEPARATOR,
630 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
631 ENC_ACTION(C_ISO_8859_1)},
632 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
633 ENC_ACTION(C_ISO_8859_15)},
634 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
635 ENC_ACTION(C_WINDOWS_1252)},
636 ENC_SEPARATOR,
638 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
639 ENC_ACTION(C_ISO_8859_2)},
640 ENC_SEPARATOR,
642 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
643 ENC_ACTION(C_ISO_8859_13)},
644 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
645 ENC_ACTION(C_ISO_8859_4)},
646 ENC_SEPARATOR,
648 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
649 ENC_ACTION(C_ISO_8859_7)},
650 ENC_SEPARATOR,
652 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
653 ENC_ACTION(C_ISO_8859_8)},
654 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
655 ENC_ACTION(C_CP1255)},
656 ENC_SEPARATOR,
658 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
659 ENC_ACTION(C_ISO_8859_6)},
660 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
661 ENC_ACTION(C_CP1256)},
662 ENC_SEPARATOR,
664 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
665 ENC_ACTION(C_ISO_8859_9)},
666 ENC_SEPARATOR,
668 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
669 ENC_ACTION(C_ISO_8859_5)},
670 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
671 ENC_ACTION(C_KOI8_R)},
672 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
673 ENC_ACTION(C_KOI8_U)},
674 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
675 ENC_ACTION(C_CP1251)},
676 ENC_SEPARATOR,
678 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
679 ENC_ACTION(C_ISO_2022_JP)},
680 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
681 ENC_ACTION(C_ISO_2022_JP_2)},
682 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
683 ENC_ACTION(C_EUC_JP)},
684 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
685 ENC_ACTION(C_SHIFT_JIS)},
686 ENC_SEPARATOR,
688 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
689 ENC_ACTION(C_GB2312)},
690 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
691 ENC_ACTION(C_GBK)},
692 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
693 ENC_ACTION(C_BIG5)},
694 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
695 ENC_ACTION(C_EUC_TW)},
696 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
697 ENC_ACTION(C_ISO_2022_CN)},
698 ENC_SEPARATOR,
700 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
701 ENC_ACTION(C_EUC_KR)},
702 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
703 ENC_ACTION(C_ISO_2022_KR)},
704 ENC_SEPARATOR,
706 {N_("/_View/Character _encoding/Thai (TIS-620)"),
707 ENC_ACTION(C_TIS_620)},
708 {N_("/_View/Character _encoding/Thai (Windows-874)"),
709 ENC_ACTION(C_WINDOWS_874)},
711 #undef ENC_SEPARATOR
712 #undef ENC_ACTION
714 #define DEC_SEPARATOR \
715 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
716 #define DEC_ACTION(action) \
717 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
718 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
719 {N_("/_View/Decode/_Auto detect"),
720 NULL, set_decode_cb, 0, "<RadioItem>"},
721 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
722 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
723 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
724 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
725 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
727 #undef DEC_SEPARATOR
728 #undef DEC_ACTION
730 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
731 {N_("/_View/Open in new _window"), "<control><alt>N", open_msg_cb, 0, NULL},
732 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
733 {N_("/_View/All headers"), "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
734 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
735 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
736 {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
737 {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
738 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
739 {N_("/_View/_Update summary"), "<control><alt>U", update_summary_cb, 0, NULL},
741 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
742 {N_("/_Message/Recei_ve"), NULL, NULL, 0, "<Branch>"},
743 {N_("/_Message/Recei_ve/Get from _current account"),
744 "<control>I", inc_mail_cb, 0, NULL},
745 {N_("/_Message/Recei_ve/Get from _all accounts"),
746 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
747 {N_("/_Message/Recei_ve/Cancel receivin_g"),
748 NULL, inc_cancel_cb, 0, NULL},
749 {N_("/_Message/Recei_ve/---"), NULL, NULL, 0, "<Separator>"},
750 {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
751 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Message/Compose a_n email message"), "<control>M", compose_mail_cb, 0, NULL},
753 {N_("/_Message/Compose a news message"), NULL, compose_news_cb, 0, NULL},
754 {N_("/_Message/_Reply"), "<control>R", main_window_reply_cb, COMPOSE_REPLY, NULL},
755 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
756 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
757 {N_("/_Message/Repl_y to/_sender"), NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
758 {N_("/_Message/Repl_y to/mailing _list"),
759 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
760 {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
761 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
762 {N_("/_Message/_Forward"), "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
763 {N_("/_Message/For_ward as attachment"), NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
764 {N_("/_Message/Redirect"), NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
766 {N_("/_Message/Mailing-_List"), NULL, NULL, 0, "<Branch>"},
767 {N_("/_Message/Mailing-_List/Post"), NULL, NULL, 0, "<Branch>"},
768 {N_("/_Message/Mailing-_List/Help"), NULL, NULL, 0, "<Branch>"},
769 {N_("/_Message/Mailing-_List/Subscribe"), NULL, NULL, 0, "<Branch>"},
770 {N_("/_Message/Mailing-_List/Unsubscribe"), NULL, NULL, 0, "<Branch>"},
771 {N_("/_Message/Mailing-_List/View archive"), NULL, NULL, 0, "<Branch>"},
772 {N_("/_Message/Mailing-_List/Contact owner"), NULL, NULL, 0, "<Branch>"},
774 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
775 {N_("/_Message/M_ove..."), "<control>O", move_to_cb, 0, NULL},
776 {N_("/_Message/_Copy..."), "<shift><control>O", copy_to_cb, 0, NULL},
777 {N_("/_Message/Move to _trash"), "<control>D", delete_trash_cb, 0, NULL},
778 {N_("/_Message/_Delete..."), NULL, delete_cb, 0, NULL},
779 {N_("/_Message/Cancel a news message"), "", cancel_cb, 0, NULL},
780 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
781 {N_("/_Message/_Mark"), NULL, NULL, 0, "<Branch>"},
782 {N_("/_Message/_Mark/_Mark"), "<shift>asterisk", mark_cb, 0, NULL},
783 {N_("/_Message/_Mark/_Unmark"), "U", unmark_cb, 0, NULL},
784 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
785 {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
786 {N_("/_Message/_Mark/Mark as rea_d"), NULL, mark_as_read_cb, 0, NULL},
787 {N_("/_Message/_Mark/Mark all _read"), NULL, mark_all_read_cb, 0, NULL},
788 {N_("/_Message/_Mark/Ignore thread"), NULL, ignore_thread_cb, 0, NULL},
789 {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
790 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
791 {N_("/_Message/_Mark/Mark as _spam"), NULL, mark_as_spam_cb, 1, NULL},
792 {N_("/_Message/_Mark/Mark as _ham"), NULL, mark_as_spam_cb, 0, NULL},
793 {N_("/_Message/_Mark/---"), NULL, NULL, 0, "<Separator>"},
794 {N_("/_Message/_Mark/Lock"), NULL, lock_msgs_cb, 0, NULL},
795 {N_("/_Message/_Mark/Unlock"), NULL, unlock_msgs_cb, 0, NULL},
796 {N_("/_Message/Color la_bel"), NULL, NULL, 0, NULL},
797 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
798 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
800 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
801 {N_("/_Tools/_Address book..."), "<shift><control>A", addressbook_open_cb, 0, NULL},
802 {N_("/_Tools/Add sender to address boo_k"),
803 NULL, add_address_cb, 0, NULL},
804 {N_("/_Tools/_Harvest addresses"), NULL, NULL, 0, "<Branch>"},
805 {N_("/_Tools/_Harvest addresses/from _Folder..."),
806 NULL, addr_harvest_cb, 0, NULL},
807 {N_("/_Tools/_Harvest addresses/from _Messages..."),
808 NULL, addr_harvest_msg_cb, 0, NULL},
809 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
810 {N_("/_Tools/_Filter all messages in folder"),
811 NULL, filter_cb, 0, NULL},
812 {N_("/_Tools/Filter _selected messages"),
813 NULL, filter_cb, 1, NULL},
814 {N_("/_Tools/_Create filter rule"), NULL, NULL, 0, "<Branch>"},
815 {N_("/_Tools/_Create filter rule/_Automatically"),
816 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
817 {N_("/_Tools/_Create filter rule/by _From"),
818 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
819 {N_("/_Tools/_Create filter rule/by _To"),
820 NULL, create_filter_cb, FILTER_BY_TO, NULL},
821 {N_("/_Tools/_Create filter rule/by _Subject"),
822 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
823 {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
824 {N_("/_Tools/C_reate processing rule/_Automatically"),
825 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
826 {N_("/_Tools/C_reate processing rule/by _From"),
827 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
828 {N_("/_Tools/C_reate processing rule/by _To"),
829 NULL, create_processing_cb, FILTER_BY_TO, NULL},
830 {N_("/_Tools/C_reate processing rule/by _Subject"),
831 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
832 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
833 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
834 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
835 {N_("/_Tools/Ch_eck for new messages in all folders"),
836 NULL, update_folderview_cb, 0, NULL},
837 {N_("/_Tools/Delete du_plicated messages"),
838 NULL, NULL, 0, "<Branch>"},
839 {N_("/_Tools/Delete du_plicated messages/In selected folder"),
840 NULL, delete_duplicated_cb, 0, NULL},
841 {N_("/_Tools/Delete du_plicated messages/In all folders"),
842 NULL, delete_duplicated_all_cb, 0, NULL},
843 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
844 {N_("/_Tools/E_xecute"), "X", execute_summary_cb, 0, NULL},
845 #ifdef USE_OPENSSL
846 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
847 {N_("/_Tools/SSL cer_tificates..."),
848 NULL, ssl_manager_open_cb, 0, NULL},
849 #endif
850 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
851 {N_("/_Tools/_Log window"), "<shift><control>L", log_window_show_cb, 0, NULL},
853 {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},
854 {N_("/_Configuration/C_hange current account"),
855 NULL, NULL, 0, "<Branch>"},
856 {N_("/_Configuration/_Preferences for current account..."),
857 NULL, prefs_account_open_cb, 0, NULL},
858 {N_("/_Configuration/Create _new account..."),
859 NULL, new_account_cb, 0, NULL},
860 {N_("/_Configuration/_Edit accounts..."),
861 NULL, account_edit_open, 0, NULL},
862 {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
863 {N_("/_Configuration/P_references..."),
864 NULL, prefs_open_cb, 0, NULL},
865 {N_("/_Configuration/Pre-pr_ocessing..."),
866 NULL, prefs_pre_processing_open_cb, 0, NULL},
867 {N_("/_Configuration/Post-pro_cessing..."),
868 NULL, prefs_post_processing_open_cb, 0, NULL},
869 {N_("/_Configuration/_Filtering..."),
870 NULL, prefs_filtering_open_cb, 0, NULL},
871 {N_("/_Configuration/_Templates..."), NULL, prefs_template_open_cb, 0, NULL},
872 {N_("/_Configuration/_Actions..."), NULL, prefs_actions_open_cb, 0, NULL},
873 {N_("/_Configuration/Plu_gins..."), NULL, plugins_open_cb, 0, NULL},
875 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
876 {N_("/_Help/_Manual"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
877 {N_("/_Help/_Online User-contributed FAQ"),
878 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
879 {N_("/_Help/Icon _Legend"), NULL, legend_open_cb, 0, NULL},
880 {N_("/_Help/---"), NULL, NULL, 0, "<Separator>"},
881 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
884 static gboolean offline_ask_sync = TRUE;
885 static guint lastkey;
887 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
888 GObject *arg1,
889 guint value,
890 GdkModifierType mod,
891 gpointer user_data)
893 MainWindow *mainwin = (MainWindow *)user_data;
895 if (mainwin->summaryview &&
896 mainwin->summaryview->quicksearch &&
897 quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
898 (mod == 0 || mod == GDK_SHIFT_MASK)) {
899 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
900 return TRUE;
902 return FALSE;
905 #define N_COLOR_LABELS colorlabel_get_color_count()
907 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
908 gpointer data)
910 MainWindow *mainwin;
911 GtkMenuShell *menu;
912 GtkCheckMenuItem **items;
913 gint n;
914 GList *cur;
915 GSList *sel;
917 mainwin = (MainWindow *)data;
918 g_return_if_fail(mainwin != NULL);
920 sel = summary_get_selection(mainwin->summaryview);
921 if (!sel) return;
923 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
924 g_return_if_fail(menu != NULL);
926 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
928 /* NOTE: don't return prematurely because we set the "dont_toggle"
929 * state for check menu items */
930 g_object_set_data(G_OBJECT(menu), "dont_toggle",
931 GINT_TO_POINTER(1));
933 /* clear items. get item pointers. */
934 for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
935 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
936 gtk_check_menu_item_set_active
937 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
938 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
939 n++;
943 if (n == (N_COLOR_LABELS + 1)) {
944 /* iterate all messages and set the state of the appropriate
945 * items */
946 for (; sel != NULL; sel = sel->next) {
947 MsgInfo *msginfo;
948 gint clabel;
950 msginfo = (MsgInfo *)sel->data;
951 if (msginfo) {
952 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
953 if (!items[clabel]->active)
954 gtk_check_menu_item_set_active
955 (items[clabel], TRUE);
958 } else
959 g_warning("invalid number of color elements (%d)\n", n);
961 /* reset "dont_toggle" state */
962 g_object_set_data(G_OBJECT(menu), "dont_toggle",
963 GINT_TO_POINTER(0));
966 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
967 gpointer data)
969 guint color = GPOINTER_TO_UINT(data);
970 MainWindow *mainwin;
972 mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
973 g_return_if_fail(mainwin != NULL);
975 /* "dont_toggle" state set? */
976 if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
977 "dont_toggle"))
978 return;
980 summary_set_colorlabel(mainwin->summaryview, color, NULL);
983 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
985 GtkWidget *label_menuitem;
986 GtkWidget *menu;
987 GtkWidget *item;
988 gint i;
990 label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
991 "/Message/Color label");
992 g_signal_connect(G_OBJECT(label_menuitem), "activate",
993 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
994 mainwin);
995 gtk_widget_show(label_menuitem);
997 menu = gtk_menu_new();
999 /* create sub items. for the menu item activation callback we pass the
1000 * index of label_colors[] as data parameter. for the None color we
1001 * pass an invalid (high) value. also we attach a data pointer so we
1002 * can always get back the Mainwindow pointer. */
1004 item = gtk_check_menu_item_new_with_label(_("None"));
1005 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1006 g_signal_connect(G_OBJECT(item), "activate",
1007 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1008 GUINT_TO_POINTER(0));
1009 g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1010 gtk_widget_show(item);
1012 gtk_widget_add_accelerator(item, "activate",
1013 mainwin->menu_factory->accel_group,
1014 GDK_0, GDK_CONTROL_MASK,
1015 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1017 item = gtk_menu_item_new();
1018 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1019 gtk_widget_show(item);
1021 /* create pixmap/label menu items */
1022 for (i = 0; i < N_COLOR_LABELS; i++) {
1023 item = colorlabel_create_check_color_menu_item(
1024 i, refresh, MAINWIN_COLORMENU);
1025 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1026 g_signal_connect(G_OBJECT(item), "activate",
1027 G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1028 GUINT_TO_POINTER(i + 1));
1029 g_object_set_data(G_OBJECT(item), "mainwin",
1030 mainwin);
1031 gtk_widget_show(item);
1032 gtk_widget_add_accelerator(item, "activate",
1033 mainwin->menu_factory->accel_group,
1034 GDK_1+i, GDK_CONTROL_MASK,
1035 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1038 gtk_widget_show(menu);
1039 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1040 mainwin->colorlabel_menu = menu;
1043 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1044 MainWindow *mainwindow)
1046 if (evt && evt->button == 1) {
1047 log_window_show_error(mainwindow->logwin);
1048 gtk_widget_hide(mainwindow->warning_btn);
1050 return FALSE;
1053 static gboolean warning_visi_notify(GtkWidget *widget,
1054 GdkEventVisibility *event,
1055 MainWindow *mainwindow)
1057 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1058 return FALSE;
1061 static gboolean warning_leave_notify(GtkWidget *widget,
1062 GdkEventCrossing *event,
1063 MainWindow *mainwindow)
1065 gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1066 return FALSE;
1069 static gboolean warning_enter_notify(GtkWidget *widget,
1070 GdkEventCrossing *event,
1071 MainWindow *mainwindow)
1073 gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1074 return FALSE;
1077 void mainwindow_show_error(void)
1079 MainWindow *mainwin = mainwindow_get_mainwindow();
1080 gtk_widget_show(mainwin->warning_btn);
1083 void mainwindow_clear_error(MainWindow *mainwin)
1085 gtk_widget_hide(mainwin->warning_btn);
1088 MainWindow *main_window_create(SeparateType type)
1090 MainWindow *mainwin;
1091 GtkWidget *window;
1092 GtkWidget *vbox;
1093 GtkWidget *menubar;
1094 GtkWidget *handlebox;
1095 GtkWidget *vbox_body;
1096 GtkWidget *hbox_stat;
1097 GtkWidget *statusbar;
1098 GtkWidget *progressbar;
1099 GtkWidget *statuslabel;
1100 GtkWidget *ac_button;
1101 GtkWidget *ac_label;
1102 GtkWidget *online_pixmap;
1103 GtkWidget *offline_pixmap;
1104 GtkWidget *online_switch;
1105 GtkWidget *offline_switch;
1106 GtkTooltips *tips;
1107 GtkWidget *warning_icon;
1108 GtkWidget *warning_btn;
1110 FolderView *folderview;
1111 SummaryView *summaryview;
1112 MessageView *messageview;
1113 GdkColormap *colormap;
1114 GdkColor color[4];
1115 gboolean success[4];
1116 GtkItemFactory *ifactory;
1117 GtkWidget *ac_menu;
1118 GtkWidget *menuitem;
1119 gint i;
1120 guint n_menu_entries;
1122 static GdkGeometry geometry;
1124 debug_print("Creating main window...\n");
1125 mainwin = g_new0(MainWindow, 1);
1127 /* main window */
1128 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1129 gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1130 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1132 if (!geometry.min_height) {
1133 geometry.min_width = 320;
1134 geometry.min_height = 200;
1136 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1137 GDK_HINT_MIN_SIZE);
1139 g_signal_connect(G_OBJECT(window), "delete_event",
1140 G_CALLBACK(main_window_close_cb), mainwin);
1141 MANAGE_WINDOW_SIGNALS_CONNECT(window);
1142 g_signal_connect(G_OBJECT(window), "focus_in_event",
1143 G_CALLBACK(mainwindow_focus_in_event),
1144 mainwin);
1145 g_signal_connect(G_OBJECT(window), "key_press_event",
1146 G_CALLBACK(mainwindow_key_pressed), mainwin);
1148 gtk_widget_realize(window);
1149 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1152 gtkut_widget_set_app_icon(window);
1154 vbox = gtk_vbox_new(FALSE, 0);
1155 gtk_widget_show(vbox);
1156 gtk_container_add(GTK_CONTAINER(window), vbox);
1158 /* menu bar */
1159 n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1160 menubar = menubar_create(window, mainwin_entries,
1161 n_menu_entries, "<Main>", mainwin);
1162 gtk_widget_show(menubar);
1163 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1164 ifactory = gtk_item_factory_from_widget(menubar);
1166 /* gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1167 main_create_mailing_list_menu (mainwin, NULL); */
1169 menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1171 if (prefs_common.toolbar_detachable) {
1172 handlebox = gtk_handle_box_new();
1173 gtk_widget_show(handlebox);
1174 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1175 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1176 G_CALLBACK(toolbar_child_attached), mainwin);
1177 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1178 G_CALLBACK(toolbar_child_detached), mainwin);
1179 } else {
1180 handlebox = gtk_hbox_new(FALSE, 0);
1181 gtk_widget_show(handlebox);
1182 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1184 /* link window to mainwin->window to avoid gdk warnings */
1185 mainwin->window = window;
1187 /* create toolbar */
1188 mainwin->toolbar = toolbar_create(TOOLBAR_MAIN,
1189 handlebox,
1190 (gpointer)mainwin);
1191 toolbar_set_learn_button
1192 (mainwin->toolbar,
1193 LEARN_SPAM);
1195 /* vbox that contains body */
1196 vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1197 gtk_widget_show(vbox_body);
1198 gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1199 gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1201 hbox_stat = gtk_hbox_new(FALSE, 2);
1202 gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1204 tips = gtk_tooltips_new();
1206 warning_icon = gtk_image_new_from_stock
1207 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1208 warning_btn = gtk_event_box_new();
1209 gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1211 mainwin->warning_btn = warning_btn;
1213 g_signal_connect(G_OBJECT(warning_btn), "button-press-event",
1214 G_CALLBACK(warning_icon_pressed),
1215 (gpointer) mainwin);
1216 g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1217 G_CALLBACK(warning_visi_notify), mainwin);
1218 g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1219 G_CALLBACK(warning_visi_notify), mainwin);
1220 g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1221 G_CALLBACK(warning_leave_notify), mainwin);
1222 g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1223 G_CALLBACK(warning_enter_notify), mainwin);
1225 gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1227 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn,
1228 _("Some error(s) happened. Click here to view log."), NULL);
1229 gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1231 statusbar = statusbar_create();
1232 gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1234 progressbar = gtk_progress_bar_new();
1235 gtk_widget_set_size_request(progressbar, 120, 1);
1236 gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1238 online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1239 offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1240 online_switch = gtk_button_new ();
1241 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch,
1242 _("You are online. Click the icon to go offline"), NULL);
1243 offline_switch = gtk_button_new ();
1244 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch,
1245 _("You are offline. Click the icon to go online"),
1246 NULL);
1247 gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1248 gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1249 g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1250 gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1251 gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1252 gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1253 g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1254 gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1256 statuslabel = gtk_label_new("");
1257 gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1259 ac_button = gtk_button_new();
1260 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1261 ac_button, _("Select account"), NULL);
1262 GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1263 gtk_widget_set_size_request(ac_button, -1, 0);
1264 gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1265 g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1266 G_CALLBACK(ac_label_button_pressed), mainwin);
1268 ac_label = gtk_label_new("");
1269 gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1271 gtk_widget_show_all(hbox_stat);
1273 gtk_widget_hide(offline_switch);
1274 gtk_widget_hide(warning_btn);
1275 /* create views */
1276 mainwin->folderview = folderview = folderview_create();
1277 mainwin->summaryview = summaryview = summary_create();
1278 mainwin->messageview = messageview = messageview_create(mainwin);
1279 mainwin->logwin = log_window_create();
1281 log_window_init(mainwin->logwin);
1282 log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1283 prefs_common.loglength);
1285 folderview->mainwin = mainwin;
1286 folderview->summaryview = summaryview;
1288 summaryview->mainwin = mainwin;
1289 summaryview->folderview = folderview;
1290 summaryview->messageview = messageview;
1291 summaryview->window = window;
1293 messageview->statusbar = statusbar;
1294 mainwin->vbox = vbox;
1295 mainwin->menubar = menubar;
1296 mainwin->menu_factory = ifactory;
1297 mainwin->handlebox = handlebox;
1298 mainwin->vbox_body = vbox_body;
1299 mainwin->hbox_stat = hbox_stat;
1300 mainwin->statusbar = statusbar;
1301 mainwin->progressbar = progressbar;
1302 mainwin->statuslabel = statuslabel;
1303 mainwin->online_switch = online_switch;
1304 mainwin->online_pixmap = online_pixmap;
1305 mainwin->offline_pixmap = offline_pixmap;
1306 mainwin->ac_button = ac_button;
1307 mainwin->ac_label = ac_label;
1308 mainwin->offline_switch = offline_switch;
1310 /* set context IDs for status bar */
1311 mainwin->mainwin_cid = gtk_statusbar_get_context_id
1312 (GTK_STATUSBAR(statusbar), "Main Window");
1313 mainwin->folderview_cid = gtk_statusbar_get_context_id
1314 (GTK_STATUSBAR(statusbar), "Folder View");
1315 mainwin->summaryview_cid = gtk_statusbar_get_context_id
1316 (GTK_STATUSBAR(statusbar), "Summary View");
1317 mainwin->messageview_cid = gtk_statusbar_get_context_id
1318 (GTK_STATUSBAR(statusbar), "Message View");
1320 messageview->statusbar_cid = mainwin->messageview_cid;
1322 /* allocate colors for summary view and folder view */
1323 summaryview->color_marked.red = summaryview->color_marked.green = 0;
1324 summaryview->color_marked.blue = (guint16)65535;
1326 summaryview->color_dim.red = summaryview->color_dim.green =
1327 summaryview->color_dim.blue = COLOR_DIM;
1329 gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1330 &folderview->color_new);
1332 gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1333 &folderview->color_op);
1335 summaryview->color_important.red = 0;
1336 summaryview->color_important.green = 0;
1337 summaryview->color_important.blue = (guint16)65535;
1339 color[0] = summaryview->color_marked;
1340 color[1] = summaryview->color_dim;
1341 color[2] = folderview->color_new;
1342 color[3] = folderview->color_op;
1344 colormap = gdk_drawable_get_colormap(window->window);
1345 gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1346 for (i = 0; i < 4; i++) {
1347 if (success[i] == FALSE)
1348 g_warning("MainWindow: color allocation %d failed\n", i);
1351 debug_print("done.\n");
1353 messageview->visible = prefs_common.msgview_visible;
1355 main_window_set_widgets(mainwin, type);
1357 g_signal_connect(G_OBJECT(window), "size_allocate",
1358 G_CALLBACK(main_window_size_allocate_cb),
1359 mainwin);
1361 /* set menu items */
1362 menuitem = gtk_item_factory_get_item
1363 (ifactory, "/View/Character encoding/Auto detect");
1364 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1366 switch (prefs_common.toolbar_style) {
1367 case TOOLBAR_NONE:
1368 menuitem = gtk_item_factory_get_item
1369 (ifactory, "/View/Show or hide/Toolbar/Hide");
1370 break;
1371 case TOOLBAR_ICON:
1372 menuitem = gtk_item_factory_get_item
1373 (ifactory, "/View/Show or hide/Toolbar/Icons only");
1374 break;
1375 case TOOLBAR_TEXT:
1376 menuitem = gtk_item_factory_get_item
1377 (ifactory, "/View/Show or hide/Toolbar/Text only");
1378 break;
1379 case TOOLBAR_BOTH:
1380 menuitem = gtk_item_factory_get_item
1381 (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1382 break;
1383 case TOOLBAR_BOTH_HORIZ:
1384 menuitem = gtk_item_factory_get_item
1385 (ifactory,
1386 "/View/Show or hide/Toolbar/Text beside icons");
1388 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1390 gtk_widget_hide(mainwin->hbox_stat);
1391 menuitem = gtk_item_factory_get_item
1392 (ifactory, "/View/Show or hide/Status bar");
1393 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1394 prefs_common.show_statusbar);
1396 /* set account selection menu */
1397 ac_menu = gtk_item_factory_get_widget
1398 (ifactory, "/Configuration/Change current account");
1399 mainwin->ac_menu = ac_menu;
1401 toolbar_main_set_sensitive(mainwin);
1403 /* create actions menu */
1404 main_window_update_actions_menu(mainwin);
1406 main_create_mailing_list_menu (mainwin, NULL);
1408 /* attach accel groups to main window */
1409 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win) \
1410 gtk_window_add_accel_group \
1411 (GTK_WINDOW(win), \
1412 gtk_item_factory_from_widget(menu)->accel_group); \
1413 g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1414 "accel_activate", \
1415 G_CALLBACK(main_window_accel_activate), mainwin);
1418 ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1420 /* connect the accelerators for equivalent
1421 menu items in different menus */
1422 menu_connect_identical_items();
1425 gtk_window_iconify(GTK_WINDOW(mainwin->window));
1427 gtk_widget_show(mainwin->window);
1429 /* initialize views */
1430 folderview_init(folderview);
1431 summary_init(summaryview);
1432 messageview_init(messageview);
1433 #ifdef USE_OPENSSL
1434 sslcertwindow_register_hook();
1435 #endif
1436 mainwin->lock_count = 0;
1437 mainwin->menu_lock_count = 0;
1438 mainwin->cursor_count = 0;
1440 mainwin->progressindicator_hook =
1441 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1443 if (!watch_cursor)
1444 watch_cursor = gdk_cursor_new(GDK_WATCH);
1445 if (!hand_cursor)
1446 hand_cursor = gdk_cursor_new(GDK_HAND2);
1448 mainwin_list = g_list_append(mainwin_list, mainwin);
1450 /* init work_offline */
1451 if (prefs_common.work_offline)
1452 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1454 mainwindow_colorlabel_menu_create(mainwin, FALSE);
1456 return mainwin;
1459 void main_window_destroy(MainWindow *mainwin)
1461 /* TODO : destroy other component */
1462 messageview_destroy(mainwin->messageview);
1463 mainwin->messageview = NULL;
1466 void main_window_update_actions_menu(MainWindow *mainwin)
1468 GtkItemFactory *ifactory;
1470 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1471 action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1474 void main_window_cursor_wait(MainWindow *mainwin)
1477 if (mainwin->cursor_count == 0) {
1478 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1479 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1482 mainwin->cursor_count++;
1484 gdk_flush();
1487 void main_window_cursor_normal(MainWindow *mainwin)
1489 if (mainwin->cursor_count)
1490 mainwin->cursor_count--;
1492 if (mainwin->cursor_count == 0) {
1493 gdk_window_set_cursor(mainwin->window->window, NULL);
1494 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1496 gdk_flush();
1499 /* lock / unlock the user-interface */
1500 void main_window_lock(MainWindow *mainwin)
1502 if (mainwin->lock_count == 0)
1503 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1505 mainwin->lock_count++;
1507 main_window_set_menu_sensitive(mainwin);
1508 toolbar_main_set_sensitive(mainwin);
1511 void main_window_unlock(MainWindow *mainwin)
1513 if (mainwin->lock_count)
1514 mainwin->lock_count--;
1516 main_window_set_menu_sensitive(mainwin);
1517 toolbar_main_set_sensitive(mainwin);
1519 if (mainwin->lock_count == 0)
1520 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1523 static void main_window_menu_callback_block(MainWindow *mainwin)
1525 mainwin->menu_lock_count++;
1528 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1530 if (mainwin->menu_lock_count)
1531 mainwin->menu_lock_count--;
1534 static guint prefs_tag = 0;
1536 void main_window_reflect_prefs_all(void)
1538 main_window_reflect_prefs_all_real(FALSE);
1541 static gboolean reflect_prefs_timeout_cb(gpointer data)
1543 gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1544 GList *cur;
1545 MainWindow *mainwin;
1546 GtkWidget *pixmap;
1548 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1549 mainwin = (MainWindow *)cur->data;
1551 main_window_show_cur_account(mainwin);
1552 main_window_set_menu_sensitive(mainwin);
1553 toolbar_main_set_sensitive(mainwin);
1555 /* pixmap themes */
1556 if (pixmap_theme_changed) {
1557 toolbar_update(TOOLBAR_MAIN, mainwin);
1558 messageview_reflect_prefs_pixmap_theme();
1559 compose_reflect_prefs_pixmap_theme();
1560 folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1561 summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1563 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1564 gtk_container_remove(GTK_CONTAINER(mainwin->online_switch),
1565 mainwin->online_pixmap);
1566 gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1567 gtk_widget_show(pixmap);
1568 mainwin->online_pixmap = pixmap;
1569 pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1570 gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch),
1571 mainwin->offline_pixmap);
1572 gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1573 gtk_widget_show(pixmap);
1574 mainwin->offline_pixmap = pixmap;
1577 headerview_set_font(mainwin->messageview->headerview);
1578 headerview_set_visibility(mainwin->messageview->headerview,
1579 prefs_common.display_header_pane);
1580 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1581 folderview_reflect_prefs();
1582 summary_reflect_prefs();
1583 summary_redisplay_msg(mainwin->summaryview);
1585 prefs_tag = 0;
1586 return FALSE;
1589 void main_window_reflect_prefs_all_now(void)
1591 reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1594 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1596 GtkMenuShell *menu;
1597 GList *cur;
1599 /* re-create colorlabel submenu */
1600 menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1601 g_return_if_fail(menu != NULL);
1603 /* clear items. get item pointers. */
1604 for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1605 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1607 mainwindow_colorlabel_menu_create(mainwin, TRUE);
1608 summary_reflect_prefs_custom_colors(mainwin->summaryview);
1612 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1614 if (prefs_tag == 0 || pixmap_theme_changed) {
1615 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb,
1616 GINT_TO_POINTER(pixmap_theme_changed));
1620 void main_window_set_summary_column(void)
1622 GList *cur;
1623 MainWindow *mainwin;
1625 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1626 mainwin = (MainWindow *)cur->data;
1627 summary_set_column_order(mainwin->summaryview);
1631 void main_window_set_folder_column(void)
1633 GList *cur;
1634 MainWindow *mainwin;
1636 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1637 mainwin = (MainWindow *)cur->data;
1638 folderview_set_column_order(mainwin->folderview);
1642 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1643 GList *account_list)
1645 GList *cur_ac, *cur_item;
1646 GtkWidget *menuitem;
1647 PrefsAccount *ac_prefs;
1649 /* destroy all previous menu item */
1650 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1651 while (cur_item != NULL) {
1652 GList *next = cur_item->next;
1653 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1654 cur_item = next;
1657 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1658 ac_prefs = (PrefsAccount *)cur_ac->data;
1660 menuitem = gtk_menu_item_new_with_label
1661 (ac_prefs->account_name
1662 ? ac_prefs->account_name : _("Untitled"));
1663 gtk_widget_show(menuitem);
1664 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1665 g_signal_connect(G_OBJECT(menuitem), "activate",
1666 G_CALLBACK(account_selector_menu_cb),
1667 ac_prefs);
1671 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1672 GList *account_list)
1674 GList *cur_ac, *cur_item;
1675 GtkWidget *menu;
1676 GtkWidget *menuitem;
1677 PrefsAccount *ac_prefs;
1679 menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1680 "/Message/Receive");
1682 /* search for separator */
1683 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1684 cur_item = cur_item->next) {
1685 if (GTK_BIN(cur_item->data)->child == NULL) {
1686 cur_item = cur_item->next;
1687 break;
1691 /* destroy all previous menu item */
1692 while (cur_item != NULL) {
1693 GList *next = cur_item->next;
1694 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1695 cur_item = next;
1698 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1699 ac_prefs = (PrefsAccount *)cur_ac->data;
1701 menuitem = gtk_menu_item_new_with_label
1702 (ac_prefs->account_name ? ac_prefs->account_name
1703 : _("Untitled"));
1704 gtk_widget_show(menuitem);
1705 gtk_menu_append(GTK_MENU(menu), menuitem);
1706 g_signal_connect(G_OBJECT(menuitem), "activate",
1707 G_CALLBACK(account_receive_menu_cb),
1708 ac_prefs);
1712 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1713 GList *account_list)
1715 GList *cur_ac, *cur_item;
1716 GtkWidget *menuitem;
1717 PrefsAccount *ac_prefs;
1718 GtkWidget *menu = NULL;
1720 if (mainwin->toolbar->getall_btn == NULL
1721 || mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1722 return;
1724 menu = mainwin->toolbar->getall_combo->menu;
1726 /* destroy all previous menu item */
1727 cur_item = GTK_MENU_SHELL(menu)->children;
1728 while (cur_item != NULL) {
1729 GList *next = cur_item->next;
1730 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1731 cur_item = next;
1734 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1735 ac_prefs = (PrefsAccount *)cur_ac->data;
1737 menuitem = gtk_menu_item_new_with_label
1738 (ac_prefs->account_name
1739 ? ac_prefs->account_name : _("Untitled"));
1740 gtk_widget_show(menuitem);
1741 gtk_menu_append(GTK_MENU(menu), menuitem);
1742 g_signal_connect(G_OBJECT(menuitem), "activate",
1743 G_CALLBACK(account_receive_menu_cb),
1744 ac_prefs);
1748 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1749 GList *account_list)
1751 GList *cur_ac, *cur_item;
1752 GtkWidget *menuitem;
1753 PrefsAccount *ac_prefs;
1754 GtkWidget *menu = NULL;
1756 if (mainwin->toolbar->compose_mail_btn == NULL
1757 || mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1758 return;
1760 menu = mainwin->toolbar->compose_combo->menu;
1762 /* destroy all previous menu item */
1763 cur_item = GTK_MENU_SHELL(menu)->children;
1764 while (cur_item != NULL) {
1765 GList *next = cur_item->next;
1766 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1767 cur_item = next;
1770 for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1771 ac_prefs = (PrefsAccount *)cur_ac->data;
1773 menuitem = gtk_menu_item_new_with_label
1774 (ac_prefs->account_name
1775 ? ac_prefs->account_name : _("Untitled"));
1776 gtk_widget_show(menuitem);
1777 gtk_menu_append(GTK_MENU(menu), menuitem);
1778 g_signal_connect(G_OBJECT(menuitem), "activate",
1779 G_CALLBACK(account_compose_menu_cb),
1780 ac_prefs);
1784 void main_window_set_account_menu(GList *account_list)
1786 GList *cur;
1787 MainWindow *mainwin;
1789 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1790 mainwin = (MainWindow *)cur->data;
1791 main_window_set_account_selector_menu(mainwin, account_list);
1792 main_window_set_account_receive_menu(mainwin, account_list);
1793 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1794 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1796 hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
1799 void main_window_set_account_menu_only_toolbar(GList *account_list)
1801 GList *cur;
1802 MainWindow *mainwin;
1804 for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1805 mainwin = (MainWindow *)cur->data;
1806 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1807 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1811 static void main_window_show_cur_account(MainWindow *mainwin)
1813 gchar *buf;
1814 gchar *ac_name;
1816 ac_name = g_strdup(cur_account
1817 ? (cur_account->account_name
1818 ? cur_account->account_name : _("Untitled"))
1819 : _("none"));
1821 if (cur_account)
1822 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1823 else
1824 buf = g_strdup(PROG_VERSION);
1825 gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1826 g_free(buf);
1828 gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1829 gtk_widget_queue_resize(mainwin->ac_button);
1831 g_free(ac_name);
1834 GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
1836 switch (mainwin->type) {
1837 case SEPARATE_FOLDER:
1838 return mainwin->win.sep_folder.folderwin;
1839 case SEPARATE_BOTH:
1840 return mainwin->win.sep_both.folderwin;
1841 default:
1842 return NULL;
1846 GtkWidget *main_window_get_message_window(MainWindow *mainwin)
1848 switch (mainwin->type) {
1849 case SEPARATE_MESSAGE:
1850 return mainwin->win.sep_message.messagewin;
1851 case SEPARATE_BOTH:
1852 return mainwin->win.sep_both.messagewin;
1853 default:
1854 return NULL;
1858 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1860 GtkWidget *folder_wid = GTK_WIDGET_PTR(mainwin->folderview);
1861 GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1862 /* GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); */
1863 GtkWidget *message_wid = mainwin->messageview->vbox;
1865 debug_print("Changing window separation type from %d to %d\n",
1866 mainwin->type, type);
1868 if (mainwin->type == type) return;
1870 /* remove widgets from those containers */
1871 gtk_widget_ref(folder_wid);
1872 gtk_widget_ref(summary_wid);
1873 gtk_widget_ref(message_wid);
1874 gtkut_container_remove
1875 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1876 gtkut_container_remove
1877 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1878 gtkut_container_remove
1879 (GTK_CONTAINER(message_wid->parent), message_wid);
1881 /* clean containers */
1882 switch (mainwin->type) {
1883 case SEPARATE_NONE:
1884 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1885 break;
1886 case SEPARATE_FOLDER:
1887 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1888 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1889 break;
1890 case SEPARATE_MESSAGE:
1891 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1892 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1893 break;
1894 case SEPARATE_BOTH:
1895 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1896 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1897 break;
1900 gtk_widget_hide(mainwin->window);
1901 main_window_set_widgets(mainwin, type);
1902 gtk_widget_show(mainwin->window);
1904 gtk_widget_unref(folder_wid);
1905 gtk_widget_unref(summary_wid);
1906 gtk_widget_unref(message_wid);
1909 void main_window_toggle_message_view(MainWindow *mainwin)
1911 SummaryView *summaryview = mainwin->summaryview;
1912 union CompositeWin *cwin = &mainwin->win;
1913 GtkWidget *vpaned = NULL;
1914 GtkWidget *container = NULL;
1915 GtkWidget *msgwin = NULL;
1917 switch (mainwin->type) {
1918 case SEPARATE_NONE:
1919 vpaned = cwin->sep_none.vpaned;
1920 container = cwin->sep_none.hpaned;
1921 break;
1922 case SEPARATE_FOLDER:
1923 vpaned = cwin->sep_folder.vpaned;
1924 container = mainwin->vbox_body;
1925 break;
1926 case SEPARATE_MESSAGE:
1927 msgwin = mainwin->win.sep_message.messagewin;
1928 break;
1929 case SEPARATE_BOTH:
1930 msgwin = mainwin->win.sep_both.messagewin;
1931 break;
1934 if (msgwin) {
1935 if (GTK_WIDGET_VISIBLE(msgwin)) {
1936 gtk_widget_hide(msgwin);
1937 mainwin->messageview->visible = FALSE;
1938 summaryview->displayed = NULL;
1939 } else {
1940 gtk_widget_show(msgwin);
1941 mainwin->messageview->visible = TRUE;
1943 } else if (vpaned->parent != NULL) {
1944 mainwin->messageview->visible = FALSE;
1945 summaryview->displayed = NULL;
1946 gtk_widget_ref(vpaned);
1947 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1948 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1949 } else {
1950 mainwin->messageview->visible = TRUE;
1951 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1952 gtk_container_add(GTK_CONTAINER(container), vpaned);
1953 gtk_widget_unref(vpaned);
1956 if (messageview_is_visible(mainwin->messageview))
1957 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1958 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1959 else
1960 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1961 GTK_ARROW_UP, GTK_SHADOW_OUT);
1963 if (mainwin->messageview->visible == FALSE)
1964 messageview_clear(mainwin->messageview);
1966 main_window_set_menu_sensitive(mainwin);
1968 prefs_common.msgview_visible = mainwin->messageview->visible;
1970 summary_grab_focus(summaryview);
1973 void main_window_get_size(MainWindow *mainwin)
1975 GtkAllocation *allocation;
1977 if (mainwin_list == NULL || mainwin->messageview == NULL) {
1978 debug_print("called after messageview "
1979 "has been deallocated!\n");
1980 return;
1983 allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1985 if (allocation->width > 1 && allocation->height > 1) {
1986 prefs_common.summaryview_width = allocation->width;
1988 if ((mainwin->type == SEPARATE_NONE ||
1989 mainwin->type == SEPARATE_FOLDER) &&
1990 messageview_is_visible(mainwin->messageview))
1991 prefs_common.summaryview_height = allocation->height;
1993 prefs_common.mainview_width = allocation->width;
1996 allocation = &mainwin->window->allocation;
1997 if (allocation->width > 1 && allocation->height > 1) {
1998 prefs_common.mainview_height = allocation->height;
1999 prefs_common.mainwin_width = allocation->width;
2000 prefs_common.mainwin_height = allocation->height;
2003 allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2004 if (allocation->width > 1 && allocation->height > 1) {
2005 prefs_common.folderview_width = allocation->width;
2006 prefs_common.folderview_height = allocation->height;
2009 allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2010 if (allocation->width > 1 && allocation->height > 1) {
2011 prefs_common.msgview_width = allocation->width;
2012 prefs_common.msgview_height = allocation->height;
2015 /* debug_print("summaryview size: %d x %d\n",
2016 prefs_common.summaryview_width,
2017 prefs_common.summaryview_height);
2018 debug_print("folderview size: %d x %d\n",
2019 prefs_common.folderview_width,
2020 prefs_common.folderview_height);
2021 debug_print("messageview size: %d x %d\n",
2022 prefs_common.msgview_width,
2023 prefs_common.msgview_height); */
2026 void main_window_get_position(MainWindow *mainwin)
2028 gint x, y;
2029 GtkWidget *window;
2031 gtkut_widget_get_uposition(mainwin->window, &x, &y);
2033 prefs_common.mainview_x = x;
2034 prefs_common.mainview_y = y;
2035 prefs_common.mainwin_x = x;
2036 prefs_common.mainwin_y = y;
2038 debug_print("main window position: %d, %d\n", x, y);
2040 window = main_window_get_folder_window(mainwin);
2041 if (window) {
2042 gtkut_widget_get_uposition(window, &x, &y);
2043 prefs_common.folderwin_x = x;
2044 prefs_common.folderwin_y = y;
2045 debug_print("folder window position: %d, %d\n", x, y);
2047 window = main_window_get_message_window(mainwin);
2048 if (window) {
2049 gtkut_widget_get_uposition(window, &x, &y);
2050 prefs_common.main_msgwin_x = x;
2051 prefs_common.main_msgwin_y = y;
2052 debug_print("message window position: %d, %d\n", x, y);
2056 void main_window_progress_on(MainWindow *mainwin)
2058 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2061 void main_window_progress_off(MainWindow *mainwin)
2063 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2064 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2067 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2069 gchar buf[32];
2071 g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2072 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2073 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2074 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2077 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2079 if (confirm) {
2080 if (alertpanel(_("Empty trash"),
2081 _("Delete all messages in trash folders?"),
2082 GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
2083 != G_ALERTALTERNATE)
2084 return;
2085 manage_window_focus_in(mainwin->window, NULL, NULL);
2088 procmsg_empty_all_trash();
2090 if (mainwin->summaryview->folder_item &&
2091 mainwin->summaryview->folder_item->stype == F_TRASH)
2092 gtk_widget_grab_focus(mainwin->folderview->ctree);
2095 void main_window_add_mailbox(MainWindow *mainwin)
2097 gchar *path;
2098 Folder *folder;
2100 path = input_dialog(_("Add mailbox"),
2101 _("Input the location of mailbox.\n"
2102 "If the existing mailbox is specified, it will be\n"
2103 "scanned automatically."),
2104 "Mail");
2105 if (!path) return;
2106 if (folder_find_from_path(path)) {
2107 alertpanel_error(_("The mailbox '%s' already exists."), path);
2108 g_free(path);
2109 return;
2111 folder = folder_new(folder_get_class_from_string("mh"),
2112 !strcmp(path, "Mail") ? _("Mailbox") :
2113 g_path_get_basename(path), path);
2114 g_free(path);
2116 if (folder->klass->create_tree(folder) < 0) {
2117 alertpanel_error(_("Creation of the mailbox failed.\n"
2118 "Maybe some files already exist, or you don't have the permission to write there."));
2119 folder_destroy(folder);
2120 return;
2123 folder_add(folder);
2124 folder_set_ui_func(folder, scan_tree_func, mainwin);
2125 folder_scan_tree(folder, TRUE);
2126 folder_set_ui_func(folder, NULL, NULL);
2129 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2131 SensitiveCond state = 0;
2132 SummarySelection selection;
2133 FolderItem *item = mainwin->summaryview->folder_item;
2134 GList *account_list = account_get_list();
2136 selection = summary_get_selection_type(mainwin->summaryview);
2138 if (mainwin->lock_count == 0)
2139 state |= M_UNLOCKED;
2140 if (selection != SUMMARY_NONE)
2141 state |= M_MSG_EXIST;
2142 if (item && item->path && folder_item_parent(item) && !item->no_select) {
2143 state |= M_EXEC;
2144 /* if (item->folder->type != F_NEWS) */
2145 state |= M_ALLOW_DELETE;
2147 if (prefs_common.immediate_exec == 0
2148 && mainwin->lock_count == 0)
2149 state |= M_DELAY_EXEC;
2151 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2152 || selection != SUMMARY_NONE)
2153 state |= M_HIDE_READ_MSG;
2155 if (mainwin->summaryview->threaded)
2156 state |= M_THREADED;
2157 else
2158 state |= M_UNTHREADED;
2159 if (selection == SUMMARY_SELECTED_SINGLE ||
2160 selection == SUMMARY_SELECTED_MULTIPLE)
2161 state |= M_TARGET_EXIST;
2162 if (selection == SUMMARY_SELECTED_SINGLE)
2163 state |= M_SINGLE_TARGET_EXIST;
2164 if (mainwin->summaryview->folder_item &&
2165 mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2166 state |= M_NEWS;
2167 else
2168 state |= M_NOT_NEWS;
2169 if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2170 state |= M_ACTIONS_EXIST;
2172 if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2173 state |= M_HAVE_QUEUED_MAILS;
2175 if (selection == SUMMARY_SELECTED_SINGLE &&
2176 (item &&
2177 (folder_has_parent_of_type(item, F_DRAFT) ||
2178 folder_has_parent_of_type(item, F_OUTBOX) ||
2179 folder_has_parent_of_type(item, F_QUEUE))))
2180 state |= M_ALLOW_REEDIT;
2181 if (cur_account)
2182 state |= M_HAVE_ACCOUNT;
2184 if (any_folder_want_synchronise())
2185 state |= M_WANT_SYNC;
2187 for ( ; account_list != NULL; account_list = account_list->next) {
2188 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2189 state |= M_HAVE_NEWS_ACCOUNT;
2190 break;
2194 if (procmsg_spam_can_learn() &&
2195 (mainwin->summaryview->folder_item &&
2196 mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2197 mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2198 state |= M_CAN_LEARN_SPAM;
2201 if (inc_is_active())
2202 state |= M_INC_ACTIVE;
2204 if (mainwin->summaryview->deleted > 0 ||
2205 mainwin->summaryview->moved > 0 ||
2206 mainwin->summaryview->copied > 0)
2207 state |= M_DELAY_EXEC;
2209 return state;
2214 void main_window_set_menu_sensitive(MainWindow *mainwin)
2216 GtkItemFactory *ifactory = mainwin->menu_factory;
2217 SensitiveCond state;
2218 gboolean sensitive;
2219 GtkWidget *menu;
2220 GtkWidget *menuitem;
2221 SummaryView *summaryview;
2222 gchar *menu_path;
2223 gint i;
2224 GList *cur_item;
2226 static const struct {
2227 gchar *const entry;
2228 SensitiveCond cond;
2229 } entry[] = {
2230 {"/File/Save as...", M_TARGET_EXIST},
2231 {"/File/Print..." , M_TARGET_EXIST},
2232 {"/File/Synchronise folders", M_WANT_SYNC},
2233 {"/File/Exit" , M_UNLOCKED},
2235 {"/Edit/Select thread" , M_SINGLE_TARGET_EXIST},
2236 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2238 {"/View/Set displayed columns/in Folder list..."
2239 , M_UNLOCKED},
2240 {"/View/Sort" , M_EXEC},
2241 {"/View/Thread view" , M_EXEC},
2242 {"/View/Expand all threads" , M_MSG_EXIST},
2243 {"/View/Collapse all threads" , M_MSG_EXIST},
2244 {"/View/Hide read messages" , M_HIDE_READ_MSG},
2245 {"/View/Go to/Previous message" , M_MSG_EXIST},
2246 {"/View/Go to/Next message" , M_MSG_EXIST},
2247 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2248 {"/View/Go to/Previous new message" , M_MSG_EXIST},
2249 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2250 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2251 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2252 {"/View/Go to/Last read message" , M_SINGLE_TARGET_EXIST},
2253 {"/View/Go to/Parent message" , M_SINGLE_TARGET_EXIST},
2254 {"/View/Open in new window" , M_SINGLE_TARGET_EXIST},
2255 {"/View/Message source" , M_SINGLE_TARGET_EXIST},
2256 {"/View/All headers" , M_SINGLE_TARGET_EXIST},
2257 {"/View/Quotes" , M_SINGLE_TARGET_EXIST},
2259 {"/Message/Receive/Get from current account"
2260 , M_HAVE_ACCOUNT|M_UNLOCKED},
2261 {"/Message/Receive/Get from all accounts"
2262 , M_HAVE_ACCOUNT|M_UNLOCKED},
2263 {"/Message/Receive/Cancel receiving"
2264 , M_INC_ACTIVE},
2265 {"/Message/Send queued messages" , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2266 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2267 {"/Message/Reply" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2268 {"/Message/Reply to" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2269 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2270 {"/Message/Forward" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2271 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2272 {"/Message/Redirect" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2273 {"/Message/Move..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2274 {"/Message/Copy..." , M_TARGET_EXIST|M_EXEC},
2275 {"/Message/Move to trash" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2276 {"/Message/Delete..." , M_TARGET_EXIST|M_ALLOW_DELETE},
2277 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2278 {"/Message/Mark" , M_TARGET_EXIST},
2279 {"/Message/Mark/Mark as spam" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2280 {"/Message/Mark/Mark as ham" , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2281 {"/Message/Mark/Ignore thread" , M_TARGET_EXIST},
2282 {"/Message/Mark/Unignore thread" , M_TARGET_EXIST},
2283 {"/Message/Mark/Lock" , M_TARGET_EXIST},
2284 {"/Message/Mark/Unlock" , M_TARGET_EXIST},
2285 {"/Message/Color label" , M_TARGET_EXIST},
2286 {"/Message/Re-edit" , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2288 {"/Tools/Add sender to address book" , M_SINGLE_TARGET_EXIST},
2289 {"/Tools/Harvest addresses" , M_MSG_EXIST},
2290 {"/Tools/Harvest addresses/from Messages..."
2291 , M_TARGET_EXIST},
2292 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2293 {"/Tools/Filter selected messages" , M_TARGET_EXIST|M_EXEC},
2294 {"/Tools/Create filter rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2295 {"/Tools/Create processing rule" , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2296 {"/Tools/Actions" , M_TARGET_EXIST|M_ACTIONS_EXIST},
2297 {"/Tools/Execute" , M_DELAY_EXEC},
2298 {"/Tools/Delete duplicated messages/In selected folder" , M_MSG_EXIST|M_ALLOW_DELETE},
2300 {"/Configuration", M_UNLOCKED},
2302 {NULL, 0}
2305 state = main_window_get_current_state(mainwin);
2307 for (i = 0; entry[i].entry != NULL; i++) {
2308 sensitive = ((entry[i].cond & state) == entry[i].cond);
2309 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2312 menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2314 /* search for separator */
2315 for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2316 cur_item = cur_item->next) {
2317 if (GTK_BIN(cur_item->data)->child == NULL) {
2318 cur_item = cur_item->next;
2319 break;
2323 for (; cur_item != NULL; cur_item = cur_item->next) {
2324 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2325 (M_UNLOCKED & state) != 0);
2328 main_window_menu_callback_block(mainwin);
2330 #define SET_CHECK_MENU_ACTIVE(path, active) \
2332 menuitem = gtk_item_factory_get_widget(ifactory, path); \
2333 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2336 SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2337 messageview_is_visible(mainwin->messageview));
2339 summaryview = mainwin->summaryview;
2340 menu_path = "/View/Sort/Don't sort";
2342 switch (summaryview->sort_key) {
2343 case SORT_BY_NUMBER:
2344 menu_path = "/View/Sort/by number"; break;
2345 case SORT_BY_SIZE:
2346 menu_path = "/View/Sort/by Size"; break;
2347 case SORT_BY_DATE:
2348 menu_path = "/View/Sort/by Date"; break;
2349 case SORT_BY_FROM:
2350 menu_path = "/View/Sort/by From"; break;
2351 case SORT_BY_TO:
2352 menu_path = "/View/Sort/by To"; break;
2353 case SORT_BY_SUBJECT:
2354 menu_path = "/View/Sort/by Subject"; break;
2355 case SORT_BY_LABEL:
2356 menu_path = "/View/Sort/by color label"; break;
2357 case SORT_BY_MARK:
2358 menu_path = "/View/Sort/by mark"; break;
2359 case SORT_BY_STATUS:
2360 menu_path = "/View/Sort/by status"; break;
2361 case SORT_BY_MIME:
2362 menu_path = "/View/Sort/by attachment"; break;
2363 case SORT_BY_SCORE:
2364 menu_path = "/View/Sort/by score"; break;
2365 case SORT_BY_LOCKED:
2366 menu_path = "/View/Sort/by locked"; break;
2367 case SORT_BY_NONE:
2368 default:
2369 menu_path = "/View/Sort/Don't sort"; break;
2371 SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2373 if (summaryview->sort_type == SORT_ASCENDING) {
2374 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2375 } else {
2376 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2379 if (summaryview->sort_key != SORT_BY_NONE) {
2380 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2381 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2382 } else {
2383 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2384 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2387 if (mainwin->messageview
2388 && mainwin->messageview->mimeview
2389 && mainwin->messageview->mimeview->textview)
2390 SET_CHECK_MENU_ACTIVE("/View/All headers",
2391 mainwin->messageview->mimeview->textview->show_all_headers);
2392 SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2393 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2394 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2395 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2396 if (prefs_common.hide_quotes == 1)
2397 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2398 if (prefs_common.hide_quotes == 2)
2399 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2400 if (prefs_common.hide_quotes == 3)
2401 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2403 #undef SET_CHECK_MENU_ACTIVE
2405 main_window_menu_callback_unblock(mainwin);
2408 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2410 GtkItemFactory *ifactory;
2411 gint is_menu = 0;
2412 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2414 if (msginfo)
2415 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2416 if (is_menu)
2417 gtk_widget_set_sensitive (gtk_item_factory_get_item
2418 (ifactory,"/Message/Mailing-List"), TRUE);
2419 else
2420 gtk_widget_set_sensitive (gtk_item_factory_get_item
2421 (ifactory,"/Message/Mailing-List"), FALSE);
2424 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2426 gint menu_nb = 0;
2427 GtkWidget *menuitem;
2429 if (!msginfo || !msginfo->extradata) {
2430 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2431 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2432 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2433 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2434 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2435 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2436 return 0;
2439 /* Mailing list post */
2440 if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2441 g_free(msginfo->extradata->list_post);
2442 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2444 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2446 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2448 /* Mailing list help */
2449 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2451 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2453 /* Mailing list subscribe */
2454 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2456 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2458 /* Mailing list unsubscribe */
2459 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2461 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2463 /* Mailing list view archive */
2464 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2466 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2468 /* Mailing list contact owner */
2469 menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2471 menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2473 return menu_nb;
2476 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2478 GtkWidget *item, *menu;
2479 const gchar *url_pt ;
2480 gchar url_decoded[BUFFSIZE];
2481 GList *amenu, *alist;
2482 gint menu_nb = 0;
2484 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2486 /* First delete old submenu */
2487 /* FIXME: we can optimize this, and only change/add/delete necessary items */
2488 for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2489 alist = amenu->next;
2490 item = GTK_WIDGET (amenu->data);
2491 gtk_widget_destroy (item);
2492 amenu = alist;
2494 if (list_header) {
2495 for (url_pt = list_header; url_pt && *url_pt;) {
2496 get_url_part (&url_pt, url_decoded, BUFFSIZE);
2497 item = NULL;
2498 if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2499 item = gtk_menu_item_new_with_label ((url_decoded));
2500 g_signal_connect(G_OBJECT(item), "activate",
2501 G_CALLBACK(mailing_list_compose),
2502 NULL);
2504 else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2505 !g_strncasecmp (url_decoded, "https:",6)) {
2507 item = gtk_menu_item_new_with_label ((url_decoded));
2508 g_signal_connect(G_OBJECT(item), "activate",
2509 G_CALLBACK(mailing_list_open_uri),
2510 NULL);
2512 if (item) {
2513 gtk_menu_append (GTK_MENU(menu), item);
2514 gtk_widget_show (item);
2515 menu_nb++;
2519 if (menu_nb)
2520 gtk_widget_set_sensitive (menuitem, TRUE);
2521 else
2522 gtk_widget_set_sensitive (menuitem, FALSE);
2525 return menu_nb;
2528 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2530 gchar tmp[BUFFSIZE];
2531 const gchar *buf;
2532 gint i = 0;
2533 buf = *buffer;
2535 if (buf == 0x00) {
2536 *url_decoded = '\0';
2537 *buffer = NULL;
2538 return;
2540 /* Ignore spaces, comments and tabs () */
2541 for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2542 if (*buf == '(')
2543 for (;*buf != ')' && *buf != 0x00; buf++);
2545 /* First non space and non comment must be a < */
2546 if (*buf =='<' ) {
2547 buf++;
2548 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2549 buf++;
2551 else {
2552 *buffer = NULL;
2553 *url_decoded = '\0';
2554 return;
2557 tmp[i] = 0x00;
2558 *url_decoded = '\0';
2559 *buffer = NULL;
2561 if (i == maxlen) {
2562 return;
2564 decode_uri (url_decoded, (const gchar *)tmp);
2566 /* Prepare the work for the next url in the list */
2567 /* after the closing bracket >, ignore space, comments and tabs */
2568 for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2569 if (*buf == '(')
2570 for (;*buf != ')' && *buf != 0x00; buf++);
2572 if (!buf || !*buf) {
2573 *buffer = NULL;
2574 return;
2577 /* now first non space, non comment must be a comma */
2578 if (*buf != ',')
2579 for (;*buf != 0x00; buf++);
2580 else
2581 buf++;
2582 *buffer = buf;
2585 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2587 gchar *mailto;
2589 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2590 compose_new(NULL, mailto+7, NULL);
2593 static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2596 gchar *mailto;
2598 gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2599 open_uri (mailto, prefs_common.uri_cmd);
2602 void main_window_popup(MainWindow *mainwin)
2604 if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2605 main_window_show(mainwin);
2607 gtkut_window_popup(mainwin->window);
2609 switch (mainwin->type) {
2610 case SEPARATE_FOLDER:
2611 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
2612 break;
2613 case SEPARATE_MESSAGE:
2614 gtkut_window_popup(mainwin->win.sep_message.messagewin);
2615 break;
2616 case SEPARATE_BOTH:
2617 gtkut_window_popup(mainwin->win.sep_both.folderwin);
2618 gtkut_window_popup(mainwin->win.sep_both.messagewin);
2619 break;
2620 default:
2621 break;
2625 void main_window_show(MainWindow *mainwin)
2627 gtk_widget_show(mainwin->window);
2628 gtk_widget_show(mainwin->vbox_body);
2630 gtk_widget_set_uposition(mainwin->window,
2631 prefs_common.mainwin_x,
2632 prefs_common.mainwin_y);
2634 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2635 prefs_common.folderview_width,
2636 prefs_common.folderview_height);
2637 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2638 prefs_common.summaryview_width,
2639 prefs_common.summaryview_height);
2640 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2641 prefs_common.msgview_width,
2642 prefs_common.msgview_height);
2644 if (mainwin->type & SEPARATE_FOLDER) {
2645 GtkWidget *folderwin;
2647 folderwin = main_window_get_folder_window(mainwin);
2648 gtk_widget_show(folderwin);
2649 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
2650 prefs_common.folderwin_y);
2653 if (mainwin->type & SEPARATE_MESSAGE) {
2654 GtkWidget *messagewin;
2656 messagewin = main_window_get_message_window(mainwin);
2657 gtk_widget_show(messagewin);
2658 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
2659 prefs_common.main_msgwin_y);
2663 void main_window_hide(MainWindow *mainwin)
2665 main_window_get_size(mainwin);
2666 main_window_get_position(mainwin);
2668 gtk_widget_hide(mainwin->window);
2669 gtk_widget_hide(mainwin->vbox_body);
2671 if (mainwin->type & SEPARATE_FOLDER) {
2672 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2675 if (mainwin->type & SEPARATE_MESSAGE) {
2676 gtk_widget_hide(mainwin->win.sep_message.messagewin);
2680 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
2682 GtkWidget *folderwin = NULL;
2683 GtkWidget *messagewin = NULL;
2684 GtkWidget *hpaned;
2685 GtkWidget *vpaned;
2686 GtkWidget *vbox_body = mainwin->vbox_body;
2687 GtkItemFactory *ifactory = mainwin->menu_factory;
2688 GtkWidget *menuitem;
2689 GtkItemFactory *msgview_ifactory;
2691 debug_print("Setting widgets... ");
2693 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2694 prefs_common.folderview_width,
2695 prefs_common.folderview_height);
2696 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2697 prefs_common.summaryview_width,
2698 prefs_common.summaryview_height);
2699 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2700 prefs_common.msgview_width,
2701 prefs_common.msgview_height);
2703 /* create separated window(s) if needed */
2704 if (type & SEPARATE_FOLDER) {
2705 static GdkGeometry folderwin_geometry;
2707 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2708 gtk_window_set_title(GTK_WINDOW(folderwin),
2709 _("Claws Mail - Folder View"));
2711 gtk_window_move(GTK_WINDOW(folderwin),
2712 prefs_common.folderwin_x,
2713 prefs_common.folderwin_y);
2715 if (!folderwin_geometry.min_height) {
2716 folderwin_geometry.min_width = 320;
2717 folderwin_geometry.min_height = 200;
2719 gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
2720 &folderwin_geometry, GDK_HINT_MIN_SIZE);
2722 gtk_widget_set_size_request(folderwin,
2723 prefs_common.folderview_width,
2724 prefs_common.folderview_height);
2726 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
2727 BORDER_WIDTH);
2729 g_signal_connect(G_OBJECT(folderwin), "delete_event",
2730 G_CALLBACK(folder_window_close_cb),
2731 mainwin);
2732 gtk_container_add(GTK_CONTAINER(folderwin),
2733 GTK_WIDGET_PTR(mainwin->folderview));
2734 gtk_widget_realize(folderwin);
2736 if (prefs_common.folderview_visible)
2737 gtk_widget_show(folderwin);
2740 if (type & SEPARATE_MESSAGE) {
2741 static GdkGeometry msgwin_geometry;
2743 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2744 gtk_window_set_title(GTK_WINDOW(messagewin),
2745 _("Claws Mail - Message View"));
2747 gtk_window_move(GTK_WINDOW(messagewin),
2748 prefs_common.main_msgwin_x,
2749 prefs_common.main_msgwin_y);
2751 if (!msgwin_geometry.min_height) {
2752 msgwin_geometry.min_width = 320;
2753 msgwin_geometry.min_height = 200;
2755 gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
2756 &msgwin_geometry, GDK_HINT_MIN_SIZE);
2758 gtk_widget_set_size_request(messagewin,
2759 prefs_common.msgwin_width,
2760 prefs_common.msgwin_height);
2762 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
2763 BORDER_WIDTH);
2764 g_signal_connect(G_OBJECT(messagewin), "delete_event",
2765 G_CALLBACK(message_window_close_cb),
2766 mainwin);
2767 if (messageview_is_visible(mainwin->messageview))
2768 gtk_widget_show(messagewin);
2769 } else {
2770 mainwin->messageview->statusbar = mainwin->statusbar;
2771 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2774 switch (type) {
2775 case SEPARATE_NONE:
2776 hpaned = gtk_hpaned_new();
2777 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2778 gtk_paned_add1(GTK_PANED(hpaned),
2779 GTK_WIDGET_PTR(mainwin->folderview));
2780 gtk_widget_show(hpaned);
2781 gtk_widget_queue_resize(hpaned);
2783 vpaned = gtk_vpaned_new();
2784 if (messageview_is_visible(mainwin->messageview)) {
2785 gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2786 gtk_paned_add1(GTK_PANED(vpaned),
2787 GTK_WIDGET_PTR(mainwin->summaryview));
2788 } else {
2789 gtk_paned_add2(GTK_PANED(hpaned),
2790 GTK_WIDGET_PTR(mainwin->summaryview));
2791 gtk_widget_ref(vpaned);
2793 gtk_paned_add2(GTK_PANED(vpaned),
2794 GTK_WIDGET_PTR(mainwin->messageview));
2795 gtk_widget_show(vpaned);
2796 gtk_widget_queue_resize(vpaned);
2798 mainwin->win.sep_none.hpaned = hpaned;
2799 mainwin->win.sep_none.vpaned = vpaned;
2801 /* remove headerview if not in prefs */
2802 headerview_set_visibility(mainwin->messageview->headerview,
2803 prefs_common.display_header_pane);
2804 break;
2805 case SEPARATE_FOLDER:
2806 vpaned = gtk_vpaned_new();
2807 if (messageview_is_visible(mainwin->messageview)) {
2808 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
2809 TRUE, TRUE, 0);
2810 gtk_paned_add1(GTK_PANED(vpaned),
2811 GTK_WIDGET_PTR(mainwin->summaryview));
2812 } else {
2813 gtk_box_pack_start(GTK_BOX(vbox_body),
2814 GTK_WIDGET_PTR(mainwin->summaryview),
2815 TRUE, TRUE, 0);
2816 gtk_widget_ref(vpaned);
2818 gtk_paned_add2(GTK_PANED(vpaned),
2819 GTK_WIDGET_PTR(mainwin->messageview));
2820 gtk_widget_show(vpaned);
2821 gtk_widget_queue_resize(vpaned);
2823 mainwin->win.sep_folder.folderwin = folderwin;
2824 mainwin->win.sep_folder.vpaned = vpaned;
2826 /* remove headerview if not in prefs */
2827 headerview_set_visibility(mainwin->messageview->headerview,
2828 prefs_common.display_header_pane);
2830 break;
2831 case SEPARATE_MESSAGE:
2832 hpaned = gtk_hpaned_new();
2833 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2834 gtk_paned_add1(GTK_PANED(hpaned),
2835 GTK_WIDGET_PTR(mainwin->folderview));
2836 gtk_paned_add2(GTK_PANED(hpaned),
2837 GTK_WIDGET_PTR(mainwin->summaryview));
2838 gtk_widget_show(hpaned);
2839 gtk_widget_queue_resize(hpaned);
2840 messageview_add_toolbar(mainwin->messageview, messagewin);
2841 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2842 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2844 mainwin->win.sep_message.messagewin = messagewin;
2845 mainwin->win.sep_message.hpaned = hpaned;
2847 gtk_widget_realize(messagewin);
2848 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2849 gtk_widget_show_all(messagewin);
2850 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2851 mainwin->messageview->handlebox,
2852 prefs_common.toolbar_style);
2854 /* remove headerview if not in prefs */
2855 headerview_set_visibility(mainwin->messageview->headerview,
2856 prefs_common.display_header_pane);
2858 break;
2859 case SEPARATE_BOTH:
2860 messageview_add_toolbar(mainwin->messageview, messagewin);
2861 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2862 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2864 gtk_box_pack_start(GTK_BOX(vbox_body),
2865 GTK_WIDGET_PTR(mainwin->summaryview),
2866 TRUE, TRUE, 0);
2868 mainwin->win.sep_both.folderwin = folderwin;
2869 mainwin->win.sep_both.messagewin = messagewin;
2871 gtk_widget_realize(messagewin);
2872 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2873 gtk_widget_show_all(messagewin);
2874 toolbar_set_style(mainwin->messageview->toolbar->toolbar,
2875 mainwin->messageview->handlebox,
2876 prefs_common.toolbar_style);
2878 /* remove headerview if not in prefs */
2879 headerview_set_visibility(mainwin->messageview->headerview,
2880 prefs_common.display_header_pane);
2882 break;
2885 if (messageview_is_visible(mainwin->messageview))
2886 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2887 GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2888 else
2889 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2890 GTK_ARROW_UP, GTK_SHADOW_OUT);
2892 gtk_window_move(GTK_WINDOW(mainwin->window),
2893 prefs_common.mainwin_x,
2894 prefs_common.mainwin_y);
2896 gtk_widget_queue_resize(vbox_body);
2897 gtk_widget_queue_resize(mainwin->vbox);
2898 gtk_widget_queue_resize(mainwin->window);
2899 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2900 * and mimeview icon list/ctree lose track of their visibility states */
2901 if (!noticeview_is_visible(mainwin->messageview->noticeview))
2902 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2903 if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview))
2904 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2905 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2906 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2907 else
2908 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2910 mainwin->type = type;
2913 /* toggle menu state */
2914 menuitem = gtk_item_factory_get_item
2915 (ifactory, "/View/Show or hide/Folder tree");
2916 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2917 (type & SEPARATE_FOLDER) == 0 ? TRUE :
2918 prefs_common.folderview_visible);
2919 gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2920 menuitem = gtk_item_factory_get_item
2921 (ifactory, "/View/Show or hide/Message view");
2922 gtk_check_menu_item_set_active
2923 (GTK_CHECK_MENU_ITEM(menuitem),
2924 messageview_is_visible(mainwin->messageview));
2926 menuitem = gtk_item_factory_get_item
2927 (ifactory, "/View/Separate folder tree");
2928 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2929 ((type & SEPARATE_FOLDER) != 0));
2930 menuitem = gtk_item_factory_get_item
2931 (ifactory, "/View/Separate message view");
2932 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2933 ((type & SEPARATE_MESSAGE) != 0));
2935 if (folderwin) {
2936 g_signal_connect
2937 (G_OBJECT(folderwin), "size_allocate",
2938 G_CALLBACK(folder_window_size_allocate_cb),
2939 mainwin);
2941 if (messagewin) {
2942 g_signal_connect
2943 (G_OBJECT(messagewin), "size_allocate",
2944 G_CALLBACK(message_window_size_allocate_cb),
2945 mainwin);
2948 debug_print("done.\n");
2951 void main_window_destroy_all(void)
2953 while (mainwin_list != NULL) {
2954 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2956 /* free toolbar stuff */
2957 toolbar_clear_list(TOOLBAR_MAIN);
2958 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2959 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2961 mainwin->folderview->mainwin = NULL;
2962 mainwin->summaryview->mainwin = NULL;
2963 mainwin->messageview->mainwin = NULL;
2965 g_free(mainwin->toolbar);
2966 g_free(mainwin);
2968 mainwin_list = g_list_remove(mainwin_list, mainwin);
2970 g_list_free(mainwin_list);
2971 mainwin_list = NULL;
2974 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2975 gpointer data)
2977 gtk_widget_set_size_request(child, 1, -1);
2980 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2981 gpointer data)
2983 gtk_widget_set_size_request(child, -1, -1);
2986 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2987 gpointer data)
2989 MainWindow *mainwin = (MainWindow *)data;
2991 if (!event) return FALSE;
2993 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2994 g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2995 widget);
2997 gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2998 menu_button_position, widget,
2999 event->button, event->time);
3001 return TRUE;
3004 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3005 gpointer data)
3007 MainWindow *mainwin = (MainWindow *)data;
3009 if (mainwin->lock_count == 0)
3010 app_exit_cb(data, 0, widget);
3012 return TRUE;
3015 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3016 gpointer data)
3018 MainWindow *mainwin = (MainWindow *)data;
3019 GtkWidget *menuitem;
3021 menuitem = gtk_item_factory_get_item
3022 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
3023 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3025 return TRUE;
3028 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3029 gpointer data)
3031 MainWindow *mainwin = (MainWindow *)data;
3032 GtkWidget *menuitem;
3034 menuitem = gtk_item_factory_get_item
3035 (mainwin->menu_factory, "/View/Show or hide/Message view");
3036 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3038 mainwin->messageview->statusbar = mainwin->statusbar;
3039 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
3041 return TRUE;
3044 static void main_window_size_allocate_cb(GtkWidget *widget,
3045 GtkAllocation *allocation,
3046 gpointer data)
3048 MainWindow *mainwin = (MainWindow *)data;
3050 main_window_get_size(mainwin);
3053 static void folder_window_size_allocate_cb(GtkWidget *widget,
3054 GtkAllocation *allocation,
3055 gpointer data)
3057 MainWindow *mainwin = (MainWindow *)data;
3059 main_window_get_size(mainwin);
3062 static void message_window_size_allocate_cb(GtkWidget *widget,
3063 GtkAllocation *allocation,
3064 gpointer data)
3066 MainWindow *mainwin = (MainWindow *)data;
3068 main_window_get_size(mainwin);
3071 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3072 GtkWidget *widget)
3074 main_window_add_mailbox(mainwin);
3077 static void update_folderview_cb(MainWindow *mainwin, guint action,
3078 GtkWidget *widget)
3080 summary_show(mainwin->summaryview, NULL);
3081 folderview_check_new_all();
3084 static void foldersort_cb(MainWindow *mainwin, guint action,
3085 GtkWidget *widget)
3087 foldersort_open();
3090 static void import_mbox_cb(MainWindow *mainwin, guint action,
3091 GtkWidget *widget)
3093 /* only notify if import has failed */
3094 if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3095 alertpanel_error(_("Mbox import has failed."));
3099 static void export_mbox_cb(MainWindow *mainwin, guint action,
3100 GtkWidget *widget)
3102 /* only notify if export has failed */
3103 if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3104 alertpanel_error(_("Export to mbox has failed."));
3108 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3109 GtkWidget *widget)
3111 /* only notify if export has failed */
3112 if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3113 alertpanel_error(_("Export to mbox has failed."));
3117 static void empty_trash_cb(MainWindow *mainwin, guint action,
3118 GtkWidget *widget)
3120 main_window_empty_trash(mainwin, TRUE);
3123 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3125 summary_save_as(mainwin->summaryview);
3128 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3130 summary_print(mainwin->summaryview);
3133 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3135 if (prefs_common.confirm_on_exit) {
3136 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3137 GTK_STOCK_CANCEL, GTK_STOCK_QUIT, NULL)
3138 != G_ALERTALTERNATE)
3139 return;
3140 manage_window_focus_in(mainwin->window, NULL, NULL);
3143 app_will_exit(widget, mainwin);
3146 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3148 if (action == 1)
3149 summary_search(mainwin->summaryview);
3150 else
3151 message_search(mainwin->messageview);
3154 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3156 summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3159 static void toggle_folder_cb(MainWindow *mainwin, guint action,
3160 GtkWidget *widget)
3162 gboolean active;
3164 active = GTK_CHECK_MENU_ITEM(widget)->active;
3166 switch (mainwin->type) {
3167 case SEPARATE_NONE:
3168 case SEPARATE_MESSAGE:
3169 break;
3170 case SEPARATE_FOLDER:
3171 debug_print("separate folder\n");
3172 if (active)
3173 gtk_widget_show(mainwin->win.sep_folder.folderwin);
3174 else
3175 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
3176 break;
3177 case SEPARATE_BOTH:
3178 if (active)
3179 gtk_widget_show(mainwin->win.sep_both.folderwin);
3180 else
3181 gtk_widget_hide(mainwin->win.sep_both.folderwin);
3182 break;
3185 prefs_common.folderview_visible = active;
3188 static void toggle_message_cb(MainWindow *mainwin, guint action,
3189 GtkWidget *widget)
3191 gboolean active;
3193 active = GTK_CHECK_MENU_ITEM(widget)->active;
3195 if (active != messageview_is_visible(mainwin->messageview))
3196 summary_toggle_view(mainwin->summaryview);
3199 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3200 GtkWidget *widget)
3202 toolbar_toggle(action, mainwin);
3205 void main_window_reply_cb(MainWindow *mainwin, guint action,
3206 GtkWidget *widget)
3208 MessageView *msgview = (MessageView*)mainwin->messageview;
3209 GSList *msginfo_list = NULL;
3211 g_return_if_fail(msgview != NULL);
3213 msginfo_list = summary_get_selection(mainwin->summaryview);
3214 g_return_if_fail(msginfo_list != NULL);
3215 compose_reply_from_messageview(msgview, msginfo_list, action);
3216 g_slist_free(msginfo_list);
3220 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3221 GtkWidget *widget)
3223 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3224 gtk_widget_show(mainwin->hbox_stat);
3225 prefs_common.show_statusbar = TRUE;
3226 } else {
3227 gtk_widget_hide(mainwin->hbox_stat);
3228 prefs_common.show_statusbar = FALSE;
3232 static void separate_widget_cb(MainWindow *mainwin, guint action,
3233 GtkWidget *widget)
3235 SeparateType type;
3237 if (GTK_CHECK_MENU_ITEM(widget)->active)
3238 type = mainwin->type | action;
3239 else
3240 type = mainwin->type & ~action;
3242 main_window_separation_change(mainwin, type);
3244 prefs_common.sep_folder = (type & SEPARATE_FOLDER) != 0;
3245 prefs_common.sep_msg = (type & SEPARATE_MESSAGE) != 0;
3248 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3249 gboolean ask_sync)
3251 offline_ask_sync = ask_sync;
3252 if (offline)
3253 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3254 else
3255 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3256 offline_ask_sync = TRUE;
3259 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3261 main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3264 static gboolean any_folder_want_synchronise(void)
3266 GList *folderlist = folder_get_list();
3268 /* see if there are synchronised folders */
3269 for (; folderlist; folderlist = folderlist->next) {
3270 Folder *folder = (Folder *)folderlist->data;
3271 if (folder_want_synchronise(folder)) {
3272 return TRUE;
3276 return FALSE;
3279 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3282 if (!any_folder_want_synchronise())
3283 return;
3285 if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3286 _("Do you want to synchronise your folders now?"),
3287 GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3288 return;
3290 folder_synchronise(NULL);
3293 static void online_switch_clicked (GtkButton *btn, gpointer data)
3295 MainWindow *mainwin;
3296 GtkItemFactory *ifactory;
3297 GtkCheckMenuItem *menuitem;
3299 mainwin = (MainWindow *) data;
3301 ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3302 menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3304 g_return_if_fail(mainwin != NULL);
3305 g_return_if_fail(menuitem != NULL);
3307 if (btn == GTK_BUTTON(mainwin->online_switch)) {
3308 gtk_widget_hide (mainwin->online_switch);
3309 gtk_widget_show (mainwin->offline_switch);
3310 menuitem->active = TRUE;
3311 inc_autocheck_timer_remove();
3313 /* go offline */
3314 if (prefs_common.work_offline)
3315 return;
3316 mainwindow_check_synchronise(mainwin, TRUE);
3317 prefs_common.work_offline = TRUE;
3318 imap_disconnect_all();
3319 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3320 } else {
3321 /*go online */
3322 if (!prefs_common.work_offline)
3323 return;
3324 gtk_widget_hide (mainwin->offline_switch);
3325 gtk_widget_show (mainwin->online_switch);
3326 menuitem->active = FALSE;
3327 prefs_common.work_offline = FALSE;
3328 inc_autocheck_timer_set();
3329 refresh_resolvers();
3330 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3334 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3335 GtkWidget *widget)
3337 addressbook_open(NULL);
3340 static void log_window_show_cb(MainWindow *mainwin, guint action,
3341 GtkWidget *widget)
3343 log_window_show(mainwin->logwin);
3346 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3348 inc_cancel_all();
3351 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3353 summary_move_to(mainwin->summaryview);
3356 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3358 summary_copy_to(mainwin->summaryview);
3361 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3363 summary_delete(mainwin->summaryview);
3366 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3368 summary_delete_trash(mainwin->summaryview);
3371 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3373 summary_cancel(mainwin->summaryview);
3376 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3378 summary_open_msg(mainwin->summaryview);
3381 static void view_source_cb(MainWindow *mainwin, guint action,
3382 GtkWidget *widget)
3384 summary_view_source(mainwin->summaryview);
3387 static void show_all_header_cb(MainWindow *mainwin, guint action,
3388 GtkWidget *widget)
3390 if (mainwin->menu_lock_count) return;
3391 mainwin->summaryview->messageview->all_headers =
3392 GTK_CHECK_MENU_ITEM(widget)->active;
3393 summary_display_msg_selected(mainwin->summaryview,
3394 GTK_CHECK_MENU_ITEM(widget)->active);
3397 #define SET_CHECK_MENU_ACTIVE(path, active) \
3399 menuitem = gtk_item_factory_get_widget(ifactory, path); \
3400 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3403 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3404 GtkWidget *widget)
3406 GtkWidget *menuitem;
3407 GtkItemFactory *ifactory = mainwin->menu_factory;
3409 if (mainwin->menu_lock_count) return;
3411 prefs_common.hide_quotes =
3412 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3414 mainwin->menu_lock_count++;
3415 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3416 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3417 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3418 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3419 mainwin->menu_lock_count--;
3421 summary_redisplay_msg(mainwin->summaryview);
3424 #undef SET_CHECK_MENU_ACTIVE
3425 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3427 summary_mark(mainwin->summaryview);
3430 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3432 summary_unmark(mainwin->summaryview);
3435 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3436 GtkWidget *widget)
3438 summary_mark_as_unread(mainwin->summaryview);
3441 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3442 GtkWidget *widget)
3444 summary_mark_as_read(mainwin->summaryview);
3447 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3448 GtkWidget *widget)
3450 summary_mark_all_read(mainwin->summaryview);
3453 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3454 GtkWidget *widget)
3456 summary_mark_as_spam(mainwin->summaryview, action, NULL);
3459 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3460 GtkWidget *widget)
3462 summary_ignore_thread(mainwin->summaryview);
3465 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3466 GtkWidget *widget)
3468 summary_unignore_thread(mainwin->summaryview);
3471 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3472 GtkWidget *widget)
3474 summary_msgs_lock(mainwin->summaryview);
3477 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3478 GtkWidget *widget)
3480 summary_msgs_unlock(mainwin->summaryview);
3484 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3486 summary_reedit(mainwin->summaryview);
3489 static void add_address_cb(MainWindow *mainwin, guint action,
3490 GtkWidget *widget)
3492 summary_add_address(mainwin->summaryview);
3495 static void set_charset_cb(MainWindow *mainwin, guint action,
3496 GtkWidget *widget)
3498 const gchar *str;
3500 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3501 str = conv_get_charset_str((CharSet)action);
3503 g_free(mainwin->messageview->forced_charset);
3504 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3505 procmime_force_charset(str);
3507 summary_redisplay_msg(mainwin->summaryview);
3509 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3513 static void set_decode_cb(MainWindow *mainwin, guint action,
3514 GtkWidget *widget)
3516 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3517 mainwin->messageview->forced_encoding = (EncodingType)action;
3519 summary_redisplay_msg(mainwin->summaryview);
3521 debug_print("forced encoding: %d\n", action);
3525 static void hide_read_messages (MainWindow *mainwin, guint action,
3526 GtkWidget *widget)
3528 if (!mainwin->summaryview->folder_item
3529 || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3530 return;
3531 summary_toggle_show_read_messages(mainwin->summaryview);
3534 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3536 gboolean threaded = FALSE;
3537 if (mainwin->menu_lock_count) return;
3538 if (!mainwin->summaryview->folder_item) return;
3540 threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3542 mainwin->summaryview->folder_item->threaded = threaded;
3544 mainwin->summaryview->threaded = threaded;
3546 summary_show(mainwin->summaryview,
3547 mainwin->summaryview->folder_item);
3550 static void expand_threads_cb(MainWindow *mainwin, guint action,
3551 GtkWidget *widget)
3553 summary_expand_threads(mainwin->summaryview);
3556 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3557 GtkWidget *widget)
3559 summary_collapse_threads(mainwin->summaryview);
3562 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3563 GtkWidget *widget)
3565 prefs_summary_column_open();
3568 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3569 GtkWidget *widget)
3571 prefs_folder_column_open();
3574 static void sort_summary_cb(MainWindow *mainwin, guint action,
3575 GtkWidget *widget)
3577 FolderItem *item = mainwin->summaryview->folder_item;
3578 GtkWidget *menuitem;
3580 if (mainwin->menu_lock_count) return;
3582 if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3583 menuitem = gtk_item_factory_get_item
3584 (mainwin->menu_factory, "/View/Sort/Ascending");
3585 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3586 GTK_CHECK_MENU_ITEM(menuitem)->active
3587 ? SORT_ASCENDING : SORT_DESCENDING);
3588 item->sort_key = action;
3592 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3593 GtkWidget *widget)
3595 FolderItem *item = mainwin->summaryview->folder_item;
3597 if (mainwin->menu_lock_count) return;
3599 if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3600 summary_sort(mainwin->summaryview,
3601 item->sort_key, (FolderSortType)action);
3604 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3605 GtkWidget *widget)
3607 summary_attract_by_subject(mainwin->summaryview);
3610 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3611 GtkWidget *widget)
3613 FolderItem *item;
3615 item = folderview_get_selected_item(mainwin->folderview);
3616 if (item) {
3617 main_window_cursor_wait(mainwin);
3618 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3620 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3621 DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3623 STATUSBAR_POP(mainwin);
3624 main_window_cursor_normal(mainwin);
3628 struct DelDupsData
3630 guint dups;
3631 guint folders;
3634 static void deldup_all(FolderItem *item, gpointer _data)
3636 struct DelDupsData *data = _data;
3637 gint result;
3639 result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3640 if (result >= 0) {
3641 data->dups += result;
3642 data->folders += 1;
3646 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3647 GtkWidget *widget)
3649 struct DelDupsData data = {0, 0};
3651 main_window_cursor_wait(mainwin);
3652 folder_func_to_all_folders(deldup_all, &data);
3653 main_window_cursor_normal(mainwin);
3655 alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3656 "Deleted %d duplicate messages in %d folders.\n",
3657 data.dups),
3658 data.dups, data.folders);
3661 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3663 summary_filter(mainwin->summaryview, (gboolean)action);
3666 static void execute_summary_cb(MainWindow *mainwin, guint action,
3667 GtkWidget *widget)
3669 summary_execute(mainwin->summaryview);
3672 static void update_summary_cb(MainWindow *mainwin, guint action,
3673 GtkWidget *widget)
3675 FolderItem *fitem;
3676 FolderView *folderview = mainwin->folderview;
3678 if (!mainwin->summaryview->folder_item) return;
3679 if (!folderview->opened) return;
3681 folder_update_op_count();
3683 fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3684 folderview->opened);
3685 if (!fitem) return;
3687 folder_item_scan(fitem);
3688 summary_show(mainwin->summaryview, fitem);
3691 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3693 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3696 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3698 summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3701 static void prev_unread_cb(MainWindow *mainwin, guint action,
3702 GtkWidget *widget)
3704 summary_select_prev_unread(mainwin->summaryview);
3707 static void next_unread_cb(MainWindow *mainwin, guint action,
3708 GtkWidget *widget)
3710 summary_select_next_unread(mainwin->summaryview);
3713 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3715 summary_select_prev_new(mainwin->summaryview);
3718 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3720 summary_select_next_new(mainwin->summaryview);
3723 static void prev_marked_cb(MainWindow *mainwin, guint action,
3724 GtkWidget *widget)
3726 summary_select_prev_marked(mainwin->summaryview);
3729 static void next_marked_cb(MainWindow *mainwin, guint action,
3730 GtkWidget *widget)
3732 summary_select_next_marked(mainwin->summaryview);
3735 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3736 GtkWidget *widget)
3738 summary_select_prev_labeled(mainwin->summaryview);
3741 static void next_labeled_cb(MainWindow *mainwin, guint action,
3742 GtkWidget *widget)
3744 summary_select_next_labeled(mainwin->summaryview);
3747 static void last_read_cb(MainWindow *mainwin, guint action,
3748 GtkWidget *widget)
3750 summary_select_last_read(mainwin->summaryview);
3753 static void parent_cb(MainWindow *mainwin, guint action,
3754 GtkWidget *widget)
3756 summary_select_parent(mainwin->summaryview);
3759 static void goto_folder_cb(MainWindow *mainwin, guint action,
3760 GtkWidget *widget)
3762 FolderItem *to_folder;
3764 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3766 if (to_folder)
3767 folderview_select(mainwin->folderview, to_folder);
3770 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3771 GtkWidget *widget)
3773 folderview_select_next_unread(mainwin->folderview, FALSE);
3776 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3778 messageview_copy_clipboard(mainwin->messageview);
3781 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3783 MessageView *msgview = mainwin->messageview;
3785 if (messageview_is_visible(msgview) &&
3786 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3787 messageview_select_all(mainwin->messageview);
3788 else
3789 summary_select_all(mainwin->summaryview);
3792 static void select_thread_cb(MainWindow *mainwin, guint action,
3793 GtkWidget *widget)
3795 summary_select_thread(mainwin->summaryview);
3798 static void create_filter_cb(MainWindow *mainwin, guint action,
3799 GtkWidget *widget)
3801 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3804 static void create_processing_cb(MainWindow *mainwin, guint action,
3805 GtkWidget *widget)
3807 summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3810 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3811 GtkWidget *widget)
3813 prefs_filtering_open(&pre_global_processing,
3814 _("Processing rules to apply before folder rules"),
3815 MANUAL_ANCHOR_PROCESSING,
3816 NULL, NULL, FALSE);
3819 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3820 GtkWidget *widget)
3822 prefs_filtering_open(&post_global_processing,
3823 _("Processing rules to apply after folder rules"),
3824 MANUAL_ANCHOR_PROCESSING,
3825 NULL, NULL, FALSE);
3828 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3829 GtkWidget *widget)
3831 prefs_filtering_open(&filtering_rules,
3832 _("Filtering configuration"),
3833 MANUAL_ANCHOR_FILTERING,
3834 NULL, NULL, TRUE);
3837 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3838 GtkWidget *widget)
3840 prefs_template_open();
3843 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3844 GtkWidget *widget)
3846 prefs_actions_open(mainwin);
3848 #ifdef USE_OPENSSL
3849 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3850 GtkWidget *widget)
3852 ssl_manager_open(mainwin);
3854 #endif
3855 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3856 GtkWidget *widget)
3858 if (!cur_account) {
3859 new_account_cb(mainwin, 0, widget);
3860 } else {
3861 account_open(cur_account);
3865 static void new_account_cb(MainWindow *mainwin, guint action,
3866 GtkWidget *widget)
3868 account_edit_open();
3869 if (!compose_get_compose_list()) account_add();
3872 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3874 FolderItem *item = NULL;
3875 cur_account = (PrefsAccount *)data;
3877 if (!mainwindow_get_mainwindow())
3878 return;
3879 main_window_show_cur_account(mainwindow_get_mainwindow());
3880 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3881 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3882 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3883 item = folderview_get_selected_item(
3884 mainwindow_get_mainwindow()->folderview);
3885 if (item) {
3886 toolbar_set_compose_button
3887 (mainwindow_get_mainwindow()->toolbar,
3888 FOLDER_TYPE(item->folder) == F_NEWS ?
3889 COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3893 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3895 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3896 PrefsAccount *account = (PrefsAccount *)data;
3898 inc_account_mail(mainwin, account);
3901 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3903 MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3904 PrefsAccount *account = (PrefsAccount *)data;
3905 FolderItem *item = mainwin->summaryview->folder_item;
3907 compose_new_with_folderitem(account, item, NULL);
3910 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3912 prefs_gtk_open();
3915 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3917 pluginwindow_create();
3920 static void manual_open_cb(MainWindow *mainwin, guint action,
3921 GtkWidget *widget)
3923 manual_open((ManualType)action, NULL);
3926 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3928 legend_show();
3931 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3933 MainWindow *mainwin = (MainWindow *)data;
3934 gchar *str;
3936 if (item->path)
3937 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3938 LOCAL_FOLDER(folder)->rootpath,
3939 G_DIR_SEPARATOR,
3940 item->path);
3941 else
3942 str = g_strdup_printf(_("Scanning folder %s ..."),
3943 LOCAL_FOLDER(folder)->rootpath);
3945 STATUSBAR_PUSH(mainwin, str);
3946 STATUSBAR_POP(mainwin);
3947 g_free(str);
3950 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3951 gpointer data)
3953 SummaryView *summary;
3955 g_return_val_if_fail(data, FALSE);
3956 if (!g_list_find(mainwin_list, data))
3957 return TRUE;
3958 summary = ((MainWindow *)data)->summaryview;
3959 g_return_val_if_fail(summary, FALSE);
3961 if (GTK_CLIST(summary->ctree)->selection &&
3962 g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3963 return FALSE;
3965 return FALSE;
3968 #define BREAK_ON_MODIFIER_KEY() \
3969 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3971 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3972 gpointer data)
3974 MainWindow *mainwin = (MainWindow*) data;
3976 if (!mainwin || !event)
3977 return FALSE;
3979 if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3981 lastkey = event->keyval;
3982 return FALSE;
3985 switch (event->keyval) {
3986 case GDK_Q: /* Quit */
3987 BREAK_ON_MODIFIER_KEY();
3989 app_exit_cb(mainwin, 0, NULL);
3990 return FALSE;
3991 case GDK_space:
3992 if (mainwin->folderview && mainwin->summaryview
3993 && ((!mainwin->summaryview->displayed
3994 && !mainwin->summaryview->selected)
3995 || (mainwin->summaryview->folder_item
3996 && mainwin->summaryview->folder_item->total_msgs == 0))) {
3997 g_signal_stop_emission_by_name(G_OBJECT(widget),
3998 "key_press_event");
3999 folderview_select_next_unread(mainwin->folderview, TRUE);
4001 break;
4002 default:
4003 break;
4005 return FALSE;
4008 #undef BREAK_ON_MODIFIER_KEY
4011 * Harvest addresses for selected folder.
4013 static void addr_harvest_cb( MainWindow *mainwin,
4014 guint action,
4015 GtkWidget *widget )
4017 addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4021 * Harvest addresses for selected messages in summary view.
4023 static void addr_harvest_msg_cb( MainWindow *mainwin,
4024 guint action,
4025 GtkWidget *widget )
4027 summary_harvest_address( mainwin->summaryview );
4031 *\brief get a MainWindow
4033 *\return MainWindow * The first mainwindow in the mainwin_list
4035 MainWindow *mainwindow_get_mainwindow(void)
4037 if (mainwin_list && mainwin_list->data)
4038 return (MainWindow *)(mainwin_list->data);
4039 else
4040 return NULL;
4043 gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4045 ProgressData *data = (ProgressData *) source;
4046 MainWindow *mainwin = (MainWindow *) userdata;
4048 switch (data->cmd) {
4049 case PROGRESS_COMMAND_START:
4050 case PROGRESS_COMMAND_STOP:
4051 gtk_progress_bar_set_fraction
4052 (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4053 break;
4054 case PROGRESS_COMMAND_SET_PERCENTAGE:
4055 gtk_progress_bar_set_fraction
4056 (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4057 break;
4059 while (gtk_events_pending()) gtk_main_iteration ();
4061 return FALSE;
4064 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4066 mainwindow_check_synchronise(mainwin, FALSE);
4069 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4071 summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4074 void mainwindow_jump_to(const gchar *target)
4076 gchar *tmp = NULL;
4077 gchar *p = NULL;
4078 FolderItem *item = NULL;
4079 gchar *msg = NULL;
4080 MainWindow *mainwin = mainwindow_get_mainwindow();
4082 if (!target)
4083 return;
4085 if (!mainwin) {
4086 printf("not initialized\n");
4087 return;
4090 tmp = g_strdup(target);
4092 if ((p = strstr(tmp, "\r")) != NULL)
4093 *p = '\0';
4094 if ((p = strstr(tmp, "\n")) != NULL)
4095 *p = '\0';
4097 if ((item = folder_find_item_from_identifier(tmp))) {
4098 printf("selecting folder '%s'\n", tmp);
4099 folderview_select(mainwin->folderview, item);
4100 main_window_popup(mainwin);
4101 g_free(tmp);
4102 return;
4105 msg = strrchr(tmp, G_DIR_SEPARATOR);
4106 if (msg) {
4107 *msg++ = '\0';
4108 if ((item = folder_find_item_from_identifier(tmp))) {
4109 printf("selecting folder '%s'\n", tmp);
4110 folderview_select(mainwin->folderview, item);
4111 } else {
4112 printf("'%s' not found\n", tmp);
4114 if (item && msg && atoi(msg)) {
4115 printf("selecting message %d\n", atoi(msg));
4116 summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4117 summary_display_msg_selected(mainwin->summaryview, FALSE);
4118 main_window_popup(mainwin);
4119 g_free(tmp);
4120 return;
4121 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4122 MsgInfo *msginfo = NULL;
4123 msg++;
4124 msg[strlen(msg)-1] = '\0';
4125 msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4126 if (msginfo) {
4127 printf("selecting message %s\n", msg);
4128 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4129 summary_display_msg_selected(mainwin->summaryview, FALSE);
4130 main_window_popup(mainwin);
4131 g_free(tmp);
4132 procmsg_msginfo_free(msginfo);
4133 return;
4134 } else {
4135 printf("'%s' not found\n", msg);
4137 } else {
4138 printf("'%s' not found\n", msg);
4140 } else {
4141 printf("'%s' not found\n", tmp);
4144 g_free(tmp);