1 /* Copyright (c) 2009, Igalia
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <glib/gi18n.h>
31 #include "modest-hildon-find-toolbar.h"
33 typedef struct _ModestHildonFindToolbarPrivate ModestHildonFindToolbarPrivate;
34 struct _ModestHildonFindToolbarPrivate {
35 gchar *current_prefix;
39 static void modest_hildon_find_toolbar_class_init (ModestHildonFindToolbarClass *klass);
40 static void modest_hildon_find_toolbar_init (ModestHildonFindToolbar *self);
41 static void modest_isearch_toolbar_iface_init (gpointer g, gpointer iface_data);
43 /* GObject interface */
44 static void modest_hildon_find_toolbar_finalize (GObject *obj);
46 /* ModestISearchToolbar interface */
47 static void modest_hildon_find_toolbar_highlight_entry (ModestISearchToolbar *self, gboolean focus);
48 static void modest_hildon_find_toolbar_highlight_entry_default (ModestISearchToolbar *self, gboolean focus);
49 static void modest_hildon_find_toolbar_set_label (ModestISearchToolbar *self, const gchar *label);
50 static void modest_hildon_find_toolbar_set_label_default (ModestISearchToolbar *self, const gchar *label);
51 static const gchar *modest_hildon_find_toolbar_get_search (ModestISearchToolbar *self);
52 static const gchar *modest_hildon_find_toolbar_get_search_default (ModestISearchToolbar *self);
55 static void on_find_toolbar_close (HildonFindToolbar *self, gpointer userdata);
56 static void on_find_toolbar_search (HildonFindToolbar *self, gpointer userdata);
58 #define MODEST_HILDON_FIND_TOOLBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
59 MODEST_TYPE_HILDON_FIND_TOOLBAR, \
60 ModestHildonFindToolbarPrivate))
62 static HildonFindToolbarClass *parent_class = NULL;
64 G_DEFINE_TYPE_EXTENDED (ModestHildonFindToolbar,
65 modest_hildon_find_toolbar,
66 HILDON_TYPE_FIND_TOOLBAR,
69 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ISEARCH_TOOLBAR, modest_isearch_toolbar_iface_init);
70 g_type_interface_add_prerequisite (g_define_type_id, GTK_TYPE_TOOLBAR);
75 modest_hildon_find_toolbar_new (const gchar *label)
77 GtkWidget *toolbar = g_object_new (MODEST_TYPE_HILDON_FIND_TOOLBAR, NULL);
78 modest_isearch_toolbar_set_label (MODEST_ISEARCH_TOOLBAR (toolbar), label);
84 modest_hildon_find_toolbar_class_init (ModestHildonFindToolbarClass *klass)
86 GObjectClass *gobject_class;
88 parent_class = g_type_class_peek_parent (klass);
89 gobject_class = (GObjectClass *) klass;
90 gobject_class->finalize = modest_hildon_find_toolbar_finalize;
92 klass->highlight_entry_func = modest_hildon_find_toolbar_highlight_entry_default;
93 klass->set_label_func = modest_hildon_find_toolbar_set_label_default;
94 klass->get_search_func = modest_hildon_find_toolbar_get_search_default;
96 g_type_class_add_private (gobject_class, sizeof(ModestHildonFindToolbarPrivate));
100 modest_hildon_find_toolbar_init (ModestHildonFindToolbar *self)
102 ModestHildonFindToolbarPrivate *priv;
104 priv = MODEST_HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
105 priv->current_prefix = NULL;
106 g_signal_connect (G_OBJECT (self), "close", G_CALLBACK (on_find_toolbar_close), self);
107 g_signal_connect (G_OBJECT (self), "search", G_CALLBACK (on_find_toolbar_search), self);
111 modest_isearch_toolbar_iface_init (gpointer g, gpointer iface_data)
113 ModestISearchToolbarIface *iface = (ModestISearchToolbarIface *) g;
115 iface->highlight_entry = modest_hildon_find_toolbar_highlight_entry;
116 iface->set_label = modest_hildon_find_toolbar_set_label;
117 iface->get_search = modest_hildon_find_toolbar_get_search;
121 modest_hildon_find_toolbar_finalize (GObject *obj)
123 ModestHildonFindToolbarPrivate *priv;
125 priv = MODEST_HILDON_FIND_TOOLBAR_GET_PRIVATE (obj);
126 g_free (priv->current_prefix);
127 G_OBJECT_CLASS(parent_class)->finalize (obj);
131 modest_hildon_find_toolbar_highlight_entry (ModestISearchToolbar *self,
134 MODEST_HILDON_FIND_TOOLBAR_GET_CLASS (self)->highlight_entry_func (self, get_focus);
138 modest_hildon_find_toolbar_highlight_entry_default (ModestISearchToolbar *self,
141 hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (self), get_focus);
145 modest_hildon_find_toolbar_set_label (ModestISearchToolbar *self,
148 MODEST_HILDON_FIND_TOOLBAR_GET_CLASS (self)->set_label_func (self, label);
152 modest_hildon_find_toolbar_set_label_default (ModestISearchToolbar *self,
155 g_object_set (G_OBJECT (self), "label", label, NULL);
159 modest_hildon_find_toolbar_get_search (ModestISearchToolbar *self)
161 return MODEST_HILDON_FIND_TOOLBAR_GET_CLASS (self)->get_search_func (self);
165 modest_hildon_find_toolbar_get_search_default (ModestISearchToolbar *self)
167 ModestHildonFindToolbarPrivate *priv;
169 priv = MODEST_HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
171 if (priv->current_prefix) {
172 g_free (priv->current_prefix);
173 priv->current_prefix = NULL;
176 g_object_get (G_OBJECT (self), "prefix", &(priv->current_prefix), NULL);
178 return priv->current_prefix;
182 on_find_toolbar_close (HildonFindToolbar *self, gpointer userdata)
184 g_signal_emit_by_name (G_OBJECT (self), "isearch-close");
188 on_find_toolbar_search (HildonFindToolbar *self, gpointer userdata)
190 g_signal_emit_by_name (G_OBJECT (self), "isearch-search");