[gnome-maps] Start with last viewed location



commit b7d9b1655f79a583a6d89fe07f2a46eb614ddab7
Author: alafazam <alafazam gmail com>
Date:   Fri Nov 6 23:20:23 2015 +0530

    Start with last viewed location
    
    When users open Maps they start with map of the world. This is less
    convenient than starting at where they were last time. So through this
    patch we store their last visited location in gsettings and retrieve
    it back next time they open.
    
    Whenever there is a view-moved event we schedule a timeout to save the
    current location. When a new timeout is sceduled, we check if we have
    a pending timeout, if we do, we dont add the new one. This ensures that
    we are not saving locations too many times.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755847

 data/org.gnome.Maps.gschema.xml |    5 +++++
 src/mapView.js                  |   31 +++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Maps.gschema.xml b/data/org.gnome.Maps.gschema.xml
index 882999c..a9dcfd9 100644
--- a/data/org.gnome.Maps.gschema.xml
+++ b/data/org.gnome.Maps.gschema.xml
@@ -1,5 +1,10 @@
 <schemalist gettext-domain="gnome-maps">
   <schema id="org.gnome.Maps" path="/org/gnome/maps/">
+    <key type="ad" name="last-viewed-location">
+      <default>[0.0,0.0,0.0,0.0]</default>
+      <summary>last viewed location</summary>
+      <description>Coordinates of last viewed location.</description>
+    </key>
     <key name="window-size" type="ai">
       <default>[768, 600]</default>
       <summary>Window size</summary>
diff --git a/src/mapView.js b/src/mapView.js
index 7fb9e04..96ba0d9 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -25,6 +25,7 @@ const GObject = imports.gi.GObject;
 const Geocode = imports.gi.GeocodeGlib;
 const GtkChamplain = imports.gi.GtkChamplain;
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 
 const Application = imports.application;
 const ContactPlace = imports.contactPlace;
@@ -47,7 +48,7 @@ const MapType = {
     CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
     TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
 };
-
+const _LOCATION_STORE_TIMEOUT = 500;
 const MapMinZoom = 2;
 
 const MapView = new Lang.Class({
@@ -91,7 +92,7 @@ const MapView = new Lang.Class({
                                     this._updateUserLocation.bind(this));
         Application.geoclue.connect('notify::state',
                                     this._updateUserLocation.bind(this));
-
+        this._storeId = 0;
         this._connectRouteSignals();
     },
 
@@ -103,6 +104,7 @@ const MapView = new Lang.Class({
         view.reactive = true;
         view.kinetic_mode = true;
 
+        view.connect('notify::realized', this._goToStoredLocation.bind(this));
         view.connect('notify::latitude', this._onViewMoved.bind(this));
         // switching map type will set view min-zoom-level from map source
         view.connect('notify::min-zoom-level', (function() {
@@ -267,6 +269,24 @@ const MapView = new Lang.Class({
         this.emit('user-location-changed');
     },
 
+    _storeLocation: function() {
+        let box = this.view.get_bounding_box();
+        let lastViewedLocation = [box.top, box.bottom, box.left, box.right];
+        Application.settings.set('last-viewed-location', lastViewedLocation);
+    },
+
+    _goToStoredLocation: function() {
+        if (!this.view.realized)
+            return;
+
+        let box = Application.settings.get('last-viewed-location');
+        let bounding_box = new Champlain.BoundingBox({ top: box[0],
+                                                       bottom: box[1],
+                                                       left: box[2],
+                                                       right: box[3] });
+        this._gotoBBox(bounding_box);
+    },
+
     _gotoBBox: function(bbox) {
         let [lat, lon] = bbox.get_center();
         let place = new Place.Place({
@@ -386,6 +406,13 @@ const MapView = new Lang.Class({
 
     _onViewMoved: function() {
         this.emit('view-moved');
+        if (this._storeId !== 0)
+            return;
+
+        this._storeId = Mainloop.timeout_add(_LOCATION_STORE_TIMEOUT,(function(){
+            this._storeId = 0;
+            this._storeLocation();
+        }).bind(this));
     },
 
     onSetMarkerSelected: function(selectedMarker) {


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