Fixing documentation for the find toolbar.
[hildon] / src / hildon-find-toolbar.c
1 /*
2  * This file is a part of hildon
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 toolbar with a search field
28  * @see_also: #HildonWindow
29  *
30  * HildonFindToolbar is a toolbar that contains a search entry and a dropdown
31  * list with previously searched strings. The list is represented using a 
32  * #GtkListStore and can be accesed using a property 'list'. Entries are added
33  * automatically to the list when the search button is pressed.
34  *
35  */    
36
37 #ifdef                                          HAVE_CONFIG_H
38 #include                                        <config.h>
39 #endif
40
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("hildon-libs", 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 /**
150  * hildon_find_toolbar_get_type:
151  *
152  * Initializes and returns the type of a hildon fond toolbar.
153  *
154  * @Returns: GType of #HildonFindToolbar
155  */
156 GType G_GNUC_CONST
157 hildon_find_toolbar_get_type                    (void)
158 {
159     static GType find_toolbar_type = 0;
160
161     if (! find_toolbar_type) {
162         static const GTypeInfo find_toolbar_info = {
163             sizeof(HildonFindToolbarClass),
164             NULL,       /* base_init */
165             NULL,       /* base_finalize */
166             (GClassInitFunc) hildon_find_toolbar_class_init,
167             NULL,       /* class_finalize */
168             NULL,       /* class_data */
169             sizeof(HildonFindToolbar),
170             0,  /* n_preallocs */
171             (GInstanceInitFunc) hildon_find_toolbar_init,
172         };
173         find_toolbar_type = g_type_register_static (GTK_TYPE_TOOLBAR,
174                 "HildonFindToolbar",
175                 &find_toolbar_info, 0);
176     }
177
178     return find_toolbar_type;
179 }
180
181 static GtkTreeModel*
182 hildon_find_toolbar_get_list_model              (HildonFindToolbarPrivate *priv)
183 {
184     GtkTreeModel *filter_model =
185         gtk_combo_box_get_model (GTK_COMBO_BOX (priv->entry_combo_box));
186
187     return filter_model == NULL ? NULL :
188         gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
189 }
190
191 static GtkEntry*
192 hildon_find_toolbar_get_entry                   (HildonFindToolbarPrivate *priv)
193 {
194     return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->entry_combo_box)));
195 }
196
197 static gboolean
198 hildon_find_toolbar_filter                      (GtkTreeModel *model,
199                                                  GtkTreeIter *iter,
200                                                  gpointer self)
201 {
202     GtkTreePath *path;
203     const gint *indices;
204     gint n;
205     gint limit;
206     gint total;
207
208     total = gtk_tree_model_iter_n_children (model, NULL);
209     g_object_get (self, "history_limit", &limit, NULL);
210     path = gtk_tree_model_get_path (model, iter);
211     indices = gtk_tree_path_get_indices (path);
212
213     /* set the row's index, list store has only one level */
214     n = indices [0];
215     gtk_tree_path_free (path);
216
217     /*if the row is among the latest "history_limit" additions of the 
218      * model, then we show it */
219     if( (total - limit <= n) && (n < total) )
220         return TRUE;
221     else
222         return FALSE;
223 }
224
225 static void
226 hildon_find_toolbar_apply_filter                (HildonFindToolbar *self,  
227                                                  GtkTreeModel *model)
228 {
229     GtkTreeModel *filter;
230     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
231     g_assert (priv);
232
233     /* Create a filter for the given model. Its only purpose is to hide
234        the oldest entries so only "history_limit" entries are visible. */
235     filter = gtk_tree_model_filter_new (model, NULL);
236
237     gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER(filter), 
238             hildon_find_toolbar_filter,
239             self, NULL);
240
241     gtk_combo_box_set_model (GTK_COMBO_BOX (priv->entry_combo_box), filter);
242
243     /* ComboBox keeps the only needed reference to the filter */
244     g_object_unref (filter);
245 }
246
247 static void
248 hildon_find_toolbar_get_property                (GObject *object,
249                                                  guint prop_id,
250                                                  GValue *value,
251                                                  GParamSpec *pspec)
252 {
253     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
254     g_assert (priv);
255
256     const gchar *string;
257     gint c_n, max_len;
258
259     switch (prop_id)
260     {
261         case PROP_LABEL:
262             string = gtk_label_get_text (GTK_LABEL (priv->label));
263             g_value_set_string (value, string);
264             break;
265
266         case PROP_PREFIX:
267             string = gtk_entry_get_text (hildon_find_toolbar_get_entry(priv));
268             g_value_set_string (value, string);
269             break;
270
271         case PROP_LIST:
272             g_value_set_object (value, hildon_find_toolbar_get_list_model(priv));
273             break;
274
275         case PROP_COLUMN:
276             c_n = gtk_combo_box_entry_get_text_column (priv->entry_combo_box);
277             g_value_set_int (value, c_n);
278             break;
279
280         case PROP_MAX:
281             max_len = gtk_entry_get_max_length (hildon_find_toolbar_get_entry(priv));
282             g_value_set_int (value, max_len);
283             break;
284
285         case PROP_HISTORY_LIMIT:
286             g_value_set_int (value, priv->history_limit);
287             break;
288
289         default:
290             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291             break;
292     }
293 }
294
295 static void
296 hildon_find_toolbar_set_property                (GObject *object,
297                                                  guint prop_id,
298                                                  const GValue *value,
299                                                  GParamSpec *pspec)
300 {
301     HildonFindToolbar *self = HILDON_FIND_TOOLBAR(object);
302     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
303     g_assert (priv);
304
305     GtkTreeModel *model;
306     const gchar *string;
307
308     switch (prop_id)
309     {
310         case PROP_LABEL:
311             string = g_value_get_string (value);   
312             gtk_label_set_text (GTK_LABEL (priv->label), string);
313             break;
314
315         case PROP_PREFIX:
316             string = g_value_get_string (value);
317             gtk_entry_set_text (hildon_find_toolbar_get_entry(priv), string);
318             break;
319
320         case PROP_LIST:
321             model = GTK_TREE_MODEL (g_value_get_object(value));
322             hildon_find_toolbar_apply_filter (self, model);
323             break;
324
325         case PROP_COLUMN:
326             gtk_combo_box_entry_set_text_column (priv->entry_combo_box,
327                     g_value_get_int (value));
328             break;
329
330         case PROP_MAX:
331             gtk_entry_set_max_length (hildon_find_toolbar_get_entry(priv),
332                     g_value_get_int (value));
333             break;
334
335         case PROP_HISTORY_LIMIT:
336             priv->history_limit = g_value_get_int (value);
337
338             /* Re-apply the history limit to the model. */
339             model = hildon_find_toolbar_get_list_model (priv);
340             if (model != NULL)
341             {
342                 /* Note that refilter function doesn't update the status of the
343                    combobox popup arrow, so we'll just recreate the filter. */
344                 hildon_find_toolbar_apply_filter (self, model);
345
346                 if (gtk_combo_box_entry_get_text_column (priv->entry_combo_box) == -1)
347                 {
348                     /* FIXME: This is only for backwards compatibility, although
349                        probably nothing actually relies on it. The behavior was only
350                        an accidental side effect of original code */
351                     gtk_combo_box_entry_set_text_column (priv->entry_combo_box, 0);
352                 }
353             }
354             break;
355
356         default:
357             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
358             break;
359     }
360 }
361
362 static gboolean
363 hildon_find_toolbar_find_string                 (HildonFindToolbar *self,
364                                                  GtkTreeIter *iter,
365                                                  gint column,
366                                                  const gchar *string)
367 {
368     GtkTreeModel *model = NULL;
369     gchar *old_string;
370     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
371     g_assert (priv);
372
373     model = hildon_find_toolbar_get_list_model (priv);
374
375     if (gtk_tree_model_get_iter_first (model, iter))
376     {
377         do {
378             gtk_tree_model_get (model, iter, column, &old_string, -1);
379             if (old_string != NULL && strcmp (string, old_string) == 0)
380             {
381                 /* Found it */
382                 return TRUE;
383             }
384         } while (gtk_tree_model_iter_next (model, iter));
385     }
386
387     return FALSE;
388 }
389
390 static gboolean
391 hildon_find_toolbar_history_append              (HildonFindToolbar *self,
392                                                  gpointer data) 
393 {
394     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
395     g_assert (priv);
396
397     gchar *string;
398     gint column = 0;
399     GtkTreeModel *model = NULL;
400     GtkListStore *list = NULL;
401     GtkTreeIter iter;
402     gboolean self_create = FALSE;
403
404     g_object_get (self, "prefix", &string, NULL);
405
406     if (*string == '\0')
407     {
408         /* empty prefix, ignore */
409         g_free (string);
410         return TRUE;
411     }
412
413
414     /* If list store is set, get it */
415     model = hildon_find_toolbar_get_list_model(priv);
416     if(model != NULL)
417     {
418         list = GTK_LIST_STORE (model);
419         g_object_get(self, "column", &column, NULL);
420
421         if (column < 0)
422         {
423             /* Column number is -1 if "column" property hasn't been set but
424                "list" property is. */
425             g_free (string);
426             return TRUE;
427         }
428
429         /* Latest string is always the first one in list. If the string
430            already exists, remove it so there are no duplicates in list. */
431         if (hildon_find_toolbar_find_string (self, &iter, column, string))
432             gtk_list_store_remove (list, &iter);
433     }
434     else
435     {
436         /* No list store set. Create our own. */
437         list = gtk_list_store_new (1, G_TYPE_STRING);
438         model = GTK_TREE_MODEL (list);
439         self_create = TRUE;
440     }
441
442     /* Add the string to first in list */
443     gtk_list_store_append (list, &iter);
444     gtk_list_store_set (list, &iter, column, string, -1);
445
446     if(self_create)
447     {
448         /* Add the created list to ComboBoxEntry */
449         hildon_find_toolbar_apply_filter (self, model);
450         /* ComboBoxEntry keeps the only needed reference to this list */
451         g_object_unref (list);
452
453         /* Set the column only after ComboBoxEntry's model is set
454            in hildon_find_toolbar_apply_filter() */
455         g_object_set (self, "column", 0, NULL);
456     }
457     else
458     {
459         /* Refilter to get the oldest entry hidden from history */
460         gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(
461                     gtk_combo_box_get_model (GTK_COMBO_BOX(priv->entry_combo_box))));
462     }
463
464     g_free (string);
465
466     return TRUE;
467 }
468
469 static void
470 hildon_find_toolbar_emit_search                 (GtkButton *button, 
471                                                  gpointer self)
472 {
473     gboolean rb;
474
475     /* Clicked search button. Perform search and add search prefix to history */
476     g_signal_emit_by_name(self, "search", NULL);
477     g_signal_emit_by_name(self, "history_append", &rb, NULL);
478 }
479
480 static void
481 hildon_find_toolbar_emit_close                  (GtkButton *button, 
482                                                  gpointer self)
483 {
484     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
485     g_assert (priv);
486
487     GtkWidget *entry = gtk_bin_get_child (GTK_BIN (priv->entry_combo_box));
488     if (GTK_WIDGET_HAS_FOCUS (entry))
489     {
490         hildon_gtk_im_context_hide (GTK_ENTRY (entry)->im_context);
491     }
492
493     /* Clicked close button */
494     g_signal_emit_by_name (self, "close", NULL);
495 }
496
497 static void
498 hildon_find_toolbar_emit_invalid_input          (GtkEntry *entry, 
499                                                  GtkInvalidInputType type, 
500                                                  gpointer self)
501 {
502     if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
503         g_signal_emit_by_name (self, "invalid_input", NULL);
504 }
505
506 static void
507 hildon_find_toolbar_entry_activate              (GtkWidget *widget,
508                                                  gpointer user_data)
509 {
510     GtkWidget *find_toolbar = GTK_WIDGET (user_data);
511     gboolean rb;  
512
513     /* NB#40936 stop focus from moving to next widget */
514     g_signal_stop_emission_by_name (widget, "activate");
515
516     g_signal_emit_by_name (find_toolbar, "search", NULL);
517     g_signal_emit_by_name (find_toolbar, "history_append", &rb, NULL);
518 }
519
520 static void
521 hildon_find_toolbar_class_init                  (HildonFindToolbarClass *klass)
522 {
523     GObjectClass *object_class;
524
525     g_type_class_add_private (klass, sizeof (HildonFindToolbarPrivate));
526
527     object_class = G_OBJECT_CLASS(klass);
528
529     object_class->get_property = hildon_find_toolbar_get_property;
530     object_class->set_property = hildon_find_toolbar_set_property;
531
532     klass->history_append = (gpointer) hildon_find_toolbar_history_append;
533
534     /**
535      * HildonFindToolbar:label:
536      *
537      * The label to display before the search box.
538      *                      
539      */
540     g_object_class_install_property (object_class, PROP_LABEL, 
541             g_param_spec_string ("label", 
542                 "Label", "Displayed name for"
543                 " find-toolbar",
544                 _("ecdg_ti_find_toolbar_label"),
545                 G_PARAM_READWRITE |
546                 G_PARAM_CONSTRUCT));
547
548     /**
549      * HildonFindToolbar:label:
550      *
551      * The label to display before the search box.
552      *                      
553      */
554     g_object_class_install_property (object_class, PROP_PREFIX, 
555             g_param_spec_string ("prefix", 
556                 "Prefix", "Search string", NULL,
557                 G_PARAM_READWRITE));
558
559     /**
560      * HildonFindToolbar:list:
561      *
562      * A #GtkListStore where the search history is kept.
563      *                      
564      */
565     g_object_class_install_property (object_class, PROP_LIST,
566             g_param_spec_object ("list",
567                 "List"," GtkListStore model where "
568                 "history list is kept",
569                 GTK_TYPE_LIST_STORE,
570                 G_PARAM_READWRITE));
571
572     /**
573      * HildonFindToolbar:column:
574      *
575      * The column number in GtkListStore where strings of
576      * search history are kept.
577      *                      
578      */
579     g_object_class_install_property(object_class, PROP_COLUMN,
580             g_param_spec_int ("column",
581                 "Column", "Column number in GtkListStore "
582                 "where history list strings are kept",
583                 0, G_MAXINT,
584                 0, G_PARAM_READWRITE));
585
586     /**
587      * HildonFindToolbar:label:
588      *
589      * The label to display before the search box.
590      *                      
591      */
592     g_object_class_install_property (object_class, PROP_MAX,
593             g_param_spec_int ("max_characters",
594                 "Maximum number of characters",
595                 "Maximum number of characters "
596                 "in search string",
597                 0, MAX_SIZE,
598                 0, G_PARAM_READWRITE |
599                 G_PARAM_CONSTRUCT));
600
601     /**
602      * HildonFindToolbar:history-limit:
603      *
604      * Maximum number of history items in the combobox.
605      *                      
606      */
607     g_object_class_install_property (object_class, PROP_HISTORY_LIMIT,
608             g_param_spec_int ("history-limit",
609                 "Maximum number of history items",
610                 "Maximum number of history items "
611                 "in search combobox",
612                 0, G_MAXINT,
613                 5, G_PARAM_READWRITE |
614                 G_PARAM_CONSTRUCT));
615
616     /**
617      * HildonFindToolbar::search:
618      * @toolbar: the toolbar which received the signal
619      * 
620      * Gets emitted when the find button is pressed.
621      */ 
622     HildonFindToolbar_signal[SEARCH] = 
623         g_signal_new(
624                 "search", HILDON_TYPE_FIND_TOOLBAR,
625                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
626                 (HildonFindToolbarClass, search),
627                 NULL, NULL, gtk_marshal_VOID__VOID,
628                 G_TYPE_NONE, 0);
629
630     /**
631      * HildonFindToolbar::close:
632      * @toolbar: the toolbar which received the signal
633      * 
634      * Gets emitted when the close button is pressed.
635      */ 
636     HildonFindToolbar_signal[CLOSE] = 
637         g_signal_new(
638                 "close", HILDON_TYPE_FIND_TOOLBAR,
639                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
640                 (HildonFindToolbarClass, close),
641                 NULL, NULL, gtk_marshal_VOID__VOID,
642                 G_TYPE_NONE, 0);
643
644     /**
645      * HildonFindToolbar::invalid-input:
646      * @toolbar: the toolbar which received the signal
647      * 
648      * Gets emitted when the maximum search prefix length is reached and
649      * user tries to type more.
650      */ 
651     HildonFindToolbar_signal[INVALID_INPUT] = 
652         g_signal_new(
653                 "invalid_input", HILDON_TYPE_FIND_TOOLBAR,
654                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
655                 (HildonFindToolbarClass, invalid_input),
656                 NULL, NULL, gtk_marshal_VOID__VOID,
657                 G_TYPE_NONE, 0);
658
659     /**
660      * HildonFindToolbar::history-append:
661      * @toolbar: the toolbar which received the signal
662      * 
663      * Gets emitted when the current search prefix should be added to history.
664      */ 
665     HildonFindToolbar_signal[HISTORY_APPEND] = 
666         g_signal_new(
667                 "history_append", HILDON_TYPE_FIND_TOOLBAR,
668                 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
669                 (HildonFindToolbarClass, history_append),
670                 g_signal_accumulator_true_handled, NULL, 
671                 gtk_marshal_BOOLEAN__VOID,
672                 G_TYPE_BOOLEAN, 0);
673 }
674
675 static void
676 hildon_find_toolbar_init                        (HildonFindToolbar *self)
677 {
678     GtkToolItem *label_container;
679     GtkToolItem *entry_combo_box_container;
680
681     HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
682     g_assert (priv);
683
684     /* Create the label */
685     priv->label = gtk_label_new (_("ecdg_ti_find_toolbar_label"));
686
687     gtk_misc_set_padding (GTK_MISC (priv->label), FIND_LABEL_XPADDING,
688             FIND_LABEL_YPADDING);
689
690     label_container = gtk_tool_item_new ();
691     gtk_container_add (GTK_CONTAINER (label_container), 
692             priv->label);
693
694     gtk_widget_show_all (GTK_WIDGET (label_container));
695     gtk_toolbar_insert (GTK_TOOLBAR (self), label_container, -1);
696
697     /* ComboBoxEntry for search prefix string / history list */
698     priv->entry_combo_box = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new ());
699     g_signal_connect (hildon_find_toolbar_get_entry(priv),
700             "invalid_input", 
701             G_CALLBACK(hildon_find_toolbar_emit_invalid_input), self);
702
703     entry_combo_box_container = gtk_tool_item_new ();
704
705     gtk_tool_item_set_expand (entry_combo_box_container, TRUE);
706     gtk_container_add (GTK_CONTAINER (entry_combo_box_container),
707             GTK_WIDGET (priv->entry_combo_box));
708     gtk_widget_show_all(GTK_WIDGET (entry_combo_box_container));
709     gtk_toolbar_insert (GTK_TOOLBAR (self), entry_combo_box_container, -1);
710     g_signal_connect (hildon_find_toolbar_get_entry (priv),
711             "activate",
712             G_CALLBACK(hildon_find_toolbar_entry_activate), self);
713
714     /* Find button */
715     priv->find_button = gtk_tool_button_new (
716             gtk_image_new_from_icon_name ("qgn_toolb_browser_gobutton",
717                 HILDON_ICON_SIZE_TOOLBAR),
718             "Find");
719
720     g_signal_connect (priv->find_button, "clicked",
721             G_CALLBACK(hildon_find_toolbar_emit_search), self);
722     gtk_widget_show_all( GTK_WIDGET(priv->find_button));
723     gtk_toolbar_insert ( GTK_TOOLBAR(self), priv->find_button, -1);
724     if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->find_button)->child) )
725         GTK_WIDGET_UNSET_FLAGS(
726                 GTK_BIN(priv->find_button)->child, GTK_CAN_FOCUS);
727
728     /* Separator */
729     priv->separator = gtk_separator_tool_item_new();
730     gtk_widget_show(GTK_WIDGET(priv->separator));
731     gtk_toolbar_insert (GTK_TOOLBAR(self), priv->separator, -1);
732
733     /* Close button */
734     priv->close_button = gtk_tool_button_new (
735             gtk_image_new_from_icon_name ("qgn_toolb_gene_close",
736                 HILDON_ICON_SIZE_TOOLBAR),
737             "Close");
738     g_signal_connect(priv->close_button, "clicked",
739             G_CALLBACK(hildon_find_toolbar_emit_close), self);
740     gtk_widget_show_all(GTK_WIDGET(priv->close_button));
741     gtk_toolbar_insert (GTK_TOOLBAR(self), priv->close_button, -1);
742     if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->close_button)->child) )
743         GTK_WIDGET_UNSET_FLAGS(
744                 GTK_BIN(priv->close_button)->child, GTK_CAN_FOCUS);
745 }
746
747 /**
748  * hildon_find_toolbar_new:
749  * @label: label for the find_toolbar, NULL to set the label to 
750  *         default "Find"
751  * 
752  * Creates a new HildonFindToolbar.
753  *
754  * Returns: a new HildonFindToolbar
755  */
756 GtkWidget*
757 hildon_find_toolbar_new                         (const gchar *label)
758 {
759     GtkWidget *findtoolbar;
760
761     findtoolbar = GTK_WIDGET (g_object_new (HILDON_TYPE_FIND_TOOLBAR, NULL));
762
763     if (label != NULL)
764         g_object_set(findtoolbar, "label", label, NULL);
765
766     return findtoolbar;
767 }
768
769 /**
770  * hildon_find_toolbar_new_with_model:
771  * @label: label for the find_toolbar, NULL to set the label to 
772  *         default "Find"
773  * @model: a @GtkListStore
774  * @column: indicating which column the search histry list will 
775  *          retreive string from
776  * 
777  * Creates a new HildonFindToolbar with a model.
778  *
779  * Returns: a new #HildonFindToolbar
780  */
781 GtkWidget*
782 hildon_find_toolbar_new_with_model              (const gchar *label,
783                                                  GtkListStore *model,
784                                                  gint column)
785 {
786     GtkWidget *findtoolbar;
787
788     findtoolbar = hildon_find_toolbar_new (label);
789
790     g_object_set (findtoolbar, "list", model, "column", column, NULL);
791
792     return findtoolbar;
793 }
794
795 /**
796  * hildon_find_toolbar_highlight_entry:
797  * @ftb: find Toolbar whose entry is to be highlighted
798  * @get_focus: if user passes TRUE to this value, then the text in
799  * the entry will not only get highlighted, but also get focused.
800  *
801  * Highlights the current entry in the find toolbar.
802  * 
803  */
804 void
805 hildon_find_toolbar_highlight_entry             (HildonFindToolbar *self,
806                                                  gboolean get_focus)
807 {
808     GtkEntry *entry = NULL;
809     HildonFindToolbarPrivate *priv;
810
811     g_return_if_fail (HILDON_IS_FIND_TOOLBAR (self));
812     priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
813     g_assert (priv);
814
815     entry = hildon_find_toolbar_get_entry (priv);
816
817     gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
818
819     if (get_focus)
820         gtk_widget_grab_focus (GTK_WIDGET (entry));
821 }
822