[evolution-data-server] Broke a few things with the local source URI change
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Broke a few things with the local source URI change
- Date: Fri, 16 Jul 2010 01:02:08 +0000 (UTC)
commit aae7f249849737efdf4de82793953c1ff4b2c16d
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Jul 15 17:58:51 2010 -0400
Broke a few things with the local source URI change
ECalBackendFileFactory:
- The factory's get_protocol() method returns "local" now.
- uri_to_path() needs to actually build the path to its ICS file
now instead of just converting the backend's URI to a filename.
EBookBackendFileFactory:
- Similar fixes.
.../backends/file/e-book-backend-file-factory.c | 61 +++++++++++++++--
addressbook/backends/file/e-book-backend-file.c | 26 +++++--
.../backends/file/e-cal-backend-file-factory.c | 2 +-
calendar/backends/file/e-cal-backend-file.c | 70 +++++++++++--------
4 files changed, 113 insertions(+), 46 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file-factory.c b/addressbook/backends/file/e-book-backend-file-factory.c
index af1c8a3..05898d5 100644
--- a/addressbook/backends/file/e-book-backend-file-factory.c
+++ b/addressbook/backends/file/e-book-backend-file-factory.c
@@ -31,25 +31,72 @@
#include "libedata-book/e-book-backend-factory.h"
#include "e-book-backend-file.h"
-E_BOOK_BACKEND_FACTORY_SIMPLE (file, File, e_book_backend_file_new)
+typedef struct _EBookBackendFileFactory EBookBackendFileFactory;
+typedef struct _EBookBackendFileFactoryClass EBookBackendFileFactoryClass;
-static GType file_type;
+struct _EBookBackendFileFactory {
+ EBookBackendFactory parent;
+};
+
+struct _EBookBackendFileFactoryClass {
+ EBookBackendFactoryClass parent_class;
+};
+
+GType e_book_backend_file_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+ EBookBackendFileFactory,
+ e_book_backend_file_factory,
+ E_TYPE_BOOK_BACKEND_FACTORY)
+
+static const gchar *
+book_backend_file_factory_get_protocol (EBookBackendFactory *factory)
+{
+ return "local";
+}
+
+static EBookBackend *
+book_backend_file_factory_new_backend (EBookBackendFactory *factory)
+{
+ return e_book_backend_file_new ();
+}
+
+static void
+e_book_backend_file_factory_class_init (EBookBackendFileFactoryClass *class)
+{
+ EBookBackendFactoryClass *factory_class;
+
+ factory_class = E_BOOK_BACKEND_FACTORY_CLASS (class);
+ factory_class->get_protocol = book_backend_file_factory_get_protocol;
+ factory_class->new_backend = book_backend_file_factory_new_backend;
+}
+
+static void
+e_book_backend_file_factory_class_finalize (EBookBackendFileFactoryClass *class)
+{
+}
+
+static void
+e_book_backend_file_factory_init (EBookBackendFileFactory *factory)
+{
+}
void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
{
- file_type = _file_factory_get_type (module);
+ e_book_backend_file_factory_register_type (type_module);
}
void
-eds_module_shutdown (void)
+eds_module_shutdown (void)
{
}
void
-eds_module_list_types (const GType **types, gint *num_types)
+eds_module_list_types (const GType **types,
+ gint *num_types)
{
- *types = & file_type;
+ *types = &e_book_backend_file_factory_type_id;
*num_types = 1;
}
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 270f057..d7e1447 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -874,11 +874,25 @@ e_book_backend_file_get_changes (EBookBackendSync *backend,
}
static gchar *
-e_book_backend_file_extract_path_from_uri (const gchar *uri)
+e_book_backend_file_extract_path_from_source (ESource *source)
{
- g_assert (g_ascii_strncasecmp (uri, "file://", 7) == 0);
+ const gchar *user_data_dir;
+ const gchar *relative_uri;
+ gchar *mangled_uri;
+ gchar *filename;
- return g_filename_from_uri (uri, NULL, NULL);
+ user_data_dir = e_get_user_data_dir ();
+ relative_uri = e_source_peek_relative_uri (source);
+
+ /* Mangle the URI to not contain invalid characters. */
+ mangled_uri = g_strdelimit (g_strdup (relative_uri), ":/", '_');
+
+ filename = g_build_filename (
+ user_data_dir, "addressbook", "local", mangled_uri, NULL);
+
+ g_free (mangled_uri);
+
+ return filename;
}
static void
@@ -1091,13 +1105,9 @@ e_book_backend_file_load_source (EBookBackend *backend,
DB_ENV *env;
time_t db_mtime;
struct stat sb;
- gchar *uri;
-
- uri = e_source_get_uri (source);
- dirname = e_book_backend_file_extract_path_from_uri (uri);
+ dirname = e_book_backend_file_extract_path_from_source (source);
filename = g_build_filename (dirname, "addressbook.db", NULL);
- g_free (uri);
db_error = e_db3_utils_maybe_recover (filename);
if (db_error != 0) {
diff --git a/calendar/backends/file/e-cal-backend-file-factory.c b/calendar/backends/file/e-cal-backend-file-factory.c
index 5182340..00fbe4f 100644
--- a/calendar/backends/file/e-cal-backend-file-factory.c
+++ b/calendar/backends/file/e-cal-backend-file-factory.c
@@ -34,7 +34,7 @@ e_cal_backend_file_factory_instance_init (ECalBackendFileFactory *factory)
static const gchar *
_get_protocol (ECalBackendFactory *factory)
{
- return "file";
+ return "local";
}
static ECalBackend*
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index b5e0035..3beac47 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -675,51 +675,61 @@ uri_to_path (ECalBackend *backend)
ECalBackendFile *cbfile;
ECalBackendFilePrivate *priv;
ESource *source;
- const gchar *master_uri;
- gchar *full_uri, *str_uri;
- GFile *file = NULL;
+ gchar *filename;
cbfile = E_CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
source = e_cal_backend_get_source (backend);
if (source && e_source_get_property (source, "custom-file")) {
- /* customr-uri is with a filename already */
- master_uri = e_source_get_property (source, "custom-file");
- file = g_file_new_for_path (master_uri);
- if (!file)
- return NULL;
- }
-
- if (!file) {
- master_uri = e_cal_backend_get_uri (backend);
+ const gchar *property;
- /* FIXME Check the error conditions a little more elegantly here */
- if (g_strrstr ("tasks.ics", master_uri) || g_strrstr ("calendar.ics", master_uri)) {
- g_warning (G_STRLOC ": Existing file name %s", master_uri);
-
- return NULL;
- }
-
- full_uri = g_strdup_printf ("%s/%s", master_uri, priv->file_name);
- file = g_file_new_for_uri (full_uri);
- g_free (full_uri);
+ /* custom-uri is with a filename already */
+ property = e_source_get_property (source, "custom-file");
+ filename = g_strdup (property);
}
- if (!file)
- return NULL;
+ if (filename != NULL) {
+ icalcomponent_kind kind;
+ const gchar *user_data_dir;
+ const gchar *source_type_dir;
+ const gchar *relative_uri;
+ gchar *mangled_uri;
+
+ user_data_dir = e_get_user_data_dir ();
+ kind = e_cal_backend_get_kind (backend);
+ relative_uri = e_source_peek_relative_uri (source);
+
+ switch (kind) {
+ case ICAL_VEVENT_COMPONENT:
+ source_type_dir = "calendar";
+ break;
+ case ICAL_VTODO_COMPONENT:
+ source_type_dir = "tasks";
+ break;
+ case ICAL_VJOURNAL_COMPONENT:
+ source_type_dir = "memos";
+ break;
+ default:
+ g_return_val_if_reached (NULL);
+ }
- str_uri = g_file_get_path (file);
+ /* Mangle the URI to not contain invalid characters. */
+ mangled_uri = g_strdelimit (g_strdup (relative_uri), ":/", '_');
- g_object_unref (file);
+ filename = g_build_filename (
+ user_data_dir, source_type_dir, "local",
+ mangled_uri, priv->file_name, NULL);
- if (!str_uri || !*str_uri) {
- g_free (str_uri);
+ g_free (mangled_uri);
+ }
- return NULL;
+ if (filename != NULL && *filename == '\0') {
+ g_free (filename);
+ filename = NULL;
}
- return str_uri;
+ return filename;
}
static gpointer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]