1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #392 from apprb/proxy

Proxy related set of patches
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-07 14:17:39 +02:00
commit 39fd7b8b25
6 changed files with 106 additions and 69 deletions

View File

@ -122,8 +122,9 @@ void Core::start()
// 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();
QString proxyAddr = Settings::getInstance().getProxyAddr();
int proxyPort = Settings::getInstance().getProxyPort();
bool useProxy = Settings::getInstance().getUseProxy();
if (enableIPv6)
qDebug() << "Core starting with IPv6 enabled";
else
@ -132,26 +133,29 @@ void Core::start()
Tox_Options toxOptions;
toxOptions.ipv6enabled = enableIPv6;
toxOptions.udp_disabled = forceTCP;
if (proxyAddr.length() > 255)
// No proxy by default
toxOptions.proxy_enabled = false;
toxOptions.proxy_address[0] = 0;
toxOptions.proxy_port = 0;
if (useProxy)
{
qWarning() << "Core: proxy address" << proxyAddr << "is too long";
toxOptions.proxy_enabled = false;
toxOptions.proxy_address[0] = 0;
toxOptions.proxy_port = 0;
}
else if (proxyAddr != "" && proxyPort > 0)
{
qDebug() << "Core: using proxy" << proxyAddr << ":" << proxyPort;
toxOptions.proxy_enabled = true;
uint16_t sz = CString::fromString(proxyAddr, (unsigned char*)toxOptions.proxy_address);
toxOptions.proxy_address[sz] = 0;
toxOptions.proxy_port = proxyPort;
}
else
{
toxOptions.proxy_enabled = false;
toxOptions.proxy_address[0] = 0;
toxOptions.proxy_port = 0;
QString proxyAddr = Settings::getInstance().getProxyAddr();
int proxyPort = Settings::getInstance().getProxyPort();
if (proxyAddr.length() > 255)
{
qWarning() << "Core: proxy address" << proxyAddr << "is too long";
}
else if (proxyAddr != "" && proxyPort > 0)
{
qDebug() << "Core: using proxy" << proxyAddr << ":" << proxyPort;
toxOptions.proxy_enabled = true;
uint16_t sz = CString::fromString(proxyAddr, (unsigned char*)toxOptions.proxy_address);
toxOptions.proxy_address[sz] = 0;
toxOptions.proxy_port = proxyPort;
}
}
tox = tox_new(&toxOptions);

View File

@ -110,6 +110,10 @@ void Settings::load()
enableIPv6 = s.value("enableIPv6", true).toBool();
useTranslations = s.value("useTranslations", true).toBool();
makeToxPortable = s.value("makeToxPortable", false).toBool();
forceTCP = s.value("forceTCP", false).toBool();
useProxy = s.value("useProxy", false).toBool();
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt();
s.endGroup();
s.beginGroup("Widgets");
@ -140,9 +144,6 @@ void Settings::load()
s.beginGroup("Privacy");
typingNotification = s.value("typingNotification", false).toBool();
forceTCP = s.value("forceTCP", false).toBool();
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt();
s.endGroup();
// try to set a smiley pack if none is selected
@ -212,6 +213,10 @@ void Settings::save(QString path)
s.setValue("enableIPv6", enableIPv6);
s.setValue("useTranslations",useTranslations);
s.setValue("makeToxPortable",makeToxPortable);
s.setValue("useProxy", useProxy);
s.setValue("forceTCP", forceTCP);
s.setValue("proxyAddr", proxyAddr);
s.setValue("proxyPort", proxyPort);
s.endGroup();
s.beginGroup("Widgets");
@ -242,9 +247,6 @@ void Settings::save(QString path)
s.beginGroup("Privacy");
s.setValue("typingNotification", typingNotification);
s.setValue("forceTCP", forceTCP);
s.setValue("proxyAddr", proxyAddr);
s.setValue("proxyPort", proxyPort);
s.endGroup();
}
@ -367,6 +369,15 @@ void Settings::setForceTCP(bool newValue)
forceTCP = newValue;
}
bool Settings::getUseProxy() const
{
return useProxy;
}
void Settings::setUseProxy(bool newValue)
{
useProxy = newValue;
}
QString Settings::getProxyAddr() const
{
return proxyAddr;

View File

@ -58,6 +58,9 @@ public:
QString getProxyAddr() const;
void setProxyAddr(const QString& newValue);
bool getUseProxy() const;
void setUseProxy(bool newValue);
int getProxyPort() const;
void setProxyPort(int newValue);
@ -164,6 +167,8 @@ private:
static bool makeToxPortable;
bool forceTCP;
bool useProxy;
QString proxyAddr;
int proxyPort;

View File

@ -42,7 +42,10 @@ GeneralForm::GeneralForm() :
bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr());
int port = Settings::getInstance().getProxyPort();
if (port != -1)
bodyUI->proxyPort->setText(QString::number(port));
bodyUI->proxyPort->setValue(port);
bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy());
onUseProxyUpdated();
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated);
@ -51,7 +54,8 @@ GeneralForm::GeneralForm() :
// new syntax can't handle overloaded signals... (at least not in a pretty way)
connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated);
connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited);
connect(bodyUI->proxyPort, &QLineEdit::editingFinished, this, &GeneralForm::onProxyPortEdited);
connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int)));
connect(bodyUI->cbUseProxy, &QCheckBox::stateChanged, this, &GeneralForm::onUseProxyUpdated);
}
GeneralForm::~GeneralForm()
@ -90,17 +94,21 @@ void GeneralForm::onProxyAddrEdited()
Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
}
void GeneralForm::onProxyPortEdited()
void GeneralForm::onProxyPortEdited(int port)
{
QString text = bodyUI->proxyPort->text();
if (text != "")
if (port > 0)
{
int port = text.toInt();
if (port < 1)
QMessageBox::warning(bodyUI->proxyPort, tr("Bad port", "title of bad port popup"), tr("The port you entered is invalid; please enter another.", "text of bad port popup"));
else
Settings::getInstance().setProxyPort(port);
}
else
Settings::getInstance().setProxyPort(port);
} else {
Settings::getInstance().setProxyPort(-1);
}
}
void GeneralForm::onUseProxyUpdated()
{
bool state = bodyUI->cbUseProxy->isChecked();
bodyUI->proxyAddr->setEnabled(state);
bodyUI->proxyPort->setEnabled(state);
Settings::getInstance().setUseProxy(state);
}

View File

@ -39,7 +39,8 @@ private slots:
void onSmileyBrowserIndexChanged(int index);
void onUDPUpdated();
void onProxyAddrEdited();
void onProxyPortEdited();
void onProxyPortEdited(int port);
void onUseProxyUpdated();
private:
Ui::GeneralSettings *bodyUI;

View File

@ -15,13 +15,13 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>15</number>
<number>6</number>
</property>
<property name="topMargin">
<number>15</number>
<number>6</number>
</property>
<property name="rightMargin">
<number>15</number>
<number>6</number>
</property>
<item>
<widget class="QGroupBox" name="generalGroup">
@ -29,13 +29,6 @@
<string>General Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="cbEnableIPv6">
<property name="text">
<string extracomment="Text on a checkbox to enable IPv6">Enable IPv6 (recommended)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbUseTranslations">
<property name="text">
@ -76,47 +69,62 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="proxyGroup">
<widget class="QGroupBox" name="connectionGroup">
<property name="title">
<string>Proxy settings</string>
<string>Connection Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayoutProxy">
<item>
<widget class="QCheckBox" name="cbUDPDisabled">
<widget class="QCheckBox" name="cbEnableIPv6">
<property name="text">
<string extracomment="Text on checkbox to disable UDP">Disable UDP (not recommended)</string>
</property>
<property name="toolTip">
<string extracomment="force tcp checkbox tooltip">This allows, e.g., toxing over Tor. It adds load to the Tox network however, so use only when necessary.</string>
<string extracomment="Text on a checkbox to enable IPv6">Enable IPv6 (recommended)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayoutProxyLabel">
<widget class="QCheckBox" name="cbUDPDisabled">
<property name="toolTip">
<string extracomment="force tcp checkbox tooltip">This allows, e.g., toxing over Tor. It adds load to the Tox network however, so use only when necessary.</string>
</property>
<property name="text">
<string extracomment="Text on checkbox to disable UDP">Disable UDP (not recommended)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbUseProxy">
<property name="text">
<string>Use proxy (SOCKS5)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="proxyLayout">
<item>
<widget class="QLabel" name="proxyAddrLabel">
<property name="text">
<string extracomment="Text on proxy addr label">Proxy address</string>
<string extracomment="Text on proxy addr label">Address</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyAddr"/>
</item>
<item>
<widget class="QLabel" name="proxyPortLabel">
<property name="text">
<string extracomment="Text on proxy port label">Proxy port</string>
<string extracomment="Text on proxy port label">Port</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayoutProxyBoxes">
<item>
<widget class="QLineEdit" name="proxyAddr">
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyPort">
<widget class="QSpinBox" name="proxyPort">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
</layout>