#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);
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];
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;
+#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;
priv->selection_changed_handler = 0;
priv->acc_removed_handler = 0;
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;
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;
- 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)))
+ 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 = subject?g_utf8_casefold (subject, -1):NULL;
+ g_free (subject);
+ bcc_fold = bcc?g_utf8_casefold (bcc, -1):NULL;
+ g_free (bcc);
+ cc_fold = cc?g_utf8_casefold (cc, -1):NULL;
+ g_free (cc);
+ to_fold = to?g_utf8_casefold (to, -1):NULL;
+ g_free (to);
+ from_fold = from?g_utf8_casefold (from, -1):NULL;
+ 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;
- g_free (subject);
- g_free (cc);
- g_free (bcc);
- g_free (to);
- g_free (from);
+ } 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;
}
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 */
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_show_latest (ModestHeaderView *header_view,
gint show_latest)
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);
}
if (priv->filter_string) {
- priv->filter_string_splitted = g_strsplit (priv->filter_string, " ", 0);
+ 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));
}
+
+#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