mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Added an option to hide GoldenDict identification in the HTTP User-Agent headers (Issue #259).
A new preference in the "Network" tab is added: * Do not identify GoldenDict in HTTP headers.
This commit is contained in:
parent
ceb170ef43
commit
82e6648efc
|
@ -112,6 +112,14 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spoof User-Agent
|
||||||
|
if ( hideGoldenDictHeader && req.url().scheme().startsWith("http", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
QNetworkRequest newReq( req );
|
||||||
|
newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName(), ""));
|
||||||
|
return QNetworkAccessManager::createRequest( op, newReq, outgoingData );
|
||||||
|
}
|
||||||
|
|
||||||
return QNetworkAccessManager::createRequest( op, req, outgoingData );
|
return QNetworkAccessManager::createRequest( op, req, outgoingData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ class ArticleNetworkAccessManager: public QNetworkAccessManager
|
||||||
vector< sptr< Dictionary::Class > > const & dictionaries;
|
vector< sptr< Dictionary::Class > > const & dictionaries;
|
||||||
ArticleMaker const & articleMaker;
|
ArticleMaker const & articleMaker;
|
||||||
bool const & disallowContentFromOtherSites;
|
bool const & disallowContentFromOtherSites;
|
||||||
|
bool const & hideGoldenDictHeader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -25,10 +26,12 @@ public:
|
||||||
vector< sptr< Dictionary::Class > > const &
|
vector< sptr< Dictionary::Class > > const &
|
||||||
dictionaries_,
|
dictionaries_,
|
||||||
ArticleMaker const & articleMaker_,
|
ArticleMaker const & articleMaker_,
|
||||||
bool const & disallowContentFromOtherSites_ ):
|
bool const & disallowContentFromOtherSites_,
|
||||||
|
bool const & hideGoldenDictHeader_ ):
|
||||||
QNetworkAccessManager( parent ), dictionaries( dictionaries_ ),
|
QNetworkAccessManager( parent ), dictionaries( dictionaries_ ),
|
||||||
articleMaker( articleMaker_ ),
|
articleMaker( articleMaker_ ),
|
||||||
disallowContentFromOtherSites( disallowContentFromOtherSites_ )
|
disallowContentFromOtherSites( disallowContentFromOtherSites_ ),
|
||||||
|
hideGoldenDictHeader( hideGoldenDictHeader_ )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/// Tries handling any kind of internal resources referenced by dictionaries.
|
/// Tries handling any kind of internal resources referenced by dictionaries.
|
||||||
|
|
|
@ -115,6 +115,7 @@ Preferences::Preferences():
|
||||||
checkForNewReleases( true ),
|
checkForNewReleases( true ),
|
||||||
disallowContentFromOtherSites( false ),
|
disallowContentFromOtherSites( false ),
|
||||||
enableWebPlugins( false ),
|
enableWebPlugins( false ),
|
||||||
|
hideGoldenDictHeader( false ),
|
||||||
zoomFactor( 1 ),
|
zoomFactor( 1 ),
|
||||||
wordsZoomLevel( 0 ),
|
wordsZoomLevel( 0 ),
|
||||||
maxStringsInHistory( 500 ),
|
maxStringsInHistory( 500 ),
|
||||||
|
@ -707,6 +708,9 @@ Class load() throw( exError )
|
||||||
if ( !preferences.namedItem( "enableWebPlugins" ).isNull() )
|
if ( !preferences.namedItem( "enableWebPlugins" ).isNull() )
|
||||||
c.preferences.enableWebPlugins = ( preferences.namedItem( "enableWebPlugins" ).toElement().text() == "1" );
|
c.preferences.enableWebPlugins = ( preferences.namedItem( "enableWebPlugins" ).toElement().text() == "1" );
|
||||||
|
|
||||||
|
if ( !preferences.namedItem( "hideGoldenDictHeader" ).isNull() )
|
||||||
|
c.preferences.hideGoldenDictHeader = ( preferences.namedItem( "hideGoldenDictHeader" ).toElement().text() == "1" );
|
||||||
|
|
||||||
if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() )
|
if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() )
|
||||||
c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ;
|
c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ;
|
||||||
|
|
||||||
|
@ -1418,6 +1422,10 @@ void save( Class const & c ) throw( exError )
|
||||||
opt.appendChild( dd.createTextNode( c.preferences.enableWebPlugins ? "1" : "0" ) );
|
opt.appendChild( dd.createTextNode( c.preferences.enableWebPlugins ? "1" : "0" ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "hideGoldenDictHeader" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.preferences.hideGoldenDictHeader ? "1" : "0" ) );
|
||||||
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
opt = dd.createElement( "maxStringsInHistory" );
|
opt = dd.createElement( "maxStringsInHistory" );
|
||||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
|
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
|
@ -196,6 +196,7 @@ struct Preferences
|
||||||
bool checkForNewReleases;
|
bool checkForNewReleases;
|
||||||
bool disallowContentFromOtherSites;
|
bool disallowContentFromOtherSites;
|
||||||
bool enableWebPlugins;
|
bool enableWebPlugins;
|
||||||
|
bool hideGoldenDictHeader;
|
||||||
|
|
||||||
qreal zoomFactor;
|
qreal zoomFactor;
|
||||||
int wordsZoomLevel;
|
int wordsZoomLevel;
|
||||||
|
|
|
@ -71,7 +71,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle,
|
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle,
|
||||||
cfg.preferences.addonStyle ),
|
cfg.preferences.addonStyle ),
|
||||||
articleNetMgr( this, dictionaries, articleMaker,
|
articleNetMgr( this, dictionaries, articleMaker,
|
||||||
cfg.preferences.disallowContentFromOtherSites ),
|
cfg.preferences.disallowContentFromOtherSites, cfg.preferences.hideGoldenDictHeader ),
|
||||||
dictNetMgr( this ),
|
dictNetMgr( this ),
|
||||||
wordFinder( this ),
|
wordFinder( this ),
|
||||||
newReleaseCheckTimer( this ),
|
newReleaseCheckTimer( this ),
|
||||||
|
|
|
@ -189,6 +189,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
||||||
ui.checkForNewReleases->setChecked( p.checkForNewReleases );
|
ui.checkForNewReleases->setChecked( p.checkForNewReleases );
|
||||||
ui.disallowContentFromOtherSites->setChecked( p.disallowContentFromOtherSites );
|
ui.disallowContentFromOtherSites->setChecked( p.disallowContentFromOtherSites );
|
||||||
ui.enableWebPlugins->setChecked( p.enableWebPlugins );
|
ui.enableWebPlugins->setChecked( p.enableWebPlugins );
|
||||||
|
ui.hideGoldenDictHeader->setChecked( p.hideGoldenDictHeader );
|
||||||
|
|
||||||
// Add-on styles
|
// Add-on styles
|
||||||
ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 );
|
ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 );
|
||||||
|
@ -270,6 +271,7 @@ Config::Preferences Preferences::getPreferences()
|
||||||
p.checkForNewReleases = ui.checkForNewReleases->isChecked();
|
p.checkForNewReleases = ui.checkForNewReleases->isChecked();
|
||||||
p.disallowContentFromOtherSites = ui.disallowContentFromOtherSites->isChecked();
|
p.disallowContentFromOtherSites = ui.disallowContentFromOtherSites->isChecked();
|
||||||
p.enableWebPlugins = ui.enableWebPlugins->isChecked();
|
p.enableWebPlugins = ui.enableWebPlugins->isChecked();
|
||||||
|
p.hideGoldenDictHeader = ui.hideGoldenDictHeader->isChecked();
|
||||||
|
|
||||||
p.addonStyle = ui.addonStyles->getCurrentStyle();
|
p.addonStyle = ui.addonStyles->getCurrentStyle();
|
||||||
|
|
||||||
|
|
|
@ -996,6 +996,17 @@ Plugin must be installed for this option to work.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="hideGoldenDictHeader">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Some sites detect GoldenDict via HTTP headers and block the requests.
|
||||||
|
Enable this option to workaround the problem.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Do not identify GoldenDict in HTTP headers</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer_10">
|
<spacer name="verticalSpacer_10">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
Loading…
Reference in a new issue