Encapsulated last network server used in network setup. Will allow to retrieve ecosystem for T272

This commit is contained in:
Klaus Basan
2018-05-29 13:33:25 +02:00
parent 0b607f9e0b
commit 839a836926
3 changed files with 171 additions and 1 deletions

View File

@@ -229,7 +229,7 @@ namespace BlackCore
BlackMisc::Network::CUrlList m_newsUrls; //!< where we can obtain latest news
BlackMisc::Network::CUrlList m_onlineHelpUrls; //!< online help URLs
BlackMisc::Network::CUrlList m_mapUrls; //!< swift map URLs
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers loaded from setup file
BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl; //!< NCEP GFS url
// transient members, to be switched on/off via GUI or set from reader

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2018
* 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.
*/
#include "blackcore/data/networksetup.h"
#include "blackcore/application.h"
#include "blackconfig/buildconfig.h"
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackCore
{
namespace Data
{
CNetworkSetup::CNetworkSetup()
{ }
CServer CNetworkSetup::getLastVatsimServer() const
{
return m_lastVatsimServer.get();
}
CStatusMessage CNetworkSetup::setLastVatsimServer(const CServer &server)
{
return m_lastVatsimServer.set(server);
}
CServer CNetworkSetup::getLastServer() const
{
return m_lastServer.get();
}
CStatusMessage CNetworkSetup::setLastServer(const CServer &server)
{
return m_lastServer.set(server);
}
CServerList CNetworkSetup::getOtherServers() const
{
return m_otherTrafficNetworkServers.get();
}
CServerList CNetworkSetup::getOtherServersPlusTestServers() const
{
// add a testserver when no servers can be loaded
CServerList otherServers(this->getOtherServers());
if (otherServers.isEmpty() && CBuildConfig::isLocalDeveloperDebugBuild())
{
otherServers.push_back(sApp->getGlobalSetup().getFsdTestServersPlusHardcodedServers());
}
return otherServers;
}
CEcosystem CNetworkSetup::getLastEcosystem() const
{
return this->getLastServer().getEcosystem();
}
bool CNetworkSetup::wasLastUsedWithVatsim() const
{
return (this->getLastEcosystem() == CEcosystem::vatsim());
}
bool CNetworkSetup::wasLastUsedWithOtherServer() const
{
const CServer server(this->getLastServer());
if (server.isNull()) { return false; }
return server.getEcosystem() == CEcosystem::privateFsd() ||
server.getEcosystem() == CEcosystem::swiftTest() ||
server.getEcosystem() == CEcosystem::swift();
}
void CNetworkSetup::onSettingsChanged()
{
emit this->setupChanged();
}
} // ns
} // ns

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2018
* 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 BLACKCORE_DATA_NETWORKSETUP_H
#define BLACKCORE_DATA_NETWORKSETUP_H
#include "blackcore/vatsim/vatsimsettings.h"
#include "blackcore/data/vatsimsetup.h"
#include "blackcore/blackcoreexport.h"
#include "blackmisc/network/data/lastserver.h"
#include "blackmisc/network/serverlist.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/metaclass.h"
#include <QMetaType>
#include <QString>
#include <QObject>
namespace BlackCore
{
namespace Data
{
//! Remembering the last servers and ecosystem.
class BLACKCORE_EXPORT CNetworkSetup : public QObject
{
Q_OBJECT
public:
//! Default constructor
CNetworkSetup();
//! Destructor.
virtual ~CNetworkSetup() {}
//! Last VATSIM server (VATSIM only)
BlackMisc::Network::CServer getLastVatsimServer() const;
//! Set value of last VATSIM server
BlackMisc::CStatusMessage setLastVatsimServer(const BlackMisc::Network::CServer &server);
//! Last server (all networks)
BlackMisc::Network::CServer getLastServer() const;
//! Set value of last server
BlackMisc::CStatusMessage setLastServer(const BlackMisc::Network::CServer &server);
//! Last used eco system
BlackMisc::Network::CEcosystem getLastEcosystem() const;
//! The other servers
BlackMisc::Network::CServerList getOtherServers() const;
//! The other servers plus test servers
BlackMisc::Network::CServerList getOtherServersPlusTestServers() const;
//! Last used with VATSIM?
bool wasLastUsedWithVatsim() const;
//! Used with an other server (i.e. non VATSIM)
bool wasLastUsedWithOtherServer() const;
signals:
//! Setup changed
void setupChanged();
private:
//! Settings have been changed
void onSettingsChanged();
BlackMisc::CSettingReadOnly<BlackCore::Vatsim::TTrafficServers> m_otherTrafficNetworkServers { this, &CNetworkSetup::onSettingsChanged };
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this, &CNetworkSetup::onSettingsChanged }; //!< recently used server (VATSIM, other)
BlackMisc::CData<BlackCore::Data::TVatsimLastServer> m_lastVatsimServer { this, &CNetworkSetup::onSettingsChanged }; //!< recently used VATSIM server
};
} // ns
} // ns
#endif // guard