[evolution-data-server] ECalBackend: Add a read-only "proxy-resolver" property.



commit a0bb67b684033300e0660f8d4cbf8b086d3ffe47
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Oct 9 17:46:56 2013 -0400

    ECalBackend: Add a read-only "proxy-resolver" property.
    
    Tracks a GProxyResolver for the backend, which is actually another
    ESource with an ESourceProxy extension (if applicable to the backend).
    
    New functions:
    
      e_cal_backend_ref_proxy_resolver()

 calendar/libedata-cal/e-cal-backend.c              |  156 +++++++++++++++++++-
 calendar/libedata-cal/e-cal-backend.h              |    3 +
 .../libedata-cal/libedata-cal-sections.txt         |    1 +
 3 files changed, 159 insertions(+), 1 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index 781221d..1ab7271 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -44,9 +44,13 @@ struct _ECalBackendPrivate {
        GList *views;
 
        GMutex property_lock;
+       GProxyResolver *proxy_resolver;
        gchar *cache_dir;
        gboolean writable;
 
+       ESource *authentication_source;
+       gulong auth_source_changed_handler_id;
+
        GHashTable *zone_cache;
        GMutex zone_cache_lock;
 
@@ -100,6 +104,7 @@ enum {
        PROP_0,
        PROP_CACHE_DIR,
        PROP_KIND,
+       PROP_PROXY_RESOLVER,
        PROP_REGISTRY,
        PROP_WRITABLE
 };
@@ -378,6 +383,72 @@ cal_backend_set_default_cache_dir (ECalBackend *backend)
        g_free (filename);
 }
 
+static void
+cal_backend_update_proxy_resolver (ECalBackend *backend)
+{
+       GProxyResolver *proxy_resolver = NULL;
+       ESourceAuthentication *extension;
+       ESource *source = NULL;
+       gboolean notify = FALSE;
+       gchar *uid;
+
+       extension = e_source_get_extension (
+               backend->priv->authentication_source,
+               E_SOURCE_EXTENSION_AUTHENTICATION);
+
+       uid = e_source_authentication_dup_proxy_uid (extension);
+       if (uid != NULL) {
+               ESourceRegistry *registry;
+
+               registry = e_cal_backend_get_registry (backend);
+               source = e_source_registry_ref_source (registry, uid);
+               g_free (uid);
+       }
+
+       if (source != NULL) {
+               proxy_resolver = G_PROXY_RESOLVER (source);
+               if (!g_proxy_resolver_is_supported (proxy_resolver))
+                       proxy_resolver = NULL;
+       }
+
+       g_mutex_lock (&backend->priv->property_lock);
+
+       /* Emitting a "notify" signal unnecessarily might have
+        * unwanted side effects like cancelling a SoupMessage.
+        * Only emit if we now have a different GProxyResolver. */
+
+       if (proxy_resolver != backend->priv->proxy_resolver) {
+               g_clear_object (&backend->priv->proxy_resolver);
+               backend->priv->proxy_resolver = proxy_resolver;
+
+               if (proxy_resolver != NULL)
+                       g_object_ref (proxy_resolver);
+
+               notify = TRUE;
+       }
+
+       g_mutex_unlock (&backend->priv->property_lock);
+
+       if (notify)
+               g_object_notify (G_OBJECT (backend), "proxy-resolver");
+
+       g_clear_object (&source);
+}
+
+static void
+cal_backend_auth_source_changed_cb (ESource *authentication_source,
+                                    GWeakRef *backend_weak_ref)
+{
+       ECalBackend *backend;
+
+       backend = g_weak_ref_get (backend_weak_ref);
+
+       if (backend != NULL) {
+               cal_backend_update_proxy_resolver (backend);
+               g_object_unref (backend);
+       }
+}
+
 static gchar *
 cal_backend_get_backend_property (ECalBackend *backend,
                                   const gchar *prop_name)
@@ -504,6 +575,12 @@ cal_backend_get_property (GObject *object,
                                E_CAL_BACKEND (object)));
                        return;
 
+               case PROP_PROXY_RESOLVER:
+                       g_value_take_object (
+                               value, e_cal_backend_ref_proxy_resolver (
+                               E_CAL_BACKEND (object)));
+                       return;
+
                case PROP_REGISTRY:
                        g_value_set_object (
                                value, e_cal_backend_get_registry (
@@ -527,8 +604,17 @@ cal_backend_dispose (GObject *object)
 
        priv = E_CAL_BACKEND_GET_PRIVATE (object);
 
+       if (priv->auth_source_changed_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       priv->authentication_source,
+                       priv->auth_source_changed_handler_id);
+               priv->auth_source_changed_handler_id = 0;
+       }
+
        g_clear_object (&priv->registry);
        g_clear_object (&priv->data_cal);
+       g_clear_object (&priv->proxy_resolver);
+       g_clear_object (&priv->authentication_source);
 
        g_hash_table_remove_all (priv->operation_ids);
 
@@ -567,11 +653,36 @@ cal_backend_finalize (GObject *object)
 static void
 cal_backend_constructed (GObject *object)
 {
+       ECalBackend *backend;
+       ESourceRegistry *registry;
+       ESource *source;
+
        /* Chain up to parent's constructed() method. */
        G_OBJECT_CLASS (e_cal_backend_parent_class)->constructed (object);
 
+       backend = E_CAL_BACKEND (object);
+       registry = e_cal_backend_get_registry (backend);
+       source = e_backend_get_source (E_BACKEND (backend));
+
        /* Initialize the "cache-dir" property. */
-       cal_backend_set_default_cache_dir (E_CAL_BACKEND (object));
+       cal_backend_set_default_cache_dir (backend);
+
+       /* Track the proxy resolver for this backend. */
+       backend->priv->authentication_source =
+               e_source_registry_find_extension (
+               registry, source, E_SOURCE_EXTENSION_AUTHENTICATION);
+       if (backend->priv->authentication_source != NULL) {
+               gulong handler_id;
+
+               handler_id = g_signal_connect_data (
+                       backend->priv->authentication_source, "changed",
+                       G_CALLBACK (cal_backend_auth_source_changed_cb),
+                       e_weak_ref_new (backend),
+                       (GClosureNotify) e_weak_ref_free, 0);
+               backend->priv->auth_source_changed_handler_id = handler_id;
+
+               cal_backend_update_proxy_resolver (backend);
+       }
 }
 
 static gboolean
@@ -811,6 +922,17 @@ e_cal_backend_class_init (ECalBackendClass *class)
 
        g_object_class_install_property (
                object_class,
+               PROP_PROXY_RESOLVER,
+               g_param_spec_object (
+                       "proxy-resolver",
+                       "Proxy Resolver",
+                       "The proxy resolver for this backend",
+                       G_TYPE_PROXY_RESOLVER,
+                       G_PARAM_READABLE |
+                       G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
                PROP_REGISTRY,
                g_param_spec_object (
                        "registry",
@@ -977,6 +1099,38 @@ e_cal_backend_set_data_cal (ECalBackend *backend,
 }
 
 /**
+ * e_cal_backend_ref_proxy_resolver:
+ * @backend: an #ECalBackend
+ *
+ * Returns the #GProxyResolver for @backend (if applicable), as indicated
+ * by the #ESourceAuthentication:proxy-uid of @backend's #EBackend:source
+ * or one of its ancestors.
+ *
+ * The returned #GProxyResolver is referenced for thread-safety and must
+ * be unreferenced with g_object_unref() when finished with it.
+ *
+ * Returns: a #GProxyResolver, or %NULL
+ *
+ * Since: 3.12
+ **/
+GProxyResolver *
+e_cal_backend_ref_proxy_resolver (ECalBackend *backend)
+{
+       GProxyResolver *proxy_resolver = NULL;
+
+       g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
+
+       g_mutex_lock (&backend->priv->property_lock);
+
+       if (backend->priv->proxy_resolver != NULL)
+               proxy_resolver = g_object_ref (backend->priv->proxy_resolver);
+
+       g_mutex_unlock (&backend->priv->property_lock);
+
+       return proxy_resolver;
+}
+
+/**
  * e_cal_backend_get_registry:
  * @backend: an #ECalBackend
  *
diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h
index 0eb5d3d..7678b58 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -217,6 +217,9 @@ icalcomponent_kind
 EDataCal *     e_cal_backend_ref_data_cal      (ECalBackend *backend);
 void           e_cal_backend_set_data_cal      (ECalBackend *backend,
                                                 EDataCal *data_cal);
+GProxyResolver *
+               e_cal_backend_ref_proxy_resolver
+                                               (ECalBackend *backend);
 ESourceRegistry *
                e_cal_backend_get_registry      (ECalBackend *backend);
 gboolean       e_cal_backend_get_writable      (ECalBackend *backend);
diff --git a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt 
b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
index e712b9a..01931bb 100644
--- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
+++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
@@ -10,6 +10,7 @@ CAL_BACKEND_PROPERTY_REVISION
 e_cal_backend_get_kind
 e_cal_backend_ref_data_cal
 e_cal_backend_set_data_cal
+e_cal_backend_ref_proxy_resolver
 e_cal_backend_get_registry
 e_cal_backend_get_writable
 e_cal_backend_set_writable


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