mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
feat: add an option to make debug dictionary easier (#1086)
* feat: add an option to make debug dictionary easier * fix: code smells * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
d310f2c55c
commit
6ba8b0c16b
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -403,6 +403,7 @@ struct Preferences
|
|||
int maxNetworkCacheSize;
|
||||
bool clearNetworkCacheOnExit;
|
||||
bool removeInvalidIndexOnExit = false;
|
||||
bool dictionaryDebug = false;
|
||||
|
||||
qreal zoomFactor;
|
||||
qreal helpZoomFactor;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -1960,6 +1960,16 @@ from Stardict, Babylon and GLS dictionaries</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="dictionaryDebug">
|
||||
<property name="toolTip">
|
||||
<string>When debugging with dictionary css/js, disable certain cache to make it easier.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dictionary debug</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue