diff --git a/articleview.cc b/articleview.cc index fa53653e..a4df09bc 100644 --- a/articleview.cc +++ b/articleview.cc @@ -519,10 +519,10 @@ void ArticleView::loadFinished( bool ) { // Anchor found, jump to it + url.clear(); url.setFragment( rx.cap( 0 ) ); - ui.definition->page()->mainFrame()->evaluateJavaScript( - QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); + QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); break; } @@ -530,9 +530,10 @@ void ArticleView::loadFinished( bool ) } else { + url.clear(); url.setFragment( anchor ); ui.definition->page()->mainFrame()->evaluateJavaScript( - QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); + QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); } } #endif @@ -545,7 +546,8 @@ void ArticleView::loadFinished( bool ) void ArticleView::handleTitleChanged( QString const & title ) { - emit titleChanged( this, title ); + if( !title.isEmpty() ) // Qt 5.x WebKit raise signal titleChanges(QString()) while navigation within page + emit titleChanged( this, title ); } void ArticleView::handleUrlChanged( QUrl const & url ) diff --git a/langcoder.cc b/langcoder.cc index ea410642..29f3b044 100644 --- a/langcoder.cc +++ b/langcoder.cc @@ -322,7 +322,7 @@ quint32 LangCoder::guessId( const QString & lang ) { for( GDLangCode const * lc = LangCodes; lc->code[ 0 ]; ++lc ) { - if ( lstr == QString( lc->lang ) ) + if ( lstr == ( lstr.size() == 3 ? QString( lc->code3 ) : QString( lc->lang ) ) ) { // We've got a match return code2toInt( lc->code ); diff --git a/mdx.cc b/mdx.cc index b99a14ee..53e80b66 100644 --- a/mdx.cc +++ b/mdx.cc @@ -848,6 +848,32 @@ void MddResourceRequest::run() if ( Filetype::isNameOfCSS( u8ResourceName ) ) { QString css = QString::fromUtf8( data.data(), data.size() ); + + // Correct some url's + + QRegExp links( "url\\(\\s*(['\"]?)([^'\"]*)(['\"]?)\\s*\\)", Qt::CaseInsensitive, QRegExp::RegExp ); + QString id = QString::fromUtf8( dict.getId().c_str() ); + int pos = 0; + for( ; ; ) + { + pos = links.indexIn( css, pos ); + if( pos < 0 ) + break; + QString url = links.cap( 2 ); + + if( url.indexOf( ":/" ) >= 0 ) + { + // External link + pos += links.cap().size(); + continue; + } + + QString newUrl = QString( "url(" ) + links.cap( 1 ) + "bres://" + + id + "/" + url + links.cap( 3 ) + ")"; + css.replace( pos, links.cap().size(), newUrl ); + pos += newUrl.size(); + } + dict.isolateCSS( css, ".mdict" ); QByteArray bytes = css.toUtf8(); data.resize( bytes.size() ); diff --git a/stardict.cc b/stardict.cc index 49b1845f..9889d7b1 100644 --- a/stardict.cc +++ b/stardict.cc @@ -1549,7 +1549,7 @@ void StardictResourceRequest::run() // Correct some url's - QRegExp links( "url\\(\\s*(['\"])([^'\"]*)(['\"])\\s*\\)"); + QRegExp links( "url\\(\\s*(['\"]?)([^'\"]*)(['\"]?)\\s*\\)", Qt::CaseInsensitive, QRegExp::RegExp ); QString id = QString::fromUtf8( dict.getId().c_str() ); int pos = 0; for( ; ; )