Fix some warnings in headers search.
[modest] / src / widgets / modest-header-view.c
index ae24edd..448fdaa 100644 (file)
@@ -158,6 +158,7 @@ struct _ModestHeaderViewPrivate {
        ModestHeaderViewFilter filter;
 #ifdef MODEST_TOOLKIT_HILDON2
        GtkWidget *live_search;
        ModestHeaderViewFilter filter;
 #ifdef MODEST_TOOLKIT_HILDON2
        GtkWidget *live_search;
+       guint live_search_timeout;
 #endif
 
        gint    sort_colid[2][TNY_FOLDER_TYPE_NUM];
 #endif
 
        gint    sort_colid[2][TNY_FOLDER_TYPE_NUM];
@@ -644,6 +645,7 @@ modest_header_view_init (ModestHeaderView *obj)
        priv->filter = MODEST_HEADER_VIEW_FILTER_NONE;
 #ifdef MODEST_TOOLKIT_HILDON2
        priv->live_search = NULL;
        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;
 #endif
        priv->filter_string = NULL;
        priv->filter_string_splitted = NULL;
@@ -676,6 +678,13 @@ modest_header_view_dispose (GObject *obj)
        self = MODEST_HEADER_VIEW(obj);
        priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
 
        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;
        if (priv->datetime_formatter) {
                g_object_unref (priv->datetime_formatter);
                priv->datetime_formatter = NULL;
@@ -2163,15 +2172,15 @@ header_match_string (TnyHeader *header, gchar **words)
        to = tny_header_dup_to (header);
        from = tny_header_dup_from (header);
 
        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);
        g_free (subject);
-       bcc_fold = g_utf8_casefold (bcc, -1);
+       bcc_fold = bcc?g_utf8_casefold (bcc, -1):NULL;
        g_free (bcc);
        g_free (bcc);
-       cc_fold = g_utf8_casefold (cc, -1);
+       cc_fold = cc?g_utf8_casefold (cc, -1):NULL;
        g_free (cc);
        g_free (cc);
-       to_fold = g_utf8_casefold (to, -1);
+       to_fold = to?g_utf8_casefold (to, -1):NULL;
        g_free (to);
        g_free (to);
-       from_fold = g_utf8_casefold (from, -1);
+       from_fold = from?g_utf8_casefold (from, -1):NULL;
        g_free (from);
 
        found = TRUE;
        g_free (from);
 
        found = TRUE;
@@ -2798,19 +2807,58 @@ modest_header_view_set_filter_string (ModestHeaderView *self,
 }
 
 #ifdef MODEST_TOOLKIT_HILDON2
 }
 
 #ifdef MODEST_TOOLKIT_HILDON2
+
 static gboolean
 static gboolean
-on_live_search_refilter (HildonLiveSearch *livesearch,
-                        ModestHeaderView *self)
+on_live_search_timeout (ModestHeaderView *self)
 {
        const gchar *needle;
 {
        const gchar *needle;
+       ModestHeaderViewPrivate *priv;
+
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE (self);
 
 
-       needle = hildon_live_search_get_text (livesearch);
+       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 (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);
        }
        } 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;
 }
 
        return TRUE;
 }