mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ class ArticleNetworkAccessManager: public QNetworkAccessManager
|
|||
vector< sptr< Dictionary::Class > > const & dictionaries;
|
||||
ArticleMaker const & articleMaker;
|
||||
bool const & disallowContentFromOtherSites;
|
||||
bool const & hideGoldenDictHeader;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -25,10 +26,12 @@ public:
|
|||
vector< sptr< Dictionary::Class > > const &
|
||||
dictionaries_,
|
||||
ArticleMaker const & articleMaker_,
|
||||
bool const & disallowContentFromOtherSites_ ):
|
||||
bool const & disallowContentFromOtherSites_,
|
||||
bool const & hideGoldenDictHeader_ ):
|
||||
QNetworkAccessManager( parent ), dictionaries( dictionaries_ ),
|
||||
articleMaker( articleMaker_ ),
|
||||
disallowContentFromOtherSites( disallowContentFromOtherSites_ )
|
||||
disallowContentFromOtherSites( disallowContentFromOtherSites_ ),
|
||||
hideGoldenDictHeader( hideGoldenDictHeader_ )
|
||||
{}
|
||||
|
||||
/// Tries handling any kind of internal resources referenced by dictionaries.
|
||||
|
|
|
@ -115,6 +115,7 @@ Preferences::Preferences():
|
|||
checkForNewReleases( true ),
|
||||
disallowContentFromOtherSites( false ),
|
||||
enableWebPlugins( false ),
|
||||
hideGoldenDictHeader( false ),
|
||||
zoomFactor( 1 ),
|
||||
wordsZoomLevel( 0 ),
|
||||
maxStringsInHistory( 500 ),
|
||||
|
@ -707,6 +708,9 @@ Class load() throw( exError )
|
|||
if ( !preferences.namedItem( "enableWebPlugins" ).isNull() )
|
||||
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() )
|
||||
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" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "hideGoldenDictHeader" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.hideGoldenDictHeader ? "1" : "0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "maxStringsInHistory" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -196,6 +196,7 @@ struct Preferences
|
|||
bool checkForNewReleases;
|
||||
bool disallowContentFromOtherSites;
|
||||
bool enableWebPlugins;
|
||||
bool hideGoldenDictHeader;
|
||||
|
||||
qreal zoomFactor;
|
||||
int wordsZoomLevel;
|
||||
|
|
|
@ -71,7 +71,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle,
|
||||
cfg.preferences.addonStyle ),
|
||||
articleNetMgr( this, dictionaries, articleMaker,
|
||||
cfg.preferences.disallowContentFromOtherSites ),
|
||||
cfg.preferences.disallowContentFromOtherSites, cfg.preferences.hideGoldenDictHeader ),
|
||||
dictNetMgr( this ),
|
||||
wordFinder( this ),
|
||||
newReleaseCheckTimer( this ),
|
||||
|
|
|
@ -189,6 +189,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
|||
ui.checkForNewReleases->setChecked( p.checkForNewReleases );
|
||||
ui.disallowContentFromOtherSites->setChecked( p.disallowContentFromOtherSites );
|
||||
ui.enableWebPlugins->setChecked( p.enableWebPlugins );
|
||||
ui.hideGoldenDictHeader->setChecked( p.hideGoldenDictHeader );
|
||||
|
||||
// Add-on styles
|
||||
ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 );
|
||||
|
@ -270,6 +271,7 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.checkForNewReleases = ui.checkForNewReleases->isChecked();
|
||||
p.disallowContentFromOtherSites = ui.disallowContentFromOtherSites->isChecked();
|
||||
p.enableWebPlugins = ui.enableWebPlugins->isChecked();
|
||||
p.hideGoldenDictHeader = ui.hideGoldenDictHeader->isChecked();
|
||||
|
||||
p.addonStyle = ui.addonStyles->getCurrentStyle();
|
||||
|
||||
|
|
|
@ -996,6 +996,17 @@ Plugin must be installed for this option to work.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="verticalSpacer_10">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in a new issue