[Xfce4-commits] <xfce4-weather-plugin:master> Let the update handler deal with writing the cache file.
Harald Judt
noreply at xfce.org
Sun Jan 12 01:08:03 CET 2014
Updating branch refs/heads/master
to 0183158cdffb3e432eccaab337b2d9053235b19b (commit)
from 2e9ef8c8b50f2505b5f21bf2280a3588f6647af0 (commit)
commit 0183158cdffb3e432eccaab337b2d9053235b19b
Author: Harald Judt <h.judt at gmx.at>
Date: Thu May 9 19:10:24 2013 +0200
Let the update handler deal with writing the cache file.
This central function is the proper place to do this. It will write the cache
file once all started downloads are completed.
panel-plugin/weather.c | 16 +++++++++++++++-
panel-plugin/weather.h | 2 ++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 9ca51af..9ee953c 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -524,6 +524,7 @@ cb_astro_update(SoupSession *session,
update_icon(data);
schedule_next_wakeup(data);
+ data->astro_update->finished = TRUE;
weather_dump(weather_dump_astrodata, data->current_astro);
}
@@ -579,8 +580,8 @@ cb_weather_update(SoupSession *session,
(GCompareFunc) xml_time_compare);
weather_debug("Updating current conditions.");
update_current_conditions(data, !parsing_error);
- write_cache_file(data);
schedule_next_wakeup(data);
+ data->weather_update->finished = TRUE;
weather_dump(weather_dump_weatherdata, data->weatherdata);
}
@@ -608,11 +609,23 @@ update_handler(plugin_data *data)
now_t = time(NULL);
now_tm = *localtime(&now_t);
+ /* check if all started downloads are finished and the cache file
+ can be written */
+ if (data->astro_update->started && data->astro_update->finished &&
+ data->weather_update->started && data->weather_update->finished) {
+ data->astro_update->started = FALSE;
+ data->astro_update->finished = FALSE;
+ data->weather_update->started = FALSE;
+ data->weather_update->finished = FALSE;
+ write_cache_file(data);
+ }
+
/* fetch astronomical data */
if (difftime(data->astro_update->next, now_t) <= 0) {
/* real next update time will be calculated when update is finished,
this is to prevent spawning multiple updates in a row */
data->astro_update->next = time_calc_hour(now_tm, 1);
+ data->astro_update->started = TRUE;
/* calculate date range for request */
end_t = time_calc_day(now_tm, ASTRODATA_MAX_DAYS);
@@ -642,6 +655,7 @@ update_handler(plugin_data *data)
/* real next update time will be calculated when update is finished,
this is to prevent spawning multiple updates in a row */
data->weather_update->next = time_calc_hour(now_tm, 1);
+ data->weather_update->started = TRUE;
/* build url */
url =
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 575a77a..ec8e26f 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -57,6 +57,8 @@ typedef struct {
time_t next;
guint attempt;
guint check_interval;
+ gboolean started;
+ gboolean finished;
} update_info;
typedef struct {
More information about the Xfce4-commits
mailing list