diff options
Diffstat (limited to 'src/query_search.c')
| -rw-r--r-- | src/query_search.c | 1698 |
1 files changed, 1698 insertions, 0 deletions
diff --git a/src/query_search.c b/src/query_search.c new file mode 100644 index 0000000..0b6170e --- /dev/null +++ b/src/query_search.c | |||
| @@ -0,0 +1,1698 @@ | |||
| 1 | /* | ||
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client | ||
| 3 | * Copyright (C) 1999-2017 Hiroyuki Yamamoto | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifdef HAVE_CONFIG_H | ||
| 21 | # include "config.h" | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include "defs.h" | ||
| 25 | |||
| 26 | #include <glib.h> | ||
| 27 | #include <glib/gi18n.h> | ||
| 28 | #include <gdk/gdkkeysyms.h> | ||
| 29 | #include <gtk/gtkwidget.h> | ||
| 30 | #include <gtk/gtkwindow.h> | ||
| 31 | #include <gtk/gtkvbox.h> | ||
| 32 | #include <gtk/gtktable.h> | ||
| 33 | #include <gtk/gtkoptionmenu.h> | ||
| 34 | #include <gtk/gtklabel.h> | ||
| 35 | #include <gtk/gtkentry.h> | ||
| 36 | #include <gtk/gtkhbox.h> | ||
| 37 | #include <gtk/gtkcheckbutton.h> | ||
| 38 | #include <gtk/gtkhbbox.h> | ||
| 39 | #include <gtk/gtkbutton.h> | ||
| 40 | #include <gtk/gtkmenuitem.h> | ||
| 41 | #include <gtk/gtkstock.h> | ||
| 42 | #include <gtk/gtktreemodel.h> | ||
| 43 | #include <gtk/gtkliststore.h> | ||
| 44 | #include <gtk/gtktreeview.h> | ||
| 45 | #include <gtk/gtktreeselection.h> | ||
| 46 | #include <gtk/gtkcellrenderertext.h> | ||
| 47 | #include <gtk/gtkuimanager.h> | ||
| 48 | #include <stdio.h> | ||
| 49 | #include <stdlib.h> | ||
| 50 | #include <string.h> | ||
| 51 | |||
| 52 | #include "query_search.h" | ||
| 53 | #include "summaryview.h" | ||
| 54 | #include "messageview.h" | ||
| 55 | #include "mainwindow.h" | ||
| 56 | #include "folderview.h" | ||
| 57 | #include "menu.h" | ||
| 58 | #include "utils.h" | ||
| 59 | #include "gtkutils.h" | ||
| 60 | #include "manage_window.h" | ||
| 61 | #include "alertpanel.h" | ||
| 62 | #include "foldersel.h" | ||
| 63 | #include "statusbar.h" | ||
| 64 | #include "procmsg.h" | ||
| 65 | #include "procheader.h" | ||
| 66 | #include "folder.h" | ||
| 67 | #include "filter.h" | ||
| 68 | #include "prefs_common.h" | ||
| 69 | #include "prefs_filter.h" | ||
| 70 | #include "prefs_filter_edit.h" | ||
| 71 | #include "compose.h" | ||
| 72 | #include "sourcewindow.h" | ||
| 73 | #include "printing.h" | ||
| 74 | |||
| 75 | enum | ||
| 76 | { | ||
| 77 | COL_FOLDER, | ||
| 78 | COL_SUBJECT, | ||
| 79 | COL_FROM, | ||
| 80 | COL_DATE, | ||
| 81 | COL_MSGINFO, | ||
| 82 | N_COLS | ||
| 83 | }; | ||
| 84 | |||
| 85 | static struct QuerySearchWindow { | ||
| 86 | GtkWidget *window; | ||
| 87 | |||
| 88 | GtkWidget *bool_optmenu; | ||
| 89 | |||
| 90 | FilterCondEdit *cond_edit; | ||
| 91 | |||
| 92 | GtkWidget *folder_entry; | ||
| 93 | GtkWidget *folder_btn; | ||
| 94 | |||
| 95 | GtkWidget *subfolder_checkbtn; | ||
| 96 | GtkWidget *case_checkbtn; | ||
| 97 | |||
| 98 | GtkWidget *treeview; | ||
| 99 | GtkListStore *store; | ||
| 100 | |||
| 101 | GtkWidget *status_label; | ||
| 102 | |||
| 103 | GtkWidget *clear_btn; | ||
| 104 | GtkWidget *search_btn; | ||
| 105 | GtkWidget *save_btn; | ||
| 106 | GtkWidget *close_btn; | ||
| 107 | |||
| 108 | GtkActionGroup *group; | ||
| 109 | GtkUIManager *ui; | ||
| 110 | |||
| 111 | FilterRule *rule; | ||
| 112 | gboolean requires_full_headers; | ||
| 113 | |||
| 114 | gboolean exclude_trash; | ||
| 115 | |||
| 116 | gint n_found; | ||
| 117 | |||
| 118 | gboolean on_search; | ||
| 119 | gboolean cancelled; | ||
| 120 | } search_window; | ||
| 121 | |||
| 122 | typedef struct { | ||
| 123 | GtkWidget *window; | ||
| 124 | |||
| 125 | GtkWidget *folder_entry; | ||
| 126 | GtkWidget *name_entry; | ||
| 127 | |||
| 128 | GtkWidget *ok_btn; | ||
| 129 | GtkWidget *cancel_btn; | ||
| 130 | |||
| 131 | gboolean cancelled; | ||
| 132 | gboolean finished; | ||
| 133 | } QuerySearchSaveDialog; | ||
| 134 | |||
| 135 | static const gchar *ui_def = | ||
| 136 | "<ui>" | ||
| 137 | " <popup name='PopUpMenu'>" | ||
| 138 | " <menuitem name='Reply' action='ReplyAction'/>" | ||
| 139 | " <menu name='ReplyTo' action='ReplyToAction'>" | ||
| 140 | " <menuitem name='ReplyAll' action='ReplyAllAction'/>" | ||
| 141 | " <menuitem name='ReplySender' action='ReplySenderAction'/>" | ||
| 142 | " <menuitem name='ReplyList' action='ReplyListAction'/>" | ||
| 143 | " </menu>" | ||
| 144 | " <separator />" | ||
| 145 | " <menuitem name='Forward' action='ForwardAction'/>" | ||
| 146 | " <menuitem name='ForwardAsAttach' action='ForwardAsAttachAction'/>" | ||
| 147 | " <menuitem name='Redirect' action='RedirectAction'/>" | ||
| 148 | " <separator />" | ||
| 149 | " <menuitem name='MoveMsg' action='MoveMsgAction'/>" | ||
| 150 | " <menuitem name='CopyMsg' action='CopyMsgAction'/>" | ||
| 151 | " <separator />" | ||
| 152 | " <menuitem name='AddAddress' action='AddAddressAction'/>" | ||
| 153 | " <menu name='CreateFilter' action='CreateFilterAction'>" | ||
| 154 | " <menuitem name='Auto' action='FilterAutoAction'/>" | ||
| 155 | " <menuitem name='From' action='FilterFromAction'/>" | ||
| 156 | " <menuitem name='To' action='FilterToAction'/>" | ||
| 157 | " <menuitem name='Subject' action='FilterSubjectAction'/>" | ||
| 158 | " </menu>" | ||
| 159 | " <separator />" | ||
| 160 | " <menuitem name='Open' action='OpenAction'/>" | ||
| 161 | " <menuitem name='OpenSource' action='OpenSourceAction'/>" | ||
| 162 | " <separator />" | ||
| 163 | " <menuitem name='Print' action='PrintAction'/>" | ||
| 164 | " </popup>" | ||
| 165 | "</ui>"; | ||
| 166 | |||
| 167 | static void query_search_create (void); | ||
| 168 | |||
| 169 | static FilterRule *query_search_dialog_to_rule (const gchar *name, | ||
| 170 | FolderItem **item); | ||
| 171 | |||
| 172 | static void query_search_query (void); | ||
| 173 | static void query_search_folder (FolderItem *item); | ||
| 174 | |||
| 175 | static gboolean query_search_recursive_func (GNode *node, | ||
| 176 | gpointer data); | ||
| 177 | |||
| 178 | static void query_search_append_msg (MsgInfo *msginfo); | ||
| 179 | static void query_search_clear_list (void); | ||
| 180 | |||
| 181 | static void query_search_hbox_added (CondHBox *hbox); | ||
| 182 | |||
| 183 | static void row_activated (GtkTreeView *treeview, | ||
| 184 | GtkTreePath *path, | ||
| 185 | GtkTreeViewColumn *column, | ||
| 186 | gpointer data); | ||
| 187 | |||
| 188 | static gboolean row_selected (GtkTreeSelection *selection, | ||
| 189 | GtkTreeModel *model, | ||
| 190 | GtkTreePath *path, | ||
| 191 | gboolean cur_selected, | ||
| 192 | gpointer data); | ||
| 193 | |||
| 194 | static gboolean treeview_button_pressed (GtkWidget *widget, | ||
| 195 | GdkEventButton *event, | ||
| 196 | gpointer data); | ||
| 197 | |||
| 198 | static void query_search_clear (GtkButton *button, | ||
| 199 | gpointer data); | ||
| 200 | static void query_select_folder (GtkButton *button, | ||
| 201 | gpointer data); | ||
| 202 | static void query_search_clicked (GtkButton *button, | ||
| 203 | gpointer data); | ||
| 204 | static void query_search_save (GtkButton *button, | ||
| 205 | gpointer data); | ||
| 206 | static void query_search_close (GtkButton *button, | ||
| 207 | gpointer data); | ||
| 208 | |||
| 209 | static void query_search_entry_activated(GtkWidget *widget, | ||
| 210 | gpointer data); | ||
| 211 | |||
| 212 | static gint query_search_deleted (GtkWidget *widget, | ||
| 213 | GdkEventAny *event, | ||
| 214 | gpointer data); | ||
| 215 | static gboolean key_pressed (GtkWidget *widget, | ||
| 216 | GdkEventKey *event, | ||
| 217 | gpointer data); | ||
| 218 | |||
| 219 | static void query_search_open_msg (gboolean new_window); | ||
| 220 | |||
| 221 | /* Popup menu callbacks */ | ||
| 222 | static void reply_cb(void); | ||
| 223 | static void reply_all_cb(void); | ||
| 224 | static void reply_sender_cb(void); | ||
| 225 | static void reply_list_cb(void); | ||
| 226 | static void forward_cb(void); | ||
| 227 | static void forward_attach_cb(void); | ||
| 228 | static void redirect_cb(void); | ||
| 229 | static void move_cb(void); | ||
| 230 | static void copy_cb(void); | ||
| 231 | static void add_address_cb(void); | ||
| 232 | static void create_filter_auto_cb(void); | ||
| 233 | static void create_filter_from_cb(void); | ||
| 234 | static void create_filter_to_cb(void); | ||
| 235 | static void create_filter_subject_cb(void); | ||
| 236 | static void open_cb (void); | ||
| 237 | static void open_source_cb (void); | ||
| 238 | static void print_cb (void); | ||
| 239 | |||
| 240 | static gint query_search_cmp_by_folder (GtkTreeModel *model, | ||
| 241 | GtkTreeIter *a, | ||
| 242 | GtkTreeIter *b, | ||
| 243 | gpointer data); | ||
| 244 | static gint query_search_cmp_by_subject (GtkTreeModel *model, | ||
| 245 | GtkTreeIter *a, | ||
| 246 | GtkTreeIter *b, | ||
| 247 | gpointer data); | ||
| 248 | static gint query_search_cmp_by_from (GtkTreeModel *model, | ||
| 249 | GtkTreeIter *a, | ||
| 250 | GtkTreeIter *b, | ||
| 251 | gpointer data); | ||
| 252 | static gint query_search_cmp_by_date (GtkTreeModel *model, | ||
| 253 | GtkTreeIter *a, | ||
| 254 | GtkTreeIter *b, | ||
| 255 | gpointer data); | ||
| 256 | |||
| 257 | static GtkActionEntry action_entries[] = { | ||
| 258 | {"ReplyAction", NULL, N_("_Reply"), NULL, NULL, reply_cb}, | ||
| 259 | {"ReplyToAction", NULL, N_("Repl_y to"), NULL, NULL, NULL}, | ||
| 260 | {"ReplyAllAction", NULL, N_("Reply to _all"), NULL, NULL, reply_all_cb}, | ||
| 261 | {"ReplySenderAction", NULL, N_("Reply to _sender"), NULL, NULL, reply_sender_cb}, | ||
| 262 | {"ReplyListAction", NULL, N_("Reply to _list"), NULL, NULL, reply_list_cb}, | ||
| 263 | |||
| 264 | {"ForwardAction", NULL, N_("_Forward"), NULL, NULL, forward_cb}, | ||
| 265 | {"ForwardAsAttachAction", NULL, N_("For_ward as attachment"), NULL, NULL, forward_attach_cb}, | ||
| 266 | {"RedirectAction", NULL, N_("Redirec_t"), NULL, NULL, redirect_cb}, | ||
| 267 | |||
| 268 | {"MoveMsgAction", NULL, N_("M_ove messages to..."), NULL, NULL, move_cb}, | ||
| 269 | {"CopyMsgAction", NULL, N_("_Copy messages to..."), NULL, NULL, copy_cb}, | ||
| 270 | |||
| 271 | {"AddAddressAction", NULL, N_("Add sender to address boo_k..."), NULL, NULL, add_address_cb}, | ||
| 272 | {"CreateFilterAction", NULL, N_("Create f_ilter rule"), NULL, NULL, NULL}, | ||
| 273 | {"FilterAutoAction", NULL, N_("_Automatically"), NULL, NULL, create_filter_auto_cb}, | ||
| 274 | {"FilterFromAction", NULL, N_("by _From"), NULL, NULL, create_filter_from_cb}, | ||
| 275 | {"FilterToAction", NULL, N_("by _To"), NULL, NULL, create_filter_to_cb}, | ||
| 276 | {"FilterSubjectAction", NULL, N_("by _Subject"), NULL, NULL, create_filter_subject_cb}, | ||
| 277 | |||
| 278 | {"OpenAction", GTK_STOCK_OPEN, N_("Open in _new window"), NULL, NULL, open_cb}, | ||
| 279 | {"OpenSourceAction", NULL, N_("View mess_age source"), NULL, NULL, open_source_cb}, | ||
| 280 | |||
| 281 | {"PrintAction", GTK_STOCK_PRINT, N_("_Print..."), NULL, NULL, print_cb}, | ||
| 282 | }; | ||
| 283 | |||
| 284 | |||
| 285 | void query_search(FolderItem *item) | ||
| 286 | { | ||
| 287 | gchar *id; | ||
| 288 | |||
| 289 | if (!search_window.window) | ||
| 290 | query_search_create(); | ||
| 291 | else | ||
| 292 | gtk_window_present(GTK_WINDOW(search_window.window)); | ||
| 293 | |||
| 294 | if (item && item->stype != F_VIRTUAL) { | ||
| 295 | id = folder_item_get_identifier(item); | ||
| 296 | gtk_entry_set_text(GTK_ENTRY(search_window.folder_entry), id); | ||
| 297 | g_free(id); | ||
| 298 | } else | ||
| 299 | gtk_entry_set_text(GTK_ENTRY(search_window.folder_entry), ""); | ||
| 300 | |||
| 301 | gtk_widget_grab_focus(search_window.search_btn); | ||
| 302 | gtk_widget_show(search_window.window); | ||
| 303 | } | ||
| 304 | |||
| 305 | static void query_search_create(void) | ||
| 306 | { | ||
| 307 | GtkWidget *window; | ||
| 308 | GtkWidget *vbox1; | ||
| 309 | GtkWidget *bool_hbox; | ||
| 310 | GtkWidget *bool_optmenu; | ||
| 311 | GtkWidget *bool_menu; | ||
| 312 | GtkWidget *menuitem; | ||
| 313 | GtkWidget *clear_btn; | ||
| 314 | GtkWidget *search_btn; | ||
| 315 | |||
| 316 | GtkWidget *scrolledwin; | ||
| 317 | FilterCondEdit *cond_edit; | ||
| 318 | CondHBox *cond_hbox; | ||
| 319 | |||
| 320 | GtkWidget *folder_hbox; | ||
| 321 | GtkWidget *folder_label; | ||
| 322 | GtkWidget *folder_entry; | ||
| 323 | GtkWidget *folder_btn; | ||
| 324 | |||
| 325 | GtkWidget *checkbtn_hbox; | ||
| 326 | GtkWidget *subfolder_checkbtn; | ||
| 327 | GtkWidget *case_checkbtn; | ||
| 328 | |||
| 329 | GtkWidget *treeview; | ||
| 330 | GtkListStore *store; | ||
| 331 | GtkTreeViewColumn *column; | ||
| 332 | GtkCellRenderer *renderer; | ||
| 333 | GtkTreeSelection *selection; | ||
| 334 | |||
| 335 | GtkWidget *confirm_area; | ||
| 336 | |||
| 337 | GtkWidget *status_label; | ||
| 338 | |||
| 339 | GtkWidget *btn_hbox; | ||
| 340 | GtkWidget *hbbox; | ||
| 341 | GtkWidget *save_btn; | ||
| 342 | GtkWidget *close_btn; | ||
| 343 | |||
| 344 | GtkActionGroup *group; | ||
| 345 | GtkUIManager *ui; | ||
| 346 | |||
| 347 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
| 348 | gtk_window_set_title(GTK_WINDOW (window), _("Search messages")); | ||
| 349 | gtk_widget_set_size_request(window, 600 * gtkut_get_dpi_multiplier(), -1); | ||
| 350 | gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); | ||
| 351 | gtk_container_set_border_width(GTK_CONTAINER (window), 8); | ||
| 352 | g_signal_connect(G_OBJECT(window), "delete_event", | ||
| 353 | G_CALLBACK(query_search_deleted), NULL); | ||
| 354 | g_signal_connect(G_OBJECT(window), "key_press_event", | ||
| 355 | G_CALLBACK(key_pressed), NULL); | ||
| 356 | MANAGE_WINDOW_SIGNALS_CONNECT(window); | ||
| 357 | |||
| 358 | vbox1 = gtk_vbox_new (FALSE, 6); | ||
| 359 | gtk_widget_show (vbox1); | ||
| 360 | gtk_container_add (GTK_CONTAINER (window), vbox1); | ||
| 361 | |||
| 362 | bool_hbox = gtk_hbox_new(FALSE, 12); | ||
| 363 | gtk_widget_show(bool_hbox); | ||
| 364 | gtk_box_pack_start(GTK_BOX(vbox1), bool_hbox, FALSE, FALSE, 0); | ||
| 365 | |||
| 366 | bool_optmenu = gtk_option_menu_new(); | ||
| 367 | gtk_widget_show(bool_optmenu); | ||
| 368 | gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0); | ||
| 369 | |||
| 370 | bool_menu = gtk_menu_new(); | ||
| 371 | MENUITEM_ADD(bool_menu, menuitem, _("Match any of the following"), | ||
| 372 | FLT_OR); | ||
| 373 | MENUITEM_ADD(bool_menu, menuitem, _("Match all of the following"), | ||
| 374 | FLT_AND); | ||
| 375 | gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_optmenu), bool_menu); | ||
| 376 | gtk_option_menu_set_history(GTK_OPTION_MENU(bool_optmenu), FLT_AND); | ||
| 377 | |||
| 378 | hbbox = gtk_hbutton_box_new(); | ||
| 379 | gtk_widget_show(hbbox); | ||
| 380 | gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END); | ||
| 381 | gtk_box_set_spacing(GTK_BOX(hbbox), 6); | ||
| 382 | gtk_box_pack_end(GTK_BOX(bool_hbox), hbbox, FALSE, FALSE, 0); | ||
| 383 | |||
| 384 | clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR); | ||
| 385 | gtk_widget_show(clear_btn); | ||
| 386 | gtk_box_pack_start(GTK_BOX(hbbox), clear_btn, FALSE, FALSE, 0); | ||
| 387 | |||
| 388 | search_btn = gtk_button_new_from_stock(GTK_STOCK_FIND); | ||
| 389 | GTK_WIDGET_SET_FLAGS(search_btn, GTK_CAN_DEFAULT); | ||
| 390 | gtk_widget_show(search_btn); | ||
| 391 | gtk_box_pack_start(GTK_BOX(hbbox), search_btn, FALSE, FALSE, 0); | ||
| 392 | gtk_widget_grab_default(search_btn); | ||
| 393 | |||
| 394 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 395 | gtk_widget_show(scrolledwin); | ||
| 396 | gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, FALSE, FALSE, 0); | ||
| 397 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 398 | GTK_POLICY_AUTOMATIC, | ||
| 399 | GTK_POLICY_AUTOMATIC); | ||
| 400 | gtk_widget_set_size_request(scrolledwin, -1, 120 * gtkut_get_dpi_multiplier()); | ||
| 401 | |||
| 402 | cond_edit = prefs_filter_edit_cond_edit_create(); | ||
| 403 | cond_edit->add_hbox = query_search_hbox_added; | ||
| 404 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 405 | cond_edit->cond_vbox); | ||
| 406 | prefs_filter_set_header_list(NULL); | ||
| 407 | prefs_filter_edit_set_header_list(cond_edit, NULL); | ||
| 408 | cond_hbox = prefs_filter_edit_cond_hbox_create(cond_edit); | ||
| 409 | prefs_filter_edit_set_cond_hbox_widgets(cond_hbox, PF_COND_HEADER); | ||
| 410 | prefs_filter_edit_insert_cond_hbox(cond_edit, cond_hbox, -1); | ||
| 411 | if (cond_edit->add_hbox) | ||
| 412 | cond_edit->add_hbox(cond_hbox); | ||
| 413 | |||
| 414 | folder_hbox = gtk_hbox_new (FALSE, 8); | ||
| 415 | gtk_widget_show (folder_hbox); | ||
| 416 | gtk_box_pack_start (GTK_BOX (vbox1), folder_hbox, FALSE, FALSE, 0); | ||
| 417 | |||
| 418 | folder_label = gtk_label_new (_("Folder:")); | ||
| 419 | gtk_widget_show (folder_label); | ||
| 420 | gtk_box_pack_start (GTK_BOX (folder_hbox), folder_label, | ||
| 421 | FALSE, FALSE, 0); | ||
| 422 | |||
| 423 | folder_entry = gtk_entry_new (); | ||
| 424 | gtk_widget_show (folder_entry); | ||
| 425 | gtk_box_pack_start (GTK_BOX (folder_hbox), folder_entry, TRUE, TRUE, 0); | ||
| 426 | |||
| 427 | folder_btn = gtk_button_new_with_label("..."); | ||
| 428 | gtk_widget_show (folder_btn); | ||
| 429 | gtk_box_pack_start (GTK_BOX (folder_hbox), folder_btn, FALSE, FALSE, 0); | ||
| 430 | |||
| 431 | checkbtn_hbox = gtk_hbox_new (FALSE, 12); | ||
| 432 | gtk_widget_show (checkbtn_hbox); | ||
| 433 | gtk_box_pack_start (GTK_BOX (vbox1), checkbtn_hbox, FALSE, FALSE, 0); | ||
| 434 | |||
| 435 | subfolder_checkbtn = | ||
| 436 | gtk_check_button_new_with_label (_("Search subfolders")); | ||
| 437 | gtk_widget_show (subfolder_checkbtn); | ||
| 438 | gtk_box_pack_start (GTK_BOX (checkbtn_hbox), subfolder_checkbtn, | ||
| 439 | FALSE, FALSE, 0); | ||
| 440 | |||
| 441 | case_checkbtn = gtk_check_button_new_with_label (_("Case sensitive")); | ||
| 442 | gtk_widget_show (case_checkbtn); | ||
| 443 | gtk_box_pack_start (GTK_BOX (checkbtn_hbox), case_checkbtn, | ||
| 444 | FALSE, FALSE, 0); | ||
| 445 | |||
| 446 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 447 | gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, TRUE, TRUE, 0); | ||
| 448 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 449 | GTK_POLICY_AUTOMATIC, | ||
| 450 | GTK_POLICY_AUTOMATIC); | ||
| 451 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 452 | GTK_SHADOW_IN); | ||
| 453 | gtk_widget_set_size_request(scrolledwin, -1, 150 * gtkut_get_dpi_multiplier()); | ||
| 454 | |||
| 455 | store = gtk_list_store_new(N_COLS, | ||
| 456 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | ||
| 457 | G_TYPE_STRING, G_TYPE_POINTER); | ||
| 458 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | ||
| 459 | g_object_unref(store); | ||
| 460 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | ||
| 461 | g_signal_connect(G_OBJECT(treeview), "row-activated", | ||
| 462 | G_CALLBACK(row_activated), NULL); | ||
| 463 | g_signal_connect(G_OBJECT(treeview), "button-press-event", | ||
| 464 | G_CALLBACK(treeview_button_pressed), NULL); | ||
| 465 | |||
| 466 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_FOLDER, | ||
| 467 | query_search_cmp_by_folder, NULL, NULL); | ||
| 468 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_SUBJECT, | ||
| 469 | query_search_cmp_by_subject, | ||
| 470 | NULL, NULL); | ||
| 471 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_FROM, | ||
| 472 | query_search_cmp_by_from, NULL, NULL); | ||
| 473 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_DATE, | ||
| 474 | query_search_cmp_by_date, NULL, NULL); | ||
| 475 | |||
| 476 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
| 477 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); | ||
| 478 | gtk_tree_selection_set_select_function(selection, row_selected, | ||
| 479 | NULL, NULL); | ||
| 480 | |||
| 481 | gtk_container_add(GTK_CONTAINER(scrolledwin), treeview); | ||
| 482 | |||
| 483 | #define APPEND_COLUMN(label, col, width) \ | ||
| 484 | { \ | ||
| 485 | renderer = gtk_cell_renderer_text_new(); \ | ||
| 486 | column = gtk_tree_view_column_new_with_attributes \ | ||
| 487 | (label, renderer, "text", col, NULL); \ | ||
| 488 | gtk_tree_view_column_set_resizable(column, TRUE); \ | ||
| 489 | if (width) { \ | ||
| 490 | gtk_tree_view_column_set_sizing \ | ||
| 491 | (column, GTK_TREE_VIEW_COLUMN_FIXED); \ | ||
| 492 | gtk_tree_view_column_set_fixed_width(column, width); \ | ||
| 493 | } \ | ||
| 494 | gtk_tree_view_column_set_sort_column_id(column, col); \ | ||
| 495 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); \ | ||
| 496 | } | ||
| 497 | |||
| 498 | APPEND_COLUMN(_("Folder"), COL_FOLDER, 0); | ||
| 499 | APPEND_COLUMN(_("Subject"), COL_SUBJECT, 200); | ||
| 500 | #if GTK_CHECK_VERSION(2, 14, 0) | ||
| 501 | gtk_tree_view_column_set_expand(column, TRUE); | ||
| 502 | #endif | ||
| 503 | APPEND_COLUMN(_("From"), COL_FROM, 180); | ||
| 504 | APPEND_COLUMN(_("Date"), COL_DATE, 0); | ||
| 505 | |||
| 506 | gtk_widget_show_all(scrolledwin); | ||
| 507 | |||
| 508 | confirm_area = gtk_hbox_new(FALSE, 12); | ||
| 509 | gtk_widget_show(confirm_area); | ||
| 510 | gtk_box_pack_start(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 0); | ||
| 511 | |||
| 512 | status_label = gtk_label_new(""); | ||
| 513 | gtk_widget_show(status_label); | ||
| 514 | gtk_box_pack_start(GTK_BOX(confirm_area), status_label, | ||
| 515 | FALSE, FALSE, 0); | ||
| 516 | |||
| 517 | btn_hbox = gtk_hbox_new(FALSE, 6); | ||
| 518 | gtk_widget_show(btn_hbox); | ||
| 519 | gtk_box_pack_end(GTK_BOX(confirm_area), btn_hbox, FALSE, FALSE, 0); | ||
| 520 | |||
| 521 | gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE, | ||
| 522 | NULL, NULL, NULL, NULL); | ||
| 523 | gtk_widget_show(hbbox); | ||
| 524 | gtk_box_pack_end(GTK_BOX(btn_hbox), hbbox, FALSE, FALSE, 0); | ||
| 525 | |||
| 526 | save_btn = gtk_button_new_with_mnemonic(_("_Save as search folder")); | ||
| 527 | gtk_widget_show(save_btn); | ||
| 528 | gtk_box_pack_end(GTK_BOX(btn_hbox), save_btn, FALSE, FALSE, 0); | ||
| 529 | |||
| 530 | g_signal_connect(G_OBJECT(clear_btn), "clicked", | ||
| 531 | G_CALLBACK(query_search_clear), NULL); | ||
| 532 | g_signal_connect(G_OBJECT(folder_btn), "clicked", | ||
| 533 | G_CALLBACK(query_select_folder), NULL); | ||
| 534 | g_signal_connect(G_OBJECT(search_btn), "clicked", | ||
| 535 | G_CALLBACK(query_search_clicked), NULL); | ||
| 536 | g_signal_connect(G_OBJECT(save_btn), "clicked", | ||
| 537 | G_CALLBACK(query_search_save), NULL); | ||
| 538 | g_signal_connect(G_OBJECT(close_btn), "clicked", | ||
| 539 | G_CALLBACK(query_search_close), NULL); | ||
| 540 | |||
| 541 | group = gtk_action_group_new("main"); | ||
| 542 | gtk_action_group_set_translation_domain(group, GETTEXT_PACKAGE); | ||
| 543 | gtk_action_group_add_actions(group, action_entries, | ||
| 544 | sizeof(action_entries) / | ||
| 545 | sizeof(action_entries[0]), NULL); | ||
| 546 | |||
| 547 | ui = gtk_ui_manager_new(); | ||
| 548 | gtk_ui_manager_insert_action_group(ui, group, 0); | ||
| 549 | gtk_ui_manager_add_ui_from_string(ui, ui_def, -1, NULL); | ||
| 550 | |||
| 551 | search_window.window = window; | ||
| 552 | search_window.bool_optmenu = bool_optmenu; | ||
| 553 | |||
| 554 | search_window.cond_edit = cond_edit; | ||
| 555 | |||
| 556 | search_window.folder_entry = folder_entry; | ||
| 557 | search_window.folder_btn = folder_btn; | ||
| 558 | search_window.subfolder_checkbtn = subfolder_checkbtn; | ||
| 559 | search_window.case_checkbtn = case_checkbtn; | ||
| 560 | |||
| 561 | search_window.treeview = treeview; | ||
| 562 | search_window.store = store; | ||
| 563 | |||
| 564 | search_window.status_label = status_label; | ||
| 565 | |||
| 566 | search_window.clear_btn = clear_btn; | ||
| 567 | search_window.search_btn = search_btn; | ||
| 568 | search_window.save_btn = save_btn; | ||
| 569 | search_window.close_btn = close_btn; | ||
| 570 | |||
| 571 | search_window.group = group; | ||
| 572 | search_window.ui = ui; | ||
| 573 | } | ||
| 574 | |||
| 575 | static FilterRule *query_search_dialog_to_rule(const gchar *name, | ||
| 576 | FolderItem **item) | ||
| 577 | { | ||
| 578 | const gchar *id; | ||
| 579 | FolderItem *item_; | ||
| 580 | FilterBoolOp bool_op; | ||
| 581 | gboolean recursive; | ||
| 582 | gboolean case_sens; | ||
| 583 | GSList *cond_list; | ||
| 584 | FilterRule *rule; | ||
| 585 | |||
| 586 | id = gtk_entry_get_text(GTK_ENTRY(search_window.folder_entry)); | ||
| 587 | item_ = folder_find_item_from_identifier(id); | ||
| 588 | if (!item_) | ||
| 589 | return NULL; | ||
| 590 | if (item) | ||
| 591 | *item = item_; | ||
| 592 | |||
| 593 | bool_op = menu_get_option_menu_active_index | ||
| 594 | (GTK_OPTION_MENU(search_window.bool_optmenu)); | ||
| 595 | recursive = gtk_toggle_button_get_active | ||
| 596 | (GTK_TOGGLE_BUTTON(search_window.subfolder_checkbtn)); | ||
| 597 | case_sens = gtk_toggle_button_get_active | ||
| 598 | (GTK_TOGGLE_BUTTON(search_window.case_checkbtn)); | ||
| 599 | |||
| 600 | cond_list = prefs_filter_edit_cond_edit_to_list(search_window.cond_edit, | ||
| 601 | case_sens); | ||
| 602 | if (!cond_list) | ||
| 603 | return NULL; | ||
| 604 | |||
| 605 | rule = filter_rule_new(name, bool_op, cond_list, NULL); | ||
| 606 | rule->target_folder = g_strdup(id); | ||
| 607 | rule->recursive = recursive; | ||
| 608 | |||
| 609 | return rule; | ||
| 610 | } | ||
| 611 | |||
| 612 | static void query_search_query(void) | ||
| 613 | { | ||
| 614 | FolderItem *item; | ||
| 615 | gchar *msg; | ||
| 616 | |||
| 617 | if (search_window.on_search) | ||
| 618 | return; | ||
| 619 | |||
| 620 | search_window.on_search = TRUE; | ||
| 621 | |||
| 622 | search_window.rule = query_search_dialog_to_rule("Query rule", &item); | ||
| 623 | if (!search_window.rule) { | ||
| 624 | search_window.on_search = FALSE; | ||
| 625 | return; | ||
| 626 | } | ||
| 627 | search_window.requires_full_headers = | ||
| 628 | filter_rule_requires_full_headers(search_window.rule); | ||
| 629 | |||
| 630 | if (search_window.rule->recursive) { | ||
| 631 | if (item->stype == F_TRASH) | ||
| 632 | search_window.exclude_trash = FALSE; | ||
| 633 | else | ||
| 634 | search_window.exclude_trash = TRUE; | ||
| 635 | } else | ||
| 636 | search_window.exclude_trash = FALSE; | ||
| 637 | |||
| 638 | search_window.n_found = 0; | ||
| 639 | search_window.cancelled = FALSE; | ||
| 640 | |||
| 641 | gtk_widget_set_sensitive(search_window.clear_btn, FALSE); | ||
| 642 | gtk_button_set_label(GTK_BUTTON(search_window.search_btn), | ||
| 643 | GTK_STOCK_STOP); | ||
| 644 | query_search_clear_list(); | ||
| 645 | |||
| 646 | if (search_window.rule->recursive) | ||
| 647 | g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, | ||
| 648 | query_search_recursive_func, NULL); | ||
| 649 | else | ||
| 650 | query_search_folder(item); | ||
| 651 | |||
| 652 | filter_rule_free(search_window.rule); | ||
| 653 | search_window.rule = NULL; | ||
| 654 | search_window.requires_full_headers = FALSE; | ||
| 655 | search_window.exclude_trash = FALSE; | ||
| 656 | |||
| 657 | gtk_widget_set_sensitive(search_window.clear_btn, TRUE); | ||
| 658 | gtk_button_set_label(GTK_BUTTON(search_window.search_btn), | ||
| 659 | GTK_STOCK_FIND); | ||
| 660 | if (search_window.n_found == 0) | ||
| 661 | msg = g_strdup_printf(_("Message not found.")); | ||
| 662 | else if (search_window.n_found == 1) | ||
| 663 | msg = g_strdup_printf(_("1 message found.")); | ||
| 664 | else | ||
| 665 | msg = g_strdup_printf(_("%d messages found."), | ||
| 666 | search_window.n_found); | ||
| 667 | gtk_label_set_text(GTK_LABEL(search_window.status_label), msg); | ||
| 668 | g_free(msg); | ||
| 669 | statusbar_pop_all(); | ||
| 670 | |||
| 671 | if (search_window.cancelled) | ||
| 672 | debug_print("* query search cancelled.\n"); | ||
| 673 | debug_print("query search finished.\n"); | ||
| 674 | |||
| 675 | search_window.n_found = 0; | ||
| 676 | search_window.on_search = FALSE; | ||
| 677 | search_window.cancelled = FALSE; | ||
| 678 | } | ||
| 679 | |||
| 680 | typedef struct _QueryData | ||
| 681 | { | ||
| 682 | FolderItem *item; | ||
| 683 | gchar *folder_name; | ||
| 684 | gint count; | ||
| 685 | gint total; | ||
| 686 | gint flag; | ||
| 687 | GTimeVal tv_prev; | ||
| 688 | GSList *mlist; | ||
| 689 | #if USE_THREADS | ||
| 690 | GAsyncQueue *queue; | ||
| 691 | guint timer_tag; | ||
| 692 | #endif | ||
| 693 | } QueryData; | ||
| 694 | |||
| 695 | static void query_search_folder_show_progress(const gchar *name, gint count, | ||
| 696 | gint total) | ||
| 697 | { | ||
| 698 | gchar *str; | ||
| 699 | |||
| 700 | str = g_strdup_printf(_("Searching %s (%d / %d)..."), | ||
| 701 | name, count, total); | ||
| 702 | gtk_label_set_text(GTK_LABEL(search_window.status_label), str); | ||
| 703 | g_free(str); | ||
| 704 | #ifndef USE_THREADS | ||
| 705 | ui_update(); | ||
| 706 | #endif | ||
| 707 | } | ||
| 708 | |||
| 709 | #if USE_THREADS | ||
| 710 | static gboolean query_search_progress_func(gpointer data) | ||
| 711 | { | ||
| 712 | QueryData *qdata = (QueryData *)data; | ||
| 713 | MsgInfo *msginfo; | ||
| 714 | |||
| 715 | gdk_threads_enter(); | ||
| 716 | query_search_folder_show_progress(qdata->folder_name, | ||
| 717 | g_atomic_int_get(&qdata->count), | ||
| 718 | qdata->total); | ||
| 719 | while ((msginfo = g_async_queue_try_pop(qdata->queue))) | ||
| 720 | query_search_append_msg(msginfo); | ||
| 721 | gdk_threads_leave(); | ||
| 722 | |||
| 723 | return TRUE; | ||
| 724 | } | ||
| 725 | #endif | ||
| 726 | |||
| 727 | static gpointer query_search_folder_func(gpointer data) | ||
| 728 | { | ||
| 729 | QueryData *qdata = (QueryData *)data; | ||
| 730 | GSList *mlist, *cur; | ||
| 731 | FilterInfo fltinfo; | ||
| 732 | GTimeVal tv_cur; | ||
| 733 | |||
| 734 | debug_print("query_search_folder_func start\n"); | ||
| 735 | |||
| 736 | #if USE_THREADS | ||
| 737 | g_async_queue_ref(qdata->queue); | ||
| 738 | #endif | ||
| 739 | |||
| 740 | mlist = qdata->mlist; | ||
| 741 | |||
| 742 | memset(&fltinfo, 0, sizeof(FilterInfo)); | ||
| 743 | |||
| 744 | debug_print("requires_full_headers: %d\n", | ||
| 745 | search_window.requires_full_headers); | ||
| 746 | debug_print("start query search: %s\n", | ||
| 747 | qdata->item->path ? qdata->item->path : ""); | ||
| 748 | |||
| 749 | for (cur = mlist; cur != NULL; cur = cur->next) { | ||
| 750 | MsgInfo *msginfo = (MsgInfo *)cur->data; | ||
| 751 | GSList *hlist; | ||
| 752 | |||
| 753 | g_atomic_int_add(&qdata->count, 1); | ||
| 754 | |||
| 755 | g_get_current_time(&tv_cur); | ||
| 756 | if ((tv_cur.tv_sec - qdata->tv_prev.tv_sec) * G_USEC_PER_SEC + | ||
| 757 | tv_cur.tv_usec - qdata->tv_prev.tv_usec > | ||
| 758 | PROGRESS_UPDATE_INTERVAL * 1000) { | ||
| 759 | #ifndef USE_THREADS | ||
| 760 | query_search_folder_show_progress(qdata->folder_name, | ||
| 761 | qdata->count, | ||
| 762 | qdata->total); | ||
| 763 | #endif | ||
| 764 | qdata->tv_prev = tv_cur; | ||
| 765 | } | ||
| 766 | |||
| 767 | if (search_window.cancelled) | ||
| 768 | break; | ||
| 769 | |||
| 770 | fltinfo.flags = msginfo->flags; | ||
| 771 | if (search_window.requires_full_headers) { | ||
| 772 | gchar *file; | ||
| 773 | |||
| 774 | file = procmsg_get_message_file(msginfo); | ||
| 775 | hlist = procheader_get_header_list_from_file(file); | ||
| 776 | g_free(file); | ||
| 777 | } else | ||
| 778 | hlist = procheader_get_header_list_from_msginfo | ||
| 779 | (msginfo); | ||
| 780 | if (!hlist) | ||
| 781 | continue; | ||
| 782 | |||
| 783 | if (filter_match_rule(search_window.rule, msginfo, hlist, | ||
| 784 | &fltinfo)) { | ||
| 785 | #if USE_THREADS | ||
| 786 | g_async_queue_push(qdata->queue, msginfo); | ||
| 787 | #else | ||
| 788 | query_search_append_msg(msginfo); | ||
| 789 | #endif | ||
| 790 | cur->data = NULL; | ||
| 791 | search_window.n_found++; | ||
| 792 | } | ||
| 793 | |||
| 794 | procheader_header_list_destroy(hlist); | ||
| 795 | } | ||
| 796 | |||
| 797 | #if USE_THREADS | ||
| 798 | g_async_queue_unref(qdata->queue); | ||
| 799 | #endif | ||
| 800 | |||
| 801 | g_atomic_int_set(&qdata->flag, 1); | ||
| 802 | g_main_context_wakeup(NULL); | ||
| 803 | |||
| 804 | debug_print("query_search_folder_func end\n"); | ||
| 805 | |||
| 806 | return GINT_TO_POINTER(0); | ||
| 807 | } | ||
| 808 | |||
| 809 | static void query_search_folder(FolderItem *item) | ||
| 810 | { | ||
| 811 | gchar *str; | ||
| 812 | QueryData data = {item}; | ||
| 813 | #if USE_THREADS | ||
| 814 | GThread *thread; | ||
| 815 | MsgInfo *msginfo; | ||
| 816 | #endif | ||
| 817 | |||
| 818 | if (!item->path || item->stype == F_VIRTUAL) | ||
| 819 | return; | ||
| 820 | |||
| 821 | data.folder_name = g_path_get_basename(item->path); | ||
| 822 | str = g_strdup_printf(_("Searching %s ..."), data.folder_name); | ||
| 823 | gtk_label_set_text(GTK_LABEL(search_window.status_label), str); | ||
| 824 | g_free(str); | ||
| 825 | g_get_current_time(&data.tv_prev); | ||
| 826 | #ifndef USE_THREADS | ||
| 827 | ui_update(); | ||
| 828 | #endif | ||
| 829 | |||
| 830 | if (search_window.cancelled) { | ||
| 831 | g_free(data.folder_name); | ||
| 832 | return; | ||
| 833 | } | ||
| 834 | |||
| 835 | if (item->opened) | ||
| 836 | summary_write_cache(main_window_get()->summaryview); | ||
| 837 | |||
| 838 | procmsg_set_auto_decrypt_message(FALSE); | ||
| 839 | |||
| 840 | data.mlist = folder_item_get_msg_list(item, TRUE); | ||
| 841 | data.total = g_slist_length(data.mlist); | ||
| 842 | |||
| 843 | #if USE_THREADS | ||
| 844 | data.queue = g_async_queue_new(); | ||
| 845 | data.timer_tag = g_timeout_add(PROGRESS_UPDATE_INTERVAL, | ||
| 846 | query_search_progress_func, &data); | ||
| 847 | thread = g_thread_create(query_search_folder_func, &data, TRUE, NULL); | ||
| 848 | |||
| 849 | debug_print("query_search_folder: thread started\n"); | ||
| 850 | while (g_atomic_int_get(&data.flag) == 0) | ||
| 851 | gtk_main_iteration(); | ||
| 852 | log_window_flush(); | ||
| 853 | |||
| 854 | while ((msginfo = g_async_queue_try_pop(data.queue))) | ||
| 855 | query_search_append_msg(msginfo); | ||
| 856 | |||
| 857 | g_source_remove(data.timer_tag); | ||
| 858 | g_thread_join(thread); | ||
| 859 | debug_print("query_search_folder: thread exited\n"); | ||
| 860 | |||
| 861 | g_async_queue_unref(data.queue); | ||
| 862 | #else /* !USE_THREADS */ | ||
| 863 | query_search_folder_func(&data); | ||
| 864 | #endif | ||
| 865 | |||
| 866 | procmsg_msg_list_free(data.mlist); | ||
| 867 | procmsg_set_auto_decrypt_message(TRUE); | ||
| 868 | g_free(data.folder_name); | ||
| 869 | } | ||
| 870 | |||
| 871 | static gboolean query_search_recursive_func(GNode *node, gpointer data) | ||
| 872 | { | ||
| 873 | FolderItem *item; | ||
| 874 | |||
| 875 | g_return_val_if_fail(node->data != NULL, FALSE); | ||
| 876 | |||
| 877 | item = FOLDER_ITEM(node->data); | ||
| 878 | |||
| 879 | if (!item->path) | ||
| 880 | return FALSE; | ||
| 881 | if (search_window.exclude_trash && item->stype == F_TRASH) | ||
| 882 | return FALSE; | ||
| 883 | |||
| 884 | query_search_folder(item); | ||
| 885 | |||
| 886 | if (search_window.cancelled) | ||
| 887 | return TRUE; | ||
| 888 | |||
| 889 | return FALSE; | ||
| 890 | } | ||
| 891 | |||
| 892 | static void query_search_append_msg(MsgInfo *msginfo) | ||
| 893 | { | ||
| 894 | GtkListStore *store = search_window.store; | ||
| 895 | GtkTreeIter iter; | ||
| 896 | gchar *folder; | ||
| 897 | gchar date_buf[80]; | ||
| 898 | const gchar *subject, *from, *date; | ||
| 899 | gchar *id; | ||
| 900 | |||
| 901 | id = folder_item_get_identifier(msginfo->folder); | ||
| 902 | folder = g_path_get_basename(id); | ||
| 903 | g_free(id); | ||
| 904 | subject = msginfo->subject ? msginfo->subject : _("(No Subject)"); | ||
| 905 | from = msginfo->from ? msginfo->from : _("(No From)"); | ||
| 906 | if (msginfo->date_t) { | ||
| 907 | procheader_date_get_localtime(date_buf, sizeof(date_buf), | ||
| 908 | msginfo->date_t); | ||
| 909 | date = date_buf; | ||
| 910 | } else if (msginfo->date) | ||
| 911 | date = msginfo->date; | ||
| 912 | else | ||
| 913 | date = _("(No Date)"); | ||
| 914 | |||
| 915 | gtk_list_store_append(store, &iter); | ||
| 916 | gtk_list_store_set(store, &iter, | ||
| 917 | COL_FOLDER, folder, | ||
| 918 | COL_SUBJECT, subject, | ||
| 919 | COL_FROM, from, | ||
| 920 | COL_DATE, date, | ||
| 921 | COL_MSGINFO, msginfo, | ||
| 922 | -1); | ||
| 923 | |||
| 924 | g_free(folder); | ||
| 925 | } | ||
| 926 | |||
| 927 | static void query_search_clear_list(void) | ||
| 928 | { | ||
| 929 | GtkTreeIter iter; | ||
| 930 | GtkTreeModel *model = GTK_TREE_MODEL(search_window.store); | ||
| 931 | MsgInfo *msginfo; | ||
| 932 | |||
| 933 | gtkut_tree_sortable_unset_sort_column_id | ||
| 934 | (GTK_TREE_SORTABLE(search_window.store)); | ||
| 935 | |||
| 936 | if (!gtk_tree_model_get_iter_first(model, &iter)) | ||
| 937 | return; | ||
| 938 | |||
| 939 | do { | ||
| 940 | gtk_tree_model_get(model, &iter, COL_MSGINFO, &msginfo, -1); | ||
| 941 | procmsg_msginfo_free(msginfo); | ||
| 942 | } while (gtk_tree_model_iter_next(model, &iter)); | ||
| 943 | |||
| 944 | gtk_list_store_clear(search_window.store); | ||
| 945 | } | ||
| 946 | |||
| 947 | static void query_search_hbox_added(CondHBox *hbox) | ||
| 948 | { | ||
| 949 | g_signal_connect(hbox->key_entry, "activate", | ||
| 950 | G_CALLBACK(query_search_entry_activated), NULL); | ||
| 951 | } | ||
| 952 | |||
| 953 | static void row_activated(GtkTreeView *treeview, GtkTreePath *path, | ||
| 954 | GtkTreeViewColumn *column, gpointer data) | ||
| 955 | { | ||
| 956 | query_search_open_msg(FALSE); | ||
| 957 | } | ||
| 958 | |||
| 959 | static gboolean row_selected(GtkTreeSelection *selection, | ||
| 960 | GtkTreeModel *model, GtkTreePath *path, | ||
| 961 | gboolean cur_selected, gpointer data) | ||
| 962 | { | ||
| 963 | return TRUE; | ||
| 964 | } | ||
| 965 | |||
| 966 | static gboolean treeview_button_pressed(GtkWidget *widget, | ||
| 967 | GdkEventButton *event, gpointer data) | ||
| 968 | { | ||
| 969 | GtkTreeIter iter; | ||
| 970 | GtkTreeModel *model = GTK_TREE_MODEL(search_window.store); | ||
| 971 | GtkWidget *menu; | ||
| 972 | GtkTreeSelection *selection; | ||
| 973 | GtkTreePath *path; | ||
| 974 | GtkTreeViewColumn *column = NULL; | ||
| 975 | gboolean is_selected; | ||
| 976 | gint px, py; | ||
| 977 | |||
| 978 | debug_print("treeview_button_pressed\n"); | ||
| 979 | |||
| 980 | if (!event) | ||
| 981 | return FALSE; | ||
| 982 | |||
| 983 | if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), | ||
| 984 | event->x, event->y, &path, &column, | ||
| 985 | NULL, NULL)) | ||
| 986 | return FALSE; | ||
| 987 | |||
| 988 | // ?? | ||
| 989 | gtk_widget_get_pointer(widget, &px, &py); | ||
| 990 | if (py == (gint)event->y) { | ||
| 991 | gtk_tree_path_free(path); | ||
| 992 | return FALSE; | ||
| 993 | } | ||
| 994 | |||
| 995 | if (!gtk_tree_model_get_iter(model, &iter, path)) { | ||
| 996 | gtk_tree_path_free(path); | ||
| 997 | return FALSE; | ||
| 998 | } | ||
| 999 | |||
| 1000 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | ||
| 1001 | is_selected = gtk_tree_selection_path_is_selected(selection, path); | ||
| 1002 | gtk_tree_path_free(path); | ||
| 1003 | |||
| 1004 | if (event->button == 3) { | ||
| 1005 | menu = gtk_ui_manager_get_widget(search_window.ui, | ||
| 1006 | "/PopUpMenu"); | ||
| 1007 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | ||
| 1008 | event->button, event->time); | ||
| 1009 | if (is_selected) | ||
| 1010 | return TRUE; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | return FALSE; | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | static void query_search_clear(GtkButton *button, gpointer data) | ||
| 1017 | { | ||
| 1018 | CondHBox *cond_hbox; | ||
| 1019 | |||
| 1020 | if (search_window.on_search) | ||
| 1021 | return; | ||
| 1022 | |||
| 1023 | prefs_filter_edit_clear_cond_edit(search_window.cond_edit); | ||
| 1024 | prefs_filter_set_header_list(NULL); | ||
| 1025 | prefs_filter_edit_set_header_list(search_window.cond_edit, NULL); | ||
| 1026 | cond_hbox = prefs_filter_edit_cond_hbox_create(search_window.cond_edit); | ||
| 1027 | prefs_filter_edit_set_cond_hbox_widgets(cond_hbox, PF_COND_HEADER); | ||
| 1028 | prefs_filter_edit_insert_cond_hbox | ||
| 1029 | (search_window.cond_edit, cond_hbox, -1); | ||
| 1030 | if (search_window.cond_edit->add_hbox) | ||
| 1031 | search_window.cond_edit->add_hbox(cond_hbox); | ||
| 1032 | |||
| 1033 | gtk_label_set_text(GTK_LABEL(search_window.status_label), ""); | ||
| 1034 | |||
| 1035 | query_search_clear_list(); | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | static void query_select_folder(GtkButton *button, gpointer data) | ||
| 1039 | { | ||
| 1040 | FolderItem *item; | ||
| 1041 | gchar *id; | ||
| 1042 | |||
| 1043 | item = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL); | ||
| 1044 | if (!item || item->stype == F_VIRTUAL) | ||
| 1045 | return; | ||
| 1046 | |||
| 1047 | id = folder_item_get_identifier(item); | ||
| 1048 | if (id) { | ||
| 1049 | gtk_entry_set_text(GTK_ENTRY(search_window.folder_entry), id); | ||
| 1050 | g_free(id); | ||
| 1051 | } | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | static void query_search_clicked(GtkButton *button, gpointer data) | ||
| 1055 | { | ||
| 1056 | if (search_window.on_search) | ||
| 1057 | search_window.cancelled = TRUE; | ||
| 1058 | else | ||
| 1059 | query_search_query(); | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | static gint query_search_save_dialog_deleted(GtkWidget *widget, | ||
| 1063 | GdkEventAny *event, gpointer data) | ||
| 1064 | { | ||
| 1065 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1066 | |||
| 1067 | dialog->cancelled = TRUE; | ||
| 1068 | dialog->finished = TRUE; | ||
| 1069 | return TRUE; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | static gint query_search_save_dialog_key_pressed(GtkWidget *widget, | ||
| 1073 | GdkEventKey *event, | ||
| 1074 | gpointer data) | ||
| 1075 | { | ||
| 1076 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1077 | |||
| 1078 | if (event && event->keyval == GDK_Escape) { | ||
| 1079 | dialog->cancelled = TRUE; | ||
| 1080 | dialog->finished = TRUE; | ||
| 1081 | } | ||
| 1082 | return FALSE; | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | static void query_search_save_dialog_select_folder(GtkButton *button, | ||
| 1086 | gpointer data) | ||
| 1087 | { | ||
| 1088 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1089 | FolderItem *item; | ||
| 1090 | gchar *id; | ||
| 1091 | |||
| 1092 | item = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL); | ||
| 1093 | if (!item || item->no_sub || item->stype == F_VIRTUAL) | ||
| 1094 | return; | ||
| 1095 | |||
| 1096 | id = folder_item_get_identifier(item); | ||
| 1097 | if (id) { | ||
| 1098 | gtk_entry_set_text(GTK_ENTRY(dialog->folder_entry), id); | ||
| 1099 | g_free(id); | ||
| 1100 | } | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | static void query_search_save_activated(GtkEditable *editable, gpointer data) | ||
| 1104 | { | ||
| 1105 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1106 | |||
| 1107 | gtk_button_clicked(GTK_BUTTON(dialog->ok_btn)); | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | static void query_search_save_ok(GtkButton *button, gpointer data) | ||
| 1111 | { | ||
| 1112 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1113 | |||
| 1114 | dialog->finished = TRUE; | ||
| 1115 | } | ||
| 1116 | |||
| 1117 | static void query_search_save_cancel(GtkButton *button, gpointer data) | ||
| 1118 | { | ||
| 1119 | QuerySearchSaveDialog *dialog = (QuerySearchSaveDialog *)data; | ||
| 1120 | |||
| 1121 | dialog->cancelled = TRUE; | ||
| 1122 | dialog->finished = TRUE; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | static QuerySearchSaveDialog *query_search_save_dialog_create(void) | ||
| 1126 | { | ||
| 1127 | QuerySearchSaveDialog *dialog; | ||
| 1128 | GtkWidget *window; | ||
| 1129 | GtkWidget *vbox; | ||
| 1130 | GtkWidget *hbox; | ||
| 1131 | GtkWidget *label; | ||
| 1132 | GtkWidget *folder_entry; | ||
| 1133 | GtkWidget *folder_btn; | ||
| 1134 | GtkWidget *name_entry; | ||
| 1135 | |||
| 1136 | GtkWidget *confirm_area; | ||
| 1137 | GtkWidget *hbbox; | ||
| 1138 | GtkWidget *cancel_btn; | ||
| 1139 | GtkWidget *ok_btn; | ||
| 1140 | |||
| 1141 | dialog = g_new0(QuerySearchSaveDialog, 1); | ||
| 1142 | |||
| 1143 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
| 1144 | gtk_window_set_title(GTK_WINDOW(window), _("Save as search folder")); | ||
| 1145 | gtk_widget_set_size_request(window, 400 * gtkut_get_dpi_multiplier(), -1); | ||
| 1146 | gtk_container_set_border_width(GTK_CONTAINER(window), 8); | ||
| 1147 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | ||
| 1148 | gtk_window_set_modal(GTK_WINDOW(window), TRUE); | ||
| 1149 | gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE); | ||
| 1150 | g_signal_connect(G_OBJECT(window), "delete_event", | ||
| 1151 | G_CALLBACK(query_search_save_dialog_deleted), | ||
| 1152 | dialog); | ||
| 1153 | g_signal_connect(G_OBJECT(window), "key_press_event", | ||
| 1154 | G_CALLBACK(query_search_save_dialog_key_pressed), | ||
| 1155 | dialog); | ||
| 1156 | MANAGE_WINDOW_SIGNALS_CONNECT(window); | ||
| 1157 | manage_window_set_transient(GTK_WINDOW(window)); | ||
| 1158 | |||
| 1159 | vbox = gtk_vbox_new(FALSE, 8); | ||
| 1160 | gtk_container_add(GTK_CONTAINER(window), vbox); | ||
| 1161 | |||
| 1162 | hbox = gtk_hbox_new(FALSE, 8); | ||
| 1163 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | ||
| 1164 | |||
| 1165 | label = gtk_label_new(_("Location:")); | ||
| 1166 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | ||
| 1167 | |||
| 1168 | folder_entry = gtk_entry_new(); | ||
| 1169 | gtk_box_pack_start(GTK_BOX(hbox), folder_entry, TRUE, TRUE, 0); | ||
| 1170 | |||
| 1171 | folder_btn = gtk_button_new_with_label("..."); | ||
| 1172 | gtk_box_pack_start(GTK_BOX(hbox), folder_btn, FALSE, FALSE, 0); | ||
| 1173 | g_signal_connect(G_OBJECT(folder_btn), "clicked", | ||
| 1174 | G_CALLBACK(query_search_save_dialog_select_folder), | ||
| 1175 | dialog); | ||
| 1176 | |||
| 1177 | hbox = gtk_hbox_new(FALSE, 8); | ||
| 1178 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | ||
| 1179 | |||
| 1180 | label = gtk_label_new(_("Folder name:")); | ||
| 1181 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | ||
| 1182 | |||
| 1183 | name_entry = gtk_entry_new(); | ||
| 1184 | gtk_box_pack_start(GTK_BOX(hbox), name_entry, TRUE, TRUE, 0); | ||
| 1185 | g_signal_connect(G_OBJECT(name_entry), "activate", | ||
| 1186 | G_CALLBACK(query_search_save_activated), dialog); | ||
| 1187 | |||
| 1188 | confirm_area = gtk_hbox_new(FALSE, 12); | ||
| 1189 | gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0); | ||
| 1190 | |||
| 1191 | gtkut_stock_button_set_create(&hbbox, | ||
| 1192 | &ok_btn, GTK_STOCK_OK, | ||
| 1193 | &cancel_btn, GTK_STOCK_CANCEL, | ||
| 1194 | NULL, NULL); | ||
| 1195 | gtk_box_pack_end(GTK_BOX(confirm_area), hbbox, FALSE, FALSE, 0); | ||
| 1196 | GTK_WIDGET_SET_FLAGS(ok_btn, GTK_CAN_DEFAULT); | ||
| 1197 | gtk_widget_grab_default(ok_btn); | ||
| 1198 | g_signal_connect(G_OBJECT(ok_btn), "clicked", | ||
| 1199 | G_CALLBACK(query_search_save_ok), dialog); | ||
| 1200 | g_signal_connect(G_OBJECT(cancel_btn), "clicked", | ||
| 1201 | G_CALLBACK(query_search_save_cancel), dialog); | ||
| 1202 | |||
| 1203 | gtk_widget_grab_focus(name_entry); | ||
| 1204 | |||
| 1205 | gtk_widget_show_all(window); | ||
| 1206 | |||
| 1207 | dialog->window = window; | ||
| 1208 | dialog->folder_entry = folder_entry; | ||
| 1209 | dialog->name_entry = name_entry; | ||
| 1210 | dialog->ok_btn = ok_btn; | ||
| 1211 | dialog->cancel_btn = cancel_btn; | ||
| 1212 | dialog->cancelled = FALSE; | ||
| 1213 | dialog->finished = FALSE; | ||
| 1214 | |||
| 1215 | return dialog; | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | static void query_search_save_dialog_destroy(QuerySearchSaveDialog *dialog) | ||
| 1219 | { | ||
| 1220 | gtk_widget_destroy(dialog->window); | ||
| 1221 | g_free(dialog); | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | static FolderItem *query_search_create_vfolder(FolderItem *parent, | ||
| 1225 | const gchar *name) | ||
| 1226 | { | ||
| 1227 | gchar *path; | ||
| 1228 | gchar *fs_name; | ||
| 1229 | gchar *fullpath; | ||
| 1230 | FolderItem *item; | ||
| 1231 | |||
| 1232 | g_return_val_if_fail(parent != NULL, NULL); | ||
| 1233 | g_return_val_if_fail(name != NULL, NULL); | ||
| 1234 | |||
| 1235 | path = folder_item_get_path(parent); | ||
| 1236 | fs_name = g_filename_from_utf8(name, -1, NULL, NULL, NULL); | ||
| 1237 | fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, | ||
| 1238 | fs_name ? fs_name : name, NULL); | ||
| 1239 | g_free(fs_name); | ||
| 1240 | g_free(path); | ||
| 1241 | |||
| 1242 | if (make_dir_hier(fullpath) < 0) { | ||
| 1243 | g_free(fullpath); | ||
| 1244 | return NULL; | ||
| 1245 | } | ||
| 1246 | |||
| 1247 | if (parent->path) | ||
| 1248 | path = g_strconcat(parent->path, "/", name, NULL); | ||
| 1249 | else | ||
| 1250 | path = g_strdup(name); | ||
| 1251 | |||
| 1252 | item = folder_item_new(name, path); | ||
| 1253 | item->stype = F_VIRTUAL; | ||
| 1254 | item->no_sub = TRUE; | ||
| 1255 | folder_item_append(parent, item); | ||
| 1256 | |||
| 1257 | g_free(path); | ||
| 1258 | |||
| 1259 | return item; | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | static void query_search_vfolder_update_rule(FolderItem *item) | ||
| 1263 | { | ||
| 1264 | GSList list; | ||
| 1265 | FilterRule *rule; | ||
| 1266 | gchar *file; | ||
| 1267 | gchar *path; | ||
| 1268 | |||
| 1269 | rule = query_search_dialog_to_rule(item->name, NULL); | ||
| 1270 | list.data = rule; | ||
| 1271 | list.next = NULL; | ||
| 1272 | |||
| 1273 | path = folder_item_get_path(item); | ||
| 1274 | file = g_strconcat(path, G_DIR_SEPARATOR_S, FILTER_LIST, NULL); | ||
| 1275 | filter_write_file(&list, file); | ||
| 1276 | g_free(file); | ||
| 1277 | g_free(path); | ||
| 1278 | |||
| 1279 | filter_rule_free(rule); | ||
| 1280 | } | ||
| 1281 | |||
| 1282 | static void query_search_save(GtkButton *button, gpointer data) | ||
| 1283 | { | ||
| 1284 | QuerySearchSaveDialog *dialog; | ||
| 1285 | const gchar *id, *name; | ||
| 1286 | FolderItem *parent, *item; | ||
| 1287 | |||
| 1288 | dialog = query_search_save_dialog_create(); | ||
| 1289 | id = gtk_entry_get_text(GTK_ENTRY(search_window.folder_entry)); | ||
| 1290 | if (id && *id) | ||
| 1291 | gtk_entry_set_text(GTK_ENTRY(dialog->folder_entry), id); | ||
| 1292 | |||
| 1293 | while (!dialog->finished) | ||
| 1294 | gtk_main_iteration(); | ||
| 1295 | |||
| 1296 | if (dialog->cancelled) { | ||
| 1297 | query_search_save_dialog_destroy(dialog); | ||
| 1298 | return; | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | id = gtk_entry_get_text(GTK_ENTRY(dialog->folder_entry)); | ||
| 1302 | parent = folder_find_item_from_identifier(id); | ||
| 1303 | name = gtk_entry_get_text(GTK_ENTRY(dialog->name_entry)); | ||
| 1304 | if (parent && name && *name) { | ||
| 1305 | if (folder_find_child_item_by_name(parent, name)) { | ||
| 1306 | alertpanel_error(_("The folder `%s' already exists."), | ||
| 1307 | name); | ||
| 1308 | } else { | ||
| 1309 | item = query_search_create_vfolder(parent, name); | ||
| 1310 | if (item) { | ||
| 1311 | query_search_vfolder_update_rule(item); | ||
| 1312 | folderview_append_item(folderview_get(), | ||
| 1313 | NULL, item, TRUE); | ||
| 1314 | folder_write_list(); | ||
| 1315 | } | ||
| 1316 | } | ||
| 1317 | } | ||
| 1318 | |||
| 1319 | query_search_save_dialog_destroy(dialog); | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | static void query_search_close(GtkButton *button, gpointer data) | ||
| 1323 | { | ||
| 1324 | if (search_window.on_search) | ||
| 1325 | search_window.cancelled = TRUE; | ||
| 1326 | gtk_widget_hide(search_window.window); | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | static void query_search_entry_activated(GtkWidget *widget, gpointer data) | ||
| 1330 | { | ||
| 1331 | gtk_button_clicked(GTK_BUTTON(search_window.search_btn)); | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | static gint query_search_deleted(GtkWidget *widget, GdkEventAny *event, | ||
| 1335 | gpointer data) | ||
| 1336 | { | ||
| 1337 | gtk_button_clicked(GTK_BUTTON(search_window.close_btn)); | ||
| 1338 | return TRUE; | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, | ||
| 1342 | gpointer data) | ||
| 1343 | { | ||
| 1344 | if (event && event->keyval == GDK_Escape) { | ||
| 1345 | if (search_window.on_search) | ||
| 1346 | gtk_button_clicked | ||
| 1347 | (GTK_BUTTON(search_window.search_btn)); | ||
| 1348 | else | ||
| 1349 | gtk_button_clicked(GTK_BUTTON(search_window.close_btn)); | ||
| 1350 | return TRUE; | ||
| 1351 | } | ||
| 1352 | return FALSE; | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | static GSList *query_search_get_selected_msg_list(void) | ||
| 1356 | { | ||
| 1357 | GtkTreeModel *model = GTK_TREE_MODEL(search_window.store); | ||
| 1358 | GtkTreeSelection *selection; | ||
| 1359 | GList *list, *cur; | ||
| 1360 | GtkTreePath *path; | ||
| 1361 | GtkTreeIter iter; | ||
| 1362 | GSList *mlist = NULL; | ||
| 1363 | MsgInfo *msginfo; | ||
| 1364 | |||
| 1365 | selection = gtk_tree_view_get_selection | ||
| 1366 | (GTK_TREE_VIEW(search_window.treeview)); | ||
| 1367 | list = gtk_tree_selection_get_selected_rows(selection, NULL); | ||
| 1368 | if (!list) | ||
| 1369 | return NULL; | ||
| 1370 | |||
| 1371 | for (cur = list; cur != NULL; cur = cur->next) { | ||
| 1372 | path = cur->data; | ||
| 1373 | if (!gtk_tree_model_get_iter(model, &iter, path)) | ||
| 1374 | break; | ||
| 1375 | msginfo = NULL; | ||
| 1376 | gtk_tree_model_get(model, &iter, COL_MSGINFO, &msginfo, -1); | ||
| 1377 | if (msginfo) | ||
| 1378 | mlist = g_slist_prepend(mlist, msginfo); | ||
| 1379 | } | ||
| 1380 | mlist = g_slist_reverse(mlist); | ||
| 1381 | |||
| 1382 | g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); | ||
| 1383 | g_list_free(list); | ||
| 1384 | |||
| 1385 | return mlist; | ||
| 1386 | } | ||
| 1387 | |||
| 1388 | static void query_search_open_msg(gboolean new_window) | ||
| 1389 | { | ||
| 1390 | GSList *mlist; | ||
| 1391 | MsgInfo *msginfo; | ||
| 1392 | MessageView *msgview; | ||
| 1393 | |||
| 1394 | mlist = query_search_get_selected_msg_list(); | ||
| 1395 | if (!mlist) | ||
| 1396 | return; | ||
| 1397 | msginfo = (MsgInfo *)mlist->data; | ||
| 1398 | g_slist_free(mlist); | ||
| 1399 | |||
| 1400 | if (new_window || !summary_select_by_msginfo(main_window_get()->summaryview, msginfo)) { | ||
| 1401 | msgview = messageview_create_with_new_window(); | ||
| 1402 | messageview_show(msgview, msginfo, FALSE); | ||
| 1403 | statusbar_pop_all(); | ||
| 1404 | } | ||
| 1405 | } | ||
| 1406 | |||
| 1407 | static void query_search_reply_forward(ComposeMode mode) | ||
| 1408 | { | ||
| 1409 | GSList *mlist; | ||
| 1410 | MsgInfo *msginfo; | ||
| 1411 | |||
| 1412 | mlist = query_search_get_selected_msg_list(); | ||
| 1413 | if (!mlist) | ||
| 1414 | return; | ||
| 1415 | msginfo = (MsgInfo *)mlist->data; | ||
| 1416 | |||
| 1417 | if (prefs_common.reply_with_quote) | ||
| 1418 | mode |= COMPOSE_WITH_QUOTE; | ||
| 1419 | |||
| 1420 | switch (COMPOSE_MODE(mode)) { | ||
| 1421 | case COMPOSE_REPLY: | ||
| 1422 | case COMPOSE_REPLY_TO_SENDER: | ||
| 1423 | case COMPOSE_REPLY_TO_ALL: | ||
| 1424 | case COMPOSE_REPLY_TO_LIST: | ||
| 1425 | compose_reply(msginfo, msginfo->folder, mode, NULL); | ||
| 1426 | break; | ||
| 1427 | case COMPOSE_FORWARD: | ||
| 1428 | compose_forward(mlist, NULL, FALSE, NULL); | ||
| 1429 | break; | ||
| 1430 | case COMPOSE_FORWARD_AS_ATTACH: | ||
| 1431 | compose_forward(mlist, NULL, TRUE, NULL); | ||
| 1432 | break; | ||
| 1433 | case COMPOSE_REDIRECT: | ||
| 1434 | compose_redirect(msginfo, msginfo->folder); | ||
| 1435 | break; | ||
| 1436 | default: | ||
| 1437 | g_warning("query_search_reply_forward: invalid mode: %d", mode); | ||
| 1438 | } | ||
| 1439 | |||
| 1440 | g_slist_free(mlist); | ||
| 1441 | } | ||
| 1442 | |||
| 1443 | static void query_search_move_copy(gboolean is_copy) | ||
| 1444 | { | ||
| 1445 | GSList *mlist, *cur; | ||
| 1446 | FolderItem *dest; | ||
| 1447 | MsgInfo *msginfo; | ||
| 1448 | |||
| 1449 | debug_print("query_search_move_copy: is_copy: %d\n", is_copy); | ||
| 1450 | |||
| 1451 | mlist = query_search_get_selected_msg_list(); | ||
| 1452 | if (!mlist) | ||
| 1453 | return; | ||
| 1454 | |||
| 1455 | if (is_copy) | ||
| 1456 | dest = foldersel_folder_sel_full(NULL, FOLDER_SEL_COPY, NULL, | ||
| 1457 | _("Select folder to copy")); | ||
| 1458 | else | ||
| 1459 | dest = foldersel_folder_sel_full(NULL, FOLDER_SEL_MOVE, NULL, | ||
| 1460 | _("Select folder to move")); | ||
| 1461 | if (!dest || dest->stype == F_VIRTUAL || !FOLDER_ITEM_CAN_ADD(dest)) { | ||
| 1462 | g_slist_free(mlist); | ||
| 1463 | return; | ||
| 1464 | } | ||
| 1465 | if (summary_is_locked(main_window_get()->summaryview)) { | ||
| 1466 | g_slist_free(mlist); | ||
| 1467 | return; | ||
| 1468 | } | ||
| 1469 | |||
| 1470 | for (cur = mlist; cur != NULL; cur = cur->next) { | ||
| 1471 | msginfo = (MsgInfo *)cur->data; | ||
| 1472 | if (!msginfo) | ||
| 1473 | continue; | ||
| 1474 | |||
| 1475 | if (is_copy) { | ||
| 1476 | folder_item_copy_msg(dest, msginfo); | ||
| 1477 | } else { | ||
| 1478 | folder_item_move_msg(dest, msginfo); | ||
| 1479 | } | ||
| 1480 | } | ||
| 1481 | |||
| 1482 | folderview_update_all_updated(TRUE); | ||
| 1483 | g_slist_free(mlist); | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | static void query_search_create_filter(FilterCreateType type) | ||
| 1487 | { | ||
| 1488 | GSList *mlist; | ||
| 1489 | MsgInfo *msginfo; | ||
| 1490 | gchar *header = NULL; | ||
| 1491 | gchar *key = NULL; | ||
| 1492 | |||
| 1493 | mlist = query_search_get_selected_msg_list(); | ||
| 1494 | if (!mlist) | ||
| 1495 | return; | ||
| 1496 | msginfo = (MsgInfo *)mlist->data; | ||
| 1497 | g_slist_free(mlist); | ||
| 1498 | |||
| 1499 | filter_get_keyword_from_msg(msginfo, &header, &key, type); | ||
| 1500 | prefs_filter_open(msginfo, header, key); | ||
| 1501 | |||
| 1502 | g_free(header); | ||
| 1503 | g_free(key); | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | static void reply_cb(void) | ||
| 1507 | { | ||
| 1508 | query_search_reply_forward(COMPOSE_REPLY); | ||
| 1509 | } | ||
| 1510 | |||
| 1511 | static void reply_all_cb(void) | ||
| 1512 | { | ||
| 1513 | query_search_reply_forward(COMPOSE_REPLY_TO_ALL); | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | static void reply_sender_cb(void) | ||
| 1517 | { | ||
| 1518 | query_search_reply_forward(COMPOSE_REPLY_TO_SENDER); | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | static void reply_list_cb(void) | ||
| 1522 | { | ||
| 1523 | query_search_reply_forward(COMPOSE_REPLY_TO_LIST); | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | static void forward_cb(void) | ||
| 1527 | { | ||
| 1528 | query_search_reply_forward(COMPOSE_FORWARD); | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | static void forward_attach_cb(void) | ||
| 1532 | { | ||
| 1533 | query_search_reply_forward(COMPOSE_FORWARD_AS_ATTACH); | ||
| 1534 | } | ||
| 1535 | |||
| 1536 | static void redirect_cb(void) | ||
| 1537 | { | ||
| 1538 | query_search_reply_forward(COMPOSE_REDIRECT); | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | static void move_cb(void) | ||
| 1542 | { | ||
| 1543 | query_search_move_copy(FALSE); | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | static void copy_cb(void) | ||
| 1547 | { | ||
| 1548 | query_search_move_copy(TRUE); | ||
| 1549 | } | ||
| 1550 | |||
| 1551 | static void add_address_cb(void) | ||
| 1552 | { | ||
| 1553 | GSList *mlist; | ||
| 1554 | MsgInfo *msginfo; | ||
| 1555 | gchar from[BUFFSIZE]; | ||
| 1556 | |||
| 1557 | mlist = query_search_get_selected_msg_list(); | ||
| 1558 | if (!mlist) | ||
| 1559 | return; | ||
| 1560 | msginfo = (MsgInfo *)mlist->data; | ||
| 1561 | g_slist_free(mlist); | ||
| 1562 | |||
| 1563 | strncpy2(from, msginfo->from, sizeof(from)); | ||
| 1564 | extract_address(from); | ||
| 1565 | addressbook_add_contact(msginfo->fromname, from, NULL); | ||
| 1566 | } | ||
| 1567 | |||
| 1568 | static void create_filter_auto_cb(void) | ||
| 1569 | { | ||
| 1570 | query_search_create_filter(FLT_BY_AUTO); | ||
| 1571 | } | ||
| 1572 | |||
| 1573 | static void create_filter_from_cb(void) | ||
| 1574 | { | ||
| 1575 | query_search_create_filter(FLT_BY_FROM); | ||
| 1576 | } | ||
| 1577 | |||
| 1578 | static void create_filter_to_cb(void) | ||
| 1579 | { | ||
| 1580 | query_search_create_filter(FLT_BY_TO); | ||
| 1581 | } | ||
| 1582 | |||
| 1583 | static void create_filter_subject_cb(void) | ||
| 1584 | { | ||
| 1585 | query_search_create_filter(FLT_BY_SUBJECT); | ||
| 1586 | } | ||
| 1587 | |||
| 1588 | static void open_cb(void) | ||
| 1589 | { | ||
| 1590 | query_search_open_msg(TRUE); | ||
| 1591 | } | ||
| 1592 | |||
| 1593 | static void open_source_cb(void) | ||
| 1594 | { | ||
| 1595 | GSList *mlist; | ||
| 1596 | MsgInfo *msginfo; | ||
| 1597 | SourceWindow *srcwin; | ||
| 1598 | |||
| 1599 | mlist = query_search_get_selected_msg_list(); | ||
| 1600 | if (!mlist) | ||
| 1601 | return; | ||
| 1602 | msginfo = (MsgInfo *)mlist->data; | ||
| 1603 | g_slist_free(mlist); | ||
| 1604 | |||
| 1605 | srcwin = source_window_create(); | ||
| 1606 | source_window_show_msg(srcwin, msginfo); | ||
| 1607 | source_window_show(srcwin); | ||
| 1608 | } | ||
| 1609 | |||
| 1610 | static void print_cb(void) | ||
| 1611 | { | ||
| 1612 | GSList *mlist; | ||
| 1613 | |||
| 1614 | mlist = query_search_get_selected_msg_list(); | ||
| 1615 | if (!mlist) | ||
| 1616 | return; | ||
| 1617 | printing_print_messages(mlist, FALSE); | ||
| 1618 | g_slist_free(mlist); | ||
| 1619 | } | ||
| 1620 | |||
| 1621 | static gint query_search_cmp_by_folder(GtkTreeModel *model, | ||
| 1622 | GtkTreeIter *a, GtkTreeIter *b, | ||
| 1623 | gpointer data) | ||
| 1624 | { | ||
| 1625 | gchar *folder_a = NULL, *folder_b = NULL; | ||
| 1626 | MsgInfo *msginfo_a = NULL, *msginfo_b = NULL; | ||
| 1627 | gint ret; | ||
| 1628 | |||
| 1629 | gtk_tree_model_get(model, a, COL_FOLDER, &folder_a, COL_MSGINFO, | ||
| 1630 | &msginfo_a, -1); | ||
| 1631 | gtk_tree_model_get(model, b, COL_FOLDER, &folder_b, COL_MSGINFO, | ||
| 1632 | &msginfo_b, -1); | ||
| 1633 | |||
| 1634 | if (!folder_a || !folder_b || !msginfo_a || !msginfo_b) | ||
| 1635 | return 0; | ||
| 1636 | |||
| 1637 | ret = g_ascii_strcasecmp(folder_a, folder_b); | ||
| 1638 | return (ret != 0) ? ret : (msginfo_a->date_t - msginfo_b->date_t); | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | static gint query_search_cmp_by_subject(GtkTreeModel *model, | ||
| 1642 | GtkTreeIter *a, GtkTreeIter *b, | ||
| 1643 | gpointer data) | ||
| 1644 | { | ||
| 1645 | MsgInfo *msginfo_a = NULL, *msginfo_b = NULL; | ||
| 1646 | gint ret; | ||
| 1647 | |||
| 1648 | gtk_tree_model_get(model, a, COL_MSGINFO, &msginfo_a, -1); | ||
| 1649 | gtk_tree_model_get(model, b, COL_MSGINFO, &msginfo_b, -1); | ||
| 1650 | |||
| 1651 | if (!msginfo_a || !msginfo_b) | ||
| 1652 | return 0; | ||
| 1653 | |||
| 1654 | if (!msginfo_a->subject) | ||
| 1655 | return -(msginfo_b->subject != NULL); | ||
| 1656 | if (!msginfo_b->subject) | ||
| 1657 | return (msginfo_a->subject != NULL); | ||
| 1658 | |||
| 1659 | ret = subject_compare_for_sort(msginfo_a->subject, msginfo_b->subject); | ||
| 1660 | return (ret != 0) ? ret : (msginfo_a->date_t - msginfo_b->date_t); | ||
| 1661 | } | ||
| 1662 | |||
| 1663 | static gint query_search_cmp_by_from(GtkTreeModel *model, | ||
| 1664 | GtkTreeIter *a, GtkTreeIter *b, | ||
| 1665 | gpointer data) | ||
| 1666 | { | ||
| 1667 | MsgInfo *msginfo_a = NULL, *msginfo_b = NULL; | ||
| 1668 | gint ret; | ||
| 1669 | |||
| 1670 | gtk_tree_model_get(model, a, COL_MSGINFO, &msginfo_a, -1); | ||
| 1671 | gtk_tree_model_get(model, b, COL_MSGINFO, &msginfo_b, -1); | ||
| 1672 | |||
| 1673 | if (!msginfo_a || !msginfo_b) | ||
| 1674 | return 0; | ||
| 1675 | |||
| 1676 | if (!msginfo_a->fromname) | ||
| 1677 | return -(msginfo_b->fromname != NULL); | ||
| 1678 | if (!msginfo_b->fromname) | ||
| 1679 | return (msginfo_a->fromname != NULL); | ||
| 1680 | |||
| 1681 | ret = g_ascii_strcasecmp(msginfo_a->fromname, msginfo_b->fromname); | ||
| 1682 | return (ret != 0) ? ret : (msginfo_a->date_t - msginfo_b->date_t); | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | static gint query_search_cmp_by_date(GtkTreeModel *model, | ||
| 1686 | GtkTreeIter *a, GtkTreeIter *b, | ||
| 1687 | gpointer data) | ||
| 1688 | { | ||
| 1689 | MsgInfo *msginfo_a = NULL, *msginfo_b = NULL; | ||
| 1690 | |||
| 1691 | gtk_tree_model_get(model, a, COL_MSGINFO, &msginfo_a, -1); | ||
| 1692 | gtk_tree_model_get(model, b, COL_MSGINFO, &msginfo_b, -1); | ||
| 1693 | |||
| 1694 | if (!msginfo_a || !msginfo_b) | ||
| 1695 | return 0; | ||
| 1696 | |||
| 1697 | return msginfo_a->date_t - msginfo_b->date_t; | ||
| 1698 | } | ||
