Fix some warnings in headers search.
[modest] / src / widgets / modest-header-view.c
index 4726780..448fdaa 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,10 @@ struct _ModestHeaderViewPrivate {
        guint   n_selected;
        GtkTreeRowReference *autoselect_reference;
        ModestHeaderViewFilter filter;
+#ifdef MODEST_TOOLKIT_HILDON2
+       GtkWidget *live_search;
+       guint live_search_timeout;
+#endif
 
        gint    sort_colid[2][TNY_FOLDER_TYPE_NUM];
        gint    sort_type[2][TNY_FOLDER_TYPE_NUM];
@@ -636,6 +643,10 @@ 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;
+       priv->live_search_timeout = 0;
+#endif
        priv->filter_string = NULL;
        priv->filter_string_splitted = NULL;
        priv->filter_date_range = FALSE;
@@ -667,6 +678,13 @@ modest_header_view_dispose (GObject *obj)
        self = MODEST_HEADER_VIEW(obj);
        priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
 
+#ifdef MODEST_TOOLKIT_HILDON2
+       if (priv->live_search_timeout > 0) {
+               g_source_remove (priv->live_search_timeout);
+               priv->live_search_timeout = 0;
+       }
+#endif
+
        if (priv->datetime_formatter) {
                g_object_unref (priv->datetime_formatter);
                priv->datetime_formatter = NULL;
@@ -2154,15 +2172,15 @@ header_match_string (TnyHeader *header, gchar **words)
        to = tny_header_dup_to (header);
        from = tny_header_dup_from (header);
 
-       subject_fold = g_utf8_casefold (subject, -1);
+       subject_fold = subject?g_utf8_casefold (subject, -1):NULL;
        g_free (subject);
-       bcc_fold = g_utf8_casefold (bcc, -1);
+       bcc_fold = bcc?g_utf8_casefold (bcc, -1):NULL;
        g_free (bcc);
-       cc_fold = g_utf8_casefold (cc, -1);
+       cc_fold = cc?g_utf8_casefold (cc, -1):NULL;
        g_free (cc);
-       to_fold = g_utf8_casefold (to, -1);
+       to_fold = to?g_utf8_casefold (to, -1):NULL;
        g_free (to);
-       from_fold = g_utf8_casefold (from, -1);
+       from_fold = from?g_utf8_casefold (from, -1):NULL;
        g_free (from);
 
        found = TRUE;
@@ -2787,3 +2805,74 @@ 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_timeout (ModestHeaderView *self)
+{
+       const gchar *needle;
+       ModestHeaderViewPrivate *priv;
+
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
+
+       needle = hildon_live_search_get_text (HILDON_LIVE_SEARCH (priv->live_search));
+       if (needle && needle[0] != '\0') {
+               modest_header_view_set_filter_string (MODEST_HEADER_VIEW (self), needle);
+               if (priv->show_latest > 0)
+                       modest_header_view_set_show_latest (MODEST_HEADER_VIEW (self), 0);
+       } else {
+               modest_header_view_set_filter_string (MODEST_HEADER_VIEW (self), NULL);
+       }
+
+       priv->live_search_timeout = 0;
+
+       return FALSE;
+}
+
+static gboolean
+on_live_search_refilter (HildonLiveSearch *livesearch,
+                        ModestHeaderView *self)
+{
+       ModestHeaderViewPrivate *priv;
+       GtkTreeModel *model, *sortable, *filter;
+
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
+
+       if (priv->live_search_timeout > 0) {
+               g_source_remove (priv->live_search_timeout);
+               priv->live_search_timeout = 0;
+       }
+
+       model = NULL;
+       sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+       if (GTK_IS_TREE_MODEL_SORT (sortable)) {
+               filter = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sortable));
+               if (GTK_IS_TREE_MODEL_FILTER (filter)) {
+                       model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter));
+               }
+       }
+
+       if (model && tny_list_get_length (TNY_LIST (model)) > 250) {
+               priv->live_search_timeout = g_timeout_add (1000, (GSourceFunc) on_live_search_timeout, self);
+       } else {
+               on_live_search_timeout (self);
+       }
+
+       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