From c1103e4a29d0f8ec59cefcfff2ff44dbce151262 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Thu, 23 Oct 2003 12:52:46 +0000 Subject: make it work with the new ebook api 003-10-21 JP Rosevear * conduit/address-conduit.c: make it work with the new ebook api * backend/pas/pas-book.c (pas_book_respond_get_changes): put the vcard in for every change * backend/pas/pas-backend.c (pas_backend_change_add_new): just use the vcard field (pas_backend_change_modify_new): ditto (pas_backend_change_delete_new): ditto * backend/pas/pas-backend-file.c (pas_backend_file_changes_foreach_key): create a fake contact with the uid (pas_backend_file_get_changes): add the card to the changes * backend/ebook/tests/ebook/test-changes.c (main): just print the uid * backend/ebook/e-book.c (e_book_free_change_list): unref the contact * backend/ebook/e-book-types.h: the change struct contains an EContact now * backend/ebook/e-book-listener.c (impl_BookListener_respond_get_changes): create the contact from the vcard string * backend/idl/addressbook.idl: Book change item is no longer a union, it always gives back a card svn path=/trunk/; revision=23031 --- addressbook/backend/ebook/e-book-listener.c | 6 ++---- addressbook/backend/ebook/e-book-types.h | 4 ++-- addressbook/backend/ebook/e-book.c | 2 +- .../backend/ebook/tests/ebook/test-changes.c | 2 +- addressbook/backend/idl/addressbook.idl | 10 +++------- addressbook/backend/pas/pas-backend-file.c | 23 ++++++++++++++++++---- addressbook/backend/pas/pas-backend.c | 14 ++++++------- addressbook/backend/pas/pas-book.c | 12 +---------- 8 files changed, 36 insertions(+), 37 deletions(-) (limited to 'addressbook/backend') diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c index 0bb5193376..f3a7de266c 100644 --- a/addressbook/backend/ebook/e-book-listener.c +++ b/addressbook/backend/ebook/e-book-listener.c @@ -187,20 +187,18 @@ impl_BookListener_respond_get_changes (PortableServer_Servant servant, EBookChange *change = g_new (EBookChange, 1); GNOME_Evolution_Addressbook_BookChangeItem corba_change = changes->_buffer[i]; - switch (corba_change._d) { + switch (corba_change.changeType) { case GNOME_Evolution_Addressbook_ContactAdded: change->change_type = E_BOOK_CHANGE_CARD_ADDED; - change->vcard = g_strdup (corba_change._u.add_vcard); break; case GNOME_Evolution_Addressbook_ContactDeleted: change->change_type = E_BOOK_CHANGE_CARD_DELETED; - change->id = g_strdup (corba_change._u.del_id); break; case GNOME_Evolution_Addressbook_ContactModified: change->change_type = E_BOOK_CHANGE_CARD_MODIFIED; - change->vcard = g_strdup (corba_change._u.mod_vcard); break; } + change->contact = e_contact_new_from_vcard (corba_change.vcard); response.list = g_list_prepend (response.list, change); } diff --git a/addressbook/backend/ebook/e-book-types.h b/addressbook/backend/ebook/e-book-types.h index 4ca69bd516..9bbc66e622 100644 --- a/addressbook/backend/ebook/e-book-types.h +++ b/addressbook/backend/ebook/e-book-types.h @@ -13,6 +13,7 @@ #define __E_BOOK_TYPES_H__ #include +#include G_BEGIN_DECLS @@ -59,8 +60,7 @@ typedef enum { typedef struct { EBookChangeType change_type; - char *vcard; /* used in the ADDED/MODIFIED case */ - char *id; /* used in the DELETED case */ + EContact *contact; } EBookChange; G_END_DECLS diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index c84b4c3f83..b551c8727b 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -1244,7 +1244,7 @@ e_book_free_change_list (GList *change_list) for (l = change_list; l; l = l->next) { EBookChange *change = l->data; - g_free (change->vcard); + g_object_unref (change->contact); g_free (change); } diff --git a/addressbook/backend/ebook/tests/ebook/test-changes.c b/addressbook/backend/ebook/tests/ebook/test-changes.c index 0c91f30cf4..f1e65adaa0 100644 --- a/addressbook/backend/ebook/tests/ebook/test-changes.c +++ b/addressbook/backend/ebook/tests/ebook/test-changes.c @@ -71,7 +71,7 @@ main (int argc, char **argv) exit(0); } - printf ("got changed vcard back: %s\n", change->vcard); + printf ("got changed vcard back: %s\n", e_contact_get_const (change->contact, E_CONTACT_UID)); e_book_free_change_list (changes); diff --git a/addressbook/backend/idl/addressbook.idl b/addressbook/backend/idl/addressbook.idl index bfdbae6882..193d1246ab 100644 --- a/addressbook/backend/idl/addressbook.idl +++ b/addressbook/backend/idl/addressbook.idl @@ -24,13 +24,9 @@ module Addressbook { ContactDeleted }; - union BookChangeItem switch (BookChangeType) { - case ContactAdded: - VCard add_vcard; - case ContactModified: - VCard mod_vcard; - case ContactDeleted: - ContactId del_id; + struct BookChangeItem { + BookChangeType changeType; + VCard vcard; }; typedef sequence BookChangeList; diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 923c7e907d..73f1797320 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -515,6 +515,7 @@ typedef struct { GList *mod_cards; GList *mod_ids; GList *del_ids; + GList *del_cards; } PASBackendFileChangeContext; static void @@ -530,10 +531,21 @@ pas_backend_file_changes_foreach_key (const char *key, gpointer user_data) db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error != 0) { + EContact *contact; char *id = id_dbt.data; + char *vcard_string; + + contact = e_contact_new (); + e_contact_set (contact, E_CONTACT_UID, id); + + vcard_string = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30); ctx->del_ids = g_list_append (ctx->del_ids, g_strdup (id)); + ctx->del_cards = g_list_append (ctx->del_cards, + vcard_string); + + g_object_unref (contact); } } @@ -645,14 +657,17 @@ pas_backend_file_get_changes (PASBackendSync *backend, g_free (i->data); g_free (v->data); - } - for (i = ctx.del_ids; i != NULL; i = i->next){ + } + for (i = ctx.del_ids, v = ctx.del_cards; i != NULL; i = i->next, v = v->next){ char *id = i->data; - + char *vcard = v->data; + e_dbhash_remove (ehash, id); + changes = g_list_prepend (changes, - pas_backend_change_delete_new (id)); + pas_backend_change_delete_new (vcard)); g_free (i->data); + g_free (v->data); } e_dbhash_write (ehash); diff --git a/addressbook/backend/pas/pas-backend.c b/addressbook/backend/pas/pas-backend.c index 5b559940d1..a447d64851 100644 --- a/addressbook/backend/pas/pas-backend.c +++ b/addressbook/backend/pas/pas-backend.c @@ -448,8 +448,8 @@ pas_backend_change_add_new (const char *vcard) { GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc(); - new_change->_d = GNOME_Evolution_Addressbook_ContactAdded; - new_change->_u.add_vcard = CORBA_string_dup (vcard); + new_change->changeType= GNOME_Evolution_Addressbook_ContactAdded; + new_change->vcard = CORBA_string_dup (vcard); return new_change; } @@ -459,19 +459,19 @@ pas_backend_change_modify_new (const char *vcard) { GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc(); - new_change->_d = GNOME_Evolution_Addressbook_ContactModified; - new_change->_u.mod_vcard = CORBA_string_dup (vcard); + new_change->changeType= GNOME_Evolution_Addressbook_ContactModified; + new_change->vcard = CORBA_string_dup (vcard); return new_change; } GNOME_Evolution_Addressbook_BookChangeItem* -pas_backend_change_delete_new (const char *id) +pas_backend_change_delete_new (const char *vcard) { GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc(); - new_change->_d = GNOME_Evolution_Addressbook_ContactDeleted; - new_change->_u.del_id = CORBA_string_dup (id); + new_change->changeType= GNOME_Evolution_Addressbook_ContactDeleted; + new_change->vcard = CORBA_string_dup (vcard); return new_change; } diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c index 08078887b6..346b37ceed 100644 --- a/addressbook/backend/pas/pas-book.c +++ b/addressbook/backend/pas/pas-book.c @@ -612,17 +612,7 @@ pas_book_respond_get_changes (PASBook *book, for (i = 0, l = changes; l; l = l->next, i ++) { GNOME_Evolution_Addressbook_BookChangeItem *change = (GNOME_Evolution_Addressbook_BookChangeItem*)l->data; changelist._buffer[i] = *change; - switch (change->_d) { - case GNOME_Evolution_Addressbook_ContactAdded: - changelist._buffer[i]._u.add_vcard = CORBA_string_dup (change->_u.add_vcard); - break; - case GNOME_Evolution_Addressbook_ContactModified: - changelist._buffer[i]._u.mod_vcard = CORBA_string_dup (change->_u.mod_vcard); - break; - case GNOME_Evolution_Addressbook_ContactDeleted: - changelist._buffer[i]._u.del_id = CORBA_string_dup (change->_u.del_id); - break; - } + changelist._buffer[i].vcard = CORBA_string_dup (change->vcard); } g_list_foreach (changes, (GFunc)CORBA_free, NULL); -- cgit v1.2.3