--- addressbook/backends/groupwise/e-book-backend-groupwise.c 2006-06-09 15:05:45.000000000 +0530 +++ addressbook/backends/groupwise/e-book-backend-groupwise-new.c 2006-06-09 14:35:19.000000000 +0530 @@ -73,12 +73,12 @@ struct _EBookBackendGroupwisePrivate { int mode; int cache_timeout; EBookBackendSummary *summary; + GMutex *update_cache_mutex; GMutex *update_mutex; DB *file_db; DB_ENV *env; /* for future use */ void *reserved1; - void *reserved2; }; static GStaticMutex global_env_lock = G_STATIC_MUTEX_INIT; @@ -1170,6 +1170,7 @@ e_book_backend_groupwise_create_contact e_contact_set (contact, E_CONTACT_UID, id); g_free (id); e_book_backend_db_cache_add_contact (egwb->priv->file_db, contact); + egwb->priv->file_db->sync(egwb->priv->file_db, 0); e_book_backend_summary_add_contact (egwb->priv->summary, contact); e_data_book_respond_create(book, opid, GNOME_Evolution_Addressbook_Success, contact); @@ -1223,6 +1224,7 @@ e_book_backend_groupwise_remove_contacts e_book_backend_db_cache_remove_contact (ebgw->priv->file_db, id); e_book_backend_summary_remove_contact (ebgw->priv->summary, id); } + ebgw->priv->file_db->sync(ebgw->priv->file_db, 0); e_data_book_respond_remove_contacts (book, opid, GNOME_Evolution_Addressbook_Success, deleted_ids); return; @@ -1358,6 +1360,7 @@ e_book_backend_groupwise_modify_contact e_book_backend_db_cache_remove_contact (egwb->priv->file_db, id); e_book_backend_summary_remove_contact (egwb->priv->summary, id); e_book_backend_db_cache_add_contact (egwb->priv->file_db, contact); + egwb->priv->file_db->sync(egwb->priv->file_db, 0); e_book_backend_summary_add_contact (egwb->priv->summary, contact); } else @@ -2691,6 +2694,8 @@ update_cache (EBookBackendGroupwise *ebg if (!ebgw) return FALSE; + g_mutex_lock (ebgw->priv->update_cache_mutex); + if (enable_debug) { g_get_current_time(&start); printf("updating cache for %s\n", ebgw->priv->book_name); @@ -2729,6 +2734,7 @@ update_cache (EBookBackendGroupwise *ebg bonobo_object_unref (book_view); if (enable_debug) printf("No connection with the server \n"); + g_mutex_unlock (ebgw->priv->update_cache_mutex); return FALSE; } @@ -2738,6 +2744,7 @@ update_cache (EBookBackendGroupwise *ebg contact = e_contact_new (); fill_contact_from_gw_item (contact, E_GW_ITEM (gw_items->data), ebgw->priv->categories_by_id); + e_contact_set (contact, E_CONTACT_BOOK_URI, ebgw->priv->original_uri); id = e_contact_get_const (contact, E_CONTACT_UID); @@ -2782,6 +2789,7 @@ update_cache (EBookBackendGroupwise *ebg printf("updating the cache for %s complated in %ld.%03ld seconds for %d contacts\n", ebgw->priv->book_name, diff / 1000, diff % 1000, contact_num); } + g_mutex_unlock (ebgw->priv->update_cache_mutex); return FALSE; } @@ -2797,6 +2805,7 @@ update_address_book_deltas (EBookBackend EContact *contact; EDataBookView *book_view; GroupwiseBackendSearchClosure *closure; + EGwItem *item; if (!ebgw) return FALSE; @@ -2827,6 +2836,9 @@ update_address_book_deltas (EBookBackend if (enable_debug) printf ("sequence is reset, rebuilding cache...\n"); build_cache (ebgw); + add_sequence_to_cache (priv->file_db, server_first_sequence, + server_last_sequence, server_last_po_rebuild_time); + ebgw->priv->file_db->sync (ebgw->priv->file_db, 0); g_mutex_unlock (priv->update_mutex); return TRUE; } @@ -2844,6 +2856,7 @@ update_address_book_deltas (EBookBackend add_sequence_to_cache (priv->file_db, server_first_sequence, server_last_sequence, server_last_po_rebuild_time); ebgw->priv->file_db->sync (ebgw->priv->file_db, 0); + g_mutex_unlock (priv->update_mutex); return TRUE; } @@ -2896,6 +2909,8 @@ update_address_book_deltas (EBookBackend if (add_list == NULL && delete_list == NULL) { if (enable_debug) printf("sequence differs but no changes found !!!\n"); + add_sequence_to_cache (priv->file_db, server_first_sequence, + server_last_sequence, server_last_po_rebuild_time); g_mutex_unlock (priv->update_mutex); return TRUE; } @@ -2945,6 +2960,20 @@ update_address_book_deltas (EBookBackend E_GW_ITEM (add_list->data), ebgw->priv->categories_by_id); + /* When a distribution list is modified the server sends me a delete and add response. + But it doesnt send me the members, so i have to explicitly request the server for the members of the distribution list */ + + if (e_contact_get (contact, E_CONTACT_IS_LIST)) { + if(enable_debug) + printf ("Contact List modified fetching the members of the contact list\n"); + + status = e_gw_connection_get_item (ebgw->priv->cnc, ebgw->priv->container_id, e_contact_get (contact, E_CONTACT_UID), "name email default members", &item); + g_object_unref (contact); + contact = e_contact_new (); + fill_contact_from_gw_item (contact, item, ebgw->priv->categories_by_id); + g_object_unref (item); + } + if (enable_debug) printf("contact email:%s, contact name:%s\n", (char *)e_contact_get(contact, E_CONTACT_EMAIL_1),(char *) e_contact_get(contact, E_CONTACT_GIVEN_NAME)); e_contact_set (contact, @@ -2977,7 +3006,6 @@ update_address_book_deltas (EBookBackend } cache_last_sequence += contact_num; - /* cache is updated, now adding the sequence information to the cache */ add_sequence_to_cache (priv->file_db, server_first_sequence, @@ -3054,11 +3082,15 @@ e_book_backend_groupwise_authenticate_us const char *cache_refresh_interval_set; int cache_refresh_interval = CACHE_REFRESH_INTERVAL; - if (enable_debug) - printf ("authenticate user ............\n"); ebgw = E_BOOK_BACKEND_GROUPWISE (backend); priv = ebgw->priv; + if (enable_debug) { + printf ("authenticate user ............\n"); + if(priv->book_name) + printf("book_name:%s\n", priv->book_name); + } + switch (ebgw->priv->mode) { case GNOME_Evolution_Addressbook_MODE_LOCAL: @@ -3094,9 +3126,6 @@ e_book_backend_groupwise_authenticate_us id = NULL; is_writable = FALSE; - if (enable_debug) - if(priv->book_name) - printf("book_name:%s\n", priv->book_name); status = e_gw_connection_get_address_book_id (priv->cnc, priv->book_name, &id, &is_writable); if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION) status = e_gw_connection_get_address_book_id (priv->cnc, priv->book_name, &id, &is_writable); @@ -3632,6 +3661,8 @@ e_book_backend_groupwise_dispose (GObjec } if (bgw->priv->update_mutex) g_mutex_free (bgw->priv->update_mutex); + if (bgw->priv->update_cache_mutex) + g_mutex_free (bgw->priv->update_cache_mutex); g_free (bgw->priv); bgw->priv = NULL; @@ -3690,8 +3721,8 @@ e_book_backend_groupwise_init (EBookBack priv->original_uri = NULL; priv->cache_timeout = 0; priv->update_mutex = g_mutex_new(); + priv->update_cache_mutex = g_mutex_new (); priv->reserved1 = NULL; - priv->reserved2 = NULL; backend->priv = priv; if (g_getenv ("GROUPWISE_DEBUG")) {