Mercurial > trustbridge
changeset 1062:515345358b71
(issue41) Add and use a UseProxy checkbox
Using proxy no longer depends on the proxyUrl beeing empty
but rather on the value of the checkbox.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 10 Sep 2014 11:06:49 +0200 |
parents | db831a204a6b |
children | 8a1071fee883 |
files | ui/downloader.cpp ui/proxysettingsdlg.cpp ui/proxysettingsdlg.h |
diffstat | 3 files changed, 28 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/downloader.cpp Wed Sep 10 11:05:34 2014 +0200 +++ b/ui/downloader.cpp Wed Sep 10 11:06:49 2014 +0200 @@ -74,13 +74,14 @@ /* Set up Proxy support. */ QSettings settings; QString settingsProxy = settings.value("ProxyURL").toString(); - if (settingsProxy.isEmpty()) { + bool useProxy = settings.value("UseProxy", false).toBool(); + if (useProxy && settingsProxy.isEmpty()) { QByteArray envProxy = qgetenv("http_proxy"); if (envProxy.size()) { settingsProxy = QString::fromLocal8Bit(envProxy); } } - if (!settingsProxy.isEmpty()) { + if (useProxy && !settingsProxy.isEmpty()) { mSSLConnection->setProxy(QUrl(settingsProxy)); } #else
--- a/ui/proxysettingsdlg.cpp Wed Sep 10 11:05:34 2014 +0200 +++ b/ui/proxysettingsdlg.cpp Wed Sep 10 11:06:49 2014 +0200 @@ -16,6 +16,7 @@ #include <QDebug> #include <QIcon> #include <QPixmap> +#include <QCheckBox> #include "proxysettingsdlg.h" @@ -36,7 +37,7 @@ QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") + " " + tr("The URL can follow the scheme:") + "<br/>" + - tr("<username>:<password>@<hostname>:<port>") + + tr("[<username>:<password>]@<hostname>[:<port>]") + "<br/></br/>"); explanation->setTextFormat(Qt::RichText); explanation->setWordWrap(true); @@ -44,9 +45,18 @@ iconTextLayout->addWidget(explanation); mainLayout->addLayout(iconTextLayout); + bool useProxy = settings.value("UseProxy", false).toBool(); + mCheckBox = new QCheckBox(tr("Use Proxy Server")); + mCheckBox->setTristate(false); + mCheckBox->setCheckState(useProxy ? Qt::Checked : Qt::Unchecked); + + mainLayout->addWidget(mCheckBox); + mProxyURL = new QLineEdit(settings.value("ProxyURL").toString()); QLabel *proxyLabel = new QLabel(tr("Proxy Server:")); proxyLabel->setBuddy(mProxyURL); + mProxyURL->setReadOnly(!useProxy); + mProxyURL->setEnabled(useProxy); labelLineLayout->addWidget(proxyLabel); labelLineLayout->addWidget(mProxyURL); @@ -61,6 +71,7 @@ connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save())); connect(mProxyURL, SIGNAL(textChanged(const QString &)), this, SLOT(checkCanSave(const QString&))); + connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkCanEdit(int))); mainLayout->addLayout(labelLineLayout); mainLayout->addLayout(okCancelLayout); @@ -69,12 +80,19 @@ } void ProxySettingsDlg::checkCanSave(const QString &val) { - mSaveButton->setEnabled(val.isEmpty() || QUrl(val).isValid()); + mSaveButton->setEnabled(mCheckBox->checkState() == Qt::Unchecked || + QUrl(val).isValid()); +} + +void ProxySettingsDlg::checkCanEdit(int state) { + mProxyURL->setReadOnly(state != Qt::Checked); + mProxyURL->setEnabled(state == Qt::Checked); } void ProxySettingsDlg::save() { QSettings settings; settings.setValue("ProxyURL", mProxyURL->text()); + settings.setValue("UseProxy", mCheckBox->checkState() == Qt::Checked); settings.sync(); accept(); }
--- a/ui/proxysettingsdlg.h Wed Sep 10 11:05:34 2014 +0200 +++ b/ui/proxysettingsdlg.h Wed Sep 10 11:06:49 2014 +0200 @@ -12,6 +12,7 @@ class QLineEdit; class QPushButton; +class QCheckBox; /** * @file proxysettingsdlg.h @@ -32,9 +33,13 @@ /** @brief save the contents of mProxyURL in the settings. */ void save(); + /** @brief make the URL editiable depending on UseProxy setting. */ + void checkCanEdit(int state); + private: QLineEdit *mProxyURL; QPushButton *mSaveButton; + QCheckBox *mCheckBox; }; #endif // PROXYSETTINGSDLG_H