Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
- index 5e8ef6d..9dd7f60 100644
- --- a/src/gnome-maps.js.gresource.xml
- +++ b/src/gnome-maps.js.gresource.xml
- @@ -19,6 +19,7 @@
- <file>notificationManager.js</file>
- <file>path.js</file>
- <file>placeEntry.js</file>
- + <file>placeFormatter.js</file>
- <file>placeStore.js</file>
- <file>route.js</file>
- <file>routeQuery.js</file>
- diff --git a/src/placeFormatter.js b/src/placeFormatter.js
- new file mode 100644
- index 0000000..05322f5
- --- /dev/null
- +++ b/src/placeFormatter.js
- @@ -0,0 +1,135 @@
- +/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
- +/* vim: set et ts=4 sw=4: */
- +/*
- + * Copyright (c) 2014 Damián Nohales
- + *
- + * 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: Damián Nohales <[email protected]>
- + */
- +
- +const Geocode = imports.gi.GeocodeGlib;
- +
- +const Lang = imports.lang;
- +
- +const PlaceFormatter = new Lang.Class({
- + Name: "PlaceFormatter",
- +
- + _init: function(place) {
- + this.place = place;
- + },
- +
- + set place(place) {
- + this._place = place;
- + this._update();
- + },
- +
- + get place() {
- + return this._place;
- + },
- +
- + get titleProperty() {
- + return this._titleProperty;
- + },
- +
- + get title() {
- + return this.getProperty(this.titleProperty);
- + },
- +
- + get infoPropertyGroups() {
- + return this._infoPropertyGroups;
- + },
- +
- + getProperty: function(prop) {
- + return this.place[prop];
- + },
- +
- + _update: function() {
- + let title;
- + let info = [];
- + let place = this.place;
- +
- + if (this._isBrokenPlace(place)) {
- + // Fallback for places coming from PlaceStore
- + title = 'name';
- + } else {
- + switch (place.place_type) {
- + case Geocode.PlaceType.COUNTRY:
- + title = 'country';
- + this._addInfoGroup(info, place, ['country_code']);
- + break;
- +
- + case Geocode.PlaceType.STATE:
- + title = 'state';
- + this._addInfoGroup(info, place, ['country']);
- + break;
- +
- + case Geocode.PlaceType.COUNTY:
- + title = 'county';
- + this._addInfoGroup(info, place, ['state', 'country']);
- + break;
- +
- + case Geocode.PlaceType.TOWN:
- + case Geocode.PlaceType.LOCAL_ADMINISTRATIVE_AREA:
- + title = place.town ? 'town' : 'administrative_area';
- + if (title === 'town')
- + this._addInfoGroup(info, place, ['administrative_area']);
- + this._addInfoGroup(info, place, ['postal_code']);
- + this._addInfoGroup(info, place, ['county']);
- + this._addInfoGroup(info, place, ['state', 'country']);
- + break;
- +
- + case Geocode.PlaceType.STREET:
- + case Geocode.PlaceType.MOTORWAY:
- + case Geocode.PlaceType.BUS_STOP:
- + title = place.street_address ? 'street_address' : 'street';
- + this._addInfoGroup(info, place, ['area', 'town', 'administrative_area']);
- + this._addInfoGroup(info, place, ['postal_code']);
- + this._addInfoGroup(info, place, ['county']);
- + this._addInfoGroup(info, place, ['state', 'country']);
- + break;
- +
- + //TODO: add specific UIs for the rest of the place types
- + default:
- + title = 'name';
- + break;
- + }
- + }
- +
- + // Ensure that we have a valid title
- + if (!this.getProperty(title))
- + title = 'name';
- +
- + this._titleProperty = title;
- + this._infoPropertyGroups = info;
- + },
- +
- + _isBrokenPlace: function(place) {
- + // Broken places are GeocodePlace objects coming from PlaceStore,
- + // which doesn't save most of the place properties.
- + // See: https://bugzilla.gnome.org/show_bug.cgi?id=726625
- + return !place.country && !place.state && !place.county && !place.town &&
- + !place.street && !place.street_address;
- + },
- +
- + _addInfoGroup: function(info, place, properties) {
- + properties = properties.filter((function(prop) {
- + return this.getProperty(prop) ? true : false;
- + }).bind(this));
- +
- + if (properties.length > 0)
- + info.push(properties);
- + }
- +});
- \ No newline at end of file
- diff --git a/src/searchPopup.js b/src/searchPopup.js
- index f54d58c..7a4459a 100644
- --- a/src/searchPopup.js
- +++ b/src/searchPopup.js
- @@ -22,9 +22,13 @@ const Gtk = imports.gi.Gtk;
- const GLib = imports.gi.GLib;
- const GdkPixbuf = imports.gi.GdkPixbuf;
- const GObject = imports.gi.GObject;
- +const Pango = imports.gi.Pango;
- const Lang = imports.lang;
- +
- +const PlaceFormatter = imports.placeFormatter;
- const Utils = imports.utils;
- +const _ = imports.gettext.gettext;
- const Columns = {
- ICON: 0,
- @@ -81,7 +85,9 @@ const SearchPopup = new Lang.Class({
- column.add_attribute(cell, 'pixbuf', Columns.ICON);
- cell = new Gtk.CellRendererText({ xpad: 8,
- - ypad: 8 });
- + ypad: 8,
- + wrap_mode: Pango.WrapMode.WORD,
- + wrap_width: 500 });
- column.pack_start(cell, true);
- column.add_attribute(cell, 'markup', Columns.DESCRIPTION);
- @@ -145,10 +151,9 @@ const SearchPopup = new Lang.Class({
- return;
- let iter = model.append();
- - let location = place.get_location();
- let icon = place.icon;
- - let description = GLib.markup_escape_text(location.description, -1);
- + let description = this._getDescription(place);
- description = this._boldMatch(description, searchString);
- model.set(iter,
- @@ -165,6 +170,30 @@ const SearchPopup = new Lang.Class({
- }).bind(this));
- },
- + _getDescription: function(place) {
- + let formatter = new PlaceFormatter.PlaceFormatter(place);
- + let title = formatter.title;
- + let info = formatter.infoPropertyGroups.map(function(group) {
- + group = group.map(function(prop) {
- + switch (prop) {
- + case 'country_code':
- + return _("Country code: %s").format(formatter.getProperty(prop));
- +
- + default:
- + return formatter.getProperty(prop);
- + }
- + });
- +
- + return group.join(', ');
- + }).join(', ');
- +
- + if (info)
- + return '%s\n<small>%s</small>'.format(GLib.markup_escape_text(title, -1),
- + GLib.markup_escape_text(info, -1));
- + else
- + return GLib.markup_escape_text(title, -1);
- + },
- +
- _boldMatch: function(description, searchString) {
- searchString = searchString.toLowerCase();
- diff --git a/src/searchResultBubble.js b/src/searchResultBubble.js
- index fb40535..a6e7286 100644
- --- a/src/searchResultBubble.js
- +++ b/src/searchResultBubble.js
- @@ -26,6 +26,7 @@ const Gtk = imports.gi.Gtk;
- const Lang = imports.lang;
- const MapBubble = imports.mapBubble;
- +const PlaceFormatter = imports.placeFormatter;
- const Utils = imports.utils;
- const _ = imports.gettext.gettext;
- @@ -46,41 +47,29 @@ const SearchResultBubble = new Lang.Class({
- ui.image.pixbuf = pixbuf;
- });
- - let title = null;
- - let content = [];
- + let formatter = new PlaceFormatter.PlaceFormatter(place);
- + let info = [];
- - if (this._isBrokenPlace(place)) {
- - // Fallback for places coming from PlaceStore
- - title = place.name;
- - } else {
- - switch (place.place_type) {
- - case Geocode.PlaceType.COUNTRY:
- - title = place.country;
- - if (place.country_code)
- - content.push(_("Country code: %s").format(place.country_code));
- - break;
- + ui.labelTitle.label = formatter.title;
- + info = formatter.infoPropertyGroups.map(function(group) {
- + group = group.map(function(prop) {
- + switch (prop) {
- + case 'postal_code':
- + return _("Postal code: %s").format(formatter.getProperty(prop));
- - case Geocode.PlaceType.TOWN:
- - title = place.town;
- - if (place.postal_code)
- - content.push(_("Postal code: %s").format(place.postal_code));
- - if (place.state)
- - content.push(place.state + ', ' + place.country);
- - else
- - content.push(place.country);
- - break;
- + case 'country_code':
- + return _("Country code: %s").format(formatter.getProperty(prop));
- - //TODO: add specific UIs for the rest of the place types
- - default:
- - title = place.name;
- - break;
- - }
- - }
- + default:
- + return formatter.getProperty(prop);
- + }
- + });
- - ui.labelTitle.label = title;
- + return group.join(', ');
- + });
- - content.forEach(function(c) {
- - let label = new Gtk.Label({ label: c,
- + info.forEach(function(i) {
- + let label = new Gtk.Label({ label: i,
- visible: true,
- halign: Gtk.Align.START });
- ui.boxRight.pack_start(label, false, true, 0);
- @@ -88,12 +77,4 @@ const SearchResultBubble = new Lang.Class({
- this.add(ui.grid);
- },
- -
- - _isBrokenPlace: function(place) {
- - // Broken places are GeocodePlace objects coming from PlaceStore,
- - // which doesn't save most of the place properties.
- - // See: https://bugzilla.gnome.org/show_bug.cgi?id=726625
- - return !place.country && !place.state && !place.county && !place.town &&
- - !place.street && !place.street_address;
- - }
- });
Advertisement
Add Comment
Please, Sign In to add comment