[gnome-maps/wip/fix-geoloc: 1/11] Cleanups



commit 7b96caf18b31e3d6cde3b4697fb1ba4dbc18417d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Jul 10 02:06:30 2013 +0200

    Cleanups
    
    Reindentions, trailing commas, extra spaces, try to fit 80 char columns
    and more js-idiomatic code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704537

 src/geoclue.js      |   12 +++---
 src/mainWindow.js   |   57 +++++++++++++++++----------------
 src/mapLocation.js  |   41 +++++++++++++-----------
 src/mapView.js      |   88 +++++++++++++++++++++------------------------------
 src/userLocation.js |   16 +++++-----
 5 files changed, 101 insertions(+), 113 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index 206dc77..033f0f9 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -58,10 +58,10 @@ 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,
+                                       Lang.bind(this, this._onManagerProxyReady));
     },
 
     _onManagerProxyReady: function(sourceObject, res) {
@@ -119,7 +119,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 +132,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..9a901c8 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -98,14 +98,14 @@ 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();
 
@@ -164,7 +164,7 @@ 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;
         }
@@ -195,7 +195,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 +218,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..5bafdba 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -42,17 +42,17 @@ 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();
@@ -87,53 +87,38 @@ 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);
     },
 
@@ -148,7 +133,6 @@ const MapView = new Lang.Class({
 
     userLocationVisible: function() {
         let box = this.view.get_bounding_box();
-
         return box.covers(this._userLocation.latitude, this._userLocation.longitude);
     },
 
@@ -168,7 +152,7 @@ const MapView = new Lang.Class({
     },
 
     _showLocations: function(locations) {
-        if (locations.length == 0)
+        if (locations.length === 0)
             return;
         this._markerLayer.remove_all();
 
@@ -177,7 +161,7 @@ const MapView = new Lang.Class({
                 location.show(this._markerLayer);
             }));
 
-        if (locations.length == 1)
+        if (locations.length === 1)
             locations[0].goTo(true);
         else
             this.ensureVisible(locations);
diff --git a/src/userLocation.js b/src/userLocation.js
index fd9419a..dd88cca 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -49,10 +49,10 @@ const UserLocation = new Lang.Class({
                                                      0);
             }));
         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 +62,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 +81,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;
         }
@@ -131,5 +131,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]