[gnome-maps] osmEdit: Add support for editing phone number



commit a0444406710c9ea8fec900fe6cad5a56ada3f9e8
Author: Marcus Lundblad <ml update uu se>
Date:   Sat Feb 6 14:26:20 2016 +0100

    osmEdit: Add support for editing phone number
    
    Adds the ability to edit phone numbers. Also reformat URIs using
    the tel: scheme by stripping off the leading tel: and trailing
    parameters (following a ”;”), which could be useful when copying
    links i.e. from a browser.
    Also add phone number to the information shown in the expanded area
    in the place bubble.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761636

 src/osmEditDialog.js |   16 ++++++++++++++++
 src/osmUtils.js      |    1 +
 src/overpass.js      |    2 ++
 src/place.js         |   12 ++++++++++++
 src/placeBubble.js   |   11 +++++++++++
 src/utils.js         |   17 +++++++++++++++++
 6 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
index 12977b1..15f5e44 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -60,6 +60,20 @@ let _osmWikipediaRewriteFunc = function(text) {
         return text;
 };
 
+/* Reformat a phone number string if it looks like a tel: URI
+ * strip off the leading tel: protocol string and trailing parameters,
+ * following a ;
+ * otherwise return the string unmodified */
+let _osmPhoneRewriteFunc = function(text) {
+    if (GLib.uri_parse_scheme(text) === 'tel') {
+        let afterTel = text.replace('tel:', '');
+
+        return afterTel.split(';')[0];
+    } else {
+        return text;
+    }
+};
+
 /*
  * specification of OSM edit fields
  * name: the label for the edit field (translatable)
@@ -70,6 +84,8 @@ let _osmWikipediaRewriteFunc = function(text) {
  */
 const OSM_FIELDS = [{name: _("Name"), tag: 'name', type: EditFieldType.TEXT},
             {name: _("Website"), tag: 'website', type: EditFieldType.TEXT},
+            {name: _("Phone"), tag: 'phone', type: EditFieldType.TEXT,
+             rewriteFunc: this._osmPhoneRewriteFunc},
             {name: _("Wikipedia"), tag: 'wikipedia', type: EditFieldType.TEXT,
              rewriteFunc: this._osmWikipediaRewriteFunc},
             {name: _("Population"), tag: 'population',
diff --git a/src/osmUtils.js b/src/osmUtils.js
index 5d5b471..01235aa 100644
--- a/src/osmUtils.js
+++ b/src/osmUtils.js
@@ -50,6 +50,7 @@ function updatePlaceFromOSMObject(place, object) {
     place.name = object.get_tag('name');
     place.population = object.get_tag('population');
     place.website = object.get_tag('website');
+    place.phone = object.get_tag('phone');
     place.wiki = object.get_tag('wikipedia');
     place.openingHours = object.get_tag('opening_hours');
     place.wheelchair = object.get_tag('wheelchair');
diff --git a/src/overpass.js b/src/overpass.js
index dd627c1..9ba86b4 100644
--- a/src/overpass.js
+++ b/src/overpass.js
@@ -96,6 +96,8 @@ const Overpass = new Lang.Class({
             place.population = element.tags.population;
         if (element.tags.website)
             place.website = element.tags.website;
+        if (element.tags.phone)
+            place.phone = element.tags.phone;
         if (element.tags.wikipedia)
             place.wiki = element.tags.wikipedia;
         if (element.tags.wheelchair)
diff --git a/src/place.js b/src/place.js
index 17546c9..a679694 100644
--- a/src/place.js
+++ b/src/place.js
@@ -39,6 +39,9 @@ const Place = new Lang.Class({
         this._website = params.website;
         delete params.website;
 
+        this._phone = params.phone;
+        delete params.phone;
+
         this._wiki = params.wiki;
         delete params.wiki;
 
@@ -111,6 +114,14 @@ const Place = new Lang.Class({
         return this._website;
     },
 
+    set phone(v) {
+        this._phone = v;
+    },
+
+    get phone() {
+        return this._phone;
+    },
+
     set wiki(v) {
         this._wiki = v;
     },
@@ -210,6 +221,7 @@ const Place = new Lang.Class({
                  continent: this.continent,
                  population: this.population,
                  website: this.website,
+                 phone: this.phone,
                  wiki: this.wiki,
                  wheelchair: this.wheelchair,
                  openingHours: this.openingHours };
diff --git a/src/placeBubble.js b/src/placeBubble.js
index afeccb1..010c8a2 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -149,6 +149,17 @@ const PlaceBubble = new Lang.Class({
                                    linkUrl: link});
         }
 
+        if (place.phone) {
+            if (Utils.uriSchemeSupported('tel')) {
+                expandedContent.push({ label: _("Phone:"),
+                                       linkText: place.phone,
+                                       linkUrl: 'tel:%s'.format(place.phone) });
+            } else {
+                expandedContent.push({ label: _("Phone:"),
+                                       info: place.phone });
+            }
+        }
+
         content.forEach((function(row) {
             let label = new Gtk.Label({ label: row,
                                         visible: true,
diff --git a/src/utils.js b/src/utils.js
index 9ace1e2..385fec8 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -363,3 +363,20 @@ function prettyDistance(distance) {
             return _("%f ft").format(distance);
     }
 }
+
+function uriSchemeSupported(scheme) {
+    let apps = Gio.AppInfo.get_all();
+    let prefix = 'x-scheme-handler/';
+
+    for (let i in apps) {
+        let types = apps[i].get_supported_types();
+        if (!types)
+            continue;
+
+        for (let j in types) {
+            if (types[j].replace(prefix, '') === scheme)
+                return true;
+        }
+    }
+    return false;
+}


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