mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25: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 <QToolButton>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
using namespace BlackConfig;
|
using namespace BlackConfig;
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
@@ -153,6 +154,13 @@ namespace BlackGui
|
|||||||
|
|
||||||
const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM;
|
const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM;
|
||||||
ui->tw_Network->setCurrentIndex(tab);
|
ui->tw_Network->setCurrentIndex(tab);
|
||||||
|
|
||||||
|
QPointer<CLoginComponent> myself(this);
|
||||||
|
QTimer::singleShot(5000, this, [ = ]
|
||||||
|
{
|
||||||
|
if (!myself) { return; }
|
||||||
|
this->updateGui();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CLoginComponent::~CLoginComponent()
|
CLoginComponent::~CLoginComponent()
|
||||||
@@ -287,11 +295,7 @@ namespace BlackGui
|
|||||||
CLogMessage::preformatted(msg);
|
CLogMessage::preformatted(msg);
|
||||||
if (msg.isSuccess())
|
if (msg.isSuccess())
|
||||||
{
|
{
|
||||||
QString ac(ownAircraft.getCallsignAsString() % QLatin1Char(' ') % ownAircraft.getAircraftIcaoCodeDesignator());
|
this->setGuiLoginAsValues(ownAircraft);
|
||||||
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);
|
|
||||||
emit this->loginOrLogoffSuccessful();
|
emit this->loginOrLogoffSuccessful();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -373,7 +377,7 @@ namespace BlackGui
|
|||||||
ui->editor_Pilot->setUser(server.getUser(), true);
|
ui->editor_Pilot->setUser(server.getUser(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLoginComponent::hasContexts()
|
bool CLoginComponent::hasValidContexts()
|
||||||
{
|
{
|
||||||
if (!sGui || !sGui->supportsContexts()) { return false; }
|
if (!sGui || !sGui->supportsContexts()) { return false; }
|
||||||
if (sGui->isShuttingDown()) { return false; }
|
if (sGui->isShuttingDown()) { return false; }
|
||||||
@@ -433,7 +437,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CLoginComponent::setOwnModelAndIcaoValues()
|
void CLoginComponent::setOwnModelAndIcaoValues()
|
||||||
{
|
{
|
||||||
if (!this->hasContexts()) { return; }
|
if (!this->hasValidContexts()) { return; }
|
||||||
CAircraftModel model;
|
CAircraftModel model;
|
||||||
const bool simulating = sGui->getIContextSimulator() &&
|
const bool simulating = sGui->getIContextSimulator() &&
|
||||||
(sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
|
(sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
|
||||||
@@ -501,6 +505,15 @@ namespace BlackGui
|
|||||||
return valid ? changed : false;
|
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()
|
bool CLoginComponent::validateAircraftValues()
|
||||||
{
|
{
|
||||||
const CGuiAircraftValues values = this->getAircraftValuesFromGui();
|
const CGuiAircraftValues values = this->getAircraftValuesFromGui();
|
||||||
@@ -673,7 +686,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
bool CLoginComponent::updateOwnAircraftCallsignAndPilotFromGuiValues()
|
bool CLoginComponent::updateOwnAircraftCallsignAndPilotFromGuiValues()
|
||||||
{
|
{
|
||||||
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
|
if (!this->hasValidContexts()) { return false; }
|
||||||
CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
||||||
const QString cs(ui->le_Callsign->text().trimmed().toUpper());
|
const QString cs(ui->le_Callsign->text().trimmed().toUpper());
|
||||||
bool changedCallsign = false;
|
bool changedCallsign = false;
|
||||||
@@ -701,7 +714,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
bool CLoginComponent::updateOwnAircaftIcaoValuesFromGuiValues()
|
bool CLoginComponent::updateOwnAircaftIcaoValuesFromGuiValues()
|
||||||
{
|
{
|
||||||
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
|
if (!this->hasValidContexts()) { return false; }
|
||||||
const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
|
||||||
const CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
|
const CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
|
||||||
|
|
||||||
@@ -727,5 +740,21 @@ namespace BlackGui
|
|||||||
|
|
||||||
return changedIcaoCodes;
|
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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QTimer>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -115,12 +116,6 @@ namespace BlackGui
|
|||||||
//! Callsign from GUI
|
//! Callsign from GUI
|
||||||
BlackMisc::Aviation::CCallsign getCallsignFromGui() const;
|
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)
|
//! Update own callsign (own aircraft from what is set in the GUI)
|
||||||
//! \return changed?
|
//! \return changed?
|
||||||
bool updateOwnAircraftCallsignAndPilotFromGuiValues();
|
bool updateOwnAircraftCallsignAndPilotFromGuiValues();
|
||||||
@@ -129,6 +124,18 @@ namespace BlackGui
|
|||||||
//! \return changed?
|
//! \return changed?
|
||||||
bool updateOwnAircaftIcaoValuesFromGuiValues();
|
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 -----------------
|
// -------------- others -----------------
|
||||||
|
|
||||||
//! Selected server (VATSIM)
|
//! Selected server (VATSIM)
|
||||||
@@ -206,8 +213,8 @@ namespace BlackGui
|
|||||||
//! Tab widget (server) changed
|
//! Tab widget (server) changed
|
||||||
void onServerTabWidgetChanged(int index);
|
void onServerTabWidgetChanged(int index);
|
||||||
|
|
||||||
//! Has contexts
|
//! Has contexts?
|
||||||
bool hasContexts();
|
bool hasValidContexts();
|
||||||
|
|
||||||
static const int OverlayMessageMs = 5000;
|
static const int OverlayMessageMs = 5000;
|
||||||
QScopedPointer<Ui::CLoginComponent> ui;
|
QScopedPointer<Ui::CLoginComponent> ui;
|
||||||
|
|||||||
Reference in New Issue
Block a user