[evolution/account-mgmt: 9/54] Adapt libeshell to the new ESource API.



commit dadb3e882c0d223b3538ad93e109694e622f8227
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Mar 4 15:46:33 2011 -0500

    Adapt libeshell to the new ESource API.

 shell/e-shell-migrate.c |  113 -----------------------------------------------
 shell/e-shell-view.c    |   64 ++++++++++++++++++++++++++
 shell/e-shell-view.h    |    6 +++
 shell/e-shell.c         |   56 +++++++++++++++++++++++-
 shell/e-shell.h         |    4 ++
 5 files changed, 129 insertions(+), 114 deletions(-)
---
diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c
index 69929a1..faf4027 100644
--- a/shell/e-shell-migrate.c
+++ b/shell/e-shell-migrate.c
@@ -792,115 +792,11 @@ fix_folder_permissions (const gchar *data_dir)
 		change_dir_modes (data_dir);
 }
 
-static void
-merge_duplicate_local_sources (GConfClient *client,
-                               const gchar *gconf_key)
-{
-	ESourceList *source_list;
-	GSList *iter, *to_remove = NULL;
-	ESourceGroup *first_local = NULL;
-
-	g_return_if_fail (client != NULL);
-	g_return_if_fail (gconf_key != NULL);
-
-	source_list = e_source_list_new_for_gconf (client, gconf_key);
-
-	for (iter = e_source_list_peek_groups (source_list); iter; iter = iter->next) {
-		GSList *sources;
-		ESourceGroup *group = iter->data;
-
-		if (!group || !e_source_group_peek_base_uri (group) ||
-			g_ascii_strncasecmp (
-			e_source_group_peek_base_uri (group), "local:", 6) != 0)
-			continue;
-
-		if (!first_local) {
-			first_local = group;
-			continue;
-		}
-
-		/* merging respective sources */
-		for (sources = e_source_group_peek_sources (group);
-				sources != NULL; sources = sources->next) {
-			GSList *liter;
-			ESource *dupe_source = sources->data;
-
-			if (!dupe_source)
-				continue;
-
-			for (liter = e_source_group_peek_sources (first_local);
-					liter != NULL; liter = liter->next) {
-				ESource *my_source = liter->data;
-				const gchar *val1, *val2;
-
-				if (!my_source)
-					continue;
-
-				/* pretty unlikely, but just in case */
-				val1 = e_source_get_uid (dupe_source);
-				val2 = e_source_get_uid (my_source);
-				if (g_strcmp0 (val1, val2) == 0)
-					break;
-
-				/* relative uri should not be empty
-				 * (but adressbook can have it empty) */
-				val1 = e_source_peek_relative_uri (dupe_source);
-				val2 = e_source_peek_relative_uri (my_source);
-				if (g_strcmp0 (val1, val2) == 0 && val1 && *val1)
-					break;
-			}
-
-			/* didn't find matching source, thus add its copy */
-			if (liter == NULL) {
-				ESource *copy;
-
-				copy = e_source_copy (dupe_source);
-				e_source_group_add_source (first_local, copy, -1);
-				g_object_unref (copy);
-			}
-		}
-
-		to_remove = g_slist_prepend (to_remove, group);
-	}
-
-	if (first_local) {
-		GSList *sources;
-
-		for (sources = e_source_group_peek_sources (first_local);
-				sources != NULL; sources = sources->next) {
-			ESource *source = sources->data;
-			const gchar *relative_uri;
-
-			if (!source)
-				continue;
-
-			relative_uri = e_source_peek_relative_uri (source);
-			if (!relative_uri || !*relative_uri)
-				e_source_set_relative_uri (source, e_source_get_uid (source));
-		}
-	}
-
-	if (!to_remove) {
-		g_object_unref (source_list);
-		return;
-	}
-
-	for (iter = to_remove; iter; iter = iter->next) {
-		e_source_list_remove_group (source_list, iter->data);
-	}
-
-	e_source_list_sync (source_list, NULL);
-
-	g_object_unref (source_list);
-	g_slist_free (to_remove);
-}
-
 gboolean
 e_shell_migrate_attempt (EShell *shell)
 {
 	ESEvent *ese;
 	GSettings *settings;
-	GConfClient *client;
 	gint major, minor, micro;
 	gint last_major, last_minor, last_micro;
 	gint curr_major, curr_minor, curr_micro;
@@ -933,15 +829,6 @@ e_shell_migrate_attempt (EShell *shell)
 	if (!shell_migrate_attempt (shell, major, minor, micro))
 		_exit (EXIT_SUCCESS);
 
-	/* The 2.32.x (except of 2.32.2) lefts duplicate
-	 * On This Computer/Personal sources, thus clean the mess up */
-	client = gconf_client_get_default ();
-	merge_duplicate_local_sources (client, "/apps/evolution/addressbook/sources");
-	merge_duplicate_local_sources (client, "/apps/evolution/calendar/sources");
-	merge_duplicate_local_sources (client, "/apps/evolution/tasks/sources");
-	merge_duplicate_local_sources (client, "/apps/evolution/memos/sources");
-	g_object_unref (client);
-
 	/* Record a successful migration. */
 	string = g_strdup_printf (
 		"%d.%d.%d", curr_major, curr_minor, curr_micro);
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index cdd8a21..bd66ce2 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -37,6 +37,7 @@
 
 #include "e-util/e-file-utils.h"
 #include "e-util/e-plugin-ui.h"
+#include "e-util/e-source-util.h"
 #include "e-util/e-ui-manager.h"
 #include "e-util/e-util-private.h"
 #include "e-util/e-util.h"
@@ -1884,3 +1885,66 @@ e_shell_view_new_view_instance (EShellView *shell_view,
 
 	return view_instance;
 }
+
+/**
+ * e_shell_view_write_source:
+ * @shell_view: an #EShellView
+ * @source: an #ESource
+ *
+ * Submits the current contents of @source to the D-Bus service to be
+ * written to disk and broadcast to other clients.
+ *
+ * This function does not block: @shell_view will dispatch the operation
+ * asynchronously and handle any errors.
+ **/
+void
+e_shell_view_write_source (EShellView *shell_view,
+                           ESource *source)
+{
+	EActivity *activity;
+	EAlertSink *alert_sink;
+	EShellBackend *shell_backend;
+	EShellContent *shell_content;
+
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+	g_return_if_fail (E_IS_SOURCE (source));
+
+	shell_backend = e_shell_view_get_shell_backend (shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
+
+	alert_sink = E_ALERT_SINK (shell_content);
+	activity = e_source_util_write (source, alert_sink);
+	e_shell_backend_add_activity (shell_backend, activity);
+}
+
+/**
+ * e_shell_view_remove_source:
+ * @shell_view: an #EShellView
+ * @source: the #ESource to be removed
+ *
+ * Requests the D-Bus service to delete the key files for @source and all of
+ * its descendants and broadcast their removal to all clients.
+ *
+ * This function does not block: @shell_view will dispatch the operation
+ * asynchronously and handle any errors.
+ **/
+void
+e_shell_view_remove_source (EShellView *shell_view,
+                            ESource *source)
+{
+	EActivity *activity;
+	EAlertSink *alert_sink;
+	EShellBackend *shell_backend;
+	EShellContent *shell_content;
+
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+	g_return_if_fail (E_IS_SOURCE (source));
+
+	shell_backend = e_shell_view_get_shell_backend (shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
+
+	alert_sink = E_ALERT_SINK (shell_content);
+	activity = e_source_util_remove (source, alert_sink);
+	e_shell_backend_add_activity (shell_backend, activity);
+}
+
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index ad311ec..0d7aee0 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -22,6 +22,8 @@
 #ifndef E_SHELL_VIEW_H
 #define E_SHELL_VIEW_H
 
+#include <libedataserver/e-source.h>
+
 #include <shell/e-shell-common.h>
 #include <shell/e-shell-backend.h>
 #include <shell/e-shell-content.h>
@@ -228,6 +230,10 @@ GtkWidget *	e_shell_view_show_popup_menu	(EShellView *shell_view,
 GalViewInstance *
 		e_shell_view_new_view_instance	(EShellView *shell_view,
 						 const gchar *instance_id);
+void		e_shell_view_write_source	(EShellView *shell_view,
+						 ESource *source);
+void		e_shell_view_remove_source	(EShellView *shell_view,
+						 ESource *source);
 
 G_END_DECLS
 
diff --git a/shell/e-shell.c b/shell/e-shell.c
index bc25284..ae2641f 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -53,6 +53,7 @@
 struct _EShellPrivate {
 	GQueue alerts;
 	EShellSettings *settings;
+	ESourceRegistry *registry;
 	GActionGroup *action_group;
 	GtkWidget *preferences_window;
 
@@ -90,6 +91,7 @@ enum {
 	PROP_MODULE_DIRECTORY,
 	PROP_NETWORK_AVAILABLE,
 	PROP_ONLINE,
+	PROP_REGISTRY,
 	PROP_SHELL_SETTINGS
 };
 
@@ -683,6 +685,12 @@ shell_get_property (GObject *object,
 				E_SHELL (object)));
 			return;
 
+		case PROP_REGISTRY:
+			g_value_set_object (
+				value, e_shell_get_registry (
+				E_SHELL (object)));
+			return;
+
 		case PROP_SHELL_SETTINGS:
 			g_value_set_object (
 				value, e_shell_get_shell_settings (
@@ -723,6 +731,11 @@ shell_dispose (GObject *object)
 		priv->settings = NULL;
 	}
 
+	if (priv->registry != NULL) {
+		g_object_unref (priv->registry);
+		priv->registry = NULL;
+	}
+
 	if (priv->action_group != NULL) {
 		g_object_unref (priv->action_group);
 		priv->action_group = NULL;
@@ -857,10 +870,20 @@ shell_initable_init (GInitable *initable,
                      GError **error)
 {
 	GApplication *application = G_APPLICATION (initable);
+	EShellPrivate *priv;
+
+	priv = E_SHELL_GET_PRIVATE (initable);
 
 	shell_add_actions (application);
 
-	return g_application_register (application, cancellable, error);
+	priv->registry = e_source_registry_new_sync (cancellable, error);
+	if (priv->registry == NULL)
+		return FALSE;
+
+	if (!g_application_register (application, cancellable, error))
+		return FALSE;
+
+	return TRUE;
 }
 
 static void
@@ -1002,6 +1025,21 @@ e_shell_class_init (EShellClass *class)
 			G_PARAM_CONSTRUCT));
 
 	/**
+	 * EShell:registry
+	 *
+	 * The #ESourceRegistry manages #ESource instances.
+	 **/
+	g_object_class_install_property (
+		object_class,
+		PROP_REGISTRY,
+		g_param_spec_object (
+			"registry",
+			"Registry",
+			"Data source registry",
+			E_TYPE_SOURCE_REGISTRY,
+			G_PARAM_READABLE));
+
+	/**
 	 * EShell:settings
 	 *
 	 * The #EShellSettings object stores application settings.
@@ -1397,6 +1435,22 @@ e_shell_get_shell_settings (EShell *shell)
 }
 
 /**
+ * e_shell_get_registry:
+ * @shell: an #EShell
+ *
+ * Returns the shell's #ESourceRegistry which holds all #ESource instances.
+ *
+ * Returns: the #ESourceRegistry
+ **/
+ESourceRegistry *
+e_shell_get_registry (EShell *shell)
+{
+	g_return_val_if_fail (E_IS_SHELL (shell), NULL);
+
+	return shell->priv->registry;
+}
+
+/**
  * e_shell_create_shell_window:
  * @shell: an #EShell
  * @view_name: name of the initial shell view, or %NULL
diff --git a/shell/e-shell.h b/shell/e-shell.h
index ffff239..786e6c8 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -22,6 +22,8 @@
 #ifndef E_SHELL_H
 #define E_SHELL_H
 
+#include <libedataserver/e-source-registry.h>
+
 #include <e-util/e-activity.h>
 #include <libevolution-utils/e-alert.h>
 
@@ -117,6 +119,8 @@ EShellBackend *	e_shell_get_backend_by_name	(EShell *shell,
 EShellBackend *	e_shell_get_backend_by_scheme	(EShell *shell,
 						 const gchar *scheme);
 EShellSettings *e_shell_get_shell_settings	(EShell *shell);
+ESourceRegistry *
+		e_shell_get_registry		(EShell *shell);
 GtkWidget *	e_shell_create_shell_window	(EShell *shell,
 						 const gchar *view_name);
 guint		e_shell_handle_uris		(EShell *shell,



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