diff --git a/authentication.ui b/authentication.ui
new file mode 100644
index 00000000..9fcdca5d
--- /dev/null
+++ b/authentication.ui
@@ -0,0 +1,111 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 389
+ 120
+
+
+
+ Proxy authentication required
+
+
+ -
+
+
+ You need to supply a Username and a Password to access via proxy
+
+
+ false
+
+
+
+ -
+
+
+ Username:
+
+
+
+ -
+
+
+ -
+
+
+ Password:
+
+
+
+ -
+
+
+ QLineEdit::Password
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ Dialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ Dialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/config.cc b/config.cc
index cebcb7c2..d7600b96 100644
--- a/config.cc
+++ b/config.cc
@@ -722,6 +722,8 @@ Class load() throw( exError )
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.preferences.proxyServer.systemProxyUser = proxy.namedItem( "systemProxyUser" ).toElement().text();
+ c.preferences.proxyServer.systemProxyPassword = proxy.namedItem( "systemProxyPassword" ).toElement().text();
}
if ( !preferences.namedItem( "checkForNewReleases" ).isNull() )
@@ -1489,6 +1491,14 @@ void save( Class const & c ) throw( exError )
opt = dd.createElement( "password" );
opt.appendChild( dd.createTextNode( c.preferences.proxyServer.password ) );
proxy.appendChild( opt );
+
+ opt = dd.createElement( "systemProxyUser" );
+ opt.appendChild( dd.createTextNode( c.preferences.proxyServer.systemProxyUser ) );
+ proxy.appendChild( opt );
+
+ opt = dd.createElement( "systemProxyPassword" );
+ opt.appendChild( dd.createTextNode( c.preferences.proxyServer.systemProxyPassword ) );
+ proxy.appendChild( opt );
}
opt = dd.createElement( "checkForNewReleases" );
diff --git a/config.hh b/config.hh
index 9ea4801c..18dfd77e 100644
--- a/config.hh
+++ b/config.hh
@@ -128,6 +128,7 @@ struct ProxyServer
QString host;
unsigned port;
QString user, password;
+ QString systemProxyUser, systemProxyPassword;
ProxyServer();
};
diff --git a/goldendict.pro b/goldendict.pro
index a6dede39..0782b96b 100644
--- a/goldendict.pro
+++ b/goldendict.pro
@@ -297,7 +297,8 @@ FORMS += groups.ui \
editdictionaries.ui \
orderandprops.ui \
dictinfo.ui \
- dictheadwords.ui
+ dictheadwords.ui \
+ authentication.ui
SOURCES += folding.cc \
main.cc \
dictionary.cc \
diff --git a/mainwindow.cc b/mainwindow.cc
index 576307c6..ed2418a2 100644
--- a/mainwindow.cc
+++ b/mainwindow.cc
@@ -31,6 +31,7 @@
#include
#include
#include
+#include "ui_authentication.h"
#ifdef Q_OS_MAC
#include "lionsupport.h"
@@ -704,6 +705,12 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
applyProxySettings();
applyWebSettings();
+ connect( &dictNetMgr, SIGNAL( proxyAuthenticationRequired( QNetworkProxy, QAuthenticator * ) ),
+ this, SLOT( proxyAuthentication( QNetworkProxy, QAuthenticator * ) ) );
+
+ connect( &articleNetMgr, SIGNAL( proxyAuthenticationRequired( QNetworkProxy, QAuthenticator * ) ),
+ this, SLOT( proxyAuthentication( QNetworkProxy, QAuthenticator * ) ) );
+
makeDictionaries();
// After we have dictionaries and groups, we can populate history
@@ -1088,10 +1095,15 @@ void MainWindow::applyProxySettings()
{
if( cfg.preferences.proxyServer.enabled && cfg.preferences.proxyServer.useSystemProxy )
{
- QNetworkProxyFactory::setUseSystemConfiguration( true );
+ QList proxies = QNetworkProxyFactory::systemProxyForQuery();
+ if( !cfg.preferences.proxyServer.systemProxyUser.isEmpty() )
+ {
+ proxies.first().setUser( cfg.preferences.proxyServer.systemProxyUser );
+ proxies.first().setPassword( cfg.preferences.proxyServer.systemProxyPassword );
+ }
+ QNetworkProxy::setApplicationProxy( proxies.first() );
return;
}
- QNetworkProxyFactory::setUseSystemConfiguration( false );
QNetworkProxy::ProxyType type = QNetworkProxy::NoProxy;
@@ -1849,6 +1861,8 @@ void MainWindow::editPreferences()
#ifndef Q_WS_X11
p.trackClipboardChanges = cfg.preferences.trackClipboardChanges;
#endif
+ p.proxyServer.systemProxyUser = cfg.preferences.proxyServer.systemProxyUser;
+ p.proxyServer.systemProxyPassword = cfg.preferences.proxyServer.systemProxyPassword;
bool needReload = false;
@@ -3813,6 +3827,57 @@ void MainWindow::storeResourceSavePath( const QString & newPath )
cfg.resourceSavePath = newPath;
}
+void MainWindow::proxyAuthentication( const QNetworkProxy &,
+ QAuthenticator * authenticator )
+{
+ QNetworkProxy proxy = QNetworkProxy::applicationProxy();
+
+ QString * userStr, * passwordStr;
+ if( cfg.preferences.proxyServer.useSystemProxy )
+ {
+ userStr = &cfg.preferences.proxyServer.systemProxyUser;
+ passwordStr = &cfg.preferences.proxyServer.systemProxyPassword;
+ }
+ else
+ {
+ userStr = &cfg.preferences.proxyServer.user;
+ passwordStr = &cfg.preferences.proxyServer.password;
+ }
+
+ if( proxy.user().isEmpty() && !userStr->isEmpty() )
+ {
+ authenticator->setUser( *userStr );
+ authenticator->setPassword( *passwordStr );
+
+ proxy.setUser( *userStr );
+ proxy.setPassword( *passwordStr );
+ QNetworkProxy::setApplicationProxy( proxy );
+ }
+ else
+ {
+ QDialog dlg;
+ Ui::Dialog ui;
+ ui.setupUi( &dlg );
+ dlg.adjustSize();
+
+ ui.userEdit->setText( *userStr );
+ ui.passwordEdit->setText( *passwordStr );
+
+ if ( dlg.exec() == QDialog::Accepted )
+ {
+ *userStr = ui.userEdit->text();
+ *passwordStr = ui.passwordEdit->text();
+
+ authenticator->setUser( *userStr );
+ authenticator->setPassword( *passwordStr );
+
+ proxy.setUser( *userStr );
+ proxy.setPassword( *passwordStr );
+ QNetworkProxy::setApplicationProxy( proxy );
+ }
+ }
+}
+
#ifdef Q_OS_WIN32
bool MainWindow::handleGDMessage( MSG * message, long * result )
diff --git a/mainwindow.hh b/mainwindow.hh
index fbb41eb5..90682e15 100644
--- a/mainwindow.hh
+++ b/mainwindow.hh
@@ -410,6 +410,8 @@ private slots:
void focusHeadwordsDialog();
+ void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator );
+
signals:
/// Set optional parts expand mode for all tabs
void setExpandOptionalParts( bool expand );