[evolution-ews] Fix notification for non-GAL updates to only happen on commit



commit e117c8070e9fbaadb1bfeaa6658315b9355fd160
Author: David Woodhouse <David Woodhouse intel com>
Date:   Wed Sep 10 17:01:50 2014 +0100

    Fix notification for non-GAL updates to only happen on commit
    
    Fix broken g_object_unref() on strings in the failure case too.

 src/addressbook/e-book-backend-ews.c |  115 ++++++++++++++--------------------
 1 files changed, 47 insertions(+), 68 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 611f909..9f34076 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -65,6 +65,7 @@ ebews_fetch_items (EBookBackendEws *ebews,  GSList *items, GSList **contacts,
 
 static void cursors_contact_added (EBookBackendEws *bf, EContact *contact);
 static void cursors_contact_removed (EBookBackendEws *bf, EContact *contact);
+static void cursors_recalculate (EBookBackendEws *bf);
 
 typedef struct {
        GCond cond;
@@ -2810,68 +2811,6 @@ exit:
 
 /********** GAL sync **************************/
 
-/**
- * ebews_sync_deleted_items 
- * @ebews: 
- * @deleted_items: 
- * @error: cannot be NULL 
- **/
-static gboolean
-ebews_sync_deleted_items (EBookBackendEws *ebews,
-                          GSList **deleted_ids,
-                         GCancellable *cancellable,
-                          GError **error)
-{
-       GSList *l;
-       EBookBackendEwsPrivate *priv;
-
-       priv = ebews->priv;
-
-       for (l = *deleted_ids; l != NULL; l = g_slist_next (l)) {
-               gchar *id = (gchar *) l->data;
-               EContact *contact = NULL;
-
-               if (e_book_sqlite_get_contact (priv->summary, id, FALSE, &contact, NULL)) {
-                       if (e_book_sqlite_remove_contact (priv->summary, id, cancellable, error)) {
-                               cursors_contact_removed (ebews, contact);
-                               g_object_unref (contact);
-                               e_book_backend_notify_remove (E_BOOK_BACKEND (ebews), id);
-                       } else {
-                               g_object_unref (contact);
-                               return FALSE;
-                       }
-               }
-       }
-
-       g_slist_free_full (*deleted_ids, g_free);
-       *deleted_ids = NULL;
-
-       return TRUE;
-}
-
-static gboolean
-ebews_sync_modified_items (EBookBackendEws *ebews, GSList **contacts,
-                          GCancellable *cancellable, GError **error)
-{
-       GSList *l;
-       EBookBackendEwsPrivate *priv;
-
-       priv = ebews->priv;
-
-       for (l = *contacts; l != NULL; l = g_slist_next (l)) {
-               EContact *contact = E_CONTACT (l->data);
-
-               if (e_book_sqlite_add_contact (priv->summary, contact, NULL, TRUE, cancellable, error))
-                       e_book_backend_notify_update (E_BOOK_BACKEND (ebews), contact);
-               else
-                       return FALSE;
-       }
-
-       g_slist_free_full (*contacts, g_object_unref);
-       *contacts = NULL;
-
-       return TRUE;
-}
 
 static EContact *
 ebews_get_contact_info (EBookBackendEws *ebews,
@@ -3761,6 +3700,7 @@ ews_update_items_thread (gpointer data)
        GSList *items_deleted_resync = NULL;
        GSList *contacts_created = NULL;
        GSList *contacts_updated = NULL;
+       GSList *l;
 
        priv = ebews->priv;
 
@@ -3836,10 +3776,10 @@ ews_update_items_thread (gpointer data)
                if (!e_book_sqlite_lock (priv->summary, EBSQL_LOCK_WRITE, priv->cancellable, &error))
                        break;
 
-               if ((items_deleted_resync && !ebews_sync_deleted_items (ebews, &items_deleted_resync, 
priv->cancellable, &error)) ||
-                   (items_deleted && !ebews_sync_deleted_items (ebews, &items_deleted, priv->cancellable, 
&error)) ||
-                   (contacts_created && !ebews_sync_modified_items (ebews, &contacts_created, 
priv->cancellable, &error)) ||
-                   (contacts_updated && !ebews_sync_modified_items (ebews, &contacts_updated, 
priv->cancellable, &error)) ||
+               if ((items_deleted_resync && !e_book_sqlite_remove_contacts (priv->summary, 
items_deleted_resync, priv->cancellable, &error)) ||
+                   (items_deleted && !e_book_sqlite_remove_contacts (priv->summary, items_deleted, 
priv->cancellable, &error)) ||
+                   (contacts_created && !e_book_sqlite_add_contacts (priv->summary, contacts_created, NULL, 
TRUE, priv->cancellable, &error)) ||
+                   (contacts_updated && !e_book_sqlite_add_contacts (priv->summary, contacts_updated, NULL, 
TRUE, priv->cancellable, &error)) ||
                    !e_book_sqlite_set_key_value (priv->summary, E_BOOK_SQL_SYNC_DATA_KEY, sync_state, 
&error) ||
                    (includes_last_item && !e_book_sqlite_set_key_value_int (priv->summary, 
E_BOOK_SQL_IS_POPULATED_KEY, TRUE, &error)) ||
                    !ebews_bump_revision (ebews, &error)) {
@@ -3849,12 +3789,39 @@ ews_update_items_thread (gpointer data)
                if (!e_book_sqlite_unlock (priv->summary, EBSQL_UNLOCK_COMMIT, &error))
                        break;
 
+               while (items_deleted_resync || items_deleted) {
+                       if (items_deleted_resync) {
+                               l = items_deleted_resync;
+                               items_deleted_resync = l->next;
+                       } else {
+                               l = items_deleted;
+                               items_deleted = l->next;
+                       }
+
+                       e_book_backend_notify_remove (E_BOOK_BACKEND (ebews), l->data);
+                       g_free (l->data);
+                       g_slist_free_1 (l);
+               }
+               while (contacts_created || contacts_updated) {
+                       if (contacts_created) {
+                               l = contacts_created;
+                               contacts_created = l->next;
+                       } else {
+                               l = contacts_updated;
+                               contacts_updated = l->next;
+                       }
+                       e_book_backend_notify_update (E_BOOK_BACKEND (ebews), l->data);
+                       g_object_unref (l->data);
+                       g_slist_free_1 (l);
+               }
+               cursors_recalculate (ebews);
+
        } while (!includes_last_item);
 
        g_slist_free_full (items_created, g_object_unref);
        g_slist_free_full (items_updated, g_object_unref);
-       g_slist_free_full (items_deleted, g_object_unref);
-       g_slist_free_full (items_deleted_resync, g_object_unref);
+       g_slist_free_full (items_deleted, g_free);
+       g_slist_free_full (items_deleted_resync, g_free);
        g_slist_free_full (contacts_created, g_object_unref);
        g_slist_free_full (contacts_updated, g_object_unref);
 
@@ -4236,6 +4203,18 @@ cursors_contact_removed (EBookBackendEws *ebews,
        }
 }
 
+static void
+cursors_recalculate (EBookBackendEws *ebews)
+{
+       GList *l;
+
+       for (l = ebews->priv->cursors; l; l = l->next) {
+               EDataBookCursor *cursor = l->data;
+
+               e_data_book_cursor_recalculate (cursor, NULL, NULL);
+       }
+}
+
 static EDataBookCursor *
 e_book_backend_ews_create_cursor (EBookBackend *backend,
                                  EContactField *sort_fields,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]