~ubuntu-branches/ubuntu/natty/xfce4-weather-plugin/natty-proposed

« back to all changes in this revision

Viewing changes to panel-plugin/weather-parsers.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Simon Huggins, Yves-Alexis Perez
  • Date: 2007-12-08 19:28:17 UTC
  • mfrom: (0.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208192817-xjr2u2eshv19ndp5
Tags: 0.6.2-1
[ Simon Huggins ]
* debian/control: Move fake Homepage field to a real one now dpkg
  supports it.
* Add Vcs-* headers to debian/control

[ Yves-Alexis Perez ]
* New upstream release.
* debian/control:
  - updated standard versions to 3.7.3.
  - updated my email to the debian.org one.
* debian/copyright: updated copyrights, authors and license.
* debian/NEWS: remove tab at beginning of lines. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: weather-parsers.c 2366 2007-01-15 19:10:23Z nick $
 
2
 *
 
3
 *  Copyright (c) 2003-2007 Xfce Development Team
 
4
 * 
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU Library General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include <config.h>
 
22
#endif
 
23
 
 
24
#include "weather-parsers.h"
 
25
#include <libxfce4panel/xfce-panel-macros.h>
 
26
 
 
27
 
 
28
 
 
29
xml_weather *
 
30
parse_weather (xmlNode *cur_node)
 
31
{
 
32
  xml_weather *ret;
 
33
  xmlNode     *child_node;
 
34
  guint        i = 0;
 
35
 
 
36
  if (!NODE_IS_TYPE (cur_node, "weather"))
 
37
    {
 
38
      return NULL;
 
39
    }
 
40
 
 
41
  if ((ret = panel_slice_new0 (xml_weather)) == NULL)
 
42
    return NULL;
 
43
 
 
44
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
45
    {
 
46
      if (cur_node->type != XML_ELEMENT_NODE)
 
47
        continue;
 
48
 
 
49
      if (NODE_IS_TYPE (cur_node, "cc"))
 
50
        ret->cc = parse_cc (cur_node);
 
51
      else if (NODE_IS_TYPE (cur_node, "loc"))
 
52
        ret->loc = parse_loc (cur_node);
 
53
      else if (NODE_IS_TYPE (cur_node, "dayf"))
 
54
        {
 
55
          for (child_node = cur_node->children; child_node;
 
56
               child_node = child_node->next)
 
57
            {
 
58
              if (NODE_IS_TYPE (child_node, "day"))
 
59
                {
 
60
                  if (i >= XML_WEATHER_DAYF_N)
 
61
                    break;
 
62
 
 
63
                  ret->dayf[i] = parse_dayf (child_node);
 
64
 
 
65
                  i++;
 
66
                }
 
67
            }
 
68
        }
 
69
    }
 
70
 
 
71
  return ret;
 
72
}
 
73
 
 
74
 
 
75
 
 
76
xml_loc *
 
77
parse_loc (xmlNode *cur_node)
 
78
{
 
79
  xml_loc *ret;
 
80
 
 
81
  if ((ret = panel_slice_new0 (xml_loc)) == NULL)
 
82
    return NULL;
 
83
 
 
84
 
 
85
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
86
    {
 
87
      if (cur_node->type != XML_ELEMENT_NODE)
 
88
        continue;
 
89
 
 
90
      if (NODE_IS_TYPE (cur_node, "dnam"))
 
91
        ret->dnam = DATA (cur_node);
 
92
      else if (NODE_IS_TYPE (cur_node, "sunr"))
 
93
        ret->sunr = DATA (cur_node);
 
94
      else if (NODE_IS_TYPE (cur_node, "suns"))
 
95
        ret->suns = DATA (cur_node);
 
96
    }
 
97
 
 
98
  return ret;
 
99
}
 
100
 
 
101
 
 
102
 
 
103
static xml_uv *
 
104
parse_uv (xmlNode *cur_node)
 
105
{
 
106
  xml_uv *ret;
 
107
 
 
108
  if ((ret = panel_slice_new0 (xml_uv)) == NULL)
 
109
    return NULL;
 
110
 
 
111
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
112
    {
 
113
      if (cur_node->type != XML_ELEMENT_NODE)
 
114
        continue;
 
115
 
 
116
      if (NODE_IS_TYPE (cur_node, "i"))
 
117
        ret->i = DATA (cur_node);
 
118
      else if (NODE_IS_TYPE (cur_node, "t"))
 
119
        ret->t = DATA (cur_node);
 
120
    }
 
121
 
 
122
  return ret;
 
123
}
 
124
 
 
125
 
 
126
 
 
127
static xml_bar *
 
128
parse_bar (xmlNode *cur_node)
 
129
{
 
130
  xml_bar *ret;
 
131
 
 
132
  if ((ret = panel_slice_new0 (xml_bar)) == NULL)
 
133
    return NULL;
 
134
 
 
135
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
136
    {
 
137
      if (cur_node->type != XML_ELEMENT_NODE)
 
138
        continue;
 
139
 
 
140
      if (NODE_IS_TYPE (cur_node, "r"))
 
141
        ret->r = DATA (cur_node);
 
142
      else if (NODE_IS_TYPE (cur_node, "d"))
 
143
        ret->d = DATA (cur_node);
 
144
    }
 
145
 
 
146
  return ret;
 
147
}
 
148
 
 
149
 
 
150
 
 
151
static xml_wind *
 
152
parse_wind (xmlNode *cur_node)
 
153
{
 
154
  xml_wind *ret;
 
155
 
 
156
  if ((ret = panel_slice_new0 (xml_wind)) == NULL)
 
157
    return NULL;
 
158
 
 
159
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
160
    {
 
161
      if (cur_node->type != XML_ELEMENT_NODE)
 
162
        continue;
 
163
 
 
164
      if (NODE_IS_TYPE (cur_node, "s"))
 
165
        ret->s = DATA (cur_node);
 
166
      else if (NODE_IS_TYPE (cur_node, "gust"))
 
167
        ret->gust = DATA (cur_node);
 
168
      else if (NODE_IS_TYPE (cur_node, "d"))
 
169
        ret->d = DATA (cur_node);
 
170
      else if (NODE_IS_TYPE (cur_node, "t"))
 
171
        ret->t = DATA (cur_node);
 
172
    }
 
173
 
 
174
  return ret;
 
175
}
 
176
 
 
177
 
 
178
 
 
179
xml_cc *
 
180
parse_cc (xmlNode *cur_node)
 
181
{
 
182
  xml_cc *ret;
 
183
 
 
184
  if ((ret = panel_slice_new0 (xml_cc)) == NULL)
 
185
    return NULL;
 
186
 
 
187
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
188
    {
 
189
      if (cur_node->type != XML_ELEMENT_NODE)
 
190
        continue;
 
191
 
 
192
      if (NODE_IS_TYPE (cur_node, "tmp"))
 
193
        ret->tmp = DATA (cur_node);
 
194
      else if (NODE_IS_TYPE (cur_node, "icon"))
 
195
        ret->icon = DATA (cur_node);
 
196
      else if (NODE_IS_TYPE (cur_node, "t"))
 
197
        ret->t = DATA (cur_node);
 
198
      else if (NODE_IS_TYPE (cur_node, "flik"))
 
199
        ret->flik = DATA (cur_node);
 
200
      else if (NODE_IS_TYPE (cur_node, "bar"))
 
201
        ret->bar = parse_bar (cur_node);
 
202
      else if (NODE_IS_TYPE (cur_node, "wind"))
 
203
        ret->wind = parse_wind (cur_node);
 
204
      else if (NODE_IS_TYPE (cur_node, "hmid"))
 
205
        ret->hmid = DATA (cur_node);
 
206
      else if (NODE_IS_TYPE (cur_node, "vis"))
 
207
        ret->vis = DATA (cur_node);
 
208
      else if (NODE_IS_TYPE (cur_node, "uv"))
 
209
        ret->uv = parse_uv (cur_node);
 
210
      else if (NODE_IS_TYPE (cur_node, "dewp"))
 
211
        ret->dewp = DATA (cur_node);
 
212
      else if (NODE_IS_TYPE (cur_node, "lsup"))
 
213
        ret->lsup = DATA (cur_node);
 
214
      else if (NODE_IS_TYPE (cur_node, "obst"))
 
215
        ret->obst = DATA (cur_node);
 
216
    }
 
217
 
 
218
  return ret;
 
219
}
 
220
 
 
221
 
 
222
 
 
223
static xml_part *
 
224
parse_part (xmlNode *cur_node)
 
225
{
 
226
  xml_part *ret;
 
227
 
 
228
  if ((ret = panel_slice_new0 (xml_part)) == NULL)
 
229
    return NULL;
 
230
 
 
231
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
232
    {
 
233
      if (cur_node->type != XML_ELEMENT_NODE)
 
234
        continue;
 
235
 
 
236
      if (NODE_IS_TYPE (cur_node, "icon"))
 
237
        ret->icon = DATA (cur_node);
 
238
      else if (NODE_IS_TYPE (cur_node, "t"))
 
239
        ret->t = DATA (cur_node);
 
240
      else if (NODE_IS_TYPE (cur_node, "wind"))
 
241
        ret->wind = parse_wind (cur_node);
 
242
      else if (NODE_IS_TYPE (cur_node, "ppcp"))
 
243
        ret->ppcp = DATA (cur_node);
 
244
      else if (NODE_IS_TYPE (cur_node, "hmid"))
 
245
        ret->hmid = DATA (cur_node);
 
246
    }
 
247
 
 
248
  return ret;
 
249
}
 
250
 
 
251
 
 
252
 
 
253
xml_dayf *
 
254
parse_dayf (xmlNode *cur_node)
 
255
{
 
256
  xml_dayf *ret;
 
257
  gchar    *value;
 
258
 
 
259
  if ((ret = panel_slice_new0 (xml_dayf)) == NULL)
 
260
    return NULL;
 
261
 
 
262
  ret->day = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "t");
 
263
  ret->date = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "dt");
 
264
 
 
265
  for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
 
266
    {
 
267
      if (cur_node->type != XML_ELEMENT_NODE)
 
268
        continue;
 
269
 
 
270
      if (NODE_IS_TYPE (cur_node, "hi"))
 
271
        {
 
272
          ret->hi = DATA (cur_node);
 
273
          g_assert (ret->hi != NULL);
 
274
        }
 
275
      else if (NODE_IS_TYPE (cur_node, "low"))
 
276
        {
 
277
          ret->low = DATA (cur_node);
 
278
        }
 
279
      else if (NODE_IS_TYPE (cur_node, "part"))
 
280
        {
 
281
          value = (gchar *) xmlGetProp (cur_node, (const xmlChar *) "p");
 
282
 
 
283
          if (xmlStrEqual ((const xmlChar *) value, (const xmlChar *) "d"))
 
284
            ret->part[0] = parse_part (cur_node);
 
285
          else
 
286
            if (xmlStrEqual ((const xmlChar *) value, (const xmlChar *) "n"))
 
287
            ret->part[1] = parse_part (cur_node);
 
288
 
 
289
          g_free (value);
 
290
        }
 
291
    }
 
292
 
 
293
  return ret;
 
294
}
 
295
 
 
296
 
 
297
 
 
298
static void
 
299
xml_uv_free (xml_uv * data)
 
300
{
 
301
  g_free (data->i);
 
302
  g_free (data->t);
 
303
 
 
304
  panel_slice_free (xml_uv, data);
 
305
}
 
306
 
 
307
 
 
308
 
 
309
static void
 
310
xml_wind_free (xml_wind * data)
 
311
{
 
312
  g_free (data->s);
 
313
  g_free (data->gust);
 
314
  g_free (data->d);
 
315
  g_free (data->t);
 
316
 
 
317
  panel_slice_free (xml_wind, data);
 
318
}
 
319
 
 
320
 
 
321
 
 
322
static void
 
323
xml_bar_free (xml_bar * data)
 
324
{
 
325
  g_free (data->r);
 
326
  g_free (data->d);
 
327
 
 
328
  panel_slice_free (xml_bar, data);
 
329
}
 
330
 
 
331
 
 
332
 
 
333
static void
 
334
xml_cc_free (xml_cc * data)
 
335
{
 
336
  g_free (data->obst);
 
337
  g_free (data->lsup);
 
338
  g_free (data->flik);
 
339
  g_free (data->t);
 
340
  g_free (data->icon);
 
341
  g_free (data->tmp);
 
342
  g_free (data->hmid);
 
343
  g_free (data->vis);
 
344
  g_free (data->dewp);
 
345
 
 
346
  if (data->uv)
 
347
    xml_uv_free (data->uv);
 
348
 
 
349
  if (data->wind)
 
350
    xml_wind_free (data->wind);
 
351
 
 
352
  if (data->bar)
 
353
    xml_bar_free (data->bar);
 
354
 
 
355
  panel_slice_free (xml_cc, data);
 
356
}
 
357
 
 
358
 
 
359
 
 
360
static void
 
361
xml_loc_free (xml_loc *data)
 
362
{
 
363
  g_free (data->dnam);
 
364
  g_free (data->sunr);
 
365
  g_free (data->suns);
 
366
 
 
367
  panel_slice_free (xml_loc, data);
 
368
}
 
369
 
 
370
 
 
371
 
 
372
static void
 
373
xml_part_free (xml_part *data)
 
374
{
 
375
  if (!data)
 
376
    return;
 
377
 
 
378
  g_free (data->icon);
 
379
  g_free (data->t);
 
380
  g_free (data->ppcp);
 
381
  g_free (data->hmid);
 
382
 
 
383
  if (data->wind)
 
384
    xml_wind_free (data->wind);
 
385
 
 
386
  panel_slice_free (xml_part, data);
 
387
}
 
388
 
 
389
 
 
390
 
 
391
static void
 
392
xml_dayf_free (xml_dayf *data)
 
393
{
 
394
  if (!data)
 
395
    return;
 
396
 
 
397
  g_free (data->day);
 
398
  g_free (data->date);
 
399
  g_free (data->hi);
 
400
  g_free (data->low);
 
401
 
 
402
  if (data->part[0])
 
403
    xml_part_free (data->part[0]);
 
404
 
 
405
  if (data->part[1])
 
406
    xml_part_free (data->part[1]);
 
407
 
 
408
  panel_slice_free (xml_dayf, data);
 
409
}
 
410
 
 
411
 
 
412
 
 
413
void
 
414
xml_weather_free (xml_weather *data)
 
415
{
 
416
  guint i;
 
417
 
 
418
  if (data->cc)
 
419
    xml_cc_free (data->cc);
 
420
 
 
421
  if (data->loc)
 
422
    xml_loc_free (data->loc);
 
423
 
 
424
  if (data->dayf)
 
425
    {
 
426
      for (i = 0; i < XML_WEATHER_DAYF_N; i++)
 
427
        {
 
428
          if (!data->dayf[i])
 
429
            break;
 
430
 
 
431
          xml_dayf_free (data->dayf[i]);
 
432
        }
 
433
    }
 
434
 
 
435
  panel_slice_free (xml_weather, data);
 
436
}