#include <modest-dnd.h>
#include <modest-tny-folder.h>
#include <modest-debug.h>
-#include <modest-main-window.h>
#include <modest-ui-actions.h>
#include <modest-marshal.h>
#include <modest-text-utils.h>
GdkColor active_color;
GdkColor secondary_color;
+
+ gchar *filter_string;
+ gchar **filter_string_splitted;
+ gboolean filter_date_range;
+ time_t date_range_start;
+ time_t date_range_end;
};
typedef struct _HeadersCountChangedHelper HeadersCountChangedHelper;
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->filter_date_range = FALSE;
priv->selection_changed_handler = 0;
priv->acc_removed_handler = 0;
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);
}
}
static gboolean
+header_match_string (TnyHeader *header, gchar **words)
+{
+ gchar *subject;
+ gchar *cc;
+ gchar *bcc;
+ gchar *to;
+ gchar *from;
+ gchar *subject_fold;
+ gchar *cc_fold;
+ gchar *bcc_fold;
+ gchar *to_fold;
+ gchar *from_fold;
+
+ gchar **current_word;
+ gboolean found;
+
+ 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);
+
+ subject_fold = g_utf8_casefold (subject, -1);
+ g_free (subject);
+ bcc_fold = g_utf8_casefold (bcc, -1);
+ g_free (bcc);
+ cc_fold = g_utf8_casefold (cc, -1);
+ g_free (cc);
+ to_fold = g_utf8_casefold (to, -1);
+ g_free (to);
+ from_fold = g_utf8_casefold (from, -1);
+ g_free (from);
+
+ found = TRUE;
+
+ for (current_word = words; *current_word != NULL; current_word++) {
+
+ if ((subject && g_strstr_len (subject_fold, -1, *current_word))
+ || (cc && g_strstr_len (cc_fold, -1, *current_word))
+ || (bcc && g_strstr_len (bcc_fold, -1, *current_word))
+ || (to && g_strstr_len (to_fold, -1, *current_word))
+ || (from && g_strstr_len (from_fold, -1, *current_word))) {
+ found = TRUE;
+ } else {
+ found = FALSE;
+ break;
+ }
+ }
+
+ g_free (subject_fold);
+ g_free (cc_fold);
+ g_free (bcc_fold);
+ g_free (to_fold);
+ g_free (from_fold);
+
+ return found;
+}
+
+static gboolean
filter_row (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
}
}
+ if (visible && priv->filter_string) {
+ if (!header_match_string (header, priv->filter_string_splitted)) {
+ visible = FALSE;
+ goto frees;
+ }
+ if (priv->filter_date_range) {
+ if ((tny_header_get_date_sent (TNY_HEADER (header)) < priv->date_range_start) ||
+ ((priv->date_range_end != -1) && (tny_header_get_date_sent (TNY_HEADER (header)) > priv->date_range_end))) {
+ visible = FALSE;
+ goto frees;
+ }
+ }
+ }
+
/* If no data on clipboard, return always TRUE */
if (modest_email_clipboard_cleared(priv->clipboard)) {
visible = TRUE;
notify_filter_change_destroy);
}
}
-
+
return visible;
}
return header;
}
+
+static gboolean
+parse_date_side (const gchar *string, time_t *date_side)
+{
+ gchar *today;
+ gchar *yesterday;
+ gchar *casefold;
+ GDate *date;
+ gboolean result = FALSE;
+
+ if (string && string[0] == '\0') {
+ *date_side = 0;
+ return TRUE;
+ }
+
+ casefold = g_utf8_casefold (string, -1);
+ today = g_utf8_casefold (dgettext ("gtk20", "Today"), -1);
+ yesterday = g_utf8_casefold (dgettext ("gtk20", "Yesterday"), -1);
+ date = g_date_new ();
+
+ if (g_utf8_collate (casefold, today) == 0) {
+ *date_side = time (NULL);
+ result = TRUE;
+ goto frees;
+ }
+
+ if (g_utf8_collate (casefold, yesterday) == 0) {
+ *date_side = time (NULL) - 24*60*60;
+ result = TRUE;
+ goto frees;
+ }
+
+ g_date_set_parse (date, string);
+ if (g_date_valid (date)) {
+ struct tm tm = {0};
+ g_date_to_struct_tm (date, &tm);
+ *date_side = mktime (&tm);
+
+ result = TRUE;
+ goto frees;
+ }
+frees:
+ g_free (today);
+ g_free (yesterday);
+ g_free (casefold);
+ g_date_free (date);
+
+ return result;
+}
+
+static gboolean
+parse_date_range (const gchar *string, time_t *date_range_start, time_t *date_range_end)
+{
+ gchar ** parts;
+ gboolean valid;
+
+ parts = g_strsplit (string, "..", 2);
+ valid = TRUE;
+
+ if (g_strv_length (parts) != 2) {
+ valid = FALSE;
+ goto frees;
+ g_strfreev (parts);
+ return FALSE;
+ }
+
+ if (!parse_date_side (parts[0], date_range_start)) {
+ valid = FALSE;
+ goto frees;
+ }
+
+ if (parse_date_side (parts[1], date_range_end)) {
+ if (*date_range_end == 0) {
+ *date_range_end = (time_t) -1;
+ } else {
+ *date_range_end += (24*60*60 - 1);
+ }
+ } else {
+ valid = FALSE;
+ goto frees;
+ }
+
+frees:
+ g_strfreev (parts);
+ return valid;
+}
+
+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);
+ priv->filter_date_range = FALSE;
+
+ if (priv->filter_string_splitted) {
+ g_strfreev (priv->filter_string_splitted);
+ priv->filter_string_splitted = NULL;
+ }
+
+ if (priv->filter_string) {
+ gchar **split, **current, **current_target;
+
+ split = g_strsplit (priv->filter_string, " ", 0);
+
+ priv->filter_string_splitted = g_malloc0 (sizeof (gchar *)*(g_strv_length (split) + 1));
+ current_target = priv->filter_string_splitted;
+ for (current = split; *current != 0; current ++) {
+ gboolean has_date_range = FALSE;;
+ if (g_strstr_len (*current, -1, "..") && strcmp(*current, "..")) {
+ time_t range_start, range_end;
+ /* It contains .. but it's not ".." so it may be a date range */
+ if (parse_date_range (*current, &range_start, &range_end)) {
+ priv->filter_date_range = TRUE;
+ has_date_range = TRUE;
+ priv->date_range_start = range_start;
+ priv->date_range_end = range_end;
+ }
+ }
+ if (!has_date_range) {
+ *current_target = g_utf8_casefold (*current, -1);
+ current_target++;
+ }
+ }
+ *current_target = '\0';
+ g_strfreev (split);
+ }
+ modest_header_view_refilter (MODEST_HEADER_VIEW (self));
+}