libgweather r257 - in trunk: . libgweather



Author: danw
Date: Wed Jun 18 18:17:09 2008
New Revision: 257
URL: http://svn.gnome.org/viewvc/libgweather?rev=257&view=rev

Log:
	* configure.in: require libsoup instead of gnome-vfs. (Also
	require gconf explicitly; it used to be pulled in implicitly by
	gnome-vfs.)

	* libgweather/weather-bom.c:
	* libgweather/weather-iwin.c:
	* libgweather/weather-met.c:
	* libgweather/weather-metar.c:
	* libgweather/weather-wx.c: Use libsoup rather than gnome-vfs for
	http. #527525

	* libgweather/Makefile.am:
	* libgweather/weather.c:
	* libgweather/weather-priv.h: update for libsoup changes


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/libgweather/Makefile.am
   trunk/libgweather/gweather.pc.in
   trunk/libgweather/weather-bom.c
   trunk/libgweather/weather-iwin.c
   trunk/libgweather/weather-met.c
   trunk/libgweather/weather-metar.c
   trunk/libgweather/weather-priv.h
   trunk/libgweather/weather-wx.c
   trunk/libgweather/weather.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Wed Jun 18 18:17:09 2008
@@ -17,7 +17,7 @@
 
 GTK_REQUIRED=2.11.0
 GLIB_REQUIRED=2.13.0
-GNOME_VFS_REQUIRED=2.15.4
+LIBSOUP_REQUIRED=2.4.0
 GCONF_REQUIRED=2.8.0
 LIBXML_REQUIRED=2.6.0
 
@@ -90,11 +90,17 @@
 AC_SUBST(LIBXML_FLAGS)
 AC_SUBST(LIBXML_LIBS)
 
-dnl -- check for gnome-vfs (optional) -----------------------------------------
-PKG_CHECK_MODULES(GNOME_VFS_APPLETS, 
-		  [gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED])
-AC_SUBST(GNOME_VFS_APPLETS_CFLAGS)
-AC_SUBST(GNOME_VFS_APPLETS_LIBS)
+dnl -- check for libsoup (required) -----------------------------------------
+PKG_CHECK_MODULES(LIBSOUP, 
+		  [libsoup-2.4 >= $LIBSOUP_REQUIRED])
+AC_SUBST(LIBSOUP_CFLAGS)
+AC_SUBST(LIBSOUP_LIBS)
+
+dnl -- check for gconf (required) -----------------------------------------
+PKG_CHECK_MODULES(GCONF, 
+		  [gconf-2.0 >= $GCONF_REQUIRED])
+AC_SUBST(GCONF_CFLAGS)
+AC_SUBST(GCONF_LIBS)
 
 AM_GCONF_SOURCE_2
 

Modified: trunk/libgweather/Makefile.am
==============================================================================
--- trunk/libgweather/Makefile.am	(original)
+++ trunk/libgweather/Makefile.am	Wed Jun 18 18:17:09 2008
@@ -21,7 +21,8 @@
 	$(WARN_CFLAGS)			\
 	$(GTK_CFLAGS)			\
 	$(LIBXML_CFLAGS)		\
-	$(GNOME_VFS_APPLETS_CFLAGS)	\
+	$(LIBSOUP_CFLAGS)		\
+	$(GCONF_CFLAGS)			\
 	-DG_LOG_DOMAIN=\"GWeather\"	\
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
 	-DGWEATHER_XML_LOCATION_DIR=\""$(pkgdatadir)"\"
@@ -29,7 +30,8 @@
 libgweather_la_LIBADD = \
 	$(GTK_LIBS)	\
 	$(LIBXML_LIBS)	\
-	$(GNOME_VFS_APPLETS_LIBS)
+	$(LIBSOUP_LIBS)	\
+	$(GCONF_LIBS)
 
 libgweather_la_LDFLAGS = \
 	-version-info $(LT_VERSION) -no-undefined
@@ -41,11 +43,11 @@
 	-I$(srcdir)			\
 	$(WARN_CFLAGS)			\
 	$(GTK_CFLAGS)			\
-	$(GNOME_VFS_APPLETS_CFLAGS)	\
+	$(LIBSOUP_CFLAGS)		\
 	-DG_LOG_DOMAIN=\"GWeather\"
 
 test_metar_LDADD = \
-	$(GNOME_VFS_APPLETS_LIB) \
+	$(LIBSOUP_LIBS)	\
 	libgweather.la
 
 noinst_HEADERS = weather-priv.h

Modified: trunk/libgweather/gweather.pc.in
==============================================================================
--- trunk/libgweather/gweather.pc.in	(original)
+++ trunk/libgweather/gweather.pc.in	Wed Jun 18 18:17:09 2008
@@ -8,6 +8,6 @@
 Description: GWeather shared library
 Version: @VERSION@
 Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-2.0 gconf-2.0
-Requires.private: libxml-2.0 gnome-vfs-2.0
+Requires.private: libxml-2.0 libsoup-2.4
 Libs: -L${libdir} -lgweather -lm
 Cflags: -I${includedir}

Modified: trunk/libgweather/weather-bom.c
==============================================================================
--- trunk/libgweather/weather-bom.c	(original)
+++ trunk/libgweather/weather-bom.c	Wed Jun 18 18:17:09 2008
@@ -21,7 +21,7 @@
 #include "weather-priv.h"
 
 static gchar *
-bom_parse (gchar *meto)
+bom_parse (const gchar *meto)
 {
     gchar *p, *rp;
 
@@ -39,89 +39,36 @@
 }
 
 static void
-bom_finish_read (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
-		 gpointer buffer, GnomeVFSFileSize requested,
-		 GnomeVFSFileSize body_len, gpointer data)
+bom_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
-    gchar *body, *forecast, *temp;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->bom_handle);
 
-    info->forecast = NULL;
-    body = (gchar *)buffer;
-    body[body_len] = '\0';
-
-    if (info->bom_buffer == NULL)
-        info->bom_buffer = g_strdup (body);
-    else {
-        temp = g_strdup (info->bom_buffer);
-	g_free (info->bom_buffer);
-	info->bom_buffer = g_strdup_printf ("%s%s", temp, body);
-	g_free (temp);
-    }
-
-    if (result == GNOME_VFS_ERROR_EOF) {
-	forecast = bom_parse (info->bom_buffer);
-        info->forecast = forecast;
-    } else if (result != GNOME_VFS_OK) {
-	info->bom_handle = NULL;
-	requests_done_check (info);
-        g_warning ("Failed to get BOM data.\n");
-    } else {
-	gnome_vfs_async_read (handle, body, DATA_SIZE - 1, bom_finish_read, info);
+    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+        g_warning ("Failed to get BOM forecast data: %d %s.\n",
+		   msg->status_code, msg->reason_phrase);
+        request_done (info, FALSE);
 	return;
     }
 
-    request_done (info->bom_handle, info);
-    g_free (buffer);
-    return;
-}
-
-static void
-bom_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
-{
-    WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body;
-
-    g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->bom_handle);
-
-    body = g_malloc0 (DATA_SIZE);
-
-    info->bom_buffer = NULL;
-    if (info->forecast)
-    	g_free (info->forecast);
-    info->forecast = NULL;
-    loc = info->location;
-    g_return_if_fail (loc != NULL);
-
-    if (result != GNOME_VFS_OK) {
-        g_warning ("Failed to get BOM forecast data.\n");
-        info->bom_handle = NULL;
-        requests_done_check (info);
-        g_free (body);
-    } else {
-    	gnome_vfs_async_read (handle, body, DATA_SIZE - 1, bom_finish_read, info);
-    }
-    return;
+    info->forecast = bom_parse (msg->response_body->data);
+    request_done (info, TRUE);
 }
 
 void
 bom_start_open (WeatherInfo *info)
 {
     gchar *url;
+    SoupMessage *msg;
     WeatherLocation *loc;
+
     loc = info->location;
 
     url = g_strdup_printf ("http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?%s.txt";,
 			   loc->zone + 1);
 
-    gnome_vfs_async_open (&info->bom_handle, url, GNOME_VFS_OPEN_READ,
-			  0, bom_finish_open, info);
+    msg = soup_message_new ("GET", url);
+    soup_session_queue_message (info->session, msg, bom_finish, info);
     g_free (url);
-
-    return;
 }

Modified: trunk/libgweather/weather-iwin.c
==============================================================================
--- trunk/libgweather/weather-iwin.c	(original)
+++ trunk/libgweather/weather-iwin.c	Wed Jun 18 18:17:09 2008
@@ -66,82 +66,22 @@
 }
 
 static void
-iwin_finish_read (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
-		  gpointer buffer, GnomeVFSFileSize requested,
-		  GnomeVFSFileSize body_len, gpointer data)
+iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
-    gchar *body, *temp;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->iwin_handle);
 
-    info->forecast = NULL;
-    body = (gchar *)buffer;
-    body[body_len] = '\0';
-
-    if (info->iwin_buffer == NULL)
-	info->iwin_buffer = g_strdup (body);
-    else {
-	temp = g_strdup (info->iwin_buffer);
-	g_free (info->iwin_buffer);
-	info->iwin_buffer = g_strdup_printf ("%s%s", temp, body);
-	g_free (temp);
-    }
-
-    if (result == GNOME_VFS_ERROR_EOF) {
-        info->forecast = formatWeatherMsg (g_strdup (info->iwin_buffer));
-    } else if (result != GNOME_VFS_OK) {
-	g_print ("%s", gnome_vfs_result_to_string (result));
-        g_warning ("Failed to get IWIN data.\n");
-    } else {
-        gnome_vfs_async_read (handle, body, DATA_SIZE - 1, iwin_finish_read, info);
-        return;
-    }
-
-    request_done (info->iwin_handle, info);
-    g_free (buffer);
-    return;
-}
-
-static void
-iwin_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
-{
-    WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body;
-
-    g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->iwin_handle);
-
-    body = g_malloc0 (DATA_SIZE);
-
-    if (info->iwin_buffer)
-    	g_free (info->iwin_buffer);
-    info->iwin_buffer = NULL;
-    if (info->forecast)
-	g_free (info->forecast);
-    info->forecast = NULL;
-    loc = info->location;
-    if (loc == NULL) {
-	g_warning (_("WeatherInfo missing location"));
-	request_done (info->iwin_handle, info);
-	info->iwin_handle = NULL;
-	requests_done_check (info);
-	g_free (body);
+    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+        /* forecast data is not really interesting anyway ;) */
+	g_warning ("Failed to get IWIN forecast data: %d %s\n",
+		   msg->status_code, msg->reason_phrase);
+        request_done (info, FALSE);
 	return;
     }
 
-    if (result != GNOME_VFS_OK) {
-        /* forecast data is not really interesting anyway ;) */
-	g_warning ("Failed to get IWIN forecast data.\n");
-        info->iwin_handle = NULL;
-        requests_done_check (info);
-        g_free (body);
-    } else {
-        gnome_vfs_async_read (handle, body, DATA_SIZE - 1, iwin_finish_read, info);
-    }
-    return;
+    info->forecast = formatWeatherMsg (g_strdup (msg->response_body->data));
+    request_done (info, TRUE);
 }
 
 /* Get forecast into newly alloc'ed string */
@@ -150,6 +90,7 @@
 {
     gchar *url, *state, *zone;
     WeatherLocation *loc;
+    SoupMessage *msg;
 
     g_return_if_fail (info != NULL);
     loc = info->location;
@@ -158,6 +99,11 @@
     if (loc->zone[0] == '-')
         return;
 
+    if (info->forecast) {
+	g_free (info->forecast);
+	info->forecast = NULL;
+    }
+
     if (loc->zone[0] == ':') {
 	/* Met Office Region Names */
     	metoffice_start_open (info);
@@ -180,7 +126,7 @@
     g_free (zone);
     g_free (state);
 
-    gnome_vfs_async_open (&info->iwin_handle, url, GNOME_VFS_OPEN_READ,
-			  0, iwin_finish_open, info);
+    msg = soup_message_new ("GET", url);
     g_free (url);
+    soup_session_queue_message (info->session, msg, iwin_finish, info);
 }

Modified: trunk/libgweather/weather-met.c
==============================================================================
--- trunk/libgweather/weather-met.c	(original)
+++ trunk/libgweather/weather-met.c	Wed Jun 18 18:17:09 2008
@@ -116,7 +116,7 @@
  */
 
 static gchar *
-met_parse (gchar *meto)
+met_parse (const gchar *meto)
 {
     gchar *p;
     gchar *rp;
@@ -140,89 +140,34 @@
 }
 
 static void
-met_finish_read (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
-		 gpointer buffer, GnomeVFSFileSize requested,
-		 GnomeVFSFileSize body_len, gpointer data)
+met_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body, *forecast, *temp;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->met_handle);
-
-    info->forecast = NULL;
-    loc = info->location;
-    body = (gchar *)buffer;
-    body[body_len] = '\0';
-
-    if (info->met_buffer == NULL)
-        info->met_buffer = g_strdup (body);
-    else {
-        temp = g_strdup (info->met_buffer);
-	g_free (info->met_buffer);
-	info->met_buffer = g_strdup_printf ("%s%s", temp, body);
-	g_free (temp);
-    }
 
-    if (result == GNOME_VFS_ERROR_EOF) {
-	forecast = met_parse (info->met_buffer);
-        info->forecast = forecast;
-    } else if (result != GNOME_VFS_OK) {
-	g_print ("%s", gnome_vfs_result_to_string (result));
-	info->met_handle = NULL;
-	requests_done_check (info);
-        g_warning ("Failed to get Met Office data.\n");
-    } else {
-        gnome_vfs_async_read (handle, body, DATA_SIZE - 1, met_finish_read, info);
+    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+	g_warning ("Failed to get Met Office forecast data: %d %s.\n",
+		   msg->status_code, msg->reason_phrase);
+        request_done (info, FALSE);
         return;
     }
 
-    request_done (info->met_handle, info);
-    g_free (buffer);
-    return;
-}
-
-static void
-met_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
-{
-    WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body;
-
-    g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->met_handle);
-
-    body = g_malloc0 (DATA_SIZE);
-
-    info->met_buffer = NULL;
-    if (info->forecast)
-    	g_free (info->forecast);
-    info->forecast = NULL;
-    loc = info->location;
-    g_return_if_fail (loc != NULL);
-
-    if (result != GNOME_VFS_OK) {
-        g_warning ("Failed to get Met Office forecast data.\n");
-        info->met_handle = NULL;
-        requests_done_check (info);
-        g_free (body);
-    } else {
-    	gnome_vfs_async_read (handle, body, DATA_SIZE - 1, met_finish_read, info);
-    }
-    return;
+    info->forecast = met_parse (msg->response_body->data);
+    request_done (info, TRUE);
 }
 
 void
 metoffice_start_open (WeatherInfo *info)
 {
     gchar *url;
+    SoupMessage *msg;
     WeatherLocation *loc;
-    loc = info->location;
 
+    loc = info->location;
     url = g_strdup_printf ("http://www.metoffice.gov.uk/weather/europe/uk/%s.html";, loc->zone + 1);
 
-    gnome_vfs_async_open (&info->met_handle, url, GNOME_VFS_OPEN_READ,
-			  0, met_finish_open, info);
+    msg = soup_message_new ("GET", url);
+    soup_session_queue_message (info->session, msg, met_finish, info);
     g_free (url);
 }

Modified: trunk/libgweather/weather-metar.c
==============================================================================
--- trunk/libgweather/weather-metar.c	(original)
+++ trunk/libgweather/weather-metar.c	Wed Jun 18 18:17:09 2008
@@ -483,105 +483,49 @@
 }
 
 static void
-metar_finish_read (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
-		   gpointer buffer, GnomeVFSFileSize requested,
-		   GnomeVFSFileSize body_len, gpointer data)
+metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
     WeatherLocation *loc;
-    gchar *metar, *eoln, *body, *temp;
+    const gchar *p, *eoln;
+    gchar *searchkey, *metar;
     gboolean success = FALSE;
-    gchar *searchkey;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->metar_handle);
 
-    loc = info->location;
-    body = (gchar *)buffer;
-
-    body[body_len] = '\0';
-
-    if (info->metar_buffer == NULL)
-    	info->metar_buffer = g_strdup (body);
-    else {
-	temp = g_strdup (info->metar_buffer);
-	g_free (info->metar_buffer);
-	info->metar_buffer = g_strdup_printf ("%s%s", temp, body);
-	g_free (temp);
-    }
-
-    if (result == GNOME_VFS_ERROR_EOF) {
-        searchkey = g_strdup_printf ("\n%s", loc->code);
-
-        metar = strstr (info->metar_buffer, searchkey);
-        g_free (searchkey);
-        if (metar == NULL) {
-            success = FALSE;
-        } else {
-            metar += WEATHER_LOCATION_CODE_LEN + 2;
-            eoln = strchr (metar, '\n');
-	    if (eoln != NULL)
-		*eoln = 0;
-            success = metar_parse (metar, info);
-	    if (eoln != NULL)
-		*eoln = '\n';
-        }
-
-        info->valid = success;
-    } else if (result != GNOME_VFS_OK) {
-	g_print ("%s", gnome_vfs_result_to_string (result));
-        g_warning (_("Failed to get METAR data.\n"));
-    } else {
-	gnome_vfs_async_read (handle, body, DATA_SIZE - 1, metar_finish_read, info);
+    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+        g_warning (_("Failed to get METAR data: %d %s.\n"),
+		   msg->status_code, msg->reason_phrase);
+	request_done (info, FALSE);
 	return;
     }
 
-    request_done (info->metar_handle, info);
-    g_free (buffer);
-    return;
-}
-
-static void
-metar_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
-{
-    WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body;
-
-    g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->metar_handle);
-
-    body = g_malloc0 (DATA_SIZE);
-
-    if (info->metar_buffer)
-    	g_free (info->metar_buffer);
-    info->metar_buffer = NULL;
     loc = info->location;
-    if (loc == NULL) {
-	g_warning (_("WeatherInfo missing location"));
-	request_done (info->metar_handle, info);
-	requests_done_check (info);
-	g_free (body);
-	return;
-    }
 
-    if (result != GNOME_VFS_OK) {
-        g_warning (_("Failed to get METAR data.\n"));
-        info->metar_handle = NULL;
-	requests_done_check (info);
-	g_free (body);
-    } else {
-        gnome_vfs_async_read (handle, body, DATA_SIZE - 1, metar_finish_read, info);
+    searchkey = g_strdup_printf ("\n%s", loc->code);
+    p = strstr (msg->response_body->data, searchkey);
+    g_free (searchkey);
+    if (p) {
+	p += WEATHER_LOCATION_CODE_LEN + 2;
+	eoln = strchr(p, '\n');
+	if (eoln)
+	    metar = g_strndup (p, eoln - p);
+	else
+	    metar = g_strdup (p);
+	success = metar_parse (metar, info);
+	g_free (metar);
     }
-    return;
+
+    info->valid = success;
+    request_done (info, TRUE);
 }
 
 /* Read current conditions and fill in info structure */
 void
 metar_start_open (WeatherInfo *info)
 {
-    gchar *url;
     WeatherLocation *loc;
+    SoupMessage *msg;
 
     g_return_if_fail (info != NULL);
     info->valid = FALSE;
@@ -591,8 +535,9 @@
 	return;
     }
 
-    url = g_strdup_printf ("http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=%s";, loc->code);
-    gnome_vfs_async_open (&info->metar_handle, url, GNOME_VFS_OPEN_READ,
-			  0, metar_finish_open, info);
-    g_free (url);
+    msg = soup_form_request_new (
+	"GET", "http://weather.noaa.gov/cgi-bin/mgetmetar.pl";,
+	"cccc", loc->code,
+	NULL);
+    soup_session_queue_message (info->session, msg, metar_finish, info);
 }

Modified: trunk/libgweather/weather-priv.h
==============================================================================
--- trunk/libgweather/weather-priv.h	(original)
+++ trunk/libgweather/weather-priv.h	Wed Jun 18 18:17:09 2008
@@ -13,7 +13,7 @@
 #define __WEATHER_PRIV_H_
 
 #include <time.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <libsoup/soup.h>
 
 #include "weather.h"
 
@@ -132,20 +132,12 @@
     WeatherUpdate sunrise;
     WeatherUpdate sunset;
     gchar *forecast;
-    gchar *metar_buffer;
-    gchar *iwin_buffer;
-    gchar *met_buffer;
-    gchar *bom_buffer;
     gchar *radar_buffer;
     gchar *radar_url;
     GdkPixbufLoader *radar_loader;
     GdkPixbufAnimation *radar;
-    GnomeVFSAsyncHandle *metar_handle;
-    GnomeVFSAsyncHandle *iwin_handle;
-    GnomeVFSAsyncHandle *wx_handle;
-    GnomeVFSAsyncHandle *met_handle;
-    GnomeVFSAsyncHandle *bom_handle;
-    gboolean requests_pending;
+    SoupSession *session;
+    gint requests_pending;
 
     WeatherInfoFunc finish_cb;
     gpointer cb_data;
@@ -202,9 +194,8 @@
 					 WeatherInfo *info);
 
 gboolean	requests_init		(WeatherInfo *info);
-void		request_done		(GnomeVFSAsyncHandle *handle,
-					 WeatherInfo *info);
-void		requests_done_check	(WeatherInfo *info);
+void		request_done		(WeatherInfo *info,
+					 gboolean     ok);
 
 gboolean	calc_sun		(WeatherInfo *info);
 

Modified: trunk/libgweather/weather-wx.c
==============================================================================
--- trunk/libgweather/weather-wx.c	(original)
+++ trunk/libgweather/weather-wx.c	Wed Jun 18 18:17:09 2008
@@ -22,77 +22,48 @@
 #include "weather-priv.h"
 
 static void
-wx_finish_read (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
-		gpointer buffer, GnomeVFSFileSize requested,
-		GnomeVFSFileSize body_len, gpointer data)
+wx_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
+    GdkPixbufAnimation *animation;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->wx_handle);
 
-    info->radar = NULL;
+    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+	g_warning ("Failed to get radar map image: %d %s.\n",
+		   msg->status_code, msg->reason_phrase);
+	g_object_unref (info->radar_loader);
+	request_done (info, FALSE);
+	return;
+    }
 
-    if (result == GNOME_VFS_OK && body_len != 0) {
-        GError *error = NULL;
-    	gdk_pixbuf_loader_write (info->radar_loader, buffer, body_len, &error);
-        if (error) {
-            g_print ("%s \n", error->message);
-            g_error_free (error);
-        }
-        gnome_vfs_async_read (handle, buffer, DATA_SIZE - 1, wx_finish_read, info);
-        return;
-    } else if (result == GNOME_VFS_ERROR_EOF) {
-        GdkPixbufAnimation *animation;
-
-        gdk_pixbuf_loader_close (info->radar_loader, NULL);
-        animation = gdk_pixbuf_loader_get_animation (info->radar_loader);
-	if (animation != NULL) {
-            if (info->radar)
-                g_object_unref (info->radar);
-	    info->radar = animation;
-	    g_object_ref (info->radar);
-        }
-	g_object_unref (G_OBJECT (info->radar_loader));
-
-    } else {
-        g_print ("%s", gnome_vfs_result_to_string (result));
-        g_warning (_("Failed to get METAR data.\n"));
-        info->wx_handle = NULL;
-        requests_done_check (info);
-	if (info->radar_loader)
-	    g_object_unref (G_OBJECT (info->radar_loader));
+    gdk_pixbuf_loader_close (info->radar_loader, NULL);
+    animation = gdk_pixbuf_loader_get_animation (info->radar_loader);
+    if (animation != NULL) {
+	if (info->radar)
+	    g_object_unref (info->radar);
+	info->radar = animation;
+	g_object_ref (info->radar);
     }
+    g_object_unref (info->radar_loader);
 
-    request_done (info->wx_handle, info);
-    g_free (buffer);
+    request_done (info, TRUE);
 }
 
 static void
-wx_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
+wx_got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer data)
 {
     WeatherInfo *info = (WeatherInfo *)data;
-    WeatherLocation *loc;
-    gchar *body;
+    GError *error = NULL;
 
     g_return_if_fail (info != NULL);
-    g_return_if_fail (handle == info->wx_handle);
 
-    body = g_malloc0 (DATA_SIZE);
-
-    info->radar_buffer = NULL;
-    info->radar = NULL;
-    loc = info->location;
-    g_return_if_fail (loc != NULL);
-
-    if (result != GNOME_VFS_OK) {
-        g_warning ("Failed to get radar map image.\n");
-        info->wx_handle = NULL;
-        requests_done_check (info);
-        g_free (body);
-    } else
-        gnome_vfs_async_read (handle, body, DATA_SIZE -1, wx_finish_read, info);
-    return;
+    gdk_pixbuf_loader_write (info->radar_loader, (guchar *)chunk->data,
+			     chunk->length, &error);
+    if (error) {
+	g_print ("%s \n", error->message);
+	g_error_free (error);
+    }
 }
 
 /* Get radar map and into newly allocated pixmap */
@@ -100,6 +71,7 @@
 wx_start_open (WeatherInfo *info)
 {
     gchar *url;
+    SoupMessage *msg;
     WeatherLocation *loc;
 
     g_return_if_fail (info != NULL);
@@ -109,15 +81,16 @@
     g_return_if_fail (loc != NULL);
 
     if (info->radar_url)
-    	url = g_strdup (info->radar_url);
+	url = g_strdup (info->radar_url);
     else {
 	if (loc->radar[0] == '-')
 	    return;
 	url = g_strdup_printf ("http://image.weather.com/web/radar/us_%s_closeradar_medium_usen.jpg";, loc->radar);
     }
-
-    gnome_vfs_async_open (&info->wx_handle, url, GNOME_VFS_OPEN_READ,
-    			 0, wx_finish_open, info);
-
+ 
+    msg = soup_message_new ("GET", url);
+    g_signal_connect (msg, "got-chunk", G_CALLBACK (wx_got_chunk), info);
+    soup_message_set_flags (msg, SOUP_MESSAGE_OVERWRITE_CHUNKS);
+    soup_session_queue_message (info->session, msg, wx_finish, info);
     g_free (url);
 }

Modified: trunk/libgweather/weather.c
==============================================================================
--- trunk/libgweather/weather.c	(original)
+++ trunk/libgweather/weather.c	Wed Jun 18 18:17:09 2008
@@ -37,15 +37,11 @@
 #include <gtk/gtkicontheme.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk-pixbuf/gdk-pixbuf-loader.h>
-#include <libgnomevfs/gnome-vfs.h>
 
 #define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
 #include <libgweather/weather.h>
 #include "weather-priv.h"
 
-static void close_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data);
-
-
 /*
  * Convert string of the form "DD-MM-SSH" to radians
  * DD:degrees (to 3 digits), MM:minutes, SS:seconds H:hemisphere (NESW)
@@ -307,62 +303,16 @@
     if (info->requests_pending)
         return FALSE;
 
-    /*g_assert (!metar_handle && !iwin_handle && !wx_handle && !met_handle);*/
-
-    info->requests_pending = TRUE;
-
     return TRUE;
 }
 
-void
-request_done (GnomeVFSAsyncHandle *handle, WeatherInfo *info)
-{
-    if (!handle)
-    	return;
-
-    gnome_vfs_async_close (handle, close_cb, info);
-
-    info->sunValid = info->valid && calc_sun (info);
-    return;
-}
-
-void
-requests_done_check (WeatherInfo *info)
+void request_done (WeatherInfo *info, gboolean ok)
 {
-    g_return_if_fail (info->requests_pending);
+    if (ok)
+	info->sunValid = info->valid && calc_sun (info);
 
-    if (!info->metar_handle && !info->iwin_handle &&
-        !info->wx_handle && !info->met_handle &&
-	!info->bom_handle) {
-        info->requests_pending = FALSE;
+    if (!--info->requests_pending)
         info->finish_cb (info, info->cb_data);
-    }
-}
-
-static void
-close_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
-{
-    WeatherInfo *info = (WeatherInfo *)data;
-
-    g_return_if_fail (info != NULL);
-
-    if (result != GNOME_VFS_OK)
-	g_warning ("Error closing GnomeVFSAsyncHandle.\n");
-
-    if (handle == info->metar_handle)
-	info->metar_handle = NULL;
-    if (handle == info->iwin_handle)
-	info->iwin_handle = NULL;
-    if (handle == info->wx_handle)
-	info->wx_handle = NULL;
-    if (handle == info->met_handle)
-	info->met_handle = NULL;
-    if (handle == info->bom_handle)
-	info->bom_handle = NULL;
-
-    requests_done_check (info);
-
-    return;
 }
 
 /* Relative humidity computation - thanks to <Olof Oberg modopaper modogroup com> */
@@ -480,16 +430,7 @@
     /* FIXME: i'm not sure this works as intended anymore */
     if (!info) {
     	info = g_new0 (WeatherInfo, 1);
-        info->metar_handle = NULL;
-    	info->iwin_handle = NULL;
-    	info->wx_handle = NULL;
-    	info->met_handle = NULL;
-        info->bom_handle = NULL;
-    	info->requests_pending = FALSE;
-    	info->metar_buffer = NULL;
-        info->iwin_buffer = NULL;
-	info->met_buffer = NULL;
-	info->bom_buffer = NULL;
+    	info->requests_pending = 0;
     	info->location = weather_location_clone (location);
     } else {
         location = info->location;
@@ -535,21 +476,22 @@
     info->forecast = NULL;
     info->radar = NULL;
     info->radar_url = prefs->radar && prefs->radar_custom_url ?
-	g_strdup (prefs->radar_custom_url) : NULL;
-    info->metar_handle = NULL;
-    info->iwin_handle = NULL;
-    info->wx_handle = NULL;
-    info->met_handle = NULL;
-    info->bom_handle = NULL;
-    info->requests_pending = TRUE;
+    		      g_strdup (prefs->radar_custom_url) : NULL;
     info->finish_cb = cb;
     info->cb_data = data;
 
+    if (!info->session)
+	info->session = soup_session_async_new ();
+
     metar_start_open (info);
+    info->requests_pending++;
     iwin_start_open (info);
+    info->requests_pending++;
 
-    if (prefs->radar)
+    if (prefs->radar) {
         wx_start_open (info);
+	info->requests_pending++;
+    }
 
     return info;
 }
@@ -557,32 +499,10 @@
 void
 weather_info_abort (WeatherInfo *info)
 {
-    if (info->metar_handle) {
-	gnome_vfs_async_cancel (info->metar_handle);
-	info->metar_handle = NULL;
-    }
-
-    if (info->iwin_handle) {
-	gnome_vfs_async_cancel (info->iwin_handle);
-	info->iwin_handle = NULL;
-    }
-
-    if (info->wx_handle) {
-	gnome_vfs_async_cancel (info->wx_handle);
-	info->wx_handle = NULL;
-    }
-
-    if (info->met_handle) {
-	gnome_vfs_async_cancel (info->met_handle);
-	info->met_handle = NULL;
+    if (info->session) {
+	soup_session_abort (info->session);
+	info->requests_pending = 0;
     }
-
-    if (info->bom_handle) {
-	gnome_vfs_async_cancel (info->bom_handle);
-	info->bom_handle = NULL;
-    }
-
-    info->requests_pending = FALSE;
 }
 
 WeatherInfo *
@@ -619,6 +539,8 @@
         return;
 
     weather_info_abort (info);
+    if (info->session)
+	g_object_unref (info->session);
 
     weather_location_free (info->location);
     info->location = NULL;
@@ -630,19 +552,7 @@
         g_object_unref (info->radar);
         info->radar = NULL;
     }
-
-    if (info->iwin_buffer)
-	g_free (info->iwin_buffer);
-
-    if (info->metar_buffer)
-	g_free (info->metar_buffer);
-
-    if (info->met_buffer)
-        g_free (info->met_buffer);
-
-    if (info->bom_buffer)
-        g_free (info->bom_buffer);
-
+	
     g_free (info);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]