[Xfce4-commits] <xfce4-weather-plugin:master> Make timezone a double value and integrate dst value into it.

Harald Judt noreply at xfce.org
Sat Jan 5 12:04:09 CET 2013


Updating branch refs/heads/master
         to fa2769012fb3f1ea0c47f40136c9f1bc8793a132 (commit)
       from db31d45ebe7dc9defb8c198219c9c677965751f4 (commit)

commit fa2769012fb3f1ea0c47f40136c9f1bc8793a132
Author: Harald Judt <h.judt at gmx.at>
Date:   Fri Dec 21 11:33:09 2012 +0100

    Make timezone a double value and integrate dst value into it.
    
    There are timezones/dsts that are just half an hour off, not a whole hour,
    e.g. Australian locations.
    
    Let's include daylight saving times into the timezone value and increase
    limits to +/- 25 hours. Without adding additional dependencies, the
    user has to alter the correction manually. This will be improved in
    the next version (glib version has to be increased to 2.26 for GDateTime
    and GTimezone support).

 panel-plugin/weather-config.c |   14 ++++++++------
 panel-plugin/weather-debug.c  |    2 +-
 panel-plugin/weather.c        |   26 ++++++++++++++++++--------
 panel-plugin/weather.h        |    2 +-
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 701f8c5..a531068 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -249,14 +249,14 @@ cb_lookup_timezone(SoupSession *session,
 {
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
     xml_timezone *timezone;
-    gint tz;
+    gdouble 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);
+        tz = string_to_double(timezone->offset, -9999);
         if (tz != -9999)
             gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->spin_timezone),
                                       tz);
@@ -475,7 +475,7 @@ spin_timezone_value_changed(const GtkWidget *spin,
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
 
     dialog->pd->timezone =
-        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+        gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
 }
 
 
@@ -577,13 +577,15 @@ create_location_page(xfceweather_dialog *dialog)
     /* timezone */
     hbox = gtk_hbox_new(FALSE, BORDER);
     ADD_LABEL(_("_Timezone:"), sg_label);
-    ADD_SPIN(dialog->spin_timezone, -24, 24, 1,
-             dialog->pd->timezone, 0, sg_spin);
+    ADD_SPIN(dialog->spin_timezone, -25, 25, 0.5,
+             dialog->pd->timezone, 1, sg_spin);
     SET_TOOLTIP
         (dialog->spin_timezone,
          _("If the chosen location is not in your current timezone, this "
            "value which is auto-detected using the EarthTools web service "
-           "will be used for correcting the time differences."));
+           "will be used for correcting the time differences. Please adjust "
+           "it manually to accomodate for daylight summer time or if it "
+           "is not correct."));
     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, BORDER);
 
     /* instructions for correction of altitude and timezone */
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index 5fb6b50..fce55d7 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -430,7 +430,7 @@ weather_dump_plugindata(const plugin_data *data)
                            "  latitude: %s\n"
                            "  longitude: %s\n"
                            "  msl: %d\n"
-                           "  timezone: %d\n"
+                           "  timezone: %.1f\n"
                            "  night time: %s\n"
                            "  --------------------------------------------\n"
                            "  icon theme dir: %s\n"
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 446630d..e6d64b5 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -720,8 +720,12 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
     data->msl = xfce_rc_read_int_entry(rc, "msl", 0);
     constrain_to_limits(&data->msl, -420, 10000);
 
-    data->timezone = xfce_rc_read_int_entry(rc, "timezone", 0);
-    constrain_to_limits(&data->timezone, -24, 24);
+    value = xfce_rc_read_entry(rc, "timezone", 0);
+    data->timezone = string_to_double(value, 0);
+    if (data->timezone < -25.0)
+        data->timezone = -25;
+    if (data->timezone > 25.0)
+        data->timezone = 25;
 
     data->cache_file_max_age =
         xfce_rc_read_int_entry(rc, "cache_file_max_age", CACHE_FILE_MAX_AGE);
@@ -830,7 +834,9 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
 
     xfce_rc_write_int_entry(rc, "msl", data->msl);
 
-    xfce_rc_write_int_entry(rc, "timezone", data->timezone);
+    value = double_to_string(data->timezone, "%.1f");
+    xfce_rc_write_entry(rc, "timezone", value);
+    g_free(value);
 
     xfce_rc_write_int_entry(rc, "cache_file_max_age",
                             data->cache_file_max_age);
@@ -909,7 +915,7 @@ write_cache_file(plugin_data *data)
     xml_weather *wd = data->weatherdata;
     xml_time *timeslice;
     xml_location *loc;
-    gchar *file, *start, *end, *point, *now;
+    gchar *file, *start, *end, *point, *now, *value;
     gchar *date_format = "%Y-%m-%dT%H:%M:%SZ";
     time_t now_t = time(NULL);
     gint i, j;
@@ -923,8 +929,11 @@ write_cache_file(plugin_data *data)
     CACHE_APPEND("location_name=%s\n", data->location_name);
     CACHE_APPEND("lat=%s\n", data->lat);
     CACHE_APPEND("lon=%s\n", data->lon);
-    g_string_append_printf(out, "msl=%d\ntimezone=%d\ntimeslices=%d\n",
-                           data->msl, data->timezone, wd->timeslices->len);
+    g_string_append_printf(out, "msl=%d\n", data->msl);
+    g_string_append_printf(out, "timeslices=%d\n", wd->timeslices->len);
+    value = double_to_string(data->timezone, "%.1f");
+    CACHE_APPEND("timezone=%s\n", value);
+    g_free(value);
     now = format_date(now_t, date_format, FALSE);
     CACHE_APPEND("cache_date=%s\n\n", now);
     g_free(now);
@@ -991,7 +1000,8 @@ read_cache_file(plugin_data *data)
     time_t now_t = time(NULL), cache_date_t;
     gchar *file, *locname = NULL, *lat = NULL, *lon = NULL, *group = NULL;
     gchar *timestring;
-    gint msl, timezone, num_timeslices, i, j;
+    gdouble timezone;
+    gint msl, num_timeslices, i, j;
 
     g_assert(data != NULL);
     if (G_UNLIKELY(data == NULL))
@@ -1032,7 +1042,7 @@ read_cache_file(plugin_data *data)
     }
     msl = g_key_file_get_integer(keyfile, group, "msl", err);
     if (!err)
-        timezone = g_key_file_get_integer(keyfile, group, "timezone", err);
+        timezone = g_key_file_get_double(keyfile, group, "timezone", err);
     if (!err)
         num_timeslices = g_key_file_get_integer(keyfile, group,
                                                 "timeslices", err);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index e3461c3..a802e58 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -98,7 +98,7 @@ typedef struct {
     gchar *lat;
     gchar *lon;
     gint msl;
-    gint timezone;
+    gdouble timezone;
     gint cache_file_max_age;
     gboolean night_time;
 


More information about the Xfce4-commits mailing list