From f2aa13a875849bdf15fa81a7a307f6358b0843c2 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Mon, 16 Jan 2006 16:36:19 +0000 Subject: Add e_data_book_view_notify_update_vcard(). 2006-01-16 Ross Burton * libedata-book/e-data-book-view.h: * libedata-book/e-data-book-view.c: Add e_data_book_view_notify_update_vcard(). * backends/file/e-book-backend-file.c: Use e_data_book_view_notify_update_vcard to avoid useless vCard->EContact->vCard round-trip. --- addressbook/ChangeLog | 10 ++++++ addressbook/backends/file/e-book-backend-file.c | 12 ++----- addressbook/libedata-book/e-data-book-view.c | 47 +++++++++++++++++++++++++ addressbook/libedata-book/e-data-book-view.h | 4 +++ 4 files changed, 64 insertions(+), 9 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index d3628d304..f3a2f7cd8 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,13 @@ +2006-01-16 Ross Burton + + * libedata-book/e-data-book-view.h: + * libedata-book/e-data-book-view.c: + Add e_data_book_view_notify_update_vcard(). + + * backends/file/e-book-backend-file.c: + Use e_data_book_view_notify_update_vcard to avoid useless + vCard->EContact->vCard round-trip. + 2006-01-16 Sushma Rai * backends/ldap/e-book-backend-ldap.c prop_info: Added GROUP_PROP. diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c index 8baf4200b..29d101ebb 100644 --- a/addressbook/backends/file/e-book-backend-file.c +++ b/addressbook/backends/file/e-book-backend-file.c @@ -563,13 +563,8 @@ book_view_thread (gpointer data) db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error == 0) { - EContact *contact = create_contact (id_dbt.data, vcard_dbt.data); /* notify_update will check if it matches for us */ - e_data_book_view_notify_update (book_view, contact); - - g_object_unref (contact); - - free (vcard_dbt.data); + e_data_book_view_notify_update_vcard (book_view, vcard_dbt.data); } else { g_warning ("db->get returned %d", db_error); @@ -584,6 +579,7 @@ book_view_thread (gpointer data) memset (&id_dbt, 0, sizeof (id_dbt)); memset (&vcard_dbt, 0, sizeof (vcard_dbt)); + vcard_dbt.flags = DB_DBT_MALLOC; db_error = db->cursor (db, NULL, &dbc, 0); if (db_error == 0) { @@ -600,10 +596,8 @@ book_view_thread (gpointer data) /* don't include the version in the list of cards */ if (strcmp (id_dbt.data, E_BOOK_BACKEND_FILE_VERSION_NAME)) { - EContact *contact = create_contact (id_dbt.data, vcard_dbt.data); /* notify_update will check if it matches for us */ - e_data_book_view_notify_update (book_view, contact); - g_object_unref (contact); + e_data_book_view_notify_update_vcard (book_view, vcard_dbt.data); } db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); diff --git a/addressbook/libedata-book/e-data-book-view.c b/addressbook/libedata-book/e-data-book-view.c index 8ac8f85b9..26d0e70c1 100644 --- a/addressbook/libedata-book/e-data-book-view.c +++ b/addressbook/libedata-book/e-data-book-view.c @@ -271,6 +271,53 @@ e_data_book_view_notify_update (EDataBookView *book_view, g_mutex_unlock (book_view->priv->pending_mutex); } +/** + * e_data_book_view_notify_update_vcard: + * @book_view: an #EDataBookView + * @vcard: a plain vCard + * + * Notify listeners that @vcard has changed. This can + * trigger an add, change or removal event depending on + * whether the change causes the contact to start matching, + * no longer match, or stay matching the query specified + * by @book_view. This method should be preferred over + * #e_data_book_view_notify_update when the native + * representation of a contact is a vCard. + **/ +void +e_data_book_view_notify_update_vcard (EDataBookView *book_view, char *vcard) +{ + gboolean currently_in_view, want_in_view; + const char *id; + EContact *contact; + + g_mutex_lock (book_view->priv->pending_mutex); + + contact = e_contact_new_from_vcard (vcard); + id = e_contact_get_const (contact, E_CONTACT_UID); + + currently_in_view = + g_hash_table_lookup (book_view->priv->ids, id) != NULL; + want_in_view = + e_book_backend_sexp_match_contact (book_view->priv->card_sexp, contact); + + if (want_in_view) { + if (currently_in_view) + notify_change (book_view, vcard); + else + notify_add (book_view, id, vcard); + } else { + if (currently_in_view) + notify_remove (book_view, id); + else + /* else nothing; we're removing a card that wasn't there */ + free (vcard); + } + + g_object_unref (contact); + g_mutex_unlock (book_view->priv->pending_mutex); +} + /** * e_data_book_view_notify_remove: * @book_view: an #EDataBookView diff --git a/addressbook/libedata-book/e-data-book-view.h b/addressbook/libedata-book/e-data-book-view.h index 564f9ddf6..1fcdf04dd 100644 --- a/addressbook/libedata-book/e-data-book-view.h +++ b/addressbook/libedata-book/e-data-book-view.h @@ -61,6 +61,10 @@ GMutex* e_data_book_view_get_mutex (EDataBookView void e_data_book_view_notify_update (EDataBookView *book_view, EContact *contact); + +void e_data_book_view_notify_update_vcard (EDataBookView *book_view, + char *vcard); + void e_data_book_view_notify_remove (EDataBookView *book_view, const char *id); void e_data_book_view_notify_complete (EDataBookView *book_view, -- cgit v1.2.1