Mercurial > trustbridge
comparison ui/proxysettingsdlg.cpp @ 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 | c1f32c87716a |
children | 8a1071fee883 |
comparison
equal
deleted
inserted
replaced
1061:db831a204a6b | 1062:515345358b71 |
---|---|
14 #include <QPushButton> | 14 #include <QPushButton> |
15 #include <QUrl> | 15 #include <QUrl> |
16 #include <QDebug> | 16 #include <QDebug> |
17 #include <QIcon> | 17 #include <QIcon> |
18 #include <QPixmap> | 18 #include <QPixmap> |
19 #include <QCheckBox> | |
19 | 20 |
20 #include "proxysettingsdlg.h" | 21 #include "proxysettingsdlg.h" |
21 | 22 |
22 ProxySettingsDlg::ProxySettingsDlg(QWidget *parent) : | 23 ProxySettingsDlg::ProxySettingsDlg(QWidget *parent) : |
23 QDialog (parent) { | 24 QDialog (parent) { |
34 iconLabel->setPixmap(QPixmap(":/img/preferences-network_64.png")); | 35 iconLabel->setPixmap(QPixmap(":/img/preferences-network_64.png")); |
35 iconTextLayout->addWidget(iconLabel); | 36 iconTextLayout->addWidget(iconLabel); |
36 | 37 |
37 QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") + | 38 QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") + |
38 " " + tr("The URL can follow the scheme:") + "<br/>" + | 39 " " + tr("The URL can follow the scheme:") + "<br/>" + |
39 tr("<username>:<password>@<hostname>:<port>") + | 40 tr("[<username>:<password>]@<hostname>[:<port>]") + |
40 "<br/></br/>"); | 41 "<br/></br/>"); |
41 explanation->setTextFormat(Qt::RichText); | 42 explanation->setTextFormat(Qt::RichText); |
42 explanation->setWordWrap(true); | 43 explanation->setWordWrap(true); |
43 | 44 |
44 iconTextLayout->addWidget(explanation); | 45 iconTextLayout->addWidget(explanation); |
45 mainLayout->addLayout(iconTextLayout); | 46 mainLayout->addLayout(iconTextLayout); |
46 | 47 |
48 bool useProxy = settings.value("UseProxy", false).toBool(); | |
49 mCheckBox = new QCheckBox(tr("Use Proxy Server")); | |
50 mCheckBox->setTristate(false); | |
51 mCheckBox->setCheckState(useProxy ? Qt::Checked : Qt::Unchecked); | |
52 | |
53 mainLayout->addWidget(mCheckBox); | |
54 | |
47 mProxyURL = new QLineEdit(settings.value("ProxyURL").toString()); | 55 mProxyURL = new QLineEdit(settings.value("ProxyURL").toString()); |
48 QLabel *proxyLabel = new QLabel(tr("Proxy Server:")); | 56 QLabel *proxyLabel = new QLabel(tr("Proxy Server:")); |
49 proxyLabel->setBuddy(mProxyURL); | 57 proxyLabel->setBuddy(mProxyURL); |
58 mProxyURL->setReadOnly(!useProxy); | |
59 mProxyURL->setEnabled(useProxy); | |
50 | 60 |
51 labelLineLayout->addWidget(proxyLabel); | 61 labelLineLayout->addWidget(proxyLabel); |
52 labelLineLayout->addWidget(mProxyURL); | 62 labelLineLayout->addWidget(mProxyURL); |
53 | 63 |
54 mSaveButton = new QPushButton (tr("&Save")); | 64 mSaveButton = new QPushButton (tr("&Save")); |
59 | 69 |
60 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); | 70 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
61 connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save())); | 71 connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save())); |
62 connect(mProxyURL, SIGNAL(textChanged(const QString &)), | 72 connect(mProxyURL, SIGNAL(textChanged(const QString &)), |
63 this, SLOT(checkCanSave(const QString&))); | 73 this, SLOT(checkCanSave(const QString&))); |
74 connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkCanEdit(int))); | |
64 | 75 |
65 mainLayout->addLayout(labelLineLayout); | 76 mainLayout->addLayout(labelLineLayout); |
66 mainLayout->addLayout(okCancelLayout); | 77 mainLayout->addLayout(okCancelLayout); |
67 | 78 |
68 setLayout(mainLayout); | 79 setLayout(mainLayout); |
69 } | 80 } |
70 | 81 |
71 void ProxySettingsDlg::checkCanSave(const QString &val) { | 82 void ProxySettingsDlg::checkCanSave(const QString &val) { |
72 mSaveButton->setEnabled(val.isEmpty() || QUrl(val).isValid()); | 83 mSaveButton->setEnabled(mCheckBox->checkState() == Qt::Unchecked || |
84 QUrl(val).isValid()); | |
85 } | |
86 | |
87 void ProxySettingsDlg::checkCanEdit(int state) { | |
88 mProxyURL->setReadOnly(state != Qt::Checked); | |
89 mProxyURL->setEnabled(state == Qt::Checked); | |
73 } | 90 } |
74 | 91 |
75 void ProxySettingsDlg::save() { | 92 void ProxySettingsDlg::save() { |
76 QSettings settings; | 93 QSettings settings; |
77 settings.setValue("ProxyURL", mProxyURL->text()); | 94 settings.setValue("ProxyURL", mProxyURL->text()); |
95 settings.setValue("UseProxy", mCheckBox->checkState() == Qt::Checked); | |
78 settings.sync(); | 96 settings.sync(); |
79 accept(); | 97 accept(); |
80 } | 98 } |