| From 3c4a6eda580c6e38aeedb63d73ae7b96cc7f9a07 Mon Sep 17 00:00:00 2001 |
| From: Carlos Garcia Campos <cgarcia@igalia.com> |
| Date: Mon, 7 Jun 2021 16:31:18 +0200 |
| Subject: [PATCH] Update to rest 1.0 |
| |
| Updates to use the rest 1.0 API |
| |
| Upstream-Status: Inappropriate [rest 1.0 is not released yet] |
| |
| Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> |
| --- |
| configure.ac | 2 +- |
| src/goabackend/goalastfmprovider.c | 26 +++++++++++++------------- |
| src/goabackend/goaoauthprovider.c | 17 +++++++++++------ |
| src/goabackend/goarestproxy.h | 2 -- |
| 4 files changed, 25 insertions(+), 22 deletions(-) |
| |
| diff --git a/configure.ac b/configure.ac |
| index 1f88bbd..e43303d 100644 |
| --- a/configure.ac |
| +++ b/configure.ac |
| @@ -129,7 +129,7 @@ if test "$enable_backend" != "no"; then |
| AC_SUBST(JSON_GLIB_CFLAGS) |
| AC_SUBST(JSON_GLIB_LIBS) |
| |
| - PKG_CHECK_MODULES(REST, [rest-0.7]) |
| + PKG_CHECK_MODULES(REST, [rest-1.0]) |
| AC_SUBST(REST_CFLAGS) |
| AC_SUBST(REST_LIBS) |
| |
| diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c |
| index cb9a6f2..a2db037 100644 |
| --- a/src/goabackend/goalastfmprovider.c |
| +++ b/src/goabackend/goalastfmprovider.c |
| @@ -483,18 +483,18 @@ add_account_cb (GoaManager *manager, GAsyncResult *res, gpointer user_data) |
| |
| static void |
| check_cb (RestProxyCall *call, |
| - const GError *error, |
| - GObject *weak_object, |
| + GAsyncResult *result, |
| gpointer user_data) |
| { |
| AddAccountData *data = user_data; |
| JsonNode *session; |
| - JsonParser *parser; |
| + JsonParser *parser = NULL; |
| JsonObject *json_obj; |
| JsonObject *session_obj; |
| const gchar *payload; |
| |
| - parser = NULL; |
| + if (!rest_proxy_call_invoke_finish (call, result, &data->error)) |
| + goto out; |
| |
| parser = json_parser_new (); |
| payload = rest_proxy_call_get_payload (call); |
| @@ -562,12 +562,12 @@ on_rest_proxy_call_cancelled_cb (GCancellable *cancellable, RestProxyCall *call) |
| } |
| |
| static void |
| -lastfm_login (GoaProvider *provider, |
| - const gchar *username, |
| - const gchar *password, |
| - GCancellable *cancellable, |
| - RestProxyCallAsyncCallback callback, |
| - gpointer user_data) |
| +lastfm_login (GoaProvider *provider, |
| + const gchar *username, |
| + const gchar *password, |
| + GCancellable *cancellable, |
| + GAsyncReadyCallback callback, |
| + gpointer user_data) |
| { |
| AddAccountData *data = user_data; |
| RestProxyCall *call; |
| @@ -598,7 +598,7 @@ lastfm_login (GoaProvider *provider, |
| rest_proxy_call_add_param (call, "api_sig", sig_md5); |
| rest_proxy_call_add_param (call, "format", "json"); |
| |
| - rest_proxy_call_async (call, callback, NULL, data, &data->error); |
| + rest_proxy_call_invoke_async (call, NULL, callback, data); |
| |
| g_signal_connect (cancellable, "cancelled", G_CALLBACK (on_rest_proxy_call_cancelled_cb), call); |
| |
| @@ -665,7 +665,7 @@ add_account (GoaProvider *provider, |
| username, |
| password, |
| data.cancellable, |
| - (RestProxyCallAsyncCallback) check_cb, |
| + (GAsyncReadyCallback) check_cb, |
| &data); |
| |
| gtk_widget_set_sensitive (data.connect_button, FALSE); |
| @@ -819,7 +819,7 @@ refresh_account (GoaProvider *provider, |
| username, |
| password, |
| data.cancellable, |
| - (RestProxyCallAsyncCallback) check_cb, |
| + (GAsyncReadyCallback) check_cb, |
| &data); |
| gtk_widget_set_sensitive (data.connect_button, FALSE); |
| gtk_widget_show (data.progress_grid); |
| diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c |
| index 0bfab6b..6a69251 100644 |
| --- a/src/goabackend/goaoauthprovider.c |
| +++ b/src/goabackend/goaoauthprovider.c |
| @@ -699,9 +699,15 @@ on_web_view_decide_policy (WebKitWebView *web_view, |
| } |
| |
| static void |
| -rest_proxy_call_cb (RestProxyCall *call, const GError *error, GObject *weak_object, gpointer user_data) |
| +rest_proxy_call_cb (GObject *source, GAsyncResult *result, gpointer user_data) |
| { |
| + RestProxyCall *call = REST_PROXY_CALL (source); |
| IdentifyData *data = user_data; |
| + |
| + if (!rest_proxy_call_invoke_finish (call, result, &data->error)) |
| + { |
| + g_prefix_error (&data->error, _("Error getting a Request Token: ")); |
| + } |
| g_main_loop_quit (data->loop); |
| } |
| |
| @@ -768,11 +774,7 @@ get_tokens_and_identity (GoaOAuthProvider *provider, |
| for (n = 0; request_params[n] != NULL; n += 2) |
| rest_proxy_call_add_param (call, request_params[n], request_params[n+1]); |
| } |
| - if (!rest_proxy_call_async (call, rest_proxy_call_cb, NULL, &data, &data.error)) |
| - { |
| - g_prefix_error (&data.error, _("Error getting a Request Token: ")); |
| - goto out; |
| - } |
| + rest_proxy_call_invoke_async (call, NULL, rest_proxy_call_cb, &data); |
| |
| goa_utils_set_dialog_title (GOA_PROVIDER (provider), dialog, add_account); |
| |
| @@ -794,6 +796,9 @@ get_tokens_and_identity (GoaOAuthProvider *provider, |
| g_main_loop_run (data.loop); |
| gtk_container_remove (GTK_CONTAINER (grid), spinner); |
| |
| + if (data.error) |
| + goto out; |
| + |
| if (rest_proxy_call_get_status_code (call) != 200) |
| { |
| gchar *msg; |
| diff --git a/src/goabackend/goarestproxy.h b/src/goabackend/goarestproxy.h |
| index 09fb076..4948cb7 100644 |
| --- a/src/goabackend/goarestproxy.h |
| +++ b/src/goabackend/goarestproxy.h |
| @@ -27,8 +27,6 @@ |
| |
| G_BEGIN_DECLS |
| |
| -G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestProxy, g_object_unref); |
| - |
| #define GOA_TYPE_REST_PROXY (goa_rest_proxy_get_type ()) |
| G_DECLARE_FINAL_TYPE (GoaRestProxy, goa_rest_proxy, GOA, REST_PROXY, RestProxy); |
| |