From a536d74906984acd16902606ac574db676344194 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 18 Aug 2010 15:49:49 -0400 Subject: 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/widgets/eab-gui-util.c | 56 +++++++++++++++++++++------------- addressbook/gui/widgets/eab-gui-util.h | 38 +++++++++++------------ 2 files changed, 53 insertions(+), 41 deletions(-) (limited to 'addressbook/gui/widgets') diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index 8e3a6a4e38..9ca8033291 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include "eab-gui-util.h" @@ -45,8 +46,6 @@ /* we link to camel for decoding quoted printable email addresses */ #include -#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 5f8890feb2..e1fd43fdf3 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, -- cgit v1.2.3