mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
Merge branch 'Original' into Qt4x5
This commit is contained in:
commit
1c2c1963a4
|
@ -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
|
||||
|
|
|
@ -193,6 +193,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 )
|
||||
|
@ -235,12 +237,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<property name="title">
|
||||
<string>Dictionary information</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<layout class="QVBoxLayout" name="infoVerticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
|
@ -214,7 +214,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<spacer name="infoVerticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
|
|
|
@ -562,7 +562,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( "<br>", "\n", Qt::CaseInsensitive )
|
||||
+ "\n\n";
|
||||
|
||||
if( !ifo.author.empty() )
|
||||
dictionaryDescription += "Author: " + QString::fromUtf8( ifo.author.c_str() ) + "\n\n";
|
||||
|
@ -574,7 +577,8 @@ QString const& StardictDictionary::getDescription()
|
|||
{
|
||||
QString desc = QString::fromUtf8( ifo.description.c_str() );
|
||||
desc.replace( "\t", "<br/>" );
|
||||
desc.replace( "\\n", "<br/>" );
|
||||
desc.replace( "\\n", "\n" );
|
||||
desc.replace( "<br>", "\n", Qt::CaseInsensitive );
|
||||
dictionaryDescription += Html::unescape( desc );
|
||||
}
|
||||
|
||||
|
|
109
zim.cc
109
zim.cc
|
@ -598,93 +598,80 @@ string ZimDictionary::convert( const string & in )
|
|||
{
|
||||
QString text = QString::fromUtf8( in.c_str() );
|
||||
|
||||
// replace background
|
||||
text.replace( QRegExp( "<\\s*body\\s*([^>]*)background:([^;\"]*)" ),
|
||||
QString( "<body \\1background: inherited;" ) );
|
||||
|
||||
text.replace( QRegExp( "<\\s*(img|script)\\s*([^>]*)src=(\"|)/" ),
|
||||
// pattern of img and script
|
||||
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=\"/" ),
|
||||
// pattern <link... href="..." ...>
|
||||
text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"(\\.\\.|)/" ),
|
||||
QString( "<link \\1href=\"bres://%1/").arg( getId().c_str() ) );
|
||||
|
||||
QRegExp linkRegexp1( "<\\s*a\\s*([^>]*)href=\"/[^\"]*\"\\s*title=\"([^\"]*)\"",
|
||||
// localize the http://en.wiki***.com|org/wiki/<key> 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( "<a href=\"gdlookup://localhost/\\6\"" ) );
|
||||
|
||||
// pattern <a href="..." ...>, 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=\"/A/([^\"]*)\"",
|
||||
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();
|
||||
tag.remove( QRegExp(".*/") ).
|
||||
remove( QRegExp( "\\.(s|)htm(l|)$", Qt::CaseInsensitive ) ).
|
||||
replace( "_", "%20" ).
|
||||
prepend( "<a href=\"gdlookup://localhost/" ).
|
||||
append( "\" " + list[4] + ">" );
|
||||
|
||||
QString tag = QString( "<a href=\"gdlookup://localhost/" );
|
||||
QString link = list[ 2 ];
|
||||
|
||||
int nbeg = link.lastIndexOf( "/" );
|
||||
if( nbeg < 0 )
|
||||
nbeg = 0;
|
||||
else
|
||||
nbeg += 1;
|
||||
|
||||
int nend = link.lastIndexOf( "." );
|
||||
if( nend < 0 || !link.mid( nend ).contains( linkRegexp3 ) )
|
||||
nend = -1;
|
||||
|
||||
link = link.mid( nbeg, nend < 0 ? -1 : nend - nbeg );
|
||||
|
||||
link.replace( QChar( '_' ), "%20", Qt::CaseInsensitive );
|
||||
|
||||
tag += link + "\" title=\"" + link + "\"";
|
||||
text.replace( pos, list[0].length(), tag );
|
||||
|
||||
pos += tag.length() + 1;
|
||||
}
|
||||
|
||||
// Occassionally words needs to be displayed in vertical, but <br/> were changed to <br\> somewhere
|
||||
// proper style: <a href="gdlookup://localhost/Neoptera" ... >N<br/>e<br/>o<br/>p<br/>t<br/>e<br/>r<br/>a</a>
|
||||
QRegExp rxBR( "(<a href=\"gdlookup://localhost/[^\"]*\"\\s*[^>]*>)\\s*((\\w\\s*<br(\\\\|/|)>\\s*)+\\w)\\s*</a>",
|
||||
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 = rxBR.capturedTexts();
|
||||
QString tag = list[2];
|
||||
tag.replace( QRegExp( "<br( |)(\\\\|/|)>", Qt::CaseInsensitive ) , "<br/>" ).
|
||||
prepend( list[1] ).
|
||||
append( "</a>" );
|
||||
|
||||
QStringList list = linkRegexp2.capturedTexts();
|
||||
|
||||
QString tag = QString( "<a ") + list[ 1 ]
|
||||
+ "href=\"gdlookup://localhost/";
|
||||
QString link = list[ 2 ];
|
||||
|
||||
int nbeg = link.lastIndexOf( "/" );
|
||||
if( nbeg <= 0 )
|
||||
nbeg = 0;
|
||||
else
|
||||
nbeg += 1;
|
||||
|
||||
int nend = link.lastIndexOf( "." );
|
||||
if( nend < 0 || !link.mid( nend ).contains( linkRegexp3 ) )
|
||||
nend = -1;
|
||||
|
||||
link = link.mid( nbeg, nend < 0 ? -1 : nend - nbeg );
|
||||
|
||||
link.replace( QChar( '_' ), "%20", Qt::CaseInsensitive );
|
||||
|
||||
tag += link + "\"";
|
||||
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 += "<br style=\"clear:both;\" />";
|
||||
|
||||
|
|
Loading…
Reference in a new issue