[evolution-data-server] Let EDataBook track the "opened" state.



commit 82ed8d71780b908c7be19e8c1e2af5eadd20aac1
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Mar 21 13:09:08 2013 -0400

    Let EDataBook track the "opened" state.
    
    Due to the asymmetric nature of our backend APIs, the open() method
    begins in EBookBackend, but the end result is reported to EDataBook.
    So it makes more sense for EDataBook to track the backend's "opened"
    state, at least until the APIs can be modernized.
    
    This adds a new function -- e_data_book_is_opened() -- which is just a
    temporary hack and should only be called by e_book_backend_is_opened().
    
    This avoids EDataBook needing to call e_book_backend_notify_opened(),
    which is deprecated and about to be removed.

 addressbook/libedata-book/e-book-backend.c         |   20 +++++---
 addressbook/libedata-book/e-data-book.c            |   49 +++++++++++++------
 addressbook/libedata-book/e-data-book.h            |    1 +
 .../libedata-book/libedata-book-sections.txt       |    1 +
 4 files changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index cc22aa7..c6964fe 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -24,7 +24,7 @@ struct _EBookBackendPrivate {
        ESourceRegistry *registry;
        EDataBook *data_book;
 
-       gboolean opened, removed;
+       gboolean removed;
        gboolean writable;
 
        GMutex views_mutex;
@@ -1094,9 +1094,19 @@ e_book_backend_set_backend_property (EBookBackend *backend,
 gboolean
 e_book_backend_is_opened (EBookBackend *backend)
 {
+       EDataBook *data_book;
+       gboolean opened = FALSE;
+
        g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), FALSE);
 
-       return backend->priv->opened;
+       data_book = e_book_backend_ref_data_book (backend);
+
+       if (data_book != NULL) {
+               opened = e_data_book_is_opened (data_book);
+               g_object_unref (data_book);
+       }
+
+       return opened;
 }
 
 /**
@@ -1426,12 +1436,6 @@ void
 e_book_backend_notify_opened (EBookBackend *backend,
                               GError *error)
 {
-       g_return_if_fail (E_IS_BOOK_BACKEND (backend));
-
-       backend->priv->opened = (error == NULL);
-
-       if (error != NULL)
-               g_error_free (error);
 }
 
 /**
diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c
index ccae791..6339a37 100644
--- a/addressbook/libedata-book/e-data-book.c
+++ b/addressbook/libedata-book/e-data-book.c
@@ -50,6 +50,8 @@ struct _EDataBookPrivate {
        GWeakRef backend;
        gchar *object_path;
 
+       gboolean opened;
+
        GRecMutex pending_ops_lock;
        GHashTable *pending_ops; /* opid -> OperationData */
        GHashTable *direct_ops; /* opid to DirectOperationData for still running operations */
@@ -1197,7 +1199,6 @@ e_data_book_respond_open (EDataBook *book,
 {
        DirectOperationData *direct = NULL;
        OperationData *data;
-       GError *copy = NULL;
 
        g_return_if_fail (E_IS_DATA_BOOK (book));
 
@@ -1207,26 +1208,15 @@ e_data_book_respond_open (EDataBook *book,
        /* Translators: This is prefix to a detailed error message */
        g_prefix_error (&error, "%s", _("Cannot open book: "));
 
-       /* This function is deprecated, but it's the only way to
-        * set EBookBackend's internal 'opened' flag.  We should
-        * be the only ones calling this. */
-       if (error != NULL) {
-               data_book_convert_to_client_error (error);
-               copy = g_error_copy (error);
-       }
-
-       e_book_backend_notify_opened (data->backend, copy);
+       book->priv->opened = (error == NULL);
 
        if (direct) {
                gboolean result = FALSE;
 
                if (error) {
-                       g_simple_async_result_set_error (
-                               direct->result,
-                               error->domain,
-                               error->code,
-                               "%s", error->message);
-                       g_error_free (error);
+                       data_book_convert_to_client_error (error);
+                       g_simple_async_result_take_error (
+                               direct->result, error);
                } else {
                        g_simple_async_result_set_check_cancellable (
                                direct->result,
@@ -1245,6 +1235,7 @@ e_data_book_respond_open (EDataBook *book,
                        book->priv->dbus_interface,
                        data->invocation);
        } else {
+               data_book_convert_to_client_error (error);
                g_dbus_method_invocation_take_error (
                        data->invocation, error);
        }
@@ -2458,6 +2449,32 @@ e_data_book_get_object_path (EDataBook *book)
        return book->priv->object_path;
 }
 
+/**
+ * e_data_book_is_opened:
+ * @book: an #EDataBook
+ *
+ * Returns whether the @book's #EDataBook:backend was successfully opened.
+ *
+ * <note>
+ *   <para>
+ *     This is a temporary function serving only to keep
+ *     e_book_backend_is_opened() working for a little while longer.
+ *     Do not call this function directly.
+ *   </para>
+ * </note>
+ *
+ * Returns: whether the #EDataBook:backend is opened
+ *
+ * Since: 3.10
+ **/
+gboolean
+e_data_book_is_opened (EDataBook *book)
+{
+       g_return_val_if_fail (E_IS_DATA_BOOK (book), FALSE);
+
+       return book->priv->opened;
+}
+
 /*************************************************************************
  *                        Direct Read Access APIs                        *
  *************************************************************************/
diff --git a/addressbook/libedata-book/e-data-book.h b/addressbook/libedata-book/e-data-book.h
index 06c5ccc..942ed57 100644
--- a/addressbook/libedata-book/e-data-book.h
+++ b/addressbook/libedata-book/e-data-book.h
@@ -157,6 +157,7 @@ struct _EBookBackend *
 GDBusConnection *
                e_data_book_get_connection      (EDataBook *book);
 const gchar *  e_data_book_get_object_path     (EDataBook *book);
+gboolean       e_data_book_is_opened           (EDataBook *book);
 
 void           e_data_book_respond_open        (EDataBook *book,
                                                 guint32 opid,
diff --git a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt 
b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
index 87c6b66..0f00c80 100644
--- a/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
+++ b/docs/reference/addressbook/libedata-book/libedata-book-sections.txt
@@ -280,6 +280,7 @@ e_data_book_new
 e_data_book_ref_backend
 e_data_book_get_connection
 e_data_book_get_object_path
+e_data_book_is_opened
 e_data_book_respond_open
 e_data_book_respond_refresh
 e_data_book_respond_get_backend_property


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