Proxy settings: Also keep proxy user/pwd

make sure not to use it when the user
has asked us not to.

Simplify setupProxy()
This commit is contained in:
Daniel Molkentin 2013-05-29 12:56:23 +02:00
parent 7d1bd9da86
commit 94f8c39a9e
5 changed files with 38 additions and 30 deletions

View file

@ -538,42 +538,41 @@ void Application::setupLogBrowser()
}
QNetworkProxy proxyFromConfig(const MirallConfigFile& cfg)
{
QNetworkProxy proxy;
proxy.setHostName(cfg.proxyHostName());
proxy.setPort(cfg.proxyPort());
if (cfg.proxyNeedsAuth()) {
proxy.setUser(cfg.proxyUser());
proxy.setPassword(cfg.proxyPassword());
}
return proxy;
}
void Application::setupProxy()
{
//
Mirall::MirallConfigFile cfg;
int proxy = cfg.proxyType();
int proxyType = cfg.proxyType();
QNetworkProxy proxy = proxyFromConfig(cfg);
switch(proxy) {
case QNetworkProxy::NoProxy: {
switch(proxyType) {
case QNetworkProxy::NoProxy:
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
break;
}
case QNetworkProxy::DefaultProxy: {
return;
case QNetworkProxy::DefaultProxy:
QNetworkProxyFactory::setUseSystemConfiguration(true);
break;
}
case QNetworkProxy::Socks5Proxy: {
QNetworkProxy proxy;
return;
case QNetworkProxy::Socks5Proxy:
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(cfg.proxyHostName());
proxy.setPort(cfg.proxyPort());
proxy.setUser(cfg.proxyUser());
proxy.setPassword(cfg.proxyPassword());
QNetworkProxy::setApplicationProxy(proxy);
break;
}
case QNetworkProxy::HttpProxy:{
QNetworkProxy proxy;
return;
case QNetworkProxy::HttpProxy:
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(cfg.proxyHostName());
proxy.setPort(cfg.proxyPort());
proxy.setUser(cfg.proxyUser());
proxy.setPassword(cfg.proxyPassword());
QNetworkProxy::setApplicationProxy(proxy);
break;
}
return;
default:
return;
}
}

View file

@ -515,7 +515,7 @@ void MirallConfigFile::acceptCustomConfig()
void MirallConfigFile::setProxyType(int proxyType,
const QString& host,
int port,
int port, bool needsAuth,
const QString& user,
const QString& pass)
{
@ -529,6 +529,7 @@ void MirallConfigFile::setProxyType(int proxyType,
proxyType == QNetworkProxy::Socks5Proxy) {
settings.setValue(QLatin1String("host"), host);
settings.setValue(QLatin1String("port"), port);
settings.setValue(QLatin1String("needsAuth"), needsAuth);
settings.setValue(QLatin1String("user"), user);
settings.setValue(QLatin1String("pass"), pass.toUtf8().toBase64());
}
@ -559,6 +560,11 @@ int MirallConfigFile::proxyPort() const
return getValue(QLatin1String("port"), QLatin1String("proxy")).toInt();
}
bool MirallConfigFile::proxyNeedsAuth() const
{
return getValue(QLatin1String("needsAuth"), QLatin1String("proxy")).toInt();
}
QString MirallConfigFile::proxyUser() const
{
return getValue(QLatin1String("user"), QLatin1String("proxy")).toString();

View file

@ -89,13 +89,14 @@ public:
// proxy settings
void setProxyType(int proxyType,
const QString& host = QString(),
int port = 0,
int port = 0, bool needsAuth = false,
const QString& user = QString(),
const QString& pass = QString());
int proxyType() const;
QString proxyHostName() const;
int proxyPort() const;
bool proxyNeedsAuth() const;
QString proxyUser() const;
QString proxyPassword() const;

View file

@ -221,7 +221,7 @@ void OwncloudSetupWizard::testOwnCloudConnect()
MirallConfigFile prevCfg;
if( prevCfg.proxyType() != QNetworkProxy::DefaultProxy ) {
cfgFile.setProxyType( prevCfg.proxyType(), prevCfg.proxyHostName(), prevCfg.proxyPort(),
prevCfg.proxyUser(), prevCfg.proxyPassword() );
prevCfg.proxyNeedsAuth(), prevCfg.proxyUser(), prevCfg.proxyPassword() );
}
}

View file

@ -82,7 +82,9 @@ void Mirall::ProxyDialog::saveSettings()
QString user = userLineEdit->text();
QString pass = passwordLineEdit->text();
cfgFile.setProxyType(proxyType, hostLineEdit->text(),
portSpinBox->value(), user, pass);
portSpinBox->value(),
authRequiredcheckBox->isChecked(),
user, pass);
}
}