mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-28 03:44:07 +00:00
Merge branch 'Original' into Qt4x5
This commit is contained in:
commit
b2b60fc2e1
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#if QT_VERSION >= 0x040600
|
#if QT_VERSION >= 0x040600
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
|
#include <QWebElementCollection>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "qt4x5.hh"
|
#include "qt4x5.hh"
|
||||||
|
@ -277,7 +278,7 @@ ArticleView::~ArticleView()
|
||||||
|
|
||||||
void ArticleView::showDefinition( QString const & word, unsigned group,
|
void ArticleView::showDefinition( QString const & word, unsigned group,
|
||||||
QString const & scrollTo,
|
QString const & scrollTo,
|
||||||
Contexts const & contexts )
|
Contexts const & contexts_ )
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef DISABLE_INTERNAL_PLAYER
|
#ifndef DISABLE_INTERNAL_PLAYER
|
||||||
|
@ -287,6 +288,7 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QUrl req;
|
QUrl req;
|
||||||
|
Contexts contexts( contexts_ );
|
||||||
|
|
||||||
req.setScheme( "gdlookup" );
|
req.setScheme( "gdlookup" );
|
||||||
req.setHost( "localhost" );
|
req.setHost( "localhost" );
|
||||||
|
@ -296,6 +298,13 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
|
||||||
if ( scrollTo.size() )
|
if ( scrollTo.size() )
|
||||||
Qt4x5::Url::addQueryItem( req, "scrollto", scrollTo );
|
Qt4x5::Url::addQueryItem( req, "scrollto", scrollTo );
|
||||||
|
|
||||||
|
Contexts::Iterator pos = contexts.find( "gdanchor" );
|
||||||
|
if( pos != contexts.end() )
|
||||||
|
{
|
||||||
|
req.addQueryItem( "gdanchor", contexts[ "gdanchor" ] );
|
||||||
|
contexts.erase( pos );
|
||||||
|
}
|
||||||
|
|
||||||
if ( contexts.size() )
|
if ( contexts.size() )
|
||||||
{
|
{
|
||||||
QBuffer buf;
|
QBuffer buf;
|
||||||
|
@ -479,6 +488,47 @@ void ArticleView::loadFinished( bool )
|
||||||
articleToJump.clear();
|
articleToJump.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
||||||
|
if( !url.queryItemValue( "gdanchor" ).isEmpty() )
|
||||||
|
{
|
||||||
|
QString anchor = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "gdanchor" ) );
|
||||||
|
|
||||||
|
// Find GD anchor on page
|
||||||
|
// Pattern: (dictionary ID (32 chars))_(articleID(quint64, hex))_(original anchor)
|
||||||
|
|
||||||
|
int n = anchor.indexOf( '_' );
|
||||||
|
if( n > 0 )
|
||||||
|
n = anchor.indexOf( '_', n + 1 );
|
||||||
|
|
||||||
|
if( n > 0 )
|
||||||
|
{
|
||||||
|
QString originalAnchor = anchor.mid( n + 1 );
|
||||||
|
|
||||||
|
QRegExp rx;
|
||||||
|
rx.setMinimal( true );
|
||||||
|
rx.setPattern( anchor.left( 33 ) + "[0-9a-f]*_" + originalAnchor );
|
||||||
|
|
||||||
|
QWebElementCollection coll = ui.definition->page()->mainFrame()->findAllElements( "a[name]" );
|
||||||
|
|
||||||
|
for( QWebElementCollection::iterator it = coll.begin(); it != coll.end(); ++it )
|
||||||
|
{
|
||||||
|
QString name = (*it).attribute( "name" );
|
||||||
|
if( rx.indexIn( name ) >= 0 )
|
||||||
|
{
|
||||||
|
// Anchor found, jump to it
|
||||||
|
|
||||||
|
url.setFragment( rx.cap( 0 ) );
|
||||||
|
|
||||||
|
ui.definition->page()->mainFrame()->evaluateJavaScript(
|
||||||
|
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
emit pageLoaded( this );
|
emit pageLoaded( this );
|
||||||
|
|
||||||
if( Qt4x5::Url::hasQueryItem( ui.definition->url(), "regexp" ) )
|
if( Qt4x5::Url::hasQueryItem( ui.definition->url(), "regexp" ) )
|
||||||
|
@ -980,10 +1030,12 @@ void ArticleView::linkClicked( QUrl const & url_ )
|
||||||
|
|
||||||
void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
||||||
QString const & scrollTo,
|
QString const & scrollTo,
|
||||||
Contexts const & contexts )
|
Contexts const & contexts_ )
|
||||||
{
|
{
|
||||||
qDebug() << "clicked" << url;
|
qDebug() << "clicked" << url;
|
||||||
|
|
||||||
|
Contexts contexts( contexts_ );
|
||||||
|
|
||||||
if( url.scheme().compare( "gdpicture" ) == 0 )
|
if( url.scheme().compare( "gdpicture" ) == 0 )
|
||||||
ui.definition->load( url );
|
ui.definition->load( url );
|
||||||
else
|
else
|
||||||
|
@ -1034,6 +1086,10 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( url.hasQueryItem( "gdanchor" ) )
|
||||||
|
contexts[ "gdanchor" ] = url.queryItemValue( "gdanchor" );
|
||||||
|
|
||||||
showDefinition( url.path().mid( 1 ),
|
showDefinition( url.path().mid( 1 ),
|
||||||
getGroup( ref ), newScrollTo, contexts );
|
getGroup( ref ), newScrollTo, contexts );
|
||||||
}
|
}
|
||||||
|
|
32
mdx.cc
32
mdx.cc
|
@ -947,15 +947,14 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar
|
||||||
QRegExp anchorLinkRe( "(<\\s*a\\s+[^>]*\\b(?:name|id)\\b\\s*=\\s*[\"']*)(?=[^\"'])", Qt::CaseInsensitive );
|
QRegExp anchorLinkRe( "(<\\s*a\\s+[^>]*\\b(?:name|id)\\b\\s*=\\s*[\"']*)(?=[^\"'])", Qt::CaseInsensitive );
|
||||||
anchorLinkRe.setMinimal( true );
|
anchorLinkRe.setMinimal( true );
|
||||||
|
|
||||||
return article
|
QRegExp wordCrossLink( "(href\\s*=\\s*[\"'])entry://([^#\"'/]+)(#?[^\"']*)", Qt::CaseInsensitive );
|
||||||
|
|
||||||
|
article = article
|
||||||
// anchors
|
// anchors
|
||||||
.replace( anchorLinkRe,
|
.replace( anchorLinkRe,
|
||||||
"\\1" + uniquePrefix )
|
"\\1" + uniquePrefix )
|
||||||
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#", Qt::CaseInsensitive ),
|
||||||
"\\1#" + uniquePrefix )
|
"\\1#" + uniquePrefix )
|
||||||
// word cross links
|
|
||||||
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://([^#\"'/]+)#?[^\"']*", Qt::CaseInsensitive ),
|
|
||||||
"\\1gdlookup://localhost/\\2" )
|
|
||||||
// sounds, and audio link script
|
// sounds, and audio link script
|
||||||
.replace( QRegExp( "(<\\s*(?:a|area)\\s+[^>]*\\bhref\\b\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(<\\s*(?:a|area)\\s+[^>]*\\bhref\\b\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
||||||
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
||||||
|
@ -981,6 +980,31 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar
|
||||||
.replace( QRegExp( "(<\\s*img\\s+[^>]*\\bsrc\\b\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
.replace( QRegExp( "(<\\s*img\\s+[^>]*\\bsrc\\b\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
||||||
"\\1\"bres://" + id + "/\\2\"" );
|
"\\1\"bres://" + id + "/\\2\"" );
|
||||||
|
|
||||||
|
// word cross links
|
||||||
|
int pos = 0;
|
||||||
|
while( pos >= 0 )
|
||||||
|
{
|
||||||
|
pos = wordCrossLink.indexIn( article, pos );
|
||||||
|
if( pos < 0 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if( wordCrossLink.cap( 3 ).isEmpty() )
|
||||||
|
pos += wordCrossLink.cap( 0 ).size();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString newLink = wordCrossLink.cap( 1 )
|
||||||
|
+ "gdlookup://localhost/"
|
||||||
|
+ wordCrossLink.cap( 2 )
|
||||||
|
+ ( wordCrossLink.cap( 3 ).isEmpty() ? "" : QString( "?gdanchor=" )
|
||||||
|
+ uniquePrefix + wordCrossLink.cap( 3 ).mid( 1 )
|
||||||
|
);
|
||||||
|
article.replace( pos, wordCrossLink.cap( 0 ).size(), newLink );
|
||||||
|
pos += newLink.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return article;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addEntryToIndex( QString const & word, uint32_t offset, IndexedWords & indexedWords )
|
static void addEntryToIndex( QString const & word, uint32_t offset, IndexedWords & indexedWords )
|
||||||
|
|
Loading…
Reference in a new issue