Commit 95f49cc0 authored by Gus Grubba's avatar Gus Grubba

Make the choice of using a personal key persistent. This will allow to toggle...

Make the choice of using a personal key persistent. This will allow to toggle between personal and hardcoded key. Otherwise you would need to clear your personal key each time you want to use the hardcoded one.
parent 31e846fb
[
{
"name": "usePersonalApiKey",
"shortDescription": "Use Personal AirMap API Key",
"type": "bool",
"defaultValue": false
},
{
"name": "apiKey",
"shortDescription": "AirMap API Key",
......
......@@ -63,10 +63,11 @@ AirMapManager::setToolbox(QGCToolbox* toolbox)
{
AirspaceManager::setToolbox(toolbox);
AirMapSettings* ap = toolbox->settingsManager()->airMapSettings();
connect(ap->apiKey(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->clientID(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->userName(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->password(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->usePersonalApiKey(),&Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->apiKey(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->clientID(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->userName(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->password(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
_settingsChanged();
}
......@@ -94,9 +95,9 @@ AirMapManager::_settingsChanged()
settings.clientID = ap->clientID()->rawValueString();
settings.userName = ap->userName()->rawValueString();
settings.password = ap->password()->rawValueString();
//-- If we have a hardwired key (and no custom key), set it.
//-- If we have a hardwired key (and no custom key is present or enabled), set it.
#if defined(QGC_AIRMAP_KEY_AVAILABLE)
if(settings.apiKey.isEmpty() || settings.clientID.isEmpty()) {
if(!ap->usePersonalApiKey()->rawValue().toBool() && (settings.apiKey.isEmpty() || settings.clientID.isEmpty())) {
settings.apiKey = kAirmapAPIKey;
settings.clientID = kAirmapClientID;
}
......@@ -123,6 +124,10 @@ AirMapManager::_settingsChanged()
QString::fromStdString(result.error().message()), description);
}
});
} else {
if(settings.apiKey == "") {
qCDebug(AirMapManagerLog) << "No API key for AirMap";
}
}
}
......
......@@ -15,6 +15,7 @@
DECLARE_SETTINGGROUP(AirMap)
{
INIT_SETTINGFACT(usePersonalApiKey);
INIT_SETTINGFACT(apiKey);
INIT_SETTINGFACT(clientID);
INIT_SETTINGFACT(userName);
......@@ -25,6 +26,7 @@ DECLARE_SETTINGGROUP(AirMap)
qmlRegisterUncreatableType<AirMapSettings>("QGroundControl.SettingsManager", 1, 0, "AirMapSettings", "Reference only");
}
DECLARE_SETTINGSFACT(AirMapSettings, usePersonalApiKey)
DECLARE_SETTINGSFACT(AirMapSettings, apiKey)
DECLARE_SETTINGSFACT(AirMapSettings, clientID)
DECLARE_SETTINGSFACT(AirMapSettings, userName)
......
......@@ -19,6 +19,7 @@ public:
DEFINE_SETTINGGROUP(AirMap)
DEFINE_SETTINGFACT(usePersonalApiKey)
DEFINE_SETTINGFACT(apiKey)
DEFINE_SETTINGFACT(clientID)
DEFINE_SETTINGFACT(userName)
......
......@@ -230,10 +230,10 @@ QGCView {
QGCCheckBox {
id: hasPrivateKey
text: qsTr("Personal API Key")
onClicked: QGroundControl.settingsManager.airMapSettings.usePersonalApiKey = checked
Layout.columnSpan: 2
Component.onCompleted: {
if(QGroundControl.settingsManager.airMapSettings.apiKey !== "")
checked = true
checked = QGroundControl.settingsManager.airMapSettings.usePersonalApiKey
}
}
Item {
......
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