X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-header-view.c;h=62667a4b30ef10deded1f5c5413559202a8f1af2;hp=e7eb3fe16f654552568cc0b4890bd5bc020166da;hb=723fc8f7c266d618eb91e2f621c7c93c6efded37;hpb=7fce57ef7b48d57bb3688d58c385a3c21cb23a25 diff --git a/src/widgets/modest-header-view.c b/src/widgets/modest-header-view.c index e7eb3fe..62667a4 100644 --- a/src/widgets/modest-header-view.c +++ b/src/widgets/modest-header-view.c @@ -176,6 +176,9 @@ struct _ModestHeaderViewPrivate { GdkColor secondary_color; gint show_latest; + + gchar *filter_string; + gchar **filter_string_splitted; }; typedef struct _HeadersCountChangedHelper HeadersCountChangedHelper; @@ -630,6 +633,8 @@ modest_header_view_init (ModestHeaderView *obj) priv->hidding_ids = NULL; priv->n_selected = 0; priv->filter = MODEST_HEADER_VIEW_FILTER_NONE; + priv->filter_string = NULL; + priv->filter_string_splitted = NULL; priv->selection_changed_handler = 0; priv->acc_removed_handler = 0; @@ -717,6 +722,14 @@ modest_header_view_finalize (GObject *obj) priv->autoselect_reference = NULL; } + if (priv->filter_string) { + g_free (priv->filter_string); + } + + if (priv->filter_string_splitted) { + g_strfreev (priv->filter_string_splitted); + } + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -2115,6 +2128,42 @@ current_folder_needs_filtering (ModestHeaderViewPrivate *priv) } static gboolean +header_match_string (TnyHeader *header, gchar **words) +{ + gchar **current_word; + gboolean found; + + found = FALSE; + + for (current_word = words; !found && *current_word != NULL; current_word++) { + gchar *subject; + gchar *cc; + gchar *bcc; + gchar *to; + gchar *from; + + subject = tny_header_dup_subject (header); + cc = tny_header_dup_cc (header); + bcc = tny_header_dup_bcc (header); + to = tny_header_dup_to (header); + from = tny_header_dup_from (header); + + if ((subject && g_strstr_len (subject, -1, *current_word)) + || (cc && g_strstr_len (cc, -1, *current_word)) + || (bcc && g_strstr_len (bcc, -1, *current_word)) + || (to && g_strstr_len (to, -1, *current_word)) + || (from && g_strstr_len (from, -1, *current_word))) + found = TRUE; + g_free (subject); + g_free (cc); + g_free (bcc); + g_free (to); + g_free (from); + } + return found; +} + +static gboolean filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) @@ -2169,6 +2218,13 @@ filter_row (GtkTreeModel *model, } } + if (visible && priv->filter_string) { + if (!header_match_string (header, priv->filter_string_splitted)) { + visible = FALSE; + goto frees; + } + } + /* If no data on clipboard, return always TRUE */ if (modest_email_clipboard_cleared(priv->clipboard)) { visible = TRUE; @@ -2561,3 +2617,28 @@ modest_header_view_get_not_latest (ModestHeaderView *header_view) return not_latest; } + +void +modest_header_view_set_filter_string (ModestHeaderView *self, + const gchar *filter_string) +{ + ModestHeaderViewPrivate *priv; + + g_return_if_fail (MODEST_IS_HEADER_VIEW (self)); + priv = MODEST_HEADER_VIEW_GET_PRIVATE (self); + + if (priv->filter_string) + g_free (priv->filter_string); + + priv->filter_string = g_strdup (filter_string); + + if (priv->filter_string_splitted) { + g_strfreev (priv->filter_string_splitted); + priv->filter_string_splitted = NULL; + } + + if (priv->filter_string) { + priv->filter_string_splitted = g_strsplit (priv->filter_string, " ", 0); + } + modest_header_view_refilter (MODEST_HEADER_VIEW (self)); +}