Merge branch 'staged' into dev

This commit is contained in:
Xiao YiFang 2022-06-08 21:25:35 +08:00
commit eb7b924e4e
14 changed files with 94 additions and 20 deletions

View file

@ -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 }}

View file

@ -97,4 +97,5 @@ body
{
clear: both;
border-top: 1px solid #92b0dd;
margin-bottom: 1em;
}

View file

@ -531,7 +531,7 @@ div.xdxf
/************* MDict dictionaries **************/
.mdict
{
/* margin-top: 1em; */
}
.mdict a[name]

View file

@ -8,6 +8,7 @@
#include "gddebug.hh"
#include "utils.hh"
#include <QNetworkAccessManager>
#include "globalbroadcaster.h"
using std::string;

View file

@ -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 );
}

View file

@ -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

View file

@ -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

View file

@ -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 );
};

View file

@ -157,6 +157,35 @@ QString unescape( QString const & str, bool saveFormat )
return str;
}
QString fromHtmlEscaped( QString const & str){
QString retVal = str;
QRegularExpression regExp("(?<lt>\\&lt\\;)|(?<gt>\\&gt\\;)|(?<amp>\\&amp\\;)|(?<quot>\\&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 );

View file

@ -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 );
}

View file

@ -1417,6 +1417,7 @@ void MainWindow::updateGroupList()
groupList->fill( groupInstances );
groupList->setCurrentGroup( cfg.lastMainGroupId );
updateCurrentGroupProperty();
updateDictionaryBar();

View file

@ -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

View file

@ -6,6 +6,11 @@ $(function() {
if ('string' != typeof(link)) {
return;
}
if(link.indexOf("javascript:")>=0){
return;
}
if(link.indexOf(":")>=0){
emitClickedEvent(link);
return false;

View file

@ -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
{