diff --git a/src/common/globalbroadcaster.cc b/src/common/globalbroadcaster.cc index e8b1b885..8a4ddb4e 100644 --- a/src/common/globalbroadcaster.cc +++ b/src/common/globalbroadcaster.cc @@ -8,7 +8,7 @@ GlobalBroadcaster::GlobalBroadcaster( QObject * parent ): { QStringList whiteUrlHosts = { "ajax.googleapis.com" }; - for ( auto host : whiteUrlHosts ) { + for ( const auto host : whiteUrlHosts ) { addWhitelist( host ); } } @@ -17,11 +17,20 @@ GlobalBroadcaster * GlobalBroadcaster::instance() { return bdcaster; } + +void GlobalBroadcaster::insertCache( const QString & key, QByteArray * object ) +{ + //do not cache the item when debug dictionary. + if ( preference->dictionaryDebug ) + return; + cache.insert( key, object ); +} + void GlobalBroadcaster::setPreference( Config::Preferences * p ) { preference = p; } -Config::Preferences * GlobalBroadcaster::getPreference() +Config::Preferences * GlobalBroadcaster::getPreference() const { return preference; } @@ -29,11 +38,11 @@ Config::Preferences * GlobalBroadcaster::getPreference() void GlobalBroadcaster::addWhitelist( QString url ) { whitelist.insert( url ); - auto baseUrl = Utils::Url::getHostBase( url ); + const auto baseUrl = Utils::Url::getHostBase( url ); whitelist.insert( baseUrl ); } -bool GlobalBroadcaster::existedInWhitelist( QString url ) +bool GlobalBroadcaster::existedInWhitelist( QString url ) const { return whitelist.contains( url ); } diff --git a/src/common/globalbroadcaster.hh b/src/common/globalbroadcaster.hh index 41466164..ac51e02f 100644 --- a/src/common/globalbroadcaster.hh +++ b/src/common/globalbroadcaster.hh @@ -29,10 +29,10 @@ class GlobalBroadcaster: public QObject public: void setPreference( Config::Preferences * _pre ); - Config::Preferences * getPreference(); + Config::Preferences * getPreference() const; GlobalBroadcaster( QObject * parent = nullptr ); void addWhitelist( QString host ); - bool existedInWhitelist( QString host ); + bool existedInWhitelist( QString host ) const; static GlobalBroadcaster * instance(); unsigned currentGroupId; QString translateLineText{}; @@ -43,6 +43,8 @@ public: PronounceEngine pronounce_engine; QCache< QString, QByteArray > cache; + void insertCache( const QString &, QByteArray * ); + signals: void dictionaryChanges( ActiveDictIds ad ); void dictionaryClear( ActiveDictIds ad ); diff --git a/src/config.cc b/src/config.cc index 95376a01..c241be0f 100644 --- a/src/config.cc +++ b/src/config.cc @@ -494,6 +494,13 @@ void saveMutedDictionaries( QDomDocument & dd, QDomElement & muted, MutedDiction } // namespace +bool fromConfig2Preference( const QDomNode & node, const QString & expectedValue, bool defaultValue = false ) +{ + if ( !node.isNull() ) + return ( node.toElement().text() == expectedValue ); + return defaultValue; +} + Class load() { QString configName = getConfigFileName(); @@ -1005,6 +1012,8 @@ Class load() c.preferences.removeInvalidIndexOnExit = ( preferences.namedItem( "removeInvalidIndexOnExit" ).toElement().text() == "1" ); + c.preferences.dictionaryDebug = fromConfig2Preference( preferences.namedItem( "dictionaryDebug" ), "1" ); + if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() ) c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt(); @@ -1989,6 +1998,10 @@ void save( Class const & c ) opt.appendChild( dd.createTextNode( c.preferences.removeInvalidIndexOnExit ? "1" : "0" ) ); preferences.appendChild( opt ); + opt = dd.createElement( "dictionaryDebug" ); + opt.appendChild( dd.createTextNode( c.preferences.dictionaryDebug ? "1" : "0" ) ); + preferences.appendChild( opt ); + opt = dd.createElement( "maxStringsInHistory" ); opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) ); preferences.appendChild( opt ); diff --git a/src/config.hh b/src/config.hh index 2e7caa4e..4ec14bac 100644 --- a/src/config.hh +++ b/src/config.hh @@ -403,6 +403,7 @@ struct Preferences int maxNetworkCacheSize; bool clearNetworkCacheOnExit; bool removeInvalidIndexOnExit = false; + bool dictionaryDebug = false; qreal zoomFactor; qreal helpZoomFactor; diff --git a/src/dict/mdx.cc b/src/dict/mdx.cc index b1d23936..78ff80cd 100644 --- a/src/dict/mdx.cc +++ b/src/dict/mdx.cc @@ -756,7 +756,7 @@ void MddResourceRequest::run() hasAnyData = true; data.resize( bytes->size() ); memcpy( &data.front(), bytes->constData(), bytes->size() ); - GlobalBroadcaster::instance()->cache.insert( unique_key, bytes ); + GlobalBroadcaster::instance()->insertCache( unique_key, bytes ); break; } } @@ -790,7 +790,7 @@ void MddResourceRequest::run() data.resize( bytes.size() ); memcpy( &data.front(), bytes.constData(), bytes.size() ); //cache the processed css result to avoid process again. - GlobalBroadcaster::instance()->cache.insert( unique_key, new QByteArray( bytes ) ); + GlobalBroadcaster::instance()->insertCache( unique_key, new QByteArray( bytes ) ); } if ( Filetype::isNameOfTiff( u8ResourceName ) ) { // Convert it diff --git a/src/ui/preferences.cc b/src/ui/preferences.cc index 28c25716..69b8d694 100644 --- a/src/ui/preferences.cc +++ b/src/ui/preferences.cc @@ -347,6 +347,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): //Misc ui.removeInvalidIndexOnExit->setChecked( p.removeInvalidIndexOnExit ); + ui.dictionaryDebug->setChecked( p.dictionaryDebug ); // Add-on styles ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 ); @@ -509,6 +510,7 @@ Config::Preferences Preferences::getPreferences() p.clearNetworkCacheOnExit = ui.clearNetworkCacheOnExit->isChecked(); p.removeInvalidIndexOnExit = ui.removeInvalidIndexOnExit->isChecked(); + p.dictionaryDebug = ui.dictionaryDebug->isChecked(); p.addonStyle = ui.addonStyles->getCurrentStyle(); diff --git a/src/ui/preferences.ui b/src/ui/preferences.ui index 614e8fce..4bd93f43 100644 --- a/src/ui/preferences.ui +++ b/src/ui/preferences.ui @@ -1960,6 +1960,16 @@ from Stardict, Babylon and GLS dictionaries + + + + When debugging with dictionary css/js, disable certain cache to make it easier. + + + Dictionary debug + + +