From 5d1b5dba383530c68b464934cd61f738c288e1d4 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 16 May 2017 16:06:40 +0200 Subject: [PATCH] Allow to select server type in FSD settings Summary: With this change the server type is a dynamic setting per server and replaces the hardcoded global server type in CNetworkVatlib. This allows the user to select the server type in settings ui and configures the vatlib session accordingly. This also removes the command line argument to set the server type since it doesn't make sense anymore. Reviewers: msutcliffe Reviewed By: msutcliffe Subscribers: jenkins Differential Revision: https://dev.swift-project.org/D24 --- src/blackcore/vatsim/networkvatlib.cpp | 32 ++--- src/blackcore/vatsim/networkvatlib.h | 1 - src/blackgui/editors/serverform.cpp | 14 +- src/blackgui/editors/serverform.ui | 170 ++++++++++++------------ src/blackgui/models/serverlistmodel.cpp | 2 + src/blackmisc/network/server.cpp | 22 ++- src/blackmisc/network/server.h | 27 +++- 7 files changed, 157 insertions(+), 111 deletions(-) diff --git a/src/blackcore/vatsim/networkvatlib.cpp b/src/blackcore/vatsim/networkvatlib.cpp index ae23195a0..ed1b1d08b 100644 --- a/src/blackcore/vatsim/networkvatlib.cpp +++ b/src/blackcore/vatsim/networkvatlib.cpp @@ -125,8 +125,11 @@ namespace BlackCore } VatServerType serverType; - bool success = getCmdLineServerType(serverType); - if (!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; } + switch (m_server.getServerType()) + { + case CServer::ServerVatsim: serverType = vatServerVatsim; break; + default: serverType = vatServerLegacyFsd; break; + } m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(), CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion(), @@ -389,6 +392,10 @@ namespace BlackCore void CNetworkVatlib::presetServer(const CServer &server) { Q_ASSERT_X(isDisconnected(), Q_FUNC_INFO, "Can't change server details while still connected"); + + // If the server type changed, we need to destroy the existing vatlib session + if (m_server.getServerType() != server.getServerType()) { m_net.reset(); } + m_server = server; const QString codecName(server.getFsdSetup().getTextCodec()); Q_ASSERT_X(!codecName.isEmpty(), Q_FUNC_INFO, "Missing code name"); @@ -697,9 +704,7 @@ namespace BlackCore static const QList opts { QCommandLineOption({ "idAndKey", "clientIdAndKey" }, - QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. :."), "clientIdAndKey"), - QCommandLineOption({ "s", "serverType" }, - QCoreApplication::translate("networkvatlib", "FSD server type. Possible values: vatsim, fsd"), "serverType") + QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. :."), "clientIdAndKey") }; // only in not officially shipped versions @@ -719,23 +724,6 @@ namespace BlackCore return true; } - bool CNetworkVatlib::getCmdLineServerType(VatServerType &serverType) const - { - QString serverTypeAsString = sApp->getParserValue("serverType").toLower(); - if (QString::compare(serverTypeAsString, "vatsim", Qt::CaseInsensitive) == 0) - { - serverType = vatServerVatsim; - return true; - } - - if (QString::compare(serverTypeAsString, "fsd", Qt::CaseInsensitive) == 0) - { - serverType = vatServerLegacyFsd; - return true; - } - return false; - } - void CNetworkVatlib::sendCustomFsinnQuery(const BlackMisc::Aviation::CCallsign &callsign) { Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); diff --git a/src/blackcore/vatsim/networkvatlib.h b/src/blackcore/vatsim/networkvatlib.h index 0725b3365..aa73be7d7 100644 --- a/src/blackcore/vatsim/networkvatlib.h +++ b/src/blackcore/vatsim/networkvatlib.h @@ -128,7 +128,6 @@ namespace BlackCore private: bool getCmdLineClientIdAndKey(int &id, QString &key) const; - bool getCmdLineServerType(VatServerType &serverType) const; private slots: void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign); diff --git a/src/blackgui/editors/serverform.cpp b/src/blackgui/editors/serverform.cpp index 818958bf0..98b7b95ae 100644 --- a/src/blackgui/editors/serverform.cpp +++ b/src/blackgui/editors/serverform.cpp @@ -26,6 +26,10 @@ namespace BlackGui ui(new Ui::CNetworkServerForm) { ui->setupUi(this); + ui->cb_ServerType->clear(); + ui->cb_ServerType->insertItem(0, QStringLiteral("VATSIM"), QVariant::fromValue(CServer::ServerVatsim)); + ui->cb_ServerType->insertItem(1, QStringLiteral("FSC"), QVariant::fromValue(CServer::ServerFSC)); + ui->cb_ServerType->insertItem(2, QStringLiteral("Legacy FSD"), QVariant::fromValue(CServer::ServerLegacyFSD)); ui->le_Port->setValidator(new QIntValidator(1, 65535, this)); } @@ -38,6 +42,12 @@ namespace BlackGui ui->le_NetworkId->setText(user.getId()); ui->le_RealName->setText(user.getRealName()); ui->le_Name->setText(server.getName()); + switch (server.getServerType()) + { + case CServer::ServerVatsim: ui->cb_ServerType->setCurrentIndex(0); break; + case CServer::ServerFSC: ui->cb_ServerType->setCurrentIndex(1); break; + case CServer::ServerLegacyFSD: ui->cb_ServerType->setCurrentIndex(2); break; + } ui->le_Password->setText(user.getPassword()); ui->le_Description->setText(server.getDescription()); ui->le_Address->setText(server.getAddress()); @@ -58,7 +68,9 @@ namespace BlackGui ui->le_Description->text().trimmed().simplified(), ui->le_Address->text().trimmed(), ui->le_Port->text().trimmed().toInt(), - user + user, + true, + ui->cb_ServerType->currentData().value() ); CFsdSetup setup(ui->form_ServerFsd->getValue()); server.setFsdSetup(setup); diff --git a/src/blackgui/editors/serverform.ui b/src/blackgui/editors/serverform.ui index e15f7683b..7893aca0e 100644 --- a/src/blackgui/editors/serverform.ui +++ b/src/blackgui/editors/serverform.ui @@ -7,7 +7,7 @@ 0 0 275 - 171 + 172 @@ -75,75 +75,6 @@ 4 - - - - e.g. "server.foo.com" - - - - - - - server description - - - - - - - - - - your name if required - - - - - - - 6809 - - - 5 - - - - - - - Real name: - - - - - - - Name: - - - - - - - Addr./ port: - - - - - - - Description: - - - - - - - server name - - - @@ -151,19 +82,6 @@ - - - - 32 - - - QLineEdit::Password - - - password - - - @@ -174,6 +92,91 @@ + + + + Name/Type: + + + + + + + Real name: + + + + + + + Description: + + + + + + + Addr./ port: + + + + + + + server name + + + + + + + + + + server description + + + + + + + 6809 + + + 5 + + + + + + + e.g. "server.foo.com" + + + + + + + + + + your name if required + + + + + + + 32 + + + QLineEdit::Password + + + password + + + @@ -222,6 +225,7 @@ le_Name + cb_ServerType le_Description le_Address le_Port diff --git a/src/blackgui/models/serverlistmodel.cpp b/src/blackgui/models/serverlistmodel.cpp index bb0ed559f..10ab42679 100644 --- a/src/blackgui/models/serverlistmodel.cpp +++ b/src/blackgui/models/serverlistmodel.cpp @@ -29,6 +29,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn::standardString("port", CServer::IndexPort)); this->m_columns.addColumn(CColumn::standardString("realname", { CServer::IndexUser, CUser::IndexRealName})); this->m_columns.addColumn(CColumn::standardString("userid", { CServer::IndexUser, CUser::IndexId})); + this->m_columns.addColumn(CColumn::standardString("type", CServer::IndexServerTypeAsString)); // force strings for translation in resource files (void)QT_TRANSLATE_NOOP("ServerListModel", "name"); @@ -37,6 +38,7 @@ namespace BlackGui (void)QT_TRANSLATE_NOOP("ServerListModel", "port"); (void)QT_TRANSLATE_NOOP("ServerListModel", "realname"); (void)QT_TRANSLATE_NOOP("ServerListModel", "userid"); + (void)QT_TRANSLATE_NOOP("ServerListModel", "type"); } } // class diff --git a/src/blackmisc/network/server.cpp b/src/blackmisc/network/server.cpp index da96d69bc..f92d02ee9 100644 --- a/src/blackmisc/network/server.cpp +++ b/src/blackmisc/network/server.cpp @@ -23,8 +23,8 @@ namespace BlackMisc { namespace Network { - CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections) - : m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections) {} + CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections, ServerType serverType) + : m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections), m_serverType(serverType) {} QString CServer::convertToQString(bool i18n) const { @@ -71,6 +71,17 @@ namespace BlackMisc return m_port > 0 && !m_address.isEmpty(); } + QString CServer::getServerTypeAsString() const + { + switch (m_serverType) + { + case CServer::ServerVatsim: return QStringLiteral("VATSIM"); + case CServer::ServerFSC: return QStringLiteral("FSC"); + case CServer::ServerLegacyFSD: return QStringLiteral("Legacy FSD"); + default: return {}; + } + } + bool CServer::isConnected() const { return this->m_timestampMSecsSinceEpoch >= 0; @@ -119,6 +130,10 @@ namespace BlackMisc return this->m_fsdSetup.propertyByIndex(index.copyFrontRemoved()); case IndexIsAcceptingConnections: return CVariant::fromValue(this->m_isAcceptingConnections); + case IndexServerType: + return CVariant::fromValue(this->m_serverType); + case IndexServerTypeAsString: + return CVariant::fromValue(getServerTypeAsString()); default: return CValueObject::propertyByIndex(index); } @@ -153,6 +168,9 @@ namespace BlackMisc case IndexIsAcceptingConnections: this->setIsAcceptingConnections(variant.value()); break; + case IndexServerType: + this->setServerType(static_cast(variant.toInt())); + break; default: CValueObject::setPropertyByIndex(index, variant); break; diff --git a/src/blackmisc/network/server.h b/src/blackmisc/network/server.h index cfb800141..880803f36 100644 --- a/src/blackmisc/network/server.h +++ b/src/blackmisc/network/server.h @@ -44,14 +44,25 @@ namespace BlackMisc IndexPort, IndexUser, IndexFsdSetup, - IndexIsAcceptingConnections + IndexIsAcceptingConnections, + IndexServerType, + IndexServerTypeAsString + }; + + //! Server Type + enum ServerType + { + ServerVatsim, + ServerFSC, + ServerLegacyFSD }; //! Default constructor. CServer() {} //! Constructor. - CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections = true); + CServer(const QString &name, const QString &description, const QString &address, int port, + const CUser &user, bool isAcceptingConnections = true, ServerType serverType = ServerVatsim); //! Get address. const QString &getAddress() const { return m_address; } @@ -110,6 +121,15 @@ namespace BlackMisc //! Set setup void setFsdSetup(const CFsdSetup &setup) { this->m_fsdSetup = setup; } + //! Set server type + void setServerType(ServerType serverType) { m_serverType = serverType; } + + //! Get server type + ServerType getServerType() const { return m_serverType; } + + //! Get server type as string + QString getServerTypeAsString() const; + //! Connected since QDateTime getConnectedSince() const { return this->getUtcTimestamp(); } @@ -148,6 +168,7 @@ namespace BlackMisc CUser m_user; CFsdSetup m_fsdSetup; bool m_isAcceptingConnections = true; //!< disable server for connections + ServerType m_serverType = ServerVatsim; BLACK_METACLASS( CServer, @@ -158,6 +179,7 @@ namespace BlackMisc BLACK_METAMEMBER(user), BLACK_METAMEMBER(fsdSetup), BLACK_METAMEMBER(isAcceptingConnections), + BLACK_METAMEMBER(serverType), BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison) ); }; @@ -165,5 +187,6 @@ namespace BlackMisc } // namespace Q_DECLARE_METATYPE(BlackMisc::Network::CServer) +Q_DECLARE_METATYPE(BlackMisc::Network::CServer::ServerType) #endif // guard