Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,7 @@ void CClientDlg::OnChatTextReceived ( QString strChatText )
{
if ( pSettings->bEnableAudioAlerts )
{
QSoundEffect* sf = new QSoundEffect();
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
sf->play();
PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
}
ChatDlg.AddChatText ( strChatText );

Expand Down Expand Up @@ -927,9 +925,7 @@ void CClientDlg::OnNumClientsChanged ( int iNewNumClients )
{
if ( pSettings->bEnableAudioAlerts && iNewNumClients > iClients )
{
QSoundEffect* sf = new QSoundEffect();
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
sf->play();
PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
}

// iNewNumClients will be zero on the first trigger of this signal handler when connecting to a new server.
Expand Down
1 change: 0 additions & 1 deletion src/clientdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QActionGroup>
#include <QSoundEffect>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 )
# include <QVersionNumber>
#endif
Expand Down
13 changes: 13 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,19 @@ QSize CMinimumStackedLayout::sizeHint() const
}
return QStackedLayout::sizeHint();
}

void PlayAudioAlert ( QUrl soundUrl )
{
QSoundEffect* sf = new QSoundEffect();
QObject::connect ( sf, &QSoundEffect::playingChanged, sf, [sf]() {
if ( !sf->isPlaying() )
{
sf->deleteLater();
}
} );
sf->setSource ( soundUrl );
sf->play();
}
#endif

/******************************************************************************\
Expand Down
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <QElapsedTimer>
#include <QTextBoundaryFinder>
#include <QTimer>

#ifndef DISABLE_SRV_DNS
# include <QDnsLookup>
#endif
Expand All @@ -94,6 +95,7 @@
# include <QDesktopServices>
# include <QKeyEvent>
# include <QStackedLayout>
# include <QSoundEffect>
# include "ui_aboutdlgbase.h"
#endif

Expand Down Expand Up @@ -489,6 +491,8 @@ class CMinimumStackedLayout : public QStackedLayout
CMinimumStackedLayout ( QWidget* parent = nullptr ) : QStackedLayout ( parent ) {}
virtual QSize sizeHint() const override;
};

void PlayAudioAlert ( QUrl soundUrl );
#endif

/******************************************************************************\
Expand Down
Loading