Utility functions for notification sounds

This commit is contained in:
Klaus Basan
2019-03-22 03:07:40 +01:00
committed by Mat Sutcliffe
parent 9450dfc3b0
commit 77a898c9ec
4 changed files with 34 additions and 19 deletions

View File

@@ -10,6 +10,7 @@
#include "blackmisc/math/mathutils.h"
#include "blackmisc/worker.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/directoryutils.h"
#include "blackconfig/buildconfig.h"
#include <QCoreApplication>
@@ -574,4 +575,16 @@ namespace BlackMisc
if (fileName.isEmpty()) { return false; }
return fileName.contains("swift", Qt::CaseInsensitive) && fileName.contains("installer");
}
QString CFileUtils::soundFilePathAndFileName(const QString &name)
{
if (name.isEmpty()) { return {}; }
return CFileUtils::appendFilePaths(CDirectoryUtils::soundFilesDirectory(), name);
}
QUrl CFileUtils::soundFileQUrl(const QString &name)
{
if (name.isEmpty()) { return {}; }
return QUrl::fromLocalFile(CFileUtils::soundFilePathAndFileName(name));
}
} // ns

View File

@@ -13,12 +13,13 @@
#include "blackmisc/blackmiscexport.h"
#include <QUrl>
#include <QDir>
#include <QFileInfo>
#include <QFileInfoList>
#include <QLockFile>
#include <QString>
#include <QStringList>
#include <QString>
#include <Qt>
#include <functional>
@@ -197,6 +198,12 @@ namespace BlackMisc
//! swift installer
static bool isSwiftInstaller(const QString &fileName);
//! Returns the full path and file name for a sound file
static QString soundFilePathAndFileName(const QString &name);
//! QUrl of soundFilePathAndFileName
static QUrl soundFileQUrl(const QString &name);
};
} // ns

View File

@@ -7,60 +7,58 @@
*/
#include "notificationplayer.h"
#include "blackmisc/directoryutils.h"
#include <QUrl>
#include "blackmisc/fileutils.h"
using namespace BlackMisc;
using namespace BlackMisc::Audio;
namespace BlackSound
{
CNotificationPlayer::CNotificationPlayer(QObject *parent) :
QObject(parent)
{
QSoundEffect *effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/error.wav"));
effect->setSource(CFileUtils::soundFileQUrl("error.wav"));
m_effects[CNotificationSounds::NotificationError] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/login.wav"));
effect->setSource(CFileUtils::soundFileQUrl("login.wav"));
m_effects[CNotificationSounds::NotificationLogin] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/logoff.wav"));
effect->setSource(CFileUtils::soundFileQUrl("logoff.wav"));
m_effects[CNotificationSounds::NotificationLogoff] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/privatemessage.wav"));
effect->setSource(CFileUtils::soundFileQUrl("privatemessage.wav"));
m_effects[CNotificationSounds::NotificationTextMessagePrivate] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/supervisormessage.wav"));
effect->setSource(CFileUtils::soundFileQUrl("supervisormessage.wav"));
m_effects[CNotificationSounds::NotificationTextMessageSupervisor] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/callsignmentioned.wav"));
effect->setSource(CFileUtils::soundFileQUrl("callsignmentioned.wav"));
m_effects[CNotificationSounds::NotificationTextCallsignMentioned] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/voiceroomjoined.wav"));
effect->setSource(CFileUtils::soundFileQUrl("voiceroomjoined.wav"));
m_effects[CNotificationSounds::NotificationVoiceRoomJoined] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/voiceroomleft.wav"));
effect->setSource(CFileUtils::soundFileQUrl("voiceroomleft.wav"));
m_effects[CNotificationSounds::NotificationVoiceRoomLeft] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/noaudiotransmission.wav"));
effect->setSource(CFileUtils::soundFileQUrl("noaudiotransmission.wav"));
m_effects[CNotificationSounds::NotificationNoAudioTransmission] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/pttclick.wav"));
effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav"));
m_effects[CNotificationSounds::PTTClickKeyDown] = effect;
effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(CDirectoryUtils::soundFilesDirectory() + "/pttclick.wav"));
effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav"));
m_effects[CNotificationSounds::PTTClickKeyUp] = effect;
}
@@ -73,5 +71,4 @@ namespace BlackSound
effect->play();
}
}
}
} // ns

View File

@@ -18,8 +18,6 @@
#include <QHash>
#include <QSoundEffect>
class QTimer;
namespace BlackSound
{
//! Player for notification sounds