[PATCH 2 of 2] (issue41) Add and use a UseProxy checkbox
Wald Commits
scm-commit at wald.intevation.org
Wed Sep 10 11:06:55 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1410340009 -7200
# Node ID 515345358b717bb441cc1a4dc697963f35cb9c78
# Parent db831a204a6b3d40d61ed49226e9404858da68d1
(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.
diff -r db831a204a6b -r 515345358b71 ui/downloader.cpp
--- 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
diff -r db831a204a6b -r 515345358b71 ui/proxysettingsdlg.cpp
--- 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();
}
diff -r db831a204a6b -r 515345358b71 ui/proxysettingsdlg.h
--- 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
More information about the Trustbridge-commits
mailing list