[gnome-maps] mainWindow: Show OSM and tile provider credits



commit a3c7609db2edd2ad6ace82034f3b800457bdcb60
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Nov 20 22:34:53 2017 +0100

    mainWindow: Show OSM and tile provider credits
    
    Always show OpenStreetMap credits in the About dialog.
    Show tile provider credits dynamically based on definition
    from the service file.
    This is done in a somewhat hackish way, since currently
    GtkAboutDialog doesn't natively support markup in the copyright
    string, solution borrowed from Weather.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752253

 src/mainWindow.js |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index f9b80d5..cb9ca58 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -39,6 +39,7 @@ const MapView = imports.mapView;
 const PlaceEntry = imports.placeEntry;
 const PlaceStore = imports.placeStore;
 const PrintOperation = imports.printOperation;
+const Service = imports.service;
 const ShapeLayer = imports.shapeLayer;
 const Sidebar = imports.sidebar;
 const Utils = imports.utils;
@@ -493,7 +494,6 @@ var MainWindow = new Lang.Class({
             /* Translators: This is the program name. */
             program_name: _("Maps"),
             comments: _("A map application for GNOME"),
-            copyright: _("Copyright © 2011 – 2017 Red Hat, Inc. and The GNOME Maps authors"),
             license_type: Gtk.License.GPL_2_0,
             logo_icon_name: 'org.gnome.Maps',
             version: pkg.version,
@@ -503,12 +503,50 @@ var MainWindow = new Lang.Class({
             modal: true,
             transient_for: this
         });
+
+        let copyright = _("Copyright © 2011 – 2017 Red Hat, Inc. and The GNOME Maps authors");
+        let attribution = this._getAttribution();
+
+        copyright += '\n' + attribution;
+
+        /* HACK: we need to poke into gtkaboutdialog internals
+         * to set the copyright with markup like attribution requires
+         */
+
+        let copyrightLabel = aboutDialog.get_template_child(Gtk.AboutDialog, 'copyright_label');
+        copyrightLabel.set_markup('<span size="small">' + copyright + '</span>');
+        copyrightLabel.show();
+
         aboutDialog.show();
         aboutDialog.connect('response', (function() {
             aboutDialog.destroy();
         }));
     },
 
+    _getAttribution: function() {
+        let tileProviderInfo = Service.getService().tileProviderInfo;
+        let attribution = _("Map data by %s and contributors").format('<a 
href="https://www.openstreetmap.org";>OpenStreetMap</a>');
+
+        if (tileProviderInfo) {
+            let tileProviderString;
+            if (tileProviderInfo.url) {
+                tileProviderString = '<a href="' + tileProviderInfo.url + '">' +
+                                     tileProviderInfo.name + '</a>';
+            } else {
+                tileProviderString = tileProviderInfo.name;
+            }
+            attribution += '\n';
+            /* Translators: this is an attribution string giving credit to the
+             * tile provider where the %s placeholder is replaced by either
+             * the bare name of the tile provider, or a linkified URL if one
+             * is available
+             */
+            attribution += _("Map tiles provided by %s").format(tileProviderString);
+        }
+
+        return attribution;
+    },
+
     _onOpenShapeLayer: function() {
         let fileChooser = new ShapeLayerFileChooser({
             transient_for: this,


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