Merge lp:~larsu/timezonemap/lp1440157 into lp:timezonemap

Proposed by Lars Karlitski on 2015-05-07
Status: Merged
Merged at revision: 53
Proposed branch: lp:~larsu/timezonemap/lp1440157
Merge into: lp:timezonemap
Diff against target: 171 lines (+48/-23)
3 files modified
configure.ac (+2/-0)
debian/control (+1/-0)
src/timezone-completion.c (+45/-23)
To merge this branch: bzr merge lp:~larsu/timezonemap/lp1440157
Reviewer Review Type Date Requested Status
Iain Lane 2015-05-07 Approve on 2015-05-07
Review via email: mp+258506@code.launchpad.net

Commit message

Description of the change

Use libsoup directly instead of gio, fix a few memory leaks, and don't reuse cancellables (as per GCancellable docs).

To post a comment you must log in.
Iain Lane (laney) wrote :

Thanks!

Going to upload later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-02-02 11:58:25 +0000
3+++ configure.ac 2015-05-07 14:10:56 +0000
4@@ -50,11 +50,13 @@
5 GLIB_REQUIRED_VERSION=2.26
6 GTK3_REQUIRED_VERSION=3.1.4
7 GIO_REQUIRED_VERSION=2.5.11
8+SOUP_REQUIRED_VERSION=2.42.0
9
10 AC_CHECK_LIBM
11
12 PKG_CHECK_MODULES(LIBTIMEZONEMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
13 gtk+-3.0 >= $GTK3_REQUIRED_VERSION
14+ libsoup-2.4 >= $SOUP_REQUIRED_VERSION
15 json-glib-1.0)
16 LIBTIMEZONEMAP_LIBS="$LIBTIMEZONEMAP_LIBS $LIBM"
17
18
19=== modified file 'debian/control'
20--- debian/control 2014-05-03 03:51:17 +0000
21+++ debian/control 2015-05-07 14:10:56 +0000
22@@ -13,6 +13,7 @@
23 libgtk-3-dev (>= 3.1.4),
24 libcairo2-dev (>= 1.10),
25 libjson-glib-dev,
26+ libsoup2.4-dev (>= 2.42.0),
27 dh-autoreconf
28 Standards-Version: 3.9.5
29 Vcs-Bzr: http://bazaar.launchpad.net/~timezonemap-team/timezonemap/trunk
30
31=== modified file 'src/timezone-completion.c'
32--- src/timezone-completion.c 2013-11-29 11:25:40 +0000
33+++ src/timezone-completion.c 2015-05-07 14:10:56 +0000
34@@ -26,6 +26,7 @@
35 #include <gdk/gdk.h>
36 #include <gdk/gdkkeysyms.h>
37 #include <glib/gi18n.h>
38+#include <libsoup/soup.h>
39 #include "timezone-completion.h"
40 #include "tz.h"
41
42@@ -45,6 +46,7 @@
43 GCancellable * cancel;
44 gchar * request_text;
45 GHashTable * request_table;
46+ SoupSession * soup_session;
47 };
48
49 #define GEONAME_URL "http://geoname-lookup.ubuntu.com/?query=%s&release=%s&lang=%s"
50@@ -134,10 +136,6 @@
51
52 json_parser_load_from_stream_finish (JSON_PARSER (object), res, &error);
53
54- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) {
55- g_cancellable_reset (priv->cancel);
56- }
57-
58 if (error != NULL)
59 {
60 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
61@@ -271,16 +269,11 @@
62 CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (user_data);
63 CcTimezoneCompletionPrivate * priv = completion->priv;
64 GError * error = NULL;
65- GFileInputStream * stream;
66-
67- stream = g_file_read_finish (G_FILE (object), res, &error);
68-
69- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel)
70- {
71- g_cancellable_reset (priv->cancel);
72- }
73-
74- if (error != NULL)
75+ GInputStream * stream;
76+ SoupMessage *message;
77+
78+ stream = soup_request_send_finish (SOUP_REQUEST (object), res, &error);
79+ if (stream == NULL)
80 {
81 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
82 save_and_use_model (completion, priv->initial_model);
83@@ -290,9 +283,24 @@
84 return;
85 }
86
87- JsonParser * parser = json_parser_new ();
88- json_parser_load_from_stream_async (parser, G_INPUT_STREAM (stream), priv->cancel,
89- json_parse_ready, user_data);
90+ message = soup_request_http_get_message (SOUP_REQUEST_HTTP (object));
91+ if (message->status_code == SOUP_STATUS_OK)
92+ {
93+ JsonParser *parser;
94+
95+ parser = json_parser_new ();
96+ json_parser_load_from_stream_async (parser, stream, priv->cancel, json_parse_ready, user_data);
97+
98+ g_object_unref (parser);
99+ }
100+ else
101+ {
102+ g_warning ("Unable to fetch geonames (server responded with: %u %s)",
103+ message->status_code, message->reason_phrase);
104+ }
105+
106+ g_object_unref (message);
107+ g_object_unref (stream);
108 }
109
110 /* Returns message locale, with possible country info too like en_US */
111@@ -354,6 +362,8 @@
112 request_zones (CcTimezoneCompletion * completion)
113 {
114 CcTimezoneCompletionPrivate * priv = completion->priv;
115+ SoupRequest *req;
116+ GError *error = NULL;
117
118 priv->queued_request = 0;
119
120@@ -366,7 +376,8 @@
121 if (priv->cancel)
122 {
123 g_cancellable_cancel (priv->cancel);
124- g_cancellable_reset (priv->cancel);
125+ g_object_unref (priv->cancel);
126+ priv->cancel = g_cancellable_new ();
127 }
128 g_free (priv->request_text);
129
130@@ -380,12 +391,19 @@
131 g_free (locale);
132 g_free (escaped);
133
134- GFile * file = g_file_new_for_uri (url);
135+ req = soup_session_request (priv->soup_session, url, &error);
136+ if (req)
137+ {
138+ soup_request_send_async (req, priv->cancel, geonames_data_ready, completion);
139+ g_object_unref (req);
140+ }
141+ else
142+ {
143+ g_warning ("%s", error->message);
144+ g_error_free (error);
145+ }
146+
147 g_free (url);
148-
149- g_file_read_async (file, G_PRIORITY_DEFAULT, priv->cancel,
150- geonames_data_ready, completion);
151-
152 return FALSE;
153 }
154
155@@ -678,6 +696,8 @@
156 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, TRUE);
157 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (self), cell, data_func, NULL, NULL);
158
159+ priv->soup_session = soup_session_new ();
160+
161 return;
162 }
163
164@@ -741,6 +761,8 @@
165 priv->request_table = NULL;
166 }
167
168+ g_clear_object (&priv->soup_session);
169+
170 return;
171 }
172

Subscribers

People subscribed via source and target branches