[evolution] Use the new e_load_book_source_async() where possible.



commit a536d74906984acd16902606ac574db676344194
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Aug 18 15:49:49 2010 -0400

    Use the new e_load_book_source_async() where possible.
    
    It's easier to use than addressbook_load() but requires starting with
    an ESource rather than an EBook, and there's a couple places left where
    that's not so easy.  I'll spend more time on it later.

 addressbook/gui/contact-editor/e-contact-editor.c  |   84 +++++++++++---------
 addressbook/gui/contact-editor/e-contact-editor.h  |    4 +-
 .../contact-list-editor/e-contact-list-editor.c    |   68 +++++++---------
 addressbook/gui/widgets/eab-gui-util.c             |   56 ++++++++-----
 addressbook/gui/widgets/eab-gui-util.h             |   38 +++++-----
 modules/addressbook/e-book-shell-view-private.c    |   68 +++++++++-------
 modules/addressbook/e-book-shell-view-private.h    |    1 +
 plugins/vcard-inline/vcard-inline.c                |   54 +++++++++----
 8 files changed, 211 insertions(+), 162 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index c7388ea..12431e4 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -28,17 +28,16 @@
 #include <string.h>
 #include <time.h>
 #include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
-
+#include <gdk/gdkkeysyms.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#include <libedataserverui/e-categories-dialog.h>
 
 #include <libebook/e-address-western.h>
+#include <libedataserverui/e-book-auth-util.h>
+#include <libedataserverui/e-categories-dialog.h>
 #include <libedataserverui/e-category-completion.h>
 #include <libedataserverui/e-source-combo-box.h>
 
-#include "addressbook/util/addressbook.h"
 #include "addressbook/printing/e-contact-print.h"
 #include "addressbook/gui/widgets/eab-gui-util.h"
 #include "e-util/e-util.h"
@@ -2691,51 +2690,63 @@ init_all (EContactEditor *editor)
 }
 
 static void
-new_target_cb (EBook *new_book, const GError *error, EContactEditor *editor)
+contact_editor_book_loaded_cb (ESource *source,
+                               GAsyncResult *result,
+                               EContactEditor *editor)
 {
-	editor->load_source_id = 0;
-	editor->load_book      = NULL;
+	EBook *book;
+	GError *error = NULL;
 
-	if (error || new_book == NULL) {
+	book = e_load_book_source_finish (source, result, &error);
+
+	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		g_warn_if_fail (book == NULL);
+		g_error_free (error);
+		goto exit;
+
+	} else if (error != NULL) {
 		GtkWidget *source_combo_box;
+		GtkWindow *parent;
+
+		g_warn_if_fail (book == NULL);
 
-		eab_load_error_dialog (NULL, e_book_get_source (new_book), error);
+		parent = eab_editor_get_window (EAB_EDITOR (editor));
+		eab_load_error_dialog (GTK_WIDGET (parent), source, error);
 
 		source_combo_box = e_builder_get_widget (
 			editor->builder, "source-combo-box-source");
 		e_source_combo_box_set_active (
-			E_SOURCE_COMBO_BOX (source_combo_box),
-			e_book_get_source (editor->target_book));
+			E_SOURCE_COMBO_BOX (source_combo_box), source);
 
-		if (new_book)
-			g_object_unref (new_book);
-		return;
+		g_error_free (error);
+		goto exit;
 	}
 
-	g_object_set (editor, "target_book", new_book, NULL);
-	g_object_unref (new_book);
-}
+	g_return_if_fail (E_IS_BOOK (book));
 
-static void
-cancel_load (EContactEditor *editor)
-{
-	if (editor->load_source_id) {
-		addressbook_load_cancel (editor->load_source_id);
-		editor->load_source_id = 0;
+	/* FIXME Write a private contact_editor_set_target_book(). */
+	g_object_set (editor, "target_book", book, NULL);
 
-		g_object_unref (editor->load_book);
-		editor->load_book = NULL;
-	}
+	g_object_unref (book);
+
+exit:
+	g_object_unref (editor);
 }
 
 static void
 source_changed (ESourceComboBox *source_combo_box, EContactEditor *editor)
 {
 	ESource *source;
+	GtkWindow *parent;
 
 	source = e_source_combo_box_get_active (source_combo_box);
+	parent = eab_editor_get_window (EAB_EDITOR (editor));
 
-	cancel_load (editor);
+	if (editor->cancellable != NULL) {
+		g_cancellable_cancel (editor->cancellable);
+		g_object_unref (editor->cancellable);
+		editor->cancellable = NULL;
+	}
 
 	if (e_source_equal (e_book_get_source (editor->target_book), source))
 		return;
@@ -2745,9 +2756,12 @@ source_changed (ESourceComboBox *source_combo_box, EContactEditor *editor)
 		return;
 	}
 
-	editor->load_book = e_book_new (source, NULL);
-	editor->load_source_id = addressbook_load (editor->load_book,
-						   (EBookAsyncCallback) new_target_cb, editor);
+	editor->cancellable = g_cancellable_new ();
+
+	e_load_book_source_async (
+		source, parent, editor->cancellable,
+		(GAsyncReadyCallback) contact_editor_book_loaded_cb,
+		g_object_ref (editor));
 }
 
 static void
@@ -3520,9 +3534,6 @@ e_contact_editor_init (EContactEditor *e_contact_editor)
 	e_contact_editor->categories_dialog = NULL;
 	e_contact_editor->compress_ui = e_shell_get_express_mode (shell);
 
-	e_contact_editor->load_source_id = 0;
-	e_contact_editor->load_book = NULL;
-
 	builder = gtk_builder_new ();
 	e_load_ui_builder_definition (builder, "contact-editor.ui");
 
@@ -3634,7 +3645,10 @@ e_contact_editor_dispose (GObject *object)
 		e_contact_editor->builder = NULL;
 	}
 
-	cancel_load (e_contact_editor);
+	if (e_contact_editor->cancellable != NULL) {
+		g_object_unref (e_contact_editor->cancellable);
+		e_contact_editor->cancellable = NULL;
+	}
 
 	if (G_OBJECT_CLASS (parent_class)->dispose)
 		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
@@ -3808,8 +3822,6 @@ e_contact_editor_set_property (GObject *object, guint prop_id, const GValue *val
 		if (changed)
 			sensitize_all (editor);
 
-		/* If we're trying to load a new target book, cancel that here. */
-		cancel_load (editor);
 		break;
 	}
 
diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h
index b41324c..81b39d1 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.h
+++ b/addressbook/gui/contact-editor/e-contact-editor.h
@@ -91,9 +91,7 @@ struct _EContactEditor
 
 	EList *required_fields;
 
-	/* ID for async load_source call */
-	guint  load_source_id;
-	EBook *load_book;
+	GCancellable *cancellable;
 
 	/* signal ids for "writable_status" */
 	gint target_editable_id;
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.c b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
index 52c15ea..af68ee0 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
@@ -36,11 +36,11 @@
 #include <gdk/gdkkeysyms.h>
 
 #include <camel/camel.h>
+#include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-combo-box.h>
 
 #include "e-util/e-util.h"
 #include "addressbook/gui/widgets/eab-gui-util.h"
-#include "addressbook/util/addressbook.h"
 #include "addressbook/util/eab-book-util.h"
 
 #include "eab-editor.h"
@@ -124,10 +124,6 @@ struct _EContactListEditorPrivate {
 
 	/* Whether an async wombat call is in progress. */
 	guint in_async_call : 1;
-
-	/* ID for async load_source call */
-	guint load_source_id;
-	EBook *load_book;
 };
 
 static gpointer parent_class;
@@ -207,48 +203,43 @@ contact_list_editor_add_email (EContactListEditor *editor)
 }
 
 static void
-contact_list_editor_book_loaded (EBook *new_book,
-                                 const GError *error,
-                                 EContactListEditor *editor)
+contact_list_editor_book_loaded_cb (ESource *source,
+                                    GAsyncResult *result,
+                                    EContactListEditor *editor)
 {
 	EContactListEditorPrivate *priv = editor->priv;
 	EContactStore *contact_store;
 	ENameSelectorEntry *entry;
+	EBook *book;
+	GError *error = NULL;
 
-	priv->load_source_id = 0;
-	priv->load_book = NULL;
+	book = e_load_book_source_finish (source, result, &error);
+
+	if (error != NULL) {
+		GtkWindow *parent;
+
+		parent = eab_editor_get_window (EAB_EDITOR (editor));
+		eab_load_error_dialog (GTK_WIDGET (parent), source, error);
 
-	if (error || new_book == NULL) {
-		eab_load_error_dialog (
-			NULL, e_book_get_source (new_book), error);
 		e_source_combo_box_set_active (
 			E_SOURCE_COMBO_BOX (WIDGET (SOURCE_MENU)),
 			e_book_get_source (priv->book));
-		if (new_book)
-			g_object_unref (new_book);
-		return;
+
+		g_error_free (error);
+		goto exit;
 	}
 
+	g_return_if_fail (E_IS_BOOK (book));
+
 	entry = E_NAME_SELECTOR_ENTRY (WIDGET (EMAIL_ENTRY));
 	contact_store = e_name_selector_entry_peek_contact_store (entry);
-	e_contact_store_add_book (contact_store, new_book);
-	e_contact_list_editor_set_book (editor, new_book);
-	g_object_unref (new_book);
-}
+	e_contact_store_add_book (contact_store, book);
+	e_contact_list_editor_set_book (editor, book);
 
-static void
-contact_list_editor_cancel_load (EContactListEditor *editor)
-{
-	EContactListEditorPrivate *priv = editor->priv;
-
-	if (priv->load_source_id == 0)
-		return;
+	g_object_unref (book);
 
-	addressbook_load_cancel (priv->load_source_id);
-	priv->load_source_id = 0;
-
-	g_object_unref (priv->load_book);
-	priv->load_book = NULL;
+exit:
+	g_object_unref (editor);
 }
 
 static gboolean
@@ -808,6 +799,7 @@ void
 contact_list_editor_source_menu_changed_cb (GtkWidget *widget)
 {
 	EContactListEditor *editor;
+	GtkWindow *parent;
 	ESource *source;
 
 	editor = contact_list_editor_extract (widget);
@@ -816,10 +808,12 @@ contact_list_editor_source_menu_changed_cb (GtkWidget *widget)
 	if (e_source_equal (e_book_get_source (editor->priv->book), source))
 		return;
 
-	editor->priv->load_book = e_book_new (source, NULL);
-	editor->priv->load_source_id = addressbook_load (
-		editor->priv->load_book, (EBookAsyncCallback)
-		contact_list_editor_book_loaded, editor);
+	parent = eab_editor_get_window (EAB_EDITOR (editor));
+
+	e_load_book_source_async (
+		source, parent, NULL, (GAsyncReadyCallback)
+		contact_list_editor_book_loaded_cb,
+		g_object_ref (editor));
 }
 
 gboolean
@@ -1057,8 +1051,6 @@ contact_list_editor_dispose (GObject *object)
 	EContactListEditor *editor = E_CONTACT_LIST_EDITOR (object);
 	EContactListEditorPrivate *priv = editor->priv;
 
-	contact_list_editor_cancel_load (editor);
-
 	if (priv->name_selector) {
 		g_object_unref (priv->name_selector);
 		priv->name_selector = NULL;
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 8e3a6a4..9ca8033 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -30,6 +30,7 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <libedataserver/e-data-server-util.h>
+#include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-selector.h>
 #include <e-util/e-util.h>
 #include "eab-gui-util.h"
@@ -45,8 +46,6 @@
 /* we link to camel for decoding quoted printable email addresses */
 #include <camel/camel.h>
 
-#include "addressbook/util/addressbook.h"
-
 void
 eab_error_dialog (const gchar *msg, const GError *error)
 {
@@ -379,30 +378,42 @@ do_copy (gpointer data, gpointer user_data)
 }
 
 static void
-got_book_cb (EBook *book, const GError *error, gpointer closure)
+book_loaded_cb (ESource *destination,
+                GAsyncResult *result,
+                ContactCopyProcess *process)
 {
-	ContactCopyProcess *process;
-	process = closure;
-	if (!error) {
+	EBook *book;
+	GError *error = NULL;
+
+	book = e_load_book_source_finish (destination, result, &error);
+
+	if (book != NULL) {
+		g_warn_if_fail (error == NULL);
 		process->destination = book;
 		process->book_status = TRUE;
-		g_object_ref (book);
-		g_list_foreach (process->contacts,
-				do_copy,
-				process);
+		g_list_foreach (process->contacts, do_copy, process);
+
+	} else if (error != NULL) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
 	}
+
 	process_unref (process);
 }
 
 void
-eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean delete_from_source, GtkWindow *parent_window)
+eab_transfer_contacts (EBook *source_book,
+                       GList *contacts /* adopted */,
+                       gboolean delete_from_source,
+                       GtkWindow *parent_window)
 {
-	EBook *dest;
-	ESource *destination_source;
+	ESource *destination;
 	static gchar *last_uid = NULL;
 	ContactCopyProcess *process;
 	gchar *desc;
 
+	g_return_if_fail (E_IS_BOOK (source_book));
+
 	if (contacts == NULL)
 		return;
 
@@ -421,22 +432,22 @@ eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean de
 			desc = _("Copy contacts to");
 	}
 
-	destination_source = eab_select_source (e_book_get_source (source), desc, NULL,
-						last_uid, parent_window);
+	destination = eab_select_source (
+		e_book_get_source (source_book),
+		desc, NULL, last_uid, parent_window);
 
-	if (!destination_source)
+	if (!destination)
 		return;
 
-	if (strcmp (last_uid, e_source_peek_uid (destination_source)) != 0) {
+	if (strcmp (last_uid, e_source_peek_uid (destination)) != 0) {
 		g_free (last_uid);
-		last_uid = g_strdup (e_source_peek_uid (destination_source));
+		last_uid = g_strdup (e_source_peek_uid (destination));
 	}
 
 	process = g_new (ContactCopyProcess, 1);
 	process->count = 1;
 	process->book_status = FALSE;
-	process->source = source;
-	g_object_ref (source);
+	process->source = g_object_ref (source_book);
 	process->contacts = contacts;
 	process->destination = NULL;
 
@@ -445,8 +456,9 @@ eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean de
 	else
 		process->done_cb = NULL;
 
-	dest = e_book_new (destination_source, NULL);
-	addressbook_load (dest, got_book_cb, process);
+	e_load_book_source_async (
+		destination, parent_window, NULL,
+		(GAsyncReadyCallback) book_loaded_cb, process);
 }
 
 /* To parse something like...
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 5f8890f..e1fd43f 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -29,25 +29,25 @@
 
 G_BEGIN_DECLS
 
-void                eab_error_dialog              (const gchar *msg,
-						   const GError *error);
-void                eab_load_error_dialog         (GtkWidget *parent,
-						   ESource *source,
-						   const GError *error);
-void                eab_search_result_dialog      (GtkWidget *parent,
-						   EBookViewStatus status,
-						   const gchar *error_msg);
-gint                eab_prompt_save_dialog        (GtkWindow   *parent);
-
-void                eab_transfer_contacts         (EBook       *source,
-						   GList       *contacts, /* adopted */
-						   gboolean     delete_from_source,
-						   GtkWindow   *parent_window);
-
-gchar *             eab_suggest_filename          (GList *contact_list);
-
-ESource            *eab_select_source             (ESource *except_source, const gchar *title, const gchar *message,
-						   const gchar *select_uid, GtkWindow *parent);
+void		eab_error_dialog		(const gchar *msg,
+						 const GError *error);
+void		eab_load_error_dialog		(GtkWidget *parent,
+						 ESource *source,
+						 const GError *error);
+void		eab_search_result_dialog	(GtkWidget *parent,
+						 EBookViewStatus status,
+						 const gchar *error_msg);
+gint		eab_prompt_save_dialog		(GtkWindow *parent);
+void		eab_transfer_contacts		(EBook *source_book,
+						 GList *contacts, /* adopted */
+						 gboolean delete_from_source,
+						 GtkWindow *parent_window);
+gchar *		eab_suggest_filename		(GList *contact_list);
+ESource *	eab_select_source		(ESource *except_source,
+						 const gchar *title,
+						 const gchar *message,
+						 const gchar *select_uid,
+						 GtkWindow *parent);
 
 /* To parse quoted printable address & return email & name fields */
 gboolean	eab_parse_qp_email		(const gchar *string,
diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c
index a9b64a3..4639d18 100644
--- a/modules/addressbook/e-book-shell-view-private.c
+++ b/modules/addressbook/e-book-shell-view-private.c
@@ -26,8 +26,6 @@
 #include "widgets/menus/gal-view-factory-etable.h"
 #include "addressbook/gui/widgets/gal-view-factory-minicard.h"
 
-#include "addressbook.h"
-
 static void
 open_contact (EBookShellView *book_shell_view,
               EContact *contact,
@@ -182,22 +180,30 @@ contacts_removed (EBookShellView *book_shell_view,
 }
 
 static void
-book_open_cb (EBook *book,
-              const GError *error,
-              gpointer user_data)
+book_shell_view_loaded_cb (ESource *source,
+                           GAsyncResult *result,
+                           EAddressbookView *view)
 {
-	EAddressbookView *view = user_data;
-	EAddressbookModel *model;
-	ESource *source;
+	EBook *book;
+	GError *error = NULL;
 
-	source = e_book_get_source (book);
-	model = e_addressbook_view_get_model (view);
+	book = e_load_book_source_finish (source, result, &error);
 
-	if (!error) {
+	if (book != NULL) {
+		EAddressbookModel *model;
+
+		g_warn_if_fail (error == NULL);
+		model = e_addressbook_view_get_model (view);
 		e_addressbook_model_set_book (model, book);
 		e_addressbook_model_force_folder_bar_message (model);
-	} else if (!g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+
+	} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
 		eab_load_error_dialog (NULL /* XXX */, source, error);
+
+	if (error != NULL)
+		g_error_free (error);
+
+	g_object_unref (view);
 }
 
 static void
@@ -205,6 +211,7 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
                                           ESourceSelector *selector)
 {
 	EShellView *shell_view;
+	EShellWindow *shell_window;
 	EBookShellContent *book_shell_content;
 	EAddressbookView *view;
 	EAddressbookModel *model;
@@ -216,6 +223,8 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
 	gchar *view_id;
 
 	shell_view = E_SHELL_VIEW (book_shell_view);
+	shell_window = e_shell_view_get_shell_window (shell_view);
+
 	book_shell_content = book_shell_view->priv->book_shell_content;
 	source = e_source_selector_peek_primary_selection (selector);
 
@@ -227,8 +236,6 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
 	widget = g_hash_table_lookup (hash_table, uid);
 
 	if (widget != NULL) {
-		EBook *book;
-
 		/* There is a view for this UID.  Make sure the view
 		 * actually contains an EBook.  The absence of an EBook
 		 * suggests a previous load failed, so try again. */
@@ -236,16 +243,16 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
 		model = e_addressbook_view_get_model (view);
 		source = e_addressbook_view_get_source (view);
 
-		if (e_addressbook_model_get_book (model) == NULL) {
-			book = e_book_new (source, NULL);
-
-			if (book != NULL)
-				addressbook_load (book, book_open_cb, view);
-		}
+		if (e_addressbook_model_get_book (model) == NULL)
+			/* XXX No way to cancel this? */
+			e_load_book_source_async (
+				source,
+				GTK_WINDOW (shell_window),
+				NULL, (GAsyncReadyCallback)
+				book_shell_view_loaded_cb,
+				g_object_ref (view));
 
 	} else {
-		EBook *book;
-
 		/* Create a view for this UID. */
 		widget = e_addressbook_view_new (shell_view, source);
 		gtk_widget_show (widget);
@@ -282,20 +289,23 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
 			widget, "selection-change", G_CALLBACK (selection_change),
 			book_shell_view, G_CONNECT_SWAPPED);
 
-		book = e_book_new (source, NULL);
 		view = E_ADDRESSBOOK_VIEW (widget);
-
-		if (book != NULL)
-			addressbook_load (book, book_open_cb, view);
-
 		model = e_addressbook_view_get_model (view);
 
+		/* XXX No way to cancel this? */
+		e_load_book_source_async (
+			source, GTK_WINDOW (shell_window), NULL,
+			(GAsyncReadyCallback) book_shell_view_loaded_cb,
+			g_object_ref (view));
+
 		g_signal_connect_object (
-			model, "contact-changed", G_CALLBACK (contact_changed),
+			model, "contact-changed",
+			G_CALLBACK (contact_changed),
 			book_shell_view, G_CONNECT_SWAPPED);
 
 		g_signal_connect_object (
-			model, "contacts-removed", G_CALLBACK (contacts_removed),
+			model, "contacts-removed",
+			G_CALLBACK (contacts_removed),
 			book_shell_view, G_CONNECT_SWAPPED);
 	}
 
diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h
index 1a0c803..b719509 100644
--- a/modules/addressbook/e-book-shell-view-private.h
+++ b/modules/addressbook/e-book-shell-view-private.h
@@ -30,6 +30,7 @@
 #include <libebook/e-book.h>
 #include <libedataserver/e-categories.h>
 #include <libedataserver/e-sexp.h>
+#include <libedataserverui/e-book-auth-util.h>
 #include <libedataserverui/e-source-selector.h>
 
 #include "e-util/e-util.h"
diff --git a/plugins/vcard-inline/vcard-inline.c b/plugins/vcard-inline/vcard-inline.c
index 5d0c681..bf27e64 100644
--- a/plugins/vcard-inline/vcard-inline.c
+++ b/plugins/vcard-inline/vcard-inline.c
@@ -25,10 +25,10 @@
 #include <libebook/e-book.h>
 #include <libebook/e-contact.h>
 #include <gtkhtml/gtkhtml-embedded.h>
+#include <libedataserverui/e-book-auth-util.h>
 
 #include "addressbook/gui/merging/eab-contact-merging.h"
 #include "addressbook/gui/widgets/eab-contact-display.h"
-#include "addressbook/util/addressbook.h"
 #include "addressbook/util/eab-book-util.h"
 #include "mail/em-format-hook.h"
 #include "mail/em-format-html.h"
@@ -41,6 +41,7 @@ struct _VCardInlinePObject {
 	EMFormatHTMLPObject object;
 
 	GList *contact_list;
+	ESourceList *source_list;
 	GtkWidget *contact_display;
 	GtkWidget *message_label;
 };
@@ -70,6 +71,11 @@ org_gnome_vcard_inline_pobject_free (EMFormatHTMLPObject *object)
 	g_list_free (vcard_object->contact_list);
 	vcard_object->contact_list = NULL;
 
+	if (vcard_object->source_list != NULL) {
+		g_object_unref (vcard_object->source_list);
+		vcard_object->source_list = NULL;
+	}
+
 	if (vcard_object->contact_display != NULL) {
 		g_object_unref (vcard_object->contact_display);
 		vcard_object->contact_display = NULL;
@@ -113,24 +119,28 @@ org_gnome_vcard_inline_decode (VCardInlinePObject *vcard_object,
 }
 
 static void
-org_gnome_vcard_inline_book_open_cb (EBook *book,
-                                     const GError *error,
-                                     gpointer user_data)
+org_gnome_vcard_inline_book_loaded_cb (ESource *source,
+                                       GAsyncResult *result,
+                                       GList *contact_list)
 {
-	GList *contact_list = user_data;
+	EBook *book;
 	GList *iter;
 
-	if (error)
+	book = e_load_book_source_finish (source, result, NULL);
+
+	if (book == NULL)
 		goto exit;
 
-	for (iter = contact_list; iter != NULL; iter = iter->next)
-		eab_merging_book_add_contact (
-			book, E_CONTACT (iter->data), NULL, NULL);
+	for (iter = contact_list; iter != NULL; iter = iter->next) {
+		EContact *contact;
 
-exit:
-	if (book != NULL)
-		g_object_unref (book);
+		contact = E_CONTACT (iter->data);
+		eab_merging_book_add_contact (book, contact, NULL, NULL);
+	}
+
+	g_object_unref (book);
 
+exit:
 	g_list_foreach (contact_list, (GFunc) g_object_unref, NULL);
 	g_list_free (contact_list);
 }
@@ -138,13 +148,20 @@ exit:
 static void
 org_gnome_vcard_inline_save_cb (VCardInlinePObject *vcard_object)
 {
+	ESource *source;
 	GList *contact_list;
 
+	g_return_if_fail (vcard_object->source_list != NULL);
+
+	source = e_source_list_peek_default_source (vcard_object->source_list);
+	g_return_if_fail (source != NULL);
+
 	contact_list = g_list_copy (vcard_object->contact_list);
 	g_list_foreach (contact_list, (GFunc) g_object_ref, NULL);
 
-	addressbook_load_default_book (
-		org_gnome_vcard_inline_book_open_cb, contact_list);
+	e_load_book_source_async (
+		source, NULL, NULL, (GAsyncReadyCallback)
+		org_gnome_vcard_inline_book_loaded_cb, contact_list);
 }
 
 static void
@@ -257,7 +274,12 @@ org_gnome_vcard_inline_embed (EMFormatHTML *format,
 
 	widget = gtk_button_new_with_label (_("Save in Address Book"));
 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
-	gtk_widget_show (widget);
+
+	/* This depends on having a source list. */
+	if (vcard_object->source_list != NULL)
+		gtk_widget_show (widget);
+	else
+		gtk_widget_hide (widget);
 
 	g_signal_connect_swapped (
 		widget, "clicked",
@@ -289,6 +311,8 @@ org_gnome_vcard_inline_format (gpointer ep, EMFormatHookTarget *target)
 	vcard_object->object.free = org_gnome_vcard_inline_pobject_free;
 	org_gnome_vcard_inline_decode (vcard_object, target->part);
 
+	e_book_get_addressbooks (&vcard_object->source_list, NULL);
+
 	camel_stream_printf (
 		target->stream, "<object classid=%s></object>", classid);
 



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