blob: 4a47fb2dbe50b379f9b16a37df73bdba1c90185c [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001From 3c4a6eda580c6e38aeedb63d73ae7b96cc7f9a07 Mon Sep 17 00:00:00 2001
2From: Carlos Garcia Campos <cgarcia@igalia.com>
3Date: Mon, 7 Jun 2021 16:31:18 +0200
4Subject: [PATCH] Update to rest 1.0
5
6Updates to use the rest 1.0 API
7
8Upstream-Status: Inappropriate [rest 1.0 is not released yet]
9
10Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
11---
12 configure.ac | 2 +-
13 src/goabackend/goalastfmprovider.c | 26 +++++++++++++-------------
14 src/goabackend/goaoauthprovider.c | 17 +++++++++++------
15 src/goabackend/goarestproxy.h | 2 --
16 4 files changed, 25 insertions(+), 22 deletions(-)
17
18diff --git a/configure.ac b/configure.ac
19index 1f88bbd..e43303d 100644
20--- a/configure.ac
21+++ b/configure.ac
22@@ -129,7 +129,7 @@ if test "$enable_backend" != "no"; then
23 AC_SUBST(JSON_GLIB_CFLAGS)
24 AC_SUBST(JSON_GLIB_LIBS)
25
26- PKG_CHECK_MODULES(REST, [rest-0.7])
27+ PKG_CHECK_MODULES(REST, [rest-1.0])
28 AC_SUBST(REST_CFLAGS)
29 AC_SUBST(REST_LIBS)
30
31diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
32index cb9a6f2..a2db037 100644
33--- a/src/goabackend/goalastfmprovider.c
34+++ b/src/goabackend/goalastfmprovider.c
35@@ -483,18 +483,18 @@ add_account_cb (GoaManager *manager, GAsyncResult *res, gpointer user_data)
36
37 static void
38 check_cb (RestProxyCall *call,
39- const GError *error,
40- GObject *weak_object,
41+ GAsyncResult *result,
42 gpointer user_data)
43 {
44 AddAccountData *data = user_data;
45 JsonNode *session;
46- JsonParser *parser;
47+ JsonParser *parser = NULL;
48 JsonObject *json_obj;
49 JsonObject *session_obj;
50 const gchar *payload;
51
52- parser = NULL;
53+ if (!rest_proxy_call_invoke_finish (call, result, &data->error))
54+ goto out;
55
56 parser = json_parser_new ();
57 payload = rest_proxy_call_get_payload (call);
58@@ -562,12 +562,12 @@ on_rest_proxy_call_cancelled_cb (GCancellable *cancellable, RestProxyCall *call)
59 }
60
61 static void
62-lastfm_login (GoaProvider *provider,
63- const gchar *username,
64- const gchar *password,
65- GCancellable *cancellable,
66- RestProxyCallAsyncCallback callback,
67- gpointer user_data)
68+lastfm_login (GoaProvider *provider,
69+ const gchar *username,
70+ const gchar *password,
71+ GCancellable *cancellable,
72+ GAsyncReadyCallback callback,
73+ gpointer user_data)
74 {
75 AddAccountData *data = user_data;
76 RestProxyCall *call;
77@@ -598,7 +598,7 @@ lastfm_login (GoaProvider *provider,
78 rest_proxy_call_add_param (call, "api_sig", sig_md5);
79 rest_proxy_call_add_param (call, "format", "json");
80
81- rest_proxy_call_async (call, callback, NULL, data, &data->error);
82+ rest_proxy_call_invoke_async (call, NULL, callback, data);
83
84 g_signal_connect (cancellable, "cancelled", G_CALLBACK (on_rest_proxy_call_cancelled_cb), call);
85
86@@ -665,7 +665,7 @@ add_account (GoaProvider *provider,
87 username,
88 password,
89 data.cancellable,
90- (RestProxyCallAsyncCallback) check_cb,
91+ (GAsyncReadyCallback) check_cb,
92 &data);
93
94 gtk_widget_set_sensitive (data.connect_button, FALSE);
95@@ -819,7 +819,7 @@ refresh_account (GoaProvider *provider,
96 username,
97 password,
98 data.cancellable,
99- (RestProxyCallAsyncCallback) check_cb,
100+ (GAsyncReadyCallback) check_cb,
101 &data);
102 gtk_widget_set_sensitive (data.connect_button, FALSE);
103 gtk_widget_show (data.progress_grid);
104diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
105index 0bfab6b..6a69251 100644
106--- a/src/goabackend/goaoauthprovider.c
107+++ b/src/goabackend/goaoauthprovider.c
108@@ -699,9 +699,15 @@ on_web_view_decide_policy (WebKitWebView *web_view,
109 }
110
111 static void
112-rest_proxy_call_cb (RestProxyCall *call, const GError *error, GObject *weak_object, gpointer user_data)
113+rest_proxy_call_cb (GObject *source, GAsyncResult *result, gpointer user_data)
114 {
115+ RestProxyCall *call = REST_PROXY_CALL (source);
116 IdentifyData *data = user_data;
117+
118+ if (!rest_proxy_call_invoke_finish (call, result, &data->error))
119+ {
120+ g_prefix_error (&data->error, _("Error getting a Request Token: "));
121+ }
122 g_main_loop_quit (data->loop);
123 }
124
125@@ -768,11 +774,7 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
126 for (n = 0; request_params[n] != NULL; n += 2)
127 rest_proxy_call_add_param (call, request_params[n], request_params[n+1]);
128 }
129- if (!rest_proxy_call_async (call, rest_proxy_call_cb, NULL, &data, &data.error))
130- {
131- g_prefix_error (&data.error, _("Error getting a Request Token: "));
132- goto out;
133- }
134+ rest_proxy_call_invoke_async (call, NULL, rest_proxy_call_cb, &data);
135
136 goa_utils_set_dialog_title (GOA_PROVIDER (provider), dialog, add_account);
137
138@@ -794,6 +796,9 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
139 g_main_loop_run (data.loop);
140 gtk_container_remove (GTK_CONTAINER (grid), spinner);
141
142+ if (data.error)
143+ goto out;
144+
145 if (rest_proxy_call_get_status_code (call) != 200)
146 {
147 gchar *msg;
148diff --git a/src/goabackend/goarestproxy.h b/src/goabackend/goarestproxy.h
149index 09fb076..4948cb7 100644
150--- a/src/goabackend/goarestproxy.h
151+++ b/src/goabackend/goarestproxy.h
152@@ -27,8 +27,6 @@
153
154 G_BEGIN_DECLS
155
156-G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestProxy, g_object_unref);
157-
158 #define GOA_TYPE_REST_PROXY (goa_rest_proxy_get_type ())
159 G_DECLARE_FINAL_TYPE (GoaRestProxy, goa_rest_proxy, GOA, REST_PROXY, RestProxy);
160