diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-10-18 10:19:24 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-10-19 10:04:28 +0000 |
commit | 6a4be78bfc0f0c51b3394a70adf76a14d45639b6 (patch) | |
tree | ef432c8a6cdaa1d5d56ae1769745e6eec1e091b3 /examples/location | |
parent | a63ee3d4b8d6760c344fa8b61e0cd48f9077c4b9 (diff) | |
download | qtlocation-6a4be78bfc0f0c51b3394a70adf76a14d45639b6.tar.gz |
Make mapviewer and places examples fetch tokens from the environment
Add the ability in these two examples who let the user switch provider
at runtime to fetch the tokens from environment variables.
This makes it easier to test them without having to modify the code or
to always run them with command line parameters
Change-Id: I6469414ed70522bbf3481b73e1e43a82d18302c5
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'examples/location')
-rw-r--r-- | examples/location/mapviewer/main.cpp | 18 | ||||
-rw-r--r-- | examples/location/places/main.cpp | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/examples/location/mapviewer/main.cpp b/examples/location/mapviewer/main.cpp index 1b526435..a58dcd44 100644 --- a/examples/location/mapviewer/main.cpp +++ b/examples/location/mapviewer/main.cpp @@ -89,6 +89,24 @@ int main(int argc, char *argv[]) QVariantMap parameters; QStringList args(QCoreApplication::arguments()); + // Fetch tokens from the environment, if present + const QByteArray mapboxMapID = qgetenv("MAPBOX_MAP_ID"); + const QByteArray mapboxAccessToken = qgetenv("MAPBOX_ACCESS_TOKEN"); + const QByteArray hereAppID = qgetenv("HERE_APP_ID"); + const QByteArray hereToken = qgetenv("HERE_TOKEN"); + const QByteArray esriToken = qgetenv("ESRI_TOKEN"); + + if (!mapboxMapID.isEmpty()) + parameters["mapbox.map_id"] = QString::fromLocal8Bit(mapboxMapID); + if (!mapboxAccessToken.isEmpty()) + parameters["mapbox.access_token"] = QString::fromLocal8Bit(mapboxAccessToken); + if (!hereAppID.isEmpty()) + parameters["here.app_id"] = QString::fromLocal8Bit(hereAppID); + if (!hereToken.isEmpty()) + parameters["here.token"] = QString::fromLocal8Bit(hereToken); + if (!esriToken.isEmpty()) + parameters["esri.token"] = QString::fromLocal8Bit(esriToken); + if (parseArgs(args, parameters)) return 0; if (!args.contains(QStringLiteral("osm.useragent"))) diff --git a/examples/location/places/main.cpp b/examples/location/places/main.cpp index 8c3b64ed..a30fb857 100644 --- a/examples/location/places/main.cpp +++ b/examples/location/places/main.cpp @@ -90,6 +90,24 @@ int main(int argc, char *argv[]) QVariantMap parameters; QStringList args(QCoreApplication::arguments()); + // Fetch tokens from the environment, if present + const QByteArray mapboxMapID = qgetenv("MAPBOX_MAP_ID"); + const QByteArray mapboxAccessToken = qgetenv("MAPBOX_ACCESS_TOKEN"); + const QByteArray hereAppID = qgetenv("HERE_APP_ID"); + const QByteArray hereToken = qgetenv("HERE_TOKEN"); + const QByteArray esriToken = qgetenv("ESRI_TOKEN"); + + if (!mapboxMapID.isEmpty()) + parameters["mapbox.map_id"] = QString::fromLocal8Bit(mapboxMapID); + if (!mapboxAccessToken.isEmpty()) + parameters["mapbox.access_token"] = QString::fromLocal8Bit(mapboxAccessToken); + if (!hereAppID.isEmpty()) + parameters["here.app_id"] = QString::fromLocal8Bit(hereAppID); + if (!hereToken.isEmpty()) + parameters["here.token"] = QString::fromLocal8Bit(hereToken); + if (!esriToken.isEmpty()) + parameters["esri.token"] = QString::fromLocal8Bit(esriToken); + if (parseArgs(args, parameters)) return 0; |