[gnome-maps] MainWindow: more robust track toggle



commit 6f876eb96c13a1c663489fe7fd0a406d42cd0acd
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Jul 24 07:26:22 2013 +0200

    MainWindow: more robust track toggle
    
    Make the track user location toggle just represent a GSettingsAction.
    This makes the code a bit cleaner and the app a bit more robust.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704537

 src/main-window.ui |    1 +
 src/mainWindow.js  |   56 +++++++++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 26 deletions(-)
---
diff --git a/src/main-window.ui b/src/main-window.ui
index b5082ed..4b622ad 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -40,6 +40,7 @@
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="symbolic-icon-name">find-location-symbolic</property>
+                               <property name="action_name">win.track-user-location</property>
                          </object>
                          <packing>
                                <property name="pack_type">start</property>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 8604034..14ed496 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -70,34 +70,21 @@ const MainWindow = new Lang.Class({
 
         this.mapView = new MapView.MapView();
 
-        let trackUserLocation = Application.settings.get_boolean('track-user-location');
-
-        let onViewMoved = function () {
-            if (!this.mapView.userLocationVisible())
-                toggle.active = false;
-        };
-
-        // Disable animation for goto animation on startup only
-        let animateGotoUserLocation = !trackUserLocation;
-        toggle.connect('toggled', (function() {
-            if (this._onViewMovedId > 0) {
-                this.mapView.disconnect(this._onViewMovedId);
-                this._onViewMovedId = 0;
+        if(Application.settings.get_boolean('track-user-location'))
+            this.mapView.gotoUserLocation(false);
+
+        this._viewMovedId = 0;
+        this._connectMapMove();
+        this.mapView.connect('going-to-user-location',
+                             this._disconnectMapMove.bind(this));
+        this.mapView.connect('gone-to-user-location',
+                             this._connectMapMove.bind(this));
+
+        Application.settings.connect('changed::track-user-location', (function() {
+            if(Application.settings.get_boolean('track-user-location')) {
+                this.mapView.gotoUserLocation(true);
             }
-
-            if (toggle.active) {
-                let goneToUserLocationId = this.mapView.connect('gone-to-user-location', (function () {
-                    this.mapView.disconnect(goneToUserLocationId);
-                    this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved.bind(this));
-                }).bind(this));
-                this.mapView.gotoUserLocation(animateGotoUserLocation);
-                if (!animateGotoUserLocation)
-                    animateGotoUserLocation = true;
-            }
-
-            Application.settings.set_boolean('track-user-location', toggle.active);
         }).bind(this));
-        toggle.active = trackUserLocation;
 
         grid.add(this.mapView);
 
@@ -124,6 +111,23 @@ const MainWindow = new Lang.Class({
                 signalHandlers: { activate: this._onMapTypeActivate }
             }
         ], this);
+        let action = Application.settings.create_action('track-user-location');
+        this.window.add_action(action);
+    },
+
+    _connectMapMove: function() {
+        if(this._viewMovedId === 0) {
+            this._viewMovedId = this.mapView.connect('view-moved', (function() {
+                if (!this.mapView.userLocationVisible())
+                    Application.settings.set_boolean('track-user-location', false);
+            }).bind(this));
+        }
+    },
+    _disconnectMapMove: function() {
+        if(this._viewMovedId !== 0) {
+            this.mapView.disconnect(this._viewMovedId);
+            this._viewMovedId = 0;
+        }
     },
 
     _saveWindowGeometry: function() {


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