diff --git a/editdictionaries.cc b/editdictionaries.cc index 79b17a32..1da47be7 100644 --- a/editdictionaries.cc +++ b/editdictionaries.cc @@ -11,19 +11,17 @@ using std::vector; EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_, vector< sptr< Dictionary::Class > > & dictionaries_, - QMap > & dictMap_, Instances::Groups & groupInstances_, QNetworkAccessManager & dictNetMgr_ ): QDialog( parent, Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint ), cfg( cfg_ ), dictionaries( dictionaries_ ), - dictMap(dictMap_), groupInstances( groupInstances_ ), dictNetMgr( dictNetMgr_ ), origCfg( cfg ), sources( this, cfg ), orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries, - dictionaries, dictMap ) ), + dictionaries ) ), groups( new Groups( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ), dictionariesChanged( false ), groupsChanged( false ), @@ -216,7 +214,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) orderAndProps.clear(); loadDictionaries( this, true, cfg, dictionaries, dictNetMgr ); - dictMap = Dictionary::dictToMap(dictionaries); + // If no changes to groups were made, update the original data bool noGroupEdits = ( origCfg.groups == savedGroups ); @@ -241,7 +239,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) if ( rebuildGroups ) { - orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries, dictMap ); + orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries ); groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); ui.tabs->removeTab( 1 ); diff --git a/editdictionaries.hh b/editdictionaries.hh index a2488d95..fe5e93f3 100644 --- a/editdictionaries.hh +++ b/editdictionaries.hh @@ -23,7 +23,6 @@ public: EditDictionaries( QWidget * parent, Config::Class & cfg, std::vector< sptr< Dictionary::Class > > & dictionaries, - QMap > & dictMap_, Instances::Groups & groupInstances, // We only clear those on rescan QNetworkAccessManager & dictNetMgr ); @@ -78,7 +77,6 @@ private: Config::Class & cfg; std::vector< sptr< Dictionary::Class > > & dictionaries; - QMap > & dictMap; Instances::Groups & groupInstances; QNetworkAccessManager & dictNetMgr; diff --git a/groups.cc b/groups.cc index d36b9520..a0b82920 100644 --- a/groups.cc +++ b/groups.cc @@ -20,7 +20,7 @@ Groups::Groups( QWidget * parent, // Populate the dictionaries' list ui.dictionaries->setAsSource(); - ui.dictionaries->populate( Instances::Group( order, Dictionary::dictToMap(dicts), Config::Group() ).dictionaries, + ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries, dicts ); ui.searchLine->applyTo( ui.dictionaries ); @@ -87,13 +87,12 @@ void Groups::editGroup( unsigned id ) void Groups::updateDictionaryOrder( Config::Group const & order ) { // Make sure it differs from what we have - auto dictMap = Dictionary::dictToMap( dicts ); - Instances::Group newOrder( order, dictMap, Config::Group() ); + Instances::Group newOrder( order, dicts, Config::Group() ); if( ui.dictionaries->getCurrentDictionaries() != newOrder.dictionaries ) { // Repopulate - ui.dictionaries->populate( Instances::Group( order, dictMap, Config::Group() ).dictionaries, dicts ); + ui.dictionaries->populate( Instances::Group( order, dicts, Config::Group() ).dictionaries, dicts ); } } diff --git a/groups_widgets.cc b/groups_widgets.cc index f1142d0b..35b158ab 100644 --- a/groups_widgets.cc +++ b/groups_widgets.cc @@ -31,8 +31,7 @@ DictGroupWidget::DictGroupWidget( QWidget * parent, groupId( group.id ) { ui.setupUi( this ); - auto dictMap = Dictionary::dictToMap(dicts); - ui.dictionaries->populate( Instances::Group( group, dictMap, Config::Group() ).dictionaries, dicts ); + ui.dictionaries->populate( Instances::Group( group, dicts, Config::Group() ).dictionaries, dicts ); // Populate icons' list @@ -329,7 +328,7 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value, g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) ); - Instances::Group i( g, Dictionary::dictToMap(*allDicts), Config::Group() ); + Instances::Group i( g, *allDicts, Config::Group() ); if ( i.dictionaries.size() == 1 ) { diff --git a/iframeschemehandler.cpp b/iframeschemehandler.cpp index da60703f..889cd872 100644 --- a/iframeschemehandler.cpp +++ b/iframeschemehandler.cpp @@ -46,57 +46,16 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) while( !base.isEmpty() && !base.endsWith( "/" ) ) base.chop( 1 ); - QRegularExpression tags( "<\\s*(a|link|img|script)\\s+[^>]*(src|href)\\s*=\\s*['\"][^>]+>", - QRegularExpression::CaseInsensitiveOption ); - QRegularExpression links( "\\b(src|href)\\s*=\\s*(['\"])([^'\"]+['\"])", - QRegularExpression::CaseInsensitiveOption ); - int pos = 0; - QString articleNewString; - QRegularExpressionMatchIterator it = tags.globalMatch( articleString ); - while( it.hasNext() ) - { - QRegularExpressionMatch match = it.next(); - articleNewString += articleString.mid( pos, match.capturedStart() - pos ); - pos = match.capturedEnd(); - - QString tag = match.captured(); - - QRegularExpressionMatch match_links = links.match( tag ); - if( !match_links.hasMatch() ) - { - articleNewString += tag; - continue; - } - - QString url = match_links.captured( 3 ); - - if( url.indexOf( ":/" ) >= 0 || url.indexOf( "data:" ) >= 0 || url.indexOf( "mailto:" ) >= 0 || - url.startsWith( "#" ) || url.startsWith( "javascript:" ) ) - { - // External link, anchor or base64-encoded data - articleNewString += tag; - continue; - } - - QString newUrl = match_links.captured( 1 ) + "=" + match_links.captured( 2 ); - if( url.startsWith( "//" ) ) - newUrl += reply->url().scheme() + ":"; - else if( url.startsWith( "/" ) ) - newUrl += root; - else - newUrl += base; - newUrl += match_links.captured( 3 ); - - tag.replace( match_links.capturedStart(), match_links.capturedLength(), newUrl ); - articleNewString += tag; - } - if( pos ) - { - articleNewString += articleString.mid( pos ); - articleString = articleNewString; - articleNewString.clear(); - } - + QRegularExpression tags( "", + QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption ); + + QString baseTagHtml = ""; + + // remove existed base tag + articleString.remove( tags ) ; + qsizetype pos = articleString.indexOf( "" ); + if( pos > -1 ) + articleString.insert( pos + 6, baseTagHtml ); buffer->setData(codec->fromUnicode(articleString)); diff --git a/instances.cc b/instances.cc index c39cfe52..69da55d0 100644 --- a/instances.cc +++ b/instances.cc @@ -11,7 +11,7 @@ using std::set; using std::string; Group::Group( Config::Group const & cfgGroup, - QMap > const & allDictionaries, + std::vector< sptr< Dictionary::Class > > const & allDictionaries, Config::Group const & inactiveGroup ): id( cfgGroup.id ), name( cfgGroup.name ), @@ -24,13 +24,15 @@ Group::Group( Config::Group const & cfgGroup, QMap > groupDicts; QVector dictOrderList; + auto dictMap = Dictionary::dictToMap( allDictionaries ); for( unsigned x = 0; x < (unsigned)cfgGroup.dictionaries.size(); ++x ) { std::string id = cfgGroup.dictionaries[ x ].id.toStdString(); - if(allDictionaries.contains(id)){ - groupDicts.insert(id, allDictionaries[ id ] ); + if( dictMap.contains( id ) ) + { + groupDicts.insert( id, dictMap[ id ] ); dictOrderList.push_back(id); } } diff --git a/instances.hh b/instances.hh index 1ce40b18..b47e6348 100644 --- a/instances.hh +++ b/instances.hh @@ -29,7 +29,7 @@ struct Group /// Instantiates the given group from its configuration. If some dictionary /// wasn't found, it just skips it. Group( Config::Group const & cfgGroup, - QMap > const & allDictionaries, + std::vector< sptr< Dictionary::Class > > const & allDictionaries, Config::Group const & inactiveGroup ); /// Creates an empty group. diff --git a/mainwindow.cc b/mainwindow.cc index b122e409..c21e99a7 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1398,11 +1398,11 @@ void MainWindow::updateGroupList() // Add dictionaryOrder first, as the 'All' group. { - Instances::Group g( cfg.dictionaryOrder, dictMap, Config::Group() ); + Instances::Group g( cfg.dictionaryOrder, dictionaries, Config::Group() ); // Add any missing entries to dictionary order Instances::complementDictionaryOrder( g, - Instances::Group( cfg.inactiveDictionaries, dictMap, Config::Group() ), + Instances::Group( cfg.inactiveDictionaries, dictionaries, Config::Group() ), dictionaries ); g.name = tr( "All" ); @@ -1413,7 +1413,7 @@ void MainWindow::updateGroupList() } for( int x = 0; x < cfg.groups.size(); ++x ) - groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictMap, cfg.inactiveDictionaries ) ); + groupInstances.push_back( Instances::Group( cfg.groups[ x ], dictionaries, cfg.inactiveDictionaries ) ); // Update names for dictionaries that are present, so that they could be // found in case they got moved. @@ -2072,7 +2072,7 @@ void MainWindow::editDictionaries( unsigned editDictionaryGroup ) { // Limit existence of newCfg Config::Class newCfg = cfg; - EditDictionaries dicts( this, newCfg, dictionaries, dictMap, groupInstances, dictNetMgr ); + EditDictionaries dicts( this, newCfg, dictionaries, groupInstances, dictNetMgr ); connect( &dicts, SIGNAL( showDictionaryInfo( QString const & ) ), this, SLOT( showDictionaryInfo( QString const & ) ) ); diff --git a/mediawiki.cc b/mediawiki.cc index 96998517..59515bfa 100644 --- a/mediawiki.cc +++ b/mediawiki.cc @@ -15,6 +15,7 @@ #include "utils.hh" #include +#include "globalbroadcaster.h" namespace MediaWiki { @@ -125,6 +126,8 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str, GD_DPRINTF( "request begin\n" ); QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" ); + GlobalBroadcaster::instance()->addWhitelist( reqUrl.host() ); + Utils::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ).replace( '+', "%2B" ) ); netReply = mgr.get( QNetworkRequest( reqUrl ) ); diff --git a/orderandprops.cc b/orderandprops.cc index 863d596c..cb16548c 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -85,15 +85,12 @@ bool dictLessThan( sptr< Dictionary::Class > const & dict1, OrderAndProps::OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder, Config::Group const & inactiveDictionaries, - std::vector< sptr< Dictionary::Class > > const & - allDictionaries , - QMap > const & dictMap): + std::vector< sptr< Dictionary::Class > > const & allDictionaries): QWidget( parent ) { ui.setupUi( this ); - - Instances::Group order( dictionaryOrder, dictMap, Config::Group() ); - Instances::Group inactive( inactiveDictionaries, dictMap, Config::Group() ); + Instances::Group order( dictionaryOrder, allDictionaries, Config::Group() ); + Instances::Group inactive( inactiveDictionaries, allDictionaries, Config::Group() ); Instances::complementDictionaryOrder( order, inactive, allDictionaries ); diff --git a/orderandprops.hh b/orderandprops.hh index f7529d1e..9cabcb43 100644 --- a/orderandprops.hh +++ b/orderandprops.hh @@ -16,8 +16,7 @@ public: OrderAndProps( QWidget * parent, Config::Group const & dictionaryOrder, Config::Group const & inactiveDictionaries, - std::vector< sptr< Dictionary::Class > > const & allDictionaries , - QMap > const & dictMap); + std::vector< sptr< Dictionary::Class > > const & allDictionaries); Config::Group getCurrentDictionaryOrder() const; Config::Group getCurrentInactiveDictionaries() const; @@ -35,7 +34,6 @@ private slots: private: Ui::OrderAndProps ui; - void disableDictionaryDescription(); void describeDictionary( DictListWidget *, QModelIndex const & ); diff --git a/utils.hh b/utils.hh index 76661c6e..a30a144c 100644 --- a/utils.hh +++ b/utils.hh @@ -84,11 +84,11 @@ inline bool isExternalLink(QUrl const &url) { url.scheme() == "file" || url.toString().startsWith( "//" ); } -inline bool isCssFontImage(QUrl const &url) { +inline bool isHtmlResources(QUrl const &url) { auto fileName = url.fileName(); auto ext=fileName.mid(fileName.lastIndexOf(".")); - QStringList extensions{".css",".woff",".woff2","ttf",".bmp" ,".jpg", ".png", ".tif",".wav", ".ogg", ".oga", ".mp3", ".mp4", ".aac", ".flac",".mid", ".wv ",".ape"} ; - return extensions.indexOf(ext)>-1; + QStringList extensions{".css",".woff",".woff2","ttf",".bmp" ,".jpg", ".png",".gif", ".tif",".wav", ".ogg", ".oga", ".mp3", ".mp4", ".aac", ".flac",".mid", ".wv",".ape"} ; + return extensions.contains( ext, Qt::CaseInsensitive ); } inline QString escape( QString const & plain ) diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp index 5e190607..1fcff130 100644 --- a/weburlrequestinterceptor.cpp +++ b/weburlrequestinterceptor.cpp @@ -21,7 +21,7 @@ void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) //whitelist url does not block return; } - if(Utils::isCssFontImage(info.requestUrl())){ + if(Utils::isHtmlResources(info.requestUrl())){ //let throuth the resources file. return; }