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