From d81ac31ece00971984176d665dabba9a27dd5de7 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 25 Jan 2013 12:57:10 -0500 Subject: [PATCH] ECalBackend: Add a "writable" boolean property. --- calendar/libedata-cal/e-cal-backend.c | 82 +++++++++++++++++++--- calendar/libedata-cal/e-cal-backend.h | 3 + .../libedata-cal/libedata-cal-sections.txt | 2 + 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c index efce8ad..7986d8c 100644 --- a/calendar/libedata-cal/e-cal-backend.c +++ b/calendar/libedata-cal/e-cal-backend.c @@ -42,7 +42,8 @@ struct _ECalBackendPrivate { /* The kind of components for this backend */ icalcomponent_kind kind; - gboolean opening, opened, readonly, removed; + gboolean opening, opened, removed; + gboolean writable; gchar *cache_dir; @@ -66,7 +67,8 @@ enum { PROP_0, PROP_CACHE_DIR, PROP_KIND, - PROP_REGISTRY + PROP_REGISTRY, + PROP_WRITABLE }; /* Forward Declarations */ @@ -213,6 +215,12 @@ cal_backend_set_property (GObject *object, E_CAL_BACKEND (object), g_value_get_object (value)); return; + + case PROP_WRITABLE: + e_cal_backend_set_writable ( + E_CAL_BACKEND (object), + g_value_get_boolean (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -242,6 +250,12 @@ cal_backend_get_property (GObject *object, value, e_cal_backend_get_registry ( E_CAL_BACKEND (object))); return; + + case PROP_WRITABLE: + g_value_set_boolean ( + value, e_cal_backend_get_writable ( + E_CAL_BACKEND (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -513,6 +527,17 @@ e_cal_backend_class_init (ECalBackendClass *class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property ( + object_class, + PROP_WRITABLE, + g_param_spec_boolean ( + "writable", + "Writable", + "Whether the backend will accept changes", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); } static void @@ -544,8 +569,6 @@ e_cal_backend_init (ECalBackend *backend) backend->priv->zone_cache = zone_cache; g_mutex_init (&backend->priv->zone_cache_lock); - - backend->priv->readonly = TRUE; } /** @@ -583,6 +606,47 @@ e_cal_backend_get_registry (ECalBackend *backend) } /** + * e_cal_backend_get_writable: + * @backend: an #ECalBackend + * + * Returns whether @backend will accept changes to its data content. + * + * Returns: whether @backend is writable + * + * Since: 3.8 + **/ +gboolean +e_cal_backend_get_writable (ECalBackend *backend) +{ + g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE); + + return backend->priv->writable; +} + +/** + * e_cal_backend_set_writable: + * @backend: an #ECalBackend + * @writable: whether @backend is writable + * + * Sets whether @backend will accept changes to its data content. + * + * Since: 3.8 + **/ +void +e_cal_backend_set_writable (ECalBackend *backend, + gboolean writable) +{ + g_return_if_fail (E_IS_CAL_BACKEND (backend)); + + if (writable == backend->priv->writable) + return; + + backend->priv->writable = writable; + + g_object_notify (G_OBJECT (backend), "writable"); +} + +/** * e_cal_backend_is_opened: * @backend: an #ECalBackend * @@ -640,7 +704,7 @@ e_cal_backend_is_readonly (ECalBackend *backend) { g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE); - return backend->priv->readonly; + return !e_cal_backend_get_writable (backend); } /** @@ -1107,13 +1171,15 @@ e_cal_backend_open (ECalBackend *backend, if (e_cal_backend_is_opened (backend)) { gboolean online; + gboolean writable; g_mutex_unlock (&backend->priv->clients_mutex); - e_data_cal_report_readonly (cal, backend->priv->readonly); - online = e_backend_get_online (E_BACKEND (backend)); + writable = e_cal_backend_get_writable (backend); + e_data_cal_report_online (cal, online); + e_data_cal_report_readonly (cal, !writable); e_cal_backend_respond_opened (backend, cal, opid, NULL); } else { @@ -1835,7 +1901,7 @@ e_cal_backend_notify_readonly (ECalBackend *backend, GList *l; priv = backend->priv; - priv->readonly = is_readonly; + e_cal_backend_set_writable (backend, !is_readonly); if (priv->notification_proxy) { e_cal_backend_notify_readonly (priv->notification_proxy, is_readonly); diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h index d53d936..bb41ab3 100644 --- a/calendar/libedata-cal/e-cal-backend.h +++ b/calendar/libedata-cal/e-cal-backend.h @@ -262,6 +262,9 @@ icalcomponent_kind e_cal_backend_get_kind (ECalBackend *backend); ESourceRegistry * e_cal_backend_get_registry (ECalBackend *backend); +gboolean e_cal_backend_get_writable (ECalBackend *backend); +void e_cal_backend_set_writable (ECalBackend *backend, + gboolean writable); gboolean e_cal_backend_is_opened (ECalBackend *backend); gboolean e_cal_backend_is_opening (ECalBackend *backend); gboolean e_cal_backend_is_readonly (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 a112465..e50985a 100644 --- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt +++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt @@ -14,6 +14,8 @@ CAL_BACKEND_PROPERTY_DEFAULT_OBJECT CAL_BACKEND_PROPERTY_REVISION e_cal_backend_get_kind e_cal_backend_get_registry +e_cal_backend_get_writable +e_cal_backend_set_writable e_cal_backend_is_opened e_cal_backend_is_opening e_cal_backend_is_readonly -- 2.7.4