Commit 5ef80c52 authored by Gus Grubba's avatar Gus Grubba

Move Esri and MapBox tokens to AppSettings.

parent c7a9943c
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
* @author Gus Grubba <mavlink@grubba.com> * @author Gus Grubba <mavlink@grubba.com>
* *
*/ */
#include "QGCApplication.h"
#include "AppSettings.h"
#include "SettingsManager.h"
#include <math.h> #include <math.h>
#include <QSettings> #include <QSettings>
...@@ -88,8 +91,6 @@ stQGeoTileCacheQGCMapTypes kEsriTypes[] = { ...@@ -88,8 +91,6 @@ stQGeoTileCacheQGCMapTypes kEsriTypes[] = {
#define NUM_ESRIMAPS (sizeof(kEsriTypes) / sizeof(stQGeoTileCacheQGCMapTypes)) #define NUM_ESRIMAPS (sizeof(kEsriTypes) / sizeof(stQGeoTileCacheQGCMapTypes))
static const char* kMapBoxTokenKey = "MapBoxToken";
static const char* kEsriTokenKey = "EsriToken";
static const char* kMaxDiskCacheKey = "MaxDiskCache"; static const char* kMaxDiskCacheKey = "MaxDiskCache";
static const char* kMaxMemCacheKey = "MaxMemoryCache"; static const char* kMaxMemCacheKey = "MaxMemoryCache";
...@@ -346,12 +347,12 @@ QGCMapEngine::getMapNameList() ...@@ -346,12 +347,12 @@ QGCMapEngine::getMapNameList()
for(size_t i = 0; i < NUM_MAPS; i++) { for(size_t i = 0; i < NUM_MAPS; i++) {
mapList << kMapTypes[i].name; mapList << kMapTypes[i].name;
} }
if(!getMapBoxToken().isEmpty()) { if(!qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString().isEmpty()) {
for(size_t i = 0; i < NUM_MAPBOXMAPS; i++) { for(size_t i = 0; i < NUM_MAPBOXMAPS; i++) {
mapList << kMapBoxTypes[i].name; mapList << kMapBoxTypes[i].name;
} }
} }
if(!getEsriToken().isEmpty()) { if(!qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().isEmpty()) {
for(size_t i = 0; i < NUM_ESRIMAPS; i++) { for(size_t i = 0; i < NUM_ESRIMAPS; i++) {
mapList << kEsriTypes[i].name; mapList << kEsriTypes[i].name;
} }
...@@ -359,46 +360,6 @@ QGCMapEngine::getMapNameList() ...@@ -359,46 +360,6 @@ QGCMapEngine::getMapNameList()
return mapList; return mapList;
} }
//-----------------------------------------------------------------------------
void
QGCMapEngine::setMapBoxToken(const QString& token)
{
QSettings settings;
settings.setValue(kMapBoxTokenKey, token);
_mapBoxToken = token;
}
//-----------------------------------------------------------------------------
void
QGCMapEngine::setEsriToken(const QString& token)
{
QSettings settings;
settings.setValue(kEsriTokenKey, token);
_esriToken = token;
}
//-----------------------------------------------------------------------------
QString
QGCMapEngine::getMapBoxToken()
{
if(_mapBoxToken.isEmpty()) {
QSettings settings;
_mapBoxToken = settings.value(kMapBoxTokenKey).toString();
}
return _mapBoxToken;
}
//-----------------------------------------------------------------------------
QString
QGCMapEngine::getEsriToken()
{
if(_esriToken.isEmpty()) {
QSettings settings;
_esriToken = settings.value(kEsriTokenKey).toString();
}
return _esriToken;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
quint32 quint32
QGCMapEngine::getMaxDiskCache() QGCMapEngine::getMaxDiskCache()
......
...@@ -78,10 +78,6 @@ public: ...@@ -78,10 +78,6 @@ public:
const QString userAgent () { return _userAgent; } const QString userAgent () { return _userAgent; }
void setUserAgent (const QString& ua) { _userAgent = ua; } void setUserAgent (const QString& ua) { _userAgent = ua; }
UrlFactory::MapType hashToType (const QString& hash); UrlFactory::MapType hashToType (const QString& hash);
QString getMapBoxToken ();
QString getEsriToken ();
void setMapBoxToken (const QString& token);
void setEsriToken (const QString& token);
quint32 getMaxDiskCache (); quint32 getMaxDiskCache ();
void setMaxDiskCache (quint32 size); void setMaxDiskCache (quint32 size);
quint32 getMaxMemCache (); quint32 getMaxMemCache ();
...@@ -121,8 +117,6 @@ private: ...@@ -121,8 +117,6 @@ private:
QGCCacheWorker _worker; QGCCacheWorker _worker;
QString _cachePath; QString _cachePath;
QString _cacheFile; QString _cacheFile;
QString _mapBoxToken;
QString _esriToken;
UrlFactory* _urlFactory; UrlFactory* _urlFactory;
QString _userAgent; QString _userAgent;
quint32 _maxDiskCache; quint32 _maxDiskCache;
......
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
//#define DEBUG_GOOGLE_MAPS //#define DEBUG_GOOGLE_MAPS
#include "QGCApplication.h"
#include "QGCMapEngine.h" #include "QGCMapEngine.h"
#include "AppSettings.h"
#include "SettingsManager.h"
#include <QRegExp> #include <QRegExp>
#include <QNetworkReply> #include <QNetworkReply>
...@@ -168,7 +171,7 @@ UrlFactory::getTileURL(MapType type, int x, int y, int zoom, QNetworkAccessManag ...@@ -168,7 +171,7 @@ UrlFactory::getTileURL(MapType type, int x, int y, int zoom, QNetworkAccessManag
case EsriWorldStreet: case EsriWorldStreet:
case EsriWorldSatellite: case EsriWorldSatellite:
case EsriTerrain: { case EsriTerrain: {
QByteArray token = getQGCMapEngine()->getEsriToken().toLatin1(); QByteArray token = qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1();
request.setRawHeader("User-Agent", QByteArrayLiteral("Qt Location based application")); request.setRawHeader("User-Agent", QByteArrayLiteral("Qt Location based application"));
request.setRawHeader("User-Token", token); request.setRawHeader("User-Token", token);
} }
...@@ -335,7 +338,7 @@ UrlFactory::_getURL(MapType type, int x, int y, int zoom, QNetworkAccessManager* ...@@ -335,7 +338,7 @@ UrlFactory::_getURL(MapType type, int x, int y, int zoom, QNetworkAccessManager*
case MapBoxEmerald: case MapBoxEmerald:
case MapBoxHighContrast: case MapBoxHighContrast:
{ {
QString mapBoxToken = getQGCMapEngine()->getMapBoxToken(); QString mapBoxToken = qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString();
if(!mapBoxToken.isEmpty()) { if(!mapBoxToken.isEmpty()) {
QString server = "https://api.mapbox.com/v4/"; QString server = "https://api.mapbox.com/v4/";
switch(type) { switch(type) {
......
...@@ -21,6 +21,8 @@ import QGroundControl.ScreenTools 1.0 ...@@ -21,6 +21,8 @@ import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.FlightMap 1.0 import QGroundControl.FlightMap 1.0
import QGroundControl.QGCMapEngineManager 1.0 import QGroundControl.QGCMapEngineManager 1.0
import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
QGCView { QGCView {
id: offlineMapView id: offlineMapView
...@@ -31,6 +33,9 @@ QGCView { ...@@ -31,6 +33,9 @@ QGCView {
property string mapKey: "lastMapType" property string mapKey: "lastMapType"
property Fact _mapboxFact: QGroundControl.settingsManager.appSettings.mapboxToken
property Fact _esriFact: QGroundControl.settingsManager.appSettings.esriToken
property string mapType: _settings.mapProvider.enumStringValue + " " + _settings.mapType.enumStringValue property string mapType: _settings.mapProvider.enumStringValue + " " + _settings.mapType.enumStringValue
property bool isMapInteractive: false property bool isMapInteractive: false
property var savedCenter: undefined property var savedCenter: undefined
...@@ -227,8 +232,6 @@ QGCView { ...@@ -227,8 +232,6 @@ QGCView {
id: optionDialog id: optionDialog
function accept() { function accept() {
QGroundControl.mapEngineManager.mapboxToken = mapBoxToken.text
QGroundControl.mapEngineManager.esriToken = esriToken.text
QGroundControl.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text) QGroundControl.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text)
QGroundControl.mapEngineManager.maxMemCache = parseInt(maxCacheMemSize.text) QGroundControl.mapEngineManager.maxMemCache = parseInt(maxCacheMemSize.text)
optionDialog.hideDialog() optionDialog.hideDialog()
...@@ -277,11 +280,10 @@ QGCView { ...@@ -277,11 +280,10 @@ QGCView {
QGCLabel { text: qsTr("MapBox Access Token") } QGCLabel { text: qsTr("MapBox Access Token") }
QGCTextField { FactTextField {
id: mapBoxToken fact: _mapboxFact
maximumLength: 256 maximumLength: 256
width: ScreenTools.defaultFontPixelWidth * 30 width: ScreenTools.defaultFontPixelWidth * 30
text: QGroundControl.mapEngineManager.mapboxToken
} }
QGCLabel { QGCLabel {
...@@ -293,11 +295,10 @@ QGCView { ...@@ -293,11 +295,10 @@ QGCView {
QGCLabel { text: qsTr("Esri Access Token") } QGCLabel { text: qsTr("Esri Access Token") }
QGCTextField { FactTextField {
id: esriToken fact: _esriFact
maximumLength: 256 maximumLength: 256
width: ScreenTools.defaultFontPixelWidth * 30 width: ScreenTools.defaultFontPixelWidth * 30
text: QGroundControl.mapEngineManager.esriToken
} }
QGCLabel { QGCLabel {
......
...@@ -195,34 +195,6 @@ QGCMapEngineManager::mapList() ...@@ -195,34 +195,6 @@ QGCMapEngineManager::mapList()
return getQGCMapEngine()->getMapNameList(); return getQGCMapEngine()->getMapNameList();
} }
//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::mapboxToken()
{
return getQGCMapEngine()->getMapBoxToken();
}
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::setMapboxToken(QString token)
{
getQGCMapEngine()->setMapBoxToken(token);
}
//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::esriToken()
{
return getQGCMapEngine()->getEsriToken();
}
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::setEsriToken(QString token)
{
getQGCMapEngine()->setEsriToken(token);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
quint32 quint32
QGCMapEngineManager::maxMemCache() QGCMapEngineManager::maxMemCache()
......
...@@ -47,8 +47,6 @@ public: ...@@ -47,8 +47,6 @@ public:
Q_PROPERTY(QString tileSizeStr READ tileSizeStr NOTIFY tileSizeChanged) Q_PROPERTY(QString tileSizeStr READ tileSizeStr NOTIFY tileSizeChanged)
Q_PROPERTY(QmlObjectListModel* tileSets READ tileSets NOTIFY tileSetsChanged) Q_PROPERTY(QmlObjectListModel* tileSets READ tileSets NOTIFY tileSetsChanged)
Q_PROPERTY(QStringList mapList READ mapList CONSTANT) Q_PROPERTY(QStringList mapList READ mapList CONSTANT)
Q_PROPERTY(QString mapboxToken READ mapboxToken WRITE setMapboxToken NOTIFY mapboxTokenChanged)
Q_PROPERTY(QString esriToken READ esriToken WRITE setEsriToken NOTIFY esriTokenChanged)
Q_PROPERTY(quint32 maxMemCache READ maxMemCache WRITE setMaxMemCache NOTIFY maxMemCacheChanged) Q_PROPERTY(quint32 maxMemCache READ maxMemCache WRITE setMaxMemCache NOTIFY maxMemCacheChanged)
Q_PROPERTY(quint32 maxDiskCache READ maxDiskCache WRITE setMaxDiskCache NOTIFY maxDiskCacheChanged) Q_PROPERTY(quint32 maxDiskCache READ maxDiskCache WRITE setMaxDiskCache NOTIFY maxDiskCacheChanged)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
...@@ -85,8 +83,6 @@ public: ...@@ -85,8 +83,6 @@ public:
quint64 tileSize () { return _totalSet.tileSize; } quint64 tileSize () { return _totalSet.tileSize; }
QString tileSizeStr (); QString tileSizeStr ();
QStringList mapList (); QStringList mapList ();
QString mapboxToken ();
QString esriToken ();
QmlObjectListModel* tileSets () { return &_tileSets; } QmlObjectListModel* tileSets () { return &_tileSets; }
quint32 maxMemCache (); quint32 maxMemCache ();
quint32 maxDiskCache (); quint32 maxDiskCache ();
...@@ -98,8 +94,6 @@ public: ...@@ -98,8 +94,6 @@ public:
ImportAction importAction () { return _importAction; } ImportAction importAction () { return _importAction; }
bool importReplace () { return _importReplace; } bool importReplace () { return _importReplace; }
void setMapboxToken (QString token);
void setEsriToken (QString token);
void setMaxMemCache (quint32 size); void setMaxMemCache (quint32 size);
void setMaxDiskCache (quint32 size); void setMaxDiskCache (quint32 size);
void setImportReplace (bool replace) { _importReplace = replace; emit importReplaceChanged(); } void setImportReplace (bool replace) { _importReplace = replace; emit importReplaceChanged(); }
...@@ -116,8 +110,6 @@ signals: ...@@ -116,8 +110,6 @@ signals:
void tileY1Changed (); void tileY1Changed ();
void tileCountChanged (); void tileCountChanged ();
void tileSizeChanged (); void tileSizeChanged ();
void mapboxTokenChanged ();
void esriTokenChanged ();
void tileSetsChanged (); void tileSetsChanged ();
void maxMemCacheChanged (); void maxMemCacheChanged ();
void maxDiskCacheChanged (); void maxDiskCacheChanged ();
......
...@@ -122,5 +122,19 @@ ...@@ -122,5 +122,19 @@
"longDescription": "Directory to which all data files are saved/loaded from", "longDescription": "Directory to which all data files are saved/loaded from",
"type": "string", "type": "string",
"defaultValue": "" "defaultValue": ""
},
{
"name": "MapBoxToken",
"shortDescription": "Access token to MapBox maps",
"longDescription": "Your personal access token for MapBox maps",
"type": "string",
"defaultValue": ""
},
{
"name": "EsriToken",
"shortDescription": "Access token to Esri maps",
"longDescription": "Your personal access token for Esri maps",
"type": "string",
"defaultValue": ""
} }
] ]
...@@ -31,6 +31,8 @@ const char* AppSettings::indoorPaletteName = "StyleIs ...@@ -31,6 +31,8 @@ const char* AppSettings::indoorPaletteName = "StyleIs
const char* AppSettings::showLargeCompassName = "ShowLargeCompass"; const char* AppSettings::showLargeCompassName = "ShowLargeCompass";
const char* AppSettings::savePathName = "SavePath"; const char* AppSettings::savePathName = "SavePath";
const char* AppSettings::autoLoadMissionsName = "AutoLoadMissions"; const char* AppSettings::autoLoadMissionsName = "AutoLoadMissions";
const char* AppSettings::mapboxTokenName = "MapBoxToken";
const char* AppSettings::esriTokenName = "EsriToken";
const char* AppSettings::parameterFileExtension = "params"; const char* AppSettings::parameterFileExtension = "params";
const char* AppSettings::planFileExtension = "plan"; const char* AppSettings::planFileExtension = "plan";
...@@ -61,6 +63,8 @@ AppSettings::AppSettings(QObject* parent) ...@@ -61,6 +63,8 @@ AppSettings::AppSettings(QObject* parent)
, _showLargeCompassFact(NULL) , _showLargeCompassFact(NULL)
, _savePathFact(NULL) , _savePathFact(NULL)
, _autoLoadMissionsFact(NULL) , _autoLoadMissionsFact(NULL)
, _mapboxTokenFact(NULL)
, _esriTokenFact(NULL)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only"); qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
...@@ -278,6 +282,24 @@ Fact* AppSettings::autoLoadMissions(void) ...@@ -278,6 +282,24 @@ Fact* AppSettings::autoLoadMissions(void)
return _autoLoadMissionsFact; return _autoLoadMissionsFact;
} }
Fact* AppSettings::mapboxToken(void)
{
if (!_mapboxTokenFact) {
_mapboxTokenFact = _createSettingsFact(mapboxTokenName);
}
return _mapboxTokenFact;
}
Fact* AppSettings::esriToken(void)
{
if (!_esriTokenFact) {
_esriTokenFact = _createSettingsFact(esriTokenName);
}
return _esriTokenFact;
}
MAV_AUTOPILOT AppSettings::offlineEditingFirmwareTypeFromFirmwareType(MAV_AUTOPILOT firmwareType) MAV_AUTOPILOT AppSettings::offlineEditingFirmwareTypeFromFirmwareType(MAV_AUTOPILOT firmwareType)
{ {
if (firmwareType != MAV_AUTOPILOT_PX4 && firmwareType != MAV_AUTOPILOT_ARDUPILOTMEGA) { if (firmwareType != MAV_AUTOPILOT_PX4 && firmwareType != MAV_AUTOPILOT_ARDUPILOTMEGA) {
......
...@@ -35,12 +35,14 @@ public: ...@@ -35,12 +35,14 @@ public:
Q_PROPERTY(Fact* showLargeCompass READ showLargeCompass CONSTANT) Q_PROPERTY(Fact* showLargeCompass READ showLargeCompass CONSTANT)
Q_PROPERTY(Fact* savePath READ savePath CONSTANT) Q_PROPERTY(Fact* savePath READ savePath CONSTANT)
Q_PROPERTY(Fact* autoLoadMissions READ autoLoadMissions CONSTANT) Q_PROPERTY(Fact* autoLoadMissions READ autoLoadMissions CONSTANT)
Q_PROPERTY(Fact* mapboxToken READ mapboxToken CONSTANT)
Q_PROPERTY(Fact* esriToken READ esriToken CONSTANT)
Q_PROPERTY(QString missionSavePath READ missionSavePath NOTIFY savePathsChanged) Q_PROPERTY(QString missionSavePath READ missionSavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString parameterSavePath READ parameterSavePath NOTIFY savePathsChanged) Q_PROPERTY(QString parameterSavePath READ parameterSavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString telemetrySavePath READ telemetrySavePath NOTIFY savePathsChanged) Q_PROPERTY(QString telemetrySavePath READ telemetrySavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString planFileExtension MEMBER planFileExtension CONSTANT) Q_PROPERTY(QString planFileExtension MEMBER planFileExtension CONSTANT)
Q_PROPERTY(QString missionFileExtension MEMBER missionFileExtension CONSTANT) Q_PROPERTY(QString missionFileExtension MEMBER missionFileExtension CONSTANT)
Q_PROPERTY(QString waypointsFileExtension MEMBER waypointsFileExtension CONSTANT) Q_PROPERTY(QString waypointsFileExtension MEMBER waypointsFileExtension CONSTANT)
Q_PROPERTY(QString parameterFileExtension MEMBER parameterFileExtension CONSTANT) Q_PROPERTY(QString parameterFileExtension MEMBER parameterFileExtension CONSTANT)
...@@ -61,6 +63,8 @@ public: ...@@ -61,6 +63,8 @@ public:
Fact* showLargeCompass (void); Fact* showLargeCompass (void);
Fact* savePath (void); Fact* savePath (void);
Fact* autoLoadMissions (void); Fact* autoLoadMissions (void);
Fact* mapboxToken (void);
Fact* esriToken (void);
QString missionSavePath (void); QString missionSavePath (void);
QString parameterSavePath (void); QString parameterSavePath (void);
...@@ -86,6 +90,8 @@ public: ...@@ -86,6 +90,8 @@ public:
static const char* showLargeCompassName; static const char* showLargeCompassName;
static const char* savePathName; static const char* savePathName;
static const char* autoLoadMissionsName; static const char* autoLoadMissionsName;
static const char* mapboxTokenName;
static const char* esriTokenName;
// Application wide file extensions // Application wide file extensions
static const char* parameterFileExtension; static const char* parameterFileExtension;
...@@ -124,6 +130,8 @@ private: ...@@ -124,6 +130,8 @@ private:
SettingsFact* _showLargeCompassFact; SettingsFact* _showLargeCompassFact;
SettingsFact* _savePathFact; SettingsFact* _savePathFact;
SettingsFact* _autoLoadMissionsFact; SettingsFact* _autoLoadMissionsFact;
SettingsFact* _mapboxTokenFact;
SettingsFact* _esriTokenFact;
}; };
#endif #endif
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
* *
****************************************************************************/ ****************************************************************************/
#include "QGCApplication.h"
#include "FlightMapSettings.h" #include "FlightMapSettings.h"
#include "QGCMapEngine.h" #include "QGCMapEngine.h"
#include "AppSettings.h"
#include "SettingsManager.h"
#include <QQmlEngine> #include <QQmlEngine>
#include <QtQml> #include <QtQml>
...@@ -34,10 +37,10 @@ FlightMapSettings::FlightMapSettings(QObject* parent) ...@@ -34,10 +37,10 @@ FlightMapSettings::FlightMapSettings(QObject* parent)
//-- Remove Google //-- Remove Google
_excludeProvider(mapProviderGoogle); _excludeProvider(mapProviderGoogle);
#endif #endif
if(getQGCMapEngine()->getMapBoxToken().isEmpty()) { if(qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString().isEmpty()) {
_excludeProvider(mapProviderMapBox); _excludeProvider(mapProviderMapBox);
} }
if(getQGCMapEngine()->getEsriToken().isEmpty()) { if(qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().isEmpty()) {
_excludeProvider(mapProviderEsri); _excludeProvider(mapProviderEsri);
} }
_newMapProvider(mapProvider()->rawValue()); _newMapProvider(mapProvider()->rawValue());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment