[evolution/account-mgmt: 21/25] Add a source-loader module.



commit 609a6d79e8fa8d0fc0fd7f3e4117bbe67625b966
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Dec 19 22:38:36 2010 -0500

    Add a source-loader module.
    
    It loads ESources at startup, submits alerts for loading errors,
    and enforces Evolution-specific ESource policies.

 configure.ac                                       |    1 +
 modules/Makefile.am                                |    1 +
 modules/source-loader/Makefile.am                  |   32 +++++
 modules/source-loader/evolution-source-loader.c    |  146 ++++++++++++++++++++
 .../evolution-source-loader.error.xml              |   11 ++
 po/POTFILES.in                                     |    1 +
 6 files changed, 192 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 592e174..441e6ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1827,6 +1827,7 @@ modules/plugin-lib/Makefile
 modules/plugin-manager/Makefile
 modules/plugin-mono/Makefile
 modules/plugin-python/Makefile
+modules/source-loader/Makefile
 modules/startup-wizard/Makefile
 modules/windows-sens/Makefile
 plugins/Makefile
diff --git a/modules/Makefile.am b/modules/Makefile.am
index ae95614..836d61c 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -27,6 +27,7 @@ SUBDIRS = \
 	offline-alert \
 	plugin-lib \
 	plugin-manager \
+	source-loader \
 	startup-wizard \
 	$(MONO_DIR) \
 	$(PYTHON_DIR) \
diff --git a/modules/source-loader/Makefile.am b/modules/source-loader/Makefile.am
new file mode 100644
index 0000000..366f4d8
--- /dev/null
+++ b/modules/source-loader/Makefile.am
@@ -0,0 +1,32 @@
+module_LTLIBRARIES = libevolution-module-source-loader.la
+
+libevolution_module_source_loader_la_CPPFLAGS =			\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir)						\
+	-DG_LOG_DOMAIN=\"evolution-source-loader\"		\
+	$(EVOLUTION_DATA_SERVER_CFLAGS)				\
+	$(GNOME_PLATFORM_CFLAGS)
+
+libevolution_module_source_loader_la_SOURCES =			\
+	evolution-source-loader.c
+
+libevolution_module_source_loader_la_LIBADD =			\
+	$(top_builddir)/e-util/libeutil.la			\
+	$(top_builddir)/shell/libeshell.la			\
+	$(EVOLUTION_DATA_SERVER_LIBS)				\
+	$(GNOME_PLATFORM_LIBS)
+
+libevolution_module_source_loader_la_LDFLAGS =			\
+	-module -avoid-version $(NO_UNDEFINED)
+
+error_DATA = evolution-source-loader.error
+errordir = $(privdatadir)/errors
+ EVO_PLUGIN_RULE@
+
+BUILT_SOURCES = $(error_DATA)
+
+CLEANFILES = $(BUILT_SOURCES)
+
+EXTRA_DIST = evolution-source-loader.error.xml
+
+-include $(top_srcdir)/git.mk
diff --git a/modules/source-loader/evolution-source-loader.c b/modules/source-loader/evolution-source-loader.c
new file mode 100644
index 0000000..649f2cc
--- /dev/null
+++ b/modules/source-loader/evolution-source-loader.c
@@ -0,0 +1,146 @@
+/*
+ * evolution-source-loader.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 <shell/e-shell.h>
+#include <e-util/e-extension.h>
+#include <libedataserver/e-source-registry.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_LOADER \
+	(e_source_loader_get_type ())
+#define E_SOURCE_LOADER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_LOADER, ESourceLoader))
+
+typedef struct _ESourceLoader ESourceLoader;
+typedef struct _ESourceLoaderClass ESourceLoaderClass;
+
+struct _ESourceLoader {
+	EExtension parent;
+};
+
+struct _ESourceLoaderClass {
+	EExtensionClass parent_class;
+};
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_source_loader_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (ESourceLoader, e_source_loader, E_TYPE_EXTENSION)
+
+static EShell *
+source_loader_get_shell (ESourceLoader *extension)
+{
+	EExtensible *extensible;
+
+	extensible = e_extension_get_extensible (E_EXTENSION (extension));
+
+	return E_SHELL (extensible);
+}
+
+static void
+source_loader_load_error_cb (ESourceRegistry *registry,
+                             GFile *file,
+                             const GError *error,
+                             ESourceLoader *extension)
+{
+	EAlert *alert;
+	EShell *shell;
+	gchar *path;
+
+	path = g_file_get_path (file);
+	alert = e_alert_new (
+		"source-loader:load-error",
+		path, error->message, NULL);
+
+	shell = source_loader_get_shell (extension);
+	e_shell_submit_alert (shell, alert);
+
+	g_object_unref (alert);
+	g_free (path);
+}
+
+static void
+source_loader_constructed (GObject *object)
+{
+	ESourceLoader *extension;
+	ESourceRegistry *registry;
+	GError *error = NULL;
+
+	extension = E_SOURCE_LOADER (object);
+	registry = e_source_registry_get_default ();
+
+	g_signal_connect (
+		registry, "load-error",
+		G_CALLBACK (source_loader_load_error_cb), extension);
+
+	e_source_registry_load_sources (registry, &error);
+
+	if (error != NULL) {
+		EAlert *alert;
+		EShell *shell;
+
+		alert = e_alert_new (
+			"source-loader:directory-error",
+			error->message, NULL);
+
+		shell = source_loader_get_shell (extension);
+		e_shell_submit_alert (shell, alert);
+
+		g_object_unref (alert);
+		g_error_free (error);
+	}
+}
+
+static void
+e_source_loader_class_init (ESourceLoaderClass *class)
+{
+	GObjectClass *object_class;
+	EExtensionClass *extension_class;
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->constructed = source_loader_constructed;
+
+	extension_class = E_EXTENSION_CLASS (class);
+	extension_class->extensible_type = E_TYPE_SHELL;
+}
+
+static void
+e_source_loader_class_finalize (ESourceLoaderClass *class)
+{
+}
+
+static void
+e_source_loader_init (ESourceLoader *extension)
+{
+}
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+	e_source_loader_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
diff --git a/modules/source-loader/evolution-source-loader.error.xml b/modules/source-loader/evolution-source-loader.error.xml
new file mode 100644
index 0000000..e526523
--- /dev/null
+++ b/modules/source-loader/evolution-source-loader.error.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<error-list domain="source-loader">
+  <error id="directory-error" type="error">
+    <_primary>Failed to open a directory containing data source files.</_primary>
+    <_secondary>The reported error was &quot;{0}&quot;. Please check that this directory exists and is readable and then restart Evolution.</_secondary>
+  </error>
+  <error id="load-error" type="warning">
+    <_primary>Failed to load a data source file.</_primary>
+    <_secondary>Evolution was unable to load the data source file &quot;{0}&quot;. The reported error was &quot;{1}&quot;.</_secondary>
+  </error>
+</error-list>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 293c4c2..cbdd10d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -281,6 +281,7 @@ modules/offline-alert/evolution-offline-alert.error.xml
 modules/plugin-manager/evolution-plugin-manager.c
 modules/plugin-python/example/org-gnome-hello-python-ui.xml
 modules/plugin-python/example/org-gnome-hello-python.eplug.xml
+modules/source-loader/evolution-source-loader.error.xml
 modules/startup-wizard/evolution-startup-wizard.c
 plugins/addressbook-file/org-gnome-addressbook-file.eplug.xml
 plugins/attachment-reminder/apps-evolution-attachment-reminder.schemas.in



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