mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
refactor getqueryword
This commit is contained in:
parent
ccd8ace0ec
commit
5f856bf2ae
|
@ -513,11 +513,10 @@ void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
||||||
request.setUrl( url );
|
request.setUrl( url );
|
||||||
|
|
||||||
//all the url reached here must be either gdlookup or bword scheme.
|
//all the url reached here must be either gdlookup or bword scheme.
|
||||||
auto queryWord = Utils::Url::getQueryWord( url );
|
auto [valid, word] = Utils::Url::getQueryWord( url );
|
||||||
auto word = queryWord.second;
|
|
||||||
// or the condition can be (!queryWord.first || word.isEmpty())
|
// or the condition can be (!queryWord.first || word.isEmpty())
|
||||||
// ( queryWord.first && word.isEmpty() ) is only part of the above condition.
|
// ( queryWord.first && word.isEmpty() ) is only part of the above condition.
|
||||||
if( queryWord.first && word.isEmpty() )
|
if( valid && word.isEmpty() )
|
||||||
{
|
{
|
||||||
// invalid gdlookup url.
|
// invalid gdlookup url.
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1113,9 +1113,8 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
||||||
audioPlayer->stop();
|
audioPlayer->stop();
|
||||||
qDebug() << "open link url:" << url;
|
qDebug() << "open link url:" << url;
|
||||||
|
|
||||||
auto queryWord = Utils::Url::getQueryWord( url );
|
auto [valid, word] = Utils::Url::getQueryWord( url );
|
||||||
auto word = queryWord.second;
|
if( valid && word.isEmpty() )
|
||||||
if( queryWord.first && word.isEmpty() )
|
|
||||||
{
|
{
|
||||||
// invalid gdlookup url.
|
// invalid gdlookup url.
|
||||||
return;
|
return;
|
||||||
|
|
17
utils.hh
17
utils.hh
|
@ -224,8 +224,25 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
|
||||||
if( url.scheme().compare( "bword" ) == 0 )
|
if( url.scheme().compare( "bword" ) == 0 )
|
||||||
{
|
{
|
||||||
validScheme = true;
|
validScheme = true;
|
||||||
|
|
||||||
|
auto path = url.path();
|
||||||
|
// url like this , bword:word or bword://localhost/word
|
||||||
|
if( !path.isEmpty() )
|
||||||
|
{
|
||||||
|
//url,bword://localhost/word
|
||||||
|
if( path.startsWith( "/" ) )
|
||||||
word = url.path().mid( 1 );
|
word = url.path().mid( 1 );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// url looks like this, bword://word,or bword://localhost
|
||||||
|
auto host = url.host();
|
||||||
|
if( host != "localhost" )
|
||||||
|
{
|
||||||
|
word = host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return std::make_pair( validScheme, word );
|
return std::make_pair( validScheme, word );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue