Add live search support to mailboxes window
authorJosé Dapena Paz <jdapena@igalia.com>
Tue, 2 Feb 2010 16:57:49 +0000 (17:57 +0100)
committerJosé Dapena Paz <jdapena@igalia.com>
Tue, 2 Feb 2010 17:22:30 +0000 (18:22 +0100)
src/widgets/modest-header-view.c
src/widgets/modest-header-view.h
src/widgets/modest-header-window.c
src/widgets/modest-mailboxes-window.c

index 9290255..c08b94d 100644 (file)
@@ -51,6 +51,9 @@
 #include <modest-vbox-cell-renderer.h>
 #include <modest-datetime-formatter.h>
 #include <modest-ui-constants.h>
+#ifdef MODEST_TOOLKIT_HILDON2
+#include <hildon/hildon.h>
+#endif
 
 static void modest_header_view_class_init  (ModestHeaderViewClass *klass);
 static void modest_header_view_init        (ModestHeaderView *obj);
@@ -152,6 +155,9 @@ struct _ModestHeaderViewPrivate {
        guint   n_selected;
        GtkTreeRowReference *autoselect_reference;
        ModestHeaderViewFilter filter;
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
 
        gint    sort_colid[2][TNY_FOLDER_TYPE_NUM];
        gint    sort_type[2][TNY_FOLDER_TYPE_NUM];
@@ -631,6 +637,9 @@ modest_header_view_init (ModestHeaderView *obj)
        priv->hidding_ids = NULL;
        priv->n_selected = 0;
        priv->filter = MODEST_HEADER_VIEW_FILTER_NONE;
+#ifdef MODEST_TOOLKIT_HILDON2
+       priv->live_search = NULL;
+#endif
        priv->filter_string = NULL;
        priv->filter_string_splitted = NULL;
        priv->filter_date_range = FALSE;
@@ -2709,3 +2718,35 @@ modest_header_view_set_filter_string (ModestHeaderView *self,
        }
        modest_header_view_refilter (MODEST_HEADER_VIEW (self));
 }
+
+#ifdef MODEST_TOOLKIT_HILDON2
+static gboolean
+on_live_search_refilter (HildonLiveSearch *livesearch,
+                        ModestHeaderView *self)
+{
+       const gchar *needle;
+
+       needle = hildon_live_search_get_text (livesearch);
+       if (needle && needle[0] != '\0') {
+               modest_header_view_set_filter_string (MODEST_HEADER_VIEW (self), needle);
+       } else {
+               modest_header_view_set_filter_string (MODEST_HEADER_VIEW (self), NULL);
+       }
+       
+       return TRUE;
+}
+
+GtkWidget *
+modest_header_view_setup_live_search (ModestHeaderView *self)
+{
+       ModestHeaderViewPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_HEADER_VIEW (self), NULL);
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
+       priv->live_search = hildon_live_search_new ();
+
+       g_signal_connect (G_OBJECT (priv->live_search), "refilter", G_CALLBACK (on_live_search_refilter), self);
+
+       return priv->live_search;
+}
+#endif
index ebd24fa..c0c9be2 100644 (file)
@@ -477,6 +477,11 @@ TnyHeader* modest_header_view_get_header_at_pos (ModestHeaderView *header_view,
                                                 gint initial_x,
                                                 gint initial_y);
 
+
+#ifdef MODEST_TOOLKIT_HILDON2
+GtkWidget *modest_header_view_setup_live_search (ModestHeaderView *self);
+#endif
+
 G_END_DECLS
 
 
index d163a76..222ad74 100644 (file)
@@ -765,7 +765,10 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
        ModestServerAccountSettings *store_settings = NULL;
        GtkWidget *alignment;
        gchar *account_display_name = NULL;
-       
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
+
        self  = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
        priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
 
@@ -785,6 +788,10 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
                                  self);
 
        priv->header_view  = create_header_view (MODEST_WINDOW (self), folder);
+#ifdef MODEST_TOOLKIT_HILDON2
+       live_search = modest_header_view_setup_live_search (MODEST_HEADER_VIEW (priv->header_view));
+       hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->header_view);
+#endif
        priv->empty_view = create_empty_view (MODEST_WINDOW (self));
 
        /* Transform the floating reference in a "hard" reference. We
@@ -819,6 +826,9 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
 
         priv->top_vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (alignment), priv->contents_view);
+#ifdef MODEST_TOOLKIT_HILDON2
+       gtk_box_pack_end (GTK_BOX (priv->top_vbox), live_search, FALSE, FALSE, 0);
+#endif
        gtk_box_pack_end (GTK_BOX (priv->top_vbox), alignment, TRUE, TRUE, 0);
 
        gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
index 5c438be..28cddde 100644 (file)
@@ -283,6 +283,9 @@ modest_mailboxes_window_new (const gchar *account)
        GdkPixbuf *window_icon;
        GtkWidget *scrollable;
        GtkWidget *top_alignment;
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+#endif
        
        self  = MODEST_MAILBOXES_WINDOW(g_object_new(MODEST_TYPE_MAILBOXES_WINDOW, NULL));
        priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(self);
@@ -295,6 +298,10 @@ modest_mailboxes_window_new (const gchar *account)
                                  self);
 
        priv->folder_view  = modest_platform_create_folder_view (NULL);
+#ifdef MODEST_TOOLKIT_HILDON2
+       live_search = modest_folder_view_setup_live_search (MODEST_FOLDER_VIEW (priv->folder_view));
+       hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->folder_view);
+#endif
        modest_folder_view_set_cell_style (MODEST_FOLDER_VIEW (priv->folder_view),
                                           MODEST_FOLDER_VIEW_CELL_STYLE_COMPACT);
        modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view), 
@@ -328,6 +335,9 @@ modest_mailboxes_window_new (const gchar *account)
 
        gtk_container_add (GTK_CONTAINER (scrollable), priv->folder_view);
        gtk_box_pack_end (GTK_BOX (priv->top_vbox), scrollable, TRUE, TRUE, 0);
+#ifdef MODEST_TOOLKIT_HILDON2
+       gtk_box_pack_end (GTK_BOX (priv->top_vbox), live_search, FALSE, FALSE, 0);
+#endif
        gtk_container_add (GTK_CONTAINER (top_alignment), priv->top_vbox);
        gtk_container_add (GTK_CONTAINER (self), top_alignment);