+ Support for sound playback under Windows added (limited to .wavs though).

This commit is contained in:
Konstantin Isakov 2009-02-06 15:37:37 +00:00
parent 2fa0c3b57b
commit c2977cf9a1
3 changed files with 39 additions and 1 deletions

View file

@ -8,6 +8,10 @@
#include <QMenu>
#include <QDesktopServices>
#ifdef Q_OS_WIN32
#include <windows.h>
#include <mmsystem.h> // For PlaySound
#endif
ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
Instances::Groups const & groups_, bool popupView_ ):
@ -37,6 +41,18 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
this, SLOT( linkClicked( QUrl const & ) ) );
}
ArticleView::~ArticleView()
{
#ifdef Q_OS_WIN32
if ( winWavData.size() )
{
// If we were playing some sound some time ago, make sure it stopped
// playing before freeing the waveform memory.
PlaySoundA( 0, 0, 0 );
}
#endif
}
void ArticleView::showDefinition( QString const & word, QString const & group )
{
QUrl req;
@ -130,6 +146,21 @@ void ArticleView::linkClicked( QUrl const & url )
// Decide the viewer
#ifdef Q_OS_WIN32
// Windows-only: use system PlaySound function
if ( winWavData.size() )
PlaySoundA( 0, 0, 0 ); // Stop any currently playing sound to make sure
// previous data isn't used anymore
//
winWavData = data;
PlaySoundA( &winWavData.front(), 0,
SND_ASYNC | SND_MEMORY | SND_NODEFAULT | SND_NOWAIT );
return;
#endif
QString program, extension;
if ( url.scheme() == "gdau" )

View file

@ -22,6 +22,11 @@ class ArticleView: public QFrame
Ui::ArticleView ui;
#ifdef Q_OS_WIN32
// Used in Windows only
vector< char > winWavData;
#endif
public:
/// The popupView flag influences contents of the context menus to be
/// appropriate to the context of the view.
@ -31,6 +36,8 @@ public:
Instances::Groups const &,
bool popupView );
~ArticleView();
/// Shows the definition of the given word with the given group
void showDefinition( QString const & word, QString const & group );

View file

@ -21,7 +21,7 @@ RCC_DIR = build
LIBS += -lvorbisfile -lvorbis -logg -lz
win32 {
LIBS += -liconv -lwsock32
LIBS += -liconv -lwsock32 -lwinmm
RC_FILE = goldendict.rc
}