[gnome-maps] Cleanups
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Cleanups
- Date: Wed, 31 Jul 2013 00:35:14 +0000 (UTC)
commit d2dc088c124c74d9b2ca56880b8d65ee26ac3042
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Wed Jul 10 02:06:30 2013 +0200
Cleanups
Reindentions, trailing commas, extra spaces and more js-idiomatic code.
https://bugzilla.gnome.org/show_bug.cgi?id=704537
src/application.js | 2 +-
src/geoclue.js | 37 ++++++++--------
src/mainWindow.js | 113 +++++++++++++++++++++++------------------------
src/mapLocation.js | 41 +++++++++--------
src/mapView.js | 121 ++++++++++++++++++++++-----------------------------
src/sidebar.js | 4 +-
src/userLocation.js | 33 +++++++-------
7 files changed, 166 insertions(+), 185 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 10ec1dc..e56318d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -97,7 +97,7 @@ const Application = new Lang.Class({
return;
this._mainWindow = new MainWindow.MainWindow(this);
- this._mainWindow.window.connect('destroy', Lang.bind(this, this._onWindowDestroy));
+ this._mainWindow.window.connect('destroy', this._onWindowDestroy.bind(this));
},
vfunc_activate: function() {
diff --git a/src/geoclue.js b/src/geoclue.js
index 206dc77..5319eb1 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -58,17 +58,17 @@ const Geoclue = new Lang.Class({
_findLocation: function() {
GClue.ManagerProxy.new_for_bus(Gio.BusType.SESSION,
Gio.DBusProxyFlags.NONE,
- "org.freedesktop.GeoClue2",
- "/org/freedesktop/GeoClue2/Manager",
- null,
- Lang.bind(this, this._onManagerProxyReady));
+ "org.freedesktop.GeoClue2",
+ "/org/freedesktop/GeoClue2/Manager",
+ null,
+ this._onManagerProxyReady.bind(this));
},
_onManagerProxyReady: function(sourceObject, res) {
try {
this._managerProxy = GClue.ManagerProxy.new_for_bus_finish(res);
- this._managerProxy.call_get_client(null, Lang.bind(this, this._onGetClientReady));
+ this._managerProxy.call_get_client(null, this._onGetClientReady.bind(this));
} catch (e) {
log ("Failed to connect to GeoClue2 service: " + e.message);
}
@@ -83,7 +83,7 @@ const Geoclue = new Lang.Class({
"org.freedesktop.GeoClue2",
clientPath,
null,
- Lang.bind(this, this._onClientProxyReady));
+ this._onClientProxyReady.bind(this));
} catch (e) {
log ("Failed to connect to GeoClue2 service: " + e.message);
}
@@ -93,17 +93,16 @@ const Geoclue = new Lang.Class({
try {
this._clientProxy = GClue.ClientProxy.new_for_bus_finish(res);
- this._clientProxy.connect("location-updated", Lang.bind(this,
- function(client, oldPath, newPath) {
- GClue.LocationProxy.new_for_bus(Gio.BusType.SESSION,
- Gio.DBusProxyFlags.NONE,
- "org.freedesktop.GeoClue2",
- newPath,
- null,
- Lang.bind(this, this._onLocationProxyReady));
- }));
-
- this._clientProxy.call_start(null, Lang.bind(this, this._onStartReady));
+ this._clientProxy.connect("location-updated", (function(client, oldPath, newPath) {
+ GClue.LocationProxy.new_for_bus(Gio.BusType.SESSION,
+ Gio.DBusProxyFlags.NONE,
+ "org.freedesktop.GeoClue2",
+ newPath,
+ null,
+ this._onLocationProxyReady.bind(this));
+ }).bind(this));
+
+ this._clientProxy.call_start(null, this._onStartReady.bind(this));
} catch (e) {
log ("Failed to connect to GeoClue2 service: " + e.message);
}
@@ -119,7 +118,7 @@ const Geoclue = new Lang.Class({
_onLocationProxyReady: function(sourceObject, res) {
try {
- this.location = GClue.LocationProxy.new_for_bus_finish(res);
+ this.location = GClue.LocationProxy.new_for_bus_finish(res);
let variant = GLib.Variant.new('ad', [this.location.latitude,
this.location.longitude,
@@ -132,6 +131,6 @@ const Geoclue = new Lang.Class({
} catch (e) {
log("Failed to find your location: " + e);
}
- },
+ }
});
Signals.addSignalMethods(Geoclue.prototype);
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d0606b9..35669e9 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -98,47 +98,44 @@ const MainWindow = new Lang.Class({
if (Application.settings.get_boolean('window-maximized'))
this.window.maximize();
- this.window.connect('delete-event',
- Lang.bind(this, this._quit));
+ this.window.connect('delete-event',
+ this._quit.bind(this));
this.window.connect('configure-event',
- Lang.bind(this, this._onConfigureEvent));
+ this._onConfigureEvent.bind(this));
this.window.connect('window-state-event',
- Lang.bind(this, this._onWindowStateEvent));
+ this._onWindowStateEvent.bind(this));
- this._searchEntry.connect('activate', Lang.bind(this, this._onSearchActivate));
+ this._searchEntry.connect('activate', this._onSearchActivate.bind(this));
this.mapView = new MapView.MapView();
let trackUserLocation = Application.settings.get_boolean('track-user-location');
- let onViewMoved = Lang.bind(this,
- function () {
- if (!this.mapView.userLocationVisible())
- toggle.active = false;
- });
+ let onViewMoved = function () {
+ if (!this.mapView.userLocationVisible())
+ toggle.active = false;
+ };
// Disable animation for goto animation on startup only
let animateGotoUserLocation = !trackUserLocation;
- toggle.connect('toggled', Lang.bind(this,
- function() {
- if (this._onViewMovedId > 0) {
- this.mapView.disconnect(this._onViewMovedId);
- this._onViewMovedId = 0;
- }
-
- if (toggle.active) {
- let goneToUserLocationId = this.mapView.connect('gone-to-user-location', Lang.bind(this,
- function () {
- this.mapView.disconnect(goneToUserLocationId);
- this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved);
- }));
- this.mapView.gotoUserLocation(animateGotoUserLocation);
- if (!animateGotoUserLocation)
- animateGotoUserLocation = true;
- }
-
- Application.settings.set_boolean('track-user-location', toggle.active);
- }));
+ toggle.connect('toggled', (function() {
+ if (this._onViewMovedId > 0) {
+ this.mapView.disconnect(this._onViewMovedId);
+ this._onViewMovedId = 0;
+ }
+
+ if (toggle.active) {
+ let goneToUserLocationId = this.mapView.connect('gone-to-user-location', (function () {
+ this.mapView.disconnect(goneToUserLocationId);
+ this._onViewMovedId = this.mapView.connect('view-moved', onViewMoved.bind(this));
+ }).bind(this));
+ this.mapView.gotoUserLocation(animateGotoUserLocation);
+ if (!animateGotoUserLocation)
+ animateGotoUserLocation = true;
+ }
+
+ Application.settings.set_boolean('track-user-location', toggle.active);
+ }).bind(this));
toggle.active = trackUserLocation;
grid.add(this.mapView);
@@ -164,16 +161,15 @@ const MainWindow = new Lang.Class({
},
_onConfigureEvent: function(widget, event) {
- if (this._configureId != 0) {
+ if (this._configureId !== 0) {
Mainloop.source_remove(this._configureId);
this._configureId = 0;
}
- this._configureId = Mainloop.timeout_add(_CONFIGURE_ID_TIMEOUT, Lang.bind(this,
- function() {
- this._saveWindowGeometry();
- return false;
- }));
+ this._configureId = Mainloop.timeout_add(_CONFIGURE_ID_TIMEOUT, (function() {
+ this._saveWindowGeometry();
+ return false;
+ }).bind(this));
},
_onWindowStateEvent: function(widget, event) {
@@ -195,7 +191,7 @@ const MainWindow = new Lang.Class({
_quit: function() {
// remove configure event handler if still there
- if (this._configureId != 0) {
+ if (this._configureId !== 0) {
Mainloop.source_remove(this._configureId);
this._configureId = 0;
}
@@ -218,27 +214,28 @@ const MainWindow = new Lang.Class({
},
_onAboutActivate: function() {
- let aboutDialog = new Gtk.AboutDialog();
-
- aboutDialog.artists = [ 'Jakub Steiner <jimmac gmail com>', 'Andreas Nilsson <nisses mail home se>'
];
- aboutDialog.authors = [ 'Zeeshan Ali (Khattak) <zeeshanak gnome org>',
- 'Mattias Bengtsson <mattias jc bengtsson gmail com>' ];
- aboutDialog.translator_credits = _("translator-credits");
- aboutDialog.program_name = _("Maps");
- aboutDialog.comments = _("A map application for GNOME");
- aboutDialog.copyright = 'Copyright ' + String.fromCharCode(0x00A9) + ' 2011' +
String.fromCharCode(0x2013) + '2013 Red Hat, Inc.';
- aboutDialog.license_type = Gtk.License.GPL_2_0;
- aboutDialog.logo_icon_name = 'gnome-maps';
- aboutDialog.version = Config.PACKAGE_VERSION;
- aboutDialog.website = 'http://live.gnome.org/Maps';
- aboutDialog.wrap_license = true;
-
- aboutDialog.modal = true;
- aboutDialog.transient_for = this.window;
-
- aboutDialog.show();
- aboutDialog.connect('response', function() {
- aboutDialog.destroy();
+ let aboutDialog = new Gtk.AboutDialog({
+ artists: [ 'Jakub Steiner <jimmac gmail com>',
+ 'Andreas Nilsson <nisses mail home se>' ],
+ authors: [ 'Zeeshan Ali (Khattak) <zeeshanak gnome org>',
+ 'Mattias Bengtsson <mattias jc bengtsson gmail com>' ],
+ translator_credits: _("translator-credits"),
+ program_name: _("Maps"),
+ comments: _("A map application for GNOME"),
+ copyright: 'Copyright ' + String.fromCharCode(0x00A9) +
+ ' 2011' + String.fromCharCode(0x2013) +
+ '2013 Red Hat, Inc.',
+ license_type: Gtk.License.GPL_2_0,
+ logo_icon_name: 'gnome-maps',
+ version: Config.PACKAGE_VERSION,
+ website: 'http://live.gnome.org/Maps',
+ wrap_license: true,
+
+ modal: true,
+ transient_for: this.window
});
+ aboutDialog.show();
+ aboutDialog.connect('response',
+ aboutDialog.destroy.bind(aboutDialog));
}
});
diff --git a/src/mapLocation.js b/src/mapLocation.js
index 48677f5..e7e98f1 100644
--- a/src/mapLocation.js
+++ b/src/mapLocation.js
@@ -64,28 +64,24 @@ const MapLocation = new Lang.Class({
* also give user a good idea of where the destination is compared to current
* location.
*/
- let locations = new Array();
- locations[0] = new Geocode.Location({ latitude: this._view.get_center_latitude(),
- longitude: this._view.get_center_longitude() });
- locations[1] = this;
-
- let animCompletedId = this._view.connect("animation-completed", Lang.bind(this,
- function() {
- this._view.disconnect(animCompletedId);
- animCompletedId = this._view.connect("animation-completed::go-to", Lang.bind(this,
- function() {
- this._view.disconnect(animCompletedId);
- this._view.set_zoom_level(zoom);
- this.emit('gone-to');
- }));
- this._view.go_to(this.latitude, this.longitude);
- }));
- this._mapView.ensureVisible(locations);
+
+ let id = this._view.connect("animation-completed", (function() {
+ this._view.disconnect(id);
+
+ id = this._view.connect("animation-completed::go-to", (function() {
+ this._view.disconnect(id);
+ this._view.set_zoom_level(zoom);
+ this.emit('gone-to');
+ }).bind(this));
+
+ this._view.go_to(this.latitude, this.longitude);
+ }).bind(this));
+
+ this._mapView.ensureVisible([this._getCurrentLocation(), this]);
},
show: function(layer) {
- let marker = new Champlain.Label();
- marker.set_text(this.description);
+ let marker = new Champlain.Label({ text: this.description });
marker.set_location(this.latitude, this.longitude);
layer.add_marker(marker);
log("Added marker at " + this.latitude + ", " + this.longitude);
@@ -95,5 +91,12 @@ const MapLocation = new Lang.Class({
this.show(layer);
this.goTo(animate);
},
+
+ _getCurrentLocation: function() {
+ return new Geocode.Location({
+ latitude: this._view.get_center_latitude(),
+ longitude: this._view.get_center_longitude()
+ });
+ }
});
Signals.addSignalMethods(MapLocation.prototype);
diff --git a/src/mapView.js b/src/mapView.js
index 0bfe944..f5d6395 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -42,25 +42,25 @@ const Geoclue = imports.geoclue;
const _ = imports.gettext.gettext;
const MapType = {
- STREET: Champlain.MAP_SOURCE_OSM_MAPQUEST,
- AERIAL: Champlain.MAP_SOURCE_OSM_AERIAL_MAP,
- CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
- TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
+ STREET: Champlain.MAP_SOURCE_OSM_MAPQUEST,
+ AERIAL: Champlain.MAP_SOURCE_OSM_AERIAL_MAP,
+ CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
+ TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
};
const MapView = new Lang.Class({
Name: 'MapView',
Extends: GtkChamplain.Embed,
- _init: function(app) {
+ _init: function() {
this.parent();
this.actor = this.get_view();
this.view = this.actor;
this.view.set_zoom_level(3);
- this.view.connect('notify::latitude', Lang.bind(this, this._onViewMoved));
- this.view.connect('notify::longitude', Lang.bind(this, this._onViewMoved));
+ this.view.connect('notify::latitude', this._onViewMoved.bind(this));
+ this.view.connect('notify::longitude', this._onViewMoved.bind(this));
this._sidebar = new Sidebar.Sidebar(this);
// Don't show sidebar until it has something in it
@@ -87,62 +87,46 @@ const MapView = new Lang.Class({
geocodeSearch: function(string) {
let forward = Geocode.Forward.new_for_string(string);
-
- forward.search_async (null, Lang.bind(this,
- function(forward, res) {
- try {
- let places = forward.search_finish(res);
- log (places.length + " places found");
- let mapLocations = new Array();
- places.forEach(Lang.bind(this,
- function(place) {
- let location = place.get_location();
- if (location == null)
- return;
-
- let mapLocation = new MapLocation.MapLocation(location, this);
- mapLocations.push(mapLocation);
- }));
- this._showLocations(mapLocations);
- } catch (e) {
- log ("Failed to search '" + string + "': " + e.message);
- }
- }));
+ forward.search_async (null, (function(forward, res) {
+ try {
+ let places = forward.search_finish(res);
+ log (places.length + " places found");
+ let mapLocations = [];
+ places.forEach((function(place) {
+ let location = place.get_location();
+ if (!location)
+ return;
+
+ let mapLocation = new MapLocation.MapLocation(location, this);
+ mapLocations.push(mapLocation);
+ }).bind(this));
+ this._showLocations(mapLocations);
+ } catch (e) {
+ log ("Failed to search '" + string + "': " + e.message);
+ }
+ }).bind(this));
},
ensureVisible: function(locations) {
- let min_latitude = 90;
- let max_latitude = -90;
- let min_longitude = 180;
- let max_longitude = -180;
-
- locations.forEach(Lang.bind(this,
- function(location) {
- if (location.latitude > max_latitude)
- max_latitude = location.latitude;
- if (location.latitude < min_latitude)
- min_latitude = location.latitude;
- if (location.longitude > max_longitude)
- max_longitude = location.longitude;
- if (location.longitude < min_longitude)
- min_longitude = location.longitude;
- }));
-
- let bbox = new Champlain.BoundingBox();
- bbox.left = min_longitude;
- bbox.right = max_longitude;
- bbox.bottom = min_latitude;
- bbox.top = max_latitude;
-
+ let bbox = new Champlain.BoundingBox({ left: 180,
+ right: -180,
+ bottom: 90,
+ top: -90 });
+
+ locations.forEach(function(location) {
+ bbox.left = Math.min(bbox.left, location.longitude);
+ bbox.right = Math.max(bbox.right, location.longitude);
+ bbox.bottom = Math.min(bbox.bottom, location.latitude);
+ bbox.top = Math.max(bbox.top, location.latitude);
+ });
this.view.ensure_visible(bbox, true);
},
gotoUserLocation: function(animate) {
- let goneToId = this._userLocation.connect("gone-to", Lang.bind(this,
- function() {
- this.emit('gone-to-user-location');
- this._userLocation.disconnect(goneToId);
- }));
+ let goneToId = this._userLocation.connect("gone-to", (function() {
+ this.emit('gone-to-user-location');
+ this._userLocation.disconnect(goneToId);
+ }).bind(this));
this._userLocation.goTo(animate);
},
@@ -155,29 +139,28 @@ const MapView = new Lang.Class({
_showUserLocation: function() {
this._geoclue = new Geoclue.Geoclue();
- let onLocationChanged = Lang.bind(this,
- function() {
- if (this._geoclue.location == null)
- return;
+ let onLocationChanged = (function() {
+ if (this._geoclue.location == null)
+ return;
+
+ this._userLocation = new UserLocation.UserLocation(this._geoclue.location, this);
+ this._userLocation.show(this._userLocationLayer);
+ }).bind(this);
- this._userLocation = new UserLocation.UserLocation(this._geoclue.location, this);
- this._userLocation.show(this._userLocationLayer);
- });
this._geoclue.connect("location-changed", onLocationChanged);
onLocationChanged();
},
_showLocations: function(locations) {
- if (locations.length == 0)
+ if (locations.length === 0)
return;
this._markerLayer.remove_all();
- locations.forEach(Lang.bind(this,
- function(location) {
- location.show(this._markerLayer);
- }));
+ locations.forEach((function(location) {
+ location.show(this._markerLayer);
+ }).bind(this));
- if (locations.length == 1)
+ if (locations.length === 1)
locations[0].goTo(true);
else
this.ensureVisible(locations);
diff --git a/src/sidebar.js b/src/sidebar.js
index 697af5a..50286b8 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -70,7 +70,7 @@ const Sidebar = new Lang.Class({
orientation: Gtk.Orientation.VERTICAL });
revealer.show_all();
- revealButton.connect('clicked', Lang.bind(this, function() {
+ revealButton.connect('clicked', (function() {
if (revealer.reveal_child) {
revealer.reveal_child = false;
revealButton.symbolic_icon_name = 'go-previous-symbolic';
@@ -78,7 +78,7 @@ const Sidebar = new Lang.Class({
revealer.reveal_child = true;
revealButton.symbolic_icon_name = 'go-next-symbolic';
}
- }));
+ }).bind(this));
// now create actors
let buttonActor = new GtkClutter.Actor({ contents: revealButton,
diff --git a/src/userLocation.js b/src/userLocation.js
index fd9419a..fe20278 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -41,18 +41,17 @@ const UserLocation = new Lang.Class({
this._locationMarker = new Champlain.CustomMarker();
this._locationMarker.set_location(this.latitude, this.longitude);
- this._locationMarker.connect('notify::size', Lang.bind(this,
- function() {
- let translate_x = -Math.floor(this._locationMarker.get_width() / 2);
- this._locationMarker.set_translation(translate_x,
- -this._locationMarker.get_height(),
- 0);
- }));
+ this._locationMarker.connect('notify::size', (function() {
+ let translate_x = -Math.floor(this._locationMarker.get_width() / 2);
+ this._locationMarker.set_translation(translate_x,
+ -this._locationMarker.get_height(),
+ 0);
+ }).bind(this));
let pin_actor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/pin.svg");
- if (pin_actor == null)
+ if (!pin_actor)
return;
let bubbleActor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/bubble.svg");
- if (bubbleActor == null)
+ if (!bubbleActor)
return;
bubbleActor.set_x_expand(true);
bubbleActor.set_y_expand(true);
@@ -62,15 +61,15 @@ const UserLocation = new Lang.Class({
textActor.set_margin_left(6);
textActor.set_margin_right(6);
textActor.set_color(new Clutter.Color({ red: 255,
- blue: 255,
- green: 255,
- alpha: 255 }));
+ blue: 255,
+ green: 255,
+ alpha: 255 }));
let layout = new Clutter.BinLayout();
let descriptionActor = new Clutter.Actor({ layout_manager: layout });
descriptionActor.add_child(bubbleActor);
descriptionActor.add_child(textActor);
- let layout = new Clutter.BoxLayout({ vertical: true });
+ layout = new Clutter.BoxLayout({ vertical: true });
let locationActor = new Clutter.Actor({ layout_manager: layout });
locationActor.add_child(descriptionActor);
locationActor.add_child(pin_actor);
@@ -81,7 +80,7 @@ const UserLocation = new Lang.Class({
descriptionActor, "visible",
GObject.BindingFlags.SYNC_CREATE);
- if (this.accuracy == 0) {
+ if (this.accuracy === 0) {
layer.add_marker(this._locationMarker);
return;
}
@@ -102,14 +101,14 @@ const UserLocation = new Lang.Class({
if (this._selectedId > 0)
this._locationMarker.disconnect(this._selectedId);
this._selectedId = this._locationMarker.connect("notify::selected",
- Lang.bind(this, this._updateAccuracyMarker));
+ this._updateAccuracyMarker.bind(this));
layer.add_marker(this._accuracyMarker);
layer.add_marker(this._locationMarker);
if (this._zoomLevelId > 0)
this._view.disconnect(this._zoomLevelId);
- this._zoomLevelId = this._view.connect("notify::zoom-level", Lang.bind(this,
this._updateAccuracyMarker));
+ this._zoomLevelId = this._view.connect("notify::zoom-level", this._updateAccuracyMarker.bind(this));
},
_updateAccuracyMarker: function() {
@@ -131,5 +130,5 @@ const UserLocation = new Lang.Class({
this._accuracyMarker.set_size(size);
this._accuracyMarker.show();
}
- },
+ }
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]