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