summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Dumez <christophe.dumez@intel.com>2011-05-27 15:40:06 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2011-06-07 10:53:08 +0200
commit078224089b3afa09c6344ce6e5327756dc2b70b8 (patch)
tree1b50a15fac2905987e05be00dc226de0acf4d3ef
parent9b0bff12a98fac22aaa2bb79d0b27fda7bd4717e (diff)
downloadevolution-data-server-078224089b3afa09c6344ce6e5327756dc2b70b8.tar.gz
Bug #651113 - [libebook] Querying date fields is not supported
(cherry picked from commit 37a3503b30cc071971a6806bd43d4a3bee949bb8)
-rw-r--r--addressbook/libedata-book/e-book-backend-sexp.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c
index 47aaefb49..c9c6bd573 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -255,9 +255,26 @@ compare_category (EContact *contact, const gchar *str,
return ret_val;
}
+static gboolean
+compare_date (EContactDate *date, const gchar *str,
+ gchar *(*compare)(const gchar *, const gchar *))
+{
+ gchar *date_str = e_contact_date_to_string (date);
+ gboolean ret_val = FALSE;
+
+ if (date_str) {
+ if (compare(date_str, str)) {
+ ret_val = TRUE;
+ }
+ g_free (date_str);
+ }
+ return ret_val;
+}
+
enum prop_type {
PROP_TYPE_NORMAL,
- PROP_TYPE_LIST
+ PROP_TYPE_LIST,
+ PROP_TYPE_DATE
};
static struct prop_info {
@@ -270,12 +287,15 @@ static struct prop_info {
} prop_info_table[] = {
#define NORMAL_PROP(f,q) {f, q, PROP_TYPE_NORMAL, NULL}
#define LIST_PROP(q,c) {0, q, PROP_TYPE_LIST, c}
+#define DATE_PROP(f,q) {f, q, PROP_TYPE_DATE, NULL}
/* query prop, type, list compare function */
NORMAL_PROP ( E_CONTACT_FILE_AS, "file_as" ),
NORMAL_PROP ( E_CONTACT_UID, "id" ),
LIST_PROP ( "full_name", compare_name), /* not really a list, but we need to compare both full and surname */
LIST_PROP ( "photo", compare_photo_uri ), /* not really a list, but we need to compare the uri in the struct */
+ DATE_PROP ( E_CONTACT_BIRTH_DATE, "birth_date" ),
+ DATE_PROP ( E_CONTACT_ANNIVERSARY, "anniversary" ),
NORMAL_PROP ( E_CONTACT_GIVEN_NAME, "given_name"),
NORMAL_PROP ( E_CONTACT_FAMILY_NAME, "family_name"),
NORMAL_PROP ( E_CONTACT_HOMEPAGE_URL, "url"),
@@ -360,6 +380,17 @@ entry_compare (SearchContext *ctx, struct _ESExp *f,
/* the special searches that match any of the list elements */
truth = info->list_compare (ctx->contact, argv[1]->value.string, compare);
}
+ else if (info->prop_type == PROP_TYPE_DATE) {
+ /* the special searches that match dates */
+ EContactDate *date;
+
+ date = e_contact_get (ctx->contact, info->field_id);
+
+ if (date) {
+ truth = compare_date (date, argv[1]->value.string, compare);
+ e_contact_date_free (date);
+ }
+ }
/* if we're looking at all fields and find a match,
or if we're just looking at this one field,