[evolution-data-server] ECalBackend: Add a "cache-dir" string property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] ECalBackend: Add a "cache-dir" string property.
- Date: Thu, 22 Jul 2010 01:23:23 +0000 (UTC)
commit ade10f3ab967f62169c5298cfdf0c7e65cae5f25
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Jul 20 17:06:48 2010 -0400
ECalBackend: Add a "cache-dir" string property.
Holds the directory where data should be cached for that specific
backend instance.
e_cal_backend_get_cache_dir()
e_cal_backend_set_cache_dir()
calendar/libedata-cal/e-cal-backend.c | 113 ++++++++++++++++++++
calendar/libedata-cal/e-cal-backend.h | 3 +
.../libedata-cal/libedata-cal-sections.txt | 2 +
.../calendar/libedata-cal/tmpl/e-cal-backend.sgml | 34 ++++--
4 files changed, 141 insertions(+), 11 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index fc6bde9..ab7475e 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -50,6 +50,8 @@ struct _ECalBackendPrivate {
/* URI, from source. This is cached, since we return const. */
gchar *uri;
+ gchar *cache_dir;
+
/* The kind of components for this backend */
icalcomponent_kind kind;
@@ -72,6 +74,7 @@ struct _ECalBackendPrivate {
/* Property IDs */
enum {
PROP_0,
+ PROP_CACHE_DIR,
PROP_KIND,
PROP_SOURCE,
PROP_URI
@@ -113,6 +116,47 @@ source_changed_cb (ESource *source, ECalBackend *backend)
}
static void
+cal_backend_set_default_cache_dir (ECalBackend *backend)
+{
+ ESource *source;
+ icalcomponent_kind kind;
+ const gchar *component_type;
+ const gchar *user_cache_dir;
+ gchar *mangled_uri;
+ gchar *filename;
+
+ user_cache_dir = e_get_user_cache_dir ();
+
+ kind = e_cal_backend_get_kind (backend);
+ source = e_cal_backend_get_source (backend);
+ g_return_if_fail (source != NULL);
+
+ switch (kind) {
+ case ICAL_VEVENT_COMPONENT:
+ component_type = "calendar";
+ break;
+ case ICAL_VTODO_COMPONENT:
+ component_type = "tasks";
+ break;
+ case ICAL_VJOURNAL_COMPONENT:
+ component_type = "memos";
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ /* Mangle the URI to not contain invalid characters. */
+ mangled_uri = g_strdelimit (e_source_get_uri (source), ":/", '_');
+
+ filename = g_build_filename (
+ user_cache_dir, component_type, mangled_uri, NULL);
+ e_cal_backend_set_cache_dir (backend, filename);
+ g_free (filename);
+
+ g_free (mangled_uri);
+}
+
+static void
cal_backend_set_source (ECalBackend *backend,
ESource *source)
{
@@ -165,6 +209,11 @@ cal_backend_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
+ case PROP_CACHE_DIR:
+ e_cal_backend_set_cache_dir (
+ E_CAL_BACKEND (object),
+ g_value_get_string (value));
+ return;
case PROP_KIND:
cal_backend_set_kind (
E_CAL_BACKEND (object),
@@ -192,6 +241,11 @@ cal_backend_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
+ case PROP_CACHE_DIR:
+ g_value_set_string (
+ value, e_cal_backend_get_cache_dir (
+ E_CAL_BACKEND (object)));
+ return;
case PROP_KIND:
g_value_set_ulong (
value, e_cal_backend_get_kind (
@@ -227,6 +281,8 @@ cal_backend_finalize (GObject *object)
g_mutex_free (priv->queries_mutex);
g_free (priv->uri);
+ g_free (priv->cache_dir);
+
if (priv->source_changed_id && priv->source) {
g_signal_handler_disconnect (priv->source, priv->source_changed_id);
priv->source_changed_id = 0;
@@ -238,6 +294,12 @@ cal_backend_finalize (GObject *object)
}
static void
+cal_backend_constructed (GObject *object)
+{
+ cal_backend_set_default_cache_dir (E_CAL_BACKEND (object));
+}
+
+static void
e_cal_backend_class_init (ECalBackendClass *class)
{
GObjectClass *object_class;
@@ -248,6 +310,17 @@ e_cal_backend_class_init (ECalBackendClass *class)
object_class->set_property = cal_backend_set_property;
object_class->get_property = cal_backend_get_property;
object_class->finalize = cal_backend_finalize;
+ object_class->constructed = cal_backend_constructed;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CACHE_DIR,
+ g_param_spec_string (
+ "cache-dir",
+ NULL,
+ NULL,
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
@@ -309,6 +382,46 @@ e_cal_backend_init (ECalBackend *backend)
}
/**
+ * e_cal_backend_get_cache_dir:
+ * @backend: an #ECalBackend
+ *
+ * Returns the cache directory for the given backend.
+ *
+ * Returns: the cache directory for the backend
+ **/
+const gchar *
+e_cal_backend_get_cache_dir (ECalBackend *backend)
+{
+ g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
+
+ return backend->priv->cache_dir;
+}
+
+/**
+ * e_cal_backend_set_cache_dir:
+ * @backend: an #ECalBackend
+ * @cache_dir: a local cache directory
+ *
+ * Sets the cache directory for the given backend.
+ *
+ * Note that #ECalBackend is initialized with a usable default based on
+ * #ECalBackend:source and #ECalBackend:kind properties. Backends should
+ * not override the default without good reason.
+ **/
+void
+e_cal_backend_set_cache_dir (ECalBackend *backend,
+ const gchar *cache_dir)
+{
+ g_return_if_fail (E_IS_CAL_BACKEND (backend));
+ g_return_if_fail (cache_dir != NULL);
+
+ g_free (backend->priv->cache_dir);
+ backend->priv->cache_dir = g_strdup (cache_dir);
+
+ g_object_notify (G_OBJECT (backend), "cache-dir");
+}
+
+/**
* e_cal_backend_get_kind:
* @backend: an #ECalBackend
*
diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h
index 8e5e87f..d9fccf8 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -114,6 +114,9 @@ ESource *e_cal_backend_get_source (ECalBackend *backend);
const gchar *e_cal_backend_get_uri (ECalBackend *backend);
icalcomponent_kind e_cal_backend_get_kind (ECalBackend *backend);
+const gchar *e_cal_backend_get_cache_dir (ECalBackend *backend);
+void e_cal_backend_set_cache_dir (ECalBackend *backend, const gchar *cache_dir);
+
void e_cal_backend_add_client (ECalBackend *backend, EDataCal *cal);
void e_cal_backend_remove_client (ECalBackend *backend, EDataCal *cal);
diff --git a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
index 64ec75d..fa29c05 100644
--- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
+++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
@@ -127,6 +127,8 @@ ECalBackend
e_cal_backend_get_source
e_cal_backend_get_uri
e_cal_backend_get_kind
+e_cal_backend_get_cache_dir
+e_cal_backend_set_cache_dir
e_cal_backend_add_client
e_cal_backend_remove_client
e_cal_backend_add_query
diff --git a/docs/reference/calendar/libedata-cal/tmpl/e-cal-backend.sgml b/docs/reference/calendar/libedata-cal/tmpl/e-cal-backend.sgml
index 95a9f31..e05ef72 100644
--- a/docs/reference/calendar/libedata-cal/tmpl/e-cal-backend.sgml
+++ b/docs/reference/calendar/libedata-cal/tmpl/e-cal-backend.sgml
@@ -33,6 +33,11 @@ Base class for calendar/tasks backend implementations.
@ecalbackend: the object which received the signal.
+<!-- ##### ARG ECalBackend:cache-dir ##### -->
+<para>
+
+</para>
+
<!-- ##### ARG ECalBackend:kind ##### -->
<para>
@@ -75,6 +80,24 @@ Base class for calendar/tasks backend implementations.
@Returns:
+<!-- ##### FUNCTION e_cal_backend_get_cache_dir ##### -->
+<para>
+
+</para>
+
+ backend:
+ Returns:
+
+
+<!-- ##### FUNCTION e_cal_backend_set_cache_dir ##### -->
+<para>
+
+</para>
+
+ backend:
+ cache_dir:
+
+
<!-- ##### FUNCTION e_cal_backend_add_client ##### -->
<para>
@@ -375,17 +398,6 @@ Base class for calendar/tasks backend implementations.
@object:
-<!-- ##### FUNCTION e_cal_backend_set_default_timezone ##### -->
-<para>
-
-</para>
-
- backend:
- cal:
- context:
- tzid:
-
-
<!-- ##### FUNCTION e_cal_backend_set_default_zone ##### -->
<para>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]