[gnome-maps] Separate class for geolocation
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Separate class for geolocation
- Date: Tue, 18 Jun 2013 10:13:39 +0000 (UTC)
commit c2f92b1989160e6dfa04a9ee37b5e6b53d433565
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Jun 17 18:06:07 2013 +0200
Separate class for geolocation
src/Makefile-js.am | 3 +-
src/geoclue.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/mapView.js | 47 ++++++++-----------------------
3 files changed, 92 insertions(+), 36 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 778fc34..3caf4bc 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -8,7 +8,8 @@ dist_js_DATA = \
path.js \
sidebar.js \
utils.js \
- userLocation.js
+ userLocation.js \
+ geoclue.js
BUILT_SOURCES += \
path.js \
diff --git a/src/geoclue.js b/src/geoclue.js
new file mode 100644
index 0000000..c6ba2c0
--- /dev/null
+++ b/src/geoclue.js
@@ -0,0 +1,78 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ *
+ * 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: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ */
+
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Geocode = imports.gi.GeocodeGlib;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+
+const Application = imports.application;
+const Utils = imports.utils;
+const Path = imports.path;
+const Signals = imports.signals;
+const _ = imports.gettext.gettext;
+
+const Geoclue = new Lang.Class({
+ Name: 'Geoclue',
+
+ _init: function() {
+ let lastLocation = Application.settings.get_value('last-location');
+ if (lastLocation.n_children() >= 3) {
+ let lat = lastLocation.get_child_value(0);
+ let lng = lastLocation.get_child_value(1);
+ let accuracy = lastLocation.get_child_value(2);
+
+ this.location = new Geocode.Location({ latitude: lat.get_double(),
+ longitude: lng.get_double(),
+ accuracy: accuracy.get_double() });
+ let lastLocationDescription = Application.settings.get_string('last-location-description');
+ this.location.set_description(lastLocationDescription);
+ }
+
+ this._findLocation();
+ },
+
+ _findLocation: function() {
+ let ipclient = new Geocode.Ipclient();
+ ipclient.server = "http://freegeoip.net/json/";
+ ipclient.compatibility_mode = true;
+ ipclient.search_async(null, Lang.bind(this,
+ function(ipclient, res) {
+ try {
+ this.location = ipclient.search_finish(res);
+
+ let variant = GLib.Variant.new('ad', [this.location.latitude,
+ this.location.longitude,
+ this.location.accuracy]);
+ Application.settings.set_value('last-location', variant);
+ Application.settings.set_string('last-location-description', this.location.description);
+
+ this.emit('location-changed');
+ } catch (e) {
+ log("Failed to find your location: " + e);
+ }
+ }));
+ },
+});
+Signals.addSignalMethods(Geoclue.prototype);
diff --git a/src/mapView.js b/src/mapView.js
index a368e0c..0bfe944 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -24,7 +24,6 @@ const Clutter = imports.gi.Clutter;
const Cogl = imports.gi.Cogl;
const Gdk = imports.gi.Gdk;
const GdkPixbuf = imports.gi.GdkPixbuf;
-const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const GtkChamplain = imports.gi.GtkChamplain;
const Champlain = imports.gi.Champlain;
@@ -34,12 +33,12 @@ const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
-const Application = imports.application;
const Sidebar = imports.sidebar;
const Utils = imports.utils;
const Path = imports.path;
const MapLocation = imports.mapLocation;
const UserLocation = imports.userLocation;
+const Geoclue = imports.geoclue;
const _ = imports.gettext.gettext;
const MapType = {
@@ -154,40 +153,18 @@ const MapView = new Lang.Class({
},
_showUserLocation: function() {
- let lastLocation = Application.settings.get_value('last-location');
- if (lastLocation.n_children() >= 3) {
- let lat = lastLocation.get_child_value(0);
- let lng = lastLocation.get_child_value(1);
- let accuracy = lastLocation.get_child_value(2);
-
- let location = new Geocode.Location({ latitude: lat.get_double(),
- longitude: lng.get_double(),
- accuracy: accuracy.get_double() });
- let lastLocationDescription = Application.settings.get_string('last-location-description');
- location.set_description(lastLocationDescription);
-
- this._userLocation = new UserLocation.UserLocation(location, this);
- this._userLocation.show(this._userLocationLayer);
- }
-
- let ipclient = new Geocode.Ipclient();
- ipclient.server = "http://freegeoip.net/json/";
- ipclient.compatibility_mode = true;
- ipclient.search_async(null, Lang.bind(this,
- function(ipclient, res) {
- try {
- let location = ipclient.search_finish(res);
-
- this._userLocation = new UserLocation.UserLocation(location, this);
- this._userLocation.show(this._userLocationLayer);
+ this._geoclue = new Geoclue.Geoclue();
- let variant = GLib.Variant.new('ad', [location.latitude, location.longitude,
location.accuracy]);
- Application.settings.set_value('last-location', variant);
- Application.settings.set_string('last-location-description', location.description);
- } catch (e) {
- log("Failed to find your location: " + e);
- }
- }));
+ let onLocationChanged = Lang.bind(this,
+ function() {
+ if (this._geoclue.location == null)
+ return;
+
+ this._userLocation = new UserLocation.UserLocation(this._geoclue.location, this);
+ this._userLocation.show(this._userLocationLayer);
+ });
+ this._geoclue.connect("location-changed", onLocationChanged);
+ onLocationChanged();
},
_showLocations: function(locations) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]