diff --git a/src/blackcore/data/vatsimsetup.h b/src/blackcore/data/vatsimsetup.h index 411e3941f..4d8ec15fb 100644 --- a/src/blackcore/data/vatsimsetup.h +++ b/src/blackcore/data/vatsimsetup.h @@ -43,8 +43,7 @@ namespace BlackCore IndexDataFiles, IndexMetarFiles, IndexFsdServers, - IndexCVoiceServers, - IndexLastLoginUser + IndexCVoiceServers }; //! Default constructor @@ -74,9 +73,6 @@ namespace BlackCore //! FSD test servers const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; } - //! User for last login - const BlackMisc::Network::CUser &getLastLoginUser() const { return m_lastLoginUser; } - //! Set FSD servers void setFsdServers(const BlackMisc::Network::CServerList &servers) { m_fsdServers = servers; } @@ -86,9 +82,6 @@ namespace BlackCore //! Set voice servers void setVoiceServers(const BlackMisc::Network::CServerList &servers) { m_voiceServers = servers; } - //! User for last login - void setLastLoginUser(const BlackMisc::Network::CUser &user) { m_lastLoginUser = user; } - //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; @@ -107,7 +100,6 @@ namespace BlackCore BlackMisc::Network::CUrlList m_metarFileUrls; //!< METAR files BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers BlackMisc::Network::CServerList m_voiceServers; //!< voice servers - BlackMisc::Network::CUser m_lastLoginUser; //!< last login user BLACK_METACLASS( CVatsimSetup, @@ -116,7 +108,6 @@ namespace BlackCore BLACK_METAMEMBER(metarFileUrls), BLACK_METAMEMBER(fsdServers), BLACK_METAMEMBER(voiceServers), - BLACK_METAMEMBER(lastLoginUser), BLACK_METAMEMBER(timestampMSecsSinceEpoch) ); }; @@ -125,7 +116,17 @@ namespace BlackCore struct VatsimSetup : public BlackMisc::CDataTrait { //! Key in data cache - static const char *key() { return "vatsim"; } + static const char *key() { return "vatsimsetup"; } + + //! First load is synchronous + static constexpr bool isPinned() { return true; } + }; + + //! Trait for currently used VATSIM server and user + struct VatsimCurrentServer : public BlackMisc::CDataTrait + { + //! Key in data cache + static const char *key() { return "vatsimserver"; } //! First load is synchronous static constexpr bool isPinned() { return true; } diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 763d113f6..53918c75d 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -85,8 +85,8 @@ namespace BlackGui this->ui->lblp_VatsimPassword->setToolTips("ok", "wrong"); this->ui->lblp_VatsimRealName->setToolTips("ok", "wrong"); - // Settings loaded - this->loadFromSettings(); + // Stored data + this->loadRememberedVatsimData(); // Remark: The validators affect the signals such as returnPressed, editingFinished // So I use no ranges in the CUpperCaseValidators, as this disables the signals for invalid values @@ -137,7 +137,7 @@ namespace BlackGui otherServers.push_back(sGui->getGlobalSetup().getFsdTestServersPlusHardcodedServers()); CLogMessage(this).info("Added servers for testing"); } - this->ui->cbp_OtherServers->setServers(otherServers); + this->ui->comp_OtherServers->setServers(otherServers); } CLoginComponent::~CLoginComponent() @@ -180,12 +180,14 @@ namespace BlackGui void CLoginComponent::ps_toggleNetworkConnection() { - bool isConnected = sGui->getIContextNetwork()->isConnected(); + const bool isConnected = sGui->getIContextNetwork()->isConnected(); + const bool vatsimLogin = (this->ui->tw_Network->currentWidget() == this->ui->pg_NetworkVatsim); + CServer currentServer; // used for login + CSimulatedAircraft ownAircraft; // used own aircraft CStatusMessage msg; if (!isConnected) { - bool vatsimLogin = (this->ui->tw_Network->currentWidget() == this->ui->pg_NetworkVatsim); if (!this->ps_validateAircraftValues()) { CLogMessage(this).warning("Invalid aircraft data, login not possible"); @@ -200,7 +202,7 @@ namespace BlackGui // sync values with GUI values CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui(); - CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); + ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); CAircraftIcaoCode aircraftCode(ownAircraft.getAircraftIcaoCode()); CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode()); @@ -244,11 +246,10 @@ namespace BlackGui } // Server - CServer currentServer; if (vatsimLogin) { currentServer = this->getCurrentVatsimServer(); - CUser vatsimUser = this->getUserFromVatsimGuiValues(); + const CUser vatsimUser = this->getUserFromVatsimGuiValues(); currentServer.setUser(vatsimUser); } else @@ -274,6 +275,11 @@ namespace BlackGui if (msg.isSeverityInfoOrLess()) { emit loginOrLogoffSuccessful(); + if (vatsimLogin) + { + this->m_currentVatsimServer.set(currentServer); + this->m_currentAircraftModel.setAndSave(ownAircraft.getModel()); + } } else { @@ -281,16 +287,17 @@ namespace BlackGui } } - void CLoginComponent::ps_onWebServiceDataRead(int entityI, int stateI, int number) - // void CLoginComponent::ps_onWebServiceDataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState, int number) + void CLoginComponent::ps_onWebServiceDataRead(int entityInt, int stateI, int number) { - CEntityFlags::EntityFlag entity = static_cast(entityI); - CEntityFlags::ReadState state = static_cast(stateI); + const CEntityFlags::EntityFlag entity = static_cast(entityInt); + const CEntityFlags::ReadState state = static_cast(stateI); if (entity != CEntityFlags::VatsimDataFile || state != CEntityFlags::ReadFinished) { return; } Q_UNUSED(number); - CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers(); + const CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers(); if (vatsimFsdServers.isEmpty()) { return; } - this->ui->cbp_VatsimServer->setServers(vatsimFsdServers); + const CServer currentServer = this->m_currentVatsimServer.get(); + this->ui->comp_VatsimServer->setServers(vatsimFsdServers); + this->ui->comp_VatsimServer->preSelect(currentServer.getName()); } void CLoginComponent::setGuiValuesFromAircraft(const CSimulatedAircraft &ownAircraft) @@ -302,14 +309,27 @@ namespace BlackGui this->ui->le_AircraftCombinedType->setText(aircraftIcao.getCombinedType()); } - void CLoginComponent::loadFromSettings() + void CLoginComponent::loadRememberedVatsimData() { - //! \todo replace with loading from settings when completed - this->ui->le_Callsign->setText("SWIFT"); - this->ui->le_VatsimId->setText("1288459"); - this->ui->le_VatsimPassword->setText("4769"); - this->ui->le_VatsimHomeAirport->setText("LOWI"); - this->ui->le_VatsimRealName->setText("Black Swift"); + const CServer lastServer = this->m_currentVatsimServer.get(); + const CUser lastUser = lastServer.getUser(); + if (lastUser.hasValidCallsign()) + { + this->ui->le_Callsign->setText(lastUser.getCallsign().asString()); + this->ui->le_VatsimId->setText(lastUser.getId()); + this->ui->le_VatsimPassword->setText(lastUser.getPassword()); + this->ui->le_VatsimHomeAirport->setText(lastUser.getHomebase().asString()); + this->ui->le_VatsimRealName->setText(lastUser.getRealName()); + } + else + { + this->ui->le_Callsign->setText("SWIFT"); + this->ui->le_VatsimId->setText("1288459"); + this->ui->le_VatsimPassword->setText("4769"); + this->ui->le_VatsimHomeAirport->setText("LOWI"); + this->ui->le_VatsimRealName->setText("Black Swift"); + } + this->ui->comp_OtherServers->preSelect(lastServer.getName()); } CLoginComponent::CGuiAircraftValues CLoginComponent::getAircraftValuesFromGui() const @@ -337,6 +357,7 @@ namespace BlackGui { CVatsimValues values = getVatsimValuesFromGui(); CUser user(values.vatsimId, values.vatsimRealName, "", values.vatsimPassword, getCallsignFromGui()); + user.setHomebase(values.vatsimHomeAirport); return user; } @@ -348,12 +369,12 @@ namespace BlackGui CServer CLoginComponent::getCurrentVatsimServer() const { - return this->ui->cbp_VatsimServer->currentServer(); + return this->ui->comp_VatsimServer->currentServer(); } CServer CLoginComponent::getCurrentOtherServer() const { - return this->ui->cbp_OtherServers->currentServer(); + return this->ui->comp_OtherServers->currentServer(); } void CLoginComponent::setOkButtonString(bool connected) @@ -382,13 +403,9 @@ namespace BlackGui Q_ASSERT(sGui->getIContextOwnAircraft()); Q_ASSERT(sGui->getIContextSimulator()); - static const CAircraftModel defaultModel( - "", CAircraftModel::TypeOwnSimulatorModel, "default model", - CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0)); - CAircraftModel model; - bool simulating = sGui->getIContextSimulator() && - (sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); + const bool simulating = sGui->getIContextSimulator() && + (sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); if (simulating) { model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel(); @@ -396,10 +413,12 @@ namespace BlackGui } else { - // Set observer mode without simulator - //! \todo Currently not working in OBS mode - model = CAircraftModel(defaultModel); - this->ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); + 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; } + this->ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); //! \todo Set observer mode without simulator, currently not working in OBS mode this->ui->le_SimulatorModel->setText("No simulator"); } @@ -471,7 +490,7 @@ namespace BlackGui void CLoginComponent::ps_reloadSettings() { CServerList otherServers(this->m_otherTrafficNetworkServers.getThreadLocal()); - this->ui->cbp_OtherServers->setServers(otherServers); + this->ui->comp_OtherServers->setServers(otherServers); } void CLoginComponent::ps_logoffCountdown() @@ -504,6 +523,5 @@ namespace BlackGui CLogMessage(this).validationInfo("Reverse lookup for %1 failed, set data manually") << modelStr; } } - } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 3fcdc4452..2d6102b35 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -13,12 +13,15 @@ #define BLACKGUI_LOGINCOMPONENT_H #include "blackcore/settings/network.h" +#include "blackcore/data/vatsimsetup.h" #include "blackgui/blackguiexport.h" +#include "blackgui/settings/settingsgui.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/network/server.h" #include "blackmisc/network/user.h" #include "blackmisc/settingscache.h" +#include "blackmisc/datacache.h" #include "blackmisc/simulation/simulatedaircraft.h" #include @@ -38,7 +41,6 @@ namespace BlackMisc } } namespace Ui { class CLoginComponent; } - namespace BlackGui { namespace Components @@ -119,7 +121,7 @@ namespace BlackGui void setGuiValuesFromAircraft(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); //! Load from settings - void loadFromSettings(); + void loadRememberedVatsimData(); //! Values from GUI CGuiAircraftValues getAircraftValuesFromGui() const; @@ -154,13 +156,14 @@ namespace BlackGui //! Set ICAO values void setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty); - bool m_visible = false; //!< is this component selected? QScopedPointer ui; + bool m_visible = false; //!< is this component selected? const int LogoffIntervalSeconds = 10; QTimer *m_logoffCountdownTimer { nullptr }; - BlackMisc::CSetting m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings }; + BlackMisc::CSettingReadOnly m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings }; + BlackMisc::CSetting m_currentAircraftModel { this }; + BlackMisc::CData m_currentVatsimServer { this }; }; - } // namespace } // namespace diff --git a/src/blackgui/components/logincomponent.ui b/src/blackgui/components/logincomponent.ui index ce9466c7e..6b7ca04f6 100644 --- a/src/blackgui/components/logincomponent.ui +++ b/src/blackgui/components/logincomponent.ui @@ -7,7 +7,7 @@ 0 0 463 - 412 + 443 @@ -156,7 +156,7 @@ - + @@ -212,7 +212,7 @@ - + @@ -584,13 +584,13 @@ le_VatsimPassword le_VatsimRealName le_VatsimHomeAirport - cbp_VatsimServer + comp_VatsimServer le_SimulatorModel le_Callsign le_AircraftIcaoDesignator le_AircraftIcaoAirline le_AircraftCombinedType - cbp_OtherServers + comp_OtherServers pb_OtherServersGotoSettings diff --git a/src/blackgui/components/serverlistselector.cpp b/src/blackgui/components/serverlistselector.cpp index 601746b64..2a9526a15 100644 --- a/src/blackgui/components/serverlistselector.cpp +++ b/src/blackgui/components/serverlistselector.cpp @@ -27,15 +27,39 @@ namespace BlackGui { if (this->m_servers == servers) { return; } this->setItemStrings(servers); + if (!servers.isEmpty() && !m_pendingPreselect.isEmpty()) + { + this->preSelect(m_pendingPreselect); + m_pendingPreselect.clear(); + } } - BlackMisc::Network::CServer CServerListSelector::currentServer() const + CServer CServerListSelector::currentServer() const { - int i = currentIndex(); + const int i = currentIndex(); if (i < 0 || i >= m_servers.size()) { return CServer(); } return m_servers[i]; } + bool CServerListSelector::preSelect(const QString &name) + { + if (name.isEmpty()) { return false; } + if (m_servers.isEmpty()) + { + m_pendingPreselect = name; // save for later + return false; + } + for (int i = 0; i < m_servers.size(); i++) + { + if (m_servers[i].matchesName(name)) + { + this->setCurrentIndex(i); + return true; + } + } + return false; + } + void CServerListSelector::setItemStrings(const CServerList &servers) { QString currentlySelected(this->currentText()); diff --git a/src/blackgui/components/serverlistselector.h b/src/blackgui/components/serverlistselector.h index 82b5940a6..ebe781f9e 100644 --- a/src/blackgui/components/serverlistselector.h +++ b/src/blackgui/components/serverlistselector.h @@ -41,12 +41,16 @@ namespace BlackGui //! Get the current server BlackMisc::Network::CServer currentServer() const; + //! Preselect + bool preSelect(const QString &name); + private: //! Build the item string descriptions void setItemStrings(const BlackMisc::Network::CServerList &servers); BlackMisc::Network::CServerList m_servers; //!< corresponding servers QStringList m_items; //!< items strings + QString m_pendingPreselect; //!< pending preselect value }; } // ns } // ns diff --git a/src/blackgui/settings/settingsgui.h b/src/blackgui/settings/settingsgui.h new file mode 100644 index 000000000..b669941a3 --- /dev/null +++ b/src/blackgui/settings/settingsgui.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_SETTINGS_GUI_H +#define BLACKGUI_SETTINGS_GUI_H + +#include "blackgui/blackguiexport.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/simulation/aircraftmodel.h" + +namespace BlackGui +{ + namespace Settings + { + //! Settings for last manual entries of own aircraft mode + struct OwnAircraftModel : public BlackMisc::CSettingTrait + { + //! Key in data cache + static const char *key() { return "guinownaircraftmodel"; } + }; + } // ns +} // ns + +#endif // guard