[gnome-weather] world: maintain a loading boolean property



commit 3bb25daec4619ac7e7bca9e25c5050411aa4995c
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Sep 8 18:46:10 2013 +0200

    world: maintain a loading boolean property
    
    The property is true any time we're updating an info, and is
    notified accordingly.

 src/city.js  |    2 +-
 src/world.js |   26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/src/city.js b/src/city.js
index 3c286c0..a6d44be 100644
--- a/src/city.js
+++ b/src/city.js
@@ -163,7 +163,7 @@ const WeatherView = new Lang.Class({
         this._spinner.start();
         this._infoPage.clear();
 
-        this._info.update();
+        getApp().model.updateInfo(this._info);
     },
 
     _onUpdate: function(info) {
diff --git a/src/world.js b/src/world.js
index 188b258..874339b 100644
--- a/src/world.js
+++ b/src/world.js
@@ -38,6 +38,9 @@ const WorldModel = new Lang.Class({
     Signals: {
         'updated': { param_types: [ GWeather.Info ] }
     },
+    Properties: {
+        'loading': GObject.ParamSpec.boolean('loading', '', '', GObject.ParamFlags.READABLE, false)
+    },
 
     _init: function(world) {
         this.parent();
@@ -63,6 +66,8 @@ const WorldModel = new Lang.Class({
                 GWeather.Provider.OWM;
         }
 
+        this._loadingCount = 0;
+
         let locations = this._settings.get_value('locations').deep_unpack();
         for (let i = 0; i < locations.length; i++) {
             let variant = locations[i];
@@ -73,6 +78,24 @@ const WorldModel = new Lang.Class({
         this._settings.connect('changed::locations', Lang.bind(this, this._onChanged));
     },
 
+    _updateLoadingCount: function(delta) {
+        let wasLoading = this._loadingCount > 0;
+        this._loadingCount += delta;
+        let isLoading = this._loadingCount > 0;
+
+        if (wasLoading != isLoading)
+            this.notify('loading');
+    },
+
+    updateInfo: function(info) {
+        info.update();
+        this._updateLoadingCount(+1);
+    },
+
+    get loading() {
+        return this._loadingCount > 0;
+    },
+
     _addLocationInternal: function(location) {
         let info = new GWeather.Info({ location: location,
                                        enabled_providers: this._providers });
@@ -84,9 +107,10 @@ const WorldModel = new Lang.Class({
                      [Columns.ICON, Columns.SECONDARY_TEXT],
                      [icon, secondary_text]);
 
+            this._updateLoadingCount(-1);
             this.emit('updated', info);
         }));
-        info.update();
+        this.updateInfo(info);
 
         let primary_text = location.get_city_name();
         let icon = Util.loadIcon('view-refresh-symbolic', ICON_SIZE);


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