mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T644, allow to fetch notifications sounds from an arbitrary directory
* added settings * utility functions
This commit is contained in:
@@ -601,6 +601,12 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CContextAudio::onChangedAudioSettings()
|
||||
{
|
||||
const QString dir = m_audioSettings.get().getNotificationSoundDirectory();
|
||||
m_notificationPlayer.updateDirectory(dir);
|
||||
}
|
||||
|
||||
QSharedPointer<IVoiceChannel> CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom)
|
||||
{
|
||||
QSharedPointer<IVoiceChannel> voiceChannel;
|
||||
|
||||
@@ -136,8 +136,12 @@ namespace BlackCore
|
||||
//! Connection in transition
|
||||
bool inTransitionState() const;
|
||||
|
||||
//! Change the device settings
|
||||
void changeDeviceSettings();
|
||||
|
||||
//! Changed audio settings
|
||||
void onChangedAudioSettings();
|
||||
|
||||
//! Voice channel by room
|
||||
QSharedPointer<IVoiceChannel> getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom);
|
||||
|
||||
@@ -161,8 +165,8 @@ namespace BlackCore
|
||||
BlackSound::CNotificationPlayer m_notificationPlayer;
|
||||
|
||||
// settings
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this };
|
||||
BlackMisc::CSetting<BlackCore::Audio::TInputDevice> m_inputDeviceSetting { this, &CContextAudio::changeDeviceSettings };
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CContextAudio::onChangedAudioSettings };
|
||||
BlackMisc::CSetting<BlackCore::Audio::TInputDevice> m_inputDeviceSetting { this, &CContextAudio::changeDeviceSettings };
|
||||
BlackMisc::CSetting<BlackCore::Audio::TOutputDevice> m_outputDeviceSetting { this, &CContextAudio::changeDeviceSettings };
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include "blackmisc/fileutils.h"
|
||||
|
||||
using namespace BlackMisc::Audio;
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -40,6 +42,19 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::setNotificationSoundDirectory(const QString &dir)
|
||||
{
|
||||
QString d = dir.trimmed();
|
||||
if (d.isEmpty())
|
||||
{
|
||||
// reset
|
||||
m_notificationSoundDir.clear();
|
||||
return;
|
||||
}
|
||||
d = CFileUtils::fixWindowsUncPath(d);
|
||||
m_notificationSoundDir = d;
|
||||
}
|
||||
|
||||
QString CSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
|
||||
@@ -57,6 +57,12 @@ namespace BlackMisc
|
||||
//! Settings value
|
||||
CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag);
|
||||
|
||||
//! Directory
|
||||
void setNotificationSoundDirectory(const QString &dir);
|
||||
|
||||
//! Notification directory
|
||||
const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; }
|
||||
|
||||
//! Init with meaningful default values
|
||||
void initDefaultValues();
|
||||
|
||||
@@ -64,11 +70,13 @@ namespace BlackMisc
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_notificationSoundDir;
|
||||
int m_notification = static_cast<int>(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(notificationSoundDir),
|
||||
BLACK_METAMEMBER(notification)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFlags>
|
||||
#include <QIODevice>
|
||||
#include <QList>
|
||||
@@ -582,9 +583,15 @@ namespace BlackMisc
|
||||
return CFileUtils::appendFilePaths(CDirectoryUtils::soundFilesDirectory(), name);
|
||||
}
|
||||
|
||||
QUrl CFileUtils::soundFileQUrl(const QString &name)
|
||||
QUrl CFileUtils::soundFileQUrl(const QString &directory, const QString &name)
|
||||
{
|
||||
if (name.isEmpty()) { return {}; }
|
||||
if (!directory.isEmpty())
|
||||
{
|
||||
const QString f = CFileUtils::appendFilePathsAndFixUnc(directory, name);
|
||||
const QFileInfo fi(f);
|
||||
if (fi.exists()) { return QUrl::fromLocalFile(f); }
|
||||
}
|
||||
return QUrl::fromLocalFile(CFileUtils::soundFilePathAndFileName(name));
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace BlackMisc
|
||||
static QString soundFilePathAndFileName(const QString &name);
|
||||
|
||||
//! QUrl of soundFilePathAndFileName
|
||||
static QUrl soundFileQUrl(const QString &name);
|
||||
static QUrl soundFileQUrl(const QString &directory, const QString &name);
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "notificationplayer.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include <QTimer>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Audio;
|
||||
@@ -17,49 +18,7 @@ namespace BlackSound
|
||||
CNotificationPlayer::CNotificationPlayer(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
QSoundEffect *effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("error.wav"));
|
||||
m_effects[CNotificationSounds::NotificationError] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("login.wav"));
|
||||
m_effects[CNotificationSounds::NotificationLogin] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("logoff.wav"));
|
||||
m_effects[CNotificationSounds::NotificationLogoff] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("privatemessage.wav"));
|
||||
m_effects[CNotificationSounds::NotificationTextMessagePrivate] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("supervisormessage.wav"));
|
||||
m_effects[CNotificationSounds::NotificationTextMessageSupervisor] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("callsignmentioned.wav"));
|
||||
m_effects[CNotificationSounds::NotificationTextCallsignMentioned] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("voiceroomjoined.wav"));
|
||||
m_effects[CNotificationSounds::NotificationVoiceRoomJoined] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("voiceroomleft.wav"));
|
||||
m_effects[CNotificationSounds::NotificationVoiceRoomLeft] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("noaudiotransmission.wav"));
|
||||
m_effects[CNotificationSounds::NotificationNoAudioTransmission] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav"));
|
||||
m_effects[CNotificationSounds::PTTClickKeyDown] = effect;
|
||||
|
||||
effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav"));
|
||||
m_effects[CNotificationSounds::PTTClickKeyUp] = effect;
|
||||
// lazy init at play
|
||||
}
|
||||
|
||||
void CNotificationPlayer::play(Audio::CNotificationSounds::NotificationFlag notification, int volume) const
|
||||
@@ -71,4 +30,32 @@ namespace BlackSound
|
||||
effect->play();
|
||||
}
|
||||
}
|
||||
|
||||
void CNotificationPlayer::updateDirectory(const QString &directory)
|
||||
{
|
||||
if (directory == m_directory && !m_effects.isEmpty()) { return; }
|
||||
m_directory = directory;
|
||||
|
||||
this->updateEffect(CNotificationSounds::NotificationError, directory, "error.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationLogin, directory, "login.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationLogoff, directory, "logoff.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationTextMessagePrivate, directory, "privatemessage.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationTextMessageSupervisor, directory, "supervisormessage.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationTextCallsignMentioned, directory, "callsignmentioned.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationVoiceRoomJoined, directory, "voiceroomjoined.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationVoiceRoomLeft, directory, "voiceroomleft.wav");
|
||||
this->updateEffect(CNotificationSounds::NotificationNoAudioTransmission, directory, "noaudiotransmission.wav");
|
||||
this->updateEffect(CNotificationSounds::PTTClickKeyDown, directory, "pttclick.wav");
|
||||
this->updateEffect(CNotificationSounds::PTTClickKeyUp, directory, "pttclick.wav");
|
||||
}
|
||||
|
||||
void CNotificationPlayer::updateEffect(CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name)
|
||||
{
|
||||
QSoundEffect *e = nullptr;
|
||||
QSoundEffect *effect = new QSoundEffect(this);
|
||||
effect->setSource(CFileUtils::soundFileQUrl(directory, name));
|
||||
if (m_effects.contains(f)) { e = m_effects[f]; }
|
||||
m_effects[f] = effect;
|
||||
if (e) { e->deleteLater(); }
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -35,8 +35,15 @@ namespace BlackSound
|
||||
//! Play notification sound
|
||||
void play(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, int volume = 100) const;
|
||||
|
||||
//! Update the directory
|
||||
void updateDirectory(const QString &directory);
|
||||
|
||||
private:
|
||||
QHash<BlackMisc::Audio::CNotificationSounds::NotificationFlag, QSoundEffect *> m_effects;
|
||||
QString m_directory;
|
||||
|
||||
//! Update an effect
|
||||
void updateEffect(BlackMisc::Audio::CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user