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
This commit is contained in:
Roland Winklmeier
2017-05-16 16:06:40 +02:00
parent f1f7ee4709
commit 5d1b5dba38
7 changed files with 157 additions and 111 deletions

View File

@@ -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<QCommandLineOption> opts
{
QCommandLineOption({ "idAndKey", "clientIdAndKey" },
QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. <id>:<key>."), "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. <id>:<key>."), "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");

View File

@@ -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);

View File

@@ -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<CServer::ServerType>()
);
CFsdSetup setup(ui->form_ServerFsd->getValue());
server.setFsdSetup(setup);

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>275</width>
<height>171</height>
<height>172</height>
</rect>
</property>
<property name="windowTitle">
@@ -75,75 +75,6 @@
<property name="spacing">
<number>4</number>
</property>
<item row="2" column="1">
<widget class="QLineEdit" name="le_Address">
<property name="placeholderText">
<string>e.g. &quot;server.foo.com&quot;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="le_Description">
<property name="placeholderText">
<string>server description</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>your name if required</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="le_Port">
<property name="text">
<string>6809</string>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Addr./ port:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="le_Name">
<property name="placeholderText">
<string>server name</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_IdPassword">
<property name="text">
@@ -151,19 +82,6 @@
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="le_Password">
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_NetworkId">
<property name="text">
@@ -174,6 +92,91 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name/Type:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Addr./ port:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="le_Name">
<property name="placeholderText">
<string>server name</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="cb_ServerType"/>
</item>
<item row="1" column="1" colspan="3">
<widget class="QLineEdit" name="le_Description">
<property name="placeholderText">
<string>server description</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="le_Port">
<property name="text">
<string>6809</string>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="le_Address">
<property name="placeholderText">
<string>e.g. &quot;server.foo.com&quot;</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>your name if required</string>
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<widget class="QLineEdit" name="le_Password">
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -222,6 +225,7 @@
</customwidgets>
<tabstops>
<tabstop>le_Name</tabstop>
<tabstop>cb_ServerType</tabstop>
<tabstop>le_Description</tabstop>
<tabstop>le_Address</tabstop>
<tabstop>le_Port</tabstop>

View File

@@ -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

View File

@@ -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<bool>());
break;
case IndexServerType:
this->setServerType(static_cast<ServerType>(variant.toInt()));
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;

View File

@@ -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