mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #227, client (representing other pilot client) class
* client class plus list * aircraft model class, representing the used model
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "blackmisc/avaircraftlist.h"
|
#include "blackmisc/avaircraftlist.h"
|
||||||
#include "blackmisc/nwserverlist.h"
|
#include "blackmisc/nwserverlist.h"
|
||||||
#include "blackmisc/nwuserlist.h"
|
#include "blackmisc/nwuserlist.h"
|
||||||
|
#include "blackmisc/nwclientlist.h"
|
||||||
#include "blackmisc/hwkeyboardkeylist.h"
|
#include "blackmisc/hwkeyboardkeylist.h"
|
||||||
#include "blackmisc/blackmiscfreefunctions.h"
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
|
|
||||||
@@ -210,6 +211,7 @@ namespace BlackGui
|
|||||||
template class CListModelBase<BlackMisc::Aviation::CAircraft, BlackMisc::Aviation::CAircraftList>;
|
template class CListModelBase<BlackMisc::Aviation::CAircraft, BlackMisc::Aviation::CAircraftList>;
|
||||||
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
|
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
|
||||||
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
|
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
|
||||||
|
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
|
||||||
template class CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>;
|
template class CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ void BlackMisc::Network::registerMetadata()
|
|||||||
CServerList::registerMetadata();
|
CServerList::registerMetadata();
|
||||||
CTextMessage::registerMetadata();
|
CTextMessage::registerMetadata();
|
||||||
CTextMessageList::registerMetadata();
|
CTextMessageList::registerMetadata();
|
||||||
|
CClient::registerMetadata();
|
||||||
|
CClientList::registerMetadata();
|
||||||
|
CAircraftModel::registerMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -10,5 +10,8 @@
|
|||||||
#include "blackmisc/nwuserlist.h"
|
#include "blackmisc/nwuserlist.h"
|
||||||
#include "blackmisc/nwserverlist.h"
|
#include "blackmisc/nwserverlist.h"
|
||||||
#include "blackmisc/nwtextmessagelist.h"
|
#include "blackmisc/nwtextmessagelist.h"
|
||||||
|
#include "blackmisc/nwclient.h"
|
||||||
|
#include "blackmisc/nwclientlist.h"
|
||||||
|
#include "blackmisc/nwaircraftmodel.h"
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
152
src/blackmisc/nwaircraftmodel.cpp
Normal file
152
src/blackmisc/nwaircraftmodel.cpp
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
#include "nwaircraftmodel.h"
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Convert to string
|
||||||
|
*/
|
||||||
|
QString CAircraftModel::convertToQString(bool /** i18n **/) const
|
||||||
|
{
|
||||||
|
QString s = this->m_queriedModelString;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare
|
||||||
|
*/
|
||||||
|
int CAircraftModel::compareImpl(const CValueObject &otherBase) const
|
||||||
|
{
|
||||||
|
const auto &other = static_cast<const CAircraftModel &>(otherBase);
|
||||||
|
return compare(TupleConverter<CAircraftModel>::toTuple(*this), TupleConverter<CAircraftModel>::toTuple(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Marshall to DBus
|
||||||
|
*/
|
||||||
|
void CAircraftModel::marshallToDbus(QDBusArgument &argument) const
|
||||||
|
{
|
||||||
|
argument << TupleConverter<CAircraftModel>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unmarshall from DBus
|
||||||
|
*/
|
||||||
|
void CAircraftModel::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
|
{
|
||||||
|
argument >> TupleConverter<CAircraftModel>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hash
|
||||||
|
*/
|
||||||
|
uint CAircraftModel::getValueHash() const
|
||||||
|
{
|
||||||
|
return qHash(TupleConverter<CAircraftModel>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Equal?
|
||||||
|
*/
|
||||||
|
bool CAircraftModel::operator ==(const CAircraftModel &other) const
|
||||||
|
{
|
||||||
|
if (this == &other) return true;
|
||||||
|
return TupleConverter<CAircraftModel>::toTuple(*this) == TupleConverter<CAircraftModel>::toTuple(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unequal?
|
||||||
|
*/
|
||||||
|
bool CAircraftModel::operator !=(const CAircraftModel &other) const
|
||||||
|
{
|
||||||
|
return !((*this) == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* metaTypeId
|
||||||
|
*/
|
||||||
|
int CAircraftModel::getMetaTypeId() const
|
||||||
|
{
|
||||||
|
return qMetaTypeId<CAircraftModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is a
|
||||||
|
*/
|
||||||
|
bool CAircraftModel::isA(int metaTypeId) const
|
||||||
|
{
|
||||||
|
if (metaTypeId == qMetaTypeId<CAircraftModel>()) { return true; }
|
||||||
|
return this->CValueObject::isA(metaTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register metadata
|
||||||
|
*/
|
||||||
|
void CAircraftModel::registerMetadata()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<CAircraftModel>();
|
||||||
|
qDBusRegisterMetaType<CAircraftModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Members
|
||||||
|
*/
|
||||||
|
const QStringList &CAircraftModel::jsonMembers()
|
||||||
|
{
|
||||||
|
return TupleConverter<CAircraftModel>::jsonMembers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To JSON
|
||||||
|
*/
|
||||||
|
QJsonObject CAircraftModel::toJson() const
|
||||||
|
{
|
||||||
|
return BlackMisc::serializeJson(CAircraftModel::jsonMembers(), TupleConverter<CAircraftModel>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From Json
|
||||||
|
*/
|
||||||
|
void CAircraftModel::fromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
BlackMisc::deserializeJson(json, CAircraftModel::jsonMembers(), TupleConverter<CAircraftModel>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Property by index
|
||||||
|
*/
|
||||||
|
QVariant CAircraftModel::propertyByIndex(int index) const
|
||||||
|
{
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case IndexQueriedModelString:
|
||||||
|
return QVariant(this->m_queriedModelString);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Q_ASSERT_X(false, "CAircraftModel", "index unknown");
|
||||||
|
QString m = QString("no property, index ").append(QString::number(index));
|
||||||
|
return QVariant::fromValue(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set property as index
|
||||||
|
*/
|
||||||
|
void CAircraftModel::setPropertyByIndex(const QVariant &variant, int index)
|
||||||
|
{
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case IndexQueriedModelString:
|
||||||
|
this->m_queriedModelString = variant.toString();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT_X(false, "CAircraftModel", "index unknown");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
99
src/blackmisc/nwaircraftmodel.h
Normal file
99
src/blackmisc/nwaircraftmodel.h
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#ifndef BLACKMISC_AIRCRAFTMODEL_H
|
||||||
|
#define BLACKMISC_AIRCRAFTMODEL_H
|
||||||
|
|
||||||
|
#include "nwuser.h"
|
||||||
|
#include "valueobject.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* Another pilot's aircraft model
|
||||||
|
*/
|
||||||
|
class CAircraftModel : public BlackMisc::CValueObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Indexes
|
||||||
|
enum ColumnIndex : uint
|
||||||
|
{
|
||||||
|
IndexQueriedModelString = 100
|
||||||
|
};
|
||||||
|
|
||||||
|
//! \brief Default constructor.
|
||||||
|
CAircraftModel() {}
|
||||||
|
|
||||||
|
//! \brief Constructor.
|
||||||
|
CAircraftModel(const QString &directModel) : m_queriedModelString(directModel) {}
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toQVariant
|
||||||
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
|
|
||||||
|
//! \brief Equal operator ==
|
||||||
|
bool operator ==(const CAircraftModel &other) const;
|
||||||
|
|
||||||
|
//! \brief Unequal operator !=
|
||||||
|
bool operator !=(const CAircraftModel &other) const;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getValueHash
|
||||||
|
virtual uint getValueHash() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toJson
|
||||||
|
virtual QJsonObject toJson() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::fromJson
|
||||||
|
void fromJson(const QJsonObject &json) override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::propertyByIndex(int)
|
||||||
|
virtual QVariant propertyByIndex(int index) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::setPropertyByIndex(const QVariant, int)
|
||||||
|
virtual void setPropertyByIndex(const QVariant &variant, int index) override;
|
||||||
|
|
||||||
|
//! Queried model string
|
||||||
|
const QString &getQueriedModelString() const { return this->m_queriedModelString; }
|
||||||
|
|
||||||
|
//! Set queried model string
|
||||||
|
void setQueriedModelString(const QString &model) { this->m_queriedModelString = model; }
|
||||||
|
|
||||||
|
//! Queried model string?
|
||||||
|
bool hasQueriedModelString() const { return !this->m_queriedModelString.isEmpty(); }
|
||||||
|
|
||||||
|
//! \brief Register metadata
|
||||||
|
static void registerMetadata();
|
||||||
|
|
||||||
|
//! \copydoc TupleConverter<>::jsonMembers()
|
||||||
|
static const QStringList &jsonMembers();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
virtual QString convertToQString(bool i18n = false) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getMetaTypeId
|
||||||
|
virtual int getMetaTypeId() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::isA
|
||||||
|
virtual bool isA(int metaTypeId) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::compareImpl
|
||||||
|
virtual int compareImpl(const CValueObject &other) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::marshallToDbus
|
||||||
|
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::unmarshallFromDbus
|
||||||
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CAircraftModel)
|
||||||
|
QString m_queriedModelString;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CAircraftModel, (o.m_queriedModelString))
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::Network::CAircraftModel)
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
226
src/blackmisc/nwclient.cpp
Normal file
226
src/blackmisc/nwclient.cpp
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
#include "nwclient.h"
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Convert to string
|
||||||
|
*/
|
||||||
|
QString CClient::convertToQString(bool i18n) const
|
||||||
|
{
|
||||||
|
QString s = this->m_user.toQString(i18n);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare
|
||||||
|
*/
|
||||||
|
int CClient::compareImpl(const CValueObject &otherBase) const
|
||||||
|
{
|
||||||
|
const auto &other = static_cast<const CClient &>(otherBase);
|
||||||
|
return compare(TupleConverter<CClient>::toTuple(*this), TupleConverter<CClient>::toTuple(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Marshall to DBus
|
||||||
|
*/
|
||||||
|
void CClient::marshallToDbus(QDBusArgument &argument) const
|
||||||
|
{
|
||||||
|
argument << TupleConverter<CClient>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unmarshall from DBus
|
||||||
|
*/
|
||||||
|
void CClient::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
|
{
|
||||||
|
argument >> TupleConverter<CClient>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hash
|
||||||
|
*/
|
||||||
|
uint CClient::getValueHash() const
|
||||||
|
{
|
||||||
|
return qHash(TupleConverter<CClient>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Equal?
|
||||||
|
*/
|
||||||
|
bool CClient::operator ==(const CClient &other) const
|
||||||
|
{
|
||||||
|
if (this == &other) return true;
|
||||||
|
return TupleConverter<CClient>::toTuple(*this) == TupleConverter<CClient>::toTuple(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unequal?
|
||||||
|
*/
|
||||||
|
bool CClient::operator !=(const CClient &other) const
|
||||||
|
{
|
||||||
|
return !((*this) == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* metaTypeId
|
||||||
|
*/
|
||||||
|
int CClient::getMetaTypeId() const
|
||||||
|
{
|
||||||
|
return qMetaTypeId<CClient>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is a
|
||||||
|
*/
|
||||||
|
bool CClient::isA(int metaTypeId) const
|
||||||
|
{
|
||||||
|
if (metaTypeId == qMetaTypeId<CClient>()) { return true; }
|
||||||
|
return this->CValueObject::isA(metaTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register metadata
|
||||||
|
*/
|
||||||
|
void CClient::registerMetadata()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<CClient>();
|
||||||
|
qDBusRegisterMetaType<CClient>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Members
|
||||||
|
*/
|
||||||
|
const QStringList &CClient::jsonMembers()
|
||||||
|
{
|
||||||
|
return TupleConverter<CClient>::jsonMembers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To JSON
|
||||||
|
*/
|
||||||
|
QJsonObject CClient::toJson() const
|
||||||
|
{
|
||||||
|
return BlackMisc::serializeJson(CClient::jsonMembers(), TupleConverter<CClient>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From Json
|
||||||
|
*/
|
||||||
|
void CClient::fromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
BlackMisc::deserializeJson(json, CClient::jsonMembers(), TupleConverter<CClient>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capability
|
||||||
|
*/
|
||||||
|
void CClient::setCapability(bool hasCapability, CClient::Capabilities capability)
|
||||||
|
{
|
||||||
|
this->m_capabilities.setPropertyByIndex(QVariant(hasCapability), capability);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capabilities
|
||||||
|
*/
|
||||||
|
void CClient::setCapabilities(const CIndexVariantMap &capabilities)
|
||||||
|
{
|
||||||
|
this->m_capabilities = capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capabilities
|
||||||
|
*/
|
||||||
|
QString CClient::getCapabilitiesAsString() const
|
||||||
|
{
|
||||||
|
QStringList sl;
|
||||||
|
if (this->hasCapability(FsdAtisCanBeReceived)) sl << "ATIS";
|
||||||
|
if (this->hasCapability(FsdWithInterimPositions)) sl << "interim pos.";
|
||||||
|
if (this->hasCapability(FsdWithModelDescription)) sl << "model";
|
||||||
|
if (sl.isEmpty()) return "";
|
||||||
|
return sl.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capability
|
||||||
|
*/
|
||||||
|
bool CClient::hasCapability(CClient::Capabilities capability) const
|
||||||
|
{
|
||||||
|
if (this->m_capabilities.contains(capability))
|
||||||
|
return this->m_capabilities.value(capability).toBool();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Property by index
|
||||||
|
*/
|
||||||
|
QVariant CClient::propertyByIndex(int index) const
|
||||||
|
{
|
||||||
|
if (index < static_cast<int>(IndexQueriedModelString))
|
||||||
|
{
|
||||||
|
return this->m_user.propertyByIndex(index);
|
||||||
|
}
|
||||||
|
else if (index < static_cast<int>(IndexCapabilities))
|
||||||
|
{
|
||||||
|
return this->m_model.propertyByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case IndexCapabilities:
|
||||||
|
return this->m_capabilities.toQVariant();
|
||||||
|
break;
|
||||||
|
case IndexCapabilitiesString:
|
||||||
|
return QVariant(this->getCapabilitiesAsString());
|
||||||
|
break;
|
||||||
|
case IndexModel:
|
||||||
|
return QVariant(this->m_model.toQVariant());
|
||||||
|
break;
|
||||||
|
case IndexHost:
|
||||||
|
return QVariant(this->m_host);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Q_ASSERT_X(false, "CClient", "index unknown");
|
||||||
|
QString m = QString("no property, index ").append(QString::number(index));
|
||||||
|
return QVariant::fromValue(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set property as index
|
||||||
|
*/
|
||||||
|
void CClient::setPropertyByIndex(const QVariant &variant, int index)
|
||||||
|
{
|
||||||
|
if (index < static_cast<int>(IndexQueriedModelString))
|
||||||
|
{
|
||||||
|
this->m_user.setPropertyByIndex(variant, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (index < static_cast<int>(IndexCapabilities))
|
||||||
|
{
|
||||||
|
this->m_model.setPropertyByIndex(variant, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case IndexCapabilities:
|
||||||
|
this->m_capabilities = variant.value<CIndexVariantMap>();
|
||||||
|
break;
|
||||||
|
case IndexModel:
|
||||||
|
this->m_model = variant.value<CAircraftModel>();
|
||||||
|
break;
|
||||||
|
case IndexHost:
|
||||||
|
this->m_host = variant.toString();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT_X(false, "CClient", "index unknown");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
153
src/blackmisc/nwclient.h
Normal file
153
src/blackmisc/nwclient.h
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
#ifndef BLACKMISC_CLIENT_H
|
||||||
|
#define BLACKMISC_CLIENT_H
|
||||||
|
|
||||||
|
#include "nwuser.h"
|
||||||
|
#include "nwaircraftmodel.h"
|
||||||
|
#include "valueobject.h"
|
||||||
|
#include "indexvariantmap.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* Another client software.
|
||||||
|
*/
|
||||||
|
class CClient : public BlackMisc::CValueObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief Properties by index
|
||||||
|
*/
|
||||||
|
enum ColumnIndex : uint
|
||||||
|
{
|
||||||
|
IndexEmail = 0,
|
||||||
|
IndexId,
|
||||||
|
IndexPassword,
|
||||||
|
IndexRealName,
|
||||||
|
IndexCallsign,
|
||||||
|
IndexCallsignIcon,
|
||||||
|
IndexQueriedModelString = 100,
|
||||||
|
IndexCapabilities = 1000,
|
||||||
|
IndexCapabilitiesString,
|
||||||
|
IndexModel, // own indexes
|
||||||
|
IndexHost
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The Capabilities enum
|
||||||
|
*/
|
||||||
|
enum Capabilities
|
||||||
|
{
|
||||||
|
FsdWithInterimPositions,
|
||||||
|
FsdWithModelDescription,
|
||||||
|
FsdAtisCanBeReceived
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Default constructor.
|
||||||
|
CClient() {}
|
||||||
|
|
||||||
|
//! Construct by callsign
|
||||||
|
CClient(const BlackMisc::Aviation::CCallsign &callsign) : m_user(CUser(callsign)) {}
|
||||||
|
|
||||||
|
//! Constructor.
|
||||||
|
CClient(const CUser &user) : m_user(user) {}
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toQVariant
|
||||||
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
|
|
||||||
|
//! Equal operator ==
|
||||||
|
bool operator ==(const CClient &other) const;
|
||||||
|
|
||||||
|
//! Unequal operator !=
|
||||||
|
bool operator !=(const CClient &other) const;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getValueHash
|
||||||
|
virtual uint getValueHash() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toJson
|
||||||
|
virtual QJsonObject toJson() const override;
|
||||||
|
|
||||||
|
//! Callsign used with other client
|
||||||
|
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_user.getCallsign(); }
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::fromJson
|
||||||
|
void fromJson(const QJsonObject &json) override;
|
||||||
|
|
||||||
|
|
||||||
|
//! Get capabilities
|
||||||
|
CIndexVariantMap getCapabilities() const { return this->m_capabilities; }
|
||||||
|
|
||||||
|
//! Set capability
|
||||||
|
void setCapability(bool hasCapability, Capabilities capability);
|
||||||
|
|
||||||
|
//! Set capabilities
|
||||||
|
void setCapabilities(const CIndexVariantMap &capabilities);
|
||||||
|
|
||||||
|
//! Get capabilities
|
||||||
|
QString getCapabilitiesAsString() const;
|
||||||
|
|
||||||
|
//! Has capability?
|
||||||
|
bool hasCapability(Capabilities capability) const;
|
||||||
|
|
||||||
|
//! Host
|
||||||
|
const QString &getHost() const { return this->m_host; }
|
||||||
|
|
||||||
|
//! Host
|
||||||
|
void setHost(const QString &host) { this->m_host = host;}
|
||||||
|
|
||||||
|
//! Model
|
||||||
|
const CAircraftModel &getAircraftModel() const { return this->m_model; }
|
||||||
|
|
||||||
|
//! Set model
|
||||||
|
void setAircraftModel(const CAircraftModel &model) { this->m_model = model; }
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toIcon()
|
||||||
|
virtual const QPixmap &toIcon() const override { return this->m_user.toIcon(); }
|
||||||
|
|
||||||
|
//! Register metadata
|
||||||
|
static void registerMetadata();
|
||||||
|
|
||||||
|
//! \copydoc TupleConverter<>::jsonMembers()
|
||||||
|
static const QStringList &jsonMembers();
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::propertyByIndex(int)
|
||||||
|
virtual QVariant propertyByIndex(int index) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::setPropertyByIndex(const QVariant, int)
|
||||||
|
virtual void setPropertyByIndex(const QVariant &variant, int index) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
virtual QString convertToQString(bool i18n = false) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getMetaTypeId
|
||||||
|
virtual int getMetaTypeId() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::isA
|
||||||
|
virtual bool isA(int metaTypeId) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::compareImpl
|
||||||
|
virtual int compareImpl(const CValueObject &other) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::marshallToDbus
|
||||||
|
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::unmarshallFromDbus
|
||||||
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CClient)
|
||||||
|
CUser m_user;
|
||||||
|
CAircraftModel m_model;
|
||||||
|
CIndexVariantMap m_capabilities;
|
||||||
|
QString m_host;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CClient, (o.m_user, o.m_model, o.m_capabilities))
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::Network::CClient)
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
34
src/blackmisc/nwclientlist.cpp
Normal file
34
src/blackmisc/nwclientlist.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "nwclientlist.h"
|
||||||
|
#include "predicates.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
CClientList::CClientList() { }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Construct from base class object
|
||||||
|
*/
|
||||||
|
CClientList::CClientList(const CSequence &other) : CSequence<CClient>(other)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register metadata
|
||||||
|
*/
|
||||||
|
void CClientList::registerMetadata()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<CClientList>();
|
||||||
|
qDBusRegisterMetaType<CClientList>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
45
src/blackmisc/nwclientlist.h
Normal file
45
src/blackmisc/nwclientlist.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_CLIENTLIST_H
|
||||||
|
#define BLACKMISC_CLIENTLIST_H
|
||||||
|
|
||||||
|
#include "nwclient.h"
|
||||||
|
#include "sequence.h"
|
||||||
|
#include "collection.h"
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
//! Value object encapsulating a list of voice rooms.
|
||||||
|
class CClientList : public CSequence<CClient>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! \brief Default constructor.
|
||||||
|
CClientList();
|
||||||
|
|
||||||
|
//! Construct from a base class object.
|
||||||
|
CClientList(const CSequence &other);
|
||||||
|
|
||||||
|
//! QVariant, required for DBus QVariant lists
|
||||||
|
virtual QVariant asQVariant() const { return QVariant::fromValue(*this); }
|
||||||
|
|
||||||
|
//! Register metadata
|
||||||
|
static void registerMetadata();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::Network::CClientList)
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Network::CClient>)
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Network::CClient>)
|
||||||
|
|
||||||
|
#endif //guard
|
||||||
Reference in New Issue
Block a user