refs #690, remember last login data

* cache/setting for last values
* integrated in login component
* allow to set default value for server selection
This commit is contained in:
Klaus Basan
2016-06-27 20:59:09 +02:00
parent 42fdcea72c
commit b4a9531357
7 changed files with 140 additions and 58 deletions

View File

@@ -43,8 +43,7 @@ namespace BlackCore
IndexDataFiles,
IndexMetarFiles,
IndexFsdServers,
IndexCVoiceServers,
IndexLastLoginUser
IndexCVoiceServers
};
//! Default constructor
@@ -74,9 +73,6 @@ namespace BlackCore
//! FSD test servers
const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; }
//! User for last login
const BlackMisc::Network::CUser &getLastLoginUser() const { return m_lastLoginUser; }
//! Set FSD servers
void setFsdServers(const BlackMisc::Network::CServerList &servers) { m_fsdServers = servers; }
@@ -86,9 +82,6 @@ namespace BlackCore
//! Set voice servers
void setVoiceServers(const BlackMisc::Network::CServerList &servers) { m_voiceServers = servers; }
//! User for last login
void setLastLoginUser(const BlackMisc::Network::CUser &user) { m_lastLoginUser = user; }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
@@ -107,7 +100,6 @@ namespace BlackCore
BlackMisc::Network::CUrlList m_metarFileUrls; //!< METAR files
BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers
BlackMisc::Network::CServerList m_voiceServers; //!< voice servers
BlackMisc::Network::CUser m_lastLoginUser; //!< last login user
BLACK_METACLASS(
CVatsimSetup,
@@ -116,7 +108,6 @@ namespace BlackCore
BLACK_METAMEMBER(metarFileUrls),
BLACK_METAMEMBER(fsdServers),
BLACK_METAMEMBER(voiceServers),
BLACK_METAMEMBER(lastLoginUser),
BLACK_METAMEMBER(timestampMSecsSinceEpoch)
);
};
@@ -125,7 +116,17 @@ namespace BlackCore
struct VatsimSetup : public BlackMisc::CDataTrait<CVatsimSetup>
{
//! Key in data cache
static const char *key() { return "vatsim"; }
static const char *key() { return "vatsimsetup"; }
//! First load is synchronous
static constexpr bool isPinned() { return true; }
};
//! Trait for currently used VATSIM server and user
struct VatsimCurrentServer : public BlackMisc::CDataTrait<BlackMisc::Network::CServer>
{
//! Key in data cache
static const char *key() { return "vatsimserver"; }
//! First load is synchronous
static constexpr bool isPinned() { return true; }

View File

@@ -85,8 +85,8 @@ namespace BlackGui
this->ui->lblp_VatsimPassword->setToolTips("ok", "wrong");
this->ui->lblp_VatsimRealName->setToolTips("ok", "wrong");
// Settings loaded
this->loadFromSettings();
// Stored data
this->loadRememberedVatsimData();
// Remark: The validators affect the signals such as returnPressed, editingFinished
// So I use no ranges in the CUpperCaseValidators, as this disables the signals for invalid values
@@ -137,7 +137,7 @@ namespace BlackGui
otherServers.push_back(sGui->getGlobalSetup().getFsdTestServersPlusHardcodedServers());
CLogMessage(this).info("Added servers for testing");
}
this->ui->cbp_OtherServers->setServers(otherServers);
this->ui->comp_OtherServers->setServers(otherServers);
}
CLoginComponent::~CLoginComponent()
@@ -180,12 +180,14 @@ namespace BlackGui
void CLoginComponent::ps_toggleNetworkConnection()
{
bool isConnected = sGui->getIContextNetwork()->isConnected();
const bool isConnected = sGui->getIContextNetwork()->isConnected();
const bool vatsimLogin = (this->ui->tw_Network->currentWidget() == this->ui->pg_NetworkVatsim);
CServer currentServer; // used for login
CSimulatedAircraft ownAircraft; // used own aircraft
CStatusMessage msg;
if (!isConnected)
{
bool vatsimLogin = (this->ui->tw_Network->currentWidget() == this->ui->pg_NetworkVatsim);
if (!this->ps_validateAircraftValues())
{
CLogMessage(this).warning("Invalid aircraft data, login not possible");
@@ -200,7 +202,7 @@ namespace BlackGui
// sync values with GUI values
CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui();
CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
CAircraftIcaoCode aircraftCode(ownAircraft.getAircraftIcaoCode());
CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode());
@@ -244,11 +246,10 @@ namespace BlackGui
}
// Server
CServer currentServer;
if (vatsimLogin)
{
currentServer = this->getCurrentVatsimServer();
CUser vatsimUser = this->getUserFromVatsimGuiValues();
const CUser vatsimUser = this->getUserFromVatsimGuiValues();
currentServer.setUser(vatsimUser);
}
else
@@ -274,6 +275,11 @@ namespace BlackGui
if (msg.isSeverityInfoOrLess())
{
emit loginOrLogoffSuccessful();
if (vatsimLogin)
{
this->m_currentVatsimServer.set(currentServer);
this->m_currentAircraftModel.setAndSave(ownAircraft.getModel());
}
}
else
{
@@ -281,16 +287,17 @@ namespace BlackGui
}
}
void CLoginComponent::ps_onWebServiceDataRead(int entityI, int stateI, int number)
// void CLoginComponent::ps_onWebServiceDataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState, int number)
void CLoginComponent::ps_onWebServiceDataRead(int entityInt, int stateI, int number)
{
CEntityFlags::EntityFlag entity = static_cast<CEntityFlags::EntityFlag>(entityI);
CEntityFlags::ReadState state = static_cast<CEntityFlags::ReadState>(stateI);
const CEntityFlags::EntityFlag entity = static_cast<CEntityFlags::EntityFlag>(entityInt);
const CEntityFlags::ReadState state = static_cast<CEntityFlags::ReadState>(stateI);
if (entity != CEntityFlags::VatsimDataFile || state != CEntityFlags::ReadFinished) { return; }
Q_UNUSED(number);
CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
const CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
if (vatsimFsdServers.isEmpty()) { return; }
this->ui->cbp_VatsimServer->setServers(vatsimFsdServers);
const CServer currentServer = this->m_currentVatsimServer.get();
this->ui->comp_VatsimServer->setServers(vatsimFsdServers);
this->ui->comp_VatsimServer->preSelect(currentServer.getName());
}
void CLoginComponent::setGuiValuesFromAircraft(const CSimulatedAircraft &ownAircraft)
@@ -302,14 +309,27 @@ namespace BlackGui
this->ui->le_AircraftCombinedType->setText(aircraftIcao.getCombinedType());
}
void CLoginComponent::loadFromSettings()
void CLoginComponent::loadRememberedVatsimData()
{
//! \todo replace with loading from settings when completed
this->ui->le_Callsign->setText("SWIFT");
this->ui->le_VatsimId->setText("1288459");
this->ui->le_VatsimPassword->setText("4769");
this->ui->le_VatsimHomeAirport->setText("LOWI");
this->ui->le_VatsimRealName->setText("Black Swift");
const CServer lastServer = this->m_currentVatsimServer.get();
const CUser lastUser = lastServer.getUser();
if (lastUser.hasValidCallsign())
{
this->ui->le_Callsign->setText(lastUser.getCallsign().asString());
this->ui->le_VatsimId->setText(lastUser.getId());
this->ui->le_VatsimPassword->setText(lastUser.getPassword());
this->ui->le_VatsimHomeAirport->setText(lastUser.getHomebase().asString());
this->ui->le_VatsimRealName->setText(lastUser.getRealName());
}
else
{
this->ui->le_Callsign->setText("SWIFT");
this->ui->le_VatsimId->setText("1288459");
this->ui->le_VatsimPassword->setText("4769");
this->ui->le_VatsimHomeAirport->setText("LOWI");
this->ui->le_VatsimRealName->setText("Black Swift");
}
this->ui->comp_OtherServers->preSelect(lastServer.getName());
}
CLoginComponent::CGuiAircraftValues CLoginComponent::getAircraftValuesFromGui() const
@@ -337,6 +357,7 @@ namespace BlackGui
{
CVatsimValues values = getVatsimValuesFromGui();
CUser user(values.vatsimId, values.vatsimRealName, "", values.vatsimPassword, getCallsignFromGui());
user.setHomebase(values.vatsimHomeAirport);
return user;
}
@@ -348,12 +369,12 @@ namespace BlackGui
CServer CLoginComponent::getCurrentVatsimServer() const
{
return this->ui->cbp_VatsimServer->currentServer();
return this->ui->comp_VatsimServer->currentServer();
}
CServer CLoginComponent::getCurrentOtherServer() const
{
return this->ui->cbp_OtherServers->currentServer();
return this->ui->comp_OtherServers->currentServer();
}
void CLoginComponent::setOkButtonString(bool connected)
@@ -382,13 +403,9 @@ namespace BlackGui
Q_ASSERT(sGui->getIContextOwnAircraft());
Q_ASSERT(sGui->getIContextSimulator());
static const CAircraftModel defaultModel(
"", CAircraftModel::TypeOwnSimulatorModel, "default model",
CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0));
CAircraftModel model;
bool simulating = sGui->getIContextSimulator() &&
(sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
const bool simulating = sGui->getIContextSimulator() &&
(sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
if (simulating)
{
model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel();
@@ -396,10 +413,12 @@ namespace BlackGui
}
else
{
// Set observer mode without simulator
//! \todo Currently not working in OBS mode
model = CAircraftModel(defaultModel);
this->ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal);
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; }
this->ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal); //! \todo Set observer mode without simulator, currently not working in OBS mode
this->ui->le_SimulatorModel->setText("No simulator");
}
@@ -471,7 +490,7 @@ namespace BlackGui
void CLoginComponent::ps_reloadSettings()
{
CServerList otherServers(this->m_otherTrafficNetworkServers.getThreadLocal());
this->ui->cbp_OtherServers->setServers(otherServers);
this->ui->comp_OtherServers->setServers(otherServers);
}
void CLoginComponent::ps_logoffCountdown()
@@ -504,6 +523,5 @@ namespace BlackGui
CLogMessage(this).validationInfo("Reverse lookup for %1 failed, set data manually") << modelStr;
}
}
} // namespace
} // namespace

View File

@@ -13,12 +13,15 @@
#define BLACKGUI_LOGINCOMPONENT_H
#include "blackcore/settings/network.h"
#include "blackcore/data/vatsimsetup.h"
#include "blackgui/blackguiexport.h"
#include "blackgui/settings/settingsgui.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/network/entityflags.h"
#include "blackmisc/network/server.h"
#include "blackmisc/network/user.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/datacache.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include <QFrame>
@@ -38,7 +41,6 @@ namespace BlackMisc
}
}
namespace Ui { class CLoginComponent; }
namespace BlackGui
{
namespace Components
@@ -119,7 +121,7 @@ namespace BlackGui
void setGuiValuesFromAircraft(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
//! Load from settings
void loadFromSettings();
void loadRememberedVatsimData();
//! Values from GUI
CGuiAircraftValues getAircraftValuesFromGui() const;
@@ -154,13 +156,14 @@ namespace BlackGui
//! Set ICAO values
void setGuiIcaoValues(const BlackMisc::Simulation::CAircraftModel &model, bool onlyIfEmpty);
bool m_visible = false; //!< is this component selected?
QScopedPointer<Ui::CLoginComponent> ui;
bool m_visible = false; //!< is this component selected?
const int LogoffIntervalSeconds = 10;
QTimer *m_logoffCountdownTimer { nullptr };
BlackMisc::CSetting<BlackCore::Settings::Network::TrafficServers> m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings };
BlackMisc::CSettingReadOnly<BlackCore::Settings::Network::TrafficServers> m_otherTrafficNetworkServers { this, &CLoginComponent::ps_reloadSettings };
BlackMisc::CSetting<BlackGui::Settings::OwnAircraftModel> m_currentAircraftModel { this };
BlackMisc::CData<BlackCore::Data::VatsimCurrentServer> m_currentVatsimServer { this };
};
} // namespace
} // namespace

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>463</width>
<height>412</height>
<height>443</height>
</rect>
</property>
<property name="minimumSize">
@@ -156,7 +156,7 @@
</widget>
</item>
<item row="4" column="1" colspan="4">
<widget class="BlackGui::Components::CServerListSelector" name="cbp_VatsimServer"/>
<widget class="BlackGui::Components::CServerListSelector" name="comp_VatsimServer"/>
</item>
<item row="1" column="2">
<widget class="BlackGui::CTickLabel" name="lblp_VatsimId">
@@ -212,7 +212,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="BlackGui::Components::CServerListSelector" name="cbp_OtherServers"/>
<widget class="BlackGui::Components::CServerListSelector" name="comp_OtherServers"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_OtherServersEdit">
@@ -584,13 +584,13 @@
<tabstop>le_VatsimPassword</tabstop>
<tabstop>le_VatsimRealName</tabstop>
<tabstop>le_VatsimHomeAirport</tabstop>
<tabstop>cbp_VatsimServer</tabstop>
<tabstop>comp_VatsimServer</tabstop>
<tabstop>le_SimulatorModel</tabstop>
<tabstop>le_Callsign</tabstop>
<tabstop>le_AircraftIcaoDesignator</tabstop>
<tabstop>le_AircraftIcaoAirline</tabstop>
<tabstop>le_AircraftCombinedType</tabstop>
<tabstop>cbp_OtherServers</tabstop>
<tabstop>comp_OtherServers</tabstop>
<tabstop>pb_OtherServersGotoSettings</tabstop>
</tabstops>
<resources>

View File

@@ -27,15 +27,39 @@ namespace BlackGui
{
if (this->m_servers == servers) { return; }
this->setItemStrings(servers);
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
{
this->preSelect(m_pendingPreselect);
m_pendingPreselect.clear();
}
}
BlackMisc::Network::CServer CServerListSelector::currentServer() const
CServer CServerListSelector::currentServer() const
{
int i = currentIndex();
const int i = currentIndex();
if (i < 0 || i >= m_servers.size()) { return CServer(); }
return m_servers[i];
}
bool CServerListSelector::preSelect(const QString &name)
{
if (name.isEmpty()) { return false; }
if (m_servers.isEmpty())
{
m_pendingPreselect = name; // save for later
return false;
}
for (int i = 0; i < m_servers.size(); i++)
{
if (m_servers[i].matchesName(name))
{
this->setCurrentIndex(i);
return true;
}
}
return false;
}
void CServerListSelector::setItemStrings(const CServerList &servers)
{
QString currentlySelected(this->currentText());

View File

@@ -41,12 +41,16 @@ namespace BlackGui
//! Get the current server
BlackMisc::Network::CServer currentServer() const;
//! Preselect
bool preSelect(const QString &name);
private:
//! Build the item string descriptions
void setItemStrings(const BlackMisc::Network::CServerList &servers);
BlackMisc::Network::CServerList m_servers; //!< corresponding servers
QStringList m_items; //!< items strings
QString m_pendingPreselect; //!< pending preselect value
};
} // ns
} // ns

View File

@@ -0,0 +1,32 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_SETTINGS_GUI_H
#define BLACKGUI_SETTINGS_GUI_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/simulation/aircraftmodel.h"
namespace BlackGui
{
namespace Settings
{
//! Settings for last manual entries of own aircraft mode
struct OwnAircraftModel : public BlackMisc::CSettingTrait<BlackMisc::Simulation::CAircraftModel>
{
//! Key in data cache
static const char *key() { return "guinownaircraftmodel"; }
};
} // ns
} // ns
#endif // guard