[gnome-maps/wip/contacts: 7/7] Add 'show-contact' action



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

    Add 'show-contact' action

 src/application.js |   40 +++++++++++++++++++++++++++++++++++++++-
 src/mapView.js     |   14 ++++++++++++++
 2 files changed, 53 insertions(+), 1 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0cd1506..e2c8c80 100644
--- a/src/application.js
+++ b/src/application.js
@@ -31,10 +31,12 @@ const Lang = imports.lang;
 const _ = imports.gettext.gettext;
 
 const CheckIn = imports.checkIn;
+const Contact = imports.contact;
 const Format = imports.format;
 const Geoclue = imports.geoclue;
 const GeocodeService = imports.geocodeService;
 const MainWindow = imports.mainWindow;
+const MapsC = imports.gi.MapsC;
 const NotificationManager = imports.notificationManager;
 const Path = imports.path;
 const PlaceStore = imports.placeStore;
@@ -52,6 +54,7 @@ let geoclue = null;
 let geocodeService = null;
 let networkMonitor = null;
 let checkInManager = null;
+let contacts = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -99,6 +102,35 @@ const Application = new Lang.Class({
         }).bind(this));
     },
 
+    _showContact: function(id) {
+        contacts.lookup(id, (function(mapscContact) {
+            let contact = new Contact.Contact(mapscContact);
+
+            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 (contacts.state === MapsC.ContactsState.LOADED) {
+            this. _showContact(id);
+        } else {
+            Utils.once(contacts, 'notify::state', (function() {
+                if (contacts.state === MapsC.ContactsState.LOADED)
+                    this._showContact(id);
+            }).bind(this));
+        }
+    },
+
     _onQuitActivate: function() {
         this._mainWindow.window.destroy();
     },
@@ -133,7 +165,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();
@@ -149,6 +185,8 @@ const Application = new Lang.Class({
         networkMonitor.connect('network-changed',
                                this._checkNetwork.bind(this));
         checkInManager = new CheckIn.CheckInManager();
+        contacts = new MapsC.Contacts();
+        contacts.load();
     },
 
     _createWindow: function() {
diff --git a/src/mapView.js b/src/mapView.js
index c92bd4c..8e5f76b 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -205,6 +205,20 @@ const MapView = new Lang.Class({
         this._turnPointMarker.goToAndSelect(true);
     },
 
+    showContact: function(contact) {
+        if (contact.places.length == 0)
+            return;
+
+        this._placeLayer.remove_all();
+        contact.places.forEach((function(place) {
+            let marker = new PlaceMarker.PlaceMarker({ place: place,
+                                                       mapView: this });
+            this._placeLayer.add_marker(marker);
+        }).bind(this));
+
+        this._gotoBBox(contact.bbox);
+    },
+
     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]