sync with 0.9.12cvs26 HEAD
[claws.git] / src / gtk / quicksearch.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2004 Hiroyuki Yamamoto & the Sylpheed-Claws team
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 <gtk/gtk.h>
25 #include <gdk/gdkkeysyms.h>
26
27 #include "intl.h"
28 #include "utils.h"
29 #include "menu.h"
30 #include "prefs_common.h"
31 #include "description_window.h"
32 #include "matcher.h"
33 #include "matcher_parser.h"
34 #include "quicksearch.h"
35
36 struct _QuickSearch
37 {
38         GtkWidget                       *hbox_search;
39         GtkWidget                       *search_type;
40         GtkWidget                       *search_type_opt;
41         GtkWidget                       *search_string_entry;
42         GtkWidget                       *search_description;
43
44         gboolean                         active;
45         gchar                           *search_string;
46         MatcherList                     *matcher_list;
47
48         QuickSearchExecuteCallback       callback;
49         gpointer                         callback_data;
50         gboolean                         running;
51 };
52
53 static void quicksearch_set_running(QuickSearch *quicksearch, gboolean run);
54
55 static void prepare_matcher(QuickSearch *quicksearch)
56 {
57         const gchar *search_string = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(quicksearch->search_string_entry)->entry));
58
59         if (quicksearch->matcher_list != NULL) {
60                 matcherlist_free(quicksearch->matcher_list);
61                 quicksearch->matcher_list = NULL;
62         }
63
64         if (search_string == NULL || search_string[0] == '\0') {
65                 quicksearch->active = FALSE;
66                 return;
67         }
68
69         if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_EXTENDED) {
70                 char *newstr = NULL;
71
72                 newstr = expand_search_string(search_string);
73                 if (newstr && newstr[0] != '\0') {
74                         quicksearch->matcher_list = matcher_parser_get_cond(newstr);
75                         g_free(newstr);
76                 } else {
77                         quicksearch->matcher_list = NULL;
78                         quicksearch->active = FALSE;
79
80                         return;
81                 }
82         } else {
83                 if (quicksearch->search_string != NULL)
84                         g_free(quicksearch->search_string);
85                 quicksearch->search_string = g_strdup(search_string);
86         }
87
88         quicksearch->active = TRUE;
89 }
90
91 static void update_extended_button (QuickSearch *quicksearch)
92 {
93         GtkWidget *btn = quicksearch->search_description;
94         
95         g_return_if_fail(btn != NULL);
96                 
97         if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_EXTENDED) {
98                 gtk_button_set_label(GTK_BUTTON(btn), _("Extended symbols"));
99                 gtk_widget_show(btn);
100         } else {
101                 gtk_widget_hide(btn);
102         }
103         
104 }
105
106 static gboolean searchbar_pressed(GtkWidget *widget, GdkEventKey *event,
107                                   QuickSearch *quicksearch)
108 {
109         if (event != NULL && event->keyval == GDK_Escape) {
110                 quicksearch_set(quicksearch, prefs_common.summary_quicksearch_type, "");
111                 gtk_widget_grab_focus(GTK_WIDGET(GTK_COMBO(quicksearch->search_string_entry)->entry));
112                 return TRUE;
113         }
114
115         if (event != NULL && event->keyval == GDK_Return) {
116                 const gchar *search_string = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(quicksearch->search_string_entry)->entry));
117
118                 if (search_string && strlen(search_string) != 0) {
119                         prefs_common.summary_quicksearch_history =
120                                 add_history(prefs_common.summary_quicksearch_history,
121                                             search_string);
122                         gtk_combo_set_popdown_strings(GTK_COMBO(quicksearch->search_string_entry), 
123                                 prefs_common.summary_quicksearch_history);                      
124                 }
125
126                 prepare_matcher(quicksearch);
127
128                 quicksearch_set_running(quicksearch, TRUE);
129                 if (quicksearch->callback != NULL)
130                         quicksearch->callback(quicksearch, quicksearch->callback_data);
131                 quicksearch_set_running(quicksearch, FALSE);
132                 g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
133                 gtk_widget_grab_focus(GTK_WIDGET(GTK_COMBO(
134                         quicksearch->search_string_entry)->entry));
135                 return TRUE;
136         }
137
138         return FALSE;           
139 }
140
141 static gboolean searchtype_changed(GtkMenuItem *widget, gpointer data)
142 {
143         QuickSearch *quicksearch = (QuickSearch *)data;
144
145         prefs_common.summary_quicksearch_type = GPOINTER_TO_INT(g_object_get_data(
146                                    G_OBJECT(GTK_MENU_ITEM(gtk_menu_get_active(
147                                    GTK_MENU(quicksearch->search_type)))), MENU_VAL_ID));
148
149         /* Show extended search description button, only when Extended is selected */
150         update_extended_button(quicksearch);
151
152         prepare_matcher(quicksearch);
153
154         quicksearch_set_running(quicksearch, TRUE);
155         if (quicksearch->callback != NULL)
156                 quicksearch->callback(quicksearch, quicksearch->callback_data);
157         quicksearch_set_running(quicksearch, FALSE);
158 }
159
160 /*
161  * Strings describing how to use Extended Search
162  * 
163  * When adding new lines, remember to put 2 strings for each line
164  */
165 static gchar *search_descr_strings[] = {
166         "a",     N_("all messages"),
167         "ag #",  N_("messages whose age is greater than #"),
168         "al #",  N_("messages whose age is less than #"),
169         "b S",   N_("messages which contain S in the message body"),
170         "B S",   N_("messages which contain S in the whole message"),
171         "c S",   N_("messages carbon-copied to S"),
172         "C S",   N_("message is either to: or cc: to S"),
173         "D",     N_("deleted messages"), /** how I can filter deleted messages **/
174         "e S",   N_("messages which contain S in the Sender field"),
175         "E S",   N_("true if execute \"S\" succeeds"),
176         "f S",   N_("messages originating from user S"),
177         "F",     N_("forwarded messages"),
178         "h S",   N_("messages which contain header S"),
179         "i S",   N_("messages which contain S in Message-ID header"),
180         "I S",   N_("messages which contain S in inreplyto header"),
181         "L",     N_("locked messages"),
182         "n S",   N_("messages which are in newsgroup S"),
183         "N",     N_("new messages"),
184         "O",     N_("old messages"),
185         "p",     N_("incomplete messages (not entirely downloaded)"),
186         "r",     N_("messages which have been replied to"),
187         "R",     N_("read messages"),
188         "s S",   N_("messages which contain S in subject"),
189         "se #",  N_("messages whose score is equal to #"),
190         "sg #",  N_("messages whose score is greater than #"),
191         "sl #",  N_("messages whose score is lower than #"),
192         "Se #",  N_("messages whose size is equal to #"),
193         "Sg #",  N_("messages whose size is greater than #"),
194         "Ss #",  N_("messages whose size is smaller than #"),
195         "t S",   N_("messages which have been sent to S"),
196         "T",     N_("marked messages"),
197         "U",     N_("unread messages"),
198         "x S",   N_("messages which contain S in References header"),
199         "X cmd", N_("messages returning 0 when passed to command"),
200         "y S",   N_("messages which contain S in X-Label header"),
201         "",      "" ,
202         "&",     N_("logical AND operator"),
203         "|",     N_("logical OR operator"),
204         "! or ~",       N_("logical NOT operator"),
205         "%",     N_("case sensitive search"),
206         "",      "" ,
207         " ",     N_("all filtering expressions are allowed"),
208         NULL,    NULL 
209 };
210  
211 static DescriptionWindow search_descr = {
212         NULL, 
213         2,
214         N_("Extended Search symbols"),
215         search_descr_strings
216 };
217         
218 static void search_description_cb(GtkWidget *widget)
219 {
220         description_window_create(&search_descr);
221 };
222
223 static gboolean clear_search_cb(GtkMenuItem *widget, gpointer data)
224 {
225         QuickSearch *quicksearch = (QuickSearch *)data;
226         
227         quicksearch_set(quicksearch, prefs_common.summary_quicksearch_type, "");
228         
229         return TRUE;
230 };
231
232 /*
233 static void summary_searchbar_focus_evt(GtkWidget *widget, GdkEventFocus *event,
234                                         SummaryView *summaryview)
235 {
236         if (event != NULL && event->in)
237                 gtk_signal_handler_block_by_func(GTK_OBJECT(summaryview->mainwin->window), 
238                                                  GTK_SIGNAL_FUNC(mainwindow_key_pressed),
239                                                  summaryview->mainwin);
240         else
241                 gtk_signal_handler_unblock_by_func(GTK_OBJECT(summaryview->mainwin->window), 
242                                                    GTK_SIGNAL_FUNC(mainwindow_key_pressed),
243                                                    summaryview->mainwin);
244 }
245 */
246
247 QuickSearch *quicksearch_new()
248 {
249         QuickSearch *quicksearch;
250
251         GtkWidget *hbox_search;
252         GtkWidget *search_type_opt;
253         GtkWidget *search_type;
254         GtkWidget *search_string_entry;
255         GtkWidget *search_hbbox;
256         GtkWidget *search_description;
257         GtkWidget *clear_search;
258         GtkWidget *menuitem;
259
260         quicksearch = g_new0(QuickSearch, 1);
261
262         /* quick search */
263         hbox_search = gtk_hbox_new(FALSE, 0);
264
265         search_type_opt = gtk_option_menu_new();
266         gtk_widget_show(search_type_opt);
267         gtk_box_pack_start(GTK_BOX(hbox_search), search_type_opt, FALSE, FALSE, 0);
268
269         search_type = gtk_menu_new();
270         MENUITEM_ADD (search_type, menuitem, _("Subject"), QUICK_SEARCH_SUBJECT);
271         g_signal_connect(G_OBJECT(menuitem), "activate",
272                          G_CALLBACK(searchtype_changed),
273                          quicksearch);
274         MENUITEM_ADD (search_type, menuitem, _("From"), QUICK_SEARCH_FROM);
275         g_signal_connect(G_OBJECT(menuitem), "activate",
276                          G_CALLBACK(searchtype_changed),
277                          quicksearch);
278         MENUITEM_ADD (search_type, menuitem, _("To"), QUICK_SEARCH_TO);
279         g_signal_connect(G_OBJECT(menuitem), "activate",
280                          G_CALLBACK(searchtype_changed),
281                          quicksearch);
282         MENUITEM_ADD (search_type, menuitem, _("Extended"), QUICK_SEARCH_EXTENDED);
283         g_signal_connect(G_OBJECT(menuitem), "activate",
284                          G_CALLBACK(searchtype_changed),
285                          quicksearch);
286
287         gtk_option_menu_set_menu(GTK_OPTION_MENU(search_type_opt), search_type);
288         
289         gtk_option_menu_set_history(GTK_OPTION_MENU(search_type_opt), prefs_common.summary_quicksearch_type);
290         
291         gtk_widget_show(search_type);
292         
293         search_string_entry = gtk_combo_new();
294         gtk_box_pack_start(GTK_BOX(hbox_search), search_string_entry, FALSE, FALSE, 2);
295         gtk_combo_set_value_in_list(GTK_COMBO(search_string_entry), FALSE, TRUE);
296         gtk_combo_set_case_sensitive(GTK_COMBO(search_string_entry), TRUE);
297         if (prefs_common.summary_quicksearch_history) 
298                 gtk_combo_set_popdown_strings(GTK_COMBO(search_string_entry), 
299                         prefs_common.summary_quicksearch_history);
300         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(search_string_entry)->entry), "");
301         gtk_widget_show(search_string_entry);
302
303         search_hbbox = gtk_hbutton_box_new();
304         gtk_button_box_set_layout(GTK_BUTTON_BOX(search_hbbox),         
305                                   GTK_BUTTONBOX_START);
306
307         gtk_box_set_spacing(GTK_BOX(search_hbbox), 5);
308                 
309         if (prefs_common.summary_quicksearch_sticky) {
310                 clear_search = gtk_button_new_with_label(_("Clear"));
311                 gtk_box_pack_start(GTK_BOX(search_hbbox), clear_search,
312                                    FALSE, FALSE, 0);
313                 gtk_widget_set_usize(clear_search, 120, -1);
314                 g_signal_connect(G_OBJECT(clear_search), "clicked",
315                                    GTK_SIGNAL_FUNC(clear_search_cb), quicksearch);
316                 gtk_widget_show(clear_search);
317         }
318
319         search_description = gtk_button_new_with_label(_("Extended Symbols"));
320         gtk_box_pack_start(GTK_BOX(search_hbbox), search_description,
321                            TRUE, TRUE, 0);
322         gtk_widget_show(search_description);
323                 
324         g_signal_connect(G_OBJECT(search_description), "clicked",
325                          G_CALLBACK(search_description_cb), NULL);
326
327         gtk_box_pack_start(GTK_BOX(hbox_search), search_hbbox, FALSE, FALSE, 2);                                
328         gtk_widget_show(search_hbbox);
329         if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_EXTENDED)
330                 gtk_widget_show(search_description);
331         else
332                 gtk_widget_hide(search_description);
333         
334         g_signal_connect(G_OBJECT(GTK_COMBO(search_string_entry)->entry), 
335                            "key_press_event",
336                            G_CALLBACK(searchbar_pressed),
337                            quicksearch);
338
339         /*
340         gtk_signal_connect(GTK_OBJECT(GTK_COMBO(search_string_entry)->entry), 
341                            "focus_in_event",
342                            GTK_SIGNAL_FUNC(searchbar_focus_evt),
343                            quicksearch);
344
345         gtk_signal_connect(GTK_OBJECT(GTK_COMBO(search_string_entry)->entry), 
346                            "focus_out_event",
347                            GTK_SIGNAL_FUNC(searchbar_focus_evt),
348                            quicksearch);
349         */
350
351         quicksearch->hbox_search = hbox_search;
352         quicksearch->search_type = search_type;
353         quicksearch->search_type_opt = search_type_opt;
354         quicksearch->search_string_entry = search_string_entry;
355         quicksearch->search_description = search_description;
356         quicksearch->matcher_list = NULL;
357         quicksearch->active = FALSE;
358         quicksearch->running = FALSE;
359         
360         update_extended_button(quicksearch);
361         
362         return quicksearch;
363 }
364
365 GtkWidget *quicksearch_get_widget(QuickSearch *quicksearch)
366 {
367         return quicksearch->hbox_search;
368 }
369
370 void quicksearch_show(QuickSearch *quicksearch)
371 {
372         prepare_matcher(quicksearch);
373         gtk_widget_show(quicksearch->hbox_search);
374         update_extended_button(quicksearch);
375 }
376
377 void quicksearch_hide(QuickSearch *quicksearch)
378 {
379         quicksearch->active = FALSE;
380         gtk_widget_hide(quicksearch->hbox_search);
381 }
382
383 void quicksearch_set(QuickSearch *quicksearch, QuickSearchType type,
384                      const gchar *matchstring)
385 {
386         gtk_option_menu_set_history(GTK_OPTION_MENU(quicksearch->search_type_opt),
387                                     type);
388         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(quicksearch->search_string_entry)->entry),
389                            matchstring);
390         prefs_common.summary_quicksearch_type = type;
391
392         prepare_matcher(quicksearch);
393
394         quicksearch_set_running(quicksearch, TRUE);
395         if (quicksearch->callback != NULL)
396                 quicksearch->callback(quicksearch, quicksearch->callback_data); 
397         quicksearch_set_running(quicksearch, FALSE);
398 }
399
400 gboolean quicksearch_is_active(QuickSearch *quicksearch)
401 {
402         return quicksearch->active;
403 }
404
405 void quicksearch_set_execute_callback(QuickSearch *quicksearch,
406                                       QuickSearchExecuteCallback callback,
407                                       gpointer data)
408 {
409         quicksearch->callback = callback;
410         quicksearch->callback_data = data;
411 }
412
413 gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
414 {
415         gchar *searched_header = NULL;
416
417         if (!quicksearch->active)
418                 return TRUE;
419
420         switch (prefs_common.summary_quicksearch_type) {
421         case QUICK_SEARCH_SUBJECT:
422                 searched_header = msginfo->subject;
423                 break;
424         case QUICK_SEARCH_FROM:
425                 searched_header = msginfo->from;
426                 break;
427         case QUICK_SEARCH_TO:
428                 searched_header = msginfo->to;
429                 break;
430         case QUICK_SEARCH_EXTENDED:
431                 break;
432         default:
433                 debug_print("unknown search type (%d)\n", prefs_common.summary_quicksearch_type);
434                 break;
435         }
436
437         if (prefs_common.summary_quicksearch_type != QUICK_SEARCH_EXTENDED && quicksearch->search_string &&
438             searched_header && strcasestr(searched_header, quicksearch->search_string) != NULL)
439                 return TRUE;
440         else if ((quicksearch->matcher_list != NULL) && matcherlist_match(quicksearch->matcher_list, msginfo))
441                 return TRUE;
442
443         return FALSE;
444 }
445
446 /* allow Mutt-like patterns in quick search */
447 gchar *expand_search_string(const gchar *search_string)
448 {
449         int i = 0;
450         gchar term_char, save_char;
451         gchar *cmd_start, *cmd_end;
452         GString *matcherstr;
453         gchar *returnstr = NULL;
454         gchar *copy_str;
455         gboolean casesens, dontmatch;
456         /* list of allowed pattern abbreviations */
457         struct {
458                 gchar           *abbreviated;   /* abbreviation */
459                 gchar           *command;       /* actual matcher command */ 
460                 gint            numparams;      /* number of params for cmd */
461                 gboolean        qualifier;      /* do we append regexpcase */
462                 gboolean        quotes;         /* do we need quotes */
463         }
464         cmds[] = {
465                 { "a",  "all",                          0,      FALSE,  FALSE },
466                 { "ag", "age_greater",                  1,      FALSE,  FALSE },
467                 { "al", "age_lower",                    1,      FALSE,  FALSE },
468                 { "b",  "body_part",                    1,      TRUE,   TRUE  },
469                 { "B",  "message",                      1,      TRUE,   TRUE  },
470                 { "c",  "cc",                           1,      TRUE,   TRUE  },
471                 { "C",  "to_or_cc",                     1,      TRUE,   TRUE  },
472                 { "D",  "deleted",                      0,      FALSE,  FALSE },
473                 { "e",  "header \"Sender\"",            1,      TRUE,   TRUE  },
474                 { "E",  "execute",                      1,      FALSE,  TRUE  },
475                 { "f",  "from",                         1,      TRUE,   TRUE  },
476                 { "F",  "forwarded",                    0,      FALSE,  FALSE },
477                 { "h",  "headers_part",                 1,      TRUE,   TRUE  },
478                 { "i",  "header \"Message-ID\"",        1,      TRUE,   TRUE  },
479                 { "I",  "inreplyto",                    1,      TRUE,   TRUE  },
480                 { "L",  "locked",                       0,      FALSE,  FALSE },
481                 { "n",  "newsgroups",                   1,      TRUE,   TRUE  },
482                 { "N",  "new",                          0,      FALSE,  FALSE },
483                 { "O",  "~new",                         0,      FALSE,  FALSE },
484                 { "r",  "replied",                      0,      FALSE,  FALSE },
485                 { "R",  "~unread",                      0,      FALSE,  FALSE },
486                 { "s",  "subject",                      1,      TRUE,   TRUE  },
487                 { "se", "score_equal",                  1,      FALSE,  FALSE },
488                 { "sg", "score_greater",                1,      FALSE,  FALSE },
489                 { "sl", "score_lower",                  1,      FALSE,  FALSE },
490                 { "Se", "size_equal",                   1,      FALSE,  FALSE },
491                 { "Sg", "size_greater",                 1,      FALSE,  FALSE },
492                 { "Ss", "size_smaller",                 1,      FALSE,  FALSE },
493                 { "t",  "to",                           1,      TRUE,   TRUE  },
494                 { "T",  "marked",                       0,      FALSE,  FALSE },
495                 { "U",  "unread",                       0,      FALSE,  FALSE },
496                 { "x",  "header \"References\"",        1,      TRUE,   TRUE  },
497                 { "X",  "test",                         1,      FALSE,  FALSE }, 
498                 { "y",  "header \"X-Label\"",           1,      TRUE,   TRUE  },
499                 { "&",  "&",                            0,      FALSE,  FALSE },
500                 { "|",  "|",                            0,      FALSE,  FALSE },
501                 { "p",  "partial",                      0,      FALSE,  FALSE },
502                 { NULL, NULL,                           0,      FALSE,  FALSE }
503         };
504
505         if (search_string == NULL)
506                 return NULL;
507
508         copy_str = g_strdup(search_string);
509
510         matcherstr = g_string_sized_new(16);
511         cmd_start = copy_str;
512         while (cmd_start && *cmd_start) {
513                 /* skip all white spaces */
514                 while (*cmd_start && isspace((guchar)*cmd_start))
515                         cmd_start++;
516                 cmd_end = cmd_start;
517
518                 /* extract a command */
519                 while (*cmd_end && !isspace((guchar)*cmd_end))
520                         cmd_end++;
521
522                 /* save character */
523                 save_char = *cmd_end;
524                 *cmd_end = '\0';
525
526                 dontmatch = FALSE;
527                 casesens = FALSE;
528
529                 /* ~ and ! mean logical NOT */
530                 if (*cmd_start == '~' || *cmd_start == '!')
531                 {
532                         dontmatch = TRUE;
533                         cmd_start++;
534                 }
535                 /* % means case sensitive match */
536                 if (*cmd_start == '%')
537                 {
538                         casesens = TRUE;
539                         cmd_start++;
540                 }
541
542                 /* find matching abbreviation */
543                 for (i = 0; cmds[i].command; i++) {
544                         if (!strcmp(cmd_start, cmds[i].abbreviated)) {
545                                 /* restore character */
546                                 *cmd_end = save_char;
547
548                                 /* copy command */
549                                 if (matcherstr->len > 0) {
550                                         g_string_append(matcherstr, " ");
551                                 }
552                                 if (dontmatch)
553                                         g_string_append(matcherstr, "~");
554                                 g_string_append(matcherstr, cmds[i].command);
555                                 g_string_append(matcherstr, " ");
556
557                                 /* stop if no params required */
558                                 if (cmds[i].numparams == 0)
559                                         break;
560
561                                 /* extract a parameter, allow quotes */
562                                 while (*cmd_end && isspace((guchar)*cmd_end))
563                                         cmd_end++;
564
565                                 cmd_start = cmd_end;
566                                 if (*cmd_start == '"') {
567                                         term_char = '"';
568                                         cmd_end++;
569                                 }
570                                 else
571                                         term_char = ' ';
572
573                                 /* extract actual parameter */
574                                 while ((*cmd_end) && (*cmd_end != term_char))
575                                         cmd_end++;
576
577                                 if (*cmd_end == '"')
578                                         cmd_end++;
579
580                                 save_char = *cmd_end;
581                                 *cmd_end = '\0';
582
583                                 if (cmds[i].qualifier) {
584                                         if (casesens)
585                                                 g_string_append(matcherstr, "regexp ");
586                                         else
587                                                 g_string_append(matcherstr, "regexpcase ");
588                                 }
589
590                                 /* do we need to add quotes ? */
591                                 if (cmds[i].quotes && term_char != '"')
592                                         g_string_append(matcherstr, "\"");
593
594                                 /* copy actual parameter */
595                                 g_string_append(matcherstr, cmd_start);
596
597                                 /* do we need to add quotes ? */
598                                 if (cmds[i].quotes && term_char != '"')
599                                         g_string_append(matcherstr, "\"");
600
601                                 /* restore original character */
602                                 *cmd_end = save_char;
603
604                                 break;
605                         }
606                 }
607
608                 if (*cmd_end)
609                         cmd_end++;
610                 cmd_start = cmd_end;
611         }
612
613         g_free(copy_str);
614
615         /* return search string if no match is found to allow 
616            all available filtering expressions in quicksearch */
617         if (matcherstr->len > 0) returnstr = matcherstr->str;
618         else returnstr = g_strdup(search_string);
619
620         g_string_free(matcherstr, FALSE);
621         return returnstr;
622 }
623
624 static void quicksearch_set_running(QuickSearch *quicksearch, gboolean run)
625 {
626         quicksearch->running = run;
627 }
628
629 gboolean quicksearch_is_running(QuickSearch *quicksearch) 
630 {
631         return quicksearch->running;
632 }
633