[evolution-data-server] Bundle built-in data sources as a GResource.



commit 1081223c4fb744345b1f6b609f6c389962ecff06
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jan 21 18:45:07 2013 -0500

    Bundle built-in data sources as a GResource.
    
    This was primarily meant to aid our test suite, whose goal is to run
    successfully without requiring evolution-data-server (or its data files)
    to be installed.  The tests inadvertently depend on these built-in data
    sources being present.
    
    But this is good to do anyway.  Bundling the data sources directly in
    the evolution-source-registry binary guarantees they're always present,
    which the E-D-S APIs already assume, and avoids the usual problems with
    installed data files: I/O errors, user meddling, etc.

 configure.ac                                       |    1 -
 data/Makefile.am                                   |    2 -
 data/sources/Makefile.am                           |   37 ---------
 po/POTFILES.in                                     |   32 ++++----
 services/evolution-source-registry/Makefile.am     |   56 +++++++++++++-
 .../builtin}/birthdays.source.in                   |    0
 .../builtin}/caldav-stub.source.in                 |    0
 .../builtin}/contacts-stub.source.in               |    0
 .../builtin}/google-stub.source.in                 |    0
 .../builtin}/ldap-stub.source.in                   |    0
 .../builtin}/local-stub.source.in                  |    0
 .../builtin}/local.source.in                       |    0
 .../builtin}/sendmail.source.in                    |    0
 .../builtin}/system-address-book.source.in         |    0
 .../builtin}/system-calendar.source.in             |    0
 .../builtin}/system-memo-list.source.in            |    0
 .../builtin}/system-task-list.source.in            |    0
 .../builtin}/vfolder.source.in                     |    0
 .../builtin}/weather-stub.source.in                |    0
 .../builtin}/webcal-stub.source.in                 |    0
 .../builtin}/webdav-stub.source.in                 |    0
 .../evolution-source-registry-resource.xml         |   23 ++++++
 .../evolution-source-registry.c                    |   79 +++++++++++++++++++-
 23 files changed, 171 insertions(+), 59 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d36fcc..1128e30 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1616,7 +1616,6 @@ camel/tests/misc/Makefile
 camel/tests/smime/Makefile
 camel/camel.pc
 data/Makefile
-data/sources/Makefile
 libebackend/Makefile
 libebackend/libebackend.pc
 libedataserver/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 654369f..31a90ab 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,5 +1,3 @@
-SUBDIRS = sources
-
 gsettings_SCHEMAS =						\
 	org.gnome.Evolution.DefaultSources.gschema.xml		\
 	org.gnome.evolution-data-server.calendar.gschema.xml	\
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2d5a2c4..d16693c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -172,22 +172,6 @@ camel/providers/smtp/camel-smtp-provider.c
 camel/providers/smtp/camel-smtp-transport.c
 data/org.gnome.evolution-data-server.addressbook.gschema.xml.in
 data/org.gnome.evolution-data-server.calendar.gschema.xml.in
-[type: gettext/ini]data/sources/birthdays.source.in
-[type: gettext/ini]data/sources/caldav-stub.source.in
-[type: gettext/ini]data/sources/contacts-stub.source.in
-[type: gettext/ini]data/sources/google-stub.source.in
-[type: gettext/ini]data/sources/ldap-stub.source.in
-[type: gettext/ini]data/sources/local.source.in
-[type: gettext/ini]data/sources/local-stub.source.in
-[type: gettext/ini]data/sources/sendmail.source.in
-[type: gettext/ini]data/sources/system-address-book.source.in
-[type: gettext/ini]data/sources/system-calendar.source.in
-[type: gettext/ini]data/sources/system-memo-list.source.in
-[type: gettext/ini]data/sources/system-task-list.source.in
-[type: gettext/ini]data/sources/vfolder.source.in
-[type: gettext/ini]data/sources/weather-stub.source.in
-[type: gettext/ini]data/sources/webcal-stub.source.in
-[type: gettext/ini]data/sources/webdav-stub.source.in
 libebackend/e-authentication-mediator.c
 libebackend/e-authentication-session.c
 libebackend/e-backend.c
@@ -214,4 +198,20 @@ modules/trust-prompt/trust-prompt-gtk.c
 modules/yahoo-backend/module-yahoo-backend.c
 services/evolution-addressbook-factory/evolution-addressbook-factory.c
 services/evolution-calendar-factory/evolution-calendar-factory.c
+[type: gettext/ini]services/evolution-source-registry/builtin/birthdays.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/caldav-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/contacts-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/google-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/ldap-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/local.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/local-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/sendmail.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/system-address-book.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/system-calendar.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/system-memo-list.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/system-task-list.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/vfolder.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/weather-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/webcal-stub.source.in
+[type: gettext/ini]services/evolution-source-registry/builtin/webdav-stub.source.in
 services/evolution-user-prompter/prompt-user-gtk.c
diff --git a/services/evolution-source-registry/Makefile.am b/services/evolution-source-registry/Makefile.am
index e276680..3f7ba0c 100644
--- a/services/evolution-source-registry/Makefile.am
+++ b/services/evolution-source-registry/Makefile.am
@@ -1,12 +1,43 @@
 NULL =
 
+builtin_sources_in_files = \
+	builtin/caldav-stub.source.in \
+	builtin/contacts-stub.source.in \
+	builtin/google-stub.source.in \
+	builtin/ldap-stub.source.in \
+	builtin/local-stub.source.in \
+	builtin/weather-stub.source.in \
+	builtin/webcal-stub.source.in \
+	builtin/webdav-stub.source.in \
+	builtin/birthdays.source.in \
+	builtin/local.source.in \
+	builtin/sendmail.source.in \
+	builtin/system-address-book.source.in \
+	builtin/system-calendar.source.in \
+	builtin/system-memo-list.source.in \
+	builtin/system-task-list.source.in \
+	builtin/vfolder.source.in \
+	$(NULL)
+builtin_sources = $(builtin_sources_in_files:.source.in=.source)
+
+%.source: %.source.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po)
+	$(AM_V_GEN) $(MKDIR_P) builtin && LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@
+
 service_in_files = org.gnome.evolution.dataserver.Sources.service.in
 servicedir = $(datadir)/dbus-1/services
 service_DATA = $(service_in_files:.service.in=.service)
 @EVO_SUBST_SERVICE_RULE@
 
-CLEANFILES = $(service_DATA)
-EXTRA_DIST = $(service_in_files)
+CLEANFILES = \
+	$(BUILT_SOURCES) \
+	$(builtin_sources) \
+	$(service_DATA) \
+	$(NULL)
+
+EXTRA_DIST = \
+	$(builtin_sources_in_files) \
+	$(service_in_files) \
+	$(NULL)
 
 libexec_PROGRAMS = evolution-source-registry
 
@@ -24,6 +55,7 @@ evolution_source_registry_CPPFLAGS = \
 	$(NULL)
 
 evolution_source_registry_SOURCES = \
+	$(BUILT_SOURCES) \
 	evolution-source-registry.c \
 	evolution-source-registry-migrate-basedir.c \
 	evolution-source-registry-migrate-sources.c \
@@ -41,4 +73,24 @@ evolution_source_registry_LDADD = \
 	$(SOUP_LIBS) \
 	$(NULL)
 
+evolution-source-registry-resource.h: evolution-source-registry-resource.xml
+	$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) \
+	$(srcdir)/evolution-source-registry-resource.xml \
+	--target=$@ \
+	--sourcedir=$(builddir)/builtin \
+	--c-name evolution_source_registry \
+	--generate-header
+evolution-source-registry-resource.c: evolution-source-registry-resource.xml $(builtin_sources)
+	$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) \
+	$(srcdir)/evolution-source-registry-resource.xml \
+	--target=$@ \
+	--sourcedir=$(builddir)/builtin \
+	--c-name evolution_source_registry \
+	--generate-source
+
+BUILT_SOURCES = \
+	evolution-source-registry-resource.c \
+	evolution-source-registry-resource.h \
+	$(NULL)
+
 -include $(top_srcdir)/git.mk
diff --git a/data/sources/birthdays.source.in b/services/evolution-source-registry/builtin/birthdays.source.in
similarity index 100%
rename from data/sources/birthdays.source.in
rename to services/evolution-source-registry/builtin/birthdays.source.in
diff --git a/data/sources/caldav-stub.source.in b/services/evolution-source-registry/builtin/caldav-stub.source.in
similarity index 100%
rename from data/sources/caldav-stub.source.in
rename to services/evolution-source-registry/builtin/caldav-stub.source.in
diff --git a/data/sources/contacts-stub.source.in b/services/evolution-source-registry/builtin/contacts-stub.source.in
similarity index 100%
rename from data/sources/contacts-stub.source.in
rename to services/evolution-source-registry/builtin/contacts-stub.source.in
diff --git a/data/sources/google-stub.source.in b/services/evolution-source-registry/builtin/google-stub.source.in
similarity index 100%
rename from data/sources/google-stub.source.in
rename to services/evolution-source-registry/builtin/google-stub.source.in
diff --git a/data/sources/ldap-stub.source.in b/services/evolution-source-registry/builtin/ldap-stub.source.in
similarity index 100%
rename from data/sources/ldap-stub.source.in
rename to services/evolution-source-registry/builtin/ldap-stub.source.in
diff --git a/data/sources/local-stub.source.in b/services/evolution-source-registry/builtin/local-stub.source.in
similarity index 100%
rename from data/sources/local-stub.source.in
rename to services/evolution-source-registry/builtin/local-stub.source.in
diff --git a/data/sources/local.source.in b/services/evolution-source-registry/builtin/local.source.in
similarity index 100%
rename from data/sources/local.source.in
rename to services/evolution-source-registry/builtin/local.source.in
diff --git a/data/sources/sendmail.source.in b/services/evolution-source-registry/builtin/sendmail.source.in
similarity index 100%
rename from data/sources/sendmail.source.in
rename to services/evolution-source-registry/builtin/sendmail.source.in
diff --git a/data/sources/system-address-book.source.in b/services/evolution-source-registry/builtin/system-address-book.source.in
similarity index 100%
rename from data/sources/system-address-book.source.in
rename to services/evolution-source-registry/builtin/system-address-book.source.in
diff --git a/data/sources/system-calendar.source.in b/services/evolution-source-registry/builtin/system-calendar.source.in
similarity index 100%
rename from data/sources/system-calendar.source.in
rename to services/evolution-source-registry/builtin/system-calendar.source.in
diff --git a/data/sources/system-memo-list.source.in b/services/evolution-source-registry/builtin/system-memo-list.source.in
similarity index 100%
rename from data/sources/system-memo-list.source.in
rename to services/evolution-source-registry/builtin/system-memo-list.source.in
diff --git a/data/sources/system-task-list.source.in b/services/evolution-source-registry/builtin/system-task-list.source.in
similarity index 100%
rename from data/sources/system-task-list.source.in
rename to services/evolution-source-registry/builtin/system-task-list.source.in
diff --git a/data/sources/vfolder.source.in b/services/evolution-source-registry/builtin/vfolder.source.in
similarity index 100%
rename from data/sources/vfolder.source.in
rename to services/evolution-source-registry/builtin/vfolder.source.in
diff --git a/data/sources/weather-stub.source.in b/services/evolution-source-registry/builtin/weather-stub.source.in
similarity index 100%
rename from data/sources/weather-stub.source.in
rename to services/evolution-source-registry/builtin/weather-stub.source.in
diff --git a/data/sources/webcal-stub.source.in b/services/evolution-source-registry/builtin/webcal-stub.source.in
similarity index 100%
rename from data/sources/webcal-stub.source.in
rename to services/evolution-source-registry/builtin/webcal-stub.source.in
diff --git a/data/sources/webdav-stub.source.in b/services/evolution-source-registry/builtin/webdav-stub.source.in
similarity index 100%
rename from data/sources/webdav-stub.source.in
rename to services/evolution-source-registry/builtin/webdav-stub.source.in
diff --git a/services/evolution-source-registry/evolution-source-registry-resource.xml b/services/evolution-source-registry/evolution-source-registry-resource.xml
new file mode 100644
index 0000000..aa60597
--- /dev/null
+++ b/services/evolution-source-registry/evolution-source-registry-resource.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/evolution-data-server/ro-sources">
+    <file>caldav-stub.source</file>
+    <file>contacts-stub.source</file>
+    <file>google-stub.source</file>
+    <file>ldap-stub.source</file>
+    <file>local-stub.source</file>
+    <file>weather-stub.source</file>
+    <file>webcal-stub.source</file>
+    <file>webdav-stub.source</file>
+  </gresource>
+  <gresource prefix="/org/gnome/evolution-data-server/rw-sources">
+    <file>birthdays.source</file>
+    <file>local.source</file>
+    <file>sendmail.source</file>
+    <file>system-address-book.source</file>
+    <file>system-calendar.source</file>
+    <file>system-memo-list.source</file>
+    <file>system-task-list.source</file>
+    <file>vfolder.source</file>
+  </gresource>
+</gresources>
diff --git a/services/evolution-source-registry/evolution-source-registry.c b/services/evolution-source-registry/evolution-source-registry.c
index d4cc15c..72f8492 100644
--- a/services/evolution-source-registry/evolution-source-registry.c
+++ b/services/evolution-source-registry/evolution-source-registry.c
@@ -27,6 +27,11 @@
 
 #include <libebackend/libebackend.h>
 
+#include "evolution-source-registry-resource.h"
+
+#define RESOURCE_PATH_RO_SOURCES "/org/gnome/evolution-data-server/ro-sources"
+#define RESOURCE_PATH_RW_SOURCES "/org/gnome/evolution-data-server/rw-sources"
+
 /* Forward Declarations */
 void evolution_source_registry_migrate_basedir (void);
 void evolution_source_registry_migrate_sources (void);
@@ -36,6 +41,73 @@ gboolean	evolution_source_registry_migrate_imap_to_imapx
 						 GKeyFile *key_file,
 						 const gchar *uid);
 
+static void
+evolution_source_registry_load_error (ESourceRegistryServer *server,
+                                      GFile *file,
+                                      const GError *error)
+{
+	gchar *uri = g_file_get_uri (file);
+
+	g_printerr (
+		"** Failed to load key file at '%s': %s\n",
+		uri, error->message);
+
+	g_free (uri);
+}
+
+static gboolean
+evolution_source_registry_load_all (ESourceRegistryServer *server,
+                                    GError **error)
+{
+	ESourcePermissionFlags flags;
+	GResource *resource;
+	const gchar *path;
+	gboolean success;
+
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), FALSE);
+
+	/* Load the user's sources directory first so that user-specific
+	 * data sources overshadow predefined data sources with identical
+	 * UIDs.  The 'local' data source is one such example. */
+
+	path = e_server_side_source_get_user_dir ();
+	flags = E_SOURCE_PERMISSION_REMOVABLE |
+		E_SOURCE_PERMISSION_WRITABLE;
+	success = e_source_registry_server_load_directory (
+		server, path, flags, error);
+	g_prefix_error (error, "%s: ", path);
+
+	if (!success)
+		return FALSE;
+
+	resource = evolution_source_registry_get_resource ();
+
+	path = RESOURCE_PATH_RO_SOURCES;
+	flags = E_SOURCE_PERMISSION_NONE;
+	success = e_source_registry_server_load_resource (
+		server, resource, path, flags, error);
+	g_prefix_error (error, "%s: ", path);
+
+	if (!success)
+		return FALSE;
+
+	path = RESOURCE_PATH_RW_SOURCES;
+	flags = E_SOURCE_PERMISSION_WRITABLE;
+	success = e_source_registry_server_load_resource (
+		server, resource, path, flags, error);
+	g_prefix_error (error, "%s: ", path);
+
+	if (!success)
+		return FALSE;
+
+	/* Signal that all files are now loaded.  One thing this
+	 * does is tell the cache-reaper module to start scanning
+	 * for orphaned cache directories. */
+	g_signal_emit_by_name (server, "files-loaded");
+
+	return TRUE;
+}
+
 gint
 main (gint argc,
       gchar **argv)
@@ -69,6 +141,11 @@ reload:
 
 	server = e_source_registry_server_new ();
 
+	g_signal_connect (
+		server, "load-error", G_CALLBACK (
+		evolution_source_registry_load_error),
+		NULL);
+
 	/* Convert "imap" mail accounts to "imapx". */
 	g_signal_connect (
 		server, "tweak-key-file", G_CALLBACK (
@@ -76,7 +153,7 @@ reload:
 		NULL);
 
 	/* Failure here is fatal.  Don't even try to keep going. */
-	e_source_registry_server_load_all (
+	evolution_source_registry_load_all (
 		E_SOURCE_REGISTRY_SERVER (server), &error);
 
 	if (error != NULL) {



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