goldendict-ng/src/pronounceengine.cc
xiaoyifang d3e6018401
fix: wikipedia open blank page in edge browser (#1003)
* 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>
2023-07-25 23:55:41 +08:00

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() );
}
}