root / src / summary_search.c @ 548
History | View | Annotate | Download (15.7 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 1 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 31 | hiro | * Copyright (C) 1999-2005 Hiroyuki Yamamoto |
| 4 | 1 | hiro | * |
| 5 | 1 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 1 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 1 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 1 | hiro | * (at your option) any later version. |
| 9 | 1 | hiro | * |
| 10 | 1 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 1 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 1 | hiro | * GNU General Public License for more details. |
| 14 | 1 | hiro | * |
| 15 | 1 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 1 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 1 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 1 | hiro | */ |
| 19 | 1 | hiro | |
| 20 | 1 | hiro | #ifdef HAVE_CONFIG_H
|
| 21 | 1 | hiro | # include "config.h" |
| 22 | 1 | hiro | #endif
|
| 23 | 1 | hiro | |
| 24 | 1 | hiro | #include "defs.h" |
| 25 | 1 | hiro | |
| 26 | 1 | hiro | #include <glib.h> |
| 27 | 92 | hiro | #include <glib/gi18n.h> |
| 28 | 1 | hiro | #include <gdk/gdkkeysyms.h> |
| 29 | 1 | hiro | #include <gtk/gtkwidget.h> |
| 30 | 1 | hiro | #include <gtk/gtkwindow.h> |
| 31 | 1 | hiro | #include <gtk/gtkvbox.h> |
| 32 | 1 | hiro | #include <gtk/gtktable.h> |
| 33 | 1 | hiro | #include <gtk/gtkoptionmenu.h> |
| 34 | 1 | hiro | #include <gtk/gtklabel.h> |
| 35 | 1 | hiro | #include <gtk/gtkentry.h> |
| 36 | 1 | hiro | #include <gtk/gtkhbox.h> |
| 37 | 1 | hiro | #include <gtk/gtkcheckbutton.h> |
| 38 | 1 | hiro | #include <gtk/gtkhbbox.h> |
| 39 | 1 | hiro | #include <gtk/gtkbutton.h> |
| 40 | 237 | hiro | #include <gtk/gtkmenuitem.h> |
| 41 | 237 | hiro | #include <gtk/gtkstock.h> |
| 42 | 241 | hiro | #include <gtk/gtktreemodel.h> |
| 43 | 241 | hiro | #include <gtk/gtktreeselection.h> |
| 44 | 1 | hiro | #include <stdio.h> |
| 45 | 1 | hiro | #include <stdlib.h> |
| 46 | 1 | hiro | #include <string.h> |
| 47 | 1 | hiro | |
| 48 | 1 | hiro | #include "main.h" |
| 49 | 1 | hiro | #include "summary_search.h" |
| 50 | 1 | hiro | #include "summaryview.h" |
| 51 | 1 | hiro | #include "messageview.h" |
| 52 | 1 | hiro | #include "mainwindow.h" |
| 53 | 1 | hiro | #include "menu.h" |
| 54 | 1 | hiro | #include "utils.h" |
| 55 | 1 | hiro | #include "gtkutils.h" |
| 56 | 1 | hiro | #include "manage_window.h" |
| 57 | 1 | hiro | #include "alertpanel.h" |
| 58 | 1 | hiro | |
| 59 | 271 | hiro | static struct SummarySearchWindow { |
| 60 | 271 | hiro | GtkWidget *window; |
| 61 | 1 | hiro | |
| 62 | 271 | hiro | GtkWidget *bool_optmenu; |
| 63 | 1 | hiro | |
| 64 | 271 | hiro | GtkWidget *from_entry; |
| 65 | 271 | hiro | GtkWidget *to_entry; |
| 66 | 271 | hiro | GtkWidget *subject_entry; |
| 67 | 271 | hiro | GtkWidget *body_entry; |
| 68 | 271 | hiro | |
| 69 | 271 | hiro | GtkWidget *case_checkbtn; |
| 70 | 271 | hiro | |
| 71 | 271 | hiro | GtkWidget *clear_btn; |
| 72 | 406 | hiro | GtkWidget *close_btn; |
| 73 | 271 | hiro | GtkWidget *all_btn; |
| 74 | 271 | hiro | GtkWidget *prev_btn; |
| 75 | 271 | hiro | GtkWidget *next_btn; |
| 76 | 271 | hiro | |
| 77 | 271 | hiro | SummaryView *summaryview; |
| 78 | 271 | hiro | } search_window; |
| 79 | 271 | hiro | |
| 80 | 271 | hiro | static void summary_search_create (void); |
| 81 | 271 | hiro | |
| 82 | 271 | hiro | static void summary_search_execute (gboolean backward, |
| 83 | 271 | hiro | gboolean search_all); |
| 84 | 271 | hiro | |
| 85 | 271 | hiro | static void summary_search_clear (GtkButton *button, |
| 86 | 271 | hiro | gpointer data); |
| 87 | 271 | hiro | static void summary_search_prev_clicked (GtkButton *button, |
| 88 | 271 | hiro | gpointer data); |
| 89 | 271 | hiro | static void summary_search_next_clicked (GtkButton *button, |
| 90 | 271 | hiro | gpointer data); |
| 91 | 271 | hiro | static void summary_search_all_clicked (GtkButton *button, |
| 92 | 271 | hiro | gpointer data); |
| 93 | 271 | hiro | |
| 94 | 271 | hiro | static void from_activated (void); |
| 95 | 271 | hiro | static void to_activated (void); |
| 96 | 271 | hiro | static void subject_activated (void); |
| 97 | 271 | hiro | static void body_activated (void); |
| 98 | 271 | hiro | |
| 99 | 271 | hiro | static gboolean key_pressed (GtkWidget *widget,
|
| 100 | 271 | hiro | GdkEventKey *event, |
| 101 | 271 | hiro | gpointer data); |
| 102 | 271 | hiro | |
| 103 | 271 | hiro | |
| 104 | 1 | hiro | void summary_search(SummaryView *summaryview)
|
| 105 | 1 | hiro | {
|
| 106 | 271 | hiro | if (!search_window.window)
|
| 107 | 271 | hiro | summary_search_create(); |
| 108 | 1 | hiro | else
|
| 109 | 271 | hiro | gtk_widget_hide(search_window.window); |
| 110 | 1 | hiro | |
| 111 | 271 | hiro | search_window.summaryview = summaryview; |
| 112 | 271 | hiro | |
| 113 | 271 | hiro | gtk_widget_grab_focus(search_window.next_btn); |
| 114 | 271 | hiro | gtk_widget_grab_focus(search_window.subject_entry); |
| 115 | 271 | hiro | gtk_widget_show(search_window.window); |
| 116 | 1 | hiro | } |
| 117 | 1 | hiro | |
| 118 | 271 | hiro | static void summary_search_create(void) |
| 119 | 1 | hiro | {
|
| 120 | 271 | hiro | GtkWidget *window; |
| 121 | 1 | hiro | GtkWidget *vbox1; |
| 122 | 1 | hiro | GtkWidget *bool_hbox; |
| 123 | 271 | hiro | GtkWidget *bool_optmenu; |
| 124 | 1 | hiro | GtkWidget *bool_menu; |
| 125 | 1 | hiro | GtkWidget *menuitem; |
| 126 | 271 | hiro | GtkWidget *clear_btn; |
| 127 | 271 | hiro | |
| 128 | 1 | hiro | GtkWidget *table1; |
| 129 | 1 | hiro | GtkWidget *from_label; |
| 130 | 271 | hiro | GtkWidget *from_entry; |
| 131 | 1 | hiro | GtkWidget *to_label; |
| 132 | 271 | hiro | GtkWidget *to_entry; |
| 133 | 1 | hiro | GtkWidget *subject_label; |
| 134 | 271 | hiro | GtkWidget *subject_entry; |
| 135 | 1 | hiro | GtkWidget *body_label; |
| 136 | 271 | hiro | GtkWidget *body_entry; |
| 137 | 271 | hiro | |
| 138 | 1 | hiro | GtkWidget *checkbtn_hbox; |
| 139 | 271 | hiro | GtkWidget *case_checkbtn; |
| 140 | 271 | hiro | |
| 141 | 1 | hiro | GtkWidget *confirm_area; |
| 142 | 406 | hiro | GtkWidget *close_btn; |
| 143 | 271 | hiro | GtkWidget *all_btn; |
| 144 | 271 | hiro | GtkWidget *prev_btn; |
| 145 | 271 | hiro | GtkWidget *next_btn; |
| 146 | 1 | hiro | |
| 147 | 1 | hiro | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 148 | 1 | hiro | gtk_window_set_title(GTK_WINDOW (window), _("Search messages"));
|
| 149 | 1 | hiro | gtk_widget_set_size_request(window, 450, -1); |
| 150 | 1 | hiro | gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); |
| 151 | 1 | hiro | gtk_container_set_border_width(GTK_CONTAINER (window), 8);
|
| 152 | 1 | hiro | g_signal_connect(G_OBJECT(window), "delete_event",
|
| 153 | 1 | hiro | G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
| 154 | 1 | hiro | g_signal_connect(G_OBJECT(window), "key_press_event",
|
| 155 | 1 | hiro | G_CALLBACK(key_pressed), NULL);
|
| 156 | 1 | hiro | MANAGE_WINDOW_SIGNALS_CONNECT(window); |
| 157 | 1 | hiro | |
| 158 | 1 | hiro | vbox1 = gtk_vbox_new (FALSE, 0);
|
| 159 | 1 | hiro | gtk_widget_show (vbox1); |
| 160 | 1 | hiro | gtk_container_add (GTK_CONTAINER (window), vbox1); |
| 161 | 1 | hiro | |
| 162 | 1 | hiro | bool_hbox = gtk_hbox_new(FALSE, 4);
|
| 163 | 1 | hiro | gtk_widget_show(bool_hbox); |
| 164 | 1 | hiro | gtk_box_pack_start(GTK_BOX(vbox1), bool_hbox, FALSE, FALSE, 0);
|
| 165 | 1 | hiro | |
| 166 | 1 | hiro | bool_optmenu = gtk_option_menu_new(); |
| 167 | 1 | hiro | gtk_widget_show(bool_optmenu); |
| 168 | 1 | hiro | gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0);
|
| 169 | 1 | hiro | |
| 170 | 1 | hiro | bool_menu = gtk_menu_new(); |
| 171 | 1 | hiro | MENUITEM_ADD(bool_menu, menuitem, _("Match any of the following"), 0); |
| 172 | 1 | hiro | MENUITEM_ADD(bool_menu, menuitem, _("Match all of the following"), 1); |
| 173 | 1 | hiro | gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_optmenu), bool_menu); |
| 174 | 1 | hiro | |
| 175 | 271 | hiro | clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR); |
| 176 | 271 | hiro | gtk_widget_show(clear_btn); |
| 177 | 271 | hiro | gtk_box_pack_end(GTK_BOX(bool_hbox), clear_btn, FALSE, FALSE, 0);
|
| 178 | 271 | hiro | |
| 179 | 1 | hiro | table1 = gtk_table_new (4, 3, FALSE); |
| 180 | 1 | hiro | gtk_widget_show (table1); |
| 181 | 1 | hiro | gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
|
| 182 | 1 | hiro | gtk_container_set_border_width (GTK_CONTAINER (table1), 4);
|
| 183 | 1 | hiro | gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
|
| 184 | 1 | hiro | gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
|
| 185 | 1 | hiro | |
| 186 | 1 | hiro | from_entry = gtk_entry_new (); |
| 187 | 1 | hiro | gtk_widget_show (from_entry); |
| 188 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), from_entry, 1, 3, 0, 1, |
| 189 | 1 | hiro | GTK_EXPAND|GTK_FILL, 0, 0, 0); |
| 190 | 1 | hiro | g_signal_connect(G_OBJECT(from_entry), "activate",
|
| 191 | 271 | hiro | G_CALLBACK(from_activated), NULL);
|
| 192 | 1 | hiro | |
| 193 | 1 | hiro | to_entry = gtk_entry_new (); |
| 194 | 1 | hiro | gtk_widget_show (to_entry); |
| 195 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), to_entry, 1, 3, 1, 2, |
| 196 | 1 | hiro | GTK_EXPAND|GTK_FILL, 0, 0, 0); |
| 197 | 1 | hiro | g_signal_connect(G_OBJECT(to_entry), "activate",
|
| 198 | 271 | hiro | G_CALLBACK(to_activated), NULL);
|
| 199 | 1 | hiro | |
| 200 | 1 | hiro | subject_entry = gtk_entry_new (); |
| 201 | 1 | hiro | gtk_widget_show (subject_entry); |
| 202 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), subject_entry, 1, 3, 2, 3, |
| 203 | 1 | hiro | GTK_EXPAND|GTK_FILL, 0, 0, 0); |
| 204 | 1 | hiro | g_signal_connect(G_OBJECT(subject_entry), "activate",
|
| 205 | 271 | hiro | G_CALLBACK(subject_activated), NULL);
|
| 206 | 1 | hiro | |
| 207 | 1 | hiro | body_entry = gtk_entry_new (); |
| 208 | 1 | hiro | gtk_widget_show (body_entry); |
| 209 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), body_entry, 1, 3, 3, 4, |
| 210 | 1 | hiro | GTK_EXPAND|GTK_FILL, 0, 0, 0); |
| 211 | 1 | hiro | g_signal_connect(G_OBJECT(body_entry), "activate",
|
| 212 | 271 | hiro | G_CALLBACK(body_activated), NULL);
|
| 213 | 1 | hiro | |
| 214 | 1 | hiro | from_label = gtk_label_new (_("From:"));
|
| 215 | 1 | hiro | gtk_widget_show (from_label); |
| 216 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), from_label, 0, 1, 0, 1, |
| 217 | 1 | hiro | GTK_FILL, 0, 0, 0); |
| 218 | 1 | hiro | gtk_label_set_justify (GTK_LABEL (from_label), GTK_JUSTIFY_RIGHT); |
| 219 | 1 | hiro | gtk_misc_set_alignment (GTK_MISC (from_label), 1, 0.5); |
| 220 | 1 | hiro | |
| 221 | 1 | hiro | to_label = gtk_label_new (_("To:"));
|
| 222 | 1 | hiro | gtk_widget_show (to_label); |
| 223 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), to_label, 0, 1, 1, 2, |
| 224 | 1 | hiro | GTK_FILL, 0, 0, 0); |
| 225 | 1 | hiro | gtk_label_set_justify (GTK_LABEL (to_label), GTK_JUSTIFY_RIGHT); |
| 226 | 1 | hiro | gtk_misc_set_alignment (GTK_MISC (to_label), 1, 0.5); |
| 227 | 1 | hiro | |
| 228 | 1 | hiro | subject_label = gtk_label_new (_("Subject:"));
|
| 229 | 1 | hiro | gtk_widget_show (subject_label); |
| 230 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), subject_label, 0, 1, 2, 3, |
| 231 | 1 | hiro | GTK_FILL, 0, 0, 0); |
| 232 | 1 | hiro | gtk_label_set_justify (GTK_LABEL (subject_label), GTK_JUSTIFY_RIGHT); |
| 233 | 1 | hiro | gtk_misc_set_alignment (GTK_MISC (subject_label), 1, 0.5); |
| 234 | 1 | hiro | |
| 235 | 1 | hiro | body_label = gtk_label_new (_("Body:"));
|
| 236 | 1 | hiro | gtk_widget_show (body_label); |
| 237 | 1 | hiro | gtk_table_attach (GTK_TABLE (table1), body_label, 0, 1, 3, 4, |
| 238 | 1 | hiro | GTK_FILL, 0, 0, 0); |
| 239 | 1 | hiro | gtk_label_set_justify (GTK_LABEL (body_label), GTK_JUSTIFY_RIGHT); |
| 240 | 1 | hiro | gtk_misc_set_alignment (GTK_MISC (body_label), 1, 0.5); |
| 241 | 1 | hiro | |
| 242 | 1 | hiro | checkbtn_hbox = gtk_hbox_new (FALSE, 8);
|
| 243 | 1 | hiro | gtk_widget_show (checkbtn_hbox); |
| 244 | 1 | hiro | gtk_box_pack_start (GTK_BOX (vbox1), checkbtn_hbox, TRUE, TRUE, 0);
|
| 245 | 1 | hiro | gtk_container_set_border_width (GTK_CONTAINER (checkbtn_hbox), 8);
|
| 246 | 1 | hiro | |
| 247 | 1 | hiro | case_checkbtn = gtk_check_button_new_with_label (_("Case sensitive"));
|
| 248 | 1 | hiro | gtk_widget_show (case_checkbtn); |
| 249 | 1 | hiro | gtk_box_pack_start (GTK_BOX (checkbtn_hbox), case_checkbtn, |
| 250 | 1 | hiro | FALSE, FALSE, 0);
|
| 251 | 1 | hiro | |
| 252 | 271 | hiro | confirm_area = gtk_hbutton_box_new(); |
| 253 | 271 | hiro | gtk_widget_show (confirm_area); |
| 254 | 271 | hiro | gtk_button_box_set_layout(GTK_BUTTON_BOX(confirm_area), |
| 255 | 271 | hiro | GTK_BUTTONBOX_END); |
| 256 | 405 | hiro | gtk_box_set_spacing(GTK_BOX(confirm_area), 6);
|
| 257 | 1 | hiro | |
| 258 | 406 | hiro | close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE); |
| 259 | 406 | hiro | GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT); |
| 260 | 406 | hiro | gtk_box_pack_start(GTK_BOX(confirm_area), close_btn, TRUE, TRUE, 0);
|
| 261 | 406 | hiro | gtk_widget_show(close_btn); |
| 262 | 406 | hiro | |
| 263 | 271 | hiro | all_btn = gtk_button_new_from_stock(_("Find all"));
|
| 264 | 271 | hiro | GTK_WIDGET_SET_FLAGS(all_btn, GTK_CAN_DEFAULT); |
| 265 | 271 | hiro | gtk_box_pack_start(GTK_BOX(confirm_area), all_btn, TRUE, TRUE, 0);
|
| 266 | 271 | hiro | gtk_widget_show(all_btn); |
| 267 | 1 | hiro | |
| 268 | 271 | hiro | prev_btn = gtk_button_new_from_stock(GTK_STOCK_GO_BACK); |
| 269 | 271 | hiro | GTK_WIDGET_SET_FLAGS(prev_btn, GTK_CAN_DEFAULT); |
| 270 | 271 | hiro | gtk_box_pack_start(GTK_BOX(confirm_area), prev_btn, TRUE, TRUE, 0);
|
| 271 | 271 | hiro | gtk_widget_show(prev_btn); |
| 272 | 271 | hiro | |
| 273 | 271 | hiro | next_btn = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD); |
| 274 | 271 | hiro | GTK_WIDGET_SET_FLAGS(next_btn, GTK_CAN_DEFAULT); |
| 275 | 271 | hiro | gtk_box_pack_start(GTK_BOX(confirm_area), next_btn, TRUE, TRUE, 0);
|
| 276 | 271 | hiro | gtk_widget_show(next_btn); |
| 277 | 271 | hiro | |
| 278 | 1 | hiro | gtk_box_pack_start (GTK_BOX (vbox1), confirm_area, FALSE, FALSE, 0);
|
| 279 | 271 | hiro | gtk_widget_grab_default(next_btn); |
| 280 | 1 | hiro | |
| 281 | 1 | hiro | g_signal_connect(G_OBJECT(clear_btn), "clicked",
|
| 282 | 271 | hiro | G_CALLBACK(summary_search_clear), NULL);
|
| 283 | 271 | hiro | g_signal_connect(G_OBJECT(all_btn), "clicked",
|
| 284 | 271 | hiro | G_CALLBACK(summary_search_all_clicked), NULL);
|
| 285 | 271 | hiro | g_signal_connect(G_OBJECT(prev_btn), "clicked",
|
| 286 | 271 | hiro | G_CALLBACK(summary_search_prev_clicked), NULL);
|
| 287 | 271 | hiro | g_signal_connect(G_OBJECT(next_btn), "clicked",
|
| 288 | 271 | hiro | G_CALLBACK(summary_search_next_clicked), NULL);
|
| 289 | 1 | hiro | g_signal_connect_closure |
| 290 | 1 | hiro | (G_OBJECT(close_btn), "clicked",
|
| 291 | 1 | hiro | g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide), |
| 292 | 1 | hiro | window, NULL),
|
| 293 | 1 | hiro | FALSE); |
| 294 | 271 | hiro | |
| 295 | 271 | hiro | search_window.window = window; |
| 296 | 271 | hiro | search_window.bool_optmenu = bool_optmenu; |
| 297 | 271 | hiro | search_window.from_entry = from_entry; |
| 298 | 271 | hiro | search_window.to_entry = to_entry; |
| 299 | 271 | hiro | search_window.subject_entry = subject_entry; |
| 300 | 271 | hiro | search_window.body_entry = body_entry; |
| 301 | 271 | hiro | search_window.case_checkbtn = case_checkbtn; |
| 302 | 271 | hiro | search_window.clear_btn = clear_btn; |
| 303 | 406 | hiro | search_window.close_btn = close_btn; |
| 304 | 271 | hiro | search_window.all_btn = all_btn; |
| 305 | 271 | hiro | search_window.prev_btn = prev_btn; |
| 306 | 271 | hiro | search_window.next_btn = next_btn; |
| 307 | 1 | hiro | } |
| 308 | 1 | hiro | |
| 309 | 271 | hiro | static void summary_search_execute(gboolean backward, gboolean search_all) |
| 310 | 1 | hiro | {
|
| 311 | 271 | hiro | SummaryView *summaryview = search_window.summaryview; |
| 312 | 241 | hiro | GtkTreeModel *model; |
| 313 | 241 | hiro | GtkTreeIter iter; |
| 314 | 1 | hiro | MsgInfo *msginfo; |
| 315 | 1 | hiro | gboolean bool_and; |
| 316 | 1 | hiro | gboolean case_sens; |
| 317 | 1 | hiro | gboolean all_searched = FALSE; |
| 318 | 1 | hiro | gboolean matched; |
| 319 | 1 | hiro | gboolean body_matched; |
| 320 | 1 | hiro | const gchar *from_str, *to_str, *subject_str, *body_str;
|
| 321 | 1 | hiro | StrFindFunc str_find_func; |
| 322 | 241 | hiro | gboolean valid; |
| 323 | 1 | hiro | |
| 324 | 1 | hiro | if (summary_is_locked(summaryview)) return; |
| 325 | 1 | hiro | summary_lock(summaryview); |
| 326 | 1 | hiro | |
| 327 | 241 | hiro | model = GTK_TREE_MODEL(summaryview->store); |
| 328 | 241 | hiro | |
| 329 | 1 | hiro | bool_and = menu_get_option_menu_active_index |
| 330 | 271 | hiro | (GTK_OPTION_MENU(search_window.bool_optmenu)); |
| 331 | 1 | hiro | case_sens = gtk_toggle_button_get_active |
| 332 | 271 | hiro | (GTK_TOGGLE_BUTTON(search_window.case_checkbtn)); |
| 333 | 1 | hiro | |
| 334 | 1 | hiro | if (case_sens)
|
| 335 | 1 | hiro | str_find_func = str_find; |
| 336 | 1 | hiro | else
|
| 337 | 1 | hiro | str_find_func = str_case_find; |
| 338 | 1 | hiro | |
| 339 | 271 | hiro | from_str = gtk_entry_get_text(GTK_ENTRY(search_window.from_entry)); |
| 340 | 271 | hiro | to_str = gtk_entry_get_text(GTK_ENTRY(search_window.to_entry)); |
| 341 | 271 | hiro | subject_str = gtk_entry_get_text(GTK_ENTRY(search_window.subject_entry)); |
| 342 | 271 | hiro | body_str = gtk_entry_get_text(GTK_ENTRY(search_window.body_entry)); |
| 343 | 1 | hiro | |
| 344 | 1 | hiro | if (search_all) {
|
| 345 | 241 | hiro | summary_unselect_all(summaryview); |
| 346 | 241 | hiro | valid = gtk_tree_model_get_iter_first(model, &iter); |
| 347 | 1 | hiro | backward = FALSE; |
| 348 | 1 | hiro | } else if (!summaryview->selected) { |
| 349 | 1 | hiro | if (backward)
|
| 350 | 271 | hiro | valid = gtkut_tree_model_get_iter_last(model, &iter); |
| 351 | 1 | hiro | else
|
| 352 | 241 | hiro | valid = gtk_tree_model_get_iter_first(model, &iter); |
| 353 | 241 | hiro | if (!valid) {
|
| 354 | 1 | hiro | summary_unlock(summaryview); |
| 355 | 1 | hiro | return;
|
| 356 | 1 | hiro | } |
| 357 | 1 | hiro | } else {
|
| 358 | 241 | hiro | valid = gtkut_tree_row_reference_get_iter |
| 359 | 241 | hiro | (model, summaryview->selected, &iter); |
| 360 | 241 | hiro | if (!valid) {
|
| 361 | 241 | hiro | summary_unlock(summaryview); |
| 362 | 241 | hiro | return;
|
| 363 | 241 | hiro | } |
| 364 | 241 | hiro | |
| 365 | 1 | hiro | if (backward)
|
| 366 | 241 | hiro | valid = gtkut_tree_model_prev(model, &iter); |
| 367 | 1 | hiro | else
|
| 368 | 241 | hiro | valid = gtkut_tree_model_next(model, &iter); |
| 369 | 1 | hiro | } |
| 370 | 1 | hiro | |
| 371 | 1 | hiro | if (*body_str)
|
| 372 | 1 | hiro | main_window_cursor_wait(summaryview->mainwin); |
| 373 | 1 | hiro | |
| 374 | 1 | hiro | for (;;) {
|
| 375 | 241 | hiro | if (!valid) {
|
| 376 | 1 | hiro | gchar *str; |
| 377 | 1 | hiro | AlertValue val; |
| 378 | 1 | hiro | |
| 379 | 1 | hiro | if (search_all) {
|
| 380 | 1 | hiro | break;
|
| 381 | 1 | hiro | } |
| 382 | 1 | hiro | |
| 383 | 1 | hiro | if (all_searched) {
|
| 384 | 1 | hiro | alertpanel_message |
| 385 | 1 | hiro | (_("Search failed"),
|
| 386 | 1 | hiro | _("Search string not found."),
|
| 387 | 1 | hiro | ALERT_WARNING); |
| 388 | 1 | hiro | break;
|
| 389 | 1 | hiro | } |
| 390 | 1 | hiro | |
| 391 | 1 | hiro | if (backward)
|
| 392 | 1 | hiro | str = _("Beginning of list reached; continue from end?");
|
| 393 | 1 | hiro | else
|
| 394 | 1 | hiro | str = _("End of list reached; continue from beginning?");
|
| 395 | 1 | hiro | |
| 396 | 1 | hiro | val = alertpanel(_("Search finished"), str,
|
| 397 | 47 | hiro | GTK_STOCK_YES, GTK_STOCK_NO, NULL);
|
| 398 | 1 | hiro | if (G_ALERTDEFAULT == val) {
|
| 399 | 1 | hiro | if (backward)
|
| 400 | 241 | hiro | valid = gtkut_tree_model_get_iter_last |
| 401 | 241 | hiro | (model, &iter); |
| 402 | 1 | hiro | else
|
| 403 | 241 | hiro | valid = gtk_tree_model_get_iter_first |
| 404 | 241 | hiro | (model, &iter); |
| 405 | 1 | hiro | all_searched = TRUE; |
| 406 | 271 | hiro | manage_window_focus_in(search_window.window, |
| 407 | 271 | hiro | NULL, NULL); |
| 408 | 1 | hiro | } else
|
| 409 | 1 | hiro | break;
|
| 410 | 1 | hiro | } |
| 411 | 1 | hiro | |
| 412 | 241 | hiro | gtk_tree_model_get(model, &iter, S_COL_MSG_INFO, &msginfo, -1);
|
| 413 | 1 | hiro | body_matched = FALSE; |
| 414 | 1 | hiro | |
| 415 | 1 | hiro | if (bool_and) {
|
| 416 | 1 | hiro | matched = TRUE; |
| 417 | 1 | hiro | if (*from_str) {
|
| 418 | 1 | hiro | if (!msginfo->from ||
|
| 419 | 1 | hiro | !str_find_func(msginfo->from, from_str)) |
| 420 | 1 | hiro | matched = FALSE; |
| 421 | 1 | hiro | } |
| 422 | 1 | hiro | if (matched && *to_str) {
|
| 423 | 1 | hiro | if (!msginfo->to ||
|
| 424 | 1 | hiro | !str_find_func(msginfo->to, to_str)) |
| 425 | 1 | hiro | matched = FALSE; |
| 426 | 1 | hiro | } |
| 427 | 1 | hiro | if (matched && *subject_str) {
|
| 428 | 1 | hiro | if (!msginfo->subject ||
|
| 429 | 1 | hiro | !str_find_func(msginfo->subject, subject_str)) |
| 430 | 1 | hiro | matched = FALSE; |
| 431 | 1 | hiro | } |
| 432 | 1 | hiro | if (matched && *body_str) {
|
| 433 | 1 | hiro | if (procmime_find_string(msginfo, body_str,
|
| 434 | 1 | hiro | str_find_func)) |
| 435 | 1 | hiro | body_matched = TRUE; |
| 436 | 1 | hiro | else
|
| 437 | 1 | hiro | matched = FALSE; |
| 438 | 1 | hiro | } |
| 439 | 1 | hiro | if (matched && !*from_str && !*to_str &&
|
| 440 | 1 | hiro | !*subject_str && !*body_str) |
| 441 | 1 | hiro | matched = FALSE; |
| 442 | 1 | hiro | } else {
|
| 443 | 1 | hiro | matched = FALSE; |
| 444 | 1 | hiro | if (*from_str && msginfo->from) {
|
| 445 | 1 | hiro | if (str_find_func(msginfo->from, from_str))
|
| 446 | 1 | hiro | matched = TRUE; |
| 447 | 1 | hiro | } |
| 448 | 1 | hiro | if (!matched && *to_str && msginfo->to) {
|
| 449 | 1 | hiro | if (str_find_func(msginfo->to, to_str))
|
| 450 | 1 | hiro | matched = TRUE; |
| 451 | 1 | hiro | } |
| 452 | 1 | hiro | if (!matched && *subject_str && msginfo->subject) {
|
| 453 | 1 | hiro | if (str_find_func(msginfo->subject, subject_str))
|
| 454 | 1 | hiro | matched = TRUE; |
| 455 | 1 | hiro | } |
| 456 | 1 | hiro | if (!matched && *body_str) {
|
| 457 | 1 | hiro | if (procmime_find_string(msginfo, body_str,
|
| 458 | 1 | hiro | str_find_func)) {
|
| 459 | 1 | hiro | matched = TRUE; |
| 460 | 1 | hiro | body_matched = TRUE; |
| 461 | 1 | hiro | } |
| 462 | 1 | hiro | } |
| 463 | 1 | hiro | } |
| 464 | 1 | hiro | |
| 465 | 1 | hiro | if (matched) {
|
| 466 | 241 | hiro | if (search_all) {
|
| 467 | 241 | hiro | gtk_tree_selection_select_iter |
| 468 | 241 | hiro | (summaryview->selection, &iter); |
| 469 | 241 | hiro | } else {
|
| 470 | 1 | hiro | if (messageview_is_visible
|
| 471 | 1 | hiro | (summaryview->messageview)) {
|
| 472 | 1 | hiro | summary_unlock(summaryview); |
| 473 | 237 | hiro | summary_select_row |
| 474 | 241 | hiro | (summaryview, &iter, |
| 475 | 241 | hiro | TRUE, TRUE); |
| 476 | 1 | hiro | summary_lock(summaryview); |
| 477 | 1 | hiro | if (body_matched) {
|
| 478 | 1 | hiro | messageview_search_string |
| 479 | 1 | hiro | (summaryview->messageview, |
| 480 | 1 | hiro | body_str, case_sens); |
| 481 | 1 | hiro | } |
| 482 | 1 | hiro | } else {
|
| 483 | 241 | hiro | summary_select_row |
| 484 | 241 | hiro | (summaryview, &iter, |
| 485 | 241 | hiro | FALSE, TRUE); |
| 486 | 1 | hiro | } |
| 487 | 1 | hiro | break;
|
| 488 | 1 | hiro | } |
| 489 | 1 | hiro | } |
| 490 | 1 | hiro | |
| 491 | 241 | hiro | if (backward)
|
| 492 | 241 | hiro | valid = gtkut_tree_model_prev(model, &iter); |
| 493 | 241 | hiro | else
|
| 494 | 241 | hiro | valid = gtkut_tree_model_next(model, &iter); |
| 495 | 1 | hiro | } |
| 496 | 1 | hiro | |
| 497 | 1 | hiro | if (*body_str)
|
| 498 | 1 | hiro | main_window_cursor_normal(summaryview->mainwin); |
| 499 | 1 | hiro | |
| 500 | 1 | hiro | summary_unlock(summaryview); |
| 501 | 1 | hiro | } |
| 502 | 1 | hiro | |
| 503 | 1 | hiro | static void summary_search_clear(GtkButton *button, gpointer data) |
| 504 | 1 | hiro | {
|
| 505 | 271 | hiro | gtk_editable_delete_text(GTK_EDITABLE(search_window.from_entry), |
| 506 | 271 | hiro | 0, -1); |
| 507 | 271 | hiro | gtk_editable_delete_text(GTK_EDITABLE(search_window.to_entry), |
| 508 | 271 | hiro | 0, -1); |
| 509 | 271 | hiro | gtk_editable_delete_text(GTK_EDITABLE(search_window.subject_entry), |
| 510 | 271 | hiro | 0, -1); |
| 511 | 271 | hiro | gtk_editable_delete_text(GTK_EDITABLE(search_window.body_entry), |
| 512 | 271 | hiro | 0, -1); |
| 513 | 1 | hiro | } |
| 514 | 1 | hiro | |
| 515 | 271 | hiro | static void summary_search_prev_clicked(GtkButton *button, gpointer data) |
| 516 | 271 | hiro | {
|
| 517 | 271 | hiro | summary_search_execute(TRUE, FALSE); |
| 518 | 271 | hiro | } |
| 519 | 271 | hiro | |
| 520 | 271 | hiro | static void summary_search_next_clicked(GtkButton *button, gpointer data) |
| 521 | 271 | hiro | {
|
| 522 | 271 | hiro | summary_search_execute(FALSE, FALSE); |
| 523 | 271 | hiro | } |
| 524 | 271 | hiro | |
| 525 | 271 | hiro | static void summary_search_all_clicked(GtkButton *button, gpointer data) |
| 526 | 271 | hiro | {
|
| 527 | 271 | hiro | summary_search_execute(FALSE, TRUE); |
| 528 | 271 | hiro | } |
| 529 | 271 | hiro | |
| 530 | 1 | hiro | static void from_activated(void) |
| 531 | 1 | hiro | {
|
| 532 | 271 | hiro | gtk_widget_grab_focus(search_window.to_entry); |
| 533 | 1 | hiro | } |
| 534 | 1 | hiro | |
| 535 | 1 | hiro | static void to_activated(void) |
| 536 | 1 | hiro | {
|
| 537 | 271 | hiro | gtk_widget_grab_focus(search_window.subject_entry); |
| 538 | 1 | hiro | } |
| 539 | 1 | hiro | |
| 540 | 1 | hiro | static void subject_activated(void) |
| 541 | 1 | hiro | {
|
| 542 | 271 | hiro | gtk_button_clicked(GTK_BUTTON(search_window.next_btn)); |
| 543 | 1 | hiro | } |
| 544 | 1 | hiro | |
| 545 | 1 | hiro | static void body_activated(void) |
| 546 | 1 | hiro | {
|
| 547 | 271 | hiro | gtk_button_clicked(GTK_BUTTON(search_window.next_btn)); |
| 548 | 1 | hiro | } |
| 549 | 1 | hiro | |
| 550 | 1 | hiro | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
|
| 551 | 1 | hiro | gpointer data) |
| 552 | 1 | hiro | {
|
| 553 | 1 | hiro | if (event && event->keyval == GDK_Escape)
|
| 554 | 271 | hiro | gtk_widget_hide(search_window.window); |
| 555 | 1 | hiro | return FALSE;
|
| 556 | 1 | hiro | } |