~ubuntu-branches/ubuntu/hardy/gnome-applets/hardy-proposed

« back to all changes in this revision

Viewing changes to libgweather/weather-bom.c

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2008-01-15 15:16:45 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20080115151645-7adqdys4ovi43xqs
Tags: 2.21.4-0ubuntu1
* New upstream development release.
  - Upstream news:
    . libgweather has been moved off to it's own module.
    . Accessx Status Applet:
       - Make bug buddy work for this applet (Kjartan Maraas).
    . Character Picker:
       - Documentation fixes.
    . CPU Frequency Monitor:
       - Fix memory leaks (kripkensteiner@gmail.com).
    . Keyboard Indicator:
       - The layout can now be printed from the preview (Sergey Udaltsov).
       - Require libgnomekbd 2.21.4.1 or later (Sergey Udaltsov).
    . Mixer:
       - Accelerators have been removed from the menu since they were.
         virtually never usable and now you won't be tempted to type Ctrl-T.
         in an unfortunate context. The normal under-score style menu.
         sortcuts are still available (Ted Gould).
    . Null Applet:
       - Make sure our example doesn't crash (Ray Strode).
    . Sticky Notes:
       - Better alignment in the UI (Christian Rose, Andrew Burton).
    . General:
       - Don't install documentation from obsolete applets (Kjartan Maraas).
    . Translations:
      ar, ca, es, et, eu, ga, he, nb, nn, oc, vi, sk, sv
    . Documentation Translations:
      ca, sv
  - Add a libgweather-dev (>= 2.21.1) build-dep.
  - Bump up libgnomekbdui-dev build-dep to >= 2.21.4.1.
  - Drop patches 05_gweather-dist-fixes, 06_gweather-dist-files,
    08_gweather_locations: the files which these patches used to dist and
    fix are now in libgweather.
  - Update autoreconf patch, 98_autoreconf.
  - Drop now useless gnome-applets-dev package.
  - Update gnome-applets' install file.
  - Drop DEB_DH_MAKESHLIBS_ARGS_gnome-applets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: weather-bom.c 9804 2006-08-07 14:05:56Z davyd $ */
2
 
 
3
 
/*
4
 
 *  Papadimitriou Spiros <spapadim+@cs.cmu.edu>
5
 
 *
6
 
 *  This code released under the GNU GPL.
7
 
 *  Read the file COPYING for more information.
8
 
 *
9
 
 *  Weather server functions (BOM)
10
 
 *
11
 
 */
12
 
 
13
 
#ifdef HAVE_CONFIG_H
14
 
#  include <config.h>
15
 
#endif
16
 
 
17
 
#include <string.h>
18
 
#include <libgweather/weather.h>
19
 
#include "weather-priv.h"
20
 
 
21
 
static gchar *bom_parse (gchar *meto)
22
 
23
 
    gchar *p, *rp;
24
 
 
25
 
    g_return_val_if_fail (meto != NULL, NULL);
26
 
 
27
 
    p = strstr(meto, "<pre>");
28
 
    g_return_val_if_fail (p != NULL, NULL);
29
 
 
30
 
    rp = strstr(p, "</pre>");
31
 
    g_return_val_if_fail (rp !=NULL, NULL);
32
 
    
33
 
    p += 5; /* skip the <pre> */
34
 
 
35
 
    return g_strndup(p, rp-p);
36
 
}
37
 
 
38
 
static void bom_finish_read(GnomeVFSAsyncHandle *handle, GnomeVFSResult result, 
39
 
                            gpointer buffer, GnomeVFSFileSize requested, 
40
 
                            GnomeVFSFileSize body_len, gpointer data)
41
 
{
42
 
    WeatherInfo *info = (WeatherInfo *)data;
43
 
    gchar *body, *forecast, *temp;
44
 
 
45
 
    g_return_if_fail(info != NULL);
46
 
    g_return_if_fail(handle == info->bom_handle);
47
 
 
48
 
    info->forecast = NULL;
49
 
    body = (gchar *)buffer;
50
 
    body[body_len] = '\0';
51
 
        
52
 
    if (info->bom_buffer == NULL)
53
 
        info->bom_buffer = g_strdup(body);
54
 
    else
55
 
    {
56
 
        temp = g_strdup(info->bom_buffer);
57
 
        g_free(info->bom_buffer);
58
 
        info->bom_buffer = g_strdup_printf("%s%s", temp, body);
59
 
        g_free(temp);
60
 
    }
61
 
        
62
 
    if (result == GNOME_VFS_ERROR_EOF)
63
 
    {
64
 
        forecast = bom_parse(info->bom_buffer);
65
 
        info->forecast = forecast;
66
 
    }
67
 
    else if (result != GNOME_VFS_OK) {
68
 
        info->bom_handle = NULL;
69
 
        requests_done_check (info);
70
 
        g_warning("Failed to get BOM data.\n");
71
 
    } else {
72
 
        gnome_vfs_async_read(handle, body, DATA_SIZE - 1, bom_finish_read, info);
73
 
 
74
 
        return;
75
 
    }
76
 
    
77
 
    request_done(info->bom_handle, info);
78
 
    g_free (buffer);
79
 
    return;
80
 
}
81
 
 
82
 
static void bom_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
83
 
{
84
 
    WeatherInfo *info = (WeatherInfo *)data;
85
 
    WeatherLocation *loc;
86
 
    gchar *body;
87
 
 
88
 
    g_return_if_fail(info != NULL);
89
 
    g_return_if_fail(handle == info->bom_handle);
90
 
 
91
 
    body = g_malloc0(DATA_SIZE);
92
 
 
93
 
    info->bom_buffer = NULL;
94
 
    if (info->forecast)
95
 
        g_free (info->forecast);        
96
 
    info->forecast = NULL;
97
 
    loc = info->location;
98
 
    g_return_if_fail(loc != NULL);
99
 
 
100
 
    if (result != GNOME_VFS_OK) {
101
 
        g_warning("Failed to get BOM forecast data.\n");
102
 
        info->bom_handle = NULL;
103
 
        requests_done_check (info);
104
 
        g_free (body);
105
 
    } else {
106
 
        gnome_vfs_async_read(handle, body, DATA_SIZE - 1, bom_finish_read, info);
107
 
    }
108
 
    return;
109
 
}
110
 
 
111
 
void bom_start_open (WeatherInfo *info)
112
 
{
113
 
    gchar *url;
114
 
    WeatherLocation *loc;
115
 
    loc = info->location;
116
 
  
117
 
    url = g_strdup_printf("http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?%s.txt",
118
 
                          loc->zone+1);
119
 
 
120
 
    gnome_vfs_async_open(&info->bom_handle, url, GNOME_VFS_OPEN_READ, 
121
 
                         0, bom_finish_open, info);
122
 
    g_free(url);
123
 
 
124
 
    return;
125
 
}