mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
d3e6018401
* fix: wikipedia open blank page in edge browser * [autofix.ci] apply automated fixes --------- Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
50 lines
994 B
C++
50 lines
994 B
C++
#include "pronounceengine.hh"
|
|
#include <QMutexLocker>
|
|
#include "common/utils.hh"
|
|
#include <QUrl>
|
|
|
|
PronounceEngine::PronounceEngine( QObject * parent ):
|
|
QObject{ parent }
|
|
{
|
|
}
|
|
|
|
|
|
void PronounceEngine::reset()
|
|
{
|
|
QMutexLocker _( &mutex );
|
|
state = PronounceState::AVAILABLE;
|
|
|
|
dictAudioMap.clear();
|
|
}
|
|
|
|
|
|
void PronounceEngine::sendAudio( std::string dictId, QString audioLink )
|
|
{
|
|
if ( state == PronounceState::OCCUPIED )
|
|
return;
|
|
|
|
if ( !Utils::Url::isAudioUrl( QUrl( audioLink ) ) )
|
|
return;
|
|
|
|
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() );
|
|
}
|
|
}
|