diff --git a/samples/blackgui/mainwindow_settings.cpp b/samples/blackgui/mainwindow_settings.cpp index ac4228c17..9b4f04169 100644 --- a/samples/blackgui/mainwindow_settings.cpp +++ b/samples/blackgui/mainwindow_settings.cpp @@ -29,12 +29,10 @@ void MainWindow::reloadSettings() // update hot keys this->ui->tvp_SettingsMiscHotkeys->update(this->getIContextSettings()->getHotkeys()); - - - // fake setting for sound notifications this->ui->cb_SettingsAudioPlayNotificationSounds->setChecked(true); this->ui->cb_SettingsAudioNotificationTextMessage->setChecked(true); + this->ui->cb_SettingsAudioNotificationVoiceRoom->setChecked(true); } /* diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp index 815107dcb..e1fa84dcb 100644 --- a/samples/blackgui/mainwindow_voice.cpp +++ b/samples/blackgui/mainwindow_voice.cpp @@ -237,6 +237,5 @@ void MainWindow::playNotifcationSound(CNotificationSounds::Notification notifica { if (!this->m_contextAudioAvailable) return; if (!this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked()) return; - if (notification == CNotificationSounds::NotificationTextMessage && !this->ui->cb_SettingsAudioNotificationTextMessage->isChecked()) return; - this->getIContextAudio()->playNotification(static_cast(notification)); + this->getIContextAudio()->playNotification(static_cast(notification), true); } diff --git a/src/blackmisc/setaudio.cpp b/src/blackmisc/setaudio.cpp new file mode 100644 index 000000000..f8d098f9c --- /dev/null +++ b/src/blackmisc/setaudio.cpp @@ -0,0 +1,165 @@ +#include "setaudio.h" +using namespace BlackSound; + +namespace BlackMisc +{ + namespace Settings + { + /* + * Constructor + */ + CSettingsAudio::CSettingsAudio() + { + this->initDefaultValues(); + } + + /* + * Flag + */ + bool CSettingsAudio::getNotificationFlag(CNotificationSounds::Notification notification) const + { + QChar f = m_notificationFlags.at(static_cast(notification)); + return '1' == f; + } + + /* + * Convert to string + */ + QString CSettingsAudio::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + QString s("Notification flags:"); + s.append(" ").append(m_notificationFlags); + return s; + } + + /* + * metaTypeId + */ + int CSettingsAudio::getMetaTypeId() const + { + return qMetaTypeId(); + } + + /* + * is a + */ + bool CSettingsAudio::isA(int metaTypeId) const + { + if (metaTypeId == qMetaTypeId()) { return true; } + return this->CValueObject::isA(metaTypeId); + } + + /* + * Compare + */ + int CSettingsAudio::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall + */ + void CSettingsAudio::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall + */ + void CSettingsAudio::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Equal? + */ + bool CSettingsAudio::operator ==(const CSettingsAudio &other) const + { + if (this == &other) return true; + return compare(*this, other) == 0; + } + + /* + * Unequal? + */ + bool CSettingsAudio::operator !=(const CSettingsAudio &other) const + { + return !((*this) == other); + } + + /* + * Hash + */ + uint CSettingsAudio::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * To JSON + */ + QJsonObject CSettingsAudio::toJson() const + { + return BlackMisc::serializeJson(CSettingsAudio::jsonMembers(), TupleConverter::toTuple(*this)); + } + + /* + * From JSON + */ + void CSettingsAudio::fromJson(const QJsonObject &json) + { + BlackMisc::deserializeJson(json, CSettingsAudio::jsonMembers(), TupleConverter::toTuple(*this)); + } + + /* + * Members + */ + const QStringList &CSettingsAudio::jsonMembers() + { + return TupleConverter::jsonMembers(); + } + + /* + * Default values + */ + void CSettingsAudio::initDefaultValues() + { + this->m_notificationFlags = QString(1 + static_cast(CNotificationSounds::Notification::NotificationsLoadSounds), '1'); + } + + /* + * Register metadata + */ + void CSettingsAudio::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + /* + * Value + */ + BlackMisc::CStatusMessageList CSettingsAudio::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag) + { + // TODO: This needs to be refactored to a smarter way to delegate commands + changedFlag = false; + CStatusMessageList msgs; + if (path == CSettingsAudio::ValueNotificationFlag()) + { + if (command == CSettingUtilities::CmdSetTrue() || command == CSettingUtilities::CmdSetFalse()) + { + CNotificationSounds::Notification index = static_cast(value.toInt()); + char value = (command == CSettingUtilities::CmdSetTrue()) ? '1' : '0' ; + this->m_notificationFlags.replace(index, 1, value); + return msgs; + } + } + return CSettingUtilities::wrongPathMessages(path); + } + } // namespace +} // namespace diff --git a/src/blackmisc/setaudio.h b/src/blackmisc/setaudio.h new file mode 100644 index 000000000..bf5b993f6 --- /dev/null +++ b/src/blackmisc/setaudio.h @@ -0,0 +1,105 @@ +/* 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_SETTINGS_AUDIO_H +#define BLACKMISC_SETTINGS_AUDIO_H + +#include "valueobject.h" +#include "statusmessagelist.h" +#include "settingutilities.h" +#include "notificationsounds.h" +#include + +namespace BlackMisc +{ + namespace Settings + { + //! Value object encapsulating information of audio related settings. + class CSettingsAudio : public BlackMisc::CValueObject + { + public: + //! Default constructor. + CSettingsAudio(); + + //! Destructor. + virtual ~CSettingsAudio() {} + + //! Path + static const QString &ValueNotificationFlag() + { + static const QString value("notificationflag"); + return value; + } + + //! \copydoc CValueObject::toQVariant() + virtual QVariant toQVariant() const override + { + return QVariant::fromValue(*this); + } + + //! Notification flag (play notification?) + bool getNotificationFlag(BlackSound::CNotificationSounds::Notification notification) const; + + //! Notification flag (play notification?) + void setNotificationFlag(BlackSound::CNotificationSounds::Notification notification, bool value); + + //! Equal operator == + bool operator ==(const CSettingsAudio &other) const; + + //! Unequal operator != + bool operator !=(const CSettingsAudio &other) const; + + //! \copydoc BlackCore::IContextSettings + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag); + + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + + //! \copydoc CValueObject::toJson + virtual QJsonObject toJson() const override; + + //! \copydoc CValueObject::fromJson + virtual void fromJson(const QJsonObject &json) override; + + //! Init with meaningful default values + void initDefaultValues(); + + //! \copydoc CValueObject::registerMetadata + 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(CSettingsAudio) + QString m_notificationFlags; //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) + }; + + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Settings::CSettingsAudio) +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Settings::CSettingsAudio, (o.m_notificationFlags)) + +#endif // guard diff --git a/src/blackmisc/settingsallclasses.h b/src/blackmisc/settingsallclasses.h index 629f14e66..9cff2d995 100644 --- a/src/blackmisc/settingsallclasses.h +++ b/src/blackmisc/settingsallclasses.h @@ -7,5 +7,6 @@ #define BLACKMISC_SETTINGSALLCLASSES_H #include "blackmisc/setnetwork.h" +#include "blackmisc/setaudio.h" #endif // guard diff --git a/src/blackmisc/settingutilities.h b/src/blackmisc/settingutilities.h index 9c0ac2fab..c06cbafd0 100644 --- a/src/blackmisc/settingutilities.h +++ b/src/blackmisc/settingutilities.h @@ -7,7 +7,7 @@ namespace BlackMisc { namespace Settings { - //! \brief Helper / utility methods for settings + //! Helper / utility methods for settings class CSettingUtilities { private: @@ -43,6 +43,20 @@ namespace BlackMisc return cmd; } + //! Command Set boolean value true + static const QString &CmdSetTrue() + { + static const QString cmd("set:true"); + return cmd; + } + + //! Command Set boolean value false + static const QString &CmdSetFalse() + { + static const QString cmd("set:false"); + return cmd; + } + //! \brief Wrong path message static BlackMisc::CStatusMessage wrongPathMessage(const QString &path = ""); diff --git a/src/blacksound/soundgenerator.cpp b/src/blacksound/soundgenerator.cpp index 2acce37dc..334bdcb78 100644 --- a/src/blacksound/soundgenerator.cpp +++ b/src/blacksound/soundgenerator.cpp @@ -474,10 +474,14 @@ namespace BlackSound success = playlist->addMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath().append("/sounds/login.wav"))) && success; success = playlist->addMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath().append("/sounds/logoff.wav"))) && success; success = playlist->addMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath().append("/sounds/privatemessage.wav"))) && success; + success = playlist->addMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath().append("/sounds/voiceroomjoined.wav"))) && success; + success = playlist->addMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath().append("/sounds/voiceroomleft.wav"))) && success; + Q_ASSERT(success); playlist->setPlaybackMode(QMediaPlaylist::CurrentItemOnce); mediaPlayer->setPlaylist(playlist); } + if (notification == CNotificationSounds::NotificationsLoadSounds) return; int index = static_cast(notification); playlist->setCurrentIndex(index); mediaPlayer->setVolume(volume); // 0-100 diff --git a/src/blacksound/sounds/voiceroomjoined.wav b/src/blacksound/sounds/voiceroomjoined.wav new file mode 100644 index 000000000..8149d79bc Binary files /dev/null and b/src/blacksound/sounds/voiceroomjoined.wav differ diff --git a/src/blacksound/sounds/voiceroomleft.wav b/src/blacksound/sounds/voiceroomleft.wav new file mode 100644 index 000000000..8149d79bc Binary files /dev/null and b/src/blacksound/sounds/voiceroomleft.wav differ