Merge pull request #1109 from xiaoyifang/fix/reference-epwing

fix: navigate through epwing restricted to certain dictionary
This commit is contained in:
xiaoyifang 2023-08-31 00:06:20 +08:00 committed by GitHub
commit 7e6dc611fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View file

@ -387,9 +387,10 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
unmutedDicts.reserve( activeDicts.size() );
for ( unsigned x = 0; x < activeDicts.size(); ++x )
for ( unsigned x = 0; x < activeDicts.size(); ++x ) {
if ( !mutedDicts.contains( QString::fromStdString( activeDicts[ x ]->getId() ) ) )
unmutedDicts.push_back( activeDicts[ x ] );
}
return std::make_shared< ArticleRequest >(
word,
@ -436,7 +437,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeEmptyPage() const
sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const
{
string result = makeHtmlHeader( tr( "(picture)" ), QString(), true )
+ "<a href=\"javascript: if(history.length>2) history.go(-1)\">" + "<img src=\"" + url + "\" /></a>"
+ R"lit(<a href="javascript: if(history.length>2) history.go(-1)">)lit" + R"(<img src=")" + url + R"(" /></a>)"
+ "</body></html>";
sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true );
@ -489,9 +490,8 @@ ArticleRequest::ArticleRequest( QString const & word,
emit GlobalBroadcaster::instance()->dictionaryClear( ActiveDictIds{ group.id, word } );
// Accumulate main forms
for ( unsigned x = 0; x < activeDicts.size(); ++x ) {
sptr< Dictionary::WordSearchRequest > s =
activeDicts[ x ]->findHeadwordsForSynonym( gd::removeTrailingZero( word ) );
for ( const auto & activeDict : activeDicts ) {
auto const s = activeDict->findHeadwordsForSynonym( gd::removeTrailingZero( word ) );
connect( s.get(), &Dictionary::Request::finished, this, &ArticleRequest::altSearchFinished, Qt::QueuedConnection );
@ -507,7 +507,7 @@ void ArticleRequest::altSearchFinished()
return;
// Check every request for finishing
for ( list< sptr< Dictionary::WordSearchRequest > >::iterator i = altSearches.begin(); i != altSearches.end(); ) {
for ( auto i = altSearches.begin(); i != altSearches.end(); ) {
if ( ( *i )->isFinished() ) {
// This one's finished
for ( size_t count = ( *i )->matchesCount(), x = 0; x < count; ++x )
@ -531,8 +531,8 @@ void ArticleRequest::altSearchFinished()
vector< wstring > altsVector( alts.begin(), alts.end() );
#ifdef QT_DEBUG
for ( unsigned x = 0; x < altsVector.size(); ++x ) {
qDebug() << "Alt:" << QString::fromStdU32String( altsVector[ x ] );
for ( const auto & x : altsVector ) {
qDebug() << "Alt:" << QString::fromStdU32String( x );
}
#endif
@ -541,12 +541,12 @@ void ArticleRequest::altSearchFinished()
if ( activeDicts.size() <= 1 )
articleSizeLimit = -1; // Don't collapse article if only one dictionary presented
for ( unsigned x = 0; x < activeDicts.size(); ++x ) {
for ( const auto & activeDict : activeDicts ) {
try {
sptr< Dictionary::DataRequest > r = activeDicts[ x ]->getArticle(
sptr< Dictionary::DataRequest > r = activeDict->getArticle(
wordStd,
altsVector,
gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDicts[ x ]->getId() ) ) ),
gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDict->getId() ) ) ),
ignoreDiacritics );
connect( r.get(), &Dictionary::Request::finished, this, &ArticleRequest::bodyFinished, Qt::QueuedConnection );
@ -554,7 +554,7 @@ void ArticleRequest::altSearchFinished()
bodyRequests.push_back( r );
}
catch ( std::exception & e ) {
gdWarning( "getArticle request error (%s) in \"%s\"\n", e.what(), activeDicts[ x ]->getName().c_str() );
gdWarning( "getArticle request error (%s) in \"%s\"\n", e.what(), activeDict->getName().c_str() );
}
}

View file

@ -303,16 +303,17 @@ void EpwingDictionary::loadArticle(
articleHeadword = string( headword.toUtf8().data() );
articleText = string( text.toUtf8().data() );
string prefix( "<div class=\"epwing_text\">" );
const string prefix( "<div class=\"epwing_text\">" );
articleText = prefix + articleText + "</div>";
}
string Epwing::EpwingDictionary::epwing_previous_button( const int & articlePage, const int & articleOffset )
{
QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
const QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
string previousLink = R"(<p><a class="epwing_previous_page" href="gdlookup://localhost/)"
+ previousButton.toStdString() + "\">" + tr( "Previous Page" ).toStdString() + "</a></p>";
+ previousButton.toStdString() + "?dictionaries=" + getId() + "\">" + tr( "Previous Page" ).toStdString()
+ "</a></p>";
return previousLink;
}
@ -348,8 +349,8 @@ void EpwingDictionary::loadArticleNextPage( string & articleHeadword,
string Epwing::EpwingDictionary::epwing_next_button( const int & articlePage, const int & articleOffset )
{
QString refLink = QString( "r%1At%2" ).arg( articlePage ).arg( articleOffset );
string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString() + "\">"
+ tr( "Next Page" ).toStdString() + "</a></p>";
string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString()
+ "?dictionaries=" + getId() + "\">" + tr( "Next Page" ).toStdString() + "</a></p>";
return nextLink;
}