[gnome-maps/wip/routing2: 3/7] Add a Route query model



commit 31b9e8a43996f36282db1c63d1f7fa0c179db2d2
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Tue Apr 22 04:38:50 2014 +0200

    Add a Route query model
    
    This will represent the route query state in the app.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728695

 src/route.js |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/src/route.js b/src/route.js
index 164c6d9..80038b4 100644
--- a/src/route.js
+++ b/src/route.js
@@ -20,11 +20,20 @@
  * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
  */
 
+const GeoCode = imports.gi.GeocodeGlib;
+const GObject = imports.gi.GObject;
+
 const Lang = imports.lang;
 const Champlain = imports.gi.Champlain;
 
 const Utils = imports.utils;
 
+const Transportation = {
+    CAR:        0,
+    BIKE:       1,
+    PEDESTRIAN: 2
+};
+
 const TurnPointType = {
     SHARP_LEFT:    0,
     LEFT:          1,
@@ -41,6 +50,67 @@ const TurnPointType = {
     START:         10000
 };
 
+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.PEDESTRIAN,
+                                                Transportation.CAR)
+    },
+
+    _init: function(args) {
+        this.parent(args);
+        this._changeSignalId = this.connect('notify',
+                                            this.emit.bind(this, 'change'));
+        this.reset();
+    },
+
+    reset: function() {
+        this.setMany({ from: null,
+                       to: null,
+                       transportation: Transportation.CAR });
+    },
+
+    setMany: function(obj) {
+        this.disconnect(this._changeSignalId);
+
+        // Only set properties actually defined on this object
+        ["from", "to", "transportation"].forEach((function(prop) {
+            if (obj.hasOwnProperty(prop))
+                this[prop] = obj[prop];
+        }).bind(this));
+
+        this._changeSignalId = this.connect('notify',
+                                            this.emit.bind(this, 'change'));
+        this.emit('change');
+    },
+
+    toString: function() {
+        return "From: " + this.from +
+            "\nTo: " + this.to +
+            "\nTransportation" + this.transportation;
+    }
+});
+Utils.addSignalMethods(Query.prototype);
+
 const Route = new Lang.Class({
     Name: 'Route',
 


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