mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
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>
This commit is contained in:
parent
f9b1d3fa92
commit
d3e6018401
|
@ -252,12 +252,24 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
|
|||
|
||||
inline bool isAudioUrl( QUrl const & url )
|
||||
{
|
||||
if ( !url.isValid() )
|
||||
return false;
|
||||
// Note: we check for forvo sound links explicitly, as they don't have extensions
|
||||
|
||||
return ( url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gdau" )
|
||||
&& ( Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
||||
}
|
||||
|
||||
inline bool isWebAudioUrl( QUrl const & url )
|
||||
{
|
||||
if ( !url.isValid() )
|
||||
return false;
|
||||
// Note: we check for forvo sound links explicitly, as they don't have extensions
|
||||
|
||||
return ( url.scheme() == "http" || url.scheme() == "https" )
|
||||
&& ( Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
||||
}
|
||||
|
||||
/// Uses some heuristics to chop off the first domain name from the host name,
|
||||
/// but only if it's not too base. Returns the resulting host name.
|
||||
inline QString getHostBase( QString const & host )
|
||||
|
|
|
@ -571,7 +571,7 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
|
|||
articleNewString.clear();
|
||||
}
|
||||
|
||||
// audio url
|
||||
// audio url like this <a href="//upload.wikimedia.org/wikipedia/a.ogg"
|
||||
articleString.replace(
|
||||
QRegularExpression(
|
||||
"<a\\s+href=\"(//upload\\.wikimedia\\.org/wikipedia/[^\"'&]*\\.og[ga](?:\\.mp3|))\"" ),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "pronounceengine.hh"
|
||||
#include <QMutexLocker>
|
||||
#include "common/utils.hh"
|
||||
#include <QUrl>
|
||||
|
||||
PronounceEngine::PronounceEngine( QObject * parent ):
|
||||
QObject{ parent }
|
||||
|
@ -21,6 +23,9 @@ 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 );
|
||||
|
|
|
@ -586,8 +586,9 @@ void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
|
|||
{
|
||||
// Don't try mangling audio urls, even if they are from the framed websites
|
||||
|
||||
if ( ( url.scheme() == "http" || url.scheme() == "https" )
|
||||
&& !Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
||||
if ( !url.isValid() )
|
||||
return;
|
||||
if ( ( url.scheme() == "http" || url.scheme() == "https" ) && !Utils::Url::isWebAudioUrl( url ) ) {
|
||||
// Maybe a link inside a website was clicked?
|
||||
|
||||
QString ca = getCurrentArticle();
|
||||
|
@ -849,7 +850,7 @@ void ArticleView::linkHovered( const QString & link )
|
|||
if ( url.scheme() == "bres" ) {
|
||||
msg = tr( "Resource" );
|
||||
}
|
||||
else if ( url.scheme() == "gdau" || Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
||||
else if ( url.scheme() == "gdau" || Utils::Url::isAudioUrl( url ) ) {
|
||||
msg = tr( "Audio" );
|
||||
}
|
||||
else if ( url.scheme() == "gdtts" ) {
|
||||
|
@ -932,7 +933,7 @@ void ArticleView::linkClicked( QUrl const & url_ )
|
|||
|
||||
void ArticleView::linkClickedInHtml( QUrl const & url_ )
|
||||
{
|
||||
emit webview->linkClickedInHtml( url_ );
|
||||
webview->linkClickedInHtml( url_ );
|
||||
if ( !url_.isEmpty() ) {
|
||||
linkClicked( url_ );
|
||||
}
|
||||
|
@ -1021,7 +1022,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
}
|
||||
}
|
||||
else if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo"
|
||||
|| Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
||||
|| Utils::Url::isAudioUrl( url ) ) {
|
||||
// Download it
|
||||
|
||||
// Clear any pending ones
|
||||
|
@ -1030,7 +1031,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
|
||||
resourceDownloadUrl = url;
|
||||
|
||||
if ( Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) {
|
||||
if ( Utils::Url::isWebAudioUrl( url ) ) {
|
||||
sptr< Dictionary::DataRequest > req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
||||
|
||||
resourceDownloadRequests.push_back( req );
|
||||
|
@ -1775,8 +1776,7 @@ void ArticleView::resourceDownloadFinished()
|
|||
|
||||
vector< char > const & data = ( *i )->getFullData();
|
||||
|
||||
if ( resourceDownloadUrl.scheme() == "gdau"
|
||||
|| Dictionary::WebMultimediaDownload::isAudioUrl( resourceDownloadUrl ) ) {
|
||||
if ( resourceDownloadUrl.scheme() == "gdau" || Utils::Url::isWebAudioUrl( resourceDownloadUrl ) ) {
|
||||
// Audio data
|
||||
connect( audioPlayer.data(),
|
||||
&AudioPlayerInterface::error,
|
||||
|
|
|
@ -340,7 +340,7 @@ private slots:
|
|||
|
||||
bool isAudioLink( QUrl & targetUrl )
|
||||
{
|
||||
return ( targetUrl.scheme() == "gdau" || Dictionary::WebMultimediaDownload::isAudioUrl( targetUrl ) );
|
||||
return ( targetUrl.scheme() == "gdau" || Utils::Url::isAudioUrl( targetUrl ) );
|
||||
}
|
||||
|
||||
void resourceDownloadFinished();
|
||||
|
|
|
@ -72,12 +72,4 @@ void WebMultimediaDownload::replyFinished( QNetworkReply * r )
|
|||
finish();
|
||||
}
|
||||
|
||||
bool WebMultimediaDownload::isAudioUrl( QUrl const & url )
|
||||
{
|
||||
// Note: we check for forvo sound links explicitly, as they don't have extensions
|
||||
|
||||
return ( url.scheme() == "http" || url.scheme() == "https" )
|
||||
&& ( Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
||||
}
|
||||
|
||||
} // namespace Dictionary
|
||||
|
|
|
@ -20,9 +20,6 @@ public:
|
|||
|
||||
WebMultimediaDownload( QUrl const &, QNetworkAccessManager & );
|
||||
|
||||
/// Checks if the given url is an http request for an audio file.
|
||||
static bool isAudioUrl( QUrl const & );
|
||||
|
||||
virtual void cancel();
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Reference in a new issue