mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T301, login component can re-init and hence reconnect to core
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include <QToolButton>
|
||||
#include <QStringBuilder>
|
||||
#include <QtGlobal>
|
||||
#include <QPointer>
|
||||
|
||||
using namespace BlackConfig;
|
||||
using namespace BlackMisc;
|
||||
@@ -153,6 +154,13 @@ namespace BlackGui
|
||||
|
||||
const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM;
|
||||
ui->tw_Network->setCurrentIndex(tab);
|
||||
|
||||
QPointer<CLoginComponent> myself(this);
|
||||
QTimer::singleShot(5000, this, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
this->updateGui();
|
||||
});
|
||||
}
|
||||
|
||||
CLoginComponent::~CLoginComponent()
|
||||
@@ -287,11 +295,7 @@ namespace BlackGui
|
||||
CLogMessage::preformatted(msg);
|
||||
if (msg.isSuccess())
|
||||
{
|
||||
QString ac(ownAircraft.getCallsignAsString() % QLatin1Char(' ') % ownAircraft.getAircraftIcaoCodeDesignator());
|
||||
if (ownAircraft.hasAirlineDesignator()) { ac += QLatin1Char(' ') % ownAircraft.getAirlineIcaoCodeDesignator(); }
|
||||
if (!ownAircraft.getAircraftIcaoCombinedType().isEmpty()) { ac += QLatin1Char(' ') % ownAircraft.getAircraftIcaoCode().getCombinedType(); }
|
||||
ui->le_LoginSince->setText(QDateTime::currentDateTimeUtc().toString());
|
||||
ui->le_LoginAsAircaft->setText(ac);
|
||||
this->setGuiLoginAsValues(ownAircraft);
|
||||
emit this->loginOrLogoffSuccessful();
|
||||
}
|
||||
else
|
||||
@@ -373,7 +377,7 @@ namespace BlackGui
|
||||
ui->editor_Pilot->setUser(server.getUser(), true);
|
||||
}
|
||||
|
||||
bool CLoginComponent::hasContexts()
|
||||
bool CLoginComponent::hasValidContexts()
|
||||
{
|
||||
if (!sGui || !sGui->supportsContexts()) { return false; }
|
||||
if (sGui->isShuttingDown()) { return false; }
|
||||
@@ -433,7 +437,7 @@ namespace BlackGui
|
||||
|
||||
void CLoginComponent::setOwnModelAndIcaoValues()
|
||||
{
|
||||
if (!this->hasContexts()) { return; }
|
||||
if (!this->hasValidContexts()) { return; }
|
||||
CAircraftModel model;
|
||||
const bool simulating = sGui->getIContextSimulator() &&
|
||||
(sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
|
||||
@@ -501,6 +505,15 @@ namespace BlackGui
|
||||
return valid ? changed : false;
|
||||
}
|
||||
|
||||
void CLoginComponent::setGuiLoginAsValues(const CSimulatedAircraft &ownAircraft)
|
||||
{
|
||||
QString ac(ownAircraft.getCallsignAsString() % QLatin1Char(' ') % ownAircraft.getAircraftIcaoCodeDesignator());
|
||||
if (ownAircraft.hasAirlineDesignator()) { ac += QLatin1Char(' ') % ownAircraft.getAirlineIcaoCodeDesignator(); }
|
||||
if (!ownAircraft.getAircraftIcaoCombinedType().isEmpty()) { ac += QLatin1Char(' ') % ownAircraft.getAircraftIcaoCode().getCombinedType(); }
|
||||
ui->le_LoginSince->setText(QDateTime::currentDateTimeUtc().toString());
|
||||
ui->le_LoginAsAircaft->setText(ac);
|
||||
}
|
||||
|
||||
bool CLoginComponent::validateAircraftValues()
|
||||
{
|
||||
const CGuiAircraftValues values = this->getAircraftValuesFromGui();
|
||||
@@ -673,7 +686,7 @@ namespace BlackGui
|
||||
|
||||
bool CLoginComponent::updateOwnAircraftCallsignAndPilotFromGuiValues()
|
||||
{
|
||||
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
|
||||
if (!this->hasValidContexts()) { return false; }
|
||||
CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
||||
const QString cs(ui->le_Callsign->text().trimmed().toUpper());
|
||||
bool changedCallsign = false;
|
||||
@@ -701,7 +714,7 @@ namespace BlackGui
|
||||
|
||||
bool CLoginComponent::updateOwnAircaftIcaoValuesFromGuiValues()
|
||||
{
|
||||
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
|
||||
if (!this->hasValidContexts()) { return false; }
|
||||
const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
||||
const CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
|
||||
|
||||
@@ -727,5 +740,21 @@ namespace BlackGui
|
||||
|
||||
return changedIcaoCodes;
|
||||
}
|
||||
|
||||
void CLoginComponent::updateGui()
|
||||
{
|
||||
if (!this->hasValidContexts()) { return; }
|
||||
IContextNetwork *nwc = sGui->getIContextNetwork();
|
||||
const bool connected = nwc->isConnected();
|
||||
if (!connected) { return; }
|
||||
this->setUiLoginState(connected);
|
||||
this->setOwnModelAndIcaoValues();
|
||||
const CServer server = nwc->getConnectedServer();
|
||||
ui->le_HomeBase->setText(server.getUser().getHomeBase().asString());
|
||||
ui->frp_CurrentServer->setServer(server);
|
||||
ui->frp_LoginMode->setLoginMode(nwc->getLoginMode());
|
||||
const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
|
||||
this->setGuiLoginAsValues(ownAircraft);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <QFrame>
|
||||
#include <QIcon>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QString>
|
||||
@@ -115,12 +116,6 @@ namespace BlackGui
|
||||
//! Callsign from GUI
|
||||
BlackMisc::Aviation::CCallsign getCallsignFromGui() const;
|
||||
|
||||
//! Set ICAO values
|
||||
//! \return changed values?
|
||||
bool setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty);
|
||||
|
||||
// -------------- values to GUI -----------------
|
||||
|
||||
//! Update own callsign (own aircraft from what is set in the GUI)
|
||||
//! \return changed?
|
||||
bool updateOwnAircraftCallsignAndPilotFromGuiValues();
|
||||
@@ -129,6 +124,18 @@ namespace BlackGui
|
||||
//! \return changed?
|
||||
bool updateOwnAircaftIcaoValuesFromGuiValues();
|
||||
|
||||
// -------------- values to GUI -----------------
|
||||
|
||||
//! Update GUI values
|
||||
void updateGui();
|
||||
|
||||
//! Set ICAO values
|
||||
//! \return changed values?
|
||||
bool setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty);
|
||||
|
||||
//! Set the "login as" values
|
||||
void setGuiLoginAsValues(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
|
||||
|
||||
// -------------- others -----------------
|
||||
|
||||
//! Selected server (VATSIM)
|
||||
@@ -206,8 +213,8 @@ namespace BlackGui
|
||||
//! Tab widget (server) changed
|
||||
void onServerTabWidgetChanged(int index);
|
||||
|
||||
//! Has contexts
|
||||
bool hasContexts();
|
||||
//! Has contexts?
|
||||
bool hasValidContexts();
|
||||
|
||||
static const int OverlayMessageMs = 5000;
|
||||
QScopedPointer<Ui::CLoginComponent> ui;
|
||||
|
||||
Reference in New Issue
Block a user