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



commit 794c661295d515ca265fc19db46e7039e8357c08
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.

 src/geoclue.js      |   12 +++---
 src/mainWindow.js   |   53 +++++++++++++++---------------
 src/mapLocation.js  |   41 ++++++++++++-----------
 src/mapView.js      |   89 +++++++++++++++++++++++----------------------------
 src/userLocation.js |   25 ++++++++------
 5 files changed, 110 insertions(+), 110 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..267c2ab 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', Lang.bind(this, this._quit));
         this.window.connect('configure-event',
                             Lang.bind(this, this._onConfigureEvent));
         this.window.connect('window-state-event',
                             Lang.bind(this, this._onWindowStateEvent));
 
-        this._searchEntry.connect('activate', Lang.bind(this, this._onSearchActivate));
+        this._searchEntry.connect('activate',
+                                  Lang.bind(this, this._onSearchActivate));
 
         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..92f0005 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();
@@ -86,54 +86,42 @@ 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) {
+        Geocode.Forward
+            .new_for_string(string)
+            .search_async (null, (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);
-                        }));
+                    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);
     },
 
@@ -147,9 +135,10 @@ const MapView = new Lang.Class({
     },
 
     userLocationVisible: function() {
-        let box = this.view.get_bounding_box();
-
-        return box.covers(this._userLocation.latitude, this._userLocation.longitude);
+        return this.view
+            .get_bounding_box()
+            .covers(this._userLocation.latitude,
+                    this._userLocation.longitude);
     },
 
     _showUserLocation: function() {
@@ -160,7 +149,9 @@ const MapView = new Lang.Class({
                 if (this._geoclue.location == null)
                     return;
 
-                this._userLocation = new UserLocation.UserLocation(this._geoclue.location, this);
+                this._userLocation =
+                    new UserLocation.UserLocation(this._geoclue.location,
+                                                  this);
                 this._userLocation.show(this._userLocationLayer);
             });
         this._geoclue.connect("location-changed", onLocationChanged);
@@ -168,7 +159,7 @@ const MapView = new Lang.Class({
     },
 
     _showLocations: function(locations) {
-        if (locations.length == 0)
+        if (locations.length === 0)
             return;
         this._markerLayer.remove_all();
 
@@ -177,7 +168,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..8673d4f 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,16 +62,21 @@ 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 }));
-        let layout = new Clutter.BinLayout();
-        let descriptionActor = new Clutter.Actor({ layout_manager: layout });
+                                                blue: 255,
+                                                green: 255,
+                                                alpha: 255 }));
+
+        let descriptionActor = new Clutter.Actor({
+            layout_manager: new Clutter.BinLayout()
+        });
         descriptionActor.add_child(bubbleActor);
         descriptionActor.add_child(textActor);
 
-        let layout = new Clutter.BoxLayout({ vertical: true });
-        let locationActor = new Clutter.Actor({ layout_manager: layout });
+        let locationActor = new Clutter.Actor({
+            layout_manager: new Clutter.BoxLayout({
+                vertical: true
+            })
+        });
         locationActor.add_child(descriptionActor);
         locationActor.add_child(pin_actor);
 
@@ -81,7 +86,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;
         }


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