From 79a4d5a123547b18d9e513e3fb02eb4bf9999451 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 13 Aug 2002 01:01:58 +0000 Subject: If invoked from a non-contact folder, add the contact to the default * gui/component/addressbook-component.c (user_create_new_item_cb): If invoked from a non-contact folder, add the contact to the default contact folder, not the local one. If invoked from a contact folder, don't append "addressbook.db" to the URI, let ebook do the right thing. Fixes #28327 and #28325. * backend/idl/addressbook.idl (CallStatus): Add NoSuchBook. (Initially intended as part of a fix for #28327, but the other changes make it so the error code never ends up getting used any more, but it's still good to have.) * gui/widgets/e-addressbook-util.c (e_addressbook_error_dialog): Handle NO_SUCH_BOOK. * backend/ebook/e-book-types.h (EBookStatus): Add E_BOOK_STATUS_NO_SUCH_BOOK. * backend/ebook/e-book-listener.c (e_book_listener_convert_status): add case for NoSuchBook. * backend/ebook/e-book-util.c (e_book_load_local_address_book): Kill this. Nothing should ever explicitly load the local addressbook. (e_book_use_default_book): Replaces e_book_use_local_address_book, using the default book instead. (e_book_default_book_open): Fall back to local contact folder on E_BOOK_STATUS_NO_SUCH_BOOK too. (e_book_query_address_default): Use default book, not local. * gui/component/e-address-widget.c (query_idle_fn): Use the default book, not the local book. * gui/component/select-names/e-select-names-popup.c (edit_contact_info_cb): Use the default book, not the local book. * backend/ebook/e-destination.c (e_destination_cardify): Use the default book, not the local book. (e_destination_touch): Query the default book, not the local book. * backend/ebook/e-card-compare.c (e_card_locate_match, e_card_locate_match_full): Use the default book, not the local book. svn path=/trunk/; revision=17764 --- addressbook/backend/ebook/e-book-util.c | 127 +++++++++++++++----------------- 1 file changed, 59 insertions(+), 68 deletions(-) (limited to 'addressbook/backend/ebook/e-book-util.c') diff --git a/addressbook/backend/ebook/e-book-util.c b/addressbook/backend/ebook/e-book-util.c index ff388105f0..e113e8c607 100644 --- a/addressbook/backend/ebook/e-book-util.c +++ b/addressbook/backend/ebook/e-book-util.c @@ -131,53 +131,27 @@ e_book_get_config_database (CORBA_Environment *ev) return config_db; } -gboolean -e_book_load_local_address_book (EBook *book, EBookCallback open_response, gpointer closure) -{ - gchar *filename; - gchar *uri; - gboolean rv; - - g_return_val_if_fail (book != NULL, FALSE); - g_return_val_if_fail (E_IS_BOOK (book), FALSE); - g_return_val_if_fail (open_response != NULL, FALSE); - - filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf ("file://%s", filename); - - rv = e_book_load_uri (book, uri, open_response, closure); - - if (!rv) { - g_warning ("Couldn't load local addressbook %s", uri); - } - - g_free (filename); - g_free (uri); - - return rv; -} - -static EBook *common_local_book = NULL; +static EBook *common_default_book = NULL; static void -got_local_book_cb (EBook *book, EBookStatus status, gpointer closure) +got_default_book_cb (EBook *book, EBookStatus status, gpointer closure) { CommonBookInfo *info = (CommonBookInfo *) closure; if (status == E_BOOK_STATUS_SUCCESS) { /* We try not to leak in a race condition where the - local book got loaded twice. */ + default book got loaded twice. */ - if (common_local_book) { + if (common_default_book) { gtk_object_unref (GTK_OBJECT (book)); - book = common_local_book; + book = common_default_book; } info->cb (book, info->closure); - if (common_local_book == NULL) { - common_local_book = book; + if (common_default_book == NULL) { + common_default_book = book; } } else { @@ -189,15 +163,15 @@ got_local_book_cb (EBook *book, EBookStatus status, gpointer closure) } void -e_book_use_local_address_book (EBookCommonCallback cb, gpointer closure) +e_book_use_default_book (EBookCommonCallback cb, gpointer closure) { EBook *book; CommonBookInfo *info; g_return_if_fail (cb != NULL); - if (common_local_book != NULL) { - cb (common_local_book, closure); + if (common_default_book != NULL) { + cb (common_default_book, closure); return; } @@ -206,12 +180,46 @@ e_book_use_local_address_book (EBookCommonCallback cb, gpointer closure) info->closure = closure; book = e_book_new (); - if (! e_book_load_local_address_book (book, got_local_book_cb, info)) { + if (! e_book_load_default_book (book, got_default_book_cb, info)) { gtk_object_unref (GTK_OBJECT (book)); g_free (info); } } +static char *default_book_uri; + +static void +set_default_book_uri_local (void) +{ + char *filename; + + if (default_book_uri) + g_free (default_book_uri); + + filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db"); + default_book_uri = g_strdup_printf ("file://%s", filename); + g_free (filename); +} + +static void +set_default_book_uri_from_bonobo_conf (void) +{ + CORBA_Environment ev; + char *val; + Bonobo_ConfigDatabase config_db; + + CORBA_exception_init (&ev); + config_db = e_book_get_config_database (&ev); + val = bonobo_config_get_string (config_db, "/DefaultFolders/contacts_uri", &ev); + CORBA_exception_free (&ev); + + if (val) { + default_book_uri = e_book_expand_uri (val); + g_free (val); + } else + set_default_book_uri_local (); +} + typedef struct { gpointer closure; EBookCallback open_response; @@ -226,15 +234,15 @@ e_book_default_book_open (EBook *book, EBookStatus status, gpointer closure) g_free (default_book_closure); - /* special case the protocol not supported error, since we - really only want to failover to the local book in the case - where there's no installed backend for that protocol. all - other errors (failure to connect, etc.) should get reported - to the caller as normal. */ - if (status == E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED) { - e_book_load_local_address_book (book, user_response, user_closure); - } - else { + /* If there's a transient error, report it to the caller, but + * if the old default folder has disappeared, fall back to + * the local contacts folder instead. + */ + if (status == E_BOOK_STATUS_PROTOCOL_NOT_SUPPORTED || + status == E_BOOK_STATUS_NO_SUCH_BOOK) { + set_default_book_uri_local (); + e_book_load_default_book (book, user_response, user_closure); + } else { user_response (book, status, user_closure); } } @@ -259,7 +267,6 @@ e_book_load_default_book (EBook *book, EBookCallback open_response, gpointer clo rv = e_book_load_uri (book, uri, e_book_default_book_open, default_book_closure); - g_free (uri); if (!rv) { g_warning ("Couldn't load default addressbook"); @@ -271,26 +278,10 @@ e_book_load_default_book (EBook *book, EBookCallback open_response, gpointer clo char* e_book_get_default_book_uri () { - CORBA_Environment ev; - char *val, *uri; - Bonobo_ConfigDatabase config_db; - - CORBA_exception_init (&ev); - config_db = e_book_get_config_database (&ev); - val = bonobo_config_get_string (config_db, "/DefaultFolders/contacts_uri", &ev); - CORBA_exception_free (&ev); - - if (val) { - uri = e_book_expand_uri (val); - g_free (val); - } else { - char *filename; - filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf ("file://%s", filename); - g_free (filename); - } + if (!default_book_uri) + set_default_book_uri_from_bonobo_conf (); - return uri; + return default_book_uri; } /* @@ -752,7 +743,7 @@ have_address_book_open_cb (EBook *book, gpointer closure) } void -e_book_query_address_locally (const gchar *email, +e_book_query_address_default (const gchar *email, EBookHaveAddressCallback cb, gpointer closure) { @@ -766,5 +757,5 @@ e_book_query_address_locally (const gchar *email, info->cb = cb; info->closure = closure; - e_book_use_local_address_book (have_address_book_open_cb, info); + e_book_use_default_book (have_address_book_open_cb, info); } -- cgit v1.2.3