mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Don't attempt to translate empty or whitespace-only text
Silently ignore empty or whitespace-only translation requests. It should be clear to most users why GoldenDict ignores them. The translated word ends up as the "word" URL query item value, which is trimmed in ArticleNetworkAccessManager::getResource(). So the added trimming in MainWindow::translateInputFinished() should be fine. When a trimmed translated word was empty, InputPhrase::isValid() returned false, ArticleNetworkAccessManager::getResource() returned a null pointer and ArticleNetworkAccessManager::createRequest() fell back to QNetworkAccessManager::createRequest(), which: * failed silently in the Qt 4 version; * displayed the Protocol "gdlookup" is unknown Failed to load URL gdlookup://localhost?word= &group=4. QtNetwork Error 301 error page in the Qt 5 version. Fixes #1179.
This commit is contained in:
parent
c7c8b6f632
commit
9330c89e4b
|
@ -2343,7 +2343,10 @@ void MainWindow::updateSuggestionList( QString const & newValue )
|
|||
|
||||
void MainWindow::translateInputFinished( bool checkModifiers )
|
||||
{
|
||||
QString word = Folding::unescapeWildcardSymbols( translateLine->text() );
|
||||
QString word = translateLine->text().trimmed();
|
||||
if( word.isEmpty() )
|
||||
return;
|
||||
word = Folding::unescapeWildcardSymbols( word );
|
||||
respondToTranslationRequest( Config::InputPhrase( word, translateBoxSuffix ), checkModifiers );
|
||||
}
|
||||
|
||||
|
|
|
@ -805,7 +805,10 @@ void ScanPopup::updateSuggestionList( QString const & text )
|
|||
|
||||
void ScanPopup::translateInputFinished()
|
||||
{
|
||||
inputPhrase.phrase = Folding::unescapeWildcardSymbols( ui.translateBox->translateLine()->text().trimmed() );
|
||||
QString const word = ui.translateBox->translateLine()->text().trimmed();
|
||||
if( word.isEmpty() )
|
||||
return;
|
||||
inputPhrase.phrase = Folding::unescapeWildcardSymbols( word );
|
||||
inputPhrase.punctuationSuffix = translateBoxSuffix;
|
||||
showTranslationFor( inputPhrase );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue