void Mirall::ProxyDialog::saveSettings() { Mirall::MirallConfigFile cfgFile; if (noProxyRadioButton->isChecked()) { cfgFile.setProxyType(QNetworkProxy::NoProxy); } if (systemProxyRadioButton->isChecked()) { cfgFile.setProxyType(QNetworkProxy::DefaultProxy); } if (manualProxyRadioButton->isChecked()) { if (authRequiredcheckBox->isChecked()) { QString user = userLineEdit->text(); QString pass = passwordLineEdit->text(); cfgFile.setProxyType(QNetworkProxy::Socks5Proxy, hostLineEdit->text(), portSpinBox->value(), user, pass); } else { cfgFile.setProxyType(QNetworkProxy::Socks5Proxy, hostLineEdit->text(), portSpinBox->value(), QString::null, QString::null); } } }
void ClientProxy::setupQtProxyFromConfig() { Mirall::MirallConfigFile cfg; int proxyType = QNetworkProxy::DefaultProxy; QNetworkProxy proxy; // if there is no config file, default to system proxy. if( cfg.exists() ) { proxyType = cfg.proxyType(); proxy = proxyFromConfig(cfg); } switch(proxyType) { case QNetworkProxy::NoProxy: QNetworkProxyFactory::setUseSystemConfiguration(false); QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); break; case QNetworkProxy::DefaultProxy: QNetworkProxyFactory::setUseSystemConfiguration(true); break; case QNetworkProxy::Socks5Proxy: proxy.setType(QNetworkProxy::Socks5Proxy); QNetworkProxyFactory::setUseSystemConfiguration(false); QNetworkProxy::setApplicationProxy(proxy); break; case QNetworkProxy::HttpProxy: proxy.setType(QNetworkProxy::HttpProxy); QNetworkProxyFactory::setUseSystemConfiguration(false); QNetworkProxy::setApplicationProxy(proxy); break; default: break; } }
Mirall::ProxyDialog::ProxyDialog( QWidget* parent ) : QDialog(parent) { setupUi(this); // designer is buggy, so do it programmatically manualSettings->setEnabled(false); #if QT_VERSION >= 0x040700 hostLineEdit->setPlaceholderText(tr("Hostname of proxy server")); userLineEdit->setPlaceholderText(tr("Username for proxy server")); passwordLineEdit->setPlaceholderText(tr("Password for proxy server")); #endif // load current proxy settings Mirall::MirallConfigFile cfgFile; if (cfgFile.proxyType() == QNetworkProxy::NoProxy) noProxyRadioButton->setChecked(true); if (cfgFile.proxyType() == QNetworkProxy::DefaultProxy) systemProxyRadioButton->setChecked(true); if (cfgFile.proxyType() == QNetworkProxy::Socks5Proxy) { manualProxyRadioButton->setChecked(true); hostLineEdit->setText(cfgFile.proxyHostName()); portSpinBox->setValue(cfgFile.proxyPort()); if (!cfgFile.proxyUser().isEmpty()) { authRequiredcheckBox->setChecked(true); userLineEdit->setText(cfgFile.proxyUser()); passwordLineEdit->setText(cfgFile.proxyPassword()); } } }
void NetworkSettings::loadProxySettings() { // load current proxy settings Mirall::MirallConfigFile cfgFile; int type = cfgFile.proxyType(); switch (type) { case QNetworkProxy::NoProxy: _ui->noProxyRadioButton->setChecked(true); break; case QNetworkProxy::DefaultProxy: _ui->systemProxyRadioButton->setChecked(true); break; case QNetworkProxy::Socks5Proxy: case QNetworkProxy::HttpProxy: _ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(type)); _ui->manualProxyRadioButton->setChecked(true); break; default: break; } _ui->hostLineEdit->setText(cfgFile.proxyHostName()); int port = cfgFile.proxyPort(); if (port == 0) port = 8080; _ui->portSpinBox->setValue(port); if (!cfgFile.proxyUser().isEmpty()) { _ui->authRequiredcheckBox->setChecked(true); _ui->userLineEdit->setText(cfgFile.proxyUser()); _ui->passwordLineEdit->setText(cfgFile.proxyPassword()); } }