[gnome-maps/wip/routing2: 8/9] WIP Route: Make the route service global



commit 114d6309f4d4844badf021ef036aba486bee2861
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sun Apr 20 03:51:45 2014 +0200

    WIP Route: Make the route service global
    
    Make the route service a global service, in the same way as
    notificationManager and settings etc.

 src/application.js  |    3 +++
 src/mainWindow.js   |   23 ++++++++++++++++++++++-
 src/route.js        |    9 +++++++++
 src/routeService.js |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+), 1 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ae00dda..a78fc78 100644
--- a/src/application.js
+++ b/src/application.js
@@ -40,12 +40,14 @@ const Utils = imports.utils;
 const Path = imports.path;
 const Settings = imports.settings;
 const PlaceStore = imports.placeStore;
+const RouteService = imports.routeService;
 
 // used globally
 let application = null;
 let settings = null;
 let placeStore = null;
 let notificationManager = null;
+let routeService = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -93,6 +95,7 @@ const Application = new Lang.Class({
 
         application = this;
         settings = new Settings.Settings('org.gnome.maps');
+        routeService = new RouteService.GraphHopper();
 
         Utils.initActions(this, [{
             properties: { name: 'quit' },
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 01d37b5..d53d784 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -38,6 +38,8 @@ const PlaceStore = imports.placeStore;
 const Utils = imports.utils;
 const Config = imports.config;
 const ZoomControl = imports.zoomControl;
+const RouteService = imports.routeService;
+const Route = imports.route;
 
 const _ = imports.gettext.gettext;
 
@@ -63,7 +65,26 @@ const MainWindow = new Lang.Class({
 
         ui.appWindow.add(this._overlay);
 
-        this.mapView = new MapView.MapView();
+        // NOTE: Maybe call these *model?
+        let routeQuery = new RouteService.Query();
+        let routeModel = new Route.Route();
+        routeQuery.connect('change', (function() {
+            if(routeQuery.from && routeQuery.to) {
+                Application.routeService.getRoute([routeQuery.from, routeQuery.to],
+                                                  routeQuery.transportation,
+                                                  (function(err, result) {
+                                                      if(!err)
+                                                          routeModel.update(result);
+                                                      else
+                                                          log("Couldn't do route'");
+                                                  }));
+            } else {
+                // TODO: implement
+                // NOTE: think about whether we should reset here
+                routeModel.reset();
+            }
+        }).bind(this));
+        this.mapView = new MapView.MapView(routeModel);
         overlay.add(this.mapView);
 
         this.mapView.gotoUserLocation(false);
diff --git a/src/route.js b/src/route.js
index 5d4fe1c..dee6d7b 100644
--- a/src/route.js
+++ b/src/route.js
@@ -44,6 +44,7 @@ const Direction = {
     ROUNDABOUT:   8
 };
 
+// TODO: make this a model-like class with signals etc.
 const Route = new Lang.Class({
     Name: 'Route',
 
@@ -76,6 +77,14 @@ const Route = new Lang.Class({
             bbox.extend(latitude, longitude);
         }, this);
         return bbox;
+    },
+
+    setMany: function(obj) {
+        // TODO: implement
+    },
+
+    reset: function() {
+        // TODO: implement
     }
 });
 Utils.addSignalMethods(Route.prototype);
diff --git a/src/routeService.js b/src/routeService.js
index 29bff69..b13ffb2 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -22,6 +22,8 @@
 
 const Soup = imports.gi.Soup;
 const Champlain = imports.gi.Champlain;
+const GObject = imports.gi.GObject;
+const GeoCode = imports.gi.GeoCodeGlib;
 
 const Lang = imports.lang;
 const Utils = imports.utils;
@@ -37,6 +39,55 @@ const Transportation = {
     TRANSIT:    3
 };
 
+const Query = new Lang.Class({
+    Name: 'Query',
+    Extends: GObject.Object,
+    Properties: {
+        'from': GObject.ParamSpec.object('from',
+                                         '',
+                                         '',
+                                         GObject.ParamFlags.READABLE |
+                                         GObject.ParamFlags.WRITABLE,
+                                         GeoCode.Place),
+        'to': GObject.ParamSpec.object('to',
+                                       '',
+                                       '',
+                                       GObject.ParamFlags.READABLE |
+                                       GObject.ParamFlags.WRITABLE,
+                                       GeoCode.Place),
+        'transportation': GObject.ParamSpec.int('transportation',
+                                                '',
+                                                '',
+                                                GObject.ParamFlags.READABLE |
+                                                GObject.ParamFlags.WRITABLE,
+                                                Transportation.CAR, Transportation.TRANSIT,
+                                                Transportation.CAR)
+    },
+
+    _init: function(args) {
+        this.parent(args);
+        this._changeSignalId = this.connect('notify', this.emit.bind(this, 'change'));
+    },
+
+    reset: function() {
+        this.setMany({ from: null,
+                       to: null,
+                       transportation: Transportation.CAR });
+    },
+
+    setMany: function(obj) {
+        this.disconnect(this._changeSignalId);
+
+        for(let key in obj) {
+            if(this.hasOwnProperty(key))
+                this[key] = obj[key];
+        }
+
+        this._changeSignalId = this.connect('notify', this.emit.bind(this, 'change'));
+        this.emit('change');
+    }
+});
+
 const RouteService = new Lang.Class({
     Name: 'RouteService',
     Abstract: true,


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