mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix: pronounce the first dictionary audio if availabe (#981)
* fix: pronounce the first dictionary audio if availabe fix #978 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5f2a1981c0
commit
b3d9d79816
|
@ -638,6 +638,10 @@ void ArticleRequest::bodyFinished()
|
|||
activeDicts[ activeDicts.size() - bodyRequests.size() ];
|
||||
|
||||
string dictId = activeDict->getId();
|
||||
|
||||
//signal finished dictionray for pronounciation
|
||||
GlobalBroadcaster::instance()->pronounce_engine.finishDictionary( dictId );
|
||||
|
||||
dictIds << QString::fromStdString(dictId);
|
||||
string head;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ std::string addAudioLink( std::string const & url,
|
|||
if ( url.empty() || url.length() < 2 )
|
||||
return {};
|
||||
GlobalBroadcaster::instance()->pronounce_engine.sendAudio(
|
||||
dictionaryId,
|
||||
QString::fromStdString( url.substr( 1, url.length() - 2 ) ) );
|
||||
|
||||
return std::string( "<script type=\"text/javascript\">" + makeAudioLinkScript( url, dictionaryId ) + "</script>" );
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "pronounceengine.hh"
|
||||
#include <QMutexLocker>
|
||||
|
||||
PronounceEngine::PronounceEngine( QObject * parent ):
|
||||
QObject{ parent }
|
||||
|
@ -10,13 +11,34 @@ void PronounceEngine::reset()
|
|||
{
|
||||
QMutexLocker _( &mutex );
|
||||
state = PronounceState::AVAILABLE;
|
||||
|
||||
dictAudioMap.clear();
|
||||
}
|
||||
|
||||
void PronounceEngine::sendAudio( QString audioLink )
|
||||
|
||||
void PronounceEngine::sendAudio( std::string dictId, QString audioLink )
|
||||
{
|
||||
QMutexLocker _( &mutex );
|
||||
if ( state == PronounceState::OCCUPIED )
|
||||
return;
|
||||
state = PronounceState::OCCUPIED;
|
||||
emit emitAudio( audioLink );
|
||||
|
||||
QMutexLocker _( &mutex );
|
||||
|
||||
dictAudioMap.operator[]( dictId ).push_back( audioLink );
|
||||
}
|
||||
|
||||
void PronounceEngine::finishDictionary( std::string dictId )
|
||||
{
|
||||
if ( state == PronounceState::OCCUPIED )
|
||||
return;
|
||||
|
||||
if ( dictAudioMap.contains( dictId ) ) {
|
||||
{
|
||||
//limit the mutex scope.
|
||||
QMutexLocker _( &mutex );
|
||||
if ( state == PronounceState::OCCUPIED )
|
||||
return;
|
||||
state = PronounceState::OCCUPIED;
|
||||
}
|
||||
emit emitAudio( dictAudioMap[ dictId ].first() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define PRONOUNCEENGINE_HH
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutexLocker>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
|
||||
|
||||
|
@ -17,11 +17,13 @@ class PronounceEngine: public QObject
|
|||
PronounceState state = PronounceState::AVAILABLE;
|
||||
QMutex mutex;
|
||||
|
||||
QMap< std::string, QList< QString > > dictAudioMap;
|
||||
|
||||
public:
|
||||
explicit PronounceEngine( QObject * parent = nullptr );
|
||||
void reset();
|
||||
void sendAudio( QString audioLink );
|
||||
|
||||
void sendAudio( std::string dictId, QString audioLink );
|
||||
void finishDictionary( std::string dictId );
|
||||
signals:
|
||||
void emitAudio( QString audioLink );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue