From 8993f0bf1298bcbad2fd9f7eb044ccb493897d9d Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Sat, 26 Jun 2004 01:42:27 +0000 Subject: Implement. (eab_contact_compare_name): Don't leak if only one of the 2004-06-25 Hans Petter Jansson * gui/meging/eab-contact-compare.[ch] (eab_contact_compare_file_as): Implement. (eab_contact_compare_name): Don't leak if only one of the strings is NULL. (use_common_book_cb): Include file_as in query. svn path=/trunk/; revision=26527 --- addressbook/gui/merging/eab-contact-compare.c | 45 +++++++++++++++++++++++++-- addressbook/gui/merging/eab-contact-compare.h | 1 + 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/merging/eab-contact-compare.c b/addressbook/gui/merging/eab-contact-compare.c index f4f9afe1a7..bc68784ed7 100644 --- a/addressbook/gui/merging/eab-contact-compare.c +++ b/addressbook/gui/merging/eab-contact-compare.c @@ -285,6 +285,37 @@ eab_contact_compare_name_to_string_full (EContact *contact, const gchar *str, gb return match_type; } +EABContactMatchType +eab_contact_compare_file_as (EContact *contact1, EContact *contact2) +{ + EABContactMatchType match_type; + gchar *a, *b; + + g_return_val_if_fail (E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE); + g_return_val_if_fail (E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE); + + a = e_contact_get (contact1, E_CONTACT_FILE_AS); + b = e_contact_get (contact2, E_CONTACT_FILE_AS); + + if (a == NULL || b == NULL) { + g_free (a); + g_free (b); + return EAB_CONTACT_MATCH_NOT_APPLICABLE; + } + + if (!strcmp (a, b)) + match_type = EAB_CONTACT_MATCH_EXACT; + else if (g_utf8_validate (a, -1, NULL) && g_utf8_validate (b, -1, NULL) && + !g_utf8_collate (a, b)) + match_type = EAB_CONTACT_MATCH_PARTIAL; + else + match_type = EAB_CONTACT_MATCH_NONE; + + g_free (a); + g_free (b); + return match_type; +} + EABContactMatchType eab_contact_compare_name (EContact *contact1, EContact *contact2) { @@ -298,8 +329,11 @@ eab_contact_compare_name (EContact *contact1, EContact *contact2) a = e_contact_get (contact1, E_CONTACT_NAME); b = e_contact_get (contact2, E_CONTACT_NAME); - if (a == NULL || b == NULL) + if (a == NULL || b == NULL) { + g_free (a); + g_free (b); return EAB_CONTACT_MATCH_NOT_APPLICABLE; + } if (a->given && b->given && *a->given && *b->given) { ++possible; @@ -530,6 +564,7 @@ eab_contact_compare (EContact *contact1, EContact *contact2) result = combine_comparisons (result, eab_contact_compare_email (contact1, contact2)); result = combine_comparisons (result, eab_contact_compare_address (contact1, contact2)); result = combine_comparisons (result, eab_contact_compare_telephone (contact1, contact2)); + result = combine_comparisons (result, eab_contact_compare_file_as (contact1, contact2)); return result; } @@ -618,7 +653,7 @@ use_common_book_cb (EBook *book, gpointer closure) GList *contact_email; gchar *query_parts[MAX_QUERY_PARTS]; gint p=0; - gchar *qj; + gchar *contact_file_as, *qj; EBookQuery *query = NULL; int i; @@ -628,6 +663,12 @@ use_common_book_cb (EBook *book, gpointer closure) return; } + contact_file_as = e_contact_get (contact, E_CONTACT_FILE_AS); + if (contact_file_as) { + query_parts [p++] = g_strdup_printf ("(contains \"file_as\" \"%s\")", contact_file_as); + g_free (contact_file_as); + } + contact_name = e_contact_get (contact, E_CONTACT_NAME); if (contact_name) { if (contact_name->given && *contact_name->given) diff --git a/addressbook/gui/merging/eab-contact-compare.h b/addressbook/gui/merging/eab-contact-compare.h index 4b97b3c698..153e44aef1 100644 --- a/addressbook/gui/merging/eab-contact-compare.h +++ b/addressbook/gui/merging/eab-contact-compare.h @@ -56,6 +56,7 @@ EABContactMatchType eab_contact_compare_name_to_string_full (EContact *contact, gint *matched_parts, EABContactMatchPart *first_matched_part, gint *matched_character_count); +EABContactMatchType eab_contact_compare_file_as (EContact *contact1, EContact *contact2); EABContactMatchType eab_contact_compare_name (EContact *contact1, EContact *contact2); EABContactMatchType eab_contact_compare_nickname (EContact *contact1, EContact *contact2); EABContactMatchType eab_contact_compare_email (EContact *contact1, EContact *contact2); -- cgit