Use encapsulated network setup and display correct server tab, follow up of Ref T272

This commit is contained in:
Klaus Basan
2018-05-29 13:34:16 +02:00
parent 839a836926
commit d1782cf014
2 changed files with 32 additions and 37 deletions

View File

@@ -88,11 +88,11 @@ namespace BlackGui
connect(ui->comp_OtherServers, &CServerListSelector::serverChanged, this, &CLoginComponent::onSelectedServerChanged);
connect(ui->comp_VatsimServers, &CServerListSelector::serverChanged, this, &CLoginComponent::onSelectedServerChanged);
connect(ui->tw_Network, &QTabWidget::currentChanged, this, &CLoginComponent::onServerTabWidgetChanged);
connect(ui->pb_Cancel, &QPushButton::clicked, this, &CLoginComponent::loginCancelled);
connect(ui->pb_Ok, &QPushButton::clicked, this, &CLoginComponent::toggleNetworkConnection);
connect(ui->pb_OtherServersGotoSettings, &QPushButton::pressed, this, &CLoginComponent::requestNetworkSettings);
connect(ui->tb_MappingWizard, &QToolButton::clicked, this, &CLoginComponent::mappingWizard);
connect(&m_networkSetup, &CNetworkSetup::setupChanged, this, &CLoginComponent::reloadSetup, Qt::QueuedConnection);
ui->comp_FsdDetails->showEnableInfo(true);
ui->comp_FsdDetails->setFsdSetupEnabled(false);
@@ -144,19 +144,15 @@ namespace BlackGui
this->validateAircraftValues();
ui->editor_Pilot->validate();
this->onWebServiceDataRead(CEntityFlags::VatsimDataFile, CEntityFlags::ReadFinished, -1);
CServerList otherServers(m_otherTrafficNetworkServers.getThreadLocal());
// add a testserver when no servers can be loaded
if (otherServers.isEmpty() && CBuildConfig::isLocalDeveloperDebugBuild())
{
otherServers.push_back(sGui->getGlobalSetup().getFsdTestServersPlusHardcodedServers());
CLogMessage(this).info("Added servers for testing");
}
const CServerList otherServers(m_networkSetup.getOtherServersPlusTestServers());
ui->comp_OtherServers->setServers(otherServers);
connect(ui->pb_OverrideCredentialsVatsim, &QPushButton::clicked, this, &CLoginComponent::overrideCredentialsToPilot);
connect(ui->pb_OverrideCredentialsOtherServers, &QPushButton::clicked, this, &CLoginComponent::overrideCredentialsToPilot);
this->setUiLoginState(false);
const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM;
ui->tw_Network->setCurrentIndex(tab);
}
CLoginComponent::~CLoginComponent()
@@ -243,12 +239,8 @@ namespace BlackGui
const INetwork::LoginMode mode = ui->frp_LoginMode->getLoginMode();
switch (mode)
{
case INetwork::LoginStealth:
CLogMessage(this).info("login in stealth mode");
break;
case INetwork::LoginAsObserver:
CLogMessage(this).info("login in observer mode");
break;
case INetwork::LoginStealth: CLogMessage(this).info("login in stealth mode"); break;
case INetwork::LoginAsObserver: CLogMessage(this).info("login in observer mode"); break;
case INetwork::LoginNormal:
default:
break;
@@ -279,10 +271,10 @@ namespace BlackGui
if (msg.isSuccess())
{
Q_ASSERT_X(currentServer.isValidForLogin(), Q_FUNC_INFO, "invalid server");
m_lastServer.set(currentServer);
m_networkSetup.setLastServer(currentServer);
m_lastAircraftModel.set(ownAircraft.getModel());
ui->le_HomeBase->setText(currentServer.getUser().getHomeBase().asString());
if (vatsimLogin) { m_lastVatsimServer.set(currentServer); }
if (vatsimLogin) { m_networkSetup.setLastVatsimServer(currentServer); }
}
}
else
@@ -320,7 +312,7 @@ namespace BlackGui
CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
if (vatsimFsdServers.isEmpty()) { return; }
vatsimFsdServers.sortBy(&CServer::getName);
const CServer currentServer = m_lastVatsimServer.get();
const CServer currentServer = m_networkSetup.getLastVatsimServer();
ui->comp_VatsimServers->setServers(vatsimFsdServers, true);
ui->comp_VatsimServers->preSelect(currentServer.getName());
}
@@ -328,7 +320,7 @@ namespace BlackGui
void CLoginComponent::loadRememberedUserData()
{
const CServer lastServer = m_lastServer.get();
const CServer lastServer = m_networkSetup.getLastServer();
if (!lastServer.isNull())
{
@@ -360,12 +352,9 @@ namespace BlackGui
else if (s == ui->pb_OverrideCredentialsVatsim)
{
// the VATSIM server selected has no valid user credentials
server = m_lastVatsimServer.get();
}
else
{
return;
server = m_networkSetup.getLastVatsimServer();
}
else { return; }
ui->editor_Pilot->setUser(server.getUser(), true);
}
@@ -388,10 +377,11 @@ namespace BlackGui
bool CLoginComponent::hasContexts()
{
if (!sApp || !sApp->supportsContexts()) { return false; }
if (!sApp->getIContextSimulator()) { return false; }
if (!sApp->getIContextNetwork()) { return false; }
if (!sApp->getIContextOwnAircraft()) { return false; }
if (!sGui || !sGui->supportsContexts()) { return false; }
if (sGui->isShuttingDown()) { return false; }
if (!sGui->getIContextSimulator()) { return false; }
if (!sGui->getIContextNetwork()) { return false; }
if (!sGui->getIContextOwnAircraft()) { return false; }
return true;
}
@@ -425,7 +415,7 @@ namespace BlackGui
if (!server.getUser().hasValidVatsimId())
{
// normally VATSIM server have no valid user associated
const CUser user = m_lastVatsimServer.get().getUser();
const CUser user = m_networkSetup.getLastVatsimServer().getUser();
server.setUser(user);
}
return server;
@@ -547,10 +537,9 @@ namespace BlackGui
this->validateAircraftValues();
}
void CLoginComponent::reloadSettings()
void CLoginComponent::reloadSetup()
{
CServerList otherServers(m_otherTrafficNetworkServers.getThreadLocal());
ui->comp_OtherServers->setServers(otherServers);
ui->comp_OtherServers->setServers(m_networkSetup.getOtherServers());
}
void CLoginComponent::logoffCountdown()

View File

@@ -13,7 +13,7 @@
#define BLACKGUI_LOGINCOMPONENT_H
#include "blackcore/vatsim/vatsimsettings.h"
#include "blackcore/data/vatsimsetup.h"
#include "blackcore/data/networksetup.h"
#include "blackgui/settings/guisettings.h"
#include "blackgui/blackguiexport.h"
#include "blackgui/overlaymessagesframe.h"
@@ -60,6 +60,14 @@ namespace BlackGui
Q_OBJECT
public:
//! The tabs
enum Tab
{
LoginVATSIM,
LoginOthers,
LoginFSD
};
//! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories();
@@ -154,7 +162,7 @@ namespace BlackGui
void changedAirlineIcao(const BlackMisc::Aviation::CAirlineIcaoCode &icao);
//! Settings have been changed
void reloadSettings();
void reloadSetup();
//! Logoff countdown
void logoffCountdown();
@@ -215,10 +223,8 @@ namespace BlackGui
const QIcon m_iconPause {":/famfamfam/icons/famfamfam/icons/silk/control_pause_blue.png"};
const int LogoffIntervalSeconds = 20; //!< time before logoff
QTimer m_logoffCountdownTimer; //!< timer for logoff countdown
BlackMisc::CSettingReadOnly<BlackCore::Vatsim::TTrafficServers> m_otherTrafficNetworkServers { this, &CLoginComponent::reloadSettings };
BlackMisc::CData<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
BlackMisc::CData<BlackCore::Data::TVatsimLastServer> m_lastVatsimServer { this }; //!< recently used VATSIM server
BlackCore::Data::CNetworkSetup m_networkSetup; //!< servers last used
};
} // namespace
} // namespace