Merge branch 'Original' into Qt4x5

This commit is contained in:
Abs62 2015-10-30 22:24:44 +03:00
commit 2ab4eeaf60
3 changed files with 30 additions and 16 deletions

View file

@ -494,11 +494,13 @@ void ArticleView::loadFinished( bool )
QString anchor = QUrl::fromPercentEncoding( Qt4x5::Url::encodedQueryItemValue( url, "gdanchor" ) ); QString anchor = QUrl::fromPercentEncoding( Qt4x5::Url::encodedQueryItemValue( url, "gdanchor" ) );
// Find GD anchor on page // Find GD anchor on page
// Pattern: (dictionary ID (32 chars))_(articleID(quint64, hex))_(original anchor)
int n = anchor.indexOf( '_' ); int n = anchor.indexOf( '_' );
if( n > 0 ) if( n == 32 )
// MDict pattern: (dictionary ID (32 chars))_(articleID(quint64, hex))_(original anchor)
n = anchor.indexOf( '_', n + 1 ); n = anchor.indexOf( '_', n + 1 );
else
n = 0;
if( n > 0 ) if( n > 0 )
{ {
@ -526,6 +528,12 @@ void ArticleView::loadFinished( bool )
} }
} }
} }
else
{
url.setFragment( anchor );
ui.definition->page()->mainFrame()->evaluateJavaScript(
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
}
} }
#endif #endif

22
mdx.cc
View file

@ -989,19 +989,15 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar
if( pos < 0 ) if( pos < 0 )
break; break;
if( wordCrossLink.cap( 3 ).isEmpty() ) QString newLink = wordCrossLink.cap( 1 )
pos += wordCrossLink.cap( 0 ).size(); + "gdlookup://localhost/"
else + wordCrossLink.cap( 2 );
{
QString newLink = wordCrossLink.cap( 1 ) if( !wordCrossLink.cap( 3 ).isEmpty() )
+ "gdlookup://localhost/" newLink += QString( "?gdanchor=" ) + uniquePrefix + wordCrossLink.cap( 3 ).mid( 1 );
+ wordCrossLink.cap( 2 )
+ ( wordCrossLink.cap( 3 ).isEmpty() ? "" : QString( "?gdanchor=" ) article.replace( pos, wordCrossLink.cap( 0 ).size(), newLink );
+ uniquePrefix + wordCrossLink.cap( 3 ).mid( 1 ) pos += newLink.size();
);
article.replace( pos, wordCrossLink.cap( 0 ).size(), newLink );
pos += newLink.size();
}
} }
return article; return article;

12
slob.cc
View file

@ -758,6 +758,9 @@ string SlobDictionary::convert( const string & in, RefEntry const & entry )
QRegExp rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>", QRegExp rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>",
Qt::CaseSensitive, Qt::CaseSensitive,
QRegExp::RegExp2 ); QRegExp::RegExp2 );
QString anchor;
int pos = 0; int pos = 0;
while( (pos = rxLink.indexIn( text, pos )) >= 0 ) while( (pos = rxLink.indexIn( text, pos )) >= 0 )
{ {
@ -766,11 +769,18 @@ string SlobDictionary::convert( const string & in, RefEntry const & entry )
if ( !list[4].isEmpty() ) if ( !list[4].isEmpty() )
tag = list[4].split("\"")[1]; tag = list[4].split("\"")[1];
// Find anchor
int n = list[ 3 ].indexOf( '#' );
if( n > 0 )
anchor = QString( "?gdanchor=" ) + list[ 3 ].mid( n + 1 );
else
anchor.clear();
tag.remove( QRegExp(".*/") ). tag.remove( QRegExp(".*/") ).
remove( QRegExp( "\\.(s|)htm(l|)$", Qt::CaseInsensitive ) ). remove( QRegExp( "\\.(s|)htm(l|)$", Qt::CaseInsensitive ) ).
replace( "_", "%20" ). replace( "_", "%20" ).
prepend( "<a href=\"gdlookup://localhost/" ). prepend( "<a href=\"gdlookup://localhost/" ).
append( "\" " + list[4] + ">" ); append( anchor + "\" " + list[4] + ">" );
text.replace( pos, list[0].length(), tag ); text.replace( pos, list[0].length(), tag );
pos += tag.length() + 1; pos += tag.length() + 1;