Remove wrong initialization from max_message_size
[claws.git] / src / summaryview.c
blob0eab5dfd446228c143ed4cba0c5ca8b2ad749616
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2023 the Claws Mail team and Hiroyuki Yamamoto
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 "config.h"
20 #include "defs.h"
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtk.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
32 #include "main.h"
33 #include "menu.h"
34 #include "mbox.h"
35 #include "mainwindow.h"
36 #include "folderview.h"
37 #include "summaryview.h"
38 #include "messageview.h"
39 #include "mimeview.h"
40 #include "foldersel.h"
41 #include "procmsg.h"
42 #include "procheader.h"
43 #include "sourcewindow.h"
44 #include "prefs_common.h"
45 #include "prefs_summary_column.h"
46 #include "prefs_summary_open.h"
47 #include "prefs_filtering.h"
48 #include "account.h"
49 #include "compose.h"
50 #include "file-utils.h"
51 #include "utils.h"
52 #include "gtkutils.h"
53 #include "stock_pixmap.h"
54 #include "filesel.h"
55 #include "alertpanel.h"
56 #include "inputdialog.h"
57 #include "statusbar.h"
58 #include "folder.h"
59 #include "colorlabel.h"
60 #include "inc.h"
61 #include "imap.h"
62 #ifndef USE_ALT_ADDRBOOK
63 #include "addressbook.h"
64 #else
65 #include "addressbook-dbus.h"
66 #include "addressadd.h"
67 #endif
68 #include "addr_compl.h"
69 #include "folder_item_prefs.h"
70 #include "filtering.h"
71 #include "string_match.h"
72 #include "toolbar.h"
73 #include "news.h"
74 #include "hooks.h"
75 #include "description_window.h"
76 #include "folderutils.h"
77 #include "quicksearch.h"
78 #include "partial_download.h"
79 #include "tags.h"
80 #include "timing.h"
81 #include "log.h"
82 #include "edittags.h"
83 #include "manual.h"
84 #include "manage_window.h"
85 #include "avatars.h"
87 #define SUMMARY_COL_MARK_WIDTH 10
88 #define SUMMARY_COL_STATUS_WIDTH 13
89 #define SUMMARY_COL_LOCKED_WIDTH 13
90 #define SUMMARY_COL_MIME_WIDTH 11
92 static int normal_row_height = -1;
93 static GtkStyle *bold_style;
95 static GdkPixbuf *markxpm;
96 static GdkPixbuf *deletedxpm;
97 static GdkPixbuf *movedxpm;
98 static GdkPixbuf *copiedxpm;
100 static GdkPixbuf *newxpm;
101 static GdkPixbuf *unreadxpm;
102 static GdkPixbuf *repliedxpm;
103 static GdkPixbuf *forwardedxpm;
104 static GdkPixbuf *repliedandforwardedxpm;
105 static GdkPixbuf *ignorethreadxpm;
106 static GdkPixbuf *watchthreadxpm;
107 static GdkPixbuf *lockedxpm;
108 static GdkPixbuf *spamxpm;
110 static GdkPixbuf *clipxpm;
111 static GdkPixbuf *keyxpm;
112 static GdkPixbuf *clipkeyxpm;
113 static GdkPixbuf *keysignxpm;
114 static GdkPixbuf *gpgsignedxpm;
115 static GdkPixbuf *clipgpgsignedxpm;
117 static void summary_free_msginfo_func (GtkCMCTree *ctree,
118 GtkCMCTreeNode *node,
119 gpointer data);
120 static void summary_set_marks_func (GtkCMCTree *ctree,
121 GtkCMCTreeNode *node,
122 gpointer data);
124 void summary_set_menu_sensitive (SummaryView *summaryview);
125 guint summary_get_msgnum (SummaryView *summaryview,
126 GtkCMCTreeNode *node);
129 static void summary_set_hide_menu (SummaryView *summaryview,
130 const gchar *menu_item,
131 guint action);
133 static GtkCMCTreeNode *summary_find_prev_msg
134 (SummaryView *summaryview,
135 GtkCMCTreeNode *current_node,
136 gboolean start_from_prev);
137 static GtkCMCTreeNode *summary_find_next_msg
138 (SummaryView *summaryview,
139 GtkCMCTreeNode *current_node,
140 gboolean start_from_next);
142 static GtkCMCTreeNode *summary_find_prev_flagged_msg
143 (SummaryView *summaryview,
144 GtkCMCTreeNode *current_node,
145 MsgPermFlags flags,
146 gboolean start_from_prev);
147 static GtkCMCTreeNode *summary_find_next_flagged_msg
148 (SummaryView *summaryview,
149 GtkCMCTreeNode *current_node,
150 MsgPermFlags flags,
151 gboolean start_from_next);
153 static GtkCMCTreeNode *summary_find_msg_by_msgnum
154 (SummaryView *summaryview,
155 guint msgnum);
157 static void summary_update_status (SummaryView *summaryview);
159 /* display functions */
160 static void summary_status_show (SummaryView *summaryview);
161 static void summary_set_column_titles (SummaryView *summaryview);
162 static void summary_set_ctree_from_list (SummaryView *summaryview,
163 GSList *mlist,
164 guint selected_msgnum);
165 static inline void summary_set_header (SummaryView *summaryview,
166 gchar *text[],
167 MsgInfo *msginfo);
168 static void summary_display_msg (SummaryView *summaryview,
169 GtkCMCTreeNode *row);
170 static void summary_display_msg_full (SummaryView *summaryview,
171 GtkCMCTreeNode *row,
172 gboolean new_window,
173 gboolean all_headers);
174 static void summary_set_row_marks (SummaryView *summaryview,
175 GtkCMCTreeNode *row);
177 static gboolean summary_set_row_tag (SummaryView *summaryview,
178 GtkCMCTreeNode *row,
179 gboolean refresh,
180 gboolean set,
181 gint id);
182 /* message handling */
183 static void summary_mark_row (SummaryView *summaryview,
184 GtkCMCTreeNode *row);
185 static void summary_lock_row (SummaryView *summaryview,
186 GtkCMCTreeNode *row);
187 static void summary_unlock_row (SummaryView *summaryview,
188 GtkCMCTreeNode *row);
189 static void summary_mark_row_as_read (SummaryView *summaryview,
190 GtkCMCTreeNode *row);
191 static void summary_mark_row_as_unread (SummaryView *summaryview,
192 GtkCMCTreeNode *row);
193 static gboolean summary_mark_all_read_confirm(gboolean ask_if_needed);
194 static gboolean summary_mark_all_unread_confirm(gboolean ask_if_needed);
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,
231 PrefsAccount *ac_prefs);
233 static void summary_colorlabel_menu_item_activate_cb
234 (GtkWidget *widget,
235 gpointer data);
236 static void summary_colorlabel_menu_item_activate_item_cb
237 (GtkMenuItem *label_menu_item,
238 gpointer data);
239 static void summary_colorlabel_menu_create(SummaryView *summaryview,
240 gboolean refresh);
241 static void summary_tags_menu_item_activate_cb
242 (GtkWidget *widget,
243 gpointer data);
244 static void summary_tags_menu_item_activate_item_cb
245 (GtkMenuItem *label_menu_item,
246 gpointer data);
247 static void summary_tags_menu_create(SummaryView *summaryview,
248 gboolean refresh);
250 static GtkWidget *summary_ctree_create (SummaryView *summaryview);
252 /* callback functions */
253 static gint summary_toggle_pressed (GtkWidget *eventbox,
254 GdkEventButton *event,
255 SummaryView *summaryview);
256 #ifdef GENERIC_UMPC
257 static void summary_toggle_multiple_pressed
258 (GtkWidget *widget,
259 SummaryView *summaryview);
260 #endif
261 static gint summary_folder_eventbox_pressed
262 (GtkWidget *eventbox,
263 GdkEventButton *event,
264 SummaryView *summaryview);
265 static gboolean summary_button_pressed (GtkWidget *ctree,
266 GdkEventButton *event,
267 SummaryView *summaryview);
268 static gboolean summary_button_released (GtkWidget *ctree,
269 GdkEventButton *event,
270 SummaryView *summaryview);
271 static gboolean summary_key_pressed (GtkWidget *ctree,
272 GdkEventKey *event,
273 SummaryView *summaryview);
274 static void summary_tree_expanded (GtkCMCTree *ctree,
275 GtkCMCTreeNode *node,
276 SummaryView *summaryview);
277 static void summary_tree_collapsed (GtkCMCTree *ctree,
278 GtkCMCTreeNode *node,
279 SummaryView *summaryview);
280 static void summary_selected (GtkCMCTree *ctree,
281 GtkCMCTreeNode *row,
282 gint column,
283 SummaryView *summaryview);
284 static void summary_unselected (GtkCMCTree *ctree,
285 GtkCMCTreeNode *row,
286 gint column,
287 SummaryView *summaryview);
288 static void summary_col_resized (GtkCMCList *clist,
289 gint column,
290 gint width,
291 SummaryView *summaryview);
292 static void summary_mark_clicked (GtkWidget *button,
293 SummaryView *summaryview);
294 static void summary_status_clicked (GtkWidget *button,
295 SummaryView *summaryview);
296 static void summary_mime_clicked (GtkWidget *button,
297 SummaryView *summaryview);
298 static void summary_num_clicked (GtkWidget *button,
299 SummaryView *summaryview);
300 static void summary_score_clicked (GtkWidget *button,
301 SummaryView *summaryview);
302 static void summary_size_clicked (GtkWidget *button,
303 SummaryView *summaryview);
304 static void summary_date_clicked (GtkWidget *button,
305 SummaryView *summaryview);
306 static void summary_from_clicked (GtkWidget *button,
307 SummaryView *summaryview);
308 static void summary_to_clicked (GtkWidget *button,
309 SummaryView *summaryview);
310 static void summary_subject_clicked (GtkWidget *button,
311 SummaryView *summaryview);
312 static void summary_score_clicked (GtkWidget *button,
313 SummaryView *summaryview);
314 static void summary_locked_clicked (GtkWidget *button,
315 SummaryView *summaryview);
316 static void summary_tags_clicked (GtkWidget *button,
317 SummaryView *summaryview);
319 static void summary_start_drag (GtkWidget *widget,
320 int button,
321 GdkEvent *event,
322 SummaryView *summaryview);
323 static void summary_drag_data_get (GtkWidget *widget,
324 GdkDragContext *drag_context,
325 GtkSelectionData *selection_data,
326 guint info,
327 guint time,
328 SummaryView *summaryview);
329 static void summary_drag_data_received(GtkWidget *widget,
330 GdkDragContext *drag_context,
331 gint x,
332 gint y,
333 GtkSelectionData *data,
334 guint info,
335 guint time,
336 SummaryView *summaryview);
337 static gboolean summary_drag_motion_cb(GtkWidget *widget,
338 GdkDragContext *context,
339 gint x,
340 gint y,
341 guint time,
342 SummaryView *summaryview);
343 static void summary_drag_end(GtkWidget *widget,
344 GdkDragContext *drag_context,
345 SummaryView *summaryview);
347 /* custom compare functions for sorting */
348 static gint summary_cmp_by_mark (GtkCMCList *clist,
349 gconstpointer ptr1,
350 gconstpointer ptr2);
351 static gint summary_cmp_by_status (GtkCMCList *clist,
352 gconstpointer ptr1,
353 gconstpointer ptr2);
354 static gint summary_cmp_by_mime (GtkCMCList *clist,
355 gconstpointer ptr1,
356 gconstpointer ptr2);
357 static gint summary_cmp_by_num (GtkCMCList *clist,
358 gconstpointer ptr1,
359 gconstpointer ptr2);
360 static gint summary_cmp_by_size (GtkCMCList *clist,
361 gconstpointer ptr1,
362 gconstpointer ptr2);
363 static gint summary_cmp_by_date (GtkCMCList *clist,
364 gconstpointer ptr1,
365 gconstpointer ptr2);
366 static gint summary_cmp_by_thread_date (GtkCMCList *clist,
367 gconstpointer ptr1,
368 gconstpointer ptr2);
369 static gint summary_cmp_by_from (GtkCMCList *clist,
370 gconstpointer ptr1,
371 gconstpointer ptr2);
372 static gint summary_cmp_by_simplified_subject
373 (GtkCMCList *clist,
374 gconstpointer ptr1,
375 gconstpointer ptr2);
376 static gint summary_cmp_by_score (GtkCMCList *clist,
377 gconstpointer ptr1,
378 gconstpointer ptr2);
379 static gint summary_cmp_by_label (GtkCMCList *clist,
380 gconstpointer ptr1,
381 gconstpointer ptr2);
382 static gint summary_cmp_by_to (GtkCMCList *clist,
383 gconstpointer ptr1,
384 gconstpointer ptr2);
385 static gint summary_cmp_by_subject (GtkCMCList *clist,
386 gconstpointer ptr1,
387 gconstpointer ptr2);
388 static gint summary_cmp_by_locked (GtkCMCList *clist,
389 gconstpointer ptr1,
390 gconstpointer ptr2);
391 static gint summary_cmp_by_tags (GtkCMCList *clist,
392 gconstpointer ptr1,
393 gconstpointer ptr2);
395 static void quicksearch_execute_cb (QuickSearch *quicksearch,
396 gpointer data);
398 static void tog_searchbar_cb (GtkWidget *w,
399 gpointer data);
401 static void summary_find_answers (SummaryView *summaryview,
402 MsgInfo *msg);
404 static gboolean summary_update_msg (gpointer source, gpointer data);
405 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data);
406 static gboolean summary_update_folder_hook(gpointer source, gpointer data);
407 static void summary_set_colorlabel_color (GtkCMCTree *ctree,
408 GtkCMCTreeNode *node,
409 guint labelcolor);
410 static void summary_thread_build(SummaryView *summaryview);
412 GtkTargetEntry summary_drag_types[3] =
414 {"text/uri-list", 0, TARGET_MAIL_URI_LIST},
415 {"claws-mail/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY},
416 {"claws-mail/msg-path-list", 0, TARGET_MAIL_CM_PATH_LIST},
419 static void summary_reedit_cb(GtkAction *gaction, gpointer data);
420 static void summary_reply_cb(GtkAction *gaction, gpointer data);
422 /* Only submenus and specifically-handled menu entries here */
423 static GtkActionEntry summary_popup_entries[] =
425 {"SummaryViewPopup", NULL, "SummaryViewPopup", NULL, NULL, NULL },
426 {"SummaryViewPopup/Reedit", NULL, N_("Re-edit"), NULL, NULL, G_CALLBACK(summary_reedit_cb) },
427 {"SummaryViewPopup/Reply", NULL, N_("_Reply"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_REPLY */
428 {"SummaryViewPopup/ReplyTo", NULL, N_("Repl_y to"), NULL, NULL, NULL },
429 {"SummaryViewPopup/ReplyTo/All", NULL, N_("_All"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_REPLY_TO_ALL */
430 {"SummaryViewPopup/ReplyTo/Sender", NULL, N_("_Sender"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_REPLY_TO_SENDER */
431 {"SummaryViewPopup/ReplyTo/List", NULL, N_("Mailing _list"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_REPLY_TO_LIST */
433 {"SummaryViewPopup/Forward", NULL, N_("_Forward"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_FORWARD_INLINE */
434 {"SummaryViewPopup/ForwardAtt", NULL, N_("For_ward as attachment"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_FORWARD_AS_ATTACH */
435 {"SummaryViewPopup/Redirect", NULL, N_("Redirec_t"), NULL, NULL, G_CALLBACK(summary_reply_cb) }, /* COMPOSE_REDIRECT */
436 {"SummaryViewPopup/Mark", NULL, NC_("Menu Item", "_Mark"), NULL, NULL, NULL },
437 {"SummaryViewPopup/ColorLabel", NULL, N_("Color la_bel"), NULL, NULL, NULL },
438 {"SummaryViewPopup/Tags", NULL, N_("Ta_gs"), NULL, NULL, NULL },
439 {"SummaryViewPopup/CreateFilterRule", NULL, N_("Create _filter rule"), NULL, NULL, NULL },
440 #ifndef GENERIC_UMPC
441 {"SummaryViewPopup/CreateProcessingRule", NULL, N_("Create processing rule"), NULL, NULL, NULL },
442 #endif
443 {"SummaryViewPopup/View", NULL, N_("_View"), NULL, NULL, NULL },
446 static void summary_header_lock_sorting_cb(GtkAction *gaction, gpointer data);
447 static void summary_header_set_displayed_columns_cb(GtkAction *gaction, gpointer data);
449 static GtkActionEntry summary_header_popup_entries[] =
451 {"SummaryViewHeaderPopup", NULL, "SummaryViewHeaderPopup", NULL, NULL, NULL },
452 {"SummaryViewHeaderPopup/SetDisplayedColumns", NULL, N_("_Set displayed columns"), NULL, NULL, G_CALLBACK(summary_header_set_displayed_columns_cb) }
455 static GtkToggleActionEntry summary_header_popup_toggle_entries[] =
457 {"SummaryViewHeaderPopup/LockColumnHeaders", NULL, N_("_Lock column headers"), NULL, NULL, G_CALLBACK(summary_header_lock_sorting_cb), FALSE }
460 static const gchar *const col_label[N_SUMMARY_COLS] = {
461 "", /* S_COL_MARK */
462 N_("S"), /* S_COL_STATUS */
463 "", /* S_COL_MIME */
464 N_("Subject"), /* S_COL_SUBJECT */
465 N_("From"), /* S_COL_FROM */
466 N_("To"), /* S_COL_TO */
467 N_("Date"), /* S_COL_DATE */
468 N_("Size"), /* S_COL_SIZE */
469 N_("#"), /* S_COL_NUMBER */
470 N_("Score"), /* S_COL_SCORE */
471 "", /* S_COL_LOCKED */
472 N_("Tags"), /* S_COL_TAGS */
475 void summary_freeze(SummaryView *summaryview)
477 if (summaryview)
478 gtk_cmclist_freeze(GTK_CMCLIST(summaryview->ctree));
481 void summary_thaw(SummaryView *summaryview)
483 if (summaryview)
484 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
487 void summary_thaw_with_status(SummaryView *summaryview)
489 if (summaryview) {
490 summary_status_show(summaryview);
491 gtk_cmclist_thaw(GTK_CMCLIST(summaryview->ctree));
495 void summary_grab_focus(SummaryView *summaryview)
497 if (summaryview)
498 gtk_widget_grab_focus(summaryview->ctree);
501 GtkWidget *summary_get_main_widget(SummaryView *summaryview)
503 if (summaryview)
504 return summaryview->ctree;
505 else
506 return NULL;
509 #define START_LONG_OPERATION(summaryview,force_freeze) { \
510 summary_lock(summaryview); \
511 main_window_cursor_wait(summaryview->mainwin); \
512 if (force_freeze || sc_g_list_bigger(GTK_CMCLIST(summaryview->ctree)->selection, 1)) {\
513 froze = TRUE; \
514 summary_freeze(summaryview); \
516 folder_item_update_freeze(); \
517 inc_lock(); \
518 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST, \
519 summaryview->msginfo_update_callback_id); \
521 #define END_LONG_OPERATION(summaryview) { \
522 inc_unlock(); \
523 folder_item_update_thaw(); \
524 if (froze) \
525 summary_thaw(summaryview); \
526 main_window_cursor_normal(summaryview->mainwin); \
527 summary_unlock(summaryview); \
528 summaryview->msginfo_update_callback_id = \
529 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, \
530 summary_update_msg, (gpointer) summaryview); \
533 static void popup_menu_selection_done(GtkMenuShell *shell, gpointer user_data)
535 SummaryView *summaryview = (SummaryView *)user_data;
537 cm_return_if_fail(summaryview != NULL);
539 /* If a message is displayed, place cursor back on the message. */
540 if (summaryview->displayed != NULL &&
541 summaryview->displayed != summaryview->selected) {
542 gtk_sctree_select(GTK_SCTREE(summaryview->ctree), summaryview->displayed);
546 SummaryView *summary_create(MainWindow *mainwin)
548 SummaryView *summaryview;
549 GtkWidget *vbox;
550 GtkWidget *scrolledwin;
551 GtkWidget *ctree;
552 GtkWidget *hbox;
553 GtkWidget *hbox_l;
554 GtkWidget *stat_box;
555 GtkWidget *stat_box2;
556 GtkWidget *stat_vbox;
557 GtkWidget *statlabel_folder;
558 GtkWidget *statlabel_select;
559 GtkWidget *statlabel_msgs;
560 GtkWidget *hbox_spc;
561 GtkWidget *toggle_eventbox;
562 #ifdef GENERIC_UMPC
563 GtkWidget *multiple_sel_togbtn;
564 #endif
565 GtkWidget *toggle_arrow;
566 GtkWidget *toggle_search;
567 QuickSearch *quicksearch;
569 debug_print("Creating summary view...\n");
570 summaryview = g_new0(SummaryView, 1);
572 #define SUMMARY_VBOX_SPACING 3
573 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, SUMMARY_VBOX_SPACING);
574 gtk_widget_set_name(GTK_WIDGET(vbox), "summaryview");
576 /* create status label */
577 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
578 gtk_widget_show(hbox);
580 stat_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
581 gtk_widget_show(stat_vbox);
583 stat_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
584 gtk_widget_show(stat_box);
586 stat_box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
587 gtk_widget_show(stat_box2);
589 toggle_search = gtk_toggle_button_new();
590 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_search),
591 prefs_common.show_searchbar);
592 gtk_widget_set_can_focus(toggle_search, FALSE);
593 gtk_widget_show(toggle_search);
595 CLAWS_SET_TIP(toggle_search, _("Toggle quick search bar"));
597 gtk_box_pack_start(GTK_BOX(hbox), toggle_search, FALSE, FALSE, 2);
599 gtk_box_pack_start(GTK_BOX(hbox), stat_vbox, TRUE, TRUE, 0);
600 gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box, TRUE, TRUE, 0);
601 gtk_box_pack_start(GTK_BOX(stat_vbox), stat_box2, TRUE, TRUE, 0);
603 hbox_l = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
604 gtk_widget_show(hbox_l);
605 gtk_box_pack_start(GTK_BOX(stat_box), hbox_l, TRUE, TRUE, 0);
607 statlabel_folder = gtk_label_new("");
608 gtk_widget_show(statlabel_folder);
609 gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_folder, FALSE, FALSE, 2);
610 statlabel_select = gtk_label_new("");
611 gtk_widget_show(statlabel_select);
612 gtk_box_pack_start(GTK_BOX(hbox_l), statlabel_select, FALSE, FALSE, 12);
614 /* toggle view button */
615 toggle_eventbox = gtk_event_box_new();
616 gtk_widget_show(toggle_eventbox);
618 gtk_box_pack_end(GTK_BOX(hbox), toggle_eventbox, FALSE, FALSE, 4);
620 toggle_arrow = gtk_image_new_from_icon_name("pan-down-symbolic", GTK_ICON_SIZE_MENU);
621 gtk_widget_show(toggle_arrow);
622 gtk_container_add(GTK_CONTAINER(toggle_eventbox), toggle_arrow);
623 g_signal_connect(G_OBJECT(toggle_eventbox), "button_press_event",
624 G_CALLBACK(summary_toggle_pressed),
625 summaryview);
627 #ifdef GENERIC_UMPC
628 multiple_sel_togbtn = gtk_toggle_button_new();
629 gtk_widget_show(multiple_sel_togbtn);
630 gtk_box_pack_end(GTK_BOX(hbox), multiple_sel_togbtn, FALSE, FALSE, 4);
631 CLAWS_SET_TIP(multiple_sel_togbtn,
632 _("Toggle multiple selection"));
633 g_signal_connect(G_OBJECT(multiple_sel_togbtn), "toggled",
634 G_CALLBACK(summary_toggle_multiple_pressed),
635 summaryview);
636 #endif
638 statlabel_msgs = gtk_label_new("");
639 gtk_widget_show(statlabel_msgs);
640 gtk_box_pack_end(GTK_BOX(stat_box), statlabel_msgs, FALSE, FALSE, 4);
642 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
643 gtk_widget_show(hbox_spc);
644 gtk_box_pack_end(GTK_BOX(hbox), hbox_spc, FALSE, FALSE, 6);
646 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
647 gtk_widget_show(scrolledwin);
648 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
649 GTK_POLICY_AUTOMATIC,
650 GTK_POLICY_AUTOMATIC);
651 summaryview->mainwidget_book = gtk_notebook_new();
652 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
653 gtk_notebook_set_show_border(GTK_NOTEBOOK(summaryview->mainwidget_book), FALSE);
654 #ifndef GENERIC_UMPC
655 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
656 scrolledwin);
657 gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
658 #endif
660 ctree = summary_ctree_create(summaryview);
661 gtk_widget_show(ctree);
663 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
664 GTK_CMCLIST(ctree)->hadjustment);
665 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
666 GTK_CMCLIST(ctree)->vadjustment);
667 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
669 /* status label */
670 gtk_widget_show_all(stat_vbox);
671 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
673 /* quick search */
674 quicksearch = quicksearch_new();
675 gtk_box_pack_start(GTK_BOX(vbox), quicksearch_get_widget(quicksearch), FALSE, FALSE, 0);
677 #ifdef GENERIC_UMPC
678 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
679 scrolledwin);
680 gtk_box_pack_start(GTK_BOX(vbox), summaryview->mainwidget_book, TRUE, TRUE, 0);
681 #endif
682 quicksearch_set_execute_callback(quicksearch, quicksearch_execute_cb, summaryview);
684 g_signal_connect (G_OBJECT(toggle_search), "toggled",
685 G_CALLBACK(tog_searchbar_cb), summaryview);
687 /* create popup menu */
689 gtk_action_group_add_actions(mainwin->action_group,
690 summary_popup_entries,
691 G_N_ELEMENTS(summary_popup_entries),
692 (gpointer)summaryview);
694 gtk_action_group_add_actions(mainwin->action_group,
695 summary_header_popup_entries,
696 G_N_ELEMENTS(summary_header_popup_entries),
697 (gpointer)summaryview);
699 gtk_action_group_add_toggle_actions(mainwin->action_group,
700 summary_header_popup_toggle_entries,
701 G_N_ELEMENTS(summary_header_popup_toggle_entries),
702 (gpointer)summaryview);
704 summaryview->ui_manager = gtk_ui_manager_new();
705 summaryview->action_group = cm_menu_create_action_group_full(summaryview->ui_manager,"Menu", summary_popup_entries,
706 G_N_ELEMENTS(summary_popup_entries), (gpointer)summaryview);
708 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus", "SummaryViewPopup", "SummaryViewPopup", GTK_UI_MANAGER_MENU)
709 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Reedit", "SummaryViewPopup/Reedit", GTK_UI_MANAGER_MENUITEM)
710 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Reply", "SummaryViewPopup/Reply", GTK_UI_MANAGER_MENUITEM)
711 #ifndef GENERIC_UMPC
712 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ReplyTo", "SummaryViewPopup/ReplyTo", GTK_UI_MANAGER_MENU)
713 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
714 #endif
715 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Forward", "SummaryViewPopup/Forward", GTK_UI_MANAGER_MENUITEM)
716 #ifndef GENERIC_UMPC
717 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ForwardAtt", "SummaryViewPopup/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
718 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Redirect", "SummaryViewPopup/Redirect", GTK_UI_MANAGER_MENUITEM)
719 #endif
720 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
721 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Move", "Message/Move", GTK_UI_MANAGER_MENUITEM)
722 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Copy", "Message/Copy", GTK_UI_MANAGER_MENUITEM)
723 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Trash", "Message/Trash", GTK_UI_MANAGER_MENUITEM)
724 #ifndef GENERIC_UMPC
725 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Delete", "Message/Delete", GTK_UI_MANAGER_MENUITEM)
726 #endif
727 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
728 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Mark", "SummaryViewPopup/Mark", GTK_UI_MANAGER_MENU)
729 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "ColorLabel", "SummaryViewPopup/ColorLabel", GTK_UI_MANAGER_MENU)
730 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Tags", "SummaryViewPopup/Tags", GTK_UI_MANAGER_MENU)
732 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
733 #ifndef GENERIC_UMPC
734 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
735 #endif
736 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateFilterRule", "SummaryViewPopup/CreateFilterRule", GTK_UI_MANAGER_MENU)
737 #ifndef GENERIC_UMPC
738 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "CreateProcessingRule", "SummaryViewPopup/CreateProcessingRule", GTK_UI_MANAGER_MENU)
739 #endif
740 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator5", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
741 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "View", "SummaryViewPopup/View", GTK_UI_MANAGER_MENU)
742 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
743 #ifndef GENERIC_UMPC
744 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
745 #endif
746 /* last separator, for plugins */
747 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup", "Separator6", "File/---", GTK_UI_MANAGER_SEPARATOR)
749 /* submenus - replyto */
750 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "All", "SummaryViewPopup/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
751 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "Sender", "SummaryViewPopup/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
752 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/ReplyTo", "MailingList", "SummaryViewPopup/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
754 /* submenus - mark */
755 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Mark", "Message/Mark/Mark", GTK_UI_MANAGER_MENUITEM)
756 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unmark", "Message/Mark/Unmark", GTK_UI_MANAGER_MENUITEM)
757 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator1", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
758 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkRead", "Message/Mark/MarkRead", GTK_UI_MANAGER_MENUITEM)
759 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkUnread", "Message/Mark/MarkUnread", GTK_UI_MANAGER_MENUITEM)
760 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator2", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
761 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllRead", "Message/Mark/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
762 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkAllUnread", "Message/Mark/MarkAllUnread", GTK_UI_MANAGER_MENUITEM)
763 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator3", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
764 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "IgnoreThread", "Message/Mark/IgnoreThread", GTK_UI_MANAGER_MENUITEM)
765 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnignoreThread", "Message/Mark/UnignoreThread", GTK_UI_MANAGER_MENUITEM)
766 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "WatchThread", "Message/Mark/WatchThread", GTK_UI_MANAGER_MENUITEM)
767 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "UnwatchThread", "Message/Mark/UnwatchThread", GTK_UI_MANAGER_MENUITEM)
768 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator4", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
769 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkSpam", "Message/Mark/MarkSpam", GTK_UI_MANAGER_MENUITEM)
770 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "MarkHam", "Message/Mark/MarkHam", GTK_UI_MANAGER_MENUITEM)
771 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Separator5", "Message/Mark/---", GTK_UI_MANAGER_SEPARATOR)
772 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Lock", "Message/Mark/Lock", GTK_UI_MANAGER_MENUITEM)
773 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/Mark", "Unlock", "Message/Mark/Unlock", GTK_UI_MANAGER_MENUITEM)
775 /* submenus - colorlabel and tags are dynamic */
776 /* submenus - createfilterrule */
777 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
778 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
779 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
780 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
781 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateFilterRule", "BySender", "Tools/CreateFilterRule/BySender", GTK_UI_MANAGER_MENUITEM)
783 #ifndef GENERIC_UMPC
784 /* submenus - createprocessingrule */
785 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
786 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
787 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
788 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
789 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/CreateProcessingRule", "BySender", "Tools/CreateProcessingRule/BySender", GTK_UI_MANAGER_MENUITEM)
790 #endif
792 /* submenus - view */
793 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "OpenNewWindow", "View/OpenNewWindow", GTK_UI_MANAGER_MENUITEM)
794 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
795 #ifndef GENERIC_UMPC
796 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewPopup/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
797 #endif
799 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus", "SummaryViewHeaderPopup", "SummaryViewHeaderPopup", GTK_UI_MANAGER_MENU)
800 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewHeaderPopup", "LockColumnHeaders", "SummaryViewHeaderPopup/LockColumnHeaders", GTK_UI_MANAGER_MENUITEM)
801 MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menus/SummaryViewHeaderPopup", "SetDisplayedColumns", "SummaryViewHeaderPopup/SetDisplayedColumns", GTK_UI_MANAGER_MENUITEM)
803 summaryview->popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
804 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menus/SummaryViewPopup")) );
805 summaryview->headerpopupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
806 gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menus/SummaryViewHeaderPopup")) );
808 summaryview->vbox = vbox;
809 summaryview->scrolledwin = scrolledwin;
810 summaryview->ctree = ctree;
811 summaryview->hbox = hbox;
812 summaryview->hbox_l = hbox_l;
813 summaryview->hbox_spc = hbox_spc;
814 summaryview->stat_box = stat_box;
815 summaryview->stat_box2 = stat_box2;
816 summaryview->statlabel_folder = statlabel_folder;
817 summaryview->statlabel_select = statlabel_select;
818 summaryview->statlabel_msgs = statlabel_msgs;
819 summaryview->toggle_eventbox = toggle_eventbox;
820 summaryview->toggle_arrow = toggle_arrow;
821 #ifdef GENERIC_UMPC
822 summaryview->multiple_sel_togbtn = multiple_sel_togbtn;
823 #endif
824 summaryview->toggle_search = toggle_search;
825 summaryview->lock_count = 0;
826 summaryview->msginfo_update_callback_id =
827 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, summary_update_msg, (gpointer) summaryview);
828 summaryview->folder_item_update_callback_id =
829 hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST,
830 summary_update_folder_item_hook,
831 (gpointer) summaryview);
832 summaryview->folder_update_callback_id =
833 hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
834 summary_update_folder_hook,
835 (gpointer) summaryview);
837 summaryview->target_list = gtk_target_list_new(summary_drag_types, 3);
839 summaryview->quicksearch = quicksearch;
841 /* CLAWS: need this to get the SummaryView * from
842 * the CList */
843 g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview);
845 gtk_widget_show_all(vbox);
847 gtk_widget_show(vbox);
849 if (prefs_common.show_searchbar)
850 quicksearch_show(quicksearch);
851 else
852 quicksearch_hide(quicksearch);
854 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
855 prefs_common.layout_mode == SMALL_LAYOUT)
856 gtk_widget_hide(summaryview->toggle_eventbox);
858 return summaryview;
861 void summary_relayout(SummaryView *summaryview)
863 gtk_widget_realize(summaryview->stat_box);
865 g_object_ref(summaryview->hbox_l);
866 g_object_ref(summaryview->statlabel_msgs);
868 gtk_container_remove(GTK_CONTAINER(
869 gtk_widget_get_parent(summaryview->hbox_l)), summaryview->hbox_l);
870 gtk_container_remove(GTK_CONTAINER(
871 gtk_widget_get_parent(summaryview->statlabel_msgs)), summaryview->statlabel_msgs);
873 switch (prefs_common.layout_mode) {
874 case NORMAL_LAYOUT:
875 case WIDE_LAYOUT:
876 case WIDE_MSGLIST_LAYOUT:
877 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
878 gtk_box_pack_end(GTK_BOX(summaryview->stat_box), summaryview->statlabel_msgs, FALSE, FALSE, 4);
879 gtk_widget_show_all(summaryview->stat_box);
880 gtk_widget_show_all(summaryview->stat_box2);
881 if (prefs_common.layout_mode == WIDE_MSGLIST_LAYOUT ||
882 prefs_common.layout_mode == SMALL_LAYOUT)
883 gtk_widget_hide(summaryview->toggle_eventbox);
884 else
885 gtk_widget_show(summaryview->toggle_eventbox);
886 break;
887 case VERTICAL_LAYOUT:
888 case SMALL_LAYOUT:
889 gtk_box_pack_start(GTK_BOX(summaryview->stat_box), summaryview->hbox_l, TRUE, TRUE, 0);
890 gtk_box_pack_start(GTK_BOX(summaryview->stat_box2), summaryview->statlabel_msgs, FALSE, FALSE, 4);
891 gtk_widget_show_all(summaryview->stat_box);
892 gtk_widget_show_all(summaryview->stat_box2);
893 if (prefs_common.layout_mode == SMALL_LAYOUT) {
894 gtk_widget_hide(summaryview->toggle_eventbox);
895 gtk_widget_hide(summaryview->statlabel_msgs);
896 } else {
897 gtk_widget_show(summaryview->toggle_eventbox);
898 gtk_widget_show(summaryview->statlabel_msgs);
901 break;
903 summary_set_column_order(summaryview);
905 g_object_unref(summaryview->hbox_l);
906 g_object_unref(summaryview->statlabel_msgs);
907 quicksearch_relayout(summaryview->quicksearch);
908 if (prefs_common.show_searchbar)
909 quicksearch_show(summaryview->quicksearch);
910 else
911 quicksearch_hide(summaryview->quicksearch);
914 static void summary_set_fonts(SummaryView *summaryview)
916 PangoFontDescription *font_desc;
917 gint size;
919 font_desc = pango_font_description_from_string(NORMAL_FONT);
920 if (font_desc) {
921 gtk_widget_override_font(summaryview->ctree, font_desc);
922 pango_font_description_free(font_desc);
925 if (!bold_style) {
926 bold_style = gtk_style_copy
927 (gtk_widget_get_style(summaryview->ctree));
929 if (prefs_common.derive_from_normal_font || !BOLD_FONT) {
930 font_desc = pango_font_description_from_string(NORMAL_FONT);
931 if (font_desc) {
932 pango_font_description_free(bold_style->font_desc);
933 bold_style->font_desc = font_desc;
935 pango_font_description_set_weight
936 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
937 } else {
938 font_desc = pango_font_description_from_string(BOLD_FONT);
939 if (font_desc) {
940 pango_font_description_free(bold_style->font_desc);
941 bold_style->font_desc = font_desc;
946 if (prefs_common.derive_from_normal_font || !SMALL_FONT) {
947 font_desc = pango_font_description_new();
948 size = pango_font_description_get_size
949 (gtk_widget_get_style(summaryview->ctree)->font_desc);
950 pango_font_description_set_size(font_desc, size * PANGO_SCALE_SMALL);
951 } else {
952 font_desc = pango_font_description_from_string(SMALL_FONT);
954 if (font_desc) {
955 gtk_widget_override_font(summaryview->statlabel_folder, font_desc);
956 gtk_widget_override_font(summaryview->statlabel_select, font_desc);
957 gtk_widget_override_font(summaryview->statlabel_msgs, font_desc);
958 pango_font_description_free(font_desc);
963 static void summary_set_folder_pixmap(SummaryView *summaryview, StockPixmap icon)
965 GtkWidget *pixmap;
966 if (!summaryview->folder_pixmap_eventbox) {
967 summaryview->folder_pixmap_eventbox = gtk_event_box_new();
968 gtk_widget_show(summaryview->folder_pixmap_eventbox);
969 gtk_box_pack_start(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, FALSE, FALSE, 4);
970 gtk_box_reorder_child(GTK_BOX(summaryview->hbox_l), summaryview->folder_pixmap_eventbox, 0); /* search_toggle before */
971 g_signal_connect(G_OBJECT(summaryview->folder_pixmap_eventbox), "button_press_event",
972 G_CALLBACK(summary_folder_eventbox_pressed),
973 summaryview);
975 if (summaryview->folder_pixmap)
976 gtk_widget_destroy(summaryview->folder_pixmap);
978 pixmap = stock_pixmap_widget(icon);
979 gtk_container_add(GTK_CONTAINER(summaryview->folder_pixmap_eventbox), pixmap);
980 gtk_widget_show(pixmap);
981 summaryview->folder_pixmap = pixmap;
984 void summary_init(SummaryView *summaryview)
986 GtkWidget *pixmap;
988 gtk_widget_realize(summaryview->ctree);
989 stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm);
990 stock_pixbuf_gdk(STOCK_PIXMAP_DELETED, &deletedxpm);
991 stock_pixbuf_gdk(STOCK_PIXMAP_NEW, &newxpm);
992 stock_pixbuf_gdk(STOCK_PIXMAP_UNREAD, &unreadxpm);
993 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED, &repliedxpm);
994 stock_pixbuf_gdk(STOCK_PIXMAP_FORWARDED, &forwardedxpm);
995 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED_AND_FORWARDED, &repliedandforwardedxpm);
996 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP, &clipxpm);
997 stock_pixbuf_gdk(STOCK_PIXMAP_LOCKED, &lockedxpm);
998 stock_pixbuf_gdk(STOCK_PIXMAP_IGNORETHREAD, &ignorethreadxpm);
999 stock_pixbuf_gdk(STOCK_PIXMAP_WATCHTHREAD, &watchthreadxpm);
1000 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_KEY, &clipkeyxpm);
1001 stock_pixbuf_gdk(STOCK_PIXMAP_KEY_SIGN, &keysignxpm);
1002 stock_pixbuf_gdk(STOCK_PIXMAP_KEY, &keyxpm);
1003 stock_pixbuf_gdk(STOCK_PIXMAP_GPG_SIGNED, &gpgsignedxpm);
1004 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_GPG_SIGNED, &clipgpgsignedxpm);
1005 stock_pixbuf_gdk(STOCK_PIXMAP_SPAM, &spamxpm);
1006 stock_pixbuf_gdk(STOCK_PIXMAP_MOVED, &movedxpm);
1007 stock_pixbuf_gdk(STOCK_PIXMAP_COPIED, &copiedxpm);
1009 summary_set_fonts(summaryview);
1011 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
1013 pixmap = stock_pixmap_widget(STOCK_PIXMAP_QUICKSEARCH);
1014 gtk_container_add (GTK_CONTAINER(summaryview->toggle_search), pixmap);
1015 gtk_widget_show(pixmap);
1016 summaryview->quick_search_pixmap = pixmap;
1018 #ifdef GENERIC_UMPC
1019 pixmap = stock_pixmap_widget(STOCK_PIXMAP_SELECTION);
1020 gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
1021 gtk_widget_show(pixmap);
1022 summaryview->multiple_sel_image = pixmap;
1023 #endif
1025 /* Init summaryview prefs */
1026 summaryview->sort_key = SORT_BY_NONE;
1027 summaryview->sort_type = SORT_ASCENDING;
1029 /* Init summaryview extra data */
1030 summaryview->simplify_subject_preg = NULL;
1031 summary_clear_list(summaryview);
1032 summary_set_column_titles(summaryview);
1033 summary_colorlabel_menu_create(summaryview, FALSE);
1034 summary_tags_menu_create(summaryview, FALSE);
1035 main_create_mailing_list_menu (summaryview->mainwin, NULL);
1036 summary_set_menu_sensitive(summaryview);
1038 summaryview->header_menu_lock = FALSE;
1041 #define CURRENTLY_DISPLAYED(m) \
1042 ( (m->msgnum == displayed_msgnum) \
1043 && (!g_ascii_strcasecmp(m->folder->name,item->name)) )
1045 #define FOLDER_SHOWS_TO_HDR(i) \
1046 ( i && (folder_has_parent_of_type(i, F_OUTBOX) \
1047 || folder_has_parent_of_type(i, F_DRAFT) \
1048 || folder_has_parent_of_type(i, F_QUEUE)) )
1050 static void summary_switch_from_to(SummaryView *summaryview, FolderItem *item)
1052 gboolean show_from = FALSE, show_to = FALSE;
1053 gboolean showing_from = FALSE, showing_to = FALSE;
1054 gint from_pos = 0, to_pos = 0;
1055 SummaryColumnState *col_state = summaryview->col_state;
1056 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1058 if (!item || ((prefs_common.layout_mode == VERTICAL_LAYOUT || prefs_common.layout_mode == SMALL_LAYOUT) && prefs_common.two_line_vert) )
1059 return;
1060 if (FOLDER_SHOWS_TO_HDR(item))
1061 show_to = TRUE;
1062 else
1063 show_from = TRUE;
1065 from_pos = summaryview->col_pos[S_COL_FROM];
1066 to_pos = summaryview->col_pos[S_COL_TO];
1067 showing_from = col_state[from_pos].visible;
1068 showing_to = col_state[to_pos].visible;
1070 if (showing_from && showing_to) {
1071 debug_print("showing both\n");
1072 return;
1075 if (!showing_from && !showing_to) {
1076 debug_print("showing none\n");
1077 return;
1080 debug_print("showing %s %s, must show %s %s\n",
1081 showing_from?"From":"",
1082 showing_to?"To":"",
1083 show_from?"From":"",
1084 show_to?"To":"");
1086 if (showing_from == show_from && showing_to == show_to)
1087 return;
1088 /* else we'll switch both */
1090 debug_print("switching columns\n");
1091 col_state[from_pos].type = S_COL_TO;
1092 col_state[from_pos].visible = show_to;
1094 col_state[to_pos].type = S_COL_FROM;
1095 col_state[to_pos].visible = show_from;
1097 summaryview->col_pos[S_COL_TO] = from_pos;
1098 summaryview->col_pos[S_COL_FROM] = to_pos;
1100 gtk_cmclist_set_column_visibility
1101 (GTK_CMCLIST(ctree), from_pos, col_state[from_pos].visible);
1102 gtk_cmclist_set_column_visibility
1103 (GTK_CMCLIST(ctree), to_pos, col_state[to_pos].visible);
1105 summary_set_column_titles(summaryview);
1108 static void summaryview_reset_recursive_folder_match(SummaryView *summaryview)
1110 GSList *cur;
1112 for (cur = summaryview->recursive_matched_folders; cur != NULL; cur = cur->next) {
1113 folderview_update_search_icon(cur->data, FALSE);
1116 g_slist_free(summaryview->recursive_matched_folders);
1117 summaryview->recursive_matched_folders = NULL;
1118 summaryview->search_root_folder = NULL;
1121 static gboolean summaryview_quicksearch_recursive_progress(gpointer data, guint at, guint matched, guint total)
1123 QuickSearch *search = (QuickSearch*) data;
1124 gint interval = quicksearch_is_fast(search) ? 5000 : 100;
1126 statusbar_progress_all(at, total, interval);
1127 if (at % interval == 0)
1128 GTK_EVENTS_FLUSH();
1130 if (matched > 0)
1131 return FALSE;
1133 return TRUE;
1136 static void summaryview_quicksearch_recurse_step(SummaryView *summaryview, FolderItem *item)
1138 MsgInfoList *msgs = NULL;
1139 gboolean result = TRUE;
1141 statusbar_print_all(_("Searching in %s... \n"),
1142 item->path ? item->path : "(null)");
1143 folder_item_update_freeze();
1145 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_quicksearch_recursive_progress, summaryview->quicksearch);
1146 if (!quicksearch_run_on_folder(summaryview->quicksearch, item, &msgs))
1147 result = FALSE;
1149 result = result && msgs != NULL;
1151 if (msgs != NULL)
1152 procmsg_msg_list_free(msgs);
1154 folder_item_update_thaw();
1155 statusbar_progress_all(0, 0, 0);
1156 statusbar_pop_all();
1158 if (result) {
1159 summaryview->recursive_matched_folders = g_slist_prepend(
1160 summaryview->recursive_matched_folders, item);
1162 folderview_update_search_icon(item, TRUE);
1166 static void summaryview_quicksearch_search_subfolders(SummaryView *summaryview, FolderItem *folder_item)
1168 FolderItem *cur = NULL;
1169 GNode *node = folder_item->node->children;
1171 if (!prefs_common.summary_quicksearch_recurse
1172 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1173 || quicksearch_is_in_typing(summaryview->quicksearch))
1174 return;
1176 for (; node != NULL; node = node->next) {
1177 if (!quicksearch_has_sat_predicate(summaryview->quicksearch))
1178 return;
1180 cur = FOLDER_ITEM(node->data);
1181 summaryview_quicksearch_recurse_step(summaryview, cur);
1182 if (cur->node->children)
1183 summaryview_quicksearch_search_subfolders(summaryview, cur);
1187 static void summaryview_quicksearch_recurse(SummaryView *summaryview)
1189 if (!prefs_common.summary_quicksearch_recurse
1190 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1191 || summaryview->folder_item == NULL) {
1192 return;
1194 START_TIMING("");
1195 main_window_cursor_wait(summaryview->mainwin);
1197 summaryview_reset_recursive_folder_match(summaryview);
1198 summaryview->search_root_folder = summaryview->folder_item;
1200 summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
1202 main_window_cursor_normal(summaryview->mainwin);
1203 END_TIMING();
1206 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
1208 int u = 0, n = 0, m = 0, t = 0, r = 0, f = 0, l = 0, i = 0, w = 0;
1209 GSList *cur;
1210 START_TIMING("");
1211 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1212 MsgInfo * msginfo = (MsgInfo *) cur->data;
1213 t++;
1214 if (MSG_IS_NEW(msginfo->flags))
1215 n++;
1216 if (MSG_IS_UNREAD(msginfo->flags))
1217 u++;
1218 if (MSG_IS_MARKED(msginfo->flags))
1219 m++;
1220 if (MSG_IS_REPLIED(msginfo->flags))
1221 r++;
1222 if (MSG_IS_FORWARDED(msginfo->flags))
1223 f++;
1224 if (MSG_IS_LOCKED(msginfo->flags))
1225 l++;
1226 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
1227 i++;
1228 if (MSG_IS_WATCH_THREAD(msginfo->flags))
1229 w++;
1231 if (t != item->total_msgs
1232 || n != item->new_msgs
1233 || u != item->unread_msgs
1234 || m != item->marked_msgs
1235 || r != item->replied_msgs
1236 || f != item->forwarded_msgs
1237 || l != item->locked_msgs
1238 || i != item->ignored_msgs
1239 || w != item->watched_msgs
1240 || (m == 0 && item->unreadmarked_msgs != 0)
1241 || item->unreadmarked_msgs < 0) {
1242 debug_print("Inconsistency\n");
1243 folder_item_scan_full(item, FALSE);
1244 END_TIMING();
1245 return FALSE;
1247 END_TIMING();
1248 return TRUE;
1251 gboolean summaryview_search_root_progress(gpointer data, guint at, guint matched, guint total)
1253 SummaryView *summaryview = (SummaryView*) data;
1255 gint interval = quicksearch_is_fast(summaryview->quicksearch) ? 5000 : 100;
1257 statusbar_progress_all(at, total, interval);
1259 if (at % interval == 0)
1260 GTK_EVENTS_FLUSH();
1262 return TRUE;
1265 gboolean summary_show(SummaryView *summaryview, FolderItem *item, gboolean avoid_refresh)
1267 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1268 GtkCMCTreeNode *node = NULL;
1269 GSList *mlist = NULL;
1270 gchar *buf;
1271 gboolean is_refresh;
1272 guint selected_msgnum = 0;
1273 guint displayed_msgnum = 0;
1274 GSList *cur;
1275 GSList *not_killed;
1276 gboolean hidden_removed = FALSE;
1278 if (summary_is_locked(summaryview)) return FALSE;
1280 if (!summaryview->mainwin)
1281 return FALSE;
1282 START_TIMING("");
1283 summary_switch_from_to(summaryview, item);
1285 inc_lock();
1286 summary_lock(summaryview);
1288 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
1290 utils_free_regex();
1292 is_refresh = (item == summaryview->folder_item && !avoid_refresh) ? TRUE : FALSE;
1294 if (item && item->folder->klass->item_opened) {
1295 item->folder->klass->item_opened(item);
1298 if (!is_refresh) {
1299 main_create_mailing_list_menu (summaryview->mainwin, NULL);
1300 if (prefs_common.layout_mode == SMALL_LAYOUT) {
1301 if (item) {
1302 mainwindow_enter_folder(summaryview->mainwin);
1303 gtk_widget_grab_focus(summaryview->ctree);
1307 if (!prefs_common.summary_quicksearch_sticky
1308 && (!prefs_common.summary_quicksearch_recurse
1309 || !quicksearch_has_sat_predicate(summaryview->quicksearch)
1310 || (item && !folder_is_child_of(item, summaryview->search_root_folder)))
1311 && !quicksearch_is_running(summaryview->quicksearch)
1312 && !is_refresh) {
1313 quicksearch_set(summaryview->quicksearch, prefs_common.summary_quicksearch_type, "");
1316 /* STATUSBAR_POP(summaryview->mainwin); */
1318 if (is_refresh) {
1319 selected_msgnum = summary_get_msgnum(summaryview,
1320 summaryview->selected);
1321 displayed_msgnum = summary_get_msgnum(summaryview,
1322 summaryview->displayed);
1325 /* process the marks if any */
1326 if (!is_refresh &&
1327 (summaryview->mainwin->lock_count == 0 &&
1328 (summaryview->moved > 0 || summaryview->copied > 0))) {
1329 AlertValue val;
1330 gboolean changed = FALSE;
1332 val = alertpanel(_("Process mark"),
1333 _("Some marks are left. Process them?"),
1334 NULL, _("_No"), NULL, _("_Yes"), NULL, _("_Cancel"),
1335 ALERTFOCUS_FIRST);
1336 if (G_ALERTALTERNATE == val) {
1337 summary_unlock(summaryview);
1338 summary_execute(summaryview);
1339 summary_lock(summaryview);
1340 changed = TRUE;
1341 } else if (G_ALERTDEFAULT == val) {
1342 /* DO NOTHING */
1343 } else {
1344 summary_unlock(summaryview);
1345 inc_unlock();
1346 END_TIMING();
1347 return FALSE;
1349 if (changed || !quicksearch_has_sat_predicate(summaryview->quicksearch))
1350 folder_update_op_count();
1353 summary_freeze(summaryview);
1355 summary_clear_list(summaryview);
1357 buf = NULL;
1358 if (!item || !item->path || !folder_item_parent(item) || item->no_select) {
1359 g_free(buf);
1360 debug_print("empty folder (%p %s %p %d)\n",
1361 item,
1362 (item && item->path)?item->path:"(null)",
1363 item?folder_item_parent(item):0x0,
1364 item?item->no_select:FALSE);
1365 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages", FALSE);
1366 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages", FALSE);
1367 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads", FALSE);
1368 summary_clear_all(summaryview);
1369 summaryview->folder_item = item;
1370 summary_thaw(summaryview);
1371 summary_unlock(summaryview);
1372 inc_unlock();
1373 END_TIMING();
1374 return TRUE;
1376 g_free(buf);
1378 if (!is_refresh)
1379 messageview_clear(summaryview->messageview);
1381 summaryview->folder_item = item;
1382 item->opened = TRUE;
1384 buf = g_strdup_printf(_("Scanning folder (%s)..."), item->path);
1385 debug_print("%s\n", buf);
1386 STATUSBAR_PUSH(summaryview->mainwin, buf);
1387 g_free(buf);
1389 main_window_cursor_wait(summaryview->mainwin);
1391 mlist = folder_item_get_msg_list(item);
1393 if (!summary_check_consistency(item, mlist)) {
1394 debug_print("reloading due to inconsistency\n");
1395 procmsg_msg_list_free(mlist);
1396 mlist = folder_item_get_msg_list(item);
1399 if (quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1400 procmsg_msg_list_free(mlist);
1401 mlist = NULL;
1403 START_TIMING("quicksearch");
1405 statusbar_print_all(_("Searching in %s... \n"),
1406 summaryview->folder_item->path ?
1407 summaryview->folder_item->path : "(null)");
1409 folder_item_update_freeze();
1411 quicksearch_set_on_progress_cb(summaryview->quicksearch, summaryview_search_root_progress, summaryview);
1412 quicksearch_run_on_folder(summaryview->quicksearch, summaryview->folder_item, &mlist);
1414 folder_item_update_thaw();
1415 statusbar_progress_all(0, 0, 0);
1416 statusbar_pop_all();
1418 if (!quicksearch_has_sat_predicate(summaryview->quicksearch)) {
1419 debug_print("search cancelled!\n");
1420 summary_thaw(summaryview);
1421 STATUSBAR_POP(summaryview->mainwin);
1422 main_window_cursor_normal(summaryview->mainwin);
1423 summary_unlock(summaryview);
1424 inc_unlock();
1425 summary_show(summaryview, summaryview->folder_item, FALSE);
1426 END_TIMING();
1427 return FALSE;
1429 END_TIMING();
1432 if ((summaryview->folder_item->hide_read_msgs
1433 || summaryview->folder_item->hide_del_msgs
1434 || summaryview->folder_item->hide_read_threads) &&
1435 quicksearch_has_sat_predicate(summaryview->quicksearch) == FALSE) {
1436 GSList *not_killed;
1438 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1439 summaryview->folder_item->hide_read_msgs);
1440 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1441 summaryview->folder_item->hide_del_msgs);
1442 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1443 summaryview->folder_item->hide_read_threads);
1444 not_killed = NULL;
1445 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1446 MsgInfo * msginfo = (MsgInfo *) cur->data;
1448 if (!msginfo->hidden) {
1449 if (MSG_IS_DELETED(msginfo->flags) && summaryview->folder_item->hide_del_msgs) {
1450 procmsg_msginfo_free(&msginfo);
1451 continue;
1453 if (summaryview->folder_item->hide_read_msgs) {
1454 if (MSG_IS_UNREAD(msginfo->flags) &&
1455 !MSG_IS_IGNORE_THREAD(msginfo->flags))
1456 not_killed = g_slist_prepend(not_killed, msginfo);
1457 else if (MSG_IS_MARKED(msginfo->flags) ||
1458 MSG_IS_LOCKED(msginfo->flags))
1459 not_killed = g_slist_prepend(not_killed, msginfo);
1460 else if (is_refresh &&
1461 (msginfo->msgnum == selected_msgnum ||
1462 msginfo->msgnum == displayed_msgnum))
1463 not_killed = g_slist_prepend(not_killed, msginfo);
1464 else
1465 procmsg_msginfo_free(&msginfo);
1466 } else {
1467 not_killed = g_slist_prepend(not_killed, msginfo);
1469 } else
1470 procmsg_msginfo_free(&msginfo);
1472 hidden_removed = TRUE;
1473 g_slist_free(mlist);
1474 mlist = not_killed;
1475 } else {
1476 summary_set_hide_menu(summaryview, "/Menu/View/HideReadMessages",
1477 FALSE);
1478 summary_set_hide_menu(summaryview, "/Menu/View/HideDelMessages",
1479 FALSE);
1480 summary_set_hide_menu(summaryview, "/Menu/View/HideReadThreads",
1481 FALSE);
1484 if (!hidden_removed) {
1485 START_TIMING("removing hidden");
1486 not_killed = NULL;
1487 for(cur = mlist ; cur != NULL && cur->data != NULL ; cur = g_slist_next(cur)) {
1488 MsgInfo * msginfo = (MsgInfo *) cur->data;
1490 if (!msginfo->hidden)
1491 not_killed = g_slist_prepend(not_killed, msginfo);
1492 else
1493 procmsg_msginfo_free(&msginfo);
1495 g_slist_free(mlist);
1496 mlist = not_killed;
1497 END_TIMING();
1500 STATUSBAR_POP(summaryview->mainwin);
1502 /* set ctree and hash table from the msginfo list, and
1503 create the thread */
1504 summary_set_ctree_from_list(summaryview, mlist, selected_msgnum);
1506 g_slist_free(mlist);
1508 if (is_refresh) {
1509 if (!quicksearch_is_in_typing(summaryview->quicksearch)) {
1510 summaryview->displayed =
1511 summary_find_msg_by_msgnum(summaryview,
1512 displayed_msgnum);
1513 if (!summaryview->displayed)
1514 messageview_clear(summaryview->messageview);
1515 summary_unlock(summaryview);
1517 if (quicksearch_is_running(summaryview->quicksearch))
1518 summary_select_by_msgnum(summaryview, selected_msgnum,
1519 OPEN_SELECTED_ON_SEARCH_RESULTS);
1520 else
1521 summary_select_by_msgnum(summaryview, selected_msgnum,
1522 FALSE);
1524 summary_lock(summaryview);
1525 if (!summaryview->selected) {
1526 /* no selected message - select first unread
1527 message, but do not display it */
1528 node = summary_find_next_flagged_msg(summaryview, NULL,
1529 MSG_UNREAD, FALSE);
1530 if (node == NULL && GTK_CMCLIST(ctree)->row_list != NULL)
1531 node = gtk_cmctree_node_nth
1532 (ctree,
1533 item->sort_type == SORT_DESCENDING
1534 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1535 summary_unlock(summaryview);
1537 if (quicksearch_is_running(summaryview->quicksearch))
1538 summary_select_node(summaryview, node,
1539 OPEN_SELECTED_ON_SEARCH_RESULTS);
1540 else
1541 summary_select_node(summaryview, node,
1542 OPEN_SELECTED_ON_FOLDER_OPEN);
1544 summary_lock(summaryview);
1546 } else {
1547 /* just select first/last */
1548 if (GTK_CMCLIST(ctree)->row_list != NULL)
1549 node = gtk_cmctree_node_nth
1550 (ctree,
1551 item->sort_type == SORT_DESCENDING
1552 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1553 summary_select_node(summaryview, node, OPEN_SELECTED_ON_SEARCH_RESULTS);
1555 } else {
1556 /* backward compat */
1557 int i = 0;
1558 gboolean set = FALSE, stop = FALSE;
1559 for (i = 0; i < 6; i++) {
1560 EntryAction act = prefs_common.summary_select_prio[i];
1562 if (act != ACTION_UNSET) {
1563 set = TRUE;
1564 break;
1567 if (!set)
1568 prefs_summary_open_set_defaults();
1570 for (i = 0; i < 6 && node == NULL; i++) {
1571 EntryAction act = prefs_common.summary_select_prio[i];
1573 switch(act) {
1574 case ACTION_OLDEST_MARKED:
1575 if (summaryview->sort_type == SORT_ASCENDING)
1576 node = summary_find_next_flagged_msg(summaryview, NULL,
1577 MSG_MARKED, FALSE);
1578 else
1579 node = summary_find_prev_flagged_msg(summaryview, NULL,
1580 MSG_MARKED, FALSE);
1581 break;
1582 case ACTION_NEWEST_MARKED:
1583 if (summaryview->sort_type == SORT_ASCENDING)
1584 node = summary_find_prev_flagged_msg(summaryview, NULL,
1585 MSG_MARKED, FALSE);
1586 else
1587 node = summary_find_next_flagged_msg(summaryview, NULL,
1588 MSG_MARKED, FALSE);
1589 break;
1590 case ACTION_OLDEST_NEW:
1591 if (summaryview->sort_type == SORT_ASCENDING)
1592 node = summary_find_next_flagged_msg(summaryview, NULL,
1593 MSG_NEW, FALSE);
1594 else
1595 node = summary_find_prev_flagged_msg(summaryview, NULL,
1596 MSG_NEW, FALSE);
1597 break;
1598 case ACTION_NEWEST_NEW:
1599 if (summaryview->sort_type == SORT_ASCENDING)
1600 node = summary_find_prev_flagged_msg(summaryview, NULL,
1601 MSG_NEW, FALSE);
1602 else
1603 node = summary_find_next_flagged_msg(summaryview, NULL,
1604 MSG_NEW, FALSE);
1605 break;
1606 case ACTION_OLDEST_UNREAD:
1607 if (summaryview->sort_type == SORT_ASCENDING)
1608 node = summary_find_next_flagged_msg(summaryview, NULL,
1609 MSG_UNREAD, FALSE);
1610 else
1611 node = summary_find_prev_flagged_msg(summaryview, NULL,
1612 MSG_UNREAD, FALSE);
1613 break;
1614 case ACTION_NEWEST_UNREAD:
1615 if (summaryview->sort_type == SORT_ASCENDING)
1616 node = summary_find_prev_flagged_msg(summaryview, NULL,
1617 MSG_UNREAD, FALSE);
1618 else
1619 node = summary_find_next_flagged_msg(summaryview, NULL,
1620 MSG_UNREAD, FALSE);
1621 break;
1622 case ACTION_LAST_OPENED:
1623 if (summaryview->folder_item) {
1624 node = summary_find_msg_by_msgnum(summaryview,
1625 summaryview->folder_item->last_seen);
1627 break;
1628 case ACTION_NEWEST_LIST:
1629 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1630 node = gtk_cmctree_node_nth
1631 (ctree,
1632 item->sort_type == SORT_DESCENDING
1633 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1635 break;
1636 case ACTION_OLDEST_LIST:
1637 if (GTK_CMCLIST(ctree)->row_list != NULL) {
1638 node = gtk_cmctree_node_nth
1639 (ctree,
1640 item->sort_type == SORT_ASCENDING
1641 ? 0 : GTK_CMCLIST(ctree)->rows - 1);
1643 break;
1644 case ACTION_NOTHING:
1645 case ACTION_UNSET:
1646 node = NULL;
1647 stop = TRUE;
1648 break;
1651 if (stop || node)
1652 break;
1655 summary_unlock(summaryview);
1657 if (node)
1658 summary_select_node(summaryview, node,
1659 OPEN_SELECTED_ON_FOLDER_OPEN);
1661 summary_lock(summaryview);
1664 summary_status_show(summaryview);
1665 summary_set_menu_sensitive(summaryview);
1666 toolbar_main_set_sensitive(summaryview->mainwin);
1668 summary_thaw(summaryview);
1669 debug_print("\n");
1670 STATUSBAR_PUSH(summaryview->mainwin, _("Done."));
1671 STATUSBAR_POP(summaryview->mainwin);
1672 main_window_cursor_normal(summaryview->mainwin);
1673 summary_unlock(summaryview);
1674 inc_unlock();
1675 END_TIMING();
1676 return TRUE;
1679 #undef CURRENTLY_DISPLAYED
1681 static void summary_cancel_mark_read_timeout(SummaryView *summaryview) {
1682 if (summaryview->mark_as_read_timeout_tag != 0) {
1683 g_source_remove(summaryview->mark_as_read_timeout_tag);
1684 summaryview->mark_as_read_timeout_tag = 0;
1688 void summary_clear_list(SummaryView *summaryview)
1690 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1691 gint optimal_width;
1693 summary_freeze(summaryview);
1695 gtk_cmctree_pre_recursive(GTK_CMCTREE(summaryview->ctree),
1696 NULL, summary_free_msginfo_func, NULL);
1698 if (summaryview->folder_item) {
1699 summaryview->folder_item->opened = FALSE;
1700 summaryview->folder_item = NULL;
1703 summary_cancel_mark_read_timeout(summaryview);
1705 summaryview->display_msg = FALSE;
1707 summaryview->selected = NULL;
1708 summaryview->displayed = NULL;
1709 summaryview->total_size = 0;
1710 summaryview->deleted = summaryview->moved = 0;
1711 summaryview->copied = 0;
1712 if (summaryview->msgid_table) {
1713 g_hash_table_destroy(summaryview->msgid_table);
1714 summaryview->msgid_table = NULL;
1716 if (summaryview->subject_table) {
1717 g_hash_table_destroy(summaryview->subject_table);
1718 summaryview->subject_table = NULL;
1720 summaryview->mlist = NULL;
1722 gtk_cmclist_clear(clist);
1723 if (summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
1724 optimal_width = gtk_cmclist_optimal_column_width
1725 (clist, summaryview->col_pos[S_COL_SUBJECT]);
1726 gtk_cmclist_set_column_width
1727 (clist, summaryview->col_pos[S_COL_SUBJECT],
1728 optimal_width);
1731 summary_thaw(summaryview);
1734 void summary_clear_all(SummaryView *summaryview)
1736 mimeview_clear(summaryview->messageview->mimeview);
1737 messageview_clear(summaryview->messageview);
1738 summary_clear_list(summaryview);
1739 summary_set_menu_sensitive(summaryview);
1740 toolbar_main_set_sensitive(summaryview->mainwin);
1741 summary_status_show(summaryview);
1744 void summary_lock(SummaryView *summaryview)
1746 summaryview->lock_count++;
1749 void summary_unlock(SummaryView *summaryview)
1751 if (summaryview->lock_count)
1752 summaryview->lock_count--;
1755 gboolean summary_is_locked(SummaryView *summaryview)
1757 return summaryview->lock_count > 0;
1760 SummarySelection summary_get_selection_type(SummaryView *summaryview)
1762 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
1763 SummarySelection selection;
1765 if (!clist->row_list)
1766 selection = SUMMARY_NONE;
1767 else if (!clist->selection)
1768 selection = SUMMARY_SELECTED_NONE;
1769 else if (!clist->selection->next)
1770 selection = SUMMARY_SELECTED_SINGLE;
1771 else
1772 selection = SUMMARY_SELECTED_MULTIPLE;
1774 return selection;
1778 *\return MsgInfo * Selected message if there's one selected;
1779 * if multiple selected, or none, return NULL.
1781 MsgInfo *summary_get_selected_msg(SummaryView *summaryview)
1783 /* summaryview->selected may be valid when multiple
1784 * messages were selected */
1785 GList *sellist = GTK_CMCLIST(summaryview->ctree)->selection;
1787 if (sellist == NULL || sellist->next)
1788 return NULL;
1790 return GTKUT_CTREE_NODE_GET_ROW_DATA(sellist->data);
1793 GSList *summary_get_selected_msg_list(SummaryView *summaryview)
1795 GSList *mlist = NULL;
1796 GList *cur;
1797 MsgInfo *msginfo;
1799 for (cur = GTK_CMCLIST(summaryview->ctree)->selection; cur != NULL && cur->data != NULL;
1800 cur = cur->next) {
1801 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data);
1802 mlist = g_slist_prepend(mlist,
1803 procmsg_msginfo_new_ref(msginfo));
1806 mlist = g_slist_reverse(mlist);
1808 return mlist;
1811 void summary_set_menu_sensitive(SummaryView *summaryview)
1813 SensitiveCondMask state;
1815 main_window_set_menu_sensitive(summaryview->mainwin);
1817 state = main_window_get_current_state(summaryview->mainwin);
1819 #define SET_SENSITIVE(entry_str, ...) \
1821 SensitiveCondMask cond = main_window_get_mask(__VA_ARGS__, -1); \
1822 cm_menu_set_sensitive_full(summaryview->mainwin->ui_manager, \
1823 (const gchar *) entry_str, \
1824 ((cond & state) == cond)); \
1826 SET_SENSITIVE("Menus/SummaryViewPopup/Reedit", M_ALLOW_REEDIT);
1827 SET_SENSITIVE("Menus/SummaryViewPopup/Reply", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1828 #ifndef GENERIC_UMPC
1829 SET_SENSITIVE("Menus/SummaryViewPopup/ReplyTo", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1830 SET_SENSITIVE("Menus/SummaryViewPopup/ReplyTo/All", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1831 SET_SENSITIVE("Menus/SummaryViewPopup/ReplyTo/Sender", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1832 SET_SENSITIVE("Menus/SummaryViewPopup/ReplyTo/MailingList", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1833 #endif
1835 SET_SENSITIVE("Menus/SummaryViewPopup/Forward", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1836 #ifndef GENERIC_UMPC
1837 SET_SENSITIVE("Menus/SummaryViewPopup/ForwardAtt", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1838 SET_SENSITIVE("Menus/SummaryViewPopup/Redirect", M_HAVE_ACCOUNT, M_TARGET_EXIST);
1839 #endif
1841 SET_SENSITIVE("Menus/SummaryViewPopup/Move", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
1842 SET_SENSITIVE("Menus/SummaryViewPopup/Copy", M_TARGET_EXIST, M_EXEC);
1843 SET_SENSITIVE("Menus/SummaryViewPopup/Trash", M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS, M_NOT_TRASH);
1844 #ifndef GENERIC_UMPC
1845 SET_SENSITIVE("Menus/SummaryViewPopup/Delete", M_TARGET_EXIST, M_ALLOW_DELETE);
1846 #endif
1848 SET_SENSITIVE("Menus/SummaryViewPopup/Mark", M_TARGET_EXIST);
1849 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/Mark", M_TARGET_EXIST);
1850 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/Unmark", M_TARGET_EXIST);
1851 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkRead", M_TARGET_EXIST);
1852 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkUnread", M_TARGET_EXIST);
1853 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkAllRead", M_TARGET_EXIST);
1854 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkAllUnread", M_TARGET_EXIST);
1855 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/IgnoreThread", M_TARGET_EXIST);
1856 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/UnignoreThread", M_TARGET_EXIST);
1857 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/WatchThread", M_TARGET_EXIST);
1858 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/UnwatchThread", M_TARGET_EXIST);
1859 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/Lock", M_TARGET_EXIST);
1860 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/Unlock", M_TARGET_EXIST);
1861 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkSpam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1862 SET_SENSITIVE("Menus/SummaryViewPopup/Mark/MarkHam", M_TARGET_EXIST, M_CAN_LEARN_SPAM);
1863 SET_SENSITIVE("Menus/SummaryViewPopup/ColorLabel", M_TARGET_EXIST);
1864 SET_SENSITIVE("Menus/SummaryViewPopup/Tags", M_TARGET_EXIST);
1866 #ifndef GENERIC_UMPC
1867 SET_SENSITIVE("Menus/SummaryViewPopup/AddSenderToAB", M_SINGLE_TARGET_EXIST);
1868 #endif
1869 SET_SENSITIVE("Menus/SummaryViewPopup/CreateFilterRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1870 #ifndef GENERIC_UMPC
1871 SET_SENSITIVE("Menus/SummaryViewPopup/CreateProcessingRule", M_SINGLE_TARGET_EXIST, M_UNLOCKED);
1872 #endif
1874 SET_SENSITIVE("Menus/SummaryViewPopup/View", M_SINGLE_TARGET_EXIST);
1875 SET_SENSITIVE("Menus/SummaryViewPopup/View/OpenNewWindow", M_SINGLE_TARGET_EXIST);
1876 SET_SENSITIVE("Menus/SummaryViewPopup/View/MessageSource", M_SINGLE_TARGET_EXIST);
1877 #ifndef GENERIC_UMPC
1878 SET_SENSITIVE("Menus/SummaryViewPopup/View/AllHeaders", M_SINGLE_TARGET_EXIST);
1879 #endif
1880 SET_SENSITIVE("Menus/SummaryViewPopup/SaveAs", M_TARGET_EXIST);
1881 #ifndef GENERIC_UMPC
1882 SET_SENSITIVE("Menus/SummaryViewPopup/Print", M_TARGET_EXIST);
1883 #endif
1884 #undef SET_SENSITIVE
1886 summary_lock(summaryview);
1887 #ifndef GENERIC_UMPC
1888 if (summaryview->messageview
1889 && summaryview->messageview->mimeview
1890 && summaryview->messageview->mimeview->textview)
1891 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager, "Menus/SummaryViewPopup/View/AllHeaders",
1892 prefs_common.show_all_headers);
1893 #endif
1894 summary_unlock(summaryview);
1896 void summary_select_prev(SummaryView *summaryview)
1898 GtkCMCTreeNode *node = summaryview->selected;
1899 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1901 if (summaryview->sort_type == SORT_ASCENDING)
1902 node = gtkut_ctree_node_prev(ctree, node);
1903 else
1904 node = gtkut_ctree_node_next(ctree, node);
1906 if (node && node != summaryview->selected)
1907 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
1910 void summary_select_next(SummaryView *summaryview)
1912 GtkCMCTreeNode *node = summaryview->selected;
1913 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
1915 if (summaryview->sort_type == SORT_ASCENDING)
1916 node = gtkut_ctree_node_next(ctree, node);
1917 else
1918 node = gtkut_ctree_node_prev(ctree, node);
1920 if (node && node != summaryview->selected)
1921 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
1924 void summary_select_prev_unread(SummaryView *summaryview)
1926 GtkCMCTreeNode *node;
1928 if (summaryview->sort_type == SORT_ASCENDING)
1929 node = summary_find_prev_flagged_msg
1930 (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1931 else
1932 node = summary_find_next_flagged_msg
1933 (summaryview, summaryview->selected, MSG_UNREAD, TRUE);
1935 if (!node || node == summaryview->selected) {
1936 AlertValue val = 0;
1938 switch (prefs_common.next_unread_msg_dialog) {
1939 case NEXTUNREADMSGDIALOG_ALWAYS:
1940 val = alertpanel(_("No more unread messages"),
1941 _("No unread message found. "
1942 "Search from the end?"),
1943 NULL, _("_No"), NULL, _("_Yes"),
1944 NULL, NULL, ALERTFOCUS_SECOND);
1945 break;
1946 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1947 val = G_ALERTALTERNATE;
1948 break;
1949 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1950 val = !G_ALERTALTERNATE;
1951 break;
1952 default:
1953 debug_print(
1954 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
1956 if (val != G_ALERTALTERNATE) return;
1957 if (summaryview->sort_type == SORT_ASCENDING)
1958 node = summary_find_prev_flagged_msg(summaryview, NULL,
1959 MSG_UNREAD, FALSE);
1960 else
1961 node = summary_find_next_flagged_msg(summaryview, NULL,
1962 MSG_UNREAD, FALSE);
1965 if (!node)
1966 alertpanel_notice(_("No unread messages."));
1967 else
1968 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
1971 void summary_select_next_unread(SummaryView *summaryview)
1973 GtkCMCTreeNode *node = summaryview->selected;
1975 if (summaryview->sort_type == SORT_ASCENDING)
1976 node = summary_find_next_flagged_msg
1977 (summaryview, node, MSG_UNREAD, TRUE);
1978 else
1979 node = summary_find_prev_flagged_msg
1980 (summaryview, node, MSG_UNREAD, TRUE);
1982 if (node)
1983 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
1984 else {
1985 AlertValue val = 0;
1987 switch (prefs_common.next_unread_msg_dialog) {
1988 case NEXTUNREADMSGDIALOG_ALWAYS:
1989 val = alertpanel(_("No more unread messages"),
1990 _("No unread message found. "
1991 "Go to next folder?"),
1992 NULL, _("_No"), NULL, _("_Yes"),
1993 NULL, NULL, ALERTFOCUS_SECOND);
1994 break;
1995 case NEXTUNREADMSGDIALOG_ASSUME_YES:
1996 val = G_ALERTALTERNATE;
1997 break;
1998 case NEXTUNREADMSGDIALOG_ASSUME_NO:
1999 val = G_ALERTOTHER;
2000 break;
2001 default:
2002 debug_print(
2003 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2006 if (val == G_ALERTALTERNATE)
2007 folderview_select_next_with_flag(summaryview->folderview, MSG_UNREAD);
2011 void summary_select_prev_new(SummaryView *summaryview)
2013 GtkCMCTreeNode *node;
2015 if (summaryview->sort_type == SORT_ASCENDING)
2016 node = summary_find_prev_flagged_msg
2017 (summaryview, summaryview->selected, MSG_NEW, TRUE);
2018 else
2019 node = summary_find_next_flagged_msg
2020 (summaryview, summaryview->selected, MSG_NEW, TRUE);
2022 if (!node || node == summaryview->selected) {
2023 AlertValue val = 0;
2025 switch (prefs_common.next_unread_msg_dialog) {
2026 case NEXTUNREADMSGDIALOG_ALWAYS:
2027 val = alertpanel(_("No more new messages"),
2028 _("No new message found. "
2029 "Search from the end?"),
2030 NULL, _("_No"), NULL, _("_Yes"),
2031 NULL, NULL, ALERTFOCUS_SECOND);
2032 break;
2033 case NEXTUNREADMSGDIALOG_ASSUME_YES:
2034 val = G_ALERTALTERNATE;
2035 break;
2036 case NEXTUNREADMSGDIALOG_ASSUME_NO:
2037 val = !G_ALERTALTERNATE;
2038 break;
2039 default:
2040 debug_print(
2041 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2043 if (val != G_ALERTALTERNATE) return;
2044 if (summaryview->sort_type == SORT_ASCENDING)
2045 node = summary_find_prev_flagged_msg(summaryview, NULL,
2046 MSG_NEW, FALSE);
2047 else
2048 node = summary_find_next_flagged_msg(summaryview, NULL,
2049 MSG_NEW, FALSE);
2052 if (!node)
2053 alertpanel_notice(_("No new messages."));
2054 else
2055 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2058 void summary_select_next_new(SummaryView *summaryview)
2060 GtkCMCTreeNode *node = summaryview->selected;
2062 if (summaryview->sort_type == SORT_ASCENDING)
2063 node = summary_find_next_flagged_msg
2064 (summaryview, node, MSG_NEW, TRUE);
2065 else
2066 node = summary_find_prev_flagged_msg
2067 (summaryview, node, MSG_NEW, TRUE);
2069 if (node)
2070 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2071 else {
2072 AlertValue val = 0;
2074 switch (prefs_common.next_unread_msg_dialog) {
2075 case NEXTUNREADMSGDIALOG_ALWAYS:
2076 val = alertpanel(_("No more new messages"),
2077 _("No new message found. "
2078 "Go to next folder?"),
2079 NULL, _("_No"), NULL, _("_Yes"),
2080 NULL, NULL, ALERTFOCUS_SECOND);
2081 break;
2082 case NEXTUNREADMSGDIALOG_ASSUME_YES:
2083 val = G_ALERTALTERNATE;
2084 break;
2085 case NEXTUNREADMSGDIALOG_ASSUME_NO:
2086 val = G_ALERTOTHER;
2087 break;
2088 default:
2089 debug_print(
2090 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2092 if (val == G_ALERTALTERNATE)
2093 folderview_select_next_with_flag(summaryview->folderview, MSG_NEW);
2097 void summary_select_prev_marked(SummaryView *summaryview)
2099 GtkCMCTreeNode *node;
2101 if (summaryview->sort_type == SORT_ASCENDING)
2102 node = summary_find_prev_flagged_msg
2103 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2104 else
2105 node = summary_find_next_flagged_msg
2106 (summaryview, summaryview->selected, MSG_MARKED, TRUE);
2108 if (!node) {
2109 AlertValue val;
2111 val = alertpanel(_("No more marked messages"),
2112 _("No marked message found. "
2113 "Search from the end?"),
2114 NULL, _("_No"), NULL, _("_Yes"),
2115 NULL, NULL, ALERTFOCUS_SECOND);
2116 if (val != G_ALERTALTERNATE) return;
2117 node = summary_find_prev_flagged_msg(summaryview, NULL,
2118 MSG_MARKED, TRUE);
2121 if (!node)
2122 alertpanel_notice(_("No marked messages."));
2123 else
2124 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2127 void summary_select_next_marked(SummaryView *summaryview)
2129 GtkCMCTreeNode *node = summaryview->selected;
2131 if (summaryview->sort_type == SORT_ASCENDING)
2132 node = summary_find_next_flagged_msg
2133 (summaryview, node, MSG_MARKED, TRUE);
2134 else
2135 node = summary_find_prev_flagged_msg
2136 (summaryview, node, MSG_MARKED, TRUE);
2138 if (node)
2139 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2140 else {
2141 AlertValue val = 0;
2143 switch (prefs_common.next_unread_msg_dialog) {
2144 case NEXTUNREADMSGDIALOG_ALWAYS:
2145 val = alertpanel(_("No more marked messages"),
2146 _("No marked message found. "
2147 "Go to next folder?"),
2148 NULL, _("_No"), NULL, _("_Yes"),
2149 NULL, NULL, ALERTFOCUS_SECOND);
2150 break;
2151 case NEXTUNREADMSGDIALOG_ASSUME_YES:
2152 val = G_ALERTALTERNATE;
2153 break;
2154 case NEXTUNREADMSGDIALOG_ASSUME_NO:
2155 val = G_ALERTOTHER;
2156 break;
2157 default:
2158 debug_print(
2159 _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
2161 if (val == G_ALERTALTERNATE)
2162 folderview_select_next_with_flag(summaryview->folderview, MSG_MARKED);
2166 void summary_select_prev_labeled(SummaryView *summaryview)
2168 GtkCMCTreeNode *node;
2170 if (summaryview->sort_type == SORT_ASCENDING)
2171 node = summary_find_prev_flagged_msg
2172 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2173 else
2174 node = summary_find_next_flagged_msg
2175 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2177 if (!node) {
2178 AlertValue val;
2180 val = alertpanel(_("No more labeled messages"),
2181 _("No labeled message found. "
2182 "Search from the end?"),
2183 NULL, _("_No"), NULL, _("_Yes"),
2184 NULL, NULL, ALERTFOCUS_SECOND);
2185 if (val != G_ALERTALTERNATE) return;
2186 node = summary_find_prev_flagged_msg(summaryview, NULL,
2187 MSG_CLABEL_FLAG_MASK, TRUE);
2190 if (!node)
2191 alertpanel_notice(_("No labeled messages."));
2192 else
2193 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2196 void summary_select_next_labeled(SummaryView *summaryview)
2198 GtkCMCTreeNode *node;
2200 if (summaryview->sort_type == SORT_ASCENDING)
2201 node = summary_find_next_flagged_msg
2202 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2203 else
2204 node = summary_find_prev_flagged_msg
2205 (summaryview, summaryview->selected, MSG_CLABEL_FLAG_MASK, TRUE);
2207 if (!node) {
2208 AlertValue val;
2210 val = alertpanel(_("No more labeled messages"),
2211 _("No labeled message found. "
2212 "Search from the beginning?"),
2213 NULL, _("_No"), NULL, _("_Yes"),
2214 NULL, NULL, ALERTFOCUS_SECOND);
2215 if (val != G_ALERTALTERNATE) return;
2216 if (summaryview->sort_type == SORT_ASCENDING)
2217 node = summary_find_next_flagged_msg(summaryview, NULL,
2218 MSG_CLABEL_FLAG_MASK, TRUE);
2219 else
2220 node = summary_find_prev_flagged_msg(summaryview, NULL,
2221 MSG_CLABEL_FLAG_MASK, TRUE);
2224 if (!node)
2225 alertpanel_notice(_("No labeled messages."));
2226 else
2227 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2230 void summary_select_parent(SummaryView *summaryview)
2232 GtkCMCTreeNode *node = NULL;
2234 if (summaryview->selected)
2235 node = GTK_CMCTREE_ROW(summaryview->selected)->parent;
2236 if (node)
2237 summary_select_node(summaryview, node, OPEN_SELECTED_ON_PREVNEXT);
2240 void summary_select_by_msgnum(SummaryView *summaryview, guint msgnum,
2241 gboolean show)
2243 GtkCMCTreeNode *node;
2245 node = summary_find_msg_by_msgnum(summaryview, msgnum);
2246 summary_select_node(summaryview, node, show);
2249 void summary_select_by_msg_list(SummaryView *summaryview, GSList *msginfos)
2251 GtkCMCTree *ctree;
2252 GSList *msgnum_list, *walk;
2253 gboolean froze = FALSE;
2255 ctree = GTK_CMCTREE(summaryview->ctree);
2257 msgnum_list = procmsg_get_number_list_for_msgs(msginfos);
2259 START_LONG_OPERATION(summaryview, FALSE);
2260 for(walk = msgnum_list; walk; walk = walk->next) {
2261 GtkCMCTreeNode *node;
2262 node = summary_find_msg_by_msgnum(summaryview, GPOINTER_TO_UINT(walk->data));
2263 if (node != NULL)
2264 gtk_cmctree_select(ctree, node);
2266 END_LONG_OPERATION(summaryview);
2267 g_slist_free(msgnum_list);
2270 typedef struct _PostponedSelectData
2272 GtkCMCTree *ctree;
2273 GtkCMCTreeNode *row;
2274 GtkCMCTreeNode *node;
2275 GtkScrollType type;
2276 gint column;
2277 SummaryView *summaryview;
2278 gboolean display_msg;
2279 } PostponedSelectData;
2281 static gboolean summary_select_retry(void *data)
2283 PostponedSelectData *psdata = (PostponedSelectData *)data;
2284 debug_print("trying again\n");
2285 if (psdata->row)
2286 summary_selected(psdata->ctree, psdata->row,
2287 psdata->column, psdata->summaryview);
2288 else if (psdata->node)
2289 summary_select_node(psdata->summaryview, psdata->node,
2290 psdata->display_msg);
2291 g_free(psdata);
2292 return FALSE;
2296 * summary_select_node:
2297 * @summaryview: Summary view.
2298 * @node: Summary tree node.
2299 * @display_msg: whether to also display the message
2301 * Select @node (bringing it into view by scrolling and expanding its
2302 * thread, if necessary) and unselect all others.
2305 void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
2306 gboolean display_msg)
2308 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2310 /* If msgview is hidden, we never want to automatically display
2311 * a selected message, since that would unhide the msgview. */
2312 if (!messageview_is_visible(summaryview->messageview))
2313 display_msg = FALSE;
2315 if (summary_is_locked(summaryview)
2316 && !GTK_SCTREE(ctree)->selecting_range
2317 && summaryview->messageview->mimeview
2318 && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
2319 && summaryview->messageview->mimeview->textview->loading) {
2320 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
2321 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
2323 data->ctree = ctree;
2324 data->row = NULL;
2325 data->node = node;
2326 data->summaryview = summaryview;
2327 data->display_msg = display_msg;
2328 debug_print("postponing open of message till end of load\n");
2329 g_timeout_add(100, summary_select_retry, data);
2330 return;
2332 if (summary_is_locked(summaryview)) {
2333 return;
2335 if (!summaryview->folder_item)
2336 return;
2337 if (node) {
2338 gtkut_ctree_expand_parent_all(ctree, node);
2340 summary_lock(summaryview);
2341 GTK_EVENTS_FLUSH();
2342 summary_unlock(summaryview);
2344 /* If quicksearch has focus, let's keep it there. */
2345 if (!quicksearch_has_focus(summaryview->quicksearch) ||
2346 quicksearch_is_running(summaryview->quicksearch))
2347 summary_grab_focus(summaryview);
2349 gtkut_ctree_node_move_if_on_the_edge(ctree, node, -1);
2351 if (display_msg && summaryview->displayed == node)
2352 summaryview->displayed = NULL;
2353 summaryview->display_msg = display_msg;
2354 gtk_sctree_select(GTK_SCTREE(ctree), node);
2355 if (summaryview->selected == NULL)
2356 summaryview->selected = node;
2360 guint summary_get_msgnum(SummaryView *summaryview, GtkCMCTreeNode *node)
2362 GtkCMCTree *ctree =NULL;
2363 MsgInfo *msginfo;
2365 if (!summaryview)
2366 return 0;
2367 ctree = GTK_CMCTREE(summaryview->ctree);
2368 if (!node)
2369 return 0;
2370 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2371 if (msginfo)
2372 return msginfo->msgnum;
2373 else
2374 return -1;
2377 static GtkCMCTreeNode *summary_find_prev_msg(SummaryView *summaryview,
2378 GtkCMCTreeNode *current_node,
2379 gboolean start_from_prev)
2381 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2382 GtkCMCTreeNode *node;
2383 MsgInfo *msginfo;
2385 if (current_node) {
2386 if (start_from_prev)
2387 node = gtkut_ctree_node_prev(ctree, current_node);
2388 else
2389 node = current_node;
2390 } else
2391 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2393 for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2394 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2395 if (msginfo && !MSG_IS_DELETED(msginfo->flags)) break;
2398 return node;
2401 static GtkCMCTreeNode *summary_find_next_msg(SummaryView *summaryview,
2402 GtkCMCTreeNode *current_node,
2403 gboolean start_from_next)
2405 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2406 GtkCMCTreeNode *node;
2407 MsgInfo *msginfo;
2409 if (current_node) {
2410 if (start_from_next)
2411 node = gtkut_ctree_node_next(ctree, current_node);
2412 else
2413 node = current_node;
2414 } else
2415 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2417 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2418 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2419 if (msginfo && !MSG_IS_DELETED(msginfo->flags)
2420 && !MSG_IS_MOVE(msginfo->flags)) break;
2423 return node;
2426 static GtkCMCTreeNode *summary_find_prev_flagged_msg(SummaryView *summaryview,
2427 GtkCMCTreeNode *current_node,
2428 MsgPermFlags flags,
2429 gboolean start_from_prev)
2431 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2432 GtkCMCTreeNode *node;
2433 MsgInfo *msginfo;
2435 if (current_node) {
2436 if (start_from_prev)
2437 node = gtkut_ctree_node_prev(ctree, current_node);
2438 else
2439 node = current_node;
2440 } else
2441 node = gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->rows - 1);
2443 for (; node != NULL; node = gtkut_ctree_node_prev(ctree, node)) {
2444 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2445 if (msginfo && (msginfo->flags.perm_flags & flags) != 0) break;
2448 return node;
2451 static GtkCMCTreeNode *summary_find_next_flagged_msg(SummaryView *summaryview,
2452 GtkCMCTreeNode *current_node,
2453 MsgPermFlags flags,
2454 gboolean start_from_next)
2456 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2457 GtkCMCTreeNode *node;
2458 MsgInfo *msginfo;
2460 if (current_node) {
2461 if (start_from_next)
2462 node = gtkut_ctree_node_next(ctree, current_node);
2463 else
2464 node = current_node;
2465 } else
2466 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2468 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2469 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2470 /* Find msg with matching flags but ignore messages with
2471 ignore flags, if searching for new or unread messages */
2472 if ((msginfo && (msginfo->flags.perm_flags & flags) != 0) &&
2473 !(((flags & (MSG_NEW | MSG_UNREAD)) != 0) && MSG_IS_IGNORE_THREAD(msginfo->flags))
2475 break;
2478 return node;
2481 static GtkCMCTreeNode *summary_find_msg_by_msgnum(SummaryView *summaryview,
2482 guint msgnum)
2484 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2485 GtkCMCTreeNode *node;
2486 MsgInfo *msginfo;
2488 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2490 for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2491 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2492 if (msginfo && msginfo->msgnum == msgnum) break;
2495 return node;
2498 static guint attract_hash_func(gconstpointer key)
2500 gchar *str;
2501 gchar *p;
2502 guint h;
2504 Xstrdup_a(str, (const gchar *)key, return 0);
2505 trim_subject(str);
2507 p = str;
2508 h = *p;
2510 if (h) {
2511 for (p += 1; *p != '\0'; p++)
2512 h = (h << 5) - h + *p;
2515 return h;
2518 static gint attract_compare_func(gconstpointer a, gconstpointer b)
2520 return subject_compare((const gchar *)a, (const gchar *)b) == 0;
2523 void summary_attract_by_subject(SummaryView *summaryview)
2525 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2526 GtkCMCList *clist = GTK_CMCLIST(ctree);
2527 GtkCMCTreeNode *src_node;
2528 GtkCMCTreeNode *dst_node, *sibling;
2529 GtkCMCTreeNode *tmp;
2530 MsgInfo *src_msginfo, *dst_msginfo;
2531 GHashTable *subject_table;
2533 debug_print("Attracting messages by subject...\n");
2534 STATUSBAR_PUSH(summaryview->mainwin,
2535 _("Attracting messages by subject..."));
2537 main_window_cursor_wait(summaryview->mainwin);
2538 summary_freeze(summaryview);
2540 subject_table = g_hash_table_new(attract_hash_func,
2541 attract_compare_func);
2543 for (src_node = GTK_CMCTREE_NODE(clist->row_list);
2544 src_node != NULL;
2545 src_node = tmp) {
2546 tmp = GTK_CMCTREE_ROW(src_node)->sibling;
2547 src_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(src_node);
2548 if (!src_msginfo) continue;
2549 if (!src_msginfo->subject) continue;
2551 /* find attracting node */
2552 dst_node = g_hash_table_lookup(subject_table,
2553 src_msginfo->subject);
2555 if (dst_node) {
2556 dst_msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(dst_node);
2558 /* if the time difference is more than 20 days,
2559 don't attract */
2560 if (ABS(src_msginfo->date_t - dst_msginfo->date_t)
2561 > 60 * 60 * 24 * 20)
2562 continue;
2564 sibling = GTK_CMCTREE_ROW(dst_node)->sibling;
2565 if (src_node != sibling)
2566 gtk_cmctree_move(ctree, src_node, NULL, sibling);
2569 g_hash_table_insert(subject_table,
2570 src_msginfo->subject, src_node);
2573 g_hash_table_destroy(subject_table);
2575 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
2577 summary_thaw(summaryview);
2579 debug_print("Attracting messages by subject done.\n");
2580 STATUSBAR_POP(summaryview->mainwin);
2582 main_window_cursor_normal(summaryview->mainwin);
2585 static void summary_free_msginfo_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2586 gpointer data)
2588 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2590 if (msginfo)
2591 procmsg_msginfo_free(&msginfo);
2594 static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
2595 gpointer data)
2597 SummaryView *summaryview = data;
2598 MsgInfo *msginfo;
2600 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
2602 cm_return_if_fail(msginfo != NULL);
2604 if (MSG_IS_DELETED(msginfo->flags))
2605 summaryview->deleted++;
2607 summaryview->total_size += msginfo->size;
2609 summary_set_row_marks(summaryview, node);
2612 static void summary_update_status(SummaryView *summaryview)
2614 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2615 GtkCMCTreeNode *node;
2616 MsgInfo *msginfo;
2618 summaryview->total_size =
2619 summaryview->deleted = summaryview->moved = summaryview->copied = 0;
2621 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
2622 node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
2623 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
2625 if (!msginfo)
2626 continue;
2628 if (MSG_IS_DELETED(msginfo->flags))
2629 summaryview->deleted++;
2630 if (MSG_IS_MOVE(msginfo->flags))
2631 summaryview->moved++;
2632 if (MSG_IS_COPY(msginfo->flags))
2633 summaryview->copied++;
2634 summaryview->total_size += msginfo->size;
2638 static void summary_status_show(SummaryView *summaryview)
2640 gchar *str;
2641 gchar *del, *mv, *cp;
2642 gchar *sel;
2643 gchar *spc;
2644 gchar *itstr;
2645 GList *rowlist, *cur;
2646 guint n_selected = 0, n_new = 0, n_unread = 0, n_total = 0;
2647 guint n_marked = 0, n_replied = 0, n_forwarded = 0, n_locked = 0, n_ignored = 0, n_watched = 0;
2648 goffset sel_size = 0, n_size = 0;
2649 MsgInfo *msginfo;
2650 gchar *name;
2651 gchar *tooltip;
2653 if (!summaryview->folder_item) {
2654 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), "");
2655 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), "");
2656 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), "");
2657 toolbar_main_set_sensitive(summaryview->mainwin);
2658 return;
2660 gtk_label_set_ellipsize(GTK_LABEL(summaryview->statlabel_folder), PANGO_ELLIPSIZE_END);
2661 gtk_label_set_ellipsize(GTK_LABEL(summaryview->statlabel_select), PANGO_ELLIPSIZE_END);
2662 gtk_label_set_ellipsize(GTK_LABEL(summaryview->statlabel_msgs), PANGO_ELLIPSIZE_START);
2664 rowlist = GTK_CMCLIST(summaryview->ctree)->selection;
2665 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2666 msginfo = gtk_cmctree_node_get_row_data
2667 (GTK_CMCTREE(summaryview->ctree),
2668 GTK_CMCTREE_NODE(cur->data));
2669 if (msginfo) {
2670 sel_size += msginfo->size;
2671 n_selected++;
2675 if (summaryview->folder_item->hide_read_msgs
2676 || summaryview->folder_item->hide_del_msgs
2677 || summaryview->folder_item->hide_read_threads
2678 || quicksearch_has_sat_predicate(summaryview->quicksearch)) {
2679 rowlist = GTK_CMCLIST(summaryview->ctree)->row_list;
2680 for (cur = rowlist; cur != NULL && cur->data != NULL; cur = cur->next) {
2681 msginfo = gtk_cmctree_node_get_row_data
2682 (GTK_CMCTREE(summaryview->ctree),
2683 GTK_CMCTREE_NODE(cur));
2684 if (msginfo) {
2685 n_size += msginfo->size;
2686 n_total++;
2687 if (MSG_IS_NEW(msginfo->flags))
2688 n_new++;
2689 if (MSG_IS_UNREAD(msginfo->flags))
2690 n_unread++;
2691 if (MSG_IS_MARKED(msginfo->flags))
2692 n_marked++;
2693 if (MSG_IS_REPLIED(msginfo->flags))
2694 n_replied++;
2695 if (MSG_IS_FORWARDED(msginfo->flags))
2696 n_forwarded++;
2697 if (MSG_IS_LOCKED(msginfo->flags))
2698 n_locked++;
2699 if (MSG_IS_IGNORE_THREAD(msginfo->flags))
2700 n_ignored++;
2701 if (MSG_IS_WATCH_THREAD(msginfo->flags))
2702 n_watched++;
2705 } else {
2706 n_new = summaryview->folder_item->new_msgs;
2707 n_unread = summaryview->folder_item->unread_msgs;
2708 n_marked = summaryview->folder_item->marked_msgs;
2709 n_replied = summaryview->folder_item->replied_msgs;
2710 n_forwarded = summaryview->folder_item->forwarded_msgs;
2711 n_locked = summaryview->folder_item->locked_msgs;
2712 n_ignored = summaryview->folder_item->ignored_msgs;
2713 n_watched = summaryview->folder_item->watched_msgs;
2714 n_total = summaryview->folder_item->total_msgs;
2715 n_size = summaryview->total_size;
2718 name = folder_item_get_name(summaryview->folder_item);
2719 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
2720 g_free(name);
2722 if (summaryview->deleted)
2723 del = g_strdup_printf(_("%d deleted"), summaryview->deleted);
2724 else
2725 del = g_strdup("");
2726 if (summaryview->moved)
2727 mv = g_strdup_printf(_("%s%d moved"),
2728 summaryview->deleted ? _(", ") : "",
2729 summaryview->moved);
2730 else
2731 mv = g_strdup("");
2732 if (summaryview->copied)
2733 cp = g_strdup_printf(_("%s%d copied"),
2734 summaryview->deleted ||
2735 summaryview->moved ? _(", ") : "",
2736 summaryview->copied);
2737 else
2738 cp = g_strdup("");
2740 if (summaryview->deleted || summaryview->moved || summaryview->copied)
2741 spc = " ";
2742 else
2743 spc = "";
2745 if (n_selected) {
2746 sel = g_strdup_printf(" (%s)", to_human_readable((goffset)sel_size));
2747 itstr = g_strdup_printf(ngettext(" item selected"," items selected", n_selected));
2748 } else {
2749 sel = g_strdup("");
2750 itstr = g_strdup("");
2753 if (prefs_common.layout_mode != SMALL_LAYOUT) {
2754 str = g_strconcat(n_selected ? itos(n_selected) : "",
2755 itstr, sel, spc, del, mv, cp, NULL);
2756 g_free(sel);
2757 g_free(del);
2758 g_free(mv);
2759 g_free(cp);
2760 g_free(itstr);
2762 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2763 g_free(str);
2765 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2766 n_new, n_unread, n_total,
2767 to_human_readable((goffset)n_size));
2769 g_signal_connect(G_OBJECT(summaryview->popupmenu), "selection-done",
2770 G_CALLBACK(popup_menu_selection_done), summaryview);
2772 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_msgs), str);
2773 g_free(str);
2774 tooltip = g_strdup_printf("<b>%s</b>\n"
2775 "<b>%s</b> %d\n"
2776 "<b>%s</b> %d\n"
2777 "<b>%s</b> %d\n"
2778 "<b>%s</b> %s\n\n"
2779 "<b>%s</b> %d\n"
2780 "<b>%s</b> %d\n"
2781 "<b>%s</b> %d\n"
2782 "<b>%s</b> %d\n"
2783 "<b>%s</b> %d\n"
2784 "<b>%s</b> %d",
2785 _("Message summary"),
2786 _("New:"), n_new,
2787 _("Unread:"), n_unread,
2788 _("Total:"), n_total,
2789 _("Size:"), to_human_readable((goffset)n_size),
2790 _("Marked:"), n_marked,
2791 _("Replied:"), n_replied,
2792 _("Forwarded:"), n_forwarded,
2793 _("Locked:"), n_locked,
2794 _("Ignored:"), n_ignored,
2795 _("Watched:"), n_watched);
2797 gtk_widget_set_tooltip_markup(GTK_WIDGET(summaryview->statlabel_msgs),
2798 tooltip);
2799 g_free(tooltip);
2800 } else {
2801 gchar *ssize, *tsize;
2802 if (n_selected) {
2803 ssize = g_strdup(to_human_readable((goffset)sel_size));
2804 tsize = g_strdup(to_human_readable((goffset)n_size));
2805 str = g_strdup_printf(_("%d/%d selected (%s/%s), %d unread"),
2806 n_selected, n_total, ssize, tsize, n_unread);
2807 g_free(ssize);
2808 g_free(tsize);
2809 } else
2810 str = g_strdup_printf(_("%d new, %d unread, %d total (%s)"),
2811 n_new, n_unread, n_total, to_human_readable((goffset)n_size));
2812 g_free(sel);
2813 g_free(del);
2814 g_free(mv);
2815 g_free(cp);
2816 g_free(itstr);
2818 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_select), str);
2819 g_free(str);
2822 summary_set_menu_sensitive(summaryview);
2823 toolbar_main_set_sensitive(summaryview->mainwin);
2826 static void summary_set_column_titles(SummaryView *summaryview)
2828 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
2829 FolderItem *item = summaryview->folder_item;
2830 GtkWidget *hbox;
2831 GtkWidget *label;
2832 GtkWidget *arrow;
2833 gint pos;
2834 const gchar *title;
2835 SummaryColumnType type;
2836 GtkJustification justify;
2838 static FolderSortKey sort_by[N_SUMMARY_COLS] = {
2839 SORT_BY_MARK,
2840 SORT_BY_STATUS,
2841 SORT_BY_MIME,
2842 SORT_BY_SUBJECT,
2843 SORT_BY_FROM,
2844 SORT_BY_TO,
2845 SORT_BY_DATE,
2846 SORT_BY_SIZE,
2847 SORT_BY_NUMBER,
2848 SORT_BY_SCORE,
2849 SORT_BY_LOCKED,
2850 SORT_BY_TAGS
2853 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
2854 type = summaryview->col_state[pos].type;
2856 /* CLAWS: mime and unread are single char headers */
2857 justify = (type == S_COL_NUMBER || type == S_COL_SIZE)
2858 ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT;
2860 switch (type) {
2861 case S_COL_SUBJECT:
2862 case S_COL_FROM:
2863 case S_COL_TO:
2864 case S_COL_DATE:
2865 case S_COL_NUMBER:
2866 if(type == S_COL_FROM && item != NULL &&
2867 FOLDER_SHOWS_TO_HDR(item) &&
2868 !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
2869 type = S_COL_TO;
2870 if(type == S_COL_NUMBER)
2871 title = gettext(col_label[type]);
2872 else
2873 title = prefs_common_translated_header_name(col_label[type]);
2874 break;
2875 default:
2876 title = gettext(col_label[type]);
2879 if (type == S_COL_MIME) {
2880 label = gtk_image_new_from_pixbuf(clipxpm);
2881 gtk_widget_show(label);
2882 gtk_cmclist_set_column_widget(clist, pos, label);
2883 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Attachment"));
2884 continue;
2885 } else if (type == S_COL_MARK) {
2886 label = gtk_image_new_from_pixbuf(markxpm);
2887 gtk_widget_show(label);
2888 gtk_cmclist_set_column_widget(clist, pos, label);
2889 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, C_("Column Header", "_Mark"));
2890 continue;
2891 } else if (type == S_COL_LOCKED) {
2892 label = gtk_image_new_from_pixbuf(lockedxpm);
2893 gtk_widget_show(label);
2894 gtk_cmclist_set_column_widget(clist, pos, label);
2895 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Locked"));
2896 continue;
2897 } else if (type == S_COL_STATUS) {
2898 gtk_cmclist_set_column_title(clist, pos, title);
2899 gtk_sctree_set_column_tooltip(GTK_SCTREE(clist), pos, _("Status"));
2900 continue;
2903 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
2904 label = gtk_label_new(title);
2905 #ifdef GENERIC_UMPC
2906 gtk_widget_set_size_request(hbox, -1, 20);
2907 #endif
2909 if (justify == GTK_JUSTIFY_RIGHT)
2910 gtk_box_pack_end(GTK_BOX(hbox), label,
2911 FALSE, FALSE, 0);
2912 else
2913 gtk_box_pack_start(GTK_BOX(hbox), label,
2914 FALSE, FALSE, 0);
2916 if (summaryview->sort_key == sort_by[type] ||
2917 (summaryview->sort_key == SORT_BY_THREAD_DATE &&
2918 sort_by[SORT_BY_DATE] && type == S_COL_DATE)) {
2919 arrow = gtk_image_new_from_icon_name
2920 (summaryview->sort_type == SORT_ASCENDING
2921 ? "pan-down-symbolic" : "pan-up-symbolic",
2922 GTK_ICON_SIZE_MENU);
2923 gtk_widget_set_size_request(GTK_WIDGET(arrow), 10, 10);
2924 if (justify == GTK_JUSTIFY_RIGHT)
2925 gtk_box_pack_start(GTK_BOX(hbox), arrow,
2926 FALSE, FALSE, 0);
2927 else
2928 gtk_box_pack_end(GTK_BOX(hbox), arrow,
2929 FALSE, FALSE, 0);
2932 gtk_widget_show_all(hbox);
2933 gtk_cmclist_set_column_widget(clist, pos, hbox);
2937 void summary_reflect_tags_changes(SummaryView *summaryview)
2939 GtkMenuShell *menu;
2940 GList *children, *cur;
2941 GtkCMCTreeNode *node;
2942 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
2943 gboolean froze = FALSE;
2944 gboolean redisplay = FALSE;
2946 /* re-create colorlabel submenu */
2947 menu = GTK_MENU_SHELL(summaryview->tags_menu);
2948 cm_return_if_fail(menu != NULL);
2950 /* clear items. get item pointers. */
2951 children = gtk_container_get_children(GTK_CONTAINER(menu));
2952 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
2953 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
2955 g_list_free(children);
2956 summary_tags_menu_create(summaryview, TRUE);
2958 START_LONG_OPERATION(summaryview, TRUE);
2959 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
2960 node = gtkut_ctree_node_next(ctree, node)) {
2961 redisplay |= summary_set_row_tag(summaryview,
2962 node, TRUE, FALSE, 0);
2964 END_LONG_OPERATION(summaryview);
2965 if (redisplay)
2966 summary_redisplay_msg(summaryview);
2970 void summary_reflect_prefs(void)
2972 static gchar *last_smallfont = NULL;
2973 static gchar *last_normalfont = NULL;
2974 static gchar *last_boldfont = NULL;
2975 static gboolean last_derive = 0;
2976 gboolean update_font = FALSE;
2977 SummaryView *summaryview = NULL;
2979 if (!mainwindow_get_mainwindow())
2980 return;
2981 summaryview = mainwindow_get_mainwindow()->summaryview;
2983 if (!last_smallfont || strcmp(last_smallfont, SMALL_FONT) ||
2984 !last_normalfont || strcmp(last_normalfont, NORMAL_FONT) ||
2985 !last_boldfont || strcmp(last_boldfont, BOLD_FONT) ||
2986 last_derive != prefs_common.derive_from_normal_font)
2987 update_font = TRUE;
2989 g_free(last_smallfont);
2990 last_smallfont = g_strdup(SMALL_FONT);
2991 g_free(last_normalfont);
2992 last_normalfont = g_strdup(NORMAL_FONT);
2993 g_free(last_boldfont);
2994 last_boldfont = g_strdup(BOLD_FONT);
2995 last_derive = prefs_common.derive_from_normal_font;
2997 #define STYLE_FREE(s) \
2998 if (s != NULL) { \
2999 g_object_unref(s); \
3000 s = NULL; \
3003 if (update_font) {
3004 STYLE_FREE(bold_style);
3005 STYLE_FREE(bold_style);
3006 summary_set_fonts(summaryview);
3009 #undef STYLE_FREE
3011 summary_set_column_titles(summaryview);
3012 summary_relayout(summaryview);
3014 if (summaryview->folder_item)
3015 summary_show(summaryview, summaryview->folder_item, FALSE);
3018 void summary_sort(SummaryView *summaryview,
3019 FolderSortKey sort_key, FolderSortType sort_type)
3021 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3022 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
3023 GtkCMCListCompareFunc cmp_func = NULL;
3024 START_TIMING("");
3025 g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
3026 G_CALLBACK(summary_tree_expanded), summaryview);
3027 summary_freeze(summaryview);
3029 switch (sort_key) {
3030 case SORT_BY_MARK:
3031 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mark;
3032 break;
3033 case SORT_BY_STATUS:
3034 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_status;
3035 break;
3036 case SORT_BY_MIME:
3037 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_mime;
3038 break;
3039 case SORT_BY_NUMBER:
3040 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_num;
3041 break;
3042 case SORT_BY_SIZE:
3043 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_size;
3044 break;
3045 case SORT_BY_DATE:
3046 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_date;
3047 break;
3048 case SORT_BY_THREAD_DATE:
3049 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_thread_date;
3050 break;
3051 case SORT_BY_FROM:
3052 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_from;
3053 break;
3054 case SORT_BY_SUBJECT:
3055 if (summaryview->simplify_subject_preg)
3056 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_simplified_subject;
3057 else
3058 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_subject;
3059 break;
3060 case SORT_BY_SCORE:
3061 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_score;
3062 break;
3063 case SORT_BY_LABEL:
3064 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_label;
3065 break;
3066 case SORT_BY_TO:
3067 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_to;
3068 break;
3069 case SORT_BY_LOCKED:
3070 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_locked;
3071 break;
3072 case SORT_BY_TAGS:
3073 cmp_func = (GtkCMCListCompareFunc)summary_cmp_by_tags;
3074 break;
3075 case SORT_BY_NONE:
3076 break;
3077 default:
3078 goto unlock;
3081 summaryview->sort_key = sort_key;
3082 summaryview->sort_type = sort_type;
3084 summary_set_column_titles(summaryview);
3085 summary_set_menu_sensitive(summaryview);
3087 /* allow fallback to don't sort */
3088 if (summaryview->sort_key == SORT_BY_NONE)
3089 goto unlock;
3091 if (cmp_func != NULL) {
3092 debug_print("Sorting summary...\n");
3093 STATUSBAR_PUSH(summaryview->mainwin, _("Sorting summary..."));
3095 main_window_cursor_wait(summaryview->mainwin);
3097 gtk_cmclist_set_compare_func(clist, cmp_func);
3099 gtk_cmclist_set_sort_type(clist, (GtkSortType)sort_type);
3100 gtk_sctree_sort_recursive(ctree, NULL);
3102 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
3104 main_window_cursor_normal(summaryview->mainwin);
3106 debug_print("Sorting summary done.\n");
3107 STATUSBAR_POP(summaryview->mainwin);
3109 unlock:
3110 summary_thaw(summaryview);
3111 g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
3112 G_CALLBACK(summary_tree_expanded), summaryview);
3113 END_TIMING();
3116 static gboolean summary_update_thread_age(GNode *node, gpointer data)
3118 MsgInfo *msginfo = node->data;
3119 time_t *most_recent = (time_t *)data;
3121 if (msginfo->date_t > *most_recent) {
3122 *most_recent = msginfo->date_t;
3124 return FALSE;
3127 static void summary_find_thread_age(GNode *gnode)
3129 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3130 time_t most_recent;
3132 if (!msginfo)
3133 return;
3134 most_recent = msginfo->thread_date = msginfo->date_t;
3136 g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_thread_age, &most_recent);
3138 msginfo->thread_date = most_recent;
3141 static gboolean summary_update_is_read(GNode *node, gpointer data)
3143 MsgInfo *msginfo = node->data;
3144 gboolean *all_read = (gboolean *)data;
3146 if (MSG_IS_UNREAD(msginfo->flags)) {
3147 *all_read = FALSE;
3148 return TRUE;
3150 return FALSE;
3153 static gboolean summary_thread_is_read(GNode *gnode)
3155 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3156 gboolean all_read = TRUE;
3158 if (!msginfo)
3159 return all_read;
3161 g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1, summary_update_is_read, &all_read);
3162 return all_read;
3165 typedef struct _ThreadSelectedData {
3166 guint msgnum;
3167 gboolean is_selected;
3168 } ThreadSelectedData;
3170 static gboolean summary_update_is_selected(GNode *gnode, gpointer data)
3172 ThreadSelectedData *selected = (ThreadSelectedData *)data;
3173 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3175 if (msginfo->msgnum == selected->msgnum) {
3176 selected->is_selected = TRUE;
3177 return TRUE;
3180 return FALSE;
3183 static gboolean summary_thread_is_selected(GNode *gnode, guint selected_msgnum)
3185 ThreadSelectedData selected;
3187 selected.msgnum = selected_msgnum;
3188 selected.is_selected = FALSE;
3189 g_node_traverse(gnode, G_IN_ORDER, G_TRAVERSE_ALL, -1,
3190 summary_update_is_selected, &selected);
3191 return selected.is_selected;
3194 static gboolean summary_insert_gnode_func(GtkCMCTree *ctree, guint depth, GNode *gnode,
3195 GtkCMCTreeNode *cnode, gpointer data)
3197 SummaryView *summaryview = (SummaryView *)data;
3198 MsgInfo *msginfo = (MsgInfo *)gnode->data;
3199 gchar *text[N_SUMMARY_COLS];
3200 gint *col_pos = summaryview->col_pos;
3201 const gchar *msgid = msginfo->msgid;
3202 GHashTable *msgid_table = summaryview->msgid_table;
3203 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3204 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3206 summary_set_header(summaryview, text, msginfo);
3208 gtk_cmctree_set_node_info(ctree, cnode, text[col_pos[S_COL_SUBJECT]], 2,
3209 NULL, NULL, FALSE, summaryview->threaded && !summaryview->thread_collapsed);
3210 #define SET_TEXT(col) { \
3211 gtk_cmctree_node_set_text(ctree, cnode, col_pos[col], \
3212 text[col_pos[col]]); \
3215 if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3216 SET_TEXT(S_COL_NUMBER);
3217 if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3218 SET_TEXT(S_COL_SCORE);
3219 if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3220 SET_TEXT(S_COL_SIZE);
3221 if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible)
3222 SET_TEXT(S_COL_DATE);
3223 if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
3224 SET_TEXT(S_COL_FROM);
3225 if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
3226 SET_TEXT(S_COL_TO);
3227 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible)
3228 SET_TEXT(S_COL_TAGS);
3230 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3231 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3233 #undef SET_TEXT
3235 GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
3236 summary_set_marks_func(ctree, cnode, summaryview);
3238 if (msgid && msgid[0] != '\0')
3239 g_hash_table_insert(msgid_table, (gchar *)msgid, cnode);
3241 return TRUE;
3244 static void summary_set_ctree_from_list(SummaryView *summaryview,
3245 GSList *mlist, guint selected_msgnum)
3247 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3248 MsgInfo *msginfo;
3249 GtkCMCTreeNode *node = NULL;
3250 GHashTable *msgid_table;
3251 GHashTable *subject_table = NULL;
3252 GSList * cur;
3253 GdkDisplay *display;
3255 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3256 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3257 START_TIMING("");
3259 if (!mlist) return;
3261 display = gdk_display_get_default();
3263 debug_print("Setting summary from message data...\n");
3264 STATUSBAR_PUSH(summaryview->mainwin,
3265 _("Setting summary from message data..."));
3266 gdk_display_flush(display);
3268 g_signal_handlers_block_by_func(G_OBJECT(ctree),
3269 G_CALLBACK(summary_tree_expanded), summaryview);
3271 msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
3272 summaryview->msgid_table = msgid_table;
3274 if (prefs_common.thread_by_subject) {
3275 subject_table = g_hash_table_new(g_str_hash, g_str_equal);
3276 summaryview->subject_table = subject_table;
3277 } else {
3278 summaryview->subject_table = NULL;
3281 if (prefs_common.use_addr_book)
3282 start_address_completion(NULL);
3284 if (summaryview->threaded) {
3285 GNode *root, *gnode;
3286 START_TIMING("threaded");
3287 root = procmsg_get_thread_tree(mlist);
3290 for (gnode = root->children; gnode != NULL;
3291 gnode = gnode->next) {
3292 if (!summaryview->folder_item->hide_read_threads ||
3293 !summary_thread_is_read(gnode) ||
3294 summary_thread_is_selected(gnode, selected_msgnum)) {
3295 summary_find_thread_age(gnode);
3296 node = gtk_sctree_insert_gnode
3297 (ctree, NULL, node, gnode,
3298 summary_insert_gnode_func, summaryview);
3302 g_node_destroy(root);
3304 END_TIMING();
3305 } else {
3306 gchar *text[N_SUMMARY_COLS];
3307 START_TIMING("unthreaded");
3308 cur = mlist;
3309 for (; mlist != NULL; mlist = mlist->next) {
3310 msginfo = (MsgInfo *)mlist->data;
3312 summary_set_header(summaryview, text, msginfo);
3314 node = gtk_sctree_insert_node
3315 (ctree, NULL, node, text, 2,
3316 NULL, NULL,
3317 FALSE, FALSE);
3318 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
3319 g_free(text[summaryview->col_pos[S_COL_SUBJECT]]);
3321 GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
3322 summary_set_marks_func(ctree, node, summaryview);
3324 if (msginfo->msgid && msginfo->msgid[0] != '\0')
3325 g_hash_table_insert(msgid_table,
3326 msginfo->msgid, node);
3328 if (prefs_common.thread_by_subject)
3329 subject_table_insert(subject_table,
3330 msginfo->subject,
3331 node);
3333 mlist = cur;
3334 END_TIMING();
3337 if (prefs_common.enable_hscrollbar &&
3338 summaryview->col_pos[S_COL_SUBJECT] == N_SUMMARY_COLS - 1) {
3339 gint optimal_width;
3341 optimal_width = gtk_cmclist_optimal_column_width
3342 (GTK_CMCLIST(ctree), summaryview->col_pos[S_COL_SUBJECT]);
3343 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree),
3344 summaryview->col_pos[S_COL_SUBJECT],
3345 optimal_width);
3348 if (prefs_common.use_addr_book)
3349 end_address_completion();
3351 debug_print("Setting summary from message data done.\n");
3352 STATUSBAR_POP(summaryview->mainwin);
3353 if (debug_get_mode()) {
3354 debug_print("\tmsgid hash table size = %d\n",
3355 g_hash_table_size(msgid_table));
3356 if (prefs_common.thread_by_subject)
3357 debug_print("\tsubject hash table size = %d\n",
3358 g_hash_table_size(subject_table));
3361 summary_sort(summaryview, summaryview->sort_key, summaryview->sort_type);
3363 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3365 if (prefs_common.bold_unread || prefs_common.bold_marked) {
3366 START_TIMING("bold_unread/bold_marked");
3367 while (node) {
3368 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
3369 if (GTK_CMCTREE_ROW(node)->children)
3370 summary_set_row_marks(summaryview, node);
3371 node = next;
3373 END_TIMING();
3376 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
3377 G_CALLBACK(summary_tree_expanded), summaryview);
3378 END_TIMING();
3381 static gchar *summary_complete_address(const gchar *addr)
3383 gint count;
3384 gchar *res, *tmp, *email_addr;
3386 if (addr == NULL || !strchr(addr, '@'))
3387 return NULL;
3389 Xstrdup_a(email_addr, addr, return NULL);
3390 extract_address(email_addr);
3391 if (!*email_addr)
3392 return NULL;
3395 * completion stuff must be already initialized
3397 res = NULL;
3398 if (1 < (count = complete_address(email_addr))) {
3399 tmp = get_complete_address(1);
3400 res = procheader_get_fromname(tmp);
3401 g_free(tmp);
3404 return res;
3407 static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
3408 MsgInfo *msginfo)
3410 static gchar date_modified[80];
3411 static gchar col_score[11];
3412 static gchar from_buf[BUFFSIZE], to_buf[BUFFSIZE];
3413 static gchar tmp1[BUFFSIZE], tmp2[BUFFSIZE+4], tmp3[BUFFSIZE];
3414 gint *col_pos = summaryview->col_pos;
3415 gchar *from_text = NULL, *to_text = NULL, *tags_text = NULL;
3416 gboolean should_swap = FALSE;
3417 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
3418 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
3419 static const gchar *color_dim_rgb = NULL;
3420 if (!color_dim_rgb)
3421 color_dim_rgb = gtkut_gdk_rgba_to_string(&summaryview->color_dim);
3422 text[col_pos[S_COL_FROM]] = "";
3423 text[col_pos[S_COL_TO]] = "";
3424 text[col_pos[S_COL_SUBJECT]]= "";
3425 text[col_pos[S_COL_MARK]] = "";
3426 text[col_pos[S_COL_STATUS]] = "";
3427 text[col_pos[S_COL_MIME]] = "";
3428 text[col_pos[S_COL_LOCKED]] = "";
3429 text[col_pos[S_COL_DATE]] = "";
3430 text[col_pos[S_COL_TAGS]] = "";
3431 if (summaryview->col_state[summaryview->col_pos[S_COL_NUMBER]].visible)
3432 text[col_pos[S_COL_NUMBER]] = itos(msginfo->msgnum);
3433 else
3434 text[col_pos[S_COL_NUMBER]] = "";
3436 /* slow! */
3437 if (summaryview->col_state[summaryview->col_pos[S_COL_SIZE]].visible)
3438 text[col_pos[S_COL_SIZE]] = to_human_readable(msginfo->size);
3439 else
3440 text[col_pos[S_COL_SIZE]] = "";
3442 if (summaryview->col_state[summaryview->col_pos[S_COL_SCORE]].visible)
3443 text[col_pos[S_COL_SCORE]] = itos_buf(col_score, msginfo->score);
3444 else
3445 text[col_pos[S_COL_SCORE]] = "";
3447 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
3448 tags_text = procmsg_msginfo_get_tags_str(msginfo);
3449 if (!tags_text) {
3450 text[col_pos[S_COL_TAGS]] = "-";
3451 } else {
3452 strncpy2(tmp1, tags_text, sizeof(tmp1));
3453 tmp1[sizeof(tmp1)-1]='\0';
3454 g_free(tags_text);
3455 text[col_pos[S_COL_TAGS]] = tmp1;
3457 } else
3458 text[col_pos[S_COL_TAGS]] = "";
3460 /* slow! */
3461 if (summaryview->col_state[summaryview->col_pos[S_COL_DATE]].visible ||
3462 ((vert_layout || small_layout) && prefs_common.two_line_vert)) {
3463 if (msginfo->date_t && msginfo->date_t > 0) {
3464 procheader_date_get_localtime(date_modified,
3465 sizeof(date_modified),
3466 msginfo->date_t);
3467 text[col_pos[S_COL_DATE]] = date_modified;
3468 } else if (msginfo->date)
3469 text[col_pos[S_COL_DATE]] = msginfo->date;
3470 else
3471 text[col_pos[S_COL_DATE]] = _("(No Date)");
3474 if (prefs_common.swap_from && msginfo->from && msginfo->to
3475 && !summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible) {
3476 gchar *addr = NULL;
3478 addr = g_strdup(msginfo->from);
3480 if (addr) {
3481 extract_address(addr);
3482 if (account_find_from_address(addr, FALSE)) {
3483 should_swap = TRUE;
3485 g_free(addr);
3489 if (!prefs_common.use_addr_book) {
3490 if (prefs_common.summary_from_show == SHOW_NAME)
3491 from_text = msginfo->fromname;
3492 else if (prefs_common.summary_from_show == SHOW_BOTH)
3493 from_text = msginfo->from;
3494 else {
3495 from_text = msginfo->from;
3496 extract_address(from_text);
3498 if (!from_text)
3499 from_text = _("(No From)");
3500 } else {
3501 gchar *tmp = summary_complete_address(msginfo->from);
3502 if (tmp) {
3503 strncpy2(from_buf, tmp, sizeof(from_buf));
3504 g_free(tmp);
3505 from_text = from_buf;
3506 } else {
3507 if (prefs_common.summary_from_show == SHOW_NAME)
3508 from_text = msginfo->fromname;
3509 else if (prefs_common.summary_from_show == SHOW_BOTH)
3510 from_text = msginfo->from;
3511 else {
3512 from_text = msginfo->from;
3513 if (from_text)
3514 extract_address(from_text);
3516 if (!from_text)
3517 from_text = _("(No From)");
3521 to_text = msginfo->to ? msginfo->to :
3522 (msginfo->cc ? msginfo->cc :
3523 (msginfo->newsgroups ? msginfo->newsgroups : NULL
3527 if (!to_text)
3528 to_text = _("(No Recipient)");
3529 else {
3530 if (prefs_common.summary_from_show == SHOW_NAME) {
3531 gchar *tmp = procheader_get_fromname(to_text);
3532 /* need to keep to_text pointing to stack, so heap-allocated
3533 * string from procheader_get_fromname() will be copied to to_buf */
3534 if (tmp != NULL) {
3535 strncpy2(to_buf, tmp, sizeof(to_buf));
3536 g_free(tmp);
3537 to_text = to_buf;
3539 } else if (prefs_common.summary_from_show == SHOW_ADDR)
3540 extract_address(to_text);
3543 text[col_pos[S_COL_TO]] = to_text;
3544 if (!should_swap) {
3545 text[col_pos[S_COL_FROM]] = from_text;
3546 } else {
3547 if (prefs_common.use_addr_book) {
3548 gchar *tmp = summary_complete_address(to_text);
3549 /* need to keep to_text pointing to stack, so heap-allocated
3550 * string from summary_complete_address() will be copied to to_buf */
3551 if (tmp) {
3552 strncpy2(to_buf, tmp, sizeof(to_buf));
3553 g_free(tmp);
3554 to_text = to_buf;
3555 } else {
3556 to_text = to_text ? to_text : _("(No From)");
3559 snprintf(tmp2, BUFFSIZE+4, "➜ %s", to_text);
3560 tmp2[BUFFSIZE-1]='\0';
3561 text[col_pos[S_COL_FROM]] = tmp2;
3564 if (summaryview->simplify_subject_preg != NULL)
3565 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ?
3566 string_remove_match(tmp3, BUFFSIZE, msginfo->subject,
3567 summaryview->simplify_subject_preg) :
3568 _("(No Subject)");
3569 else
3570 text[col_pos[S_COL_SUBJECT]] = msginfo->subject ? msginfo->subject :
3571 _("(No Subject)");
3572 if ((vert_layout || small_layout) && prefs_common.two_line_vert) {
3573 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) {
3574 gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3575 "<span color='%s' style='italic'>",
3576 _("From: %s, on %s"), "</span>", NULL),
3577 text[col_pos[S_COL_SUBJECT]],
3578 color_dim_rgb,
3579 text[col_pos[S_COL_FROM]],
3580 text[col_pos[S_COL_DATE]]);
3581 text[col_pos[S_COL_SUBJECT]] = tmp;
3582 } else {
3583 gchar *tmp = g_markup_printf_escaped(g_strconcat("%s\n",
3584 "<span color='%s' style='italic'>",
3585 _("To: %s, on %s"), "</span>", NULL),
3586 text[col_pos[S_COL_SUBJECT]],
3587 color_dim_rgb,
3588 text[col_pos[S_COL_TO]],
3589 text[col_pos[S_COL_DATE]]);
3590 text[col_pos[S_COL_SUBJECT]] = tmp;
3595 static void summary_display_msg(SummaryView *summaryview, GtkCMCTreeNode *row)
3597 summary_display_msg_full(summaryview, row, FALSE, FALSE);
3600 static gboolean defer_change(gpointer data);
3601 typedef enum {
3602 FLAGS_UNSET,
3603 FLAGS_SET,
3604 FLAGS_CHANGE
3605 } ChangeType;
3606 typedef struct _ChangeData {
3607 MsgInfo *info;
3608 ChangeType op;
3609 MsgPermFlags set_flags;
3610 MsgTmpFlags set_tmp_flags;
3611 MsgPermFlags unset_flags;
3612 MsgTmpFlags unset_tmp_flags;
3613 } ChangeData;
3615 static void summary_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3617 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3618 debug_print("flags: doing unset now\n");
3619 procmsg_msginfo_unset_flags(msginfo, flags, tmp_flags);
3620 } else {
3621 ChangeData *unset_data = g_new0(ChangeData, 1);
3622 unset_data->info = msginfo;
3623 unset_data->op = FLAGS_UNSET;
3624 unset_data->unset_flags = flags;
3625 unset_data->unset_tmp_flags = tmp_flags;
3626 debug_print("flags: deferring unset\n");
3627 g_timeout_add(100, defer_change, unset_data);
3631 static void summary_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags flags, MsgTmpFlags tmp_flags)
3633 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3634 debug_print("flags: doing set now\n");
3635 procmsg_msginfo_set_flags(msginfo, flags, tmp_flags);
3636 } else {
3637 ChangeData *set_data = g_new0(ChangeData, 1);
3638 set_data->info = msginfo;
3639 set_data->op = FLAGS_SET;
3640 set_data->set_flags = flags;
3641 set_data->set_tmp_flags = tmp_flags;
3642 debug_print("flags: deferring set\n");
3643 g_timeout_add(100, defer_change, set_data);
3647 static void summary_msginfo_change_flags(MsgInfo *msginfo,
3648 MsgPermFlags add_flags, MsgTmpFlags add_tmp_flags,
3649 MsgPermFlags rem_flags, MsgTmpFlags rem_tmp_flags)
3651 if (!msginfo->folder || !msginfo->folder->processing_pending) {
3652 debug_print("flags: doing change now\n");
3653 procmsg_msginfo_change_flags(msginfo, add_flags, add_tmp_flags,
3654 rem_flags, rem_tmp_flags);
3655 } else {
3656 ChangeData *change_data = g_new0(ChangeData, 1);
3657 change_data->info = msginfo;
3658 change_data->op = FLAGS_CHANGE;
3659 change_data->set_flags = add_flags;
3660 change_data->set_tmp_flags = add_tmp_flags;
3661 change_data->unset_flags = rem_flags;
3662 change_data->unset_tmp_flags = rem_tmp_flags;
3663 debug_print("flags: deferring change\n");
3664 g_timeout_add(100, defer_change, change_data);
3668 gboolean defer_change(gpointer data)
3670 ChangeData *chg = (ChangeData *)data;
3671 if (chg->info->folder && chg->info->folder->processing_pending) {
3672 debug_print("flags: trying later\n");
3673 return TRUE; /* try again */
3674 } else {
3675 debug_print("flags: finally doing it\n");
3676 switch(chg->op) {
3677 case FLAGS_UNSET:
3678 procmsg_msginfo_unset_flags(chg->info, chg->unset_flags, chg->unset_tmp_flags);
3679 break;
3680 case FLAGS_SET:
3681 procmsg_msginfo_set_flags(chg->info, chg->set_flags, chg->set_tmp_flags);
3682 break;
3683 case FLAGS_CHANGE:
3684 procmsg_msginfo_change_flags(chg->info, chg->set_flags, chg->set_tmp_flags,
3685 chg->unset_flags, chg->unset_tmp_flags);
3686 break;
3687 default:
3688 g_warning("unknown change op");
3690 g_free(chg);
3692 return FALSE;
3695 static void msginfo_mark_as_read (SummaryView *summaryview, MsgInfo *msginfo,
3696 GtkCMCTreeNode *row)
3698 cm_return_if_fail(summaryview != NULL);
3699 cm_return_if_fail(msginfo != NULL);
3700 cm_return_if_fail(row != NULL);
3702 if (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)) {
3703 summary_msginfo_unset_flags
3704 (msginfo, MSG_NEW | MSG_UNREAD, 0);
3705 summary_set_row_marks(summaryview, row);
3706 summary_status_show(summaryview);
3710 typedef struct {
3711 MsgInfo *msginfo;
3712 SummaryView *summaryview;
3713 } MarkAsReadData;
3715 static int msginfo_mark_as_read_timeout(void *data)
3717 MarkAsReadData *mdata = (MarkAsReadData *)data;
3718 if (!mdata)
3719 return FALSE;
3721 summary_lock(mdata->summaryview);
3722 if (mdata->msginfo == summary_get_selected_msg(mdata->summaryview))
3723 msginfo_mark_as_read(mdata->summaryview, mdata->msginfo,
3724 mdata->summaryview->selected);
3725 procmsg_msginfo_free(&(mdata->msginfo));
3727 mdata->summaryview->mark_as_read_timeout_tag = 0;
3728 summary_unlock(mdata->summaryview);
3730 g_free(mdata);
3731 return FALSE;
3734 static void summary_display_msg_full(SummaryView *summaryview,
3735 GtkCMCTreeNode *row,
3736 gboolean new_window, gboolean all_headers)
3738 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3739 MsgInfo *msginfo;
3740 gint val;
3741 START_TIMING("");
3742 if (!new_window) {
3743 if (summaryview->displayed == row &&
3744 messageview_is_visible(summaryview->messageview))
3745 return;
3746 else if (summaryview->messageview)
3747 summaryview->messageview->filtered = FALSE;
3749 cm_return_if_fail(row != NULL);
3751 if (summary_is_locked(summaryview)) return;
3752 summary_lock(summaryview);
3754 STATUSBAR_POP(summaryview->mainwin);
3755 GTK_EVENTS_FLUSH();
3757 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3759 if (!msginfo) {
3760 debug_print("NULL msginfo\n");
3761 summary_unlock(summaryview);
3762 END_TIMING();
3763 return;
3766 if (new_window && prefs_common.layout_mode != SMALL_LAYOUT) {
3767 MessageView *msgview;
3769 msgview = messageview_create_with_new_window(summaryview->mainwin);
3770 val = messageview_show(msgview, msginfo, all_headers);
3771 } else {
3772 MessageView *msgview;
3774 if (prefs_common.layout_mode == SMALL_LAYOUT) {
3775 if (summaryview->ext_messageview == NULL)
3776 summaryview->ext_messageview = messageview_create_with_new_window(summaryview->mainwin);
3777 else
3778 gtkut_window_popup(summaryview->ext_messageview->window);
3779 msgview = summaryview->ext_messageview;
3780 summaryview->displayed = row;
3781 val = messageview_show(msgview, msginfo, all_headers);
3782 if (mimeview_tree_is_empty(msgview->mimeview))
3783 gtk_widget_grab_focus(summaryview->ctree);
3784 gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3785 GTK_CMCLIST(summaryview->ctree)->focus_row);
3786 } else {
3787 msgview = summaryview->messageview;
3788 summaryview->displayed = row;
3789 if (!messageview_is_visible(msgview) &&
3790 gtk_window_is_active(GTK_WINDOW(summaryview->mainwin->window))) {
3791 main_window_toggle_message_view(summaryview->mainwin);
3792 GTK_EVENTS_FLUSH();
3794 val = messageview_show(msgview, msginfo, all_headers);
3795 if (mimeview_tree_is_empty(msgview->mimeview))
3796 gtk_widget_grab_focus(summaryview->ctree);
3797 gtkut_ctree_node_move_if_on_the_edge(ctree, row,
3798 GTK_CMCLIST(summaryview->ctree)->focus_row);
3802 if (val == 0 && MSG_IS_UNREAD(msginfo->flags)) {
3803 if (!prefs_common.mark_as_read_on_new_window &&
3804 prefs_common.mark_as_read_delay) {
3805 MarkAsReadData *data = g_new0(MarkAsReadData, 1);
3806 data->summaryview = summaryview;
3807 data->msginfo = procmsg_msginfo_new_ref(msginfo);
3808 if (summaryview->mark_as_read_timeout_tag != 0)
3809 g_source_remove(summaryview->mark_as_read_timeout_tag);
3810 summaryview->mark_as_read_timeout_tag =
3811 g_timeout_add_seconds(prefs_common.mark_as_read_delay,
3812 msginfo_mark_as_read_timeout, data);
3813 } else if (new_window || !prefs_common.mark_as_read_on_new_window) {
3814 msginfo_mark_as_read(summaryview, msginfo, row);
3818 summary_set_menu_sensitive(summaryview);
3819 toolbar_main_set_sensitive(summaryview->mainwin);
3820 messageview_set_menu_sensitive(summaryview->messageview);
3822 summary_unlock(summaryview);
3823 END_TIMING();
3826 void summary_display_msg_selected(SummaryView *summaryview,
3827 gboolean all_headers)
3829 if (summary_is_locked(summaryview)) return;
3830 summaryview->displayed = NULL;
3831 summary_display_msg_full(summaryview, summaryview->selected, FALSE,
3832 all_headers);
3835 void summary_redisplay_msg(SummaryView *summaryview)
3837 GtkCMCTreeNode *node;
3839 if (summaryview->displayed) {
3840 node = summaryview->displayed;
3841 summaryview->displayed = NULL;
3842 summary_display_msg(summaryview, node);
3846 void summary_open_msg(SummaryView *summaryview)
3848 if (!summaryview->selected) return;
3850 /* CLAWS: if separate message view, don't open a new window
3851 * but rather use the current separated message view */
3852 summary_display_msg_full(summaryview, summaryview->selected,
3853 TRUE, FALSE);
3856 void summary_view_source(SummaryView * summaryview)
3858 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3859 MsgInfo *msginfo;
3860 SourceWindow *srcwin;
3862 if (!summaryview->selected) return;
3864 srcwin = source_window_create();
3865 msginfo = gtk_cmctree_node_get_row_data(ctree, summaryview->selected);
3866 source_window_show_msg(srcwin, msginfo);
3867 source_window_show(srcwin);
3870 void summary_reedit(SummaryView *summaryview)
3872 MsgInfo *msginfo;
3874 if (!summaryview->selected) return;
3875 if (!summaryview->folder_item) return;
3876 if (!FOLDER_SHOWS_TO_HDR(summaryview->folder_item))
3877 return;
3879 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
3880 summaryview->selected);
3881 if (!msginfo) return;
3883 compose_reedit(msginfo, FALSE);
3886 gboolean summary_is_list(SummaryView *summaryview)
3888 return (gtk_notebook_get_current_page(
3889 GTK_NOTEBOOK(summaryview->mainwidget_book)) == 0);
3892 void summary_toggle_view(SummaryView *summaryview)
3894 if (prefs_common.layout_mode == SMALL_LAYOUT)
3895 return;
3896 if (summary_is_locked(summaryview))
3897 return;
3898 if (!messageview_is_visible(summaryview->messageview) &&
3899 summaryview->selected && summary_is_list(summaryview))
3900 summary_display_msg(summaryview,
3901 summaryview->selected);
3902 else
3903 main_window_toggle_message_view(summaryview->mainwin);
3906 static gboolean summary_search_unread_recursive(GtkCMCTree *ctree,
3907 GtkCMCTreeNode *node)
3909 MsgInfo *msginfo;
3911 if (node) {
3912 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
3913 if (msginfo && MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
3914 return TRUE;
3915 node = GTK_CMCTREE_ROW(node)->children;
3916 } else
3917 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
3919 while (node) {
3920 if (summary_search_unread_recursive(ctree, node) == TRUE)
3921 return TRUE;
3922 node = GTK_CMCTREE_ROW(node)->sibling;
3925 return FALSE;
3928 static gboolean summary_have_unread_children(SummaryView *summaryview,
3929 GtkCMCTreeNode *node)
3931 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3933 if (!node) return FALSE;
3935 node = GTK_CMCTREE_ROW(node)->children;
3937 while (node) {
3938 if (summary_search_unread_recursive(ctree, node) == TRUE)
3939 return TRUE;
3940 node = GTK_CMCTREE_ROW(node)->sibling;
3942 return FALSE;
3945 static void summary_set_row_marks(SummaryView *summaryview, GtkCMCTreeNode *row)
3947 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
3948 GtkStyle *style = NULL;
3949 MsgInfo *msginfo;
3950 MsgFlags flags;
3951 gint *col_pos = summaryview->col_pos;
3953 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
3954 if (!msginfo) return;
3956 flags = msginfo->flags;
3958 gtk_cmctree_node_set_foreground(ctree, row, NULL);
3960 /* set new/unread column */
3961 if (MSG_IS_IGNORE_THREAD(flags)) {
3962 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3963 ignorethreadxpm);
3964 } else if (MSG_IS_WATCH_THREAD(flags)) {
3965 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3966 watchthreadxpm);
3967 } else if (MSG_IS_SPAM(flags)) {
3968 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3969 spamxpm);
3970 } else if (MSG_IS_NEW(flags)) {
3971 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3972 newxpm);
3973 } else if (MSG_IS_UNREAD(flags)) {
3974 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3975 unreadxpm);
3976 } else if (MSG_IS_REPLIED(flags) && MSG_IS_FORWARDED(flags)) {
3977 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3978 repliedandforwardedxpm);
3979 } else if (MSG_IS_REPLIED(flags)) {
3980 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3981 repliedxpm);
3982 } else if (MSG_IS_FORWARDED(flags)) {
3983 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_STATUS],
3984 forwardedxpm);
3985 } else {
3986 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_STATUS],
3987 "");
3990 if ((((prefs_common.bold_unread && MSG_IS_UNREAD(flags)) ||
3991 (prefs_common.bold_marked && MSG_IS_MARKED(flags))) &&
3992 !MSG_IS_IGNORE_THREAD(flags)) ||
3993 (!GTK_CMCTREE_ROW(row)->expanded &&
3994 GTK_CMCTREE_ROW(row)->children &&
3995 summary_have_unread_children(summaryview, row)))
3996 style = bold_style;
3998 /* set mark column */
3999 if (MSG_IS_DELETED(flags)) {
4000 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
4001 deletedxpm);
4002 if (style)
4003 style = bold_style;
4004 gtk_cmctree_node_set_foreground
4005 (ctree, row, &summaryview->color_dim);
4006 } else if (MSG_IS_MARKED(flags)) {
4007 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
4008 markxpm);
4009 } else if (MSG_IS_MOVE(flags)) {
4010 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
4011 movedxpm);
4012 if (!msginfo->to_folder ||
4013 !folder_has_parent_of_type(msginfo->to_folder, F_TRASH)) {
4014 if (style)
4015 style = bold_style;
4016 gtk_cmctree_node_set_foreground
4017 (ctree, row, &summaryview->color_marked);
4018 } else {
4019 if (style)
4020 style = bold_style;
4021 gtk_cmctree_node_set_foreground
4022 (ctree, row, &summaryview->color_dim);
4024 } else if (MSG_IS_COPY(flags)) {
4025 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MARK],
4026 copiedxpm);
4027 if (style)
4028 style = bold_style;
4029 gtk_cmctree_node_set_foreground
4030 (ctree, row, &summaryview->color_marked);
4031 } else {
4032 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_MARK], "");
4035 if (MSG_IS_LOCKED(flags)) {
4036 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_LOCKED],
4037 lockedxpm);
4039 else {
4040 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_LOCKED], "");
4043 if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_SIGNED(flags)) {
4044 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4045 clipgpgsignedxpm);
4046 } else if (MSG_IS_SIGNED(flags)) {
4047 if (MSG_IS_ENCRYPTED(flags)) {
4048 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4049 keysignxpm);
4050 } else {
4051 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4052 gpgsignedxpm);
4054 } else if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_ENCRYPTED(flags)) {
4055 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4056 clipkeyxpm);
4057 } else if (MSG_IS_ENCRYPTED(flags)) {
4058 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4059 keyxpm);
4060 } else if (MSG_IS_WITH_ATTACHMENT(flags)) {
4061 gtk_cmctree_node_set_pixbuf(ctree, row, col_pos[S_COL_MIME],
4062 clipxpm);
4063 } else {
4064 gtk_cmctree_node_set_text(ctree, row, col_pos[S_COL_MIME], "");
4067 gtk_cmctree_node_set_row_style(ctree, row, style);
4069 if (MSG_GET_COLORLABEL(flags))
4070 summary_set_colorlabel_color(ctree, row, MSG_GET_COLORLABEL_VALUE(flags));
4073 static void summary_mark_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4075 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4076 MsgInfo *msginfo;
4078 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4079 cm_return_if_fail(msginfo);
4080 if (MSG_IS_DELETED(msginfo->flags))
4081 summaryview->deleted--;
4082 if (MSG_IS_MOVE(msginfo->flags))
4083 summaryview->moved--;
4084 if (MSG_IS_COPY(msginfo->flags))
4085 summaryview->copied--;
4087 procmsg_msginfo_set_to_folder(msginfo, NULL);
4088 summary_msginfo_change_flags(msginfo, MSG_MARKED, 0, MSG_DELETED,
4089 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4090 summary_set_row_marks(summaryview, row);
4091 debug_print("Message %s/%d is marked\n", msginfo->folder->path, msginfo->msgnum);
4094 static void summary_lock_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4096 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4097 MsgInfo *msginfo;
4099 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4100 cm_return_if_fail(msginfo);
4101 if (MSG_IS_DELETED(msginfo->flags))
4102 summaryview->deleted--;
4103 if (MSG_IS_MOVE(msginfo->flags)) {
4104 summaryview->moved--;
4106 if (MSG_IS_COPY(msginfo->flags)) {
4107 summaryview->copied--;
4109 procmsg_msginfo_set_to_folder(msginfo, NULL);
4110 summary_msginfo_change_flags(msginfo, MSG_LOCKED, 0, MSG_DELETED,
4111 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4113 summary_set_row_marks(summaryview, row);
4114 debug_print("Message %d is locked\n", msginfo->msgnum);
4117 static void summary_unlock_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4119 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4120 MsgInfo *msginfo;
4122 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4123 cm_return_if_fail(msginfo);
4124 if (!MSG_IS_LOCKED(msginfo->flags))
4125 return;
4126 procmsg_msginfo_set_to_folder(msginfo, NULL);
4127 summary_msginfo_unset_flags(msginfo, MSG_LOCKED, 0);
4128 summary_set_row_marks(summaryview, row);
4129 debug_print("Message %d is unlocked\n", msginfo->msgnum);
4132 void summary_mark(SummaryView *summaryview)
4134 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4135 GList *cur;
4136 gboolean froze = FALSE;
4138 if (summary_is_locked(summaryview))
4139 return;
4140 START_LONG_OPERATION(summaryview, FALSE);
4141 folder_item_set_batch(summaryview->folder_item, TRUE);
4142 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4143 summary_mark_row(summaryview, GTK_CMCTREE_NODE(cur->data));
4144 folder_item_set_batch(summaryview->folder_item, FALSE);
4145 END_LONG_OPERATION(summaryview);
4147 summary_status_show(summaryview);
4150 static void summary_mark_row_as_read(SummaryView *summaryview,
4151 GtkCMCTreeNode *row)
4153 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4154 MsgInfo *msginfo;
4156 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4157 cm_return_if_fail(msginfo);
4159 if(!(MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
4160 return;
4162 summary_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
4163 summary_set_row_marks(summaryview, row);
4164 debug_print("Message %d is marked as read\n",
4165 msginfo->msgnum);
4168 static void summary_mark_row_as_unread(SummaryView *summaryview,
4169 GtkCMCTreeNode *row)
4171 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4172 MsgInfo *msginfo;
4174 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4175 cm_return_if_fail(msginfo);
4177 if(MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags))
4178 return;
4180 summary_msginfo_set_flags(msginfo, MSG_UNREAD, 0);
4181 summary_set_row_marks(summaryview, row);
4182 debug_print("Message %d is marked as unread\n",
4183 msginfo->msgnum);
4186 void summary_mark_as_read(SummaryView *summaryview)
4188 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4189 GList *cur;
4190 gboolean froze = FALSE;
4192 if (summary_is_locked(summaryview))
4193 return;
4195 if (!summaryview->folder_item)
4196 return;
4198 if ((summaryview->folder_item->total_msgs == (gint)g_list_length(GTK_CMCLIST(ctree)->selection) &&
4199 summaryview->folder_item->total_msgs > 1) &&
4200 !summary_mark_all_read_confirm(TRUE))
4201 return;
4203 START_LONG_OPERATION(summaryview, FALSE);
4204 folder_item_set_batch(summaryview->folder_item, TRUE);
4205 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4206 summary_mark_row_as_read(summaryview,
4207 GTK_CMCTREE_NODE(cur->data));
4208 folder_item_set_batch(summaryview->folder_item, FALSE);
4209 END_LONG_OPERATION(summaryview);
4211 summary_status_show(summaryview);
4214 void summary_mark_as_unread(SummaryView *summaryview)
4216 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4217 GList *cur;
4218 gboolean froze = FALSE;
4220 if (summary_is_locked(summaryview))
4221 return;
4223 if ((summaryview->folder_item->total_msgs == (gint)g_list_length(GTK_CMCLIST(ctree)->selection) &&
4224 summaryview->folder_item->total_msgs > 1) &&
4225 !summary_mark_all_unread_confirm(TRUE))
4226 return;
4228 START_LONG_OPERATION(summaryview, FALSE);
4229 folder_item_set_batch(summaryview->folder_item, TRUE);
4230 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4231 summary_mark_row_as_unread(summaryview,
4232 GTK_CMCTREE_NODE(cur->data));
4233 folder_item_set_batch(summaryview->folder_item, FALSE);
4234 END_LONG_OPERATION(summaryview);
4236 summary_status_show(summaryview);
4239 void summary_msgs_lock(SummaryView *summaryview)
4241 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4242 GList *cur;
4243 gboolean froze = FALSE;
4245 if (summary_is_locked(summaryview))
4246 return;
4247 START_LONG_OPERATION(summaryview, FALSE);
4248 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4249 summary_lock_row(summaryview,
4250 GTK_CMCTREE_NODE(cur->data));
4251 END_LONG_OPERATION(summaryview);
4253 summary_status_show(summaryview);
4256 void summary_msgs_unlock(SummaryView *summaryview)
4258 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4259 GList *cur;
4260 gboolean froze = FALSE;
4262 if (summary_is_locked(summaryview))
4263 return;
4264 START_LONG_OPERATION(summaryview, FALSE);
4265 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4266 summary_unlock_row(summaryview,
4267 GTK_CMCTREE_NODE(cur->data));
4268 END_LONG_OPERATION(summaryview);
4270 summary_status_show(summaryview);
4273 static gboolean summary_mark_all_read_confirm(gboolean ask_if_needed)
4275 /* ask_if_needed is FALSE when user-asking is performed by caller,
4276 commonly when the caller is a mark-as-read-recursive func */
4277 if (ask_if_needed && prefs_common.ask_mark_all_read) {
4278 AlertValue val = alertpanel_full(_("Mark all as read"),
4279 _("Do you really want to mark all mails in this folder as read?"),
4280 NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST,
4281 TRUE, NULL, ALERT_QUESTION);
4283 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
4284 return FALSE;
4285 else if (val & G_ALERTDISABLE)
4286 prefs_common.ask_mark_all_read = FALSE;
4288 return TRUE;
4291 void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
4293 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4294 GtkCMCTreeNode *node;
4295 gboolean froze = FALSE;
4297 if (summary_is_locked(summaryview))
4298 return;
4300 if (!summary_mark_all_read_confirm(ask_if_needed))
4301 return;
4303 START_LONG_OPERATION(summaryview, TRUE);
4304 folder_item_set_batch(summaryview->folder_item, TRUE);
4305 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4306 node = gtkut_ctree_node_next(ctree, node))
4307 summary_mark_row_as_read(summaryview, node);
4308 folder_item_set_batch(summaryview->folder_item, FALSE);
4309 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4310 node = gtkut_ctree_node_next(ctree, node)) {
4311 if (!GTK_CMCTREE_ROW(node)->expanded)
4312 summary_set_row_marks(summaryview, node);
4314 END_LONG_OPERATION(summaryview);
4316 summary_status_show(summaryview);
4319 static gboolean summary_mark_all_unread_confirm(gboolean ask_if_needed)
4321 /* ask_if_needed is FALSE when user-asking is performed by caller,
4322 commonly when the caller is a mark-as-unread-recursive func */
4323 if (ask_if_needed && prefs_common.ask_mark_all_read) {
4324 AlertValue val = alertpanel_full(_("Mark all as unread"),
4325 _("Do you really want to mark all mails in this folder as unread?"),
4326 NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST,
4327 TRUE, NULL, ALERT_QUESTION);
4329 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
4330 return FALSE;
4331 else if (val & G_ALERTDISABLE)
4332 prefs_common.ask_mark_all_read = FALSE;
4334 return TRUE;
4337 void summary_mark_all_unread(SummaryView *summaryview, gboolean ask_if_needed)
4339 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4340 GtkCMCTreeNode *node;
4341 gboolean froze = FALSE;
4343 if (summary_is_locked(summaryview))
4344 return;
4346 if (!summary_mark_all_unread_confirm(ask_if_needed))
4347 return;
4349 START_LONG_OPERATION(summaryview, TRUE);
4350 folder_item_set_batch(summaryview->folder_item, TRUE);
4351 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4352 node = gtkut_ctree_node_next(ctree, node))
4353 summary_mark_row_as_unread(summaryview, node);
4354 folder_item_set_batch(summaryview->folder_item, FALSE);
4355 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
4356 node = gtkut_ctree_node_next(ctree, node)) {
4357 if (!GTK_CMCTREE_ROW(node)->expanded)
4358 summary_set_row_marks(summaryview, node);
4360 END_LONG_OPERATION(summaryview);
4362 summary_status_show(summaryview);
4365 void summary_mark_as_spam(SummaryView *summaryview, guint action, GtkWidget *widget)
4367 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4368 GList *cur;
4369 gboolean is_spam = action;
4370 GSList *msgs = NULL;
4371 gboolean immediate_exec = prefs_common.immediate_exec;
4372 gboolean moved = FALSE;
4373 gboolean froze = FALSE;
4376 if (summary_is_locked(summaryview))
4377 return;
4379 prefs_common.immediate_exec = FALSE;
4380 START_LONG_OPERATION(summaryview, FALSE);
4381 folder_item_set_batch(summaryview->folder_item, TRUE);
4382 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4383 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4384 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4385 if (msginfo)
4386 msgs = g_slist_prepend(msgs, msginfo);
4389 if (procmsg_spam_learner_learn(NULL, msgs, is_spam) == 0) {
4390 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4391 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4392 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4393 if (!msginfo)
4394 continue;
4395 if (is_spam) {
4396 summary_msginfo_change_flags(msginfo, MSG_SPAM, 0, MSG_NEW|MSG_UNREAD, 0);
4397 if (procmsg_spam_get_folder(msginfo) != summaryview->folder_item) {
4398 summary_move_row_to(summaryview, row,
4399 procmsg_spam_get_folder(msginfo));
4400 moved = TRUE;
4402 } else {
4403 summary_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
4405 summaryview->display_msg = prefs_common.always_show_msg;
4407 summary_set_row_marks(summaryview, row);
4409 } else {
4410 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
4413 prefs_common.immediate_exec = immediate_exec;
4414 folder_item_set_batch(summaryview->folder_item, FALSE);
4415 END_LONG_OPERATION(summaryview);
4417 if (prefs_common.immediate_exec && moved) {
4418 summary_execute(summaryview);
4421 if (!moved && msgs) {
4422 MsgInfo *msginfo = (MsgInfo *)msgs->data;
4423 toolbar_set_learn_button
4424 (summaryview->mainwin->toolbar,
4425 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
4427 g_slist_free(msgs);
4429 summary_status_show(summaryview);
4432 static gboolean check_permission(SummaryView *summaryview, MsgInfo * msginfo)
4434 GList * cur;
4435 gboolean found;
4437 switch (FOLDER_TYPE(summaryview->folder_item->folder)) {
4439 case F_NEWS:
4442 security : checks if one the accounts correspond to
4443 the author of the post
4446 found = FALSE;
4447 for(cur = account_get_list() ; cur != NULL ; cur = cur->next) {
4448 PrefsAccount * account;
4449 gchar * from_name;
4451 account = cur->data;
4452 if (account->name && *account->name)
4453 from_name =
4454 g_strdup_printf("%s <%s>",
4455 account->name,
4456 account->address);
4457 else
4458 from_name =
4459 g_strdup_printf("%s",
4460 account->address);
4462 if (g_utf8_collate(from_name, msginfo->from) == 0) {
4463 g_free(from_name);
4464 found = TRUE;
4465 break;
4467 g_free(from_name);
4470 if (!found) {
4471 alertpanel_error(_("You're not the author of the article."));
4474 return found;
4476 default:
4477 return TRUE;
4481 static void summary_delete_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4483 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4484 MsgInfo *msginfo;
4486 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4487 cm_return_if_fail(msginfo);
4489 if (MSG_IS_LOCKED(msginfo->flags)) return;
4491 if (MSG_IS_DELETED(msginfo->flags)) return;
4493 if (MSG_IS_MOVE(msginfo->flags))
4494 summaryview->moved--;
4495 if (MSG_IS_COPY(msginfo->flags))
4496 summaryview->copied--;
4498 procmsg_msginfo_set_to_folder(msginfo, NULL);
4499 summary_msginfo_change_flags(msginfo, MSG_DELETED, 0, MSG_MARKED,
4500 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4501 summaryview->deleted++;
4503 if (!prefs_common.immediate_exec &&
4504 !folder_has_parent_of_type(summaryview->folder_item, F_TRASH)) {
4505 summary_set_row_marks(summaryview, row);
4507 debug_print("Message %s/%d is set to delete\n",
4508 msginfo->folder->path, msginfo->msgnum);
4511 void summary_cancel(SummaryView *summaryview)
4513 MsgInfo * msginfo;
4515 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
4516 summaryview->selected);
4517 if (!msginfo) return;
4519 if (!check_permission(summaryview, msginfo))
4520 return;
4522 news_cancel_article(summaryview->folder_item->folder, msginfo);
4524 if (summary_is_locked(summaryview)) return;
4526 summary_lock(summaryview);
4528 summary_freeze(summaryview);
4530 summary_update_status(summaryview);
4531 summary_status_show(summaryview);
4533 summary_thaw(summaryview);
4535 summary_unlock(summaryview);
4538 void summary_delete(SummaryView *summaryview)
4540 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4541 FolderItem *item = summaryview->folder_item;
4542 GList *cur;
4543 GtkCMCTreeNode *sel_last = NULL;
4544 GtkCMCTreeNode *node;
4545 AlertValue aval;
4546 MsgInfo *msginfo;
4547 gboolean froze = FALSE;
4549 if (!item) return;
4551 if (summary_is_locked(summaryview)) return;
4553 if (!summaryview->folder_item) return;
4555 START_LONG_OPERATION(summaryview, FALSE);
4557 if (!prefs_common.live_dangerously) {
4558 gchar *buf = NULL;
4559 guint num = g_list_length(GTK_CMCLIST(summaryview->ctree)->selection);
4560 buf = g_strdup_printf(ngettext(
4561 "Do you really want to delete the selected message?",
4562 "Do you really want to delete the %d selected messages?", num),
4563 num);
4564 aval = alertpanel(ngettext("Delete message", "Delete messages", num),
4565 buf,
4566 NULL, _("_Cancel"), NULL, _("_Delete"), NULL, NULL, ALERTFOCUS_SECOND);
4567 g_free(buf);
4568 if (aval != G_ALERTALTERNATE) {
4569 END_LONG_OPERATION(summaryview);
4570 return;
4574 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL;
4575 cur = cur->next) {
4576 GtkCMCTreeNode *row = GTK_CMCTREE_NODE(cur->data);
4577 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4578 if (msginfo && msginfo->total_size != 0 &&
4579 msginfo->size != (goffset)msginfo->total_size)
4580 partial_mark_for_delete(msginfo);
4583 main_window_cursor_wait(summaryview->mainwin);
4585 /* next code sets current row focus right. We need to find a row
4586 * that is not deleted. */
4587 folder_item_set_batch(summaryview->folder_item, TRUE);
4588 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
4589 sel_last = GTK_CMCTREE_NODE(cur->data);
4590 summary_delete_row(summaryview, sel_last);
4592 folder_item_set_batch(summaryview->folder_item, FALSE);
4593 END_LONG_OPERATION(summaryview);
4595 if (summaryview->sort_type == SORT_ASCENDING) {
4596 node = summary_find_next_msg(summaryview, sel_last, TRUE);
4597 if (!node || prefs_common.next_on_delete == FALSE)
4598 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4599 } else {
4600 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4601 if (!node || prefs_common.next_on_delete == FALSE)
4602 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4604 summary_select_node(summaryview, node, OPEN_SELECTED_ON_DELETEMOVE);
4606 if (prefs_common.immediate_exec || folder_has_parent_of_type(item, F_TRASH)) {
4607 summary_execute(summaryview);
4608 /* after deleting, the anchor may be at an invalid row
4609 * so reset it to the node we found earlier */
4610 gtk_sctree_set_anchor_row(GTK_SCTREE(ctree), node);
4611 } else
4612 summary_status_show(summaryview);
4615 main_window_cursor_normal(summaryview->mainwin);
4618 void summary_delete_trash(SummaryView *summaryview)
4620 FolderItem *to_folder = NULL;
4621 PrefsAccount *ac;
4622 if (!summaryview->folder_item ||
4623 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4625 if (NULL != (ac = account_find_from_item(summaryview->folder_item)))
4626 to_folder = account_get_special_folder(ac, F_TRASH);
4628 if (to_folder == NULL)
4629 to_folder = summaryview->folder_item->folder->trash;
4631 if (to_folder == NULL || to_folder == summaryview->folder_item
4632 || folder_has_parent_of_type(summaryview->folder_item, F_TRASH))
4633 summary_delete(summaryview);
4634 else
4635 summary_move_selected_to(summaryview, to_folder);
4639 static void summary_unmark_row(SummaryView *summaryview, GtkCMCTreeNode *row)
4641 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4642 MsgInfo *msginfo;
4644 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4645 cm_return_if_fail(msginfo);
4646 if (MSG_IS_DELETED(msginfo->flags))
4647 summaryview->deleted--;
4648 if (MSG_IS_MOVE(msginfo->flags))
4649 summaryview->moved--;
4650 if (MSG_IS_COPY(msginfo->flags))
4651 summaryview->copied--;
4653 procmsg_msginfo_set_to_folder(msginfo, NULL);
4654 summary_msginfo_unset_flags(msginfo, MSG_MARKED | MSG_DELETED,
4655 MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
4656 summary_set_row_marks(summaryview, row);
4658 debug_print("Message %s/%d is unmarked\n",
4659 msginfo->folder->path, msginfo->msgnum);
4662 void summary_unmark(SummaryView *summaryview)
4664 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4665 GList *cur;
4666 gboolean froze = FALSE;
4668 if (summary_is_locked(summaryview))
4669 return;
4670 START_LONG_OPERATION(summaryview, FALSE);
4671 folder_item_set_batch(summaryview->folder_item, TRUE);
4672 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
4673 summary_unmark_row(summaryview, GTK_CMCTREE_NODE(cur->data));
4674 folder_item_set_batch(summaryview->folder_item, FALSE);
4675 END_LONG_OPERATION(summaryview);
4677 summary_status_show(summaryview);
4680 static void summary_move_row_to(SummaryView *summaryview, GtkCMCTreeNode *row,
4681 FolderItem *to_folder)
4683 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4684 MsgInfo *msginfo;
4686 cm_return_if_fail(to_folder != NULL);
4688 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4689 cm_return_if_fail(msginfo);
4690 if (MSG_IS_LOCKED(msginfo->flags))
4691 return;
4693 procmsg_msginfo_set_to_folder(msginfo, to_folder);
4694 if (MSG_IS_DELETED(msginfo->flags))
4695 summaryview->deleted--;
4696 if (MSG_IS_COPY(msginfo->flags)) {
4697 summaryview->copied--;
4699 if (!MSG_IS_MOVE(msginfo->flags)) {
4700 summary_msginfo_change_flags(msginfo, 0, MSG_MOVE, MSG_DELETED,
4701 MSG_COPY | MSG_MOVE_DONE);
4702 summaryview->moved++;
4703 } else {
4704 summary_msginfo_unset_flags(msginfo, MSG_DELETED, MSG_COPY);
4707 if (!prefs_common.immediate_exec) {
4708 summary_set_row_marks(summaryview, row);
4711 debug_print("Message %d is set to move to %s\n",
4712 msginfo->msgnum, to_folder->path);
4715 void summary_move_selected_to(SummaryView *summaryview, FolderItem *to_folder)
4717 GList *cur;
4718 GtkCMCTreeNode *sel_last = NULL;
4719 gboolean froze = FALSE;
4721 if (!to_folder) return;
4722 if (!summaryview->folder_item ||
4723 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4725 if (summary_is_locked(summaryview)) return;
4727 if (summaryview->folder_item == to_folder) {
4728 alertpanel_error(_("Destination is same as current folder."));
4729 return;
4732 if (to_folder->no_select) {
4733 alertpanel_error(_("The destination folder can only be used to "
4734 "store subfolders."));
4735 return;
4738 START_LONG_OPERATION(summaryview, FALSE);
4740 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
4741 cur != NULL && cur->data != NULL; cur = cur->next) {
4742 sel_last = GTK_CMCTREE_NODE(cur->data);
4743 summary_move_row_to
4744 (summaryview, GTK_CMCTREE_NODE(cur->data), to_folder);
4746 END_LONG_OPERATION(summaryview);
4748 if (prefs_common.immediate_exec) {
4749 summary_execute(summaryview);
4750 } else {
4751 GtkCMCTreeNode *node = NULL;
4752 if (summaryview->sort_type == SORT_ASCENDING) {
4753 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4754 if (!node || prefs_common.next_on_delete == FALSE)
4755 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4756 } else {
4757 node = summary_find_prev_msg(summaryview, sel_last,TRUE);
4758 if (!node || prefs_common.next_on_delete == FALSE)
4759 node = summary_find_next_msg(summaryview, sel_last,TRUE);
4761 summary_select_node(summaryview, node, OPEN_SELECTED_ON_DELETEMOVE);
4762 summary_status_show(summaryview);
4765 if (!summaryview->selected) { /* this was the last message */
4766 GtkCMCTreeNode *node = gtk_cmctree_node_nth (GTK_CMCTREE(summaryview->ctree),
4767 GTK_CMCLIST(summaryview->ctree)->rows - 1);
4768 if (node)
4769 summary_select_node(summaryview, node, OPEN_SELECTED_ON_DELETEMOVE);
4774 void summary_move_to(SummaryView *summaryview)
4776 FolderItem *to_folder;
4778 if (!summaryview->folder_item ||
4779 FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS) return;
4781 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE,
4782 ngettext(
4783 "Select folder to move selected message to",
4784 "Select folder to move selected messages to",
4785 g_list_length(GTK_CMCLIST(summaryview->ctree)->selection))
4787 summary_move_selected_to(summaryview, to_folder);
4790 static void summary_copy_row_to(SummaryView *summaryview, GtkCMCTreeNode *row,
4791 FolderItem *to_folder)
4793 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4794 MsgInfo *msginfo;
4796 cm_return_if_fail(to_folder != NULL);
4798 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
4799 cm_return_if_fail(msginfo);
4800 procmsg_msginfo_set_to_folder(msginfo, to_folder);
4801 if (MSG_IS_DELETED(msginfo->flags))
4802 summaryview->deleted--;
4803 if (MSG_IS_MOVE(msginfo->flags)) {
4804 summaryview->moved--;
4807 if (!MSG_IS_COPY(msginfo->flags)) {
4808 summary_msginfo_change_flags(msginfo, 0, MSG_COPY, MSG_DELETED,
4809 MSG_MOVE | MSG_MOVE_DONE);
4810 summaryview->copied++;
4811 } else {
4812 summary_msginfo_unset_flags(msginfo, MSG_DELETED, MSG_MOVE);
4814 if (!prefs_common.immediate_exec) {
4815 summary_set_row_marks(summaryview, row);
4818 debug_print("Message %d is set to copy to %s\n",
4819 msginfo->msgnum, to_folder->path);
4822 void summary_copy_selected_to(SummaryView *summaryview, FolderItem *to_folder)
4824 GList *cur;
4825 gboolean froze = FALSE;
4827 if (!to_folder) return;
4828 if (!summaryview->folder_item) return;
4830 if (summary_is_locked(summaryview)) return;
4832 if (summaryview->folder_item == to_folder) {
4833 alertpanel_error
4834 (_("Destination to copy is same as current folder."));
4835 return;
4838 if (to_folder->no_select) {
4839 alertpanel_error(_("The destination folder can only be used to "
4840 "store subfolders."));
4841 return;
4844 START_LONG_OPERATION(summaryview, FALSE);
4846 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
4847 cur != NULL && cur->data != NULL; cur = cur->next)
4848 summary_copy_row_to
4849 (summaryview, GTK_CMCTREE_NODE(cur->data), to_folder);
4851 END_LONG_OPERATION(summaryview);
4853 if (prefs_common.immediate_exec)
4854 summary_execute(summaryview);
4855 else {
4856 summary_status_show(summaryview);
4860 void summary_copy_to(SummaryView *summaryview)
4862 FolderItem *to_folder;
4864 if (!summaryview->folder_item) return;
4866 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
4867 ngettext(
4868 "Select folder to copy selected message to",
4869 "Select folder to copy selected messages to",
4870 g_list_length(GTK_CMCLIST(summaryview->ctree)->selection))
4872 summary_copy_selected_to(summaryview, to_folder);
4875 void summary_add_address(SummaryView *summaryview)
4877 MsgInfo *msginfo, *full_msginfo;
4878 gchar *from;
4879 GdkPixbuf *picture = NULL;
4880 AvatarRender *avatarr;
4882 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
4883 summaryview->selected);
4884 if (!msginfo || !msginfo->from)
4885 return;
4887 Xstrdup_a(from, msginfo->from, return);
4888 eliminate_address_comment(from);
4889 extract_address(from);
4891 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
4893 avatarr = avatars_avatarrender_new(full_msginfo);
4894 hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
4896 procmsg_msginfo_free(&full_msginfo);
4898 if (avatarr->image)
4899 picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
4901 #ifndef USE_ALT_ADDRBOOK
4902 addressbook_add_contact(msginfo->fromname, from, NULL, picture);
4903 #else
4904 if (addressadd_selection(msginfo->fromname, from, NULL, picture)) {
4905 debug_print( "addressbook_add_contact - added\n" );
4907 #endif
4908 avatars_avatarrender_free(avatarr);
4911 void summary_select_all(SummaryView *summaryview)
4913 GtkCMCTreeNode *node;
4915 if (!summaryview->folder_item) return;
4917 if (GTK_CMCLIST(summaryview->ctree)->focus_row < 0) {
4918 /* If no row is selected, select (but do not open) the first
4919 * row, to get summaryview into correct state for selecting all. */
4920 debug_print("summary_select_all: no row selected, selecting first one\n");
4921 if (GTK_CMCLIST(summaryview->ctree)->row_list != NULL) {
4922 node = gtk_cmctree_node_nth(GTK_CMCTREE(summaryview->ctree), 0);
4923 summary_select_node(summaryview, node, FALSE);
4927 /* Now select all rows while locking the summaryview for
4928 * faster performance. */
4929 summary_lock(summaryview);
4930 gtk_cmclist_select_all(GTK_CMCLIST(summaryview->ctree));
4931 summary_unlock(summaryview);
4933 summary_status_show(summaryview);
4936 void summary_unselect_all(SummaryView *summaryview)
4938 summary_lock(summaryview);
4939 gtk_sctree_unselect_all(GTK_SCTREE(summaryview->ctree));
4940 summary_unlock(summaryview);
4941 summary_status_show(summaryview);
4944 void summary_select_thread(SummaryView *summaryview, gboolean delete_thread,
4945 gboolean trash_thread)
4947 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4948 GtkCMCTreeNode *node = NULL;
4949 gboolean froze = FALSE;
4950 GList *cur = NULL;
4951 GList *copy = NULL;
4952 if (!GTK_CMCLIST(summaryview->ctree)->selection)
4953 return;
4956 START_LONG_OPERATION(summaryview, FALSE);
4957 copy = g_list_copy(GTK_CMCLIST(summaryview->ctree)->selection);
4958 for (cur = copy; cur != NULL && cur->data != NULL;
4959 cur = cur->next) {
4960 node = GTK_CMCTREE_NODE(cur->data);
4961 if (!node)
4962 continue;
4963 while (GTK_CMCTREE_ROW(node)->parent != NULL)
4964 node = GTK_CMCTREE_ROW(node)->parent;
4966 gtk_cmctree_select_recursive(ctree, node);
4968 g_list_free(copy);
4969 END_LONG_OPERATION(summaryview);
4971 if (trash_thread) {
4972 if (FOLDER_TYPE(summaryview->folder_item->folder) == F_NEWS)
4973 summary_delete(summaryview);
4974 else
4975 summary_delete_trash(summaryview);
4976 } else if (delete_thread)
4977 summary_delete(summaryview);
4979 summary_status_show(summaryview);
4982 void summary_save_as(SummaryView *summaryview)
4984 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
4985 MsgInfo *msginfo;
4986 gchar *filename = NULL;
4987 gchar *src, *dest;
4988 gchar *tmp;
4989 gchar *filedir = NULL;
4990 gchar *converted_filename = NULL;
4991 gchar * filepath = NULL;
4993 AlertValue aval = 0;
4995 if (!summaryview->selected) return;
4996 msginfo = gtk_cmctree_node_get_row_data(ctree, summaryview->selected);
4997 if (!msginfo) return;
4999 if (msginfo->subject) {
5000 Xstrdup_a(filename, msginfo->subject, return);
5001 subst_for_filename(filename);
5004 manage_window_focus_in(summaryview->window, NULL, NULL);
5006 if (filename && !g_utf8_validate(filename, -1, NULL)) {
5007 converted_filename = conv_codeset_strdup(filename,
5008 conv_get_locale_charset_str(),
5009 CS_UTF_8);
5010 if (!converted_filename) {
5011 g_warning("summary_save_as(): failed to convert character set");
5012 } else {
5013 filename = converted_filename;
5016 if (!filename)
5017 return;
5019 if (prefs_common.attach_save_dir && *prefs_common.attach_save_dir) {
5020 filepath = g_strconcat(prefs_common.attach_save_dir, G_DIR_SEPARATOR_S,
5021 filename, NULL);
5023 dest = filesel_select_file_save(_("Save as"), filepath ? filepath : filename);
5024 if (filepath)
5025 g_free(filepath);
5026 if (converted_filename)
5027 g_free(converted_filename);
5028 if (!dest)
5029 return;
5031 if (is_file_exist(dest)) {
5032 aval = alertpanel(_("Append or Overwrite"),
5033 _("Append or overwrite existing file?"),
5034 NULL, _("_Append"), NULL, _("_Overwrite"),
5035 NULL, _("_Cancel"), ALERTFOCUS_FIRST);
5036 if (aval != 0 && aval != 1)
5037 return;
5040 src = procmsg_get_message_file(msginfo);
5041 tmp = g_path_get_basename(dest);
5043 if ( aval==0 ) { /* append */
5044 if (append_file(src, dest, TRUE) < 0)
5045 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
5046 } else { /* overwrite */
5047 if (copy_file(src, dest, TRUE) < 0)
5048 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
5050 g_free(src);
5053 * If two or more msgs are selected,
5054 * append them to the output file.
5056 if (GTK_CMCLIST(ctree)->selection->next) {
5057 GList *item;
5058 for (item = GTK_CMCLIST(ctree)->selection->next; item != NULL; item=item->next) {
5059 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(item->data));
5060 if (!msginfo) break;
5061 src = procmsg_get_message_file(msginfo);
5062 if (append_file(src, dest, TRUE) < 0) {
5063 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
5065 g_free(src);
5069 filedir = g_path_get_dirname(dest);
5070 if (filedir) {
5071 if (strcmp(filedir, ".")) {
5072 g_free(prefs_common.attach_save_dir);
5073 prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
5075 g_free(filedir);
5078 g_free(dest);
5079 g_free(tmp);
5082 void summary_print(SummaryView *summaryview)
5084 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
5085 GList *cur;
5086 gchar *msg = g_strdup_printf(_("You are about to print %d "
5087 "messages, one by one. Do you "
5088 "want to continue?"),
5089 g_list_length(clist->selection));
5090 if (g_list_length(clist->selection) > 9
5091 && alertpanel(_("Warning"), msg, NULL, _("_Cancel"), NULL, _("_Yes"),
5092 NULL, NULL, ALERTFOCUS_SECOND) != G_ALERTALTERNATE) {
5093 g_free(msg);
5094 return;
5096 g_free(msg);
5098 if (clist->selection == NULL) return;
5099 for (cur = clist->selection;
5100 cur != NULL && cur->data != NULL;
5101 cur = cur->next) {
5102 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(cur->data);
5103 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(
5104 GTK_CMCTREE(summaryview->ctree),
5105 node);
5106 gint sel_start = -1, sel_end = -1, partnum = 0;
5108 if (node == summaryview->displayed) {
5109 partnum = mimeview_get_selected_part_num(summaryview->messageview->mimeview);
5110 textview_get_selection_offsets(summaryview->messageview->mimeview->textview,
5111 &sel_start, &sel_end);
5113 messageview_print(msginfo, summaryview->messageview->all_headers,
5114 sel_start, sel_end, partnum);
5118 gboolean summary_execute(SummaryView *summaryview)
5120 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5121 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
5122 GtkCMCTreeNode *node, *next;
5123 GtkCMCTreeNode *new_selected = NULL;
5124 gint move_val = -1;
5126 if (!summaryview->folder_item) return FALSE;
5128 if (summary_is_locked(summaryview)) return FALSE;
5129 summary_lock(summaryview);
5131 summary_freeze(summaryview);
5133 main_window_cursor_wait(summaryview->mainwin);
5135 if (summaryview->threaded)
5136 summary_unthread_for_exec(summaryview);
5138 folder_item_update_freeze();
5139 move_val = summary_execute_move(summaryview);
5140 summary_execute_copy(summaryview);
5141 summary_execute_delete(summaryview);
5143 node = GTK_CMCTREE_NODE(clist->row_list);
5144 for (; node != NULL; node = next) {
5145 next = gtkut_ctree_node_next(ctree, node);
5146 if (gtk_cmctree_node_get_row_data(ctree, node) != NULL) continue;
5148 if (node == summaryview->displayed) {
5149 messageview_clear(summaryview->messageview);
5150 summary_cancel_mark_read_timeout(summaryview);
5151 summaryview->displayed = NULL;
5153 if (GTK_CMCTREE_ROW(node)->children != NULL) {
5154 next = NULL;
5155 if (GTK_CMCTREE_ROW(node)->sibling) {
5156 next = GTK_CMCTREE_ROW(node)->sibling;
5157 } else {
5158 GtkCMCTreeNode *parent = NULL;
5159 for (parent = GTK_CMCTREE_ROW(node)->parent; parent != NULL;
5160 parent = GTK_CMCTREE_ROW(parent)->parent) {
5161 if (GTK_CMCTREE_ROW(parent)->sibling) {
5162 next = GTK_CMCTREE_ROW(parent)->sibling;
5168 if (!new_selected &&
5169 gtkut_ctree_node_is_selected(ctree, node)) {
5170 summary_unselect_all(summaryview);
5171 if (summaryview->sort_type == SORT_ASCENDING) {
5172 new_selected = summary_find_next_msg(summaryview, node,TRUE);
5173 if (!new_selected || prefs_common.next_on_delete == FALSE)
5174 new_selected = summary_find_prev_msg(summaryview, node,TRUE);
5175 } else {
5176 new_selected = summary_find_prev_msg(summaryview, node,TRUE);
5177 if (!new_selected || prefs_common.next_on_delete == FALSE)
5178 new_selected = summary_find_next_msg(summaryview, node,TRUE);
5182 gtk_sctree_remove_node((GtkSCTree *)ctree, node);
5185 folder_item_update_thaw();
5187 if (new_selected) {
5188 summary_unlock(summaryview);
5189 summary_select_node(summaryview, new_selected, OPEN_SELECTED_ON_DELETEMOVE);
5190 summary_lock(summaryview);
5193 if (summaryview->threaded) {
5194 summary_thread_build(summaryview);
5195 summary_thread_init(summaryview);
5198 summary_thaw(summaryview);
5200 summaryview->selected = clist->selection ?
5201 GTK_CMCTREE_NODE(clist->selection->data) : NULL;
5203 if (!GTK_CMCLIST(summaryview->ctree)->row_list) {
5204 menu_set_insensitive_all
5205 (GTK_MENU_SHELL(summaryview->popupmenu));
5206 folderview_grab_focus(summaryview->folderview);
5207 } else {
5208 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
5209 gtk_widget_grab_focus(summaryview->ctree);
5211 summary_update_status(summaryview);
5212 summary_status_show(summaryview);
5214 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5216 summary_unlock(summaryview);
5218 main_window_cursor_normal(summaryview->mainwin);
5220 if (move_val < 0)
5221 summary_show(summaryview, summaryview->folder_item, FALSE);
5222 return TRUE;
5225 gboolean summary_expunge(SummaryView *summaryview)
5227 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5228 GtkCMCList *clist = GTK_CMCLIST(summaryview->ctree);
5229 GtkCMCTreeNode *node, *next;
5230 GtkCMCTreeNode *new_selected = NULL;
5232 if (!summaryview->folder_item) return FALSE;
5234 if (summary_is_locked(summaryview)) return FALSE;
5236 summary_lock(summaryview);
5238 summary_freeze(summaryview);
5240 main_window_cursor_wait(summaryview->mainwin);
5242 if (summaryview->threaded)
5243 summary_unthread_for_exec(summaryview);
5245 folder_item_update_freeze();
5246 summary_execute_expunge(summaryview);
5248 node = GTK_CMCTREE_NODE(clist->row_list);
5249 for (; node != NULL; node = next) {
5250 next = gtkut_ctree_node_next(ctree, node);
5251 if (gtk_cmctree_node_get_row_data(ctree, node) != NULL) continue;
5253 if (node == summaryview->displayed) {
5254 messageview_clear(summaryview->messageview);
5255 summary_cancel_mark_read_timeout(summaryview);
5256 summaryview->displayed = NULL;
5258 if (GTK_CMCTREE_ROW(node)->children != NULL) {
5259 next = NULL;
5260 if (GTK_CMCTREE_ROW(node)->sibling) {
5261 next = GTK_CMCTREE_ROW(node)->sibling;
5262 } else {
5263 GtkCMCTreeNode *parent = NULL;
5264 for (parent = GTK_CMCTREE_ROW(node)->parent; parent != NULL;
5265 parent = GTK_CMCTREE_ROW(parent)->parent) {
5266 if (GTK_CMCTREE_ROW(parent)->sibling) {
5267 next = GTK_CMCTREE_ROW(parent)->sibling;
5273 if (!new_selected &&
5274 gtkut_ctree_node_is_selected(ctree, node)) {
5275 summary_unselect_all(summaryview);
5276 new_selected = summary_find_next_msg(summaryview, node,TRUE);
5277 if (!new_selected)
5278 new_selected = summary_find_prev_msg
5279 (summaryview, node,TRUE);
5282 gtk_sctree_remove_node((GtkSCTree *)ctree, node);
5285 folder_item_update_thaw();
5287 if (new_selected) {
5288 summary_unlock(summaryview);
5289 summary_select_node(summaryview, new_selected, OPEN_SELECTED_ON_DELETEMOVE);
5290 summary_lock(summaryview);
5293 if (summaryview->threaded) {
5294 summary_thread_build(summaryview);
5295 summary_thread_init(summaryview);
5298 summary_thaw(summaryview);
5300 summaryview->selected = clist->selection ?
5301 GTK_CMCTREE_NODE(clist->selection->data) : NULL;
5303 if (!GTK_CMCLIST(summaryview->ctree)->row_list) {
5304 menu_set_insensitive_all
5305 (GTK_MENU_SHELL(summaryview->popupmenu));
5306 folderview_grab_focus(summaryview->folderview);
5307 } else {
5308 menu_set_sensitive_all(GTK_MENU_SHELL(summaryview->popupmenu), TRUE);
5309 gtk_widget_grab_focus(summaryview->ctree);
5312 summary_update_status(summaryview);
5313 summary_status_show(summaryview);
5315 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5317 summary_unlock(summaryview);
5319 main_window_cursor_normal(summaryview->mainwin);
5321 return TRUE;
5324 static gint summary_execute_move(SummaryView *summaryview)
5326 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5327 GSList *cur;
5328 gint val = -1;
5329 /* search moving messages and execute */
5331 gtk_cmctree_pre_recursive(ctree, NULL, summary_execute_move_func,
5332 summaryview);
5334 if (summaryview->mlist) {
5335 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5336 summaryview->msginfo_update_callback_id);
5337 val = procmsg_move_messages(summaryview->mlist);
5338 summaryview->msginfo_update_callback_id =
5339 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5340 summary_update_msg, (gpointer) summaryview);
5342 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next) {
5343 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5346 g_slist_free(summaryview->mlist);
5347 summaryview->mlist = NULL;
5348 return val;
5350 return 0;
5353 static void summary_execute_move_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5354 gpointer data)
5356 SummaryView *summaryview = data;
5357 MsgInfo *msginfo;
5359 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5361 if (msginfo && MSG_IS_MOVE(msginfo->flags) && msginfo->to_folder) {
5362 summaryview->mlist =
5363 g_slist_prepend(summaryview->mlist, msginfo);
5364 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5366 if (msginfo->msgid && *msginfo->msgid &&
5367 node == g_hash_table_lookup(summaryview->msgid_table,
5368 msginfo->msgid))
5369 g_hash_table_remove(summaryview->msgid_table,
5370 msginfo->msgid);
5371 if (prefs_common.thread_by_subject &&
5372 msginfo->subject && *msginfo->subject &&
5373 node == subject_table_lookup(summaryview->subject_table,
5374 msginfo->subject)) {
5375 subject_table_remove(summaryview->subject_table,
5376 msginfo->subject);
5381 static void summary_execute_copy(SummaryView *summaryview)
5383 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5385 /* search copying messages and execute */
5386 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5387 summaryview->msginfo_update_callback_id);
5388 gtk_cmctree_pre_recursive(ctree, NULL, summary_execute_copy_func,
5389 summaryview);
5391 if (summaryview->mlist) {
5392 summaryview->mlist = g_slist_reverse(summaryview->mlist);
5393 procmsg_copy_messages(summaryview->mlist);
5395 g_slist_free(summaryview->mlist);
5396 summaryview->mlist = NULL;
5398 summaryview->msginfo_update_callback_id =
5399 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5400 summary_update_msg, (gpointer) summaryview);
5403 static void summary_execute_copy_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5404 gpointer data)
5406 SummaryView *summaryview = data;
5407 MsgInfo *msginfo;
5409 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5411 if (msginfo && MSG_IS_COPY(msginfo->flags) && msginfo->to_folder) {
5412 summaryview->mlist =
5413 g_slist_prepend(summaryview->mlist, msginfo);
5415 summary_msginfo_unset_flags(msginfo, 0, MSG_COPY);
5416 summary_set_row_marks(summaryview, node);
5420 static void summary_execute_delete(SummaryView *summaryview)
5422 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5423 GSList *cur;
5425 /* search deleting messages and execute */
5426 gtk_cmctree_pre_recursive
5427 (ctree, NULL, summary_execute_delete_func, summaryview);
5429 if (!summaryview->mlist) return;
5431 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5432 summaryview->msginfo_update_callback_id);
5434 folder_item_remove_msgs(summaryview->folder_item,
5435 summaryview->mlist);
5437 summaryview->msginfo_update_callback_id =
5438 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5439 summary_update_msg, (gpointer) summaryview);
5441 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next) {
5442 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5445 g_slist_free(summaryview->mlist);
5446 summaryview->mlist = NULL;
5449 static void summary_execute_delete_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5450 gpointer data)
5452 SummaryView *summaryview = data;
5453 MsgInfo *msginfo;
5455 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5457 if (msginfo && MSG_IS_DELETED(msginfo->flags)) {
5458 summaryview->mlist =
5459 g_slist_prepend(summaryview->mlist, msginfo);
5460 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5462 if (msginfo->msgid && *msginfo->msgid &&
5463 node == g_hash_table_lookup(summaryview->msgid_table,
5464 msginfo->msgid)) {
5465 g_hash_table_remove(summaryview->msgid_table,
5466 msginfo->msgid);
5468 if (prefs_common.thread_by_subject &&
5469 msginfo->subject && *msginfo->subject &&
5470 node == subject_table_lookup(summaryview->subject_table,
5471 msginfo->subject)) {
5472 subject_table_remove(summaryview->subject_table,
5473 msginfo->subject);
5478 static void summary_execute_expunge_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5479 gpointer data)
5481 SummaryView *summaryview = data;
5482 MsgInfo *msginfo;
5484 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5486 if (msginfo && MSG_IS_DELETED(msginfo->flags)) {
5487 summaryview->mlist =
5488 g_slist_prepend(summaryview->mlist, msginfo);
5489 gtk_cmctree_node_set_row_data(ctree, node, NULL);
5491 if (msginfo->msgid && *msginfo->msgid &&
5492 node == g_hash_table_lookup(summaryview->msgid_table,
5493 msginfo->msgid)) {
5494 g_hash_table_remove(summaryview->msgid_table,
5495 msginfo->msgid);
5497 if (prefs_common.thread_by_subject &&
5498 msginfo->subject && *msginfo->subject &&
5499 node == subject_table_lookup(summaryview->subject_table,
5500 msginfo->subject)) {
5501 subject_table_remove(summaryview->subject_table,
5502 msginfo->subject);
5507 static void summary_execute_expunge(SummaryView *summaryview)
5509 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5510 GSList *cur;
5512 gtk_cmctree_pre_recursive
5513 (ctree, NULL, summary_execute_expunge_func, summaryview);
5515 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
5516 summaryview->msginfo_update_callback_id);
5518 folder_item_expunge(summaryview->folder_item);
5520 summaryview->msginfo_update_callback_id =
5521 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST,
5522 summary_update_msg, (gpointer) summaryview);
5523 for (cur = summaryview->mlist; cur != NULL && cur->data != NULL; cur = cur->next)
5524 procmsg_msginfo_free((MsgInfo **)&(cur->data));
5526 g_slist_free(summaryview->mlist);
5527 summaryview->mlist = NULL;
5530 /* thread functions */
5532 static void summary_thread_build(SummaryView *summaryview)
5534 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5535 GtkCMCTreeNode *node;
5536 GtkCMCTreeNode *next;
5537 GtkCMCTreeNode *parent;
5538 MsgInfo *msginfo;
5539 GSList *reflist;
5541 summary_lock(summaryview);
5543 debug_print("Building threads...\n");
5544 STATUSBAR_PUSH(summaryview->mainwin, _("Building threads..."));
5545 main_window_cursor_wait(summaryview->mainwin);
5547 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5548 G_CALLBACK(summary_tree_expanded), summaryview);
5549 summary_freeze(summaryview);
5551 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5552 while (node) {
5553 next = GTK_CMCTREE_ROW(node)->sibling;
5555 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5557 parent = NULL;
5559 if (msginfo && msginfo->inreplyto) {
5560 parent = g_hash_table_lookup(summaryview->msgid_table,
5561 msginfo->inreplyto);
5563 if (!parent && msginfo->references) {
5564 for (reflist = msginfo->references;
5565 reflist != NULL; reflist = reflist->next)
5566 if ((parent = g_hash_table_lookup
5567 (summaryview->msgid_table,
5568 reflist->data)))
5569 break;
5573 if (msginfo && prefs_common.thread_by_subject && parent == NULL) {
5574 parent = subject_table_lookup
5575 (summaryview->subject_table,
5576 msginfo->subject);
5579 if (parent && parent != node && parent != GTK_CMCTREE_ROW(node)->parent) {
5580 gtk_cmctree_move(ctree, node, parent, NULL);
5583 node = next;
5586 gtkut_ctree_set_focus_row(ctree, summaryview->selected);
5588 summary_thaw(summaryview);
5589 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5590 G_CALLBACK(summary_tree_expanded), summaryview);
5592 debug_print("Building threads done.\n");
5593 STATUSBAR_POP(summaryview->mainwin);
5594 main_window_cursor_normal(summaryview->mainwin);
5596 summaryview->threaded = TRUE;
5598 summary_unlock(summaryview);
5601 static void summary_thread_init(SummaryView *summaryview)
5603 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5604 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5605 GtkCMCTreeNode *next;
5606 START_TIMING("");
5607 if (!summaryview->thread_collapsed) {
5608 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5609 G_CALLBACK(summary_tree_expanded), summaryview);
5610 while (node) {
5611 next = GTK_CMCTREE_ROW(node)->sibling;
5612 if (GTK_CMCTREE_ROW(node)->children)
5613 gtk_cmctree_expand_recursive(ctree, node);
5614 node = next;
5616 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5617 G_CALLBACK(summary_tree_expanded), summaryview);
5619 END_TIMING();
5622 static void summary_unthread_for_exec(SummaryView *summaryview)
5624 GtkCMCTreeNode *node;
5625 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5626 gboolean froze = FALSE;
5628 debug_print("Unthreading for execution...\n");
5630 START_LONG_OPERATION(summaryview, TRUE);
5631 for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5632 node != NULL; node = GTK_CMCTREE_NODE_NEXT(node)) {
5633 summary_unthread_for_exec_func(ctree, node, summaryview);
5636 END_LONG_OPERATION(summaryview);
5638 debug_print("Unthreading for execution done.\n");
5641 static void summary_unthread_for_exec_func(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5642 gpointer data)
5644 MsgInfo *msginfo;
5645 GtkCMCTreeNode *top_parent;
5646 GtkCMCTreeNode *child;
5647 GtkCMCTreeNode *sibling;
5648 SummaryView * summaryview = (SummaryView *)data;
5649 msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
5651 if (!msginfo ||
5652 (!MSG_IS_MOVE(msginfo->flags) &&
5653 !MSG_IS_DELETED(msginfo->flags)))
5654 return;
5655 child = GTK_CMCTREE_ROW(node)->children;
5656 if (!child) return;
5658 if (node == summaryview->selected)
5659 summaryview->selected = NULL;
5660 if (node == summaryview->displayed)
5661 summaryview->displayed = NULL;
5663 summary_cancel_mark_read_timeout(summaryview);
5665 for (top_parent = node;
5666 GTK_CMCTREE_ROW(top_parent)->parent != NULL;
5667 top_parent = GTK_CMCTREE_ROW(top_parent)->parent)
5669 sibling = GTK_CMCTREE_ROW(top_parent)->sibling;
5671 GTK_SCTREE(ctree)->sorting = TRUE;
5672 while (child != NULL) {
5673 GtkCMCTreeNode *next_child;
5674 MsgInfo *cinfo = GTKUT_CTREE_NODE_GET_ROW_DATA(child);
5676 next_child = GTK_CMCTREE_ROW(child)->sibling;
5678 if (!MSG_IS_MOVE(cinfo->flags) && !MSG_IS_DELETED(cinfo->flags)) {
5679 gtk_cmctree_move(ctree, child,
5680 NULL,
5681 sibling);
5682 } else {
5683 if (child == summaryview->displayed) {
5684 messageview_clear(summaryview->messageview);
5685 summaryview->displayed = NULL;
5687 if (child == summaryview->selected) {
5688 messageview_clear(summaryview->messageview);
5689 summaryview->selected = NULL;
5692 child = next_child;
5694 GTK_SCTREE(ctree)->sorting = FALSE;
5697 void summary_expand_threads(SummaryView *summaryview)
5699 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5700 GtkCMCTreeNode *node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5701 GtkCMCTreeNode *focus_node = GTK_CMCTREE_NODE (g_list_nth (GTK_CMCLIST(ctree)->row_list, GTK_CMCLIST(ctree)->focus_row));
5703 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5704 G_CALLBACK(summary_tree_expanded), summaryview);
5705 summary_freeze(summaryview);
5706 GTK_SCTREE(ctree)->sorting = TRUE;
5708 while (node) {
5709 if (GTK_CMCTREE_ROW(node)->children) {
5710 gtk_cmctree_expand(ctree, node);
5711 summary_set_row_marks(summaryview, node);
5713 node = GTK_CMCTREE_NODE_NEXT(node);
5716 GTK_SCTREE(ctree)->sorting = FALSE;
5717 if (focus_node) {
5718 GTK_CMCLIST(ctree)->focus_row = g_list_position (GTK_CMCLIST(ctree)->row_list,(GList *)focus_node);
5720 summary_thaw(summaryview);
5722 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5723 G_CALLBACK(summary_tree_expanded), summaryview);
5725 summaryview->thread_collapsed = FALSE;
5727 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5730 void summary_collapse_threads(SummaryView *summaryview)
5732 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
5733 GtkCMCTreeNode *node = NULL;
5734 GtkCMCTreeNode *focus_node = GTK_CMCTREE_NODE (g_list_nth (GTK_CMCLIST(ctree)->row_list, GTK_CMCLIST(ctree)->focus_row));
5736 g_signal_handlers_block_by_func(G_OBJECT(ctree),
5737 G_CALLBACK(summary_tree_collapsed), summaryview);
5738 summary_freeze(summaryview);
5739 GTK_SCTREE(ctree)->sorting = TRUE;
5741 node = focus_node;
5742 while (node && GTK_CMCTREE_ROW(node)->parent) {
5743 focus_node = node = GTK_CMCTREE_ROW(node)->parent;
5745 summary_select_node(summaryview, node, OPEN_SELECTED_ON_DIRECTIONAL);
5746 node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
5747 while (node) {
5748 if (GTK_CMCTREE_ROW(node)->children) {
5749 gtk_cmctree_collapse(ctree, node);
5750 summary_set_row_marks(summaryview, node);
5752 node = GTK_CMCTREE_ROW(node)->sibling;
5755 GTK_SCTREE(ctree)->sorting = FALSE;
5756 if (focus_node) {
5757 GTK_CMCLIST(ctree)->focus_row = g_list_position (GTK_CMCLIST(ctree)->row_list,(GList *)focus_node);
5759 GTK_SCTREE(ctree)->anchor_row =
5760 gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->focus_row);
5761 summary_thaw(summaryview);
5762 g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
5763 G_CALLBACK(summary_tree_collapsed), summaryview);
5765 summaryview->thread_collapsed = TRUE;
5767 gtk_cmctree_node_moveto(ctree, summaryview->selected, 0, 0.5, 0);
5770 static void account_rules_radio_button_toggled_cb(GtkToggleButton *btn, gpointer data)
5772 prefs_common.apply_per_account_filtering_rules = GPOINTER_TO_INT(data);
5775 static gboolean summary_filter_get_mode(void)
5776 /* ask what to do w/ them: skip them, apply them regardless to the account,
5777 use the current account */
5779 /* TODO: eventually also propose to use the current folder's default account,
5780 if it is set */
5781 /* TODO: eventually allow to select the account to use from a optmenu */
5783 GtkWidget *vbox;
5784 GtkWidget *account_rules_skip;
5785 GtkWidget *account_rules_force;
5786 GtkWidget *account_rules_user_current;
5787 AlertValue val;
5789 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
5791 account_rules_skip = gtk_radio_button_new_with_label
5792 (NULL, _("Skip these rules"));
5793 account_rules_force = gtk_radio_button_new_with_label_from_widget
5794 (GTK_RADIO_BUTTON(account_rules_skip),
5795 _("Apply these rules regardless of the account they belong to"));
5796 account_rules_user_current = gtk_radio_button_new_with_label_from_widget
5797 (GTK_RADIO_BUTTON(account_rules_skip),
5798 _("Apply these rules if they apply to the current account"));
5799 gtk_box_pack_start (GTK_BOX (vbox), account_rules_skip, FALSE, FALSE, 0);
5800 gtk_box_pack_start (GTK_BOX (vbox), account_rules_force, FALSE, FALSE, 0);
5801 gtk_box_pack_start (GTK_BOX (vbox), account_rules_user_current, FALSE, FALSE, 0);
5802 g_signal_connect(G_OBJECT(account_rules_skip), "toggled",
5803 G_CALLBACK(account_rules_radio_button_toggled_cb),
5804 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_SKIP));
5805 g_signal_connect(G_OBJECT(account_rules_force), "toggled",
5806 G_CALLBACK(account_rules_radio_button_toggled_cb),
5807 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_FORCE));
5808 g_signal_connect(G_OBJECT(account_rules_user_current), "toggled",
5809 G_CALLBACK(account_rules_radio_button_toggled_cb),
5810 GINT_TO_POINTER(FILTERING_ACCOUNT_RULES_USE_CURRENT));
5811 switch (prefs_common.apply_per_account_filtering_rules) {
5812 case FILTERING_ACCOUNT_RULES_SKIP:
5813 gtk_toggle_button_set_active(
5814 GTK_TOGGLE_BUTTON(account_rules_skip), TRUE);
5815 break;
5816 case FILTERING_ACCOUNT_RULES_FORCE:
5817 gtk_toggle_button_set_active(
5818 GTK_TOGGLE_BUTTON(account_rules_force), TRUE);
5819 break;
5820 case FILTERING_ACCOUNT_RULES_USE_CURRENT:
5821 gtk_toggle_button_set_active(
5822 GTK_TOGGLE_BUTTON(account_rules_user_current), TRUE);
5823 break;
5826 val = alertpanel_with_widget(
5827 _("Filtering"),
5828 _("There are some filtering rules that belong to an account.\n"
5829 "Please choose what to do with these rules:"),
5830 NULL, _("_Cancel"), NULL, _("_Filter"), NULL, NULL,
5831 ALERTFOCUS_SECOND, TRUE, vbox);
5833 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE) {
5834 return FALSE;
5835 } else if (val & G_ALERTDISABLE)
5836 prefs_common.ask_apply_per_account_filtering_rules = FALSE;
5838 return TRUE;
5841 void summary_filter(SummaryView *summaryview, gboolean selected_only)
5843 GSList *mlist = NULL, *cur_list;
5844 PrefsAccount *ac_prefs = NULL;
5845 summary_lock(summaryview);
5847 /* are there any per-account filtering rules? */
5848 if (prefs_common.ask_apply_per_account_filtering_rules == TRUE &&
5849 filtering_peek_per_account_rules(filtering_rules)) {
5851 if (summary_filter_get_mode() == FALSE) {
5852 summary_unlock(summaryview);
5853 return;
5857 folder_item_update_freeze();
5859 debug_print("filtering...\n");
5860 STATUSBAR_PUSH(summaryview->mainwin, _("Filtering..."));
5861 main_window_cursor_wait(summaryview->mainwin);
5863 summary_freeze(summaryview);
5865 if (selected_only) {
5866 GList *cur;
5868 for (cur = GTK_CMCLIST(summaryview->ctree)->selection;
5869 cur != NULL && cur->data != NULL; cur = cur->next) {
5870 mlist = g_slist_prepend(mlist,
5871 procmsg_msginfo_new_ref(
5872 GTKUT_CTREE_NODE_GET_ROW_DATA(cur->data)));
5874 mlist = g_slist_reverse(mlist);
5875 } else {
5876 mlist = folder_item_get_msg_list(summaryview->folder_item);
5879 ac_prefs = ((summaryview->folder_item->folder != NULL) &&
5880 (summaryview->folder_item->folder->account != NULL))
5881 ? summaryview->folder_item->folder->account : NULL;
5883 folder_item_set_batch(summaryview->folder_item, TRUE);
5884 for (cur_list = mlist; cur_list; cur_list = cur_list->next) {
5885 summary_filter_func((MsgInfo *)cur_list->data, ac_prefs);
5887 folder_item_set_batch(summaryview->folder_item, FALSE);
5889 filtering_move_and_copy_msgs(mlist);
5891 for (cur_list = mlist; cur_list; cur_list = cur_list->next) {
5892 procmsg_msginfo_free((MsgInfo **)&(cur_list->data));
5894 g_slist_free(mlist);
5896 summary_thaw(summaryview);
5898 folder_item_update_thaw();
5899 debug_print("filtering done.\n");
5900 STATUSBAR_POP(summaryview->mainwin);
5901 main_window_cursor_normal(summaryview->mainwin);
5903 summary_unlock(summaryview);
5906 * CLAWS: summary_show() only valid after having a lock. ideally
5907 * we want the lock to be context aware...
5909 summary_show(summaryview, summaryview->folder_item, TRUE);
5912 static void summary_filter_func(MsgInfo *msginfo, PrefsAccount *ac_prefs)
5914 MailFilteringData mail_filtering_data;
5916 mail_filtering_data.msginfo = msginfo;
5917 mail_filtering_data.msglist = NULL;
5918 mail_filtering_data.filtered = NULL;
5919 mail_filtering_data.unfiltered = NULL;
5920 if (hooks_invoke(MAIL_MANUAL_FILTERING_HOOKLIST, &mail_filtering_data))
5921 return;
5923 filter_message_by_msginfo(filtering_rules, msginfo, ac_prefs,
5924 FILTERING_MANUALLY, NULL);
5927 void summary_msginfo_filter_open(FolderItem * item, MsgInfo *msginfo,
5928 PrefsFilterType type, gint processing_rule)
5930 gchar *header = NULL;
5931 gchar *key = NULL;
5933 procmsg_get_filter_keyword(msginfo, &header, &key, type);
5935 if (processing_rule) {
5936 if (item == NULL)
5937 prefs_filtering_open(&pre_global_processing,
5938 _("Processing rules to apply before folder rules"),
5939 MANUAL_ANCHOR_PROCESSING,
5940 header, key, FALSE);
5941 else
5942 prefs_filtering_open(&item->prefs->processing,
5943 _("Processing configuration"),
5944 MANUAL_ANCHOR_PROCESSING,
5945 header, key, FALSE);
5947 else {
5948 prefs_filtering_open(&filtering_rules,
5949 _("Filtering configuration"),
5950 MANUAL_ANCHOR_FILTERING,
5951 header, key, TRUE);
5954 g_free(header);
5955 g_free(key);
5958 void summary_filter_open(SummaryView *summaryview, PrefsFilterType type,
5959 gint processing_rule)
5961 MsgInfo *msginfo;
5962 FolderItem * item;
5964 if (!summaryview->selected) return;
5966 msginfo = gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
5967 summaryview->selected);
5968 if (!msginfo) return;
5970 item = summaryview->folder_item;
5971 summary_msginfo_filter_open(item, msginfo, type, processing_rule);
5974 /* color label */
5976 #define N_COLOR_LABELS colorlabel_get_color_count()
5978 static void summary_colorlabel_menu_item_activate_cb(GtkWidget *widget,
5979 gpointer data)
5981 guint color = GPOINTER_TO_UINT(data);
5982 SummaryView *summaryview;
5984 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
5985 cm_return_if_fail(summaryview != NULL);
5987 /* "dont_toggle" state set? */
5988 if (g_object_get_data(G_OBJECT(summaryview->colorlabel_menu),
5989 "dont_toggle"))
5990 return;
5992 summary_set_colorlabel(summaryview, color, NULL);
5995 /* summary_set_colorlabel_color() - labelcolor parameter is the color *flag*
5996 * for the message; not the color index */
5997 void summary_set_colorlabel_color(GtkCMCTree *ctree, GtkCMCTreeNode *node,
5998 guint labelcolor)
6000 GdkColor color;
6001 GdkRGBA rgba;
6002 GtkStyle *style, *prev_style, *ctree_style;
6003 MsgInfo *msginfo;
6004 gint color_index;
6006 msginfo = gtk_cmctree_node_get_row_data(ctree, node);
6007 cm_return_if_fail(msginfo);
6009 color_index = labelcolor == 0 ? -1 : (gint)labelcolor - 1;
6010 ctree_style = gtk_widget_get_style(GTK_WIDGET(ctree));
6011 prev_style = gtk_cmctree_node_get_row_style(ctree, node);
6013 if (color_index < 0 || color_index >= N_COLOR_LABELS) {
6014 if (!prev_style) return;
6015 style = gtk_style_copy(prev_style);
6016 color = ctree_style->text[GTK_STATE_NORMAL];
6017 style->text[GTK_STATE_NORMAL] = color;
6018 color = ctree_style->text[GTK_STATE_SELECTED];
6019 style->text[GTK_STATE_SELECTED] = color;
6020 } else {
6021 if (prev_style)
6022 style = gtk_style_copy(prev_style);
6023 else
6024 style = gtk_style_copy(ctree_style);
6025 rgba = colorlabel_get_color(color_index);
6026 GTKUT_GDKRGBA_TO_GDKCOLOR(rgba, color);
6027 style->text[GTK_STATE_NORMAL] = color;
6028 /* get the average of label color and selected fg color
6029 for visibility */
6030 style->text[GTK_STATE_SELECTED].red = (color.red + 3*ctree_style->text[GTK_STATE_SELECTED].red ) / 4;
6031 style->text[GTK_STATE_SELECTED].green = (color.green + 3*ctree_style->text[GTK_STATE_SELECTED].green) / 4;
6032 style->text[GTK_STATE_SELECTED].blue = (color.blue + 3*ctree_style->text[GTK_STATE_SELECTED].blue ) / 4;
6035 gtk_cmctree_node_set_row_style(ctree, node, style);
6036 g_object_unref(style);
6039 static void summary_set_row_colorlabel(SummaryView *summaryview, GtkCMCTreeNode *row, guint labelcolor)
6041 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
6042 MsgInfo *msginfo;
6044 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
6045 cm_return_if_fail(msginfo);
6047 summary_msginfo_change_flags(msginfo, MSG_COLORLABEL_TO_FLAGS(labelcolor), 0,
6048 MSG_CLABEL_FLAG_MASK, 0);
6049 summary_set_row_marks(summaryview, row);
6052 void summary_set_colorlabel(SummaryView *summaryview, guint labelcolor,
6053 GtkWidget *widget)
6055 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
6056 GList *cur;
6057 gboolean froze = FALSE;
6059 if (prefs_common.ask_override_colorlabel) {
6060 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
6061 gboolean ask = FALSE;
6062 AlertValue val;
6063 guint color;
6064 gboolean already_this_color_everywhere = TRUE;
6066 /* if clearing color labels (applying 'none', 0):
6067 - ask if at least one message has a non-0 color label set
6068 if applying a non-0 color label:
6069 - ask if at least one of the selected messages has a non-0 color label different
6070 from the one we want to apply.
6071 - don't ask if all messages have the same color label as the one we're applying
6073 for (cur = GTK_CMCLIST(ctree)->selection;
6074 !ask && cur != NULL && cur->data != NULL;
6075 cur = cur->next) {
6076 MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(cur->data));
6077 if (msginfo) {
6078 color = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
6079 if (labelcolor == 0) {
6080 /* clearing color labels */
6081 ask = (color != 0);
6082 } else {
6083 already_this_color_everywhere &= (color == labelcolor);
6084 ask = ((color != 0) && (color != labelcolor)) && !already_this_color_everywhere;
6089 if (ask) {
6090 gchar *msg;
6092 if (labelcolor == 0)
6093 msg = _("Do you really want to reset the color label of all selected messages?");
6094 else
6095 msg = _("Do you really want to apply this color label to all selected messages?");
6096 val = alertpanel_full(labelcolor == 0? _("Reset color label"): _("Set color label"), msg,
6097 NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST,
6098 TRUE, NULL, ALERT_QUESTION);
6100 if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
6101 return;
6102 else if (val & G_ALERTDISABLE)
6103 prefs_common.ask_override_colorlabel = FALSE;
6107 START_LONG_OPERATION(summaryview, FALSE);
6108 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
6109 summary_set_row_colorlabel(summaryview,
6110 GTK_CMCTREE_NODE(cur->data), labelcolor);
6111 END_LONG_OPERATION(summaryview);
6114 static gboolean summary_set_row_tag(SummaryView *summaryview, GtkCMCTreeNode *row, gboolean refresh, gboolean set, gint id)
6116 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
6117 MsgInfo *msginfo;
6118 gchar *tags_str = NULL;
6119 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
6120 cm_return_val_if_fail(msginfo, FALSE);
6122 procmsg_msginfo_update_tags(msginfo, set, id);
6124 if (summaryview->col_state[summaryview->col_pos[S_COL_TAGS]].visible) {
6125 tags_str = procmsg_msginfo_get_tags_str(msginfo);
6126 gtk_cmctree_node_set_text(ctree, row,
6127 summaryview->col_pos[S_COL_TAGS],
6128 tags_str?tags_str:"-");
6129 g_free(tags_str);
6132 summary_set_row_marks(summaryview, row);
6133 if (row == summaryview->displayed) {
6134 return TRUE;
6136 return FALSE;
6139 void summary_set_tag(SummaryView *summaryview, gint tag_id,
6140 GtkWidget *widget)
6142 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
6143 GList *cur;
6144 gboolean set = tag_id > 0;
6145 gint real_id = set? tag_id:-tag_id;
6146 gboolean froze = FALSE;
6147 gboolean redisplay = FALSE;
6149 if (summary_is_locked(summaryview))
6150 return;
6151 START_LONG_OPERATION(summaryview, FALSE);
6152 folder_item_set_batch(summaryview->folder_item, TRUE);
6153 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next) {
6154 redisplay |= summary_set_row_tag(summaryview,
6155 GTK_CMCTREE_NODE(cur->data), FALSE, set, real_id);
6157 folder_item_set_batch(summaryview->folder_item, FALSE);
6158 END_LONG_OPERATION(summaryview);
6159 if (redisplay)
6160 summary_redisplay_msg(summaryview);
6163 static void summary_tags_menu_item_activate_cb(GtkWidget *widget,
6164 gpointer data)
6166 gint id = GPOINTER_TO_INT(data);
6167 gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
6168 SummaryView *summaryview;
6170 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
6171 cm_return_if_fail(summaryview != NULL);
6173 /* "dont_toggle" state set? */
6174 if (g_object_get_data(G_OBJECT(summaryview->tags_menu),
6175 "dont_toggle"))
6176 return;
6178 if (!set)
6179 id = -id;
6180 summary_set_tag(summaryview, id, NULL);
6183 static void summary_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
6184 gpointer data)
6186 SummaryView *summaryview;
6187 GtkMenuShell *menu;
6188 GtkCheckMenuItem **items;
6189 gint n;
6190 GList *children, *cur, *sel;
6192 summaryview = (SummaryView *)data;
6193 cm_return_if_fail(summaryview != NULL);
6195 sel = GTK_CMCLIST(summaryview->ctree)->selection;
6196 if (!sel) return;
6198 menu = GTK_MENU_SHELL(summaryview->colorlabel_menu);
6200 cm_return_if_fail(menu != NULL);
6202 Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
6204 /* NOTE: don't return prematurely because we set the "dont_toggle"
6205 * state for check menu items */
6206 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6207 GINT_TO_POINTER(1));
6209 /* clear items. get item pointers. */
6210 children = gtk_container_get_children(GTK_CONTAINER(menu));
6211 for (n = 0, cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
6212 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
6213 gtk_check_menu_item_set_active
6214 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
6215 gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(cur->data),
6216 TRUE);
6217 items[n] = GTK_CHECK_MENU_ITEM(cur->data);
6218 n++;
6222 g_list_free(children);
6224 if (n == (N_COLOR_LABELS + 1)) {
6225 /* iterate all messages and set the state of the appropriate
6226 * items */
6227 for (; sel != NULL; sel = sel->next) {
6228 MsgInfo *msginfo;
6229 gint clabel;
6231 msginfo = gtk_cmctree_node_get_row_data
6232 (GTK_CMCTREE(summaryview->ctree),
6233 GTK_CMCTREE_NODE(sel->data));
6234 if (msginfo) {
6235 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
6236 if (!gtk_check_menu_item_get_active(items[clabel]))
6237 gtk_check_menu_item_set_active
6238 (items[clabel], TRUE);
6241 } else
6242 g_warning("invalid number of color elements (%d)", n);
6244 /* reset "dont_toggle" state */
6245 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6246 GINT_TO_POINTER(0));
6249 static void summary_colorlabel_menu_create(SummaryView *summaryview, gboolean refresh)
6251 GtkWidget *label_menuitem;
6252 GtkWidget *menu;
6253 GtkWidget *item;
6254 gint i;
6255 gchar *accel_path = NULL;
6257 label_menuitem = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, "/Menus/SummaryViewPopup/ColorLabel");
6258 g_signal_connect(G_OBJECT(label_menuitem), "activate",
6259 G_CALLBACK(summary_colorlabel_menu_item_activate_item_cb),
6260 summaryview);
6261 gtk_widget_show(label_menuitem);
6263 menu = gtk_menu_new();
6265 gtk_menu_set_accel_group (GTK_MENU (menu),
6266 gtk_ui_manager_get_accel_group(mainwindow_get_mainwindow()->ui_manager));
6268 /* create sub items. for the menu item activation callback we pass the
6269 * index of label_colors[] as data parameter. for the None color we
6270 * pass an invalid (high) value. also we attach a data pointer so we
6271 * can always get back the SummaryView pointer. */
6273 item = gtk_check_menu_item_new_with_label(_("None"));
6274 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6275 g_signal_connect(G_OBJECT(item), "activate",
6276 G_CALLBACK(summary_colorlabel_menu_item_activate_cb),
6277 GUINT_TO_POINTER(0));
6278 g_object_set_data(G_OBJECT(item), "summaryview", summaryview);
6279 gtk_widget_show(item);
6281 accel_path = g_strdup_printf("<ClawsColorLabels>/None");
6282 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6283 g_free(accel_path);
6284 gtk_accel_map_add_entry("<ClawsColorLabels>/None", GDK_KEY_0, GDK_CONTROL_MASK);
6286 /* create pixmap/label menu items */
6287 for (i = 0; i < N_COLOR_LABELS; i++) {
6288 item = colorlabel_create_check_color_menu_item(
6289 i, refresh, SUMMARY_COLORMENU);
6290 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6291 g_signal_connect(G_OBJECT(item), "activate",
6292 G_CALLBACK(summary_colorlabel_menu_item_activate_cb),
6293 GUINT_TO_POINTER(i + 1));
6294 g_object_set_data(G_OBJECT(item), "summaryview",
6295 summaryview);
6296 gtk_widget_show(item);
6297 accel_path = g_strdup_printf("<ClawsColorLabels>/%d", i+1);
6298 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6299 if (i < 9)
6300 gtk_accel_map_add_entry(accel_path, GDK_KEY_1+i, GDK_CONTROL_MASK);
6301 g_free(accel_path);
6302 g_signal_connect (gtk_ui_manager_get_accel_group(mainwindow_get_mainwindow()->ui_manager),
6303 "accel-changed", G_CALLBACK (mainwin_accel_changed_cb), item);
6306 gtk_widget_show(menu);
6307 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
6308 summaryview->colorlabel_menu = menu;
6311 static void summary_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
6312 gpointer data)
6314 GtkMenuShell *menu;
6315 GList *children, *cur;
6316 GList *sel;
6317 GHashTable *menu_table = g_hash_table_new_full(
6318 g_direct_hash,
6319 g_direct_equal,
6320 NULL, NULL);
6321 GHashTable *menu_allsel_table = g_hash_table_new_full(
6322 g_direct_hash,
6323 g_direct_equal,
6324 NULL, NULL);
6325 gint sel_len;
6326 SummaryView *summaryview = (SummaryView *)data;
6327 cm_return_if_fail(summaryview != NULL);
6329 sel = GTK_CMCLIST(summaryview->ctree)->selection;
6330 if (!sel) return;
6332 menu = GTK_MENU_SHELL(summaryview->tags_menu);
6333 cm_return_if_fail(menu != NULL);
6335 /* NOTE: don't return prematurely because we set the "dont_toggle"
6336 * state for check menu items */
6337 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6338 GINT_TO_POINTER(1));
6340 /* clear items. get item pointers. */
6341 children = gtk_container_get_children(GTK_CONTAINER(menu));
6342 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
6343 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
6344 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
6345 "tag_id"));
6346 gtk_check_menu_item_set_active
6347 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
6349 g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
6350 g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
6354 g_list_free(children);
6356 /* iterate all messages and set the state of the appropriate
6357 * items */
6358 sel_len = 0;
6359 for (; sel != NULL; sel = sel->next) {
6360 MsgInfo *msginfo;
6361 GSList *tags = NULL;
6362 GtkCheckMenuItem *item;
6363 msginfo = gtk_cmctree_node_get_row_data
6364 (GTK_CMCTREE(summaryview->ctree),
6365 GTK_CMCTREE_NODE(sel->data));
6366 sel_len++;
6367 if (msginfo) {
6368 tags = msginfo->tags;
6369 if (!tags)
6370 continue;
6372 for (; tags; tags = tags->next) {
6373 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
6374 item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
6375 if (item && !gtk_check_menu_item_get_active(item)) {
6376 gtk_check_menu_item_set_active
6377 (item, TRUE);
6379 num_checked++;
6380 g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
6385 children = gtk_container_get_children(GTK_CONTAINER(menu));
6386 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
6387 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
6388 gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
6389 "tag_id"));
6390 gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
6391 if (num_checked < sel_len && num_checked > 0)
6392 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
6393 else
6394 gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
6397 g_list_free(children);
6398 g_hash_table_destroy(menu_table);
6399 g_hash_table_destroy(menu_allsel_table);
6400 /* reset "dont_toggle" state */
6401 g_object_set_data(G_OBJECT(menu), "dont_toggle",
6402 GINT_TO_POINTER(0));
6405 void summaryview_destroy(SummaryView *summaryview)
6407 if(summaryview->simplify_subject_preg) {
6408 regfree(summaryview->simplify_subject_preg);
6409 g_free(summaryview->simplify_subject_preg);
6410 summaryview->simplify_subject_preg = NULL;
6413 static void summary_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
6414 gpointer data)
6416 SummaryView *summaryview;
6418 summaryview = g_object_get_data(G_OBJECT(widget), "summaryview");
6419 cm_return_if_fail(summaryview != NULL);
6421 /* "dont_toggle" state set? */
6422 if (g_object_get_data(G_OBJECT(summaryview->tags_menu),
6423 "dont_toggle"))
6424 return;
6426 tags_window_open(summary_get_selection(summaryview));
6429 static gint summary_tag_cmp_list(gconstpointer a, gconstpointer b)
6431 gint id_a = GPOINTER_TO_INT(a);
6432 gint id_b = GPOINTER_TO_INT(b);
6433 const gchar *tag_a = tags_get_tag(id_a);
6434 const gchar *tag_b = tags_get_tag(id_b);
6436 if (tag_a == NULL)
6437 return tag_b == NULL ? 0:1;
6439 if (tag_b == NULL)
6440 return 1;
6442 return g_utf8_collate(tag_a, tag_b);
6445 static void summary_tags_menu_create(SummaryView *summaryview, gboolean refresh)
6448 GtkWidget *label_menuitem;
6449 GtkWidget *menu;
6450 GtkWidget *item;
6451 GSList *cur = tags_get_list();
6452 GSList *orig = NULL;
6453 gboolean existing_tags = FALSE;
6454 gchar *accel_path = NULL;
6456 cur = orig = g_slist_sort(cur, summary_tag_cmp_list);
6457 label_menuitem = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, "/Menus/SummaryViewPopup/Tags");
6458 g_signal_connect(G_OBJECT(label_menuitem), "activate",
6459 G_CALLBACK(summary_tags_menu_item_activate_item_cb),
6460 summaryview);
6462 gtk_widget_show(label_menuitem);
6464 menu = gtk_menu_new();
6466 gtk_menu_set_accel_group (GTK_MENU (menu),
6467 gtk_ui_manager_get_accel_group(summaryview->mainwin->ui_manager));
6469 /* create tags menu items */
6470 for (; cur; cur = cur->next) {
6471 gint id = GPOINTER_TO_INT(cur->data);
6472 const gchar *tag = tags_get_tag(id);
6473 item = gtk_check_menu_item_new_with_label(tag);
6474 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6475 g_signal_connect(G_OBJECT(item), "activate",
6476 G_CALLBACK(summary_tags_menu_item_activate_cb),
6477 GINT_TO_POINTER(id));
6478 g_object_set_data(G_OBJECT(item), "summaryview",
6479 summaryview);
6480 g_object_set_data(G_OBJECT(item), "tag_id",
6481 GINT_TO_POINTER(id));
6482 gtk_widget_show(item);
6483 accel_path = g_strconcat("<ClawsTags>/",tag, NULL);
6484 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6485 g_free(accel_path);
6486 existing_tags = TRUE;
6488 if (existing_tags) {
6489 /* separator */
6490 item = gtk_separator_menu_item_new();
6491 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6492 gtk_widget_show(item);
6495 item = gtk_menu_item_new_with_label(_("Modify tags..."));
6496 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6497 g_signal_connect(G_OBJECT(item), "activate",
6498 G_CALLBACK(summary_tags_menu_item_apply_tags_activate_cb),
6499 NULL);
6500 g_object_set_data(G_OBJECT(item), "summaryview",
6501 summaryview);
6502 gtk_widget_show(item);
6503 accel_path = g_strdup_printf("<ClawsTags>/ModifyTags");
6504 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
6505 g_free(accel_path);
6507 g_slist_free(orig);
6508 gtk_widget_show(menu);
6509 gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
6510 summaryview->tags_menu = menu;
6513 static gboolean summary_popup_menu(GtkWidget *widget, gpointer data)
6515 SummaryView *summaryview = (SummaryView *)data;
6516 summaryview->display_msg = messageview_is_visible(summaryview->messageview);
6518 gtk_menu_popup_at_pointer(GTK_MENU(summaryview->popupmenu), NULL);
6520 return TRUE;
6523 #if !GENERIC_UMPC
6524 static gchar *summaryview_get_tooltip_text(SummaryView *summaryview, MsgInfo *info, gint column)
6526 MsgFlags flags;
6527 if (!info)
6528 return NULL;
6530 flags = info->flags;
6532 switch(summaryview->col_state[column].type) {
6533 case S_COL_STATUS:
6534 if (MSG_IS_IGNORE_THREAD(flags)) {
6535 return _("Ignored thread");
6536 } else if (MSG_IS_WATCH_THREAD(flags)) {
6537 return _("Watched thread");
6538 } else if (MSG_IS_SPAM(flags)) {
6539 return _("Spam");
6540 } else if (MSG_IS_NEW(flags)) {
6541 return _("New");
6542 } else if (MSG_IS_UNREAD(flags)) {
6543 return _("Unread");
6544 } else if (MSG_IS_REPLIED(flags) && MSG_IS_FORWARDED(flags)) {
6545 return _("Replied but also forwarded - click to see reply");
6546 } else if (MSG_IS_REPLIED(flags)) {
6547 return _("Replied - click to see reply");
6548 } else if (MSG_IS_FORWARDED(flags)) {
6549 return _("Forwarded");
6550 } else {
6551 return NULL;
6553 case S_COL_MARK:
6554 if (MSG_IS_DELETED(flags)) {
6555 return _("Deleted");
6556 } else if (MSG_IS_MARKED(flags)) {
6557 return _("Marked");
6558 } else if (MSG_IS_MOVE(flags)) {
6559 return _("To be moved");
6560 } else if (MSG_IS_COPY(flags)) {
6561 return _("To be copied");
6562 } else {
6563 return NULL;
6565 case S_COL_LOCKED:
6566 if (MSG_IS_LOCKED(flags)) {
6567 return _("Locked");
6568 } else {
6569 return NULL;
6571 case S_COL_MIME:
6572 if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_SIGNED(flags)) {
6573 return _("Signed, has attachment(s)");
6574 } else if (MSG_IS_SIGNED(flags)) {
6575 return _("Signed");
6576 } else if (MSG_IS_WITH_ATTACHMENT(flags) && MSG_IS_ENCRYPTED(flags)) {
6577 return _("Encrypted, has attachment(s)");
6578 } else if (MSG_IS_ENCRYPTED(flags)) {
6579 return _("Encrypted");
6580 } else if (MSG_IS_WITH_ATTACHMENT(flags)) {
6581 return _("Has attachment(s)");
6582 } else {
6583 return NULL;
6585 default:
6586 return NULL;
6589 static gboolean tooltip_cb (GtkWidget *widget,
6590 gint x,
6591 gint y,
6592 gboolean keyboard_mode,
6593 GtkTooltip *tooltip,
6594 gpointer user_data)
6596 GtkCMCTree *ctree = GTK_CMCTREE(widget);
6597 SummaryView *summaryview = (SummaryView *)user_data;
6598 gint row = -1, column = -1;
6599 int offset = prefs_common.show_col_headers ? 24:0;
6600 GtkCMCTreeNode *node = NULL;
6601 gchar *text = NULL;
6602 gchar *formatted = NULL;
6603 MsgInfo *info = NULL;
6604 GdkRectangle rect;
6605 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
6606 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
6607 if (!prefs_common.show_tooltips)
6608 return FALSE;
6610 if (y - offset < 0)
6611 return FALSE;
6613 if (!gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree), x, y - offset,
6614 &row, &column))
6615 return FALSE;
6617 if ((node = gtk_cmctree_node_nth(ctree, row)) == NULL)
6618 return FALSE;
6620 if ((info = gtk_cmctree_node_get_row_data(ctree, node)) == NULL)
6621 return FALSE;
6623 switch (gtk_cmctree_node_get_cell_type(ctree, node, column)) {
6624 case GTK_CMCELL_TEXT:
6625 if (gtk_cmctree_node_get_text(ctree, node, column, &text) != TRUE)
6626 return FALSE;
6627 if (column == summaryview->col_pos[S_COL_FROM])
6628 text = info->from;
6629 else if (column == summaryview->col_pos[S_COL_TO])
6630 text = info->to;
6631 break;
6632 case GTK_CMCELL_PIXTEXT:
6633 if (gtk_cmctree_node_get_pixtext(ctree, node, column, &text,
6634 NULL, NULL) != TRUE)
6635 return FALSE;
6636 break;
6637 default:
6638 if ((text = summaryview_get_tooltip_text(summaryview, info, column)) == NULL)
6639 return FALSE;
6642 if (!text || !*text)
6643 return FALSE;
6645 formatted = g_strdup(text);
6646 g_strstrip(formatted);
6648 if ((vert_layout || small_layout) && prefs_common.two_line_vert)
6649 gtk_tooltip_set_markup (tooltip, formatted);
6650 else
6651 gtk_tooltip_set_text (tooltip, formatted);
6652 g_free(formatted);
6654 rect.x = x - 2;
6655 rect.y = y - 2;
6656 rect.width = 12;
6657 rect.height= 12;
6658 gtk_tooltip_set_tip_area(tooltip, &rect);
6660 return TRUE;
6662 #endif
6664 static gboolean summary_header_button_pressed(GtkWidget *widget,
6665 GdkEvent *_event,
6666 gpointer user_data)
6668 GdkEventButton *event = (GdkEventButton *)_event;
6669 SummaryView *summaryview = (SummaryView *)user_data;
6671 cm_return_val_if_fail(summaryview != NULL, FALSE);
6673 /* Only handle single button presses. */
6674 if (event->type == GDK_2BUTTON_PRESS ||
6675 event->type == GDK_3BUTTON_PRESS)
6676 return FALSE;
6678 /* Handle right-click for context menu */
6679 if (event->button == 3) {
6680 /* Set up any menu items that need setting up. */
6681 summaryview->header_menu_lock = TRUE;
6682 cm_toggle_menu_set_active_full(summaryview->mainwin->ui_manager,
6683 "Menus/SummaryViewHeaderPopup/LockColumnHeaders",
6684 prefs_common_get_prefs()->summary_col_lock);
6685 summaryview->header_menu_lock = FALSE;
6687 gtk_menu_popup_at_pointer(GTK_MENU(summaryview->headerpopupmenu), NULL);
6688 return TRUE;
6691 return FALSE;
6694 static GtkWidget *summary_ctree_create(SummaryView *summaryview)
6696 GtkWidget *ctree;
6697 gint *col_pos = summaryview->col_pos;
6698 SummaryColumnState *col_state;
6699 gchar *titles[N_SUMMARY_COLS];
6700 SummaryColumnType type;
6701 gint pos;
6702 gboolean vert_layout = (prefs_common.layout_mode == VERTICAL_LAYOUT);
6703 gboolean small_layout = (prefs_common.layout_mode == SMALL_LAYOUT);
6704 memset(titles, 0, sizeof(titles));
6706 col_state = prefs_summary_column_get_config();
6707 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
6708 summaryview->col_state[pos] = col_state[pos];
6709 type = col_state[pos].type;
6710 col_pos[type] = pos;
6711 titles[pos] = "dummy";
6713 col_state = summaryview->col_state;
6715 ctree = gtk_sctree_new_with_titles
6716 (N_SUMMARY_COLS, col_pos[S_COL_SUBJECT], titles);
6718 gtk_widget_set_name(GTK_WIDGET(ctree), "summaryview_sctree");
6720 if (prefs_common.show_col_headers == FALSE)
6721 gtk_cmclist_column_titles_hide(GTK_CMCLIST(ctree));
6723 gtk_cmclist_set_selection_mode(GTK_CMCLIST(ctree), GTK_SELECTION_MULTIPLE);
6724 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_MARK],
6725 GTK_JUSTIFY_CENTER);
6726 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_STATUS],
6727 GTK_JUSTIFY_CENTER);
6728 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_LOCKED],
6729 GTK_JUSTIFY_CENTER);
6730 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_MIME],
6731 GTK_JUSTIFY_CENTER);
6732 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_SIZE],
6733 GTK_JUSTIFY_RIGHT);
6734 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_NUMBER],
6735 GTK_JUSTIFY_RIGHT);
6736 gtk_cmclist_set_column_justification(GTK_CMCLIST(ctree), col_pos[S_COL_SCORE],
6737 GTK_JUSTIFY_RIGHT);
6738 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_MARK],
6739 prefs_common.summary_col_size[S_COL_MARK]);
6740 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_STATUS],
6741 prefs_common.summary_col_size[S_COL_STATUS]);
6742 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_LOCKED],
6743 prefs_common.summary_col_size[S_COL_LOCKED]);
6744 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_MIME],
6745 prefs_common.summary_col_size[S_COL_MIME]);
6746 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SUBJECT],
6747 prefs_common.summary_col_size[S_COL_SUBJECT]);
6748 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_FROM],
6749 prefs_common.summary_col_size[S_COL_FROM]);
6750 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_TO],
6751 prefs_common.summary_col_size[S_COL_TO]);
6752 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_DATE],
6753 prefs_common.summary_col_size[S_COL_DATE]);
6754 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SIZE],
6755 prefs_common.summary_col_size[S_COL_SIZE]);
6756 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_NUMBER],
6757 prefs_common.summary_col_size[S_COL_NUMBER]);
6758 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_SCORE],
6759 prefs_common.summary_col_size[S_COL_SCORE]);
6760 gtk_cmclist_set_column_width(GTK_CMCLIST(ctree), col_pos[S_COL_TAGS],
6761 prefs_common.summary_col_size[S_COL_TAGS]);
6763 gtk_cmctree_set_expander_style(GTK_CMCTREE(ctree),
6764 GTK_CMCTREE_EXPANDER_TRIANGLE);
6766 gtk_sctree_set_stripes(GTK_SCTREE(ctree), prefs_common.use_stripes_in_summaries);
6768 gtk_cmctree_set_indent(GTK_CMCTREE(ctree), 12);
6769 g_object_set_data(G_OBJECT(ctree), "summaryview", (gpointer)summaryview);
6771 for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
6772 gtk_widget_set_can_focus(GTK_CMCLIST(ctree)->column[pos].button,
6773 FALSE);
6774 if (((pos == summaryview->col_pos[S_COL_FROM] && !FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) ||
6775 (pos == summaryview->col_pos[S_COL_TO] && FOLDER_SHOWS_TO_HDR(summaryview->folder_item)) ||
6776 pos == summaryview->col_pos[S_COL_DATE]) && (vert_layout || small_layout) &&
6777 prefs_common.two_line_vert)
6778 gtk_cmclist_set_column_visibility
6779 (GTK_CMCLIST(ctree), pos, FALSE);
6780 else
6781 gtk_cmclist_set_column_visibility
6782 (GTK_CMCLIST(ctree), pos, col_state[pos].visible);
6784 if (prefs_common.two_line_vert)
6785 gtk_sctree_set_use_markup(GTK_SCTREE(ctree), summaryview->col_pos[S_COL_SUBJECT], vert_layout||small_layout);
6787 /* connect signal to the buttons for sorting */
6788 #define CLIST_BUTTON_SIGNAL_CONNECT(col, func) \
6789 g_signal_connect \
6790 (G_OBJECT(GTK_CMCLIST(ctree)->column[col_pos[col]].button), \
6791 "button-press-event", \
6792 G_CALLBACK(summary_header_button_pressed), \
6793 summaryview); \
6794 g_signal_connect \
6795 (G_OBJECT(GTK_CMCLIST(ctree)->column[col_pos[col]].button), \
6796 "clicked", \
6797 G_CALLBACK(func), \
6798 summaryview);
6800 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_MARK , summary_mark_clicked)
6801 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_STATUS , summary_status_clicked)
6802 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_MIME , summary_mime_clicked)
6803 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_NUMBER , summary_num_clicked)
6804 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SIZE , summary_size_clicked)
6805 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_DATE , summary_date_clicked)
6806 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_FROM , summary_from_clicked)
6807 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_TO , summary_to_clicked)
6808 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SUBJECT, summary_subject_clicked)
6809 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_SCORE , summary_score_clicked)
6810 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_LOCKED , summary_locked_clicked)
6811 CLIST_BUTTON_SIGNAL_CONNECT(S_COL_TAGS , summary_tags_clicked)
6813 #undef CLIST_BUTTON_SIGNAL_CONNECT
6815 g_signal_connect(G_OBJECT(ctree), "tree_select_row",
6816 G_CALLBACK(summary_selected), summaryview);
6817 g_signal_connect(G_OBJECT(ctree), "tree_unselect_row",
6818 G_CALLBACK(summary_unselected), summaryview);
6819 g_signal_connect(G_OBJECT(ctree), "button_press_event",
6820 G_CALLBACK(summary_button_pressed),
6821 summaryview);
6822 g_signal_connect(G_OBJECT(ctree), "popup-menu",
6823 G_CALLBACK(summary_popup_menu), summaryview);
6824 g_signal_connect(G_OBJECT(ctree), "button_release_event",
6825 G_CALLBACK(summary_button_released),
6826 summaryview);
6827 g_signal_connect(G_OBJECT(ctree), "key_press_event",
6828 G_CALLBACK(summary_key_pressed), summaryview);
6829 g_signal_connect(G_OBJECT(ctree), "resize_column",
6830 G_CALLBACK(summary_col_resized), summaryview);
6831 g_signal_connect(G_OBJECT(ctree), "open_row",
6832 G_CALLBACK(summary_open_row), summaryview);
6834 g_signal_connect_after(G_OBJECT(ctree), "tree_expand",
6835 G_CALLBACK(summary_tree_expanded),
6836 summaryview);
6837 g_signal_connect_after(G_OBJECT(ctree), "tree_collapse",
6838 G_CALLBACK(summary_tree_collapsed),
6839 summaryview);
6841 g_signal_connect(G_OBJECT(ctree), "start_drag",
6842 G_CALLBACK(summary_start_drag),
6843 summaryview);
6844 g_signal_connect(G_OBJECT(ctree), "drag_data_get",
6845 G_CALLBACK(summary_drag_data_get),
6846 summaryview);
6847 g_signal_connect(G_OBJECT(ctree), "drag_end",
6848 G_CALLBACK(summary_drag_end),
6849 summaryview);
6851 gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL & ~GTK_DEST_DEFAULT_HIGHLIGHT,
6852 summary_drag_types, 3,
6853 GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_DEFAULT);
6855 g_signal_connect(G_OBJECT(ctree), "drag_data_received",
6856 G_CALLBACK(summary_drag_data_received),
6857 summaryview);
6859 g_signal_connect(G_OBJECT(ctree), "drag_motion",
6860 G_CALLBACK(summary_drag_motion_cb),
6861 summaryview);
6863 #if !GENERIC_UMPC
6864 g_object_set (G_OBJECT(ctree), "has-tooltip", TRUE, NULL);
6865 g_signal_connect(G_OBJECT(ctree), "query-tooltip",
6866 G_CALLBACK(tooltip_cb),
6867 summaryview);
6868 #endif
6869 return ctree;
6872 void summary_set_column_order(SummaryView *summaryview)
6874 GtkWidget *ctree;
6875 GtkWidget *scrolledwin = summaryview->scrolledwin;
6876 FolderItem *item;
6877 guint selected_msgnum = summary_get_msgnum(summaryview, summaryview->selected);
6878 guint displayed_msgnum = summary_get_msgnum(summaryview, summaryview->displayed);
6880 item = summaryview->folder_item;
6882 summary_clear_all(summaryview);
6883 gtk_widget_destroy(summaryview->ctree);
6885 summaryview->ctree = ctree = summary_ctree_create(summaryview);
6886 summary_set_fonts(summaryview);
6887 summary_set_column_titles(summaryview);
6888 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
6889 GTK_CMCLIST(ctree)->hadjustment);
6890 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
6891 GTK_CMCLIST(ctree)->vadjustment);
6892 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
6893 gtk_widget_show(ctree);
6895 summary_show(summaryview, item, FALSE);
6897 summary_select_by_msgnum(summaryview, selected_msgnum, FALSE);
6899 summaryview->selected = summary_find_msg_by_msgnum(summaryview, selected_msgnum);
6900 summaryview->displayed = summary_find_msg_by_msgnum(summaryview, displayed_msgnum);
6901 if (!summaryview->displayed)
6902 messageview_clear(summaryview->messageview);
6903 else
6904 summary_redisplay_msg(summaryview);
6906 /* get normal row height */
6907 gtk_cmclist_set_row_height(GTK_CMCLIST(ctree), 0);
6908 normal_row_height = GTK_CMCLIST(ctree)->row_height;
6910 if ((prefs_common.layout_mode == SMALL_LAYOUT || prefs_common.layout_mode == VERTICAL_LAYOUT) &&
6911 prefs_common.two_line_vert) {
6912 gtk_cmclist_set_row_height(GTK_CMCLIST(summaryview->ctree), 2*normal_row_height + 2);
6917 /* callback functions */
6919 static gint summary_folder_eventbox_pressed(GtkWidget *eventbox, GdkEventButton *event,
6920 SummaryView *summaryview)
6922 if (event) {
6923 folderview_grab_focus(summaryview->folderview);
6924 mainwindow_exit_folder(summaryview->mainwin);
6926 return TRUE;
6929 static gint summary_toggle_pressed(GtkWidget *eventbox, GdkEventButton *event,
6930 SummaryView *summaryview)
6932 if (event)
6933 summary_toggle_view(summaryview);
6934 return TRUE;
6936 #ifdef GENERIC_UMPC
6937 static void summary_toggle_multiple_pressed(GtkWidget *widget,
6938 SummaryView *summaryview)
6940 GTK_SCTREE(summaryview->ctree)->force_additive_sel =
6941 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
6943 #endif
6944 static gboolean summary_button_pressed(GtkWidget *ctree, GdkEventButton *event,
6945 SummaryView *summaryview)
6947 if (!event) return FALSE;
6948 if (event->window != GTK_CMCLIST(ctree)->clist_window) return FALSE;
6950 if (event->button == 3) {
6951 /* right clicked */
6952 summary_set_menu_sensitive(summaryview);
6953 gtk_menu_popup_at_pointer(GTK_MENU(summaryview->popupmenu), NULL);
6954 } else if (event->button == 2) {
6955 summaryview->display_msg = messageview_is_visible(summaryview->messageview);
6956 } else if (event->button == 1) {
6957 if (!prefs_common.emulate_emacs &&
6958 messageview_is_visible(summaryview->messageview))
6959 summaryview->display_msg = TRUE;
6962 return FALSE;
6965 static gboolean summary_button_released(GtkWidget *ctree, GdkEventButton *event,
6966 SummaryView *summaryview)
6968 return FALSE;
6971 gboolean summary_pass_key_press_event(SummaryView *summaryview, GdkEventKey *event)
6973 if (!summaryview)
6974 return FALSE;
6975 if (summary_is_list(summaryview))
6976 return summary_key_pressed(summaryview->ctree, event, summaryview);
6977 else
6978 return FALSE;
6981 #define BREAK_ON_MODIFIER_KEY() \
6982 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
6984 /* Copied from gtkcmclist.c, if it changes there, it has to change
6985 * here as well. This is an ugly hack, there must be a better way to
6986 * find out how much to move for page up/down. */
6987 #define CELL_SPACING 1
6988 static gboolean summary_key_pressed(GtkWidget *widget, GdkEventKey *event,
6989 SummaryView *summaryview)
6991 GtkCMCTree *ctree = GTK_CMCTREE(widget);
6992 GtkCMCTreeNode *node;
6993 MessageView *messageview;
6994 GtkAdjustment *adj;
6995 gboolean mod_pressed;
6997 if (!event)
6998 return TRUE;
7000 if (quicksearch_has_focus(summaryview->quicksearch))
7001 return FALSE;
7003 messageview = summaryview->messageview;
7005 mod_pressed =
7006 ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
7008 if (summaryview->selected) {
7009 gboolean handled = FALSE;
7010 switch (event->keyval) {
7011 case GDK_KEY_space: /* Page down or go to the next */
7012 handled = TRUE;
7013 if (event->state & GDK_CONTROL_MASK) {
7014 handled = FALSE;
7015 break;
7017 if (event->state & GDK_SHIFT_MASK)
7018 mimeview_scroll_page(messageview->mimeview, TRUE);
7019 if (summaryview->displayed != summaryview->selected) {
7020 summary_display_msg(summaryview,
7021 summaryview->selected);
7022 } else {
7023 if (mod_pressed) {
7024 if (!mimeview_scroll_page(messageview->mimeview, TRUE))
7025 summary_select_prev_unread(summaryview);
7026 } else {
7027 if (!mimeview_scroll_page(messageview->mimeview, FALSE))
7028 summary_select_next_unread(summaryview);
7031 break;
7032 case GDK_KEY_BackSpace: /* Page up */
7033 handled = TRUE;
7034 mimeview_scroll_page(messageview->mimeview, TRUE);
7035 break;
7036 case GDK_KEY_Return: /* Scroll up/down one line */
7037 case GDK_KEY_KP_Enter:
7038 handled = TRUE;
7039 if (summaryview->displayed != summaryview->selected) {
7040 #ifndef GENERIC_UMPC
7041 summary_display_msg(summaryview,
7042 summaryview->selected);
7043 #else
7044 summary_open_row(NULL, summaryview);
7045 #endif
7046 break;
7048 mimeview_scroll_one_line(messageview->mimeview, mod_pressed);
7049 break;
7052 if (handled)
7053 return FALSE;
7055 if (summary_is_locked(summaryview))
7056 return TRUE;
7058 switch (event->keyval) {
7059 case GDK_KEY_Left: /* Move focus */
7060 adj = gtk_scrolled_window_get_hadjustment
7061 (GTK_SCROLLED_WINDOW(summaryview->scrolledwin));
7062 if (gtk_adjustment_get_lower(adj) != gtk_adjustment_get_value(adj))
7063 break;
7064 /* FALLTHROUGH */
7065 case GDK_KEY_Escape:
7066 folderview_grab_focus(summaryview->folderview);
7067 mainwindow_exit_folder(summaryview->mainwin);
7068 return TRUE;
7069 case GDK_KEY_Home: case GDK_KEY_KP_Home:
7070 case GDK_KEY_End: case GDK_KEY_KP_End:
7071 case GDK_KEY_Up: case GDK_KEY_KP_Up:
7072 case GDK_KEY_Down: case GDK_KEY_KP_Down:
7073 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
7074 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
7075 if ((node = summaryview->selected) != NULL) {
7076 GtkCMCTreeNode *next = NULL;
7077 switch (event->keyval) {
7078 case GDK_KEY_Home: case GDK_KEY_KP_Home:
7079 next = gtk_cmctree_node_nth(ctree, 0);
7080 break;
7081 case GDK_KEY_End: case GDK_KEY_KP_End:
7082 next = gtk_cmctree_node_nth(ctree,
7083 g_list_length(GTK_CMCLIST(ctree)->row_list)-1);
7084 break;
7085 case GDK_KEY_Up: case GDK_KEY_KP_Up:
7086 next = gtk_cmctree_node_nth(ctree,
7087 MAX(0, GTK_CMCLIST(ctree)->focus_row - 1));
7088 break;
7089 case GDK_KEY_Down: case GDK_KEY_KP_Down:
7090 next = gtk_cmctree_node_nth(ctree,
7091 MIN(GTK_CMCLIST(ctree)->focus_row + 1, GTK_CMCLIST(ctree)->rows - 1));
7092 break;
7093 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
7094 next = gtk_cmctree_node_nth(ctree,
7095 MAX(0, GTK_CMCLIST(ctree)->focus_row -
7096 (2 * GTK_CMCLIST(ctree)->clist_window_height -
7097 GTK_CMCLIST(ctree)->row_height - CELL_SPACING) /
7098 (2 * (GTK_CMCLIST(ctree)->row_height + CELL_SPACING))));
7099 break;
7100 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
7101 next = gtk_cmctree_node_nth(ctree,
7102 MIN(GTK_CMCLIST(ctree)->rows - 1, GTK_CMCLIST(ctree)->focus_row +
7103 (2 * GTK_CMCLIST(ctree)->clist_window_height -
7104 GTK_CMCLIST(ctree)->row_height - CELL_SPACING) /
7105 (2 * (GTK_CMCLIST(ctree)->row_height + CELL_SPACING))));
7106 break;
7109 if (next != NULL &&
7110 next != gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->focus_row)) {
7111 gtk_sctree_select_with_state
7112 (GTK_SCTREE(ctree), next, (event->state & ~GDK_CONTROL_MASK) );
7114 /* Deprecated - what are the non-deprecated equivalents? */
7115 if (gtk_cmctree_node_is_visible(GTK_CMCTREE(ctree), next) != GTK_VISIBILITY_FULL)
7116 gtkut_ctree_node_move_if_on_the_edge(GTK_CMCTREE(ctree), next, -1);
7117 if (!mod_pressed)
7118 summary_select_node(summaryview, summaryview->selected, OPEN_SELECTED_ON_DIRECTIONAL);
7119 summaryview->selected = next;
7122 return TRUE;
7123 default:
7124 break;
7127 if (!summaryview->selected) {
7128 node = gtk_cmctree_node_nth(ctree, 0);
7129 if (node)
7130 gtk_sctree_select(GTK_SCTREE(ctree), node);
7131 else
7132 return TRUE;
7135 switch (event->keyval) {
7136 case GDK_KEY_Delete:
7137 BREAK_ON_MODIFIER_KEY();
7138 summary_delete_trash(summaryview);
7139 break;
7140 default:
7141 break;
7143 return FALSE;
7145 #undef CELL_SPACING
7147 static void quicksearch_execute_cb(QuickSearch *quicksearch, gpointer data)
7149 SummaryView *summaryview = data;
7151 summaryview_reset_recursive_folder_match(summaryview);
7152 if (summary_show(summaryview, summaryview->folder_item, FALSE))
7153 summaryview_quicksearch_recurse(summaryview);
7154 else
7155 summaryview_reset_recursive_folder_match(summaryview);
7158 static void tog_searchbar_cb(GtkWidget *w, gpointer data)
7160 SummaryView *summaryview = (SummaryView *)data;
7162 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
7163 prefs_common.show_searchbar = TRUE;
7164 quicksearch_show(summaryview->quicksearch);
7165 } else {
7166 prefs_common.show_searchbar = FALSE;
7167 quicksearch_hide(summaryview->quicksearch);
7171 void summaryview_activate_quicksearch(SummaryView *summaryview, gboolean show)
7173 prefs_common.show_searchbar = show;
7174 gtk_toggle_button_set_active(
7175 GTK_TOGGLE_BUTTON(summaryview->toggle_search),
7176 show);
7177 if (show) {
7178 quicksearch_show(summaryview->quicksearch);
7179 } else {
7180 quicksearch_hide(summaryview->quicksearch);
7181 summary_grab_focus(summaryview);
7185 void summary_open_row(GtkSCTree *sctree, SummaryView *summaryview)
7187 if (FOLDER_SHOWS_TO_HDR(summaryview->folder_item))
7188 summary_reedit(summaryview);
7189 else
7190 summary_open_msg(summaryview);
7192 summaryview->display_msg = FALSE;
7195 static void summary_tree_expanded(GtkCMCTree *ctree, GtkCMCTreeNode *node,
7196 SummaryView *summaryview)
7198 summary_set_row_marks(summaryview, node);
7199 if (prefs_common.bold_unread) {
7200 while (node) {
7201 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
7202 if (GTK_CMCTREE_ROW(node)->children)
7203 summary_set_row_marks(summaryview, node);
7204 node = next;
7209 static void summary_tree_collapsed(GtkCMCTree *ctree, GtkCMCTreeNode *node,
7210 SummaryView *summaryview)
7212 gtk_sctree_select(GTK_SCTREE(ctree), node);
7213 summary_set_row_marks(summaryview, node);
7216 static void summary_unselected(GtkCMCTree *ctree, GtkCMCTreeNode *row,
7217 gint column, SummaryView *summaryview)
7219 if (summary_is_locked(summaryview)
7220 || GTK_SCTREE(ctree)->selecting_range) {
7221 return;
7224 summary_status_show(summaryview);
7227 static void summary_selected(GtkCMCTree *ctree, GtkCMCTreeNode *row,
7228 gint column, SummaryView *summaryview)
7230 const GList *list, *cur;
7231 MessageView *msgview;
7232 MsgInfo *msginfo;
7233 gboolean marked_unread = FALSE;
7235 if (summary_is_locked(summaryview)
7236 && !GTK_SCTREE(ctree)->selecting_range
7237 && summaryview->messageview
7238 && summaryview->messageview->mimeview
7239 && summaryview->messageview->mimeview->type == MIMEVIEW_TEXT
7240 && summaryview->messageview->mimeview->textview->loading) {
7241 PostponedSelectData *data = g_new0(PostponedSelectData, 1);
7242 summaryview->messageview->mimeview->textview->stop_loading = TRUE;
7244 data->ctree = ctree;
7245 data->row = row;
7246 data->node = NULL;
7247 data->column = column;
7248 data->summaryview = summaryview;
7249 debug_print("postponing open of message till end of load\n");
7250 g_timeout_add(100, summary_select_retry, data);
7251 return;
7253 if (summary_is_locked(summaryview)
7254 || GTK_SCTREE(ctree)->selecting_range) {
7255 return;
7258 summary_status_show(summaryview);
7260 if (GTK_CMCLIST(ctree)->selection &&
7261 GTK_CMCLIST(ctree)->selection->next) {
7262 summaryview->display_msg = FALSE;
7263 summary_set_menu_sensitive(summaryview);
7264 toolbar_main_set_sensitive(summaryview->mainwin);
7265 return;
7268 summaryview->selected = row;
7270 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7271 cm_return_if_fail(msginfo != NULL);
7273 main_create_mailing_list_menu (summaryview->mainwin, msginfo);
7274 toolbar_set_learn_button
7275 (summaryview->mainwin->toolbar,
7276 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
7278 switch (column < 0 ? column : summaryview->col_state[column].type) {
7279 case S_COL_MARK:
7280 if (!MSG_IS_DELETED(msginfo->flags) &&
7281 !MSG_IS_MOVE(msginfo->flags) &&
7282 !MSG_IS_COPY(msginfo->flags)) {
7283 if (MSG_IS_MARKED(msginfo->flags)) {
7284 summary_unmark_row(summaryview, row);
7285 summary_status_show(summaryview);
7286 } else {
7287 summary_mark_row(summaryview, row);
7288 summary_status_show(summaryview);
7291 break;
7292 case S_COL_STATUS:
7293 if (MSG_IS_UNREAD(msginfo->flags)) {
7294 summary_mark_row_as_read(summaryview, row);
7295 summary_status_show(summaryview);
7296 } else if (MSG_IS_SPAM(msginfo->flags)) {
7297 if (procmsg_spam_learner_learn(msginfo, NULL, FALSE) == 0)
7298 summary_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
7299 else
7300 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
7301 } else if (!MSG_IS_REPLIED(msginfo->flags) &&
7302 !MSG_IS_FORWARDED(msginfo->flags)) {
7303 marked_unread = TRUE;
7304 } else if (MSG_IS_REPLIED(msginfo->flags)) {
7305 summary_find_answers(summaryview, msginfo);
7306 return;
7308 break;
7309 case S_COL_LOCKED:
7310 if (MSG_IS_LOCKED(msginfo->flags)) {
7311 summary_unlock_row(summaryview, row);
7312 summary_status_show(summaryview);
7314 else {
7315 summary_lock_row(summaryview, row);
7316 summary_status_show(summaryview);
7318 break;
7319 default:
7320 break;
7323 list = messageview_get_msgview_list();
7324 for (cur = list; cur != NULL; cur = cur->next) {
7325 msgview = (MessageView *) cur->data;
7327 if (msgview->new_window && msgview->update_needed) {
7328 MsgInfo *new_msginfo = summary_get_selected_msg(summaryview);
7329 messageview_show(msgview, new_msginfo, msgview->all_headers);
7330 msgview->update_needed = FALSE;
7334 if (summaryview->display_msg) {
7335 summaryview->display_msg = FALSE;
7336 if (summaryview->displayed != row) {
7337 summary_display_msg(summaryview, row);
7338 if (marked_unread) {
7339 summary_mark_row_as_unread(summaryview, row);
7340 summary_status_show(summaryview);
7342 return;
7346 if (marked_unread) {
7347 summary_mark_row_as_unread(summaryview, row);
7348 summary_status_show(summaryview);
7351 summary_set_menu_sensitive(summaryview);
7352 toolbar_main_set_sensitive(summaryview->mainwin);
7355 static void summary_col_resized(GtkCMCList *clist, gint column, gint width,
7356 SummaryView *summaryview)
7358 SummaryColumnType type = summaryview->col_state[column].type;
7360 prefs_common.summary_col_size[type] = width;
7365 * \brief get List of msginfo selected in SummaryView
7367 * \param summaryview
7369 * \return GSList holding MsgInfo
7371 GSList *summary_get_selection(SummaryView *summaryview)
7373 GList *sel = NULL;
7374 GSList *msginfo_list = NULL;
7376 cm_return_val_if_fail(summaryview != NULL, NULL);
7378 sel = GTK_CMCLIST(summaryview->ctree)->selection;
7380 cm_return_val_if_fail(sel != NULL, NULL);
7382 for ( ; sel != NULL; sel = sel->next)
7383 msginfo_list =
7384 g_slist_prepend(msginfo_list,
7385 gtk_cmctree_node_get_row_data(GTK_CMCTREE(summaryview->ctree),
7386 GTK_CMCTREE_NODE(sel->data)));
7387 return g_slist_reverse(msginfo_list);
7391 * \brief get number of messages currently selected in SummaryView
7393 * \param summaryview
7395 * \return number of messages currently selected
7397 guint summary_get_selection_count(SummaryView *summaryview)
7399 cm_return_val_if_fail(summaryview != NULL, 0);
7400 return g_list_length(GTK_CMCLIST(summaryview->ctree)->selection);
7403 static void summary_sort_by_column_click(SummaryView *summaryview,
7404 FolderSortKey sort_key)
7406 if (prefs_common.summary_col_lock) {
7407 debug_print("summaryview columns locked, ignoring\n");
7408 return;
7411 GtkCMCTreeNode *node = NULL;
7412 START_TIMING("");
7413 if (summaryview->sort_key == sort_key)
7414 summary_sort(summaryview, sort_key,
7415 summaryview->sort_type == SORT_ASCENDING
7416 ? SORT_DESCENDING : SORT_ASCENDING);
7417 else
7418 summary_sort(summaryview, sort_key, summaryview->sort_type);
7420 node = GTK_CMCTREE_NODE(GTK_CMCLIST(summaryview->ctree)->row_list);
7422 summary_freeze(summaryview);
7423 if (prefs_common.bold_unread || prefs_common.bold_marked) {
7424 while (node) {
7425 GtkCMCTreeNode *next = GTK_CMCTREE_NODE_NEXT(node);
7426 if (GTK_CMCTREE_ROW(node)->children)
7427 summary_set_row_marks(summaryview, node);
7428 node = next;
7431 summary_thaw(summaryview);
7432 END_TIMING();
7435 static void summary_mark_clicked(GtkWidget *button, SummaryView *summaryview)
7437 summary_sort_by_column_click(summaryview, SORT_BY_MARK);
7440 static void summary_status_clicked(GtkWidget *button, SummaryView *summaryview)
7442 summary_sort_by_column_click(summaryview, SORT_BY_STATUS);
7445 static void summary_mime_clicked(GtkWidget *button, SummaryView *summaryview)
7447 summary_sort_by_column_click(summaryview, SORT_BY_MIME);
7450 static void summary_num_clicked(GtkWidget *button, SummaryView *summaryview)
7452 summary_sort_by_column_click(summaryview, SORT_BY_NUMBER);
7455 static void summary_size_clicked(GtkWidget *button, SummaryView *summaryview)
7457 summary_sort_by_column_click(summaryview, SORT_BY_SIZE);
7460 static void summary_date_clicked(GtkWidget *button, SummaryView *summaryview)
7462 if (summaryview->sort_key == SORT_BY_THREAD_DATE)
7463 summary_sort_by_column_click(summaryview, SORT_BY_THREAD_DATE);
7464 else
7465 summary_sort_by_column_click(summaryview, SORT_BY_DATE);
7468 static void summary_from_clicked(GtkWidget *button, SummaryView *summaryview)
7470 if (summaryview->col_state[summaryview->col_pos[S_COL_FROM]].visible)
7471 summary_sort_by_column_click(summaryview, SORT_BY_FROM);
7472 else
7473 summary_sort_by_column_click(summaryview, SORT_BY_TO);
7476 static void summary_to_clicked(GtkWidget *button, SummaryView *summaryview)
7478 if (summaryview->col_state[summaryview->col_pos[S_COL_TO]].visible)
7479 summary_sort_by_column_click(summaryview, SORT_BY_TO);
7480 else
7481 summary_sort_by_column_click(summaryview, SORT_BY_FROM);
7484 static void summary_subject_clicked(GtkWidget *button,
7485 SummaryView *summaryview)
7487 summary_sort_by_column_click(summaryview, SORT_BY_SUBJECT);
7490 static void summary_score_clicked(GtkWidget *button,
7491 SummaryView *summaryview)
7493 summary_sort_by_column_click(summaryview, SORT_BY_SCORE);
7496 static void summary_locked_clicked(GtkWidget *button,
7497 SummaryView *summaryview)
7499 summary_sort_by_column_click(summaryview, SORT_BY_LOCKED);
7502 static void summary_tags_clicked(GtkWidget *button,
7503 SummaryView *summaryview)
7505 summary_sort_by_column_click(summaryview, SORT_BY_TAGS);
7508 static void summary_start_drag(GtkWidget *widget, gint button, GdkEvent *event,
7509 SummaryView *summaryview)
7511 GdkDragContext *context;
7513 cm_return_if_fail(summaryview != NULL);
7514 cm_return_if_fail(summaryview->folder_item != NULL);
7515 cm_return_if_fail(summaryview->folder_item->folder != NULL);
7517 if (summaryview->selected == NULL) return;
7519 context = gtk_drag_begin_with_coordinates(widget, summaryview->target_list,
7520 GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event,
7521 -1, -1);
7522 gtk_drag_set_icon_default(context);
7523 if (prefs_common.layout_mode == SMALL_LAYOUT) {
7524 GtkWidget *paned = gtk_widget_get_parent(GTK_WIDGET_PTR(summaryview));
7525 if (paned && GTK_IS_PANED(paned)) {
7526 mainwindow_reset_paned(GTK_PANED(paned));
7531 static gboolean summary_return_to_list(void *data)
7533 SummaryView *summaryview = (SummaryView *)data;
7534 mainwindow_enter_folder(summaryview->mainwin);
7535 return FALSE;
7538 static void summary_drag_end (GtkWidget *widget,
7539 GdkDragContext *drag_context,
7540 SummaryView *summaryview)
7542 if (prefs_common.layout_mode == SMALL_LAYOUT) {
7543 g_timeout_add(250, summary_return_to_list, summaryview);
7547 static void summary_drag_data_get(GtkWidget *widget,
7548 GdkDragContext *drag_context,
7549 GtkSelectionData *selection_data,
7550 guint info,
7551 guint time,
7552 SummaryView *summaryview)
7554 if (info == TARGET_MAIL_URI_LIST) {
7555 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7556 GList *cur;
7557 MsgInfo *msginfo;
7558 gchar *mail_list = NULL, *tmp1, *tmp2;
7560 for (cur = GTK_CMCLIST(ctree)->selection;
7561 cur != NULL && cur->data != NULL; cur = cur->next) {
7562 msginfo = gtk_cmctree_node_get_row_data
7563 (ctree, GTK_CMCTREE_NODE(cur->data));
7564 tmp2 = procmsg_get_message_file(msginfo);
7565 if (!tmp2) continue;
7566 if (msginfo->subject) {
7567 gchar *san_subject = g_strdup(msginfo->subject);
7568 gchar *dest = NULL;
7569 subst_for_filename(san_subject);
7570 dest = g_strdup_printf("%s%s%s.%d.txt",
7571 get_tmp_dir(),
7572 G_DIR_SEPARATOR_S,
7573 san_subject, msginfo->msgnum);
7574 g_free(san_subject);
7575 san_subject = g_filename_from_utf8(dest, -1, NULL, NULL, NULL);
7576 if (!san_subject) {
7577 g_warning("failed to convert encoding of file name: %s", dest);
7578 } else {
7579 g_free(dest);
7580 dest = san_subject;
7582 if (copy_file(tmp2, dest, TRUE) < 0) {
7583 g_warning("summary_drag_data_get: can't copy %s to %s",
7584 tmp2, dest);
7586 g_free(tmp2);
7587 tmp2 = dest;
7589 tmp1 = g_filename_to_uri(tmp2, NULL, NULL);
7590 g_free(tmp2);
7591 tmp2 = g_strconcat(tmp1, "\r\n", NULL);
7592 g_free(tmp1);
7593 tmp1 = tmp2;
7595 if (!mail_list) {
7596 mail_list = tmp1;
7597 } else {
7598 tmp2 = g_strconcat(mail_list, tmp1, NULL);
7599 g_free(mail_list);
7600 g_free(tmp1);
7601 mail_list = tmp2;
7605 if (mail_list != NULL) {
7606 gtk_selection_data_set(selection_data,
7607 gtk_selection_data_get_target(selection_data), 8,
7608 mail_list, strlen(mail_list));
7609 g_free(mail_list);
7611 } else if (info == TARGET_DUMMY) {
7612 if (GTK_CMCLIST(summaryview->ctree)->selection)
7613 gtk_selection_data_set(selection_data,
7614 gtk_selection_data_get_target(selection_data), 8,
7615 "Dummy-Summaryview",
7616 strlen("Dummy-Summaryview")+1);
7617 } else if (info == TARGET_MAIL_CM_PATH_LIST) {
7618 /* content: folder_item_identifier\nmsgid1\nmsgid2\nmsgid3 */
7620 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7621 GList *cur;
7622 MsgInfo *msginfo;
7623 gchar *path_list = NULL;
7625 /* identifier */
7626 if(GTK_CMCLIST(ctree)->selection != NULL) {
7627 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->selection->data));
7628 if(msginfo && msginfo->folder)
7629 path_list = folder_item_get_identifier(msginfo->folder);
7632 if (path_list != NULL) {
7633 for (cur = GTK_CMCLIST(ctree)->selection;
7634 cur != NULL && cur->data != NULL && path_list != NULL; cur = cur->next) {
7635 gchar *tmp;
7637 msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(cur->data));
7638 if(!msginfo)
7639 continue;
7640 tmp = path_list;
7641 path_list = g_strconcat(path_list, "\n", (msginfo->msgid ? msginfo->msgid : "unknown"), NULL);
7642 g_free(tmp);
7645 if (path_list != NULL) {
7646 gtk_selection_data_set(selection_data,
7647 gtk_selection_data_get_target(selection_data), 8,
7648 path_list, strlen(path_list));
7649 g_free(path_list);
7651 } else {
7652 g_warning("summary_drag_data_get: no folder item identifier");
7657 static gboolean summary_drag_motion_cb(GtkWidget *widget,
7658 GdkDragContext *context,
7659 gint x,
7660 gint y,
7661 guint time,
7662 SummaryView *summaryview)
7664 FolderItem *item = summaryview->folder_item;
7665 if (!(item && item->folder && folder_item_parent(item) != NULL
7666 && FOLDER_CLASS(item->folder)->add_msg != NULL)) {
7667 gdk_drag_status(context, 0, time);
7668 return FALSE;
7669 } else if (gtk_drag_get_source_widget(context) ==
7670 mainwindow_get_mainwindow()->folderview->ctree) {
7671 /* no folders */
7672 gdk_drag_status(context, 0, time);
7673 return FALSE;
7674 } else if (gtk_drag_get_source_widget(context) ==
7675 summaryview->ctree) {
7676 /* not from same folder */
7677 gdk_drag_status(context, 0, time);
7678 return FALSE;
7679 } else {
7680 gdk_drag_status(context, GDK_ACTION_COPY, time);
7681 return TRUE;
7685 static void summary_drag_data_received(GtkWidget *widget,
7686 GdkDragContext *drag_context,
7687 gint x,
7688 gint y,
7689 GtkSelectionData *data,
7690 guint info,
7691 guint time,
7692 SummaryView *summaryview)
7694 if (info == TARGET_MAIL_URI_LIST) {
7695 FolderItem *item = summaryview->folder_item;
7696 if (!item) {
7697 gtk_drag_finish(drag_context, FALSE, FALSE, time);
7698 return;
7699 } else {
7700 folderview_finish_dnd(gtk_selection_data_get_data(data),
7701 drag_context, time, item);
7707 /* custom compare functions for sorting */
7709 static gint summary_cmp_by_date(GtkCMCList *clist,
7710 gconstpointer ptr1, gconstpointer ptr2)
7712 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7713 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7714 gint res;
7715 if (!msginfo1 || !msginfo2)
7716 return -1;
7718 res = (msginfo1->date_t - msginfo2->date_t);
7719 if (res == 0)
7720 res = msginfo1->msgnum - msginfo2->msgnum;
7721 return res;
7724 #define CMP_FUNC_DEF(func_name, val) \
7725 static gint func_name(GtkCMCList *clist, \
7726 gconstpointer ptr1, gconstpointer ptr2) \
7728 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data; \
7729 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data; \
7730 gint res; \
7731 if (!msginfo1 || !msginfo2) \
7732 return -1; \
7734 res = (val); \
7735 return (res != 0) ? res:summary_cmp_by_date(clist, ptr1, ptr2); \
7738 CMP_FUNC_DEF(summary_cmp_by_mark,
7739 MSG_IS_MARKED(msginfo1->flags) - MSG_IS_MARKED(msginfo2->flags))
7740 CMP_FUNC_DEF(summary_cmp_by_status,
7741 (-(MSG_IS_SPAM(msginfo1->flags))+(MSG_IS_UNREAD(msginfo1->flags)<<1)+(MSG_IS_NEW(msginfo1->flags)<<2))
7742 - (-(MSG_IS_SPAM(msginfo2->flags))+(MSG_IS_UNREAD(msginfo2->flags)<<1)+(MSG_IS_NEW(msginfo2->flags)<<2)) )
7743 CMP_FUNC_DEF(summary_cmp_by_mime,
7744 MSG_IS_WITH_ATTACHMENT(msginfo1->flags) - MSG_IS_WITH_ATTACHMENT(msginfo2->flags))
7745 CMP_FUNC_DEF(summary_cmp_by_label,
7746 MSG_GET_COLORLABEL(msginfo1->flags) -
7747 MSG_GET_COLORLABEL(msginfo2->flags))
7748 CMP_FUNC_DEF(summary_cmp_by_locked,
7749 MSG_IS_LOCKED(msginfo1->flags) - MSG_IS_LOCKED(msginfo2->flags))
7751 CMP_FUNC_DEF(summary_cmp_by_num, msginfo1->msgnum - msginfo2->msgnum)
7752 CMP_FUNC_DEF(summary_cmp_by_size, msginfo1->size - msginfo2->size)
7754 #undef CMP_FUNC_DEF
7756 static gint summary_cmp_by_subject(GtkCMCList *clist,
7757 gconstpointer ptr1,
7758 gconstpointer ptr2)
7760 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7761 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7762 gint res;
7764 if (!msginfo1->subject)
7765 return (msginfo2->subject != NULL);
7766 if (!msginfo2->subject)
7767 return -1;
7769 res = subject_compare_for_sort
7770 (msginfo1->subject, msginfo2->subject);
7771 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7774 static gint summary_cmp_by_thread_date(GtkCMCList *clist,
7775 gconstpointer ptr1,
7776 gconstpointer ptr2)
7778 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7779 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7780 gint thread_diff = msginfo1->thread_date - msginfo2->thread_date;
7782 if (msginfo1->thread_date > 0 && msginfo2->thread_date > 0)
7783 return thread_diff;
7784 else
7785 return msginfo1->date_t - msginfo2->date_t;
7788 static gint summary_cmp_by_from(GtkCMCList *clist, gconstpointer ptr1,
7789 gconstpointer ptr2)
7791 const gchar *str1, *str2;
7792 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7793 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7794 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7795 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7796 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7797 gint res;
7799 cm_return_val_if_fail(sv, -1);
7800 if (sv->col_state[sv->col_pos[S_COL_FROM]].visible) {
7801 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_FROM]])->text;
7802 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_FROM]])->text;
7803 } else {
7804 str1 = msginfo1->from;
7805 str2 = msginfo2->from;
7808 if (!str1)
7809 return str2 != NULL;
7811 if (!str2)
7812 return -1;
7814 res = g_utf8_collate(str1, str2);
7815 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7818 static gint summary_cmp_by_to(GtkCMCList *clist, gconstpointer ptr1,
7819 gconstpointer ptr2)
7821 const gchar *str1, *str2;
7822 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7823 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7824 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7825 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7826 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7827 gint res;
7828 cm_return_val_if_fail(sv, -1);
7830 if (sv->col_state[sv->col_pos[S_COL_TO]].visible) {
7831 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_TO]])->text;
7832 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_TO]])->text;
7833 } else {
7834 str1 = msginfo1->to;
7835 str2 = msginfo2->to;
7838 if (!str1)
7839 return str2 != NULL;
7841 if (!str2)
7842 return -1;
7844 res = g_utf8_collate(str1, str2);
7845 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7848 static gint summary_cmp_by_tags(GtkCMCList *clist, gconstpointer ptr1,
7849 gconstpointer ptr2)
7851 gchar *str1, *str2;
7852 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7853 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7854 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7855 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7856 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7857 gint res;
7858 cm_return_val_if_fail(sv, -1);
7860 if (sv->col_state[sv->col_pos[S_COL_TAGS]].visible) {
7861 str1 = g_strdup(GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_TAGS]])->text);
7862 str2 = g_strdup(GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_TAGS]])->text);
7863 } else {
7864 str1 = procmsg_msginfo_get_tags_str(msginfo1);
7865 str2 = procmsg_msginfo_get_tags_str(msginfo2);
7868 if (!str1) {
7869 res = (str2 != NULL);
7870 g_free(str2);
7871 return res;
7873 if (!str2) {
7874 g_free(str1);
7875 return -1;
7878 res = g_utf8_collate(str1, str2);
7879 g_free(str1);
7880 g_free(str2);
7881 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7884 static gint summary_cmp_by_simplified_subject
7885 (GtkCMCList *clist, gconstpointer ptr1, gconstpointer ptr2)
7887 const FolderItemPrefs *prefs;
7888 const gchar *str1, *str2;
7889 const GtkCMCListRow *r1 = (const GtkCMCListRow *) ptr1;
7890 const GtkCMCListRow *r2 = (const GtkCMCListRow *) ptr2;
7891 const MsgInfo *msginfo1 = r1->data;
7892 const MsgInfo *msginfo2 = r2->data;
7893 const SummaryView *sv = g_object_get_data(G_OBJECT(clist), "summaryview");
7894 gint res;
7896 cm_return_val_if_fail(sv, -1);
7897 cm_return_val_if_fail(msginfo1 != NULL && msginfo2 != NULL, -1);
7899 if (sv->col_state[sv->col_pos[S_COL_SUBJECT]].visible) {
7900 str1 = GTK_CMCELL_TEXT(r1->cell[sv->col_pos[S_COL_SUBJECT]])->text;
7901 str2 = GTK_CMCELL_TEXT(r2->cell[sv->col_pos[S_COL_SUBJECT]])->text;
7902 } else {
7903 str1 = msginfo1->subject;
7904 str2 = msginfo2->subject;
7907 if (!str1)
7908 return str2 != NULL;
7910 if (!str2)
7911 return -1;
7913 prefs = msginfo1->folder->prefs;
7914 if (!prefs)
7915 prefs = msginfo2->folder->prefs;
7916 if (!prefs)
7917 return -1;
7919 res = subject_compare_for_sort(str1, str2);
7920 return (res != 0)? res: summary_cmp_by_date(clist, ptr1, ptr2);
7923 static gint summary_cmp_by_score(GtkCMCList *clist,
7924 gconstpointer ptr1, gconstpointer ptr2)
7926 MsgInfo *msginfo1 = ((GtkCMCListRow *)ptr1)->data;
7927 MsgInfo *msginfo2 = ((GtkCMCListRow *)ptr2)->data;
7928 int diff;
7930 /* if score are equal, sort by date */
7932 diff = msginfo1->score - msginfo2->score;
7933 if (diff != 0)
7934 return diff;
7935 else
7936 return summary_cmp_by_date(clist, ptr1, ptr2);
7939 static void summary_ignore_thread_func_mark_unread(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7941 MsgInfo *msginfo;
7943 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7944 cm_return_if_fail(msginfo);
7946 summary_msginfo_unset_flags(msginfo, MSG_WATCH_THREAD, 0);
7947 summary_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0, MSG_NEW | MSG_UNREAD, 0);
7949 debug_print("Message %d is marked as ignore thread\n", msginfo->msgnum);
7952 static void summary_ignore_thread_func_set_row(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7954 SummaryView *summaryview = (SummaryView *) data;
7955 MsgInfo *msginfo;
7957 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7958 cm_return_if_fail(msginfo);
7960 summary_set_row_marks(summaryview, row);
7961 debug_print("Message %d update in row view\n", msginfo->msgnum);
7964 void summary_ignore_thread(SummaryView *summaryview)
7966 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
7967 GList *cur;
7968 gboolean froze = FALSE;
7970 START_LONG_OPERATION(summaryview, FALSE);
7971 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7972 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7973 GTK_CMCTREE_FUNC(summary_ignore_thread_func_mark_unread),
7974 summaryview);
7976 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
7977 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
7978 GTK_CMCTREE_FUNC(summary_ignore_thread_func_set_row),
7979 summaryview);
7981 END_LONG_OPERATION(summaryview);
7983 summary_status_show(summaryview);
7986 static void summary_unignore_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
7988 SummaryView *summaryview = (SummaryView *) data;
7989 MsgInfo *msginfo;
7991 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
7992 cm_return_if_fail(msginfo);
7994 summary_msginfo_unset_flags(msginfo, MSG_IGNORE_THREAD, 0);
7996 summary_set_row_marks(summaryview, row);
7997 debug_print("Message %d is marked as unignore thread\n",
7998 msginfo->msgnum);
8001 void summary_unignore_thread(SummaryView *summaryview)
8003 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
8004 GList *cur;
8005 gboolean froze = FALSE;
8007 START_LONG_OPERATION(summaryview, FALSE);
8008 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
8009 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
8010 GTK_CMCTREE_FUNC(summary_unignore_thread_func),
8011 summaryview);
8013 END_LONG_OPERATION(summaryview);
8015 summary_status_show(summaryview);
8018 static void summary_check_ignore_thread_func
8019 (GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
8021 MsgInfo *msginfo;
8022 gint *found_ignore = (gint *) data;
8024 if (*found_ignore) return;
8025 else {
8026 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
8027 *found_ignore = msginfo && MSG_IS_IGNORE_THREAD(msginfo->flags);
8031 void summary_toggle_ignore_thread(SummaryView *summaryview)
8033 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
8034 GList *cur;
8035 gint found_ignore = 0;
8037 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
8038 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
8039 GTK_CMCTREE_FUNC(summary_check_ignore_thread_func),
8040 &found_ignore);
8042 if (found_ignore)
8043 summary_unignore_thread(summaryview);
8044 else
8045 summary_ignore_thread(summaryview);
8048 static void summary_watch_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
8050 SummaryView *summaryview = (SummaryView *) data;
8051 MsgInfo *msginfo;
8053 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
8054 cm_return_if_fail(msginfo);
8056 summary_msginfo_change_flags(msginfo, MSG_WATCH_THREAD, 0, MSG_IGNORE_THREAD, 0);
8058 summary_set_row_marks(summaryview, row);
8059 debug_print("Message %d is marked as watch thread\n",
8060 msginfo->msgnum);
8063 void summary_watch_thread(SummaryView *summaryview)
8065 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
8066 GList *cur;
8067 gboolean froze = FALSE;
8069 START_LONG_OPERATION(summaryview, FALSE);
8070 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
8071 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
8072 GTK_CMCTREE_FUNC(summary_watch_thread_func),
8073 summaryview);
8075 END_LONG_OPERATION(summaryview);
8077 summary_status_show(summaryview);
8080 static void summary_unwatch_thread_func(GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
8082 SummaryView *summaryview = (SummaryView *) data;
8083 MsgInfo *msginfo;
8085 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
8086 cm_return_if_fail(msginfo);
8088 summary_msginfo_unset_flags(msginfo, MSG_WATCH_THREAD, 0);
8090 summary_set_row_marks(summaryview, row);
8091 debug_print("Message %d is marked as unwatch thread\n",
8092 msginfo->msgnum);
8095 void summary_unwatch_thread(SummaryView *summaryview)
8097 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
8098 GList *cur;
8099 gboolean froze = FALSE;
8101 START_LONG_OPERATION(summaryview, FALSE);
8102 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
8103 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
8104 GTK_CMCTREE_FUNC(summary_unwatch_thread_func),
8105 summaryview);
8107 END_LONG_OPERATION(summaryview);
8109 summary_status_show(summaryview);
8112 static void summary_check_watch_thread_func
8113 (GtkCMCTree *ctree, GtkCMCTreeNode *row, gpointer data)
8115 MsgInfo *msginfo;
8116 gint *found_watch = (gint *) data;
8118 if (*found_watch) return;
8119 else {
8120 msginfo = gtk_cmctree_node_get_row_data(ctree, row);
8121 *found_watch = msginfo && MSG_IS_WATCH_THREAD(msginfo->flags);
8125 void summary_toggle_watch_thread(SummaryView *summaryview)
8127 GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
8128 GList *cur;
8129 gint found_watch = 0;
8131 for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
8132 gtk_cmctree_pre_recursive(ctree, GTK_CMCTREE_NODE(cur->data),
8133 GTK_CMCTREE_FUNC(summary_check_watch_thread_func),
8134 &found_watch);
8136 if (found_watch)
8137 summary_unwatch_thread(summaryview);
8138 else
8139 summary_watch_thread(summaryview);
8143 void summary_toggle_show_read_messages(SummaryView *summaryview)
8145 FolderItemUpdateData source;
8146 if (summaryview->folder_item->hide_read_msgs)
8147 summaryview->folder_item->hide_read_msgs = 0;
8148 else
8149 summaryview->folder_item->hide_read_msgs = 1;
8151 source.item = summaryview->folder_item;
8152 source.update_flags = F_ITEM_UPDATE_NAME;
8153 source.msg = NULL;
8154 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
8155 summary_show(summaryview, summaryview->folder_item, FALSE);
8158 void summary_toggle_show_del_messages(SummaryView *summaryview)
8160 FolderItemUpdateData source;
8161 if (summaryview->folder_item->hide_del_msgs)
8162 summaryview->folder_item->hide_del_msgs = 0;
8163 else
8164 summaryview->folder_item->hide_del_msgs = 1;
8166 source.item = summaryview->folder_item;
8167 source.update_flags = F_ITEM_UPDATE_NAME;
8168 source.msg = NULL;
8169 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
8170 summary_show(summaryview, summaryview->folder_item, FALSE);
8173 void summary_toggle_show_read_threads(SummaryView *summaryview)
8175 FolderItemUpdateData source;
8176 if (summaryview->folder_item->hide_read_threads)
8177 summaryview->folder_item->hide_read_threads = 0;
8178 else
8179 summaryview->folder_item->hide_read_threads = 1;
8181 source.item = summaryview->folder_item;
8182 source.update_flags = F_ITEM_UPDATE_NAME;
8183 source.msg = NULL;
8184 hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
8185 summary_show(summaryview, summaryview->folder_item, FALSE);
8188 static void summary_set_hide_menu (SummaryView *summaryview,
8189 const gchar *menu_item,
8190 guint action)
8192 GtkWidget *widget;
8194 widget = gtk_ui_manager_get_widget(summaryview->mainwin->ui_manager, menu_item);
8195 cm_return_if_fail(widget != NULL);
8197 g_object_set_data(G_OBJECT(widget), "dont_toggle",
8198 GINT_TO_POINTER(1));
8199 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), action);
8200 g_object_set_data(G_OBJECT(widget), "dont_toggle",
8201 GINT_TO_POINTER(0));
8204 void summary_reflect_prefs_pixmap_theme(SummaryView *summaryview)
8206 GtkWidget *pixmap;
8208 stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm);
8209 stock_pixbuf_gdk(STOCK_PIXMAP_DELETED, &deletedxpm);
8210 stock_pixbuf_gdk(STOCK_PIXMAP_NEW, &newxpm);
8211 stock_pixbuf_gdk(STOCK_PIXMAP_UNREAD, &unreadxpm);
8212 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED, &repliedxpm);
8213 stock_pixbuf_gdk(STOCK_PIXMAP_FORWARDED, &forwardedxpm);
8214 stock_pixbuf_gdk(STOCK_PIXMAP_REPLIED_AND_FORWARDED, &repliedandforwardedxpm);
8215 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP, &clipxpm);
8216 stock_pixbuf_gdk(STOCK_PIXMAP_LOCKED, &lockedxpm);
8217 stock_pixbuf_gdk(STOCK_PIXMAP_IGNORETHREAD, &ignorethreadxpm);
8218 stock_pixbuf_gdk(STOCK_PIXMAP_WATCHTHREAD, &watchthreadxpm);
8219 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_KEY, &clipkeyxpm);
8220 stock_pixbuf_gdk(STOCK_PIXMAP_KEY, &keyxpm);
8221 stock_pixbuf_gdk(STOCK_PIXMAP_KEY_SIGN, &keysignxpm);
8222 stock_pixbuf_gdk(STOCK_PIXMAP_GPG_SIGNED, &gpgsignedxpm);
8223 stock_pixbuf_gdk(STOCK_PIXMAP_CLIP_GPG_SIGNED, &clipgpgsignedxpm);
8224 stock_pixbuf_gdk(STOCK_PIXMAP_SPAM, &spamxpm);
8225 stock_pixbuf_gdk(STOCK_PIXMAP_MOVED, &movedxpm);
8226 stock_pixbuf_gdk(STOCK_PIXMAP_COPIED, &copiedxpm);
8228 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
8230 pixmap = stock_pixmap_widget(STOCK_PIXMAP_QUICKSEARCH);
8231 gtk_container_remove (GTK_CONTAINER(summaryview->toggle_search),
8232 summaryview->quick_search_pixmap);
8233 gtk_container_add(GTK_CONTAINER(summaryview->toggle_search), pixmap);
8234 gtk_widget_show(pixmap);
8235 summaryview->quick_search_pixmap = pixmap;
8237 #ifdef GENERIC_UMPC
8238 pixmap = stock_pixmap_widget(STOCK_PIXMAP_SELECTION);
8239 gtk_container_remove (GTK_CONTAINER(summaryview->multiple_sel_togbtn),
8240 summaryview->multiple_sel_image);
8241 gtk_container_add(GTK_CONTAINER(summaryview->multiple_sel_togbtn), pixmap);
8242 gtk_widget_show(pixmap);
8243 summaryview->multiple_sel_togbtn = pixmap;
8244 #endif
8246 folderview_unselect(summaryview->folderview);
8247 folderview_select(summaryview->folderview, summaryview->folder_item);
8248 summary_set_column_titles(summaryview);
8251 void summary_reflect_prefs_custom_colors(SummaryView *summaryview)
8253 GtkMenuShell *menu;
8254 GList *children, *cur;
8256 /* re-create colorlabel submenu */
8257 menu = GTK_MENU_SHELL(summaryview->colorlabel_menu);
8258 cm_return_if_fail(menu != NULL);
8260 /* clear items. get item pointers. */
8261 children = gtk_container_get_children(GTK_CONTAINER(menu));
8262 for (cur = children; cur != NULL && cur->data != NULL; cur = cur->next) {
8263 g_signal_handlers_disconnect_matched
8264 (gtk_ui_manager_get_accel_group(summaryview->mainwin->ui_manager),
8265 G_SIGNAL_MATCH_DATA|G_SIGNAL_MATCH_FUNC,
8266 0, 0, NULL, mainwin_accel_changed_cb, cur->data);
8267 gtk_menu_item_set_submenu(GTK_MENU_ITEM(cur->data), NULL);
8269 g_list_free(children);
8270 summary_colorlabel_menu_create(summaryview, TRUE);
8274 * Harvest addresses for selected messages in summary view.
8276 void summary_harvest_address(SummaryView *summaryview)
8278 GtkCMCTree *ctree = GTK_CMCTREE( summaryview->ctree );
8279 GList *cur;
8280 GList *msgList;
8281 MsgInfo *msginfo;
8283 msgList = NULL;
8284 for( cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next ) {
8285 msginfo = gtk_cmctree_node_get_row_data( ctree, GTK_CMCTREE_NODE(cur->data) );
8286 if (!msginfo)
8287 continue;
8288 msgList = g_list_append( msgList, GUINT_TO_POINTER( msginfo->msgnum ) );
8291 addressbook_harvest( summaryview->folder_item, TRUE, msgList );
8293 g_list_free( msgList );
8296 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
8298 int err;
8299 gchar buf[BUFFSIZE];
8300 regex_t *preg = NULL;
8302 preg = g_new0(regex_t, 1);
8304 err = regcomp(preg, simplify_subject_regexp, REG_EXTENDED);
8305 if (err) {
8306 regerror(err, preg, buf, BUFFSIZE);
8307 alertpanel_error(_("Regular expression (regexp) error:\n%s"), buf);
8308 g_free(preg);
8309 preg = NULL;
8312 return preg;
8314 void summary_set_prefs_from_folderitem(SummaryView *summaryview, FolderItem *item)
8316 FolderSortKey sort_key;
8317 FolderSortType sort_type;
8318 cm_return_if_fail(summaryview != NULL);
8319 cm_return_if_fail(item != NULL);
8321 /* Subject simplification */
8322 if(summaryview->simplify_subject_preg) {
8323 regfree(summaryview->simplify_subject_preg);
8324 g_free(summaryview->simplify_subject_preg);
8325 summaryview->simplify_subject_preg = NULL;
8327 if(item->prefs && item->prefs->simplify_subject_regexp &&
8328 item->prefs->simplify_subject_regexp[0] && item->prefs->enable_simplify_subject)
8329 summaryview->simplify_subject_preg = summary_compile_simplify_regexp(item->prefs->simplify_subject_regexp);
8331 /* Sorting */
8332 sort_key = item->sort_key;
8333 sort_type = item->sort_type;
8335 folder_get_sort_type(item->folder, &sort_key, &sort_type);
8337 summaryview->sort_key = sort_key;
8338 summaryview->sort_type = sort_type;
8340 /* Threading */
8341 summaryview->threaded = item->threaded;
8342 summaryview->thread_collapsed = item->thread_collapsed;
8344 /* Scoring */
8347 void summary_save_prefs_to_folderitem(SummaryView *summaryview, FolderItem *item)
8349 /* Sorting */
8350 item->sort_key = summaryview->sort_key;
8351 item->sort_type = summaryview->sort_type;
8353 /* Threading */
8354 item->threaded = summaryview->threaded;
8355 item->thread_collapsed = summaryview->thread_collapsed;
8358 static gboolean summary_update_msg(gpointer source, gpointer data)
8360 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
8361 SummaryView *summaryview = (SummaryView *)data;
8362 GtkCMCTreeNode *node;
8364 cm_return_val_if_fail(msginfo_update != NULL, TRUE);
8365 cm_return_val_if_fail(summaryview != NULL, FALSE);
8367 if (msginfo_update->msginfo->folder != summaryview->folder_item)
8368 return FALSE;
8370 if (msginfo_update->flags & MSGINFO_UPDATE_FLAGS) {
8371 node = gtk_cmctree_find_by_row_data(
8372 GTK_CMCTREE(summaryview->ctree), NULL,
8373 msginfo_update->msginfo);
8375 if (node)
8376 summary_set_row_marks(summaryview, node);
8379 return FALSE;
8382 void summary_update_unread(SummaryView *summaryview, FolderItem *removed_item)
8384 guint new, unread, unreadmarked, marked, total;
8385 guint replied, forwarded, locked, ignored, watched;
8386 static gboolean tips_initialized = FALSE;
8388 if (prefs_common.layout_mode != SMALL_LAYOUT) {
8389 if (tips_initialized) {
8390 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
8391 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8392 NULL);
8393 tips_initialized = FALSE;
8395 return;
8397 folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
8398 &replied, &forwarded, &locked, &ignored,
8399 &watched);
8400 if (removed_item) {
8401 total -= removed_item->total_msgs;
8402 new -= removed_item->new_msgs;
8403 unread -= removed_item->unread_msgs;
8406 if (new > 0 || unread > 0) {
8407 tips_initialized = TRUE;
8408 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN_HRM);
8409 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8410 _("Go back to the folder list (You have unread messages)"));
8411 } else {
8412 tips_initialized = TRUE;
8413 summary_set_folder_pixmap(summaryview, STOCK_PIXMAP_DIR_OPEN);
8414 CLAWS_SET_TIP(summaryview->folder_pixmap_eventbox,
8415 _("Go back to the folder list"));
8419 static gboolean summary_update_folder_item_hook(gpointer source, gpointer data)
8421 FolderItemUpdateData *hookdata = (FolderItemUpdateData *)source;
8422 SummaryView *summaryview = (SummaryView *)data;
8424 cm_return_val_if_fail(hookdata != NULL, FALSE);
8425 cm_return_val_if_fail(hookdata->item != NULL, FALSE);
8426 cm_return_val_if_fail(summaryview != NULL, FALSE);
8428 if (hookdata->item == summaryview->folder_item &&
8429 hookdata->update_flags & F_ITEM_UPDATE_NAME) {
8430 gchar *name = folder_item_get_name(hookdata->item);
8431 gtk_label_set_text(GTK_LABEL(summaryview->statlabel_folder), name);
8432 g_free(name);
8434 summary_update_unread(summaryview, NULL);
8436 return FALSE;
8439 static gboolean summary_update_folder_hook(gpointer source, gpointer data)
8441 FolderUpdateData *hookdata;
8442 SummaryView *summaryview = (SummaryView *)data;
8443 hookdata = source;
8444 if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM) {
8445 summary_update_unread(summaryview, hookdata->item);
8446 } else
8447 summary_update_unread(summaryview, NULL);
8449 return FALSE;
8453 *\brief change summaryview to display your answer(s) to a message
8455 *\param summaryview The SummaryView ;)
8456 *\param msginfo The message for which answers are searched
8459 static void summary_find_answers (SummaryView *summaryview, MsgInfo *msg)
8461 FolderItem *sent_folder = NULL;
8462 PrefsAccount *account = NULL;
8463 GtkCMCTreeNode *node = NULL;
8464 char *buf = NULL;
8465 if (msg == NULL || msg->msgid == NULL)
8466 return;
8468 account = account_get_reply_account(msg, prefs_common.reply_account_autosel);
8469 if (account == NULL)
8470 return;
8471 sent_folder = account_get_special_folder
8472 (account, F_OUTBOX);
8474 buf = g_strdup_printf("inreplyto matchcase \"%s\"", msg->msgid);
8476 if (sent_folder != summaryview->folder_item) {
8477 folderview_select(summaryview->mainwin->folderview, sent_folder);
8480 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(summaryview->toggle_search), TRUE);
8482 quicksearch_set(summaryview->quicksearch, ADVANCED_SEARCH_EXTENDED, buf);
8483 g_free(buf);
8485 node = gtk_cmctree_node_nth(GTK_CMCTREE(summaryview->ctree), 0);
8486 if (node)
8487 summary_select_node(summaryview, node, OPEN_SELECTED_ON_SEARCH_RESULTS);
8490 gint summaryview_export_mbox_list(SummaryView *summaryview)
8491 /* return values: -2 skipped, -1 error, 0 OK */
8493 GSList *list = summary_get_selected_msg_list(summaryview);
8494 gchar *mbox = filesel_select_file_save(_("Export to mbox file"), NULL);
8495 gint ret;
8497 if (mbox == NULL)
8498 return -2;
8499 if (list == NULL)
8500 return -1;
8502 ret = export_list_to_mbox(list, mbox);
8504 g_slist_free(list);
8505 g_free(mbox);
8507 return ret;
8510 static void summary_reedit_cb(GtkAction *gaction, gpointer data)
8512 SummaryView *summaryview = (SummaryView *)data;
8513 summary_reedit(summaryview);
8516 #define DO_ACTION(name, act) { if (!strcmp(a_name, name)) action = act; }
8517 static void summary_reply_cb(GtkAction *gaction, gpointer data)
8519 SummaryView *summaryview = (SummaryView *)data;
8520 GSList *msginfo_list = NULL;
8521 gint action = COMPOSE_REPLY;
8522 const gchar *a_name = gtk_action_get_name(gaction);
8524 DO_ACTION("SummaryViewPopup/Reply", COMPOSE_REPLY);
8525 DO_ACTION("SummaryViewPopup/ReplyTo/All", COMPOSE_REPLY_TO_ALL);
8526 DO_ACTION("SummaryViewPopup/ReplyTo/Sender", COMPOSE_REPLY_TO_SENDER);
8527 DO_ACTION("SummaryViewPopup/ReplyTo/List", COMPOSE_REPLY_TO_LIST);
8528 DO_ACTION("SummaryViewPopup/Forward", COMPOSE_FORWARD_INLINE);
8529 DO_ACTION("SummaryViewPopup/ForwardAtt", COMPOSE_FORWARD_AS_ATTACH);
8530 DO_ACTION("SummaryViewPopup/Redirect", COMPOSE_REDIRECT);
8532 msginfo_list = summary_get_selection(summaryview);
8533 cm_return_if_fail(msginfo_list != NULL);
8534 compose_reply_from_messageview(NULL, msginfo_list, action);
8535 g_slist_free(msginfo_list);
8538 gboolean summary_is_opened_message_selected(SummaryView *summaryview)
8540 GList *sel = NULL;
8542 cm_return_val_if_fail(summaryview != NULL, FALSE);
8544 sel = GTK_CMCLIST(summaryview->ctree)->selection;
8546 if (summaryview->displayed == NULL || sel == NULL) {
8547 return FALSE;
8550 for ( ; sel != NULL; sel = sel->next) {
8551 if (summaryview->displayed == GTK_CMCTREE_NODE(sel->data)) {
8552 return TRUE;
8555 return FALSE;
8558 gboolean summary_has_opened_message(SummaryView *summaryview)
8560 cm_return_val_if_fail(summaryview != NULL, FALSE);
8562 return (summaryview->displayed != NULL);
8565 static void summary_header_lock_sorting_cb(GtkAction *gaction, gpointer data)
8567 SummaryView *summaryview = (SummaryView *)data;
8568 gboolean sorting_lock = prefs_common_get_prefs()->summary_col_lock;
8570 if (summaryview->header_menu_lock)
8571 return;
8573 debug_print("%slocking summaryview columns\n",
8574 sorting_lock ? "un" : "");
8575 prefs_common_get_prefs()->summary_col_lock = !sorting_lock;
8578 static void summary_header_set_displayed_columns_cb(GtkAction *gaction,
8579 gpointer data)
8581 SummaryView *summaryview = (SummaryView *)data;
8583 if (summaryview->header_menu_lock)
8584 return;
8586 prefs_summary_column_open();