[Xfce4-commits] <xfce4-weather-plugin:master> Implement earthtools.org timezone detection.
Harald Judt
noreply at xfce.org
Tue Nov 27 16:46:05 CET 2012
Updating branch refs/heads/master
to f553076d8b61f5cb5ec57e113d0d53120eca1a31 (commit)
from 4220403887e70748535e5c365d200fa34bc430ec (commit)
commit f553076d8b61f5cb5ec57e113d0d53120eca1a31
Author: Harald Judt <h.judt at gmx.at>
Date: Thu Nov 22 11:12:43 2012 +0100
Implement earthtools.org timezone detection.
panel-plugin/weather-config.c | 50 +++++++++++++++++++++++++++++++++++++
panel-plugin/weather-debug.c | 27 ++++++++++++++++++++
panel-plugin/weather-debug.h | 2 +
panel-plugin/weather-parsers.c | 53 ++++++++++++++++++++++++++++++++++++++-
panel-plugin/weather-parsers.h | 15 ++++++++++-
5 files changed, 143 insertions(+), 4 deletions(-)
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 83b9c82..514ebed 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -436,6 +436,54 @@ button_lookup_altitude_clicked(GtkButton *button,
}
+static void
+cb_lookup_timezone(SoupSession *session,
+ SoupMessage *msg,
+ gpointer user_data)
+{
+ xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+ xml_timezone *timezone = NULL;
+ gint tz;
+
+ timezone = (xml_timezone *)
+ parse_xml_document(msg, (XmlParseFunc) parse_timezone);
+ weather_dump(weather_dump_timezone, timezone);
+
+ if (timezone) {
+ tz = (gint) string_to_double(timezone->offset, -9999);
+ if (tz != -9999)
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->spin_timezone),
+ tz);
+ xml_timezone_free(timezone);
+ }
+}
+
+
+static gboolean
+button_lookup_timezone_clicked(GtkButton *button,
+ gpointer user_data)
+{
+ xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+ gchar *url, latbuf[10], lonbuf[10];
+ gdouble lat, lon;
+
+ gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
+ lat = gtk_spin_button_get_value(GTK_SPIN_BUTTON(dialog->spin_lat));
+ lon = gtk_spin_button_get_value(GTK_SPIN_BUTTON(dialog->spin_lon));
+
+ (void) g_ascii_formatd(latbuf, 10, "%.6f", lat);
+ (void) g_ascii_formatd(lonbuf, 10, "%.6f", lon);
+
+ url = g_strdup_printf("http://www.earthtools.org/timezone/%s/%s",
+ &latbuf[0], &lonbuf[0]);
+ weather_http_queue_request(dialog->wd->session, url,
+ cb_lookup_timezone, user_data);
+ g_free(url);
+ gtk_widget_set_sensitive(GTK_WIDGET(button), TRUE);
+ return FALSE;
+}
+
+
static GtkWidget *
create_location_page(xfceweather_dialog *dialog)
{
@@ -547,6 +595,8 @@ create_location_page(xfceweather_dialog *dialog)
button_timezone_lookup =
gtk_button_new_with_mnemonic(_("Lookup time_zone"));
gtk_size_group_add_widget(sg_button, button_timezone_lookup);
+ g_signal_connect(G_OBJECT(button_timezone_lookup), "clicked",
+ G_CALLBACK(button_lookup_timezone_clicked), dialog);
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table),
dialog->spin_timezone, 1, 2, 1, 2);
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index 06c9cf1..41d19f7 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -172,6 +172,33 @@ weather_dump_place(const xml_place *place)
gchar *
+weather_dump_timezone(const xml_timezone *tz)
+{
+ gchar *out;
+
+ if (!tz)
+ return g_strdup("No timezone data.");
+
+ out = g_strdup_printf("Timezone data:\n"
+ " --------------------------------------------\n"
+ " offset: %s\n"
+ " suffix: %s\n"
+ " dst: %s\n"
+ " localtime: %s\n"
+ " isotime: %s\n"
+ " utctime: %s\n"
+ " --------------------------------------------",
+ tz->offset,
+ tz->suffix,
+ tz->dst,
+ tz->localtime,
+ tz->isotime,
+ tz->utctime);
+ return out;
+}
+
+
+gchar *
weather_dump_icon_theme(const icon_theme *theme)
{
gchar *out;
diff --git a/panel-plugin/weather-debug.h b/panel-plugin/weather-debug.h
index 092c9be..97b8e50 100644
--- a/panel-plugin/weather-debug.h
+++ b/panel-plugin/weather-debug.h
@@ -64,6 +64,8 @@ gchar *weather_dump_geolocation(const xml_geolocation *geo);
gchar *weather_dump_place(const xml_place *place);
+gchar *weather_dump_timezone(const xml_timezone *timezone);
+
gchar *weather_dump_icon_theme(const icon_theme *theme);
gchar *weather_dump_astrodata(const xml_astro *astrodata);
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 2e473b8..e9c1bf9 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -455,14 +455,47 @@ parse_altitude(xmlNode *cur_node)
if (G_UNLIKELY(alt == NULL))
return NULL;
for (cur_node = cur_node->children; cur_node;
- cur_node = cur_node->next) {
+ cur_node = cur_node->next)
if (NODE_IS_TYPE(cur_node, "srtm3"))
alt->altitude = DATA(cur_node);
- }
return alt;
}
+xml_timezone *
+parse_timezone(xmlNode *cur_node)
+{
+ xml_timezone *tz;
+
+ g_assert(cur_node != NULL);
+ if (G_UNLIKELY(cur_node == NULL))
+ return NULL;
+
+ if (!NODE_IS_TYPE(cur_node, "timezone"))
+ return NULL;
+
+ tz = g_slice_new0(xml_timezone);
+ if (G_UNLIKELY(tz == NULL))
+ return NULL;
+ for (cur_node = cur_node->children; cur_node;
+ cur_node = cur_node->next) {
+ if (NODE_IS_TYPE(cur_node, "offset"))
+ tz->offset = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "suffix"))
+ tz->suffix = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "dst"))
+ tz->dst = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "localtime"))
+ tz->localtime = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "isotime"))
+ tz->isotime = DATA(cur_node);
+ if (NODE_IS_TYPE(cur_node, "utctime"))
+ tz->utctime = DATA(cur_node);
+ }
+ return tz;
+}
+
+
xmlDoc *
get_xml_document(SoupMessage *msg)
{
@@ -608,3 +641,19 @@ xml_altitude_free(xml_altitude *alt)
g_free(alt->altitude);
g_slice_free(xml_altitude, alt);
}
+
+
+void
+xml_timezone_free(xml_timezone *tz)
+{
+ g_assert(tz != NULL);
+ if (G_UNLIKELY(tz == NULL))
+ return;
+ g_free(tz->offset);
+ g_free(tz->suffix);
+ g_free(tz->dst);
+ g_free(tz->localtime);
+ g_free(tz->isotime);
+ g_free(tz->utctime);
+ g_slice_free(xml_timezone, tz);
+}
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 144926f..86166ea 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -102,18 +102,25 @@ typedef struct {
gchar *longitude;
} xml_geolocation;
-
typedef struct {
gchar *display_name;
gchar *lat;
gchar *lon;
} xml_place;
-
typedef struct {
gchar *altitude;
} xml_altitude;
+typedef struct {
+ gchar *offset;
+ gchar *suffix;
+ gchar *dst;
+ gchar *localtime;
+ gchar *isotime;
+ gchar *utctime;
+} xml_timezone;
+
xml_weather *parse_weather(xmlNode *cur_node);
@@ -125,6 +132,8 @@ xml_place *parse_place(xmlNode *cur_node);
xml_altitude *parse_altitude(xmlNode *cur_node);
+xml_timezone *parse_timezone(xmlNode *cur_node);
+
xml_time *get_timeslice(xml_weather *data,
const time_t start_t,
const time_t end_t);
@@ -146,6 +155,8 @@ void xml_place_free(xml_place *place);
void xml_altitude_free(xml_altitude *alt);
+void xml_timezone_free(xml_timezone *tz);
+
G_END_DECLS
#endif
More information about the Xfce4-commits
mailing list