mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
added "Use Proxy" checkbox
This commit is contained in:
parent
f0a825fd76
commit
ddf7a7edfd
46
core.cpp
46
core.cpp
|
@ -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);
|
||||
|
|
|
@ -141,6 +141,7 @@ void Settings::load()
|
|||
s.beginGroup("Privacy");
|
||||
typingNotification = s.value("typingNotification", 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();
|
||||
|
@ -242,6 +243,7 @@ void Settings::save(QString path)
|
|||
|
||||
s.beginGroup("Privacy");
|
||||
s.setValue("typingNotification", typingNotification);
|
||||
s.setValue("useProxy", useProxy);
|
||||
s.setValue("forceTCP", forceTCP);
|
||||
s.setValue("proxyAddr", proxyAddr);
|
||||
s.setValue("proxyPort", proxyPort);
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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">
|
||||
|
@ -83,40 +83,48 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayoutProxy">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbUDPDisabled">
|
||||
<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>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string extracomment="Text on checkbox to disable UDP">Disable UDP (not recommended)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayoutProxyLabel">
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user