diff options
author | Chris Toshok <toshok@helixcode.com> | 2000-08-09 13:12:19 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2000-08-09 13:12:19 +0800 |
commit | 37f85438b274e6285335f8484031f06522ce1fe2 (patch) | |
tree | 15df7f73f1c59b06c0366376de4caa37f02d9fb4 /addressbook | |
parent | e367caf0428dd69039dedcea8d2376dcba94101d (diff) | |
download | gsoc2013-evolution-37f85438b274e6285335f8484031f06522ce1fe2.tar.gz gsoc2013-evolution-37f85438b274e6285335f8484031f06522ce1fe2.tar.zst gsoc2013-evolution-37f85438b274e6285335f8484031f06522ce1fe2.zip |
use x-evolution-any-field.
2000-08-08 Chris Toshok <toshok@helixcode.com>
* gui/component/e-addressbook-model.c (e_addressbook_model_init):
use x-evolution-any-field.
* gui/component/addressbook.c (search_entry_activated): use
x-evolution-any-field.
(change_view_type): same.
* gui/minicard/e-minicard-view.c (e_minicard_view_init): set query
to x-evolution-any-field.
* backend/pas/pas-backend-ldap.c (func_contains): support
x-evolution-any-field for matching any evolution supported field.
* backend/pas/pas-backend-file.c (compare_email): switch to using
ECardSimple calls.
(compare_phone): same.
(compare_address): same.
(entry_compare): switch to using ECardSimple calls, and support a
'x-evolution-any-field' wildcard field.
(vcard_matches_search): use an ECardSimple.
svn path=/trunk/; revision=4626
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/ChangeLog | 23 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 156 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 115 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook.c | 4 | ||||
-rw-r--r-- | addressbook/gui/component/e-addressbook-model.c | 2 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard-view.c | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-model.c | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.c | 2 |
8 files changed, 177 insertions, 129 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index cb8e0f1580..5beb02afaf 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,26 @@ +2000-08-08 Chris Toshok <toshok@helixcode.com> + + * gui/component/e-addressbook-model.c (e_addressbook_model_init): + use x-evolution-any-field. + + * gui/component/addressbook.c (search_entry_activated): use + x-evolution-any-field. + (change_view_type): same. + + * gui/minicard/e-minicard-view.c (e_minicard_view_init): set query + to x-evolution-any-field. + + * backend/pas/pas-backend-ldap.c (func_contains): support + x-evolution-any-field for matching any evolution supported field. + + * backend/pas/pas-backend-file.c (compare_email): switch to using + ECardSimple calls. + (compare_phone): same. + (compare_address): same. + (entry_compare): switch to using ECardSimple calls, and support a + 'x-evolution-any-field' wildcard field. + (vcard_matches_search): use an ECardSimple. + 2000-08-07 Christopher James Lahey <clahey@helixcode.com> * contact-editor/e-contact-editor.c: Removed the next and prev diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index a64a94c402..36310e0f43 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -20,7 +20,7 @@ #include "pas-backend-file.h" #include "pas-book.h" #include "pas-card-cursor.h" -#include <ebook/e-card.h> +#include <ebook/e-card-simple.h> #include <e-util/e-sexp.h> #include <e-util/e-util.h> @@ -56,7 +56,7 @@ struct _PASBackendFileBookView { }; struct _PASBackendFileSearchContext { - ECard *ecard; + ECardSimple *card; }; static long @@ -157,65 +157,39 @@ pas_backend_file_create_unique_id (char *vcard) } static gboolean -compare_email (ECard *ecard, const char *str, +compare_email (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { - EList *prop_list; - EIterator *iter; - gboolean truth = FALSE; - - gtk_object_get(GTK_OBJECT(ecard), - "email", &prop_list, NULL); + int i; - iter = e_list_get_iterator(prop_list); + for (i = E_CARD_SIMPLE_EMAIL_ID_EMAIL; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { + const char *email = e_card_simple_get_email (card, i); - while (e_iterator_is_valid(iter)) { - - if (compare((char*)e_iterator_get(iter), str)) { - truth = TRUE; - break; - } - else { - e_iterator_next(iter); - } + if (compare(email, str)) + return TRUE; } - gtk_object_unref (GTK_OBJECT(iter)); - - return truth; + return FALSE; } static gboolean -compare_phone (ECard *ecard, const char *str, +compare_phone (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { - EList *prop_list; - EIterator *iter; - gboolean truth = FALSE; + int i; - gtk_object_get(GTK_OBJECT(ecard), - "phone", &prop_list, NULL); - - iter = e_list_get_iterator(prop_list); + for (i = E_CARD_SIMPLE_PHONE_ID_ASSISTANT; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { + const ECardPhone *phone = e_card_simple_get_phone (card, i); - while (e_iterator_is_valid(iter)) { - ECardPhone *phone = (ECardPhone*)e_iterator_get(iter); - if (compare(phone->number, str)) { - truth = TRUE; - break; - } - else { - e_iterator_next(iter); - } + if (compare(phone->number, str)) + return TRUE; } - gtk_object_unref (GTK_OBJECT(iter)); - - return truth; + return FALSE; } static gboolean -compare_address (ECard *ecard, const char *str, +compare_address (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { g_warning("address searching not implemented\n"); @@ -223,34 +197,38 @@ compare_address (ECard *ecard, const char *str, } static struct prop_info { + ECardSimpleField field_id; const char *query_prop; const char *ecard_prop; #define PROP_TYPE_NORMAL 0x01 #define PROP_TYPE_LIST 0x02 #define PROP_TYPE_LISTITEM 0x03 int prop_type; - gboolean (*list_compare)(ECard *ecard, const char *str, + gboolean (*list_compare)(ECardSimple *ecard, const char *str, char *(*compare)(const char*, const char*)); } prop_info_table[] = { +#define NORMAL_PROP(f,q,e) {f, q, e, PROP_TYPE_NORMAL, NULL} +#define LIST_PROP(q,e,c) {0, q, e, PROP_TYPE_LIST, c} + /* query prop, ecard prop, type, list compare function */ - { "file_as", "file_as", PROP_TYPE_NORMAL, NULL }, - { "full_name", "full_name", PROP_TYPE_NORMAL, NULL }, - { "url", "url", PROP_TYPE_NORMAL, NULL }, - { "mailer", "mailer", PROP_TYPE_NORMAL, NULL }, - { "org", "org", PROP_TYPE_NORMAL, NULL }, - { "org_unit", "org_unit", PROP_TYPE_NORMAL, NULL }, - { "office", "office", PROP_TYPE_NORMAL, NULL }, - { "title", "title", PROP_TYPE_NORMAL, NULL }, - { "role", "role", PROP_TYPE_NORMAL, NULL }, - { "manager", "manager", PROP_TYPE_NORMAL, NULL }, - { "assistant", "assistant", PROP_TYPE_NORMAL, NULL }, - { "nickname", "nickname", PROP_TYPE_NORMAL, NULL }, - { "spouse", "spouse", PROP_TYPE_NORMAL, NULL }, - { "email", "email", PROP_TYPE_LIST, compare_email }, - { "phone", "phone", PROP_TYPE_LIST, compare_phone }, - { "address", "address", PROP_TYPE_LIST, compare_address }, - { "note", "note", PROP_TYPE_NORMAL, NULL }, + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FILE_AS, "file_as", "file_as" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "full_name" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_URL, "url", "url" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MAILER, "mailer", "mailer"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG, "org", "org"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG_UNIT, "org_unit", "org_unit"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_OFFICE, "office", "office"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_TITLE, "title", "title"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ROLE, "role", "role"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MANAGER, "manager", "manager"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ASSISTANT, "assistant", "assistant"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NICKNAME, "nickname", "nickname"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_SPOUSE, "spouse", "spouse" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NOTE, "note", "note"), + LIST_PROP ( "email", "email", compare_email ), + LIST_PROP ( "phone", "phone", compare_phone ), + LIST_PROP ( "address", "address", compare_address ), }; static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); @@ -268,35 +246,41 @@ entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f, char *propname; struct prop_info *info = NULL; int i; + gboolean any_field; propname = argv[0]->value.string; + any_field = !strcmp(propname, "x-evolution-any-field"); for (i = 0; i < num_prop_infos; i ++) { - if (!strcmp (prop_info_table[i].query_prop, propname)) { + if (any_field + || strcmp (prop_info_table[i].query_prop, propname)) { info = &prop_info_table[i]; - break; - } - } - - if (info) { - if (info->prop_type == PROP_TYPE_NORMAL) { - char *prop = NULL; - /* searches where the query's property - maps directly to an ecard property */ - - gtk_object_get(GTK_OBJECT(ctx->ecard), - info->ecard_prop, &prop, NULL); - - if (prop && compare(prop, argv[1]->value.string)) { - truth = TRUE; - } - if ((!prop) && compare("", argv[1]->value.string)) { - truth = TRUE; + + if (info->prop_type == PROP_TYPE_NORMAL) { + char *prop = NULL; + /* searches where the query's property + maps directly to an ecard property */ + + prop = e_card_simple_get (ctx->card, info->field_id); + + if (prop && compare(prop, argv[1]->value.string)) { + truth = TRUE; + } + if ((!prop) && compare("", argv[1]->value.string)) { + truth = TRUE; + } } - } - else if (info->prop_type == PROP_TYPE_LIST) { + else if (info->prop_type == PROP_TYPE_LIST) { /* the special searches that match any of the list elements */ - truth = info->list_compare (ctx->ecard, argv[1]->value.string, compare); + truth = info->list_compare (ctx->card, argv[1]->value.string, compare); + } + + /* if we're looking at all fields and find a match, + or if we're just looking at this one field, + break. */ + if ((any_field && truth) + || !any_field) + break; } } @@ -389,17 +373,17 @@ vcard_matches_search (PASBackendFileBookView *view, char *vcard_string) ESExpResult *r; gboolean retval; - view->search_context->ecard = e_card_new (vcard_string); + view->search_context->card = e_card_simple_new (e_card_new (vcard_string)); /* if it's not a valid vcard why is it in our db? :) */ - if (!view->search_context->ecard) + if (!view->search_context->card) return FALSE; r = e_sexp_eval(view->search_sexp); retval = (r && r->type == ESEXP_RES_BOOL && r->value.bool); - gtk_object_unref(GTK_OBJECT(view->search_context->ecard)); + gtk_object_unref(GTK_OBJECT(view->search_context->card)); e_sexp_result_free(r); diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index 5257177328..3968648972 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -314,6 +314,36 @@ pas_backend_ldap_process_get_cursor (PASBackend *backend, cursor); } +static void +construct_email_list(ECardSimple *card, const char *prop, char **values) +{ + int i; + + for (i = 0; values[i] && i < 3; i ++) { + e_card_simple_set_email (card, i, values[i]); + } +} + +struct prop_info { + ECardSimpleField field_id; + char *query_prop; + char *ldap_attr; +#define PROP_TYPE_NORMAL 0x01 +#define PROP_TYPE_LIST 0x02 +#define PROP_TYPE_LISTITEM 0x03 + int prop_type; + void (*construct_list_func)(ECardSimple *card, const char *prop, char **values); +} prop_info_table[] = { + /* field_id, query prop, ldap attr, type, list construct function */ + { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "cn", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_TITLE, "title", "title", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_ORG, "org", "o", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "phone", "telephonenumber", PROP_TYPE_NORMAL, NULL }, + { 0 /* unused */, "email", "mail", PROP_TYPE_LIST, construct_email_list }, +}; + +static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); + static ESExpResult * func_and(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) { @@ -415,18 +445,59 @@ func_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data && argv[1]->type == ESEXP_RES_STRING) { char *propname = argv[0]->value.string; char *str = argv[1]->value.string; - char *ldap_attr = query_prop_to_ldap(propname); gboolean one_star = FALSE; if (strlen(str) == 0) one_star = TRUE; - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=*%s%s)", - ldap_attr, - str, - one_star ? "" : "*")); + if (!strcmp (propname, "x-evolution-any-field")) { + int i; + int query_length; + char *big_query; + char *header, *footer; + char *match_str; + + header = g_malloc0((num_prop_infos - 1) * 2 + 1); + footer = g_malloc0(num_prop_infos + 1); + for (i = 0; i < num_prop_infos - 1; i ++) { + strcat (header, "(|"); + strcat (footer, ")"); + } + + match_str = g_strdup_printf("=*%s%s)", + str, one_star ? "" : "*"); + + query_length = strlen (header); + + for (i = 0; i < num_prop_infos; i ++) { + query_length += 1 + strlen(prop_info_table[i].ldap_attr) + strlen (match_str); + } + + big_query = g_malloc0(query_length + 1); + strcat (big_query, header); + for (i = 0; i < num_prop_infos; i ++) { + strcat (big_query, "("); + strcat (big_query, prop_info_table[i].ldap_attr); + strcat (big_query, match_str); + } + strcat (big_query, footer); + + *list = g_list_prepend(*list, big_query); + + g_free (match_str); + g_free (header); + g_free (footer); + } + else { + char *ldap_attr = query_prop_to_ldap(propname); + + if (ldap_attr) + *list = g_list_prepend(*list, + g_strdup_printf("(%s=*%s%s)", + ldap_attr, + str, + one_star ? "" : "*")); + } } r = e_sexp_result_new(ESEXP_RES_BOOL); @@ -578,36 +649,6 @@ pas_backend_ldap_build_query (gchar *query) return retval; } -static void -construct_email_list(ECardSimple *card, const char *prop, char **values) -{ - int i; - - for (i = 0; values[i] && i < 3; i ++) { - e_card_simple_set_email (card, i, values[i]); - } -} - -struct prop_info { - ECardSimpleField field_id; - char *query_prop; - char *ldap_attr; -#define PROP_TYPE_NORMAL 0x01 -#define PROP_TYPE_LIST 0x02 -#define PROP_TYPE_LISTITEM 0x03 - int prop_type; - void (*construct_list_func)(ECardSimple *card, const char *prop, char **values); -} prop_info_table[] = { - /* field_id, query prop, ldap attr, type, list construct function */ - { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "cn", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_TITLE, "title", "title", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_ORG, "org", "o", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "phone", "telephonenumber", PROP_TYPE_NORMAL, NULL }, - { 0 /* unused */, "email", "mail", PROP_TYPE_LIST, construct_email_list }, -}; - -static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); - static gchar * query_prop_to_ldap(gchar *query_prop) { diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index bf2b054280..d25e41c313 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -438,7 +438,7 @@ search_entry_activated (GtkWidget* widget, gpointer user_data) if (search_word && strlen (search_word)) search_query = g_strdup_printf ( - "(or (contains \"full_name\" \"%s\") (contains \"org\" \"%s\"))", + "(contains \"x-evolution-any-field\" \"%s\")", search_word, search_word); else search_query = g_strdup ( @@ -1023,7 +1023,7 @@ change_view_type (AddressbookView *view, AddressbookViewType view_type) if (view->view_type != ADDRESSBOOK_VIEW_NONE) query = get_query(view); else - query = g_strdup("(contains \"full_name\" \"\")"); + query = g_strdup("(contains \"x-evolution-any-field\" \"\")"); switch (view_type) { diff --git a/addressbook/gui/component/e-addressbook-model.c b/addressbook/gui/component/e-addressbook-model.c index 87b872784c..d46b42fe00 100644 --- a/addressbook/gui/component/e-addressbook-model.c +++ b/addressbook/gui/component/e-addressbook-model.c @@ -254,7 +254,7 @@ e_addressbook_model_init (GtkObject *object) { EAddressbookModel *model = E_ADDRESSBOOK_MODEL(object); model->book = NULL; - model->query = g_strdup("(contains \"full_name\" \"\")"); + model->query = g_strdup("(contains \"x-evolution-any-field\" \"\")"); model->book_view = NULL; model->get_view_idle = 0; model->create_card_id = 0; diff --git a/addressbook/gui/minicard/e-minicard-view.c b/addressbook/gui/minicard/e-minicard-view.c index 28f8243dff..8e275bdb2b 100644 --- a/addressbook/gui/minicard/e-minicard-view.c +++ b/addressbook/gui/minicard/e-minicard-view.c @@ -98,7 +98,7 @@ static void e_minicard_view_init (EMinicardView *view) { view->book = NULL; - view->query = g_strdup("(contains \"full_name\" \"\")"); + view->query = g_strdup("(contains \"x-evolution-any-field\" \"\")"); view->book_view = NULL; view->get_view_idle = 0; view->create_card_id = 0; diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c index 87b872784c..d46b42fe00 100644 --- a/addressbook/gui/widgets/e-addressbook-model.c +++ b/addressbook/gui/widgets/e-addressbook-model.c @@ -254,7 +254,7 @@ e_addressbook_model_init (GtkObject *object) { EAddressbookModel *model = E_ADDRESSBOOK_MODEL(object); model->book = NULL; - model->query = g_strdup("(contains \"full_name\" \"\")"); + model->query = g_strdup("(contains \"x-evolution-any-field\" \"\")"); model->book_view = NULL; model->get_view_idle = 0; model->create_card_id = 0; diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c index 28f8243dff..8e275bdb2b 100644 --- a/addressbook/gui/widgets/e-minicard-view.c +++ b/addressbook/gui/widgets/e-minicard-view.c @@ -98,7 +98,7 @@ static void e_minicard_view_init (EMinicardView *view) { view->book = NULL; - view->query = g_strdup("(contains \"full_name\" \"\")"); + view->query = g_strdup("(contains \"x-evolution-any-field\" \"\")"); view->book_view = NULL; view->get_view_idle = 0; view->create_card_id = 0; |