Skip to content

Commit ae4898b

Browse files
authored
Merge pull request #3728 from ann0see/bug/copilotMemleakFix
2 parents 76fc757 + 30a13b9 commit ae4898b

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/clientdlg.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,7 @@ void CClientDlg::OnChatTextReceived ( QString strChatText )
876876
{
877877
if ( pSettings->bEnableAudioAlerts )
878878
{
879-
QSoundEffect* sf = new QSoundEffect();
880-
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
881-
sf->play();
879+
PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_message.wav" ) );
882880
}
883881
ChatDlg.AddChatText ( strChatText );
884882

@@ -927,9 +925,7 @@ void CClientDlg::OnNumClientsChanged ( int iNewNumClients )
927925
{
928926
if ( pSettings->bEnableAudioAlerts && iNewNumClients > iClients )
929927
{
930-
QSoundEffect* sf = new QSoundEffect();
931-
sf->setSource ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
932-
sf->play();
928+
PlayAudioAlert ( QUrl::fromLocalFile ( ":sounds/res/sounds/new_user.wav" ) );
933929
}
934930

935931
// iNewNumClients will be zero on the first trigger of this signal handler when connecting to a new server.

src/clientdlg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include <QMessageBox>
6161
#include <QFileDialog>
6262
#include <QActionGroup>
63-
#include <QSoundEffect>
6463
#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 )
6564
# include <QVersionNumber>
6665
#endif

src/util.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,19 @@ QSize CMinimumStackedLayout::sizeHint() const
758758
}
759759
return QStackedLayout::sizeHint();
760760
}
761+
762+
void PlayAudioAlert ( QUrl soundUrl )
763+
{
764+
QSoundEffect* sf = new QSoundEffect();
765+
QObject::connect ( sf, &QSoundEffect::playingChanged, sf, [sf]() {
766+
if ( !sf->isPlaying() )
767+
{
768+
sf->deleteLater();
769+
}
770+
} );
771+
sf->setSource ( soundUrl );
772+
sf->play();
773+
}
761774
#endif
762775

763776
/******************************************************************************\

src/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <QElapsedTimer>
7676
#include <QTextBoundaryFinder>
7777
#include <QTimer>
78+
7879
#ifndef DISABLE_SRV_DNS
7980
# include <QDnsLookup>
8081
#endif
@@ -94,6 +95,7 @@
9495
# include <QDesktopServices>
9596
# include <QKeyEvent>
9697
# include <QStackedLayout>
98+
# include <QSoundEffect>
9799
# include "ui_aboutdlgbase.h"
98100
#endif
99101

@@ -489,6 +491,8 @@ class CMinimumStackedLayout : public QStackedLayout
489491
CMinimumStackedLayout ( QWidget* parent = nullptr ) : QStackedLayout ( parent ) {}
490492
virtual QSize sizeHint() const override;
491493
};
494+
495+
void PlayAudioAlert ( QUrl soundUrl );
492496
#endif
493497

494498
/******************************************************************************\

0 commit comments

Comments
 (0)