new function for searching all email addresses of a contact.

* addressbook/backend/pas/pas-backend-file.c
	(compare_email): new function for searching all email addresses of
	a contact.
	(compare_phone): new function for searching all phone numbers of a
	contact.
	(compare_address): new function for searching all addresses of a
	contact (unimplemented as yet).
	(entry_compare): add support for searching the list items "email",
	"phone" and "address".

svn path=/trunk/; revision=2393
This commit is contained in:
Chris Toshok
2000-04-11 16:04:48 +00:00
parent 562afc46d5
commit b4cea26ae4
2 changed files with 95 additions and 7 deletions

View File

@ -10,9 +10,19 @@
function.
(func_is): new function, implementing "is" for searches.
(endswith_helper): new function.
(func_endswith) new function, implementing "endswith" for searches.
(func_endswith) new function, implementing "endswith" for
searches.
(beginswith_helper): new function.
(func_beginswith): new function, implementing "beginswith" for searches.
(func_beginswith): new function, implementing "beginswith" for
searches.
(compare_email): new function for searching all email addresses of
a contact.
(compare_phone): new function for searching all phone numbers of a
contact.
(compare_address): new function for searching all addresses of a
contact (unimplemented as yet).
(entry_compare): add support for searching the list items "email",
"phone" and "address".
2000-04-11 Christopher James Lahey <clahey@helixcode.com>

View File

@ -154,7 +154,7 @@ pas_backend_file_create_unique_id (char *vcard)
}
static char *
get_e_card_prop (ECard *ecard, const char *propname)
get_e_card_string_prop (ECard *ecard, const char *propname)
{
char *prop = NULL;
@ -171,6 +171,72 @@ get_e_card_prop (ECard *ecard, const char *propname)
return prop;
}
static gboolean
compare_email (ECard *ecard, const char *str,
char *(*compare)(const char*, const char*))
{
ECardList *prop_list;
ECardIterator *iter;
gboolean truth = FALSE;
gtk_object_get(GTK_OBJECT(ecard),
"email", &prop_list, NULL);
iter = e_card_list_get_iterator(prop_list);
while (e_card_iterator_is_valid(iter)) {
if (compare((char*)e_card_iterator_get(iter), str)) {
truth = TRUE;
break;
}
else {
e_card_iterator_next(iter);
}
}
gtk_object_unref (GTK_OBJECT(iter));
return truth;
}
static gboolean
compare_phone (ECard *ecard, const char *str,
char *(*compare)(const char*, const char*))
{
ECardList *prop_list;
ECardIterator *iter;
gboolean truth = FALSE;
gtk_object_get(GTK_OBJECT(ecard),
"phone", &prop_list, NULL);
iter = e_card_list_get_iterator(prop_list);
while (e_card_iterator_is_valid(iter)) {
ECardPhone *phone = (ECardPhone*)e_card_iterator_get(iter);
if (compare(phone->number, str)) {
truth = TRUE;
break;
}
else {
e_card_iterator_next(iter);
}
}
gtk_object_unref (GTK_OBJECT(iter));
return truth;
}
static gboolean
compare_address (ECard *ecard, const char *str,
char *(*compare)(const char*, const char*))
{
g_warning("address searching not implemented\n");
return FALSE;
}
static ESExpResult *
entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f,
int argc, struct _ESExpResult **argv,
@ -180,19 +246,31 @@ entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f,
int truth = FALSE;
if (argc>1
&& argv[0]->type == ESEXP_RES_STRING) {
&& argv[0]->type == ESEXP_RES_STRING
&& argv[1]->type == ESEXP_RES_STRING) {
char *propname, *prop = NULL;
propname = argv[0]->value.string;
prop = get_e_card_prop (ctx->ecard, propname);
prop = get_e_card_string_prop (ctx->ecard, propname);
if (prop) {
if (argv[1]->type == ESEXP_RES_STRING
&& compare(prop, argv[1]->value.string)) {
if (compare(prop, argv[1]->value.string)) {
truth = TRUE;
}
}
else{
if (!strcmp(propname, "email")) {
truth = compare_email (ctx->ecard, argv[1]->value.string, compare);
}
else if (!strcasecmp(propname, "phone")) {
truth = compare_phone (ctx->ecard, argv[1]->value.string, compare);
}
else if (!strcasecmp(propname, "address")) {
truth = compare_address (ctx->ecard, argv[1]->value.string, compare);
}
}
}
r = e_sexp_result_new(ESEXP_RES_BOOL);
r->value.bool = truth;