diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index a73b6d8d2..e1726a390 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -166,7 +166,7 @@ namespace BlackCore //! Play notification sound //! \param notification CSoundGenerator::Notification //! \param considerSettings consider settings (notification on/off), false means settings ignored - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const = 0; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings) const = 0; //! Enable audio loopback virtual void enableAudioLoopback(bool enable = true) = 0; diff --git a/src/blackcore/context/contextaudioempty.h b/src/blackcore/context/contextaudioempty.h index 7b518dd71..1dbbfb1fd 100644 --- a/src/blackcore/context/contextaudioempty.h +++ b/src/blackcore/context/contextaudioempty.h @@ -150,7 +150,7 @@ namespace BlackCore } //! \copydoc IContextAudio::playNotification() - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings) const override { Q_UNUSED(notification); Q_UNUSED(considerSettings); diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 9c453f774..4fe214743 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -430,22 +430,19 @@ namespace BlackCore m_selcalPlayer->play(90, selcal); } - void CContextAudio::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const + void CContextAudio::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings) const { Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; } - bool play = !considerSettings || m_audioSettings.getThreadLocal().getNotificationFlag(notification); - if (play) - { - CSoundGenerator::playNotificationSound(90, notification); - } + const bool play = !considerSettings || m_audioSettings.getThreadLocal().isNotificationFlagSet(notification); + if (play) { CSoundGenerator::playNotificationSound(90, notification); } } void CContextAudio::initNotificationSounds() { // not possible in own thread - CSoundGenerator::playNotificationSound(0, CNotificationSounds::NotificationsLoadSounds); + CSoundGenerator::playNotificationSound(0, CNotificationSounds::LoadSounds); } void CContextAudio::enableAudioLoopback(bool enable) @@ -544,10 +541,8 @@ namespace BlackCore case IVoiceChannel::Connected: emit this->changedVoiceRooms(getComVoiceRooms(), true); break; - case IVoiceChannel::Disconnecting: - break; - case IVoiceChannel::Connecting: - break; + case IVoiceChannel::Disconnecting: break; + case IVoiceChannel::Connecting: break; case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: CLogMessage(this).warning(u"Voice channel disconnecting error"); diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 385e7ddd4..c380272a8 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -92,7 +92,7 @@ namespace BlackCore virtual void setMute(bool muted) override; virtual bool isMuted() const override; virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings) const override; virtual void enableAudioLoopback(bool enable = true) override; virtual bool isAudioLoopbackEnabled() const override; virtual BlackMisc::Audio::CVoiceSetup getVoiceSetup() const override; diff --git a/src/blackcore/context/contextaudioproxy.cpp b/src/blackcore/context/contextaudioproxy.cpp index f2465a744..113272b9c 100644 --- a/src/blackcore/context/contextaudioproxy.cpp +++ b/src/blackcore/context/contextaudioproxy.cpp @@ -122,7 +122,7 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1String("playSelcalTone"), selcal); } - void CContextAudioProxy::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const + void CContextAudioProxy::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings) const { this->m_dBusInterface->callDBus(QLatin1String("playNotification"), notification, considerSettings); } diff --git a/src/blackcore/context/contextaudioproxy.h b/src/blackcore/context/contextaudioproxy.h index 8c0527977..72a88b4e0 100644 --- a/src/blackcore/context/contextaudioproxy.h +++ b/src/blackcore/context/contextaudioproxy.h @@ -80,7 +80,7 @@ namespace BlackCore virtual void setMute(bool muted) override; virtual bool isMuted() const override; virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings) const override; virtual void enableAudioLoopback(bool enable = true) override; virtual bool isAudioLoopbackEnabled() const override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; diff --git a/src/blackgui/components/voiceroomscomponent.cpp b/src/blackgui/components/voiceroomscomponent.cpp index e8408a0de..b0e2fbdad 100644 --- a/src/blackgui/components/voiceroomscomponent.cpp +++ b/src/blackgui/components/voiceroomscomponent.cpp @@ -118,7 +118,7 @@ namespace BlackGui // notify if (sGui->getIContextAudio()) { - CNotificationSounds::Notification sound = connected ? + CNotificationSounds::NotificationFlag sound = connected ? CNotificationSounds::NotificationVoiceRoomJoined : CNotificationSounds::NotificationVoiceRoomLeft; sGui->getIContextAudio()->playNotification(sound, true); diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index 4413c5540..310cc6653 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -11,6 +11,7 @@ #include #include +#include using namespace BlackMisc::Audio; @@ -23,37 +24,32 @@ namespace BlackMisc this->initDefaultValues(); } - bool CSettings::getNotificationFlag(CNotificationSounds::Notification notification) const + bool CSettings::isNotificationFlagSet(CNotificationSounds::NotificationFlag notification) const { - const int i = static_cast(notification); - if (i >= m_notificationFlags.length()) return true; // default - QChar f = m_notificationFlags.at(i); - return '1' == f; + return this->getNotification().testFlag(notification); + } + + void CSettings::setNotificationFlag(CNotificationSounds::NotificationFlag notification, bool value) + { + if (value) + { + m_notification |= notification; + } + else + { + m_notification &= ~notification; + } } QString CSettings::convertToQString(bool i18n) const { Q_UNUSED(i18n); - QString s("Notification flags:"); - s.append(" ").append(m_notificationFlags); - return s; + return u"Notification flags: " % CNotificationSounds::toString(this->getNotification()); } void CSettings::initDefaultValues() { - this->initNotificationFlags(); + this->setNotification(CNotificationSounds::AllNotifications); } - - void CSettings::initNotificationFlags() - { - // if we add flags in the future, we automatically extend ... - constexpr int l = 1 + static_cast(CNotificationSounds::Notification::NotificationsLoadSounds); - if (this->m_notificationFlags.length() < l) - { - int cl = m_notificationFlags.length(); - this->m_notificationFlags.append(QString(l - cl, '1')); - } - } - } // namespace } // namespace diff --git a/src/blackmisc/audio/audiosettings.h b/src/blackmisc/audio/audiosettings.h index 0f3149476..a9e6b64ff 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -34,13 +34,19 @@ namespace BlackMisc CSettings(); //! Notification flag (play notification?) - bool getNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification) const; + bool isNotificationFlagSet(CNotificationSounds::NotificationFlag notification) const; //! Notification flag (play notification?) - void setNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification, bool value); + void setNotificationFlag(CNotificationSounds::NotificationFlag notification, bool value); + + //! Get notification + CNotificationSounds::Notification getNotification() const { return static_cast(m_notification); } + + //! Set notification + void setNotification(CNotificationSounds::Notification notification) { m_notification = static_cast(notification); } //! Settings value - BlackMisc::CStatusMessage value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag); + CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag); //! Init with meaningful default values void initDefaultValues(); @@ -49,12 +55,12 @@ namespace BlackMisc QString convertToQString(bool i18n = false) const; private: - QString m_notificationFlags; //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) + int m_notification = static_cast(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) void initNotificationFlags(); //!< init flags BLACK_METACLASS( CSettings, - BLACK_METAMEMBER(notificationFlags) + BLACK_METAMEMBER(notification) ); }; } // namespace diff --git a/src/blackmisc/audio/notificationsounds.cpp b/src/blackmisc/audio/notificationsounds.cpp new file mode 100644 index 000000000..a3c3b90c8 --- /dev/null +++ b/src/blackmisc/audio/notificationsounds.cpp @@ -0,0 +1,61 @@ +/* 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 "notificationsounds.h" +#include +#include + +namespace BlackMisc +{ + namespace Audio + { + const QString &CNotificationSounds::flagToString(CNotificationSounds::NotificationFlag notification) + { + static const QString unknown("unknown"); + static const QString error("error"); + static const QString login("login"); + static const QString logoff("logoff"); + static const QString privateMsg("private msg."); + static const QString mentioned("cs mentioned"); + static const QString joined("room joined"); + static const QString left("room left"); + static const QString ptt("PTT click"); + static const QString load("load sounds"); + + switch (notification) + { + case NotificationError: return error; + case NotificationLogin: return login; + case NotificationLogoff: return logoff; + case NotificationTextMessagePrivate: return privateMsg; + case NotificationTextCallsignMentioned: return mentioned; + case NotificationVoiceRoomJoined: return joined; + case NotificationVoiceRoomLeft: return left; + case PTTClick: return ptt; + case LoadSounds: return load; + default: break; + } + return unknown; + } + + const QString CNotificationSounds::toString(Notification notification) + { + QStringList n; + if (notification.testFlag(NotificationError)) n << flagToString(NotificationError); + if (notification.testFlag(NotificationLogin)) n << flagToString(NotificationLogin); + if (notification.testFlag(NotificationLogoff)) n << flagToString(NotificationLogoff); + if (notification.testFlag(NotificationTextMessagePrivate)) n << flagToString(NotificationTextMessagePrivate); + if (notification.testFlag(NotificationTextCallsignMentioned)) n << flagToString(NotificationTextCallsignMentioned); + if (notification.testFlag(NotificationVoiceRoomJoined)) n << flagToString(NotificationVoiceRoomJoined); + if (notification.testFlag(NotificationVoiceRoomLeft)) n << flagToString(NotificationVoiceRoomLeft); + if (notification.testFlag(LoadSounds)) n << flagToString(LoadSounds); + return n.join(", "); + } + } // ns +} // ns diff --git a/src/blackmisc/audio/notificationsounds.h b/src/blackmisc/audio/notificationsounds.h index bb98280c1..0a4f99d8e 100644 --- a/src/blackmisc/audio/notificationsounds.h +++ b/src/blackmisc/audio/notificationsounds.h @@ -12,6 +12,7 @@ #ifndef BLACKMISC_NOTIFICATIONSOUNDS_H #define BLACKMISC_NOTIFICATIONSOUNDS_H +#include "blackmisc/blackmiscexport.h" #include namespace BlackMisc @@ -23,7 +24,7 @@ namespace BlackMisc * \remarks Currently located in project BlackMisc (i.e. outside project BlackSound) * as this allows to trigger sounds without using Multimedia libraries. */ - struct CNotificationSounds + struct BLACKMISC_EXPORT CNotificationSounds { //! How to play? enum PlayMode @@ -34,21 +35,38 @@ namespace BlackMisc }; //! Play notification - enum Notification + enum NotificationFlag { - NotificationError = 0, - NotificationLogin, - NotificationLogoff, - NotificationTextMessagePrivate, - NotificationVoiceRoomJoined, - NotificationVoiceRoomLeft, - NotificationsLoadSounds //!< end marker and force loading of sounds, keep as last element + NoNotifications = 0, + NotificationError = 1 << 0, + NotificationLogin = 1 << 1, + NotificationLogoff = 1 << 2, + NotificationTextMessagePrivate = 1 << 3, + NotificationTextCallsignMentioned = 1 << 4, + NotificationVoiceRoomJoined = 1 << 5, + NotificationVoiceRoomLeft = 1 << 6, + PTTClick = 1 << 7, + LoadSounds = 1 << 8, //!< end marker and force loading of sounds, keep as last element + AllTextNotifications = NotificationTextMessagePrivate | NotificationTextCallsignMentioned, + AllLoginNotifications = NotificationLogin | NotificationLogoff, + AllVoiceRoomNotifications = NotificationVoiceRoomJoined | NotificationVoiceRoomLeft, + AllNotifications = NotificationError | AllTextNotifications | AllLoginNotifications | AllVoiceRoomNotifications, + DefaultNotifications = NotificationError | NotificationTextMessagePrivate | AllLoginNotifications | AllVoiceRoomNotifications, + All = AllNotifications | PTTClick }; + Q_DECLARE_FLAGS(Notification, NotificationFlag) + + //! As string + static const QString &flagToString(NotificationFlag notification); + + //! As string + static const QString toString(Notification notification); }; } // ns } // ns Q_DECLARE_METATYPE(BlackMisc::Audio::CNotificationSounds::PlayMode) Q_DECLARE_METATYPE(BlackMisc::Audio::CNotificationSounds::Notification) +Q_DECLARE_METATYPE(BlackMisc::Audio::CNotificationSounds::NotificationFlag) #endif // guard diff --git a/src/blackmisc/audio/registermetadataaudio.cpp b/src/blackmisc/audio/registermetadataaudio.cpp index c6be5be8b..699339d2f 100644 --- a/src/blackmisc/audio/registermetadataaudio.cpp +++ b/src/blackmisc/audio/registermetadataaudio.cpp @@ -25,9 +25,9 @@ namespace BlackMisc CSettings::registerMetadata(); CVoiceSetup::registerMetadata(); - // struct - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); + // ENUMs + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); } } // ns } // ns diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 3dea0f6a2..964e6c90f 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -443,7 +443,7 @@ void SwiftGuiStd::checkDbDataLoaded() m_dbLoadDialog->newerOrEmptyEntitiesDetected(loadEntities); } -void SwiftGuiStd::playNotifcationSound(CNotificationSounds::Notification notification) const +void SwiftGuiStd::playNotifcationSound(CNotificationSounds::NotificationFlag notification) const { if (!m_contextAudioAvailable) { return; } if (!ui->comp_MainInfoArea->getSettingsComponent()->playNotificationSounds()) { return; } diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index 684f2b808..5121e88b6 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -158,7 +158,7 @@ private: void stopAllTimers(bool disconnectSignalSlots); //! Play notifcation sound - void playNotifcationSound(BlackMisc::Audio::CNotificationSounds::Notification notification) const; + void playNotifcationSound(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification) const; //! Display console void displayConsole();