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