[evolution-data-server] EClient cleanups.



commit a3ac57363e4eabb1548ddb1a609f762ea075a0dd
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Feb 23 10:08:25 2013 -0500

    EClient cleanups.

 libedataserver/e-client.c |  168 +++++++++++++++++++++-----------------------
 1 files changed, 80 insertions(+), 88 deletions(-)
---
diff --git a/libedataserver/e-client.c b/libedataserver/e-client.c
index 449592f..e0b8712 100644
--- a/libedataserver/e-client.c
+++ b/libedataserver/e-client.c
@@ -65,11 +65,11 @@ struct _AsyncContext {
 
 enum {
        PROP_0,
-       PROP_SOURCE,
        PROP_CAPABILITIES,
-       PROP_READONLY,
        PROP_ONLINE,
-       PROP_OPENED
+       PROP_OPENED,
+       PROP_READONLY,
+       PROP_SOURCE
 };
 
 enum {
@@ -199,46 +199,14 @@ e_client_error_create (EClientError code,
        return g_error_new_literal (E_CLIENT_ERROR, code, custom_msg ? custom_msg : e_client_error_to_string 
(code));
 }
 
-static void client_set_source (EClient *client, ESource *source);
-
-static void
-e_client_init (EClient *client)
-{
-       client->priv = E_CLIENT_GET_PRIVATE (client);
-
-       client->priv->readonly = TRUE;
-
-       g_rec_mutex_init (&client->priv->prop_mutex);
-}
-
 static void
-client_finalize (GObject *object)
+client_set_source (EClient *client,
+                   ESource *source)
 {
-       EClient *client;
-       EClientPrivate *priv;
-
-       client = E_CLIENT (object);
-
-       priv = client->priv;
-
-       g_rec_mutex_lock (&priv->prop_mutex);
-
-       if (priv->source) {
-               g_object_unref (priv->source);
-               priv->source = NULL;
-       }
-
-       if (priv->capabilities) {
-               g_slist_foreach (priv->capabilities, (GFunc) g_free, NULL);
-               g_slist_free (priv->capabilities);
-               priv->capabilities = NULL;
-       }
-
-       g_rec_mutex_unlock (&priv->prop_mutex);
-       g_rec_mutex_clear (&priv->prop_mutex);
+       g_return_if_fail (E_IS_SOURCE (source));
+       g_return_if_fail (client->priv->source == NULL);
 
-       /* Chain up to parent's finalize() method. */
-       G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
+       client->priv->source = g_object_ref (source);
 }
 
 static void
@@ -248,17 +216,17 @@ client_set_property (GObject *object,
                      GParamSpec *pspec)
 {
        switch (property_id) {
-               case PROP_SOURCE:
-                       client_set_source (
-                               E_CLIENT (object),
-                               g_value_get_object (value));
-                       return;
-
                case PROP_ONLINE:
                        e_client_set_online (
                                E_CLIENT (object),
                                g_value_get_boolean (value));
                        return;
+
+               case PROP_SOURCE:
+                       client_set_source (
+                               E_CLIENT (object),
+                               g_value_get_object (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -271,13 +239,6 @@ client_get_property (GObject *object,
                      GParamSpec *pspec)
 {
        switch (property_id) {
-               case PROP_SOURCE:
-                       g_value_set_object (
-                               value,
-                               e_client_get_source (
-                               E_CLIENT (object)));
-                       return;
-
                case PROP_CAPABILITIES:
                        g_value_set_pointer (
                                value,
@@ -285,24 +246,31 @@ client_get_property (GObject *object,
                                E_CLIENT (object)));
                        return;
 
-               case PROP_READONLY:
+               case PROP_ONLINE:
                        g_value_set_boolean (
                                value,
-                               e_client_is_readonly (
+                               e_client_is_online (
                                E_CLIENT (object)));
                        return;
 
-               case PROP_ONLINE:
+               case PROP_OPENED:
                        g_value_set_boolean (
                                value,
-                               e_client_is_online (
+                               e_client_is_opened (
                                E_CLIENT (object)));
                        return;
 
-               case PROP_OPENED:
+               case PROP_READONLY:
                        g_value_set_boolean (
                                value,
-                               e_client_is_opened (
+                               e_client_is_readonly (
+                               E_CLIENT (object)));
+                       return;
+
+               case PROP_SOURCE:
+                       g_value_set_object (
+                               value,
+                               e_client_get_source (
                                E_CLIENT (object)));
                        return;
        }
@@ -311,6 +279,34 @@ client_get_property (GObject *object,
 }
 
 static void
+client_dispose (GObject *object)
+{
+       EClientPrivate *priv;
+
+       priv = E_CLIENT_GET_PRIVATE (object);
+
+       g_clear_object (&priv->source);
+
+       /* Chain up to parent's dispose() method. */
+       G_OBJECT_CLASS (e_client_parent_class)->dispose (object);
+}
+
+static void
+client_finalize (GObject *object)
+{
+       EClientPrivate *priv;
+
+       priv = E_CLIENT_GET_PRIVATE (object);
+
+       g_slist_free_full (priv->capabilities, (GDestroyNotify) g_free);
+
+       g_rec_mutex_clear (&priv->prop_mutex);
+
+       /* Chain up to parent's finalize() method. */
+       G_OBJECT_CLASS (e_client_parent_class)->finalize (object);
+}
+
+static void
 client_unwrap_dbus_error (EClient *client,
                           GError *dbus_error,
                           GError **out_error)
@@ -750,6 +746,7 @@ e_client_class_init (EClientClass *class)
        object_class = G_OBJECT_CLASS (class);
        object_class->set_property = client_set_property;
        object_class->get_property = client_get_property;
+       object_class->dispose = client_dispose;
        object_class->finalize = client_finalize;
 
        class->unwrap_dbus_error = client_unwrap_dbus_error;
@@ -770,18 +767,6 @@ e_client_class_init (EClientClass *class)
 
        g_object_class_install_property (
                object_class,
-               PROP_SOURCE,
-               g_param_spec_object (
-                       "source",
-                       NULL,
-                       NULL,
-                       E_TYPE_SOURCE,
-                       G_PARAM_READWRITE |
-                       G_PARAM_CONSTRUCT_ONLY |
-                       G_PARAM_STATIC_STRINGS));
-
-       g_object_class_install_property (
-               object_class,
                PROP_CAPABILITIES,
                g_param_spec_pointer (
                        "capabilities",
@@ -792,37 +777,49 @@ e_client_class_init (EClientClass *class)
 
        g_object_class_install_property (
                object_class,
-               PROP_READONLY,
+               PROP_ONLINE,
                g_param_spec_boolean (
-                       "readonly",
+                       "online",
                        NULL,
                        NULL,
                        FALSE,
-                       G_PARAM_READABLE |
+                       G_PARAM_READWRITE |
                        G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property (
                object_class,
-               PROP_ONLINE,
+               PROP_OPENED,
                g_param_spec_boolean (
-                       "online",
+                       "opened",
                        NULL,
                        NULL,
                        FALSE,
-                       G_PARAM_READWRITE |
+                       G_PARAM_READABLE |
                        G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property (
                object_class,
-               PROP_OPENED,
+               PROP_READONLY,
                g_param_spec_boolean (
-                       "opened",
+                       "readonly",
                        NULL,
                        NULL,
                        FALSE,
                        G_PARAM_READABLE |
                        G_PARAM_STATIC_STRINGS));
 
+       g_object_class_install_property (
+               object_class,
+               PROP_SOURCE,
+               g_param_spec_object (
+                       "source",
+                       NULL,
+                       NULL,
+                       E_TYPE_SOURCE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT_ONLY |
+                       G_PARAM_STATIC_STRINGS));
+
        /**
         * EClient::opened:
         *
@@ -869,18 +866,13 @@ e_client_class_init (EClientClass *class)
 }
 
 static void
-client_set_source (EClient *client,
-                   ESource *source)
+e_client_init (EClient *client)
 {
-       g_return_if_fail (E_IS_CLIENT (client));
-       g_return_if_fail (E_IS_SOURCE (source));
-
-       g_object_ref (source);
+       client->priv = E_CLIENT_GET_PRIVATE (client);
 
-       if (client->priv->source)
-               g_object_unref (client->priv->source);
+       client->priv->readonly = TRUE;
 
-       client->priv->source = source;
+       g_rec_mutex_init (&client->priv->prop_mutex);
 }
 
 /**


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