[evolution-ews] Use GInitable to initialise addressbook



commit e5286c3ab34b063b07e969482bcdf9c5cacb31ea
Author: David Woodhouse <David Woodhouse intel com>
Date:   Mon Sep 1 16:23:31 2014 +0100

    Use GInitable to initialise addressbook
    
    We apparently get asked for revision and locale information before it's
    actually opened, and clients will crash if we just return NULL. So open
    the sqlite database at instantiation time, like the file backend does.

 src/addressbook/e-book-backend-ews.c |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 19b98db..cf879d0 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -118,6 +118,8 @@ enum {
 /* Forward Declarations */
 static void    e_book_backend_ews_authenticator_init
                                (ESourceAuthenticatorInterface *iface);
+static void    e_book_backend_ews_initable_init
+                               (GInitableIface *iface);
 static gpointer ews_update_items_thread (gpointer data);
 
 
@@ -127,7 +129,10 @@ G_DEFINE_TYPE_WITH_CODE (
        E_TYPE_BOOK_BACKEND,
        G_IMPLEMENT_INTERFACE (
                E_TYPE_SOURCE_AUTHENTICATOR,
-               e_book_backend_ews_authenticator_init))
+               e_book_backend_ews_authenticator_init)
+       G_IMPLEMENT_INTERFACE (
+               G_TYPE_INITABLE,
+               e_book_backend_ews_initable_init))
 
 static CamelEwsSettings *
 book_backend_ews_get_collection_settings (EBookBackendEws *backend)
@@ -3400,10 +3405,12 @@ e_book_backend_ews_stop_view (EBookBackend *backend,
 }
 
 static gboolean
-e_book_backend_ews_load_source (EBookBackend *backend,
-                                ESource *source,
-                                GError **perror)
+book_backend_ews_initable_init (GInitable *initable,
+                               GCancellable *cancellable,
+                               GError **error)
 {
+       EBookBackend *backend = E_BOOK_BACKEND (initable);
+       ESource *source = e_backend_get_source (E_BACKEND (backend));
        EBookBackendEws *cbews;
        EBookBackendEwsPrivate *priv;
        CamelEwsSettings *settings;
@@ -3435,10 +3442,12 @@ e_book_backend_ews_load_source (EBookBackend *backend,
 
        priv->summary = e_book_backend_sqlitedb_new (
                cache_dir, email, priv->folder_id,
-               display_name, TRUE, perror);
+               display_name, TRUE, error);
 
-       if (priv->summary == NULL)
+       if (priv->summary == NULL) {
+               convert_error_to_edb_error (error);
                return FALSE;
+       }
 
        priv->marked_for_offline = FALSE;
        priv->is_writable = FALSE;
@@ -3814,7 +3823,6 @@ e_book_backend_ews_open_sync (EBookBackend *backend,
        CamelEwsSettings *ews_settings;
        EBookBackendEws *ebews;
        EBookBackendEwsPrivate * priv;
-       ESource *source;
        gboolean need_to_authenticate;
 
        if (e_book_backend_is_opened (backend))
@@ -3823,11 +3831,6 @@ e_book_backend_ews_open_sync (EBookBackend *backend,
        ebews = E_BOOK_BACKEND_EWS (backend);
        priv = ebews->priv;
 
-       source = e_backend_get_source (E_BACKEND (backend));
-       if (!e_book_backend_ews_load_source (backend, source, error)) {
-               convert_error_to_edb_error (error);
-               return FALSE;
-       }
        ews_settings = book_backend_ews_get_collection_settings (ebews);
 
        PRIV_LOCK (priv);
@@ -4124,6 +4127,12 @@ e_book_backend_ews_authenticator_init (ESourceAuthenticatorInterface *iface)
 }
 
 static void
+e_book_backend_ews_initable_init (GInitableIface *iface)
+{
+       iface->init = book_backend_ews_initable_init;
+}
+
+static void
 e_book_backend_ews_init (EBookBackendEws *backend)
 {
        backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (backend, E_TYPE_BOOK_BACKEND_EWS, 
EBookBackendEwsPrivate);


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