mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 16:54: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
|
||||
# --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: |
|
||||
|
@ -123,3 +126,5 @@ jobs:
|
|||
|
||||
CHANGES:
|
||||
${{ steps.vars.outputs.COMMIT_SUMMARY }}
|
||||
CHANGE LOGS:
|
||||
${{ steps.changelog.outputs.changelog }}
|
||||
|
|
|
@ -97,4 +97,5 @@ body
|
|||
{
|
||||
clear: both;
|
||||
border-top: 1px solid #92b0dd;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ div.xdxf
|
|||
/************* MDict dictionaries **************/
|
||||
.mdict
|
||||
{
|
||||
/* margin-top: 1em; */
|
||||
|
||||
}
|
||||
|
||||
.mdict a[name]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "gddebug.hh"
|
||||
#include "utils.hh"
|
||||
#include <QNetworkAccessManager>
|
||||
#include "globalbroadcaster.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <QWebEnginePage>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,6 +17,7 @@ class GlobalBroadcaster : public QObject
|
|||
private:
|
||||
Config::Preferences * preference;
|
||||
std::vector<QString> 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 );
|
||||
};
|
||||
|
|
|
@ -157,6 +157,35 @@ QString unescape( QString const & str, bool saveFormat )
|
|||
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 )
|
||||
{
|
||||
return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data(), saveFormat );
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef __HTMLESCAPE_HH_INCLUDED__
|
||||
#define __HTMLESCAPE_HH_INCLUDED__
|
||||
|
||||
#include <QString>
|
||||
#include <string>
|
||||
|
||||
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 );
|
||||
|
||||
}
|
||||
|
|
|
@ -1417,6 +1417,7 @@ void MainWindow::updateGroupList()
|
|||
|
||||
groupList->fill( groupInstances );
|
||||
groupList->setCurrentGroup( cfg.lastMainGroupId );
|
||||
|
||||
updateCurrentGroupProperty();
|
||||
|
||||
updateDictionaryBar();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,6 +6,11 @@ $(function() {
|
|||
if ('string' != typeof(link)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(link.indexOf("javascript:")>=0){
|
||||
return;
|
||||
}
|
||||
|
||||
if(link.indexOf(":")>=0){
|
||||
emitClickedEvent(link);
|
||||
return false;
|
||||
|
|
11
utils.hh
11
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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue