mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-28 12:04:08 +00:00
Merge branch 'staged' into dev
This commit is contained in:
commit
eb7b924e4e
9
.github/workflows/macos.yml
vendored
9
.github/workflows/macos.yml
vendored
|
@ -75,8 +75,11 @@ jobs:
|
||||||
mv ${targetName}.app ./tmp
|
mv ${targetName}.app ./tmp
|
||||||
# --background "installer_background.png"
|
# --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/
|
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
|
- name: Set outputs
|
||||||
id: vars
|
id: vars
|
||||||
run: |
|
run: |
|
||||||
|
@ -123,3 +126,5 @@ jobs:
|
||||||
|
|
||||||
CHANGES:
|
CHANGES:
|
||||||
${{ steps.vars.outputs.COMMIT_SUMMARY }}
|
${{ steps.vars.outputs.COMMIT_SUMMARY }}
|
||||||
|
CHANGE LOGS:
|
||||||
|
${{ steps.changelog.outputs.changelog }}
|
||||||
|
|
|
@ -97,4 +97,5 @@ body
|
||||||
{
|
{
|
||||||
clear: both;
|
clear: both;
|
||||||
border-top: 1px solid #92b0dd;
|
border-top: 1px solid #92b0dd;
|
||||||
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,7 +531,7 @@ div.xdxf
|
||||||
/************* MDict dictionaries **************/
|
/************* MDict dictionaries **************/
|
||||||
.mdict
|
.mdict
|
||||||
{
|
{
|
||||||
/* margin-top: 1em; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.mdict a[name]
|
.mdict a[name]
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "gddebug.hh"
|
#include "gddebug.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
#include "globalbroadcaster.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,38 @@
|
||||||
#include "articlewebpage.h"
|
#include "articlewebpage.h"
|
||||||
|
#include "utils.hh"
|
||||||
|
|
||||||
ArticleWebPage::ArticleWebPage(QObject *parent)
|
ArticleWebPage::ArticleWebPage(QObject *parent)
|
||||||
: QWebEnginePage{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 )
|
if( type == QWebEnginePage::NavigationTypeLinkClicked )
|
||||||
{
|
{
|
||||||
emit linkClicked( url );
|
emit linkClicked( url );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
|
return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
#include <QWebEnginePage>
|
#include <QWebEnginePage>
|
||||||
|
|
||||||
|
struct LastReqInfo{
|
||||||
|
QString group;
|
||||||
|
QString mutedDicts;
|
||||||
|
};
|
||||||
|
|
||||||
class ArticleWebPage : public QWebEnginePage
|
class ArticleWebPage : public QWebEnginePage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -12,6 +17,8 @@ signals:
|
||||||
void linkClicked( const QUrl & url );
|
void linkClicked( const QUrl & url );
|
||||||
protected:
|
protected:
|
||||||
virtual bool acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame );
|
virtual bool acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame );
|
||||||
|
private:
|
||||||
|
LastReqInfo lastReq;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ARTICLEWEBPAGE_H
|
#endif // ARTICLEWEBPAGE_H
|
||||||
|
|
|
@ -20,13 +20,15 @@ Config::Preferences * GlobalBroadcaster::getPreference()
|
||||||
return preference;
|
return preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalBroadcaster::addWhitelist(QString url){
|
void GlobalBroadcaster::addWhitelist( QString url )
|
||||||
whitelist.push_back(url);
|
{
|
||||||
auto baseUrl=::getHostBase(url);
|
whitelist.push_back( url );
|
||||||
whitelist.push_back(baseUrl);
|
auto baseUrl = ::getHostBase( url );
|
||||||
|
whitelist.push_back( baseUrl );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalBroadcaster::existedInWhitelist(QString url){
|
bool GlobalBroadcaster::existedInWhitelist( QString url )
|
||||||
return std::find(whitelist.begin(), whitelist.end(), url) != whitelist.end();
|
{
|
||||||
|
return std::find( whitelist.begin(), whitelist.end(), url ) != whitelist.end();
|
||||||
}
|
}
|
||||||
// namespace global
|
// namespace global
|
||||||
|
|
|
@ -17,6 +17,7 @@ class GlobalBroadcaster : public QObject
|
||||||
private:
|
private:
|
||||||
Config::Preferences * preference;
|
Config::Preferences * preference;
|
||||||
std::vector<QString> whitelist;
|
std::vector<QString> whitelist;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setPreference( Config::Preferences * _pre );
|
void setPreference( Config::Preferences * _pre );
|
||||||
Config::Preferences * getPreference();
|
Config::Preferences * getPreference();
|
||||||
|
@ -24,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();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dictionaryChanges( ActiveDictIds ad );
|
void dictionaryChanges( ActiveDictIds ad );
|
||||||
};
|
};
|
||||||
|
|
|
@ -157,6 +157,35 @@ QString unescape( QString const & str, bool saveFormat )
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString fromHtmlEscaped( QString const & str){
|
||||||
|
QString retVal = str;
|
||||||
|
QRegularExpression regExp("(?<lt>\\<\\;)|(?<gt>\\>\\;)|(?<amp>\\&\\;)|(?<quot>\\"\\;)", 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 )
|
string unescapeUtf8( const string &str, bool saveFormat )
|
||||||
{
|
{
|
||||||
return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data(), saveFormat );
|
return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data(), saveFormat );
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#ifndef __HTMLESCAPE_HH_INCLUDED__
|
#ifndef __HTMLESCAPE_HH_INCLUDED__
|
||||||
#define __HTMLESCAPE_HH_INCLUDED__
|
#define __HTMLESCAPE_HH_INCLUDED__
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Html {
|
namespace Html {
|
||||||
|
@ -24,6 +25,8 @@ string escapeForJavaScript( string const & );
|
||||||
|
|
||||||
// Replace html entities
|
// Replace html entities
|
||||||
QString unescape( QString const & str, bool saveFormat = false );
|
QString unescape( QString const & str, bool saveFormat = false );
|
||||||
|
|
||||||
|
QString fromHtmlEscaped( QString const & str);
|
||||||
string unescapeUtf8( string const & str, bool saveFormat = false );
|
string unescapeUtf8( string const & str, bool saveFormat = false );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1417,6 +1417,7 @@ void MainWindow::updateGroupList()
|
||||||
|
|
||||||
groupList->fill( groupInstances );
|
groupList->fill( groupInstances );
|
||||||
groupList->setCurrentGroup( cfg.lastMainGroupId );
|
groupList->setCurrentGroup( cfg.lastMainGroupId );
|
||||||
|
|
||||||
updateCurrentGroupProperty();
|
updateCurrentGroupProperty();
|
||||||
|
|
||||||
updateDictionaryBar();
|
updateDictionaryBar();
|
||||||
|
|
|
@ -374,7 +374,7 @@ bool MdictParser::readHeader( QDataStream & in )
|
||||||
{
|
{
|
||||||
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||||
styleSheets_[ lines[ i ].toInt() ] =
|
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
|
#else
|
||||||
styleSheets_[ lines[ i ].toInt() ] = pair< QString, QString >( lines[ i + 1 ], lines[ i + 2 ] );
|
styleSheets_[ lines[ i ].toInt() ] = pair< QString, QString >( lines[ i + 1 ], lines[ i + 2 ] );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,6 +6,11 @@ $(function() {
|
||||||
if ('string' != typeof(link)) {
|
if ('string' != typeof(link)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(link.indexOf("javascript:")>=0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(link.indexOf(":")>=0){
|
if(link.indexOf(":")>=0){
|
||||||
emitClickedEvent(link);
|
emitClickedEvent(link);
|
||||||
return false;
|
return false;
|
||||||
|
|
11
utils.hh
11
utils.hh
|
@ -78,13 +78,6 @@ inline QString rstripnull(const QString &str) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QString unescapeHtml(const QString &str) {
|
|
||||||
QTextDocument text;
|
|
||||||
text.setHtml(str);
|
|
||||||
return text.toPlainText();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool isExternalLink(QUrl const &url) {
|
inline bool isExternalLink(QUrl const &url) {
|
||||||
return url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "ftp" || url.scheme() == "mailto" ||
|
return url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "ftp" || url.scheme() == "mailto" ||
|
||||||
url.scheme() == "file" || url.toString().startsWith( "//" );
|
url.scheme() == "file" || url.toString().startsWith( "//" );
|
||||||
|
@ -231,7 +224,9 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
|
||||||
{
|
{
|
||||||
//url,bword://localhost/word
|
//url,bword://localhost/word
|
||||||
if( path.startsWith( "/" ) )
|
if( path.startsWith( "/" ) )
|
||||||
word = url.path().mid( 1 );
|
word = path.mid( 1 );
|
||||||
|
else
|
||||||
|
word = path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue