Ref T85, minor improvements on server type

* UI: generic generation of combobox
* UI: Read only for combobox
* CServer utility functions
This commit is contained in:
Klaus Basan
2017-06-23 17:04:31 +02:00
parent efd82f4391
commit 36037c4c04
7 changed files with 93 additions and 52 deletions

View File

@@ -23,24 +23,21 @@ namespace BlackMisc
{
namespace Network
{
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) {}
const QList<int> &CServer::allServerTypes()
{
static const QList<int> all({ FSDServerVatsim, FSDServerFSC, FSDServerLegacy, WebService, Unspecified });
return all;
}
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, ServerType serverType, bool isAcceptingConnections)
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_serverType(serverType), m_isAcceptingConnections(isAcceptingConnections) {}
QString CServer::convertToQString(bool i18n) const
{
QString s(this->m_name);
s.append(' ').append(this->m_description);
s.append(' ').append(this->m_address);
s.append(' ').append(QString::number(this->m_port));
s.append(' ').append(this->m_user.toQString(i18n));
s.append(' ').append(boolToYesNo(this->m_isAcceptingConnections));
s.append(' ').append(this->m_fsdSetup.toQString(i18n));
if (this->isConnected())
{
s.append(" connected: ").append(this->getFormattedUtcTimestampHms());
}
return s;
static const QString str("%1 %2 %3:%4 %5 accepting: %6 FSD: %7 con.since: %8");
return str.
arg(this->m_name, this->m_description, this->m_address).arg(this->m_port).
arg(this->m_user.toQString(i18n), boolToYesNo(this->m_isAcceptingConnections), this->m_fsdSetup.toQString(i18n), this->isConnected() ? this->getFormattedUtcTimestampHms() : "not con.");
}
bool CServer::matchesName(const QString &name) const
@@ -71,15 +68,16 @@ namespace BlackMisc
return m_port > 0 && !m_address.isEmpty();
}
QString CServer::getServerTypeAsString() const
bool CServer::isFsdServer() 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 {};
}
return (this->getServerType() == FSDServerVatsim ||
this->getServerType() == FSDServerLegacy ||
this->getServerType() == FSDServerFSC);
}
const QString &CServer::getServerTypeAsString() const
{
return serverTypeToString(getServerType());
}
bool CServer::isConnected() const
@@ -199,11 +197,33 @@ namespace BlackMisc
return Compare::compare(this->getPort(), compareValue.getPort());
case IndexUser:
return this->getUser().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getUser());
case IndexServerType:
case IndexServerTypeAsString:
return this->getServerTypeAsString().compare(compareValue.getServerTypeAsString(), Qt::CaseInsensitive);
default:
break;
}
Q_ASSERT_X(false, Q_FUNC_INFO, "No compare function");
return 0;
}
const QString &CServer::serverTypeToString(CServer::ServerType server)
{
static const QString fsdVatsim("FSD [VATSIM]");
static const QString fsdFsc("FSD [FSC]");
static const QString fsdLegacy("FSD (legacy)");
static const QString webService("web service");
static const QString unspecified("unspecified");
switch (server)
{
case FSDServerVatsim: return fsdVatsim;
case FSDServerFSC: return fsdFsc;
case FSDServerLegacy: return fsdLegacy;
case WebService: return webService;
case Unspecified: return unspecified;
default: return unspecified;
}
}
} // namespace
} // namespace