diff options
author | Milan Crha <mcrha@redhat.com> | 2010-07-09 20:29:51 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2010-07-09 20:29:51 +0800 |
commit | 03d626856b294bc98919ac244e04e9b8821a681d (patch) | |
tree | 62433e158f1791aa6b9222ecbe05d164c4703f6c /addressbook/util | |
parent | 6d4ce8571ff62a3e489999d2feeac1691e06c59a (diff) | |
download | gsoc2013-evolution-03d626856b294bc98919ac244e04e9b8821a681d.tar.gz gsoc2013-evolution-03d626856b294bc98919ac244e04e9b8821a681d.tar.zst gsoc2013-evolution-03d626856b294bc98919ac244e04e9b8821a681d.zip |
Bug #623204 - Be able to report detailed errors from backends
Diffstat (limited to 'addressbook/util')
-rw-r--r-- | addressbook/util/addressbook.c | 68 | ||||
-rw-r--r-- | addressbook/util/addressbook.h | 4 | ||||
-rw-r--r-- | addressbook/util/eab-book-util.c | 8 | ||||
-rw-r--r-- | addressbook/util/eab-book-util.h | 4 |
4 files changed, 44 insertions, 40 deletions
diff --git a/addressbook/util/addressbook.c b/addressbook/util/addressbook.c index b394319c0f..2185434d00 100644 --- a/addressbook/util/addressbook.c +++ b/addressbook/util/addressbook.c @@ -37,11 +37,11 @@ #define d(x) static void addressbook_authenticate (EBook *book, gboolean previous_failure, - ESource *source, EBookCallback cb, gpointer closure); + ESource *source, EBookExCallback cb, gpointer closure); static void auth_required_cb (EBook *book, gpointer data); typedef struct { - EBookCallback cb; + EBookExCallback cb; ESource *source; gpointer closure; guint cancelled : 1; @@ -71,7 +71,7 @@ remove_parameters_from_uri (const gchar *uri) } static void -load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure) +load_source_auth_cb (EBook *book, const GError *error, gpointer closure) { LoadSourceData *data = closure; gboolean was_in = g_object_get_data (G_OBJECT (book), "authenticated") != NULL; @@ -83,10 +83,10 @@ load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure) return; } - if (status != E_BOOK_ERROR_OK) { + if (error) { /* the user clicked cancel in the password dialog */ - if (status == E_BOOK_ERROR_CANCELLED) { + if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) { if (e_book_check_static_capability (book, "anon-access")) { @@ -103,20 +103,20 @@ load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure) "%s", _("Accessing LDAP Server anonymously")); g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); gtk_widget_show (dialog); - status = E_BOOK_ERROR_OK; + error = NULL; goto done; } - } else if (status == E_BOOK_ERROR_INVALID_SERVER_VERSION) { + } else if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_INVALID_SERVER_VERSION)) { e_alert_run_dialog_for_args (e_shell_get_active_window (NULL), "addressbook:server-version", NULL); - status = E_BOOK_ERROR_OK; + error = NULL; goto done; - } else if (status == E_BOOK_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD) { + } else if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD)) { goto done; } else { - if (status == E_BOOK_ERROR_AUTHENTICATION_FAILED) { + if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_AUTHENTICATION_FAILED)) { const gchar *uri = e_book_get_uri (book); gchar *stripped_uri = remove_parameters_from_uri (uri); const gchar *auth_domain = e_source_get_property (data->source, "auth-domain"); @@ -142,7 +142,7 @@ load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure) done: if (data->cb) - data->cb (book, status, data->closure); + data->cb (book, error, data->closure); free_load_source_data (data); } @@ -168,7 +168,7 @@ set_remember_password (ESource *source, gboolean value) static void addressbook_authenticate (EBook *book, gboolean previous_failure, ESource *source, - EBookCallback cb, gpointer closure) + EBookExCallback cb, gpointer closure) { const gchar *password = NULL; gchar *pass_dup = NULL; @@ -231,14 +231,18 @@ addressbook_authenticate (EBook *book, gboolean previous_failure, ESource *sourc } if (password || pass_dup) { - e_book_async_authenticate_user (book, user, password ? password : pass_dup, - e_source_get_property (source, "auth"), - cb, closure); + e_book_async_authenticate_user_ex (book, user, password ? password : pass_dup, + e_source_get_property (source, "auth"), + cb, closure); g_free (pass_dup); } else { + GError *error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED, _("Cancelled")); + /* they hit cancel */ - cb (book, E_BOOK_ERROR_CANCELLED, closure); + cb (book, error, closure); + + g_error_free (error); } g_free (uri); @@ -256,7 +260,7 @@ auth_required_cb (EBook *book, gpointer data) } static void -load_source_cb (EBook *book, EBookStatus status, gpointer closure) +load_source_cb (EBook *book, const GError *error, gpointer closure) { LoadSourceData *load_source_data = closure; @@ -265,7 +269,7 @@ load_source_cb (EBook *book, EBookStatus status, gpointer closure) return; } - if (status == E_BOOK_ERROR_OK && book != NULL) { + if (!error && book != NULL) { const gchar *auth; auth = e_source_get_property (load_source_data->source, "auth"); @@ -279,13 +283,13 @@ load_source_cb (EBook *book, EBookStatus status, gpointer closure) } } } - load_source_data->cb (book, status, load_source_data->closure); + load_source_data->cb (book, error, load_source_data->closure); free_load_source_data (load_source_data); } guint addressbook_load (EBook *book, - EBookCallback cb, gpointer closure) + EBookExCallback cb, gpointer closure) { LoadSourceData *load_source_data = g_new0 (LoadSourceData, 1); @@ -294,7 +298,7 @@ addressbook_load (EBook *book, load_source_data->source = g_object_ref (g_object_ref (e_book_get_source (book))); load_source_data->cancelled = FALSE; - e_book_async_open (book, FALSE, load_source_cb, load_source_data); + e_book_async_open_ex (book, FALSE, load_source_cb, load_source_data); return GPOINTER_TO_UINT (load_source_data); } @@ -308,33 +312,33 @@ addressbook_load_cancel (guint id) } static void -default_book_cb (EBook *book, EBookStatus status, gpointer closure) +default_book_cb (EBook *book, const GError *error, gpointer closure) { LoadSourceData *load_source_data = closure; - if (status == E_BOOK_ERROR_OK) + if (!error) load_source_data->source = g_object_ref (e_book_get_source (book)); - load_source_cb (book, status, closure); + load_source_cb (book, error, closure); } void -addressbook_load_default_book (EBookCallback cb, gpointer closure) +addressbook_load_default_book (EBookExCallback cb, gpointer closure) { LoadSourceData *load_source_data = g_new (LoadSourceData, 1); EBook *book; + GError *error = NULL; load_source_data->cb = cb; load_source_data->source = NULL; load_source_data->closure = closure; load_source_data->cancelled = FALSE; - book = e_book_new_default_addressbook (NULL); - if (!book) - /* XXX We should just use a GError and its error code here. */ - load_source_cb ( - NULL, E_BOOK_ERROR_OTHER_ERROR, load_source_data); - else - e_book_async_open ( + book = e_book_new_default_addressbook (&error); + if (!book) { + load_source_cb (NULL, error, load_source_data); + g_error_free (error); + } else + e_book_async_open_ex ( book, FALSE, default_book_cb, load_source_data); } diff --git a/addressbook/util/addressbook.h b/addressbook/util/addressbook.h index 7bc92ee344..fca409ed8c 100644 --- a/addressbook/util/addressbook.h +++ b/addressbook/util/addressbook.h @@ -24,8 +24,8 @@ #include <libebook/e-book.h> -guint addressbook_load (EBook *book, EBookCallback cb, gpointer closure); +guint addressbook_load (EBook *book, EBookExCallback cb, gpointer closure); void addressbook_load_cancel (guint id); -void addressbook_load_default_book (EBookCallback open_response, gpointer closure); +void addressbook_load_default_book (EBookExCallback open_response, gpointer closure); #endif /* __ADDRESSBOOK_H__ */ diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c index 40180d4631..2b1966684e 100644 --- a/addressbook/util/eab-book-util.c +++ b/addressbook/util/eab-book-util.c @@ -58,7 +58,7 @@ guint eab_name_and_email_query (EBook *book, const gchar *name, const gchar *email, - EBookListCallback cb, + EBookListExCallback cb, gpointer closure) { gchar *email_query=NULL, *name_query=NULL; @@ -119,7 +119,7 @@ eab_name_and_email_query (EBook *book, else return 0; - tag = e_book_async_get_contacts (book, query, cb, closure); + tag = e_book_async_get_contacts_ex (book, query, cb, closure); g_free (email_query); g_free (name_query); @@ -136,7 +136,7 @@ eab_name_and_email_query (EBook *book, guint eab_nickname_query (EBook *book, const gchar *nickname, - EBookListCallback cb, + EBookListExCallback cb, gpointer closure) { EBookQuery *query; @@ -154,7 +154,7 @@ eab_nickname_query (EBook *book, query = e_book_query_from_string (query_string); - retval = e_book_async_get_contacts (book, query, cb, closure); + retval = e_book_async_get_contacts_ex (book, query, cb, closure); g_free (query_string); e_book_query_unref (query); diff --git a/addressbook/util/eab-book-util.h b/addressbook/util/eab-book-util.h index 9f8a79eae1..edc7c3ebe6 100644 --- a/addressbook/util/eab-book-util.h +++ b/addressbook/util/eab-book-util.h @@ -34,11 +34,11 @@ typedef void (*EABHaveAddressCallback) (EBook *book, const gchar *addr, EContact guint eab_name_and_email_query (EBook *book, const gchar *name, const gchar *email, - EBookListCallback cb, + EBookListExCallback cb, gpointer closure); guint eab_nickname_query (EBook *book, const gchar *nickname, - EBookListCallback cb, + EBookListExCallback cb, gpointer closure); GList *eab_contact_list_from_string (const gchar *str); |