[evolution-ews] Listen and act on EBackend's online state changes



commit 5f6d33536075ce00367e8272f84b27e8299854d2
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 21 15:27:15 2013 +0100

    Listen and act on EBackend's online state changes

 src/addressbook/e-book-backend-ews.c |   58 ++++++++++++++++++
 src/calendar/e-cal-backend-ews.c     |  106 ++++++++++++++++++++++++++--------
 src/collection/e-ews-backend.c       |   66 ++++++++++++++++++---
 3 files changed, 197 insertions(+), 33 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index c4a5250..3649eaa 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -2891,6 +2891,59 @@ e_book_backend_ews_new (void)
        return E_BOOK_BACKEND (backend);
 }
 
+static gboolean
+e_book_backend_ews_get_destination_address (EBackend *backend,
+                                           gchar **host,
+                                           guint16 *port)
+{
+       CamelEwsSettings *ews_settings;
+       SoupURI *soup_uri;
+       gchar *host_url;
+       gboolean result = FALSE;
+
+       g_return_val_if_fail (port != NULL, FALSE);
+       g_return_val_if_fail (host != NULL, FALSE);
+
+       /* Sanity checking */
+       if (!e_book_backend_get_registry (E_BOOK_BACKEND (backend)) ||
+           !e_backend_get_source (backend))
+               return FALSE;
+
+       ews_settings = book_backend_ews_get_collection_settings (E_BOOK_BACKEND_EWS (backend));
+       g_return_val_if_fail (ews_settings != NULL, FALSE);
+
+       host_url = camel_ews_settings_dup_hosturl (ews_settings);
+       g_return_val_if_fail (host_url != NULL, FALSE);
+
+       soup_uri = soup_uri_new (host_url);
+       if (soup_uri) {
+               *host = g_strdup (soup_uri_get_host (soup_uri));
+               *port = soup_uri_get_port (soup_uri);
+
+               result = *host && **host;
+               if (!result) {
+                       g_free (*host);
+                       *host = NULL;
+               }
+
+               soup_uri_free (soup_uri);
+       }
+
+       g_free (host_url);
+
+       return result;
+}
+
+static void
+e_book_backend_ews_constructed (GObject *object)
+{
+       G_OBJECT_CLASS (e_book_backend_ews_parent_class)->constructed (object);
+
+       /* Reset the connectable, it steals data from Authentication extension,
+          where is written incorrect address */
+       e_backend_set_connectable (E_BACKEND (object), NULL);
+}
+
 static void
 e_book_backend_ews_dispose (GObject *object)
 {
@@ -3015,8 +3068,10 @@ e_book_backend_ews_class_init (EBookBackendEwsClass *klass)
 {
 
        GObjectClass  *object_class = G_OBJECT_CLASS (klass);
+       EBackendClass *backend_class;
        EBookBackendClass *parent_class;
 
+       backend_class = E_BACKEND_CLASS (klass);
        parent_class = E_BOOK_BACKEND_CLASS (klass);
 
        /* Set the virtual methods. */
@@ -3031,6 +3086,9 @@ e_book_backend_ews_class_init (EBookBackendEwsClass *klass)
        parent_class->start_view              = e_book_backend_ews_start_view;
        parent_class->stop_view               = e_book_backend_ews_stop_view;
 
+       backend_class->get_destination_address = e_book_backend_ews_get_destination_address;
+
+       object_class->constructed             = e_book_backend_ews_constructed;
        object_class->dispose                 = e_book_backend_ews_dispose;
 }
 
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index fdee560..ae27269 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -4079,7 +4079,7 @@ e_cal_backend_ews_get_backend_property (ECalBackend *backend,
 }
 
 static void
-e_cal_backend_ews_notify_online_cb (ECalBackend *backend,
+e_cal_backend_ews_notify_online_cb (EBackend *backend,
                                     GParamSpec *spec)
 {
        ECalBackendEws *cbews;
@@ -4090,7 +4090,7 @@ e_cal_backend_ews_notify_online_cb (ECalBackend *backend,
 
        PRIV_LOCK (priv);
 
-       if (e_backend_get_online (E_BACKEND (backend))) {
+       if (e_backend_get_online (backend)) {
                if (priv->cancellable) {
                        g_cancellable_cancel (priv->cancellable);
                        g_object_unref (priv->cancellable);
@@ -4099,15 +4099,68 @@ e_cal_backend_ews_notify_online_cb (ECalBackend *backend,
                priv->cancellable = g_cancellable_new ();
 
                priv->read_only = FALSE;
-               e_cal_backend_set_writable (backend, !priv->read_only);
        } else {
-               switch_offline (E_CAL_BACKEND_EWS (backend));
-               e_cal_backend_set_writable (backend, !priv->read_only);
+               switch_offline (cbews);
        }
 
+       e_cal_backend_set_writable (E_CAL_BACKEND (backend), !priv->read_only);
+
        PRIV_UNLOCK (priv);
 }
 
+static gboolean
+e_cal_backend_ews_get_destination_address (EBackend *backend,
+                                          gchar **host,
+                                          guint16 *port)
+{
+       CamelEwsSettings *ews_settings;
+       SoupURI *soup_uri;
+       gchar *host_url;
+       gboolean result = FALSE;
+
+       g_return_val_if_fail (port != NULL, FALSE);
+       g_return_val_if_fail (host != NULL, FALSE);
+
+       /* Sanity checking */
+       if (!e_cal_backend_get_registry (E_CAL_BACKEND (backend)) ||
+           !e_backend_get_source (backend))
+               return FALSE;
+
+       ews_settings = cal_backend_ews_get_collection_settings (E_CAL_BACKEND_EWS (backend));
+       g_return_val_if_fail (ews_settings != NULL, FALSE);
+
+       host_url = camel_ews_settings_dup_hosturl (ews_settings);
+       g_return_val_if_fail (host_url != NULL, FALSE);
+
+       soup_uri = soup_uri_new (host_url);
+       if (soup_uri) {
+               *host = g_strdup (soup_uri_get_host (soup_uri));
+               *port = soup_uri_get_port (soup_uri);
+
+               result = *host && **host;
+               if (!result) {
+                       g_free (*host);
+                       *host = NULL;
+               }
+
+               soup_uri_free (soup_uri);
+       }
+
+       g_free (host_url);
+
+       return result;
+}
+
+static void
+e_cal_backend_ews_constructed (GObject *object)
+{
+       G_OBJECT_CLASS (e_cal_backend_ews_parent_class)->constructed (object);
+
+       /* Reset the connectable, it steals data from Authentication extension,
+          where is written incorrect address */
+       e_backend_set_connectable (E_BACKEND (object), NULL);
+}
+
 static void
 e_cal_backend_ews_dispose (GObject *object)
 {
@@ -4301,39 +4354,42 @@ static void
 e_cal_backend_ews_class_init (ECalBackendEwsClass *class)
 {
        GObjectClass *object_class;
-       ECalBackendClass *backend_class;
+       EBackendClass *backend_class;
+       ECalBackendClass *cal_backend_class;
 
-       object_class = (GObjectClass *) class;
-       backend_class = (ECalBackendClass *) class;
+       object_class = G_OBJECT_CLASS (class);
+       backend_class = E_BACKEND_CLASS (class);
+       cal_backend_class = E_CAL_BACKEND_CLASS (class);
 
+       object_class->constructed = e_cal_backend_ews_constructed;
        object_class->dispose = e_cal_backend_ews_dispose;
        object_class->finalize = e_cal_backend_ews_finalize;
 
+       backend_class->get_destination_address = e_cal_backend_ews_get_destination_address;
+
        /* Property accessors */
-       backend_class->get_backend_property = e_cal_backend_ews_get_backend_property;
+       cal_backend_class->get_backend_property = e_cal_backend_ews_get_backend_property;
 
-       backend_class->start_view = e_cal_backend_ews_start_query;
+       cal_backend_class->start_view = e_cal_backend_ews_start_query;
 
        /* Many of these can be moved to Base class */
-       backend_class->add_timezone = e_cal_backend_ews_add_timezone;
-       backend_class->get_timezone = e_cal_backend_ews_get_timezone;
+       cal_backend_class->add_timezone = e_cal_backend_ews_add_timezone;
+       cal_backend_class->get_timezone = e_cal_backend_ews_get_timezone;
 
-       backend_class->open = e_cal_backend_ews_open;
-       backend_class->refresh = e_cal_backend_ews_refresh;
-       backend_class->get_object = e_cal_backend_ews_get_object;
-       backend_class->get_object_list = e_cal_backend_ews_get_object_list;
+       cal_backend_class->open = e_cal_backend_ews_open;
+       cal_backend_class->refresh = e_cal_backend_ews_refresh;
+       cal_backend_class->get_object = e_cal_backend_ews_get_object;
+       cal_backend_class->get_object_list = e_cal_backend_ews_get_object_list;
 
-       backend_class->discard_alarm = e_cal_backend_ews_discard_alarm;
+       cal_backend_class->discard_alarm = e_cal_backend_ews_discard_alarm;
 
-       backend_class->create_objects = e_cal_backend_ews_create_objects;
-       backend_class->modify_objects = e_cal_backend_ews_modify_objects;
-       backend_class->remove_objects = e_cal_backend_ews_remove_objects;
+       cal_backend_class->create_objects = e_cal_backend_ews_create_objects;
+       cal_backend_class->modify_objects = e_cal_backend_ews_modify_objects;
+       cal_backend_class->remove_objects = e_cal_backend_ews_remove_objects;
 
-       backend_class->receive_objects = e_cal_backend_ews_receive_objects;
-       backend_class->send_objects = e_cal_backend_ews_send_objects;
-       /* backend_class->get_attachment_list = e_cal_backend_ews_get_attachment_list; */
-       backend_class->get_free_busy = e_cal_backend_ews_get_free_busy;
-       /* backend_class->get_changes = e_cal_backend_ews_get_changes; */
+       cal_backend_class->receive_objects = e_cal_backend_ews_receive_objects;
+       cal_backend_class->send_objects = e_cal_backend_ews_send_objects;
+       cal_backend_class->get_free_busy = e_cal_backend_ews_get_free_busy;
 }
 
 static void
diff --git a/src/collection/e-ews-backend.c b/src/collection/e-ews-backend.c
index ec3e85f..6f349c1 100644
--- a/src/collection/e-ews-backend.c
+++ b/src/collection/e-ews-backend.c
@@ -627,6 +627,10 @@ ews_backend_constructed (GObject *object)
        g_signal_connect (
                source, "changed",
                G_CALLBACK (ews_backend_source_changed_cb), object);
+
+       /* Reset the connectable, it steals data from Authentication extension,
+          where is written incorrect address */
+       e_backend_set_connectable (E_BACKEND (object), NULL);
 }
 
 static void
@@ -939,11 +943,50 @@ exit:
        return success;
 }
 
+static gboolean
+ews_backend_get_destination_address (EBackend *backend,
+                                    gchar **host,
+                                    guint16 *port)
+{
+       CamelEwsSettings *ews_settings;
+       SoupURI *soup_uri;
+       gchar *host_url;
+       gboolean result = FALSE;
+
+       g_return_val_if_fail (port != NULL, FALSE);
+       g_return_val_if_fail (host != NULL, FALSE);
+
+       ews_settings = ews_backend_get_settings (E_EWS_BACKEND (backend));
+       g_return_val_if_fail (ews_settings != NULL, FALSE);
+
+       host_url = camel_ews_settings_dup_hosturl (ews_settings);
+       g_return_val_if_fail (host_url != NULL, FALSE);
+
+       soup_uri = soup_uri_new (host_url);
+       if (soup_uri) {
+               *host = g_strdup (soup_uri_get_host (soup_uri));
+               *port = soup_uri_get_port (soup_uri);
+
+               result = *host && **host;
+               if (!result) {
+                       g_free (*host);
+                       *host = NULL;
+               }
+
+               soup_uri_free (soup_uri);
+       }
+
+       g_free (host_url);
+
+       return result;
+}
+
 static void
 e_ews_backend_class_init (EEwsBackendClass *class)
 {
        GObjectClass *object_class;
-       ECollectionBackendClass *backend_class;
+       EBackendClass *backend_class;
+       ECollectionBackendClass *collection_backend_class;
 
        g_type_class_add_private (class, sizeof (EEwsBackendPrivate));
 
@@ -952,13 +995,16 @@ e_ews_backend_class_init (EEwsBackendClass *class)
        object_class->finalize = ews_backend_finalize;
        object_class->constructed = ews_backend_constructed;
 
-       backend_class = E_COLLECTION_BACKEND_CLASS (class);
-       backend_class->populate = ews_backend_populate;
-       backend_class->dup_resource_id = ews_backend_dup_resource_id;
-       backend_class->child_added = ews_backend_child_added;
-       backend_class->child_removed = ews_backend_child_removed;
-       backend_class->create_resource_sync = ews_backend_create_resource_sync;
-       backend_class->delete_resource_sync = ews_backend_delete_resource_sync;
+       collection_backend_class = E_COLLECTION_BACKEND_CLASS (class);
+       collection_backend_class->populate = ews_backend_populate;
+       collection_backend_class->dup_resource_id = ews_backend_dup_resource_id;
+       collection_backend_class->child_added = ews_backend_child_added;
+       collection_backend_class->child_removed = ews_backend_child_removed;
+       collection_backend_class->create_resource_sync = ews_backend_create_resource_sync;
+       collection_backend_class->delete_resource_sync = ews_backend_delete_resource_sync;
+
+       backend_class = E_BACKEND_CLASS (class);
+       backend_class->get_destination_address = ews_backend_get_destination_address;
 
        /* This generates an ESourceCamel subtype for CamelEwsSettings. */
        e_source_camel_generate_subtype ("ews", CAMEL_TYPE_EWS_SETTINGS);
@@ -983,6 +1029,10 @@ e_ews_backend_init (EEwsBackend *backend)
        g_mutex_init (&backend->priv->folders_lock);
        g_mutex_init (&backend->priv->sync_state_lock);
        g_mutex_init (&backend->priv->connection_lock);
+
+       g_signal_connect (
+               backend, "notify::online",
+               G_CALLBACK (ews_backend_populate), NULL);
 }
 
 void


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