diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7624d090..6601aefd 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -75,8 +75,11 @@ jobs: mv ${targetName}.app ./tmp # --background "installer_background.png" create-dmg --volname "${targetName} Installer" --volicon "icons/macicon.icns" --window-pos 200 120 --window-size 800 400 --icon-size 100 --icon "${targetName}.app" 200 190 --hide-extension "${targetName}.app" --app-drop-link 600 185 --skip-jenkins "${targetName}.dmg" tmp/ - - + - name: Generate changelog + id: changelog + uses: metcalfc/changelog-generator@v3.0.0 + with: + myToken: ${{ secrets.GITHUB_TOKEN }} - name: Set outputs id: vars run: | @@ -122,4 +125,6 @@ jobs: auto built by github action. use on your on risk:-) CHANGES: - ${{ steps.vars.outputs.COMMIT_SUMMARY }} + ${{ steps.vars.outputs.COMMIT_SUMMARY }} + CHANGE LOGS: + ${{ steps.changelog.outputs.changelog }} diff --git a/article-style-st-lingoes.css b/article-style-st-lingoes.css index 9f31b39e..455aa75b 100644 --- a/article-style-st-lingoes.css +++ b/article-style-st-lingoes.css @@ -97,4 +97,5 @@ body { clear: both; border-top: 1px solid #92b0dd; + margin-bottom: 1em; } diff --git a/article-style.css b/article-style.css index a7ea4d2a..959edbaa 100644 --- a/article-style.css +++ b/article-style.css @@ -531,7 +531,7 @@ div.xdxf /************* MDict dictionaries **************/ .mdict { - /* margin-top: 1em; */ + } .mdict a[name] diff --git a/article_netmgr.cc b/article_netmgr.cc index 5a172289..e0e23650 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -8,6 +8,7 @@ #include "gddebug.hh" #include "utils.hh" #include +#include "globalbroadcaster.h" using std::string; diff --git a/articlewebpage.cpp b/articlewebpage.cpp index 9b782f8d..bf686114 100644 --- a/articlewebpage.cpp +++ b/articlewebpage.cpp @@ -1,15 +1,38 @@ #include "articlewebpage.h" +#include "utils.hh" ArticleWebPage::ArticleWebPage(QObject *parent) : QWebEnginePage{parent} { } -bool ArticleWebPage::acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame ) +bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame ) { + QUrl url = resUrl; + if( url.scheme() == "bword" || url.scheme() == "entry" ) + { + url.setScheme( "gdlookup" ); + url.setHost( "localhost" ); + url.setPath( "" ); + auto [ valid, word ] = Utils::Url::getQueryWord( resUrl ); + Utils::Url::addQueryItem( url, "word", word ); + Utils::Url::addQueryItem( url, "group", lastReq.group ); + Utils::Url::addQueryItem( url, "muted", lastReq.mutedDicts ); + setUrl( url ); + return false; + } + + //save current gdlookup's values. + if( url.scheme() == "gdlookup" ) + { + lastReq.group = Utils::Url::queryItemValue( url, "group" ); + lastReq.mutedDicts = Utils::Url::queryItemValue( url, "muted" ); + } + if( type == QWebEnginePage::NavigationTypeLinkClicked ) { emit linkClicked( url ); return true; } + return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame ); } diff --git a/articlewebpage.h b/articlewebpage.h index 3e1d32d6..19027148 100644 --- a/articlewebpage.h +++ b/articlewebpage.h @@ -3,6 +3,11 @@ #include +struct LastReqInfo{ + QString group; + QString mutedDicts; +}; + class ArticleWebPage : public QWebEnginePage { Q_OBJECT @@ -12,6 +17,8 @@ signals: void linkClicked( const QUrl & url ); protected: virtual bool acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame ); +private: + LastReqInfo lastReq; }; #endif // ARTICLEWEBPAGE_H diff --git a/globalbroadcaster.cpp b/globalbroadcaster.cpp index 885bf89a..bcac205f 100644 --- a/globalbroadcaster.cpp +++ b/globalbroadcaster.cpp @@ -20,13 +20,15 @@ Config::Preferences * GlobalBroadcaster::getPreference() return preference; } -void GlobalBroadcaster::addWhitelist(QString url){ - whitelist.push_back(url); - auto baseUrl=::getHostBase(url); - whitelist.push_back(baseUrl); +void GlobalBroadcaster::addWhitelist( QString url ) +{ + whitelist.push_back( url ); + auto baseUrl = ::getHostBase( url ); + whitelist.push_back( baseUrl ); } -bool GlobalBroadcaster::existedInWhitelist(QString url){ - return std::find(whitelist.begin(), whitelist.end(), url) != whitelist.end(); +bool GlobalBroadcaster::existedInWhitelist( QString url ) +{ + return std::find( whitelist.begin(), whitelist.end(), url ) != whitelist.end(); } // namespace global diff --git a/globalbroadcaster.h b/globalbroadcaster.h index 3014a46e..6e6992c2 100644 --- a/globalbroadcaster.h +++ b/globalbroadcaster.h @@ -17,6 +17,7 @@ class GlobalBroadcaster : public QObject private: Config::Preferences * preference; std::vector whitelist; + public: void setPreference( Config::Preferences * _pre ); Config::Preferences * getPreference(); @@ -24,6 +25,7 @@ public: void addWhitelist(QString host); bool existedInWhitelist(QString host); static GlobalBroadcaster * instance(); + signals: void dictionaryChanges( ActiveDictIds ad ); }; diff --git a/htmlescape.cc b/htmlescape.cc index 59086e8c..bb2c65e6 100644 --- a/htmlescape.cc +++ b/htmlescape.cc @@ -157,6 +157,35 @@ QString unescape( QString const & str, bool saveFormat ) return str; } +QString fromHtmlEscaped( QString const & str){ + QString retVal = str; + QRegularExpression regExp("(?\\<\\;)|(?\\>\\;)|(?\\&\\;)|(?\\"\\;)", QRegularExpression::PatternOption::CaseInsensitiveOption); + auto match = regExp.match(str, 0); + + while (match.hasMatch()) + { + if (!match.captured("lt").isEmpty()) + { + retVal.replace(match.capturedStart("lt"), match.capturedLength("lt"), "<"); + } + else if (!match.captured("gt").isEmpty()) + { + retVal.replace(match.capturedStart("gt"), match.capturedLength("gt"), ">"); + } + else if (!match.captured("amp").isEmpty()) + { + retVal.replace(match.capturedStart("amp"), match.capturedLength("amp"), "&"); + } + else if (!match.captured("quot").isEmpty()) + { + retVal.replace(match.capturedStart("quot"), match.capturedLength("quot"), "\""); + } + match = regExp.match(retVal, match.capturedStart() + 1); + } + + return retVal; +} + string unescapeUtf8( const string &str, bool saveFormat ) { return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data(), saveFormat ); diff --git a/htmlescape.hh b/htmlescape.hh index f86e4136..39f3d161 100644 --- a/htmlescape.hh +++ b/htmlescape.hh @@ -4,6 +4,7 @@ #ifndef __HTMLESCAPE_HH_INCLUDED__ #define __HTMLESCAPE_HH_INCLUDED__ +#include #include namespace Html { @@ -24,6 +25,8 @@ string escapeForJavaScript( string const & ); // Replace html entities QString unescape( QString const & str, bool saveFormat = false ); + +QString fromHtmlEscaped( QString const & str); string unescapeUtf8( string const & str, bool saveFormat = false ); } diff --git a/mainwindow.cc b/mainwindow.cc index 29f2bee3..fb4ae931 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1417,6 +1417,7 @@ void MainWindow::updateGroupList() groupList->fill( groupInstances ); groupList->setCurrentGroup( cfg.lastMainGroupId ); + updateCurrentGroupProperty(); updateDictionaryBar(); diff --git a/mdictparser.cc b/mdictparser.cc index f3124a46..a4ec7142 100644 --- a/mdictparser.cc +++ b/mdictparser.cc @@ -374,7 +374,7 @@ bool MdictParser::readHeader( QDataStream & in ) { #if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) styleSheets_[ lines[ i ].toInt() ] = - pair< QString, QString >( Html::unescape( lines[ i + 1 ] ), Html::unescape( lines[ i + 2 ] ) ); + pair< QString, QString >( Html::fromHtmlEscaped( lines[ i + 1 ] ), Html::fromHtmlEscaped( lines[ i + 2 ] ) ); #else styleSheets_[ lines[ i ].toInt() ] = pair< QString, QString >( lines[ i + 1 ], lines[ i + 2 ] ); #endif diff --git a/resources/gd-custom.js b/resources/gd-custom.js index ae07cf31..d7557151 100644 --- a/resources/gd-custom.js +++ b/resources/gd-custom.js @@ -6,6 +6,11 @@ $(function() { if ('string' != typeof(link)) { return; } + + if(link.indexOf("javascript:")>=0){ + return; + } + if(link.indexOf(":")>=0){ emitClickedEvent(link); return false; diff --git a/utils.hh b/utils.hh index eb4fee08..a12175af 100644 --- a/utils.hh +++ b/utils.hh @@ -78,13 +78,6 @@ inline QString rstripnull(const QString &str) { return ""; } -inline QString unescapeHtml(const QString &str) { - QTextDocument text; - text.setHtml(str); - return text.toPlainText(); -} - - inline bool isExternalLink(QUrl const &url) { return url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "ftp" || url.scheme() == "mailto" || url.scheme() == "file" || url.toString().startsWith( "//" ); @@ -231,7 +224,9 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url ) { //url,bword://localhost/word if( path.startsWith( "/" ) ) - word = url.path().mid( 1 ); + word = path.mid( 1 ); + else + word = path; } else {