[gnome-weather] Show tomorrow's forecasts at the end of the day



commit 3f4c5954d9ae4d279d5d78d3d4ca5be2062a65ce
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Jan 12 22:09:56 2017 -0600

    Show tomorrow's forecasts at the end of the day
    
    When opening Weather at the end of the day, it invariably shows the text
    "Forecast not available", which is not very friendly to the user who is
    looking to see what the forecast is for a few hours ahead. So when
    absolutely no forecast data is available for the current day, go ahead
    and display tomorrow's forecasts instead, by activating that stack.
    
    Also, leave a warning about what seems to be a bug in the existing code
    here.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777200

 src/app/city.js     | 4 ++++
 src/app/forecast.js | 8 ++++++++
 2 files changed, 12 insertions(+)
---
diff --git a/src/app/city.js b/src/app/city.js
index d444ccc..a7e0354 100644
--- a/src/app/city.js
+++ b/src/app/city.js
@@ -188,6 +188,10 @@ var WeatherWidget = new Lang.Class({
         for (let t of ['today', 'tomorrow'])
             this._forecasts[t].update(forecasts, t);
 
+        if (!this._forecasts['today'].hasForecastInfo() && this._forecasts['tomorrow'].hasForecastInfo())
+            this._forecastStack.set_visible_child_name('tomorrow');
+
+        // FIXME: This doesn't make sense, since the above code assumes forecasts.length != 0.
         if (forecasts.length == 0) {
             this._weeklyForecasts.hide();
         } else {
diff --git a/src/app/forecast.js b/src/app/forecast.js
index 9199170..d39f27e 100644
--- a/src/app/forecast.js
+++ b/src/app/forecast.js
@@ -45,6 +45,8 @@ var ForecastBox = new Lang.Class({
                                     margin_bottom: 12,
                                     column_homogeneous: true });
         this.add(this._grid);
+
+        this._hasForecastInfo = false;
     },
 
     // Ensure that infos are sufficiently spaced, and
@@ -145,9 +147,15 @@ var ForecastBox = new Lang.Class({
         let temperature = new Gtk.Label({ label: Util.getTemperature(info),
                                           visible: true });
         this._grid.attach(temperature, col, 2, 1, 1);
+
+        this._hasForecastInfo = true;
     },
 
     clear: function() {
         this._grid.foreach(function(w) { w.destroy(); });
+    },
+
+    hasForecastInfo: function() {
+        return this._hasForecastInfo;
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]