refs #780, fixes login/flightplan preset

* empty airline is valid
* sync with flightplan (new signal to indicate changed login values)
* better preset of own model
This commit is contained in:
Klaus Basan
2016-10-21 15:38:25 +02:00
parent 492649c061
commit cdea8cff95
12 changed files with 127 additions and 25 deletions

View File

@@ -86,7 +86,7 @@ namespace BlackSample
// User parsing
CUser user("12345", "Joe KING KGLC");
out << user.getRealName() << user.getHomebase() << endl;
out << user.getRealName() << user.getHomeBase() << endl;
// ATC List
CAtcStationList atcList;

View File

@@ -59,6 +59,7 @@ namespace BlackGui
ui(new Ui::CFlightPlanComponent)
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui");
Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "missing web services");
// UI
ui->setupUi(this);
@@ -119,7 +120,10 @@ namespace BlackGui
{
if (this->m_flightPlan.wasSentOrLoaded()) { return; } // when loaded or sent do not override
if (!sGui->getIContextOwnAircraft()) { return; }
this->prefillWithAircraftData(sGui->getIContextOwnAircraft()->getOwnAircraft());
const CSimulatedAircraft ownAircraft(sGui->getIContextOwnAircraft()->getOwnAircraft());
this->prefillWithAircraftData(ownAircraft);
this->prefillWithUserData(ownAircraft.getPilot());
}
void CFlightPlanComponent::prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft)
@@ -139,6 +143,18 @@ namespace BlackGui
}
}
void CFlightPlanComponent::prefillWithUserData(const Network::CUser &user)
{
if (user.hasValidRealName())
{
ui->le_PilotsName->setText(user.getRealName());
}
if (user.hasHomeBase())
{
ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode());
}
}
void CFlightPlanComponent::fillWithFlightPlanData(const BlackMisc::Aviation::CFlightPlan &flightPlan)
{
ui->le_AlternateAirport->setText(flightPlan.getAlternateAirportIcao().asString());

View File

@@ -14,6 +14,7 @@
#include "blackgui/blackguiexport.h"
#include "blackmisc/aviation/flightplan.h"
#include "blackmisc/network/user.h"
#include "blackmisc/identifier.h"
#include "blackmisc/statusmessagelist.h"
@@ -52,6 +53,9 @@ namespace BlackGui
//! Prefill with aircraft data
void prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
//! Prefill with user data
void prefillWithUserData(const BlackMisc::Network::CUser &user);
//! Prefill with aircraft dara
void fillWithFlightPlanData(const BlackMisc::Aviation::CFlightPlan &flightPlan);

View File

@@ -246,7 +246,7 @@
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="lbl_PilotsNameAndHomebase">
<widget class="QLabel" name="lbl_PilotsNameAndHomeBase">
<property name="text">
<string>14. Pilots name / homebase</string>
</property>
@@ -447,7 +447,7 @@
</widget>
</item>
<item row="9" column="3">
<widget class="QLineEdit" name="le_PilotsHomebase"/>
<widget class="QLineEdit" name="le_PilotsHomeBase"/>
</item>
<item row="6" column="3">
<widget class="QLabel" name="lbl_AlternateAirport">
@@ -1027,7 +1027,7 @@
<tabstop>pb_RemarksGenerator</tabstop>
<tabstop>pte_Remarks</tabstop>
<tabstop>le_PilotsName</tabstop>
<tabstop>le_PilotsHomebase</tabstop>
<tabstop>le_PilotsHomeBase</tabstop>
<tabstop>pb_Reset</tabstop>
<tabstop>pb_Load</tabstop>
<tabstop>pb_Send</tabstop>

View File

@@ -248,7 +248,7 @@ namespace BlackGui
if (ownAircraft.getCallsign() != aircraftValues.ownCallsign)
{
ownAircraft.setCallsign(aircraftValues.ownCallsign);
sGui->getIContextOwnAircraft()->updateOwnCallsign(ownAircraft.getCallsign());
this->updateOwnCallsignAndPilotFromGuiValue();
}
if (setIcaoCodes)
@@ -354,7 +354,7 @@ namespace BlackGui
ui->le_Callsign->setText(lastUser.getCallsign().asString());
ui->le_VatsimId->setText(lastUser.getId());
ui->le_VatsimPassword->setText(lastUser.getPassword());
ui->le_VatsimHomeAirport->setText(lastUser.getHomebase().asString());
ui->le_VatsimHomeAirport->setText(lastUser.getHomeBase().asString());
ui->le_VatsimRealName->setText(lastUser.getRealName());
}
else
@@ -393,7 +393,7 @@ namespace BlackGui
{
CVatsimValues values = getVatsimValuesFromGui();
CUser user(values.vatsimId, values.vatsimRealName, "", values.vatsimPassword, getCallsignFromGui());
user.setHomebase(values.vatsimHomeAirport);
user.setHomeBase(values.vatsimHomeAirport);
return user;
}
@@ -450,20 +450,29 @@ namespace BlackGui
}
else
{
static const CAircraftModel defaultModel(
"", CAircraftModel::TypeOwnSimulatorModel, "default model",
CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0));
model = this->m_currentAircraftModel.get();
if (!model.hasAircraftDesignator()) { model = defaultModel; }
model = this->getPrefillModel();
ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); //! \todo Set observer mode without simulator, currently not working in OBS mode
ui->le_SimulatorModel->setText("");
this->highlightModelField();
}
if (model.hasAircraftDesignator())
// reset the model
if (model.isLoadedFromDb())
{
// full model from DB, take all values
this->setGuiIcaoValues(model, false);
}
else
{
if (model.hasAircraftDesignator())
{
// typed in model, override unempty values only
this->setGuiIcaoValues(model, true);
}
}
this->updateOwnCallsignAndPilotFromGuiValue();
this->triggerDataChangedSignal(1500);
}
void CLoginComponent::setGuiIcaoValues(const CAircraftModel &model, bool onlyIfEmpty)
@@ -491,7 +500,8 @@ namespace BlackGui
const bool validCombinedType = CAircraftIcaoCode::isValidCombinedType(values.ownAircraftCombinedType);
ui->lblp_AircraftCombinedType->setTicked(validCombinedType);
const bool validAirlineDesignator = values.ownAirlineIcao.hasValidDesignator();
// airline is optional, e.g. C172 has no airline
const bool validAirlineDesignator = values.ownAirlineIcao.hasValidDesignator() || values.ownAirlineIcao.getDesignator().isEmpty();
ui->lblp_AirlineIcao->setTicked(validAirlineDesignator);
const bool validAircraftDesignator = values.ownAircraftIcao.hasValidDesignator();
@@ -566,6 +576,7 @@ namespace BlackGui
void CLoginComponent::ps_simulatorModelChanged(const CAircraftModel &model)
{
Q_ASSERT_X(sGui && sGui->getIContextNetwork(), Q_FUNC_INFO, "Missing context");
const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected();
if (isConnected) { return; }
const QString modelStr(model.hasModelString() ? model.getModelString() : "<unknown>");
@@ -581,6 +592,12 @@ namespace BlackGui
{
this->ps_mappingWizard();
}
// check state of own aircraft
this->updateOwnCallsignAndPilotFromGuiValue();
// let others know data changed
this->triggerDataChangedSignal(1500);
}
void CLoginComponent::ps_mappingWizard()
@@ -647,5 +664,54 @@ namespace BlackGui
static const QString sheet("background-color: %1;");
ui->le_SimulatorModel->setStyleSheet(sheet.arg(color));
}
void CLoginComponent::triggerDataChangedSignal(int deferTimeMs)
{
QTimer::singleShot(deferTimeMs, this, &CLoginComponent::loginDataChanged);
}
CAircraftModel CLoginComponent::getPrefillModel() const
{
// if all fails
static const CAircraftModel defaultModel(
"", CAircraftModel::TypeOwnSimulatorModel, "default model",
CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0));
CAircraftModel model = this->m_currentAircraftModel.get();
if (model.hasAircraftDesignator()) { return model; }
// create one from DB data
if (sGui && sGui->hasWebDataServices())
{
const CAircraftIcaoCode icao = sGui->getWebDataServices()->getAircraftIcaoCodeForDesignator("C172");
const CLivery livery = sGui->getWebDataServices()->getLiveryForCombinedCode("_CC_WHITE_WHITE");
model = CAircraftModel("", CAircraftModel::TypeOwnSimulatorModel);
model.setLivery(livery);
model.setAircraftIcaoCode(icao);
return model;
}
return defaultModel;
}
void CLoginComponent::updateOwnCallsignAndPilotFromGuiValue()
{
if (!sGui || !sGui->getIContextOwnAircraft()) { return; }
const CSimulatedAircraft ownAircaft(sGui->getIContextOwnAircraft()->getOwnAircraft());
const QString cs(ui->le_Callsign->text().trimmed().toUpper());
if (!cs.isEmpty() && ownAircaft.getCallsignAsString() != cs)
{
sGui->getIContextOwnAircraft()->updateOwnCallsign(CCallsign(cs));
}
CUser pilot = ownAircaft.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)
{
sGui->getIContextOwnAircraft()->updateOwnAircraftPilot(pilot);
}
}
} // namespace
} // namespace

View File

@@ -78,6 +78,9 @@ namespace BlackGui
//! Request network settings
void requestNetworkSettings();
//! Relevant login data changed
void loginDataChanged();
public slots:
//! Main info area chnaged
void mainInfoAreaChanged(const QWidget *currentWidget);
@@ -181,11 +184,20 @@ namespace BlackGui
//! 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);
//! 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;
bool m_autoPopupWizard = false; //!< automatically popup wizard if mapping is needed
bool m_visible = false; //!< is this component selected?
const int LogoffIntervalSeconds = 10; //!< time before logoff
const int LogoffIntervalSeconds = 20; //!< time before logoff
QTimer *m_logoffCountdownTimer { nullptr }; //!< timer used logoff countdown
BlackMisc::CSettingReadOnly<BlackCore::Vatsim::TTrafficServers> m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings };
BlackMisc::CSetting<BlackGui::Settings::TOwnAircraftModel> m_currentAircraftModel { this }; //!< current settings of aircraft

View File

@@ -99,7 +99,7 @@ namespace BlackGui
if (aircraft.hasValidRealName())
{
i += " - ";
i += aircraft.getPilotRealname();
i += aircraft.getPilotRealName();
}
items.append(i);
}

View File

@@ -194,7 +194,7 @@ namespace BlackMisc
{
if (this->m_controller == otherStation.getController()) { return; }
CUser otherController = otherStation.getController();
this->m_controller.syncronizeData(otherController);
this->m_controller.synchronizeData(otherController);
otherStation.setController(otherController);
}

View File

@@ -103,7 +103,7 @@ namespace BlackMisc
int pos = match.capturedStart(0);
QString icao = match.captured(0).trimmed().right(4);
rn = rn.left(pos).trimmed();
this->setHomebase(CAirportIcaoCode(icao));
this->setHomeBase(CAirportIcaoCode(icao));
}
}
@@ -130,7 +130,7 @@ namespace BlackMisc
if (!this->hasValidCallsign()) { this->setCallsign(otherUser.getCallsign()); }
}
void CUser::syncronizeData(CUser &otherUser)
void CUser::synchronizeData(CUser &otherUser)
{
if (this == &otherUser) { return; }
this->updateMissingParts(otherUser);
@@ -239,7 +239,7 @@ namespace BlackMisc
case IndexRealName:
return this->m_realname.compare(compareValue.getRealName(), Qt::CaseInsensitive);
case IndexHomebase:
return this->m_homebase.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getHomebase());
return this->m_homebase.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getHomeBase());
case IndexCallsign:
return this->m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign());
default:

View File

@@ -109,10 +109,13 @@ namespace BlackMisc
void setId(const QString &id) { m_id = id.trimmed(); }
//! Homebase
const BlackMisc::Aviation::CAirportIcaoCode &getHomebase() const { return this->m_homebase; }
const BlackMisc::Aviation::CAirportIcaoCode &getHomeBase() const { return this->m_homebase; }
//! Set homebase
void setHomebase(const BlackMisc::Aviation::CAirportIcaoCode &homebase) { this->m_homebase = homebase; }
void setHomeBase(const BlackMisc::Aviation::CAirportIcaoCode &homebase) { this->m_homebase = homebase; }
//! Has home base?
bool hasHomeBase() const { return !this->m_homebase.isEmpty(); }
//! Get associated callsign.
const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_callsign; }
@@ -133,7 +136,7 @@ namespace BlackMisc
int comparePropertyByIndex(const CPropertyIndex &index, const CUser &compareValue) const;
//! This and another user exchange missing data, This user has priority and overrides first.
void syncronizeData(CUser &otherUser);
void synchronizeData(CUser &otherUser);
//! Update missing parts in this object
void updateMissingParts(const CUser &otherUser);

View File

@@ -114,7 +114,7 @@ namespace BlackMisc
const BlackMisc::Network::CUser &getPilot() const { return m_pilot; }
//! Get user's real name
QString getPilotRealname() const { return m_pilot.getRealName(); }
QString getPilotRealName() const { return m_pilot.getRealName(); }
//! Get user's real id
QString getPilotId() { return m_pilot.getId(); }

View File

@@ -214,6 +214,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(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged);
connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings, ui->comp_MainInfoArea->getFlightPlanComponent(), [ = ]()
{