[gnome-maps/wip/routing2] WIP



commit 19cf1013ff50e4303cff72e3aabe4998ffd786fc
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sun Apr 6 23:02:57 2014 +0100

    WIP
    
    This commit should make the routeService a global service and add a
    query object that when changed automatically runs a new query.

 src/application.js  |    3 ++
 src/mainWindow.js   |   18 ++++++++++++++++-
 src/route.js        |    9 ++++++++
 src/routeService.js |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 81 insertions(+), 2 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..8f4c8db 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,21 @@ 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 route = new Route.Route();
+        routeQuery.connect('change', (function() {
+            if(routeQuery.from && routeQuery.to) {
+                Application.routeService.getRoute(routeQuery, (function(result) {
+                    route.setMany(route);
+                }).bind(this));
+            } else {
+                // TODO: implement
+                // NOTE: think about whether we should reset here
+                route.reset();
+            }
+        }).bind(this));
+        this.mapView = new MapView.MapView(route);
         overlay.add(this.mapView);
 
         this.mapView.gotoUserLocation(false);
diff --git a/src/route.js b/src/route.js
index e7bf128..bbfe18e 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',
 
@@ -62,6 +63,14 @@ const Route = new Lang.Class({
             bbox.extend(latitude, longitude);
         }, this);
         return bbox;
+    },
+
+    setMany: function(obj) {
+        // TODO: implement
+    },
+
+    reset: function() {
+        // TODO: implement
     }
 });
 
diff --git a/src/routeService.js b/src/routeService.js
index 7003bfc..45c9490 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,12 +39,61 @@ 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,
 
     _init: function() {
-        this._session = new Soup.SessionAsync({ user_agent : "gnome-maps " });
+        this._session = new Soup.SessionAsync({ user_agent : "gnome-maps" });
     },
 
     _buildURL: function(viaPoints, transportation) {},


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