diff --git a/src/core.cpp b/src/core.cpp index 637436fb2..fa098e0e3 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -121,7 +121,7 @@ void Core::make_tox() // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options. bool enableIPv6 = Settings::getInstance().getEnableIPv6(); bool forceTCP = Settings::getInstance().getForceTCP(); - bool useProxy = Settings::getInstance().getUseProxy(); + ProxyType proxyType = Settings::getInstance().getProxyType(); if (enableIPv6) qDebug() << "Core starting with IPv6 enabled"; @@ -133,11 +133,11 @@ void Core::make_tox() toxOptions.udp_disabled = forceTCP; // No proxy by default - toxOptions.proxy_enabled = false; + toxOptions.proxy_type = TOX_PROXY_NONE; toxOptions.proxy_address[0] = 0; toxOptions.proxy_port = 0; - if (useProxy) + if (proxyType != ProxyType::ptNone) { QString proxyAddr = Settings::getInstance().getProxyAddr(); int proxyPort = Settings::getInstance().getProxyPort(); @@ -149,7 +149,11 @@ void Core::make_tox() else if (proxyAddr != "" && proxyPort > 0) { qDebug() << "Core: using proxy" << proxyAddr << ":" << proxyPort; - toxOptions.proxy_enabled = true; + // protection against changings in TOX_PROXY_TYPE enum + if (proxyType == ProxyType::ptSOCKS5) + toxOptions.proxy_type = TOX_PROXY_SOCKS5; + else if (proxyType == ProxyType::ptHTTP) + toxOptions.proxy_type = TOX_PROXY_HTTP; uint16_t sz = CString::fromString(proxyAddr, (unsigned char*)toxOptions.proxy_address); toxOptions.proxy_address[sz] = 0; toxOptions.proxy_port = proxyPort; @@ -165,7 +169,7 @@ void Core::make_tox() tox = tox_new(&toxOptions); if (tox == nullptr) { - if (toxOptions.proxy_enabled) + if (toxOptions.proxy_type != TOX_PROXY_NONE) { //QMessageBox::critical(Widget::getInstance(), tr("Proxy failure", "popup title"), //tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your " @@ -183,7 +187,7 @@ void Core::make_tox() else qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; } - else if (toxOptions.proxy_enabled) + else if (toxOptions.proxy_type != TOX_PROXY_NONE) { emit badProxy(); return; diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index ad2c9fbb3..1f0e8a0c8 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -130,7 +130,7 @@ void Settings::load() autostartInTray = s.value("autostartInTray", false).toBool(); closeToTray = s.value("closeToTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); - useProxy = s.value("useProxy", false).toBool(); + setProxyType(s.value("proxyType", static_cast(ProxyType::ptNone)).toInt()); proxyAddr = s.value("proxyAddr", "").toString(); proxyPort = s.value("proxyPort", 0).toInt(); currentProfile = s.value("currentProfile", "").toString(); @@ -282,7 +282,7 @@ void Settings::save(QString path, bool writeFriends) s.setValue("showSystemTray", showSystemTray); s.setValue("autostartInTray",autostartInTray); s.setValue("closeToTray", closeToTray); - s.setValue("useProxy", useProxy); + s.setValue("proxyType", static_cast(proxyType)); s.setValue("forceTCP", forceTCP); s.setValue("proxyAddr", proxyAddr); s.setValue("proxyPort", proxyPort); @@ -584,13 +584,17 @@ void Settings::setForceTCP(bool newValue) forceTCP = newValue; } -bool Settings::getUseProxy() const +ProxyType Settings::getProxyType() const { - return useProxy; + return proxyType; } -void Settings::setUseProxy(bool newValue) + +void Settings::setProxyType(int newValue) { - useProxy = newValue; + if (newValue >= 0 && newValue <= 2) + proxyType = static_cast(newValue); + else + proxyType = ProxyType::ptNone; } QString Settings::getProxyAddr() const diff --git a/src/misc/settings.h b/src/misc/settings.h index 64ff6009e..d05be0a03 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -24,6 +24,8 @@ struct ToxID; namespace Db { enum class syncType; } +enum ProxyType {ptNone, ptSOCKS5, ptHTTP}; + class Settings : public QObject { Q_OBJECT @@ -89,8 +91,8 @@ public: QString getProxyAddr() const; void setProxyAddr(const QString& newValue); - bool getUseProxy() const; - void setUseProxy(bool newValue); + ProxyType getProxyType() const; + void setProxyType(int newValue); int getProxyPort() const; void setProxyPort(int newValue); @@ -257,7 +259,7 @@ private: bool forceTCP; - bool useProxy; + ProxyType proxyType; QString proxyAddr; int proxyPort; diff --git a/src/widget/form/addfriendform.cpp b/src/widget/form/addfriendform.cpp index e0623efa7..efacf17e8 100644 --- a/src/widget/form/addfriendform.cpp +++ b/src/widget/form/addfriendform.cpp @@ -95,7 +95,7 @@ void AddFriendForm::onSendTriggered() this->toxId.clear(); this->message.clear(); } else { - if (Settings::getInstance().getUseProxy()) + if (Settings::getInstance().getProxyType() != ProxyType::ptNone) { QMessageBox::StandardButton btn = QMessageBox::warning(main, "qTox", tr("qTox needs to use the Tox DNS, but can't do it through a proxy.\n\ Ignore the proxy and connect to the Internet directly?"), QMessageBox::Ok|QMessageBox::No, QMessageBox::No); diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 64efcbdf5..cf5555a68 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -111,7 +111,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : if (port != -1) bodyUI->proxyPort->setValue(port); - bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy()); + bodyUI->proxyType->setCurrentIndex(static_cast(Settings::getInstance().getProxyType())); onUseProxyUpdated(); //general @@ -139,7 +139,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : //connection connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); connect(bodyUI->cbEnableUDP, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); - connect(bodyUI->cbUseProxy, &QCheckBox::stateChanged, this, &GeneralForm::onUseProxyUpdated); + connect(bodyUI->proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(onUseProxyUpdated())); connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited); connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int))); connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked); @@ -286,11 +286,11 @@ void GeneralForm::onProxyPortEdited(int port) void GeneralForm::onUseProxyUpdated() { - bool state = bodyUI->cbUseProxy->isChecked(); + int proxytype = bodyUI->proxyType->currentIndex(); - bodyUI->proxyAddr->setEnabled(state); - bodyUI->proxyPort->setEnabled(state); - Settings::getInstance().setUseProxy(state); + bodyUI->proxyAddr->setEnabled(proxytype); + bodyUI->proxyPort->setEnabled(proxytype); + Settings::getInstance().setProxyType(proxytype); } void GeneralForm::onReconnectClicked() diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index 47258e049..762b39447 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -38,12 +38,12 @@ 0 - 0 - 513 - 819 + -173 + 511 + 797 - + 9 @@ -216,6 +216,9 @@ Set to 0 to disable + + true + minutes @@ -225,9 +228,6 @@ 2147483647 - - true - @@ -294,6 +294,9 @@ + + QFormLayout::AllNonFixedFieldsGrow + 0 @@ -317,23 +320,6 @@ - - - - Style - - - - - - - - 0 - 0 - - - - @@ -391,6 +377,23 @@ + + + + Style + + + + + + + + 0 + 0 + + + + @@ -462,7 +465,7 @@ - + Connection Settings @@ -492,11 +495,40 @@ - - - Use proxy (SOCKS5) - - + + + + + Proxy type + + + + + + + + 0 + 0 + + + + + None + + + + + SOCKS5 + + + + + HTTP + + + + +