[Xfce4-commits] <xfce4-weather-plugin:master> Add merge_timeslice() helper function.
Harald Judt
noreply at xfce.org
Sun Dec 9 23:44:19 CET 2012
Updating branch refs/heads/master
to dca05f6933f222b668d68edc0e1102eac2172d6e (commit)
from 3105a3adee74c89f40e27e89b8a55c8509e441de (commit)
commit dca05f6933f222b668d68edc0e1102eac2172d6e
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Dec 9 19:24:34 2012 +0100
Add merge_timeslice() helper function.
panel-plugin/weather-data.c | 44 +++++++++++++++++++++++++++++++++++++++++++
panel-plugin/weather-data.h | 3 ++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 2d8f797..638aa68 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -516,6 +516,50 @@ make_combined_timeslice(xml_weather *wd,
}
+void
+merge_timeslice(xml_weather *wd,
+ const xml_time *timeslice)
+{
+ xml_time *old_ts, *new_ts;
+ time_t now_t = time(NULL);
+ guint i;
+
+ g_assert(wd != NULL);
+ if (G_UNLIKELY(wd == NULL))
+ return;
+
+ if (wd->timeslices == NULL)
+ wd->timeslices = g_array_sized_new(FALSE, TRUE,
+ sizeof(xml_time *), 200);
+
+ g_assert(wd->timeslices != NULL);
+ if (G_UNLIKELY(wd->timeslices == NULL))
+ return;
+
+ /* first check if it isn't too old */
+ if (difftime(now_t, timeslice->end) > DATA_EXPIRY_TIME) {
+ weather_debug("Not merging timeslice because it has expired.");
+ return;
+ }
+
+ /* Copy timeslice, as it will be deleted by the calling function */
+ new_ts = xml_time_copy(timeslice);
+
+ /* check if there is a timeslice with the same interval and
+ replace it with the current data */
+ old_ts = get_timeslice(wd, timeslice->start, timeslice->end, &i);
+ if (old_ts) {
+ xml_time_free(old_ts);
+ g_array_remove_index(wd->timeslices, i);
+ g_array_insert_val(wd->timeslices, i, new_ts);
+ weather_debug("Replaced existing timeslice at %d.", i);
+ } else {
+ g_array_prepend_val(wd->timeslices, new_ts);
+ //weather_debug("Prepended timeslice to the existing timeslices.");
+ }
+}
+
+
/* Return current weather conditions, or NULL if not available. */
xml_time *
get_current_conditions(const xml_weather *wd)
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index d135235..2197940 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -113,6 +113,9 @@ time_t time_calc_hour(struct tm time_tm,
time_t time_calc_day(struct tm time_tm,
gint days);
+void merge_timeslice(xml_weather *wd,
+ const xml_time *timeslice);
+
xml_time *get_current_conditions(const xml_weather *wd);
xml_time *make_current_conditions(xml_weather *wd,
More information about the Xfce4-commits
mailing list