From 5af562caec6cbe8d64b263797bdc9cf5cd29a98c Mon Sep 17 00:00:00 2001 From: Abs62 Date: Sat, 13 Dec 2014 18:09:42 +0300 Subject: [PATCH 1/7] Stardict: Handle
tags in dictionary decription --- stardict.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stardict.cc b/stardict.cc index ffca3c35..0a51f726 100644 --- a/stardict.cc +++ b/stardict.cc @@ -561,7 +561,10 @@ QString const& StardictDictionary::getDescription() Ifo ifo( ifoFile ); if( !ifo.copyright.empty() ) - dictionaryDescription += "Copyright: " + QString::fromUtf8( ifo.copyright.c_str() ) + "\n\n"; + dictionaryDescription += "Copyright: " + + QString::fromUtf8( ifo.copyright.c_str() ) + .replace( "
", "\n", Qt::CaseInsensitive ) + + "\n\n"; if( !ifo.author.empty() ) dictionaryDescription += "Author: " + QString::fromUtf8( ifo.author.c_str() ) + "\n\n"; @@ -573,7 +576,8 @@ QString const& StardictDictionary::getDescription() { QString desc = QString::fromUtf8( ifo.description.c_str() ); desc.replace( "\t", "
" ); - desc.replace( "\\n", "
" ); + desc.replace( "\\n", "\n" ); + desc.replace( "
", "\n", Qt::CaseInsensitive ); dictionaryDescription += Html::unescape( desc ); } From eaa8e8f270bee84fbb1f73702d0b65c3f9f89efa Mon Sep 17 00:00:00 2001 From: Abs62 Date: Sat, 13 Dec 2014 20:14:31 +0300 Subject: [PATCH 2/7] Change sizing of dictionary description window in dictionaries dialog --- orderandprops.cc | 5 +++++ orderandprops.ui | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/orderandprops.cc b/orderandprops.cc index 6cef5332..264ed2a4 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -191,6 +191,8 @@ void OrderAndProps::disableDictionaryDescription() ui.dictionaryDescription->clear(); ui.dictionaryDescription->setVisible( false ); ui.dictionaryDescriptionLabel->setVisible( false ); + ui.infoVerticalSpacer->changeSize( 20, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ); + ui.infoVerticalLayout->invalidate(); } void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx ) @@ -233,12 +235,15 @@ void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const ui.dictionaryDescription->setPlainText( descText ); ui.dictionaryDescription->setVisible( true ); ui.dictionaryDescriptionLabel->setVisible( true ); + ui.infoVerticalSpacer->changeSize( 0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum ); } else { ui.dictionaryDescription->setVisible( false ); ui.dictionaryDescriptionLabel->setVisible( false ); + ui.infoVerticalSpacer->changeSize( 20, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ); } + ui.infoVerticalLayout->invalidate(); } } diff --git a/orderandprops.ui b/orderandprops.ui index 93c6143e..62d48533 100644 --- a/orderandprops.ui +++ b/orderandprops.ui @@ -66,7 +66,7 @@ Dictionary information - + @@ -214,7 +214,7 @@ - + Qt::Vertical From dc8914e8a5b0fe9b2cbd66c8ff19e711576480e8 Mon Sep 17 00:00:00 2001 From: Steve J Date: Thu, 18 Dec 2014 18:48:16 -0800 Subject: [PATCH 3/7] update note on required Qt version, is now 4.6 on Windows because of use of QWebElement class --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac83c8f0..1c618d94 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ This code has been run and tested on Windows XP/Vista/7, Ubuntu Linux, Mac OS X. ### External Deps * Make, GCC, Git -* Qt framework. Minumal required version is 4.5. But Qt 4.7 or 4.8 is recommended. +* Qt framework. Minimum required version is 4.6 for Windows, 4.5 for all other platforms. But Qt 4.7 or 4.8 is recommended. +* If you want to use Qt 5.x then use branch qt4x5 * Qt Creator IDE is recommended for development * Various libraries on Linux (png, zlib, etc) * On Mac and Windows all the libraries are already included in the repository From 0e746be996240ddb8d350ab9afdab9a9c3025c55 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 19 Dec 2014 17:12:09 +0300 Subject: [PATCH 4/7] Zim: Fix some links handling (issue #555) --- zim.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zim.cc b/zim.cc index 048317db..d30d7d72 100644 --- a/zim.cc +++ b/zim.cc @@ -600,24 +600,24 @@ string ZimDictionary::convert( const string & in ) text.replace( QRegExp( "<\\s*body\\s*([^>]*)background:([^;\"]*)" ), QString( "]*)src=(\"|)/" ), + text.replace( QRegExp( "<\\s*(img|script)\\s*([^>]*)src=(\"|)(\\.\\.|)/" ), QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); // Fix links without '"' - text.replace( QRegExp( "href=/([^\\s>]+)" ), QString( "href=\"/\\1\"" ) ); + text.replace( QRegExp( "href=(\\.\\.|)/([^\\s>]+)" ), QString( "href=\"\\1/\\2\"" ) ); - text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"/" ), + text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"(\\.\\.|)/" ), QString( "]*)href=\"/[^\"]*\"\\s*title=\"([^\"]*)\"", + QRegExp linkRegexp1( "<\\s*a\\s*([^>]*)href=\"(?!(http(s|)|ftp)://)(/|)[^\"]*\"\\s*title=\"([^\"]*)\"", Qt::CaseSensitive, QRegExp::RegExp2 ); - QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"/A/([^\"]*)\"", + QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"(\\.\\.|)/A/([^\"]*)\"", Qt::CaseSensitive, QRegExp::RegExp2 ); - QRegExp linkRegexp3( ".(s|)htm(l|)", Qt::CaseInsensitive ); + QRegExp linkRegexp3( "\\.(s|)htm(l|)", Qt::CaseInsensitive ); int pos = 0; while( pos >= 0 ) @@ -629,7 +629,7 @@ string ZimDictionary::convert( const string & in ) QStringList list = linkRegexp1.capturedTexts(); QString tag = QString( " Date: Fri, 26 Dec 2014 19:42:31 +0300 Subject: [PATCH 5/7] Zim: Some more links handling --- zim.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zim.cc b/zim.cc index d30d7d72..abc88841 100644 --- a/zim.cc +++ b/zim.cc @@ -613,7 +613,7 @@ string ZimDictionary::convert( const string & in ) Qt::CaseSensitive, QRegExp::RegExp2 ); - QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"(\\.\\.|)/A/([^\"]*)\"", + QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"(\\.\\.|)/([^\"]*)\"", Qt::CaseSensitive, QRegExp::RegExp2 ); From 6bf6dd46df2cd3832d544b508631fbbd0f8c36e4 Mon Sep 17 00:00:00 2001 From: jjzz Date: Wed, 7 Jan 2015 07:08:13 -0500 Subject: [PATCH 6/7] update ZimDictionary::convert(), proper display --- zim.cc | 105 +++++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 60 deletions(-) diff --git a/zim.cc b/zim.cc index abc88841..6c3088dd 100644 --- a/zim.cc +++ b/zim.cc @@ -597,93 +597,78 @@ string ZimDictionary::convert( const string & in ) { QString text = QString::fromUtf8( in.c_str() ); + // replace background text.replace( QRegExp( "<\\s*body\\s*([^>]*)background:([^;\"]*)" ), QString( "]*)src=(\"|)(\\.\\.|)/" ), QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); // Fix links without '"' text.replace( QRegExp( "href=(\\.\\.|)/([^\\s>]+)" ), QString( "href=\"\\1/\\2\"" ) ); + // pattern text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"(\\.\\.|)/" ), QString( "]*)href=\"(?!(http(s|)|ftp)://)(/|)[^\"]*\"\\s*title=\"([^\"]*)\"", + // localize the en.wiki***.com|org series links + text.replace( QRegExp( "<\\s*a\\s+(class=\"external\"\\s+)href=\"http(s|)://en\\.(wiki(pedia|books|news|quote|source|versity)|wiktionary)\\.(org|com)/wiki/" ), + QString( ", excluding any known protocols such as http://, mailto:, #(comment) + // these links will be translated into local definitions + QRegExp rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>", Qt::CaseSensitive, QRegExp::RegExp2 ); - - QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"(\\.\\.|)/([^\"]*)\"", - Qt::CaseSensitive, - QRegExp::RegExp2 ); - - QRegExp linkRegexp3( "\\.(s|)htm(l|)", Qt::CaseInsensitive ); - int pos = 0; - while( pos >= 0 ) + while( (pos = rxLink.indexIn( text, pos )) >= 0 ) { - pos = linkRegexp1.indexIn( text, pos ); - if( pos < 0 ) - break; + QStringList list = rxLink.capturedTexts(); + QString tag = list[3]; // a url, ex: Precambrian_Chaotian.html + if ( !list[4].isEmpty() ) // a title, ex: title="Precambrian/Chaotian" + tag = list[4].split("\"")[1]; - QStringList list = linkRegexp1.capturedTexts(); - - QString tag = QString( "" ); + text.replace( pos, list[0].length(), tag ); pos += tag.length() + 1; } + // Occassionally words needs to be displayed in vertical, but
were changed to somewhere + // proper style:
N
e
o
p
t
e
r
a
+ QRegExp rxBR( "(]*>)\\s*((\\w\\s*<br(\\\\|/|)>\\s*)+\\w)\\s*", + Qt::CaseSensitive, + QRegExp::RegExp2 ); pos = 0; - while( pos >= 0 ) + while( (pos = rxBR.indexIn( text, pos )) >= 0 ) { - pos = linkRegexp2.indexIn( text, pos ); - if( pos < 0 ) - break; - - QStringList list = linkRegexp2.capturedTexts(); - - QString tag = QString( "" ). + prepend( list[1] ). + append( "" ); + text.replace( pos, list[0].length(), tag ); pos += tag.length() + 1; } + // // output all links in the page - only for analysis + // QRegExp rxPrintAllLinks( "<\\s*a\\s+[^>]*href=\"[^\"]*\"[^>]*>", + // Qt::CaseSensitive, + // QRegExp::RegExp2 ); + // pos = 0; + // while( (pos = rxPrintAllLinks.indexIn( text, pos )) >= 0 ) + // { + // QStringList list = rxPrintAllLinks.capturedTexts(); + // qDebug() << "\n--Alllinks--" << list[0]; + // pos += list[0].length() + 1; + // } + // Fix outstanding elements text += "
"; From 7859474f1338f084c01c8a14c9949099340911cf Mon Sep 17 00:00:00 2001 From: jjzz Date: Wed, 7 Jan 2015 13:33:26 -0500 Subject: [PATCH 7/7] minor change on wiki url --- zim.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zim.cc b/zim.cc index 6c3088dd..c9546a16 100644 --- a/zim.cc +++ b/zim.cc @@ -612,9 +612,11 @@ string ZimDictionary::convert( const string & in ) text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"(\\.\\.|)/" ), QString( " series links + // excluding those keywords that have ":" in it + QString urlWiki = "\"http(s|)://en\\.(wiki(pedia|books|news|quote|source|voyage|versity)|wiktionary)\\.(org|com)/wiki/([^:\"]*)\""; + text.replace( QRegExp( "<\\s*a\\s+(class=\"external\"\\s+|)href=" + urlWiki ), + QString( ", excluding any known protocols such as http://, mailto:, #(comment) // these links will be translated into local definitions