Add proxy authentication dialog

This commit is contained in:
Abs62 2014-04-03 18:21:02 +04:00
parent fe9998f2bf
commit 9623cbdd7a
6 changed files with 193 additions and 3 deletions

111
authentication.ui Normal file
View file

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>120</height>
</rect>
</property>
<property name="windowTitle">
<string>Proxy authentication required</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>You need to supply a Username and a Password to access via proxy</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="userEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="passwordEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -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" );

View file

@ -128,6 +128,7 @@ struct ProxyServer
QString host;
unsigned port;
QString user, password;
QString systemProxyUser, systemProxyPassword;
ProxyServer();
};

View file

@ -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 \

View file

@ -31,6 +31,7 @@
#include <QThreadPool>
#include <QSslConfiguration>
#include <QDesktopWidget>
#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<QNetworkProxy> 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 )

View file

@ -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 );