[gnome-maps] sidebar: Add indications about distance and time



commit ccb9f03b4d5f5c3ccdff2360406ad75a58f9fc74
Author: Dario Di Nucci <linkin88mail gmail com>
Date:   Thu Jul 31 21:36:00 2014 +0200

    sidebar: Add indications about distance and time
    
    Add a new row in the sidebar forinformation about the
    estimated time for reaching the destination and the
    distance to it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731068

 src/sidebar.js |   19 ++++++++++++++++++-
 src/sidebar.ui |   40 +++++++++++++++++++++++++++++++++++++++-
 src/utils.js   |   27 +++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)
---
diff --git a/src/sidebar.js b/src/sidebar.js
index 85df03e..2124492 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -26,6 +26,7 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
+const _ = imports.gettext.gettext;
 
 const Application = imports.application;
 const PlaceStore = imports.placeStore;
@@ -57,6 +58,8 @@ const Sidebar = new Lang.Class({
                                                 'mode-pedestrian-toggle',
                                                 'mode-bike-toggle',
                                                 'mode-car-toggle',
+                                                'time-info',
+                                                'distance-info',
                                                 'from-entry-grid',
                                                 'to-entry-grid',
                                                 'via-add-button']);
@@ -67,6 +70,9 @@ const Sidebar = new Lang.Class({
         this._instructionStack = ui.instructionStack;
         this._instructionWindow = ui.instructionListScrolled;
         this._instructionSpinner = ui.instructionSpinner;
+        this._timeInfo = ui.timeInfo;
+        this._distanceInfo = ui.distanceInfo;
+
         this._initInstructionList();
 
         this._initTransportationToggles(ui.modePedestrianToggle,
@@ -160,6 +166,9 @@ const Sidebar = new Lang.Class({
                 query.removePoint(row.get_index() + 1);
                 row.destroy();
             }).bind(this));
+
+            this._timeInfo.label = '';
+            this._distanceInfo.label = '';
         }).bind(this));
 
         query.connect('notify', (function() {
@@ -176,6 +185,10 @@ const Sidebar = new Lang.Class({
                                                turnPoint: turnPoint });
                 this._instructionList.add(row);
             }).bind(this));
+
+            /* Translators: %s is a time expression with the format "%f h" or "%f min" */
+            this._timeInfo.label = _("Estimated time: %s").format(Utils.prettyTime(route.time));
+            this._distanceInfo.label = Utils.prettyDistance(route.distance);
         }).bind(this));
     },
 
@@ -198,10 +211,14 @@ const InstructionRow = new Lang.Class({
         this.visible = true;
         let ui = Utils.getUIObject('sidebar', ['instruction-box',
                                                'direction-image',
-                                               'instruction-label']);
+                                               'instruction-label',
+                                               'distance-label']);
         ui.instructionLabel.label  = this.turnPoint.instruction;
         ui.directionImage.resource = this.turnPoint.iconResource;
 
+        if (this.turnPoint.distance > 0)
+            ui.distanceLabel.label = Utils.prettyDistance(this.turnPoint.distance);
+
         this.add(ui.instructionBox);
     }
 });
diff --git a/src/sidebar.ui b/src/sidebar.ui
index 8346283..f6a2164 100644
--- a/src/sidebar.ui
+++ b/src/sidebar.ui
@@ -163,9 +163,31 @@
       </object>
     </child>
     <child>
-      <object class="GtkFrame" id="instruction-frame">
+      <object class="GtkGrid" id="sidebar-route-info">
+        <property name="name">sidebar-route-info</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="margin_start">17</property>
+        <property name="margin_end">12</property>
+        <property name="margin_top">12</property>
+        <child>
+          <object class="GtkLabel" id="time-info">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="distance-info">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">100</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkFrame" id="instruction-frame">
+        <property name="can_focus">False</property>
         <property name="margin_top">10</property>
         <property name="shadow_type">in</property>
         <child>
@@ -247,5 +269,21 @@
         <property name="position">1</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkLabel" id="distance-label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">end</property>
+        <property name="use_underline">True</property>
+        <property name="wrap">True</property>
+        <property name="lines">3</property>
+        <property name="margin_end">5</property>
+      </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="position">3</property>
+      </packing>
+    </child>
   </object>
 </interface>
diff --git a/src/utils.js b/src/utils.js
index 9d4df43..2cc0d9a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -263,3 +263,30 @@ function _load_themed_icon(icon, size, loadCompleteCallback) {
         log("Failed to load pixbuf: " + e);
     }
 }
+
+function prettyTime(time) {
+    let seconds = Math.floor(time / 1000);
+    let minutes = Math.floor(seconds / 60);
+    seconds = seconds % 60;
+    let hours = Math.floor(minutes / 60);
+    minutes = minutes % 60;
+
+    let labelledTime = "";
+    if (hours > 0)
+        labelledTime += _("%f h").format(hours)+' ';
+    if (minutes > 0)
+        labelledTime += _("%f min").format(minutes);
+    return labelledTime;
+}
+
+function prettyDistance(distance) {
+    let m = Math.floor(distance);
+    let km = Math.floor(m/1000);
+    m = m % 1000;
+
+    if (km > 0)
+        return _("%f km").format(km);
+    else if (m > 0)
+        return _("%f m").format(m);
+    return '';
+}


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