Merge branch 'staged' into dev

This commit is contained in:
Xiao YiFang 2022-11-24 20:34:56 +08:00
commit ff5d82d7af
14 changed files with 70 additions and 34 deletions

View file

@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true

View file

@ -29,7 +29,7 @@ jobs:
qt_arch: [clang_64] qt_arch: [clang_64]
env: env:
targetName: GoldenDict targetName: GoldenDict
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true

View file

@ -26,7 +26,7 @@ jobs:
qt_arch: [clang_64] qt_arch: [clang_64]
env: env:
targetName: GoldenDict targetName: GoldenDict
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
steps: steps:

View file

@ -30,7 +30,7 @@ jobs:
qt_arch: [clang_64] qt_arch: [clang_64]
env: env:
targetName: GoldenDict targetName: GoldenDict
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true

View file

@ -30,7 +30,7 @@ jobs:
qt_ver: [6.3.2,6.4.1] qt_ver: [6.3.2,6.4.1]
qt_arch: [gcc_64] qt_arch: [gcc_64]
env: env:
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
steps: steps:

View file

@ -30,7 +30,7 @@ jobs:
qt_ver: [5.15.2] qt_ver: [5.15.2]
qt_arch: [gcc_64] qt_arch: [gcc_64]
env: env:
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
steps: steps:

View file

@ -27,11 +27,11 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [windows-2019] os: [windows-2019]
qt_ver: [6.3.2,6.4.1] qt_ver: [6.3.2]
qt_arch: [win64_msvc2019_64] qt_arch: [win64_msvc2019_64]
env: env:
targetName: GoldenDict.exe targetName: GoldenDict.exe
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
steps: steps:

View file

@ -27,11 +27,11 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [windows-2019] os: [windows-2019]
qt_ver: [6.3.2,6.4.1] qt_ver: [6.3.2]
qt_arch: [win64_msvc2019_64] qt_arch: [win64_msvc2019_64]
env: env:
targetName: GoldenDict.exe targetName: GoldenDict.exe
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
steps: steps:

View file

@ -32,7 +32,7 @@ jobs:
qt_arch: [win64_msvc2019_64] qt_arch: [win64_msvc2019_64]
env: env:
targetName: GoldenDict.exe targetName: GoldenDict.exe
version: 22.9.24 version: 22.11.24
version-suffix: alpha version-suffix: alpha
prerelease: true prerelease: true
# 步骤 # 步骤

View file

@ -170,14 +170,9 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
if( !path.isEmpty() ) if( !path.isEmpty() )
{ {
url.setPath( "" ); url.setPath( "" );
QByteArray referer = req.rawHeader( "Referer" );
QUrl refererUrl = QUrl::fromEncoded( referer );
Utils::Url::addQueryItem( url, "word", path.mid( 1 ) ); Utils::Url::addQueryItem( url, "word", path.mid( 1 ) );
if( Utils::Url::hasQueryItem( refererUrl, "group" ) ) Utils::Url::addQueryItem( url, "group", QString::number(GlobalBroadcaster::instance()->currentGroupId ) );
{
Utils::Url::addQueryItem( url, "group", Utils::Url::queryItemValue( refererUrl, "group" ) );
}
} }
} }
@ -318,7 +313,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
bool ignoreDiacritics = Utils::Url::queryItemValue( url, "ignore_diacritics" ) == "1"; bool ignoreDiacritics = Utils::Url::queryItemValue( url, "ignore_diacritics" ) == "1";
if ( phrase.isValid() ) // Require group and phrase to be passed if ( groupIsValid && phrase.isValid() ) // Require group and phrase to be passed
return articleMaker.makeDefinitionFor( phrase, group, contexts, mutedDicts, QStringList(), ignoreDiacritics ); return articleMaker.makeDefinitionFor( phrase, group, contexts, mutedDicts, QStringList(), ignoreDiacritics );
} }

View file

@ -25,6 +25,7 @@ public:
void addWhitelist(QString host); void addWhitelist(QString host);
bool existedInWhitelist(QString host); bool existedInWhitelist(QString host);
static GlobalBroadcaster * instance(); static GlobalBroadcaster * instance();
unsigned currentGroupId;
signals: signals:
void dictionaryChanges( ActiveDictIds ad ); void dictionaryChanges( ActiveDictIds ad );

View file

@ -1,6 +1,6 @@
TEMPLATE = app TEMPLATE = app
TARGET = goldendict TARGET = goldendict
VERSION = 22.9.24-alpha VERSION = 22.11.24-alpha
# Generate version file. We do this here and in a build rule described later. # Generate version file. We do this here and in a build rule described later.
# The build rule is required since qmake isn't run each time the project is # The build rule is required since qmake isn't run each time the project is
@ -89,7 +89,7 @@ win32 {
win32-msvc* { win32-msvc* {
# VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++ # VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++
VERSION = 22.9.24 VERSION = 22.11.24
DEFINES += __WIN32 _CRT_SECURE_NO_WARNINGS DEFINES += __WIN32 _CRT_SECURE_NO_WARNINGS
contains(QMAKE_TARGET.arch, x86_64) { contains(QMAKE_TARGET.arch, x86_64) {
DEFINES += NOMINMAX __WIN64 DEFINES += NOMINMAX __WIN64

View file

@ -572,6 +572,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
igrp->checkMutedDictionaries( &grp->mutedDictionaries ); igrp->checkMutedDictionaries( &grp->mutedDictionaries );
dictionaryBar.setMutedDictionaries( grp ? &grp->mutedDictionaries : 0 ); dictionaryBar.setMutedDictionaries( grp ? &grp->mutedDictionaries : 0 );
} }
GlobalBroadcaster::instance()->currentGroupId = cfg.lastMainGroupId;
showDictBarNamesTriggered(); // Make update its state according to initial showDictBarNamesTriggered(); // Make update its state according to initial
// setting // setting
@ -2323,6 +2324,10 @@ void MainWindow::currentGroupChanged( int )
dictionaryBar.setMutedDictionaries( 0 ); dictionaryBar.setMutedDictionaries( 0 );
} }
if(igrp){
GlobalBroadcaster::instance()->currentGroupId = cfg.lastMainGroupId;
}
updateDictionaryBar(); updateDictionaryBar();
// Update word search results // Update word search results

63
zim.cc
View file

@ -128,7 +128,7 @@ __attribute__((packed))
enum enum
{ {
Signature = 0x584D495A, // ZIMX on little-endian, XMIZ on big-endian Signature = 0x584D495A, // ZIMX on little-endian, XMIZ on big-endian
CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + Folding::Version CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion + Folding::Version
}; };
struct IdxHeader struct IdxHeader
@ -839,8 +839,44 @@ string ZimDictionary::convert( const string & in )
QString( "<body \\1" ) ); QString( "<body \\1" ) );
// pattern of img and script // pattern of img and script
text.replace( QRegularExpression( "<\\s*(img|script)\\s+([^>]*)src=(\"|)(\\.\\./)*" ), // text.replace( QRegularExpression( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" ),
QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); // QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) );
QRegularExpression rxImgScript( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" );
QRegularExpressionMatchIterator it = rxImgScript.globalMatch( text );
int pos = 0;
QString newText;
while( it.hasNext() )
{
QRegularExpressionMatch match = it.next();
newText += text.mid( pos, match.capturedStart() - pos );
pos = match.capturedEnd();
QStringList list = match.capturedTexts();
QString url = list[ 4 ]; // a url
QString urlLink = match.captured();
QString replacedLink = urlLink;
if( !url.isEmpty() && !url.startsWith( "//" ) && !url.startsWith( "http://" ) && !url.startsWith( "https://" ) )
{
//<\\1 \\2src=\\3bres://%1/
url.remove(QRegularExpression("^\\.*\\/[A-Z]\\/", QRegularExpression::CaseInsensitiveOption));
replacedLink =
QString( "<%1 %2 src=\"bres://%3/%4\"" ).arg( list[ 1 ], list[ 2 ], QString::fromStdString( getId() ), url );
}
newText += replacedLink;
}
if( pos )
{
newText += text.mid( pos );
text = newText;
}
newText.clear();
// Fix links without '"' // Fix links without '"'
text.replace( QRegularExpression( "href=(\\.\\.|)/([^\\s>]+)" ), text.replace( QRegularExpression( "href=(\\.\\.|)/([^\\s>]+)" ),
@ -860,9 +896,8 @@ string ZimDictionary::convert( const string & in )
// these links will be translated into local definitions // these links will be translated into local definitions
// <meta http-equiv="Refresh" content="0;url=../dsalsrv02.uchicago.edu/cgi-bin/0994.html"> // <meta http-equiv="Refresh" content="0;url=../dsalsrv02.uchicago.edu/cgi-bin/0994.html">
QRegularExpression rxLink( "<\\s*(?:a|meta)\\s+([^>]*)(?:href|url)=\"?(?!(?:\\w+://|#|mailto:|tel:))()([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" ); QRegularExpression rxLink( "<\\s*(?:a|meta)\\s+([^>]*)(?:href|url)=\"?(?!(?:\\w+://|#|mailto:|tel:))()([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" );
QRegularExpressionMatchIterator it = rxLink.globalMatch( text ); it = rxLink.globalMatch( text );
int pos = 0; pos = 0;
QString newText;
while( it.hasNext() ) while( it.hasNext() )
{ {
QRegularExpressionMatch match = it.next(); QRegularExpressionMatch match = it.next();
@ -1485,7 +1520,7 @@ void ZimResourceRequest::run()
sptr< Dictionary::DataRequest > ZimDictionary::getResource( string const & name ) sptr< Dictionary::DataRequest > ZimDictionary::getResource( string const & name )
{ {
auto formatedName = QString::fromStdString(name).replace(RX::Zim::linkSpecialChar,""); auto formatedName = QString::fromStdString(name).remove(QRegularExpression("^\\.*\\/[A-Z]\\/", QRegularExpression::CaseInsensitiveOption));
return new ZimResourceRequest( *this, formatedName.toStdString() ); return new ZimResourceRequest( *this, formatedName.toStdString() );
} }
@ -1658,8 +1693,10 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
} }
else else
{ {
auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); // url.insert( url.begin(), '/' );
indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); // url.insert( url.begin(), nameSpace );
// auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar," ");
indexedResources.addSingleWord( Utf8::decode( url ), n );
} }
} }
else else
@ -1689,16 +1726,14 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
} }
} }
else else
if( nameSpace == 'X' ) if( nameSpace == 'X' || nameSpace=='V' || nameSpace=='U'|| nameSpace=='W' )
{ {
continue; continue;
} }
else else
{ {
// url.insert( url.begin(), '/' ); // auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar," ");
// url.insert( url.begin(), nameSpace ); indexedResources.addSingleWord( Utf8::decode( url ), n );
auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,"");
indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n );
} }
} }