[Xfce4-commits] <xfce4-weather-plugin:master> Fix refresh function.

Harald Judt noreply at xfce.org
Sun Feb 3 21:48:01 CET 2013


Updating branch refs/heads/master
         to 15c71683bc1532f59980b99c50fe1aa0c2e83384 (commit)
       from 6d47e55204e97412baf8053246a8cd1278da81ee (commit)

commit 15c71683bc1532f59980b99c50fe1aa0c2e83384
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Feb 3 20:24:48 2013 +0100

    Fix refresh function.
    
    The current implementation of that function with asynchronous downloads
    is a bit weird. When the user hits refresh, the plugin should do exactly
    that, not show cached data which may be replaced by downloaded data some
    time later. It's also a bit unorthodox to require a "clear" parameter
    in a reset function, so let's clean up this mess.
    
    This commit sets the following new behaviour:
    If the user hits refresh, then "No data" is displayed at once, all data is
    cleared, cached data read and downloads are scheduled immediately (and for
    real). If the download finishes before the standard update interval (10
    secs) runs the GUI update, then new data will be shown, if not then cached
    data will be shown until download is finished. If the download fails and
    cached data is available, cached data will be shown immediately.
    
    The scrollbox and icons are now reset synchronously and immediately after a
    download.

 panel-plugin/weather-config.c |    2 +-
 panel-plugin/weather.c        |   43 ++++++++++++++++++++++++++--------------
 panel-plugin/weather.h        |    3 +-
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index ae5f431..2f0d337 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -155,7 +155,7 @@ schedule_data_update(gpointer user_data)
 
     /* force update of downloaded data */
     weather_debug("Delayed update timer expired, now scheduling data update.");
-    update_weatherdata_with_reset(pd, TRUE);
+    update_weatherdata_with_reset(pd);
 
     gtk_spinner_stop(GTK_SPINNER(dialog->update_spinner));
     gtk_widget_hide(GTK_WIDGET(dialog->update_spinner));
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index dabb434..6085924 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -371,7 +371,8 @@ update_scrollbox(plugin_data *data,
 
 
 static void
-update_current_conditions(plugin_data *data)
+update_current_conditions(plugin_data *data,
+                          gboolean immediately)
 {
     struct tm now_tm;
 
@@ -408,6 +409,8 @@ update_current_conditions(plugin_data *data)
     /* update widgets */
     update_icon(data);
     update_scrollbox(data, FALSE);
+    if (immediately)
+        gtk_scrollbox_reset(GTK_SCROLLBOX(data->scrollbox));
     weather_debug("Updated current conditions.");
 }
 
@@ -558,7 +561,7 @@ cb_weather_update(SoupSession *session,
     g_array_sort(data->weatherdata->timeslices,
                  (GCompareFunc) xml_time_compare);
     weather_debug("Updating current conditions.");
-    update_current_conditions(data);
+    update_current_conditions(data, !parsing_error);
     write_cache_file(data);
     schedule_next_wakeup(data);
     weather_dump(weather_dump_weatherdata, data->weatherdata);
@@ -637,7 +640,7 @@ update_handler(plugin_data *data)
            this is to prevent spawning multiple updates in a row */
         data->conditions_update->next = time_calc_hour(now_tm, 1);
         weather_debug("Updating current conditions.");
-        update_current_conditions(data);
+        update_current_conditions(data, FALSE);
         /* update_current_conditions updates day/night time status
            too, so quit here */
         return FALSE;
@@ -1300,8 +1303,10 @@ read_cache_file(plugin_data *data)
 
 
 void
-update_weatherdata_with_reset(plugin_data *data, gboolean clear)
+update_weatherdata_with_reset(plugin_data *data)
 {
+    time_t now_t;
+
     weather_debug("Update weatherdata with reset.");
     g_assert(data != NULL);
     if (G_UNLIKELY(data == NULL))
@@ -1313,22 +1318,30 @@ update_weatherdata_with_reset(plugin_data *data, gboolean clear)
     }
 
     /* set location timezone */
-    if (clear)
-        update_timezone(data);
+    update_timezone(data);
 
-    /* reset update times */
+    /* clear update times */
     init_update_infos(data);
 
-    /* clear existing weather data, needed for location changes */
-    if (clear && data->weatherdata) {
+    /* clear existing weather data */
+    if (data->weatherdata) {
         xml_weather_free(data->weatherdata);
         data->weatherdata = make_weather_data();
-
-        /* make use of previously saved data */
-        read_cache_file(data);
     }
+
+    /* update GUI to display NODATA */
+    update_icon(data);
+    update_scrollbox(data, TRUE);
+
+    /* make use of previously saved data */
+    read_cache_file(data);
+
+    /* schedule downloads immediately */
+    time(&now_t);
+    data->weather_update->next = now_t;
+    data->astro_update->next = now_t;
     schedule_next_wakeup(data);
-    gtk_scrollbox_reset(GTK_SCROLLBOX(data->scrollbox));
+
     weather_debug("Updated weatherdata with reset.");
 }
 
@@ -1407,7 +1420,7 @@ cb_click(GtkWidget *widget,
     if (event->button == 1)
         forecast_click(widget, user_data);
     else if (event->button == 2)
-        update_weatherdata_with_reset(data, FALSE);
+        update_weatherdata_with_reset(data);
     return FALSE;
 }
 
@@ -1434,7 +1447,7 @@ mi_click(GtkWidget *widget,
 {
     plugin_data *data = (plugin_data *) user_data;
 
-    update_weatherdata_with_reset(data, FALSE);
+    update_weatherdata_with_reset(data);
 }
 
 
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index f2b5a1c..60001f1 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -136,8 +136,7 @@ void update_icon(plugin_data *data);
 void update_scrollbox(plugin_data *data,
                       gboolean immediately);
 
-void update_weatherdata_with_reset(plugin_data *data,
-                                   gboolean clear);
+void update_weatherdata_with_reset(plugin_data *data);
 
 GArray *labels_clear(GArray *array);
 


More information about the Xfce4-commits mailing list