mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Merge pull request #1111 from xiaoyifang/fix/epwing-reference-link
fix: epwing dictionary reference navigation restrict to certain dicti…
This commit is contained in:
commit
b244d5ce0f
|
@ -839,7 +839,7 @@ QString EpwingBook::getPreviousTextWithLength( int page, int offset, int total,
|
|||
if ( buf.length() > TextSizeLimit ) {
|
||||
error_string = "Data too large";
|
||||
currentPosition.page = 0;
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1373,6 +1373,7 @@ void EpwingBook::finalizeText( QString & text )
|
|||
url.setHost( "localhost" );
|
||||
|
||||
url.setPath( Utils::Url::ensureLeadingSlash( QString( "r%1At%2" ).arg( ebpos.page ).arg( ebpos.offset ) ) );
|
||||
url.setQuery( "dictionaries=" + dictID );
|
||||
|
||||
QString link = "<a href=\"" + url.toEncoded() + "\">";
|
||||
|
||||
|
|
|
@ -584,11 +584,6 @@ void ArticleView::isFramedArticle( QString const & ca, const std::function< void
|
|||
} );
|
||||
}
|
||||
|
||||
bool ArticleView::isExternalLink( QUrl const & url )
|
||||
{
|
||||
return Utils::isExternalLink( url );
|
||||
}
|
||||
|
||||
void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
|
||||
{
|
||||
// Don't try mangling audio urls, even if they are from the framed websites
|
||||
|
@ -796,7 +791,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
|
|||
else
|
||||
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
||||
if ( !mutedDictionaries )
|
||||
return QString();
|
||||
return {};
|
||||
|
||||
QStringList mutedDicts;
|
||||
|
||||
|
@ -813,7 +808,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
|
|||
return mutedDicts.join( "," );
|
||||
}
|
||||
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList ArticleView::getMutedDictionaries( unsigned group )
|
||||
|
@ -830,7 +825,7 @@ QStringList ArticleView::getMutedDictionaries( unsigned group )
|
|||
else
|
||||
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
||||
if ( !mutedDictionaries )
|
||||
return QStringList();
|
||||
return {};
|
||||
|
||||
QStringList mutedDicts;
|
||||
|
||||
|
@ -846,7 +841,7 @@ QStringList ArticleView::getMutedDictionaries( unsigned group )
|
|||
return mutedDicts;
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
return {};
|
||||
}
|
||||
|
||||
void ArticleView::linkHovered( const QString & link )
|
||||
|
@ -1010,6 +1005,14 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
return;
|
||||
}
|
||||
|
||||
if ( Utils::Url::hasQueryItem( url, "dictionaries" ) ) {
|
||||
// Specific dictionary group from full-text search
|
||||
QStringList dictsList = Utils::Url::queryItemValue( url, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
||||
|
||||
showDefinition( word, dictsList, QRegExp(), getGroup( url ), false );
|
||||
return;
|
||||
}
|
||||
|
||||
QString newScrollTo( scrollTo );
|
||||
if ( Utils::Url::hasQueryItem( url, "dict" ) ) {
|
||||
// Link to other dictionary
|
||||
|
@ -1054,7 +1057,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
|
||||
std::vector< sptr< Dictionary::Class > > const * activeDicts = nullptr;
|
||||
|
||||
if ( groups.size() ) {
|
||||
if ( !groups.empty() ) {
|
||||
for ( const auto & group : groups )
|
||||
if ( group.id == currentGroup ) {
|
||||
activeDicts = &( group.dictionaries );
|
||||
|
@ -1203,7 +1206,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
}
|
||||
}
|
||||
}
|
||||
else if ( isExternalLink( url ) ) {
|
||||
else if ( Utils::isExternalLink( url ) ) {
|
||||
// Use the system handler for the conventional external links
|
||||
QDesktopServices::openUrl( url );
|
||||
}
|
||||
|
@ -1518,7 +1521,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
tryMangleWebsiteClickedUrl( targetUrl, contexts );
|
||||
|
||||
if ( !targetUrl.isEmpty() ) {
|
||||
if ( !isExternalLink( targetUrl ) ) {
|
||||
if ( !Utils::isExternalLink( targetUrl ) ) {
|
||||
followLink = new QAction( tr( "Op&en Link" ), &menu );
|
||||
menu.addAction( followLink );
|
||||
|
||||
|
@ -1528,7 +1531,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
}
|
||||
}
|
||||
|
||||
if ( isExternalLink( targetUrl ) ) {
|
||||
if ( Utils::isExternalLink( targetUrl ) ) {
|
||||
followLinkExternal = new QAction( tr( "Open Link in &External Browser" ), &menu );
|
||||
menu.addAction( followLinkExternal );
|
||||
menu.addAction( webview->pageAction( QWebEnginePage::CopyLinkToClipboard ) );
|
||||
|
|
|
@ -401,10 +401,6 @@ private:
|
|||
/// frame.
|
||||
void isFramedArticle( QString const & article, const std::function< void( bool framed ) > & callback );
|
||||
|
||||
/// Checks if the given link is to be opened externally, as opposed to opening
|
||||
/// it in-place.
|
||||
bool isExternalLink( QUrl const & url );
|
||||
|
||||
/// Sees if the last clicked link is from a website frame. If so, changes url
|
||||
/// to point to url text translation instead, and saves the original
|
||||
/// url to the appropriate "contexts" entry.
|
||||
|
|
Loading…
Reference in a new issue