Fix bug #3574: Template addressing
[claws.git] / src / summaryview.c
blobf1353249c3ba4ce57a98b77bb82257829401ce34
1 /*
2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2016 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 3 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, see <http://www.gnu.org/licenses/>.
19 #include "defs.h"
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtk.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
31 #include "main.h"
32 #include "menu.h"
33 #include "mbox.h"
34 #include "mainwindow.h"
35 #include "folderview.h"
36 #include "summaryview.h"
37 #include "messageview.h"
38 #include "mimeview.h"
39 #include "foldersel.h"
40 #include "procmsg.h"
41 #include "procheader.h"
42 #include "sourcewindow.h"
43 #include "prefs_common.h"
44 #include "prefs_summary_column.h"
45 #include "prefs_summary_open.h"
46 #include "prefs_filtering.h"
47 #include "account.h"
48 #include "compose.h"
49 #include "utils.h"
50 #include "gtkutils.h"
51 #include "stock_pixmap.h"
52 #include "filesel.h"
53 #include "alertpanel.h"
54 #include "inputdialog.h"
55 #include "statusbar.h"
56 #include "folder.h"
57 #include "colorlabel.h"
58 #include "inc.h"
59 #include "imap.h"
60 #ifndef USE_ALT_ADDRBOOK
61 #include "addressbook.h"
62 #else
63 #include "addressbook-dbus.h"
64 #include "addressadd.h"
65 #endif
66 #include "addr_compl.h"
67 #include "folder_item_prefs.h"
68 #include "filtering.h"
69 #include "string_match.h"
70 #include "toolbar.h"
71 #include "news.h"
72 #include "hooks.h"
73 #include "description_window.h"
74 #include "folderutils.h"
75 #include "quicksearch.h"
76 #include "partial_download.h"
77 #include "tags.h"
78 #include "timing.h"
79 #include "log.h"
80 #include "edittags.h"
81 #include "manual.h"
82 #include "manage_window.h"
83 #include "avatars.h"
85 #define SUMMARY_COL_MARK_WIDTH 10
86 #define SUMMARY_COL_STATUS_WIDTH 13
87 #define SUMMARY_COL_LOCKED_WIDTH 13
88 #define SUMMARY_COL_MIME_WIDTH 11
90 static int normal_row_height = -1;
91 static GtkStyle *bold_style;
92 static GtkStyle *bold_marked_style;
93 static GtkStyle *bold_deleted_style;
94 static GtkStyle *small_style;
95 static GtkStyle *small_marked_style;
96 static GtkStyle *small_deleted_style;
98 static GdkPixbuf *markxpm;
99 static GdkPixbuf *deletedxpm;
100 static GdkPixbuf *movedxpm;
101 static GdkPixbuf *copiedxpm;
103 static GdkPixbuf *newxpm;
104 static GdkPixbuf *unreadxpm;
105 static GdkPixbuf *repliedxpm;
106 static GdkPixbuf *forwardedxpm;
107 static GdkPixbuf *repliedandforwardedxpm;
108 static GdkPixbuf *ignorethreadxpm;
109 static GdkPixbuf *watchthreadxpm;
110 static GdkPixbuf *lockedxpm;
111 static GdkPixbuf *spamxpm;
113 static GdkPixbuf *clipxpm;
114 static GdkPixbuf *keyxpm;
115 static GdkPixbuf *clipkeyxpm;
116 static GdkPixbuf *keysignxpm;
117 static GdkPixbuf *gpgsignedxpm;
118 static GdkPixbuf *clipgpgsignedxpm;
120 static void summary_free_msginfo_func (GtkCMCTree *ctree,
121 GtkCMCTreeNode *node,
122 gpointer data);
123 static void summary_set_marks_func (GtkCMCTree *ctree,
124 GtkCMCTreeNode *node,
125 gpointer data);
127 void summary_set_menu_sensitive (SummaryView *summaryview);
128 guint summary_get_msgnum (SummaryView *summaryview,
129 GtkCMCTreeNode *node);
132 static void summary_set_hide_menu (SummaryView *summaryview,
133 const gchar *menu_item,
134 guint action);
136 static GtkCMCTreeNode *summary_find_prev_msg
137 (SummaryView *summaryview,
138 GtkCMCTreeNode *current_node,
139 gboolean start_from_prev);
140 static GtkCMCTreeNode *summary_find_next_msg
141 (SummaryView *summaryview,
142 GtkCMCTreeNode *current_node,
143 gboolean start_from_next);
145 static GtkCMCTreeNode *summary_find_prev_flagged_msg
146 (SummaryView *summaryview,
147 GtkCMCTreeNode *current_node,
148 MsgPermFlags flags,
149 gboolean start_from_prev);
150 static GtkCMCTreeNode *summary_find_next_flagged_msg
151 (SummaryView *summaryview,
152 GtkCMCTreeNode *current_node,
153 MsgPermFlags flags,
154 gboolean start_from_next);
156 static GtkCMCTreeNode *summary_find_msg_by_msgnum
157 (SummaryView *summaryview,
158 guint msgnum);
160 static void summary_update_status (SummaryView *summaryview);
162 /* display functions */
163 static void summary_status_show (SummaryView *summaryview);
164 static void summary_set_column_titles (SummaryView *summaryview);
165 static void summary_set_ctree_from_list (SummaryView *summaryview,
166 GSList *mlist);
167 static inline void summary_set_header (SummaryView *summaryview,
168 gchar *text[],
169 MsgInfo *msginfo);
170 static void summary_display_msg (SummaryView *summaryview,
171 GtkCMCTreeNode *row);
172 static void summary_display_msg_full (SummaryView *summaryview,
173 GtkCMCTreeNode *row,
174 gboolean new_window,
175 gboolean all_headers);
176 static void summary_set_row_marks (SummaryView *summaryview,
177 GtkCMCTreeNode *row);
179 static gboolean summary_set_row_tag (SummaryView *summaryview,
180 GtkCMCTreeNode *row,
181 gboolean refresh,
182 gboolean set,
183 gint id);
184 /* message handling */
185 static void summary_mark_row (SummaryView *summaryview,
186 GtkCMCTreeNode *row);
187 static void summary_lock_row (SummaryView *summaryview,
188 GtkCMCTreeNode *row);
189 static void summary_unlock_row (SummaryView *summaryview,
190 GtkCMCTreeNode *row);
191 static void summary_mark_row_as_read (SummaryView *summaryview,
192 GtkCMCTreeNode *row);
193 static void summary_mark_row_as_unread (SummaryView *summaryview,
194 GtkCMCTreeNode *row);
195 static void summary_delete_row (SummaryView *summaryview,
196 GtkCMCTreeNode *row);
197 static void summary_unmark_row (SummaryView *summaryview,
198 GtkCMCTreeNode *row);
199 static void summary_move_row_to (SummaryView *summaryview,
200 GtkCMCTreeNode *row,
201 FolderItem *to_folder);
202 static void summary_copy_row_to (SummaryView *summaryview,
203 GtkCMCTreeNode *row,
204 FolderItem *to_folder);
206 static gint summary_execute_move (SummaryView *summaryview);
207 static void summary_execute_move_func (GtkCMCTree *ctree,
208 GtkCMCTreeNode *node,
209 gpointer data);
210 static void summary_execute_copy (SummaryView *summaryview);
211 static void summary_execute_copy_func (GtkCMCTree *ctree,
212 GtkCMCTreeNode *node,
213 gpointer data);
214 static void summary_execute_delete (SummaryView *summaryview);
215 static void summary_execute_delete_func (GtkCMCTree *ctree,
216 GtkCMCTreeNode *node,
217 gpointer data);
218 static void summary_execute_expunge (SummaryView *summaryview);
220 static void summary_thread_init (SummaryView *summaryview);
222 static void summary_unthread_for_exec (SummaryView *summaryview);
223 static void summary_unthread_for_exec_func (GtkCMCTree *ctree,
224 GtkCMCTreeNode *node,
225 gpointer data);
227 void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
228 GSList * mlist);
230 static void summary_filter_func (MsgInfo *msginfo);
232 static void summary_colorlabel_menu_item_activate_cb
233 (GtkWidget *widget,
234 gpointer data);
235 static void summary_colorlabel_menu_item_activate_item_cb
236 (GtkMenuItem *label_menu_item,
237 gpointer data);
238 static void summary_colorlabel_menu_create(SummaryView *summaryview,
239 gboolean refresh);
240 static void summary_tags_menu_item_activate_cb
241 (GtkWidget *widget,
242 gpointer data);
243 static void summary_tags_menu_item_activate_item_cb
244 (GtkMenuItem *label_menu_item,
245 gpointer data);
246 static void summary_tags_menu_create(SummaryView *summaryview,
247 gboolean refresh);
249 static GtkWidget *summary_ctree_create (SummaryView *summaryview);
251 /* callback functions */
252 static gint summary_toggle_pressed (GtkWidget *eventbox,
253 GdkEventButton *event,
254 SummaryView *summaryview);
255 #ifdef GENERIC_UMPC
256 static void summary_toggle_multiple_pressed
257 (GtkWidget *widget,
258 SummaryView *summaryview);
259 #endif
260 static gint summary_folder_eventbox_pressed
261 (GtkWidget *eventbox,
262 GdkEventButton *event,
263 SummaryView *summaryview);
264 static gboolean summary_button_pressed (GtkWidget *ctree,
265 GdkEventButton *event,
266 SummaryView *summaryview);
267 static gboolean summary_button_released (GtkWidget *ctree,
268 GdkEventButton *event,
269 SummaryView *summaryview);
270 static gboolean summary_key_pressed (GtkWidget *ctree,
271 GdkEventKey *event,
272 SummaryView *summaryview);
273 static void summary_tree_expanded (GtkCMCTree *ctree,
274 GtkCMCTreeNode *node,
275 SummaryView *summaryview);
276 static void summary_tree_collapsed (GtkCMCTree *ctree,
277 GtkCMCTreeNode *node,
278 SummaryView *summaryview);
279 static void summary_selected (GtkCMCTree *ctree,
280 GtkCMCTreeNode *row,
281 gint column,
282 SummaryView *summaryview);
283 static void summary_unselected (GtkCMCTree *ctree,
284 GtkCMCTreeNode *row,
285 gint column,
286 SummaryView *summaryview);
287 static void summary_col_resized (GtkCMCList *clist,
288 gint column,
289 gint width,
290 SummaryView *summaryview);
291 static void summary_mark_clicked (GtkWidget *button,
292 SummaryView *summaryview);
293 static void summary_status_clicked (GtkWidget *button,
294 SummaryView *summaryview);
295 static void summary_mime_clicked (GtkWidget *button,
296 SummaryView *summaryview);
297 static void summary_num_clicked (GtkWidget *button,
298 SummaryView *summaryview);
299 static void summary_score_clicked (GtkWidget *button,
300 SummaryView *summaryview);
301 static void summary_size_clicked (GtkWidget *button,
302 SummaryView *summaryview);
303 static void summary_date_clicked (GtkWidget *button,
304 SummaryView *summaryview);
305 static void summary_from_clicked (GtkWidget *button,
306 SummaryView *summaryview);
307 static void summary_to_clicked (GtkWidget *button,
308 SummaryView *summaryview);
309 static void summary_subject_clicked (GtkWidget *button,
310 SummaryView *summaryview);
311 static void summary_score_clicked (GtkWidget *button,
312 SummaryView *summaryview);
313 static void summary_locked_clicked (GtkWidget *button,
314 SummaryView *summaryview);
315 static void summary_tags_clicked (GtkWidget *button,
316 SummaryView *summaryview);
318 static void summary_start_drag (GtkWidget *widget,
319 int button,
320 GdkEvent *event,
321 SummaryView *summaryview);
322 static void summary_drag_data_get (GtkWidget *widget,
323 GdkDragContext *drag_context,
324 GtkSelectionData *selection_data,
325 guint info,
326 guint time,
327 SummaryView *summaryview);
328 static void summary_drag_data_received(GtkWidget *widget,
329 GdkDragContext *drag_context,
330 gint x,
331 gint y,
332 GtkSelectionData *data,
333 guint info,
334 guint time,
335 SummaryView *summaryview);
336 static gboolean summary_drag_motion_cb(GtkWidget *widget,
337 GdkDragContext *context,
338 gint x,
339 gint y,
340 guint time,
341 SummaryView *summaryview);
342 static void summary_drag_end(GtkWidget *widget,
343 GdkDragContext *drag_context,
344 SummaryView *summaryview);
345 /* custom compare functions for sorting */
347 static gint summary_cmp_by_mark (GtkCMCList *clist,
348 gconstpointer ptr1,
349 gconstpointer ptr2);
350 static gint summary_cmp_by_status (GtkCMCList *clist,
351 gconstpointer ptr1,
352 gconstpointer ptr2);
353 static gint summary_cmp_by_mime (GtkCMCList *clist,
354 gconstpointer ptr1,
355 gconstpointer ptr2);
356 static gint summary_cmp_by_num (GtkCMCList *clist,
357 gconstpointer ptr1,
358 gconstpointer ptr2);
359 static gint summary_cmp_by_size (GtkCMCList *clist,
360 gconstpointer ptr1,
361 gconstpointer ptr2);
362 static gint summary_cmp_by_date (GtkCMCList *clist,
363 gconstpointer ptr1,
364 gconstpointer ptr2);
365 static gint summary_cmp_by_thread_date (GtkCMCList *clist,
366 gconstpointer ptr1,
367 gconstpointer ptr2);
368 static gint summary_cmp_by_from (GtkCMCList *clist,
369 gconstpointer ptr1,
370 gconstpointer ptr2);
371 static gint summary_cmp_by_simplified_subject
372 (GtkCMCList *clist,
373 gconstpointer ptr1,
374 gconstpointer ptr2);
375 static gint summary_cmp_by_score (GtkCMCList *clist,
376 gconstpointer ptr1,
377 gconstpointer ptr2);
378 static gint summary_cmp_by_label (GtkCMCList *clist,
379 gconstpointer ptr1,
380 gconstpointer ptr2);
381 static gint summary_cmp_by_to (GtkCMCList *clist,
382 gconstpointer ptr1,
383 gconstpointer ptr2);
384 static gint summary_cmp_by_subject (GtkCMCList *clist,
385 gconstpointer ptr1,
386 gconstpointer ptr2);
387 static gint summary_cmp_by_locked (GtkCMCList *clist,
388 gconstpointer ptr1,
389 gconstpointer ptr2);
390 static gint summary_cmp_by_tags (GtkCMCList *clist,
391 gconstpointer ptr1,
392 gconstpointer ptr2);
394 static void quicksearch_execute_cb (QuickSearch *quicksearch,
395 gpointer data);
397 static void tog_searchbar_cb (GtkWidget *w,
398 gpointer data);
400 static void summary_find_answers (SummaryView *summaryview,
401 MsgInfo *msg);
403 static gboolean summary_update_msg (gpointer source, gpointer data);
404 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data);
405 static gboolean summary_update_folder_hook(gpointer source, gpointer data);
406 static void summary_set_colorlabel_color (GtkCMCTree *ctree,
407 GtkCMCTreeNode *node,
408 guint labelcolor);
409 static void summary_thread_build(SummaryView *summaryview);
411 GtkTargetEntry summary_drag_types[3] =
413 {"text/uri-list", 0, TARGET_MAIL_URI_LIST},
414 {"claws-mail/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY},
415 {"claws-mail/msg-path-list", 0, TARGET_MAIL_CM_PATH_LIST},
418 #define DO_ACTION(name, act) { \
419 if(!strcmp(name, a_name)) { \
420 act; \
424 static GtkActionEntry summary_popup_entries[] =
426 {"SummaryViewPopup", NULL, "SummaryViewPopup" },
427 {"SummaryViewPopup/ReplyTo", NULL, N_("Repl_y to") },
428 {"SummaryViewPopup/Mark", NULL, N_("_Mark") },
429 {"SummaryViewPopup/ColorLabel", NULL, N_("Color la_bel") },
430 {"SummaryViewPopup/Tags", NULL, N_("Ta_gs") },
431 {"SummaryViewPopup/CreateFilterRule", NULL, N_("Create _filter rule") },
432 #ifndef GENERIC_UMPC
433 {"SummaryViewPopup/CreateProcessingRule", NULL, N_("Create processing rule") },
434 #endif
435 {"SummaryViewPopup/View", NULL, N_("_View") },
438 static const gchar *const col_label[N_SUMMARY_COLS] = {
439 "", /* S_COL_MARK */
440 N_("S"), /* S_COL_STATUS */
441 "", /* S_COL_MIME */
442 N_("Subject"), /* S_COL_SUBJECT */
443 N_("From"), /* S_COL_FROM */
444 N_("To"), /* S_COL_TO */
445 N_("Date"), /* S_COL_DATE */
446 N_("Size"), /* S_COL_SIZE */
447 N_("#"), /* S_COL_NUMBER */
448 N_("Score"), /* S_COL_SCORE */
449 "", /* S_COL_LOCKED */
450 N_("Tags"), /* S_COL_TAGS */
453 void summary_freeze(SummaryView *summaryview)
455 if (summaryview)
456 gtk_cmclist_freeze(GTK_CMCLIST(summaryview->ctree));
459 void summary_thaw(SummaryView *summaryview)
461 if (summaryview)
462 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
465 void summary_thaw_with_status(SummaryView *summaryview)
467 if (summaryview) {
468 summary_status_show(summaryview);
469 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
473 void summary_grab_focus(SummaryView *summaryview)
475 if (summaryview)
476 gtk_widget_grab_focus(summaryview->ctree);
479 GtkWidget *summary_get_main_widget(SummaryView *summaryview)
481 if (summaryview)
482 return summaryview->ctree;
483 else
484 return NULL;
487 #define START_LONG_OPERATION(summaryview,force_freeze) { \
488 summary_lock(summaryview); \
489 main_window_cursor_wait(summaryview->mainwin); \
490 if (force_freeze || sc_g_list_bigger(GTK_CMCLIST(summaryview->ctree)->selection, 1)) {\
491 froze = TRUE; \
492 summary_freeze(summaryview); \
494 folder_item_update_freeze(); \
495 inc_lock(); \
496 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST, \
497 summaryview->msginfo_update_callback_id); \
499 #define END_LONG_OPERATION(summaryview) { \
500 inc_unlock(); \
501 folder_item_update_thaw(); \
502 if (froze) \
503 summary_thaw(summaryview); \
504 main_window_cursor_normal(summaryview->mainwin); \
505 summary_unlock(summaryview); \
506 summaryview->msginfo_update_callback_id = \
507 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, \
508 summary_update_msg, (gpointer) summaryview); \
511 SummaryView *summary_create(MainWindow *mainwin)
513 SummaryView *summaryview;
514 GtkWidget *vbox;
515 GtkWidget *scrolledwin;
516 GtkWidget *ctree;
517 GtkWidget *hbox;
518 GtkWidget *hbox_l;
519 GtkWidget *stat_box;
520 GtkWidget *stat_box2;
521 GtkWidget *stat_vbox;
522 GtkWidget *statlabel_folder;
523 GtkWidget *statlabel_select;
524 GtkWidget *statlabel_msgs;
525 GtkWidget *hbox_spc;
526 GtkWidget *toggle_eventbox;
527 #ifdef GENERIC_UMPC
528 GtkWidget *multiple_sel_togbtn;
529 #endif
530 GtkWidget *toggle_arrow;
531 GtkWidget *toggle_search;
532 QuickSearch *quicksearch;
534 debug_print("Creating summary view...\n");
535 summaryview = g_new0(SummaryView, 1);
537 #define SUMMARY_VBOX_SPACING 3
538 vbox = gtk_vbox_new(FALSE, SUMMARY_VBOX_SPACING);
540 /* create status label */
541 hbox = gtk_hbox_new(FALSE, 0);
542 gtk_widget_show(hbox);
544 stat_vbox = gtk_vbox_new(FALSE, 0);
545 gtk_widget_show(stat_vbox);
547 stat_box = gtk_hbox_new(FALSE, 0);
548 gtk_widget_show(stat_box);
550 stat_box2 = gtk_hbox_new(FALSE, 0);
551 gtk_widget_show(stat_box2);
553 toggle_search = gtk_toggle_button_new();
554 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_search),
555 prefs_common.show_searchbar);
556 gtkut_widget_set_can_focus(toggle_search, FALSE);
557 gtk_widget_show(toggle_search);
559 CLAWS_SET_TIP(toggle_search, _("Toggle quick search bar"));
561 gtk_box_pack_start(GTK_BOX(hbox), toggle_search, FALSE, FALSE, 2);
563 gtk_box_pack_start(GTK_BOX(hbox), stat_vbox, TRUE, TRUE, 0);
564 gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box, TRUE, TRUE, 0);
565 gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box2, TRUE, TRUE, 0);
567 hbox_l = gtk_hbox_new(FALSE, 0);
568 gtk_widget_show(hbox_l);
569 gtk_box_pack_start(GTK_BOX(stat_box), hbox_l, TRUE, TRUE, 0);
571 statlabel_folder = gtk_label_new("");
572 gtk_widget_show(statlabel_folder);
573 gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_folder, FALSE, FALSE, 2);
574 statlabel_select = gtk_label_new("");
575 gtk_widget_show(statlabel_select);
576 gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_select, FALSE, FALSE, 12);
578 /* toggle view button */
579 toggle_eventbox = gtk_event_box_new();
580 gtk_widget_show(toggle_eventbox);
582 gtk_box_pack_end(GTK_BOX(hbox), toggle_eventbox, FALSE, FALSE, 4);
584 toggle_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
585 gtk_widget_show(toggle_arrow);
586 gtk_container_add(GTK_CONTAINER(toggle_eventbox), toggle_arrow);
587 g_signal_connect(G_OBJECT(toggle_eventbox), "button_press_event",
588 G_CALLBACK(summary_toggle_pressed),
589 summaryview);
591 #ifdef GENERIC_UMPC
592 multiple_sel_togbtn = gtk_toggle_button_new();
593 gtk_widget_show(multiple_sel_togbtn);
594 gtk_box_pack_end(GTK_BOX(hbox), multiple_sel_togbtn, FALSE, FALSE, 4);
595 CLAWS_SET_TIP(multiple_sel_togbtn,
596 _("Toggle multiple selection"));
597 g_signal_connect(G_OBJECT(multiple_sel_togbtn), "toggled",
598 G_CALLBACK(summary_toggle_multiple_pressed),
599 summaryview);
600 #endif
602 statlabel_msgs = gtk_label_new("");
603 gtk_widget_show(statlabel_msgs);
604 gtk_box_pack_end(GTK_BOX(stat_box), statlabel_msgs, FALSE, FALSE, 4);
606 hbox_spc = gtk_hbox_new(FALSE, 0);
607 gtk_widget_show(hbox_spc);
608 gtk_box_pack_end(GTK_BOX(hbox), hbox_spc, FALSE, FALSE, 6);
610 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
611 gtk_widget_show(scrolledwin);
612 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
613 GTK_POLICY_AUTOMATIC,
614 GTK_POLICY_AUTOMATIC);
615 summaryview->mainwidget_book = gtk_notebook_new();
616 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
617 gtk_notebook_set_show_border(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
618 #ifndef GENERIC_UMPC
619 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
620 scrolledwin);
621 gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
622 #endif
623 gtk_widget_set_size_request(vbox,
624 prefs_common.summaryview_width,
625 prefs_common.summaryview_height);
627 ctree = summary_ctree_create(summaryview);
628 gtk_widget_show(ctree);
630 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
631 GTK_CMCLIST(ctree)->hadjustment);
632 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
633 GTK_CMCLIST(ctree)->vadjustment);
634 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
636 /* status label */
637 gtk_widget_show_all(stat_vbox);
638 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
640 /* quick search */
641 quicksearch = quicksearch_new();
642 gtk_box_pack_start(GTK_BOX(vbox), quicksearch_get_widget(quicksearch), FALSE, FALSE, 0);
644 #ifdef GENERIC_UMPC
645 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
646 scrolledwin);
647 gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
648 #endif
649 quicksearch_set_execute_callback(quicksearch, quicksearch_execute_cb, summaryview);
651 g_signal_connect (G_OBJECT(toggle_search), "toggled",
652 G_CALLBACK(tog_searchbar_cb), summaryview);
654 /* create popup menu */
656 gtk_action_group_add_actions(mainwin->action_group, summary_popup_entries,
657 G_N_ELEMENTS(summary_popup_entries), (gpointer)summaryview);
659 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
660 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus", "SummaryViewPopup", "SummaryViewPopup", GTK_UI_MANAGER_MENU)
661 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
662 #ifndef GENERIC_UMPC
663 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ReplyTo", "SummaryViewPopup/ReplyTo", GTK_UI_MANAGER_MENU)
664 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
665 #endif
666 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
667 #ifndef GENERIC_UMPC
668 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
669 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
670 #endif
671 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
672 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
673 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
674 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
675 #ifndef GENERIC_UMPC
676 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
677 #endif
678 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
679 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Mark", "SummaryViewPopup/Mark", GTK_UI_MANAGER_MENU)
680 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ColorLabel", "SummaryViewPopup/ColorLabel", GTK_UI_MANAGER_MENU)
681 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Tags", "SummaryViewPopup/Tags", GTK_UI_MANAGER_MENU)
683 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
684 #ifndef GENERIC_UMPC
685 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
686 #endif
687 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateFilterRule", "SummaryViewPopup/CreateFilterRule", GTK_UI_MANAGER_MENU)
688 #ifndef GENERIC_UMPC
689 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateProcessingRule", "SummaryViewPopup/CreateProcessingRule", GTK_UI_MANAGER_MENU)
690 #endif
691 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
692 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "View", "SummaryViewPopup/View", GTK_UI_MANAGER_MENU)
693 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
694 #ifndef GENERIC_UMPC
695 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
696 #endif
697 /* last separator, for plugins */
698 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
700 /* submenus - replyto */
701 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
702 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
703 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "MailingList", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
705 /* submenus - mark */
706 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
707 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
708 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
709 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
710 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
711 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
712 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
713 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
714 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
715 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
716 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
717 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
718 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator4", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
719 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
720 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
721 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator5", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
722 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
723 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
725 /* submenus - colorlabel and tags are dynamic */
726 /* submenus - createfilterrule */
727 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
728 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
729 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
730 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
732 #ifndef GENERIC_UMPC
733 /* submenus - createprocessingrule */
734 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
735 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
736 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
737 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
738 #endif
740 /* submenus - view */
741 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
742 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
743 #ifndef GENERIC_UMPC
744 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
745 #endif
746 summaryview->popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
747 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menus/SummaryViewPopup")) );
750 summaryview->vbox = vbox;
751 summaryview->scrolledwin = scrolledwin;
752 summaryview->ctree = ctree;
753 summaryview->hbox = hbox;
754 summaryview->hbox_l = hbox_l;
755 summaryview->hbox_spc = hbox_spc;
756 summaryview->stat_box = stat_box;
757 summaryview->stat_box2 = stat_box2;
758 summaryview->statlabel_folder = statlabel_folder;
759 summaryview->statlabel_select = statlabel_select;
760 summaryview->statlabel_msgs = statlabel_msgs;
761 summaryview->toggle_eventbox = toggle_eventbox;
762 summaryview->toggle_arrow = toggle_arrow;
763 #ifdef GENERIC_UMPC
764 summaryview->multiple_sel_togbtn = multiple_sel_togbtn;
765 #endif
766 summaryview->toggle_search = toggle_search;
767 summaryview->lock_count = 0;
768 summaryview->msginfo_update_callback_id =
769 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, summary_update_msg, (gpointer) summaryview);
770 summaryview->folder_item_update_callback_id =
771 hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST,
772 summary_update_folder_item_hook,
773 (gpointer) summaryview);
774 summaryview->folder_update_callback_id =
775 hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
776 summary_update_folder_hook,
777 (gpointer) summaryview);
779 summaryview->target_list = gtk_target_list_new(summary_drag_types, 3);
781 summaryview->quicksearch = quicksearch;
783 /* CLAWS: need this to get the SummaryView * from
784 * the CList */
785 g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview);
787 gtk_widget_show_all(vbox);
789 gtk_widget_show(vbox);
791 if (prefs_common.show_searchbar)
792 quicksearch_show(quicksearch);
793 else
794 quicksearch_hide(quicksearch);
796 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
797 prefs_common.layout_mode == SMALL_LAYOUT)
798 gtk_widget_hide(summaryview->toggle_eventbox);
800 return summaryview;
803 void summary_relayout(SummaryView *summaryview)
805 gtk_widget_realize(summaryview->stat_box);
807 g_object_ref(summaryview->hbox_l);
808 g_object_ref(summaryview->statlabel_msgs);
810 gtkut_container_remove(GTK_CONTAINER(
811 gtk_widget_get_parent(summaryview->hbox_l)), summaryview->hbox_l);
812 gtkut_container_remove(GTK_CONTAINER(
813 gtk_widget_get_parent(summaryview->statlabel_msgs)), summaryview->statlabel_msgs);
815 switch (prefs_common.layout_mode) {
816 case NORMAL_LAYOUT:
817 case WIDE_LAYOUT:
818 case WIDE_MSGLIST_LAYOUT:
819 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
820 gtk_box_pack_end(GTK_BOX(summaryview->stat_box), summaryview->statlabel_msgs, FALSE, FALSE, 4);
821 gtk_widget_show_all(summaryview->stat_box);
822 gtk_widget_show_all(summaryview->stat_box2);
823 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
824 prefs_common.layout_mode == SMALL_LAYOUT)
825 gtk_widget_hide(summaryview->toggle_eventbox);
826 else
827 gtk_widget_show(summaryview->toggle_eventbox);
828 break;
829 case VERTICAL_LAYOUT:
830 case SMALL_LAYOUT:
831 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
832 gtk_box_pack_start(GTK_BOX(summaryview->stat_box2), summaryview->statlabel_msgs, FALSE, FALSE, 4);
833 gtk_widget_show_all(summaryview->stat_box);
834 gtk_widget_show_all(summaryview->stat_box2);
835 if (prefs_common.layout_mode == SMALL_LAYOUT) {
836 gtk_widget_hide(summaryview->toggle_eventbox);
837 gtk_widget_hide(summaryview->statlabel_msgs);
838 } else {
839 gtk_widget_show(summaryview->toggle_eventbox);
840 gtk_widget_show(summaryview->statlabel_msgs);
843 break;
845 summary_set_column_order(summaryview);
847 g_object_unref(summaryview->hbox_l);
848 g_object_unref(summaryview->statlabel_msgs);
849 quicksearch_relayout(summaryview->quicksearch);
850 if (prefs_common.show_searchbar)
851 quicksearch_show(summaryview->quicksearch);
852 else
853 quicksearch_hide(summaryview->quicksearch);
856 static void summary_set_fonts(SummaryView *summaryview)
858 PangoFontDescription *font_desc;
859 gint size;
861 font_desc = pango_font_description_from_string(NORMAL_FONT);
862 if (font_desc) {
863 gtk_widget_modify_font(summaryview->ctree, font_desc);
864 pango_font_description_free(font_desc);
867 if (!bold_style) {
868 bold_style = gtk_style_copy
869 (gtk_widget_get_style(summaryview->ctree));
871 if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
872 font_desc = pango_font_description_from_string(NORMAL_FONT);
873 if (font_desc) {
874 pango_font_description_free(bold_style->font_desc);
875 bold_style->font_desc = font_desc;
877 pango_font_description_set_weight
878 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
879 } else {
880 font_desc = pango_font_description_from_string(BOLD_FONT);
881 if (font_desc) {
882 pango_font_description_free(bold_style->font_desc);
883 bold_style->font_desc = font_desc;
886 bold_marked_style = gtk_style_copy(bold_style);
887 bold_marked_style->fg[GTK_STATE_NORMAL] =
888 summaryview->color_marked;
889 bold_deleted_style = gtk_style_copy(bold_style);
890 bold_deleted_style->fg[GTK_STATE_NORMAL] =
891 summaryview->color_dim;
894 if (prefs_common.derive_from_normal_font || !SMALL_FONT) {
895 font_desc = pango_font_description_new();
896 size = pango_font_description_get_size
897 (gtk_widget_get_style(summaryview->ctree)->font_desc);
898 pango_font_description_set_size(font_desc, size * PANGO_SCALE_SMALL);
899 } else {
900 font_desc = pango_font_description_from_string(SMALL_FONT);
902 if (font_desc) {
903 gtk_widget_modify_font(summaryview->statlabel_folder, font_desc);
904 gtk_widget_modify_font(summaryview->statlabel_select, font_desc);
905 gtk_widget_modify_font(summaryview->statlabel_msgs, font_desc);
906 pango_font_description_free(font_desc);
911 static void summary_set_folder_pixmap(SummaryView *summaryview, StockPixmap icon)
913 GtkWidget *pixmap;
914 if (!summaryview->folder_pixmap_eventbox) {
915 summaryview->folder_pixmap_eventbox = gtk_event_box_new();
916 gtk_widget_show(summaryview->folder_pixmap_eventbox);
917 gtk_box_pack_start(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, FALSE, FALSE, 4);
918 gtk_box_reorder_child(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, 0); /* search_toggle before */
919 g_signal_connect(G_OBJECT(summaryview->folder_pixmap_eventbox), "button_press_event",
920 G_CALLBACK(summary_folder_eventbox_pressed),
921 summaryview);
923 if (summaryview->folder_pixmap)
924 gtk_widget_destroy(summaryview->folder_pixmap);
926 pixmap = stock_pixmap_widget(icon);
927 gtk_container_add(GTK_CONTAINER(summaryview->folder_pixmap_eventbox), pixmap);
928 gtk_widget_show(pixmap);
929 summaryview->folder_pixmap = pixmap;
932 void summary_init(SummaryView *summaryview)
934 GtkWidget *pixmap;
936 gtk_widget_realize(summaryview->ctree);
937 stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm);
938 stock_pixbuf_gdk(STOCK_PIXMAP_DELETED, &deletedxpm);
939 stock_pixbuf_gdk(STOCK_PIXMAP_NEW, &newxpm);
940 stock_pixbuf_gdk(STOCK_PIXMAP_UNREAD, &unreadxpm);
941 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED, &repliedxpm);
942 stock_pixbuf_gdk(STOCK_PIXMAP_FORWARDED, &forwardedxpm);
943 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED_AND_FORWARDED, &repliedandforwardedxpm);
944 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP, &clipxpm);
945 stock_pixbuf_gdk(STOCK_PIXMAP_LOCKED, &lockedxpm);
946 stock_pixbuf_gdk(STOCK_PIXMAP_IGNORETHREAD, &ignorethreadxpm);
947 stock_pixbuf_gdk(STOCK_PIXMAP_WATCHTHREAD, &watchthreadxpm);
948 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_KEY, &clipkeyxpm);
949 stock_pixbuf_gdk(STOCK_PIXMAP_KEY_SIGN, &keysignxpm);
950 stock_pixbuf_gdk(STOCK_PIXMAP_KEY, &keyxpm);
951 stock_pixbuf_gdk(STOCK_PIXMAP_GPG_SIGNED, &gpgsignedxpm);
952 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_GPG_SIGNED, &clipgpgsignedxpm);
953 stock_pixbuf_gdk(STOCK_PIXMAP_SPAM, &spamxpm);
954 stock_pixbuf_gdk(STOCK_PIXMAP_MOVED, &movedxpm);
955 stock_pixbuf_gdk(STOCK_PIXMAP_COPIED, &copiedxpm);
957 summary_set_fonts(summaryview);
959 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
961 pixmap = stock_pixmap_widget(STOCK_PIXMAP_QUICKSEARCH);
962 gtk_container_add (GTK_CONTAINER(summaryview->toggle_search), pixmap);
963 gtk_widget_show(pixmap);
964 summaryview->quick_search_pixmap = pixmap;
966 #ifdef GENERIC_UMPC
967 pixmap = stock_pixmap_widget(STOCK_PIXMAP_SELECTION);
968 gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
969 gtk_widget_show(pixmap);
970 summaryview->multiple_sel_image = pixmap;
971 #endif
973 /* Init summaryview prefs */
974 summaryview->sort_key = SORT_BY_NONE;
975 summaryview->sort_type = SORT_ASCENDING;
977 /* Init summaryview extra data */
978 summaryview->simplify_subject_preg = NULL;
979 summary_clear_list(summaryview);
980 summary_set_column_titles(summaryview);
981 summary_colorlabel_menu_create(summaryview, FALSE);
982 summary_tags_menu_create(summaryview, FALSE);
983 main_create_mailing_list_menu (summaryview->mainwin, NULL);
984 summary_set_menu_sensitive(summaryview);
988 #define CURRENTLY_DISPLAYED(m) \
989 ( (m->msgnum == displayed_msgnum) \
990 && (!g_ascii_strcasecmp(m->folder->name,item->name)) )
992 #define FOLDER_SHOWS_TO_HDR(i) \
993 ( i && (folder_has_parent_of_type(i, F_OUTBOX) \
994 || folder_has_parent_of_type(i, F_DRAFT) \
995 || folder_has_parent_of_type(i, F_QUEUE)) )
997 static void summary_switch_from_to(SummaryView *summaryview, FolderItem *item)
999 gboolean show_from = FALSE, show_to = FALSE;
1000 gboolean showing_from = FALSE, showing_to = FALSE;
1001 gint from_pos = 0, to_pos = 0;
1002 SummaryColumnState *col_state = summaryview->col_state;
1003 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1005 if (!item || ((prefs_common.layout_mode == VERTICAL_LAYOUT || prefs_common.layout_mode == SMALL_LAYOUT) && prefs_common.two_line_vert) )
1006 return;
1007 if (FOLDER_SHOWS_TO_HDR(item))
1008 show_to = TRUE;
1009 else
1010 show_from = TRUE;
1012 from_pos = summaryview->col_pos[S_COL_FROM];
1013 to_pos = summaryview->col_pos[S_COL_TO];
1014 showing_from = col_state[from_pos].visible;
1015 showing_to = col_state[to_pos].visible;
1017 if (showing_from && showing_to) {
1018 debug_print("showing both\n");
1019 return;
1022 if (!showing_from && !showing_to) {
1023 debug_print("showing none\n");
1024 return;
1027 debug_print("showing %s %s, must show %s %s\n",
1028 showing_from?"From":"",
1029 showing_to?"To":"",
1030 show_from?"From":"",
1031 show_to?"To":"");
1033 if (showing_from == show_from && showing_to == show_to)
1034 return;
1035 /* else we'll switch both */
1037 debug_print("switching columns\n");
1038 col_state[from_pos].type = S_COL_TO;
1039 col_state[from_pos].visible = show_to;
1041 col_state[to_pos].type = S_COL_FROM;
1042 col_state[to_pos].visible = show_from;
1044 summaryview->col_pos[S_COL_TO] = from_pos;
1045 summaryview->col_pos[S_COL_FROM] = to_pos;
1047 gtk_cmclist_set_column_visibility
1048 (GTK_CMCLIST(ctree), from_pos, col_state[from_pos].visible);
1049 gtk_cmclist_set_column_visibility
1050 (GTK_CMCLIST(ctree), to_pos, col_state[to_pos].visible);
1052 summary_set_column_titles(summaryview);
1055 static void summaryview_reset_recursive_folder_match(SummaryView *summaryview)
1057 GSList *cur;
1059 for (cur = summaryview->recursive_matched_folders; cur != NULL; cur = cur->next) {
1060 folderview_update_search_icon(cur->data, FALSE);
1063 g_slist_free(summaryview->recursive_matched_folders);
1064 summaryview->recursive_matched_folders = NULL;
1065 summaryview->search_root_folder = NULL;
1068 static gboolean summaryview_quicksearch_recursive_progress(gpointer data, guint at, guint matched, guint total)
1070 QuickSearch *search = (QuickSearch*) data;
1071 gint interval = quicksearch_is_fast(search) ? 5000 : 100;
1073 statusbar_progress_all(at, total, interval);
1074 if (at % interval == 0)
1075 GTK_EVENTS_FLUSH();
1077 if (matched > 0)
1078 return FALSE;
1080 return TRUE;
1083 static void summaryview_quicksearch_recurse_step(SummaryView *summaryview, FolderItem *item)
1085 MsgInfoList *msgs = NULL;
1086 gboolean result = TRUE;
1088 statusbar_print_all(_("Searching in %s... \n"),
1089 item->path ? item->path : "(null)");
1090 folder_item_update_freeze();
1092 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_quicksearch_recursive_progress, summaryview->quicksearch);
1093 if (!quicksearch_run_on_folder(summaryview->quicksearch, item, &msgs))
1094 result = FALSE;
1096 result = result && msgs != NULL;
1098 if (msgs != NULL)
1099 procmsg_msg_list_free(msgs);
1101 folder_item_update_thaw();
1102 statusbar_progress_all(0, 0, 0);
1103 statusbar_pop_all();
1105 if (result) {
1106 summaryview->recursive_matched_folders = g_slist_prepend(
1107 summaryview->recursive_matched_folders, item);
1109 folderview_update_search_icon(item, TRUE);
1113 static void summaryview_quicksearch_search_subfolders(SummaryView *summaryview, FolderItem *folder_item)
1115 FolderItem *cur = NULL;
1116 GNode *node = folder_item->node->children;
1118 if (!prefs_common.summary_quicksearch_recurse
1119 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1120 || quicksearch_is_in_typing(summaryview->quicksearch))
1121 return;
1123 for (; node != NULL; node = node->next) {
1124 if (!quicksearch_has_sat_predicate(summaryview->quicksearch))
1125 return;
1127 cur = FOLDER_ITEM(node->data);
1128 summaryview_quicksearch_recurse_step(summaryview, cur);
1129 if (cur->node->children)
1130 summaryview_quicksearch_search_subfolders(summaryview, cur);
1134 static void summaryview_quicksearch_recurse(SummaryView *summaryview)
1136 if (!prefs_common.summary_quicksearch_recurse
1137 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1138 || summaryview->folder_item == NULL) {
1139 return;
1142 main_window_cursor_wait(summaryview->mainwin);
1144 summaryview_reset_recursive_folder_match(summaryview);
1145 summaryview->search_root_folder = summaryview->folder_item;
1147 summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
1149 main_window_cursor_normal(summaryview->mainwin);
1152 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
1154 int u = 0, n = 0, m = 0, t = 0, r = 0, f = 0, l = 0, i = 0, w = 0;
1155 GSList *cur;
1156 START_TIMING("");
1157 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1158 MsgInfo * msginfo = (MsgInfo *) cur->data;
1159 t++;
1160 if (MSG_IS_NEW(msginfo->flags))
1161 n++;
1162 if (MSG_IS_UNREAD(msginfo->flags))
1163 u++;
1164 if (MSG_IS_MARKED(msginfo->flags))
1165 m++;
1166 if (MSG_IS_REPLIED(msginfo->flags))
1167 r++;
1168 if (MSG_IS_FORWARDED(msginfo->flags))
1169 f++;
1170 if (MSG_IS_LOCKED(msginfo->flags))
1171 l++;
1172 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
1173 i++;
1174 if (MSG_IS_WATCH_THREAD(msginfo->flags))
1175 w++;
1177 if (t != item->total_msgs
1178 || n != item->new_msgs
1179 || u != item->unread_msgs
1180 || m != item->marked_msgs
1181 || r != item->replied_msgs
1182 || f != item->forwarded_msgs
1183 || l != item->locked_msgs
1184 || i != item->ignored_msgs
1185 || w != item->watched_msgs
1186 || (m == 0 && item->unreadmarked_msgs != 0)
1187 || item->unreadmarked_msgs < 0) {
1188 debug_print("Inconsistency\n");
1189 folder_item_scan_full(item, FALSE);
1190 END_TIMING();
1191 return FALSE;
1193 END_TIMING();
1194 return TRUE;
1197 gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total)
1199 SummaryView *summaryview = (SummaryView*) data;
1201 gint interval = quicksearch_is_fast(summaryview->quicksearch) ? 5000 : 100;
1203 statusbar_progress_all(at, total, interval);
1205 if (at % interval == 0)
1206 GTK_EVENTS_FLUSH();
1208 return TRUE;
1211 gboolean summary_show(SummaryView *summaryview, FolderItem *item)
1213 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1214 GtkCMCTreeNode *node = NULL;
1215 GSList *mlist = NULL;
1216 gchar *buf;
1217 gboolean is_refresh;
1218 guint selected_msgnum = 0;
1219 guint displayed_msgnum = 0;
1220 GSList *cur;
1221 GSList *not_killed;
1222 gboolean hidden_removed = FALSE;
1224 if (summary_is_locked(summaryview)) return FALSE;
1226 if (!summaryview->mainwin)
1227 return FALSE;
1228 START_TIMING("");
1229 summary_switch_from_to(summaryview, item);
1231 inc_lock();
1232 summary_lock(summaryview);
1234 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
1236 utils_free_regex();
1238 is_refresh = (item == summaryview->folder_item) ? TRUE : FALSE;
1240 if (item && item->folder->klass->item_opened) {
1241 item->folder->klass->item_opened(item);
1244 if (!is_refresh) {
1245 main_create_mailing_list_menu (summaryview->mainwin, NULL);
1246 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1247 if (item) {
1248 mainwindow_enter_folder(summaryview->mainwin);
1249 gtk_widget_grab_focus(summaryview->ctree);
1253 if (!prefs_common.summary_quicksearch_sticky
1254 && (!prefs_common.summary_quicksearch_recurse
1255 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1256 || (item && !folder_is_child_of(item, summaryview->search_root_folder)))
1257 && !quicksearch_is_running(summaryview->quicksearch)
1258 && !is_refresh) {
1259 quicksearch_set(summaryview->quicksearch, prefs_common.summary_quicksearch_type, "");
1262 /* STATUSBAR_POP(summaryview->mainwin); */
1264 if (is_refresh) {
1265 selected_msgnum = summary_get_msgnum(summaryview,
1266 summaryview->selected);
1267 displayed_msgnum = summary_get_msgnum(summaryview,
1268 summaryview->displayed);
1271 /* process the marks if any */
1272 if (!is_refresh &&
1273 (summaryview->mainwin->lock_count == 0 &&
1274 (summaryview->moved > 0 || summaryview->copied > 0))) {
1275 AlertValue val;
1276 gboolean changed = FALSE;
1278 val = alertpanel(_("Process mark"),
1279 _("Some marks are left. Process them?"),
1280 GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_CANCEL);
1281 if (G_ALERTALTERNATE == val) {
1282 summary_unlock(summaryview);
1283 summary_execute(summaryview);
1284 summary_lock(summaryview);
1285 changed = TRUE;
1286 } else if (G_ALERTDEFAULT == val) {
1287 /* DO NOTHING */
1288 } else {
1289 summary_unlock(summaryview);
1290 inc_unlock();
1291 END_TIMING();
1292 return FALSE;
1294 if (changed || !quicksearch_has_sat_predicate(summaryview->quicksearch))
1295 folder_update_op_count();
1298 summary_freeze(summaryview);
1300 summary_clear_list(summaryview);
1302 buf = NULL;
1303 if (!item || !item->path || !folder_item_parent(item) || item->no_select) {
1304 g_free(buf);
1305 debug_print("empty folder (%p %s %p %d)\n",
1306 item,
1307 (item && item->path)?item->path:"(null)",
1308 item?folder_item_parent(item):0x0,
1309 item?item->no_select:FALSE);
1310 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages", FALSE);
1311 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages", FALSE);
1312 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads", FALSE);
1313 summary_clear_all(summaryview);
1314 summaryview->folder_item = item;
1315 summary_thaw(summaryview);
1316 summary_unlock(summaryview);
1317 inc_unlock();
1318 END_TIMING();
1319 return TRUE;
1321 g_free(buf);
1323 if (!is_refresh)
1324 messageview_clear(summaryview->messageview);
1326 summaryview->folder_item = item;
1327 item->opened = TRUE;
1329 buf = g_strdup_printf(_("Scanning folder (%s)..."), item->path);
1330 debug_print("%s\n", buf);
1331 STATUSBAR_PUSH(summaryview->mainwin, buf);
1332 g_free(buf);
1334 main_window_cursor_wait(summaryview->mainwin);
1336 mlist = folder_item_get_msg_list(item);
1338 if (!summary_check_consistency(item, mlist)) {
1339 debug_print("reloading due to inconsistency\n");
1340 procmsg_msg_list_free(mlist);
1341 mlist = folder_item_get_msg_list(item);
1344 if (quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1345 procmsg_msg_list_free(mlist);
1346 mlist = NULL;
1348 START_TIMING("quicksearch");
1350 statusbar_print_all(_("Searching in %s... \n"),
1351 summaryview->folder_item->path ?
1352 summaryview->folder_item->path : "(null)");
1354 folder_item_update_freeze();
1356 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_search_root_progress, summaryview);
1357 quicksearch_run_on_folder(summaryview->quicksearch, summaryview->folder_item, &mlist);
1359 folder_item_update_thaw();
1360 statusbar_progress_all(0, 0, 0);
1361 statusbar_pop_all();
1363 if (!quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1364 debug_print("search cancelled!\n");
1365 summary_thaw(summaryview);
1366 STATUSBAR_POP(summaryview->mainwin);
1367 main_window_cursor_normal(summaryview->mainwin);
1368 summary_unlock(summaryview);
1369 inc_unlock();
1370 summary_show(summaryview, summaryview->folder_item);
1371 END_TIMING();
1372 return FALSE;
1374 END_TIMING();
1377 if ((summaryview->folder_item->hide_read_msgs
1378 || summaryview->folder_item->hide_del_msgs
1379 || summaryview->folder_item->hide_read_threads) &&
1380 quicksearch_has_sat_predicate(summaryview->quicksearch) == FALSE) {
1381 GSList *not_killed;
1383 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1384 summaryview->folder_item->hide_read_msgs);
1385 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1386 summaryview->folder_item->hide_del_msgs);
1387 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1388 summaryview->folder_item->hide_read_threads);
1389 not_killed = NULL;
1390 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1391 MsgInfo * msginfo = (MsgInfo *) cur->data;
1393 if (!msginfo->hidden) {
1394 if (MSG_IS_DELETED(msginfo->flags) && summaryview->folder_item->hide_del_msgs) {
1395 procmsg_msginfo_free(&msginfo);
1396 continue;
1398 if (summaryview->folder_item->hide_read_msgs) {
1399 if (MSG_IS_UNREAD(msginfo->flags) &&
1400 !MSG_IS_IGNORE_THREAD(msginfo->flags))
1401 not_killed = g_slist_prepend(not_killed, msginfo);
1402 else if (MSG_IS_MARKED(msginfo->flags) ||
1403 MSG_IS_LOCKED(msginfo->flags))
1404 not_killed = g_slist_prepend(not_killed, msginfo);
1405 else if (is_refresh &&
1406 (msginfo->msgnum == selected_msgnum ||
1407 msginfo->msgnum == displayed_msgnum))
1408 not_killed = g_slist_prepend(not_killed, msginfo);
1409 else
1410 procmsg_msginfo_free(&msginfo);
1411 } else {
1412 not_killed = g_slist_prepend(not_killed, msginfo);
1414 } else
1415 procmsg_msginfo_free(&msginfo);
1417 hidden_removed = TRUE;
1418 g_slist_free(mlist);
1419 mlist = not_killed;
1420 } else {
1421 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1422 FALSE);
1423 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1424 FALSE);
1425 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1426 FALSE);
1429 if (!hidden_removed) {
1430 START_TIMING("removing hidden");
1431 not_killed = NULL;
1432 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1433 MsgInfo * msginfo = (MsgInfo *) cur->data;
1435 if (!msginfo->hidden)
1436 not_killed = g_slist_prepend(not_killed, msginfo);
1437 else
1438 procmsg_msginfo_free(&msginfo);
1440 g_slist_free(mlist);
1441 mlist = not_killed;
1442 END_TIMING();
1445 STATUSBAR_POP(summaryview->mainwin);
1447 /* set ctree and hash table from the msginfo list, and
1448 create the thread */
1449 summary_set_ctree_from_list(summaryview, mlist);
1451 g_slist_free(mlist);
1453 if (is_refresh) {
1454 if (!quicksearch_is_in_typing(summaryview->quicksearch)) {
1455 summaryview->displayed =
1456 summary_find_msg_by_msgnum(summaryview,
1457 displayed_msgnum);
1458 if (!summaryview->displayed)
1459 messageview_clear(summaryview->messageview);
1460 summary_unlock(summaryview);
1461 summary_select_by_msgnum(summaryview, selected_msgnum);
1462 summary_lock(summaryview);
1463 if (!summaryview->selected) {
1464 /* no selected message - select first unread
1465 message, but do not display it */
1466 node = summary_find_next_flagged_msg(summaryview, NULL,
1467 MSG_UNREAD, FALSE);
1468 if (node == NULL && GTK_CMCLIST(ctree)->row_list != NULL)
1469 node = gtk_cmctree_node_nth
1470 (ctree,
1471 item->sort_type == SORT_DESCENDING
1472 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1473 summary_unlock(summaryview);
1474 summary_select_node(summaryview, node, 0);
1475 summary_lock(summaryview);
1477 } else {
1478 /* just select first/last */
1479 if (GTK_CMCLIST(ctree)->row_list != NULL)
1480 node = gtk_cmctree_node_nth
1481 (ctree,
1482 item->sort_type == SORT_DESCENDING
1483 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1484 summary_select_node(summaryview, node, -1);
1486 } else {
1487 /* backward compat */
1488 int i = 0;
1489 gboolean set = FALSE, stop = FALSE;
1490 for (i = 0; i < 6; i++) {
1491 EntryAction act = prefs_common.summary_select_prio[i];
1493 if (act != ACTION_UNSET) {
1494 set = TRUE;
1495 break;
1498 if (!set)
1499 prefs_summary_open_set_defaults();
1501 for (i = 0; i < 6 && node == NULL; i++) {
1502 EntryAction act = prefs_common.summary_select_prio[i];
1504 switch(act) {
1505 case ACTION_MARKED:
1506 node = summary_find_next_flagged_msg(summaryview, NULL,
1507 MSG_MARKED, FALSE);
1508 break;
1509 case ACTION_NEW:
1510 node = summary_find_next_flagged_msg(summaryview, NULL,
1511 MSG_NEW, FALSE);
1512 break;
1513 case ACTION_UNREAD:
1514 node = summary_find_next_flagged_msg(summaryview, NULL,
1515 MSG_UNREAD, FALSE);
1516 break;
1517 case ACTION_LAST_OPENED:
1518 if (summaryview->folder_item) {
1519 node = summary_find_msg_by_msgnum(summaryview,
1520 summaryview->folder_item->last_seen);
1522 break;
1523 case ACTION_LAST_LIST:
1524 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1525 node = gtk_cmctree_node_nth
1526 (ctree,
1527 item->sort_type == SORT_DESCENDING
1528 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1530 break;
1531 case ACTION_FIRST_LIST:
1532 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1533 node = gtk_cmctree_node_nth
1534 (ctree,
1535 item->sort_type == SORT_ASCENDING
1536 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1538 break;
1539 case ACTION_NOTHING:
1540 case ACTION_UNSET:
1541 node = NULL;
1542 stop = TRUE;
1543 break;
1546 if (stop || node)
1547 break;
1550 summary_unlock(summaryview);
1552 if (node) {
1553 gint open_selected = -1;
1554 if (!is_refresh) {
1555 if (prefs_common.open_selected_on_folder_open)
1556 open_selected = 1;
1557 else
1558 open_selected = 0;
1560 summary_select_node(summaryview, node, open_selected);
1563 summary_lock(summaryview);
1566 summary_status_show(summaryview);
1567 summary_set_menu_sensitive(summaryview);
1568 toolbar_main_set_sensitive(summaryview->mainwin);
1570 summary_thaw(summaryview);
1571 debug_print("\n");
1572 STATUSBAR_PUSH(summaryview->mainwin, _("Done."));
1573 STATUSBAR_POP(summaryview->mainwin);
1574 main_window_cursor_normal(summaryview->mainwin);
1575 summary_unlock(summaryview);
1576 inc_unlock();
1577 END_TIMING();
1578 return TRUE;
1581 #undef CURRENTLY_DISPLAYED
1583 static void summary_cancel_mark_read_timeout(SummaryView *summaryview) {
1584 if (summaryview->mark_as_read_timeout_tag != 0) {
1585 g_source_remove(summaryview->mark_as_read_timeout_tag);
1586 summaryview->mark_as_read_timeout_tag = 0;
1590 void summary_clear_list(SummaryView *summaryview)
1592 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1593 gint optimal_width;
1595 summary_freeze(summaryview);
1597 gtk_cmctree_pre_recursive(GTK_CMCTREE(summaryview->ctree),
1598 NULL, summary_free_msginfo_func, NULL);
1600 if (summaryview->folder_item) {
1601 summaryview->folder_item->opened = FALSE;
1602 summaryview->folder_item = NULL;
1605 summary_cancel_mark_read_timeout(summaryview);
1607 summaryview->display_msg = FALSE;
1609 summaryview->selected = NULL;
1610 summaryview->displayed = NULL;
1611 summaryview->total_size = 0;
1612 summaryview->deleted = summaryview->moved = 0;
1613 summaryview->copied = 0;
1614 if (summaryview->msgid_table) {
1615 g_hash_table_destroy(summaryview->msgid_table);
1616 summaryview->msgid_table = NULL;
1618 if (summaryview->subject_table) {
1619 g_hash_table_destroy(summaryview->subject_table);
1620 summaryview->subject_table = NULL;
1622 summaryview->mlist = NULL;
1624 gtk_cmclist_clear(clist);
1625 if (summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
1626 optimal_width = gtk_cmclist_optimal_column_width
1627 (clist, summaryview->col_pos[S_COL_SUBJECT]);
1628 gtk_cmclist_set_column_width
1629 (clist, summaryview->col_pos[S_COL_SUBJECT],
1630 optimal_width);
1633 summary_thaw(summaryview);
1636 void summary_clear_all(SummaryView *summaryview)
1638 messageview_clear(summaryview->messageview);
1639 summary_clear_list(summaryview);
1640 summary_set_menu_sensitive(summaryview);
1641 toolbar_main_set_sensitive(summaryview->mainwin);
1642 summary_status_show(summaryview);
1645 void summary_lock(SummaryView *summaryview)
1647 summaryview->lock_count++;
1650 void summary_unlock(SummaryView *summaryview)
1652 if (summaryview->lock_count)
1653 summaryview->lock_count--;
1656 gboolean summary_is_locked(SummaryView *summaryview)
1658 return summaryview->lock_count > 0;
1661 SummarySelection summary_get_selection_type(SummaryView *summaryview)
1663 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1664 SummarySelection selection;
1666 if (!clist->row_list)
1667 selection = SUMMARY_NONE;
1668 else if (!clist->selection)
1669 selection = SUMMARY_SELECTED_NONE;
1670 else if (!clist->selection->next)
1671 selection = SUMMARY_SELECTED_SINGLE;
1672 else
1673 selection = SUMMARY_SELECTED_MULTIPLE;
1675 return selection;
1679 *\return MsgInfo * Selected message if there's one selected;
1680 * if multiple selected, or none, return NULL.
1682 MsgInfo *summary_get_selected_msg(SummaryView *summaryview)
1684 /* summaryview->selected may be valid when multiple
1685 * messages were selected */
1686 GList *sellist = GTK_CMCLIST(summaryview->ctree)->selection;
1688 if (sellist == NULL || sellist->next)
1689 return NULL;
1691 return GTKUT_CTREE_NODE_GET_ROW_DATA(sellist->data);
1694 GSList *summary_get_selected_msg_list(SummaryView *summaryview)
1696 GSList *mlist = NULL;
1697 GList *cur;
1698 MsgInfo *msginfo;
1700 for (cur = GTK_CMCLIST(summaryview->ctree)->selection; cur != NULL && cur->data != NULL;
1701 cur = cur->next) {
1702 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data);
1703 mlist = g_slist_prepend(mlist, msginfo);
1706 mlist = g_slist_reverse(mlist);
1708 return mlist;
1711 void summary_set_menu_sensitive(SummaryView *summaryview)
1713 SensitiveCondMask state;
1714 gboolean sensitive;
1715 gint i;
1717 #define N_ENTRIES 38
1718 static struct {
1719 const gchar *entry;
1720 SensitiveCondMask cond;
1721 } entry[N_ENTRIES];
1723 i = 0;
1724 #define FILL_TABLE(entry_str, ...) \
1725 do { \
1726 entry[i].entry = (const gchar *) entry_str; entry[i++].cond = main_window_get_mask(__VA_ARGS__, -1); \
1727 } while (0)
1729 FILL_TABLE("Menus/SummaryViewPopup/Reply", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1730 #ifndef GENERIC_UMPC
1731 FILL_TABLE("Menus/SummaryViewPopup/ReplyTo", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1732 FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/All", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1733 FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/Sender", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1734 FILL_TABLE("Menus/SummaryViewPopup/ReplyTo/MailingList", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1735 #endif
1737 FILL_TABLE("Menus/SummaryViewPopup/Forward", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1738 #ifndef GENERIC_UMPC
1739 FILL_TABLE("Menus/SummaryViewPopup/ForwardAtt", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1740 FILL_TABLE("Menus/SummaryViewPopup/Redirect", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1741 #endif
1743 FILL_TABLE("Menus/SummaryViewPopup/Move", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
1744 FILL_TABLE("Menus/SummaryViewPopup/Copy", M_TARGET_EXIST, M_EXEC);
1745 FILL_TABLE("Menus/SummaryViewPopup/Trash", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS, M_NOT_TRASH);
1746 #ifndef GENERIC_UMPC
1747 FILL_TABLE("Menus/SummaryViewPopup/Delete", M_TARGET_EXIST, M_ALLOW_DELETE);
1748 #endif
1750 FILL_TABLE("Menus/SummaryViewPopup/Mark", M_TARGET_EXIST);
1751 FILL_TABLE("Menus/SummaryViewPopup/Mark/Mark", M_TARGET_EXIST);
1752 FILL_TABLE("Menus/SummaryViewPopup/Mark/Unmark", M_TARGET_EXIST);
1753 FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkUnread", M_TARGET_EXIST);
1754 FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkRead", M_TARGET_EXIST);
1755 FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkAllRead", M_TARGET_EXIST);
1756 FILL_TABLE("Menus/SummaryViewPopup/Mark/IgnoreThread", M_TARGET_EXIST);
1757 FILL_TABLE("Menus/SummaryViewPopup/Mark/UnignoreThread", M_TARGET_EXIST);
1758 FILL_TABLE("Menus/SummaryViewPopup/Mark/WatchThread", M_TARGET_EXIST);
1759 FILL_TABLE("Menus/SummaryViewPopup/Mark/UnwatchThread", M_TARGET_EXIST);
1760 FILL_TABLE("Menus/SummaryViewPopup/Mark/Unlock", M_TARGET_EXIST);
1761 FILL_TABLE("Menus/SummaryViewPopup/Mark/Lock", M_TARGET_EXIST);
1762 FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkSpam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1763 FILL_TABLE("Menus/SummaryViewPopup/Mark/MarkHam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1764 FILL_TABLE("Menus/SummaryViewPopup/ColorLabel", M_TARGET_EXIST);
1765 FILL_TABLE("Menus/SummaryViewPopup/Tags", M_TARGET_EXIST);
1767 #ifndef GENERIC_UMPC
1768 FILL_TABLE("Menus/SummaryViewPopup/AddSenderToAB", M_SINGLE_TARGET_EXIST);
1769 #endif
1770 FILL_TABLE("Menus/SummaryViewPopup/CreateFilterRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1771 #ifndef GENERIC_UMPC
1772 FILL_TABLE("Menus/SummaryViewPopup/CreateProcessingRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1773 #endif
1775 FILL_TABLE("Menus/SummaryViewPopup/View", M_SINGLE_TARGET_EXIST);
1776 FILL_TABLE("Menus/SummaryViewPopup/View/OpenNewWindow", M_SINGLE_TARGET_EXIST);
1777 FILL_TABLE("Menus/SummaryViewPopup/View/MessageSource", M_SINGLE_TARGET_EXIST);
1778 #ifndef GENERIC_UMPC
1779 FILL_TABLE("Menus/SummaryViewPopup/View/AllHeaders", M_SINGLE_TARGET_EXIST);
1780 #endif
1781 FILL_TABLE("Menus/SummaryViewPopup/SaveAs", M_TARGET_EXIST);
1782 #ifndef GENERIC_UMPC
1783 FILL_TABLE("Menus/SummaryViewPopup/Print", M_TARGET_EXIST);
1784 #endif
1785 FILL_TABLE(NULL, -1);
1786 #undef FILL_TABLE
1787 if (i != N_ENTRIES)
1788 g_error("summaryview menu entry table size mismatch (%d/%d)", i, N_ENTRIES);
1789 #undef ENTRIES
1791 main_window_set_menu_sensitive(summaryview->mainwin);
1793 state = main_window_get_current_state(summaryview->mainwin);
1795 for (i = 0; entry[i].entry != NULL; i++) {
1796 sensitive = ((entry[i].cond & state) == entry[i].cond);
1797 cm_menu_set_sensitive_full(summaryview->mainwin->ui_manager, entry[i].entry, sensitive);
1800 summary_lock(summaryview);
1801 #ifndef GENERIC_UMPC
1802 if (summaryview->messageview
1803 && summaryview->messageview->mimeview
1804 && summaryview->messageview->mimeview->textview)
1805 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager, "Menus/SummaryViewPopup/View/AllHeaders",
1806 prefs_common.show_all_headers);
1807 #endif
1808 summary_unlock(summaryview);
1810 void summary_select_prev(SummaryView *summaryview)
1812 GtkCMCTreeNode *node = summaryview->selected;
1813 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1815 node = gtkut_ctree_node_prev(ctree, node);
1817 if (node && node != summaryview->selected)
1818 summary_select_node(summaryview, node, -1);
1821 void summary_select_next(SummaryView *summaryview)
1823 GtkCMCTreeNode *node = summaryview->selected;
1824 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1826 node = gtkut_ctree_node_next(ctree, node);
1828 if (node && node != summaryview->selected)
1829 summary_select_node(summaryview, node, -1);
1832 void summary_select_prev_unread(SummaryView *summaryview)
1834 GtkCMCTreeNode *node;
1836 if (summaryview->sort_type == SORT_ASCENDING)
1837 node = summary_find_prev_flagged_msg
1838 (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1839 else
1840 node = summary_find_next_flagged_msg
1841 (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1843 if (!node || node == summaryview->selected) {
1844 AlertValue val = 0;
1846 switch (prefs_common.next_unread_msg_dialog) {
1847 case NEXTUNREADMSGDIALOG_ALWAYS:
1848 val = alertpanel(_("No more unread messages"),
1849 _("No unread message found. "
1850 "Search from the end?"),
1851 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1852 break;
1853 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1854 val = G_ALERTALTERNATE;
1855 break;
1856 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1857 val = !G_ALERTALTERNATE;
1858 break;
1859 default:
1860 debug_print(
1861 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1863 if (val != G_ALERTALTERNATE) return;
1864 if (summaryview->sort_type == SORT_ASCENDING)
1865 node = summary_find_prev_flagged_msg(summaryview, NULL,
1866 MSG_UNREAD, FALSE);
1867 else
1868 node = summary_find_next_flagged_msg(summaryview, NULL,
1869 MSG_UNREAD, FALSE);
1872 if (!node)
1873 alertpanel_notice(_("No unread messages."));
1874 else
1875 summary_select_node(summaryview, node, -1);
1878 void summary_select_next_unread(SummaryView *summaryview)
1880 GtkCMCTreeNode *node = summaryview->selected;
1882 if (summaryview->sort_type == SORT_ASCENDING)
1883 node = summary_find_next_flagged_msg
1884 (summaryview, node, MSG_UNREAD, TRUE);
1885 else
1886 node = summary_find_prev_flagged_msg
1887 (summaryview, node, MSG_UNREAD, TRUE);
1889 if (node)
1890 summary_select_node(summaryview, node, -1);
1891 else {
1892 AlertValue val = 0;
1894 switch (prefs_common.next_unread_msg_dialog) {
1895 case NEXTUNREADMSGDIALOG_ALWAYS:
1896 val = alertpanel(_("No more unread messages"),
1897 _("No unread message found. "
1898 "Go to next folder?"),
1899 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1900 break;
1901 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1902 val = G_ALERTALTERNATE;
1903 break;
1904 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1905 val = G_ALERTOTHER;
1906 break;
1907 default:
1908 debug_print(
1909 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1912 if (val == G_ALERTALTERNATE)
1913 folderview_select_next_with_flag(summaryview->folderview, MSG_UNREAD);
1917 void summary_select_prev_new(SummaryView *summaryview)
1919 GtkCMCTreeNode *node;
1921 if (summaryview->sort_type == SORT_ASCENDING)
1922 node = summary_find_prev_flagged_msg
1923 (summaryview, summaryview->selected, MSG_NEW, TRUE);
1924 else
1925 node = summary_find_next_flagged_msg
1926 (summaryview, summaryview->selected, MSG_NEW, TRUE);
1928 if (!node || node == summaryview->selected) {
1929 AlertValue val = 0;
1931 switch (prefs_common.next_unread_msg_dialog) {
1932 case NEXTUNREADMSGDIALOG_ALWAYS:
1933 val = alertpanel(_("No more new messages"),
1934 _("No new message found. "
1935 "Search from the end?"),
1936 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1937 break;
1938 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1939 val = G_ALERTALTERNATE;
1940 break;
1941 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1942 val = !G_ALERTALTERNATE;
1943 break;
1944 default:
1945 debug_print(
1946 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1948 if (val != G_ALERTALTERNATE) return;
1949 if (summaryview->sort_type == SORT_ASCENDING)
1950 node = summary_find_prev_flagged_msg(summaryview, NULL,
1951 MSG_NEW, FALSE);
1952 else
1953 node = summary_find_next_flagged_msg(summaryview, NULL,
1954 MSG_NEW, FALSE);
1957 if (!node)
1958 alertpanel_notice(_("No new messages."));
1959 else
1960 summary_select_node(summaryview, node, -1);
1963 void summary_select_next_new(SummaryView *summaryview)
1965 GtkCMCTreeNode *node = summaryview->selected;
1967 if (summaryview->sort_type == SORT_ASCENDING)
1968 node = summary_find_next_flagged_msg
1969 (summaryview, node, MSG_NEW, TRUE);
1970 else
1971 node = summary_find_prev_flagged_msg
1972 (summaryview, node, MSG_NEW, TRUE);
1974 if (node)
1975 summary_select_node(summaryview, node, -1);
1976 else {
1977 AlertValue val = 0;
1979 switch (prefs_common.next_unread_msg_dialog) {
1980 case NEXTUNREADMSGDIALOG_ALWAYS:
1981 val = alertpanel(_("No more new messages"),
1982 _("No new message found. "
1983 "Go to next folder?"),
1984 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
1985 break;
1986 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1987 val = G_ALERTALTERNATE;
1988 break;
1989 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1990 val = G_ALERTOTHER;
1991 break;
1992 default:
1993 debug_print(
1994 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1996 if (val == G_ALERTALTERNATE)
1997 folderview_select_next_with_flag(summaryview->folderview, MSG_NEW);
2001 void summary_select_prev_marked(SummaryView *summaryview)
2003 GtkCMCTreeNode *node;
2005 if (summaryview->sort_type == SORT_ASCENDING)
2006 node = summary_find_prev_flagged_msg
2007 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2008 else
2009 node = summary_find_next_flagged_msg
2010 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2012 if (!node) {
2013 AlertValue val;
2015 val = alertpanel(_("No more marked messages"),
2016 _("No marked message found. "
2017 "Search from the end?"),
2018 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2019 if (val != G_ALERTALTERNATE) return;
2020 node = summary_find_prev_flagged_msg(summaryview, NULL,
2021 MSG_MARKED, TRUE);
2024 if (!node)
2025 alertpanel_notice(_("No marked messages."));
2026 else
2027 summary_select_node(summaryview, node, -1);
2030 void summary_select_next_marked(SummaryView *summaryview)
2032 GtkCMCTreeNode *node = summaryview->selected;
2034 if (summaryview->sort_type == SORT_ASCENDING)
2035 node = summary_find_next_flagged_msg
2036 (summaryview, node, MSG_MARKED, TRUE);
2037 else
2038 node = summary_find_prev_flagged_msg
2039 (summaryview, node, MSG_MARKED, TRUE);
2041 if (node)
2042 summary_select_node(summaryview, node, -1);
2043 else {
2044 AlertValue val = 0;
2046 switch (prefs_common.next_unread_msg_dialog) {
2047 case NEXTUNREADMSGDIALOG_ALWAYS:
2048 val = alertpanel(_("No more marked messages"),
2049 _("No marked message found. "
2050 "Go to next folder?"),
2051 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2052 break;
2053 case NEXTUNREADMSGDIALOG_ASSUME_YES:
2054 val = G_ALERTALTERNATE;
2055 break;
2056 case NEXTUNREADMSGDIALOG_ASSUME_NO:
2057 val = G_ALERTOTHER;
2058 break;
2059 default:
2060 debug_print(
2061 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2063 if (val == G_ALERTALTERNATE)
2064 folderview_select_next_with_flag(summaryview->folderview, MSG_MARKED);
2068 void summary_select_prev_labeled(SummaryView *summaryview)
2070 GtkCMCTreeNode *node;
2072 if (summaryview->sort_type == SORT_ASCENDING)
2073 node = summary_find_prev_flagged_msg
2074 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2075 else
2076 node = summary_find_next_flagged_msg
2077 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2079 if (!node) {
2080 AlertValue val;
2082 val = alertpanel(_("No more labeled messages"),
2083 _("No labeled message found. "
2084 "Search from the end?"),
2085 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2086 if (val != G_ALERTALTERNATE) return;
2087 node = summary_find_prev_flagged_msg(summaryview, NULL,
2088 MSG_CLABEL_FLAG_MASK, TRUE);
2091 if (!node)
2092 alertpanel_notice(_("No labeled messages."));
2093 else
2094 summary_select_node(summaryview, node, -1);
2097 void summary_select_next_labeled(SummaryView *summaryview)
2099 GtkCMCTreeNode *node;
2101 if (summaryview->sort_type == SORT_ASCENDING)
2102 node = summary_find_next_flagged_msg
2103 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2104 else
2105 node = summary_find_prev_flagged_msg
2106 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2108 if (!node) {
2109 AlertValue val;
2111 val = alertpanel(_("No more labeled messages"),
2112 _("No labeled message found. "
2113 "Search from the beginning?"),
2114 GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
2115 if (val != G_ALERTALTERNATE) return;
2116 if (summaryview->sort_type == SORT_ASCENDING)
2117 node = summary_find_next_flagged_msg(summaryview, NULL,
2118 MSG_CLABEL_FLAG_MASK, TRUE);
2119 else
2120 node = summary_find_prev_flagged_msg(summaryview, NULL,
2121 MSG_CLABEL_FLAG_MASK, TRUE);
2124 if (!node)
2125 alertpanel_notice(_("No labeled messages."));
2126 else
2127 summary_select_node(summaryview, node, -1);
2130 void summary_select_parent(SummaryView *summaryview)
2132 GtkCMCTreeNode *node = NULL;
2134 if (summaryview->selected)
2135 node = GTK_CMCTREE_ROW(summaryview->selected)->parent;
2136 if (node)
2137 summary_select_node(summaryview, node, -1);
2140 void summary_select_by_msgnum(SummaryView *summaryview, guint msgnum)
2142 GtkCMCTreeNode *node;
2144 node = summary_find_msg_by_msgnum(summaryview, msgnum);
2145 summary_select_node(summaryview, node, 0);
2148 void summary_display_by_msgnum(SummaryView *summaryview, guint msgnum)
2150 GtkCMCTreeNode *node;
2152 node = summary_find_msg_by_msgnum(summaryview, msgnum);
2153 summary_select_node(summaryview, node, 1);
2156 void summary_select_by_msg_list(SummaryView *summaryview, GSList *msginfos)
2158 GtkCMCTree *ctree;
2159 GSList *msgnum_list, *walk;
2160 gboolean froze = FALSE;
2162 ctree = GTK_CMCTREE(summaryview->ctree);
2164 msgnum_list = procmsg_get_number_list_for_msgs(msginfos);
2166 START_LONG_OPERATION(summaryview, FALSE);
2167 for(walk = msgnum_list; walk; walk = walk->next) {
2168 GtkCMCTreeNode *node;
2169 node = summary_find_msg_by_msgnum(summaryview, GPOINTER_TO_UINT(walk->data));
2170 gtk_cmctree_select(ctree, node);
2172 END_LONG_OPERATION(summaryview);
2173 g_slist_free(msgnum_list);
2176 typedef struct _PostponedSelectData
2178 GtkCMCTree *ctree;
2179 GtkCMCTreeNode *row;
2180 GtkCMCTreeNode *node;
2181 GtkScrollType type;
2182 gint column;
2183 SummaryView *summaryview;
2184 gboolean display_msg;
2185 } PostponedSelectData;
2187 static gboolean summary_select_retry(void *data)
2189 PostponedSelectData *psdata = (PostponedSelectData *)data;
2190 debug_print("trying again\n");
2191 if (psdata->row)
2192 summary_selected(psdata->ctree, psdata->row,
2193 psdata->column, psdata->summaryview);
2194 else if (psdata->node)
2195 summary_select_node(psdata->summaryview, psdata->node,
2196 psdata->display_msg);
2197 g_free(psdata);
2198 return FALSE;
2202 * summary_select_node:
2203 * @summaryview: Summary view.
2204 * @node: Summary tree node.
2205 * @force_display: -1 unset, 0 don't show the msg, 1 show the msg.
2207 * Select @node (bringing it into view by scrolling and expanding its
2208 * thread, if necessary) and unselect all others. If @force_display is
2209 * 1, display the corresponding message in the message view, if
2210 * @force_display is -1, obey prefs_common.always_show_msg.
2212 void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
2213 gint force_display)
2215 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2216 gboolean display_msg;
2218 display_msg = force_display > -1? force_display :
2219 (prefs_common.always_show_msg == OPENMSG_YES) ||
2220 ((prefs_common.always_show_msg == OPENMSG_WHEN_VIEW_VISIBLE &&
2221 messageview_is_visible(summaryview->messageview)));
2223 if (summary_is_locked(summaryview)
2224 && !GTK_SCTREE(ctree)->selecting_range
2225 && summaryview->messageview->mimeview
2226 && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
2227 && summaryview->messageview->mimeview->textview->loading) {
2228 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
2229 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
2231 data->ctree = ctree;
2232 data->row = NULL;
2233 data->node = node;
2234 data->summaryview = summaryview;
2235 data->display_msg = display_msg;
2236 debug_print("postponing open of message till end of load\n");
2237 g_timeout_add(100, summary_select_retry, data);
2238 return;
2240 if (summary_is_locked(summaryview)) {
2241 return;
2243 if (!summaryview->folder_item)
2244 return;
2245 if (node) {
2246 summary_cancel_mark_read_timeout(summaryview);
2247 gtkut_ctree_expand_parent_all(ctree, node);
2249 summary_lock(summaryview);
2250 GTK_EVENTS_FLUSH();
2251 summary_unlock(summaryview);
2252 gtk_widget_grab_focus(GTK_WIDGET(ctree));
2253 gtkut_ctree_node_move_if_on_the_edge(ctree, node, -1);
2255 if (display_msg && summaryview->displayed == node)
2256 summaryview->displayed = NULL;
2257 summaryview->display_msg = display_msg;
2258 gtk_sctree_select(GTK_SCTREE(ctree), node);
2259 if (summaryview->selected == NULL)
2260 summaryview->selected = node;
2264 guint summary_get_msgnum(SummaryView *summaryview, GtkCMCTreeNode *node)
2266 GtkCMCTree *ctree =NULL;
2267 MsgInfo *msginfo;
2269 if (!summaryview)
2270 return 0;
2271 ctree = GTK_CMCTREE(summaryview->ctree);
2272 if (!node)
2273 return 0;
2274 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2275 if (msginfo)
2276 return msginfo->msgnum;
2277 else
2278 return -1;
2281 static GtkCMCTreeNode *summary_find_prev_msg(SummaryView *summaryview,
2282 GtkCMCTreeNode *current_node,
2283 gboolean start_from_prev)
2285 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2286 GtkCMCTreeNode *node;
2287 MsgInfo *msginfo;
2289 if (current_node) {
2290 if (start_from_prev)
2291 node = gtkut_ctree_node_prev(ctree, current_node);
2292 else
2293 node = current_node;
2294 } else
2295 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2297 for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2298 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2299 if (msginfo && !MSG_IS_DELETED(msginfo->flags)) break;
2302 return node;
2305 static GtkCMCTreeNode *summary_find_next_msg(SummaryView *summaryview,
2306 GtkCMCTreeNode *current_node,
2307 gboolean start_from_next)
2309 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2310 GtkCMCTreeNode *node;
2311 MsgInfo *msginfo;
2313 if (current_node) {
2314 if (start_from_next)
2315 node = gtkut_ctree_node_next(ctree, current_node);
2316 else
2317 node = current_node;
2318 } else
2319 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2321 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2322 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2323 if (msginfo && !MSG_IS_DELETED(msginfo->flags)
2324 && !MSG_IS_MOVE(msginfo->flags)) break;
2327 return node;
2330 static GtkCMCTreeNode *summary_find_prev_flagged_msg(SummaryView *summaryview,
2331 GtkCMCTreeNode *current_node,
2332 MsgPermFlags flags,
2333 gboolean start_from_prev)
2335 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2336 GtkCMCTreeNode *node;
2337 MsgInfo *msginfo;
2339 if (current_node) {
2340 if (start_from_prev)
2341 node = gtkut_ctree_node_prev(ctree, current_node);
2342 else
2343 node = current_node;
2344 } else
2345 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2347 for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2348 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2349 if (msginfo && (msginfo->flags.perm_flags & flags) != 0) break;
2352 return node;
2355 static GtkCMCTreeNode *summary_find_next_flagged_msg(SummaryView *summaryview,
2356 GtkCMCTreeNode *current_node,
2357 MsgPermFlags flags,
2358 gboolean start_from_next)
2360 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2361 GtkCMCTreeNode *node;
2362 MsgInfo *msginfo;
2364 if (current_node) {
2365 if (start_from_next)
2366 node = gtkut_ctree_node_next(ctree, current_node);
2367 else
2368 node = current_node;
2369 } else
2370 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2372 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2373 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2374 /* Find msg with matching flags but ignore messages with
2375 ignore flags, if searching for new or unread messages */
2376 if ((msginfo && (msginfo->flags.perm_flags & flags) != 0) &&
2377 !(((flags & (MSG_NEW | MSG_UNREAD)) != 0) && MSG_IS_IGNORE_THREAD(msginfo->flags))
2379 break;
2382 return node;
2385 static GtkCMCTreeNode *summary_find_msg_by_msgnum(SummaryView *summaryview,
2386 guint msgnum)
2388 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2389 GtkCMCTreeNode *node;
2390 MsgInfo *msginfo;
2392 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2394 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2395 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2396 if (msginfo && msginfo->msgnum == msgnum) break;
2399 return node;
2402 static guint attract_hash_func(gconstpointer key)
2404 gchar *str;
2405 gchar *p;
2406 guint h;
2408 Xstrdup_a(str, (const gchar *)key, return 0);
2409 trim_subject(str);
2411 p = str;
2412 h = *p;
2414 if (h) {
2415 for (p += 1; *p != '\0'; p++)
2416 h = (h << 5) - h + *p;
2419 return h;
2422 static gint attract_compare_func(gconstpointer a, gconstpointer b)
2424 return subject_compare((const gchar *)a, (const gchar *)b) == 0;
2427 void summary_attract_by_subject(SummaryView *summaryview)
2429 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2430 GtkCMCList *clist = GTK_CMCLIST(ctree);
2431 GtkCMCTreeNode *src_node;
2432 GtkCMCTreeNode *dst_node, *sibling;
2433 GtkCMCTreeNode *tmp;
2434 MsgInfo *src_msginfo, *dst_msginfo;
2435 GHashTable *subject_table;
2437 debug_print("Attracting messages by subject...\n");
2438 STATUSBAR_PUSH(summaryview->mainwin,
2439 _("Attracting messages by subject..."));
2441 main_window_cursor_wait(summaryview->mainwin);
2442 summary_freeze(summaryview);
2444 subject_table = g_hash_table_new(attract_hash_func,
2445 attract_compare_func);
2447 for (src_node = GTK_CMCTREE_NODE(clist->row_list);
2448 src_node != NULL;
2449 src_node = tmp) {
2450 tmp = GTK_CMCTREE_ROW(src_node)->sibling;
2451 src_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(src_node);
2452 if (!src_msginfo) continue;
2453 if (!src_msginfo->subject) continue;
2455 /* find attracting node */
2456 dst_node = g_hash_table_lookup(subject_table,
2457 src_msginfo->subject);
2459 if (dst_node) {
2460 dst_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(dst_node);
2462 /* if the time difference is more than 20 days,
2463 don't attract */
2464 if (ABS(src_msginfo->date_t - dst_msginfo->date_t)
2465 > 60 * 60 * 24 * 20)
2466 continue;
2468 sibling = GTK_CMCTREE_ROW(dst_node)->sibling;
2469 if (src_node != sibling)
2470 gtk_cmctree_move(ctree, src_node, NULL, sibling);
2473 g_hash_table_insert(subject_table,
2474 src_msginfo->subject, src_node);
2477 g_hash_table_destroy(subject_table);
2479 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2481 summary_thaw(summaryview);
2483 debug_print("Attracting messages by subject done.\n");
2484 STATUSBAR_POP(summaryview->mainwin);
2486 main_window_cursor_normal(summaryview->mainwin);
2489 static void summary_free_msginfo_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2490 gpointer data)
2492 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2494 if (msginfo)
2495 procmsg_msginfo_free(&msginfo);
2498 static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2499 gpointer data)
2501 SummaryView *summaryview = data;
2502 MsgInfo *msginfo;
2504 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2506 cm_return_if_fail(msginfo != NULL);
2508 if (MSG_IS_DELETED(msginfo->flags))
2509 summaryview->deleted++;
2511 summaryview->total_size += msginfo->size;
2513 summary_set_row_marks(summaryview, node);
2516 static void summary_update_status(SummaryView *summaryview)
2518 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2519 GtkCMCTreeNode *node;
2520 MsgInfo *msginfo;
2522 summaryview->total_size =
2523 summaryview->deleted = summaryview->moved = summaryview->copied = 0;
2525 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2526 node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2527 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
2529 if (!msginfo)
2530 continue;
2532 if (MSG_IS_DELETED(msginfo->flags))
2533 summaryview->deleted++;
2534 if (MSG_IS_MOVE(msginfo->flags))
2535 summaryview->moved++;
2536 if (MSG_IS_COPY(msginfo->flags))
2537 summaryview->copied++;
2538 summaryview->total_size += msginfo->size;
2542 static void summary_status_show(SummaryView *summaryview)
2544 gchar *str;
2545 gchar *del, *mv, *cp;
2546 gchar *sel;
2547 gchar *spc;
2548 gchar *itstr;
2549 GList *rowlist, *cur;
2550 guint n_selected = 0, n_new = 0, n_unread = 0, n_total = 0;
2551 guint n_marked = 0, n_replied = 0, n_forwarded = 0, n_locked = 0, n_ignored = 0, n_watched = 0;
2552 goffset sel_size = 0, n_size = 0;
2553 MsgInfo *msginfo;
2554 gchar *name;
2555 gchar *tooltip;
2557 if (!summaryview->folder_item) {
2558 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), "");
2559 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), "");
2560 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), "");
2561 toolbar_main_set_sensitive(summaryview->mainwin);
2562 return;
2565 rowlist = GTK_CMCLIST(summaryview->ctree)->selection;
2566 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2567 msginfo = gtk_cmctree_node_get_row_data
2568 (GTK_CMCTREE(summaryview->ctree),
2569 GTK_CMCTREE_NODE(cur->data));
2570 if (msginfo) {
2571 sel_size += msginfo->size;
2572 n_selected++;
2576 if (summaryview->folder_item->hide_read_msgs
2577 || summaryview->folder_item->hide_del_msgs
2578 || summaryview->folder_item->hide_read_threads
2579 || quicksearch_has_sat_predicate(summaryview->quicksearch)) {
2580 rowlist = GTK_CMCLIST(summaryview->ctree)->row_list;
2581 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2582 msginfo = gtk_cmctree_node_get_row_data
2583 (GTK_CMCTREE(summaryview->ctree),
2584 GTK_CMCTREE_NODE(cur));
2585 if (msginfo) {
2586 n_size += msginfo->size;
2587 n_total++;
2588 if (MSG_IS_NEW(msginfo->flags))
2589 n_new++;
2590 if (MSG_IS_UNREAD(msginfo->flags))
2591 n_unread++;
2592 if (MSG_IS_MARKED(msginfo->flags))
2593 n_marked++;
2594 if (MSG_IS_REPLIED(msginfo->flags))
2595 n_replied++;
2596 if (MSG_IS_FORWARDED(msginfo->flags))
2597 n_forwarded++;
2598 if (MSG_IS_LOCKED(msginfo->flags))
2599 n_locked++;
2600 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
2601 n_ignored++;
2602 if (MSG_IS_WATCH_THREAD(msginfo->flags))
2603 n_watched++;
2606 } else {
2607 n_new = summaryview->folder_item->new_msgs;
2608 n_unread = summaryview->folder_item->unread_msgs;
2609 n_marked = summaryview->folder_item->marked_msgs;
2610 n_replied = summaryview->folder_item->replied_msgs;
2611 n_forwarded = summaryview->folder_item->forwarded_msgs;
2612 n_locked = summaryview->folder_item->locked_msgs;
2613 n_ignored = summaryview->folder_item->ignored_msgs;
2614 n_watched = summaryview->folder_item->watched_msgs;
2615 n_total = summaryview->folder_item->total_msgs;
2616 n_size = summaryview->total_size;
2619 name = folder_item_get_name(summaryview->folder_item);
2620 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
2621 g_free(name);
2623 if (summaryview->deleted)
2624 del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
2625 else
2626 del = g_strdup("");
2627 if (summaryview->moved)
2628 mv = g_strdup_printf(_("%s%d moved"),
2629 summaryview->deleted ? _(", ") : "",
2630 summaryview->moved);
2631 else
2632 mv = g_strdup("");
2633 if (summaryview->copied)
2634 cp = g_strdup_printf(_("%s%d copied"),
2635 summaryview->deleted ||
2636 summaryview->moved ? _(", ") : "",
2637 summaryview->copied);
2638 else
2639 cp = g_strdup("");
2641 if (summaryview->deleted || summaryview->moved || summaryview->copied)
2642 spc = " ";
2643 else
2644 spc = "";
2646 if (n_selected) {
2647 sel = g_strdup_printf(" (%s)", to_human_readable((goffset)sel_size));
2648 itstr = g_strdup_printf(ngettext(" item selected"," items selected", n_selected));
2649 } else {
2650 sel = g_strdup("");
2651 itstr = g_strdup("");
2654 if (prefs_common.layout_mode != SMALL_LAYOUT) {
2655 str = g_strconcat(n_selected ? itos(n_selected) : "",
2656 itstr, sel, spc, del, mv, cp, NULL);
2657 g_free(sel);
2658 g_free(del);
2659 g_free(mv);
2660 g_free(cp);
2661 g_free(itstr);
2663 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2664 g_free(str);
2666 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2667 n_new, n_unread, n_total,
2668 to_human_readable((goffset)n_size));
2671 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), str);
2672 g_free(str);
2673 tooltip = g_strdup_printf("<b>%s</b>\n"
2674 "<b>%s</b> %d\n"
2675 "<b>%s</b> %d\n"
2676 "<b>%s</b> %d\n"
2677 "<b>%s</b> %s\n\n"
2678 "<b>%s</b> %d\n"
2679 "<b>%s</b> %d\n"
2680 "<b>%s</b> %d\n"
2681 "<b>%s</b> %d\n"
2682 "<b>%s</b> %d\n"
2683 "<b>%s</b> %d",
2684 _("Message summary"),
2685 _("New:"), n_new,
2686 _("Unread:"), n_unread,
2687 _("Total:"), n_total,
2688 _("Size:"), to_human_readable((goffset)n_size),
2689 _("Marked:"), n_marked,
2690 _("Replied:"), n_replied,
2691 _("Forwarded:"), n_forwarded,
2692 _("Locked:"), n_locked,
2693 _("Ignored:"), n_ignored,
2694 _("Watched:"), n_watched);
2696 gtk_widget_set_tooltip_markup(GTK_WIDGET(summaryview->statlabel_msgs),
2697 tooltip);
2698 g_free(tooltip);
2699 } else {
2700 gchar *ssize, *tsize;
2701 if (n_selected) {
2702 ssize = g_strdup(to_human_readable((goffset)sel_size));
2703 tsize = g_strdup(to_human_readable((goffset)n_size));
2704 str = g_strdup_printf(_("%d/%d selected (%s/%s), %d unread"),
2705 n_selected, n_total, ssize, tsize, n_unread);
2706 g_free(ssize);
2707 g_free(tsize);
2708 } else
2709 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2710 n_new, n_unread, n_total, to_human_readable((goffset)n_size));
2711 g_free(sel);
2712 g_free(del);
2713 g_free(mv);
2714 g_free(cp);
2715 g_free(itstr);
2717 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2718 g_free(str);
2721 summary_set_menu_sensitive(summaryview);
2722 toolbar_main_set_sensitive(summaryview->mainwin);
2725 static void summary_set_column_titles(SummaryView *summaryview)
2727 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2728 FolderItem *item = summaryview->folder_item;
2729 GtkWidget *hbox;
2730 GtkWidget *label;
2731 GtkWidget *arrow;
2732 gint pos;
2733 const gchar *title;
2734 SummaryColumnType type;
2735 GtkJustification justify;
2737 static FolderSortKey sort_by[N_SUMMARY_COLS] = {
2738 SORT_BY_MARK,
2739 SORT_BY_STATUS,
2740 SORT_BY_MIME,
2741 SORT_BY_SUBJECT,
2742 SORT_BY_FROM,
2743 SORT_BY_TO,
2744 SORT_BY_DATE,
2745 SORT_BY_SIZE,
2746 SORT_BY_NUMBER,
2747 SORT_BY_SCORE,
2748 SORT_BY_LOCKED,
2749 SORT_BY_TAGS
2752 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
2753 type = summaryview->col_state[pos].type;
2755 /* CLAWS: mime and unread are single char headers */
2756 justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
2757 ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
2759 switch (type) {
2760 case S_COL_SUBJECT:
2761 case S_COL_FROM:
2762 case S_COL_TO:
2763 case S_COL_DATE:
2764 case S_COL_NUMBER:
2765 if(type == S_COL_FROM && item != NULL &&
2766 FOLDER_SHOWS_TO_HDR(item) &&
2767 !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2768 type = S_COL_TO;
2769 if(type == S_COL_NUMBER)
2770 title = gettext(col_label[type]);
2771 else
2772 title = prefs_common_translated_header_name(col_label[type]);
2773 break;
2774 default:
2775 title = gettext(col_label[type]);
2778 if (type == S_COL_MIME) {
2779 label = gtk_image_new_from_pixbuf(clipxpm);
2780 gtk_widget_show(label);
2781 gtk_cmclist_set_column_widget(clist, pos, label);
2782 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Attachment"));
2783 continue;
2784 } else if (type == S_COL_MARK) {
2785 label = gtk_image_new_from_pixbuf(markxpm);
2786 gtk_widget_show(label);
2787 gtk_cmclist_set_column_widget(clist, pos, label);
2788 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Mark"));
2789 continue;
2790 } else if (type == S_COL_LOCKED) {
2791 label = gtk_image_new_from_pixbuf(lockedxpm);
2792 gtk_widget_show(label);
2793 gtk_cmclist_set_column_widget(clist, pos, label);
2794 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Locked"));
2795 continue;
2796 } else if (type == S_COL_STATUS) {
2797 gtk_cmclist_set_column_title(clist, pos, title);
2798 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Status"));
2799 continue;
2802 hbox = gtk_hbox_new(FALSE, 4);
2803 label = gtk_label_new(title);
2804 #ifdef GENERIC_UMPC
2805 gtk_widget_set_size_request(hbox, -1, 20);
2806 #endif
2808 if (justify == GTK_JUSTIFY_RIGHT)
2809 gtk_box_pack_end(GTK_BOX(hbox), label,
2810 FALSE, FALSE, 0);
2811 else
2812 gtk_box_pack_start(GTK_BOX(hbox), label,
2813 FALSE, FALSE, 0);
2815 if (summaryview->sort_key == sort_by[type] ||
2816 (summaryview->sort_key == SORT_BY_THREAD_DATE &&
2817 sort_by[SORT_BY_DATE] && type == S_COL_DATE)) {
2818 arrow = gtk_arrow_new
2819 (summaryview->sort_type == SORT_ASCENDING
2820 ? GTK_ARROW_DOWN : GTK_ARROW_UP,
2821 GTK_SHADOW_IN);
2822 gtk_widget_set_size_request(GTK_WIDGET(arrow), 10, 10);
2823 if (justify == GTK_JUSTIFY_RIGHT)
2824 gtk_box_pack_start(GTK_BOX(hbox), arrow,
2825 FALSE, FALSE, 0);
2826 else
2827 gtk_box_pack_end(GTK_BOX(hbox), arrow,
2828 FALSE, FALSE, 0);
2831 gtk_widget_show_all(hbox);
2832 gtk_cmclist_set_column_widget(clist, pos, hbox);
2836 void summary_reflect_tags_changes(SummaryView *summaryview)
2838 GtkMenuShell *menu;
2839 GList *children, *cur;
2840 GtkCMCTreeNode *node;
2841 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2842 gboolean froze = FALSE;
2843 gboolean redisplay = FALSE;
2845 /* re-create colorlabel submenu */
2846 menu = GTK_MENU_SHELL(summaryview->tags_menu);
2847 cm_return_if_fail(menu != NULL);
2849 /* clear items. get item pointers. */
2850 children = gtk_container_get_children(GTK_CONTAINER(menu));
2851 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2852 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2854 g_list_free(children);
2855 summary_tags_menu_create(summaryview, TRUE);
2857 START_LONG_OPERATION(summaryview, TRUE);
2858 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
2859 node = gtkut_ctree_node_next(ctree, node)) {
2860 redisplay |= summary_set_row_tag(summaryview,
2861 node, TRUE, FALSE, 0);
2863 END_LONG_OPERATION(summaryview);
2864 if (redisplay)
2865 summary_redisplay_msg(summaryview);
2869 void summary_reflect_prefs(void)
2871 static gchar *last_smallfont = NULL;
2872 static gchar *last_normalfont = NULL;
2873 static gchar *last_boldfont = NULL;
2874 static gboolean last_derive = 0;
2875 gboolean update_font = FALSE;
2876 SummaryView *summaryview = NULL;
2878 if (!mainwindow_get_mainwindow())
2879 return;
2880 summaryview = mainwindow_get_mainwindow()->summaryview;
2882 if (!last_smallfont || strcmp(last_smallfont, SMALL_FONT) ||
2883 !last_normalfont || strcmp(last_normalfont, NORMAL_FONT) ||
2884 !last_boldfont || strcmp(last_boldfont, BOLD_FONT) ||
2885 last_derive != prefs_common.derive_from_normal_font)
2886 update_font = TRUE;
2888 g_free(last_smallfont);
2889 last_smallfont = g_strdup(SMALL_FONT);
2890 g_free(last_normalfont);
2891 last_normalfont = g_strdup(NORMAL_FONT);
2892 g_free(last_boldfont);
2893 last_boldfont = g_strdup(BOLD_FONT);
2894 last_derive = prefs_common.derive_from_normal_font;
2896 #define STYLE_FREE(s) \
2897 if (s != NULL) { \
2898 g_object_unref(s); \
2899 s = NULL; \
2902 if (update_font) {
2903 STYLE_FREE(bold_style);
2904 STYLE_FREE(bold_style);
2905 STYLE_FREE(bold_marked_style);
2906 STYLE_FREE(bold_deleted_style);
2907 STYLE_FREE(small_style);
2908 STYLE_FREE(small_marked_style);
2909 STYLE_FREE(small_deleted_style);
2910 summary_set_fonts(summaryview);
2913 #undef STYLE_FREE
2915 summary_set_column_titles(summaryview);
2916 summary_relayout(summaryview);
2918 if (summaryview->folder_item)
2919 summary_show(summaryview, summaryview->folder_item);
2922 void summary_sort(SummaryView *summaryview,
2923 FolderSortKey sort_key, FolderSortType sort_type)
2925 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2926 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2927 GtkCMCListCompareFunc cmp_func = NULL;
2928 START_TIMING("");
2929 g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
2930 G_CALLBACK(summary_tree_expanded), summaryview);
2931 summary_freeze(summaryview);
2933 switch (sort_key) {
2934 case SORT_BY_MARK:
2935 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mark;
2936 break;
2937 case SORT_BY_STATUS:
2938 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_status;
2939 break;
2940 case SORT_BY_MIME:
2941 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mime;
2942 break;
2943 case SORT_BY_NUMBER:
2944 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_num;
2945 break;
2946 case SORT_BY_SIZE:
2947 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_size;
2948 break;
2949 case SORT_BY_DATE:
2950 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_date;
2951 break;
2952 case SORT_BY_THREAD_DATE:
2953 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_thread_date;
2954 break;
2955 case SORT_BY_FROM:
2956 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_from;
2957 break;
2958 case SORT_BY_SUBJECT:
2959 if (summaryview->simplify_subject_preg)
2960 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_simplified_subject;
2961 else
2962 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_subject;
2963 break;
2964 case SORT_BY_SCORE:
2965 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_score;
2966 break;
2967 case SORT_BY_LABEL:
2968 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_label;
2969 break;
2970 case SORT_BY_TO:
2971 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_to;
2972 break;
2973 case SORT_BY_LOCKED:
2974 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_locked;
2975 break;
2976 case SORT_BY_TAGS:
2977 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_tags;
2978 break;
2979 case SORT_BY_NONE:
2980 break;
2981 default:
2982 goto unlock;
2985 summaryview->sort_key = sort_key;
2986 summaryview->sort_type = sort_type;
2988 summary_set_column_titles(summaryview);
2989 summary_set_menu_sensitive(summaryview);
2991 /* allow fallback to don't sort */
2992 if (summaryview->sort_key == SORT_BY_NONE)
2993 goto unlock;
2995 if (cmp_func != NULL) {
2996 debug_print("Sorting summary...\n");
2997 STATUSBAR_PUSH(summaryview->mainwin, _("Sorting summary..."));
2999 main_window_cursor_wait(summaryview->mainwin);
3001 gtk_cmclist_set_compare_func(clist, cmp_func);
3003 gtk_cmclist_set_sort_type(clist, (GtkSortType)sort_type);
3004 gtk_sctree_sort_recursive(ctree, NULL);
3006 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
3008 main_window_cursor_normal(summaryview->mainwin);
3010 debug_print("Sorting summary done.\n");
3011 STATUSBAR_POP(summaryview->mainwin);
3013 unlock:
3014 summary_thaw(summaryview);
3015 g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
3016 G_CALLBACK(summary_tree_expanded), summaryview);
3017 END_TIMING();
3020 static gboolean summary_update_thread_age(GNode *node, gpointer data)
3022 MsgInfo *msginfo = node->data;
3023 time_t *most_recent = (time_t *)data;
3025 if (msginfo->date_t > *most_recent) {
3026 *most_recent = msginfo->date_t;
3028 return FALSE;
3031 static void summary_find_thread_age(GNode *gnode)
3033 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3034 time_t most_recent;
3036 if (!msginfo)
3037 return;
3038 most_recent = msginfo->thread_date = msginfo->date_t;
3040 g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_thread_age, &most_recent);
3042 msginfo->thread_date = most_recent;
3045 static gboolean summary_update_is_read(GNode *node, gpointer data)
3047 MsgInfo *msginfo = node->data;
3048 gboolean *all_read = (gboolean *)data;
3050 if (MSG_IS_UNREAD(msginfo->flags)) {
3051 *all_read = FALSE;
3052 return TRUE;
3054 return FALSE;
3057 static gboolean summary_thread_is_read(GNode *gnode)
3059 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3060 gboolean all_read = TRUE;
3062 if (!msginfo)
3063 return all_read;
3065 g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_is_read, &all_read);
3066 return all_read;
3069 static gboolean summary_insert_gnode_func(GtkCMCTree *ctree, guint depth, GNode *gnode,
3070 GtkCMCTreeNode *cnode, gpointer data)
3072 SummaryView *summaryview = (SummaryView *)data;
3073 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3074 gchar *text[N_SUMMARY_COLS];
3075 gint *col_pos = summaryview->col_pos;
3076 const gchar *msgid = msginfo->msgid;
3077 GHashTable *msgid_table = summaryview->msgid_table;
3078 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3079 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3081 summary_set_header(summaryview, text, msginfo);
3083 gtk_cmctree_set_node_info(ctree, cnode, text[col_pos[S_COL_SUBJECT]], 2,
3084 NULL, NULL, FALSE, summaryview->threaded && !summaryview->thread_collapsed);
3085 #define SET_TEXT(col) { \
3086 gtk_cmctree_node_set_text(ctree, cnode, col_pos[col], \
3087 text[col_pos[col]]); \
3090 if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3091 SET_TEXT(S_COL_NUMBER);
3092 if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3093 SET_TEXT(S_COL_SCORE);
3094 if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3095 SET_TEXT(S_COL_SIZE);
3096 if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible)
3097 SET_TEXT(S_COL_DATE);
3098 if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
3099 SET_TEXT(S_COL_FROM);
3100 if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
3101 SET_TEXT(S_COL_TO);
3102 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible)
3103 SET_TEXT(S_COL_TAGS);
3105 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3106 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3108 #undef SET_TEXT
3110 GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
3111 summary_set_marks_func(ctree, cnode, summaryview);
3113 if (msgid && msgid[0] != '\0')
3114 g_hash_table_insert(msgid_table, (gchar *)msgid, cnode);
3116 return TRUE;
3119 static void summary_set_ctree_from_list(SummaryView *summaryview,
3120 GSList *mlist)
3122 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3123 MsgInfo *msginfo;
3124 GtkCMCTreeNode *node = NULL;
3125 GHashTable *msgid_table;
3126 GHashTable *subject_table = NULL;
3127 GSList * cur;
3128 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3129 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3130 START_TIMING("");
3132 if (!mlist) return;
3134 debug_print("Setting summary from message data...\n");
3135 STATUSBAR_PUSH(summaryview->mainwin,
3136 _("Setting summary from message data..."));
3137 gdk_flush();
3139 g_signal_handlers_block_by_func(G_OBJECT(ctree),
3140 G_CALLBACK(summary_tree_expanded), summaryview);
3142 msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
3143 summaryview->msgid_table = msgid_table;
3145 if (prefs_common.thread_by_subject) {
3146 subject_table = g_hash_table_new(g_str_hash, g_str_equal);
3147 summaryview->subject_table = subject_table;
3148 } else {
3149 summaryview->subject_table = NULL;
3152 if (prefs_common.use_addr_book)
3153 start_address_completion(NULL);
3155 if (summaryview->threaded) {
3156 GNode *root, *gnode;
3157 START_TIMING("threaded");
3158 root = procmsg_get_thread_tree(mlist);
3161 for (gnode = root->children; gnode != NULL;
3162 gnode = gnode->next) {
3163 if (!summaryview->folder_item->hide_read_threads ||
3164 !summary_thread_is_read(gnode))
3166 summary_find_thread_age(gnode);
3167 node = gtk_sctree_insert_gnode
3168 (ctree, NULL, node, gnode,
3169 summary_insert_gnode_func, summaryview);
3173 g_node_destroy(root);
3175 END_TIMING();
3176 } else {
3177 gchar *text[N_SUMMARY_COLS];
3178 START_TIMING("unthreaded");
3179 cur = mlist;
3180 for (; mlist != NULL; mlist = mlist->next) {
3181 msginfo = (MsgInfo *)mlist->data;
3183 summary_set_header(summaryview, text, msginfo);
3185 node = gtk_sctree_insert_node
3186 (ctree, NULL, node, text, 2,
3187 NULL, NULL,
3188 FALSE, FALSE);
3189 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3190 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3192 GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
3193 summary_set_marks_func(ctree, node, summaryview);
3195 if (msginfo->msgid && msginfo->msgid[0] != '\0')
3196 g_hash_table_insert(msgid_table,
3197 msginfo->msgid, node);
3199 if (prefs_common.thread_by_subject)
3200 subject_table_insert(subject_table,
3201 msginfo->subject,
3202 node);
3204 mlist = cur;
3205 END_TIMING();
3208 if (prefs_common.enable_hscrollbar &&
3209 summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
3210 gint optimal_width;
3212 optimal_width = gtk_cmclist_optimal_column_width
3213 (GTK_CMCLIST(ctree), summaryview->col_pos[S_COL_SUBJECT]);
3214 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree),
3215 summaryview->col_pos[S_COL_SUBJECT],
3216 optimal_width);
3219 if (prefs_common.use_addr_book)
3220 end_address_completion();
3222 debug_print("Setting summary from message data done.\n");
3223 STATUSBAR_POP(summaryview->mainwin);
3224 if (debug_get_mode()) {
3225 debug_print("\tmsgid hash table size = %d\n",
3226 g_hash_table_size(msgid_table));
3227 if (prefs_common.thread_by_subject)
3228 debug_print("\tsubject hash table size = %d\n",
3229 g_hash_table_size(subject_table));
3232 summary_sort(summaryview, summaryview->sort_key, summaryview->sort_type);
3234 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3236 if (prefs_common.bold_unread) {
3237 START_TIMING("bold_unread");
3238 while (node) {
3239 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
3240 if (GTK_CMCTREE_ROW(node)->children)
3241 summary_set_row_marks(summaryview, node);
3242 node = next;
3244 END_TIMING();
3247 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
3248 G_CALLBACK(summary_tree_expanded), summaryview);
3249 END_TIMING();
3252 static gchar *summary_complete_address(const gchar *addr)
3254 gint count;
3255 gchar *res, *tmp, *email_addr;
3257 if (addr == NULL || !strchr(addr, '@'))
3258 return NULL;
3260 Xstrdup_a(email_addr, addr, return NULL);
3261 extract_address(email_addr);
3262 if (!*email_addr)
3263 return NULL;
3266 * completion stuff must be already initialized
3268 res = NULL;
3269 if (1 < (count = complete_address(email_addr))) {
3270 tmp = get_complete_address(1);
3271 res = procheader_get_fromname(tmp);
3272 g_free(tmp);
3275 return res;
3278 static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
3279 MsgInfo *msginfo)
3281 static gchar date_modified[80];
3282 static gchar col_score[11];
3283 static gchar buf[BUFFSIZE], tmp1[BUFFSIZE], tmp2[BUFFSIZE], tmp3[BUFFSIZE];
3284 gint *col_pos = summaryview->col_pos;
3285 gchar *from_text = NULL, *to_text = NULL, *tags_text = NULL;
3286 gboolean should_swap = FALSE;
3287 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3288 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3289 static const gchar *color_dim_rgb = NULL;
3290 if (!color_dim_rgb)
3291 color_dim_rgb = gdk_color_to_string(&summaryview->color_dim);
3292 text[col_pos[S_COL_FROM]] = "";
3293 text[col_pos[S_COL_TO]] = "";
3294 text[col_pos[S_COL_SUBJECT]]= "";
3295 text[col_pos[S_COL_MARK]] = "";
3296 text[col_pos[S_COL_STATUS]] = "";
3297 text[col_pos[S_COL_MIME]] = "";
3298 text[col_pos[S_COL_LOCKED]] = "";
3299 text[col_pos[S_COL_DATE]] = "";
3300 text[col_pos[S_COL_TAGS]] = "";
3301 if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3302 text[col_pos[S_COL_NUMBER]] = itos(msginfo->msgnum);
3303 else
3304 text[col_pos[S_COL_NUMBER]] = "";
3306 /* slow! */
3307 if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3308 text[col_pos[S_COL_SIZE]] = to_human_readable(msginfo->size);
3309 else
3310 text[col_pos[S_COL_SIZE]] = "";
3312 if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3313 text[col_pos[S_COL_SCORE]] = itos_buf(col_score, msginfo->score);
3314 else
3315 text[col_pos[S_COL_SCORE]] = "";
3317 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
3318 tags_text = procmsg_msginfo_get_tags_str(msginfo);
3319 if (!tags_text) {
3320 text[col_pos[S_COL_TAGS]] = "-";
3321 } else {
3322 strncpy2(tmp1, tags_text, sizeof(tmp1));
3323 tmp1[sizeof(tmp1)-1]='\0';
3324 g_free(tags_text);
3325 text[col_pos[S_COL_TAGS]] = tmp1;
3327 } else
3328 text[col_pos[S_COL_TAGS]] = "";
3330 /* slow! */
3331 if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible ||
3332 ((vert_layout || small_layout) && prefs_common.two_line_vert)) {
3333 if (msginfo->date_t && msginfo->date_t > 0) {
3334 procheader_date_get_localtime(date_modified,
3335 sizeof(date_modified),
3336 msginfo->date_t);
3337 text[col_pos[S_COL_DATE]] = date_modified;
3338 } else if (msginfo->date)
3339 text[col_pos[S_COL_DATE]] = msginfo->date;
3340 else
3341 text[col_pos[S_COL_DATE]] = _("(No Date)");
3344 if (prefs_common.swap_from && msginfo->from && msginfo->to
3345 && !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible) {
3346 gchar *addr = NULL;
3348 addr = g_strdup(msginfo->from);
3350 if (addr) {
3351 extract_address(addr);
3352 if (account_find_from_address(addr, FALSE)) {
3353 should_swap = TRUE;
3355 g_free(addr);
3359 if (!prefs_common.use_addr_book) {
3360 if (prefs_common.summary_from_show == SHOW_NAME)
3361 from_text = msginfo->fromname;
3362 else if (prefs_common.summary_from_show == SHOW_BOTH)
3363 from_text = msginfo->from;
3364 else {
3365 from_text = msginfo->from;
3366 extract_address(from_text);
3368 if (!from_text)
3369 from_text = _("(No From)");
3370 } else {
3371 gchar *tmp = summary_complete_address(msginfo->from);
3372 if (tmp) {
3373 strncpy2(buf, tmp, sizeof(buf));
3374 g_free(tmp);
3375 from_text = buf;
3376 } else {
3377 if (prefs_common.summary_from_show == SHOW_NAME)
3378 from_text = msginfo->fromname;
3379 else if (prefs_common.summary_from_show == SHOW_BOTH)
3380 from_text = msginfo->from;
3381 else {
3382 from_text = msginfo->from;
3383 if (from_text)
3384 extract_address(from_text);
3386 if (!from_text)
3387 from_text = _("(No From)");
3391 to_text = msginfo->to ? msginfo->to :
3392 (msginfo->cc ? msginfo->cc :
3393 (msginfo->newsgroups ? msginfo->newsgroups : _("(No Recipient)")
3397 text[col_pos[S_COL_TO]] = to_text;
3398 if (!should_swap) {
3399 text[col_pos[S_COL_FROM]] = from_text;
3400 } else {
3401 if (prefs_common.use_addr_book) {
3402 gchar *tmp = summary_complete_address(to_text);
3403 if (tmp) {
3404 strncpy2(buf, tmp, sizeof(buf));
3405 g_free(tmp);
3406 to_text = buf;
3407 } else {
3408 to_text = to_text ? to_text : _("(No From)");
3411 snprintf(tmp2, BUFFSIZE-1, "➜ %s", to_text);
3412 tmp2[BUFFSIZE-1]='\0';
3413 text[col_pos[S_COL_FROM]] = tmp2;
3416 if (summaryview->simplify_subject_preg != NULL)
3417 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ?
3418 string_remove_match(tmp3, BUFFSIZE, msginfo->subject,
3419 summaryview->simplify_subject_preg) :
3420 _("(No Subject)");
3421 else
3422 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? msginfo->subject :
3423 _("(No Subject)");
3424 if ((vert_layout || small_layout) && prefs_common.two_line_vert) {
3425 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) {
3426 gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3427 "<span color='%s' style='italic'>",
3428 _("From: %s, on %s"), "</span>", NULL),
3429 text[col_pos[S_COL_SUBJECT]],
3430 color_dim_rgb,
3431 text[col_pos[S_COL_FROM]],
3432 text[col_pos[S_COL_DATE]]);
3433 text[col_pos[S_COL_SUBJECT]] = tmp;
3434 } else {
3435 gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3436 "<span color='%s' style='italic'>",
3437 _("To: %s, on %s"), "</span>", NULL),
3438 text[col_pos[S_COL_SUBJECT]],
3439 color_dim_rgb,
3440 text[col_pos[S_COL_TO]],
3441 text[col_pos[S_COL_DATE]]);
3442 text[col_pos[S_COL_SUBJECT]] = tmp;
3447 static void summary_display_msg(SummaryView *summaryview, GtkCMCTreeNode *row)
3449 summary_display_msg_full(summaryview, row, FALSE, FALSE);
3452 static gboolean defer_change(gpointer data);
3453 typedef struct _ChangeData {
3454 MsgInfo *info;
3455 gint op; /* 0, 1, 2 for unset, set, change */
3456 MsgPermFlags set_flags;
3457 MsgTmpFlags set_tmp_flags;
3458 MsgPermFlags unset_flags;
3459 MsgTmpFlags unset_tmp_flags;
3460 } ChangeData;
3462 static void summary_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3464 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3465 debug_print("flags: doing unset now\n");
3466 procmsg_msginfo_unset_flags(msginfo, flags, tmp_flags);
3467 } else {
3468 ChangeData *unset_data = g_new0(ChangeData, 1);
3469 unset_data->info = msginfo;
3470 unset_data->op = 0;
3471 unset_data->unset_flags = flags;
3472 unset_data->unset_tmp_flags = tmp_flags;
3473 debug_print("flags: deferring unset\n");
3474 g_timeout_add(100, defer_change, unset_data);
3478 static void summary_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3480 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3481 debug_print("flags: doing set now\n");
3482 procmsg_msginfo_set_flags(msginfo, flags, tmp_flags);
3483 } else {
3484 ChangeData *set_data = g_new0(ChangeData, 1);
3485 set_data->info = msginfo;
3486 set_data->op = 1;
3487 set_data->set_flags = flags;
3488 set_data->set_tmp_flags = tmp_flags;
3489 debug_print("flags: deferring set\n");
3490 g_timeout_add(100, defer_change, set_data);
3494 static void summary_msginfo_change_flags(MsgInfo *msginfo,
3495 MsgPermFlags add_flags, MsgTmpFlags add_tmp_flags,
3496 MsgPermFlags rem_flags, MsgTmpFlags rem_tmp_flags)
3498 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3499 debug_print("flags: doing change now\n");
3500 procmsg_msginfo_change_flags(msginfo, add_flags, add_tmp_flags,
3501 rem_flags, rem_tmp_flags);
3502 } else {
3503 ChangeData *change_data = g_new0(ChangeData, 1);
3504 change_data->info = msginfo;
3505 change_data->op = 2;
3506 change_data->set_flags = add_flags;
3507 change_data->set_tmp_flags = add_tmp_flags;
3508 change_data->unset_flags = rem_flags;
3509 change_data->unset_tmp_flags = rem_tmp_flags;
3510 debug_print("flags: deferring change\n");
3511 g_timeout_add(100, defer_change, change_data);
3515 gboolean defer_change(gpointer data)
3517 ChangeData *chg = (ChangeData *)data;
3518 if (chg->info->folder && chg->info->folder->processing_pending) {
3519 debug_print("flags: trying later\n");
3520 return TRUE; /* try again */
3521 } else {
3522 debug_print("flags: finally doing it\n");
3523 switch(chg->op) {
3524 case 0:
3525 procmsg_msginfo_unset_flags(chg->info, chg->unset_flags, chg->unset_tmp_flags);
3526 break;
3527 case 1:
3528 procmsg_msginfo_set_flags(chg->info, chg->set_flags, chg->set_tmp_flags);
3529 break;
3530 case 2:
3531 procmsg_msginfo_change_flags(chg->info, chg->set_flags, chg->set_tmp_flags,
3532 chg->unset_flags, chg->unset_tmp_flags);
3533 break;
3534 default:
3535 g_warning("unknown change op");
3537 g_free(chg);
3539 return FALSE;
3542 static void msginfo_mark_as_read (SummaryView *summaryview, MsgInfo *msginfo,
3543 GtkCMCTreeNode *row)
3545 cm_return_if_fail(summaryview != NULL);
3546 cm_return_if_fail(msginfo != NULL);
3547 cm_return_if_fail(row != NULL);
3549 if (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)) {
3550 summary_msginfo_unset_flags
3551 (msginfo, MSG_NEW | MSG_UNREAD, 0);
3552 summary_set_row_marks(summaryview, row);
3553 summary_status_show(summaryview);
3557 typedef struct {
3558 MsgInfo *msginfo;
3559 SummaryView *summaryview;
3560 } MarkAsReadData;
3562 static int msginfo_mark_as_read_timeout(void *data)
3564 MarkAsReadData *mdata = (MarkAsReadData *)data;
3565 if (!mdata)
3566 return FALSE;
3568 summary_lock(mdata->summaryview);
3569 if (mdata->msginfo == summary_get_selected_msg(mdata->summaryview))
3570 msginfo_mark_as_read(mdata->summaryview, mdata->msginfo,
3571 mdata->summaryview->selected);
3572 procmsg_msginfo_free(&(mdata->msginfo));
3574 mdata->summaryview->mark_as_read_timeout_tag = 0;
3575 summary_unlock(mdata->summaryview);
3577 g_free(mdata);
3578 return FALSE;
3581 static void summary_display_msg_full(SummaryView *summaryview,
3582 GtkCMCTreeNode *row,
3583 gboolean new_window, gboolean all_headers)
3585 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3586 MsgInfo *msginfo;
3587 gint val;
3588 START_TIMING("");
3589 if (!new_window) {
3590 if (summaryview->displayed == row &&
3591 messageview_is_visible(summaryview->messageview))
3592 return;
3593 else if (summaryview->messageview)
3594 summaryview->messageview->filtered = FALSE;
3596 cm_return_if_fail(row != NULL);
3598 if (summary_is_locked(summaryview)) return;
3599 summary_lock(summaryview);
3601 STATUSBAR_POP(summaryview->mainwin);
3602 GTK_EVENTS_FLUSH();
3604 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3606 if (!msginfo) {
3607 debug_print("NULL msginfo\n");
3608 summary_unlock(summaryview);
3609 END_TIMING();
3610 return;
3613 if (new_window && prefs_common.layout_mode != SMALL_LAYOUT) {
3614 MessageView *msgview;
3616 msgview = messageview_create_with_new_window(summaryview->mainwin);
3617 val = messageview_show(msgview, msginfo, all_headers);
3618 } else {
3619 MessageView *msgview;
3621 if (prefs_common.layout_mode == SMALL_LAYOUT) {
3622 if (summaryview->ext_messageview == NULL)
3623 summaryview->ext_messageview = messageview_create_with_new_window(summaryview->mainwin);
3624 else
3625 gtkut_window_popup(summaryview->ext_messageview->window);
3626 msgview = summaryview->ext_messageview;
3627 summaryview->displayed = row;
3628 val = messageview_show(msgview, msginfo, all_headers);
3629 if (mimeview_tree_is_empty(msgview->mimeview))
3630 gtk_widget_grab_focus(summaryview->ctree);
3631 gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3632 GTK_CMCLIST(summaryview->ctree)->focus_row);
3633 } else {
3634 msgview = summaryview->messageview;
3635 summaryview->displayed = row;
3636 if (!messageview_is_visible(msgview) &&
3637 gtk_window_is_active(GTK_WINDOW(summaryview->mainwin->window))) {
3638 main_window_toggle_message_view(summaryview->mainwin);
3639 GTK_EVENTS_FLUSH();
3641 val = messageview_show(msgview, msginfo, all_headers);
3642 if (mimeview_tree_is_empty(msgview->mimeview))
3643 gtk_widget_grab_focus(summaryview->ctree);
3644 gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3645 GTK_CMCLIST(summaryview->ctree)->focus_row);
3649 if (val == 0 && MSG_IS_UNREAD(msginfo->flags)) {
3650 if (!prefs_common.mark_as_read_on_new_window &&
3651 prefs_common.mark_as_read_delay) {
3652 MarkAsReadData *data = g_new0(MarkAsReadData, 1);
3653 data->summaryview = summaryview;
3654 data->msginfo = procmsg_msginfo_new_ref(msginfo);
3655 if (summaryview->mark_as_read_timeout_tag != 0)
3656 g_source_remove(summaryview->mark_as_read_timeout_tag);
3657 summaryview->mark_as_read_timeout_tag =
3658 g_timeout_add_seconds(prefs_common.mark_as_read_delay,
3659 msginfo_mark_as_read_timeout, data);
3660 } else if (new_window || !prefs_common.mark_as_read_on_new_window) {
3661 msginfo_mark_as_read(summaryview, msginfo, row);
3665 summary_set_menu_sensitive(summaryview);
3666 toolbar_main_set_sensitive(summaryview->mainwin);
3667 messageview_set_menu_sensitive(summaryview->messageview);
3669 summary_unlock(summaryview);
3670 END_TIMING();
3673 void summary_display_msg_selected(SummaryView *summaryview,
3674 gboolean all_headers)
3676 if (summary_is_locked(summaryview)) return;
3677 summaryview->displayed = NULL;
3678 summary_display_msg_full(summaryview, summaryview->selected, FALSE,
3679 all_headers);
3682 void summary_redisplay_msg(SummaryView *summaryview)
3684 GtkCMCTreeNode *node;
3686 if (summaryview->displayed) {
3687 node = summaryview->displayed;
3688 summaryview->displayed = NULL;
3689 summary_display_msg(summaryview, node);
3693 void summary_open_msg(SummaryView *summaryview)
3695 if (!summaryview->selected) return;
3697 /* CLAWS: if separate message view, don't open a new window
3698 * but rather use the current separated message view */
3699 summary_display_msg_full(summaryview, summaryview->selected,
3700 TRUE, FALSE);
3703 void summary_view_source(SummaryView * summaryview)
3705 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3706 MsgInfo *msginfo;
3707 SourceWindow *srcwin;
3709 if (!summaryview->selected) return;
3711 srcwin = source_window_create();
3712 msginfo = gtk_cmctree_node_get_row_data(ctree, summaryview->selected);
3713 source_window_show_msg(srcwin, msginfo);
3714 source_window_show(srcwin);
3717 void summary_reedit(SummaryView *summaryview)
3719 MsgInfo *msginfo;
3721 if (!summaryview->selected) return;
3722 if (!summaryview->folder_item) return;
3723 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item))
3724 return;
3726 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
3727 summaryview->selected);
3728 if (!msginfo) return;
3730 compose_reedit(msginfo, FALSE);
3733 gboolean summary_is_list(SummaryView *summaryview)
3735 return (gtk_notebook_get_current_page(
3736 GTK_NOTEBOOK(summaryview->mainwidget_book)) == 0);
3739 void summary_toggle_view(SummaryView *summaryview)
3741 if (prefs_common.layout_mode == SMALL_LAYOUT)
3742 return;
3743 if (summary_is_locked(summaryview))
3744 return;
3745 if (!messageview_is_visible(summaryview->messageview) &&
3746 summaryview->selected && summary_is_list(summaryview))
3747 summary_display_msg(summaryview,
3748 summaryview->selected);
3749 else
3750 main_window_toggle_message_view(summaryview->mainwin);
3753 static gboolean summary_search_unread_recursive(GtkCMCTree *ctree,
3754 GtkCMCTreeNode *node)
3756 MsgInfo *msginfo;
3758 if (node) {
3759 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
3760 if (msginfo && MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
3761 return TRUE;
3762 node = GTK_CMCTREE_ROW(node)->children;
3763 } else
3764 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3766 while (node) {
3767 if (summary_search_unread_recursive(ctree, node) == TRUE)
3768 return TRUE;
3769 node = GTK_CMCTREE_ROW(node)->sibling;
3772 return FALSE;
3775 static gboolean summary_have_unread_children(SummaryView *summaryview,
3776 GtkCMCTreeNode *node)
3778 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3780 if (!node) return FALSE;
3782 node = GTK_CMCTREE_ROW(node)->children;
3784 while (node) {
3785 if (summary_search_unread_recursive(ctree, node) == TRUE)
3786 return TRUE;
3787 node = GTK_CMCTREE_ROW(node)->sibling;
3789 return FALSE;
3792 static void summary_set_row_marks(SummaryView *summaryview, GtkCMCTreeNode *row)
3794 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3795 GtkStyle *style = NULL;
3796 MsgInfo *msginfo;
3797 MsgFlags flags;
3798 gint *col_pos = summaryview->col_pos;
3800 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3801 if (!msginfo) return;
3803 flags = msginfo->flags;
3805 gtk_cmctree_node_set_foreground(ctree, row, NULL);
3807 /* set new/unread column */
3808 if (MSG_IS_IGNORE_THREAD(flags)) {
3809 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3810 ignorethreadxpm);
3811 } else if (MSG_IS_WATCH_THREAD(flags)) {
3812 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3813 watchthreadxpm);
3814 } else if (MSG_IS_SPAM(flags)) {
3815 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3816 spamxpm);
3817 } else if (MSG_IS_NEW(flags)) {
3818 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3819 newxpm);
3820 } else if (MSG_IS_UNREAD(flags)) {
3821 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3822 unreadxpm);
3823 } else if (MSG_IS_REPLIED(flags) && MSG_IS_FORWARDED(flags)) {
3824 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3825 repliedandforwardedxpm);
3826 } else if (MSG_IS_REPLIED(flags)) {
3827 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3828 repliedxpm);
3829 } else if (MSG_IS_FORWARDED(flags)) {
3830 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3831 forwardedxpm);
3832 } else {
3833 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_STATUS],
3834 "");
3837 if (prefs_common.bold_unread &&
3838 ((MSG_IS_UNREAD(flags) && !MSG_IS_IGNORE_THREAD(flags)) ||
3839 (!GTK_CMCTREE_ROW(row)->expanded &&
3840 GTK_CMCTREE_ROW(row)->children &&
3841 summary_have_unread_children(summaryview, row))))
3842 style = bold_style;
3844 /* set mark column */
3845 if (MSG_IS_DELETED(flags)) {
3846 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
3847 deletedxpm);
3848 if (style)
3849 style = bold_deleted_style;
3850 else {
3851 style = small_deleted_style;
3853 gtk_cmctree_node_set_foreground
3854 (ctree, row, &summaryview->color_dim);
3855 } else if (MSG_IS_MARKED(flags)) {
3856 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
3857 markxpm);
3858 } else if (MSG_IS_MOVE(flags)) {
3859 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
3860 movedxpm);
3861 if (!msginfo->to_folder ||
3862 !folder_has_parent_of_type(msginfo->to_folder, F_TRASH)) {
3863 if (style)
3864 style = bold_marked_style;
3865 else {
3866 style = small_marked_style;
3868 gtk_cmctree_node_set_foreground
3869 (ctree, row, &summaryview->color_marked);
3870 } else {
3871 if (style)
3872 style = bold_deleted_style;
3873 else {
3874 style = small_deleted_style;
3876 gtk_cmctree_node_set_foreground
3877 (ctree, row, &summaryview->color_dim);
3879 } else if (MSG_IS_COPY(flags)) {
3880 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
3881 copiedxpm);
3882 if (style)
3883 style = bold_marked_style;
3884 else {
3885 style = small_marked_style;
3887 gtk_cmctree_node_set_foreground
3888 (ctree, row, &summaryview->color_marked);
3889 } else {
3890 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_MARK], "");
3893 if (MSG_IS_LOCKED(flags)) {
3894 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_LOCKED],
3895 lockedxpm);
3897 else {
3898 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_LOCKED], "");
3901 if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_SIGNED(flags)) {
3902 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3903 clipgpgsignedxpm);
3904 } else if (MSG_IS_SIGNED(flags)) {
3905 if (MSG_IS_ENCRYPTED(flags)) {
3906 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3907 keysignxpm);
3908 } else {
3909 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3910 gpgsignedxpm);
3912 } else if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_ENCRYPTED(flags)) {
3913 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3914 clipkeyxpm);
3915 } else if (MSG_IS_ENCRYPTED(flags)) {
3916 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3917 keyxpm);
3918 } else if (MSG_IS_WITH_ATTACHMENT(flags)) {
3919 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
3920 clipxpm);
3921 } else {
3922 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_MIME], "");
3924 if (!style)
3925 style = small_style;
3927 gtk_cmctree_node_set_row_style(ctree, row, style);
3929 if (MSG_GET_COLORLABEL(flags))
3930 summary_set_colorlabel_color(ctree, row, MSG_GET_COLORLABEL_VALUE(flags));
3933 static void summary_mark_row(SummaryView *summaryview, GtkCMCTreeNode *row)
3935 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3936 MsgInfo *msginfo;
3938 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3939 cm_return_if_fail(msginfo);
3940 if (MSG_IS_DELETED(msginfo->flags))
3941 summaryview->deleted--;
3942 if (MSG_IS_MOVE(msginfo->flags))
3943 summaryview->moved--;
3944 if (MSG_IS_COPY(msginfo->flags))
3945 summaryview->copied--;
3947 procmsg_msginfo_set_to_folder(msginfo, NULL);
3948 summary_msginfo_change_flags(msginfo, MSG_MARKED, 0, MSG_DELETED,
3949 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
3950 summary_set_row_marks(summaryview, row);
3951 debug_print("Message %s/%d is marked\n", msginfo->folder->path, msginfo->msgnum);
3954 static void summary_lock_row(SummaryView *summaryview, GtkCMCTreeNode *row)
3956 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3957 MsgInfo *msginfo;
3959 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3960 cm_return_if_fail(msginfo);
3961 if (MSG_IS_DELETED(msginfo->flags))
3962 summaryview->deleted--;
3963 if (MSG_IS_MOVE(msginfo->flags)) {
3964 summaryview->moved--;
3966 if (MSG_IS_COPY(msginfo->flags)) {
3967 summaryview->copied--;
3969 procmsg_msginfo_set_to_folder(msginfo, NULL);
3970 summary_msginfo_change_flags(msginfo, MSG_LOCKED, 0, MSG_DELETED,
3971 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
3973 summary_set_row_marks(summaryview, row);
3974 debug_print("Message %d is locked\n", msginfo->msgnum);
3977 static void summary_unlock_row(SummaryView *summaryview, GtkCMCTreeNode *row)
3979 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3980 MsgInfo *msginfo;
3982 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3983 cm_return_if_fail(msginfo);
3984 if (!MSG_IS_LOCKED(msginfo->flags))
3985 return;
3986 procmsg_msginfo_set_to_folder(msginfo, NULL);
3987 summary_msginfo_unset_flags(msginfo, MSG_LOCKED, 0);
3988 summary_set_row_marks(summaryview, row);
3989 debug_print("Message %d is unlocked\n", msginfo->msgnum);
3992 void summary_mark(SummaryView *summaryview)
3994 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3995 GList *cur;
3996 gboolean froze = FALSE;
3998 if (summary_is_locked(summaryview))
3999 return;
4000 START_LONG_OPERATION(summaryview, FALSE);
4001 folder_item_set_batch(summaryview->folder_item, TRUE);
4002 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4003 summary_mark_row(summaryview, GTK_CMCTREE_NODE(cur->data));
4004 folder_item_set_batch(summaryview->folder_item, FALSE);
4005 END_LONG_OPERATION(summaryview);
4007 summary_status_show(summaryview);
4010 static void summary_mark_row_as_read(SummaryView *summaryview,
4011 GtkCMCTreeNode *row)
4013 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4014 MsgInfo *msginfo;
4016 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4017 cm_return_if_fail(msginfo);
4019 if(!(MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
4020 return;
4022 summary_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
4023 summary_set_row_marks(summaryview, row);
4024 debug_print("Message %d is marked as read\n",
4025 msginfo->msgnum);
4028 void summary_mark_as_read(SummaryView *summaryview)
4030 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4031 GList *cur;
4032 gboolean froze = FALSE;
4034 if (summary_is_locked(summaryview))
4035 return;
4036 START_LONG_OPERATION(summaryview, FALSE);
4037 folder_item_set_batch(summaryview->folder_item, TRUE);
4038 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4039 summary_mark_row_as_read(summaryview,
4040 GTK_CMCTREE_NODE(cur->data));
4041 folder_item_set_batch(summaryview->folder_item, FALSE);
4042 END_LONG_OPERATION(summaryview);
4044 summary_status_show(summaryview);
4047 void summary_msgs_lock(SummaryView *summaryview)
4049 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4050 GList *cur;
4051 gboolean froze = FALSE;
4053 if (summary_is_locked(summaryview))
4054 return;
4055 START_LONG_OPERATION(summaryview, FALSE);
4056 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4057 summary_lock_row(summaryview,
4058 GTK_CMCTREE_NODE(cur->data));
4059 END_LONG_OPERATION(summaryview);
4061 summary_status_show(summaryview);
4064 void summary_msgs_unlock(SummaryView *summaryview)
4066 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4067 GList *cur;
4068 gboolean froze = FALSE;
4070 if (summary_is_locked(summaryview))
4071 return;
4072 START_LONG_OPERATION(summaryview, FALSE);
4073 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4074 summary_unlock_row(summaryview,
4075 GTK_CMCTREE_NODE(cur->data));
4076 END_LONG_OPERATION(summaryview);
4078 summary_status_show(summaryview);
4081 void summary_mark_all_read(SummaryView *summaryview)
4083 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4084 GtkCMCTreeNode *node;
4085 AlertValue val;
4086 gboolean froze = FALSE;
4088 if (prefs_common.ask_mark_all_read) {
4089 val = alertpanel_full(_("Mark all as read"),
4090 _("Do you really want to mark all mails in this "
4091 "folder as read?"), GTK_STOCK_NO, GTK_STOCK_YES, NULL,
4092 TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
4094 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
4095 return;
4096 else if (val & G_ALERTDISABLE)
4097 prefs_common.ask_mark_all_read = FALSE;
4100 if (summary_is_locked(summaryview))
4101 return;
4102 START_LONG_OPERATION(summaryview, TRUE);
4103 folder_item_set_batch(summaryview->folder_item, TRUE);
4104 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4105 node = gtkut_ctree_node_next(ctree, node))
4106 summary_mark_row_as_read(summaryview, node);
4107 folder_item_set_batch(summaryview->folder_item, FALSE);
4108 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4109 node = gtkut_ctree_node_next(ctree, node)) {
4110 if (!GTK_CMCTREE_ROW(node)->expanded)
4111 summary_set_row_marks(summaryview, node);
4113 END_LONG_OPERATION(summaryview);
4115 summary_status_show(summaryview);
4118 void summary_mark_as_spam(SummaryView *summaryview, guint action, GtkWidget *widget)
4120 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4121 GList *cur;
4122 gboolean is_spam = action;
4123 GSList *msgs = NULL;
4124 gboolean immediate_exec = prefs_common.immediate_exec;
4125 gboolean moved = FALSE;
4126 gboolean froze = FALSE;
4129 if (summary_is_locked(summaryview))
4130 return;
4132 prefs_common.immediate_exec = FALSE;
4133 START_LONG_OPERATION(summaryview, FALSE);
4134 folder_item_set_batch(summaryview->folder_item, TRUE);
4135 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4136 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4137 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4138 if (msginfo)
4139 msgs = g_slist_prepend(msgs, msginfo);
4142 if (procmsg_spam_learner_learn(NULL, msgs, is_spam) == 0) {
4143 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4144 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4145 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4146 if (!msginfo)
4147 continue;
4148 if (is_spam) {
4149 summary_msginfo_change_flags(msginfo, MSG_SPAM, 0, MSG_NEW|MSG_UNREAD, 0);
4150 if (procmsg_spam_get_folder(msginfo) != summaryview->folder_item) {
4151 summary_move_row_to(summaryview, row,
4152 procmsg_spam_get_folder(msginfo));
4153 moved = TRUE;
4155 } else {
4156 summary_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
4158 summaryview->display_msg = prefs_common.always_show_msg;
4160 summary_set_row_marks(summaryview, row);
4162 } else {
4163 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
4166 prefs_common.immediate_exec = immediate_exec;
4167 folder_item_set_batch(summaryview->folder_item, FALSE);
4168 END_LONG_OPERATION(summaryview);
4170 if (prefs_common.immediate_exec && moved) {
4171 summary_execute(summaryview);
4174 if (!moved && msgs) {
4175 MsgInfo *msginfo = (MsgInfo *)msgs->data;
4176 toolbar_set_learn_button
4177 (summaryview->mainwin->toolbar,
4178 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
4180 g_slist_free(msgs);
4182 summary_status_show(summaryview);
4186 static void summary_mark_row_as_unread(SummaryView *summaryview,
4187 GtkCMCTreeNode *row)
4189 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4190 MsgInfo *msginfo;
4192 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4193 cm_return_if_fail(msginfo);
4194 if (MSG_IS_DELETED(msginfo->flags)) {
4195 procmsg_msginfo_set_to_folder(msginfo, NULL);
4196 summary_msginfo_unset_flags(msginfo, MSG_DELETED, 0);
4197 summaryview->deleted--;
4200 summary_msginfo_set_flags(msginfo, MSG_UNREAD, 0);
4201 debug_print("Message %d is marked as unread\n",
4202 msginfo->msgnum);
4204 summary_set_row_marks(summaryview, row);
4207 void summary_mark_as_unread(SummaryView *summaryview)
4209 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4210 GList *cur;
4211 gboolean froze = FALSE;
4213 if (summary_is_locked(summaryview))
4214 return;
4215 START_LONG_OPERATION(summaryview, FALSE);
4216 folder_item_set_batch(summaryview->folder_item, TRUE);
4217 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL;
4218 cur = cur->next)
4219 summary_mark_row_as_unread(summaryview,
4220 GTK_CMCTREE_NODE(cur->data));
4221 folder_item_set_batch(summaryview->folder_item, FALSE);
4222 END_LONG_OPERATION(summaryview);
4224 summary_status_show(summaryview);
4227 static gboolean check_permission(SummaryView *summaryview, MsgInfo * msginfo)
4229 GList * cur;
4230 gboolean found;
4232 switch (FOLDER_TYPE(summaryview->folder_item->folder)) {
4234 case F_NEWS:
4237 security : checks if one the accounts correspond to
4238 the author of the post
4241 found = FALSE;
4242 for(cur = account_get_list() ; cur != NULL ; cur = cur->next) {
4243 PrefsAccount * account;
4244 gchar * from_name;
4246 account = cur->data;
4247 if (account->name && *account->name)
4248 from_name =
4249 g_strdup_printf("%s <%s>",
4250 account->name,
4251 account->address);
4252 else
4253 from_name =
4254 g_strdup_printf("%s",
4255 account->address);
4257 if (g_utf8_collate(from_name, msginfo->from) == 0) {
4258 g_free(from_name);
4259 found = TRUE;
4260 break;
4262 g_free(from_name);
4265 if (!found) {
4266 alertpanel_error(_("You're not the author of the article.\n"));
4269 return found;
4271 default:
4272 return TRUE;
4276 static void summary_delete_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4278 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4279 MsgInfo *msginfo;
4281 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4282 cm_return_if_fail(msginfo);
4284 if (MSG_IS_LOCKED(msginfo->flags)) return;
4286 if (MSG_IS_DELETED(msginfo->flags)) return;
4288 if (MSG_IS_MOVE(msginfo->flags))
4289 summaryview->moved--;
4290 if (MSG_IS_COPY(msginfo->flags))
4291 summaryview->copied--;
4293 procmsg_msginfo_set_to_folder(msginfo, NULL);
4294 summary_msginfo_change_flags(msginfo, MSG_DELETED, 0, MSG_MARKED,
4295 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4296 summaryview->deleted++;
4298 if (!prefs_common.immediate_exec &&
4299 !folder_has_parent_of_type(summaryview->folder_item, F_TRASH)) {
4300 summary_set_row_marks(summaryview, row);
4302 debug_print("Message %s/%d is set to delete\n",
4303 msginfo->folder->path, msginfo->msgnum);
4306 void summary_cancel(SummaryView *summaryview)
4308 MsgInfo * msginfo;
4310 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
4311 summaryview->selected);
4312 if (!msginfo) return;
4314 if (!check_permission(summaryview, msginfo))
4315 return;
4317 news_cancel_article(summaryview->folder_item->folder, msginfo);
4319 if (summary_is_locked(summaryview)) return;
4321 summary_lock(summaryview);
4323 summary_freeze(summaryview);
4325 summary_update_status(summaryview);
4326 summary_status_show(summaryview);
4328 summary_thaw(summaryview);
4330 summary_unlock(summaryview);
4333 void summary_delete(SummaryView *summaryview)
4335 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4336 FolderItem *item = summaryview->folder_item;
4337 GList *cur;
4338 GtkCMCTreeNode *sel_last = NULL;
4339 GtkCMCTreeNode *node;
4340 AlertValue aval;
4341 MsgInfo *msginfo;
4342 gboolean froze = FALSE;
4344 if (!item) return;
4346 if (summary_is_locked(summaryview)) return;
4348 if (!summaryview->folder_item) return;
4350 START_LONG_OPERATION(summaryview, FALSE);
4352 if (!prefs_common.live_dangerously) {
4353 gchar *buf = NULL;
4354 int num = g_list_length(GTK_CMCLIST(summaryview->ctree)->selection);
4355 buf = g_strdup_printf(ngettext(
4356 "Do you really want to delete the selected message?",
4357 "Do you really want to delete the %d selected messages?", num),
4358 num);
4359 aval = alertpanel(ngettext("Delete message", "Delete messages", num),
4360 buf,
4361 GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL);
4362 g_free(buf);
4363 if (aval != G_ALERTALTERNATE) {
4364 END_LONG_OPERATION(summaryview);
4365 return;
4369 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL;
4370 cur = cur->next) {
4371 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4372 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4373 if (msginfo && msginfo->total_size != 0 &&
4374 msginfo->size != (goffset)msginfo->total_size)
4375 partial_mark_for_delete(msginfo);
4378 main_window_cursor_wait(summaryview->mainwin);
4380 /* next code sets current row focus right. We need to find a row
4381 * that is not deleted. */
4382 folder_item_set_batch(summaryview->folder_item, TRUE);
4383 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4384 sel_last = GTK_CMCTREE_NODE(cur->data);
4385 summary_delete_row(summaryview, sel_last);
4387 folder_item_set_batch(summaryview->folder_item, FALSE);
4388 END_LONG_OPERATION(summaryview);
4390 if (summaryview->sort_type == SORT_ASCENDING) {
4391 node = summary_find_next_msg(summaryview, sel_last, TRUE);
4392 if (!node || prefs_common.next_on_delete == FALSE)
4393 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4394 } else {
4395 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4396 if (!node || prefs_common.next_on_delete == FALSE)
4397 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4399 summary_select_node(summaryview, node, -1);
4401 if (prefs_common.immediate_exec || folder_has_parent_of_type(item, F_TRASH)) {
4402 summary_execute(summaryview);
4403 /* after deleting, the anchor may be at an invalid row
4404 * so reset it to the node we found earlier */
4405 gtk_sctree_set_anchor_row(GTK_SCTREE(ctree), node);
4406 } else
4407 summary_status_show(summaryview);
4410 main_window_cursor_normal(summaryview->mainwin);
4413 void summary_delete_trash(SummaryView *summaryview)
4415 FolderItem *to_folder = NULL;
4416 PrefsAccount *ac;
4417 if (!summaryview->folder_item ||
4418 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4420 if (NULL != (ac = account_find_from_item(summaryview->folder_item)))
4421 to_folder = account_get_special_folder(ac, F_TRASH);
4423 if (to_folder == NULL)
4424 to_folder = summaryview->folder_item->folder->trash;
4426 if (to_folder == NULL || to_folder == summaryview->folder_item
4427 || folder_has_parent_of_type(summaryview->folder_item, F_TRASH))
4428 summary_delete(summaryview);
4429 else
4430 summary_move_selected_to(summaryview, to_folder);
4434 static void summary_unmark_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4436 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4437 MsgInfo *msginfo;
4439 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4440 cm_return_if_fail(msginfo);
4441 if (MSG_IS_DELETED(msginfo->flags))
4442 summaryview->deleted--;
4443 if (MSG_IS_MOVE(msginfo->flags))
4444 summaryview->moved--;
4445 if (MSG_IS_COPY(msginfo->flags))
4446 summaryview->copied--;
4448 procmsg_msginfo_set_to_folder(msginfo, NULL);
4449 summary_msginfo_unset_flags(msginfo, MSG_MARKED | MSG_DELETED,
4450 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4451 summary_set_row_marks(summaryview, row);
4453 debug_print("Message %s/%d is unmarked\n",
4454 msginfo->folder->path, msginfo->msgnum);
4457 void summary_unmark(SummaryView *summaryview)
4459 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4460 GList *cur;
4461 gboolean froze = FALSE;
4463 if (summary_is_locked(summaryview))
4464 return;
4465 START_LONG_OPERATION(summaryview, FALSE);
4466 folder_item_set_batch(summaryview->folder_item, TRUE);
4467 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4468 summary_unmark_row(summaryview, GTK_CMCTREE_NODE(cur->data));
4469 folder_item_set_batch(summaryview->folder_item, FALSE);
4470 END_LONG_OPERATION(summaryview);
4472 summary_status_show(summaryview);
4475 static void summary_move_row_to(SummaryView *summaryview, GtkCMCTreeNode *row,
4476 FolderItem *to_folder)
4478 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4479 MsgInfo *msginfo;
4481 cm_return_if_fail(to_folder != NULL);
4483 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4484 cm_return_if_fail(msginfo);
4485 if (MSG_IS_LOCKED(msginfo->flags))
4486 return;
4488 procmsg_msginfo_set_to_folder(msginfo, to_folder);
4489 if (MSG_IS_DELETED(msginfo->flags))
4490 summaryview->deleted--;
4491 if (MSG_IS_COPY(msginfo->flags)) {
4492 summaryview->copied--;
4494 if (!MSG_IS_MOVE(msginfo->flags)) {
4495 summary_msginfo_change_flags(msginfo, 0, MSG_MOVE, MSG_DELETED,
4496 MSG_COPY | MSG_MOVE_DONE);
4497 summaryview->moved++;
4498 } else {
4499 summary_msginfo_unset_flags(msginfo, MSG_DELETED, MSG_COPY);
4502 if (!prefs_common.immediate_exec) {
4503 summary_set_row_marks(summaryview, row);
4506 debug_print("Message %d is set to move to %s\n",
4507 msginfo->msgnum, to_folder->path);
4510 void summary_move_selected_to(SummaryView *summaryview, FolderItem *to_folder)
4512 GList *cur;
4513 GtkCMCTreeNode *sel_last = NULL;
4514 gboolean froze = FALSE;
4516 if (!to_folder) return;
4517 if (!summaryview->folder_item ||
4518 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4520 if (summary_is_locked(summaryview)) return;
4522 if (summaryview->folder_item == to_folder) {
4523 alertpanel_error(_("Destination is same as current folder."));
4524 return;
4527 if (to_folder->no_select) {
4528 alertpanel_error(_("The destination folder can only be used to "
4529 "store subfolders."));
4530 return;
4533 START_LONG_OPERATION(summaryview, FALSE);
4535 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
4536 cur != NULL && cur->data != NULL; cur = cur->next) {
4537 sel_last = GTK_CMCTREE_NODE(cur->data);
4538 summary_move_row_to
4539 (summaryview, GTK_CMCTREE_NODE(cur->data), to_folder);
4541 END_LONG_OPERATION(summaryview);
4543 if (prefs_common.immediate_exec) {
4544 summary_execute(summaryview);
4545 } else {
4546 GtkCMCTreeNode *node = NULL;
4547 if (summaryview->sort_type == SORT_ASCENDING) {
4548 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4549 if (!node || prefs_common.next_on_delete == FALSE)
4550 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4551 } else {
4552 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4553 if (!node || prefs_common.next_on_delete == FALSE)
4554 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4556 summary_select_node(summaryview, node, -1);
4557 summary_status_show(summaryview);
4560 if (!summaryview->selected) { /* this was the last message */
4561 GtkCMCTreeNode *node = gtk_cmctree_node_nth (GTK_CMCTREE(summaryview->ctree),
4562 GTK_CMCLIST(summaryview->ctree)->rows - 1);
4563 if (node)
4564 summary_select_node(summaryview, node, -1);
4569 void summary_move_to(SummaryView *summaryview)
4571 FolderItem *to_folder;
4573 if (!summaryview->folder_item ||
4574 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4576 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
4577 summary_move_selected_to(summaryview, to_folder);
4580 static void summary_copy_row_to(SummaryView *summaryview, GtkCMCTreeNode *row,
4581 FolderItem *to_folder)
4583 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4584 MsgInfo *msginfo;
4586 cm_return_if_fail(to_folder != NULL);
4588 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4589 cm_return_if_fail(msginfo);
4590 procmsg_msginfo_set_to_folder(msginfo, to_folder);
4591 if (MSG_IS_DELETED(msginfo->flags))
4592 summaryview->deleted--;
4593 if (MSG_IS_MOVE(msginfo->flags)) {
4594 summaryview->moved--;
4597 if (!MSG_IS_COPY(msginfo->flags)) {
4598 summary_msginfo_change_flags(msginfo, 0, MSG_COPY, MSG_DELETED,
4599 MSG_MOVE | MSG_MOVE_DONE);
4600 summaryview->copied++;
4601 } else {
4602 summary_msginfo_unset_flags(msginfo, MSG_DELETED, MSG_MOVE);
4604 if (!prefs_common.immediate_exec) {
4605 summary_set_row_marks(summaryview, row);
4608 debug_print("Message %d is set to copy to %s\n",
4609 msginfo->msgnum, to_folder->path);
4612 void summary_copy_selected_to(SummaryView *summaryview, FolderItem *to_folder)
4614 GList *cur;
4615 gboolean froze = FALSE;
4617 if (!to_folder) return;
4618 if (!summaryview->folder_item) return;
4620 if (summary_is_locked(summaryview)) return;
4622 if (summaryview->folder_item == to_folder) {
4623 alertpanel_error
4624 (_("Destination to copy is same as current folder."));
4625 return;
4628 if (to_folder->no_select) {
4629 alertpanel_error(_("The destination folder can only be used to "
4630 "store subfolders."));
4631 return;
4634 START_LONG_OPERATION(summaryview, FALSE);
4636 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
4637 cur != NULL && cur->data != NULL; cur = cur->next)
4638 summary_copy_row_to
4639 (summaryview, GTK_CMCTREE_NODE(cur->data), to_folder);
4641 END_LONG_OPERATION(summaryview);
4643 if (prefs_common.immediate_exec)
4644 summary_execute(summaryview);
4645 else {
4646 summary_status_show(summaryview);
4650 void summary_copy_to(SummaryView *summaryview)
4652 FolderItem *to_folder;
4654 if (!summaryview->folder_item) return;
4656 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
4657 summary_copy_selected_to(summaryview, to_folder);
4660 void summary_add_address(SummaryView *summaryview)
4662 MsgInfo *msginfo, *full_msginfo;
4663 gchar *from;
4664 GdkPixbuf *picture = NULL;
4665 AvatarRender *avatarr;
4667 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
4668 summaryview->selected);
4669 if (!msginfo || !msginfo->from)
4670 return;
4672 Xstrdup_a(from, msginfo->from, return);
4673 eliminate_address_comment(from);
4674 extract_address(from);
4676 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
4678 avatarr = avatars_avatarrender_new(full_msginfo);
4679 hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
4681 procmsg_msginfo_free(&full_msginfo);
4683 if (avatarr->image)
4684 picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
4686 #ifndef USE_ALT_ADDRBOOK
4687 addressbook_add_contact(msginfo->fromname, from, NULL, picture);
4688 #else
4689 if (addressadd_selection(msginfo->fromname, from, NULL, picture)) {
4690 debug_print( "addressbook_add_contact - added\n" );
4692 #endif
4693 avatars_avatarrender_free(avatarr);
4696 void summary_select_all(SummaryView *summaryview)
4698 if (!summaryview->folder_item) return;
4700 summary_lock(summaryview);
4701 gtk_cmclist_select_all(GTK_CMCLIST(summaryview->ctree));
4702 summary_unlock(summaryview);
4703 summary_status_show(summaryview);
4706 void summary_unselect_all(SummaryView *summaryview)
4708 summary_lock(summaryview);
4709 gtk_sctree_unselect_all(GTK_SCTREE(summaryview->ctree));
4710 summary_unlock(summaryview);
4711 summary_status_show(summaryview);
4714 void summary_select_thread(SummaryView *summaryview, gboolean delete_thread,
4715 gboolean trash_thread)
4717 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4718 GtkCMCTreeNode *node = NULL;
4719 gboolean froze = FALSE;
4720 GList *cur = NULL;
4721 GList *copy = NULL;
4722 if (!GTK_CMCLIST(summaryview->ctree)->selection)
4723 return;
4726 START_LONG_OPERATION(summaryview, FALSE);
4727 copy = g_list_copy(GTK_CMCLIST(summaryview->ctree)->selection);
4728 for (cur = copy; cur != NULL && cur->data != NULL;
4729 cur = cur->next) {
4730 node = GTK_CMCTREE_NODE(cur->data);
4731 if (!node)
4732 continue;
4733 while (GTK_CMCTREE_ROW(node)->parent != NULL)
4734 node = GTK_CMCTREE_ROW(node)->parent;
4736 gtk_cmctree_select_recursive(ctree, node);
4738 g_list_free(copy);
4739 END_LONG_OPERATION(summaryview);
4741 if (trash_thread) {
4742 if (FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS)
4743 summary_delete(summaryview);
4744 else
4745 summary_delete_trash(summaryview);
4746 } else if (delete_thread)
4747 summary_delete(summaryview);
4749 summary_status_show(summaryview);
4752 void summary_save_as(SummaryView *summaryview)
4754 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4755 MsgInfo *msginfo;
4756 gchar *filename = NULL;
4757 gchar *src, *dest;
4758 gchar *tmp;
4760 AlertValue aval = 0;
4762 if (!summaryview->selected) return;
4763 msginfo = gtk_cmctree_node_get_row_data(ctree, summaryview->selected);
4764 if (!msginfo) return;
4766 if (msginfo->subject) {
4767 Xstrdup_a(filename, msginfo->subject, return);
4768 subst_for_filename(filename);
4771 manage_window_focus_in(summaryview->window, NULL, NULL);
4773 if (filename && !g_utf8_validate(filename, -1, NULL)) {
4774 gchar *oldstr = filename;
4775 filename = conv_codeset_strdup(filename,
4776 conv_get_locale_charset_str(),
4777 CS_UTF_8);
4778 if (!filename) {
4779 g_warning("summary_save_as(): failed to convert character set.");
4780 filename = g_strdup(oldstr);
4782 dest = filesel_select_file_save(_("Save as"), filename);
4783 g_free(filename);
4784 } else
4785 dest = filesel_select_file_save(_("Save as"), filename);
4786 filename = NULL;
4787 if (!dest) return;
4788 if (is_file_exist(dest)) {
4789 aval = alertpanel(_("Append or Overwrite"),
4790 _("Append or overwrite existing file?"),
4791 _("_Append"), _("_Overwrite"),
4792 GTK_STOCK_CANCEL);
4793 if (aval != 0 && aval != 1)
4794 return;
4797 src = procmsg_get_message_file(msginfo);
4798 tmp = g_path_get_basename(dest);
4800 if ( aval==0 ) { /* append */
4801 if (append_file(src, dest, TRUE) < 0)
4802 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
4803 } else { /* overwrite */
4804 if (copy_file(src, dest, TRUE) < 0)
4805 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
4807 g_free(src);
4810 * If two or more msgs are selected,
4811 * append them to the output file.
4813 if (GTK_CMCLIST(ctree)->selection->next) {
4814 GList *item;
4815 for (item = GTK_CMCLIST(ctree)->selection->next; item != NULL; item=item->next) {
4816 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(item->data));
4817 if (!msginfo) break;
4818 src = procmsg_get_message_file(msginfo);
4819 if (append_file(src, dest, TRUE) < 0)
4820 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
4822 g_free(src);
4824 g_free(dest);
4825 g_free(tmp);
4828 void summary_print(SummaryView *summaryview)
4830 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
4831 GList *cur;
4832 gchar *msg = g_strdup_printf(_("You are about to print %d "
4833 "messages, one by one. Do you "
4834 "want to continue?"),
4835 g_list_length(clist->selection));
4836 if (g_list_length(clist->selection) > 9
4837 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
4838 != G_ALERTALTERNATE) {
4839 g_free(msg);
4840 return;
4842 g_free(msg);
4844 if (clist->selection == NULL) return;
4845 for (cur = clist->selection;
4846 cur != NULL && cur->data != NULL;
4847 cur = cur->next) {
4848 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(cur->data);
4849 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(
4850 GTK_CMCTREE(summaryview->ctree),
4851 node);
4852 gint sel_start = -1, sel_end = -1, partnum = 0;
4854 if (node == summaryview->displayed) {
4855 partnum = mimeview_get_selected_part_num(summaryview->messageview->mimeview);
4856 textview_get_selection_offsets(summaryview->messageview->mimeview->textview,
4857 &sel_start, &sel_end);
4859 messageview_print(msginfo, summaryview->messageview->all_headers,
4860 sel_start, sel_end, partnum);
4864 gboolean summary_execute(SummaryView *summaryview)
4866 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4867 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
4868 GtkCMCTreeNode *node, *next;
4869 GtkCMCTreeNode *new_selected = NULL;
4870 gint move_val = -1;
4872 if (!summaryview->folder_item) return FALSE;
4874 if (summary_is_locked(summaryview)) return FALSE;
4875 summary_lock(summaryview);
4877 summary_freeze(summaryview);
4879 main_window_cursor_wait(summaryview->mainwin);
4881 if (summaryview->threaded)
4882 summary_unthread_for_exec(summaryview);
4884 folder_item_update_freeze();
4885 move_val = summary_execute_move(summaryview);
4886 summary_execute_copy(summaryview);
4887 summary_execute_delete(summaryview);
4889 node = GTK_CMCTREE_NODE(clist->row_list);
4890 for (; node != NULL; node = next) {
4891 next = gtkut_ctree_node_next(ctree, node);
4892 if (gtk_cmctree_node_get_row_data(ctree, node) != NULL) continue;
4894 if (node == summaryview->displayed) {
4895 messageview_clear(summaryview->messageview);
4896 summary_cancel_mark_read_timeout(summaryview);
4897 summaryview->displayed = NULL;
4899 if (GTK_CMCTREE_ROW(node)->children != NULL) {
4900 next = NULL;
4901 if (GTK_CMCTREE_ROW(node)->sibling) {
4902 next = GTK_CMCTREE_ROW(node)->sibling;
4903 } else {
4904 GtkCMCTreeNode *parent = NULL;
4905 for (parent = GTK_CMCTREE_ROW(node)->parent; parent != NULL;
4906 parent = GTK_CMCTREE_ROW(parent)->parent) {
4907 if (GTK_CMCTREE_ROW(parent)->sibling) {
4908 next = GTK_CMCTREE_ROW(parent)->sibling;
4914 if (!new_selected &&
4915 gtkut_ctree_node_is_selected(ctree, node)) {
4916 summary_unselect_all(summaryview);
4917 if (summaryview->sort_type == SORT_ASCENDING) {
4918 new_selected = summary_find_next_msg(summaryview, node,TRUE);
4919 if (!new_selected || prefs_common.next_on_delete == FALSE)
4920 new_selected = summary_find_prev_msg(summaryview, node,TRUE);
4921 } else {
4922 new_selected = summary_find_prev_msg(summaryview, node,TRUE);
4923 if (!new_selected || prefs_common.next_on_delete == FALSE)
4924 new_selected = summary_find_next_msg(summaryview, node,TRUE);
4928 gtk_sctree_remove_node((GtkSCTree *)ctree, node);
4931 folder_item_update_thaw();
4933 if (new_selected) {
4934 summary_unlock(summaryview);
4935 summary_select_node(summaryview, new_selected, -1);
4936 summary_lock(summaryview);
4939 if (summaryview->threaded) {
4940 summary_thread_build(summaryview);
4941 summary_thread_init(summaryview);
4944 summary_thaw(summaryview);
4946 summaryview->selected = clist->selection ?
4947 GTK_CMCTREE_NODE(clist->selection->data) : NULL;
4949 if (!GTK_CMCLIST(summaryview->ctree)->row_list) {
4950 menu_set_insensitive_all
4951 (GTK_MENU_SHELL(summaryview->popupmenu));
4952 folderview_grab_focus(summaryview->folderview);
4953 } else {
4954 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
4955 gtk_widget_grab_focus(summaryview->ctree);
4957 summary_update_status(summaryview);
4958 summary_status_show(summaryview);
4960 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
4962 summary_unlock(summaryview);
4964 main_window_cursor_normal(summaryview->mainwin);
4966 if (move_val < 0)
4967 summary_show(summaryview, summaryview->folder_item);
4968 return TRUE;
4971 gboolean summary_expunge(SummaryView *summaryview)
4973 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4974 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
4975 GtkCMCTreeNode *node, *next;
4976 GtkCMCTreeNode *new_selected = NULL;
4978 if (!summaryview->folder_item) return FALSE;
4980 if (summary_is_locked(summaryview)) return FALSE;
4982 summary_lock(summaryview);
4984 summary_freeze(summaryview);
4986 main_window_cursor_wait(summaryview->mainwin);
4988 if (summaryview->threaded)
4989 summary_unthread_for_exec(summaryview);
4991 folder_item_update_freeze();
4992 summary_execute_expunge(summaryview);
4994 node = GTK_CMCTREE_NODE(clist->row_list);
4995 for (; node != NULL; node = next) {
4996 next = gtkut_ctree_node_next(ctree, node);
4997 if (gtk_cmctree_node_get_row_data(ctree, node) != NULL) continue;
4999 if (node == summaryview->displayed) {
5000 messageview_clear(summaryview->messageview);
5001 summary_cancel_mark_read_timeout(summaryview);
5002 summaryview->displayed = NULL;
5004 if (GTK_CMCTREE_ROW(node)->children != NULL) {
5005 next = NULL;
5006 if (GTK_CMCTREE_ROW(node)->sibling) {
5007 next = GTK_CMCTREE_ROW(node)->sibling;
5008 } else {
5009 GtkCMCTreeNode *parent = NULL;
5010 for (parent = GTK_CMCTREE_ROW(node)->parent; parent != NULL;
5011 parent = GTK_CMCTREE_ROW(parent)->parent) {
5012 if (GTK_CMCTREE_ROW(parent)->sibling) {
5013 next = GTK_CMCTREE_ROW(parent)->sibling;
5019 if (!new_selected &&
5020 gtkut_ctree_node_is_selected(ctree, node)) {
5021 summary_unselect_all(summaryview);
5022 new_selected = summary_find_next_msg(summaryview, node,TRUE);
5023 if (!new_selected)
5024 new_selected = summary_find_prev_msg
5025 (summaryview, node,TRUE);
5028 gtk_sctree_remove_node((GtkSCTree *)ctree, node);
5031 folder_item_update_thaw();
5033 if (new_selected) {
5034 summary_unlock(summaryview);
5035 summary_select_node(summaryview, new_selected, -1);
5036 summary_lock(summaryview);
5039 if (summaryview->threaded) {
5040 summary_thread_build(summaryview);
5041 summary_thread_init(summaryview);
5044 summary_thaw(summaryview);
5046 summaryview->selected = clist->selection ?
5047 GTK_CMCTREE_NODE(clist->selection->data) : NULL;
5049 if (!GTK_CMCLIST(summaryview->ctree)->row_list) {
5050 menu_set_insensitive_all
5051 (GTK_MENU_SHELL(summaryview->popupmenu));
5052 folderview_grab_focus(summaryview->folderview);
5053 } else {
5054 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
5055 gtk_widget_grab_focus(summaryview->ctree);
5058 summary_update_status(summaryview);
5059 summary_status_show(summaryview);
5061 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5063 summary_unlock(summaryview);
5065 main_window_cursor_normal(summaryview->mainwin);
5067 return TRUE;
5070 static gint summary_execute_move(SummaryView *summaryview)
5072 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5073 GSList *cur;
5074 gint val = -1;
5075 /* search moving messages and execute */
5077 gtk_cmctree_pre_recursive(ctree, NULL, summary_execute_move_func,
5078 summaryview);
5080 if (summaryview->mlist) {
5081 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5082 summaryview->msginfo_update_callback_id);
5083 val = procmsg_move_messages(summaryview->mlist);
5084 summaryview->msginfo_update_callback_id =
5085 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5086 summary_update_msg, (gpointer) summaryview);
5088 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next) {
5089 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5092 g_slist_free(summaryview->mlist);
5093 summaryview->mlist = NULL;
5094 return val;
5096 return 0;
5099 static void summary_execute_move_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5100 gpointer data)
5102 SummaryView *summaryview = data;
5103 MsgInfo *msginfo;
5105 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5107 if (msginfo && MSG_IS_MOVE(msginfo->flags) && msginfo->to_folder) {
5108 summaryview->mlist =
5109 g_slist_prepend(summaryview->mlist, msginfo);
5110 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5112 if (msginfo->msgid && *msginfo->msgid &&
5113 node == g_hash_table_lookup(summaryview->msgid_table,
5114 msginfo->msgid))
5115 g_hash_table_remove(summaryview->msgid_table,
5116 msginfo->msgid);
5117 if (prefs_common.thread_by_subject &&
5118 msginfo->subject && *msginfo->subject &&
5119 node == subject_table_lookup(summaryview->subject_table,
5120 msginfo->subject)) {
5121 subject_table_remove(summaryview->subject_table,
5122 msginfo->subject);
5127 static void summary_execute_copy(SummaryView *summaryview)
5129 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5131 /* search copying messages and execute */
5132 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5133 summaryview->msginfo_update_callback_id);
5134 gtk_cmctree_pre_recursive(ctree, NULL, summary_execute_copy_func,
5135 summaryview);
5137 if (summaryview->mlist) {
5138 summaryview->mlist = g_slist_reverse(summaryview->mlist);
5139 procmsg_copy_messages(summaryview->mlist);
5141 g_slist_free(summaryview->mlist);
5142 summaryview->mlist = NULL;
5144 summaryview->msginfo_update_callback_id =
5145 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5146 summary_update_msg, (gpointer) summaryview);
5149 static void summary_execute_copy_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5150 gpointer data)
5152 SummaryView *summaryview = data;
5153 MsgInfo *msginfo;
5155 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5157 if (msginfo && MSG_IS_COPY(msginfo->flags) && msginfo->to_folder) {
5158 summaryview->mlist =
5159 g_slist_prepend(summaryview->mlist, msginfo);
5161 summary_msginfo_unset_flags(msginfo, 0, MSG_COPY);
5162 summary_set_row_marks(summaryview, node);
5166 static void summary_execute_delete(SummaryView *summaryview)
5168 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5169 GSList *cur;
5171 /* search deleting messages and execute */
5172 gtk_cmctree_pre_recursive
5173 (ctree, NULL, summary_execute_delete_func, summaryview);
5175 if (!summaryview->mlist) return;
5177 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5178 summaryview->msginfo_update_callback_id);
5180 folder_item_remove_msgs(summaryview->folder_item,
5181 summaryview->mlist);
5183 summaryview->msginfo_update_callback_id =
5184 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5185 summary_update_msg, (gpointer) summaryview);
5187 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next) {
5188 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5191 g_slist_free(summaryview->mlist);
5192 summaryview->mlist = NULL;
5195 static void summary_execute_delete_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5196 gpointer data)
5198 SummaryView *summaryview = data;
5199 MsgInfo *msginfo;
5201 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5203 if (msginfo && MSG_IS_DELETED(msginfo->flags)) {
5204 summaryview->mlist =
5205 g_slist_prepend(summaryview->mlist, msginfo);
5206 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5208 if (msginfo->msgid && *msginfo->msgid &&
5209 node == g_hash_table_lookup(summaryview->msgid_table,
5210 msginfo->msgid)) {
5211 g_hash_table_remove(summaryview->msgid_table,
5212 msginfo->msgid);
5214 if (prefs_common.thread_by_subject &&
5215 msginfo->subject && *msginfo->subject &&
5216 node == subject_table_lookup(summaryview->subject_table,
5217 msginfo->subject)) {
5218 subject_table_remove(summaryview->subject_table,
5219 msginfo->subject);
5224 static void summary_execute_expunge_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5225 gpointer data)
5227 SummaryView *summaryview = data;
5228 MsgInfo *msginfo;
5230 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5232 if (msginfo && MSG_IS_DELETED(msginfo->flags)) {
5233 summaryview->mlist =
5234 g_slist_prepend(summaryview->mlist, msginfo);
5235 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5237 if (msginfo->msgid && *msginfo->msgid &&
5238 node == g_hash_table_lookup(summaryview->msgid_table,
5239 msginfo->msgid)) {
5240 g_hash_table_remove(summaryview->msgid_table,
5241 msginfo->msgid);
5243 if (prefs_common.thread_by_subject &&
5244 msginfo->subject && *msginfo->subject &&
5245 node == subject_table_lookup(summaryview->subject_table,
5246 msginfo->subject)) {
5247 subject_table_remove(summaryview->subject_table,
5248 msginfo->subject);
5253 static void summary_execute_expunge(SummaryView *summaryview)
5255 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5256 GSList *cur;
5258 gtk_cmctree_pre_recursive
5259 (ctree, NULL, summary_execute_expunge_func, summaryview);
5261 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5262 summaryview->msginfo_update_callback_id);
5264 folder_item_expunge(summaryview->folder_item);
5266 summaryview->msginfo_update_callback_id =
5267 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5268 summary_update_msg, (gpointer) summaryview);
5269 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next)
5270 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5272 g_slist_free(summaryview->mlist);
5273 summaryview->mlist = NULL;
5276 /* thread functions */
5278 static void summary_thread_build(SummaryView *summaryview)
5280 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5281 GtkCMCTreeNode *node;
5282 GtkCMCTreeNode *next;
5283 GtkCMCTreeNode *parent;
5284 MsgInfo *msginfo;
5285 GSList *reflist;
5287 summary_lock(summaryview);
5289 debug_print("Building threads...\n");
5290 STATUSBAR_PUSH(summaryview->mainwin, _("Building threads..."));
5291 main_window_cursor_wait(summaryview->mainwin);
5293 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5294 G_CALLBACK(summary_tree_expanded), summaryview);
5295 summary_freeze(summaryview);
5297 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5298 while (node) {
5299 next = GTK_CMCTREE_ROW(node)->sibling;
5301 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5303 parent = NULL;
5305 if (msginfo && msginfo->inreplyto) {
5306 parent = g_hash_table_lookup(summaryview->msgid_table,
5307 msginfo->inreplyto);
5309 if (!parent && msginfo->references) {
5310 for (reflist = msginfo->references;
5311 reflist != NULL; reflist = reflist->next)
5312 if ((parent = g_hash_table_lookup
5313 (summaryview->msgid_table,
5314 reflist->data)))
5315 break;
5319 if (msginfo && prefs_common.thread_by_subject && parent == NULL) {
5320 parent = subject_table_lookup
5321 (summaryview->subject_table,
5322 msginfo->subject);
5325 if (parent && parent != node && parent != GTK_CMCTREE_ROW(node)->parent) {
5326 gtk_cmctree_move(ctree, node, parent, NULL);
5329 node = next;
5332 gtkut_ctree_set_focus_row(ctree, summaryview->selected);
5334 summary_thaw(summaryview);
5335 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5336 G_CALLBACK(summary_tree_expanded), summaryview);
5338 debug_print("Building threads done.\n");
5339 STATUSBAR_POP(summaryview->mainwin);
5340 main_window_cursor_normal(summaryview->mainwin);
5342 summaryview->threaded = TRUE;
5344 summary_unlock(summaryview);
5347 static void summary_thread_init(SummaryView *summaryview)
5349 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5350 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5351 GtkCMCTreeNode *next;
5352 START_TIMING("");
5353 if (!summaryview->thread_collapsed) {
5354 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5355 G_CALLBACK(summary_tree_expanded), summaryview);
5356 while (node) {
5357 next = GTK_CMCTREE_ROW(node)->sibling;
5358 if (GTK_CMCTREE_ROW(node)->children)
5359 gtk_cmctree_expand_recursive(ctree, node);
5360 node = next;
5362 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5363 G_CALLBACK(summary_tree_expanded), summaryview);
5365 END_TIMING();
5368 static void summary_unthread_for_exec(SummaryView *summaryview)
5370 GtkCMCTreeNode *node;
5371 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5372 gboolean froze = FALSE;
5374 debug_print("Unthreading for execution...\n");
5376 START_LONG_OPERATION(summaryview, TRUE);
5377 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5378 node != NULL; node = GTK_CMCTREE_NODE_NEXT(node)) {
5379 summary_unthread_for_exec_func(ctree, node, summaryview);
5382 END_LONG_OPERATION(summaryview);
5384 debug_print("Unthreading for execution done.\n");
5387 static void summary_unthread_for_exec_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5388 gpointer data)
5390 MsgInfo *msginfo;
5391 GtkCMCTreeNode *top_parent;
5392 GtkCMCTreeNode *child;
5393 GtkCMCTreeNode *sibling;
5394 SummaryView * summaryview = (SummaryView *)data;
5395 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5397 if (!msginfo ||
5398 (!MSG_IS_MOVE(msginfo->flags) &&
5399 !MSG_IS_DELETED(msginfo->flags)))
5400 return;
5401 child = GTK_CMCTREE_ROW(node)->children;
5402 if (!child) return;
5404 if (node == summaryview->selected)
5405 summaryview->selected = NULL;
5406 if (node == summaryview->displayed)
5407 summaryview->displayed = NULL;
5409 summary_cancel_mark_read_timeout(summaryview);
5411 for (top_parent = node;
5412 GTK_CMCTREE_ROW(top_parent)->parent != NULL;
5413 top_parent = GTK_CMCTREE_ROW(top_parent)->parent)
5415 sibling = GTK_CMCTREE_ROW(top_parent)->sibling;
5417 GTK_SCTREE(ctree)->sorting = TRUE;
5418 while (child != NULL) {
5419 GtkCMCTreeNode *next_child;
5420 MsgInfo *cinfo = GTKUT_CTREE_NODE_GET_ROW_DATA(child);
5422 next_child = GTK_CMCTREE_ROW(child)->sibling;
5424 if (!MSG_IS_MOVE(cinfo->flags) && !MSG_IS_DELETED(cinfo->flags)) {
5425 gtk_cmctree_move(ctree, child,
5426 NULL,
5427 sibling);
5428 } else {
5429 if (child == summaryview->displayed) {
5430 messageview_clear(summaryview->messageview);
5431 summaryview->displayed = NULL;
5433 if (child == summaryview->selected) {
5434 messageview_clear(summaryview->messageview);
5435 summaryview->selected = NULL;
5438 child = next_child;
5440 GTK_SCTREE(ctree)->sorting = FALSE;
5443 void summary_expand_threads(SummaryView *summaryview)
5445 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5446 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5447 GtkCMCTreeNode *focus_node = GTK_CMCTREE_NODE (g_list_nth (GTK_CMCLIST(ctree)->row_list, GTK_CMCLIST(ctree)->focus_row));
5449 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5450 G_CALLBACK(summary_tree_expanded), summaryview);
5451 summary_freeze(summaryview);
5452 GTK_SCTREE(ctree)->sorting = TRUE;
5454 while (node) {
5455 if (GTK_CMCTREE_ROW(node)->children) {
5456 gtk_cmctree_expand(ctree, node);
5457 summary_set_row_marks(summaryview, node);
5459 node = GTK_CMCTREE_NODE_NEXT(node);
5462 GTK_SCTREE(ctree)->sorting = FALSE;
5463 if (focus_node) {
5464 GTK_CMCLIST(ctree)->focus_row = g_list_position (GTK_CMCLIST(ctree)->row_list,(GList *)focus_node);
5466 summary_thaw(summaryview);
5468 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5469 G_CALLBACK(summary_tree_expanded), summaryview);
5471 summaryview->thread_collapsed = FALSE;
5473 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5476 void summary_collapse_threads(SummaryView *summaryview)
5478 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5479 GtkCMCTreeNode *node = NULL;
5480 GtkCMCTreeNode *focus_node = GTK_CMCTREE_NODE (g_list_nth (GTK_CMCLIST(ctree)->row_list, GTK_CMCLIST(ctree)->focus_row));
5482 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5483 G_CALLBACK(summary_tree_collapsed), summaryview);
5484 summary_freeze(summaryview);
5485 GTK_SCTREE(ctree)->sorting = TRUE;
5487 node = focus_node;
5488 while (node && GTK_CMCTREE_ROW(node)->parent) {
5489 focus_node = node = GTK_CMCTREE_ROW(node)->parent;
5491 summary_select_node(summaryview, node, -1);
5492 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5493 while (node) {
5494 if (GTK_CMCTREE_ROW(node)->children) {
5495 gtk_cmctree_collapse(ctree, node);
5496 summary_set_row_marks(summaryview, node);
5498 node = GTK_CMCTREE_ROW(node)->sibling;
5501 GTK_SCTREE(ctree)->sorting = FALSE;
5502 if (focus_node) {
5503 GTK_CMCLIST(ctree)->focus_row = g_list_position (GTK_CMCLIST(ctree)->row_list,(GList *)focus_node);
5505 GTK_SCTREE(ctree)->anchor_row =
5506 gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->focus_row);
5507 summary_thaw(summaryview);
5508 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5509 G_CALLBACK(summary_tree_collapsed), summaryview);
5511 summaryview->thread_collapsed = TRUE;
5513 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5516 static void account_rules_radio_button_toggled_cb(GtkToggleButton *btn, gpointer data)
5518 prefs_common.apply_per_account_filtering_rules = GPOINTER_TO_INT(data);
5521 static gboolean summary_filter_get_mode(void)
5522 /* ask what to do w/ them: skip them, apply them regardless to the account,
5523 use the current account */
5525 /* TODO: eventually also propose to use the current folder's default account,
5526 if it is set */
5527 /* TODO: eventually allow to select the account to use from a optmenu */
5529 GtkWidget *vbox;
5530 GtkWidget *account_rules_skip;
5531 GtkWidget *account_rules_force;
5532 GtkWidget *account_rules_user_current;
5533 AlertValue val;
5535 vbox = gtk_vbox_new (FALSE, 0);
5537 account_rules_skip = gtk_radio_button_new_with_label
5538 (NULL, _("Skip these rules"));
5539 account_rules_force = gtk_radio_button_new_with_label_from_widget
5540 (GTK_RADIO_BUTTON(account_rules_skip),
5541 _("Apply these rules regardless of the account they belong to"));
5542 account_rules_user_current = gtk_radio_button_new_with_label_from_widget
5543 (GTK_RADIO_BUTTON(account_rules_skip),
5544 _("Apply these rules if they apply to the current account"));
5545 gtk_box_pack_start (GTK_BOX (vbox), account_rules_skip, FALSE, FALSE, 0);
5546 gtk_box_pack_start (GTK_BOX (vbox), account_rules_force, FALSE, FALSE, 0);
5547 gtk_box_pack_start (GTK_BOX (vbox), account_rules_user_current, FALSE, FALSE, 0);
5548 g_signal_connect(G_OBJECT(account_rules_skip), "toggled",
5549 G_CALLBACK(account_rules_radio_button_toggled_cb),
5550 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_SKIP));
5551 g_signal_connect(G_OBJECT(account_rules_force), "toggled",
5552 G_CALLBACK(account_rules_radio_button_toggled_cb),
5553 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_FORCE));
5554 g_signal_connect(G_OBJECT(account_rules_user_current), "toggled",
5555 G_CALLBACK(account_rules_radio_button_toggled_cb),
5556 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_USE_CURRENT));
5557 switch (prefs_common.apply_per_account_filtering_rules) {
5558 case FILTERING_ACCOUNT_RULES_SKIP:
5559 gtk_toggle_button_set_active(
5560 GTK_TOGGLE_BUTTON(account_rules_skip), TRUE);
5561 break;
5562 case FILTERING_ACCOUNT_RULES_FORCE:
5563 gtk_toggle_button_set_active(
5564 GTK_TOGGLE_BUTTON(account_rules_force), TRUE);
5565 break;
5566 case FILTERING_ACCOUNT_RULES_USE_CURRENT:
5567 gtk_toggle_button_set_active(
5568 GTK_TOGGLE_BUTTON(account_rules_user_current), TRUE);
5569 break;
5572 val = alertpanel_with_widget(
5573 _("Filtering"),
5574 _("There are some filtering rules that belong to an account.\n"
5575 "Please choose what to do with these rules:"),
5576 GTK_STOCK_CANCEL, _("_Filter"), NULL, TRUE, G_ALERTALTERNATE, vbox);
5578 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE) {
5579 return FALSE;
5580 } else if (val & G_ALERTDISABLE)
5581 prefs_common.ask_apply_per_account_filtering_rules = FALSE;
5583 return TRUE;
5586 void summary_filter(SummaryView *summaryview, gboolean selected_only)
5588 GSList *mlist = NULL, *cur_list;
5589 summary_lock(summaryview);
5591 /* are there any per-account filtering rules? */
5592 if (prefs_common.ask_apply_per_account_filtering_rules == TRUE &&
5593 filtering_peek_per_account_rules(filtering_rules)) {
5595 if (summary_filter_get_mode() == FALSE) {
5596 summary_unlock(summaryview);
5597 return;
5601 folder_item_update_freeze();
5603 debug_print("filtering...\n");
5604 STATUSBAR_PUSH(summaryview->mainwin, _("Filtering..."));
5605 main_window_cursor_wait(summaryview->mainwin);
5607 summary_freeze(summaryview);
5609 if (selected_only) {
5610 GList *cur;
5612 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
5613 cur != NULL && cur->data != NULL; cur = cur->next) {
5614 mlist = g_slist_prepend(mlist,
5615 procmsg_msginfo_new_ref(
5616 GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data)));
5618 mlist = g_slist_reverse(mlist);
5619 } else {
5620 mlist = folder_item_get_msg_list(summaryview->folder_item);
5623 folder_item_set_batch(summaryview->folder_item, TRUE);
5624 for (cur_list = mlist; cur_list; cur_list = cur_list->next) {
5625 summary_filter_func((MsgInfo *)cur_list->data);
5627 folder_item_set_batch(summaryview->folder_item, FALSE);
5629 filtering_move_and_copy_msgs(mlist);
5631 for (cur_list = mlist; cur_list; cur_list = cur_list->next) {
5632 procmsg_msginfo_free((MsgInfo **)&(cur_list->data));
5634 g_slist_free(mlist);
5636 summary_thaw(summaryview);
5638 folder_item_update_thaw();
5639 debug_print("filtering done.\n");
5640 STATUSBAR_POP(summaryview->mainwin);
5641 main_window_cursor_normal(summaryview->mainwin);
5643 summary_unlock(summaryview);
5646 * CLAWS: summary_show() only valid after having a lock. ideally
5647 * we want the lock to be context aware...
5649 summary_show(summaryview, summaryview->folder_item);
5652 static void summary_filter_func(MsgInfo *msginfo)
5654 MailFilteringData mail_filtering_data;
5656 mail_filtering_data.msginfo = msginfo;
5657 mail_filtering_data.msglist = NULL;
5658 mail_filtering_data.filtered = NULL;
5659 mail_filtering_data.unfiltered = NULL;
5660 if (hooks_invoke(MAIL_MANUAL_FILTERING_HOOKLIST, &mail_filtering_data))
5661 return;
5663 filter_message_by_msginfo(filtering_rules, msginfo, NULL,
5664 FILTERING_MANUALLY, NULL);
5667 void summary_msginfo_filter_open(FolderItem * item, MsgInfo *msginfo,
5668 PrefsFilterType type, gint processing_rule)
5670 gchar *header = NULL;
5671 gchar *key = NULL;
5673 procmsg_get_filter_keyword(msginfo, &header, &key, type);
5675 if (processing_rule) {
5676 if (item == NULL)
5677 prefs_filtering_open(&pre_global_processing,
5678 _("Processing rules to apply before folder rules"),
5679 MANUAL_ANCHOR_PROCESSING,
5680 header, key, FALSE);
5681 else
5682 prefs_filtering_open(&item->prefs->processing,
5683 _("Processing configuration"),
5684 MANUAL_ANCHOR_PROCESSING,
5685 header, key, FALSE);
5687 else {
5688 prefs_filtering_open(&filtering_rules,
5689 _("Filtering configuration"),
5690 MANUAL_ANCHOR_FILTERING,
5691 header, key, TRUE);
5694 g_free(header);
5695 g_free(key);
5698 void summary_filter_open(SummaryView *summaryview, PrefsFilterType type,
5699 gint processing_rule)
5701 MsgInfo *msginfo;
5702 FolderItem * item;
5704 if (!summaryview->selected) return;
5706 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
5707 summaryview->selected);
5708 if (!msginfo) return;
5710 item = summaryview->folder_item;
5711 summary_msginfo_filter_open(item, msginfo, type, processing_rule);
5714 /* color label */
5716 #define N_COLOR_LABELS colorlabel_get_color_count()
5718 static void summary_colorlabel_menu_item_activate_cb(GtkWidget *widget,
5719 gpointer data)
5721 guint color = GPOINTER_TO_UINT(data);
5722 SummaryView *summaryview;
5724 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
5725 cm_return_if_fail(summaryview != NULL);
5727 /* "dont_toggle" state set? */
5728 if (g_object_get_data(G_OBJECT(summaryview->colorlabel_menu),
5729 "dont_toggle"))
5730 return;
5732 summary_set_colorlabel(summaryview, color, NULL);
5735 /* summary_set_colorlabel_color() - labelcolor parameter is the color *flag*
5736 * for the messsage; not the color index */
5737 void summary_set_colorlabel_color(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5738 guint labelcolor)
5740 GdkColor color;
5741 GtkStyle *style, *prev_style, *ctree_style;
5742 MsgInfo *msginfo;
5743 gint color_index;
5745 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
5746 cm_return_if_fail(msginfo);
5748 color_index = labelcolor == 0 ? -1 : (gint)labelcolor - 1;
5749 ctree_style = gtk_widget_get_style(GTK_WIDGET(ctree));
5750 prev_style = gtk_cmctree_node_get_row_style(ctree, node);
5752 if (color_index < 0 || color_index >= N_COLOR_LABELS) {
5753 if (!prev_style) return;
5754 style = gtk_style_copy(prev_style);
5755 color = ctree_style->fg[GTK_STATE_NORMAL];
5756 style->fg[GTK_STATE_NORMAL] = color;
5757 color = ctree_style->fg[GTK_STATE_SELECTED];
5758 style->fg[GTK_STATE_SELECTED] = color;
5759 } else {
5760 if (prev_style)
5761 style = gtk_style_copy(prev_style);
5762 else
5763 style = gtk_style_copy(ctree_style);
5764 color = colorlabel_get_color(color_index);
5765 style->fg[GTK_STATE_NORMAL] = color;
5766 /* get the average of label color and selected fg color
5767 for visibility */
5768 style->fg[GTK_STATE_SELECTED].red = (color.red + 3*ctree_style->fg[GTK_STATE_SELECTED].red ) / 4;
5769 style->fg[GTK_STATE_SELECTED].green = (color.green + 3*ctree_style->fg[GTK_STATE_SELECTED].green) / 4;
5770 style->fg[GTK_STATE_SELECTED].blue = (color.blue + 3*ctree_style->fg[GTK_STATE_SELECTED].blue ) / 4;
5773 gtk_cmctree_node_set_row_style(ctree, node, style);
5774 g_object_unref(style);
5777 static void summary_set_row_colorlabel(SummaryView *summaryview, GtkCMCTreeNode *row, guint labelcolor)
5779 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5780 MsgInfo *msginfo;
5782 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
5783 cm_return_if_fail(msginfo);
5785 summary_msginfo_change_flags(msginfo, MSG_COLORLABEL_TO_FLAGS(labelcolor), 0,
5786 MSG_CLABEL_FLAG_MASK, 0);
5787 summary_set_row_marks(summaryview, row);
5790 void summary_set_colorlabel(SummaryView *summaryview, guint labelcolor,
5791 GtkWidget *widget)
5793 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5794 GList *cur;
5795 gboolean froze = FALSE;
5797 START_LONG_OPERATION(summaryview, FALSE);
5798 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
5799 summary_set_row_colorlabel(summaryview,
5800 GTK_CMCTREE_NODE(cur->data), labelcolor);
5801 END_LONG_OPERATION(summaryview);
5804 static gboolean summary_set_row_tag(SummaryView *summaryview, GtkCMCTreeNode *row, gboolean refresh, gboolean set, gint id)
5806 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5807 MsgInfo *msginfo;
5808 gchar *tags_str = NULL;
5809 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
5810 cm_return_val_if_fail(msginfo, FALSE);
5812 procmsg_msginfo_update_tags(msginfo, set, id);
5814 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
5815 tags_str = procmsg_msginfo_get_tags_str(msginfo);
5816 gtk_cmctree_node_set_text(ctree, row,
5817 summaryview->col_pos[S_COL_TAGS],
5818 tags_str?tags_str:"-");
5819 g_free(tags_str);
5822 summary_set_row_marks(summaryview, row);
5823 if (row == summaryview->displayed) {
5824 return TRUE;
5826 return FALSE;
5829 void summary_set_tag(SummaryView *summaryview, gint tag_id,
5830 GtkWidget *widget)
5832 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5833 GList *cur;
5834 gboolean set = tag_id > 0;
5835 gint real_id = set? tag_id:-tag_id;
5836 gboolean froze = FALSE;
5837 gboolean redisplay = FALSE;
5839 if (summary_is_locked(summaryview))
5840 return;
5841 START_LONG_OPERATION(summaryview, FALSE);
5842 folder_item_set_batch(summaryview->folder_item, TRUE);
5843 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
5844 redisplay |= summary_set_row_tag(summaryview,
5845 GTK_CMCTREE_NODE(cur->data), FALSE, set, real_id);
5847 folder_item_set_batch(summaryview->folder_item, FALSE);
5848 END_LONG_OPERATION(summaryview);
5849 if (redisplay)
5850 summary_redisplay_msg(summaryview);
5853 static void summary_tags_menu_item_activate_cb(GtkWidget *widget,
5854 gpointer data)
5856 gint id = GPOINTER_TO_INT(data);
5857 gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
5858 SummaryView *summaryview;
5860 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
5861 cm_return_if_fail(summaryview != NULL);
5863 /* "dont_toggle" state set? */
5864 if (g_object_get_data(G_OBJECT(summaryview->tags_menu),
5865 "dont_toggle"))
5866 return;
5868 if (!set)
5869 id = -id;
5870 summary_set_tag(summaryview, id, NULL);
5873 static void summary_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
5874 gpointer data)
5876 SummaryView *summaryview;
5877 GtkMenuShell *menu;
5878 GtkCheckMenuItem **items;
5879 gint n;
5880 GList *children, *cur, *sel;
5882 summaryview = (SummaryView *)data;
5883 cm_return_if_fail(summaryview != NULL);
5885 sel = GTK_CMCLIST(summaryview->ctree)->selection;
5886 if (!sel) return;
5888 menu = GTK_MENU_SHELL(summaryview->colorlabel_menu);
5890 cm_return_if_fail(menu != NULL);
5892 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
5894 /* NOTE: don't return prematurely because we set the "dont_toggle"
5895 * state for check menu items */
5896 g_object_set_data(G_OBJECT(menu), "dont_toggle",
5897 GINT_TO_POINTER(1));
5899 /* clear items. get item pointers. */
5900 children = gtk_container_get_children(GTK_CONTAINER(menu));
5901 for (n = 0, cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
5902 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
5903 gtk_check_menu_item_set_active
5904 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
5905 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
5906 n++;
5910 g_list_free(children);
5912 if (n == (N_COLOR_LABELS + 1)) {
5913 /* iterate all messages and set the state of the appropriate
5914 * items */
5915 for (; sel != NULL; sel = sel->next) {
5916 MsgInfo *msginfo;
5917 gint clabel;
5919 msginfo = gtk_cmctree_node_get_row_data
5920 (GTK_CMCTREE(summaryview->ctree),
5921 GTK_CMCTREE_NODE(sel->data));
5922 if (msginfo) {
5923 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
5924 if (!gtk_check_menu_item_get_active(items[clabel]))
5925 gtk_check_menu_item_set_active
5926 (items[clabel], TRUE);
5929 } else
5930 g_warning("invalid number of color elements (%d)", n);
5932 /* reset "dont_toggle" state */
5933 g_object_set_data(G_OBJECT(menu), "dont_toggle",
5934 GINT_TO_POINTER(0));
5937 static void summary_colorlabel_menu_create(SummaryView *summaryview, gboolean refresh)
5939 GtkWidget *label_menuitem;
5940 GtkWidget *menu;
5941 GtkWidget *item;
5942 gint i;
5943 gchar *accel_path = NULL;
5945 label_menuitem = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, "/Menus/SummaryViewPopup/ColorLabel");
5946 g_signal_connect(G_OBJECT(label_menuitem), "activate",
5947 G_CALLBACK(summary_colorlabel_menu_item_activate_item_cb),
5948 summaryview);
5949 gtk_widget_show(label_menuitem);
5951 menu = gtk_menu_new();
5953 gtk_menu_set_accel_group (GTK_MENU (menu),
5954 gtk_ui_manager_get_accel_group(mainwindow_get_mainwindow()->ui_manager));
5956 /* create sub items. for the menu item activation callback we pass the
5957 * index of label_colors[] as data parameter. for the None color we
5958 * pass an invalid (high) value. also we attach a data pointer so we
5959 * can always get back the SummaryView pointer. */
5961 item = gtk_check_menu_item_new_with_label(_("None"));
5962 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5963 g_signal_connect(G_OBJECT(item), "activate",
5964 G_CALLBACK(summary_colorlabel_menu_item_activate_cb),
5965 GUINT_TO_POINTER(0));
5966 g_object_set_data(G_OBJECT(item), "summaryview", summaryview);
5967 gtk_widget_show(item);
5969 accel_path = g_strdup_printf("<ClawsColorLabels>/None");
5970 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
5971 g_free(accel_path);
5972 gtk_accel_map_add_entry("<ClawsColorLabels>/None", GDK_KEY_0, GDK_CONTROL_MASK);
5974 item = gtk_menu_item_new();
5975 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5976 gtk_widget_show(item);
5978 /* create pixmap/label menu items */
5979 for (i = 0; i < N_COLOR_LABELS; i++) {
5980 item = colorlabel_create_check_color_menu_item(
5981 i, refresh, SUMMARY_COLORMENU);
5982 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5983 g_signal_connect(G_OBJECT(item), "activate",
5984 G_CALLBACK(summary_colorlabel_menu_item_activate_cb),
5985 GUINT_TO_POINTER(i + 1));
5986 g_object_set_data(G_OBJECT(item), "summaryview",
5987 summaryview);
5988 gtk_widget_show(item);
5989 accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i+1);
5990 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
5991 if (i < 9)
5992 gtk_accel_map_add_entry(accel_path, GDK_KEY_1+i, GDK_CONTROL_MASK);
5993 g_free(accel_path);
5994 g_signal_connect (gtk_ui_manager_get_accel_group(mainwindow_get_mainwindow()->ui_manager),
5995 "accel-changed", G_CALLBACK (mainwin_accel_changed_cb), item);
5998 gtk_widget_show(menu);
5999 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
6000 summaryview->colorlabel_menu = menu;
6003 static void summary_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
6004 gpointer data)
6006 GtkMenuShell *menu;
6007 GList *children, *cur;
6008 GList *sel;
6009 GHashTable *menu_table = g_hash_table_new_full(
6010 g_direct_hash,
6011 g_direct_equal,
6012 NULL, NULL);
6013 GHashTable *menu_allsel_table = g_hash_table_new_full(
6014 g_direct_hash,
6015 g_direct_equal,
6016 NULL, NULL);
6017 gint sel_len;
6018 SummaryView *summaryview = (SummaryView *)data;
6019 cm_return_if_fail(summaryview != NULL);
6021 sel = GTK_CMCLIST(summaryview->ctree)->selection;
6022 if (!sel) return;
6024 menu = GTK_MENU_SHELL(summaryview->tags_menu);
6025 cm_return_if_fail(menu != NULL);
6027 /* NOTE: don't return prematurely because we set the "dont_toggle"
6028 * state for check menu items */
6029 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6030 GINT_TO_POINTER(1));
6032 /* clear items. get item pointers. */
6033 children = gtk_container_get_children(GTK_CONTAINER(menu));
6034 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
6035 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
6036 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
6037 "tag_id"));
6038 gtk_check_menu_item_set_active
6039 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
6041 g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
6042 g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
6046 g_list_free(children);
6048 /* iterate all messages and set the state of the appropriate
6049 * items */
6050 sel_len = 0;
6051 for (; sel != NULL; sel = sel->next) {
6052 MsgInfo *msginfo;
6053 GSList *tags = NULL;
6054 GtkCheckMenuItem *item;
6055 msginfo = gtk_cmctree_node_get_row_data
6056 (GTK_CMCTREE(summaryview->ctree),
6057 GTK_CMCTREE_NODE(sel->data));
6058 sel_len++;
6059 if (msginfo) {
6060 tags = msginfo->tags;
6061 if (!tags)
6062 continue;
6064 for (; tags; tags = tags->next) {
6065 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
6066 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
6067 if (item && !gtk_check_menu_item_get_active(item)) {
6068 gtk_check_menu_item_set_active
6069 (item, TRUE);
6071 num_checked++;
6072 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
6077 children = gtk_container_get_children(GTK_CONTAINER(menu));
6078 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
6079 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
6080 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
6081 "tag_id"));
6082 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
6083 if (num_checked < sel_len && num_checked > 0)
6084 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
6085 else
6086 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
6089 g_list_free(children);
6090 g_hash_table_destroy(menu_table);
6091 g_hash_table_destroy(menu_allsel_table);
6092 /* reset "dont_toggle" state */
6093 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6094 GINT_TO_POINTER(0));
6097 void summaryview_destroy(SummaryView *summaryview)
6099 if(summaryview->simplify_subject_preg) {
6100 regfree(summaryview->simplify_subject_preg);
6101 g_free(summaryview->simplify_subject_preg);
6102 summaryview->simplify_subject_preg = NULL;
6105 static void summary_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
6106 gpointer data)
6108 SummaryView *summaryview;
6110 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
6111 cm_return_if_fail(summaryview != NULL);
6113 /* "dont_toggle" state set? */
6114 if (g_object_get_data(G_OBJECT(summaryview->tags_menu),
6115 "dont_toggle"))
6116 return;
6118 tag_apply_open(summary_get_selection(summaryview));
6121 static gint summary_tag_cmp_list(gconstpointer a, gconstpointer b)
6123 gint id_a = GPOINTER_TO_INT(a);
6124 gint id_b = GPOINTER_TO_INT(b);
6125 const gchar *tag_a = tags_get_tag(id_a);
6126 const gchar *tag_b = tags_get_tag(id_b);
6128 if (tag_a == NULL)
6129 return tag_b == NULL ? 0:1;
6131 if (tag_b == NULL)
6132 return 1;
6134 return g_utf8_collate(tag_a, tag_b);
6137 static void summary_tags_menu_create(SummaryView *summaryview, gboolean refresh)
6140 GtkWidget *label_menuitem;
6141 GtkWidget *menu;
6142 GtkWidget *item;
6143 GSList *cur = tags_get_list();
6144 GSList *orig = NULL;
6145 gboolean existing_tags = FALSE;
6146 gchar *accel_path = NULL;
6148 cur = orig = g_slist_sort(cur, summary_tag_cmp_list);
6149 label_menuitem = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, "/Menus/SummaryViewPopup/Tags");
6150 g_signal_connect(G_OBJECT(label_menuitem), "activate",
6151 G_CALLBACK(summary_tags_menu_item_activate_item_cb),
6152 summaryview);
6154 gtk_widget_show(label_menuitem);
6156 menu = gtk_menu_new();
6158 gtk_menu_set_accel_group (GTK_MENU (menu),
6159 gtk_ui_manager_get_accel_group(summaryview->mainwin->ui_manager));
6161 /* create tags menu items */
6162 for (; cur; cur = cur->next) {
6163 gint id = GPOINTER_TO_INT(cur->data);
6164 const gchar *tag = tags_get_tag(id);
6165 item = gtk_check_menu_item_new_with_label(tag);
6166 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6167 g_signal_connect(G_OBJECT(item), "activate",
6168 G_CALLBACK(summary_tags_menu_item_activate_cb),
6169 GINT_TO_POINTER(id));
6170 g_object_set_data(G_OBJECT(item), "summaryview",
6171 summaryview);
6172 g_object_set_data(G_OBJECT(item), "tag_id",
6173 GINT_TO_POINTER(id));
6174 gtk_widget_show(item);
6175 accel_path = g_strconcat("<ClawsTags>/",tag, NULL);
6176 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6177 g_free(accel_path);
6178 existing_tags = TRUE;
6180 if (existing_tags) {
6181 /* separator */
6182 item = gtk_menu_item_new();
6183 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6184 gtk_widget_show(item);
6187 item = gtk_menu_item_new_with_label(_("Apply tags..."));
6188 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6189 g_signal_connect(G_OBJECT(item), "activate",
6190 G_CALLBACK(summary_tags_menu_item_apply_tags_activate_cb),
6191 NULL);
6192 g_object_set_data(G_OBJECT(item), "summaryview",
6193 summaryview);
6194 gtk_widget_show(item);
6195 accel_path = g_strdup_printf("<ClawsTags>/ApplyTags");
6196 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6197 g_free(accel_path);
6199 g_slist_free(orig);
6200 gtk_widget_show(menu);
6201 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
6202 summaryview->tags_menu = menu;
6205 static gboolean summary_popup_menu(GtkWidget *widget, gpointer data)
6207 SummaryView *summaryview = (SummaryView *)data;
6208 summaryview->display_msg = messageview_is_visible(summaryview->messageview);
6210 gtk_menu_popup(GTK_MENU(summaryview->popupmenu),
6211 NULL, NULL, NULL, NULL,
6212 3, gtk_get_current_event_time());
6214 return TRUE;
6217 #if !GENERIC_UMPC
6218 static gchar *summaryview_get_tooltip_text(SummaryView *summaryview, MsgInfo *info, gint column)
6220 MsgFlags flags;
6221 if (!info)
6222 return NULL;
6224 flags = info->flags;
6226 switch(summaryview->col_state[column].type) {
6227 case S_COL_STATUS:
6228 if (MSG_IS_IGNORE_THREAD(flags)) {
6229 return _("Ignored thread");
6230 } else if (MSG_IS_WATCH_THREAD(flags)) {
6231 return _("Watched thread");
6232 } else if (MSG_IS_SPAM(flags)) {
6233 return _("Spam");
6234 } else if (MSG_IS_NEW(flags)) {
6235 return _("New");
6236 } else if (MSG_IS_UNREAD(flags)) {
6237 return _("Unread");
6238 } else if (MSG_IS_REPLIED(flags) && MSG_IS_FORWARDED(flags)) {
6239 return _("Replied but also forwarded - click to see reply");
6240 } else if (MSG_IS_REPLIED(flags)) {
6241 return _("Replied - click to see reply");
6242 } else if (MSG_IS_FORWARDED(flags)) {
6243 return _("Forwarded");
6244 } else {
6245 return NULL;
6247 case S_COL_MARK:
6248 if (MSG_IS_DELETED(flags)) {
6249 return _("Deleted");
6250 } else if (MSG_IS_MARKED(flags)) {
6251 return _("Marked");
6252 } else if (MSG_IS_MOVE(flags)) {
6253 return _("To be moved");
6254 } else if (MSG_IS_COPY(flags)) {
6255 return _("To be copied");
6256 } else {
6257 return NULL;
6259 case S_COL_LOCKED:
6260 if (MSG_IS_LOCKED(flags)) {
6261 return _("Locked");
6262 } else {
6263 return NULL;
6265 case S_COL_MIME:
6266 if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_SIGNED(flags)) {
6267 return _("Signed, has attachment(s)");
6268 } else if (MSG_IS_SIGNED(flags)) {
6269 return _("Signed");
6270 } else if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_ENCRYPTED(flags)) {
6271 return _("Encrypted, has attachment(s)");
6272 } else if (MSG_IS_ENCRYPTED(flags)) {
6273 return _("Encrypted");
6274 } else if (MSG_IS_WITH_ATTACHMENT(flags)) {
6275 return _("Has attachment(s)");
6276 } else {
6277 return NULL;
6279 default:
6280 return NULL;
6283 static gboolean tooltip_cb (GtkWidget *widget,
6284 gint x,
6285 gint y,
6286 gboolean keyboard_mode,
6287 GtkTooltip *tooltip,
6288 gpointer user_data)
6290 GtkCMCTree *ctree = GTK_CMCTREE(widget);
6291 SummaryView *summaryview = (SummaryView *)user_data;
6292 gint row = -1, column = -1;
6293 int offset = prefs_common.show_col_headers ? 24:0;
6294 GtkCMCTreeNode *node = NULL;
6295 gchar *text = NULL;
6296 gchar *formatted = NULL;
6297 MsgInfo *info = NULL;
6298 GdkRectangle rect;
6299 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
6300 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
6301 if (!prefs_common.show_tooltips)
6302 return FALSE;
6304 if (y - offset < 0)
6305 return FALSE;
6307 if (!gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree), x, y - offset,
6308 &row, &column))
6309 return FALSE;
6311 if ((node = gtk_cmctree_node_nth(ctree, row)) == NULL)
6312 return FALSE;
6314 if ((info = gtk_cmctree_node_get_row_data(ctree, node)) == NULL)
6315 return FALSE;
6317 switch (gtk_cmctree_node_get_cell_type(ctree, node, column)) {
6318 case GTK_CMCELL_TEXT:
6319 if (gtk_cmctree_node_get_text(ctree, node, column, &text) != TRUE)
6320 return FALSE;
6321 break;
6322 case GTK_CMCELL_PIXTEXT:
6323 if (gtk_cmctree_node_get_pixtext(ctree, node, column, &text,
6324 NULL, NULL) != TRUE)
6325 return FALSE;
6326 break;
6327 default:
6328 if ((text = summaryview_get_tooltip_text(summaryview, info, column)) == NULL)
6329 return FALSE;
6332 if (!text || !*text)
6333 return FALSE;
6335 formatted = g_strdup(text);
6336 g_strstrip(formatted);
6338 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
6339 gtk_tooltip_set_markup (tooltip, formatted);
6340 else
6341 gtk_tooltip_set_text (tooltip, formatted);
6342 g_free(formatted);
6344 rect.x = x - 2;
6345 rect.y = y - 2;
6346 rect.width = 12;
6347 rect.height= 12;
6348 gtk_tooltip_set_tip_area(tooltip, &rect);
6350 return TRUE;
6352 #endif
6353 static GtkWidget *summary_ctree_create(SummaryView *summaryview)
6355 GtkWidget *ctree;
6356 gint *col_pos = summaryview->col_pos;
6357 SummaryColumnState *col_state;
6358 gchar *titles[N_SUMMARY_COLS];
6359 SummaryColumnType type;
6360 gint pos;
6361 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
6362 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
6363 memset(titles, 0, sizeof(titles));
6365 col_state = prefs_summary_column_get_config();
6366 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
6367 summaryview->col_state[pos] = col_state[pos];
6368 type = col_state[pos].type;
6369 col_pos[type] = pos;
6370 titles[pos] = "dummy";
6372 col_state = summaryview->col_state;
6374 ctree = gtk_sctree_new_with_titles
6375 (N_SUMMARY_COLS, col_pos[S_COL_SUBJECT], titles);
6377 if (prefs_common.show_col_headers == FALSE)
6378 gtk_cmclist_column_titles_hide(GTK_CMCLIST(ctree));
6380 gtk_cmclist_set_selection_mode(GTK_CMCLIST(ctree), GTK_SELECTION_MULTIPLE);
6381 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_MARK],
6382 GTK_JUSTIFY_CENTER);
6383 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_STATUS],
6384 GTK_JUSTIFY_CENTER);
6385 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_LOCKED],
6386 GTK_JUSTIFY_CENTER);
6387 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_MIME],
6388 GTK_JUSTIFY_CENTER);
6389 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_SIZE],
6390 GTK_JUSTIFY_RIGHT);
6391 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_NUMBER],
6392 GTK_JUSTIFY_RIGHT);
6393 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_SCORE],
6394 GTK_JUSTIFY_RIGHT);
6395 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_MARK],
6396 prefs_common.summary_col_size[S_COL_MARK]);
6397 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_STATUS],
6398 prefs_common.summary_col_size[S_COL_STATUS]);
6399 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_LOCKED],
6400 prefs_common.summary_col_size[S_COL_LOCKED]);
6401 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_MIME],
6402 prefs_common.summary_col_size[S_COL_MIME]);
6403 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SUBJECT],
6404 prefs_common.summary_col_size[S_COL_SUBJECT]);
6405 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_FROM],
6406 prefs_common.summary_col_size[S_COL_FROM]);
6407 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_TO],
6408 prefs_common.summary_col_size[S_COL_TO]);
6409 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_DATE],
6410 prefs_common.summary_col_size[S_COL_DATE]);
6411 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SIZE],
6412 prefs_common.summary_col_size[S_COL_SIZE]);
6413 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_NUMBER],
6414 prefs_common.summary_col_size[S_COL_NUMBER]);
6415 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SCORE],
6416 prefs_common.summary_col_size[S_COL_SCORE]);
6417 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_TAGS],
6418 prefs_common.summary_col_size[S_COL_TAGS]);
6420 gtk_cmctree_set_line_style(GTK_CMCTREE(ctree), GTK_CMCTREE_LINES_NONE);
6421 gtk_cmctree_set_expander_style(GTK_CMCTREE(ctree),
6422 GTK_CMCTREE_EXPANDER_TRIANGLE);
6424 gtk_sctree_set_stripes(GTK_SCTREE(ctree), prefs_common.use_stripes_in_summaries);
6426 gtk_cmctree_set_indent(GTK_CMCTREE(ctree), 12);
6427 g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview);
6429 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
6430 gtkut_widget_set_can_focus(GTK_CMCLIST(ctree)->column[pos].button,
6431 FALSE);
6432 if (((pos == summaryview->col_pos[S_COL_FROM] && !FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) ||
6433 (pos == summaryview->col_pos[S_COL_TO] && FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) ||
6434 pos == summaryview->col_pos[S_COL_DATE]) && (vert_layout || small_layout) &&
6435 prefs_common.two_line_vert)
6436 gtk_cmclist_set_column_visibility
6437 (GTK_CMCLIST(ctree), pos, FALSE);
6438 else
6439 gtk_cmclist_set_column_visibility
6440 (GTK_CMCLIST(ctree), pos, col_state[pos].visible);
6442 if (prefs_common.two_line_vert)
6443 gtk_sctree_set_use_markup(GTK_SCTREE(ctree), summaryview->col_pos[S_COL_SUBJECT], vert_layout||small_layout);
6445 /* connect signal to the buttons for sorting */
6446 #define CLIST_BUTTON_SIGNAL_CONNECT(col, func) \
6447 g_signal_connect \
6448 (G_OBJECT(GTK_CMCLIST(ctree)->column[col_pos[col]].button), \
6449 "clicked", \
6450 G_CALLBACK(func), \
6451 summaryview)
6453 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_MARK , summary_mark_clicked);
6454 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_STATUS , summary_status_clicked);
6455 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_MIME , summary_mime_clicked);
6456 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_NUMBER , summary_num_clicked);
6457 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SIZE , summary_size_clicked);
6458 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_DATE , summary_date_clicked);
6459 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_FROM , summary_from_clicked);
6460 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_TO , summary_to_clicked);
6461 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SUBJECT, summary_subject_clicked);
6462 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SCORE, summary_score_clicked);
6463 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_LOCKED, summary_locked_clicked);
6464 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_TAGS, summary_tags_clicked);
6466 #undef CLIST_BUTTON_SIGNAL_CONNECT
6468 g_signal_connect(G_OBJECT(ctree), "tree_select_row",
6469 G_CALLBACK(summary_selected), summaryview);
6470 g_signal_connect(G_OBJECT(ctree), "tree_unselect_row",
6471 G_CALLBACK(summary_unselected), summaryview);
6472 g_signal_connect(G_OBJECT(ctree), "button_press_event",
6473 G_CALLBACK(summary_button_pressed),
6474 summaryview);
6475 g_signal_connect(G_OBJECT(ctree), "popup-menu",
6476 G_CALLBACK(summary_popup_menu), summaryview);
6477 g_signal_connect(G_OBJECT(ctree), "button_release_event",
6478 G_CALLBACK(summary_button_released),
6479 summaryview);
6480 g_signal_connect(G_OBJECT(ctree), "key_press_event",
6481 G_CALLBACK(summary_key_pressed), summaryview);
6482 g_signal_connect(G_OBJECT(ctree), "resize_column",
6483 G_CALLBACK(summary_col_resized), summaryview);
6484 g_signal_connect(G_OBJECT(ctree), "open_row",
6485 G_CALLBACK(summary_open_row), summaryview);
6487 g_signal_connect_after(G_OBJECT(ctree), "tree_expand",
6488 G_CALLBACK(summary_tree_expanded),
6489 summaryview);
6490 g_signal_connect_after(G_OBJECT(ctree), "tree_collapse",
6491 G_CALLBACK(summary_tree_collapsed),
6492 summaryview);
6494 g_signal_connect(G_OBJECT(ctree), "start_drag",
6495 G_CALLBACK(summary_start_drag),
6496 summaryview);
6497 g_signal_connect(G_OBJECT(ctree), "drag_data_get",
6498 G_CALLBACK(summary_drag_data_get),
6499 summaryview);
6500 g_signal_connect(G_OBJECT(ctree), "drag_end",
6501 G_CALLBACK(summary_drag_end),
6502 summaryview);
6504 gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL & ~GTK_DEST_DEFAULT_HIGHLIGHT,
6505 summary_drag_types, 3,
6506 GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_DEFAULT);
6508 g_signal_connect(G_OBJECT(ctree), "drag_data_received",
6509 G_CALLBACK(summary_drag_data_received),
6510 summaryview);
6512 g_signal_connect(G_OBJECT(ctree), "drag_motion",
6513 G_CALLBACK(summary_drag_motion_cb),
6514 summaryview);
6516 #if !GENERIC_UMPC
6517 g_object_set (G_OBJECT(ctree), "has-tooltip", TRUE, NULL);
6518 g_signal_connect(G_OBJECT(ctree), "query-tooltip",
6519 G_CALLBACK(tooltip_cb),
6520 summaryview);
6521 #endif
6522 return ctree;
6525 void summary_set_column_order(SummaryView *summaryview)
6527 GtkWidget *ctree;
6528 GtkWidget *scrolledwin = summaryview->scrolledwin;
6529 FolderItem *item;
6530 guint selected_msgnum = summary_get_msgnum(summaryview, summaryview->selected);
6531 guint displayed_msgnum = summary_get_msgnum(summaryview, summaryview->displayed);
6533 item = summaryview->folder_item;
6535 summary_clear_all(summaryview);
6536 gtk_widget_destroy(summaryview->ctree);
6538 summaryview->ctree = ctree = summary_ctree_create(summaryview);
6539 summary_set_fonts(summaryview);
6540 summary_set_column_titles(summaryview);
6541 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
6542 GTK_CMCLIST(ctree)->hadjustment);
6543 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
6544 GTK_CMCLIST(ctree)->vadjustment);
6545 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
6546 gtk_widget_show(ctree);
6548 summary_show(summaryview, item);
6550 summary_select_by_msgnum(summaryview, selected_msgnum);
6552 summaryview->selected = summary_find_msg_by_msgnum(summaryview, selected_msgnum);
6553 summaryview->displayed = summary_find_msg_by_msgnum(summaryview, displayed_msgnum);
6554 if (!summaryview->displayed)
6555 messageview_clear(summaryview->messageview);
6556 else
6557 summary_redisplay_msg(summaryview);
6559 /* get normal row height */
6560 gtk_cmclist_set_row_height(GTK_CMCLIST(ctree), 0);
6561 normal_row_height = GTK_CMCLIST(ctree)->row_height;
6563 if ((prefs_common.layout_mode == SMALL_LAYOUT || prefs_common.layout_mode == VERTICAL_LAYOUT) &&
6564 prefs_common.two_line_vert) {
6565 gtk_cmclist_set_row_height(GTK_CMCLIST(summaryview->ctree), 2*normal_row_height + 2);
6570 /* callback functions */
6572 static gint summary_folder_eventbox_pressed(GtkWidget *eventbox, GdkEventButton *event,
6573 SummaryView *summaryview)
6575 if (event) {
6576 folderview_grab_focus(summaryview->folderview);
6577 mainwindow_exit_folder(summaryview->mainwin);
6579 return TRUE;
6582 static gint summary_toggle_pressed(GtkWidget *eventbox, GdkEventButton *event,
6583 SummaryView *summaryview)
6585 if (event)
6586 summary_toggle_view(summaryview);
6587 return TRUE;
6589 #ifdef GENERIC_UMPC
6590 static void summary_toggle_multiple_pressed(GtkWidget *widget,
6591 SummaryView *summaryview)
6593 GTK_SCTREE(summaryview->ctree)->force_additive_sel =
6594 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
6596 #endif
6597 static gboolean summary_button_pressed(GtkWidget *ctree, GdkEventButton *event,
6598 SummaryView *summaryview)
6600 if (!event) return FALSE;
6602 if (event->button == 3) {
6603 /* right clicked */
6604 summary_set_menu_sensitive(summaryview);
6605 gtk_menu_popup(GTK_MENU(summaryview->popupmenu), NULL, NULL,
6606 NULL, NULL, event->button, event->time);
6607 } else if (event->button == 2) {
6608 summaryview->display_msg = messageview_is_visible(summaryview->messageview);
6609 } else if (event->button == 1) {
6610 if (!prefs_common.emulate_emacs &&
6611 messageview_is_visible(summaryview->messageview))
6612 summaryview->display_msg = TRUE;
6615 return FALSE;
6618 static gboolean summary_button_released(GtkWidget *ctree, GdkEventButton *event,
6619 SummaryView *summaryview)
6621 return FALSE;
6624 gboolean summary_pass_key_press_event(SummaryView *summaryview, GdkEventKey *event)
6626 if (!summaryview)
6627 return FALSE;
6628 if (summary_is_list(summaryview))
6629 return summary_key_pressed(summaryview->ctree, event, summaryview);
6630 else
6631 return FALSE;
6634 #define BREAK_ON_MODIFIER_KEY() \
6635 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
6637 /* Copied from gtkcmclist.c, if it changes there, it has to change
6638 * here as well. This is an ugly hack, there must be a better way to
6639 * find out how much to move for page up/down. */
6640 #define CELL_SPACING 1
6641 static gboolean summary_key_pressed(GtkWidget *widget, GdkEventKey *event,
6642 SummaryView *summaryview)
6644 GtkCMCTree *ctree = GTK_CMCTREE(widget);
6645 GtkCMCTreeNode *node;
6646 MessageView *messageview;
6647 GtkAdjustment *adj;
6648 gboolean mod_pressed;
6650 if (!event)
6651 return TRUE;
6653 if (quicksearch_has_focus(summaryview->quicksearch))
6654 return FALSE;
6656 messageview = summaryview->messageview;
6658 mod_pressed =
6659 ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
6661 if (summaryview->selected) {
6662 gboolean handled = FALSE;
6663 switch (event->keyval) {
6664 case GDK_KEY_space: /* Page down or go to the next */
6665 handled = TRUE;
6666 if (event->state & GDK_CONTROL_MASK) {
6667 handled = FALSE;
6668 break;
6670 if (event->state & GDK_SHIFT_MASK)
6671 mimeview_scroll_page(messageview->mimeview, TRUE);
6672 else {
6673 if (summaryview->displayed != summaryview->selected) {
6674 summary_display_msg(summaryview,
6675 summaryview->selected);
6676 break;
6678 if (mod_pressed) {
6679 if (!mimeview_scroll_page(messageview->mimeview, TRUE))
6680 summary_select_prev_unread(summaryview);
6681 } else {
6682 if (!mimeview_scroll_page(messageview->mimeview, FALSE))
6683 summary_select_next_unread(summaryview);
6686 break;
6687 case GDK_KEY_BackSpace: /* Page up */
6688 handled = TRUE;
6689 mimeview_scroll_page(messageview->mimeview, TRUE);
6690 break;
6691 case GDK_KEY_Return: /* Scroll up/down one line */
6692 case GDK_KEY_KP_Enter:
6693 handled = TRUE;
6694 if (summaryview->displayed != summaryview->selected) {
6695 #ifndef GENERIC_UMPC
6696 summary_display_msg(summaryview,
6697 summaryview->selected);
6698 #else
6699 summary_open_row(NULL, summaryview);
6700 #endif
6701 break;
6703 mimeview_scroll_one_line(messageview->mimeview, mod_pressed);
6704 break;
6707 if (handled)
6708 return FALSE;
6710 if (summary_is_locked(summaryview))
6711 return TRUE;
6713 switch (event->keyval) {
6714 case GDK_KEY_Left: /* Move focus */
6715 adj = gtk_scrolled_window_get_hadjustment
6716 (GTK_SCROLLED_WINDOW(summaryview->scrolledwin));
6717 if (gtk_adjustment_get_lower(adj) != gtk_adjustment_get_value(adj))
6718 break;
6719 /* FALLTHROUGH */
6720 case GDK_KEY_Escape:
6721 folderview_grab_focus(summaryview->folderview);
6722 mainwindow_exit_folder(summaryview->mainwin);
6723 return TRUE;
6724 case GDK_KEY_Home: case GDK_KEY_KP_Home:
6725 case GDK_KEY_End: case GDK_KEY_KP_End:
6726 case GDK_KEY_Up: case GDK_KEY_KP_Up:
6727 case GDK_KEY_Down: case GDK_KEY_KP_Down:
6728 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
6729 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
6730 if ((node = summaryview->selected) != NULL) {
6731 GtkCMCTreeNode *next = NULL;
6732 switch (event->keyval) {
6733 case GDK_KEY_Home: case GDK_KEY_KP_Home:
6734 next = gtk_cmctree_node_nth(ctree, 0);
6735 break;
6736 case GDK_KEY_End: case GDK_KEY_KP_End:
6737 next = gtk_cmctree_node_nth(ctree,
6738 g_list_length(GTK_CMCLIST(ctree)->row_list)-1);
6739 break;
6740 case GDK_KEY_Up: case GDK_KEY_KP_Up:
6741 next = gtk_cmctree_node_nth(ctree,
6742 MAX(0, GTK_CMCLIST(ctree)->focus_row - 1));
6743 break;
6744 case GDK_KEY_Down: case GDK_KEY_KP_Down:
6745 next = gtk_cmctree_node_nth(ctree,
6746 MIN(GTK_CMCLIST(ctree)->focus_row + 1, GTK_CMCLIST(ctree)->rows));
6747 break;
6748 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
6749 next = gtk_cmctree_node_nth(ctree,
6750 MAX(0, GTK_CMCLIST(ctree)->focus_row -
6751 (2 * GTK_CMCLIST(ctree)->clist_window_height -
6752 GTK_CMCLIST(ctree)->row_height - CELL_SPACING) /
6753 (2 * (GTK_CMCLIST(ctree)->row_height + CELL_SPACING))));
6754 break;
6755 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
6756 next = gtk_cmctree_node_nth(ctree,
6757 MIN(GTK_CMCLIST(ctree)->rows - 1, GTK_CMCLIST(ctree)->focus_row +
6758 (2 * GTK_CMCLIST(ctree)->clist_window_height -
6759 GTK_CMCLIST(ctree)->row_height - CELL_SPACING) /
6760 (2 * (GTK_CMCLIST(ctree)->row_height + CELL_SPACING))));
6761 break;
6764 if (next) {
6765 gtk_sctree_select_with_state
6766 (GTK_SCTREE(ctree), next, (event->state & ~GDK_CONTROL_MASK) );
6768 /* Deprecated - what are the non-deprecated equivalents? */
6769 if (gtk_cmctree_node_is_visible(GTK_CMCTREE(ctree), next) != GTK_VISIBILITY_FULL)
6770 gtkut_ctree_node_move_if_on_the_edge(GTK_CMCTREE(ctree), next, -1);
6771 if (!mod_pressed)
6772 summary_select_node(summaryview, summaryview->selected, -1);
6773 summaryview->selected = next;
6776 return TRUE;
6777 default:
6778 break;
6781 if (!summaryview->selected) {
6782 node = gtk_cmctree_node_nth(ctree, 0);
6783 if (node)
6784 gtk_sctree_select(GTK_SCTREE(ctree), node);
6785 else
6786 return TRUE;
6789 switch (event->keyval) {
6790 case GDK_KEY_Delete:
6791 BREAK_ON_MODIFIER_KEY();
6792 summary_delete_trash(summaryview);
6793 break;
6794 default:
6795 break;
6797 return FALSE;
6799 #undef CELL_SPACING
6801 static void quicksearch_execute_cb(QuickSearch *quicksearch, gpointer data)
6803 SummaryView *summaryview = data;
6805 summaryview_reset_recursive_folder_match(summaryview);
6806 if (summary_show(summaryview, summaryview->folder_item))
6807 summaryview_quicksearch_recurse(summaryview);
6808 else
6809 summaryview_reset_recursive_folder_match(summaryview);
6812 static void tog_searchbar_cb(GtkWidget *w, gpointer data)
6814 SummaryView *summaryview = (SummaryView *)data;
6816 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
6817 prefs_common.show_searchbar = TRUE;
6818 quicksearch_show(summaryview->quicksearch);
6819 } else {
6820 prefs_common.show_searchbar = FALSE;
6821 quicksearch_hide(summaryview->quicksearch);
6825 void summaryview_activate_quicksearch(SummaryView *summaryview, gboolean show)
6827 prefs_common.show_searchbar = show;
6828 gtk_toggle_button_set_active(
6829 GTK_TOGGLE_BUTTON(summaryview->toggle_search),
6830 show);
6831 if (show) {
6832 quicksearch_show(summaryview->quicksearch);
6833 } else {
6834 quicksearch_hide(summaryview->quicksearch);
6835 summary_grab_focus(summaryview);
6839 void summary_open_row(GtkSCTree *sctree, SummaryView *summaryview)
6841 if (FOLDER_SHOWS_TO_HDR(summaryview->folder_item))
6842 summary_reedit(summaryview);
6843 else
6844 summary_open_msg(summaryview);
6846 summaryview->display_msg = FALSE;
6849 static void summary_tree_expanded(GtkCMCTree *ctree, GtkCMCTreeNode *node,
6850 SummaryView *summaryview)
6852 summary_set_row_marks(summaryview, node);
6853 if (prefs_common.bold_unread) {
6854 while (node) {
6855 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
6856 if (GTK_CMCTREE_ROW(node)->children)
6857 summary_set_row_marks(summaryview, node);
6858 node = next;
6863 static void summary_tree_collapsed(GtkCMCTree *ctree, GtkCMCTreeNode *node,
6864 SummaryView *summaryview)
6866 gtk_sctree_select(GTK_SCTREE(ctree), node);
6867 summary_set_row_marks(summaryview, node);
6870 static void summary_unselected(GtkCMCTree *ctree, GtkCMCTreeNode *row,
6871 gint column, SummaryView *summaryview)
6873 if (summary_is_locked(summaryview)
6874 || GTK_SCTREE(ctree)->selecting_range) {
6875 return;
6878 summary_status_show(summaryview);
6881 static void summary_selected(GtkCMCTree *ctree, GtkCMCTreeNode *row,
6882 gint column, SummaryView *summaryview)
6884 const GList *list, *cur;
6885 MessageView *msgview;
6886 MsgInfo *msginfo;
6887 gboolean marked_unread = FALSE;
6889 if (summary_is_locked(summaryview)
6890 && !GTK_SCTREE(ctree)->selecting_range
6891 && summaryview->messageview
6892 && summaryview->messageview->mimeview
6893 && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
6894 && summaryview->messageview->mimeview->textview->loading) {
6895 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
6896 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
6898 data->ctree = ctree;
6899 data->row = row;
6900 data->node = NULL;
6901 data->column = column;
6902 data->summaryview = summaryview;
6903 debug_print("postponing open of message till end of load\n");
6904 g_timeout_add(100, summary_select_retry, data);
6905 return;
6907 if (summary_is_locked(summaryview)
6908 || GTK_SCTREE(ctree)->selecting_range) {
6909 return;
6912 summary_status_show(summaryview);
6914 if (GTK_CMCLIST(ctree)->selection &&
6915 GTK_CMCLIST(ctree)->selection->next) {
6916 summaryview->display_msg = FALSE;
6917 summary_set_menu_sensitive(summaryview);
6918 toolbar_main_set_sensitive(summaryview->mainwin);
6919 return;
6922 summaryview->selected = row;
6924 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
6925 cm_return_if_fail(msginfo != NULL);
6927 main_create_mailing_list_menu (summaryview->mainwin, msginfo);
6928 toolbar_set_learn_button
6929 (summaryview->mainwin->toolbar,
6930 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
6932 switch (column < 0 ? column : summaryview->col_state[column].type) {
6933 case S_COL_MARK:
6934 if (!MSG_IS_DELETED(msginfo->flags) &&
6935 !MSG_IS_MOVE(msginfo->flags) &&
6936 !MSG_IS_COPY(msginfo->flags)) {
6937 if (MSG_IS_MARKED(msginfo->flags)) {
6938 summary_unmark_row(summaryview, row);
6939 summary_status_show(summaryview);
6940 } else {
6941 summary_mark_row(summaryview, row);
6942 summary_status_show(summaryview);
6945 break;
6946 case S_COL_STATUS:
6947 if (MSG_IS_UNREAD(msginfo->flags)) {
6948 summary_mark_row_as_read(summaryview, row);
6949 summary_status_show(summaryview);
6950 } else if (MSG_IS_SPAM(msginfo->flags)) {
6951 if (procmsg_spam_learner_learn(msginfo, NULL, FALSE) == 0)
6952 summary_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
6953 else
6954 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
6955 } else if (!MSG_IS_REPLIED(msginfo->flags) &&
6956 !MSG_IS_FORWARDED(msginfo->flags)) {
6957 marked_unread = TRUE;
6958 } else if (MSG_IS_REPLIED(msginfo->flags)) {
6959 summary_find_answers(summaryview, msginfo);
6960 return;
6962 break;
6963 case S_COL_LOCKED:
6964 if (MSG_IS_LOCKED(msginfo->flags)) {
6965 summary_unlock_row(summaryview, row);
6966 summary_status_show(summaryview);
6968 else {
6969 summary_lock_row(summaryview, row);
6970 summary_status_show(summaryview);
6972 break;
6973 default:
6974 break;
6977 list = messageview_get_msgview_list();
6978 for (cur = list; cur != NULL; cur = cur->next) {
6979 msgview = (MessageView *) cur->data;
6981 if (msgview->new_window && msgview->update_needed) {
6982 MsgInfo *new_msginfo = summary_get_selected_msg(summaryview);
6983 messageview_show(msgview, new_msginfo, msgview->all_headers);
6984 msgview->update_needed = FALSE;
6988 if (summaryview->display_msg) {
6989 summaryview->display_msg = FALSE;
6990 if (summaryview->displayed != row) {
6991 summary_display_msg(summaryview, row);
6992 if (marked_unread) {
6993 summary_mark_row_as_unread(summaryview, row);
6994 summary_status_show(summaryview);
6996 return;
7000 if (marked_unread) {
7001 summary_mark_row_as_unread(summaryview, row);
7002 summary_status_show(summaryview);
7005 summary_set_menu_sensitive(summaryview);
7006 toolbar_main_set_sensitive(summaryview->mainwin);
7009 static void summary_col_resized(GtkCMCList *clist, gint column, gint width,
7010 SummaryView *summaryview)
7012 SummaryColumnType type = summaryview->col_state[column].type;
7014 prefs_common.summary_col_size[type] = width;
7019 * \brief get List of msginfo selected in SummaryView
7021 * \param summaryview
7023 * \return GSList holding MsgInfo
7025 GSList *summary_get_selection(SummaryView *summaryview)
7027 GList *sel = NULL;
7028 GSList *msginfo_list = NULL;
7030 cm_return_val_if_fail(summaryview != NULL, NULL);
7032 sel = GTK_CMCLIST(summaryview->ctree)->selection;
7034 cm_return_val_if_fail(sel != NULL, NULL);
7036 for ( ; sel != NULL; sel = sel->next)
7037 msginfo_list =
7038 g_slist_prepend(msginfo_list,
7039 gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
7040 GTK_CMCTREE_NODE(sel->data)));
7041 return g_slist_reverse(msginfo_list);
7044 static void summary_sort_by_column_click(SummaryView *summaryview,
7045 FolderSortKey sort_key)
7047 GtkCMCTreeNode *node = NULL;
7048 START_TIMING("");
7049 if (summaryview->sort_key == sort_key)
7050 summary_sort(summaryview, sort_key,
7051 summaryview->sort_type == SORT_ASCENDING
7052 ? SORT_DESCENDING : SORT_ASCENDING);
7053 else
7054 summary_sort(summaryview, sort_key, SORT_ASCENDING);
7056 node = GTK_CMCTREE_NODE(GTK_CMCLIST(summaryview->ctree)->row_list);
7058 summary_freeze(summaryview);
7059 if (prefs_common.bold_unread) {
7060 while (node) {
7061 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
7062 if (GTK_CMCTREE_ROW(node)->children)
7063 summary_set_row_marks(summaryview, node);
7064 node = next;
7067 summary_thaw(summaryview);
7068 END_TIMING();
7071 static void summary_mark_clicked(GtkWidget *button, SummaryView *summaryview)
7073 summary_sort_by_column_click(summaryview, SORT_BY_MARK);
7076 static void summary_status_clicked(GtkWidget *button, SummaryView *summaryview)
7078 summary_sort_by_column_click(summaryview, SORT_BY_STATUS);
7081 static void summary_mime_clicked(GtkWidget *button, SummaryView *summaryview)
7083 summary_sort_by_column_click(summaryview, SORT_BY_MIME);
7086 static void summary_num_clicked(GtkWidget *button, SummaryView *summaryview)
7088 summary_sort_by_column_click(summaryview, SORT_BY_NUMBER);
7091 static void summary_size_clicked(GtkWidget *button, SummaryView *summaryview)
7093 summary_sort_by_column_click(summaryview, SORT_BY_SIZE);
7096 static void summary_date_clicked(GtkWidget *button, SummaryView *summaryview)
7098 if (summaryview->sort_key == SORT_BY_THREAD_DATE)
7099 summary_sort_by_column_click(summaryview, SORT_BY_THREAD_DATE);
7100 else
7101 summary_sort_by_column_click(summaryview, SORT_BY_DATE);
7104 static void summary_from_clicked(GtkWidget *button, SummaryView *summaryview)
7106 if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
7107 summary_sort_by_column_click(summaryview, SORT_BY_FROM);
7108 else
7109 summary_sort_by_column_click(summaryview, SORT_BY_TO);
7112 static void summary_to_clicked(GtkWidget *button, SummaryView *summaryview)
7114 if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
7115 summary_sort_by_column_click(summaryview, SORT_BY_TO);
7116 else
7117 summary_sort_by_column_click(summaryview, SORT_BY_FROM);
7120 static void summary_subject_clicked(GtkWidget *button,
7121 SummaryView *summaryview)
7123 summary_sort_by_column_click(summaryview, SORT_BY_SUBJECT);
7126 static void summary_score_clicked(GtkWidget *button,
7127 SummaryView *summaryview)
7129 summary_sort_by_column_click(summaryview, SORT_BY_SCORE);
7132 static void summary_locked_clicked(GtkWidget *button,
7133 SummaryView *summaryview)
7135 summary_sort_by_column_click(summaryview, SORT_BY_LOCKED);
7138 static void summary_tags_clicked(GtkWidget *button,
7139 SummaryView *summaryview)
7141 summary_sort_by_column_click(summaryview, SORT_BY_TAGS);
7144 static void summary_start_drag(GtkWidget *widget, gint button, GdkEvent *event,
7145 SummaryView *summaryview)
7147 GdkDragContext *context;
7149 cm_return_if_fail(summaryview != NULL);
7150 cm_return_if_fail(summaryview->folder_item != NULL);
7151 cm_return_if_fail(summaryview->folder_item->folder != NULL);
7153 if (summaryview->selected == NULL) return;
7155 context = gtk_drag_begin(widget, summaryview->target_list,
7156 GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event);
7157 gtk_drag_set_icon_default(context);
7158 if (prefs_common.layout_mode == SMALL_LAYOUT) {
7159 GtkWidget *paned = gtk_widget_get_parent(GTK_WIDGET_PTR(summaryview));
7160 if (paned && GTK_IS_PANED(paned)) {
7161 mainwindow_reset_paned(GTK_PANED(paned));
7166 static gboolean summary_return_to_list(void *data)
7168 SummaryView *summaryview = (SummaryView *)data;
7169 mainwindow_enter_folder(summaryview->mainwin);
7170 return FALSE;
7173 static void summary_drag_end (GtkWidget *widget,
7174 GdkDragContext *drag_context,
7175 SummaryView *summaryview)
7177 if (prefs_common.layout_mode == SMALL_LAYOUT) {
7178 g_timeout_add(250, summary_return_to_list, summaryview);
7182 static void summary_drag_data_get(GtkWidget *widget,
7183 GdkDragContext *drag_context,
7184 GtkSelectionData *selection_data,
7185 guint info,
7186 guint time,
7187 SummaryView *summaryview)
7189 if (info == TARGET_MAIL_URI_LIST) {
7190 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7191 GList *cur;
7192 MsgInfo *msginfo;
7193 gchar *mail_list = NULL, *tmp1, *tmp2;
7195 for (cur = GTK_CMCLIST(ctree)->selection;
7196 cur != NULL && cur->data != NULL; cur = cur->next) {
7197 msginfo = gtk_cmctree_node_get_row_data
7198 (ctree, GTK_CMCTREE_NODE(cur->data));
7199 tmp2 = procmsg_get_message_file(msginfo);
7200 if (!tmp2) continue;
7201 if (msginfo->subject) {
7202 gchar *san_subject = g_strdup(msginfo->subject);
7203 gchar *dest = NULL;
7204 subst_for_filename(san_subject);
7205 dest = g_strdup_printf("%s%s%s.%d.txt",
7206 get_tmp_dir(),
7207 G_DIR_SEPARATOR_S,
7208 san_subject, msginfo->msgnum);
7209 g_free(san_subject);
7210 san_subject = g_filename_from_utf8(dest, -1, NULL, NULL, NULL);
7211 g_free(dest);
7212 dest = san_subject;
7213 if (copy_file(tmp2, dest, TRUE) == 0) {
7214 g_free(tmp2);
7215 tmp2 = dest;
7218 tmp1 = g_filename_to_uri(tmp2, NULL, NULL);
7219 g_free(tmp2);
7220 tmp2 = g_strconcat(tmp1, "\r\n", NULL);
7221 g_free(tmp1);
7222 tmp1 = tmp2;
7224 if (!mail_list) {
7225 mail_list = tmp1;
7226 } else {
7227 tmp2 = g_strconcat(mail_list, tmp1, NULL);
7228 g_free(mail_list);
7229 g_free(tmp1);
7230 mail_list = tmp2;
7234 if (mail_list != NULL) {
7235 gtk_selection_data_set(selection_data,
7236 gtk_selection_data_get_target(selection_data), 8,
7237 mail_list, strlen(mail_list));
7238 g_free(mail_list);
7240 } else if (info == TARGET_DUMMY) {
7241 if (GTK_CMCLIST(summaryview->ctree)->selection)
7242 gtk_selection_data_set(selection_data,
7243 gtk_selection_data_get_target(selection_data), 8,
7244 "Dummy-Summaryview",
7245 strlen("Dummy-Summaryview")+1);
7246 } else if (info == TARGET_MAIL_CM_PATH_LIST) {
7247 /* content: folder_item_identifier\nmsgid1\nmsgid2\nmsgid3 */
7249 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7250 GList *cur;
7251 MsgInfo *msginfo;
7252 gchar *path_list = NULL;
7254 /* identifier */
7255 if(GTK_CMCLIST(ctree)->selection != NULL) {
7256 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->selection->data));
7257 if(msginfo && msginfo->folder)
7258 path_list = folder_item_get_identifier(msginfo->folder);
7261 for (cur = GTK_CMCLIST(ctree)->selection;
7262 cur != NULL && cur->data != NULL; cur = cur->next) {
7263 gchar *tmp;
7265 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(cur->data));
7266 if(!msginfo)
7267 continue;
7268 tmp = path_list;
7269 path_list = g_strconcat(path_list, "\n", (msginfo->msgid ? msginfo->msgid : "unknown"), NULL);
7270 g_free(tmp);
7273 if (path_list != NULL) {
7274 gtk_selection_data_set(selection_data,
7275 gtk_selection_data_get_target(selection_data), 8,
7276 path_list, strlen(path_list));
7277 g_free(path_list);
7282 static gboolean summary_drag_motion_cb(GtkWidget *widget,
7283 GdkDragContext *context,
7284 gint x,
7285 gint y,
7286 guint time,
7287 SummaryView *summaryview)
7289 FolderItem *item = summaryview->folder_item;
7290 if (!(item && item->folder && folder_item_parent(item) != NULL
7291 && FOLDER_CLASS(item->folder)->add_msg != NULL)) {
7292 gdk_drag_status(context, 0, time);
7293 return FALSE;
7294 } else if (gtk_drag_get_source_widget(context) ==
7295 mainwindow_get_mainwindow()->folderview->ctree) {
7296 /* no folders */
7297 gdk_drag_status(context, 0, time);
7298 return FALSE;
7299 } else if (gtk_drag_get_source_widget(context) ==
7300 summaryview->ctree) {
7301 /* not from same folder */
7302 gdk_drag_status(context, 0, time);
7303 return FALSE;
7304 } else {
7305 gdk_drag_status(context, GDK_ACTION_COPY, time);
7306 return TRUE;
7310 static void summary_drag_data_received(GtkWidget *widget,
7311 GdkDragContext *drag_context,
7312 gint x,
7313 gint y,
7314 GtkSelectionData *data,
7315 guint info,
7316 guint time,
7317 SummaryView *summaryview)
7319 if (info == TARGET_MAIL_URI_LIST) {
7320 FolderItem *item = summaryview->folder_item;
7321 if (!item) {
7322 gtk_drag_finish(drag_context, FALSE, FALSE, time);
7323 return;
7324 } else {
7325 folderview_finish_dnd(gtk_selection_data_get_data(data),
7326 drag_context, time, item);
7332 /* custom compare functions for sorting */
7334 static gint summary_cmp_by_date(GtkCMCList *clist,
7335 gconstpointer ptr1, gconstpointer ptr2)
7337 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7338 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7339 gint res;
7340 if (!msginfo1 || !msginfo2)
7341 return -1;
7343 res = (msginfo1->date_t - msginfo2->date_t);
7344 if (res == 0)
7345 res = msginfo1->msgnum - msginfo2->msgnum;
7346 return res;
7349 #define CMP_FUNC_DEF(func_name, val) \
7350 static gint func_name(GtkCMCList *clist, \
7351 gconstpointer ptr1, gconstpointer ptr2) \
7353 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data; \
7354 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data; \
7355 gint res; \
7356 if (!msginfo1 || !msginfo2) \
7357 return -1; \
7359 res = (val); \
7360 return (res != 0) ? res:summary_cmp_by_date(clist, ptr1, ptr2); \
7363 CMP_FUNC_DEF(summary_cmp_by_mark,
7364 MSG_IS_MARKED(msginfo1->flags) - MSG_IS_MARKED(msginfo2->flags))
7365 CMP_FUNC_DEF(summary_cmp_by_status,
7366 (-(MSG_IS_SPAM(msginfo1->flags))+(MSG_IS_UNREAD(msginfo1->flags)<<1)+(MSG_IS_NEW(msginfo1->flags)<<2))
7367 - (-(MSG_IS_SPAM(msginfo2->flags))+(MSG_IS_UNREAD(msginfo2->flags)<<1)+(MSG_IS_NEW(msginfo2->flags)<<2)) )
7368 CMP_FUNC_DEF(summary_cmp_by_mime,
7369 MSG_IS_WITH_ATTACHMENT(msginfo1->flags) - MSG_IS_WITH_ATTACHMENT(msginfo2->flags))
7370 CMP_FUNC_DEF(summary_cmp_by_label,
7371 MSG_GET_COLORLABEL(msginfo1->flags) -
7372 MSG_GET_COLORLABEL(msginfo2->flags))
7373 CMP_FUNC_DEF(summary_cmp_by_locked,
7374 MSG_IS_LOCKED(msginfo1->flags) - MSG_IS_LOCKED(msginfo2->flags))
7376 CMP_FUNC_DEF(summary_cmp_by_num, msginfo1->msgnum - msginfo2->msgnum)
7377 CMP_FUNC_DEF(summary_cmp_by_size, msginfo1->size - msginfo2->size)
7379 #undef CMP_FUNC_DEF
7381 static gint summary_cmp_by_subject(GtkCMCList *clist,
7382 gconstpointer ptr1,
7383 gconstpointer ptr2)
7385 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7386 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7387 gint res;
7389 if (!msginfo1->subject)
7390 return (msginfo2->subject != NULL);
7391 if (!msginfo2->subject)
7392 return -1;
7394 res = subject_compare_for_sort
7395 (msginfo1->subject, msginfo2->subject);
7396 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7399 static gint summary_cmp_by_thread_date(GtkCMCList *clist,
7400 gconstpointer ptr1,
7401 gconstpointer ptr2)
7403 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7404 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7405 gint thread_diff = msginfo1->thread_date - msginfo2->thread_date;
7407 if (msginfo1->thread_date > 0 && msginfo2->thread_date > 0)
7408 return thread_diff;
7409 else
7410 return msginfo1->date_t - msginfo2->date_t;
7413 static gint summary_cmp_by_from(GtkCMCList *clist, gconstpointer ptr1,
7414 gconstpointer ptr2)
7416 const gchar *str1, *str2;
7417 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7418 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7419 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7420 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7421 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7422 gint res;
7424 cm_return_val_if_fail(sv, -1);
7425 if (sv->col_state[sv->col_pos[S_COL_FROM]].visible) {
7426 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_FROM]])->text;
7427 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_FROM]])->text;
7428 } else {
7429 str1 = msginfo1->from;
7430 str2 = msginfo2->from;
7433 if (!str1)
7434 return str2 != NULL;
7436 if (!str2)
7437 return -1;
7439 res = g_utf8_collate(str1, str2);
7440 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7443 static gint summary_cmp_by_to(GtkCMCList *clist, gconstpointer ptr1,
7444 gconstpointer ptr2)
7446 const gchar *str1, *str2;
7447 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7448 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7449 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7450 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7451 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7452 gint res;
7453 cm_return_val_if_fail(sv, -1);
7455 if (sv->col_state[sv->col_pos[S_COL_TO]].visible) {
7456 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_TO]])->text;
7457 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_TO]])->text;
7458 } else {
7459 str1 = msginfo1->to;
7460 str2 = msginfo2->to;
7463 if (!str1)
7464 return str2 != NULL;
7466 if (!str2)
7467 return -1;
7469 res = g_utf8_collate(str1, str2);
7470 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7473 static gint summary_cmp_by_tags(GtkCMCList *clist, gconstpointer ptr1,
7474 gconstpointer ptr2)
7476 gchar *str1, *str2;
7477 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7478 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7479 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7480 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7481 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7482 gint res;
7483 cm_return_val_if_fail(sv, -1);
7485 if (sv->col_state[sv->col_pos[S_COL_TAGS]].visible) {
7486 str1 = g_strdup(GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_TAGS]])->text);
7487 str2 = g_strdup(GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_TAGS]])->text);
7488 } else {
7489 str1 = procmsg_msginfo_get_tags_str(msginfo1);
7490 str2 = procmsg_msginfo_get_tags_str(msginfo2);
7493 if (!str1) {
7494 res = (str2 != NULL);
7495 g_free(str2);
7496 return res;
7498 if (!str2) {
7499 g_free(str1);
7500 return -1;
7503 res = g_utf8_collate(str1, str2);
7504 g_free(str1);
7505 g_free(str2);
7506 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7509 static gint summary_cmp_by_simplified_subject
7510 (GtkCMCList *clist, gconstpointer ptr1, gconstpointer ptr2)
7512 const FolderItemPrefs *prefs;
7513 const gchar *str1, *str2;
7514 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7515 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7516 const MsgInfo *msginfo1 = r1->data;
7517 const MsgInfo *msginfo2 = r2->data;
7518 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7519 gint res;
7521 cm_return_val_if_fail(sv, -1);
7522 cm_return_val_if_fail(msginfo1 != NULL && msginfo2 != NULL, -1);
7524 if (sv->col_state[sv->col_pos[S_COL_SUBJECT]].visible) {
7525 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_SUBJECT]])->text;
7526 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_SUBJECT]])->text;
7527 } else {
7528 str1 = msginfo1->subject;
7529 str2 = msginfo2->subject;
7532 if (!str1)
7533 return str2 != NULL;
7535 if (!str2)
7536 return -1;
7538 prefs = msginfo1->folder->prefs;
7539 if (!prefs)
7540 prefs = msginfo2->folder->prefs;
7541 if (!prefs)
7542 return -1;
7544 res = subject_compare_for_sort(str1, str2);
7545 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7548 static gint summary_cmp_by_score(GtkCMCList *clist,
7549 gconstpointer ptr1, gconstpointer ptr2)
7551 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7552 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7553 int diff;
7555 /* if score are equal, sort by date */
7557 diff = msginfo1->score - msginfo2->score;
7558 if (diff != 0)
7559 return diff;
7560 else
7561 return summary_cmp_by_date(clist, ptr1, ptr2);
7564 static void summary_ignore_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7566 SummaryView *summaryview = (SummaryView *) data;
7567 MsgInfo *msginfo;
7569 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7570 cm_return_if_fail(msginfo);
7572 summary_msginfo_unset_flags(msginfo, MSG_WATCH_THREAD, 0);
7573 summary_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0, MSG_NEW | MSG_UNREAD, 0);
7575 summary_set_row_marks(summaryview, row);
7576 debug_print("Message %d is marked as ignore thread\n",
7577 msginfo->msgnum);
7580 void summary_ignore_thread(SummaryView *summaryview)
7582 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7583 GList *cur;
7584 gboolean froze = FALSE;
7586 START_LONG_OPERATION(summaryview, FALSE);
7587 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7588 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7589 GTK_CMCTREE_FUNC(summary_ignore_thread_func),
7590 summaryview);
7592 END_LONG_OPERATION(summaryview);
7594 summary_status_show(summaryview);
7597 static void summary_unignore_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7599 SummaryView *summaryview = (SummaryView *) data;
7600 MsgInfo *msginfo;
7602 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7603 cm_return_if_fail(msginfo);
7605 summary_msginfo_unset_flags(msginfo, MSG_IGNORE_THREAD, 0);
7607 summary_set_row_marks(summaryview, row);
7608 debug_print("Message %d is marked as unignore thread\n",
7609 msginfo->msgnum);
7612 void summary_unignore_thread(SummaryView *summaryview)
7614 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7615 GList *cur;
7616 gboolean froze = FALSE;
7618 START_LONG_OPERATION(summaryview, FALSE);
7619 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7620 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7621 GTK_CMCTREE_FUNC(summary_unignore_thread_func),
7622 summaryview);
7624 END_LONG_OPERATION(summaryview);
7626 summary_status_show(summaryview);
7629 static void summary_check_ignore_thread_func
7630 (GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7632 MsgInfo *msginfo;
7633 gint *found_ignore = (gint *) data;
7635 if (*found_ignore) return;
7636 else {
7637 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7638 *found_ignore = msginfo && MSG_IS_IGNORE_THREAD(msginfo->flags);
7642 void summary_toggle_ignore_thread(SummaryView *summaryview)
7644 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7645 GList *cur;
7646 gint found_ignore = 0;
7648 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7649 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7650 GTK_CMCTREE_FUNC(summary_check_ignore_thread_func),
7651 &found_ignore);
7653 if (found_ignore)
7654 summary_unignore_thread(summaryview);
7655 else
7656 summary_ignore_thread(summaryview);
7659 static void summary_watch_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7661 SummaryView *summaryview = (SummaryView *) data;
7662 MsgInfo *msginfo;
7664 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7665 cm_return_if_fail(msginfo);
7667 summary_msginfo_change_flags(msginfo, MSG_WATCH_THREAD, 0, MSG_IGNORE_THREAD, 0);
7669 summary_set_row_marks(summaryview, row);
7670 debug_print("Message %d is marked as watch thread\n",
7671 msginfo->msgnum);
7674 void summary_watch_thread(SummaryView *summaryview)
7676 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7677 GList *cur;
7678 gboolean froze = FALSE;
7680 START_LONG_OPERATION(summaryview, FALSE);
7681 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7682 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7683 GTK_CMCTREE_FUNC(summary_watch_thread_func),
7684 summaryview);
7686 END_LONG_OPERATION(summaryview);
7688 summary_status_show(summaryview);
7691 static void summary_unwatch_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7693 SummaryView *summaryview = (SummaryView *) data;
7694 MsgInfo *msginfo;
7696 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7697 cm_return_if_fail(msginfo);
7699 summary_msginfo_unset_flags(msginfo, MSG_WATCH_THREAD, 0);
7701 summary_set_row_marks(summaryview, row);
7702 debug_print("Message %d is marked as unwatch thread\n",
7703 msginfo->msgnum);
7706 void summary_unwatch_thread(SummaryView *summaryview)
7708 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7709 GList *cur;
7710 gboolean froze = FALSE;
7712 START_LONG_OPERATION(summaryview, FALSE);
7713 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7714 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7715 GTK_CMCTREE_FUNC(summary_unwatch_thread_func),
7716 summaryview);
7718 END_LONG_OPERATION(summaryview);
7720 summary_status_show(summaryview);
7723 static void summary_check_watch_thread_func
7724 (GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7726 MsgInfo *msginfo;
7727 gint *found_watch = (gint *) data;
7729 if (*found_watch) return;
7730 else {
7731 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7732 *found_watch = msginfo && MSG_IS_WATCH_THREAD(msginfo->flags);
7736 void summary_toggle_watch_thread(SummaryView *summaryview)
7738 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7739 GList *cur;
7740 gint found_watch = 0;
7742 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7743 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7744 GTK_CMCTREE_FUNC(summary_check_watch_thread_func),
7745 &found_watch);
7747 if (found_watch)
7748 summary_unwatch_thread(summaryview);
7749 else
7750 summary_watch_thread(summaryview);
7753 void summary_toggle_show_read_messages(SummaryView *summaryview)
7755 FolderItemUpdateData source;
7756 if (summaryview->folder_item->hide_read_msgs)
7757 summaryview->folder_item->hide_read_msgs = 0;
7758 else
7759 summaryview->folder_item->hide_read_msgs = 1;
7761 source.item = summaryview->folder_item;
7762 source.update_flags = F_ITEM_UPDATE_NAME;
7763 source.msg = NULL;
7764 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
7765 summary_show(summaryview, summaryview->folder_item);
7768 void summary_toggle_show_del_messages(SummaryView *summaryview)
7770 FolderItemUpdateData source;
7771 if (summaryview->folder_item->hide_del_msgs)
7772 summaryview->folder_item->hide_del_msgs = 0;
7773 else
7774 summaryview->folder_item->hide_del_msgs = 1;
7776 source.item = summaryview->folder_item;
7777 source.update_flags = F_ITEM_UPDATE_NAME;
7778 source.msg = NULL;
7779 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
7780 summary_show(summaryview, summaryview->folder_item);
7783 void summary_toggle_show_read_threads(SummaryView *summaryview)
7785 FolderItemUpdateData source;
7786 if (summaryview->folder_item->hide_read_threads)
7787 summaryview->folder_item->hide_read_threads = 0;
7788 else
7789 summaryview->folder_item->hide_read_threads = 1;
7791 source.item = summaryview->folder_item;
7792 source.update_flags = F_ITEM_UPDATE_NAME;
7793 source.msg = NULL;
7794 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
7795 summary_show(summaryview, summaryview->folder_item);
7798 static void summary_set_hide_menu (SummaryView *summaryview,
7799 const gchar *menu_item,
7800 guint action)
7802 GtkWidget *widget;
7804 widget = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, menu_item);
7805 cm_return_if_fail(widget != NULL);
7807 g_object_set_data(G_OBJECT(widget), "dont_toggle",
7808 GINT_TO_POINTER(1));
7809 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), action);
7810 g_object_set_data(G_OBJECT(widget), "dont_toggle",
7811 GINT_TO_POINTER(0));
7814 void summary_reflect_prefs_pixmap_theme(SummaryView *summaryview)
7816 GtkWidget *pixmap;
7818 stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm);
7819 stock_pixbuf_gdk(STOCK_PIXMAP_DELETED, &deletedxpm);
7820 stock_pixbuf_gdk(STOCK_PIXMAP_NEW, &newxpm);
7821 stock_pixbuf_gdk(STOCK_PIXMAP_UNREAD, &unreadxpm);
7822 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED, &repliedxpm);
7823 stock_pixbuf_gdk(STOCK_PIXMAP_FORWARDED, &forwardedxpm);
7824 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED_AND_FORWARDED, &repliedandforwardedxpm);
7825 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP, &clipxpm);
7826 stock_pixbuf_gdk(STOCK_PIXMAP_LOCKED, &lockedxpm);
7827 stock_pixbuf_gdk(STOCK_PIXMAP_IGNORETHREAD, &ignorethreadxpm);
7828 stock_pixbuf_gdk(STOCK_PIXMAP_WATCHTHREAD, &watchthreadxpm);
7829 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_KEY, &clipkeyxpm);
7830 stock_pixbuf_gdk(STOCK_PIXMAP_KEY, &keyxpm);
7831 stock_pixbuf_gdk(STOCK_PIXMAP_KEY_SIGN, &keysignxpm);
7832 stock_pixbuf_gdk(STOCK_PIXMAP_GPG_SIGNED, &gpgsignedxpm);
7833 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_GPG_SIGNED, &clipgpgsignedxpm);
7834 stock_pixbuf_gdk(STOCK_PIXMAP_SPAM, &spamxpm);
7835 stock_pixbuf_gdk(STOCK_PIXMAP_MOVED, &movedxpm);
7836 stock_pixbuf_gdk(STOCK_PIXMAP_COPIED, &copiedxpm);
7838 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
7840 pixmap = stock_pixmap_widget(STOCK_PIXMAP_QUICKSEARCH);
7841 gtk_container_remove (GTK_CONTAINER(summaryview->toggle_search),
7842 summaryview->quick_search_pixmap);
7843 gtk_container_add(GTK_CONTAINER(summaryview->toggle_search), pixmap);
7844 gtk_widget_show(pixmap);
7845 summaryview->quick_search_pixmap = pixmap;
7847 #ifdef GENERIC_UMPC
7848 pixmap = stock_pixmap_widget(STOCK_PIXMAP_SELECTION);
7849 gtk_container_remove (GTK_CONTAINER(summaryview->multiple_sel_togbtn),
7850 summaryview->multiple_sel_image);
7851 gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
7852 gtk_widget_show(pixmap);
7853 summaryview->multiple_sel_togbtn = pixmap;
7854 #endif
7856 folderview_unselect(summaryview->folderview);
7857 folderview_select(summaryview->folderview, summaryview->folder_item);
7858 summary_set_column_titles(summaryview);
7861 void summary_reflect_prefs_custom_colors(SummaryView *summaryview)
7863 GtkMenuShell *menu;
7864 GList *children, *cur;
7866 /* re-create colorlabel submenu */
7867 menu = GTK_MENU_SHELL(summaryview->colorlabel_menu);
7868 cm_return_if_fail(menu != NULL);
7870 /* clear items. get item pointers. */
7871 children = gtk_container_get_children(GTK_CONTAINER(menu));
7872 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
7873 g_signal_handlers_disconnect_matched
7874 (gtk_ui_manager_get_accel_group(summaryview->mainwin->ui_manager),
7875 G_SIGNAL_MATCH_DATA|G_SIGNAL_MATCH_FUNC,
7876 0, 0, NULL, mainwin_accel_changed_cb, cur->data);
7877 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
7879 g_list_free(children);
7880 summary_colorlabel_menu_create(summaryview, TRUE);
7884 * Harvest addresses for selected messages in summary view.
7886 void summary_harvest_address(SummaryView *summaryview)
7888 GtkCMCTree *ctree = GTK_CMCTREE( summaryview->ctree );
7889 GList *cur;
7890 GList *msgList;
7891 MsgInfo *msginfo;
7893 msgList = NULL;
7894 for( cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next ) {
7895 msginfo = gtk_cmctree_node_get_row_data( ctree, GTK_CMCTREE_NODE(cur->data) );
7896 if (!msginfo)
7897 continue;
7898 msgList = g_list_append( msgList, GUINT_TO_POINTER( msginfo->msgnum ) );
7901 addressbook_harvest( summaryview->folder_item, TRUE, msgList );
7903 g_list_free( msgList );
7906 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
7908 int err;
7909 gchar buf[BUFFSIZE];
7910 regex_t *preg = NULL;
7912 preg = g_new0(regex_t, 1);
7914 err = string_match_precompile(simplify_subject_regexp,
7915 preg, REG_EXTENDED);
7916 if (err) {
7917 regerror(err, preg, buf, BUFFSIZE);
7918 alertpanel_error(_("Regular expression (regexp) error:\n%s"), buf);
7919 g_free(preg);
7920 preg = NULL;
7923 return preg;
7925 void summary_set_prefs_from_folderitem(SummaryView *summaryview, FolderItem *item)
7927 FolderSortKey sort_key;
7928 FolderSortType sort_type;
7929 cm_return_if_fail(summaryview != NULL);
7930 cm_return_if_fail(item != NULL);
7932 /* Subject simplification */
7933 if(summaryview->simplify_subject_preg) {
7934 regfree(summaryview->simplify_subject_preg);
7935 g_free(summaryview->simplify_subject_preg);
7936 summaryview->simplify_subject_preg = NULL;
7938 if(item->prefs && item->prefs->simplify_subject_regexp &&
7939 item->prefs->simplify_subject_regexp[0] && item->prefs->enable_simplify_subject)
7940 summaryview->simplify_subject_preg = summary_compile_simplify_regexp(item->prefs->simplify_subject_regexp);
7942 /* Sorting */
7943 sort_key = item->sort_key;
7944 sort_type = item->sort_type;
7946 folder_get_sort_type(item->folder, &sort_key, &sort_type);
7948 summaryview->sort_key = sort_key;
7949 summaryview->sort_type = sort_type;
7951 /* Threading */
7952 summaryview->threaded = item->threaded;
7953 summaryview->thread_collapsed = item->thread_collapsed;
7955 /* Scoring */
7958 void summary_save_prefs_to_folderitem(SummaryView *summaryview, FolderItem *item)
7960 /* Sorting */
7961 item->sort_key = summaryview->sort_key;
7962 item->sort_type = summaryview->sort_type;
7964 /* Threading */
7965 item->threaded = summaryview->threaded;
7966 item->thread_collapsed = summaryview->thread_collapsed;
7969 static gboolean summary_update_msg(gpointer source, gpointer data)
7971 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
7972 SummaryView *summaryview = (SummaryView *)data;
7973 GtkCMCTreeNode *node;
7975 cm_return_val_if_fail(msginfo_update != NULL, TRUE);
7976 cm_return_val_if_fail(summaryview != NULL, FALSE);
7978 if (msginfo_update->msginfo->folder != summaryview->folder_item)
7979 return FALSE;
7981 if (msginfo_update->flags & MSGINFO_UPDATE_FLAGS) {
7982 node = gtk_cmctree_find_by_row_data(
7983 GTK_CMCTREE(summaryview->ctree), NULL,
7984 msginfo_update->msginfo);
7986 if (node)
7987 summary_set_row_marks(summaryview, node);
7990 return FALSE;
7993 void summary_update_unread(SummaryView *summaryview, FolderItem *removed_item)
7995 guint new, unread, unreadmarked, marked, total;
7996 guint replied, forwarded, locked, ignored, watched;
7997 static gboolean tips_initialized = FALSE;
7999 if (prefs_common.layout_mode != SMALL_LAYOUT) {
8000 if (tips_initialized) {
8001 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
8002 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8003 NULL);
8004 tips_initialized = FALSE;
8006 return;
8008 folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
8009 &replied, &forwarded, &locked, &ignored,
8010 &watched);
8011 if (removed_item) {
8012 total -= removed_item->total_msgs;
8013 new -= removed_item->new_msgs;
8014 unread -= removed_item->unread_msgs;
8017 if (new > 0 || unread > 0) {
8018 tips_initialized = TRUE;
8019 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN_HRM);
8020 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8021 _("Go back to the folder list (You have unread messages)"));
8022 } else {
8023 tips_initialized = TRUE;
8024 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
8025 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8026 _("Go back to the folder list"));
8030 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data)
8032 FolderItemUpdateData *hookdata = (FolderItemUpdateData *)source;
8033 SummaryView *summaryview = (SummaryView *)data;
8035 cm_return_val_if_fail(hookdata != NULL, FALSE);
8036 cm_return_val_if_fail(hookdata->item != NULL, FALSE);
8037 cm_return_val_if_fail(summaryview != NULL, FALSE);
8039 if (hookdata->update_flags & F_ITEM_UPDATE_NAME) {
8040 gchar *name = folder_item_get_name(hookdata->item);
8041 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
8042 g_free(name);
8044 summary_update_unread(summaryview, NULL);
8046 return FALSE;
8049 static gboolean summary_update_folder_hook(gpointer source, gpointer data)
8051 FolderUpdateData *hookdata;
8052 SummaryView *summaryview = (SummaryView *)data;
8053 hookdata = source;
8054 if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM) {
8055 summary_update_unread(summaryview, hookdata->item);
8056 } else
8057 summary_update_unread(summaryview, NULL);
8059 return FALSE;
8063 *\brief change summaryview to display your answer(s) to a message
8065 *\param summaryview The SummaryView ;)
8066 *\param msginfo The message for which answers are searched
8069 static void summary_find_answers (SummaryView *summaryview, MsgInfo *msg)
8071 FolderItem *sent_folder = NULL;
8072 PrefsAccount *account = NULL;
8073 GtkCMCTreeNode *node = NULL;
8074 char *buf = NULL;
8075 if (msg == NULL || msg->msgid == NULL)
8076 return;
8078 account = account_get_reply_account(msg, prefs_common.reply_account_autosel);
8079 if (account == NULL)
8080 return;
8081 sent_folder = account_get_special_folder
8082 (account, F_OUTBOX);
8084 buf = g_strdup_printf("inreplyto matchcase \"%s\"", msg->msgid);
8086 if (sent_folder != summaryview->folder_item) {
8087 folderview_select(summaryview->mainwin->folderview, sent_folder);
8090 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(summaryview->toggle_search), TRUE);
8092 quicksearch_set(summaryview->quicksearch, ADVANCED_SEARCH_EXTENDED, buf);
8093 g_free(buf);
8095 node = gtk_cmctree_node_nth(GTK_CMCTREE(summaryview->ctree), 0);
8096 if (node)
8097 summary_select_node(summaryview, node, 1);
8100 gint summaryview_export_mbox_list(SummaryView *summaryview)
8101 /* return values: -2 skipped, -1 error, 0 OK */
8103 GSList *list = summary_get_selected_msg_list(summaryview);
8104 gchar *mbox = filesel_select_file_save(_("Export to mbox file"), NULL);
8105 gint ret;
8107 if (mbox == NULL)
8108 return -2;
8109 if (list == NULL)
8110 return -1;
8112 ret = export_list_to_mbox(list, mbox);
8114 g_slist_free(list);
8115 g_free(mbox);
8117 return ret;
8120 void summaryview_lock(SummaryView *summaryview, FolderItem *item)
8122 if (!summaryview || !summaryview->folder_item || !item) {
8123 return;
8126 if (summaryview->folder_item->folder == item->folder) {
8127 gtk_widget_set_sensitive(summaryview->ctree, FALSE);
8130 void summaryview_unlock(SummaryView *summaryview, FolderItem *item)
8132 gtk_widget_set_sensitive(summaryview->ctree, TRUE);