98f9b6be89fe1918261afc4d4dcf0ae0aafdcb4a
[hildon] / src / hildon-find-toolbar.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-find-toolbar
27  * @short_description: A special toolbar to be used with HildonAppView
28  * @see_also: #HildonAppView
29  *
30  * HildonFindToolbar is a predefined toolbar for text searching purpose. 
31  * It contains a GtkListStore which has the text items that the user has 
32  * searched. But once the application is terminated, or HildonFindToolbar 
33  * is trashed. Programmer is responsible for getting the GtkListStore through 
34  * property "list", if he/she wants to use the information in the future.
35  * And through the same property, programmer is able to set the GtkListStore. 
36  * Note, once the search button is pressed, string in the GtkComboxEntry is 
37  * automatically added to the existing model, unless it is empty.
38  */    
39
40 #include                                        <config.h>
41 #include                                        "hildon-find-toolbar.h"
42 #include                                        "hildon-defines.h"
43 #include                                        <gdk/gdkkeysyms.h>
44 #include                                        <gtk/gtklabel.h>
45 #include                                        <gtk/gtkentry.h>
46 #include                                        <gtk/gtkbutton.h>
47 #include                                        <gtk/gtktoolbutton.h>
48 #include                                        <gtk/gtktoolitem.h>
49 #include                                        <gtk/gtkcomboboxentry.h>
50 #include                                        <gtk/gtkseparatortoolitem.h>
51 #include                                        <string.h>
52 #include                                        <libintl.h>
53 #include                                        "hildon-find-toolbar-private.h"
54
55 #define                                         _(String) \
56                                                 dgettext(PACKAGE, String)
57
58 /*same define as gtkentry.c as entry will further handle this*/
59
60 #define                                         MAX_SIZE G_MAXUSHORT
61
62 #define                                         FIND_LABEL_XPADDING 6
63
64 #define                                         FIND_LABEL_YPADDING 0
65
66 static GtkTreeModel*
67 hildon_find_toolbar_get_list_model              (HildonFindToolbarPrivate *priv);
68
69 static GtkEntry*
70 hildon_find_toolbar_get_entry                   (HildonFindToolbarPrivate *priv);
71
72 static gboolean
73 hildon_find_toolbar_filter                      (GtkTreeModel *model,
74                                                  GtkTreeIter *iter,
75                                                  gpointer self);
76
77 static void
78 hildon_find_toolbar_apply_filter                (HildonFindToolbar *self,  
79                                                  GtkTreeModel *model);
80
81 static void
82 hildon_find_toolbar_get_property                (GObject *object,
83                                                  guint prop_id,
84                                                  GValue *value,
85                                                  GParamSpec *pspec);
86
87 static void
88 hildon_find_toolbar_set_property                (GObject *object,
89                                                  guint prop_id,
90                                                  const GValue *value,
91                                                  GParamSpec *pspec);
92
93 static gboolean
94 hildon_find_toolbar_find_string                 (HildonFindToolbar *self,
95                                                  GtkTreeIter *iter,
96                                                  gint column,
97                                                  const gchar *string);
98
99 static gboolean
100 hildon_find_toolbar_history_append              (HildonFindToolbar *self,
101                                                  gpointer data);
102
103 static void
104 hildon_find_toolbar_emit_search                 (GtkButton *button, 
105                                                  gpointer self);
106
107 static void
108 hildon_find_toolbar_emit_close                  (GtkButton *button, 
109                                                  gpointer self);
110
111 static void
112 hildon_find_toolbar_emit_invalid_input          (GtkEntry *entry, 
113                                                  GtkInvalidInputType type, 
114                                                  gpointer self);
115
116 static void
117 hildon_find_toolbar_entry_activate              (GtkWidget *widget,
118                                                  gpointer user_data);
119
120 static void
121 hildon_find_toolbar_class_init                  (HildonFindToolbarClass *klass);
122
123 static void
124 hildon_find_toolbar_init                        (HildonFindToolbar *self);
125
126 enum
127 {
128     SEARCH = 0,
129     CLOSE,
130     INVALID_INPUT,
131     HISTORY_APPEND,
132
133     LAST_SIGNAL
134 };
135
136 enum
137 {
138     PROP_0,
139     PROP_LABEL = 1,
140     PROP_PREFIX,
141     PROP_LIST,
142     PROP_COLUMN,
143     PROP_MAX,
144     PROP_HISTORY_LIMIT
145 };
146
147 static guint                                    HildonFindToolbar_signal [LAST_SIGNAL] = {0};
148
149 GType G_GNUC_CONST
150 hildon_find_toolbar_get_type                    (void)
151 {
152     static GType find_toolbar_type = 0;
153
154     if (! find_toolbar_type) {
155         static const GTypeInfo find_toolbar_info = {
156             sizeof(HildonFindToolbarClass),
157             NULL,       /* base_init */
158             NULL,       /* base_finalize */
159             (GClassInitFunc) hildon_find_toolbar_class_init,
160             NULL,       /* class_finalize */
161             NULL,       /* class_data */
162             sizeof(HildonFindToolbar),
163             0,  /* n_preallocs */
164             (GInstanceInitFunc) hildon_find_toolbar_init,
165         };
166         find_toolbar_type = g_type_register_static (GTK_TYPE_TOOLBAR,
167                 "HildonFindToolbar",
168                 &find_toolbar_info, 0);
169     }
170
171     return find_toolbar_type;
172 }
173
174 static GtkTreeModel*
175 hildon_find_toolbar_get_list_model              (HildonFindToolbarPrivate *priv)
176 {
177     GtkTreeModel *filter_model =
178         gtk_combo_box_get_model (GTK_COMBO_BOX (priv->entry_combo_box));
179
180     return filter_model == NULL ? NULL :
181         gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
182 }
183
184 static GtkEntry*
185 hildon_find_toolbar_get_entry                   (HildonFindToolbarPrivate *priv)
186 {
187     return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->entry_combo_box)));
188 }
189
190 static gboolean
191 hildon_find_toolbar_filter                      (GtkTreeModel *model,
192                                                  GtkTreeIter *iter,
193                                                  gpointer self)
194 {
195     GtkTreePath *path;
196     const gint *indices;
197     gint n;
198     gint limit;
199     gint total;
200
201     total = gtk_tree_model_iter_n_children (model, NULL);
202     g_object_get (self, "history_limit", &limit, NULL);
203     path = gtk_tree_model_get_path (model, iter);
204     indices = gtk_tree_path_get_indices (path);
205
206     /* set the row's index, list store has only one level */
207     n = indices [0];
208     gtk_tree_path_free (path);
209
210     /*if the row is among the latest "history_limit" additions of the 
211      * model, then we show it */
212     if( (total - limit <= n) && (n < total) )
213         return TRUE;
214     else
215         return FALSE;
216 }
217
218 static void
219 hildon_find_toolbar_apply_filter                (HildonFindToolbar *self,  
220                                                  GtkTreeModel *model)
221 {
222     GtkTreeModel *filter;
223     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
224     g_assert (priv);
225
226     /* Create a filter for the given model. Its only purpose is to hide
227        the oldest entries so only "history_limit" entries are visible. */
228     filter = gtk_tree_model_filter_new (model, NULL);
229
230     gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER(filter), 
231             hildon_find_toolbar_filter,
232             self, NULL);
233
234     gtk_combo_box_set_model (GTK_COMBO_BOX (priv->entry_combo_box), filter);
235
236     /* ComboBox keeps the only needed reference to the filter */
237     g_object_unref (filter);
238 }
239
240 static void
241 hildon_find_toolbar_get_property                (GObject *object,
242                                                  guint prop_id,
243                                                  GValue *value,
244                                                  GParamSpec *pspec)
245 {
246     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
247     g_assert (priv);
248
249     const gchar *string;
250     gint c_n, max_len;
251
252     switch (prop_id)
253     {
254         case PROP_LABEL:
255             string = gtk_label_get_text (GTK_LABEL (priv->label));
256             g_value_set_string (value, string);
257             break;
258
259         case PROP_PREFIX:
260             string = gtk_entry_get_text (hildon_find_toolbar_get_entry(priv));
261             g_value_set_string (value, string);
262             break;
263
264         case PROP_LIST:
265             g_value_set_object (value, hildon_find_toolbar_get_list_model(priv));
266             break;
267
268         case PROP_COLUMN:
269             c_n = gtk_combo_box_entry_get_text_column (priv->entry_combo_box);
270             g_value_set_int (value, c_n);
271             break;
272
273         case PROP_MAX:
274             max_len = gtk_entry_get_max_length (hildon_find_toolbar_get_entry(priv));
275             g_value_set_int (value, max_len);
276             break;
277
278         case PROP_HISTORY_LIMIT:
279             g_value_set_int (value, priv->history_limit);
280             break;
281
282         default:
283             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
284             break;
285     }
286 }
287
288 static void
289 hildon_find_toolbar_set_property                (GObject *object,
290                                                  guint prop_id,
291                                                  const GValue *value,
292                                                  GParamSpec *pspec)
293 {
294     HildonFindToolbar *self = HILDON_FIND_TOOLBAR(object);
295     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
296     g_assert (priv);
297
298     GtkTreeModel *model;
299     const gchar *string;
300
301     switch (prop_id)
302     {
303         case PROP_LABEL:
304             string = g_value_get_string (value);   
305             gtk_label_set_text (GTK_LABEL (priv->label), string);
306             break;
307
308         case PROP_PREFIX:
309             string = g_value_get_string (value);
310             gtk_entry_set_text (hildon_find_toolbar_get_entry(priv), string);
311             break;
312
313         case PROP_LIST:
314             model = GTK_TREE_MODEL (g_value_get_object(value));
315             hildon_find_toolbar_apply_filter (self, model);
316             break;
317
318         case PROP_COLUMN:
319             gtk_combo_box_entry_set_text_column (priv->entry_combo_box,
320                     g_value_get_int (value));
321             break;
322
323         case PROP_MAX:
324             gtk_entry_set_max_length (hildon_find_toolbar_get_entry(priv),
325                     g_value_get_int (value));
326             break;
327
328         case PROP_HISTORY_LIMIT:
329             priv->history_limit = g_value_get_int (value);
330
331             /* Re-apply the history limit to the model. */
332             model = hildon_find_toolbar_get_list_model (priv);
333             if (model != NULL)
334             {
335                 /* Note that refilter function doesn't update the status of the
336                    combobox popup arrow, so we'll just recreate the filter. */
337                 hildon_find_toolbar_apply_filter (self, model);
338
339                 if (gtk_combo_box_entry_get_text_column (priv->entry_combo_box) == -1)
340                 {
341                     /* FIXME: This is only for backwards compatibility, although
342                        probably nothing actually relies on it. The behavior was only
343                        an accidental side effect of original code */
344                     gtk_combo_box_entry_set_text_column (priv->entry_combo_box, 0);
345                 }
346             }
347             break;
348
349         default:
350             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
351             break;
352     }
353 }
354
355 static gboolean
356 hildon_find_toolbar_find_string                 (HildonFindToolbar *self,
357                                                  GtkTreeIter *iter,
358                                                  gint column,
359                                                  const gchar *string)
360 {
361     GtkTreeModel *model = NULL;
362     gchar *old_string;
363     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
364     g_assert (priv);
365
366     model = hildon_find_toolbar_get_list_model (priv);
367
368     if (gtk_tree_model_get_iter_first (model, iter))
369     {
370         do {
371             gtk_tree_model_get (model, iter, column, &old_string, -1);
372             if (old_string != NULL && strcmp (string, old_string) == 0)
373             {
374                 /* Found it */
375                 return TRUE;
376             }
377         } while (gtk_tree_model_iter_next (model, iter));
378     }
379
380     return FALSE;
381 }
382
383 static gboolean
384 hildon_find_toolbar_history_append              (HildonFindToolbar *self,
385                                                  gpointer data) 
386 {
387     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
388     g_assert (priv);
389
390     gchar *string;
391     gint column = 0;
392     GtkTreeModel *model = NULL;
393     GtkListStore *list = NULL;
394     GtkTreeIter iter;
395     gboolean self_create = FALSE;
396
397     g_object_get (self, "prefix", &string, NULL);
398
399     if (*string == '\0')
400     {
401         /* empty prefix, ignore */
402         g_free (string);
403         return TRUE;
404     }
405
406
407     /* If list store is set, get it */
408     model = hildon_find_toolbar_get_list_model(priv);
409     if(model != NULL)
410     {
411         list = GTK_LIST_STORE (model);
412         g_object_get(self, "column", &column, NULL);
413
414         if (column < 0)
415         {
416             /* Column number is -1 if "column" property hasn't been set but
417                "list" property is. */
418             g_free (string);
419             return TRUE;
420         }
421
422         /* Latest string is always the first one in list. If the string
423            already exists, remove it so there are no duplicates in list. */
424         if (hildon_find_toolbar_find_string (self, &iter, column, string))
425             gtk_list_store_remove (list, &iter);
426     }
427     else
428     {
429         /* No list store set. Create our own. */
430         list = gtk_list_store_new (1, G_TYPE_STRING);
431         model = GTK_TREE_MODEL (list);
432         self_create = TRUE;
433     }
434
435     /* Add the string to first in list */
436     gtk_list_store_append (list, &iter);
437     gtk_list_store_set (list, &iter, column, string, -1);
438
439     if(self_create)
440     {
441         /* Add the created list to ComboBoxEntry */
442         hildon_find_toolbar_apply_filter (self, model);
443         /* ComboBoxEntry keeps the only needed reference to this list */
444         g_object_unref (list);
445
446         /* Set the column only after ComboBoxEntry's model is set
447            in hildon_find_toolbar_apply_filter() */
448         g_object_set (self, "column", 0, NULL);
449     }
450     else
451     {
452         /* Refilter to get the oldest entry hidden from history */
453         gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(
454                     gtk_combo_box_get_model (GTK_COMBO_BOX(priv->entry_combo_box))));
455     }
456
457     g_free (string);
458
459     return TRUE;
460 }
461
462 static void
463 hildon_find_toolbar_emit_search                 (GtkButton *button, 
464                                                  gpointer self)
465 {
466     gboolean rb;
467
468     /* Clicked search button. Perform search and add search prefix to history */
469     g_signal_emit_by_name(self, "search", NULL);
470     g_signal_emit_by_name(self, "history_append", &rb, NULL);
471 }
472
473 static void
474 hildon_find_toolbar_emit_close                  (GtkButton *button, 
475                                                  gpointer self)
476 {
477     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
478     g_assert (priv);
479
480     GtkWidget *entry = gtk_bin_get_child (GTK_BIN (priv->entry_combo_box));
481     if (GTK_WIDGET_HAS_FOCUS (entry))
482     {
483         hildon_gtk_im_context_hide (GTK_ENTRY (entry)->im_context);
484     }
485
486     /* Clicked close button */
487     g_signal_emit_by_name (self, "close", NULL);
488 }
489
490 static void
491 hildon_find_toolbar_emit_invalid_input          (GtkEntry *entry, 
492                                                  GtkInvalidInputType type, 
493                                                  gpointer self)
494 {
495     if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
496         g_signal_emit_by_name (self, "invalid_input", NULL);
497 }
498
499 static void
500 hildon_find_toolbar_entry_activate              (GtkWidget *widget,
501                                                  gpointer user_data)
502 {
503     GtkWidget *find_toolbar = GTK_WIDGET (user_data);
504     gboolean rb;  
505
506     /* NB#40936 stop focus from moving to next widget */
507     g_signal_stop_emission_by_name (widget, "activate");
508
509     g_signal_emit_by_name (find_toolbar, "search", NULL);
510     g_signal_emit_by_name (find_toolbar, "history_append", &rb, NULL);
511 }
512
513 static void
514 hildon_find_toolbar_class_init                  (HildonFindToolbarClass *klass)
515 {
516     GObjectClass *object_class;
517
518     g_type_class_add_private (klass, sizeof(HildonFindToolbarPrivate));
519
520     object_class = G_OBJECT_CLASS(klass);
521
522     object_class->get_property = hildon_find_toolbar_get_property;
523     object_class->set_property = hildon_find_toolbar_set_property;
524
525     klass->history_append = (gpointer) hildon_find_toolbar_history_append;
526
527     g_object_class_install_property(object_class, PROP_LABEL, 
528             g_param_spec_string("label", 
529                 "Label", "Displayed name for"
530                 " find-toolbar",
531                 _("ecdg_ti_find_toolbar_label"),
532                 G_PARAM_READWRITE |
533                 G_PARAM_CONSTRUCT));
534
535     g_object_class_install_property(object_class, PROP_PREFIX, 
536             g_param_spec_string("prefix", 
537                 "Prefix", "Search string", NULL,
538                 G_PARAM_READWRITE));
539
540     g_object_class_install_property(object_class, PROP_LIST,
541             g_param_spec_object("list",
542                 "List"," GtkListStore model where "
543                 "history list is kept",
544                 GTK_TYPE_LIST_STORE,
545                 G_PARAM_READWRITE));
546
547     g_object_class_install_property(object_class, PROP_COLUMN,
548             g_param_spec_int("column",
549                 "Column", "Column number in GtkListStore "
550                 "where history list strings are kept",
551                 0, G_MAXINT,
552                 0, G_PARAM_READWRITE));
553
554     g_object_class_install_property(object_class, PROP_MAX,
555             g_param_spec_int("max_characters",
556                 "Maximum number of characters",
557                 "Maximum number of characters "
558                 "in search string",
559                 0, MAX_SIZE,
560                 0, G_PARAM_READWRITE |
561                 G_PARAM_CONSTRUCT));
562
563     g_object_class_install_property(object_class, PROP_HISTORY_LIMIT,
564             g_param_spec_int("history_limit",
565                 "Maximum number of history items",
566                 "Maximum number of history items "
567                 "in search combobox",
568                 0, G_MAXINT,
569                 5, G_PARAM_READWRITE |
570                 G_PARAM_CONSTRUCT));
571
572     /**
573      * HildonFindToolbar::search:
574      * @toolbar: the toolbar which received the signal
575      * 
576      * Gets emitted when the find button is pressed.
577      */ 
578     HildonFindToolbar_signal[SEARCH] = 
579         g_signal_new(
580                 "search", HILDON_TYPE_FIND_TOOLBAR,
581                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
582                 (HildonFindToolbarClass, search),
583                 NULL, NULL, gtk_marshal_VOID__VOID,
584                 G_TYPE_NONE, 0);
585
586     /**
587      * HildonFindToolbar::close:
588      * @toolbar: the toolbar which received the signal
589      * 
590      * Gets emitted when the close button is pressed.
591      */ 
592     HildonFindToolbar_signal[CLOSE] = 
593         g_signal_new(
594                 "close", HILDON_TYPE_FIND_TOOLBAR,
595                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
596                 (HildonFindToolbarClass, close),
597                 NULL, NULL, gtk_marshal_VOID__VOID,
598                 G_TYPE_NONE, 0);
599
600     /**
601      * HildonFindToolbar::invalid-input:
602      * @toolbar: the toolbar which received the signal
603      * 
604      * Gets emitted when the maximum search prefix length is reached and
605      * user tries to type more.
606      */ 
607     HildonFindToolbar_signal[INVALID_INPUT] = 
608         g_signal_new(
609                 "invalid_input", HILDON_TYPE_FIND_TOOLBAR,
610                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
611                 (HildonFindToolbarClass, invalid_input),
612                 NULL, NULL, gtk_marshal_VOID__VOID,
613                 G_TYPE_NONE, 0);
614
615     /**
616      * HildonFindToolbar::history-append:
617      * @toolbar: the toolbar which received the signal
618      * 
619      * Gets emitted when the current search prefix should be added to history.
620      */ 
621     HildonFindToolbar_signal[HISTORY_APPEND] = 
622         g_signal_new(
623                 "history_append", HILDON_TYPE_FIND_TOOLBAR,
624                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
625                 (HildonFindToolbarClass, history_append),
626                 g_signal_accumulator_true_handled, NULL, 
627                 gtk_marshal_BOOLEAN__VOID,
628                 G_TYPE_BOOLEAN, 0);
629 }
630
631 static void
632 hildon_find_toolbar_init                        (HildonFindToolbar *self)
633 {
634     GtkToolItem *label_container;
635     GtkToolItem *entry_combo_box_container;
636
637     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
638     g_assert (priv);
639
640     /* Create the label */
641     priv->label = gtk_label_new (_("ecdg_ti_find_toolbar_label"));
642
643     gtk_misc_set_padding (GTK_MISC (priv->label), FIND_LABEL_XPADDING,
644             FIND_LABEL_YPADDING);
645
646     label_container = gtk_tool_item_new ();
647     gtk_container_add (GTK_CONTAINER (label_container), 
648             priv->label);
649
650     gtk_widget_show_all (GTK_WIDGET (label_container));
651     gtk_toolbar_insert (GTK_TOOLBAR (self), label_container, -1);
652
653     /* ComboBoxEntry for search prefix string / history list */
654     priv->entry_combo_box = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new ());
655     g_signal_connect (hildon_find_toolbar_get_entry(priv),
656             "invalid_input", 
657             G_CALLBACK(hildon_find_toolbar_emit_invalid_input), self);
658
659     entry_combo_box_container = gtk_tool_item_new ();
660
661     gtk_tool_item_set_expand (entry_combo_box_container, TRUE);
662     gtk_container_add (GTK_CONTAINER (entry_combo_box_container),
663             GTK_WIDGET (priv->entry_combo_box));
664     gtk_widget_show_all(GTK_WIDGET (entry_combo_box_container));
665     gtk_toolbar_insert (GTK_TOOLBAR (self), entry_combo_box_container, -1);
666     g_signal_connect (hildon_find_toolbar_get_entry (priv),
667             "activate",
668             G_CALLBACK(hildon_find_toolbar_entry_activate), self);
669
670     /* Find button */
671     priv->find_button = gtk_tool_button_new (
672             gtk_image_new_from_icon_name ("qgn_toolb_browser_gobutton",
673                 HILDON_ICON_SIZE_TOOLBAR),
674             "Find");
675
676     g_signal_connect (priv->find_button, "clicked",
677             G_CALLBACK(hildon_find_toolbar_emit_search), self);
678     gtk_widget_show_all( GTK_WIDGET(priv->find_button));
679     gtk_toolbar_insert ( GTK_TOOLBAR(self), priv->find_button, -1);
680     if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->find_button)->child) )
681         GTK_WIDGET_UNSET_FLAGS(
682                 GTK_BIN(priv->find_button)->child, GTK_CAN_FOCUS);
683
684     /* Separator */
685     priv->separator = gtk_separator_tool_item_new();
686     gtk_widget_show(GTK_WIDGET(priv->separator));
687     gtk_toolbar_insert (GTK_TOOLBAR(self), priv->separator, -1);
688
689     /* Close button */
690     priv->close_button = gtk_tool_button_new (
691             gtk_image_new_from_icon_name ("qgn_toolb_gene_close",
692                 HILDON_ICON_SIZE_TOOLBAR),
693             "Close");
694     g_signal_connect(priv->close_button, "clicked",
695             G_CALLBACK(hildon_find_toolbar_emit_close), self);
696     gtk_widget_show_all(GTK_WIDGET(priv->close_button));
697     gtk_toolbar_insert (GTK_TOOLBAR(self), priv->close_button, -1);
698     if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->close_button)->child) )
699         GTK_WIDGET_UNSET_FLAGS(
700                 GTK_BIN(priv->close_button)->child, GTK_CAN_FOCUS);
701 }
702
703 /**
704  * hildon_find_toolbar_new:
705  * @label: label for the find_toolbar, NULL to set the label to 
706  *         default "Find"
707  * 
708  * Returns a new HildonFindToolbar.
709  *
710  * Returns: a new HildonFindToolbar
711  */
712
713 GtkWidget*
714 hildon_find_toolbar_new                         (const gchar *label)
715 {
716     GtkWidget *findtoolbar;
717
718     findtoolbar = GTK_WIDGET (g_object_new (HILDON_TYPE_FIND_TOOLBAR, NULL));
719
720     if (label != NULL)
721         g_object_set(findtoolbar, "label", label, NULL);
722
723     return findtoolbar;
724 }
725
726 /**
727  * hildon_find_toolbar_new_with_model
728  * @label: label for the find_toolbar, NULL to set the label to 
729  *         default "Find"
730  * @model: a @GtkListStore
731  * @column: indicating which column the search histry list will 
732  *          retreive string from
733  * 
734  * Returns a new HildonFindToolbar, with a model.
735  *
736  * Returns: a new #HildonFindToolbar
737  */
738 GtkWidget*
739 hildon_find_toolbar_new_with_model              (const gchar *label,
740                                                  GtkListStore *model,
741                                                  gint column)
742 {
743     GtkWidget *findtoolbar;
744
745     findtoolbar = hildon_find_toolbar_new (label);
746
747     g_object_set (findtoolbar, "list", model, "column", column, NULL);
748
749     return findtoolbar;
750 }
751
752 /**
753  * hildon_find_toolbar_highlight_entry
754  * @ftb: find Toolbar whose entry is to be highlighted
755  * @get_focus: if user passes TRUE to this value, then the text in
756  * the entry will not only get highlighted, but also get focused.
757  * 
758  */
759 void
760 hildon_find_toolbar_highlight_entry             (HildonFindToolbar *self,
761                                                  gboolean get_focus)
762 {
763     GtkEntry *entry = NULL;
764     HildonFindToolbarPrivate *priv;
765
766     g_return_if_fail (HILDON_IS_FIND_TOOLBAR (self));
767     priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
768     g_assert (priv);
769
770     entry = hildon_find_toolbar_get_entry (priv);
771
772     gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
773
774     if(get_focus)
775         gtk_widget_grab_focus (GTK_WIDGET (entry));
776 }
777