Merge branch 'staged' into dev

This commit is contained in:
Xiao YiFang 2022-06-07 08:16:08 +08:00
commit b2e9728510
12 changed files with 44 additions and 27 deletions

View file

@ -429,7 +429,7 @@ void AardDictionary::loadArticle( quint32 address,
while( 1 ) while( 1 )
{ {
articleText = string( QObject::tr( "Article loading error" ).toUtf8().constData() ); articleText = QObject::tr( "Article loading error" ).toStdString();
try try
{ {
Mutex::Lock _( aardMutex ); Mutex::Lock _( aardMutex );
@ -521,7 +521,7 @@ void AardDictionary::loadArticle( quint32 address,
articleText = convert( articleText ); articleText = convert( articleText );
} }
else else
articleText = string( QObject::tr( "Article decoding error" ).toUtf8().constData() ); articleText = QObject::tr( "Article decoding error" ).toStdString();
// See Issue #271: A mechanism to clean-up invalid HTML cards. // See Issue #271: A mechanism to clean-up invalid HTML cards.
string cleaner = "</font>""</font>""</font>""</font>""</font>""</font>" string cleaner = "</font>""</font>""</font>""</font>""</font>""</font>"

View file

@ -1,13 +1,14 @@
/******** Global, non-dictionary-specific classes ***********/ /******** Global, non-dictionary-specific classes ***********/
html{ html {
height:100%; height: 100%;
} }
body body
{ {
background: #fefdeb; background: #fefdeb;
font-family: Tahoma, Verdana, "Lucida Sans Unicode", sans-serif; font-family: Tahoma, Verdana, "Lucida Sans Unicode", sans-serif;
height: 100%;
} }
/* This stylesheet is used to highligh current selection when doing a search. /* This stylesheet is used to highligh current selection when doing a search.

View file

@ -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;

View file

@ -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;
@ -1126,7 +1125,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
if( url.scheme().compare( "gdpicture" ) == 0 ) if( url.scheme().compare( "gdpicture" ) == 0 )
ui.definition->load( url ); ui.definition->load( url );
else else
if ( url.scheme().compare( "bword" ) == 0 ) if ( url.scheme().compare( "bword" ) == 0 || url.scheme().compare( "entry" ) == 0 )
{ {
if( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) if( Utils::Url::hasQueryItem( ref, "dictionaries" ) )
{ {

2
dsl.cc
View file

@ -1697,7 +1697,7 @@ void DslArticleRequest::run()
{ {
gdWarning( "DSL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() ); gdWarning( "DSL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
articleText = string( "<span class=\"dsl_article\">" ) articleText = string( "<span class=\"dsl_article\">" )
+ string( QObject::tr( "Article loading error" ).toUtf8().constData() ) + QObject::tr( "Article loading error" ).toStdString()
+ "</span>"; + "</span>";
} }

View file

@ -253,7 +253,7 @@ int main( int argc, char ** argv )
#endif #endif
QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword","gdprg","gdvideo","gdpicture","gdtts","ifr"}; QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword","gdprg","gdvideo","gdpicture","gdtts","ifr", "entry"};
for (int i = 0; i < localSchemes.size(); ++i) for (int i = 0; i < localSchemes.size(); ++i)
{ {

View file

@ -164,6 +164,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
localSchemeHandler = new LocalSchemeHandler( articleNetMgr ); localSchemeHandler = new LocalSchemeHandler( articleNetMgr );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler ); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler ); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "entry", localSchemeHandler );
iframeSchemeHandler = new IframeSchemeHandler( this ); iframeSchemeHandler = new IframeSchemeHandler( this );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler ); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler );

View file

@ -173,7 +173,7 @@ public:
{ {
QString s = QString::fromUtf8( article.c_str() ); QString s = QString::fromUtf8( article.c_str() );
substituteStylesheet( s, styleSheets ); substituteStylesheet( s, styleSheets );
return string( s.toUtf8().constData() ); return s.toStdString();
} }
protected: protected:

14
mdx.cc
View file

@ -977,7 +977,7 @@ void MdxDictionary::loadArticle( uint32_t offset, string & articleText, bool noF
if( !noFilter ) if( !noFilter )
article = filterResource( articleId, article ); article = filterResource( articleId, article );
articleText = string( article.toUtf8().constData() ); articleText = article.toStdString();
} }
QString & MdxDictionary::filterResource( QString const & articleId, QString & article ) QString & MdxDictionary::filterResource( QString const & articleId, QString & article )
@ -1409,7 +1409,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( !parser.open( i->c_str() ) ) if ( !parser.open( i->c_str() ) )
continue; continue;
string title = string( parser.title().toUtf8().constData() ); string title = parser.title().toStdString();
initializing.indexingDictionary( title ); initializing.indexingDictionary( title );
for ( vector< string >::const_iterator mddIter = dictFiles.begin() + 1; for ( vector< string >::const_iterator mddIter = dictFiles.begin() + 1;
@ -1440,7 +1440,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// then the encoding // then the encoding
{ {
string encoding = string( parser.encoding().toUtf8().constData() ); string encoding = parser.encoding().toStdString();
idx.write< uint32_t >( encoding.size() ); idx.write< uint32_t >( encoding.size() );
idx.write( encoding.data(), encoding.size() ); idx.write( encoding.data(), encoding.size() );
} }
@ -1457,7 +1457,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Save dictionary description if there's one // Save dictionary description if there's one
{ {
string description = string( parser.description().toUtf8().constData() ); string description = parser.description().toStdString();
idxHeader.descriptionAddress = chunks.startNewBlock(); idxHeader.descriptionAddress = chunks.startNewBlock();
chunks.addToBlock( description.c_str(), description.size() + 1 ); chunks.addToBlock( description.c_str(), description.size() + 1 );
idxHeader.descriptionSize = description.size() + 1; idxHeader.descriptionSize = description.size() + 1;
@ -1491,7 +1491,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
mddIndices.push_back( mddIndexedWords ); mddIndices.push_back( mddIndexedWords );
// Save filename for .mdd files only // Save filename for .mdd files only
QFileInfo fi( mddParser->filename() ); QFileInfo fi( mddParser->filename() );
mddFileNames.push_back( string( fi.fileName().toUtf8().constData() ) ); mddFileNames.push_back( fi.fileName().toStdString() );
mddParsers.pop_front(); mddParsers.pop_front();
} }
@ -1514,8 +1514,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
for ( MdictParser::StyleSheets::const_iterator iter = styleSheets.begin(); for ( MdictParser::StyleSheets::const_iterator iter = styleSheets.begin();
iter != styleSheets.end(); ++iter ) iter != styleSheets.end(); ++iter )
{ {
string styleBegin( iter->second.first.toUtf8().constData() ); string styleBegin(iter->second.first.toStdString());
string styleEnd( iter->second.second.toUtf8().constData() ); string styleEnd( iter->second.second.toStdString() );
// key // key
idx.write<qint32>( iter->first ); idx.write<qint32>( iter->first );

View file

@ -694,12 +694,12 @@ SlobDictionary::SlobDictionary( string const & id,
// Read dictionary name // Read dictionary name
dictionaryName = string( sf.getDictionaryName().toUtf8().constData() ); dictionaryName = sf.getDictionaryName().toStdString();
if( dictionaryName.empty() ) if( dictionaryName.empty() )
{ {
QString name = QDir::fromNativeSeparators( FsEncoding::decode( dictionaryFiles[ 0 ].c_str() ) ); QString name = QDir::fromNativeSeparators( FsEncoding::decode( dictionaryFiles[ 0 ].c_str() ) );
int n = name.lastIndexOf( '/' ); int n = name.lastIndexOf( '/' );
dictionaryName = string( name.mid( n + 1 ).toUtf8().constData() ); dictionaryName = name.mid( n + 1 ).toStdString();
} }
// Full-text search parameters // Full-text search parameters
@ -799,7 +799,7 @@ void SlobDictionary::loadArticle( quint32 address,
articleText = convert( articleText, entry ); articleText = convert( articleText, entry );
} }
else else
articleText = string( QObject::tr( "Article decoding error" ).toUtf8().constData() ); articleText = QObject::tr( "Article decoding error" ).toStdString();
// See Issue #271: A mechanism to clean-up invalid HTML cards. // See Issue #271: A mechanism to clean-up invalid HTML cards.
string cleaner = "</font>""</font>""</font>""</font>""</font>""</font>" string cleaner = "</font>""</font>""</font>""</font>""</font>""</font>"

View file

@ -221,10 +221,27 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
word = url.path().mid( 1 ); word = url.path().mid( 1 );
} }
} }
if( url.scheme().compare( "bword" ) == 0 ) if( url.scheme().compare( "bword" ) == 0 || url.scheme().compare( "entry" ) == 0 )
{ {
validScheme = true; validScheme = true;
word = url.path().mid( 1 );
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 );
}
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 );
} }

2
zim.cc
View file

@ -769,7 +769,7 @@ ZimDictionary::ZimDictionary( string const & id,
{ {
QString name = QDir::fromNativeSeparators( FsEncoding::decode( dictionaryFiles[ 0 ].c_str() ) ); QString name = QDir::fromNativeSeparators( FsEncoding::decode( dictionaryFiles[ 0 ].c_str() ) );
int n = name.lastIndexOf( '/' ); int n = name.lastIndexOf( '/' );
dictionaryName = string( name.mid( n + 1 ).toUtf8().constData() ); dictionaryName = name.mid( n + 1 ).toStdString();
} }
else else
{ {