From 4d019fff1f21d110beb9c3bea34b775fb9760929 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Tue, 6 Nov 2018 00:09:28 -0500 Subject: [PATCH] feat(core,ui): add support for SOCKS5 proxies (fixes #893) --- src/libs/core/application.cpp | 13 +- src/libs/core/settings.h | 7 +- src/libs/ui/settingsdialog.cpp | 42 ++-- src/libs/ui/settingsdialog.ui | 383 +++++++++++++++------------------ 4 files changed, 207 insertions(+), 238 deletions(-) diff --git a/src/libs/core/application.cpp b/src/libs/core/application.cpp index 85c83e5ab..0c6621fb2 100644 --- a/src/libs/core/application.cpp +++ b/src/libs/core/application.cpp @@ -209,16 +209,21 @@ void Application::applySettings() // HTTP Proxy Settings switch (m_settings->proxyType) { - case Core::Settings::ProxyType::None: + case Settings::ProxyType::None: QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); break; - case Core::Settings::ProxyType::System: + case Settings::ProxyType::System: QNetworkProxyFactory::setUseSystemConfiguration(true); break; - case Core::Settings::ProxyType::UserDefined: { - QNetworkProxy proxy(QNetworkProxy::HttpProxy, m_settings->proxyHost, m_settings->proxyPort); + case Settings::ProxyType::Http: + case Settings::ProxyType::Socks5: { + const QNetworkProxy::ProxyType type = m_settings->proxyType == Settings::ProxyType::Socks5 + ? QNetworkProxy::Socks5Proxy + : QNetworkProxy::HttpProxy; + + QNetworkProxy proxy(type, m_settings->proxyHost, m_settings->proxyPort); if (m_settings->proxyAuthenticate) { proxy.setUser(m_settings->proxyUserName); proxy.setPassword(m_settings->proxyPassword); diff --git a/src/libs/core/settings.h b/src/libs/core/settings.h index 282b81398..c95a32bcf 100644 --- a/src/libs/core/settings.h +++ b/src/libs/core/settings.h @@ -85,9 +85,10 @@ class Settings : public QObject // Network enum ProxyType : unsigned int { - None, - System, - UserDefined + None = 0, + System = 1, + Http = 3, + Socks5 = 4 }; Q_ENUM(ProxyType) diff --git a/src/libs/ui/settingsdialog.cpp b/src/libs/ui/settingsdialog.cpp index d7eb73a65..284d2f9e0 100644 --- a/src/libs/ui/settingsdialog.cpp +++ b/src/libs/ui/settingsdialog.cpp @@ -224,16 +224,21 @@ void SettingsDialog::loadSettings() case Core::Settings::ProxyType::System: ui->systemProxySettings->setChecked(true); break; - case Core::Settings::ProxyType::UserDefined: + case Core::Settings::ProxyType::Http: ui->manualProxySettings->setChecked(true); + ui->proxyTypeHttpRadioButton->setChecked(true); + break; + case Core::Settings::ProxyType::Socks5: + ui->manualProxySettings->setChecked(true); + ui->proxyTypeSocks5RadioButton->setChecked(true); break; } - ui->httpProxy->setText(settings->proxyHost); - ui->httpProxyPort->setValue(settings->proxyPort); - ui->httpProxyNeedsAuth->setChecked(settings->proxyAuthenticate); - ui->httpProxyUser->setText(settings->proxyUserName); - ui->httpProxyPass->setText(settings->proxyPassword); + ui->proxyHostEdit->setText(settings->proxyHost); + ui->proxyPortEdit->setValue(settings->proxyPort); + ui->proxyRequiresAuthCheckBox->setChecked(settings->proxyAuthenticate); + ui->proxyUsernameEdit->setText(settings->proxyUserName); + ui->proxyPasswordEdit->setText(settings->proxyPassword); } void SettingsDialog::saveSettings() @@ -285,18 +290,23 @@ void SettingsDialog::saveSettings() // Network Tab // Proxy settings - if (ui->noProxySettings->isChecked()) + if (ui->noProxySettings->isChecked()) { settings->proxyType = Core::Settings::ProxyType::None; - else if (ui->systemProxySettings->isChecked()) + } else if (ui->systemProxySettings->isChecked()) { settings->proxyType = Core::Settings::ProxyType::System; - else if (ui->manualProxySettings->isChecked()) - settings->proxyType = Core::Settings::ProxyType::UserDefined; - - settings->proxyHost = ui->httpProxy->text(); - settings->proxyPort = ui->httpProxyPort->text().toUShort(); - settings->proxyAuthenticate = ui->httpProxyNeedsAuth->isChecked(); - settings->proxyUserName = ui->httpProxyUser->text(); - settings->proxyPassword = ui->httpProxyPass->text(); + } else if (ui->manualProxySettings->isChecked()) { + if (ui->proxyTypeSocks5RadioButton->isChecked()) { + settings->proxyType = Core::Settings::ProxyType::Socks5; + } else { + settings->proxyType = Core::Settings::ProxyType::Http; + } + } + + settings->proxyHost = ui->proxyHostEdit->text(); + settings->proxyPort = ui->proxyPortEdit->text().toUShort(); + settings->proxyAuthenticate = ui->proxyRequiresAuthCheckBox->isChecked(); + settings->proxyUserName = ui->proxyUsernameEdit->text(); + settings->proxyPassword = ui->proxyPasswordEdit->text(); settings->save(); } diff --git a/src/libs/ui/settingsdialog.ui b/src/libs/ui/settingsdialog.ui index b7e443151..e168e9f4a 100644 --- a/src/libs/ui/settingsdialog.ui +++ b/src/libs/ui/settingsdialog.ui @@ -535,7 +535,7 @@ - HTTP Proxy + Proxy Settings @@ -554,7 +554,7 @@ true - System proxy settings + Use system proxy settings true @@ -569,114 +569,144 @@ - - - - - - - false - - - HTTP proxy: - - - - - - - false - - - - - - - false - - - Port: - - - - - - - false - - - 65535 - - - - - - - - - false - - - HTTP proxy requires authentication - - - - - - - false - - - - 0 + + + false + + + + + + Proxy host: - - 0 + + proxyHostEdit - - 0 + + + + + + Type: - - - - false - + + + + + + - Username: + HTTP + + true + + + proxyTypeButtonGroup + - - - - false + + + + SOCKS5 + + proxyTypeButtonGroup + - - - - false + + + + Qt::Horizontal + + + 40 + 20 + + + + + + + + + + + + + - Password: + Port: + + + proxyPortEdit - - - - false - - - QLineEdit::Password + + + + 65535 - - - + + + + + Authentication required + + + + + + + false + + + Username: + + + proxyUsernameEdit + + + + + + + false + + + Password: + + + proxyPasswordEdit + + + + + + + false + + + + + + + false + + + QLineEdit::Password + + + + + @@ -749,196 +779,119 @@ - manualProxySettings - toggled(bool) - httpProxyLabel - setEnabled(bool) - - - 104 - 74 - - - 121 - 97 - - - - - manualProxySettings - toggled(bool) - httpProxyPortLabel - setEnabled(bool) - - - 349 - 78 - - - 347 - 96 - - - - - manualProxySettings - toggled(bool) - httpProxy - setEnabled(bool) + customCssFileBrowseButton + clicked() + Zeal::WidgetUi::SettingsDialog + chooseCustomCssFile() - 232 - 77 + 526 + 232 - 232 - 97 + 299 + 249 - manualProxySettings - toggled(bool) - httpProxyPort - setEnabled(bool) + docsetStorageBrowseButton + clicked() + Zeal::WidgetUi::SettingsDialog + chooseDocsetStoragePath() - 392 - 74 + 526 + 371 - 392 - 96 + 299 + 249 manualProxySettings toggled(bool) - httpProxyNeedsAuth - setEnabled(bool) - - - 53 - 75 - - - 100 - 129 - - - - - httpProxyNeedsAuth - toggled(bool) - httpProxyPass + manualProxySettingsGroup setEnabled(bool) - 287 - 134 + 299 + 131 - 285 - 182 + 299 + 222 - httpProxyNeedsAuth + proxyRequiresAuthCheckBox toggled(bool) - httpProxyUser + proxyUsernameLabel setEnabled(bool) - 183 - 135 + 299 + 224 - 182 - 154 + 66 + 250 - manualProxySettings + proxyRequiresAuthCheckBox toggled(bool) - httpAuthWidget + proxyUsernameEdit setEnabled(bool) - 54 - 79 + 299 + 224 - 53 - 179 + 330 + 250 - httpProxyNeedsAuth + proxyRequiresAuthCheckBox toggled(bool) - httpProxyUserLabel + proxyPasswordLabel setEnabled(bool) - 81 - 134 + 299 + 224 - 70 - 154 + 65 + 278 - httpProxyNeedsAuth + proxyRequiresAuthCheckBox toggled(bool) - httpProxyPassLabel + proxyPasswordEdit setEnabled(bool) - 87 - 137 - - - 84 - 186 - - - - - customCssFileBrowseButton - clicked() - Zeal::WidgetUi::SettingsDialog - chooseCustomCssFile() - - - 526 - 232 - - 299 - 249 - - - - - docsetStorageBrowseButton - clicked() - Zeal::WidgetUi::SettingsDialog - chooseDocsetStoragePath() - - - 526 - 371 + 224 - 299 - 249 + 330 + 278 + + +