[evolution-data-server/openismus-work-master: 114/137] EBookClientCursor: Cursor move API changed to return number of contacts traversed.



commit 02479b88997d40b236338abc19513c51654a5729
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sun Oct 13 04:08:21 2013 +0200

    EBookClientCursor: Cursor move API changed to return number of contacts traversed.

 addressbook/libebook/e-book-client-cursor.c |   68 +++++++++++++++------------
 addressbook/libebook/e-book-client-cursor.h |    4 +-
 2 files changed, 40 insertions(+), 32 deletions(-)
---
diff --git a/addressbook/libebook/e-book-client-cursor.c b/addressbook/libebook/e-book-client-cursor.c
index db1ecf8..0823e86 100644
--- a/addressbook/libebook/e-book-client-cursor.c
+++ b/addressbook/libebook/e-book-client-cursor.c
@@ -1488,6 +1488,7 @@ struct _MoveByContext {
        GSList *contacts;
        guint new_total;
        guint new_position;
+       gint n_results;
 };
 
 struct _AlphabetIndexContext {
@@ -1599,6 +1600,7 @@ move_by_context_new (const gchar      *revision,
        context->origin        = origin;
        context->count         = count;
        context->fetch_results = fetch_results;
+       context->n_results     = 0;
 
        return context;
 }
@@ -1613,7 +1615,7 @@ move_by_context_free (MoveByContext *context)
        }
 }
 
-static gboolean
+static gint
 move_by_sync_internal (EBookClientCursor   *cursor,
                       const gchar         *revision,
                       EBookCursorOrigin    origin,
@@ -1627,6 +1629,7 @@ move_by_sync_internal (EBookClientCursor   *cursor,
        EBookClientCursorPrivate *priv;
        GError *local_error = NULL;
        gchar **vcards = NULL;
+       gint n_results = -1;
 
        priv = cursor->priv;
 
@@ -1634,13 +1637,14 @@ move_by_sync_internal (EBookClientCursor   *cursor,
                GSList *results = NULL, *l;
                GSList *contacts = NULL;
 
-               if (!e_data_book_cursor_move_by (priv->direct_cursor,
-                                                revision,
-                                                origin,
-                                                count,
-                                                out_contacts ? &results : NULL,
-                                                error))
-                       return FALSE;
+               n_results = e_data_book_cursor_move_by (priv->direct_cursor,
+                                                       revision,
+                                                       origin,
+                                                       count,
+                                                       out_contacts ? &results : NULL,
+                                                       error);
+               if (n_results < 0)
+                       return n_results;
 
                for (l = results; l; l = l->next) {
                        gchar *vcard = l->data;
@@ -1660,7 +1664,7 @@ move_by_sync_internal (EBookClientCursor   *cursor,
                *new_total = e_data_book_cursor_get_total (priv->direct_cursor);
                *new_position = e_data_book_cursor_get_position (priv->direct_cursor);
 
-               return TRUE;
+               return n_results;
        }
 
        e_dbus_address_book_cursor_call_move_by_sync (
@@ -1668,6 +1672,7 @@ move_by_sync_internal (EBookClientCursor   *cursor,
                revision,
                origin, count,
                out_contacts != NULL,
+               &n_results,
                &vcards,
                new_total,
                new_position,
@@ -1677,7 +1682,7 @@ move_by_sync_internal (EBookClientCursor   *cursor,
        if (local_error != NULL) {
                g_dbus_error_strip_remote_error (local_error);
                g_propagate_error (error, local_error);
-               return FALSE;
+               return -1;
        }
 
        if (vcards != NULL) {
@@ -1698,7 +1703,7 @@ move_by_sync_internal (EBookClientCursor   *cursor,
                g_strfreev (vcards);
        }
 
-       return TRUE;
+       return n_results;
 }
 
 static void
@@ -1711,14 +1716,15 @@ move_by_thread (GSimpleAsyncResult *simple,
 
        context = g_simple_async_result_get_op_res_gpointer (simple);
 
-       move_by_sync_internal (E_BOOK_CLIENT_CURSOR (source_object),
-                              context->revision,
-                              context->origin,
-                              context->count,
-                              context->fetch_results ? &(context->contacts) : NULL,
-                              &context->new_total,
-                              &context->new_position,
-                              cancellable, &local_error);
+       context->n_results = 
+               move_by_sync_internal (E_BOOK_CLIENT_CURSOR (source_object),
+                                      context->revision,
+                                      context->origin,
+                                      context->count,
+                                      context->fetch_results ? &(context->contacts) : NULL,
+                                      &context->new_total,
+                                      &context->new_position,
+                                      cancellable, &local_error);
 
        if (local_error != NULL)
                g_simple_async_result_take_error (simple, local_error);
@@ -2160,11 +2166,12 @@ e_book_client_cursor_move_by (EBookClientCursor   *cursor,
  * Completes an asynchronous call initiated by e_book_client_cursor_move_by(), fetching
  * any contacts which might have been returned by the call.
  *
- * Returns: %TRUE on success, otherwise %FALSE is returned and @error is set.
+ * Returns: The number of contacts which the cursor has moved by if successfull.
+ * Otherwise -1 is returned and @error is set.
  *
  * Since: 3.12
  */
-gboolean
+gint
 e_book_client_cursor_move_by_finish (EBookClientCursor   *cursor,
                                     GAsyncResult        *result,
                                     GSList             **out_contacts,
@@ -2182,7 +2189,7 @@ e_book_client_cursor_move_by_finish (EBookClientCursor   *cursor,
        context = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+               return -1;
 
        if (out_contacts != NULL) {
                *out_contacts = context->contacts;
@@ -2199,7 +2206,7 @@ e_book_client_cursor_move_by_finish (EBookClientCursor   *cursor,
                g_object_thaw_notify (G_OBJECT (cursor));
        }
 
-       return TRUE;
+       return context->n_results;
 }
 
 /**
@@ -2254,11 +2261,12 @@ e_book_client_cursor_move_by_finish (EBookClientCursor   *cursor,
  * to be followed by an #EBookClientCursor::refresh signal at which point any content
  * should be reloaded.
  *
- * Returns: %TRUE on success, otherwise %FALSE is returned and @error is set.
+ * Returns: The number of contacts which the cursor has moved by if successfull.
+ * Otherwise -1 is returned and @error is set.
  *
  * Since: 3.12
  */
-gboolean
+gint
 e_book_client_cursor_move_by_sync (EBookClientCursor   *cursor,
                                   EBookCursorOrigin    origin,
                                   gint                 count,
@@ -2267,25 +2275,25 @@ e_book_client_cursor_move_by_sync (EBookClientCursor   *cursor,
                                   GError             **error)
 {
        guint new_total = 0, new_position = 0;
-       gboolean success;
+       gint retval;
 
        g_return_val_if_fail (E_IS_BOOK_CLIENT_CURSOR (cursor), FALSE);
        g_return_val_if_fail (count != 0 || origin == E_BOOK_CURSOR_ORIGIN_RESET, FALSE);
 
-       success = move_by_sync_internal (cursor, cursor->priv->revision, origin, count, out_contacts,
-                                        &new_total, &new_position, cancellable, error);
+       retval = move_by_sync_internal (cursor, cursor->priv->revision, origin, count, out_contacts,
+                                       &new_total, &new_position, cancellable, error);
 
        /* If we are in the thread where the cursor was created, 
         * then synchronize the new total & position right away
         */
-       if (success && book_client_cursor_context_is_current (cursor)) {
+       if (retval >= 0 && book_client_cursor_context_is_current (cursor)) {
                g_object_freeze_notify (G_OBJECT (cursor));
                book_client_cursor_set_total (cursor, new_total);
                book_client_cursor_set_position (cursor, new_position);
                g_object_thaw_notify (G_OBJECT (cursor));
        }
 
-       return success;
+       return retval;
 }
 
 /**
diff --git a/addressbook/libebook/e-book-client-cursor.h b/addressbook/libebook/e-book-client-cursor.h
index 7e2bdff..fbaadc4 100644
--- a/addressbook/libebook/e-book-client-cursor.h
+++ b/addressbook/libebook/e-book-client-cursor.h
@@ -114,11 +114,11 @@ void                 e_book_client_cursor_move_by                     (EBookClie
                                                                       GCancellable        *cancellable,
                                                                       GAsyncReadyCallback  callback,
                                                                       gpointer             user_data);
-gboolean             e_book_client_cursor_move_by_finish              (EBookClientCursor   *cursor,
+gint                 e_book_client_cursor_move_by_finish              (EBookClientCursor   *cursor,
                                                                       GAsyncResult        *result,
                                                                       GSList             **out_contacts,
                                                                       GError             **error);
-gboolean             e_book_client_cursor_move_by_sync                (EBookClientCursor   *cursor,
+gint                 e_book_client_cursor_move_by_sync                (EBookClientCursor   *cursor,
                                                                       EBookCursorOrigin    origin,
                                                                       gint                 count,
                                                                       GSList             **out_contacts,


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