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