sync with 0.9.12cvs18 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         "r",     N_("messages which have been replied to"),
186         "R",     N_("read messages"),
187         "s S",   N_("messages which contain S in subject"),
188         "se #",  N_("messages whose score is equal to #"),
189         "sg #",  N_("messages whose score is greater than #"),
190         "sl #",  N_("messages whose score is lower than #"),
191         "Se #",  N_("messages whose size is equal to #"),
192         "Sg #",  N_("messages whose size is greater than #"),
193         "Ss #",  N_("messages whose size is smaller than #"),
194         "t S",   N_("messages which have been sent to S"),
195         "T",     N_("marked messages"),
196         "U",     N_("unread messages"),
197         "x S",   N_("messages which contain S in References header"),
198         "X cmd", N_("messages returning 0 when passed to command"),
199         "y S",   N_("messages which contain S in X-Label header"),
200         "",      "" ,
201         "&",     N_("logical AND operator"),
202         "|",     N_("logical OR operator"),
203         "! or ~",       N_("logical NOT operator"),
204         "%",     N_("case sensitive search"),
205         "",      "" ,
206         " ",     N_("all filtering expressions are allowed"),
207         NULL,    NULL 
208 };
209  
210 static DescriptionWindow search_descr = {
211         NULL, 
212         2,
213         N_("Extended Search symbols"),
214         search_descr_strings
215 };
216         
217 static void search_description_cb(GtkWidget *widget)
218 {
219         description_window_create(&search_descr);
220 };
221
222 static gboolean clear_search_cb(GtkMenuItem *widget, gpointer data)
223 {
224         QuickSearch *quicksearch = (QuickSearch *)data;
225         
226         quicksearch_set(quicksearch, prefs_common.summary_quicksearch_type, "");
227         
228         return TRUE;
229 };
230
231 /*
232 static void summary_searchbar_focus_evt(GtkWidget *widget, GdkEventFocus *event,
233                                         SummaryView *summaryview)
234 {
235         if (event != NULL && event->in)
236                 gtk_signal_handler_block_by_func(GTK_OBJECT(summaryview->mainwin->window), 
237                                                  GTK_SIGNAL_FUNC(mainwindow_key_pressed),
238                                                  summaryview->mainwin);
239         else
240                 gtk_signal_handler_unblock_by_func(GTK_OBJECT(summaryview->mainwin->window), 
241                                                    GTK_SIGNAL_FUNC(mainwindow_key_pressed),
242                                                    summaryview->mainwin);
243 }
244 */
245
246 QuickSearch *quicksearch_new()
247 {
248         QuickSearch *quicksearch;
249
250         GtkWidget *hbox_search;
251         GtkWidget *search_type_opt;
252         GtkWidget *search_type;
253         GtkWidget *search_string_entry;
254         GtkWidget *search_hbbox;
255         GtkWidget *search_description;
256         GtkWidget *clear_search;
257         GtkWidget *menuitem;
258
259         quicksearch = g_new0(QuickSearch, 1);
260
261         /* quick search */
262         hbox_search = gtk_hbox_new(FALSE, 0);
263
264         search_type_opt = gtk_option_menu_new();
265         gtk_widget_show(search_type_opt);
266         gtk_box_pack_start(GTK_BOX(hbox_search), search_type_opt, FALSE, FALSE, 0);
267
268         search_type = gtk_menu_new();
269         MENUITEM_ADD (search_type, menuitem, _("Subject"), QUICK_SEARCH_SUBJECT);
270         g_signal_connect(G_OBJECT(menuitem), "activate",
271                          G_CALLBACK(searchtype_changed),
272                          quicksearch);
273         MENUITEM_ADD (search_type, menuitem, _("From"), QUICK_SEARCH_FROM);
274         g_signal_connect(G_OBJECT(menuitem), "activate",
275                          G_CALLBACK(searchtype_changed),
276                          quicksearch);
277         MENUITEM_ADD (search_type, menuitem, _("To"), QUICK_SEARCH_TO);
278         g_signal_connect(G_OBJECT(menuitem), "activate",
279                          G_CALLBACK(searchtype_changed),
280                          quicksearch);
281         MENUITEM_ADD (search_type, menuitem, _("Extended"), QUICK_SEARCH_EXTENDED);
282         g_signal_connect(G_OBJECT(menuitem), "activate",
283                          G_CALLBACK(searchtype_changed),
284                          quicksearch);
285
286         gtk_option_menu_set_menu(GTK_OPTION_MENU(search_type_opt), search_type);
287         
288         gtk_option_menu_set_history(GTK_OPTION_MENU(search_type_opt), prefs_common.summary_quicksearch_type);
289         
290         gtk_widget_show(search_type);
291         
292         search_string_entry = gtk_combo_new();
293         gtk_box_pack_start(GTK_BOX(hbox_search), search_string_entry, FALSE, FALSE, 2);
294         gtk_combo_set_value_in_list(GTK_COMBO(search_string_entry), FALSE, TRUE);
295         gtk_combo_set_case_sensitive(GTK_COMBO(search_string_entry), TRUE);
296         if (prefs_common.summary_quicksearch_history) 
297                 gtk_combo_set_popdown_strings(GTK_COMBO(search_string_entry), 
298                         prefs_common.summary_quicksearch_history);
299         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(search_string_entry)->entry), "");
300         gtk_widget_show(search_string_entry);
301
302         search_hbbox = gtk_hbutton_box_new();
303         gtk_button_box_set_layout(GTK_BUTTON_BOX(search_hbbox),         
304                                   GTK_BUTTONBOX_START);
305
306         gtk_box_set_spacing(GTK_BOX(search_hbbox), 5);
307                 
308         if (prefs_common.summary_quicksearch_sticky) {
309                 clear_search = gtk_button_new_with_label(_("Clear"));
310                 gtk_box_pack_start(GTK_BOX(search_hbbox), clear_search,
311                                    FALSE, FALSE, 0);
312                 gtk_widget_set_usize(clear_search, 120, -1);
313                 g_signal_connect(G_OBJECT(clear_search), "clicked",
314                                    GTK_SIGNAL_FUNC(clear_search_cb), quicksearch);
315                 gtk_widget_show(clear_search);
316         }
317
318         search_description = gtk_button_new_with_label(_("Extended Symbols"));
319         gtk_box_pack_start(GTK_BOX(search_hbbox), search_description,
320                            TRUE, TRUE, 0);
321         gtk_widget_show(search_description);
322                 
323         g_signal_connect(G_OBJECT(search_description), "clicked",
324                          G_CALLBACK(search_description_cb), NULL);
325
326         gtk_box_pack_start(GTK_BOX(hbox_search), search_hbbox, FALSE, FALSE, 2);                                
327         gtk_widget_show(search_hbbox);
328         if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_EXTENDED)
329                 gtk_widget_show(search_description);
330         else
331                 gtk_widget_hide(search_description);
332         
333         g_signal_connect(G_OBJECT(GTK_COMBO(search_string_entry)->entry), 
334                            "key_press_event",
335                            G_CALLBACK(searchbar_pressed),
336                            quicksearch);
337
338         /*
339         gtk_signal_connect(GTK_OBJECT(GTK_COMBO(search_string_entry)->entry), 
340                            "focus_in_event",
341                            GTK_SIGNAL_FUNC(searchbar_focus_evt),
342                            quicksearch);
343
344         gtk_signal_connect(GTK_OBJECT(GTK_COMBO(search_string_entry)->entry), 
345                            "focus_out_event",
346                            GTK_SIGNAL_FUNC(searchbar_focus_evt),
347                            quicksearch);
348         */
349
350         quicksearch->hbox_search = hbox_search;
351         quicksearch->search_type = search_type;
352         quicksearch->search_type_opt = search_type_opt;
353         quicksearch->search_string_entry = search_string_entry;
354         quicksearch->search_description = search_description;
355         quicksearch->matcher_list = NULL;
356         quicksearch->active = FALSE;
357         quicksearch->running = FALSE;
358         
359         update_extended_button(quicksearch);
360         
361         return quicksearch;
362 }
363
364 GtkWidget *quicksearch_get_widget(QuickSearch *quicksearch)
365 {
366         return quicksearch->hbox_search;
367 }
368
369 void quicksearch_show(QuickSearch *quicksearch)
370 {
371         prepare_matcher(quicksearch);
372         gtk_widget_show(quicksearch->hbox_search);
373         update_extended_button(quicksearch);
374 }
375
376 void quicksearch_hide(QuickSearch *quicksearch)
377 {
378         quicksearch->active = FALSE;
379         gtk_widget_hide(quicksearch->hbox_search);
380 }
381
382 void quicksearch_set(QuickSearch *quicksearch, QuickSearchType type,
383                      const gchar *matchstring)
384 {
385         gtk_option_menu_set_history(GTK_OPTION_MENU(quicksearch->search_type_opt),
386                                     type);
387         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(quicksearch->search_string_entry)->entry),
388                            matchstring);
389         prefs_common.summary_quicksearch_type = type;
390
391         prepare_matcher(quicksearch);
392
393         if (quicksearch->callback != NULL)
394                 quicksearch->callback(quicksearch, quicksearch->callback_data); 
395 }
396
397 gboolean quicksearch_is_active(QuickSearch *quicksearch)
398 {
399         return quicksearch->active;
400 }
401
402 void quicksearch_set_execute_callback(QuickSearch *quicksearch,
403                                       QuickSearchExecuteCallback callback,
404                                       gpointer data)
405 {
406         quicksearch->callback = callback;
407         quicksearch->callback_data = data;
408 }
409
410 gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
411 {
412         gchar *searched_header = NULL;
413
414         if (!quicksearch->active)
415                 return TRUE;
416
417         switch (prefs_common.summary_quicksearch_type) {
418         case QUICK_SEARCH_SUBJECT:
419                 searched_header = msginfo->subject;
420                 break;
421         case QUICK_SEARCH_FROM:
422                 searched_header = msginfo->from;
423                 break;
424         case QUICK_SEARCH_TO:
425                 searched_header = msginfo->to;
426                 break;
427         case QUICK_SEARCH_EXTENDED:
428                 break;
429         default:
430                 debug_print("unknown search type (%d)\n", prefs_common.summary_quicksearch_type);
431                 break;
432         }
433
434         if (prefs_common.summary_quicksearch_type != QUICK_SEARCH_EXTENDED && quicksearch->search_string &&
435             searched_header && strcasestr(searched_header, quicksearch->search_string) != NULL)
436                 return TRUE;
437         else if ((quicksearch->matcher_list != NULL) && matcherlist_match(quicksearch->matcher_list, msginfo))
438                 return TRUE;
439
440         return FALSE;
441 }
442
443 /* allow Mutt-like patterns in quick search */
444 gchar *expand_search_string(const gchar *search_string)
445 {
446         int i = 0;
447         gchar term_char, save_char;
448         gchar *cmd_start, *cmd_end;
449         GString *matcherstr;
450         gchar *returnstr = NULL;
451         gchar *copy_str;
452         gboolean casesens, dontmatch;
453         /* list of allowed pattern abbreviations */
454         struct {
455                 gchar           *abbreviated;   /* abbreviation */
456                 gchar           *command;       /* actual matcher command */ 
457                 gint            numparams;      /* number of params for cmd */
458                 gboolean        qualifier;      /* do we append regexpcase */
459                 gboolean        quotes;         /* do we need quotes */
460         }
461         cmds[] = {
462                 { "a",  "all",                          0,      FALSE,  FALSE },
463                 { "ag", "age_greater",                  1,      FALSE,  FALSE },
464                 { "al", "age_lower",                    1,      FALSE,  FALSE },
465                 { "b",  "body_part",                    1,      TRUE,   TRUE  },
466                 { "B",  "message",                      1,      TRUE,   TRUE  },
467                 { "c",  "cc",                           1,      TRUE,   TRUE  },
468                 { "C",  "to_or_cc",                     1,      TRUE,   TRUE  },
469                 { "D",  "deleted",                      0,      FALSE,  FALSE },
470                 { "e",  "header \"Sender\"",            1,      TRUE,   TRUE  },
471                 { "E",  "execute",                      1,      FALSE,  TRUE  },
472                 { "f",  "from",                         1,      TRUE,   TRUE  },
473                 { "F",  "forwarded",                    0,      FALSE,  FALSE },
474                 { "h",  "headers_part",                 1,      TRUE,   TRUE  },
475                 { "i",  "header \"Message-Id\"",        1,      TRUE,   TRUE  },
476                 { "I",  "inreplyto",                    1,      TRUE,   TRUE  },
477                 { "L",  "locked",                       0,      FALSE,  FALSE },
478                 { "n",  "newsgroups",                   1,      TRUE,   TRUE  },
479                 { "N",  "new",                          0,      FALSE,  FALSE },
480                 { "O",  "~new",                         0,      FALSE,  FALSE },
481                 { "r",  "replied",                      0,      FALSE,  FALSE },
482                 { "R",  "~unread",                      0,      FALSE,  FALSE },
483                 { "s",  "subject",                      1,      TRUE,   TRUE  },
484                 { "se", "score_equal",                  1,      FALSE,  FALSE },
485                 { "sg", "score_greater",                1,      FALSE,  FALSE },
486                 { "sl", "score_lower",                  1,      FALSE,  FALSE },
487                 { "Se", "size_equal",                   1,      FALSE,  FALSE },
488                 { "Sg", "size_greater",                 1,      FALSE,  FALSE },
489                 { "Ss", "size_smaller",                 1,      FALSE,  FALSE },
490                 { "t",  "to",                           1,      TRUE,   TRUE  },
491                 { "T",  "marked",                       0,      FALSE,  FALSE },
492                 { "U",  "unread",                       0,      FALSE,  FALSE },
493                 { "x",  "header \"References\"",        1,      TRUE,   TRUE  },
494                 { "X",  "test",                         1,      FALSE,  FALSE }, 
495                 { "y",  "header \"X-Label\"",           1,      TRUE,   TRUE  },
496                 { "&",  "&",                            0,      FALSE,  FALSE },
497                 { "|",  "|",                            0,      FALSE,  FALSE },
498                 { NULL, NULL,                           0,      FALSE,  FALSE }
499         };
500
501         if (search_string == NULL)
502                 return NULL;
503
504         copy_str = g_strdup(search_string);
505
506         matcherstr = g_string_sized_new(16);
507         cmd_start = copy_str;
508         while (cmd_start && *cmd_start) {
509                 /* skip all white spaces */
510                 while (*cmd_start && isspace((guchar)*cmd_start))
511                         cmd_start++;
512                 cmd_end = cmd_start;
513
514                 /* extract a command */
515                 while (*cmd_end && !isspace((guchar)*cmd_end))
516                         cmd_end++;
517
518                 /* save character */
519                 save_char = *cmd_end;
520                 *cmd_end = '\0';
521
522                 dontmatch = FALSE;
523                 casesens = FALSE;
524
525                 /* ~ and ! mean logical NOT */
526                 if (*cmd_start == '~' || *cmd_start == '!')
527                 {
528                         dontmatch = TRUE;
529                         cmd_start++;
530                 }
531                 /* % means case sensitive match */
532                 if (*cmd_start == '%')
533                 {
534                         casesens = TRUE;
535                         cmd_start++;
536                 }
537
538                 /* find matching abbreviation */
539                 for (i = 0; cmds[i].command; i++) {
540                         if (!strcmp(cmd_start, cmds[i].abbreviated)) {
541                                 /* restore character */
542                                 *cmd_end = save_char;
543
544                                 /* copy command */
545                                 if (matcherstr->len > 0) {
546                                         g_string_append(matcherstr, " ");
547                                 }
548                                 if (dontmatch)
549                                         g_string_append(matcherstr, "~");
550                                 g_string_append(matcherstr, cmds[i].command);
551                                 g_string_append(matcherstr, " ");
552
553                                 /* stop if no params required */
554                                 if (cmds[i].numparams == 0)
555                                         break;
556
557                                 /* extract a parameter, allow quotes */
558                                 while (*cmd_end && isspace((guchar)*cmd_end))
559                                         cmd_end++;
560
561                                 cmd_start = cmd_end;
562                                 if (*cmd_start == '"') {
563                                         term_char = '"';
564                                         cmd_end++;
565                                 }
566                                 else
567                                         term_char = ' ';
568
569                                 /* extract actual parameter */
570                                 while ((*cmd_end) && (*cmd_end != term_char))
571                                         cmd_end++;
572
573                                 if (*cmd_end == '"')
574                                         cmd_end++;
575
576                                 save_char = *cmd_end;
577                                 *cmd_end = '\0';
578
579                                 if (cmds[i].qualifier) {
580                                         if (casesens)
581                                                 g_string_append(matcherstr, "regexp ");
582                                         else
583                                                 g_string_append(matcherstr, "regexpcase ");
584                                 }
585
586                                 /* do we need to add quotes ? */
587                                 if (cmds[i].quotes && term_char != '"')
588                                         g_string_append(matcherstr, "\"");
589
590                                 /* copy actual parameter */
591                                 g_string_append(matcherstr, cmd_start);
592
593                                 /* do we need to add quotes ? */
594                                 if (cmds[i].quotes && term_char != '"')
595                                         g_string_append(matcherstr, "\"");
596
597                                 /* restore original character */
598                                 *cmd_end = save_char;
599
600                                 break;
601                         }
602                 }
603
604                 if (*cmd_end)
605                         cmd_end++;
606                 cmd_start = cmd_end;
607         }
608
609         g_free(copy_str);
610
611         /* return search string if no match is found to allow 
612            all available filtering expressions in quicksearch */
613         if (matcherstr->len > 0) returnstr = matcherstr->str;
614         else returnstr = g_strdup(search_string);
615
616         g_string_free(matcherstr, FALSE);
617         return returnstr;
618 }
619
620 static void quicksearch_set_running(QuickSearch *quicksearch, gboolean run)
621 {
622         quicksearch->running = run;
623 }
624
625 gboolean quicksearch_is_running(QuickSearch *quicksearch) 
626 {
627         return quicksearch->running;
628 }
629