diff --git a/src/blackmisc/audio/audio.h b/src/blackmisc/audio/audio.h index 619518e7b..77bcf9e94 100644 --- a/src/blackmisc/audio/audio.h +++ b/src/blackmisc/audio/audio.h @@ -22,5 +22,6 @@ #include "blackmisc/audio/voiceroom.h" #include "blackmisc/audio/voiceroomlist.h" #include "blackmisc/audio/audiosettings.h" +#include "blackmisc/audio/voicesetup.h" #endif // guard diff --git a/src/blackmisc/audio/registermetadataaudio.cpp b/src/blackmisc/audio/registermetadataaudio.cpp index 4684e04c7..c6be5be8b 100644 --- a/src/blackmisc/audio/registermetadataaudio.cpp +++ b/src/blackmisc/audio/registermetadataaudio.cpp @@ -9,7 +9,6 @@ #include "registermetadataaudio.h" #include "audio.h" - #include namespace BlackMisc @@ -24,6 +23,9 @@ namespace BlackMisc CVoiceRoom::registerMetadata(); CVoiceRoomList::registerMetadata(); CSettings::registerMetadata(); + CVoiceSetup::registerMetadata(); + + // struct qDBusRegisterMetaType(); qDBusRegisterMetaType(); } diff --git a/src/blackmisc/audio/settings/voicesettings.h b/src/blackmisc/audio/settings/voicesettings.h new file mode 100644 index 000000000..5d3bce2b3 --- /dev/null +++ b/src/blackmisc/audio/settings/voicesettings.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_AUDIO_SETTINGS_VOICESETTINGS_H +#define BLACKMISC_AUDIO_SETTINGS_VOICESETTINGS_H + +#include "blackmisc/audio/voicesetup.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/settingscache.h" + +namespace BlackMisc +{ + namespace Audio + { + namespace Settings + { + //! Voice settings + struct TVoiceSetup : public TSettingTrait + { + //! \copydoc BlackMisc::TSettingTrait::key + static const char *key() { return "audio/currentvoicesetup"; } + + //! \copydoc BlackCore::TSettingTrait::humanReadable + static const QString &humanReadable() { static const QString name("Voice setup"); return name; } + + //! \copydoc BlackCore::TSettingTrait::isValid + static bool isValid(const CVoiceSetup &setup) { return setup.validate().isSuccess(); } + }; + } // ns + } // ns +} // ns + +#endif diff --git a/src/blackmisc/audio/voicesetup.cpp b/src/blackmisc/audio/voicesetup.cpp new file mode 100644 index 000000000..6b415cdf4 --- /dev/null +++ b/src/blackmisc/audio/voicesetup.cpp @@ -0,0 +1,85 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackmisc/audio/voicesetup.h" +#include "blackmisc/logcategorylist.h" +#include "blackmisc/stringutils.h" +#include "blackmisc/verify.h" +#include "blackmisc/comparefunctions.h" + +#include +#include + +namespace BlackMisc +{ + namespace Audio + { + QString CVoiceSetup::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + static const QString s("Port: %1"); + return s.arg(getVatsimUdpVoicePort()); + } + + CStatusMessageList CVoiceSetup::validate() const + { + static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); + CStatusMessageList msgs; + if (this->getVatsimUdpVoicePort() < 1 || this->getVatsimUdpVoicePort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, "Invalid voice port")); } + msgs.addCategories(cats); + return msgs; + } + + const CVoiceSetup &CVoiceSetup::vatsimStandard() + { + static const CVoiceSetup s; + return s; + } + + CVoiceSetup::CVoiceSetup(int vatsimUdpPort) : m_vatismVoiceUdpPort(vatsimUdpPort) + { } + + CVariant CVoiceSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexVatsimVoiceUdpPort: return CVariant::fromValue(m_vatismVoiceUdpPort); + default: return CValueObject::propertyByIndex(index); + } + } + + void CVoiceSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexVatsimVoiceUdpPort: m_vatismVoiceUdpPort = variant.toInt(); break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + + int CVoiceSetup::comparePropertyByIndex(const CPropertyIndex &index, const CVoiceSetup &compareValue) const + { + if (index.isMyself()) { return this->convertToQString(true).compare(compareValue.convertToQString()); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexVatsimVoiceUdpPort: return Compare::compare(m_vatismVoiceUdpPort, compareValue.m_vatismVoiceUdpPort); + default: break; + } + BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString())); + return 0; + } + } // namespace +} // namespace diff --git a/src/blackmisc/audio/voicesetup.h b/src/blackmisc/audio/voicesetup.h new file mode 100644 index 000000000..e6dc8f7ac --- /dev/null +++ b/src/blackmisc/audio/voicesetup.h @@ -0,0 +1,81 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_AUDIO_VOICESETUP_H +#define BLACKMISC_AUDIO_VOICESETUP_H + +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/metaclass.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/blackmiscexport.h" + +#include +#include + +namespace BlackMisc +{ + namespace Audio + { + //! Value object for a voice setup + class BLACKMISC_EXPORT CVoiceSetup : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexVatsimVoiceUdpPort = CPropertyIndex::GlobalIndexCVoiceSetup, + }; + + //! Default constructor. + CVoiceSetup() {} + + //! Setup with values + CVoiceSetup(int vatsimUdpPort); + + //! The voice UDP port + void setVatsimUdpVoicePort(int port) { m_vatismVoiceUdpPort = port;} + + //! VATSIM UDP voice port + int getVatsimUdpVoicePort() const { return m_vatismVoiceUdpPort; } + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); + + //! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex + int comparePropertyByIndex(const CPropertyIndex &index, const CVoiceSetup &compareValue) const; + + //! \copydoc BlackMisc::Mixin::String::toQString() + QString convertToQString(bool i18n = false) const; + + //! Validate + CStatusMessageList validate() const; + + //! Standard FSD setup for official VATSIM servers + static const CVoiceSetup &vatsimStandard(); + + private: + int m_vatismVoiceUdpPort = 3290; + + BLACK_METACLASS( + CVoiceSetup, + BLACK_METAMEMBER(vatismVoiceUdpPort) + ); + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Audio::CVoiceSetup) + +#endif // guard diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 440090445..a4d9cc6de 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -26,6 +26,7 @@ TRANSLATIONS += translations/blackmisc_i18n_de.ts \ HEADERS += *.h \ $$PWD/audio/*.h \ + $$PWD/audio/settings/*.h \ $$PWD/aviation/*.h \ $$PWD/db/*.h \ $$PWD/geo/*.h \ @@ -47,6 +48,7 @@ HEADERS += *.h \ SOURCES += *.cpp \ $$PWD/audio/*.cpp \ +# $$PWD/audio/settings/*.cpp \ $$PWD/aviation/*.cpp \ $$PWD/db/*.cpp \ $$PWD/geo/*.cpp \ diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 968d6acdb..423c3691e 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -124,12 +124,13 @@ namespace BlackMisc GlobalIndexCRole = 6300, GlobalIndexCServer = 6400, GlobalIndexCFsdSetup = 6500, - GlobalIndexCNetworkSettings = 6600, - GlobalIndexCUrl = 6700, - GlobalIndexCUrlLog = 6800, - GlobalIndexCRemoteFile = 6900, - GlobalIndexCEcosystem = 7000, - GlobalIndexCRawFsdMessage = 7100, + GlobalIndexCVoiceSetup = 6600, + GlobalIndexCNetworkSettings = 6700, + GlobalIndexCUrl = 6800, + GlobalIndexCUrlLog = 6900, + GlobalIndexCRemoteFile = 7000, + GlobalIndexCEcosystem = 7100, + GlobalIndexCRawFsdMessage = 7200, GlobalIndexCAircraftModel = 8000, GlobalIndexCSimulatedAircraft = 8100, GlobalIndexCTextMessage = 8200,