diff options
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/ChangeLog | 10 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-compare.c | 62 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-compare.h | 2 | ||||
-rw-r--r-- | addressbook/gui/merging/e-card-merging.c | 2 |
4 files changed, 70 insertions, 6 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 7c8190de9d..a720f63274 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,13 @@ +2001-06-11 Christopher James Lahey <clahey@ximian.com> + + * backend/ebook/e-card-compare.c, backend/ebook/e-card-compare.h + (e_card_locate_match_full): Added this function to let you do + slightly more complicated searches. + + * gui/merging/e-card-merging.c (e_card_merging_book_add_card): Use + e_card_locate_match_full to check if the card exists in the book + it's being added to instead of in the default book. + 2001-06-09 Christopher James Lahey <clahey@ximian.com> * gui/component/select-names/e-select-names-completion.c diff --git a/addressbook/backend/ebook/e-card-compare.c b/addressbook/backend/ebook/e-card-compare.c index f249c1727b..136535409b 100644 --- a/addressbook/backend/ebook/e-card-compare.c +++ b/addressbook/backend/ebook/e-card-compare.c @@ -326,6 +326,7 @@ e_card_compare (ECard *card1, ECard *card2) typedef struct _MatchSearchInfo MatchSearchInfo; struct _MatchSearchInfo { ECard *card; + GList *avoid; ECardMatchQueryCallback cb; gpointer closure; }; @@ -375,6 +376,7 @@ use_common_book_cb (EBook *book, gpointer closure) gchar *query_parts[MAX_QUERY_PARTS]; gint p=0; gchar *query, *qj; + int i; if (book == NULL) { info->cb (info->card, NULL, E_CARD_MATCH_NONE, info->closure); @@ -409,7 +411,7 @@ use_common_book_cb (EBook *book, gpointer closure) } ++s; } - query_parts[p++] = g_strdup_printf ("beginswith \"email\" \"%s\")", addr); + query_parts[p++] = g_strdup_printf ("(beginswith \"email\" \"%s\")", addr); g_free (addr); } e_iterator_next (iter); @@ -421,18 +423,34 @@ use_common_book_cb (EBook *book, gpointer closure) /* Build up our full query from the parts. */ query_parts[p] = NULL; qj = g_strjoinv (" ", query_parts); + for(i = 0; query_parts[i] != NULL; i++) + g_free(query_parts[i]); if (p > 0) { query = g_strdup_printf ("(or %s)", qj); + g_free (qj); } else { query = qj; - qj = NULL; + } + + if (info->avoid) { + GList *iterator; + p = 0; + query_parts[p++] = query; + for (iterator = info->avoid; iterator; iterator = iterator->next) { + query_parts[p++] = g_strdup_printf("(not (is \"id\" \"%s\"))", e_card_get_id (iterator->data)); + } + query_parts[p] = 0; + qj = g_strjoinv (" ", query_parts); + for(i = 0; query_parts[i] != NULL; i++) + g_free(query_parts[i]); + query = g_strdup_printf ("(and %s)", qj); + g_list_foreach (info->avoid, (GFunc) gtk_object_unref, NULL); + g_list_free (info->avoid); + info->avoid = NULL; } e_book_simple_query (book, query, simple_query_cb, info); - for (p=0; query_parts[p]; ++p) - g_free (query_parts[p]); - g_free (qj); g_free (query); } @@ -449,7 +467,41 @@ e_card_locate_match (ECard *card, ECardMatchQueryCallback cb, gpointer closure) gtk_object_ref (GTK_OBJECT (card)); info->cb = cb; info->closure = closure; + info->avoid = NULL; e_book_use_local_address_book (use_common_book_cb, info); } +/** + * e_card_locate_match_full: + * @book: The book to look in. If this is NULL, use the main local + * addressbook. + * @card: The card to compare to. + * @avoid: A list of cards to not match. These will not show up in the search. + * @cb: The function to call. + * @closure: The closure to add to the call. + * + * Look for the best match and return it using the ECardMatchQueryCallback. + **/ +void +e_card_locate_match_full (EBook *book, ECard *card, GList *avoid, ECardMatchQueryCallback cb, gpointer closure) +{ + MatchSearchInfo *info; + + g_return_if_fail (card && E_IS_CARD (card)); + g_return_if_fail (cb != NULL); + + info = g_new (MatchSearchInfo, 1); + info->card = card; + gtk_object_ref (GTK_OBJECT (card)); + info->cb = cb; + info->closure = closure; + info->avoid = g_list_copy (avoid); + g_list_foreach (info->avoid, (GFunc) gtk_object_ref, NULL); + + if (book) + use_common_book_cb (book, info); + else + e_book_use_local_address_book (use_common_book_cb, info); +} + diff --git a/addressbook/backend/ebook/e-card-compare.h b/addressbook/backend/ebook/e-card-compare.h index 7c55dabeab..e5f034600b 100644 --- a/addressbook/backend/ebook/e-card-compare.h +++ b/addressbook/backend/ebook/e-card-compare.h @@ -28,6 +28,7 @@ #ifndef __E_CARD_COMPARE_H__ #define __E_CARD_COMPARE_H__ +#include "e-book.h" #include "e-card.h" typedef enum { @@ -49,6 +50,7 @@ ECardMatchType e_card_compare_telephone (ECard *card1, ECard *card2); ECardMatchType e_card_compare (ECard *card1, ECard *card2); void e_card_locate_match (ECard *card, ECardMatchQueryCallback cb, gpointer closure); +void e_card_locate_match_full (EBook *book, ECard *card, GList *avoid, ECardMatchQueryCallback cb, gpointer closure); diff --git a/addressbook/gui/merging/e-card-merging.c b/addressbook/gui/merging/e-card-merging.c index 701ab69da9..c367a60271 100644 --- a/addressbook/gui/merging/e-card-merging.c +++ b/addressbook/gui/merging/e-card-merging.c @@ -82,7 +82,7 @@ e_card_merging_book_add_card (EBook *book, lookup->cb = cb; lookup->closure = closure; - e_card_locate_match (card, match_query_callback, lookup); + e_card_locate_match_full (book, card, NULL, match_query_callback, lookup); return TRUE; } |