Commit 15950e3e authored by Harald Judt's avatar Harald Judt

Summary window: Add date of last update to details tab (bug #9499).

parent 2f811dd1
......@@ -75,6 +75,31 @@ string_to_double(const gchar *str,
}
gchar *
format_date(const time_t date_t,
gchar *format,
gboolean local)
{
struct tm *tm;
time_t t = date_t;
gchar buf[40];
size_t size;
if (G_LIKELY(local))
tm = localtime(&t);
else
tm = gmtime(&t);
/* A year <= 1970 means date has not been set */
if (G_UNLIKELY(tm == NULL) || tm->tm_year <= 70)
return g_strdup("-");
if (format == NULL)
format = "%Y-%m-%d %H:%M:%S";
size = strftime(buf, 40, format, tm);
return (size ? g_strdup(buf) : g_strdup("-"));
}
/* check whether timeslice is interval or point data */
gboolean
timeslice_is_interval(xml_time *timeslice)
......
......@@ -90,6 +90,10 @@ typedef struct {
gdouble string_to_double(const gchar *str,
gdouble backup);
gchar *format_date(const time_t t,
gchar *format,
gboolean local);
gboolean timeslice_is_interval(xml_time *timeslice);
gchar *get_data(const xml_time *timeslice,
......
......@@ -29,8 +29,6 @@
#include "weather-debug.h"
#define INVALID_TIME "INVALID"
#define YESNO(bool) ((bool) ? "yes" : "no")
......@@ -109,19 +107,6 @@ weather_debug_real(const gchar *log_domain,
}
gchar *
weather_debug_strftime_t(const time_t t)
{
struct tm tm;
gchar str[20];
size_t size;
tm = *localtime(&t);
size = strftime(str, 20, "%Y-%m-%d %H:%M:%S", &tm);
return (size ? g_strdup(str) : g_strdup(INVALID_TIME));
}
gchar *
weather_dump_geolocation(const xml_geolocation *geo)
{
......@@ -230,10 +215,10 @@ weather_dump_astrodata(const xml_astro *astro)
if (!astro)
return g_strdup("No astronomical data.");
sunrise = weather_debug_strftime_t(astro->sunrise);
sunset = weather_debug_strftime_t(astro->sunset);
moonrise = weather_debug_strftime_t(astro->moonrise);
moonset = weather_debug_strftime_t(astro->moonset);
sunrise = format_date(astro->sunrise, "%c", TRUE);
sunset = format_date(astro->sunset, "%c", TRUE);
moonrise = format_date(astro->moonrise, "%c", TRUE);
moonset = format_date(astro->moonset, "%c", TRUE);
out = g_strdup_printf("Astronomical data:\n"
" --------------------------------------------\n"
......@@ -349,8 +334,8 @@ weather_dump_timeslice(const xml_time *timeslice)
return g_strdup("No timeslice data.");
out = g_string_sized_new(512);
start = weather_debug_strftime_t(timeslice->start);
end = weather_debug_strftime_t(timeslice->end);
start = format_date(timeslice->start, "%c", TRUE);
end = format_date(timeslice->end, "%c", TRUE);
is_interval = (gboolean) strcmp(start, end);
loc = weather_dump_location((timeslice) ? timeslice->location : NULL,
is_interval);
......@@ -411,15 +396,15 @@ weather_dump_plugindata(const plugin_data *data)
gchar *next_astro_update, *next_weather_update, *next_conditions_update;
gchar *next_wakeup, *result;
last_astro_update = weather_debug_strftime_t(data->astro_update->last);
last_weather_update = weather_debug_strftime_t(data->weather_update->last);
last_astro_update = format_date(data->astro_update->last, "%c", TRUE);
last_weather_update = format_date(data->weather_update->last, "%c", TRUE);
last_conditions_update =
weather_debug_strftime_t(data->conditions_update->last);
next_astro_update = weather_debug_strftime_t(data->astro_update->next);
next_weather_update = weather_debug_strftime_t(data->weather_update->next);
format_date(data->conditions_update->last, "%c", TRUE);
next_astro_update = format_date(data->astro_update->next, "%c", TRUE);
next_weather_update = format_date(data->weather_update->next, "%c", TRUE);
next_conditions_update =
weather_debug_strftime_t(data->conditions_update->next);
next_wakeup = weather_debug_strftime_t(data->next_wakeup);
format_date(data->conditions_update->next, "%c", TRUE);
next_wakeup = format_date(data->next_wakeup, "%c", TRUE);
out = g_string_sized_new(1024);
g_string_assign(out, "xfce_weatherdata:\n");
......
......@@ -58,8 +58,6 @@ void weather_debug_real(const gchar *log_domain,
const gchar *format,
...);
gchar *weather_debug_strftime_t(const time_t t);
gchar *weather_dump_geolocation(const xml_geolocation *geo);
gchar *weather_dump_place(const xml_place *place);
......
......@@ -278,18 +278,6 @@ weather_summary_get_logo(plugin_data *data)
}
static gchar *
format_date(time_t t)
{
struct tm *tm;
gchar buf[80];
tm = localtime(&t);
strftime(buf, 80, "%c", tm);
return g_strdup(buf);
}
static GtkWidget *
create_summary_tab(plugin_data *data)
{
......@@ -301,11 +289,9 @@ create_summary_tab(plugin_data *data)
GdkColor lnk_color;
xml_time *conditions;
const gchar *unit;
struct tm *start_tm, *end_tm, *point_tm;
struct tm *sunrise_tm, *sunset_tm, *moonrise_tm, *moonset_tm;
gchar *value, *rawvalue, *wind;
gchar interval_start[80], interval_end[80], point[80];
gchar sunrise[80], sunset[80], moonrise[80], moonset[80];
gchar *interval_start, *interval_end, *point, *last_weather_update;
gchar *sunrise, *sunset, *moonrise, *moonset;
summary_details *sum;
sum = g_slice_new0(summary_details);
......@@ -352,17 +338,21 @@ create_summary_tab(plugin_data *data)
APPEND_TEXT_ITEM(_("Longitude"), LONGITUDE);
APPEND_BTEXT(_("\nTime\n"));
point_tm = localtime(&conditions->point);
strftime(point, 80, "%c", point_tm);
last_weather_update = format_date(data->weather_update->last, NULL, TRUE);
value = g_strdup_printf(_("\tLast updated:\t%s\n\n"),
last_weather_update);
g_free(last_weather_update);
APPEND_TEXT_ITEM_REAL(value);
point = format_date(conditions->point, NULL, TRUE);
value = g_strdup_printf
(_("\tTemperature, wind, atmosphere and cloud data apply to:\n\t%s\n"),
(_("\tTemperature, wind, atmosphere and cloud data calculated for:\n\t%s\n"),
point);
g_free(point);
APPEND_TEXT_ITEM_REAL(value);
start_tm = localtime(&conditions->start);
strftime(interval_start, 80, "%c", start_tm);
end_tm = localtime(&conditions->end);
strftime(interval_end, 80, "%c", end_tm);
interval_start = format_date(conditions->start, NULL, TRUE);
interval_end = format_date(conditions->end, NULL, TRUE);
value = g_strdup_printf
(_("\n\tPrecipitation and the weather symbol have been calculated\n"
"\tfor the following time interval:\n"
......@@ -370,6 +360,8 @@ create_summary_tab(plugin_data *data)
"\tEnd:\t%s\n"),
interval_start,
interval_end);
g_free(interval_end);
g_free(interval_start);
APPEND_TEXT_ITEM_REAL(value);
/* sun and moon */
......@@ -382,14 +374,14 @@ create_summary_tab(plugin_data *data)
value = g_strdup(_("\tSunset:\t\tThe sun never sets today.\n"));
APPEND_TEXT_ITEM_REAL(value);
} else {
sunrise_tm = localtime(&data->astrodata->sunrise);
strftime(sunrise, 80, "%c", sunrise_tm);
sunrise = format_date(data->astrodata->sunrise, NULL, TRUE);
value = g_strdup_printf(_("\tSunrise:\t\t%s\n"), sunrise);
g_free(sunrise);
APPEND_TEXT_ITEM_REAL(value);
sunset_tm = localtime(&data->astrodata->sunset);
strftime(sunset, 80, "%c", sunset_tm);
sunset = format_date(data->astrodata->sunset, NULL, TRUE);
value = g_strdup_printf(_("\tSunset:\t\t%s\n\n"), sunset);
g_free(sunset);
APPEND_TEXT_ITEM_REAL(value);
}
......@@ -408,14 +400,14 @@ create_summary_tab(plugin_data *data)
value = g_strdup(_("\tMoonset:\tThe moon never sets today.\n"));
APPEND_TEXT_ITEM_REAL(value);
} else {
moonrise_tm = localtime(&data->astrodata->moonrise);
strftime(moonrise, 80, "%c", moonrise_tm);
moonrise = format_date(data->astrodata->moonrise, NULL, TRUE);
value = g_strdup_printf(_("\tMoonrise:\t%s\n"), moonrise);
g_free(moonrise);
APPEND_TEXT_ITEM_REAL(value);
moonset_tm = localtime(&data->astrodata->moonset);
strftime(moonset, 80, "%c", moonset_tm);
moonset = format_date(data->astrodata->moonset, NULL, TRUE);
value = g_strdup_printf(_("\tMoonset:\t%s\n"), moonset);
g_free(moonset);
APPEND_TEXT_ITEM_REAL(value);
}
} else {
......@@ -539,13 +531,13 @@ forecast_cell_get_tooltip_text(plugin_data *data,
/* TRANSLATORS: Please use \t as needed to properly align the values */
text = g_string_new(_("<b>Times used for calculation</b>\n"));
value = format_date(fcdata->start);
value = format_date(fcdata->start, NULL, TRUE);
g_string_append_printf(text, _("Interval start:\t\t\t%s\n"), value);
g_free(value);
value = format_date(fcdata->end);
value = format_date(fcdata->end, NULL, TRUE);
g_string_append_printf(text, _("Interval end:\t\t\t%s\n"), value);
g_free(value);
value = format_date(fcdata->point);
value = format_date(fcdata->point, NULL, TRUE);
g_string_append_printf(text, _("Data calculated for:\t%s\n\n"), value);
g_free(value);
......
......@@ -452,12 +452,10 @@ cb_weather_update(SoupSession *session,
xmlDoc *doc;
xmlNode *root_node;
time_t now_t;
struct tm now_tm;
gboolean parsing_error = TRUE;
weather_debug("Processing downloaded weather data.");
time(&now_t);
now_tm = *localtime(&now_t);
data->weather_update->attempt++;
if (msg->status_code == 200 || msg->status_code == 203) {
if (msg->status_code == 203)
......@@ -868,23 +866,6 @@ make_cache_filename(plugin_data *data)
}
/*
* Convert localtime to gmtime and format it to a string
* that can be parsed later by parse_timestring.
*/
static gchar *
cache_file_strftime_t(const time_t t)
{
struct tm *tm;
gchar str[21];
size_t size;
tm = gmtime(&t);
size = strftime(str, 21, "%Y-%m-%dT%H:%M:%SZ", tm);
return (size ? g_strdup(str) : g_strdup(""));
}
static void
write_cache_file(plugin_data *data)
{
......@@ -893,6 +874,7 @@ write_cache_file(plugin_data *data)
xml_time *timeslice;
xml_location *loc;
gchar *file, *start, *end, *point, *now;
gchar *date_format = "%Y-%m-%dT%H:%M:%SZ";
time_t now_t = time(NULL);
gint i, j;
......@@ -907,7 +889,7 @@ write_cache_file(plugin_data *data)
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);
now = cache_file_strftime_t(now_t);
now = format_date(now_t, date_format, FALSE);
CACHE_APPEND("cache_date=%s\n\n", now);
g_free(now);
......@@ -916,9 +898,9 @@ write_cache_file(plugin_data *data)
if (G_UNLIKELY(timeslice == NULL || timeslice->location == NULL))
continue;
loc = timeslice->location;
start = cache_file_strftime_t(timeslice->start);
end = cache_file_strftime_t(timeslice->end);
point = cache_file_strftime_t(timeslice->point);
start = format_date(timeslice->start, date_format, FALSE);
end = format_date(timeslice->end, date_format, FALSE);
point = format_date(timeslice->point, date_format, FALSE);
g_string_append_printf(out, "[timeslice%d]\n", i);
CACHE_APPEND("start=%s\n", start);
CACHE_APPEND("end=%s\n", end);
......@@ -1281,13 +1263,11 @@ static gchar *
weather_get_tooltip_text(const plugin_data *data)
{
xml_time *conditions;
struct tm *point_tm, *start_tm, *end_tm, *sunrise_tm, *sunset_tm;
gchar *text, *sym, *alt, *temp;
gchar *windspeed, *windbeau, *winddir, *winddir_trans, *winddeg;
gchar *pressure, *humidity, *precipitations;
gchar *fog, *cloudiness, *sunval, *value;
gchar sunrise[40], sunset[40];
gchar point[40], interval_start[40], interval_end[40];
gchar *point, *interval_start, *interval_end, *sunrise, *sunset;
const gchar *unit;
conditions = get_current_conditions(data->weatherdata);
......@@ -1297,12 +1277,9 @@ weather_get_tooltip_text(const plugin_data *data)
}
/* times for forecast and point data */
point_tm = localtime(&conditions->point);
strftime(point, 40, "%X", point_tm);
start_tm = localtime(&conditions->start);
strftime(interval_start, 40, "%X", start_tm);
end_tm = localtime(&conditions->end);
strftime(interval_end, 40, "%X", end_tm);
point = format_date(conditions->point, "%H:%M", TRUE);
interval_start = format_date(conditions->start, "%H:%M", TRUE);
interval_end = format_date(conditions->end, "%H:%M", TRUE);
/* use sunrise and sunset times if available */
if (data->astrodata)
......@@ -1311,12 +1288,12 @@ weather_get_tooltip_text(const plugin_data *data)
} else if (data->astrodata->sun_never_sets) {
sunval = g_strdup(_("The sun never sets today."));
} else {
sunrise_tm = localtime(&data->astrodata->sunrise);
strftime(sunrise, 40, "%X", sunrise_tm);
sunset_tm = localtime(&data->astrodata->sunset);
strftime(sunset, 40, "%X", sunset_tm);
sunrise = format_date(data->astrodata->sunrise, "%H:%M:%S", TRUE);
sunset = format_date(data->astrodata->sunset, "%H:%M:%S", TRUE);
sunval = g_strdup_printf(_("The sun rises at %s and sets at %s."),
sunrise, sunset);
g_free(sunrise);
g_free(sunset);
}
else
sunval = g_strdup_printf("");
......@@ -1391,6 +1368,9 @@ weather_get_tooltip_text(const plugin_data *data)
g_free(sym);
g_free(alt);
g_free(temp);
g_free(interval_start);
g_free(interval_end);
g_free(point);
g_free(windspeed);
g_free(windbeau);
g_free(winddir_trans);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment