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



commit 3eaf17a63bd07217bd9275f264f7292d33f9be02
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 |  110 -----------------------------------------------
 shell/e-shell.c         |   29 ++++++++++++
 shell/e-shell.h         |    3 +
 3 files changed, 32 insertions(+), 110 deletions(-)
---
diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c
index 89f94b0..3bfa2fb 100644
--- a/shell/e-shell-migrate.c
+++ b/shell/e-shell-migrate.c
@@ -797,109 +797,6 @@ 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_peek_uid (dupe_source);
-				val2 = e_source_peek_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_peek_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)
 {
@@ -938,13 +835,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 */
-	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");
-
 	/* Record a successful migration. */
 	string = g_strdup_printf (
 		"%d.%d.%d", curr_major, curr_minor, curr_micro);
diff --git a/shell/e-shell.c b/shell/e-shell.c
index dbcb55b..f4eb2e5 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -51,6 +51,7 @@ struct _EShellPrivate {
 	GList *watched_windows;
 	EShellSettings *settings;
 	GConfClient *gconf_client;
+	ESourceRegistry *registry;
 	GActionGroup *action_group;
 	GtkWidget *preferences_window;
 
@@ -762,6 +763,11 @@ shell_dispose (GObject *object)
 		priv->gconf_client = 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;
@@ -1236,6 +1242,7 @@ e_shell_init (EShell *shell)
 
 	shell->priv->settings = g_object_new (E_TYPE_SHELL_SETTINGS, NULL);
 	shell->priv->gconf_client = gconf_client_get_default ();
+	shell->priv->registry = e_source_registry_get_default ();
 	shell->priv->preferences_window = e_preferences_window_new (shell);
 	shell->priv->backends_by_name = backends_by_name;
 	shell->priv->backends_by_scheme = backends_by_scheme;
@@ -1243,6 +1250,8 @@ e_shell_init (EShell *shell)
 
 	shell->priv->startup_view = NULL;
 
+	g_object_ref (shell->priv->registry);
+
 	g_object_ref_sink (shell->priv->preferences_window);
 
 	/* Add our icon directory to the theme's search path
@@ -1471,6 +1480,26 @@ e_shell_get_gconf_client (EShell *shell)
 }
 
 /**
+ * e_shell_get_registry:
+ * @shell: an #EShell
+ *
+ * Returns the default #ESourceRegistry.
+ *
+ * This is equivalent to e_source_registry_get_default(), but this
+ * function is preferred so that all singleton objects come from the
+ * same place.
+ *
+ * Returns: the default #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 ede071e..d9bf7ab 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -23,6 +23,7 @@
 #define E_SHELL_H
 
 #include <gconf/gconf-client.h>
+#include <libedataserver/e-source-registry.h>
 
 #include <e-util/e-activity.h>
 #include <e-util/e-alert.h>
@@ -123,6 +124,8 @@ EShellBackend *	e_shell_get_backend_by_scheme	(EShell *shell,
 						 const gchar *scheme);
 EShellSettings *e_shell_get_shell_settings	(EShell *shell);
 GConfClient *	e_shell_get_gconf_client	(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]