[evolution-data-server] EDataCal: Add a getCacheDir() D-Bus method.



commit 49eaa525866ae480ab5706446ef5fe26a79d1a9d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Jul 20 17:26:45 2010 -0400

    EDataCal: Add a getCacheDir() D-Bus method.
    
    ECal calls getCacheDir() to find the local attachment store.  ECal
    caches the result, so getCacheDir() is only called once per instance.

 calendar/libecal/e-cal.c             |   68 +++++----------------------------
 calendar/libedata-cal/e-data-cal.c   |   11 +++++
 calendar/libedata-cal/e-data-cal.xml |    8 +++-
 3 files changed, 29 insertions(+), 58 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 195095f..48344bc 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -765,69 +765,23 @@ backend_error_cb (DBusGProxy *proxy, const gchar *message, ECal *ecal)
 	g_idle_add (backend_error_idle_cb, error_data);
 }
 
-/* TODO - For now, the policy of where each backend serializes its
- * attachment data is hardcoded below. Should this end up as a
- * gconf key set during the account creation  and fetched
- * from eds???
- */
 static void
 set_local_attachment_store (ECal *ecal)
 {
-	ECalPrivate *priv;
-	const gchar *user_cache_dir;
-	gchar *mangled_uri;
-
-	user_cache_dir = e_get_user_cache_dir ();
+	gchar *cache_dir = NULL;
+	GError *error = NULL;
 
-	priv = ecal->priv;
+	LOCK_CONN ();
+	org_gnome_evolution_dataserver_calendar_Cal_get_cache_dir (
+		ecal->priv->proxy, &cache_dir, &error);
+	UNLOCK_CONN ();
 
-	/* Mangle the URI to not contain invalid characters. */
-	mangled_uri = g_strdelimit (g_strdup (priv->uri), ":/", '_');
-
-	/* The file backend uses its uri as the attachment store. */
-	if (g_str_has_prefix (priv->uri, "file://")) {
-		priv->local_attachment_store = g_strdup (priv->uri);
-	} else if (g_str_has_prefix (priv->uri, "groupwise://")) {
-		gchar *filename = g_build_filename (
-			user_cache_dir, "calendar", mangled_uri, NULL);
-		priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
-	} else if (g_str_has_prefix (priv->uri, "exchange://")) {
-		gchar *filename = g_build_filename (g_get_home_dir (),
-						    ".evolution/exchange",
-						    mangled_uri,
-						    NULL);
-		priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
-	} else if (g_str_has_prefix (priv->uri, "scalix://")) {
-		gchar *filename = g_build_filename (
-			user_cache_dir, "scalix", mangled_uri, "attach", NULL);
-                priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
-        } else if (g_str_has_prefix (priv->uri, "google://")) {
-		gchar *filename = g_build_filename (
-			user_cache_dir, "calendar", mangled_uri, NULL);
-		priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
-	} else if (g_str_has_prefix (priv->uri, "mapi://")) {
-		gchar *filename = g_build_filename (
-			user_cache_dir, "calendar", mangled_uri, NULL);
-		priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
-	} else if (g_str_has_prefix (priv->uri, "caldav://")) {
-		gchar *filename = g_build_filename (
-			user_cache_dir, "calendar", mangled_uri, NULL);
-		priv->local_attachment_store =
-			g_filename_to_uri (filename, NULL, NULL);
-		g_free (filename);
+	if (error == NULL)
+		ecal->priv->local_attachment_store = cache_dir;
+	else {
+		g_warning ("%s", error->message);
+		g_error_free (error);
 	}
-
-	g_free (mangled_uri);
 }
 
 /**
diff --git a/calendar/libedata-cal/e-data-cal.c b/calendar/libedata-cal/e-data-cal.c
index b3633ea..5c72e9d 100644
--- a/calendar/libedata-cal/e-data-cal.c
+++ b/calendar/libedata-cal/e-data-cal.c
@@ -41,6 +41,7 @@ DBusGConnection *connection;
 
 /* DBus glue */
 static void impl_Cal_get_uri (EDataCal *cal, DBusGMethodInvocation *context);
+static void impl_Cal_getCacheDir (EDataCal *cal, DBusGMethodInvocation *context);
 static void impl_Cal_open (EDataCal *cal, gboolean only_if_exists, gchar *username, gchar *password, DBusGMethodInvocation *context);
 static gboolean impl_Cal_close (EDataCal *cal, GError **error);
 static void impl_Cal_refresh (EDataCal *cal, DBusGMethodInvocation *context);
@@ -280,6 +281,16 @@ impl_Cal_get_uri (EDataCal *cal, DBusGMethodInvocation *context)
 	dbus_g_method_return (context, g_strdup (e_cal_backend_get_uri (cal->priv->backend)));
 }
 
+/* EDataCal::getCacheDir method */
+static void
+impl_Cal_getCacheDir (EDataCal *cal, DBusGMethodInvocation *context)
+{
+	const gchar *cache_dir;
+
+	cache_dir = e_cal_backend_get_cache_dir (cal->priv->backend);
+	dbus_g_method_return (context, g_strdup (cache_dir));
+}
+
 /* EDataCal::open method */
 static void
 impl_Cal_open (EDataCal *cal,
diff --git a/calendar/libedata-cal/e-data-cal.xml b/calendar/libedata-cal/e-data-cal.xml
index d2f5087..8076710 100644
--- a/calendar/libedata-cal/e-data-cal.xml
+++ b/calendar/libedata-cal/e-data-cal.xml
@@ -23,7 +23,13 @@
 			<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
 			<arg name="str_uri_copy" type="s" direction="out"/>
 		</method>
-		
+
+		<method name="getCacheDir">
+			<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_Cal_getCacheDir"/>
+			<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+			<arg name="dirname" type="s" direction="out"/>
+		</method>
+
 		<method name="open">
 			<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_Cal_open"/>
 			<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>



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