[gnome-maps/wip/contacts: 6/7] Add contact module



commit 93be58fba76fca07919916fcc98645e10bc7c3de
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Dec 16 04:47:34 2014 -0500

    Add contact module

 src/contact.js                  |   88 +++++++++++++++++++++++++++++++++++++++
 src/gnome-maps.js.gresource.xml |    1 +
 src/placeBubble.js              |    4 +-
 3 files changed, 92 insertions(+), 1 deletions(-)
---
diff --git a/src/contact.js b/src/contact.js
new file mode 100644
index 0000000..990ec53
--- /dev/null
+++ b/src/contact.js
@@ -0,0 +1,88 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Jonas Danielsson
+ *
+ * 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: Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const _ = imports.gettext.gettext;
+
+const Champlain = imports.gi.Champlain;
+const Geocode = imports.gi.GeocodeGlib;
+const Lang = imports.lang;
+
+const Place = imports.place;
+
+const ContactPlace = new Lang.Class({
+    Name: 'ContactPlace',
+    Extends: Place.Place,
+
+    _init: function(params) {
+        this._avatar = params.avatar;
+        delete params.avatar;
+
+        this.parent(params);
+    },
+
+    get icon() {
+        return this._avatar;
+    },
+
+    get isContact() {
+        return true;
+    }
+});
+
+const Contact = new Lang.Class({
+    Name: 'Contact',
+
+    _init: function(mapscContact) {
+        this._mapscContact = mapscContact;
+        this._places = [];
+        this._bbox = null;
+    },
+
+    get places() {
+        return this._places;
+    },
+
+    get bbox() {
+        return this._bbox;
+    },
+
+    get avatar() {
+        return this._mapscContact.icon;
+    },
+
+    geocode: function(callback) {
+        this._bbox = new Champlain.BoundingBox();
+        this._mapscContact.geocode((function () {
+            this._mapscContact.get_places().forEach((function(p) {
+                if (!p.location) {
+                    return;
+                }
+                this._bbox.extend(p.location.latitude, p.location.longitude);
+                let place = new ContactPlace({ place: p,
+                                               avatar: this.icon });
+                this._places.push(place);
+            }).bind(this));
+
+            callback(this._places);
+        }).bind(this));
+    }
+});
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index bd9654a..92149e4 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -7,6 +7,7 @@
     <file>checkIn.js</file>
     <file>checkInDialog.js</file>
     <file>config.js</file>
+    <file>contact.js</file>
     <file>contextMenu.js</file>
     <file>epaf.js</file>
     <file>favoritesPopover.js</file>
diff --git a/src/placeBubble.js b/src/placeBubble.js
index 8426a22..0efafcb 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -56,7 +56,9 @@ const PlaceBubble = new Lang.Class({
         this._title = ui.labelTitle;
         this._boxContent = ui.boxContent;
 
-        if (Application.placeStore.exists(this.place, null)) {
+        if (this.place.isContact) {
+            this._populate(this.place);
+        } else if (Application.placeStore.exists(this.place, null)) {
             let place = Application.placeStore.get(this.place);
             this._populate(place);
         } else {


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