[gnome-maps/wip/fix-geoloc: 6/6] WIP: move track-user-location to gsettingsAction



commit a282b8a64dfbc90eb21fc432b6d6d0aba977f222
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu Jul 11 04:07:28 2013 +0200

    WIP: move track-user-location to gsettingsAction

 src/main-window.ui |    1 +
 src/mainWindow.js  |   81 ++++++++++++++++++++++++++++++++--------------------
 2 files changed, 51 insertions(+), 31 deletions(-)
---
diff --git a/src/main-window.ui b/src/main-window.ui
index b5082ed..4911841 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 1bf7366..5efb3a6 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -70,38 +70,55 @@ const MainWindow = new Lang.Class({
 
         this.mapView = new MapView.MapView();
 
-        let trackUserLocation = Application.settings.get_boolean('track-user-location');
 
-        let onViewMoved = Lang.bind(this,
-            function () {
-                if (!this.mapView.userLocationVisible())
-                    toggle.active = false;
-            });
 
-        // Disable animation for goto animation on startup only
-        let animateGotoUserLocation = !trackUserLocation;
-        toggle.connect('toggled', Lang.bind(this,
-            function() {
-                if (this._onViewMovedId > 0) {
-                    this.mapView.disconnect(this._onViewMovedId);
-                    this._onViewMovedId = 0;
-                }
-
-                if (toggle.active) {
-                    let goneToUserLocationId = this.mapView.connect('gone-to-user-location', Lang.bind(this,
-                        function () {
-                            this.mapView.disconnect(goneToUserLocationId);
-                            this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved);
-                        }));
-                    this.mapView.gotoUserLocation(animateGotoUserLocation);
-                    if (!animateGotoUserLocation)
-                        animateGotoUserLocation = true;
-                }
-
-                Application.settings.set_boolean('track-user-location', toggle.active);
-            }));
-        toggle.active = trackUserLocation;
+        this.mapView.connect('view-moved', (function() {
+            if (!this.mapView.userLocationVisible())
+                Application.settings.set_boolean('track-user-location', false);
+        }).bind(this));
 
+        Application.settings.connect('changed::track-user-location', (function() {
+            if(Application.settings.get_boolean('track-user-location'))
+                this.mapView.gotoUserLocation(true);
+        }).bind(this));
+
+        if(Application.settings.get_boolean('track-user-location')) {
+            log("lol");
+            this.mapView.gotoUserLocation(false);
+        }
+        
+        // let onViewMoved = Lang.bind(this,
+        //     function () {
+        //         if (!this.mapView.userLocationVisible())
+        //             toggle.active = false;
+        //     });
+
+        // // Disable animation for goto animation on startup only
+        // let animateGotoUserLocation = !trackUserLocation;
+        // toggle.connect('toggled', Lang.bind(this,
+        //     function() {
+        //         if (this._onViewMovedId > 0) {
+        //             this.mapView.disconnect(this._onViewMovedId);
+        //             this._onViewMovedId = 0;
+        //         }
+
+        //         if (toggle.active) {
+        //             let goneToUserLocationId = this.mapView.connect('gone-to-user-location', 
Lang.bind(this,
+        //                 function () {
+        //                     this.mapView.disconnect(goneToUserLocationId);
+        //                     this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved);
+        //                 }));
+        //             this.mapView.gotoUserLocation(animateGotoUserLocation);
+        //             if (!animateGotoUserLocation)
+        //                 animateGotoUserLocation = true;
+        //         }
+
+        //         Application.settings.set_boolean('track-user-location', toggle.active);
+        //     }));
+        // toggle.active = trackUserLocation;
+
+        
+        
         grid.add(this.mapView);
 
         grid.show_all();
@@ -127,6 +144,8 @@ const MainWindow = new Lang.Class({
                 signalHandlers: { activate: this._onMapTypeActivate }
             }
         ], this);
+        this.window.add_action(
+            Application.settings.create_action('track-user-location'));
     },
 
     _saveWindowGeometry: function() {


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