Commit 3779f0e3 authored by Gus Grubba's avatar Gus Grubba

Test authentication as soon as the user adds/changes user name and/or password.

parent 7aecf62b
...@@ -63,6 +63,7 @@ AirMapManager::~AirMapManager() ...@@ -63,6 +63,7 @@ AirMapManager::~AirMapManager()
void void
AirMapManager::setToolbox(QGCToolbox* toolbox) AirMapManager::setToolbox(QGCToolbox* toolbox)
{ {
_settingsTimer.setSingleShot(true);
AirspaceManager::setToolbox(toolbox); AirspaceManager::setToolbox(toolbox);
AirMapSettings* ap = toolbox->settingsManager()->airMapSettings(); AirMapSettings* ap = toolbox->settingsManager()->airMapSettings();
connect(ap->enableAirMap(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged); connect(ap->enableAirMap(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
...@@ -71,7 +72,8 @@ AirMapManager::setToolbox(QGCToolbox* toolbox) ...@@ -71,7 +72,8 @@ AirMapManager::setToolbox(QGCToolbox* toolbox)
connect(ap->clientID(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged); connect(ap->clientID(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->userName(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged); connect(ap->userName(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
connect(ap->password(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged); connect(ap->password(), &Fact::rawValueChanged, this, &AirMapManager::_settingsChanged);
_settingsChanged(); connect(&_settingsTimer, &QTimer::timeout, this, &AirMapManager::_settingsTimeout);
_settingsTimeout();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -100,6 +102,13 @@ AirMapManager::_authStatusChanged(AirspaceManager::AuthStatus status) ...@@ -100,6 +102,13 @@ AirMapManager::_authStatusChanged(AirspaceManager::AuthStatus status)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapManager::_settingsChanged() AirMapManager::_settingsChanged()
{
_settingsTimer.start(1000);
}
//-----------------------------------------------------------------------------
void
AirMapManager::_settingsTimeout()
{ {
qCDebug(AirMapManagerLog) << "AirMap settings changed"; qCDebug(AirMapManagerLog) << "AirMap settings changed";
_connectStatus.clear(); _connectStatus.clear();
...@@ -156,6 +165,8 @@ AirMapManager::_settingsChanged() ...@@ -156,6 +165,8 @@ AirMapManager::_settingsChanged()
emit connectedChanged(); emit connectedChanged();
_connectStatus = tr("AirMap Enabled"); _connectStatus = tr("AirMap Enabled");
emit connectStatusChanged(); emit connectStatusChanged();
//-- Now test authentication
_shared.login();
} else { } else {
qWarning("Failed to create airmap::qt::Client instance"); qWarning("Failed to create airmap::qt::Client instance");
QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : ""); QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
......
...@@ -55,10 +55,12 @@ protected: ...@@ -55,10 +55,12 @@ protected:
private slots: private slots:
void _error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); void _error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
void _settingsChanged (); void _settingsChanged ();
void _settingsTimeout ();
void _authStatusChanged (AirspaceManager::AuthStatus status); void _authStatusChanged (AirspaceManager::AuthStatus status);
private: private:
QString _connectStatus; QString _connectStatus;
QTimer _settingsTimer;
AirMapSharedState _shared; AirMapSharedState _shared;
std::shared_ptr<airmap::qt::Logger> _logger; std::shared_ptr<airmap::qt::Logger> _logger;
std::shared_ptr<airmap::qt::DispatchingLogger> _dispatchingLogger; std::shared_ptr<airmap::qt::DispatchingLogger> _dispatchingLogger;
......
...@@ -76,7 +76,7 @@ AirMapSharedState::login() ...@@ -76,7 +76,7 @@ AirMapSharedState::login()
if (result) { if (result) {
qCDebug(AirMapManagerLog) << "Successfully authenticated with AirMap: id="<< result.value().id.c_str()<<", access=" qCDebug(AirMapManagerLog) << "Successfully authenticated with AirMap: id="<< result.value().id.c_str()<<", access="
<<result.value().access.c_str(); <<result.value().access.c_str();
emit authStatus(AirspaceManager::AuthStatus::Autheticated); emit authStatus(AirspaceManager::AuthStatus::Authenticated);
_loginToken = QString::fromStdString(result.value().id); _loginToken = QString::fromStdString(result.value().id);
_processPendingRequests(); _processPendingRequests();
} else { } else {
......
...@@ -209,10 +209,10 @@ QGCView { ...@@ -209,10 +209,10 @@ QGCView {
return qsTr("") return qsTr("")
case AirspaceManager.Anonymous: case AirspaceManager.Anonymous:
return qsTr("Anonymous") return qsTr("Anonymous")
case AirspaceManager.Autheticated: case AirspaceManager.Authenticated:
return qsTr("Autheticated") return qsTr("Authenticated")
default: default:
return qsTr("Authetication Error") return qsTr("Authentication Error")
} }
} }
Layout.rowSpan: 2 Layout.rowSpan: 2
......
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
enum AuthStatus { enum AuthStatus {
Unknown, Unknown,
Anonymous, Anonymous,
Autheticated, Authenticated,
Error Error
}; };
......
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