From c2977cf9a11cfea32045b5b7af956df916d3ab04 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 6 Feb 2009 15:37:37 +0000 Subject: [PATCH] + Support for sound playback under Windows added (limited to .wavs though). --- src/articleview.cc | 31 +++++++++++++++++++++++++++++++ src/articleview.hh | 7 +++++++ src/goldendict.pro | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/articleview.cc b/src/articleview.cc index a4a5b86d..67961b59 100644 --- a/src/articleview.cc +++ b/src/articleview.cc @@ -8,6 +8,10 @@ #include #include +#ifdef Q_OS_WIN32 +#include +#include // 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" ) diff --git a/src/articleview.hh b/src/articleview.hh index c67da94e..b46b3942 100644 --- a/src/articleview.hh +++ b/src/articleview.hh @@ -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 ); diff --git a/src/goldendict.pro b/src/goldendict.pro index 428e320d..88c8b730 100644 --- a/src/goldendict.pro +++ b/src/goldendict.pro @@ -21,7 +21,7 @@ RCC_DIR = build LIBS += -lvorbisfile -lvorbis -logg -lz win32 { - LIBS += -liconv -lwsock32 + LIBS += -liconv -lwsock32 -lwinmm RC_FILE = goldendict.rc }