From 0975abcc46a97c680513b83b5bb4a803dfad353b Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 2 Jan 2018 02:47:47 +0100 Subject: [PATCH] Ref T215, remember last server and model as cache value * also remember last server not VATSIM server * remember last model used * server list selector uses remembered value * login component sets those values --- src/blackcore/data/vatsimsetup.h | 4 +- src/blackgui/components/logincomponent.cpp | 17 +++++---- src/blackgui/components/logincomponent.h | 9 +++-- .../components/serverlistselector.cpp | 8 +++- src/blackgui/components/serverlistselector.h | 4 +- src/blackgui/settings/guisettings.h | 10 ----- src/blackmisc/blackmisc.pro | 1 + src/blackmisc/network/data/lastserver.h | 37 +++++++++++++++++++ src/blackmisc/simulation/data/lastmodel.h | 37 +++++++++++++++++++ src/blackmisc/simulation/data/modelcaches.h | 2 +- 10 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 src/blackmisc/network/data/lastserver.h create mode 100644 src/blackmisc/simulation/data/lastmodel.h diff --git a/src/blackcore/data/vatsimsetup.h b/src/blackcore/data/vatsimsetup.h index 016f67f9e..5ee6f88d6 100644 --- a/src/blackcore/data/vatsimsetup.h +++ b/src/blackcore/data/vatsimsetup.h @@ -128,8 +128,8 @@ namespace BlackCore static constexpr bool isPinned() { return true; } }; - //! Trait for currently used VATSIM server and user - struct TVatsimCurrentServer : public BlackMisc::TDataTrait + //! Trait for last (most recently) used VATSIM server and user + struct TVatsimLastServer : public BlackMisc::TDataTrait { //! Key in data cache static const char *key() { return "vatsimserver"; } diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 5fa0956e9..11a76f1ca 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -291,11 +291,13 @@ namespace BlackGui // Login msg = sGui->getIContextNetwork()->connectToNetwork(currentServer, mode); - if (msg.isSuccess() && vatsimLogin) + if (msg.isSuccess()) { Q_ASSERT_X(currentServer.isValidForLogin(), Q_FUNC_INFO, "invalid server"); - m_currentVatsimServer.set(currentServer); - m_currentAircraftModel.setAndSave(ownAircraft.getModel()); + m_lastServer.set(currentServer); + m_lastAircraftModel.set(ownAircraft.getModel()); + ui->le_HomeBase->setText(currentServer.getUser().getHomeBase().asString()); + if (vatsimLogin) { m_lastVatsimServer.set(currentServer); } } } else @@ -335,7 +337,7 @@ namespace BlackGui CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers(); if (vatsimFsdServers.isEmpty()) { return; } vatsimFsdServers.sortBy(&CServer::getName); - const CServer currentServer = m_currentVatsimServer.get(); + const CServer currentServer = m_lastVatsimServer.get(); ui->comp_VatsimServer->setServers(vatsimFsdServers, true); ui->comp_VatsimServer->preSelect(currentServer.getName()); } @@ -347,7 +349,7 @@ namespace BlackGui void CLoginComponent::loadRememberedVatsimData() { - const CServer lastServer = m_currentVatsimServer.get(); + const CServer lastServer = m_lastVatsimServer.get(); const CUser lastUser = lastServer.getUser(); if (lastUser.hasValidCallsign()) { @@ -357,7 +359,7 @@ namespace BlackGui ui->le_VatsimHomeAirport->setText(lastUser.getHomeBase().asString()); ui->le_VatsimRealName->setText(lastUser.getRealName()); } - else + else if (CBuildConfig::isLocalDeveloperDebugBuild()) { ui->le_Callsign->setText("SWIFT"); ui->le_VatsimId->setText("1288459"); @@ -365,7 +367,6 @@ namespace BlackGui ui->le_VatsimHomeAirport->setText("LOWI"); ui->le_VatsimRealName->setText("Black Swift"); } - ui->comp_OtherServers->preSelect(lastServer.getName()); } CLoginComponent::CGuiAircraftValues CLoginComponent::getAircraftValuesFromGui() const @@ -702,7 +703,7 @@ namespace BlackGui CAircraftModel CLoginComponent::getPrefillModel() const { - CAircraftModel model = m_currentAircraftModel.get(); + const CAircraftModel model = m_lastAircraftModel.get(); if (model.hasAircraftDesignator()) { return model; } return IContextOwnAircraft::getDefaultOwnAircraftModel(); } diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 82c3bc27f..a0b15a4e5 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -16,12 +16,14 @@ #include "blackcore/data/vatsimsetup.h" #include "blackgui/blackguiexport.h" #include "blackgui/settings/guisettings.h" +#include "blackmisc/simulation/data/lastmodel.h" #include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/network/data/lastserver.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/network/server.h" #include "blackmisc/network/user.h" #include "blackmisc/digestsignal.h" -#include "blackmisc/aviation/callsign.h" #include "blackmisc/settingscache.h" #include "blackmisc/datacache.h" @@ -217,8 +219,9 @@ namespace BlackGui const int LogoffIntervalSeconds = 20; //!< time before logoff QTimer *m_logoffCountdownTimer { nullptr }; //!< timer for logoff countdown BlackMisc::CSettingReadOnly m_otherTrafficNetworkServers { this, &CLoginComponent::reloadSettings }; - BlackMisc::CSetting m_currentAircraftModel { this }; //!< current settings of aircraft - BlackMisc::CData m_currentVatsimServer { this }; //!< cache for current VATSIM server + BlackMisc::CData m_lastAircraftModel { this }; //!< recently used aircraft model + BlackMisc::CData m_lastServer { this }; //!< recently used server (VATSIM, other) + BlackMisc::CData m_lastVatsimServer { this }; //!< recently used VATSIM server }; } // namespace } // namespace diff --git a/src/blackgui/components/serverlistselector.cpp b/src/blackgui/components/serverlistselector.cpp index 6fadd5952..d93eac25f 100644 --- a/src/blackgui/components/serverlistselector.cpp +++ b/src/blackgui/components/serverlistselector.cpp @@ -27,7 +27,13 @@ namespace BlackGui { CServerListSelector::CServerListSelector(QWidget *parent) : QComboBox(parent) - { } + { + const CServer server = m_lastServer.get(); + if (server.hasName()) + { + m_pendingPreselect = server.getName(); + } + } void CServerListSelector::setServers(const CServerList &servers, bool nameIsCountry) { diff --git a/src/blackgui/components/serverlistselector.h b/src/blackgui/components/serverlistselector.h index ce50c2ece..4a1c36831 100644 --- a/src/blackgui/components/serverlistselector.h +++ b/src/blackgui/components/serverlistselector.h @@ -13,9 +13,10 @@ #define BLACKGUI_COMPONENTS_SERVERLISTSELECTOR_H #include "blackgui/blackguiexport.h" -#include "blackmisc/network/server.h" +#include "blackmisc/network/data/lastserver.h" #include "blackmisc/network/serverlist.h" #include "blackmisc/country.h" +#include "blackmisc/datacache.h" #include #include @@ -58,6 +59,7 @@ namespace BlackGui BlackMisc::Network::CServerList m_servers; //!< corresponding servers QStringList m_items; //!< items strings QString m_pendingPreselect; //!< pending preselect value + BlackMisc::CData m_lastServer { this }; //!< recently used server (VATSIM, other) }; } // ns } // ns diff --git a/src/blackgui/settings/guisettings.h b/src/blackgui/settings/guisettings.h index 820a599c1..84f7cff4b 100644 --- a/src/blackgui/settings/guisettings.h +++ b/src/blackgui/settings/guisettings.h @@ -83,16 +83,6 @@ namespace BlackGui static const QString &humanReadable() { static const QString name("General GUI"); return name; } }; - //! Settings for last manual entries of own aircraft mode - struct TOwnAircraftModel : public BlackMisc::TSettingTrait - { - //! \copydoc BlackCore::TSettingTrait::key - static const char *key() { return "guinownaircraftmodel"; } - - //! \copydoc BlackCore::TSettingTrait::humanReadable - static const QString &humanReadable() { static const QString name("Own aircraft"); return name; } - }; - //! Settings for last manual entries of own aircraft mode struct TBackgroundConsolidation : public BlackMisc::TSettingTrait { diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index c8c68ee9e..0a3471b74 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -32,6 +32,7 @@ HEADERS += *.h \ $$PWD/input/*.h \ $$PWD/math/*.h \ $$PWD/network/*.h \ + $$PWD/network/data/*.h \ $$PWD/pq/*.h \ $$PWD/simulation/*.h \ $$PWD/simulation/data/*.h \ diff --git a/src/blackmisc/network/data/lastserver.h b/src/blackmisc/network/data/lastserver.h new file mode 100644 index 000000000..101f46112 --- /dev/null +++ b/src/blackmisc/network/data/lastserver.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2017 + * 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 BLACKMISC_NETWORK_DATA_LASTSERVER_H +#define BLACKMISC_NETWORK_DATA_LASTSERVER_H + +#include "../server.h" +#include "blackmisc/datacache.h" + +namespace BlackMisc +{ + namespace Network + { + namespace Data + { + //! Trait for last (most recently) used server and user + struct TLastServer : public TDataTrait + { + //! Key in data cache + static const char *key() { return "lastserver"; } + + //! First load is synchronous + static constexpr bool isPinned() { return true; } + }; + } // ns + } // ns +} // ns + +#endif // guard diff --git a/src/blackmisc/simulation/data/lastmodel.h b/src/blackmisc/simulation/data/lastmodel.h new file mode 100644 index 000000000..69df1deaa --- /dev/null +++ b/src/blackmisc/simulation/data/lastmodel.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2017 + * 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 BLACKMISC_SIMULATION_DATA_LASTMODEL_H +#define BLACKMISC_SIMULATION_DATA_LASTMODEL_H + +#include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/datacache.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace Data + { + //! Last model used + struct TLastModel : public BlackMisc::TDataTrait + { + //! \copydoc BlackCore::TSettingTrait::key + static const char *key() { return "lastaircraftmodel"; } + + //! \copydoc BlackCore::TSettingTrait::humanReadable + static const QString &humanReadable() { static const QString name("Own aircraft model"); return name; } + }; + } // ns + } // ns +} // ns + +#endif // guard diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index 8918506a3..ee8b7aa37 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -29,7 +29,7 @@ namespace BlackMisc namespace Data { //! Trait for model cache - struct TModelCache : public BlackMisc::TDataTrait + struct TModelCache : public TDataTrait { //! Defer loading static constexpr bool isDeferred() { return true; }