[evolution-data-server/account-mgmt: 17/28] Add an ESource extension for the file backend.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 17/28] Add an ESource extension for the file backend.
- Date: Wed, 2 Mar 2011 03:46:27 +0000 (UTC)
commit a346a89a198be8636eef21035cc323ef68172ce2
Author: Matthew Barnes <mbarnes redhat com>
Date: Sat Nov 20 17:15:39 2010 -0500
Add an ESource extension for the file backend.
calendar/backends/file/Makefile.am | 9 +-
.../backends/file/e-cal-backend-file-factory.c | 216 +++++++---------
calendar/backends/file/e-cal-backend-file.c | 277 ++++++++++---------
calendar/backends/file/e-source-local.c | 165 ++++++++++++
calendar/backends/file/e-source-local.h | 68 +++++
5 files changed, 483 insertions(+), 252 deletions(-)
---
diff --git a/calendar/backends/file/Makefile.am b/calendar/backends/file/Makefile.am
index fe79080..952d60e 100644
--- a/calendar/backends/file/Makefile.am
+++ b/calendar/backends/file/Makefile.am
@@ -21,7 +21,9 @@ libecalbackendfile_la_SOURCES = \
e-cal-backend-file-todos.c \
e-cal-backend-file-todos.h \
e-cal-backend-file.c \
- e-cal-backend-file.h
+ e-cal-backend-file.h \
+ e-source-local.c \
+ e-source-local.h
libecalbackendfile_la_LIBADD = \
$(top_builddir)/calendar/libecal/libecal-1.2.la \
@@ -32,7 +34,10 @@ libecalbackendfile_la_LIBADD = \
libecalbackendfile_la_LDFLAGS = \
-module -avoid-version $(NO_UNDEFINED)
-test_interval_searches_SOURCES = e-cal-backend-file.c
+test_interval_searches_SOURCES = \
+ e-cal-backend-file.c \
+ e-source-local.c \
+ e-source-local.h
test_interval_searches_LDADD = \
$(top_builddir)/calendar/libecal/libecal-1.2.la \
diff --git a/calendar/backends/file/e-cal-backend-file-factory.c b/calendar/backends/file/e-cal-backend-file-factory.c
index 00fbe4f..c53a364 100644
--- a/calendar/backends/file/e-cal-backend-file-factory.c
+++ b/calendar/backends/file/e-cal-backend-file-factory.c
@@ -17,19 +17,36 @@
#include "e-cal-backend-file-events.h"
#include "e-cal-backend-file-journal.h"
#include "e-cal-backend-file-todos.h"
+#include "e-source-local.h"
-typedef struct {
- ECalBackendFactory parent_object;
-} ECalBackendFileFactory;
+typedef ECalBackendFactory ECalBackendFileEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendFileEventsFactoryClass;
-typedef struct {
- ECalBackendFactoryClass parent_class;
-} ECalBackendFileFactoryClass;
+typedef ECalBackendFactory ECalBackendFileJournalFactory;
+typedef ECalBackendFactoryClass ECalBackendFileJournalFactoryClass;
-static void
-e_cal_backend_file_factory_instance_init (ECalBackendFileFactory *factory)
-{
-}
+typedef ECalBackendFactory ECalBackendFileTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendFileTodosFactoryClass;
+
+/* Forward Declarations */
+GType e_cal_backend_file_events_factory_get_type (void);
+GType e_cal_backend_file_journal_factory_get_type (void);
+GType e_cal_backend_file_todos_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendFileEventsFactory,
+ e_cal_backend_file_events_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendFileJournalFactory,
+ e_cal_backend_file_journal_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+ ECalBackendFileTodosFactory,
+ e_cal_backend_file_todos_factory,
+ E_TYPE_CAL_BACKEND_FACTORY)
static const gchar *
_get_protocol (ECalBackendFactory *factory)
@@ -37,28 +54,20 @@ _get_protocol (ECalBackendFactory *factory)
return "local";
}
-static ECalBackend*
-_todos_new_backend (ECalBackendFactory *factory, ESource *source)
-{
- return g_object_new (e_cal_backend_file_todos_get_type (),
- "source", source,
- "kind", ICAL_VTODO_COMPONENT,
- NULL);
-}
-
static icalcomponent_kind
-_todos_get_kind (ECalBackendFactory *factory)
+_events_get_kind (ECalBackendFactory *factory)
{
- return ICAL_VTODO_COMPONENT;
+ return ICAL_VEVENT_COMPONENT;
}
-static ECalBackend*
-_journal_new_backend (ECalBackendFactory *factory, ESource *source)
+static ECalBackend *
+_events_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- return g_object_new (e_cal_backend_file_journal_get_type (),
- "source", source,
- "kind", ICAL_VJOURNAL_COMPONENT,
- NULL);
+ return g_object_new (
+ e_cal_backend_file_events_get_type (),
+ "kind", ICAL_VEVENT_COMPONENT,
+ "source", source, NULL);
}
static icalcomponent_kind
@@ -67,130 +76,93 @@ _journal_get_kind (ECalBackendFactory *factory)
return ICAL_VJOURNAL_COMPONENT;
}
-static ECalBackend*
-_events_new_backend (ECalBackendFactory *factory, ESource *source)
+static ECalBackend *
+_journal_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- return g_object_new (e_cal_backend_file_events_get_type (),
- "source", source,
- "kind", ICAL_VEVENT_COMPONENT,
- NULL);
+ return g_object_new (
+ e_cal_backend_file_journal_get_type (),
+ "kind", ICAL_VJOURNAL_COMPONENT,
+ "source", source, NULL);
}
static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
+_todos_get_kind (ECalBackendFactory *factory)
{
- return ICAL_VEVENT_COMPONENT;
+ return ICAL_VTODO_COMPONENT;
}
-static void
-todos_backend_factory_class_init (ECalBackendFileFactoryClass *klass)
+static ECalBackend *
+_todos_new_backend (ECalBackendFactory *factory,
+ ESource *source)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _todos_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _todos_new_backend;
+ return g_object_new (
+ e_cal_backend_file_todos_get_type (),
+ "kind", ICAL_VTODO_COMPONENT,
+ "source", source, NULL);
}
static void
-journal_backend_factory_class_init (ECalBackendFileFactoryClass *klass)
+e_cal_backend_file_events_factory_class_init (ECalBackendFactoryClass *class)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _journal_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _journal_new_backend;
+ class->get_protocol = _get_protocol;
+ class->get_kind = _events_get_kind;
+ class->new_backend = _events_new_backend;
}
static void
-events_backend_factory_class_init (ECalBackendFileFactoryClass *klass)
+e_cal_backend_file_events_factory_class_finalize (ECalBackendFactoryClass *class)
{
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind = _events_get_kind;
- E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _events_new_backend;
}
-static GType
-events_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_file_events_factory_init (ECalBackendFactory *factory)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendFileFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) events_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_file_factory_instance_init
- };
-
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendFileEventsFactory",
- &info, 0);
-
- return type;
}
-static GType
-journal_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_file_journal_factory_class_init (ECalBackendFactoryClass *class)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendFileFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) journal_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_file_factory_instance_init
- };
-
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendFileJournalFactory",
- &info, 0);
-
- return type;
+ class->get_protocol = _get_protocol;
+ class->get_kind = _journal_get_kind;
+ class->new_backend = _journal_new_backend;
}
-static GType
-todos_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_file_journal_factory_class_finalize (ECalBackendFactoryClass *class)
{
- GType type;
-
- GTypeInfo info = {
- sizeof (ECalBackendFileFactoryClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) todos_backend_factory_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (ECalBackend),
- 0, /* n_preallocs */
- (GInstanceInitFunc) e_cal_backend_file_factory_instance_init
- };
+}
- type = g_type_module_register_type (module,
- E_TYPE_CAL_BACKEND_FACTORY,
- "ECalBackendFileTodosFactory",
- &info, 0);
+static void
+e_cal_backend_file_journal_factory_init (ECalBackendFactory *factory)
+{
+}
- return type;
+static void
+e_cal_backend_file_todos_factory_class_init (ECalBackendFactoryClass *class)
+{
+ class->get_protocol = _get_protocol;
+ class->get_kind = _todos_get_kind;
+ class->new_backend = _todos_new_backend;
}
-
+static void
+e_cal_backend_file_todos_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
-static GType file_types[3];
+static void
+e_cal_backend_file_todos_factory_init (ECalBackendFactory *factory)
+{
+}
void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
{
- file_types[0] = todos_backend_factory_get_type (module);
- file_types[1] = events_backend_factory_get_type (module);
- file_types[2] = journal_backend_factory_get_type (module);
+ e_source_local_type_register (type_module);
+ e_cal_backend_file_events_factory_register_type (type_module);
+ e_cal_backend_file_journal_factory_register_type (type_module);
+ e_cal_backend_file_todos_factory_register_type (type_module);
}
void
@@ -201,6 +173,12 @@ eds_module_shutdown (void)
void
eds_module_list_types (const GType **types, gint *num_types)
{
+ static GType file_types[3];
+
+ file_types[0] = e_cal_backend_file_events_factory_get_type ();
+ file_types[1] = e_cal_backend_file_journal_factory_get_type ();
+ file_types[2] = e_cal_backend_file_todos_factory_get_type ();
+
*types = file_types;
- *num_types = 3;
+ *num_types = G_N_ELEMENTS (file_types);
}
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 7aff3f6..3aea20f 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -40,10 +40,12 @@
#include <libecal/e-cal-time-util.h>
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-check-timezones.h>
+#include <libecal/e-source-calendar.h>
#include <libedata-cal/e-cal-backend-util.h>
#include <libedata-cal/e-cal-backend-sexp.h>
#include <libedata-cal/e-cal-backend-intervaltree.h>
#include "e-cal-backend-file-events.h"
+#include "e-source-local.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -97,9 +99,6 @@ struct _ECalBackendFilePrivate {
floating DATE-TIME values. */
icaltimezone *default_zone;
- /* a custom filename opened */
- gchar *custom_file;
-
/* guards refresh members */
GMutex *refresh_lock;
/* set to TRUE to indicate thread should stop */
@@ -111,11 +110,7 @@ struct _ECalBackendFilePrivate {
/* increased when backend saves the file */
guint refresh_skip;
- /* Monitor for a refresh type "1" */
GFileMonitor *refresh_monitor;
-
- /* timeour id for refresh type "2" */
- guint refresh_timeout_id;
};
@@ -152,6 +147,32 @@ free_object_data (gpointer data)
g_free (obj_data);
}
+static gboolean
+source_is_writable (ECalBackend *backend,
+ ESource *source)
+{
+ ESourceSelectable *extension;
+ const gchar *extension_name;
+
+ switch (e_cal_backend_get_kind (backend)) {
+ case ICAL_VEVENT_COMPONENT:
+ extension_name = E_SOURCE_EXTENSION_CALENDAR;
+ break;
+ case ICAL_VTODO_COMPONENT:
+ extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+ break;
+ case ICAL_VJOURNAL_COMPONENT:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ break;
+ default:
+ g_return_val_if_reached (FALSE);
+ }
+
+ extension = e_source_get_extension (source, extension_name);
+
+ return e_source_selectable_get_writable_hint (extension);
+}
+
/* Saves the calendar data */
static gboolean
save_file_when_idle (gpointer user_data)
@@ -368,9 +389,6 @@ e_cal_backend_file_finalize (GObject *object)
priv->path = NULL;
}
- g_free (priv->custom_file);
- priv->custom_file = NULL;
-
if (priv->default_zone && priv->default_zone != icaltimezone_get_utc_timezone ()) {
icaltimezone_free (priv->default_zone, 1);
}
@@ -751,6 +769,9 @@ uri_to_path (ECalBackend *backend)
ECalBackendFile *cbfile;
ECalBackendFilePrivate *priv;
ESource *source;
+ ESourceLocal *local_extension;
+ GFile *custom_file;
+ const gchar *extension_name;
const gchar *cache_dir;
gchar *filename = NULL;
@@ -760,13 +781,13 @@ uri_to_path (ECalBackend *backend)
cache_dir = e_cal_backend_get_cache_dir (backend);
source = e_cal_backend_get_source (backend);
- if (source && e_source_get_property (source, "custom-file")) {
- const gchar *property;
- /* custom-uri is with a filename already */
- property = e_source_get_property (source, "custom-file");
- filename = g_strdup (property);
- }
+ extension_name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
+ local_extension = e_source_get_extension (source, extension_name);
+
+ custom_file = e_source_local_get_custom_file (local_extension);
+ if (custom_file != NULL)
+ filename = g_file_get_path (custom_file);
if (filename == NULL)
filename = g_build_filename (cache_dir, priv->file_name, NULL);
@@ -784,18 +805,31 @@ refresh_thread_func (gpointer data)
{
ECalBackendFile *cbfile = data;
ECalBackendFilePrivate *priv;
- GFile *file;
+ ESource *source;
+ ESourceLocal *extension;
GFileInfo *info;
+ GFile *file;
+ const gchar *extension_name;
guint64 last_modified, modified;
g_return_val_if_fail (cbfile != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_BACKEND_FILE (cbfile), NULL);
priv = cbfile->priv;
- g_return_val_if_fail (priv->custom_file != NULL, NULL);
- file = g_file_new_for_path (priv->custom_file);
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ extension_name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
+ source = e_cal_backend_get_source (E_CAL_BACKEND (cbfile));
+ extension = e_source_get_extension (source, extension_name);
+
+ file = e_source_local_get_custom_file (extension);
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ /* Keep the GFile alive until we exit. */
+ g_object_ref (file);
+
+ info = g_file_query_info (
+ file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
g_return_val_if_fail (info != NULL, NULL);
last_modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
@@ -845,19 +879,6 @@ refresh_thread_func (gpointer data)
return NULL;
}
-static gboolean
-check_refresh_calendar_timeout (ECalBackendFilePrivate *priv)
-{
- g_return_val_if_fail (priv != NULL, FALSE);
-
- /* called in the main thread */
- if (priv->refresh_cond)
- g_cond_signal (priv->refresh_cond);
-
- /* call it next time again */
- return TRUE;
-}
-
static void
custom_file_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, ECalBackendFilePrivate *priv)
{
@@ -870,7 +891,9 @@ prepare_refresh_data (ECalBackendFile *cbfile)
{
ECalBackendFilePrivate *priv;
ESource *source;
- const gchar *value;
+ ESourceLocal *local_extension;
+ GFile *custom_file;
+ const gchar *extension_name;
g_return_if_fail (cbfile != NULL);
@@ -882,32 +905,29 @@ prepare_refresh_data (ECalBackendFile *cbfile)
priv->refresh_skip = 0;
source = e_cal_backend_get_source (E_CAL_BACKEND (cbfile));
- value = e_source_get_property (source, "refresh-type");
- if (e_source_get_property (source, "custom-file") && value && *value && !value[1]) {
- GFile *file;
+
+ extension_name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
+ local_extension = e_source_get_extension (source, extension_name);
+
+ custom_file = e_source_local_get_custom_file (local_extension);
+
+ if (custom_file != NULL) {
GError *error = NULL;
- switch (*value) {
- case '1': /* on file change */
- file = g_file_new_for_path (priv->custom_file);
- priv->refresh_monitor = g_file_monitor_file (file, G_FILE_MONITOR_WATCH_MOUNTS, NULL, &error);
- if (file)
- g_object_unref (file);
- if (priv->refresh_monitor)
- g_signal_connect (G_OBJECT (priv->refresh_monitor), "changed", G_CALLBACK (custom_file_changed), priv);
- break;
- case '2': /* on refresh timeout */
- value = e_source_get_property (source, "refresh");
- if (value && atoi (value) > 0) {
- priv->refresh_timeout_id = g_timeout_add_seconds (60 * atoi (value), (GSourceFunc) check_refresh_calendar_timeout, priv);
- }
- break;
- default:
- break;
+ priv->refresh_monitor = g_file_monitor_file (
+ custom_file, G_FILE_MONITOR_WATCH_MOUNTS, NULL, &error);
+
+ if (error == NULL) {
+ g_signal_connect (
+ priv->refresh_monitor, "changed",
+ G_CALLBACK (custom_file_changed), priv);
+ } else {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
}
- if (priv->refresh_monitor || priv->refresh_timeout_id) {
+ if (priv->refresh_monitor) {
priv->refresh_cond = g_cond_new ();
priv->refresh_gone_cond = g_cond_new ();
@@ -933,10 +953,6 @@ free_refresh_data (ECalBackendFile *cbfile)
g_object_unref (priv->refresh_monitor);
priv->refresh_monitor = NULL;
- if (priv->refresh_timeout_id)
- g_source_remove (priv->refresh_timeout_id);
- priv->refresh_timeout_id = 0;
-
if (priv->refresh_cond) {
priv->refresh_thread_stop = TRUE;
g_cond_signal (priv->refresh_cond);
@@ -983,8 +999,6 @@ open_cal (ECalBackendFile *cbfile, const gchar *uristr, GError **perror)
priv->icalcomp = icalcomp;
priv->path = uri_to_path (E_CAL_BACKEND (cbfile));
- g_free (priv->custom_file);
- priv->custom_file = g_strdup (uristr);
priv->comp_uid_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_object_data);
priv->interval_tree = e_intervaltree_new ();
@@ -1180,8 +1194,6 @@ create_cal (ECalBackendFile *cbfile, const gchar *uristr, GError **perror)
save (cbfile);
- g_free (priv->custom_file);
- priv->custom_file = g_strdup (uristr);
prepare_refresh_data (cbfile);
}
@@ -1298,37 +1310,41 @@ add_timezone (icalcomponent *icalcomp, icaltimezone *tzone)
static void
source_changed_cb (ESource *source, ECalBackend *backend)
{
- const gchar *value;
+ ECalBackendFile *cbfile;
+ ESourceLocal *extension;
+ const gchar *extension_name;
+ GFile *custom_file;
+ gboolean writable;
+ gboolean read_only;
g_return_if_fail (source != NULL);
- g_return_if_fail (backend != NULL);
g_return_if_fail (E_IS_CAL_BACKEND (backend));
- value = e_source_get_property (source, "custom-file");
- if (value && *value) {
- ECalBackendFile *cbfile;
- gboolean forced_readonly;
+ cbfile = E_CAL_BACKEND_FILE (backend);
- cbfile = E_CAL_BACKEND_FILE (backend);
- g_return_if_fail (cbfile != NULL);
+ extension_name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
+ extension = e_source_get_extension (source, extension_name);
- value = e_source_get_property (source, "custom-file-readonly");
- forced_readonly = value && g_str_equal (value, "1");
+ custom_file = e_source_local_get_custom_file (extension);
+ if (custom_file == NULL)
+ return;
- if ((forced_readonly != FALSE) != (cbfile->priv->read_only != FALSE)) {
- cbfile->priv->read_only = forced_readonly;
- if (!forced_readonly) {
- gchar *str_uri = get_uri_string (backend);
+ writable = source_is_writable (backend, source);
+ read_only = !writable;
- g_return_if_fail (str_uri != NULL);
+ if (read_only != cbfile->priv->read_only) {
+ cbfile->priv->read_only = read_only;
+ if (writable) {
+ gchar *str_uri = get_uri_string (backend);
- cbfile->priv->read_only = g_access (str_uri, W_OK) != 0;
+ g_return_if_fail (str_uri != NULL);
- g_free (str_uri);
- }
+ cbfile->priv->read_only = g_access (str_uri, W_OK) != 0;
- e_cal_backend_notify_readonly (backend, cbfile->priv->read_only);
+ g_free (str_uri);
}
+
+ e_cal_backend_notify_readonly (backend, cbfile->priv->read_only);
}
}
@@ -1372,14 +1388,16 @@ e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
if (!err) {
if (!priv->read_only) {
- ESource *source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
+ ESource *source;
- if (source) {
- g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), backend);
+ source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
- if (e_source_get_property (source, "custom-file-readonly") && g_str_equal (e_source_get_property (source, "custom-file-readonly"), "1"))
- priv->read_only = TRUE;
- }
+ g_signal_connect (
+ source, "changed",
+ G_CALLBACK (source_changed_cb), backend);
+
+ if (!source_is_writable (E_CAL_BACKEND (backend), source))
+ priv->read_only = TRUE;
}
if (priv->default_zone && add_timezone (priv->icalcomp, priv->default_zone)) {
@@ -1396,8 +1414,22 @@ e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
g_propagate_error (perror, err);
}
-static void
-e_cal_backend_file_remove (ECalBackendSync *backend, EDataCal *cal, GError **perror)
+/* is_loaded handler for the file backend */
+static gboolean
+e_cal_backend_file_is_loaded (ECalBackend *backend)
+{
+ ECalBackendFile *cbfile;
+ ECalBackendFilePrivate *priv;
+
+ cbfile = E_CAL_BACKEND_FILE (backend);
+ priv = cbfile->priv;
+
+ return (priv->icalcomp != NULL);
+}
+
+static gboolean
+e_cal_backend_file_remove (ECalBackend *backend,
+ GError **error)
{
ECalBackendFile *cbfile;
ECalBackendFilePrivate *priv;
@@ -1405,7 +1437,8 @@ e_cal_backend_file_remove (ECalBackendSync *backend, EDataCal *cal, GError **per
gchar *full_path = NULL;
const gchar *fname;
GDir *dir = NULL;
- GError *error = NULL, *err = NULL;
+ GError *local_error = NULL;
+ GError *err = NULL;
cbfile = E_CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
@@ -1424,10 +1457,11 @@ e_cal_backend_file_remove (ECalBackendSync *backend, EDataCal *cal, GError **per
/* remove all files in the directory */
dirname = g_path_get_dirname (str_uri);
- dir = g_dir_open (dirname, 0, &error);
+ dir = g_dir_open (dirname, 0, &local_error);
if (!dir) {
- err = e_data_cal_create_error (PermissionDenied, error ? error->message : NULL);
- goto done;
+ err = e_data_cal_create_error (
+ PermissionDenied, local_error->message);
+ goto done;
}
while ((fname = g_dir_read_name (dir))) {
@@ -1456,27 +1490,15 @@ e_cal_backend_file_remove (ECalBackendSync *backend, EDataCal *cal, GError **per
g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
- /* lie here a bit, but otherwise the calendar will not be removed, even it should */
- if (err) {
- g_print (G_STRLOC ": %s", err->message);
- g_error_free (err);
- }
+ if (local_error)
+ g_error_free (local_error);
- if (error)
- g_error_free (error);
-}
-
-/* is_loaded handler for the file backend */
-static gboolean
-e_cal_backend_file_is_loaded (ECalBackend *backend)
-{
- ECalBackendFile *cbfile;
- ECalBackendFilePrivate *priv;
-
- cbfile = E_CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
+ if (err != NULL) {
+ g_propagate_error (error, err);
+ return FALSE;
+ }
- return (priv->icalcomp != NULL);
+ return TRUE;
}
/* is_remote handler for the file backend */
@@ -3211,7 +3233,6 @@ e_cal_backend_file_init (ECalBackendFile *cbfile)
priv->comp_uid_hash = NULL;
priv->comp = NULL;
priv->interval_tree = NULL;
- priv->custom_file = NULL;
priv->refresh_lock = g_mutex_new ();
/* The timezone defaults to UTC. */
@@ -3230,10 +3251,9 @@ cal_backend_file_constructed (GObject *object)
ECalBackend *backend;
ESource *source;
icalcomponent_kind kind;
- const gchar *source_dir;
const gchar *user_data_dir;
const gchar *component_type;
- gchar *mangled_source_dir;
+ const gchar *uid;
gchar *filename;
user_data_dir = e_get_user_data_dir ();
@@ -3246,6 +3266,7 @@ cal_backend_file_constructed (GObject *object)
backend = E_CAL_BACKEND (object);
kind = e_cal_backend_get_kind (backend);
source = e_cal_backend_get_source (backend);
+ uid = e_source_get_uid (source);
switch (kind) {
case ICAL_VEVENT_COMPONENT:
@@ -3263,20 +3284,9 @@ cal_backend_file_constructed (GObject *object)
break;
}
- source_dir = e_source_peek_relative_uri (source);
- if (!source_dir || !g_str_equal (source_dir, "system"))
- source_dir = e_source_peek_uid (source);
-
- /* Mangle the URI to not contain invalid characters. */
- mangled_source_dir = g_strdelimit (g_strdup (source_dir), ":/", '_');
-
- filename = g_build_filename (
- user_data_dir, component_type, mangled_source_dir, NULL);
-
+ filename = g_build_filename (user_data_dir, component_type, uid, NULL);
e_cal_backend_set_cache_dir (backend, filename);
-
g_free (filename);
- g_free (mangled_source_dir);
}
/* Class initialization function for the file backend */
@@ -3303,7 +3313,6 @@ e_cal_backend_file_class_init (ECalBackendFileClass *class)
sync_class->get_ldap_attribute_sync = e_cal_backend_file_get_ldap_attribute;
sync_class->get_static_capabilities_sync = e_cal_backend_file_get_static_capabilities;
sync_class->open_sync = e_cal_backend_file_open;
- sync_class->remove_sync = e_cal_backend_file_remove;
sync_class->create_object_sync = e_cal_backend_file_create_object;
sync_class->modify_object_sync = e_cal_backend_file_modify_object;
sync_class->remove_object_sync = e_cal_backend_file_remove_object;
@@ -3320,12 +3329,16 @@ e_cal_backend_file_class_init (ECalBackendFileClass *class)
sync_class->get_changes_sync = e_cal_backend_file_get_changes;
backend_class->is_loaded = e_cal_backend_file_is_loaded;
+ backend_class->remove = e_cal_backend_file_remove;
backend_class->start_query = e_cal_backend_file_start_query;
backend_class->get_mode = e_cal_backend_file_get_mode;
backend_class->set_mode = e_cal_backend_file_set_mode;
backend_class->internal_get_default_timezone = e_cal_backend_file_internal_get_default_timezone;
backend_class->internal_get_timezone = e_cal_backend_file_internal_get_timezone;
+
+ /* Register our ESource extension. */
+ E_TYPE_SOURCE_LOCAL;
}
void
@@ -3388,9 +3401,11 @@ e_cal_backend_file_reload (ECalBackendFile *cbfile, GError **perror)
g_free (str_uri);
if (!err && !priv->read_only) {
- ESource *source = e_cal_backend_get_source (E_CAL_BACKEND (cbfile));
+ ESource *source;
+
+ source = e_cal_backend_get_source (E_CAL_BACKEND (cbfile));
- if (source && e_source_get_property (source, "custom-file-readonly") && g_str_equal (e_source_get_property (source, "custom-file-readonly"), "1"))
+ if (!source_is_writable (E_CAL_BACKEND (cbfile), source))
priv->read_only = TRUE;
}
done:
diff --git a/calendar/backends/file/e-source-local.c b/calendar/backends/file/e-source-local.c
new file mode 100644
index 0000000..596ed69
--- /dev/null
+++ b/calendar/backends/file/e-source-local.c
@@ -0,0 +1,165 @@
+/*
+ * e-source-local.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-local.h"
+
+#define E_SOURCE_LOCAL_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SOURCE_LOCAL, ESourceLocalPrivate))
+
+struct _ESourceLocalPrivate {
+ GFile *custom_file;
+};
+
+enum {
+ PROP_0,
+ PROP_CUSTOM_FILE
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+ ESourceLocal,
+ e_source_local,
+ E_TYPE_SOURCE_EXTENSION)
+
+static void
+source_local_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CUSTOM_FILE:
+ e_source_local_set_custom_file (
+ E_SOURCE_LOCAL (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_local_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CUSTOM_FILE:
+ g_value_set_object (
+ value,
+ e_source_local_get_custom_file (
+ E_SOURCE_LOCAL (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_local_dispose (GObject *object)
+{
+ ESourceLocalPrivate *priv;
+
+ priv = E_SOURCE_LOCAL_GET_PRIVATE (object);
+
+ if (priv->custom_file != NULL) {
+ g_object_unref (priv->custom_file);
+ priv->custom_file = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_source_local_parent_class)->dispose (object);
+}
+
+static void
+e_source_local_class_init (ESourceLocalClass *class)
+{
+ GObjectClass *object_class;
+ ESourceExtensionClass *extension_class;
+
+ g_type_class_add_private (class, sizeof (ESourceLocalPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = source_local_set_property;
+ object_class->get_property = source_local_get_property;
+ object_class->dispose = source_local_dispose;
+
+ extension_class = E_SOURCE_EXTENSION_CLASS (class);
+ extension_class->name = E_SOURCE_EXTENSION_LOCAL_BACKEND;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CUSTOM_FILE,
+ g_param_spec_object (
+ "custom-file",
+ "Custom File",
+ "Custom iCalendar file",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ E_SOURCE_PARAM_SETTING));
+}
+
+static void
+e_source_local_class_finalize (ESourceLocalClass *class)
+{
+}
+
+static void
+e_source_local_init (ESourceLocal *extension)
+{
+ extension->priv = E_SOURCE_LOCAL_GET_PRIVATE (extension);
+}
+
+void
+e_source_local_type_register (GTypeModule *type_module)
+{
+ /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+ * function, so we have to wrap it with a public function in
+ * order to register types from a separate compilation unit. */
+ e_source_local_register_type (type_module);
+}
+
+GFile *
+e_source_local_get_custom_file (ESourceLocal *extension)
+{
+ g_return_val_if_fail (E_IS_SOURCE_LOCAL (extension), NULL);
+
+ return extension->priv->custom_file;
+}
+
+void
+e_source_local_set_custom_file (ESourceLocal *extension,
+ GFile *custom_file)
+{
+ g_return_if_fail (E_IS_SOURCE_LOCAL (extension));
+
+ if (custom_file != NULL) {
+ g_return_if_fail (G_IS_FILE (custom_file));
+ g_object_ref (custom_file);
+ }
+
+ if (extension->priv->custom_file != NULL)
+ g_object_unref (extension->priv->custom_file);
+
+ extension->priv->custom_file = custom_file;
+
+ g_object_notify (G_OBJECT (extension), "custom-file");
+}
+
diff --git a/calendar/backends/file/e-source-local.h b/calendar/backends/file/e-source-local.h
new file mode 100644
index 0000000..74c7d88
--- /dev/null
+++ b/calendar/backends/file/e-source-local.h
@@ -0,0 +1,68 @@
+/*
+ * e-source-local.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_LOCAL_H
+#define E_SOURCE_LOCAL_H
+
+#include <libedataserver/e-source-extension.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_LOCAL \
+ (e_source_local_get_type ())
+#define E_SOURCE_LOCAL(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_SOURCE_LOCAL, ESourceLocal))
+#define E_SOURCE_LOCAL_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_SOURCE_LOCAL, ESourceLocalClass))
+#define E_IS_SOURCE_LOCAL(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_SOURCE_LOCAL))
+#define E_IS_SOURCE_LOCAL_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_SOURCE_LOCAL))
+#define E_SOURCE_LOCAL_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_SOURCE_LOCAL, ESourceLocalClass))
+
+#define E_SOURCE_EXTENSION_LOCAL_BACKEND "Local Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceLocal ESourceLocal;
+typedef struct _ESourceLocalClass ESourceLocalClass;
+typedef struct _ESourceLocalPrivate ESourceLocalPrivate;
+
+struct _ESourceLocal {
+ ESourceExtension parent;
+ ESourceLocalPrivate *priv;
+};
+
+struct _ESourceLocalClass {
+ ESourceExtensionClass parent_class;
+};
+
+GType e_source_local_get_type (void);
+void e_source_local_type_register (GTypeModule *type_module);
+GFile * e_source_local_get_custom_file (ESourceLocal *extension);
+void e_source_local_set_custom_file (ESourceLocal *extension,
+ GFile *custom_file);
+
+G_END_DECLS
+
+#endif /* E_SOURCE_LOCAL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]