aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Rosevear <jpr@ximian.com>2003-10-23 20:52:46 +0800
committerJP Rosevear <jpr@src.gnome.org>2003-10-23 20:52:46 +0800
commitc1103e4a29d0f8ec59cefcfff2ff44dbce151262 (patch)
treea784d9157aed736b4ab365176af124816f55827d
parent2c1e34fa853d10da883be5923ec207fc85dcd8b0 (diff)
downloadgsoc2013-evolution-c1103e4a29d0f8ec59cefcfff2ff44dbce151262.tar.gz
gsoc2013-evolution-c1103e4a29d0f8ec59cefcfff2ff44dbce151262.tar.zst
gsoc2013-evolution-c1103e4a29d0f8ec59cefcfff2ff44dbce151262.zip
make it work with the new ebook api
003-10-21 JP Rosevear <jpr@ximian.com> * 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
-rw-r--r--addressbook/ChangeLog33
-rw-r--r--addressbook/backend/ebook/e-book-listener.c6
-rw-r--r--addressbook/backend/ebook/e-book-types.h4
-rw-r--r--addressbook/backend/ebook/e-book.c2
-rw-r--r--addressbook/backend/ebook/tests/ebook/test-changes.c2
-rw-r--r--addressbook/backend/idl/addressbook.idl10
-rw-r--r--addressbook/backend/pas/pas-backend-file.c23
-rw-r--r--addressbook/backend/pas/pas-backend.c14
-rw-r--r--addressbook/backend/pas/pas-book.c12
-rw-r--r--addressbook/conduit/address-conduit.c861
10 files changed, 402 insertions, 565 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 75919f4713..34c2c58ae9 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -34,6 +34,39 @@
"evolution:button_label" property on the component for use in the
shell.
+2003-10-21 JP Rosevear <jpr@ximian.com>
+
+ * 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
+
2003-10-21 Chris Toshok <toshok@ximian.com>
* tools/evolution-addressbook-abuse.c: use the synchronous api for
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 <glib.h>
+#include <ebook/e-contact.h>
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<BookChangeItem> 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);
diff --git a/addressbook/conduit/address-conduit.c b/addressbook/conduit/address-conduit.c
index 4bc3226903..a85dda4587 100644
--- a/addressbook/conduit/address-conduit.c
+++ b/addressbook/conduit/address-conduit.c
@@ -32,11 +32,6 @@
#include <pi-dlp.h>
#include <pi-address.h>
#include <ebook/e-book.h>
-#include <ebook/e-book-util.h>
-#include <ebook/e-card-types.h>
-#include <ebook/e-card-cursor.h>
-#include <ebook/e-card.h>
-#include <ebook/e-card-simple.h>
#include <gpilotd/gnome-pilot-conduit.h>
#include <gpilotd/gnome-pilot-conduit-sync-abs.h>
#include <libgpilotdCM/gnome-pilot-conduit-management.h>
@@ -63,23 +58,6 @@ void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
#define WARN g_warning
#define INFO g_message
-typedef struct {
- EBookStatus status;
- char *id;
-} CardObjectChangeStatus;
-
-typedef enum {
- CARD_ADDED,
- CARD_MODIFIED,
- CARD_DELETED
-} CardObjectChangeType;
-
-typedef struct
-{
- ECard *card;
- CardObjectChangeType type;
-} CardObjectChange;
-
enum {
LABEL_WORK,
LABEL_HOME,
@@ -91,22 +69,22 @@ enum {
LABEL_MOBILE
};
-static ECardSimpleField priority [] = {
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS,
- E_CARD_SIMPLE_FIELD_PHONE_HOME,
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX,
- E_CARD_SIMPLE_FIELD_EMAIL,
- E_CARD_SIMPLE_FIELD_PHONE_PAGER,
- E_CARD_SIMPLE_FIELD_PHONE_MOBILE,
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2,
- E_CARD_SIMPLE_FIELD_PHONE_HOME_2,
- E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX,
- E_CARD_SIMPLE_FIELD_EMAIL_2,
- E_CARD_SIMPLE_FIELD_PHONE_OTHER,
- E_CARD_SIMPLE_FIELD_PHONE_PRIMARY,
- E_CARD_SIMPLE_FIELD_PHONE_OTHER_FAX,
- E_CARD_SIMPLE_FIELD_EMAIL_3,
- E_CARD_SIMPLE_FIELD_LAST
+static EContactField priority [] = {
+ E_CONTACT_PHONE_BUSINESS,
+ E_CONTACT_PHONE_HOME,
+ E_CONTACT_PHONE_BUSINESS_FAX,
+ E_CONTACT_EMAIL,
+ E_CONTACT_PHONE_PAGER,
+ E_CONTACT_PHONE_MOBILE,
+ E_CONTACT_PHONE_BUSINESS_2,
+ E_CONTACT_PHONE_HOME_2,
+ E_CONTACT_PHONE_HOME_FAX,
+ E_CONTACT_EMAIL_2,
+ E_CONTACT_PHONE_OTHER,
+ E_CONTACT_PHONE_PRIMARY,
+ E_CONTACT_PHONE_OTHER_FAX,
+ E_CONTACT_EMAIL_3,
+ E_CONTACT_FIELD_LAST
};
static int priority_label [] = {
@@ -141,7 +119,7 @@ struct _EAddrLocalRecord {
GnomePilotDesktopRecord local;
/* The corresponding ECard object */
- ECard *ecard;
+ EContact *contact;
/* pilot-link address structure, used for implementing Transmit. */
struct Address *addr;
@@ -151,7 +129,7 @@ struct _EAddrLocalRecord {
static void
addrconduit_destroy_record (EAddrLocalRecord *local)
{
- g_object_unref (local->ecard);
+ g_object_unref (local->contact);
free_Address (local->addr);
g_free (local->addr);
g_free (local);
@@ -163,7 +141,7 @@ struct _EAddrConduitCfg {
GnomePilotConduitSyncType sync_type;
gboolean secret;
- ECardSimpleAddressId default_address;
+ EContactField default_address;
gchar *last_uri;
};
@@ -199,11 +177,11 @@ addrconduit_load_configuration (guint32 pilot_id)
c->secret = gnome_config_get_bool ("secret=FALSE");
address = gnome_config_get_string ("default_address=business");
if (!strcmp (address, "business"))
- c->default_address = E_CARD_SIMPLE_ADDRESS_ID_BUSINESS;
+ c->default_address = E_CONTACT_ADDRESS_WORK;
else if (!strcmp (address, "home"))
- c->default_address = E_CARD_SIMPLE_ADDRESS_ID_HOME;
+ c->default_address = E_CONTACT_ADDRESS_HOME;
else if (!strcmp (address, "other"))
- c->default_address = E_CARD_SIMPLE_ADDRESS_ID_OTHER;
+ c->default_address = E_CONTACT_ADDRESS_OTHER;
g_free (address);
c->last_uri = gnome_config_get_string ("last_uri");
@@ -223,13 +201,13 @@ addrconduit_save_configuration (EAddrConduitCfg *c)
gnome_config_push_prefix (prefix);
gnome_config_set_bool ("secret", c->secret);
switch (c->default_address) {
- case E_CARD_SIMPLE_ADDRESS_ID_BUSINESS:
+ case E_CONTACT_ADDRESS_WORK:
gnome_config_set_string ("default_address", "business");
break;
- case E_CARD_SIMPLE_ADDRESS_ID_HOME:
+ case E_CONTACT_ADDRESS_HOME:
gnome_config_set_string ("default_address", "home");
break;
- case E_CARD_SIMPLE_ADDRESS_ID_OTHER:
+ case E_CONTACT_ADDRESS_OTHER:
gnome_config_set_string ("default_address", "other");
break;
default:
@@ -314,9 +292,9 @@ e_addr_gui_new (EPilotSettings *ps)
}
static const int default_address_map[] = {
- E_CARD_SIMPLE_ADDRESS_ID_BUSINESS,
- E_CARD_SIMPLE_ADDRESS_ID_HOME,
- E_CARD_SIMPLE_ADDRESS_ID_OTHER,
+ E_CONTACT_ADDRESS_WORK,
+ E_CONTACT_ADDRESS_HOME,
+ E_CONTACT_ADDRESS_OTHER,
-1
};
@@ -363,9 +341,6 @@ struct _EAddrConduitContext {
GList *changed;
GHashTable *changed_hash;
GList *locals;
-
- gboolean address_load_tried;
- gboolean address_load_success;
EPilotMap *map;
};
@@ -415,17 +390,8 @@ e_addr_context_destroy (EAddrConduitContext *ctxt)
if (ctxt->changed_hash != NULL)
g_hash_table_destroy (ctxt->changed_hash);
- if (ctxt->changed != NULL) {
- CardObjectChange *coc;
-
- for (l = ctxt->changed; l != NULL; l = l->next) {
- coc = l->data;
-
- g_object_unref (coc->card);
- g_free (coc);
- }
- g_list_free (ctxt->changed);
- }
+ if (ctxt->changed != NULL)
+ e_book_free_change_list (ctxt->changed);
if (ctxt->locals != NULL) {
for (l = ctxt->locals; l != NULL; l = l->next)
@@ -490,87 +456,6 @@ static char *print_remote (GnomePilotRecord *remote)
return buff;
}
-/* Addressbok Server routines */
-static void
-add_card_cb (EBook *ebook, EBookStatus status, const char *id, gpointer closure)
-{
- CardObjectChangeStatus *cons = closure;
-
- cons->status = status;
- cons->id = g_strdup (id);
-
- gtk_main_quit();
-}
-
-static void
-status_cb (EBook *ebook, EBookStatus status, gpointer closure)
-{
- (*(EBookStatus*)closure) = status;
- gtk_main_quit();
-}
-
-static void
-cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure)
-{
- EAddrConduitContext *ctxt = (EAddrConduitContext*)closure;
-
- if (status == E_BOOK_STATUS_SUCCESS) {
- long length;
- int i;
-
- ctxt->address_load_success = TRUE;
-
- length = e_card_cursor_get_length (cursor);
- ctxt->cards = NULL;
- for (i = 0; i < length; i ++) {
- ECard *card = e_card_cursor_get_nth (cursor, i);
-
- if (e_card_evolution_list (card))
- continue;
-
- ctxt->cards = g_list_append (ctxt->cards, card);
- }
-
- gtk_main_quit(); /* end the sub event loop */
- }
- else {
- WARN (_("Cursor could not be loaded\n"));
- gtk_main_quit(); /* end the sub event loop */
- }
-}
-
-static void
-book_open_cb (EBook *book, EBookStatus status, gpointer closure)
-{
- EAddrConduitContext *ctxt = (EAddrConduitContext*)closure;
-
- if (status == E_BOOK_STATUS_SUCCESS) {
- e_book_get_cursor (book, "(contains \"full_name\" \"\")", cursor_cb, ctxt);
- } else {
- WARN (_("EBook not loaded\n"));
- gtk_main_quit(); /* end the sub event loop */
- }
-}
-
-static int
-start_addressbook_server (EAddrConduitContext *ctxt)
-{
- g_return_val_if_fail(ctxt!=NULL,-2);
-
- ctxt->ebook = e_book_new ();
-
- e_book_load_default_book (ctxt->ebook, book_open_cb, ctxt);
-
- /* run a sub event loop to turn ebook's async loading into a
- synchronous call */
- gtk_main ();
-
- if (ctxt->address_load_success)
- return 0;
-
- return -1;
-}
-
/* Utility routines */
static char *
map_name (EAddrConduitContext *ctxt)
@@ -585,128 +470,128 @@ map_name (EAddrConduitContext *ctxt)
static GList *
next_changed_item (EAddrConduitContext *ctxt, GList *changes)
{
- CardObjectChange *coc;
+ EBookChange *ebc;
GList *l;
for (l = changes; l != NULL; l = l->next) {
- coc = l->data;
+ ebc = l->data;
- if (g_hash_table_lookup (ctxt->changed_hash, e_card_get_id (coc->card)))
+ if (g_hash_table_lookup (ctxt->changed_hash, e_contact_get_const (ebc->contact, E_CONTACT_UID)))
return l;
}
return NULL;
}
-static ECardSimpleField
-get_next_mail (ECardSimpleField *field)
+static EContactField
+get_next_mail (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_EMAIL;
+ return E_CONTACT_EMAIL;
switch (*field) {
- case E_CARD_SIMPLE_FIELD_EMAIL:
- return E_CARD_SIMPLE_FIELD_EMAIL_2;
- case E_CARD_SIMPLE_FIELD_EMAIL_2:
- return E_CARD_SIMPLE_FIELD_EMAIL_3;
+ case E_CONTACT_EMAIL:
+ return E_CONTACT_EMAIL_2;
+ case E_CONTACT_EMAIL_2:
+ return E_CONTACT_EMAIL_3;
default:
}
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_home (ECardSimpleField *field)
+static EContactField
+get_next_home (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_HOME;
+ return E_CONTACT_PHONE_HOME;
switch (*field) {
- case E_CARD_SIMPLE_FIELD_PHONE_HOME:
- return E_CARD_SIMPLE_FIELD_PHONE_HOME_2;
+ case E_CONTACT_PHONE_HOME:
+ return E_CONTACT_PHONE_HOME_2;
default:
}
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_work (ECardSimpleField *field)
+static EContactField
+get_next_work (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_BUSINESS;
+ return E_CONTACT_PHONE_BUSINESS;
switch (*field) {
- case E_CARD_SIMPLE_FIELD_PHONE_BUSINESS:
- return E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2;
+ case E_CONTACT_PHONE_BUSINESS:
+ return E_CONTACT_PHONE_BUSINESS_2;
default:
}
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_fax (ECardSimpleField *field)
+static EContactField
+get_next_fax (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX;
+ return E_CONTACT_PHONE_BUSINESS_FAX;
switch (*field) {
- case E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX:
- return E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX;
- case E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX:
- return E_CARD_SIMPLE_FIELD_PHONE_OTHER_FAX;
+ case E_CONTACT_PHONE_BUSINESS_FAX:
+ return E_CONTACT_PHONE_HOME_FAX;
+ case E_CONTACT_PHONE_HOME_FAX:
+ return E_CONTACT_PHONE_OTHER_FAX;
default:
}
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_other (ECardSimpleField *field)
+static EContactField
+get_next_other (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_OTHER;
+ return E_CONTACT_PHONE_OTHER;
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_main (ECardSimpleField *field)
+static EContactField
+get_next_main (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_PRIMARY;
+ return E_CONTACT_PHONE_PRIMARY;
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_pager (ECardSimpleField *field)
+static EContactField
+get_next_pager (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_PAGER;
+ return E_CONTACT_PHONE_PAGER;
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
-static ECardSimpleField
-get_next_mobile (ECardSimpleField *field)
+static EContactField
+get_next_mobile (EContactField *field)
{
if (field == NULL)
- return E_CARD_SIMPLE_FIELD_PHONE_MOBILE;
+ return E_CONTACT_PHONE_MOBILE;
- return E_CARD_SIMPLE_FIELD_LAST;
+ return E_CONTACT_FIELD_LAST;
}
static void
-get_next_init (ECardSimpleField *next_mail,
- ECardSimpleField *next_home,
- ECardSimpleField *next_work,
- ECardSimpleField *next_fax,
- ECardSimpleField *next_other,
- ECardSimpleField *next_main,
- ECardSimpleField *next_pager,
- ECardSimpleField *next_mobile)
+get_next_init (EContactField *next_mail,
+ EContactField *next_home,
+ EContactField *next_work,
+ EContactField *next_fax,
+ EContactField *next_other,
+ EContactField *next_main,
+ EContactField *next_pager,
+ EContactField *next_mobile)
{
*next_mail = get_next_mail (NULL);
*next_home = get_next_home (NULL);
@@ -719,9 +604,9 @@ get_next_init (ECardSimpleField *next_mail,
}
static gboolean
-is_next_done (ECardSimpleField field)
+is_next_done (EContactField field)
{
- if (field == E_CARD_SIMPLE_FIELD_LAST)
+ if (field == E_CONTACT_FIELD_LAST)
return TRUE;
return FALSE;
@@ -730,8 +615,8 @@ is_next_done (ECardSimpleField field)
static gboolean
is_syncable (EAddrConduitContext *ctxt, EAddrLocalRecord *local)
{
- ECardSimpleField next_mail, next_home, next_work, next_fax;
- ECardSimpleField next_other, next_main, next_pager, next_mobile;
+ EContactField next_mail, next_home, next_work, next_fax;
+ EContactField next_other, next_main, next_pager, next_mobile;
gboolean syncable = TRUE;
int i, l = 0;
@@ -810,13 +695,26 @@ is_syncable (EAddrConduitContext *ctxt, EAddrLocalRecord *local)
return syncable;
}
-static char *
-get_entry_text (struct Address address, int field)
+static void
+set_contact_text (EContact *contact, EContactField field, struct Address address, int entry)
{
- if (address.entry[field])
- return e_pilot_utf8_from_pchar (address.entry[field]);
+ char *text = NULL;
+
+ if (address.entry[entry])
+ text = e_pilot_utf8_from_pchar (address.entry[entry]);
+
+ e_contact_set (contact, field, text);
- return g_strdup ("");
+ g_free (text);
+}
+
+static char *
+get_entry_text (struct Address address, int entry)
+{
+ if (address.entry[entry])
+ return e_pilot_utf8_from_pchar (address.entry[entry]);
+
+ return NULL;
}
static void
@@ -831,26 +729,26 @@ clear_entry_text (struct Address address, int field)
static void
compute_status (EAddrConduitContext *ctxt, EAddrLocalRecord *local, const char *uid)
{
- CardObjectChange *coc;
+ EBookChange *ebc;
local->local.archived = FALSE;
local->local.secret = FALSE;
- coc = g_hash_table_lookup (ctxt->changed_hash, uid);
+ ebc = g_hash_table_lookup (ctxt->changed_hash, uid);
- if (coc == NULL) {
+ if (ebc == NULL) {
local->local.attr = GnomePilotRecordNothing;
return;
}
- switch (coc->type) {
- case CARD_ADDED:
+ switch (ebc->change_type) {
+ case E_BOOK_CHANGE_CARD_ADDED:
local->local.attr = GnomePilotRecordNew;
break;
- case CARD_MODIFIED:
+ case E_BOOK_CHANGE_CARD_MODIFIED:
local->local.attr = GnomePilotRecordModified;
break;
- case CARD_DELETED:
+ case E_BOOK_CHANGE_CARD_DELETED:
local->local.attr = GnomePilotRecordDeleted;
break;
}
@@ -881,26 +779,22 @@ local_record_to_pilot_record (EAddrLocalRecord *local,
}
static void
-local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitContext *ctxt)
+local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrConduitContext *ctxt)
{
- ECardSimple *simple;
- const ECardDeliveryAddress *delivery;
- ECardSimpleAddressId mailing_address;
+ const EContactAddress *address;
+ EContactField mailing_address;
int phone = entryPhone1;
gboolean syncable;
int i;
g_return_if_fail (local != NULL);
- g_return_if_fail (ecard != NULL);
+ g_return_if_fail (contact != NULL);
- local->ecard = ecard;
- g_object_ref (ecard);
- simple = e_card_simple_new (ecard);
-
- local->local.ID = e_pilot_map_lookup_pid (ctxt->map, ecard->id, TRUE);
+ local->contact = g_object_ref (contact);
+ local->local.ID = e_pilot_map_lookup_pid (ctxt->map, e_contact_get_const (contact, E_CONTACT_UID), TRUE);
- compute_status (ctxt, local, ecard->id);
+ compute_status (ctxt, local, e_contact_get_const (contact, E_CONTACT_UID));
local->addr = g_new0 (struct Address, 1);
@@ -935,41 +829,46 @@ local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitCont
}
}
- if (ecard->name) {
- local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (ecard->name->given);
- local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (ecard->name->family);
- }
-
- local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (ecard->org);
- local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (ecard->title);
-
+ local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
+ local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
+ local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG));
+ local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE));
+
+ /* See if the default has something in it */
mailing_address = -1;
- for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) {
- const ECardAddrLabel *address;
-
- address = e_card_simple_get_address(simple, i);
- if (address && (address->flags & E_CARD_ADDR_DEFAULT))
- mailing_address = i;
+ if (e_contact_get_const (contact, ctxt->cfg->default_address))
+ mailing_address = ctxt->cfg->default_address;
+
+ /* If it doesn't, look for any address */
+ if (mailing_address == -1) {
+ for (i = E_CONTACT_FIRST_LABEL_ID; i < E_CONTACT_LAST_LABEL_ID; i++) {
+ if (e_contact_get_const (contact, i)) {
+ mailing_address = i;
+ break;
+ }
+ }
}
+
+ /* If all else fails, use the default */
if (mailing_address == -1)
mailing_address = ctxt->cfg->default_address;
- delivery = e_card_simple_get_delivery_address (simple, mailing_address);
- if (delivery) {
+ address = e_contact_get_const (contact, mailing_address);
+ if (address) {
char *add;
/* If the address has 2 lines, make sure both get added */
- if (delivery->ext != NULL)
- add = g_strconcat (delivery->street, "\n", delivery->ext, NULL);
+ if (address->ext != NULL)
+ add = g_strconcat (address->street, "\n", address->ext, NULL);
else
- add = g_strdup (delivery->street);
+ add = g_strdup (address->street);
local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add);
g_free (add);
- local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (delivery->city);
- local->addr->entry[entryState] = e_pilot_utf8_to_pchar (delivery->region);
- local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (delivery->code);
- local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (delivery->country);
+ local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality);
+ local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region);
+ local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code);
+ local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country);
}
/* Phone numbers */
@@ -982,10 +881,10 @@ local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitCont
/* Sync by priority */
for (i = 0, phone = entryPhone1;
- priority[i] != E_CARD_SIMPLE_FIELD_LAST && phone <= entryPhone5; i++) {
+ priority[i] != E_CONTACT_FIELD_LAST && phone <= entryPhone5; i++) {
const char *phone_str;
- phone_str = e_card_simple_get_const (simple, priority[i]);
+ phone_str = e_contact_get_const (contact, priority[i]);
if (phone_str && *phone_str) {
clear_entry_text (*local->addr, phone);
local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str);
@@ -997,8 +896,8 @@ local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitCont
local->addr->phoneLabel[phone - entryPhone1] = phone - entryPhone1;
local->addr->showPhone = 0;
} else {
- ECardSimpleField next_mail, next_home, next_work, next_fax;
- ECardSimpleField next_other, next_main, next_pager, next_mobile;
+ EContactField next_mail, next_home, next_work, next_fax;
+ EContactField next_other, next_main, next_pager, next_mobile;
INFO ("Not Syncable");
get_next_init (&next_mail, &next_home, &next_work, &next_fax,
@@ -1010,28 +909,28 @@ local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitCont
const char *phone_str = NULL;
if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
- phone_str = e_card_simple_get_const (simple, next_mail);
+ phone_str = e_contact_get_const (contact, next_mail);
next_mail = get_next_mail (&next_mail);
} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
- phone_str = e_card_simple_get_const (simple, next_home);
+ phone_str = e_contact_get_const (contact, next_home);
next_home = get_next_home (&next_home);
} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
- phone_str = e_card_simple_get_const (simple, next_work);
+ phone_str = e_contact_get_const (contact, next_work);
next_work = get_next_work (&next_work);
} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
- phone_str = e_card_simple_get_const (simple, next_fax);
+ phone_str = e_contact_get_const (contact, next_fax);
next_fax = get_next_fax (&next_fax);
} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
- phone_str = e_card_simple_get_const (simple, next_other);
+ phone_str = e_contact_get_const (contact, next_other);
next_other = get_next_other (&next_other);
} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
- phone_str = e_card_simple_get_const (simple, next_main);
+ phone_str = e_contact_get_const (contact, next_main);
next_main = get_next_main (&next_main);
} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
- phone_str = e_card_simple_get_const (simple, next_pager);
+ phone_str = e_contact_get_const (contact, next_pager);
next_pager = get_next_pager (&next_pager);
} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
- phone_str = e_card_simple_get_const (simple, next_mobile);
+ phone_str = e_contact_get_const (contact, next_mobile);
next_mobile = get_next_mobile (&next_mobile);
}
@@ -1043,9 +942,7 @@ local_record_from_ecard (EAddrLocalRecord *local, ECard *ecard, EAddrConduitCont
}
/* Note */
- local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (ecard->note);
-
- g_object_unref (simple);
+ local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE));
}
static void
@@ -1053,118 +950,104 @@ local_record_from_uid (EAddrLocalRecord *local,
const char *uid,
EAddrConduitContext *ctxt)
{
- ECard *ecard = NULL;
+ EContact *contact = NULL;
GList *l;
g_assert (local != NULL);
for (l = ctxt->cards; l != NULL; l = l->next) {
- ecard = l->data;
+ contact = l->data;
- if (ecard->id && !strcmp (ecard->id, uid))
+ /* FIXME Do we need to check for the empty string? */
+ if (e_contact_get_const (contact, E_CONTACT_UID));
break;
- ecard = NULL;
+ contact = NULL;
}
- if (ecard != NULL) {
- local_record_from_ecard (local, ecard, ctxt);
+ if (contact != NULL) {
+ local_record_from_ecard (local, contact, ctxt);
} else {
- ecard = e_card_new ("");
- e_card_set_id (ecard, uid);
- local_record_from_ecard (local, ecard, ctxt);
- g_object_unref (ecard);
+ contact = e_contact_new ();
+ e_contact_set (contact, E_CONTACT_UID, (gpointer) uid);
+ local_record_from_ecard (local, contact, ctxt);
+ g_object_unref (contact);
}
}
-static ECard *
+static EContact *
ecard_from_remote_record(EAddrConduitContext *ctxt,
GnomePilotRecord *remote,
- ECard *in_card)
+ EContact *in_contact)
{
struct Address address;
- ECard *ecard;
- ECardSimple *simple;
- ECardName *name;
- ECardDeliveryAddress *delivery;
- ECardAddrLabel *label;
- ECardSimpleAddressId mailing_address;
+ EContact *contact;
+ EContactName *name;
+ EContactAddress *eaddress;
+ EContactField mailing_address;
char *txt, *find;
- ECardSimpleField next_mail, next_home, next_work, next_fax;
- ECardSimpleField next_other, next_main, next_pager, next_mobile;
+ EContactField next_mail, next_home, next_work, next_fax;
+ EContactField next_other, next_main, next_pager, next_mobile;
int i;
g_return_val_if_fail(remote!=NULL,NULL);
memset (&address, 0, sizeof (struct Address));
unpack_Address (&address, remote->record, remote->length);
- if (in_card == NULL)
- ecard = e_card_new("");
+ if (in_contact == NULL)
+ contact = e_contact_new ();
else
- ecard = e_card_duplicate (in_card);
+ contact = e_contact_duplicate (in_contact);
/* Name */
- name = e_card_name_copy (ecard->name);
+ name = e_contact_name_new ();
name->given = get_entry_text (address, entryFirstname);
name->family = get_entry_text (address, entryLastname);
- simple = e_card_simple_new (ecard);
- txt = e_card_name_to_string (name);
- e_card_simple_set (simple, E_CARD_SIMPLE_FIELD_FULL_NAME, txt);
- e_card_simple_set_name (simple, name);
-
+ e_contact_set (contact, E_CONTACT_NAME, name);
+ e_contact_name_free (name);
+
/* File as */
- if (!(txt && *txt))
- e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_FILE_AS,
- address.entry[entryCompany]);
-
- g_free (txt);
- e_card_name_unref (name);
+ if (!e_contact_get_const (contact, E_CONTACT_FULL_NAME))
+ set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany);
/* Title and Company */
- txt = get_entry_text (address, entryTitle);
- e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_TITLE, txt);
- g_free (txt);
-
- txt = get_entry_text (address, entryCompany);
- e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_ORG, txt);
- g_free (txt);
+ set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle);
+ set_contact_text (contact, E_CONTACT_ORG, address, entryCompany);
/* Address */
mailing_address = -1;
- for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) {
- const ECardAddrLabel *addr;
+ if (e_contact_get_const (contact, ctxt->cfg->default_address))
+ mailing_address = ctxt->cfg->default_address;
- addr = e_card_simple_get_address(simple, i);
- if (addr && (addr->flags & E_CARD_ADDR_DEFAULT))
- mailing_address = i;
+ if (mailing_address == -1) {
+ for (i = E_CONTACT_FIRST_LABEL_ID; i < E_CONTACT_LAST_LABEL_ID; i++) {
+ if (e_contact_get_const (contact, i)) {
+ mailing_address = i;
+ break;
+ }
+ }
}
+
if (mailing_address == -1)
mailing_address = ctxt->cfg->default_address;
- delivery = e_card_delivery_address_new ();
- delivery->flags |= E_CARD_ADDR_DEFAULT;
+ eaddress = g_new0 (EContactAddress, 1);
+
txt = get_entry_text (address, entryAddress);
if ((find = strchr (txt, '\n')) != NULL) {
*find = '\0';
find++;
- }
- delivery->street = txt;
- delivery->ext = find != NULL ? g_strdup (find) : g_strdup ("");
- delivery->city = get_entry_text (address, entryCity);
- delivery->region = get_entry_text (address, entryState);
- delivery->country = get_entry_text (address, entryCountry);
- delivery->code = get_entry_text (address, entryZip);
-
- label = e_card_address_label_new ();
- label->flags |= E_CARD_ADDR_DEFAULT;
- label->data = e_card_delivery_address_to_string (delivery);
-
- e_card_simple_set_address (simple, mailing_address, label);
- e_card_simple_set_delivery_address (simple, mailing_address, delivery);
+ }
+ eaddress->street = txt;
+ eaddress->ext = find != NULL ? g_strdup (find) : g_strdup ("");
+ eaddress->locality = get_entry_text (address, entryCity);
+ eaddress->region = get_entry_text (address, entryState);
+ eaddress->country = get_entry_text (address, entryCountry);
+ eaddress->code = get_entry_text (address, entryZip);
- e_card_delivery_address_unref (delivery);
- e_card_address_label_unref (label);
+ e_contact_set (contact, mailing_address, eaddress);
+ e_contact_address_free (eaddress);
/* Phone numbers */
get_next_init (&next_mail, &next_home, &next_work, &next_fax,
@@ -1175,28 +1058,28 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
char *phonenum = get_entry_text (address, i);
if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
- e_card_simple_set (simple, next_mail, phonenum);
+ e_contact_set (contact, next_mail, phonenum);
next_mail = get_next_mail (&next_mail);
} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
- e_card_simple_set (simple, next_home, phonenum);
+ e_contact_set (contact, next_home, phonenum);
next_home = get_next_home (&next_home);
} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
- e_card_simple_set (simple, next_work, phonenum);
+ e_contact_set (contact, next_work, phonenum);
next_work = get_next_work (&next_work);
} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
- e_card_simple_set (simple, next_fax, phonenum);
+ e_contact_set (contact, next_fax, phonenum);
next_fax = get_next_fax (&next_fax);
} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
- e_card_simple_set (simple, next_other, phonenum);
+ e_contact_set (contact, next_other, phonenum);
next_other = get_next_other (&next_other);
} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
- e_card_simple_set (simple, next_main, phonenum);
+ e_contact_set (contact, next_main, phonenum);
next_main = get_next_main (&next_main);
} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
- e_card_simple_set (simple, next_pager, phonenum);
+ e_contact_set (contact, next_pager, phonenum);
next_pager = get_next_pager (&next_pager);
} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
- e_card_simple_set (simple, next_mobile, phonenum);
+ e_contact_set (contact, next_mobile, phonenum);
next_mobile = get_next_mobile (&next_mobile);
}
@@ -1204,16 +1087,11 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
}
/* Note */
- txt = get_entry_text (address, entryNote);
- e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_NOTE, txt);
- g_free (txt);
-
- e_card_simple_sync_card (simple);
- g_object_unref(simple);
+ set_contact_text (contact, E_CONTACT_NOTE, address, entryNote);
free_Address(&address);
- return ecard;
+ return contact;
}
static void
@@ -1243,112 +1121,6 @@ check_for_slow_setting (GnomePilotConduit *c, EAddrConduitContext *ctxt)
}
}
-static void
-card_added (EBookView *book_view, const GList *cards, EAddrConduitContext *ctxt)
-{
- const GList *l;
-
- for (l = cards; l != NULL; l = l->next) {
- ECard *card = E_CARD (l->data);
- CardObjectChange *coc;
-
- if (e_card_evolution_list (card))
- continue;
-
- coc = g_new0 (CardObjectChange, 1);
- coc->card = card;
- coc->type = CARD_ADDED;
-
- g_object_ref (coc->card);
- ctxt->changed = g_list_prepend (ctxt->changed, coc);
- if (!e_pilot_map_uid_is_archived (ctxt->map, e_card_get_id (coc->card)))
- g_hash_table_insert (ctxt->changed_hash, (gpointer)e_card_get_id (coc->card), coc);
- }
-}
-
-static void
-card_changed (EBookView *book_view, const GList *cards, EAddrConduitContext *ctxt)
-{
- const GList *l;
-
- for (l = cards; l != NULL; l = l->next) {
- ECard *card = E_CARD (l->data);
- CardObjectChange *coc;
-
- if (e_card_evolution_list (card))
- continue;
-
- coc = g_new0 (CardObjectChange, 1);
- coc->card = E_CARD (l->data);
- coc->type = CARD_MODIFIED;
-
- g_object_ref (coc->card);
- ctxt->changed = g_list_prepend (ctxt->changed, coc);
- if (!e_pilot_map_uid_is_archived (ctxt->map, e_card_get_id (coc->card)))
- g_hash_table_insert (ctxt->changed_hash, (gpointer)e_card_get_id (coc->card), coc);
- }
-}
-
-
-static void
-card_removed (EBookView *book_view, GList *ids, EAddrConduitContext *ctxt)
-{
- GList *l;
-
- for (l = ids; l != NULL; l = l->next) {
- const char *id = l->data;
- CardObjectChange *coc;
- gboolean archived;
-
- archived = e_pilot_map_uid_is_archived (ctxt->map, id);
-
- /* If its deleted, not in the archive and not in the map its a list */
- if (!archived && e_pilot_map_lookup_pid (ctxt->map, id, FALSE) == 0)
- return;
-
- coc = g_new0 (CardObjectChange, 1);
- coc->card = e_card_new ("");
- e_card_set_id (coc->card, id);
- coc->type = CARD_DELETED;
-
- ctxt->changed = g_list_prepend (ctxt->changed, coc);
-
- if (!archived)
- g_hash_table_insert (ctxt->changed_hash, (gpointer)e_card_get_id (coc->card), coc);
- else
- e_pilot_map_remove_by_uid (ctxt->map, id);
- }
-}
-
-static void
-sequence_complete (EBookView *book_view, EBookViewStatus status, EAddrConduitContext *ctxt)
-{
- g_signal_handlers_disconnect_matched(book_view,
- G_SIGNAL_MATCH_DATA,
- 0, 0,
- NULL, NULL, ctxt);
- g_object_unref (book_view);
- gtk_main_quit ();
-}
-
-static void
-view_cb (EBook *book, EBookStatus status, EBookView *book_view, gpointer data)
-{
- EAddrConduitContext *ctxt = data;
-
- g_object_ref (book_view);
-
- g_signal_connect (book_view, "card_added",
- G_CALLBACK (card_added), ctxt);
- g_signal_connect (book_view, "card_changed",
- G_CALLBACK (card_changed), ctxt);
- g_signal_connect (book_view, "card_removed",
- G_CALLBACK (card_removed), ctxt);
- g_signal_connect (book_view, "sequence_complete",
- G_CALLBACK (sequence_complete), ctxt);
-
-}
-
/* Pilot syncing callbacks */
static gint
pre_sync (GnomePilotConduit *conduit,
@@ -1356,12 +1128,13 @@ pre_sync (GnomePilotConduit *conduit,
EAddrConduitContext *ctxt)
{
GnomePilotConduitSyncAbs *abs_conduit;
-/* GList *l; */
+ EBookQuery *query;
+ GList *l;
int len;
unsigned char *buf;
char *filename;
char *change_id;
-/* gint num_records; */
+ gint num_records, add_records = 0, mod_records = 0, del_records = 0;
abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit);
@@ -1370,11 +1143,13 @@ pre_sync (GnomePilotConduit *conduit,
/* g_message ("Addressbook Conduit v.%s", CONDUIT_VERSION); */
ctxt->dbi = dbi;
- ctxt->ebook = NULL;
- if (start_addressbook_server (ctxt) != 0) {
- WARN(_("Could not start wombat server"));
- gnome_pilot_conduit_error (conduit, _("Could not start wombat"));
+ /* FIXME Need to allow our own concept of "local" */
+ ctxt->ebook = e_book_new ();
+ if (!e_book_load_local_addressbook (ctxt->ebook, NULL)) {
+ WARN(_("Could not load addressbook"));
+ gnome_pilot_conduit_error (conduit, _("Could not load addressbook"));
+
return -1;
}
@@ -1383,21 +1158,53 @@ pre_sync (GnomePilotConduit *conduit,
e_pilot_map_read (filename, &ctxt->map);
g_free (filename);
+ /* Get a list of all contacts */
+ query = e_book_query_from_string ("#t");
+ if (!e_book_get_contacts (ctxt->ebook, query, &ctxt->cards, NULL)) {
+ g_object_unref (query);
+
+ return -1;
+ }
+ g_object_unref (query);
+
/* Count and hash the changes */
change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id);
+ if (!e_book_get_changes (ctxt->ebook, change_id, &ctxt->changed, NULL))
+ return -1;
ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal);
- e_book_get_changes (ctxt->ebook, change_id, view_cb, ctxt);
-
- /* Force the view loading to be synchronous */
- gtk_main ();
- g_free (change_id);
+ g_free (change_id);
+
+ for (l = ctxt->changed; l != NULL; l = l->next) {
+ EBookChange *ebc = l->data;
+ const char *uid;
+
+ uid = e_contact_get_const (ebc->contact, E_CONTACT_UID);
+ if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) {
+
+ g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ebc);
+
+ switch (ebc->change_type) {
+ case E_BOOK_CHANGE_CARD_ADDED:
+ add_records++;
+ break;
+ case E_BOOK_CHANGE_CARD_MODIFIED:
+ mod_records++;
+ break;
+ case E_BOOK_CHANGE_CARD_DELETED:
+ del_records++;
+ break;
+ }
+ } else if (ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
+ e_pilot_map_remove_by_uid (ctxt->map, uid);
+ }
+ }
/* Set the count information */
-/* num_records = cal_client_get_n_objects (ctxt->client, CALOBJ_TYPE_TODO); */
-/* gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); */
-/* gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); */
-/* gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); */
-/* gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records); */
+ num_records = g_list_length (ctxt->cards);
+ gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records);
+ gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records);
+ gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records);
+ gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records);
buf = (unsigned char*)g_malloc (0xffff);
len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
@@ -1426,6 +1233,7 @@ post_sync (GnomePilotConduit *conduit,
GnomePilotDBInfo *dbi,
EAddrConduitContext *ctxt)
{
+ GList *changed;
gchar *filename, *change_id;
LOG (g_message ( "post_sync: Address Conduit v.%s", CONDUIT_VERSION ));
@@ -1442,9 +1250,9 @@ post_sync (GnomePilotConduit *conduit,
* a race condition if anyone changes a record elsewhere during sycnc
*/
change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id);
- e_book_get_changes (ctxt->ebook, change_id, view_cb, ctxt);
+ if (e_book_get_changes (ctxt->ebook, change_id, &changed, NULL))
+ e_book_free_change_list (changed);
g_free (change_id);
- gtk_main ();
LOG (g_message ( "---------------------------------------------------------\n" ));
@@ -1459,7 +1267,7 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit,
{
LOG (g_message ( "set_pilot_id: setting to %d\n", ID ));
- e_pilot_map_insert (ctxt->map, ID, local->ecard->id, FALSE);
+ e_pilot_map_insert (ctxt->map, ID, e_contact_get_const (local->contact, E_CONTACT_UID), FALSE);
return 0;
}
@@ -1471,7 +1279,7 @@ set_status_cleared (GnomePilotConduitSyncAbs *conduit,
{
LOG (g_message ( "set_status_cleared: clearing status\n" ));
- g_hash_table_remove (ctxt->changed_hash, e_card_get_id (local->ecard));
+ g_hash_table_remove (ctxt->changed_hash, e_contact_get_const (local->contact, E_CONTACT_UID));
return 0;
}
@@ -1545,12 +1353,12 @@ for_each_modified (GnomePilotConduitSyncAbs *conduit,
iterator = next_changed_item (ctxt, iterator);
if (iterator != NULL) {
- CardObjectChange *coc = iterator->data;
+ EBookChange *ebc = iterator->data;
- LOG (g_message ( "iterating over %d records", g_hash_table_size (ctxt->changed_hash) ));
+ LOG (g_message ( "iterating over %d records", g_hash_table_size (ctxt->changed_hash)));
*local = g_new0 (EAddrLocalRecord, 1);
- local_record_from_ecard (*local, coc->card, ctxt);
+ local_record_from_ecard (*local, ebc->contact, ctxt);
g_list_prepend (ctxt->locals, *local);
} else {
LOG (g_message ( "no events" ));
@@ -1561,10 +1369,10 @@ for_each_modified (GnomePilotConduitSyncAbs *conduit,
count++;
iterator = g_list_next (iterator);
if (iterator && (iterator = next_changed_item (ctxt, iterator))) {
- CardObjectChange *coc = iterator->data;
+ EBookChange *ebc = iterator->data;
*local = g_new0 (EAddrLocalRecord, 1);
- local_record_from_ecard (*local, coc->card, ctxt);
+ local_record_from_ecard (*local, ebc->contact, ctxt);
g_list_prepend (ctxt->locals, *local);
} else {
LOG (g_message ( "for_each_modified ending" ));
@@ -1613,30 +1421,26 @@ add_record (GnomePilotConduitSyncAbs *conduit,
GnomePilotRecord *remote,
EAddrConduitContext *ctxt)
{
- ECard *ecard;
- CardObjectChangeStatus cons;
+ EContact *contact;
int retval = 0;
g_return_val_if_fail (remote != NULL, -1);
LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote) ));
- ecard = ecard_from_remote_record (ctxt, remote, NULL);
+ contact = ecard_from_remote_record (ctxt, remote, NULL);
/* add the ecard to the server */
- e_book_add_card (ctxt->ebook, ecard, add_card_cb, &cons);
-
- gtk_main(); /* enter sub mainloop */
-
- if (cons.status != E_BOOK_STATUS_SUCCESS) {
+ if (!e_book_add_contact (ctxt->ebook, contact, NULL)) {
WARN ("add_record: failed to add card to ebook\n");
+ g_object_unref (contact);
+
return -1;
}
- e_card_set_id (ecard, cons.id);
- e_pilot_map_insert (ctxt->map, remote->ID, ecard->id, FALSE);
+ e_pilot_map_insert (ctxt->map, remote->ID, e_contact_get (contact, E_CONTACT_UID), FALSE);
- g_object_unref (ecard);
+ g_object_unref (contact);
return retval;
}
@@ -1647,10 +1451,8 @@ replace_record (GnomePilotConduitSyncAbs *conduit,
GnomePilotRecord *remote,
EAddrConduitContext *ctxt)
{
- ECard *new_ecard;
- EBookStatus commit_status;
- CardObjectChange *coc;
- CardObjectChangeStatus cons;
+ EContact *new_contact;
+ EBookChange *ebc;
char *old_id;
int retval = 0;
@@ -1659,41 +1461,46 @@ replace_record (GnomePilotConduitSyncAbs *conduit,
LOG (g_message ("replace_record: replace %s with %s\n",
print_local (local), print_remote (remote)));
- old_id = g_strdup (e_card_get_id (local->ecard));
- coc = g_hash_table_lookup (ctxt->changed_hash, old_id);
+ old_id = e_contact_get (local->contact, E_CONTACT_UID);
+ ebc = g_hash_table_lookup (ctxt->changed_hash, old_id);
- new_ecard = ecard_from_remote_record (ctxt, remote, local->ecard);
- g_object_unref (local->ecard);
- local->ecard = new_ecard;
+ new_contact = ecard_from_remote_record (ctxt, remote, local->contact);
+ g_object_unref (local->contact);
+ local->contact = new_contact;
- if (coc && coc->type == CARD_DELETED)
- e_book_add_card (ctxt->ebook, local->ecard, add_card_cb, &cons);
- else
- e_book_commit_card (ctxt->ebook, local->ecard, status_cb, &commit_status);
-
- gtk_main (); /* enter sub mainloop */
+ if (ebc && ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
+ if (!e_book_add_contact (ctxt->ebook, local->contact, NULL)) {
+ WARN (G_STRLOC ": failed to add card\n");
+
+ return -1;
+ }
+
+ } else {
+ if (!e_book_commit_contact (ctxt->ebook, local->contact, NULL)) {
+ WARN (G_STRLOC ": failed to commit card\n");
+
+ return -1;
+ }
+ }
/* Adding a record causes wombat to assign a new uid so we must tidy */
- if (coc && coc->type == CARD_DELETED) {
- gboolean arch = e_pilot_map_uid_is_archived (ctxt->map, e_card_get_id (local->ecard));
+ if (ebc && ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
+ const char *uid = e_contact_get_const (local->contact, E_CONTACT_UID);
+ gboolean arch;
- e_card_set_id (local->ecard, cons.id);
- e_pilot_map_insert (ctxt->map, remote->ID, cons.id, arch);
-
- coc = g_hash_table_lookup (ctxt->changed_hash, old_id);
- if (coc) {
- g_hash_table_remove (ctxt->changed_hash, e_card_get_id (coc->card));
- g_object_unref (coc->card);
- g_object_ref (local->ecard);
- coc->card = local->ecard;
- g_hash_table_insert (ctxt->changed_hash, (gpointer)e_card_get_id (coc->card), coc);
+ arch = e_pilot_map_uid_is_archived (ctxt->map, uid);
+ e_pilot_map_insert (ctxt->map, remote->ID, uid, arch);
+
+ ebc = g_hash_table_lookup (ctxt->changed_hash, old_id);
+ if (ebc) {
+ g_hash_table_remove (ctxt->changed_hash, old_id);
+ g_object_unref (ebc->contact);
+ g_object_ref (local->contact);
+ ebc->contact = local->contact;
+ /* FIXME We should possibly be duplicating the uid */
+ g_hash_table_insert (ctxt->changed_hash, (gpointer) uid, ebc);
}
-
- commit_status = cons.status;
}
-
- if (commit_status != E_BOOK_STATUS_SUCCESS)
- WARN ("replace_record: failed to update card in ebook\n");
return retval;
}
@@ -1703,21 +1510,19 @@ delete_record (GnomePilotConduitSyncAbs *conduit,
EAddrLocalRecord *local,
EAddrConduitContext *ctxt)
{
- EBookStatus commit_status;
int retval = 0;
g_return_val_if_fail (local != NULL, -1);
- g_return_val_if_fail (local->ecard != NULL, -1);
+ g_return_val_if_fail (local->contact != NULL, -1);
LOG (g_message ( "delete_record: delete %s\n", print_local (local) ));
- e_pilot_map_remove_by_uid (ctxt->map, local->ecard->id);
- e_book_remove_card_by_id (ctxt->ebook, local->ecard->id, status_cb, &commit_status);
-
- gtk_main (); /* enter sub mainloop */
-
- if (commit_status != E_BOOK_STATUS_SUCCESS && commit_status != E_BOOK_STATUS_CARD_NOT_FOUND)
+ e_pilot_map_remove_by_uid (ctxt->map, e_contact_get_const (local->contact, E_CONTACT_UID));
+ if (!e_book_remove_contact (ctxt->ebook, e_contact_get_const (local->contact, E_CONTACT_UID), NULL)) {
WARN ("delete_record: failed to delete card in ebook\n");
+
+ retval = -1;
+ }
return retval;
}
@@ -1734,7 +1539,7 @@ archive_record (GnomePilotConduitSyncAbs *conduit,
LOG (g_message ( "archive_record: %s\n", archive ? "yes" : "no" ));
- e_pilot_map_insert (ctxt->map, local->local.ID, local->ecard->id, archive);
+ e_pilot_map_insert (ctxt->map, local->local.ID, e_contact_get_const (local->contact, E_CONTACT_UID), archive);
return retval;
}