mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
+ Proxy server configuration is now supported.
This commit is contained in:
parent
3bbae73093
commit
2fbb7d9895
|
@ -36,6 +36,10 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
ProxyServer::ProxyServer(): enabled( false ), type( Socks5 ), port( 3128 )
|
||||
{
|
||||
}
|
||||
|
||||
Preferences::Preferences():
|
||||
enableTrayIcon( true ),
|
||||
startToTray( false ),
|
||||
|
@ -186,7 +190,19 @@ Class load() throw( exError )
|
|||
c.preferences.enableScanPopup = ( preferences.namedItem( "enableScanPopup" ).toElement().text() == "1" );
|
||||
c.preferences.startWithScanPopupOn = ( preferences.namedItem( "startWithScanPopupOn" ).toElement().text() == "1" );
|
||||
c.preferences.enableScanPopupModifiers = ( preferences.namedItem( "enableScanPopupModifiers" ).toElement().text() == "1" );
|
||||
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
|
||||
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
|
||||
|
||||
QDomNode proxy = preferences.namedItem( "proxyserver" );
|
||||
|
||||
if ( !proxy.isNull() )
|
||||
{
|
||||
c.preferences.proxyServer.enabled = ( proxy.toElement().attribute( "enabled" ) == "1" );
|
||||
c.preferences.proxyServer.type = ( ProxyServer::Type ) proxy.namedItem( "type" ).toElement().text().toULong();
|
||||
c.preferences.proxyServer.host = proxy.namedItem( "host" ).toElement().text();
|
||||
c.preferences.proxyServer.port = proxy.namedItem( "port" ).toElement().text().toULong();
|
||||
c.preferences.proxyServer.user = proxy.namedItem( "user" ).toElement().text();
|
||||
c.preferences.proxyServer.password = proxy.namedItem( "password" ).toElement().text();
|
||||
}
|
||||
}
|
||||
|
||||
c.lastMainGroup = root.namedItem( "lastMainGroup" ).toElement().text();
|
||||
|
@ -336,6 +352,35 @@ void save( Class const & c ) throw( exError )
|
|||
opt = dd.createElement( "scanPopupModifiers" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.scanPopupModifiers ) ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
{
|
||||
QDomElement proxy = dd.createElement( "proxyserver" );
|
||||
preferences.appendChild( proxy );
|
||||
|
||||
QDomAttr enabled = dd.createAttribute( "enabled" );
|
||||
enabled.setValue( c.preferences.proxyServer.enabled ? "1" : "0" );
|
||||
proxy.setAttributeNode( enabled );
|
||||
|
||||
opt = dd.createElement( "type" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.proxyServer.type ) ) );
|
||||
proxy.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "host" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.proxyServer.host ) );
|
||||
proxy.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "port" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.proxyServer.port ) ) );
|
||||
proxy.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "user" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.proxyServer.user ) );
|
||||
proxy.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "password" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.proxyServer.password ) );
|
||||
proxy.appendChild( opt );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -50,6 +50,25 @@ struct Group
|
|||
/// All the groups
|
||||
typedef vector< Group > Groups;
|
||||
|
||||
/// Proxy server configuration
|
||||
struct ProxyServer
|
||||
{
|
||||
bool enabled;
|
||||
|
||||
enum Type
|
||||
{
|
||||
Socks5 = 0,
|
||||
HttpConnect,
|
||||
HttpGet
|
||||
} type;
|
||||
|
||||
QString host;
|
||||
unsigned port;
|
||||
QString user, password;
|
||||
|
||||
ProxyServer();
|
||||
};
|
||||
|
||||
/// Various user preferences
|
||||
struct Preferences
|
||||
{
|
||||
|
@ -61,6 +80,8 @@ struct Preferences
|
|||
bool enableScanPopupModifiers;
|
||||
unsigned long scanPopupModifiers; // Combination of KeyboardState::Modifier
|
||||
|
||||
ProxyServer proxyServer;
|
||||
|
||||
Preferences();
|
||||
};
|
||||
|
||||
|
|
|
@ -130,6 +130,8 @@ MainWindow::MainWindow():
|
|||
ui.translateLine->installEventFilter( this );
|
||||
ui.wordList->installEventFilter( this );
|
||||
|
||||
applyProxySettings();
|
||||
|
||||
makeDictionaries();
|
||||
|
||||
addNewTab();
|
||||
|
@ -276,6 +278,42 @@ void MainWindow::closeEvent( QCloseEvent * ev )
|
|||
ev->accept();
|
||||
}
|
||||
|
||||
void MainWindow::applyProxySettings()
|
||||
{
|
||||
QNetworkProxy proxy;
|
||||
|
||||
if ( cfg.preferences.proxyServer.enabled )
|
||||
{
|
||||
switch( cfg.preferences.proxyServer.type )
|
||||
{
|
||||
case Config::ProxyServer::Socks5:
|
||||
proxy.setType( QNetworkProxy::Socks5Proxy );
|
||||
break;
|
||||
case Config::ProxyServer::HttpConnect:
|
||||
proxy.setType( QNetworkProxy::HttpProxy );
|
||||
break;
|
||||
case Config::ProxyServer::HttpGet:
|
||||
proxy.setType( QNetworkProxy::HttpCachingProxy );
|
||||
break;
|
||||
default:
|
||||
proxy.setType( QNetworkProxy::NoProxy );
|
||||
}
|
||||
|
||||
proxy.setHostName( cfg.preferences.proxyServer.host );
|
||||
proxy.setPort( cfg.preferences.proxyServer.port );
|
||||
|
||||
if ( cfg.preferences.proxyServer.user.size() )
|
||||
proxy.setUser( cfg.preferences.proxyServer.user );
|
||||
|
||||
if ( cfg.preferences.proxyServer.password.size() )
|
||||
proxy.setPassword( cfg.preferences.proxyServer.password );
|
||||
}
|
||||
else
|
||||
proxy.setType( QNetworkProxy::NoProxy );
|
||||
|
||||
QNetworkProxy::setApplicationProxy( proxy );
|
||||
}
|
||||
|
||||
void MainWindow::makeDictionaries()
|
||||
{
|
||||
scanPopup.reset();
|
||||
|
@ -559,6 +597,7 @@ void MainWindow::editPreferences()
|
|||
enableScanPopup->setChecked( false );
|
||||
|
||||
updateTrayIcon();
|
||||
applyProxySettings();
|
||||
makeScanPopup();
|
||||
Config::save( cfg );
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ private:
|
|||
|
||||
void closeEvent( QCloseEvent * );
|
||||
|
||||
void applyProxySettings();
|
||||
void makeDictionaries();
|
||||
void updateStatusLine();
|
||||
void updateGroupList();
|
||||
|
|
|
@ -64,6 +64,22 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
|
|||
ui.leftShift->hide();
|
||||
ui.rightShift->hide();
|
||||
#endif
|
||||
|
||||
// Proxy server
|
||||
|
||||
ui.useProxyServer->setChecked( p.proxyServer.enabled );
|
||||
|
||||
ui.proxyType->addItem( "SOCKS5" );
|
||||
ui.proxyType->addItem( "HTTP Transp." );
|
||||
ui.proxyType->addItem( "HTTP Caching" );
|
||||
|
||||
ui.proxyType->setCurrentIndex( p.proxyServer.type );
|
||||
|
||||
ui.proxyHost->setText( p.proxyServer.host );
|
||||
ui.proxyPort->setValue( p.proxyServer.port );
|
||||
|
||||
ui.proxyUser->setText( p.proxyServer.user );
|
||||
ui.proxyPassword->setText( p.proxyServer.password );
|
||||
}
|
||||
|
||||
Config::Preferences Preferences::getPreferences()
|
||||
|
@ -88,6 +104,16 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.scanPopupModifiers += ui.leftShift->isChecked() ? KeyboardState::LeftShift: 0;
|
||||
p.scanPopupModifiers += ui.rightShift->isChecked() ? KeyboardState::RightShift: 0;
|
||||
|
||||
p.proxyServer.enabled = ui.useProxyServer->isChecked();
|
||||
|
||||
p.proxyServer.type = ( Config::ProxyServer::Type ) ui.proxyType->currentIndex();
|
||||
|
||||
p.proxyServer.host = ui.proxyHost->text();
|
||||
p.proxyServer.port = ( unsigned ) ui.proxyPort->value();
|
||||
|
||||
p.proxyServer.user = ui.proxyUser->text();
|
||||
p.proxyServer.password = ui.proxyPassword->text();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>331</height>
|
||||
<height>392</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -264,6 +264,94 @@ in the pressed state when the word selection changes.</string>
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="useProxyServer">
|
||||
<property name="toolTip">
|
||||
<string>Enable if you wish to use a proxy server
|
||||
for all program's network requests.</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Use proxy server</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="proxyType"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Host:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="proxyHost"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="proxyPort">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>8080</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>User:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="proxyUser"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Password:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="proxyPassword">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in a new issue