mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
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:
@@ -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
|
||||
|
||||
@@ -52,17 +52,25 @@ namespace BlackMisc
|
||||
//! Server Type
|
||||
enum ServerType
|
||||
{
|
||||
ServerVatsim,
|
||||
ServerFSC,
|
||||
ServerLegacyFSD
|
||||
FSDServerVatsim,
|
||||
FSDServerFSC,
|
||||
FSDServerLegacy,
|
||||
WebService,
|
||||
Unspecified
|
||||
};
|
||||
|
||||
//! Allows to iterate over all ServerType
|
||||
static const QList<int> &allServerTypes();
|
||||
|
||||
//! Enum to string
|
||||
static const QString &serverTypeToString(ServerType server);
|
||||
|
||||
//! Default constructor.
|
||||
CServer() {}
|
||||
|
||||
//! Constructor.
|
||||
CServer(const QString &name, const QString &description, const QString &address, int port,
|
||||
const CUser &user, bool isAcceptingConnections = true, ServerType serverType = ServerVatsim);
|
||||
const CUser &user, ServerType serverType = FSDServerVatsim, bool isAcceptingConnections = true);
|
||||
|
||||
//! Get address.
|
||||
const QString &getAddress() const { return m_address; }
|
||||
@@ -118,17 +126,20 @@ namespace BlackMisc
|
||||
//! Get setup
|
||||
const CFsdSetup &getFsdSetup() const { return this->m_fsdSetup; }
|
||||
|
||||
//! A FSD server?
|
||||
bool isFsdServer() const;
|
||||
|
||||
//! Set setup
|
||||
void setFsdSetup(const CFsdSetup &setup) { this->m_fsdSetup = setup; }
|
||||
|
||||
//! Set server type
|
||||
void setServerType(ServerType serverType) { m_serverType = serverType; }
|
||||
void setServerType(ServerType serverType) { m_serverType = static_cast<int>(serverType); }
|
||||
|
||||
//! Get server type
|
||||
ServerType getServerType() const { return m_serverType; }
|
||||
ServerType getServerType() const { return static_cast<ServerType>(m_serverType); }
|
||||
|
||||
//! Get server type as string
|
||||
QString getServerTypeAsString() const;
|
||||
const QString &getServerTypeAsString() const;
|
||||
|
||||
//! Connected since
|
||||
QDateTime getConnectedSince() const { return this->getUtcTimestamp(); }
|
||||
@@ -167,8 +178,8 @@ namespace BlackMisc
|
||||
int m_port = -1;
|
||||
CUser m_user;
|
||||
CFsdSetup m_fsdSetup;
|
||||
int m_serverType = FSDServerVatsim;
|
||||
bool m_isAcceptingConnections = true; //!< disable server for connections
|
||||
ServerType m_serverType = ServerVatsim;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CServer,
|
||||
@@ -178,8 +189,8 @@ namespace BlackMisc
|
||||
BLACK_METAMEMBER(port),
|
||||
BLACK_METAMEMBER(user),
|
||||
BLACK_METAMEMBER(fsdSetup),
|
||||
BLACK_METAMEMBER(isAcceptingConnections),
|
||||
BLACK_METAMEMBER(serverType),
|
||||
BLACK_METAMEMBER(isAcceptingConnections),
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include "blackmisc/network/serverlist.h"
|
||||
#include "blackmisc/metaclassprivate.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -72,6 +70,16 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
CServerList CServerList::findFsdServers() const
|
||||
{
|
||||
CServerList fsdServers;
|
||||
for (const CServer &s : *this)
|
||||
{
|
||||
if (s.isFsdServer()) { fsdServers.push_back(s); }
|
||||
}
|
||||
return fsdServers;
|
||||
}
|
||||
|
||||
void CServerList::setFsdSetup(const CFsdSetup &setup)
|
||||
{
|
||||
for (CServer &s : *this)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#ifndef BLACKMISC_NETWORK_SERVERLIST_H
|
||||
#define BLACKMISC_NETWORK_SERVERLIST_H
|
||||
|
||||
#include "server.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
class CServer;
|
||||
|
||||
//! Value object encapsulating a list of servers.
|
||||
class BLACKMISC_EXPORT CServerList :
|
||||
public CSequence<CServer>,
|
||||
@@ -56,6 +54,9 @@ namespace BlackMisc
|
||||
//! Add if address not already exists
|
||||
void addIfAddressNotExists(const CServerList &servers);
|
||||
|
||||
//! Find all FSD servers
|
||||
CServerList findFsdServers() const;
|
||||
|
||||
//! Set FSD setup for all entries
|
||||
void setFsdSetup(const CFsdSetup &setup);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user