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:03:12 +0000 (18:03 +0100)
src/hildon2/modest-header-window.c
src/hildon2/modest-mailboxes-window.c
src/widgets/modest-header-view.c
src/widgets/modest-header-view.h

index b44f12e..5d94a8a 100644 (file)
 #include <modest-ui-actions.h>
 #include <modest-platform.h>
 #include <modest-text-utils.h>
-#include <hildon/hildon-button.h>
-#include <hildon/hildon-program.h>
-#include <hildon/hildon-banner.h>
-#include <hildon/hildon-find-toolbar.h>
+#include <hildon/hildon.h>
 #include <modest-ui-dimming-rules.h>
 #include <modest-tny-folder.h>
 #include <modest-tny-account.h>
@@ -809,6 +806,9 @@ modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gc
        GdkPixbuf *new_message_pixbuf;
        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);
@@ -829,6 +829,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
@@ -858,6 +862,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 04e8a7a..4f2ef17 100644 (file)
@@ -41,9 +41,7 @@
 #include <modest-defs.h>
 #include <modest-ui-actions.h>
 #include <modest-window.h>
-#include <hildon/hildon-program.h>
-#include <hildon/hildon-banner.h>
-#include <hildon/hildon-button.h>
+#include <hildon/hildon.h>
 #include <tny-account-store-view.h>
 #include <modest-header-window.h>
 #include <modest-ui-dimming-rules.h>
@@ -277,6 +275,9 @@ modest_mailboxes_window_new (const gchar *account)
        GdkModifierType accel_mods;
        GtkAccelGroup *accel_group;
        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);
@@ -289,6 +290,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), 
@@ -318,6 +323,9 @@ modest_mailboxes_window_new (const gchar *account)
 
        gtk_container_add (GTK_CONTAINER (pannable), priv->folder_view);
        gtk_box_pack_end (GTK_BOX (priv->top_vbox), pannable, 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);
 
index 4726780..ae24edd 100644 (file)
@@ -52,6 +52,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);
@@ -153,6 +156,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];
@@ -636,6 +642,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;
@@ -2787,3 +2796,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 ea0358e..a70656f 100644 (file)
@@ -483,6 +483,10 @@ void modest_header_view_set_show_latest (ModestHeaderView *header_view,
 gint modest_header_view_get_show_latest (ModestHeaderView *header_view);
 gint modest_header_view_get_not_latest (ModestHeaderView *header_view);
 
+#ifdef MODEST_TOOLKIT_HILDON2
+GtkWidget *modest_header_view_setup_live_search (ModestHeaderView *self);
+#endif
+
 G_END_DECLS