andre@955: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik andre@955: * Software engineering by Intevation GmbH andre@955: * andre@955: * This file is Free Software under the GNU GPL (v>=2) andre@955: * and comes with ABSOLUTELY NO WARRANTY! andre@955: * See LICENSE.txt for details. andre@955: */ andre@955: andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@955: #include andre@1062: #include andre@955: andre@955: #include "proxysettingsdlg.h" andre@955: andre@955: ProxySettingsDlg::ProxySettingsDlg(QWidget *parent) : andre@955: QDialog (parent) { andre@955: setWindowIcon(QIcon(":/img/preferences-network_16.png")); andre@955: setWindowTitle(tr("Proxy server settings")); andre@955: QVBoxLayout *mainLayout = new QVBoxLayout(); andre@955: QHBoxLayout *iconTextLayout = new QHBoxLayout(); andre@955: QHBoxLayout *labelLineLayout = new QHBoxLayout(); andre@955: QHBoxLayout *okCancelLayout = new QHBoxLayout(); andre@955: andre@955: QSettings settings; andre@955: andre@955: QLabel *iconLabel = new QLabel(); andre@955: iconLabel->setPixmap(QPixmap(":/img/preferences-network_64.png")); andre@955: iconTextLayout->addWidget(iconLabel); andre@955: andre@955: QLabel *explanation = new QLabel(tr("Please enter the proxy server to use in the field below.") + emanuel@1009: " " + tr("The URL can follow the scheme:") + "
" + emanuel@1063: tr("[<username>:<password>@]<hostname>[:<port>]") + emanuel@1009: "

"); andre@955: explanation->setTextFormat(Qt::RichText); andre@955: explanation->setWordWrap(true); andre@955: andre@955: iconTextLayout->addWidget(explanation); andre@955: mainLayout->addLayout(iconTextLayout); andre@955: andre@1062: bool useProxy = settings.value("UseProxy", false).toBool(); andre@1062: mCheckBox = new QCheckBox(tr("Use Proxy Server")); andre@1062: mCheckBox->setTristate(false); andre@1062: mCheckBox->setCheckState(useProxy ? Qt::Checked : Qt::Unchecked); andre@1062: andre@1062: mainLayout->addWidget(mCheckBox); andre@1062: andre@955: mProxyURL = new QLineEdit(settings.value("ProxyURL").toString()); andre@955: QLabel *proxyLabel = new QLabel(tr("Proxy Server:")); andre@955: proxyLabel->setBuddy(mProxyURL); andre@1062: mProxyURL->setReadOnly(!useProxy); andre@1062: mProxyURL->setEnabled(useProxy); andre@955: andre@955: labelLineLayout->addWidget(proxyLabel); andre@955: labelLineLayout->addWidget(mProxyURL); andre@955: andre@955: mSaveButton = new QPushButton (tr("&Save")); andre@955: QPushButton * cancelButton = new QPushButton (tr("&Cancel")); andre@955: okCancelLayout->addStretch(10); andre@955: okCancelLayout->addWidget(mSaveButton); andre@955: okCancelLayout->addWidget(cancelButton); andre@955: andre@955: connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); andre@955: connect(mSaveButton, SIGNAL(clicked()), this, SLOT(save())); andre@955: connect(mProxyURL, SIGNAL(textChanged(const QString &)), andre@955: this, SLOT(checkCanSave(const QString&))); andre@1062: connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkCanEdit(int))); andre@955: andre@955: mainLayout->addLayout(labelLineLayout); andre@955: mainLayout->addLayout(okCancelLayout); andre@955: andre@955: setLayout(mainLayout); andre@955: } andre@955: andre@955: void ProxySettingsDlg::checkCanSave(const QString &val) { andre@1062: mSaveButton->setEnabled(mCheckBox->checkState() == Qt::Unchecked || andre@1062: QUrl(val).isValid()); andre@1062: } andre@1062: andre@1062: void ProxySettingsDlg::checkCanEdit(int state) { andre@1062: mProxyURL->setReadOnly(state != Qt::Checked); andre@1062: mProxyURL->setEnabled(state == Qt::Checked); andre@955: } andre@955: andre@955: void ProxySettingsDlg::save() { andre@955: QSettings settings; andre@955: settings.setValue("ProxyURL", mProxyURL->text()); andre@1062: settings.setValue("UseProxy", mCheckBox->checkState() == Qt::Checked); andre@955: settings.sync(); andre@955: accept(); andre@955: }