[Xfce4-commits] <xfce4-weather-plugin:master> weather-parsers: Prepare to move geolocation parsing code.
Harald Judt
noreply at xfce.org
Fri Aug 3 01:06:02 CEST 2012
Updating branch refs/heads/master
to 3e0a83e6855a0a71762a564317c3795600688a23 (commit)
from 325e943c0868b6f8fbc4bc421fb26e8697c233e4 (commit)
commit 3e0a83e6855a0a71762a564317c3795600688a23
Author: Harald Judt <h.judt at gmx.at>
Date: Fri Aug 3 00:06:36 2012 +0200
weather-parsers: Prepare to move geolocation parsing code.
All XML parsing should be done in weather-parsers.
panel-plugin/weather-parsers.c | 47 ++++++++++++++++++++++++++++++++++++++++
panel-plugin/weather-parsers.h | 13 +++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 5a70161..1359b09 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -372,6 +372,38 @@ parse_astro(xmlNode *cur_node)
}
+xml_geolocation *
+parse_geolocation(xmlNode *cur_node)
+{
+ xml_geolocation *geo;
+
+ g_assert(cur_node != NULL);
+ if (G_UNLIKELY(cur_node == NULL))
+ return NULL;
+
+ geo = g_slice_new0(xml_geolocation);
+ if (G_UNLIKELY(geo == NULL))
+ return NULL;
+
+ for (cur_node = cur_node->children; cur_node;
+ cur_node = cur_node->next) {
+ if (NODE_IS_TYPE(cur_node, "City"))
+ geo->city = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "CountryName"))
+ geo->country_name = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "CountryCode"))
+ geo->country_code = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "RegionName"))
+ geo->region_name = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "Latitude"))
+ geo->latitude = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "Longitude"))
+ geo->longitude = DATA(cur_node);
+ }
+ return geo;
+}
+
+
static void
xml_location_free(xml_location *loc)
{
@@ -443,3 +475,18 @@ xml_astro_free(xml_astro *astro)
g_slice_free(xml_astro, astro);
astro = NULL;
}
+
+
+void
+xml_geolocation_free(xml_geolocation *geo)
+{
+ g_assert(geo != NULL);
+ if (G_UNLIKELY(geo == NULL))
+ return;
+ g_free(geo->city);
+ g_free(geo->country_name);
+ g_free(geo->country_code);
+ g_free(geo->region_name);
+ g_free(geo->latitude);
+ g_free(geo->longitude);
+}
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 03bfb94..fe26e48 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -98,11 +98,22 @@ typedef struct {
gchar *moon_phase;
} xml_astro;
+typedef struct {
+ gchar *city;
+ gchar *country_name;
+ gchar *country_code;
+ gchar *region_name;
+ gchar *latitude;
+ gchar *longitude;
+} xml_geolocation;
+
xml_weather *parse_weather(xmlNode *cur_node);
xml_astro *parse_astro(xmlNode *cur_node);
+xml_geolocation *parse_geolocation(xmlNode *cur_node);
+
xml_time *get_timeslice(xml_weather *data,
const time_t start_t,
const time_t end_t);
@@ -113,6 +124,8 @@ void xml_weather_free(xml_weather *data);
void xml_astro_free(xml_astro *astro);
+void xml_geolocation_free(xml_geolocation *geo);
+
G_END_DECLS
#endif
More information about the Xfce4-commits
mailing list