From 6322c6d3025e9085aea7c48bdf6802d595dc9efd Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 17 Oct 2016 03:28:21 +0200 Subject: [PATCH] refs #768, login component * opens wizard when a model is unknown * now uses new completers --- src/blackgui/components/logincomponent.cpp | 195 ++++++++------ src/blackgui/components/logincomponent.h | 39 ++- src/blackgui/components/logincomponent.ui | 284 ++++++++++++--------- 3 files changed, 305 insertions(+), 213 deletions(-) diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 9a944e74e..d2ca89885 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -16,9 +16,10 @@ #include "blackcore/data/globalsetup.h" #include "blackcore/network.h" #include "blackcore/simulator.h" -#include "blackgui/components/logincomponent.h" +#include "logincomponent.h" +#include "serverlistselector.h" +#include "dbquickmappingwizard.h" #include "blackgui/editors/serverform.h" -#include "blackgui/components/serverlistselector.h" #include "blackgui/guiapplication.h" #include "blackgui/loginmodebuttons.h" #include "blackgui/ticklabel.h" @@ -79,19 +80,23 @@ namespace BlackGui ui->pb_LogoffTimeout->setValue(LogoffIntervalSeconds); connect(this->m_logoffCountdownTimer, &QTimer::timeout, this, &CLoginComponent::ps_logoffCountdown); + ui->selector_AircraftIcao->displayWithIcaoDescription(false); + ui->selector_AirlineIcao->displayWithIcaoDescription(false); + ui->selector_AircraftIcao->displayMode(CDbAircraftIcaoSelectorComponent::DisplayIcaoAndId); + ui->selector_AirlineIcao->displayMode(CDbAirlineIcaoSelectorComponent::DisplayVDesignatorAndId); + setOkButtonString(false); connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CLoginComponent::ps_loginCancelled); connect(ui->bb_OkCancel, &QDialogButtonBox::accepted, this, &CLoginComponent::ps_toggleNetworkConnection); connect(ui->pb_OtherServersGotoSettings, &QPushButton::pressed, this, &CLoginComponent::requestNetworkSettings); + connect(ui->tb_MappingWizard, &QToolButton::clicked, this, &CLoginComponent::ps_mappingWizard); ui->comp_FsdDetails->showEnableInfo(true); ui->comp_FsdDetails->setFsdSetupEnabled(false); - ui->lblp_SimulatorModel->setToolTips("available", "unavailable"); - ui->lblp_SimulatorModel->setPixmapUnticked(CIcons::empty()); ui->lblp_AircraftCombinedType->setToolTips("ok", "wrong"); - ui->lblp_AircraftIcaoAirline->setToolTips("ok", "wrong"); - ui->lblp_AircraftIcaoDesignator->setToolTips("ok", "wrong"); + ui->lblp_AirlineIcao->setToolTips("ok", "wrong"); + ui->lblp_AircraftIcao->setToolTips("ok", "wrong"); ui->lblp_Callsign->setToolTips("ok", "wrong"); ui->lblp_VatsimHomeAirport->setToolTips("ok", "wrong"); ui->lblp_VatsimId->setToolTips("ok", "wrong"); @@ -122,15 +127,9 @@ namespace BlackGui ui->le_AircraftCombinedType->setMaxLength(3); ui->le_AircraftCombinedType->setValidator(new CUpperCaseValidator(this)); connect(ui->le_AircraftCombinedType, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues); - - ui->le_AirlineIcaoDesignator->setMaxLength(5); - ui->le_AirlineIcaoDesignator->setValidator(new CUpperCaseValidator(this)); - connect(ui->le_AirlineIcaoDesignator, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues); - - ui->le_AircraftIcaoDesignator->setMaxLength(5); - ui->le_AircraftIcaoDesignator->setValidator(new CUpperCaseValidator(this)); - connect(ui->le_AircraftIcaoDesignator, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues); - connect(ui->tb_SimulatorIcaoReverseLookup, &QToolButton::clicked, this, &CLoginComponent::ps_reverseLookupModel); + connect(ui->selector_AircraftIcao, &CDbAircraftIcaoSelectorComponent::changedAircraftIcao, this, &CLoginComponent::ps_changedAircraftIcao); + connect(ui->selector_AirlineIcao, &CDbAirlineIcaoSelectorComponent::changedAirlineIcao, this, &CLoginComponent::ps_changedAirlineIcao); + connect(ui->tb_SimulatorIcaoReverseLookup, &QToolButton::clicked, this, &CLoginComponent::ps_reverseLookupAircraftIcaoData); if (sGui && sGui->getIContextSimulator()) { @@ -156,6 +155,12 @@ namespace BlackGui CLogMessage(this).info("Added servers for testing"); } ui->comp_OtherServers->setServers(otherServers); + + // init completers if data are already available + if (sGui && sGui->hasWebDataServices()) + { + this->initCompleters(CEntityFlags::AircraftIcaoEntity | CEntityFlags::AirlineIcaoEntity | CEntityFlags::AirportEntity); + } } CLoginComponent::~CLoginComponent() @@ -229,18 +234,18 @@ namespace BlackGui CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode()); bool setIcaoCodes = false; - if (!ownAircraft.hasAircraftDesignator() && !aircraftValues.ownAircraftIcaoTypeDesignator.isEmpty()) + if (!ownAircraft.hasAircraftDesignator() && aircraftValues.ownAircraftIcao.hasValidDesignator()) { - aircraftCode = CAircraftIcaoCode(aircraftValues.ownAircraftIcaoTypeDesignator, aircraftValues.ownAircraftCombinedType); + aircraftCode = aircraftValues.ownAircraftIcao; setIcaoCodes = true; } - if (!ownAircraft.hasAircraftDesignator() && !aircraftValues.ownAircraftIcaoAirline.isEmpty()) + if (!ownAircraft.hasAircraftDesignator() && aircraftValues.ownAirlineIcao.hasValidDesignator()) { - airlineCode = CAirlineIcaoCode(aircraftValues.ownAircraftIcaoAirline); + airlineCode = aircraftValues.ownAirlineIcao; setIcaoCodes = true; } - if (ownAircraft.getCallsign().asString() != aircraftValues.ownCallsign) + if (ownAircraft.getCallsign() != aircraftValues.ownCallsign) { ownAircraft.setCallsign(aircraftValues.ownCallsign); sGui->getIContextOwnAircraft()->updateOwnCallsign(ownAircraft.getCallsign()); @@ -366,9 +371,9 @@ namespace BlackGui CLoginComponent::CGuiAircraftValues CLoginComponent::getAircraftValuesFromGui() const { CGuiAircraftValues values; - values.ownCallsign = ui->le_Callsign->text().trimmed().toUpper(); - values.ownAircraftIcaoTypeDesignator = CAircraftIcaoCode::normalizeDesignator(ui->le_AircraftIcaoDesignator->text()); - values.ownAircraftIcaoAirline = CAirlineIcaoCode::normalizeDesignator(ui->le_AirlineIcaoDesignator->text()); + values.ownCallsign = CCallsign(ui->le_Callsign->text().trimmed().toUpper()); + values.ownAircraftIcao = ui->selector_AircraftIcao->getAircraftIcao(); + values.ownAirlineIcao = ui->selector_AirlineIcao->getAirlineIcao(); values.ownAircraftCombinedType = ui->le_AircraftCombinedType->text().trimmed().toUpper(); values.ownAircraftSimulatorModel = ui->le_SimulatorModel->text().trimmed().toUpper(); return values; @@ -440,7 +445,8 @@ namespace BlackGui if (simulating) { model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel(); - ui->le_SimulatorModel->setText(model.getModelString()); + ui->le_SimulatorModel->setText(model.getModelStringAndDbKey()); + this->highlightModelField(model); } else { @@ -450,7 +456,8 @@ namespace BlackGui model = this->m_currentAircraftModel.get(); if (!model.hasAircraftDesignator()) { model = defaultModel; } ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); //! \todo Set observer mode without simulator, currently not working in OBS mode - ui->le_SimulatorModel->setText("No simulator"); + ui->le_SimulatorModel->setText(""); + this->highlightModelField(); } if (model.hasAircraftDesignator()) @@ -462,13 +469,13 @@ namespace BlackGui void CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty) { ui->le_SimulatorModel->setText(model.getModelStringAndDbKey()); - if (!onlyIfEmpty || ui->le_AircraftIcaoDesignator->text().trimmed().isEmpty()) + if (!onlyIfEmpty || !ui->selector_AircraftIcao->isSet()) { - ui->le_AircraftIcaoDesignator->setText(model.getAircraftIcaoCode().getDesignator()); + ui->selector_AircraftIcao->setAircraftIcao(model.getAircraftIcaoCode()); } - if (!onlyIfEmpty || ui->le_AirlineIcaoDesignator->text().trimmed().isEmpty()) + if (!onlyIfEmpty || !ui->selector_AirlineIcao->isSet()) { - ui->le_AirlineIcaoDesignator->setText(model.getAirlineIcaoCode().getDesignator()); + ui->selector_AirlineIcao->setAirlineIcao(model.getAirlineIcaoCode()); } if (!onlyIfEmpty || ui->le_AircraftCombinedType->text().trimmed().isEmpty()) { @@ -484,20 +491,17 @@ namespace BlackGui const bool validCombinedType = CAircraftIcaoCode::isValidCombinedType(values.ownAircraftCombinedType); ui->lblp_AircraftCombinedType->setTicked(validCombinedType); - const bool validAirlineDesignator = values.ownAircraftIcaoAirline.isEmpty() || CAircraftIcaoCode::isValidDesignator(values.ownAircraftIcaoAirline); - ui->lblp_AircraftIcaoAirline->setTicked(validAirlineDesignator); + const bool validAirlineDesignator = values.ownAirlineIcao.hasValidDesignator(); + ui->lblp_AirlineIcao->setTicked(validAirlineDesignator); - const bool validIcaoDesignator = CAircraftIcaoCode::isValidDesignator(values.ownAircraftIcaoTypeDesignator); - ui->lblp_AircraftIcaoDesignator->setTicked(validIcaoDesignator); + const bool validAircraftDesignator = values.ownAircraftIcao.hasValidDesignator(); + ui->lblp_AircraftIcao->setTicked(validAircraftDesignator); const bool validCallsign = CCallsign::isValidAircraftCallsign(values.ownCallsign); ui->lblp_Callsign->setTicked(validCallsign); - const bool validSimulatorModel = !values.ownAircraftSimulatorModel.isEmpty(); - ui->lblp_SimulatorModel->setTicked(validSimulatorModel); - // model intentionally ignored - return validCombinedType && validAirlineDesignator && validIcaoDesignator && validCallsign; + return validCombinedType && validAirlineDesignator && validAircraftDesignator && validCallsign; } bool CLoginComponent::ps_validateVatsimValues() @@ -519,6 +523,21 @@ namespace BlackGui return validVatsimId && validHomeAirport && validVatsimPassword && validRealUserName; } + void CLoginComponent::ps_changedAircraftIcao(const CAircraftIcaoCode &icao) + { + if (icao.isLoadedFromDb()) + { + ui->le_AircraftCombinedType->setText(icao.getCombinedType()); + } + this->ps_validateAircraftValues(); + } + + void CLoginComponent::ps_changedAirlineIcao(const CAirlineIcaoCode &icao) + { + Q_UNUSED(icao); + this->ps_validateAircraftValues(); + } + void CLoginComponent::ps_reloadSettings() { CServerList otherServers(this->m_otherTrafficNetworkServers.getThreadLocal()); @@ -538,67 +557,62 @@ namespace BlackGui } } - void CLoginComponent::ps_reverseLookupModel() + void CLoginComponent::ps_reverseLookupAircraftIcaoData() { if (!sGui->getIContextSimulator()->isSimulatorAvailable()) { return; } 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' successful: %2") << modelStr << model.toQString(); - - // update GUI - this->setGuiIcaoValues(model, false); - } - else - { - CLogMessage(this).validationInfo("Reverse lookup for '%1'' failed, set data manually") << modelStr; - } + this->ps_simulatorModelChanged(model); } void CLoginComponent::ps_simulatorModelChanged(const CAircraftModel &model) { const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected(); if (isConnected) { return; } + const QString modelStr(model.hasModelString() ? model.getModelString() : ""); + if (!model.hasModelString()) + { + CLogMessage(this).validationInfo("Invalid lookup for '%1' successful: %2") << modelStr << model.toQString(); + return; + } this->setGuiIcaoValues(model, false); - this->ps_reverseLookupModel(); + + // open dialog for model mapping + if (this->m_autoPopupWizard && !model.isLoadedFromDb()) + { + this->ps_mappingWizard(); + } + } + + void CLoginComponent::ps_mappingWizard() + { + if (!this->m_mappingWizard) + { + this->m_mappingWizard.reset(new CDbQuickMappingWizard(this)); + } + + if (sGui->getIContextSimulator()->isSimulatorAvailable()) + { + // preset on model + const CAircraftModel model(sGui->getIContextOwnAircraft()->getOwnAircraft().getModel()); + this->m_mappingWizard->presetModel(model); + } + else + { + // preset on GUI values only + const CAircraftIcaoCode icao(ui->selector_AircraftIcao->getAircraftIcao()); + this->m_mappingWizard->presetAircraftIcao(icao); + } + this->m_mappingWizard->show(); } void CLoginComponent::initCompleters(CEntityFlags::Entity entity) { // completers where possible - if (sGui && sGui->getWebDataServices()) + if (sGui && sGui->hasWebDataServices()) { - if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) && !ui->le_AircraftIcaoDesignator->completer()) - { - const QStringList aircraftDesignators = sGui->getWebDataServices()->getAircraftIcaoCodes().toCompleterStrings(); - if (!aircraftDesignators.isEmpty()) - { - QCompleter *completer = new QCompleter(aircraftDesignators, this); - QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(completer); - completer->popup()->setItemDelegate(itemDelegate); - ui->le_AircraftIcaoDesignator->setCompleter(completer); - completer->popup()->setObjectName("AircraftCompleter"); - completer->popup()->setMinimumWidth(175); - } - } - - if (entity.testFlag(CEntityFlags::AirlineIcaoEntity) && !ui->le_AirlineIcaoDesignator->completer()) - { - const QStringList airlineDesignators = sGui->getWebDataServices()->getAirlineIcaoCodes().toIcaoDesignatorNameCountryCompleterStrings(); - if (!airlineDesignators.isEmpty()) - { - QCompleter *completer = new QCompleter(airlineDesignators, this); - QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(completer); - completer->popup()->setItemDelegate(itemDelegate); - ui->le_AirlineIcaoDesignator->setCompleter(completer); - completer->popup()->setObjectName("AirlineCompleter"); - completer->popup()->setMinimumWidth(175); - } - } - if (entity.testFlag(CEntityFlags::AirportEntity) && !ui->le_VatsimHomeAirport->completer()) { + // one time init const QStringList airports = sGui->getWebDataServices()->getAirports().allIcaoCodes(true); if (!airports.isEmpty()) { @@ -612,5 +626,26 @@ namespace BlackGui } } } + + void CLoginComponent::highlightModelField(const CAircraftModel &model) + { + static const QString error("rgba(255, 0, 0, 40%)"); + static const QString warning("rgba(255, 255, 0, 40%)"); + static const QString ok("rgba(0, 255, 0, 40%)"); + QString color(ok); + if (!model.hasModelString()) + { + color = error; + } + else + { + if (!model.isLoadedFromDb()) + { + color = warning; + } + } + static const QString sheet("background-color: %1;"); + ui->le_SimulatorModel->setStyleSheet(sheet.arg(color)); + } } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index f68913e38..ed690dd5c 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -45,7 +45,11 @@ namespace BlackGui { namespace Components { - //! Login component + class CDbQuickMappingWizard; + + /*! + * Login component to flight network + */ class BLACKGUI_EXPORT CLoginComponent : public QFrame { @@ -58,6 +62,9 @@ namespace BlackGui //! Constructor explicit CLoginComponent(QWidget *parent = nullptr); + //! Automatically popup + void setAutoPopupWizad(bool autoPopup); + //! Destructor ~CLoginComponent(); @@ -91,6 +98,12 @@ namespace BlackGui //! Validate VATSIM credentials bool ps_validateVatsimValues(); + //! Aircraft ICAO code has been changed + void ps_changedAircraftIcao(const BlackMisc::Aviation::CAircraftIcaoCode &icao); + + //! Airline ICAO code has been changed + void ps_changedAirlineIcao(const BlackMisc::Aviation::CAirlineIcaoCode &icao); + //! Settings have been changed void ps_reloadSettings(); @@ -98,18 +111,21 @@ namespace BlackGui void ps_logoffCountdown(); //! Reverse lookup model - void ps_reverseLookupModel(); + void ps_reverseLookupAircraftIcaoData(); //! Simulator model has been changed void ps_simulatorModelChanged(const BlackMisc::Simulation::CAircraftModel &model); + //! Launch mapping wizard + void ps_mappingWizard(); + private: //! GUI aircraft values, formatted struct CGuiAircraftValues { - QString ownCallsign; - QString ownAircraftIcaoTypeDesignator; - QString ownAircraftIcaoAirline; + BlackMisc::Aviation::CCallsign ownCallsign; + BlackMisc::Aviation::CAircraftIcaoCode ownAircraftIcao; + BlackMisc::Aviation::CAirlineIcaoCode ownAirlineIcao; QString ownAircraftCombinedType; QString ownAircraftSimulatorModel; }; @@ -162,13 +178,18 @@ namespace BlackGui //! Completers void initCompleters(BlackMisc::Network::CEntityFlags::Entity entity); + //! Highlight model field according to model data + void highlightModelField(const BlackMisc::Simulation::CAircraftModel &model = {}); + QScopedPointer ui; + QScopedPointer m_mappingWizard; + bool m_autoPopupWizard = false; //!< automatically popup wizard if mapping is needed bool m_visible = false; //!< is this component selected? - const int LogoffIntervalSeconds = 10; - QTimer *m_logoffCountdownTimer { nullptr }; + const int LogoffIntervalSeconds = 10; //!< time before logoff + QTimer *m_logoffCountdownTimer { nullptr }; //!< timer used logoff countdown BlackMisc::CSettingReadOnly m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings }; - BlackMisc::CSetting m_currentAircraftModel { this }; - BlackMisc::CData m_currentVatsimServer { this }; + BlackMisc::CSetting m_currentAircraftModel { this }; //!< current settings of aircraft + BlackMisc::CData m_currentVatsimServer { this }; //!< cache for current VATSIM server }; } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.ui b/src/blackgui/components/logincomponent.ui index 602f8aebf..0f4713e70 100644 --- a/src/blackgui/components/logincomponent.ui +++ b/src/blackgui/components/logincomponent.ui @@ -10,14 +10,8 @@ 576 - - - 0 - 0 - - - Frame + Login component QFrame::StyledPanel @@ -152,7 +146,11 @@ - + + + e.g. Joe Doe + + @@ -313,30 +311,84 @@ 3 - + - e.g. DLH, LHA, ... + ICAO code e.g. DLH, LHA, ... - ICAO airline + Airline - - + + - e.g. DLH + e.g. DEMBZ + + + Qt::ImhUppercaseOnly - 128 + 10 - e.g. "DLH" + e.g. DEMBZ - + + + + Callsign + + + + + + + ICAO code e.g. B737, A320, F18 + + + Aircraft + + + + + + + + + + + + + + + + + + + + + Launch + + + Model + + + + + + + Aircraft type e.g. L2J, L1P, .... + + + Type + + + + e.g. L2J @@ -355,129 +407,102 @@ - - - - e.g. L2J, L1P, .... - + + - Aircraft type + - - + + + + + 0 + 0 + + - Callsign + - - - - e.g. DEMBZ - - - Qt::ImhUppercaseOnly - - - 10 - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + unique model identifier + + + + + + + ... + + + + :/diagona/icons/diagona/icons/arrow-circle-225.png:/diagona/icons/diagona/icons/arrow-circle-225.png + + + + + + + ... + + + + :/own/icons/own/swift3D/sw3DGreen-24.png:/own/icons/own/swift3D/sw3DGreen-24.png + + + + - - - e.g. B737 + + + + 75 + 0 + - - 128 - - - e.g. "B737" + + Qt::StrongFocus - - - - e.g. B737, A320, F18 + + + + + 75 + 0 + - - ICAO designator + + Qt::StrongFocus - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - unique model identifier - - - - - - - 0 - - - - - Model - - - - - - - ... - - - - :/diagona/icons/diagona/icons/arrow-circle-225.png:/diagona/icons/diagona/icons/arrow-circle-225.png - - - - - @@ -602,6 +627,18 @@
blackgui/editors/fsdsetupform.h
1 + + BlackGui::Components::CDbAircraftIcaoSelectorComponent + QFrame +
blackgui/components/dbaircrafticaoselectorcomponent.h
+ 1 +
+ + BlackGui::Components::CDbAirlineIcaoSelectorComponent + QFrame +
blackgui/components/dbairlineicaoselectorcomponent.h
+ 1 +
tw_Network @@ -610,11 +647,10 @@ le_VatsimRealName le_VatsimHomeAirport comp_VatsimServer - le_SimulatorModel le_Callsign - le_AircraftIcaoDesignator - le_AirlineIcaoDesignator + selector_AircraftIcao le_AircraftCombinedType + selector_AirlineIcao comp_OtherServers pb_OtherServersGotoSettings