From 64dc16168cc6331f01ba45594644b8ffdb599f36 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 12 Aug 2018 03:13:33 +0200 Subject: [PATCH] Ref T301, login component can re-init and hence reconnect to core --- src/blackgui/components/logincomponent.cpp | 47 +++++++++++++++++----- src/blackgui/components/logincomponent.h | 23 +++++++---- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 5ee37c2ee..3566adc7d 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -48,6 +48,7 @@ #include #include #include +#include using namespace BlackConfig; using namespace BlackMisc; @@ -153,6 +154,13 @@ namespace BlackGui const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM; ui->tw_Network->setCurrentIndex(tab); + + QPointer myself(this); + QTimer::singleShot(5000, this, [ = ] + { + if (!myself) { return; } + this->updateGui(); + }); } CLoginComponent::~CLoginComponent() @@ -287,11 +295,7 @@ namespace BlackGui CLogMessage::preformatted(msg); if (msg.isSuccess()) { - QString ac(ownAircraft.getCallsignAsString() % QLatin1Char(' ') % ownAircraft.getAircraftIcaoCodeDesignator()); - if (ownAircraft.hasAirlineDesignator()) { ac += QLatin1Char(' ') % ownAircraft.getAirlineIcaoCodeDesignator(); } - if (!ownAircraft.getAircraftIcaoCombinedType().isEmpty()) { ac += QLatin1Char(' ') % ownAircraft.getAircraftIcaoCode().getCombinedType(); } - ui->le_LoginSince->setText(QDateTime::currentDateTimeUtc().toString()); - ui->le_LoginAsAircaft->setText(ac); + this->setGuiLoginAsValues(ownAircraft); emit this->loginOrLogoffSuccessful(); } else @@ -373,7 +377,7 @@ namespace BlackGui ui->editor_Pilot->setUser(server.getUser(), true); } - bool CLoginComponent::hasContexts() + bool CLoginComponent::hasValidContexts() { if (!sGui || !sGui->supportsContexts()) { return false; } if (sGui->isShuttingDown()) { return false; } @@ -433,7 +437,7 @@ namespace BlackGui void CLoginComponent::setOwnModelAndIcaoValues() { - if (!this->hasContexts()) { return; } + if (!this->hasValidContexts()) { return; } CAircraftModel model; const bool simulating = sGui->getIContextSimulator() && (sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); @@ -501,6 +505,15 @@ namespace BlackGui return valid ? changed : false; } + void CLoginComponent::setGuiLoginAsValues(const CSimulatedAircraft &ownAircraft) + { + QString ac(ownAircraft.getCallsignAsString() % QLatin1Char(' ') % ownAircraft.getAircraftIcaoCodeDesignator()); + if (ownAircraft.hasAirlineDesignator()) { ac += QLatin1Char(' ') % ownAircraft.getAirlineIcaoCodeDesignator(); } + if (!ownAircraft.getAircraftIcaoCombinedType().isEmpty()) { ac += QLatin1Char(' ') % ownAircraft.getAircraftIcaoCode().getCombinedType(); } + ui->le_LoginSince->setText(QDateTime::currentDateTimeUtc().toString()); + ui->le_LoginAsAircaft->setText(ac); + } + bool CLoginComponent::validateAircraftValues() { const CGuiAircraftValues values = this->getAircraftValuesFromGui(); @@ -673,7 +686,7 @@ namespace BlackGui bool CLoginComponent::updateOwnAircraftCallsignAndPilotFromGuiValues() { - if (!sGui || !sGui->getIContextOwnAircraft()) { return false; } + if (!this->hasValidContexts()) { return false; } CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft()); const QString cs(ui->le_Callsign->text().trimmed().toUpper()); bool changedCallsign = false; @@ -701,7 +714,7 @@ namespace BlackGui bool CLoginComponent::updateOwnAircaftIcaoValuesFromGuiValues() { - if (!sGui || !sGui->getIContextOwnAircraft()) { return false; } + if (!this->hasValidContexts()) { return false; } const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft()); const CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui(); @@ -727,5 +740,21 @@ namespace BlackGui return changedIcaoCodes; } + + void CLoginComponent::updateGui() + { + if (!this->hasValidContexts()) { return; } + IContextNetwork *nwc = sGui->getIContextNetwork(); + const bool connected = nwc->isConnected(); + if (!connected) { return; } + this->setUiLoginState(connected); + this->setOwnModelAndIcaoValues(); + const CServer server = nwc->getConnectedServer(); + ui->le_HomeBase->setText(server.getUser().getHomeBase().asString()); + ui->frp_CurrentServer->setServer(server); + ui->frp_LoginMode->setLoginMode(nwc->getLoginMode()); + const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); + this->setGuiLoginAsValues(ownAircraft); + } } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 92f412d5d..ada4204c5 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -115,12 +116,6 @@ namespace BlackGui //! Callsign from GUI BlackMisc::Aviation::CCallsign getCallsignFromGui() const; - //! Set ICAO values - //! \return changed values? - bool setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty); - - // -------------- values to GUI ----------------- - //! Update own callsign (own aircraft from what is set in the GUI) //! \return changed? bool updateOwnAircraftCallsignAndPilotFromGuiValues(); @@ -129,6 +124,18 @@ namespace BlackGui //! \return changed? bool updateOwnAircaftIcaoValuesFromGuiValues(); + // -------------- values to GUI ----------------- + + //! Update GUI values + void updateGui(); + + //! Set ICAO values + //! \return changed values? + bool setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty); + + //! Set the "login as" values + void setGuiLoginAsValues(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); + // -------------- others ----------------- //! Selected server (VATSIM) @@ -206,8 +213,8 @@ namespace BlackGui //! Tab widget (server) changed void onServerTabWidgetChanged(int index); - //! Has contexts - bool hasContexts(); + //! Has contexts? + bool hasValidContexts(); static const int OverlayMessageMs = 5000; QScopedPointer ui;