[evolution/wip/gsettings] Merge duplicate local sources



commit f3c11101c3c58a154c005a936a6b99671401986d
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 3 11:26:41 2011 +0100

    Merge duplicate local sources

 shell/e-shell-migrate.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c
index 878b121..01b3f9f 100644
--- a/shell/e-shell-migrate.c
+++ b/shell/e-shell-migrate.c
@@ -793,6 +793,87 @@ 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; 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 (!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)
 {
@@ -831,6 +912,13 @@ 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);



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