[gnome-maps] Add 'show-contact' action



commit bbeec47427e100f45afcab411a6dbb3b93724efa
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Dec 16 04:48:04 2014 -0500

    Add 'show-contact' action
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741591

 src/application.js |   38 +++++++++++++++++++++++++++++++++++++-
 src/mapView.js     |   18 ++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 80d3749..4f3e153 100644
--- a/src/application.js
+++ b/src/application.js
@@ -33,7 +33,9 @@ const Format = imports.format;
 const Geoclue = imports.geoclue;
 const GeocodeService = imports.geocodeService;
 const MainWindow = imports.mainWindow;
+const Maps = imports.gi.GnomeMaps;
 const NotificationManager = imports.notificationManager;
+const Place = imports.place;
 const PlaceStore = imports.placeStore;
 const RouteService = imports.routeService;
 const Settings = imports.settings;
@@ -49,6 +51,7 @@ let geoclue = null;
 let geocodeService = null;
 let networkMonitor = null;
 let checkInManager = null;
+let contactStore = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -93,6 +96,33 @@ const Application = new Lang.Class({
         }).bind(this));
     },
 
+    _showContact: function(id) {
+        contactStore.lookup(id, (function(contact) {
+            this._mainWindow.markBusy();
+            contact.geocode((function() {
+                this._mainWindow.unmarkBusy();
+                this._mainWindow.mapView.showContact(contact);
+            }).bind(this));
+        }).bind(this));
+    },
+
+    _onShowContactActivate: function(action, parameter) {
+        this._createWindow();
+        this._checkNetwork();
+        this._mainWindow.window.present();
+
+        let id = parameter.deep_unpack();
+
+        if (contactStore.state === Maps.ContactStoreState.LOADED) {
+            this. _showContact(id);
+        } else {
+            Utils.once(contactStore, 'notify::state', (function() {
+                if (contactStore.state === Maps.ContactStoreState.LOADED)
+                    this._showContact(id);
+            }).bind(this));
+        }
+    },
+
     _onQuitActivate: function() {
         this._mainWindow.window.destroy();
     },
@@ -126,7 +156,11 @@ const Application = new Lang.Class({
         this._initServices();
 
         Utils.addActions(this, {
-            'quit': { onActivate: this._onQuitActivate.bind(this) }
+            'quit': { onActivate: this._onQuitActivate.bind(this) },
+            'show-contact': {
+                paramType: 's',
+                onActivate: this._onShowContactActivate.bind(this)
+            }
         });
 
         this._initPlaceStore();
@@ -142,6 +176,8 @@ const Application = new Lang.Class({
         networkMonitor.connect('network-changed',
                                this._checkNetwork.bind(this));
         checkInManager = new CheckIn.CheckInManager();
+        contactStore = new Maps.ContactStore();
+        contactStore.load();
     },
 
     _createWindow: function() {
diff --git a/src/mapView.js b/src/mapView.js
index 46ecbea..1b58ef8 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -28,6 +28,7 @@ const GtkChamplain = imports.gi.GtkChamplain;
 const Lang = imports.lang;
 
 const Application = imports.application;
+const ContactPlace = imports.contactPlace;
 const Geoclue = imports.geoclue;
 const MapWalker = imports.mapWalker;
 const Place = imports.place;
@@ -216,6 +217,23 @@ const MapView = new Lang.Class({
         this._turnPointMarker.goToAndSelect(true);
     },
 
+    showContact: function(contact) {
+        let places = contact.get_places();
+        if (places.length === 0)
+            return;
+
+        this._placeLayer.remove_all();
+        places.forEach((function(p) {
+            let place = new ContactPlace.ContactPlace({ place: p,
+                                                        contact: contact });
+            let marker = new PlaceMarker.PlaceMarker({ place: place,
+                                                       mapView: this });
+            this._placeLayer.add_marker(marker);
+        }).bind(this));
+
+        this._gotoBBox(contact.bounding_box);
+    },
+
     showSearchResult: function(place) {
         this._placeLayer.remove_all();
         let placeMarker = new PlaceMarker.PlaceMarker({ place: place,


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