Ref T215, remember last server and model as cache value

* also remember last server not VATSIM server
* remember last model used
* server list selector uses remembered value
* login component sets those values
This commit is contained in:
Klaus Basan
2018-01-02 02:47:47 +01:00
parent ee0d69faf2
commit 0975abcc46
10 changed files with 103 additions and 26 deletions

View File

@@ -128,8 +128,8 @@ namespace BlackCore
static constexpr bool isPinned() { return true; }
};
//! Trait for currently used VATSIM server and user
struct TVatsimCurrentServer : public BlackMisc::TDataTrait<BlackMisc::Network::CServer>
//! Trait for last (most recently) used VATSIM server and user
struct TVatsimLastServer : public BlackMisc::TDataTrait<BlackMisc::Network::CServer>
{
//! Key in data cache
static const char *key() { return "vatsimserver"; }

View File

@@ -291,11 +291,13 @@ namespace BlackGui
// Login
msg = sGui->getIContextNetwork()->connectToNetwork(currentServer, mode);
if (msg.isSuccess() && vatsimLogin)
if (msg.isSuccess())
{
Q_ASSERT_X(currentServer.isValidForLogin(), Q_FUNC_INFO, "invalid server");
m_currentVatsimServer.set(currentServer);
m_currentAircraftModel.setAndSave(ownAircraft.getModel());
m_lastServer.set(currentServer);
m_lastAircraftModel.set(ownAircraft.getModel());
ui->le_HomeBase->setText(currentServer.getUser().getHomeBase().asString());
if (vatsimLogin) { m_lastVatsimServer.set(currentServer); }
}
}
else
@@ -335,7 +337,7 @@ namespace BlackGui
CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
if (vatsimFsdServers.isEmpty()) { return; }
vatsimFsdServers.sortBy(&CServer::getName);
const CServer currentServer = m_currentVatsimServer.get();
const CServer currentServer = m_lastVatsimServer.get();
ui->comp_VatsimServer->setServers(vatsimFsdServers, true);
ui->comp_VatsimServer->preSelect(currentServer.getName());
}
@@ -347,7 +349,7 @@ namespace BlackGui
void CLoginComponent::loadRememberedVatsimData()
{
const CServer lastServer = m_currentVatsimServer.get();
const CServer lastServer = m_lastVatsimServer.get();
const CUser lastUser = lastServer.getUser();
if (lastUser.hasValidCallsign())
{
@@ -357,7 +359,7 @@ namespace BlackGui
ui->le_VatsimHomeAirport->setText(lastUser.getHomeBase().asString());
ui->le_VatsimRealName->setText(lastUser.getRealName());
}
else
else if (CBuildConfig::isLocalDeveloperDebugBuild())
{
ui->le_Callsign->setText("SWIFT");
ui->le_VatsimId->setText("1288459");
@@ -365,7 +367,6 @@ namespace BlackGui
ui->le_VatsimHomeAirport->setText("LOWI");
ui->le_VatsimRealName->setText("Black Swift");
}
ui->comp_OtherServers->preSelect(lastServer.getName());
}
CLoginComponent::CGuiAircraftValues CLoginComponent::getAircraftValuesFromGui() const
@@ -702,7 +703,7 @@ namespace BlackGui
CAircraftModel CLoginComponent::getPrefillModel() const
{
CAircraftModel model = m_currentAircraftModel.get();
const CAircraftModel model = m_lastAircraftModel.get();
if (model.hasAircraftDesignator()) { return model; }
return IContextOwnAircraft::getDefaultOwnAircraftModel();
}

View File

@@ -16,12 +16,14 @@
#include "blackcore/data/vatsimsetup.h"
#include "blackgui/blackguiexport.h"
#include "blackgui/settings/guisettings.h"
#include "blackmisc/simulation/data/lastmodel.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/network/data/lastserver.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"
@@ -217,8 +219,9 @@ namespace BlackGui
const int LogoffIntervalSeconds = 20; //!< time before logoff
QTimer *m_logoffCountdownTimer { nullptr }; //!< timer for logoff countdown
BlackMisc::CSettingReadOnly<BlackCore::Vatsim::TTrafficServers> m_otherTrafficNetworkServers { this, &CLoginComponent::reloadSettings };
BlackMisc::CSetting<BlackGui::Settings::TOwnAircraftModel> m_currentAircraftModel { this }; //!< current settings of aircraft
BlackMisc::CData<BlackCore::Data::TVatsimCurrentServer> m_currentVatsimServer { this }; //!< cache for current VATSIM server
BlackMisc::CData<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
BlackMisc::CData<BlackCore::Data::TVatsimLastServer> m_lastVatsimServer { this }; //!< recently used VATSIM server
};
} // namespace
} // namespace

View File

@@ -27,7 +27,13 @@ namespace BlackGui
{
CServerListSelector::CServerListSelector(QWidget *parent) :
QComboBox(parent)
{ }
{
const CServer server = m_lastServer.get();
if (server.hasName())
{
m_pendingPreselect = server.getName();
}
}
void CServerListSelector::setServers(const CServerList &servers, bool nameIsCountry)
{

View File

@@ -13,9 +13,10 @@
#define BLACKGUI_COMPONENTS_SERVERLISTSELECTOR_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/network/server.h"
#include "blackmisc/network/data/lastserver.h"
#include "blackmisc/network/serverlist.h"
#include "blackmisc/country.h"
#include "blackmisc/datacache.h"
#include <QComboBox>
#include <QObject>
@@ -58,6 +59,7 @@ namespace BlackGui
BlackMisc::Network::CServerList m_servers; //!< corresponding servers
QStringList m_items; //!< items strings
QString m_pendingPreselect; //!< pending preselect value
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
};
} // ns
} // ns

View File

@@ -83,16 +83,6 @@ namespace BlackGui
static const QString &humanReadable() { static const QString name("General GUI"); return name; }
};
//! Settings for last manual entries of own aircraft mode
struct TOwnAircraftModel : public BlackMisc::TSettingTrait<BlackMisc::Simulation::CAircraftModel>
{
//! \copydoc BlackCore::TSettingTrait::key
static const char *key() { return "guinownaircraftmodel"; }
//! \copydoc BlackCore::TSettingTrait::humanReadable
static const QString &humanReadable() { static const QString name("Own aircraft"); return name; }
};
//! Settings for last manual entries of own aircraft mode
struct TBackgroundConsolidation : public BlackMisc::TSettingTrait<int>
{

View File

@@ -32,6 +32,7 @@ HEADERS += *.h \
$$PWD/input/*.h \
$$PWD/math/*.h \
$$PWD/network/*.h \
$$PWD/network/data/*.h \
$$PWD/pq/*.h \
$$PWD/simulation/*.h \
$$PWD/simulation/data/*.h \

View File

@@ -0,0 +1,37 @@
/* Copyright (C) 2017
* 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 BLACKMISC_NETWORK_DATA_LASTSERVER_H
#define BLACKMISC_NETWORK_DATA_LASTSERVER_H
#include "../server.h"
#include "blackmisc/datacache.h"
namespace BlackMisc
{
namespace Network
{
namespace Data
{
//! Trait for last (most recently) used server and user
struct TLastServer : public TDataTrait<CServer>
{
//! Key in data cache
static const char *key() { return "lastserver"; }
//! First load is synchronous
static constexpr bool isPinned() { return true; }
};
} // ns
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,37 @@
/* Copyright (C) 2017
* 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 BLACKMISC_SIMULATION_DATA_LASTMODEL_H
#define BLACKMISC_SIMULATION_DATA_LASTMODEL_H
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/datacache.h"
namespace BlackMisc
{
namespace Simulation
{
namespace Data
{
//! Last model used
struct TLastModel : public BlackMisc::TDataTrait<CAircraftModel>
{
//! \copydoc BlackCore::TSettingTrait::key
static const char *key() { return "lastaircraftmodel"; }
//! \copydoc BlackCore::TSettingTrait::humanReadable
static const QString &humanReadable() { static const QString name("Own aircraft model"); return name; }
};
} // ns
} // ns
} // ns
#endif // guard

View File

@@ -29,7 +29,7 @@ namespace BlackMisc
namespace Data
{
//! Trait for model cache
struct TModelCache : public BlackMisc::TDataTrait<BlackMisc::Simulation::CAircraftModelList>
struct TModelCache : public TDataTrait<CAircraftModelList>
{
//! Defer loading
static constexpr bool isDeferred() { return true; }