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



commit 822aba5c77c74a50a86d9f1e63de68d8d3359939
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   |   49 +++++++++++++++++++++--------------------
 src/mapLocation.js  |   41 +++++++++++++++++++----------------
 src/mapView.js      |   59 ++++++++++++++++++++++----------------------------
 src/userLocation.js |   19 ++++++++++------
 5 files changed, 91 insertions(+), 89 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..f85d7b0 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();
 
@@ -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..730898c 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -42,10 +42,10 @@ 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({
@@ -93,14 +93,16 @@ const MapView = new Lang.Class({
                 try {
                     let places = forward.search_finish(res);
                     log (places.length + " places found");
-                    let mapLocations = new Array();
+                    let mapLocations = [];
                     places.forEach(Lang.bind(this,
                         function(place) {
                             let location = place.get_location();
                             if (location == null)
                                 return;
 
-                            let mapLocation = new MapLocation.MapLocation(location, this);
+                            let mapLocation
+                                    = new MapLocation.MapLocation(location,
+                                                                  this);
                             mapLocations.push(mapLocation);
                         }));
                     this._showLocations(mapLocations);
@@ -111,29 +113,17 @@ const MapView = new Lang.Class({
     },
 
     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 +137,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 +151,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);
diff --git a/src/userLocation.js b/src/userLocation.js
index fd9419a..67aaf99 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -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);
 


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