[gnome-maps/wip/mlundblad/transit-routing: 2/4] WIP: Add list box row class for representing transit itineraries
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/transit-routing: 2/4] WIP: Add list box row class for representing transit itineraries
- Date: Thu, 2 Jun 2016 20:53:52 +0000 (UTC)
commit c7a60b3fc3fbfd77cca5c1d7123e9ff678282cd3
Author: Marcus Lundblad <ml update uu se>
Date: Mon May 30 22:34:39 2016 +0200
WIP: Add list box row class for representing transit itineraries
This list box class is used to render the overview items showing the list of
found itineraries when performing a transit route search.
data/ui/transit-itinerary-row.ui | 74 ++++++++++++++++++++++
src/org.gnome.Maps.src.gresource.xml | 1 +
src/transitItineraryRow.js | 113 ++++++++++++++++++++++++++++++++++
3 files changed, 188 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/transit-itinerary-row.ui b/data/ui/transit-itinerary-row.ui
new file mode 100644
index 0000000..c226356
--- /dev/null
+++ b/data/ui/transit-itinerary-row.ui
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<interface>
+ <requires lib="gtk+" version="3.14"/>
+ <template class="Gjs_TransitItineraryRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="margin">13</property>
+ <property name="column_spacing">13</property>
+ <property name="row-spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="timeLabel">
+ <property name="visible">True</property>
+ <property name="expand">False</property>
+ <property name="halign">GTK_ALIGN_START</property>
+ </object>
+ <packing>
+ <property name="top-attach">0</property>
+ <property name="left-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="durationLabel">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="halign">GTK_ALIGN_START</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top-attach">0</property>
+ <property name="left-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="summaryGrid">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="column-spacing">13</property>
+ </object>
+ <packing>
+ <property name="top-attach">1</property>
+ <property name="left-attach">0</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="selectButton">
+ <property name="visible">True</property>
+ <style>
+ <class name="flat"/>
+ <class name="circular"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">go-next-symbolic</property>
+ <property name="pixel-size">16</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="top-attach">0</property>
+ <property name="left-attach">2</property>
+ <property name="height">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 7fc9174..468f46d 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -72,6 +72,7 @@
<file>socialPlaceMatcher.js</file>
<file>storedRoute.js</file>
<file>togeojson/togeojson.js</file>
+ <file>transitItineraryRow.js</file>
<file>transitOptions.js</file>
<file>transitPlan.js</file>
<file>transitRouteLabel.js</file>
diff --git a/src/transitItineraryRow.js b/src/transitItineraryRow.js
new file mode 100644
index 0000000..1fae522
--- /dev/null
+++ b/src/transitItineraryRow.js
@@ -0,0 +1,113 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+
+const TransitRouteLabel = imports.transitRouteLabel;
+
+// in org.gnome.desktop.interface
+const CLOCK_FORMAT_KEY = 'clock-format';
+
+let _desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
+let clockFormat = _desktopSettings.get_string(CLOCK_FORMAT_KEY);
+
+const TransitItineraryRow = new Lang.Class({
+ Name: 'TransitItineraryRow',
+ Extends: Gtk.ListBoxRow,
+ Template: 'resource:///org/gnome/Maps/ui/transit-itinerary-row.ui',
+ InternalChildren: ['timeLabel',
+ 'durationLabel',
+ 'summaryGrid'],
+
+ _init: function(params) {
+ this._itinerary = params.itinerary;
+ delete params.itinerary;
+
+ this.parent(params);
+
+ this._timeLabel.label =
+ _("%s \u2014 %s").format(this._getDepartureTime(),
+ this._getArrivalTime());
+ this._durationLabel.label =
+ _("%d minutes").format(this._itinerary.duration / 60);
+
+ this._populateSummary();
+ },
+
+ _getDepartureTime: function() {
+ /* take the itinerary departure time and offset using the timezone
+ * offset of the first leg */
+ let utcTimeWithOffset =
+ (this._itinerary.departure +
+ this._itinerary.legs[0].agencyTimezoneOffset) / 1000;
+ let date = GLib.DateTime.new_from_unix_utc(utcTimeWithOffset);
+
+ if (clockFormat === '24h')
+ return date.format('%R');
+ else
+ return date.format('%r');
+ },
+
+ _getArrivalTime: function() {
+ /* take the itinerary departure time and offset using the timezone
+ * offset of the first leg */
+ let utcTimeWithOffset =
+ (this._itinerary.arrival +
+ this._itinerary.legs[this._itinerary.legs.length - 1].agencyTimezoneOffset) / 1000;
+ let date = GLib.DateTime.new_from_unix_utc(utcTimeWithOffset);
+
+ if (clockFormat === '24h')
+ return date.format('%R');
+ else
+ return date.format('%r');
+ },
+
+ _populateSummary: function() {
+ this._itinerary.legs.forEach((function(leg) {
+ this._summaryGrid.add(this._createLeg(leg));
+ }).bind(this));
+ },
+
+ _createLeg: function(leg) {
+ if (!leg.transit) {
+ /* if this is a non-transit leg (walking), insert a sole icon */
+ return new Gtk.Image({ icon_name: leg.iconName,
+ visible: true })
+ } else {
+ /* for transit legs put besides a short route label */
+ let grid = new Gtk.Grid({ visible: true, column_spacing: 2 });
+
+ grid.attach(new Gtk.Image({ icon_name: leg.iconName, visible: true }),
+ 0, 0, 1, 1);
+ grid.attach(new TransitRouteLabel.TransitRouteLabel({ leg: leg,
+ visible: true,
+ use_markup: true }),
+ 1, 0, 1, 1);
+
+ return grid;
+ }
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]