]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-live-search.c
individual_view_drag_end: remove the auto scroll
[empathy.git] / libempathy-gtk / empathy-live-search.c
1 /*
2  * Copyright (C) 2010 Collabora Ltd.
3  * Copyright (C) 2007-2010 Nokia Corporation.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Felix Kaser <felix.kaser@collabora.co.uk>
20  *          Xavier Claessens <xavier.claessens@collabora.co.uk>
21  *          Claudio Saavedra <csaavedra@igalia.com>
22  */
23
24 #include <config.h>
25 #include <string.h>
26
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29
30 #include <libempathy/empathy-utils.h>
31
32 #include "empathy-live-search.h"
33
34 G_DEFINE_TYPE (EmpathyLiveSearch, empathy_live_search, GTK_TYPE_HBOX)
35
36 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLiveSearch)
37
38 typedef struct
39 {
40   GtkWidget *search_entry;
41   GtkWidget *hook_widget;
42
43   GPtrArray *stripped_words;
44 } EmpathyLiveSearchPriv;
45
46 enum
47 {
48   PROP_0,
49   PROP_HOOK_WIDGET,
50   PROP_TEXT
51 };
52
53 enum
54 {
55   ACTIVATE,
56   KEYNAV,
57   LAST_SIGNAL
58 };
59
60 static guint signals[LAST_SIGNAL];
61
62 static void live_search_hook_widget_destroy_cb (GtkWidget *object,
63     gpointer user_data);
64
65 /**
66  * stripped_char:
67  *
68  * Returns a stripped version of @ch, removing any case, accentuation
69  * mark, or any special mark on it.
70  **/
71 static gunichar
72 stripped_char (gunichar ch)
73 {
74   gunichar retval = 0;
75   GUnicodeType utype;
76
77   utype = g_unichar_type (ch);
78
79   switch (utype)
80     {
81     case G_UNICODE_CONTROL:
82     case G_UNICODE_FORMAT:
83     case G_UNICODE_UNASSIGNED:
84     case G_UNICODE_NON_SPACING_MARK:
85     case G_UNICODE_COMBINING_MARK:
86     case G_UNICODE_ENCLOSING_MARK:
87       /* Ignore those */
88       break;
89     case G_UNICODE_PRIVATE_USE:
90     case G_UNICODE_SURROGATE:
91     case G_UNICODE_LOWERCASE_LETTER:
92     case G_UNICODE_MODIFIER_LETTER:
93     case G_UNICODE_OTHER_LETTER:
94     case G_UNICODE_TITLECASE_LETTER:
95     case G_UNICODE_UPPERCASE_LETTER:
96     case G_UNICODE_DECIMAL_NUMBER:
97     case G_UNICODE_LETTER_NUMBER:
98     case G_UNICODE_OTHER_NUMBER:
99     case G_UNICODE_CONNECT_PUNCTUATION:
100     case G_UNICODE_DASH_PUNCTUATION:
101     case G_UNICODE_CLOSE_PUNCTUATION:
102     case G_UNICODE_FINAL_PUNCTUATION:
103     case G_UNICODE_INITIAL_PUNCTUATION:
104     case G_UNICODE_OTHER_PUNCTUATION:
105     case G_UNICODE_OPEN_PUNCTUATION:
106     case G_UNICODE_CURRENCY_SYMBOL:
107     case G_UNICODE_MODIFIER_SYMBOL:
108     case G_UNICODE_MATH_SYMBOL:
109     case G_UNICODE_OTHER_SYMBOL:
110     case G_UNICODE_LINE_SEPARATOR:
111     case G_UNICODE_PARAGRAPH_SEPARATOR:
112     case G_UNICODE_SPACE_SEPARATOR:
113     default:
114       ch = g_unichar_tolower (ch);
115       g_unichar_fully_decompose (ch, FALSE, &retval, 1);
116     }
117
118   return retval;
119 }
120
121 static void
122 append_word (GPtrArray **word_array,
123     GString **word)
124 {
125   if (*word != NULL)
126     {
127       if (*word_array == NULL)
128         *word_array = g_ptr_array_new_with_free_func (g_free);
129       g_ptr_array_add (*word_array, g_string_free (*word, FALSE));
130       *word = NULL;
131     }
132 }
133
134 GPtrArray *
135 empathy_live_search_strip_utf8_string (const gchar *string)
136 {
137   GPtrArray *word_array = NULL;
138   GString *word = NULL;
139   const gchar *p;
140
141   if (EMP_STR_EMPTY (string))
142     return NULL;
143
144   for (p = string; *p != '\0'; p = g_utf8_next_char (p))
145     {
146       gunichar sc;
147
148       /* Make the char lower-case, remove its accentuation marks, and ignore it
149        * if it is just unicode marks */
150       sc = stripped_char (g_utf8_get_char (p));
151       if (sc == 0)
152         continue;
153
154       /* If it is not alpha-num, it is separator between words */
155       if (!g_unichar_isalnum (sc))
156         {
157           append_word (&word_array, &word);
158           continue;
159         }
160
161       /* It is alpha-num, append this char to current word, or start new word */
162       if (word == NULL)
163         word = g_string_new (NULL);
164       g_string_append_unichar (word, sc);
165     }
166
167   append_word (&word_array, &word);
168
169   return word_array;
170 }
171
172 static gboolean
173 live_search_match_prefix (const gchar *string,
174     const gchar *prefix)
175 {
176   const gchar *p;
177   const gchar *prefix_p;
178   gboolean next_word = FALSE;
179
180   if (prefix == NULL || prefix[0] == 0)
181     return TRUE;
182
183   if (EMP_STR_EMPTY (string))
184     return FALSE;
185
186   prefix_p = prefix;
187   for (p = string; *p != '\0'; p = g_utf8_next_char (p))
188     {
189       gunichar sc;
190
191       /* Make the char lower-case, remove its accentuation marks, and ignore it
192        * if it is just unicode marks */
193       sc = stripped_char (g_utf8_get_char (p));
194       if (sc == 0)
195         continue;
196
197       /* If we want to go to next word, ignore alpha-num chars */
198       if (next_word && g_unichar_isalnum (sc))
199         continue;
200       next_word = FALSE;
201
202       /* Ignore word separators */
203       if (!g_unichar_isalnum (sc))
204         continue;
205
206       /* If this char does not match prefix_p, go to next word and start again
207        * from the beginning of prefix */
208       if (sc != g_utf8_get_char (prefix_p))
209         {
210           next_word = TRUE;
211           prefix_p = prefix;
212           continue;
213         }
214
215       /* prefix_p match, verify to next char. If this was the last of prefix,
216        * it means it completely machted and we are done. */
217       prefix_p = g_utf8_next_char (prefix_p);
218       if (*prefix_p == '\0')
219         return TRUE;
220     }
221
222   return FALSE;
223 }
224
225 gboolean
226 empathy_live_search_match_words (const gchar *string,
227     GPtrArray *words)
228 {
229   guint i;
230
231   if (words == NULL)
232     return TRUE;
233
234   for (i = 0; i < words->len; i++)
235     if (!live_search_match_prefix (string, g_ptr_array_index (words, i)))
236       return FALSE;
237
238   return TRUE;
239 }
240
241 static gboolean
242 fire_key_navigation_sig (EmpathyLiveSearch *self,
243     GdkEventKey *event)
244 {
245   gboolean ret;
246
247   g_signal_emit (self, signals[KEYNAV], 0, event, &ret);
248   return ret;
249 }
250
251 static gboolean
252 live_search_entry_key_pressed_cb (GtkEntry *entry,
253     GdkEventKey *event,
254     gpointer user_data)
255 {
256   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (user_data);
257
258   /* if esc key pressed, hide the search */
259   if (event->keyval == GDK_KEY_Escape)
260     {
261       gtk_widget_hide (GTK_WIDGET (self));
262       return TRUE;
263     }
264
265   /* emit key navigation signal, so other widgets can respond to it properly */
266   if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down
267       || event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down)
268      {
269        return fire_key_navigation_sig (self, event);
270      }
271
272   if (event->keyval == GDK_KEY_Home || event->keyval == GDK_KEY_End ||
273       event->keyval == GDK_KEY_space)
274     {
275       /* If the live search is visible, the entry should catch the Home/End
276        * and space events */
277       if (!gtk_widget_get_visible (GTK_WIDGET (self)))
278         {
279           return fire_key_navigation_sig (self, event);
280         }
281     }
282
283   return FALSE;
284 }
285
286 static void
287 live_search_text_changed (GtkEntry *entry,
288     gpointer user_data)
289 {
290   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (user_data);
291   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
292   const gchar *text;
293
294   text = gtk_entry_get_text (entry);
295
296   if (EMP_STR_EMPTY (text))
297     gtk_widget_hide (GTK_WIDGET (self));
298   else
299     gtk_widget_show (GTK_WIDGET (self));
300
301   if (priv->stripped_words != NULL)
302     g_ptr_array_unref (priv->stripped_words);
303
304   priv->stripped_words = empathy_live_search_strip_utf8_string (text);
305
306   g_object_notify (G_OBJECT (self), "text");
307 }
308
309 static void
310 live_search_close_pressed (GtkEntry *entry,
311     GtkEntryIconPosition icon_pos,
312     GdkEvent *event,
313     gpointer user_data)
314 {
315   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (user_data);
316
317   gtk_widget_hide (GTK_WIDGET (self));
318 }
319
320 static gboolean
321 live_search_key_press_event_cb (GtkWidget *widget,
322     GdkEventKey *event,
323     gpointer user_data)
324 {
325   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (user_data);
326   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
327   GdkEvent *new_event;
328   gboolean ret;
329
330   /* dont forward this event to the entry, else the event is consumed by the
331    * entry and does not close the window */
332   if (!gtk_widget_get_visible (GTK_WIDGET (self)) &&
333       event->keyval == GDK_KEY_Escape)
334     return FALSE;
335
336   /* do not show the search if CTRL and/or ALT are pressed with a key
337    * this is needed, because otherwise the CTRL + F accel would not work,
338    * because the entry consumes it */
339   if (event->state & (GDK_MOD1_MASK | GDK_CONTROL_MASK) ||
340       event->keyval == GDK_KEY_Control_L ||
341       event->keyval == GDK_KEY_Control_R)
342     return FALSE;
343
344   /* dont forward the up/down and Page Up/Down arrow keys to the entry,
345    * they are needed for navigation in the treeview and are not needed in
346    * the search entry */
347    if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down ||
348        event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down)
349      return FALSE;
350
351    if (event->keyval == GDK_KEY_Home || event->keyval == GDK_KEY_End ||
352        event->keyval == GDK_KEY_space)
353      {
354        /* Home/End and space keys have to be forwarded to the entry only if
355         * the live search is visible (to move the cursor inside the entry). */
356        if (!gtk_widget_get_visible (GTK_WIDGET (self)))
357          return FALSE;
358      }
359
360   /* realize the widget if it is not realized yet */
361   gtk_widget_realize (priv->search_entry);
362   if (!gtk_widget_has_focus (priv->search_entry))
363     {
364       gtk_widget_grab_focus (priv->search_entry);
365       gtk_editable_set_position (GTK_EDITABLE (priv->search_entry), -1);
366     }
367
368   /* forward the event to the search entry */
369   new_event = gdk_event_copy ((GdkEvent *) event);
370   ret = gtk_widget_event (priv->search_entry, new_event);
371   gdk_event_free (new_event);
372
373   return ret;
374 }
375
376 static void
377 live_search_entry_activate_cb (GtkEntry *entry,
378     EmpathyLiveSearch *self)
379 {
380   g_signal_emit (self, signals[ACTIVATE], 0);
381 }
382
383 static void
384 live_search_release_hook_widget (EmpathyLiveSearch *self)
385 {
386   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
387
388   /* remove old handlers if old source was not null */
389   if (priv->hook_widget != NULL)
390     {
391       g_signal_handlers_disconnect_by_func (priv->hook_widget,
392           live_search_key_press_event_cb, self);
393       g_signal_handlers_disconnect_by_func (priv->hook_widget,
394           live_search_hook_widget_destroy_cb, self);
395       g_object_unref (priv->hook_widget);
396       priv->hook_widget = NULL;
397     }
398 }
399
400 static void
401 live_search_hook_widget_destroy_cb (GtkWidget *object,
402     gpointer user_data)
403 {
404   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (user_data);
405
406   /* unref the hook widget and hide search */
407   gtk_widget_hide (GTK_WIDGET (self));
408   live_search_release_hook_widget (self);
409 }
410
411 static void
412 live_search_dispose (GObject *obj)
413 {
414   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (obj);
415
416   live_search_release_hook_widget (self);
417
418   if (G_OBJECT_CLASS (empathy_live_search_parent_class)->dispose != NULL)
419     G_OBJECT_CLASS (empathy_live_search_parent_class)->dispose (obj);
420 }
421
422 static void
423 live_search_finalize (GObject *obj)
424 {
425   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (obj);
426   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
427
428   if (priv->stripped_words != NULL)
429     g_ptr_array_unref (priv->stripped_words);
430
431   if (G_OBJECT_CLASS (empathy_live_search_parent_class)->finalize != NULL)
432     G_OBJECT_CLASS (empathy_live_search_parent_class)->finalize (obj);
433 }
434
435 static void
436 live_search_get_property (GObject *object,
437     guint param_id,
438     GValue *value,
439     GParamSpec *pspec)
440 {
441   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (object);
442
443   switch (param_id)
444     {
445     case PROP_HOOK_WIDGET:
446       g_value_set_object (value, empathy_live_search_get_hook_widget (self));
447       break;
448     case PROP_TEXT:
449       g_value_set_string (value, empathy_live_search_get_text (self));
450       break;
451     default:
452       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
453       break;
454     }
455 }
456
457 static void
458 live_search_set_property (GObject *object,
459     guint param_id,
460     const GValue *value,
461     GParamSpec *pspec)
462 {
463   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (object);
464
465   switch (param_id) {
466   case PROP_HOOK_WIDGET:
467     empathy_live_search_set_hook_widget (self, g_value_get_object (value));
468     break;
469   case PROP_TEXT:
470     empathy_live_search_set_text (self, g_value_get_string (value));
471     break;
472   default:
473     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
474     break;
475   };
476 }
477
478 static void
479 live_search_unmap (GtkWidget *widget)
480 {
481   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (widget);
482   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
483
484   GTK_WIDGET_CLASS (empathy_live_search_parent_class)->unmap (widget);
485
486   /* unmap can happen if a parent gets hidden, in that case we want to hide
487    * the live search as well, so when it gets mapped again, the live search
488    * won't be shown. */
489   gtk_widget_hide (widget);
490
491   gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
492   gtk_widget_grab_focus (priv->hook_widget);
493 }
494
495 static void
496 live_search_show (GtkWidget *widget)
497 {
498   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (widget);
499   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
500
501   if (!gtk_widget_has_focus (priv->search_entry))
502     gtk_widget_grab_focus (priv->search_entry);
503
504   GTK_WIDGET_CLASS (empathy_live_search_parent_class)->show (widget);
505 }
506
507 static void
508 live_search_grab_focus (GtkWidget *widget)
509 {
510   EmpathyLiveSearch *self = EMPATHY_LIVE_SEARCH (widget);
511   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
512
513   if (!gtk_widget_has_focus (priv->search_entry))
514     {
515       gtk_widget_grab_focus (priv->search_entry);
516       gtk_editable_set_position (GTK_EDITABLE (priv->search_entry), -1);
517     }
518 }
519
520 static void
521 empathy_live_search_class_init (EmpathyLiveSearchClass *klass)
522 {
523   GObjectClass *object_class = (GObjectClass *) klass;
524   GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
525   GParamSpec *param_spec;
526
527   object_class->finalize = live_search_finalize;
528   object_class->dispose = live_search_dispose;
529   object_class->get_property = live_search_get_property;
530   object_class->set_property = live_search_set_property;
531
532   widget_class->unmap = live_search_unmap;
533   widget_class->show = live_search_show;
534   widget_class->grab_focus = live_search_grab_focus;
535
536   signals[ACTIVATE] = g_signal_new ("activate",
537       G_TYPE_FROM_CLASS (object_class),
538       G_SIGNAL_RUN_LAST,
539       0,
540       NULL, NULL,
541       g_cclosure_marshal_generic,
542       G_TYPE_NONE, 0);
543
544   signals[KEYNAV] = g_signal_new ("key-navigation",
545       G_TYPE_FROM_CLASS (object_class),
546       G_SIGNAL_RUN_LAST,
547       0,
548       g_signal_accumulator_true_handled, NULL,
549       g_cclosure_marshal_generic,
550       G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
551
552   param_spec = g_param_spec_object ("hook-widget", "Live Search Hook Widget",
553       "The live search catches key-press-events on this widget",
554       GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
555   g_object_class_install_property (object_class, PROP_HOOK_WIDGET,
556       param_spec);
557
558   param_spec = g_param_spec_string ("text", "Live Search Text",
559       "The text of the live search entry",
560       "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
561   g_object_class_install_property (object_class, PROP_TEXT, param_spec);
562
563   g_type_class_add_private (klass, sizeof (EmpathyLiveSearchPriv));
564 }
565
566 static void
567 empathy_live_search_init (EmpathyLiveSearch *self)
568 {
569   EmpathyLiveSearchPriv *priv =
570     G_TYPE_INSTANCE_GET_PRIVATE ((self), EMPATHY_TYPE_LIVE_SEARCH,
571         EmpathyLiveSearchPriv);
572
573   gtk_widget_set_no_show_all (GTK_WIDGET (self), TRUE);
574
575   priv->search_entry = gtk_entry_new ();
576   gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
577       GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLOSE);
578   gtk_entry_set_icon_activatable (GTK_ENTRY (priv->search_entry),
579       GTK_ENTRY_ICON_SECONDARY, TRUE);
580   gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->search_entry),
581       GTK_ENTRY_ICON_SECONDARY, TRUE);
582   gtk_widget_show (priv->search_entry);
583
584   gtk_box_pack_start (GTK_BOX (self), priv->search_entry, TRUE, TRUE, 0);
585
586   g_signal_connect (priv->search_entry, "icon_release",
587       G_CALLBACK (live_search_close_pressed), self);
588   g_signal_connect (priv->search_entry, "changed",
589       G_CALLBACK (live_search_text_changed), self);
590   g_signal_connect (priv->search_entry, "key-press-event",
591       G_CALLBACK (live_search_entry_key_pressed_cb), self);
592   g_signal_connect (priv->search_entry, "activate",
593       G_CALLBACK (live_search_entry_activate_cb), self);
594
595   priv->hook_widget = NULL;
596
597   self->priv = priv;
598 }
599
600 GtkWidget *
601 empathy_live_search_new (GtkWidget *hook)
602 {
603   g_return_val_if_fail (hook == NULL || GTK_IS_WIDGET (hook), NULL);
604
605   return g_object_new (EMPATHY_TYPE_LIVE_SEARCH,
606       "hook-widget", hook,
607       NULL);
608 }
609
610 /* public methods */
611
612 GtkWidget *
613 empathy_live_search_get_hook_widget (EmpathyLiveSearch *self)
614 {
615   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
616
617   g_return_val_if_fail (EMPATHY_IS_LIVE_SEARCH (self), NULL);
618
619   return priv->hook_widget;
620 }
621
622 void
623 empathy_live_search_set_hook_widget (EmpathyLiveSearch *self,
624     GtkWidget *hook)
625 {
626   EmpathyLiveSearchPriv *priv;
627
628   g_return_if_fail (EMPATHY_IS_LIVE_SEARCH (self));
629   g_return_if_fail (hook == NULL || GTK_IS_WIDGET (hook));
630
631   priv = GET_PRIV (self);
632
633   /* release the actual widget */
634   live_search_release_hook_widget (self);
635
636   /* connect handlers if new source is not null */
637   if (hook != NULL)
638     {
639       priv->hook_widget = g_object_ref (hook);
640       g_signal_connect (priv->hook_widget, "key-press-event",
641           G_CALLBACK (live_search_key_press_event_cb),
642           self);
643       g_signal_connect (priv->hook_widget, "destroy",
644           G_CALLBACK (live_search_hook_widget_destroy_cb),
645           self);
646     }
647 }
648
649 const gchar *
650 empathy_live_search_get_text (EmpathyLiveSearch *self)
651 {
652   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
653
654   g_return_val_if_fail (EMPATHY_IS_LIVE_SEARCH (self), NULL);
655
656   return gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
657 }
658
659 void
660 empathy_live_search_set_text (EmpathyLiveSearch *self,
661     const gchar *text)
662 {
663   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
664
665   g_return_if_fail (EMPATHY_IS_LIVE_SEARCH (self));
666   g_return_if_fail (text != NULL);
667
668   gtk_entry_set_text (GTK_ENTRY (priv->search_entry), text);
669 }
670
671 /**
672  * empathy_live_search_match:
673  * @self: a #EmpathyLiveSearch
674  * @string: a string where to search, must be valid UTF-8.
675  *
676  * Search if one of the words in @string string starts with the current text
677  * of @self.
678  *
679  * Searching for "aba" in "Abasto" will match, searching in "Moraba" will not,
680  * and searching in "A tool (abacus)" will do.
681  *
682  * The match is not case-sensitive, and regardless of the accentuation marks.
683  *
684  * Returns: %TRUE if a match is found, %FALSE otherwise.
685  *
686  **/
687 gboolean
688 empathy_live_search_match (EmpathyLiveSearch *self,
689     const gchar *string)
690 {
691   EmpathyLiveSearchPriv *priv;
692
693   g_return_val_if_fail (EMPATHY_IS_LIVE_SEARCH (self), FALSE);
694
695   priv = GET_PRIV (self);
696
697   return empathy_live_search_match_words (string, priv->stripped_words);
698 }
699
700 gboolean
701 empathy_live_search_match_string (const gchar *string,
702     const gchar *prefix)
703 {
704   GPtrArray *words;
705   gboolean match;
706
707   words = empathy_live_search_strip_utf8_string (prefix);
708   match = empathy_live_search_match_words (string, words);
709   if (words != NULL)
710     g_ptr_array_unref (words);
711
712   return match;
713 }
714
715 GPtrArray *
716 empathy_live_search_get_words (EmpathyLiveSearch *self)
717 {
718   EmpathyLiveSearchPriv *priv = GET_PRIV (self);
719
720   return priv->stripped_words;
721 }