From e583928e0401a4baea4432c5b7e12a1b1eff8c2e Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 23 Jan 2013 14:59:41 -0500 Subject: Use e_book_client_connect(). Instead of e_client_utils_open_new() and e_book_client_new(). --- addressbook/gui/contact-editor/e-contact-editor.c | 27 ++++++++--------- .../gui/contact-editor/e-contact-quick-add.c | 33 ++++++++++----------- .../contact-list-editor/e-contact-list-editor.c | 25 ++++++++-------- addressbook/gui/merging/eab-contact-compare.c | 15 ++++------ addressbook/gui/widgets/e-addressbook-selector.c | 34 ++++++++++------------ addressbook/gui/widgets/eab-gui-util.c | 24 +++++++-------- addressbook/importers/evolution-csv-importer.c | 15 ++++------ addressbook/importers/evolution-ldif-importer.c | 15 ++++------ addressbook/importers/evolution-vcard-importer.c | 15 ++++------ .../evolution-addressbook-export-list-cards.c | 13 +++++---- .../evolution-addressbook-export-list-folders.c | 14 +++++---- addressbook/util/eab-book-util.c | 32 +++++++++++--------- addressbook/util/eab-book-util.h | 6 ++-- 13 files changed, 130 insertions(+), 138 deletions(-) (limited to 'addressbook') diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index b168b79985..a0bd221f94 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -3084,16 +3084,21 @@ init_all (EContactEditor *editor) } static void -contact_editor_book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +contact_editor_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { ESource *source = E_SOURCE (source_object); EContactEditor *editor = user_data; - EClient *client = NULL; + EClient *client; GError *error = NULL; - e_client_utils_open_new_finish (source, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { @@ -3105,8 +3110,6 @@ contact_editor_book_loaded_cb (GObject *source_object, GtkWidget *source_combo_box; GtkWindow *parent; - g_warn_if_fail (client == NULL); - parent = eab_editor_get_window (EAB_EDITOR (editor)); eab_load_error_dialog (GTK_WIDGET (parent), NULL, source, error); @@ -3119,8 +3122,6 @@ contact_editor_book_loaded_cb (GObject *source_object, goto exit; } - g_return_if_fail (E_IS_CLIENT (client)); - /* FIXME Write a private contact_editor_set_target_client(). */ g_object_set (editor, "target_client", client, NULL); @@ -3162,10 +3163,10 @@ source_changed (ESourceComboBox *source_combo_box, editor->cancellable = g_cancellable_new (); - e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_CONTACTS, - FALSE, editor->cancellable, - contact_editor_book_loaded_cb, g_object_ref (editor)); + e_book_client_connect ( + source, editor->cancellable, + contact_editor_client_connect_cb, + g_object_ref (editor)); exit: g_object_unref (source); diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c index 6dcb7dc628..afbd817ac7 100644 --- a/addressbook/gui/contact-editor/e-contact-quick-add.c +++ b/addressbook/gui/contact-editor/e-contact-quick-add.c @@ -126,10 +126,15 @@ merge_cb (GObject *source_object, { ESource *source = E_SOURCE (source_object); QuickAdd *qa = user_data; - EClient *client = NULL; + EClient *client; GError *error = NULL; - e_client_utils_open_new_finish (source, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); /* Ignore cancellations. */ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) || @@ -140,7 +145,6 @@ merge_cb (GObject *source_object, } if (error != NULL) { - g_warn_if_fail (client == NULL); if (qa->cb) qa->cb (NULL, qa->closure); g_error_free (error); @@ -148,8 +152,6 @@ merge_cb (GObject *source_object, return; } - g_return_if_fail (E_IS_CLIENT (client)); - if (!e_client_is_readonly (client)) eab_merging_book_add_contact ( qa->registry, E_BOOK_CLIENT (client), @@ -179,9 +181,7 @@ quick_add_merge_contact (QuickAdd *qa) qa->cancellable = g_cancellable_new (); - e_client_utils_open_new ( - qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS, - FALSE, qa->cancellable, merge_cb, qa); + e_book_client_connect (qa->source, qa->cancellable, merge_cb, qa); } /* Raise a contact editor with all fields editable, @@ -279,12 +279,16 @@ ce_have_book (GObject *source_object, GAsyncResult *result, gpointer user_data) { - ESource *source = E_SOURCE (source_object); QuickAdd *qa = user_data; - EClient *client = NULL; + EClient *client; GError *error = NULL; - e_client_utils_open_new_finish (source, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); /* Ignore cancellations. */ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) || @@ -295,7 +299,6 @@ ce_have_book (GObject *source_object, } if (error != NULL) { - g_warn_if_fail (client == NULL); g_warning ( "Couldn't open local address book (%s).", error->message); @@ -304,8 +307,6 @@ ce_have_book (GObject *source_object, return; } - g_return_if_fail (E_IS_CLIENT (client)); - eab_merging_book_find_contact ( qa->registry, E_BOOK_CLIENT (client), qa->contact, ce_have_contact, qa); @@ -321,9 +322,7 @@ edit_contact (QuickAdd *qa) qa->cancellable = g_cancellable_new (); - e_client_utils_open_new ( - qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS, - FALSE, qa->cancellable, ce_have_book, qa); + e_book_client_connect (qa->source, qa->cancellable, ce_have_book, qa); } #define QUICK_ADD_RESPONSE_EDIT_FULL 2 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 58ea7046dc..6f92e511de 100644 --- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c +++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c @@ -301,26 +301,29 @@ contact_list_editor_add_email (EContactListEditor *editor, } static void -contact_list_editor_book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +contact_list_editor_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { ESource *source = E_SOURCE (source_object); EContactListEditor *editor = user_data; EContactListEditorPrivate *priv = editor->priv; EContactStore *contact_store; ENameSelectorEntry *entry; - EClient *client = NULL; + EClient *client; EBookClient *book_client; GError *error = NULL; - e_client_utils_open_new_finish (source, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); if (error != NULL) { GtkWindow *parent; - g_warn_if_fail (client == NULL); - parent = eab_editor_get_window (EAB_EDITOR (editor)); eab_load_error_dialog (GTK_WIDGET (parent), NULL, source, error); @@ -332,8 +335,6 @@ contact_list_editor_book_loaded_cb (GObject *source_object, goto exit; } - g_return_if_fail (E_IS_CLIENT (client)); - book_client = E_BOOK_CLIENT (client); entry = E_NAME_SELECTOR_ENTRY (WIDGET (EMAIL_ENTRY)); @@ -977,9 +978,9 @@ contact_list_editor_source_menu_changed_cb (GtkWidget *widget) client_source = e_client_get_source (client); if (!e_source_equal (client_source, active_source)) - e_client_utils_open_new ( - active_source, E_CLIENT_SOURCE_TYPE_CONTACTS, - FALSE, NULL, contact_list_editor_book_loaded_cb, + e_book_client_connect ( + active_source, NULL, + contact_list_editor_client_connect_cb, g_object_ref (editor)); g_object_unref (active_source); diff --git a/addressbook/gui/merging/eab-contact-compare.c b/addressbook/gui/merging/eab-contact-compare.c index 1cd5228873..bfca37cbff 100644 --- a/addressbook/gui/merging/eab-contact-compare.c +++ b/addressbook/gui/merging/eab-contact-compare.c @@ -768,15 +768,14 @@ use_common_book_client (EBookClient *book_client, } static void -book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +book_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *source = E_SOURCE (source_object); MatchSearchInfo *info = user_data; - EClient *client = NULL; + EClient *client; - e_client_utils_open_new_finish (source, result, &client, NULL); + client = e_book_client_connect_finish (result, NULL); /* Client may be NULL; don't use a type cast macro. */ use_common_book_client ((EBookClient *) client, info); @@ -833,9 +832,7 @@ eab_contact_locate_match_full (ESourceRegistry *registry, source = e_source_registry_ref_default_address_book (registry); - e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - book_loaded_cb, info); + e_book_client_connect (source, NULL, book_client_connect_cb, info); g_object_unref (source); } diff --git a/addressbook/gui/widgets/e-addressbook-selector.c b/addressbook/gui/widgets/e-addressbook-selector.c index 2441a0bc89..eedc776a6c 100644 --- a/addressbook/gui/widgets/e-addressbook-selector.c +++ b/addressbook/gui/widgets/e-addressbook-selector.c @@ -247,29 +247,30 @@ addressbook_selector_constructed (GObject *object) } static void -target_client_open_ready_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +target_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *source = E_SOURCE (source_object); MergeContext *merge_context = user_data; - EClient *client = NULL; + EClient *client; GError *error = NULL; g_return_if_fail (merge_context != NULL); - e_client_utils_open_new_finish (source, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); if (error != NULL) { - g_warn_if_fail (client == NULL); g_warning ( "%s: Failed to open targer client: %s", G_STRFUNC, error->message); g_error_free (error); } - g_return_if_fail (E_IS_CLIENT (client)); - merge_context->target_client = client ? E_BOOK_CLIENT (client) : NULL; if (!merge_context->target_client) { @@ -299,7 +300,7 @@ addressbook_selector_data_dropped (ESourceSelector *selector, EAddressbookSelectorPrivate *priv; MergeContext *merge_context; EAddressbookModel *model; - EBookClient *source_client = NULL; + EBookClient *source_client; ESourceRegistry *registry; GSList *list; const gchar *string; @@ -314,12 +315,8 @@ addressbook_selector_data_dropped (ESourceSelector *selector, model = e_addressbook_view_get_model (priv->current_view); registry = e_addressbook_model_get_registry (model); - /* XXX Function assumes both out arguments are provided. All we - * care about is the contact list; source_client will be NULL. */ - eab_book_and_contact_list_from_string ( - registry, string, &source_client, &list); - if (source_client) - g_object_unref (source_client); + eab_source_and_contact_list_from_string ( + registry, string, NULL, &list); if (list == NULL) return FALSE; @@ -332,9 +329,8 @@ addressbook_selector_data_dropped (ESourceSelector *selector, merge_context->remove_from_source = remove_from_source; merge_context->pending_adds = TRUE; - e_client_utils_open_new ( - destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - target_client_open_ready_cb, merge_context); + e_book_client_connect ( + destination, NULL, target_client_connect_cb, merge_context); return TRUE; } diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index 089c12b573..2f0f29ea23 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -524,19 +524,22 @@ do_copy (gpointer data, } static void -book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +book_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *destination = E_SOURCE (source_object); ContactCopyProcess *process = user_data; - EClient *client = NULL; + EClient *client; GError *error = NULL; - e_client_utils_open_new_finish (destination, result, &client, &error); + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); if (error != NULL) { - g_warn_if_fail (client == NULL); g_warning ( "%s: Failed to open destination client: %s", G_STRFUNC, error->message); @@ -544,8 +547,6 @@ book_loaded_cb (GObject *source_object, goto exit; } - g_return_if_fail (E_IS_CLIENT (client)); - process->destination = E_BOOK_CLIENT (client); process->book_status = TRUE; g_slist_foreach (process->contacts, do_copy, process); @@ -612,9 +613,8 @@ eab_transfer_contacts (ESourceRegistry *registry, process->alert_sink = alert_sink; process->delete_from_source = delete_from_source; - e_client_utils_open_new ( - destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - book_loaded_cb, process); + e_book_client_connect ( + destination, NULL, book_client_connect_cb, process); } /* diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c index 38ba5cacbf..6d5423e064 100644 --- a/addressbook/importers/evolution-csv-importer.c +++ b/addressbook/importers/evolution-csv-importer.c @@ -871,15 +871,14 @@ csv_import_done (CSVImporter *gci) } static void -book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +book_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *source = E_SOURCE (source_object); CSVImporter *gci = user_data; - EClient *client = NULL; + EClient *client; - e_client_utils_open_new_finish (source, result, &client, NULL); + client = e_book_client_connect_finish (result, NULL); if (client == NULL) { csv_import_done (gci); @@ -928,9 +927,7 @@ csv_import (EImport *ei, source = g_datalist_get_data (&target->data, "csv-source"); - e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - book_loaded_cb, gci); + e_book_client_connect (source, NULL, book_client_connect_cb, gci); } static void diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c index 3ecde6f6f3..ae8fb5ac95 100644 --- a/addressbook/importers/evolution-ldif-importer.c +++ b/addressbook/importers/evolution-ldif-importer.c @@ -663,15 +663,14 @@ ldif_import_done (LDIFImporter *gci) } static void -book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +book_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *source = E_SOURCE (source_object); LDIFImporter *gci = user_data; - EClient *client = NULL; + EClient *client; - e_client_utils_open_new_finish (source, result, &client, NULL); + client = e_book_client_connect_finish (result, NULL); if (client == NULL) { ldif_import_done (gci); @@ -719,9 +718,7 @@ ldif_import (EImport *ei, source = g_datalist_get_data (&target->data, "ldif-source"); - e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - book_loaded_cb, gci); + e_book_client_connect (source, NULL, book_client_connect_cb, gci); } static void diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c index b7ee8660ca..09778b5f21 100644 --- a/addressbook/importers/evolution-vcard-importer.c +++ b/addressbook/importers/evolution-vcard-importer.c @@ -491,15 +491,14 @@ vcard_import_done (VCardImporter *gci) } static void -book_loaded_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +book_client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - ESource *source = E_SOURCE (source_object); VCardImporter *gci = user_data; - EClient *client = NULL; + EClient *client; - e_client_utils_open_new_finish (source, result, &client, NULL); + client = e_book_client_connect_finish (result, NULL); if (client == NULL) { vcard_import_done (gci); @@ -579,9 +578,7 @@ vcard_import (EImport *ei, source = g_datalist_get_data (&target->data, "vcard-source"); - e_client_utils_open_new ( - source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - book_loaded_cb, gci); + e_book_client_connect (source, NULL, book_client_connect_cb, gci); } static void diff --git a/addressbook/tools/evolution-addressbook-export-list-cards.c b/addressbook/tools/evolution-addressbook-export-list-cards.c index 977fd9cac4..eee2fe92b7 100644 --- a/addressbook/tools/evolution-addressbook-export-list-cards.c +++ b/addressbook/tools/evolution-addressbook-export-list-cards.c @@ -771,6 +771,7 @@ guint action_list_cards_init (ESourceRegistry *registry, ActionContext *p_actctx) { + EClient *client; EBookClient *book_client; EBookQuery *query; ESource *source; @@ -788,12 +789,14 @@ action_list_cards_init (ESourceRegistry *registry, else source = e_source_registry_ref_default_address_book (registry); - book_client = e_book_client_new (source, &error); + client = e_book_client_connect_sync (source, NULL, &error); g_object_unref (source); - if (book_client != NULL) - e_client_open_sync (E_CLIENT (book_client), TRUE, NULL, &error); + /* Sanity check. */ + g_return_val_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL)), FAILED); if (error != NULL) { g_warning ( @@ -801,13 +804,11 @@ action_list_cards_init (ESourceRegistry *registry, p_actctx->action_list_cards.addressbook_source_uid ? p_actctx->action_list_cards.addressbook_source_uid : "'default'", error->message); - if (book_client != NULL) - g_object_unref (book_client); g_error_free (error); exit (-1); } - g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), FAILED); + book_client = E_BOOK_CLIENT (client); query = e_book_query_any_field_contains (""); query_str = e_book_query_to_string (query); diff --git a/addressbook/tools/evolution-addressbook-export-list-folders.c b/addressbook/tools/evolution-addressbook-export-list-folders.c index bfaf110cb9..29c44dbeba 100644 --- a/addressbook/tools/evolution-addressbook-export-list-folders.c +++ b/addressbook/tools/evolution-addressbook-export-list-folders.c @@ -52,6 +52,7 @@ action_list_folders_init (ESourceRegistry *registry, list = e_source_registry_list_sources (registry, extension_name); for (iter = list; iter != NULL; iter = g_list_next (iter)) { + EClient *client; EBookClient *book_client; EBookQuery *query; ESource *source; @@ -63,23 +64,24 @@ action_list_folders_init (ESourceRegistry *registry, source = E_SOURCE (iter->data); - book_client = e_book_client_new (source, &error); + client = e_book_client_connect_sync (source, NULL, &error); - if (book_client != NULL) - e_client_open_sync ( - E_CLIENT (book_client), TRUE, NULL, &error); + /* Sanity check. */ + g_return_val_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL)), FAILED); if (error != NULL) { g_warning ( _("Failed to open client '%s': %s"), e_source_get_display_name (source), error->message); - if (book_client != NULL) - g_object_unref (book_client); g_error_free (error); continue; } + book_client = E_BOOK_CLIENT (client); + query = e_book_query_any_field_contains (""); query_str = e_book_query_to_string (query); e_book_query_unref (query); diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c index 161d848ce6..d7c0941c69 100644 --- a/addressbook/util/eab-book-util.c +++ b/addressbook/util/eab-book-util.c @@ -150,21 +150,24 @@ eab_contact_list_to_string (const GSList *contacts) } gboolean -eab_book_and_contact_list_from_string (ESourceRegistry *registry, - const gchar *str, - EBookClient **book_client, - GSList **contacts) +eab_source_and_contact_list_from_string (ESourceRegistry *registry, + const gchar *str, + ESource **out_source, + GSList **out_contacts) { ESource *source; const gchar *s0, *s1; gchar *uid; + gboolean success = FALSE; g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE); g_return_val_if_fail (str != NULL, FALSE); - g_return_val_if_fail (book_client != NULL, FALSE); - g_return_val_if_fail (contacts != NULL, FALSE); - *contacts = eab_contact_list_from_string (str); + if (out_source != NULL) + *out_source = NULL; /* in case we fail */ + + if (out_contacts != NULL) + *out_contacts = NULL; /* in case we fail */ if (!strncmp (str, "Book: ", 6)) { s0 = str + 6; @@ -177,22 +180,23 @@ eab_book_and_contact_list_from_string (ESourceRegistry *registry, s1 = NULL; } - if (!s0 || !s1) { - *book_client = NULL; + if (!s0 || !s1) return FALSE; - } uid = g_strndup (s0, s1 - s0); source = e_source_registry_ref_source (registry, uid); if (source != NULL) { - *book_client = e_book_client_new (source, NULL); + if (out_source != NULL) + *out_source = g_object_ref (source); g_object_unref (source); - } else { - *book_client = NULL; + success = TRUE; } g_free (uid); - return (*book_client != NULL); + if (success && out_contacts != NULL) + *out_contacts = eab_contact_list_from_string (str); + + return success; } gchar * diff --git a/addressbook/util/eab-book-util.h b/addressbook/util/eab-book-util.h index 45602c2547..559aa79714 100644 --- a/addressbook/util/eab-book-util.h +++ b/addressbook/util/eab-book-util.h @@ -31,11 +31,11 @@ G_BEGIN_DECLS GSList * eab_contact_list_from_string (const gchar *str); gchar * eab_contact_list_to_string (const GSList *contacts); -gboolean eab_book_and_contact_list_from_string +gboolean eab_source_and_contact_list_from_string (ESourceRegistry *registry, const gchar *str, - EBookClient **book_client, - GSList **contacts); + ESource **out_source, + GSList **out_contacts); gchar * eab_book_and_contact_list_to_string (EBookClient *book_client, const GSList *contacts); -- cgit v1.2.3