diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index b9631de16..cc06a5323 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -86,7 +86,7 @@ namespace BlackSample // User parsing CUser user("12345", "Joe KING KGLC"); - out << user.getRealName() << user.getHomebase() << endl; + out << user.getRealName() << user.getHomeBase() << endl; // ATC List CAtcStationList atcList; diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index c12bf96cb..b90e6ee69 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -59,6 +59,7 @@ namespace BlackGui ui(new Ui::CFlightPlanComponent) { Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui"); + Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "missing web services"); // UI ui->setupUi(this); @@ -119,7 +120,10 @@ namespace BlackGui { if (this->m_flightPlan.wasSentOrLoaded()) { return; } // when loaded or sent do not override if (!sGui->getIContextOwnAircraft()) { return; } - this->prefillWithAircraftData(sGui->getIContextOwnAircraft()->getOwnAircraft()); + + const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft()); + this->prefillWithAircraftData(ownAircraft); + this->prefillWithUserData(ownAircraft.getPilot()); } void CFlightPlanComponent::prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft) @@ -139,6 +143,18 @@ namespace BlackGui } } + void CFlightPlanComponent::prefillWithUserData(const Network::CUser &user) + { + if (user.hasValidRealName()) + { + ui->le_PilotsName->setText(user.getRealName()); + } + if (user.hasHomeBase()) + { + ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode()); + } + } + void CFlightPlanComponent::fillWithFlightPlanData(const BlackMisc::Aviation::CFlightPlan &flightPlan) { ui->le_AlternateAirport->setText(flightPlan.getAlternateAirportIcao().asString()); diff --git a/src/blackgui/components/flightplancomponent.h b/src/blackgui/components/flightplancomponent.h index 2895f6750..074090f9a 100644 --- a/src/blackgui/components/flightplancomponent.h +++ b/src/blackgui/components/flightplancomponent.h @@ -14,6 +14,7 @@ #include "blackgui/blackguiexport.h" #include "blackmisc/aviation/flightplan.h" +#include "blackmisc/network/user.h" #include "blackmisc/identifier.h" #include "blackmisc/statusmessagelist.h" @@ -52,6 +53,9 @@ namespace BlackGui //! Prefill with aircraft data void prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); + //! Prefill with user data + void prefillWithUserData(const BlackMisc::Network::CUser &user); + //! Prefill with aircraft dara void fillWithFlightPlanData(const BlackMisc::Aviation::CFlightPlan &flightPlan); diff --git a/src/blackgui/components/flightplancomponent.ui b/src/blackgui/components/flightplancomponent.ui index 4e3913a89..eeb995e19 100644 --- a/src/blackgui/components/flightplancomponent.ui +++ b/src/blackgui/components/flightplancomponent.ui @@ -246,7 +246,7 @@ - + 14. Pilots name / homebase @@ -447,7 +447,7 @@ - + @@ -1027,7 +1027,7 @@ pb_RemarksGenerator pte_Remarks le_PilotsName - le_PilotsHomebase + le_PilotsHomeBase pb_Reset pb_Load pb_Send diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index d2ca89885..37bb48194 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -248,7 +248,7 @@ namespace BlackGui if (ownAircraft.getCallsign() != aircraftValues.ownCallsign) { ownAircraft.setCallsign(aircraftValues.ownCallsign); - sGui->getIContextOwnAircraft()->updateOwnCallsign(ownAircraft.getCallsign()); + this->updateOwnCallsignAndPilotFromGuiValue(); } if (setIcaoCodes) @@ -354,7 +354,7 @@ namespace BlackGui ui->le_Callsign->setText(lastUser.getCallsign().asString()); ui->le_VatsimId->setText(lastUser.getId()); ui->le_VatsimPassword->setText(lastUser.getPassword()); - ui->le_VatsimHomeAirport->setText(lastUser.getHomebase().asString()); + ui->le_VatsimHomeAirport->setText(lastUser.getHomeBase().asString()); ui->le_VatsimRealName->setText(lastUser.getRealName()); } else @@ -393,7 +393,7 @@ namespace BlackGui { CVatsimValues values = getVatsimValuesFromGui(); CUser user(values.vatsimId, values.vatsimRealName, "", values.vatsimPassword, getCallsignFromGui()); - user.setHomebase(values.vatsimHomeAirport); + user.setHomeBase(values.vatsimHomeAirport); return user; } @@ -450,20 +450,29 @@ namespace BlackGui } else { - static const CAircraftModel defaultModel( - "", CAircraftModel::TypeOwnSimulatorModel, "default model", - CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0)); - model = this->m_currentAircraftModel.get(); - if (!model.hasAircraftDesignator()) { model = defaultModel; } + model = this->getPrefillModel(); ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); //! \todo Set observer mode without simulator, currently not working in OBS mode ui->le_SimulatorModel->setText(""); this->highlightModelField(); } - if (model.hasAircraftDesignator()) + // reset the model + if (model.isLoadedFromDb()) { + // full model from DB, take all values this->setGuiIcaoValues(model, false); } + else + { + if (model.hasAircraftDesignator()) + { + // typed in model, override unempty values only + this->setGuiIcaoValues(model, true); + } + } + + this->updateOwnCallsignAndPilotFromGuiValue(); + this->triggerDataChangedSignal(1500); } void CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty) @@ -491,7 +500,8 @@ namespace BlackGui const bool validCombinedType = CAircraftIcaoCode::isValidCombinedType(values.ownAircraftCombinedType); ui->lblp_AircraftCombinedType->setTicked(validCombinedType); - const bool validAirlineDesignator = values.ownAirlineIcao.hasValidDesignator(); + // airline is optional, e.g. C172 has no airline + const bool validAirlineDesignator = values.ownAirlineIcao.hasValidDesignator() || values.ownAirlineIcao.getDesignator().isEmpty(); ui->lblp_AirlineIcao->setTicked(validAirlineDesignator); const bool validAircraftDesignator = values.ownAircraftIcao.hasValidDesignator(); @@ -566,6 +576,7 @@ namespace BlackGui void CLoginComponent::ps_simulatorModelChanged(const CAircraftModel &model) { + Q_ASSERT_X(sGui && sGui->getIContextNetwork(), Q_FUNC_INFO, "Missing context"); const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected(); if (isConnected) { return; } const QString modelStr(model.hasModelString() ? model.getModelString() : ""); @@ -581,6 +592,12 @@ namespace BlackGui { this->ps_mappingWizard(); } + + // check state of own aircraft + this->updateOwnCallsignAndPilotFromGuiValue(); + + // let others know data changed + this->triggerDataChangedSignal(1500); } void CLoginComponent::ps_mappingWizard() @@ -647,5 +664,54 @@ namespace BlackGui static const QString sheet("background-color: %1;"); ui->le_SimulatorModel->setStyleSheet(sheet.arg(color)); } + + void CLoginComponent::triggerDataChangedSignal(int deferTimeMs) + { + QTimer::singleShot(deferTimeMs, this, &CLoginComponent::loginDataChanged); + } + + CAircraftModel CLoginComponent::getPrefillModel() const + { + // if all fails + static const CAircraftModel defaultModel( + "", CAircraftModel::TypeOwnSimulatorModel, "default model", + CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0)); + + CAircraftModel model = this->m_currentAircraftModel.get(); + if (model.hasAircraftDesignator()) { return model; } + + // create one from DB data + if (sGui && sGui->hasWebDataServices()) + { + const CAircraftIcaoCode icao = sGui->getWebDataServices()->getAircraftIcaoCodeForDesignator("C172"); + const CLivery livery = sGui->getWebDataServices()->getLiveryForCombinedCode("_CC_WHITE_WHITE"); + model = CAircraftModel("", CAircraftModel::TypeOwnSimulatorModel); + model.setLivery(livery); + model.setAircraftIcaoCode(icao); + return model; + } + + return defaultModel; + } + + void CLoginComponent::updateOwnCallsignAndPilotFromGuiValue() + { + if (!sGui || !sGui->getIContextOwnAircraft()) { return; } + const CSimulatedAircraft ownAircaft(sGui->getIContextOwnAircraft()->getOwnAircraft()); + const QString cs(ui->le_Callsign->text().trimmed().toUpper()); + if (!cs.isEmpty() && ownAircaft.getCallsignAsString() != cs) + { + sGui->getIContextOwnAircraft()->updateOwnCallsign(CCallsign(cs)); + } + CUser pilot = ownAircaft.getPilot(); + pilot.setRealName(CUser::beautifyRealName(ui->le_VatsimRealName->text())); + pilot.setHomeBase(CAirportIcaoCode(ui->le_VatsimHomeAirport->text())); + pilot.setId(ui->le_VatsimId->text()); + pilot.setCallsign(CCallsign(cs)); + if (ownAircaft.getPilot() != pilot) + { + sGui->getIContextOwnAircraft()->updateOwnAircraftPilot(pilot); + } + } } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index ed690dd5c..90e5efd9b 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -78,6 +78,9 @@ namespace BlackGui //! Request network settings void requestNetworkSettings(); + //! Relevant login data changed + void loginDataChanged(); + public slots: //! Main info area chnaged void mainInfoAreaChanged(const QWidget *currentWidget); @@ -181,11 +184,20 @@ namespace BlackGui //! Highlight model field according to model data void highlightModelField(const BlackMisc::Simulation::CAircraftModel &model = {}); + //! Trigger the signal that data have been changed + void triggerDataChangedSignal(int deferTimeMs); + + //! Get a prefill model + BlackMisc::Simulation::CAircraftModel getPrefillModel() const; + + //! Update own callsign (own aircraft from what is set in the GUI) + void updateOwnCallsignAndPilotFromGuiValue(); + 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; //!< time before logoff + const int LogoffIntervalSeconds = 20; //!< time before logoff QTimer *m_logoffCountdownTimer { nullptr }; //!< timer used logoff countdown BlackMisc::CSettingReadOnly m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings }; BlackMisc::CSetting m_currentAircraftModel { this }; //!< current settings of aircraft diff --git a/src/blackgui/components/remoteaircraftselector.cpp b/src/blackgui/components/remoteaircraftselector.cpp index 92a4639e6..d1549991d 100644 --- a/src/blackgui/components/remoteaircraftselector.cpp +++ b/src/blackgui/components/remoteaircraftselector.cpp @@ -99,7 +99,7 @@ namespace BlackGui if (aircraft.hasValidRealName()) { i += " - "; - i += aircraft.getPilotRealname(); + i += aircraft.getPilotRealName(); } items.append(i); } diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index 77e3a6449..be9de4aca 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -194,7 +194,7 @@ namespace BlackMisc { if (this->m_controller == otherStation.getController()) { return; } CUser otherController = otherStation.getController(); - this->m_controller.syncronizeData(otherController); + this->m_controller.synchronizeData(otherController); otherStation.setController(otherController); } diff --git a/src/blackmisc/network/user.cpp b/src/blackmisc/network/user.cpp index 183bfe5bf..7988fb475 100644 --- a/src/blackmisc/network/user.cpp +++ b/src/blackmisc/network/user.cpp @@ -103,7 +103,7 @@ namespace BlackMisc int pos = match.capturedStart(0); QString icao = match.captured(0).trimmed().right(4); rn = rn.left(pos).trimmed(); - this->setHomebase(CAirportIcaoCode(icao)); + this->setHomeBase(CAirportIcaoCode(icao)); } } @@ -130,7 +130,7 @@ namespace BlackMisc if (!this->hasValidCallsign()) { this->setCallsign(otherUser.getCallsign()); } } - void CUser::syncronizeData(CUser &otherUser) + void CUser::synchronizeData(CUser &otherUser) { if (this == &otherUser) { return; } this->updateMissingParts(otherUser); @@ -239,7 +239,7 @@ namespace BlackMisc case IndexRealName: return this->m_realname.compare(compareValue.getRealName(), Qt::CaseInsensitive); case IndexHomebase: - return this->m_homebase.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getHomebase()); + return this->m_homebase.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getHomeBase()); case IndexCallsign: return this->m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); default: diff --git a/src/blackmisc/network/user.h b/src/blackmisc/network/user.h index fbbdab1c1..4ebd7d094 100644 --- a/src/blackmisc/network/user.h +++ b/src/blackmisc/network/user.h @@ -109,10 +109,13 @@ namespace BlackMisc void setId(const QString &id) { m_id = id.trimmed(); } //! Homebase - const BlackMisc::Aviation::CAirportIcaoCode &getHomebase() const { return this->m_homebase; } + const BlackMisc::Aviation::CAirportIcaoCode &getHomeBase() const { return this->m_homebase; } //! Set homebase - void setHomebase(const BlackMisc::Aviation::CAirportIcaoCode &homebase) { this->m_homebase = homebase; } + void setHomeBase(const BlackMisc::Aviation::CAirportIcaoCode &homebase) { this->m_homebase = homebase; } + + //! Has home base? + bool hasHomeBase() const { return !this->m_homebase.isEmpty(); } //! Get associated callsign. const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_callsign; } @@ -133,7 +136,7 @@ namespace BlackMisc int comparePropertyByIndex(const CPropertyIndex &index, const CUser &compareValue) const; //! This and another user exchange missing data, This user has priority and overrides first. - void syncronizeData(CUser &otherUser); + void synchronizeData(CUser &otherUser); //! Update missing parts in this object void updateMissingParts(const CUser &otherUser); diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index a29697f0f..890784152 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -114,7 +114,7 @@ namespace BlackMisc const BlackMisc::Network::CUser &getPilot() const { return m_pilot; } //! Get user's real name - QString getPilotRealname() const { return m_pilot.getRealName(); } + QString getPilotRealName() const { return m_pilot.getRealName(); } //! Get user's real id QString getPilotId() { return m_pilot.getId(); } diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 4cce75a81..65dcf96f1 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -214,6 +214,7 @@ void SwiftGuiStd::initGuiSignals() connect(ui->comp_Login, &CLoginComponent::loginOrLogoffCancelled, this, &SwiftGuiStd::ps_setMainPageToInfoArea); connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, this, &SwiftGuiStd::ps_setMainPageToInfoArea); connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet); + connect(ui->comp_Login, &CLoginComponent::loginDataChanged, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet); connect(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged); connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings, ui->comp_MainInfoArea->getFlightPlanComponent(), [ = ]() {