From 74173a734eb68b8270e4cd5ca2d82cb8fc6c4e69 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 6 Oct 2016 21:36:03 +0200 Subject: [PATCH] refs #768, fixed reverse lookup on login page (model changes in SIM are reflected here) * use reverse lookup function * complete model when web services have read the DB data (before that no reverse lookup is possible) * use new model changed signature Remark: Temp adjustement when signal allSwiftDbDataRead is sent. As soon #748 is ready needs to be changed to include airport entities --- src/blackcore/webdataservices.cpp | 5 ++-- src/blackcore/webdataservices.h | 2 +- src/blackgui/components/logincomponent.cpp | 33 +++++++++++++--------- src/blackgui/components/logincomponent.h | 6 ++-- src/blackgui/components/logincomponent.ui | 3 ++ src/blackmisc/network/entityflags.h | 5 ++-- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 62d03f345..fff5ad1a8 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -754,8 +754,9 @@ namespace BlackCore CLogMessage(cats).info("Read data %1 entries: %2 state: %3") << CEntityFlags::flagToString(entity) << number << CEntityFlags::flagToString(state); } - this->m_swiftDbEntitiesReaad |= entity; - if (this->m_swiftDbEntitiesReaad == CEntityFlags::AllDbEntitiesNoInfoObjects || this->m_swiftDbEntitiesReaad == CEntityFlags::AllDbEntities) + //! \todo adjust value when airports are ready + this->m_swiftDbEntitiesRead |= entity; + if (((static_cast(this->m_swiftDbEntitiesRead)) & static_cast(CEntityFlags::AllDbEntitiesNoInfoObjectsNoAirports)) > 0) { emit allSwiftDbDataRead(); } diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index a82dda3ef..24908ed41 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -381,7 +381,7 @@ namespace BlackCore CWebReaderFlags::WebReader m_readers = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data BlackMisc::Network::CEntityFlags::Entity m_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< those entities which are permanently updated by timers - BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesReaad = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read + BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read bool m_initialRead = false; //!< Initial read started int m_infoObjectTrials = 0; //!< Tried to read info objects diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 6ed4f0dfa..e85c73c72 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -132,6 +132,11 @@ namespace BlackGui connect(ui->le_AircraftIcaoDesignator, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues); connect(ui->tb_SimulatorIcaoReverseLookup, &QToolButton::clicked, this, &CLoginComponent::ps_reverseLookupModel); + if (sGui && sGui->getIContextSimulator()) + { + connect(sGui->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this, &CLoginComponent::ps_simulatorModelChanged); + } + // server GUI element ui->frp_CurrentServer->setReadOnly(true); ui->frp_CurrentServer->showPasswordField(false); @@ -176,7 +181,7 @@ namespace BlackGui else { this->m_visible = true; - bool isConnected = sGui->getIContextNetwork()->isConnected(); + const bool isConnected = sGui->getIContextNetwork()->isConnected(); this->setGuiVisibility(isConnected); this->setOkButtonString(isConnected); if (isConnected) { this->startLogoffTimerCountdown(); } @@ -198,7 +203,7 @@ namespace BlackGui CLogMessage(this).validationError("No login possible from this very tab, use VATSIM or other servers"); return; } - const bool isConnected = sGui->getIContextNetwork()->isConnected(); + const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected(); const bool vatsimLogin = (ui->tw_Network->currentWidget() == ui->pg_NetworkVatsim); CServer currentServer; // used for login CSimulatedAircraft ownAircraft; // used own aircraft @@ -335,15 +340,6 @@ namespace BlackGui } } - void CLoginComponent::setGuiValuesFromAircraft(const CSimulatedAircraft &ownAircraft) - { - const CAircraftIcaoCode aircraftIcao = ownAircraft.getAircraftIcaoCode(); - ui->le_Callsign->setText(ownAircraft.getCallsignAsString()); - ui->le_AircraftIcaoDesignator->setText(aircraftIcao.getDesignator()); - ui->le_AirlineIcaoDesignator->setText(ownAircraft.getAirlineIcaoCodeDesignator()); - ui->le_AircraftCombinedType->setText(aircraftIcao.getCombinedType()); - } - void CLoginComponent::loadRememberedVatsimData() { const CServer lastServer = this->m_currentVatsimServer.get(); @@ -465,6 +461,7 @@ namespace BlackGui void CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty) { + ui->le_SimulatorModel->setText(model.getModelStringAndDbKey()); if (!onlyIfEmpty || ui->le_AircraftIcaoDesignator->text().trimmed().isEmpty()) { ui->le_AircraftIcaoDesignator->setText(model.getAircraftIcaoCode().getDesignator()); @@ -544,11 +541,11 @@ namespace BlackGui void CLoginComponent::ps_reverseLookupModel() { if (!sGui->getIContextSimulator()->isSimulatorAvailable()) { return; } - CAircraftModel model(sGui->getIContextOwnAircraft()->getOwnAircraft().getModel()); - QString modelStr(model.hasModelString() ? model.getModelString() : ""); + const CAircraftModel model(sGui->getIContextOwnAircraft()->getOwnAircraft().getModel()); + const QString modelStr(model.hasModelString() ? model.getModelString() : ""); if (model.getAircraftIcaoCode().hasDesignator()) { - CLogMessage(this).validationInfo("Reverse lookup for '%1'") << modelStr; + CLogMessage(this).validationInfo("Reverse lookup for '%1' successful: %2") << modelStr << model.toQString(); // update GUI this->setGuiIcaoValues(model, false); @@ -559,6 +556,14 @@ namespace BlackGui } } + void CLoginComponent::ps_simulatorModelChanged(const CAircraftModel &model) + { + const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected(); + if (isConnected) { return; } + this->setGuiIcaoValues(model, false); + this->ps_reverseLookupModel(); + } + void CLoginComponent::initCompleters(CEntityFlags::Entity entity) { // completers where possible diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index ef8db7784..f68913e38 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -100,6 +100,9 @@ namespace BlackGui //! Reverse lookup model void ps_reverseLookupModel(); + //! Simulator model has been changed + void ps_simulatorModelChanged(const BlackMisc::Simulation::CAircraftModel &model); + private: //! GUI aircraft values, formatted struct CGuiAircraftValues @@ -120,9 +123,6 @@ namespace BlackGui QString vatsimHomeAirport; }; - //! GUI values from aircraft - void setGuiValuesFromAircraft(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); - //! Load from settings void loadRememberedVatsimData(); diff --git a/src/blackgui/components/logincomponent.ui b/src/blackgui/components/logincomponent.ui index fcb7b42e8..602f8aebf 100644 --- a/src/blackgui/components/logincomponent.ui +++ b/src/blackgui/components/logincomponent.ui @@ -448,6 +448,9 @@ true + + unique model identifier + diff --git a/src/blackmisc/network/entityflags.h b/src/blackmisc/network/entityflags.h index 8e7d489f5..f54907ecf 100644 --- a/src/blackmisc/network/entityflags.h +++ b/src/blackmisc/network/entityflags.h @@ -49,8 +49,9 @@ namespace BlackMisc AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, //!< all ICAO codes AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, //!< all ICAO codes and countries DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, //!< Combinded - AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | InfoObjectEntity | AirportEntity, //!< All DB stuff - AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel | AirportEntity //!< All DB entities, no info objects + AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | InfoObjectEntity | AirportEntity, //!< All DB stuff + AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel | AirportEntity, //!< All DB entities, no info objects + AllDbEntitiesNoInfoObjectsNoAirports = AllIcaoAndCountries | DistributorLiveryModel //!< All DB entities, no info objects and airports }; Q_DECLARE_FLAGS(Entity, EntityFlag)