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

View File

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

View File

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

View File

@ -42,7 +42,10 @@ GeneralForm::GeneralForm() :
bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr()); bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr());
int port = Settings::getInstance().getProxyPort(); int port = Settings::getInstance().getProxyPort();
if (port != -1) 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->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated); 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) // new syntax can't handle overloaded signals... (at least not in a pretty way)
connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated);
connect(bodyUI->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited); 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() GeneralForm::~GeneralForm()
@ -90,17 +94,21 @@ void GeneralForm::onProxyAddrEdited()
Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text()); Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
} }
void GeneralForm::onProxyPortEdited() void GeneralForm::onProxyPortEdited(int port)
{ {
QString text = bodyUI->proxyPort->text(); if (port > 0)
if (text != "")
{ {
int port = text.toInt(); Settings::getInstance().setProxyPort(port);
if (port < 1) } else {
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(-1); 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 onSmileyBrowserIndexChanged(int index);
void onUDPUpdated(); void onUDPUpdated();
void onProxyAddrEdited(); void onProxyAddrEdited();
void onProxyPortEdited(); void onProxyPortEdited(int port);
void onUseProxyUpdated();
private: private:
Ui::GeneralSettings *bodyUI; Ui::GeneralSettings *bodyUI;

View File

@ -15,13 +15,13 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin"> <property name="leftMargin">
<number>15</number> <number>6</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>15</number> <number>6</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>15</number> <number>6</number>
</property> </property>
<item> <item>
<widget class="QGroupBox" name="generalGroup"> <widget class="QGroupBox" name="generalGroup">
@ -29,13 +29,6 @@
<string>General Settings</string> <string>General Settings</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <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> <item>
<widget class="QCheckBox" name="cbUseTranslations"> <widget class="QCheckBox" name="cbUseTranslations">
<property name="text"> <property name="text">
@ -76,47 +69,62 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="proxyGroup"> <widget class="QGroupBox" name="connectionGroup">
<property name="title"> <property name="title">
<string>Proxy settings</string> <string>Connection Settings</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayoutProxy"> <layout class="QVBoxLayout" name="verticalLayoutProxy">
<item> <item>
<widget class="QCheckBox" name="cbUDPDisabled"> <widget class="QCheckBox" name="cbEnableIPv6">
<property name="text"> <property name="text">
<string extracomment="Text on checkbox to disable UDP">Disable UDP (not recommended)</string> <string extracomment="Text on a checkbox to enable IPv6">Enable IPv6 (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>
</property> </property>
</widget> </widget>
</item> </item>
<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> <item>
<widget class="QLabel" name="proxyAddrLabel"> <widget class="QLabel" name="proxyAddrLabel">
<property name="text"> <property name="text">
<string extracomment="Text on proxy addr label">Proxy address</string> <string extracomment="Text on proxy addr label">Address</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLineEdit" name="proxyAddr"/>
</item>
<item> <item>
<widget class="QLabel" name="proxyPortLabel"> <widget class="QLabel" name="proxyPortLabel">
<property name="text"> <property name="text">
<string extracomment="Text on proxy port label">Proxy port</string> <string extracomment="Text on proxy port label">Port</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayoutProxyBoxes">
<item> <item>
<widget class="QLineEdit" name="proxyAddr"> <widget class="QSpinBox" name="proxyPort">
</widget> <property name="minimum">
</item> <number>0</number>
<item> </property>
<widget class="QLineEdit" name="proxyPort"> <property name="maximum">
<number>65535</number>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>