mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
Prepared for voice capabilities
This commit is contained in:
@@ -26,5 +26,9 @@
|
||||
<file>icons/sky.jpg</file>
|
||||
<file>icons/tower_framed.jpg</file>
|
||||
<file>icons/gnd_framed.jpg</file>
|
||||
<file>icons/captextonly.png</file>
|
||||
<file>icons/capunknown.png</file>
|
||||
<file>icons/capvoice.png</file>
|
||||
<file>icons/capvoicereceive.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -96,6 +96,7 @@ void BlackMisc::Network::registerMetadata()
|
||||
CClient::registerMetadata();
|
||||
CClientList::registerMetadata();
|
||||
CAircraftModel::registerMetadata();
|
||||
CVoiceCapabilities::registerMetadata();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
BIN
src/blackmisc/icons/captextonly.png
Normal file
BIN
src/blackmisc/icons/captextonly.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 723 B |
BIN
src/blackmisc/icons/capunknown.png
Normal file
BIN
src/blackmisc/icons/capunknown.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 B |
BIN
src/blackmisc/icons/capvoice.png
Normal file
BIN
src/blackmisc/icons/capvoice.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 717 B |
BIN
src/blackmisc/icons/capvoicereceive.png
Normal file
BIN
src/blackmisc/icons/capvoicereceive.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 769 B |
@@ -13,5 +13,6 @@
|
||||
#include "blackmisc/nwclient.h"
|
||||
#include "blackmisc/nwclientlist.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include "blackmisc/nwvoicecapabilities.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -182,6 +182,15 @@ namespace BlackMisc
|
||||
case IndexHost:
|
||||
return QVariant(this->m_host);
|
||||
break;
|
||||
case IndexVoiceCapabilities:
|
||||
return this->m_voiceCapabilities.toQVariant();
|
||||
break;
|
||||
case IndexVoiceCapabilitiesString:
|
||||
return QVariant(this->m_voiceCapabilities.toQString(false));
|
||||
break;
|
||||
case IndexVoiceCapabilitiesIcon:
|
||||
return QVariant(this->m_voiceCapabilities.toIcon());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -217,6 +226,12 @@ namespace BlackMisc
|
||||
case IndexHost:
|
||||
this->m_host = variant.toString();
|
||||
break;
|
||||
case IndexVoiceCapabilities:
|
||||
this->m_voiceCapabilities = variant.value<CVoiceCapabilities>();
|
||||
break;
|
||||
case IndexVoiceCapabilitiesString:
|
||||
this->m_voiceCapabilities = CVoiceCapabilities(variant.toString());
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(false, "CClient", "index unknown");
|
||||
break;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "nwuser.h"
|
||||
#include "nwaircraftmodel.h"
|
||||
#include "nwvoicecapabilities.h"
|
||||
#include "valueobject.h"
|
||||
#include "indexvariantmap.h"
|
||||
|
||||
@@ -22,17 +23,23 @@ namespace BlackMisc
|
||||
*/
|
||||
enum ColumnIndex : uint
|
||||
{
|
||||
// user
|
||||
IndexEmail = 0,
|
||||
IndexId,
|
||||
IndexPassword,
|
||||
IndexRealName,
|
||||
IndexCallsign,
|
||||
IndexCallsignIcon,
|
||||
// model
|
||||
IndexQueriedModelString = 100,
|
||||
// own indexes
|
||||
IndexCapabilities = 1000,
|
||||
IndexCapabilitiesString,
|
||||
IndexModel, // own indexes
|
||||
IndexHost
|
||||
IndexModel,
|
||||
IndexHost,
|
||||
IndexVoiceCapabilities,
|
||||
IndexVoiceCapabilitiesString,
|
||||
IndexVoiceCapabilitiesIcon
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -75,7 +82,6 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::fromJson
|
||||
void fromJson(const QJsonObject &json) override;
|
||||
|
||||
|
||||
//! Get capabilities
|
||||
CIndexVariantMap getCapabilities() const { return this->m_capabilities; }
|
||||
|
||||
@@ -91,6 +97,15 @@ namespace BlackMisc
|
||||
//! Has capability?
|
||||
bool hasCapability(Capabilities capability) const;
|
||||
|
||||
//! Get voice capabilities
|
||||
const CVoiceCapabilities &getVoiceCapabilities() const { return m_voiceCapabilities;}
|
||||
|
||||
//! Set voice capabilities
|
||||
void setVoiceCapabilities(const CVoiceCapabilities &voiceCapabilities) { m_voiceCapabilities = voiceCapabilities;}
|
||||
|
||||
//! Set voice capabilities
|
||||
void setVoiceCapabilities(const QString &flightPlanRemarks) { m_voiceCapabilities = CVoiceCapabilities(flightPlanRemarks);}
|
||||
|
||||
//! Host
|
||||
const QString &getHost() const { return this->m_host; }
|
||||
|
||||
@@ -143,6 +158,8 @@ namespace BlackMisc
|
||||
CAircraftModel m_model;
|
||||
CIndexVariantMap m_capabilities;
|
||||
QString m_host;
|
||||
CVoiceCapabilities m_voiceCapabilities;
|
||||
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
190
src/blackmisc/nwvoicecapabilites.cpp
Normal file
190
src/blackmisc/nwvoicecapabilites.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "blackmisc/nwvoicecapabilities.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include <tuple>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CVoiceCapabilities::CVoiceCapabilities(const QString &flightPlanRemarks)
|
||||
{
|
||||
this->fromFlightPlanRemarks(flightPlanRemarks);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CVoiceCapabilities::convertToQString(bool /** i18n **/) const
|
||||
{
|
||||
switch (this->m_voiceCapabilities)
|
||||
{
|
||||
case Voice:
|
||||
{
|
||||
static const QString v("voice");
|
||||
return v;
|
||||
}
|
||||
case TextOnly:
|
||||
{
|
||||
static const QString t("text only");
|
||||
return t;
|
||||
}
|
||||
case VoiceReceivingOnly:
|
||||
{
|
||||
static const QString r("voice listening only");
|
||||
return r;
|
||||
}
|
||||
default:
|
||||
case Unknown:
|
||||
{
|
||||
static const QString u("unknown");
|
||||
return u;
|
||||
}
|
||||
}
|
||||
Q_ASSERT("Wrong index");
|
||||
return QString(""); // never reached
|
||||
}
|
||||
|
||||
void CVoiceCapabilities::fromFlightPlanRemarks(const QString &flightPlanRemarks)
|
||||
{
|
||||
if (flightPlanRemarks.isEmpty())
|
||||
{
|
||||
this->m_voiceCapabilities = Unknown;
|
||||
return;
|
||||
}
|
||||
|
||||
QString r = flightPlanRemarks.toLower();
|
||||
if (r.contains("/v/") || r.contains("/voice/"))
|
||||
{
|
||||
this->setCapabilities(Voice);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* metaTypeId
|
||||
*/
|
||||
int CVoiceCapabilities::getMetaTypeId() const
|
||||
{
|
||||
return qMetaTypeId<CVoiceCapabilities>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CVoiceCapabilities::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CVoiceCapabilities>()) { return true; }
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CVoiceCapabilities::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CVoiceCapabilities &>(otherBase);
|
||||
return compare(TupleConverter<CVoiceCapabilities>::toTuple(*this), TupleConverter<CVoiceCapabilities>::toTuple(other));
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CVoiceCapabilities::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << TupleConverter<CVoiceCapabilities>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CVoiceCapabilities::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> TupleConverter<CVoiceCapabilities>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
const QPixmap &CVoiceCapabilities::toIcon() const
|
||||
{
|
||||
static const QPixmap v(QPixmap(":/blackmisc/icons/capvoice.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static const QPixmap t(QPixmap(":/blackmisc/icons/captextonly.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static const QPixmap u(QPixmap(":/blackmisc/icons/capunknown.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static const QPixmap r(QPixmap(":/blackmisc/icons/capvoicereceive.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
|
||||
switch (this->m_voiceCapabilities)
|
||||
{
|
||||
case Voice:
|
||||
return v;
|
||||
case TextOnly:
|
||||
return t;
|
||||
case Unknown:
|
||||
return u;
|
||||
case VoiceReceivingOnly:
|
||||
return r;
|
||||
}
|
||||
Q_ASSERT("Wrong index");
|
||||
return u; // never reached
|
||||
}
|
||||
|
||||
bool CVoiceCapabilities::operator ==(const CVoiceCapabilities &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return TupleConverter<CVoiceCapabilities>::toTuple(*this) == TupleConverter<CVoiceCapabilities>::toTuple(other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unequal?
|
||||
*/
|
||||
bool CVoiceCapabilities::operator !=(const CVoiceCapabilities &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CVoiceCapabilities::getValueHash() const
|
||||
{
|
||||
return qHash(TupleConverter<CVoiceCapabilities>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
QJsonObject CVoiceCapabilities::toJson() const
|
||||
{
|
||||
return BlackMisc::serializeJson(CVoiceCapabilities::jsonMembers(), TupleConverter<CVoiceCapabilities>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
void CVoiceCapabilities::fromJson(const QJsonObject &json)
|
||||
{
|
||||
BlackMisc::deserializeJson(json, CVoiceCapabilities::jsonMembers(), TupleConverter<CVoiceCapabilities>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
const QStringList &CVoiceCapabilities::jsonMembers()
|
||||
{
|
||||
return TupleConverter<CVoiceCapabilities>::jsonMembers();
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CVoiceCapabilities::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CVoiceCapabilities>();
|
||||
qDBusRegisterMetaType<CVoiceCapabilities>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
108
src/blackmisc/nwvoicecapabilities.h
Normal file
108
src/blackmisc/nwvoicecapabilities.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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_VOICECAPABILITIES_H
|
||||
#define BLACKMISC_VOICECAPABILITIES_H
|
||||
|
||||
#include "valueobject.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
|
||||
/*!
|
||||
* Value object encapsulating information for voice capabilities.
|
||||
*/
|
||||
class CVoiceCapabilities : public BlackMisc::CValueObject
|
||||
{
|
||||
public:
|
||||
|
||||
//!< Voice capabilities
|
||||
enum VoiceCapabilities
|
||||
{
|
||||
Unknown,
|
||||
Voice,
|
||||
VoiceReceivingOnly,
|
||||
TextOnly,
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CVoiceCapabilities() {}
|
||||
|
||||
//! Constructor by callsign
|
||||
CVoiceCapabilities(VoiceCapabilities capabilities) : m_voiceCapabilities(static_cast<uint>(capabilities)) {}
|
||||
|
||||
//! Constructor.
|
||||
CVoiceCapabilities(const QString &flightPlanRemarks);
|
||||
|
||||
//! \copydoc CValueObject::toQVariant()
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! Get capabilities
|
||||
VoiceCapabilities getCapabilities() const { return static_cast<VoiceCapabilities>(m_voiceCapabilities); }
|
||||
|
||||
//! Set capabilites
|
||||
void setCapabilities(VoiceCapabilities capabilites) { m_voiceCapabilities = static_cast<uint>(capabilites); }
|
||||
|
||||
//! \copydoc CValueObject::toIcon()
|
||||
virtual const QPixmap &toIcon() const override;
|
||||
|
||||
//! \brief Equal operator ==
|
||||
bool operator ==(const CVoiceCapabilities &other) const;
|
||||
|
||||
//! \brief Unequal operator !=
|
||||
bool operator !=(const CVoiceCapabilities &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;
|
||||
|
||||
//! \brief Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
//! \brief Members
|
||||
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(CVoiceCapabilities)
|
||||
uint m_voiceCapabilities;
|
||||
|
||||
//! Capabilites from flight plans remarks such as "/V/"
|
||||
void fromFlightPlanRemarks(const QString &flightPlanRemarks);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CVoiceCapabilities, (o.m_voiceCapabilities))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CVoiceCapabilities)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user