File: | weather-wx.c |
Warning: | line 30, column 18 Value stored to 'session' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | /* weather-wx.c - Weather server functions (WX Radar) |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License as |
6 | * published by the Free Software Foundation; either version 2 of the |
7 | * License, or (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, see |
16 | * <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #ifdef HAVE_CONFIG_H1 |
20 | #include <config.h> |
21 | #endif |
22 | |
23 | #define CAFEWEATHER_I_KNOW_THIS_IS_UNSTABLE |
24 | #include "weather.h" |
25 | #include "weather-priv.h" |
26 | |
27 | static void |
28 | wx_finish (GObject *object, GAsyncResult *result, gpointer data) |
29 | { |
30 | SoupSession *session = SOUP_SESSION (object); |
Value stored to 'session' during its initialization is never read | |
31 | SoupMessage *msg = soup_session_get_async_result_message (SOUP_SESSION (object), result); |
32 | WeatherInfo *info = (WeatherInfo *)data; |
33 | GdkPixbufAnimation *animation; |
34 | GBytes *response_body = NULL((void*)0); |
35 | |
36 | g_return_if_fail (info != NULL)do { if ((info != ((void*)0))) { } else { g_return_if_fail_warning ("CafeWeather", ((const char*) (__func__)), "info != NULL"); return; } } while (0); |
37 | |
38 | response_body = soup_session_send_and_read_finish(SOUP_SESSION(object), |
39 | result, NULL((void*)0)/*&error*/); |
40 | |
41 | if (!SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (msg))((soup_message_get_status (msg)) >= 200 && (soup_message_get_status (msg)) < 300)) { |
42 | g_warning ("Failed to get radar map image: %d %s.\n", |
43 | soup_message_get_status (msg), soup_message_get_reason_phrase (msg)); |
44 | g_object_unref (info->radar_loader); |
45 | request_done (info, FALSE(0)); |
46 | return; |
47 | } |
48 | |
49 | gdk_pixbuf_loader_close (info->radar_loader, NULL((void*)0)); |
50 | animation = gdk_pixbuf_loader_get_animation (info->radar_loader); |
51 | if (animation != NULL((void*)0)) { |
52 | if (info->radar) |
53 | g_object_unref (info->radar); |
54 | info->radar = animation; |
55 | g_object_ref (info->radar)((__typeof__ (info->radar)) (g_object_ref) (info->radar )); |
56 | } |
57 | g_object_unref (info->radar_loader); |
58 | |
59 | request_done (info, TRUE(!(0))); |
60 | } |
61 | |
62 | static void |
63 | wx_got_chunk /*(SoupMessage *msg, SoupBuffer *chunk, gpointer data)*/ |
64 | (SoupServerMessage *msg, GBytes *chunk, gpointer data) |
65 | { |
66 | WeatherInfo *info = (WeatherInfo *)data; |
67 | const gchar *msgdata; |
68 | GError *error = NULL((void*)0); |
69 | |
70 | msgdata = g_bytes_get_data(chunk, NULL((void*)0)/*&length*/); |
71 | |
72 | g_return_if_fail (info != NULL)do { if ((info != ((void*)0))) { } else { g_return_if_fail_warning ("CafeWeather", ((const char*) (__func__)), "info != NULL"); return; } } while (0); |
73 | |
74 | gdk_pixbuf_loader_write (info->radar_loader, (guchar *)msgdata, |
75 | (gsize) chunk, &error); |
76 | if (error) { |
77 | g_print ("%s \n", error->message); |
78 | g_error_free (error); |
79 | } |
80 | } |
81 | |
82 | /* Get radar map and into newly allocated pixmap */ |
83 | void |
84 | wx_start_open (WeatherInfo *info) |
85 | { |
86 | gchar *url; |
87 | SoupMessage *msg; |
88 | WeatherLocation *loc; |
89 | |
90 | g_return_if_fail (info != NULL)do { if ((info != ((void*)0))) { } else { g_return_if_fail_warning ("CafeWeather", ((const char*) (__func__)), "info != NULL"); return; } } while (0); |
91 | info->radar = NULL((void*)0); |
92 | info->radar_loader = gdk_pixbuf_loader_new (); |
93 | loc = info->location; |
94 | g_return_if_fail (loc != NULL)do { if ((loc != ((void*)0))) { } else { g_return_if_fail_warning ("CafeWeather", ((const char*) (__func__)), "loc != NULL"); return ; } } while (0); |
95 | |
96 | if (info->radar_url) |
97 | url = g_strdup (info->radar_url)g_strdup_inline (info->radar_url); |
98 | else { |
99 | if (loc->radar[0] == '-') |
100 | return; |
101 | url = g_strdup_printf ("http://image.weather.com/web/radar/us_%s_closeradar_medium_usen.jpg", loc->radar); |
102 | } |
103 | |
104 | msg = soup_message_new ("GET", url); |
105 | if (!msg) { |
106 | g_warning ("Invalid radar URL: %s\n", url); |
107 | g_free (url); |
108 | return; |
109 | } |
110 | |
111 | g_signal_connect (msg, "got-chunk", G_CALLBACK (wx_got_chunk), info)g_signal_connect_data ((msg), ("got-chunk"), (((GCallback) (wx_got_chunk ))), (info), ((void*)0), (GConnectFlags) 0); |
112 | // soup_message_body_set_accumulate (msg->response_body, FALSE); |
113 | soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT0, NULL((void*)0), wx_finish, info); |
114 | g_free (url); |
115 | |
116 | info->requests_pending++; |
117 | } |