[evolution-data-server/gnome-2-32] Bug #651226 - e_book_new_system_addressbook() should create source in GConf



commit 0a5cca7e367807e776a0818e526f9cdc670a14ca
Author: Christophe Dumez <christophe dumez intel com>
Date:   Fri Jun 3 11:33:49 2011 +0200

    Bug #651226 - e_book_new_system_addressbook() should create source in GConf
    
    The same problem was fixed in libecal by commit 3bb75464a67
    and commit 05c0b7b4bd0.
    (cherry picked from commit 65a0f255464dc7d7b8f7f0aefeff1462f00d4475)

 addressbook/libebook/e-book.c |   74 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 71 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index 0239485..b747bcc 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -3201,9 +3201,16 @@ check_uri (ESource *source, gpointer uri)
 		g_free (my_uri);
 
 		return res;
-	}
+	} else {
+		gboolean ret;
+		gchar *suri2;
 
-	return FALSE;
+		suri2 = e_source_get_uri (source);
+		ret = !g_ascii_strcasecmp (suri2, uri);
+		g_free (suri2);
+
+		return ret;
+	}
 }
 
 /**
@@ -3275,6 +3282,67 @@ check_system (ESource *source, gpointer data)
 	return FALSE;
 }
 
+static EBook *
+get_local_source (GError **error)
+{
+	ESourceGroup *on_this_computer;
+	ESourceList *sources;
+	GSList *local_sources, *iter;
+	ESource *personal = NULL;
+	const gchar *name;
+	gchar *source_uri = NULL;
+	EBook *book;
+
+	if (e_book_get_addressbooks (&sources, error)) {
+		on_this_computer = e_source_list_ensure_group (
+		        sources, _("On This Computer"), "local:", TRUE);
+
+		if (on_this_computer) {
+			local_sources = e_source_group_peek_sources (on_this_computer);
+
+			/* Make sure this group includes a "Personal" source. */
+			for (iter = local_sources; iter != NULL; iter = iter->next) {
+				ESource *source = iter->data;
+				const gchar *relative_uri;
+
+				relative_uri = e_source_peek_relative_uri (source);
+				if (g_strcmp0 (relative_uri, "system") == 0) {
+				        personal = source;
+				        break;
+				}
+			}
+
+			name = _("Personal");
+
+			if (personal == NULL) {
+				ESource *source;
+
+				/* Create the default Personal address book. */
+				source = e_source_new (name, "system");
+				e_source_group_add_source (on_this_computer, source, -1);
+				e_source_set_property (source, "completion", "true");
+
+				source_uri = e_source_get_uri (source);
+				g_object_unref(source);
+			} else {
+				/* Force the source name to the current locale. */
+				e_source_set_name (personal, name);
+
+				source_uri = e_source_get_uri (personal);
+			}
+
+			g_object_unref (on_this_computer);
+		}
+
+		g_object_unref (sources);
+	}
+
+	book = e_book_new_from_uri (source_uri?:"local:system", error);
+	g_free (source_uri);
+
+	return book;
+}
+
 /**
  * e_book_new_system_addressbook:
  * @error: A #GError pointer
@@ -3314,7 +3382,7 @@ e_book_new_system_addressbook (GError **error)
 		book = e_book_new (system_source, &err);
 		g_object_unref (system_source);
 	} else {
-		book = e_book_new_from_uri (csd.uri, &err);
+		book = get_local_source (&err);
 	}
 
 	if (csd.uri_source)



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