refs #859, improved sending of ICAO code/callsign updates

* use digest signal
* restructured updateOwnAircaftIcaoValuesFromGuiValues / updateOwnAircraftCallsignAndPilotFromGuiValues
* also send change signal when login UI becomes invisible
This commit is contained in:
Klaus Basan
2017-01-13 04:41:57 +01:00
committed by Mathew Sutcliffe
parent 8b9b540c22
commit 5f2955916c
3 changed files with 112 additions and 74 deletions

View File

@@ -85,7 +85,7 @@ namespace BlackGui
ui->selector_AircraftIcao->displayMode(CDbAircraftIcaoSelectorComponent::DisplayIcaoAndId);
ui->selector_AirlineIcao->displayMode(CDbAirlineIcaoSelectorComponent::DisplayVDesignatorAndId);
setOkButtonString(false);
this->setOkButtonString(false);
connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CLoginComponent::ps_loginCancelled);
connect(ui->bb_OkCancel, &QDialogButtonBox::accepted, this, &CLoginComponent::ps_toggleNetworkConnection);
connect(ui->pb_OtherServersGotoSettings, &QPushButton::pressed, this, &CLoginComponent::requestNetworkSettings);
@@ -171,8 +171,15 @@ namespace BlackGui
this->m_logoffCountdownTimer->stop(); // in any case stop the timer
if (currentWidget != this && currentWidget != this->parentWidget())
{
const bool wasVisible = this->m_visible;
this->m_visible = false;
this->m_logoffCountdownTimer->stop();
if (wasVisible)
{
// set own values, and send signals
this->setOwnModelAndIcaoValues();
}
}
else
{
@@ -228,34 +235,8 @@ namespace BlackGui
}
// sync values with GUI values
CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
CAircraftIcaoCode aircraftCode(ownAircraft.getAircraftIcaoCode());
CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode());
bool setIcaoCodes = false;
if (!ownAircraft.hasAircraftDesignator() && aircraftValues.ownAircraftIcao.hasValidDesignator())
{
aircraftCode = aircraftValues.ownAircraftIcao;
setIcaoCodes = true;
}
if (!ownAircraft.hasAircraftDesignator() && aircraftValues.ownAirlineIcao.hasValidDesignator())
{
airlineCode = aircraftValues.ownAirlineIcao;
setIcaoCodes = true;
}
if (ownAircraft.getCallsign() != aircraftValues.ownCallsign)
{
ownAircraft.setCallsign(aircraftValues.ownCallsign);
this->updateOwnCallsignAndPilotFromGuiValue();
}
if (setIcaoCodes)
{
ownAircraft.setIcaoCodes(aircraftCode, airlineCode);
sGui->getIContextOwnAircraft()->updateOwnIcaoCodes(ownAircraft.getAircraftIcaoCode(), ownAircraft.getAirlineIcaoCode());
}
this->updateOwnAircraftCallsignAndPilotFromGuiValues();
this->updateOwnAircaftIcaoValuesFromGuiValues();
// Login mode
INetwork::LoginMode mode = ui->gbp_LoginMode->getLoginMode();
@@ -396,7 +377,7 @@ namespace BlackGui
CUser CLoginComponent::getUserFromVatsimGuiValues() const
{
CVatsimValues values = getVatsimValuesFromGui();
const CVatsimValues values = this->getVatsimValuesFromGui();
CUser user(values.vatsimId, values.vatsimRealName, "", values.vatsimPassword, getCallsignFromGui());
user.setHomeBase(values.vatsimHomeAirport);
return user;
@@ -404,7 +385,7 @@ namespace BlackGui
CCallsign CLoginComponent::getCallsignFromGui() const
{
CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
return cs;
}
@@ -420,7 +401,7 @@ namespace BlackGui
void CLoginComponent::setOkButtonString(bool connected)
{
QString s = connected ? "Disconnect" : "Connect";
const QString s = connected ? "Disconnect" : "Connect";
ui->bb_OkCancel->button(QDialogButtonBox::Ok)->setText(s);
}
@@ -477,30 +458,42 @@ namespace BlackGui
}
}
this->updateOwnCallsignAndPilotFromGuiValue();
this->triggerDataChangedSignal(1500);
const bool changedOwnAircraftCallsignPilot = this->updateOwnAircraftCallsignAndPilotFromGuiValues();
const bool changedOwnAircraftIcaoValues = this->updateOwnAircaftIcaoValuesFromGuiValues();
if (changedOwnAircraftIcaoValues || changedOwnAircraftCallsignPilot)
{
emit this->loginDataChanged();
}
}
void CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty)
bool CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty)
{
bool changed = false;
if (!onlyIfEmpty || !ui->selector_AircraftIcao->isSet())
{
ui->selector_AircraftIcao->setAircraftIcao(model.getAircraftIcaoCode());
changed = ui->selector_AircraftIcao->setAircraftIcao(model.getAircraftIcaoCode());
}
if (!onlyIfEmpty || !ui->selector_AirlineIcao->isSet())
{
ui->selector_AirlineIcao->setAirlineIcao(model.getAirlineIcaoCode());
const bool c = ui->selector_AirlineIcao->setAirlineIcao(model.getAirlineIcaoCode());
changed |= c;
}
if (!onlyIfEmpty || ui->le_AircraftCombinedType->text().trimmed().isEmpty())
{
ui->le_AircraftCombinedType->setText(model.getAircraftIcaoCode().getCombinedType());
const QString combined(model.getAircraftIcaoCode().getCombinedType());
if (ui->le_AircraftCombinedType->text() != combined)
{
ui->le_AircraftCombinedType->setText(combined);
changed = true;
}
}
this->ps_validateAircraftValues();
const bool valid = this->ps_validateAircraftValues();
return valid ? changed : false;
}
bool CLoginComponent::ps_validateAircraftValues()
{
CGuiAircraftValues values = getAircraftValuesFromGui();
const CGuiAircraftValues values = getAircraftValuesFromGui();
const bool validCombinedType = CAircraftIcaoCode::isValidCombinedType(values.ownAircraftCombinedType);
ui->lblp_AircraftCombinedType->setTicked(validCombinedType);
@@ -599,10 +592,10 @@ namespace BlackGui
}
// check state of own aircraft
this->updateOwnCallsignAndPilotFromGuiValue();
this->updateOwnAircraftCallsignAndPilotFromGuiValues();
// let others know data changed
this->triggerDataChangedSignal(1500);
emit this->loginDataChanged();
}
void CLoginComponent::ps_mappingWizard()
@@ -670,11 +663,6 @@ namespace BlackGui
ui->le_SimulatorModel->setStyleSheet(sheet.arg(color));
}
void CLoginComponent::triggerDataChangedSignal(int deferTimeMs)
{
QTimer::singleShot(deferTimeMs, this, &CLoginComponent::loginDataChanged);
}
CAircraftModel CLoginComponent::getPrefillModel() const
{
CAircraftModel model = this->m_currentAircraftModel.get();
@@ -682,24 +670,60 @@ namespace BlackGui
return IContextOwnAircraft::getDefaultOwnAircraftModel();
}
void CLoginComponent::updateOwnCallsignAndPilotFromGuiValue()
bool CLoginComponent::updateOwnAircraftCallsignAndPilotFromGuiValues()
{
if (!sGui || !sGui->getIContextOwnAircraft()) { return; }
const CSimulatedAircraft ownAircaft(sGui->getIContextOwnAircraft()->getOwnAircraft());
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
const QString cs(ui->le_Callsign->text().trimmed().toUpper());
if (!cs.isEmpty() && ownAircaft.getCallsignAsString() != cs)
bool changedCallsign = false;
if (!cs.isEmpty() && ownAircraft.getCallsignAsString() != cs)
{
sGui->getIContextOwnAircraft()->updateOwnCallsign(CCallsign(cs));
const CCallsign callsign(cs);
sGui->getIContextOwnAircraft()->updateOwnCallsign(callsign);
ownAircraft.setCallsign(callsign); // also update
changedCallsign = true;
}
CUser pilot = ownAircaft.getPilot();
CUser pilot = ownAircraft.getPilot();
pilot.setRealName(CUser::beautifyRealName(ui->le_VatsimRealName->text()));
pilot.setHomeBase(CAirportIcaoCode(ui->le_VatsimHomeAirport->text()));
pilot.setId(ui->le_VatsimId->text());
pilot.setCallsign(CCallsign(cs));
if (ownAircaft.getPilot() != pilot)
bool changedPilot = false;
if (ownAircraft.getPilot() != pilot)
{
sGui->getIContextOwnAircraft()->updateOwnAircraftPilot(pilot);
// it can be that the callsign was changed and this results in unchanged here
changedPilot = sGui->getIContextOwnAircraft()->updateOwnAircraftPilot(pilot);
}
return changedCallsign || changedPilot;
}
bool CLoginComponent::updateOwnAircaftIcaoValuesFromGuiValues()
{
if (!sGui || !sGui->getIContextOwnAircraft()) { return false; }
const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
const CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
CAircraftIcaoCode aircraftCode(ownAircraft.getAircraftIcaoCode());
CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode());
bool changedIcaoCodes = false;
if (aircraftValues.ownAircraftIcao.hasValidDesignator() && aircraftValues.ownAircraftIcao != aircraftCode)
{
aircraftCode = aircraftValues.ownAircraftIcao;
changedIcaoCodes = true;
}
if (aircraftValues.ownAirlineIcao.hasValidDesignator() && aircraftValues.ownAirlineIcao != airlineCode)
{
airlineCode = aircraftValues.ownAirlineIcao;
changedIcaoCodes = true;
}
if (changedIcaoCodes)
{
sGui->getIContextOwnAircraft()->updateOwnIcaoCodes(aircraftCode, airlineCode);
}
return changedIcaoCodes;
}
} // namespace
} // namespace

View File

@@ -16,13 +16,14 @@
#include "blackcore/data/vatsimsetup.h"
#include "blackgui/blackguiexport.h"
#include "blackgui/settings/guisettings.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/simulation/simulatedaircraft.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"
#include "blackmisc/simulation/simulatedaircraft.h"
#include <QFrame>
#include <QObject>
@@ -50,8 +51,7 @@ namespace BlackGui
/*!
* Login component to flight network
*/
class BLACKGUI_EXPORT CLoginComponent :
public QFrame
class BLACKGUI_EXPORT CLoginComponent : public QFrame
{
Q_OBJECT
@@ -66,7 +66,7 @@ namespace BlackGui
void setAutoPopupWizad(bool autoPopup);
//! Destructor
~CLoginComponent();
virtual ~CLoginComponent();
signals:
//! Login
@@ -79,8 +79,12 @@ namespace BlackGui
void requestNetworkSettings();
//! Relevant login data changed
//! \private normally loginDataChangedDigest will be used
void loginDataChanged();
//! Relevant login data changed (digest version)
void loginDataChangedDigest();
public slots:
//! Main info area changed
void mainInfoAreaChanged(const QWidget *currentWidget);
@@ -142,8 +146,7 @@ namespace BlackGui
QString vatsimHomeAirport;
};
//! Load from settings
void loadRememberedVatsimData();
// -------------- values from GUI -----------------
//! Values from GUI
CGuiAircraftValues getAircraftValuesFromGui() const;
@@ -157,6 +160,25 @@ 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 from GUI -----------------
//! Update own callsign (own aircraft from what is set in the GUI)
//! \return changed?
bool updateOwnAircraftCallsignAndPilotFromGuiValues();
//! Update own ICAO values (own aircraft from what is set in the GUI)
//! \return changed?
bool updateOwnAircaftIcaoValuesFromGuiValues();
// -------------- others -----------------
//! Own model and ICAO data for GUI and own aircraft
void setOwnModelAndIcaoValues();
//! Selected server (VATSIM)
BlackMisc::Network::CServer getCurrentVatsimServer() const;
@@ -172,29 +194,21 @@ namespace BlackGui
//! Logoff countdown
void startLogoffTimerCountdown();
//! Own model and ICAO data
void setOwnModelAndIcaoValues();
//! Set ICAO values
void setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty);
//! Completers
void initCompleters(BlackMisc::Network::CEntityFlags::Entity entity);
//! Highlight model field according to model data
void highlightModelField(const BlackMisc::Simulation::CAircraftModel &model = {});
//! Trigger the signal that data have been changed
void triggerDataChangedSignal(int deferTimeMs);
//! Load from settings
void loadRememberedVatsimData();
//! Get a prefill model
BlackMisc::Simulation::CAircraftModel getPrefillModel() const;
//! Update own callsign (own aircraft from what is set in the GUI)
void updateOwnCallsignAndPilotFromGuiValue();
QScopedPointer<Ui::CLoginComponent> ui;
QScopedPointer<CDbQuickMappingWizard> m_mappingWizard;
BlackMisc::CDigestSignal m_changedLoginDataDigestSignal { this, &CLoginComponent::loginDataChanged, &CLoginComponent::loginDataChangedDigest, 1500, 10 };
bool m_autoPopupWizard = false; //!< automatically popup wizard if mapping is needed
bool m_visible = false; //!< is this component selected?
const int LogoffIntervalSeconds = 20; //!< time before logoff

View File

@@ -212,7 +212,7 @@ void SwiftGuiStd::initGuiSignals()
connect(ui->comp_Login, &CLoginComponent::loginOrLogoffCancelled, this, &SwiftGuiStd::ps_setMainPageToInfoArea);
connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, this, &SwiftGuiStd::ps_setMainPageToInfoArea);
connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet);
connect(ui->comp_Login, &CLoginComponent::loginDataChanged, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet);
connect(ui->comp_Login, &CLoginComponent::loginDataChangedDigest, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet);
connect(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged);
connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings, ui->comp_MainInfoArea->getFlightPlanComponent(), [ = ]()
{