[gnome-maps/wip/jonasdn/storedRoute: 117/118] sidebar: Add storing of recent routes



commit 61b23dee8c708d0a2a59375dac4fb08d7b0ce301
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sun Aug 16 19:54:48 2015 +0200

    sidebar: Add storing of recent routes
    
    Add route to placeStore, after timeout. In order
    to not store each intermitten route when doing multiple
    places route searches. Wait 5 seconds before adding a route to
    the place store.

 src/sidebar.js |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/sidebar.js b/src/sidebar.js
index d02db87..4ad6d65 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -25,10 +25,13 @@ const Gdk = imports.gi.Gdk;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 
 const Application = imports.application;
+const PlaceStore  = imports.placeStore;
 const RouteEntry = imports.routeEntry;
 const RouteQuery = imports.routeQuery;
+const StoredRoute = imports.storedRoute;
 const Utils = imports.utils;
 
 const InstructionRow = new Lang.Class({
@@ -129,6 +132,11 @@ const Sidebar = new Lang.Class({
         }).bind(this));
     },
 
+    _cancelStore: function() {
+        Mainloop.source_remove(this._storeRouteTimeoutId);
+        this._storeRouteTimeoutId = 0;
+    },
+
     _createRouteEntry: function(index, point) {
         let type;
         if (index === 0)
@@ -181,12 +189,35 @@ const Sidebar = new Lang.Class({
                 this._instructionStack.visible_child = this._instructionSpinner;
             else
                 this._clearInstructions();
+
+            if (this._storeRouteTimeoutId)
+                this._cancelStore();
+
         }).bind(this));
 
         route.connect('update', (function() {
             this._clearInstructions();
             this._instructionStack.visible_child = this._instructionWindow;
 
+            if (this._storeRouteTimeoutId)
+                this._cancelStore();
+
+            this._storeRouteTimeoutId = Mainloop.timeout_add(5000, (function() {
+                let placeStore = Application.placeStore;
+                let places = query.filledPoints.map(function(point) {
+                    return point.place;
+                });
+                let storedRoute = new StoredRoute.StoredRoute({
+                    route: route,
+                    places: places
+                });
+
+                placeStore.addPlace(storedRoute,
+                                    PlaceStore.PlaceType.RECENT_ROUTE);
+
+                this._storeRouteTimeoutId = 0;
+            }).bind(this));
+
             route.turnPoints.forEach((function(turnPoint) {
                 let row = new InstructionRow({ visible: true,
                                                turnPoint: turnPoint });


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