[evolution-data-server/evolution-data-server-3-12] Bug 732983 - e_book_query_field_exists() fails with non-string fields



commit 3a2c2a0e06ba290d856b0c9215cf6fd4bfd5bcf8
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jul 17 08:44:44 2014 +0200

    Bug 732983 - e_book_query_field_exists() fails with non-string fields

 addressbook/libebook-contacts/e-contact.c       |   22 +++++++++++++++++++++-
 addressbook/libebook-contacts/e-contact.h       |    1 +
 addressbook/libedata-book/e-book-backend-sexp.c |   15 +++++++++++----
 3 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-contact.c b/addressbook/libebook-contacts/e-contact.c
index dce1e0e..7a59169 100644
--- a/addressbook/libebook-contacts/e-contact.c
+++ b/addressbook/libebook-contacts/e-contact.c
@@ -1457,6 +1457,25 @@ e_contact_vcard_attribute (EContactField field_id)
 }
 
 /**
+ * e_contact_field_is_string:
+ * @field_id: an #EContactField
+ *
+ * Returns whether the @field_id is of a string type,
+ * thus it can be used with e_contact_get_const().
+ *
+ * Returns: Whether the @field_id is of a string type.
+ *
+ * Since: 3.14
+ **/
+gboolean
+e_contact_field_is_string (EContactField field_id)
+{
+       g_return_val_if_fail (field_id >= 1 && field_id < E_CONTACT_FIELD_LAST, FALSE);
+
+       return (field_info[field_id].t & E_CONTACT_FIELD_TYPE_STRING) != 0;
+}
+
+/**
  * e_contact_field_id:
  * @field_name: a string representing a contact field
  *
@@ -1711,7 +1730,8 @@ e_contact_get (EContact *contact,
  * @field_id: an #EContactField
  *
  * Gets the value of @contact's field specified by @field_id, caching
- * the result so it can be freed later.
+ * the result so it can be freed later. Use e_contact_field_is_string()
+ * to check whether the field can be used here.
  *
  * Returns: (transfer none): Depends on the field's type, owned by the
  * #EContact.
diff --git a/addressbook/libebook-contacts/e-contact.h b/addressbook/libebook-contacts/e-contact.h
index dbd9778..22ac45c 100644
--- a/addressbook/libebook-contacts/e-contact.h
+++ b/addressbook/libebook-contacts/e-contact.h
@@ -421,6 +421,7 @@ GType               e_contact_field_type            (EContactField field_id);
 const gchar *  e_contact_field_name            (EContactField field_id);
 const gchar *  e_contact_pretty_name           (EContactField field_id);
 const gchar *  e_contact_vcard_attribute       (EContactField field_id);
+gboolean       e_contact_field_is_string       (EContactField field_id);
 EContactField  e_contact_field_id              (const gchar *field_name);
 EContactField  e_contact_field_id_from_vcard   (const gchar *vcard_field);
 
diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c
index e0bf16c..c99ef09 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -962,7 +962,7 @@ func_exists (struct _ESExp *f,
 
        if (argc == 1
            && argv[0]->type == ESEXP_RES_STRING) {
-               gchar *propname;
+               const gchar *propname;
                struct prop_info *info = NULL;
                gint i;
                gboolean saw_any = FALSE;
@@ -1013,15 +1013,22 @@ func_exists (struct _ESExp *f,
                         * against value in this field only */
                        EContactField fid = e_contact_field_id (propname);
 
-                       if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST) {
+                       if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST &&
+                           e_contact_field_is_string (fid)) {
                                const gchar *prop = e_contact_get_const (ctx->contact, fid);
 
                                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;
+                               EVCardAttribute *attr;
+                               GList *l, *values;
+
+                               if (fid >= E_CONTACT_FIELD_FIRST && fid < E_CONTACT_FIELD_LAST)
+                                       propname = e_contact_vcard_attribute (fid);
+
+                               attr = e_vcard_get_attribute (E_VCARD (ctx->contact), propname);
+                               values = attr ? e_vcard_attribute_get_values (attr) : NULL;
 
                                for (l = values; l && !truth; l = l->next) {
                                        const gchar *value = l->data;


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