evolution-data-server r8516 - in trunk/addressbook: . libebook libedata-book



Author: mcrha
Date: Wed Feb 20 11:17:25 2008
New Revision: 8516
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8516&view=rev

Log:
2008-02-20  Milan Crha  <mcrha redhat com>

	** Fix for bug #516474

	* libebook/e-book-query.h: (e_book_query_vcard_field_test):
	* libebook/e-book-query.c: (struct EBookQuery::field_test),
	(e_book_query_field_test), (e_book_query_vcard_field_test),
	(e_book_query_unref), (func_contains), (func_is), (func_beginswith),
	(func_endswith), (func_exists), (e_book_query_to_string):
	* libedata-book/e-book-backend-sexp.c: (entry_compare), (func_exists):
	Fallback to EVCard attributes in query if field name doesn't correspond
	to any known EContactField.



Modified:
   trunk/addressbook/ChangeLog
   trunk/addressbook/libebook/e-book-query.c
   trunk/addressbook/libebook/e-book-query.h
   trunk/addressbook/libedata-book/e-book-backend-sexp.c

Modified: trunk/addressbook/libebook/e-book-query.c
==============================================================================
--- trunk/addressbook/libebook/e-book-query.c	(original)
+++ trunk/addressbook/libebook/e-book-query.c	Wed Feb 20 11:17:25 2008
@@ -33,7 +33,7 @@
 
 		struct {
 			EBookQueryTest test;
-			EContactField  field;
+			char          *field_name;
 			char          *value;
 		} field_test;
 
@@ -195,7 +195,32 @@
 	EBookQuery *ret = g_new0 (EBookQuery, 1);
 
 	ret->type = E_BOOK_QUERY_TYPE_FIELD_TEST;
-	ret->query.field_test.field = field;
+	ret->query.field_test.field_name = g_strdup (e_contact_field_name (field));
+	ret->query.field_test.test = test;
+	ret->query.field_test.value = g_strdup (value);
+
+	return ret;
+}
+
+/**
+ * e_book_query_vcard_field_test:
+ * @field: a EVCard field name to test
+ * @test: the test to apply
+ * @value: the value to test for
+ *
+ * Creates a new #EBookQuery which tests @field for @value using the test @test.
+ *
+ * Return value: the new #EBookQuery
+ **/
+EBookQuery *
+e_book_query_vcard_field_test (const char     *field,
+			       EBookQueryTest  test,
+			       const char     *value)
+{
+	EBookQuery *ret = g_new0 (EBookQuery, 1);
+
+	ret->type = E_BOOK_QUERY_TYPE_FIELD_TEST;
+	ret->query.field_test.field_name = g_strdup (field);
 	ret->query.field_test.test = test;
 	ret->query.field_test.value = g_strdup (value);
 
@@ -288,6 +313,7 @@
 		break;
 
 	case E_BOOK_QUERY_TYPE_FIELD_TEST:
+		g_free (q->query.field_test.field_name);
 		g_free (q->query.field_test.value);
 		break;
 
@@ -424,6 +450,10 @@
 				*list = g_list_prepend (*list, e_book_query_field_test (field,
 											E_BOOK_QUERY_CONTAINS,
 											str));
+			else
+				*list = g_list_prepend (*list, e_book_query_vcard_field_test (propname,
+											E_BOOK_QUERY_CONTAINS,
+											str));
 		}
 	}
 
@@ -450,6 +480,10 @@
 			*list = g_list_prepend (*list, e_book_query_field_test (field,
 										E_BOOK_QUERY_IS,
 										str));
+		else
+			*list = g_list_prepend (*list, e_book_query_vcard_field_test (propname,
+										E_BOOK_QUERY_IS,
+										str));
 	}
 
 	r = e_sexp_result_new(f, ESEXP_RES_BOOL);
@@ -475,6 +509,10 @@
 			*list = g_list_prepend (*list, e_book_query_field_test (field,
 										E_BOOK_QUERY_BEGINS_WITH,
 										str));
+		else
+			*list = g_list_prepend (*list, e_book_query_vcard_field_test (propname,
+										E_BOOK_QUERY_BEGINS_WITH,
+										str));
 	}
 
 	r = e_sexp_result_new(f, ESEXP_RES_BOOL);
@@ -500,6 +538,10 @@
 			*list = g_list_prepend (*list, e_book_query_field_test (field,
 										E_BOOK_QUERY_ENDS_WITH,
 										str));
+		else
+			*list = g_list_prepend (*list, e_book_query_vcard_field_test (propname,
+										E_BOOK_QUERY_ENDS_WITH,
+										str));
 	}
 
 	r = e_sexp_result_new(f, ESEXP_RES_BOOL);
@@ -521,6 +563,8 @@
 
 		if (field)
 			*list = g_list_prepend (*list, e_book_query_field_exists (field));
+		else
+			*list = g_list_prepend (*list, e_book_query_vcard_field_exists (propname));
 	}
 
 	r = e_sexp_result_new(f, ESEXP_RES_BOOL);
@@ -665,7 +709,7 @@
 
 		g_string_append_printf (str, "%s \"%s\" %s",
 					s,
-					e_contact_field_name (q->query.field_test.field),
+					q->query.field_test.field_name,
 					encoded->str);
 		break;
 	case E_BOOK_QUERY_TYPE_ANY_FIELD_CONTAINS:

Modified: trunk/addressbook/libebook/e-book-query.h
==============================================================================
--- trunk/addressbook/libebook/e-book-query.h	(original)
+++ trunk/addressbook/libebook/e-book-query.h	Wed Feb 20 11:17:25 2008
@@ -45,6 +45,9 @@
 EBookQuery* e_book_query_field_test   (EContactField   field,
 				       EBookQueryTest     test,
 				       const char        *value);
+EBookQuery* e_book_query_vcard_field_test (const char    *field,
+				       EBookQueryTest     test,
+				       const char        *value);
 
 /* a special any field contains query */
 EBookQuery* e_book_query_any_field_contains (const char  *value);

Modified: trunk/addressbook/libedata-book/e-book-backend-sexp.c
==============================================================================
--- trunk/addressbook/libedata-book/e-book-backend-sexp.c	(original)
+++ trunk/addressbook/libedata-book/e-book-backend-sexp.c	Wed Feb 20 11:17:25 2008
@@ -353,6 +353,21 @@
 				if ((!prop) && compare ("", argv[1]->value.string)) {
 					truth = TRUE;
 				}
+			} else {
+				/* it is not direct EContact known field, so try to find
+				   it in EVCard attributes */
+				EVCardAttribute *attr = e_vcard_get_attribute (E_VCARD (ctx->contact), propname);
+				GList *l, *values = attr ? e_vcard_attribute_get_values (attr) : NULL;
+
+				for (l = values; l && !truth; l = l->next) {
+					const char *value = l->data;
+
+					if (value && compare (value, argv[1]->value.string)) {
+						truth = TRUE;
+					} else if ((!value) && compare ("", argv[1]->value.string)) {
+						truth = TRUE;
+					}
+				}
 			}
 		}
 	}
@@ -476,6 +491,17 @@
 
 				if (prop && *prop)
 					truth = TRUE;
+			} else {
+				/* is is not a known EContact field, try with EVCard attributes */
+				EVCardAttribute *attr = e_vcard_get_attribute (E_VCARD (ctx->contact), propname);
+				GList *l, *values = attr ? e_vcard_attribute_get_values (attr) : NULL;
+
+				for (l = values; l && !truth; l = l->next) {
+					const char *value = l->data;
+
+					if (value && *value)
+						truth = TRUE;
+				}
 			}
 		}
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]