summaryrefslogtreecommitdiff
path: root/addressbook
diff options
context:
space:
mode:
authorRoss Burton <ross@openedhand.com>2006-01-16 16:36:19 +0000
committerRoss Burton <rburton@src.gnome.org>2006-01-16 16:36:19 +0000
commitf2aa13a875849bdf15fa81a7a307f6358b0843c2 (patch)
treee387e96039670cf4672f9529537d88919ba115b9 /addressbook
parent087d208b601aec2bc3e9a3a5b1c1121391600bff (diff)
downloadevolution-data-server-f2aa13a875849bdf15fa81a7a307f6358b0843c2.tar.gz
Add e_data_book_view_notify_update_vcard().
2006-01-16 Ross Burton <ross@openedhand.com> * 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.
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog10
-rw-r--r--addressbook/backends/file/e-book-backend-file.c12
-rw-r--r--addressbook/libedata-book/e-data-book-view.c47
-rw-r--r--addressbook/libedata-book/e-data-book-view.h4
4 files changed, 64 insertions, 9 deletions
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 <ross@openedhand.com>
+
+ * 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 <rsushma@novell.com>
* 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
@@ -272,6 +272,53 @@ e_data_book_view_notify_update (EDataBookView *book_view,
}
/**
+ * 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
* @id: a unique contact ID
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,