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

Merge branch 'pr965'

This commit is contained in:
Dubslow 2014-12-31 00:50:03 -06:00
commit 75331af311
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
6 changed files with 94 additions and 52 deletions

View File

@ -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. // 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();
bool useProxy = Settings::getInstance().getUseProxy(); ProxyType proxyType = Settings::getInstance().getProxyType();
if (enableIPv6) if (enableIPv6)
qDebug() << "Core starting with IPv6 enabled"; qDebug() << "Core starting with IPv6 enabled";
@ -133,11 +133,11 @@ void Core::make_tox()
toxOptions.udp_disabled = forceTCP; toxOptions.udp_disabled = forceTCP;
// No proxy by default // No proxy by default
toxOptions.proxy_enabled = false; toxOptions.proxy_type = TOX_PROXY_NONE;
toxOptions.proxy_address[0] = 0; toxOptions.proxy_address[0] = 0;
toxOptions.proxy_port = 0; toxOptions.proxy_port = 0;
if (useProxy) if (proxyType != ProxyType::ptNone)
{ {
QString proxyAddr = Settings::getInstance().getProxyAddr(); QString proxyAddr = Settings::getInstance().getProxyAddr();
int proxyPort = Settings::getInstance().getProxyPort(); int proxyPort = Settings::getInstance().getProxyPort();
@ -149,7 +149,11 @@ void Core::make_tox()
else if (proxyAddr != "" && proxyPort > 0) else if (proxyAddr != "" && proxyPort > 0)
{ {
qDebug() << "Core: using proxy" << proxyAddr << ":" << proxyPort; 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); uint16_t sz = CString::fromString(proxyAddr, (unsigned char*)toxOptions.proxy_address);
toxOptions.proxy_address[sz] = 0; toxOptions.proxy_address[sz] = 0;
toxOptions.proxy_port = proxyPort; toxOptions.proxy_port = proxyPort;
@ -165,7 +169,7 @@ void Core::make_tox()
tox = tox_new(&toxOptions); tox = tox_new(&toxOptions);
if (tox == nullptr) if (tox == nullptr)
{ {
if (toxOptions.proxy_enabled) if (toxOptions.proxy_type != TOX_PROXY_NONE)
{ {
//QMessageBox::critical(Widget::getInstance(), tr("Proxy failure", "popup title"), //QMessageBox::critical(Widget::getInstance(), tr("Proxy failure", "popup title"),
//tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your " //tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your "
@ -183,7 +187,7 @@ void Core::make_tox()
else else
qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; 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(); emit badProxy();
return; return;

View File

@ -130,7 +130,7 @@ void Settings::load()
autostartInTray = s.value("autostartInTray", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool();
closeToTray = s.value("closeToTray", false).toBool(); closeToTray = s.value("closeToTray", false).toBool();
forceTCP = s.value("forceTCP", false).toBool(); forceTCP = s.value("forceTCP", false).toBool();
useProxy = s.value("useProxy", false).toBool(); setProxyType(s.value("proxyType", static_cast<int>(ProxyType::ptNone)).toInt());
proxyAddr = s.value("proxyAddr", "").toString(); proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt(); proxyPort = s.value("proxyPort", 0).toInt();
currentProfile = s.value("currentProfile", "").toString(); currentProfile = s.value("currentProfile", "").toString();
@ -282,7 +282,7 @@ void Settings::save(QString path, bool writeFriends)
s.setValue("showSystemTray", showSystemTray); s.setValue("showSystemTray", showSystemTray);
s.setValue("autostartInTray",autostartInTray); s.setValue("autostartInTray",autostartInTray);
s.setValue("closeToTray", closeToTray); s.setValue("closeToTray", closeToTray);
s.setValue("useProxy", useProxy); s.setValue("proxyType", static_cast<int>(proxyType));
s.setValue("forceTCP", forceTCP); s.setValue("forceTCP", forceTCP);
s.setValue("proxyAddr", proxyAddr); s.setValue("proxyAddr", proxyAddr);
s.setValue("proxyPort", proxyPort); s.setValue("proxyPort", proxyPort);
@ -584,13 +584,17 @@ void Settings::setForceTCP(bool newValue)
forceTCP = 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<ProxyType>(newValue);
else
proxyType = ProxyType::ptNone;
} }
QString Settings::getProxyAddr() const QString Settings::getProxyAddr() const

View File

@ -24,6 +24,8 @@
struct ToxID; struct ToxID;
namespace Db { enum class syncType; } namespace Db { enum class syncType; }
enum ProxyType {ptNone, ptSOCKS5, ptHTTP};
class Settings : public QObject class Settings : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -89,8 +91,8 @@ public:
QString getProxyAddr() const; QString getProxyAddr() const;
void setProxyAddr(const QString& newValue); void setProxyAddr(const QString& newValue);
bool getUseProxy() const; ProxyType getProxyType() const;
void setUseProxy(bool newValue); void setProxyType(int newValue);
int getProxyPort() const; int getProxyPort() const;
void setProxyPort(int newValue); void setProxyPort(int newValue);
@ -257,7 +259,7 @@ private:
bool forceTCP; bool forceTCP;
bool useProxy; ProxyType proxyType;
QString proxyAddr; QString proxyAddr;
int proxyPort; int proxyPort;

View File

@ -95,7 +95,7 @@ void AddFriendForm::onSendTriggered()
this->toxId.clear(); this->toxId.clear();
this->message.clear(); this->message.clear();
} else { } 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\ 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); Ignore the proxy and connect to the Internet directly?"), QMessageBox::Ok|QMessageBox::No, QMessageBox::No);

View File

@ -111,7 +111,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
if (port != -1) if (port != -1)
bodyUI->proxyPort->setValue(port); bodyUI->proxyPort->setValue(port);
bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy()); bodyUI->proxyType->setCurrentIndex(static_cast<int>(Settings::getInstance().getProxyType()));
onUseProxyUpdated(); onUseProxyUpdated();
//general //general
@ -139,7 +139,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
//connection //connection
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
connect(bodyUI->cbEnableUDP, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); 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->proxyAddr, &QLineEdit::editingFinished, this, &GeneralForm::onProxyAddrEdited);
connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int))); connect(bodyUI->proxyPort, SIGNAL(valueChanged(int)), this, SLOT(onProxyPortEdited(int)));
connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked); connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked);
@ -286,11 +286,11 @@ void GeneralForm::onProxyPortEdited(int port)
void GeneralForm::onUseProxyUpdated() void GeneralForm::onUseProxyUpdated()
{ {
bool state = bodyUI->cbUseProxy->isChecked(); int proxytype = bodyUI->proxyType->currentIndex();
bodyUI->proxyAddr->setEnabled(state); bodyUI->proxyAddr->setEnabled(proxytype);
bodyUI->proxyPort->setEnabled(state); bodyUI->proxyPort->setEnabled(proxytype);
Settings::getInstance().setUseProxy(state); Settings::getInstance().setProxyType(proxytype);
} }
void GeneralForm::onReconnectClicked() void GeneralForm::onReconnectClicked()

View File

@ -38,12 +38,12 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-173</y>
<width>513</width> <width>511</width>
<height>819</height> <height>797</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,1"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0">
<property name="spacing"> <property name="spacing">
<number>9</number> <number>9</number>
</property> </property>
@ -216,6 +216,9 @@
<property name="toolTip"> <property name="toolTip">
<string>Set to 0 to disable</string> <string>Set to 0 to disable</string>
</property> </property>
<property name="showGroupSeparator" stdset="0">
<bool>true</bool>
</property>
<property name="suffix"> <property name="suffix">
<string> minutes</string> <string> minutes</string>
</property> </property>
@ -225,9 +228,6 @@
<property name="maximum"> <property name="maximum">
<number>2147483647</number> <number>2147483647</number>
</property> </property>
<property name="showGroupSeparator" stdset="0">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -294,6 +294,9 @@
</item> </item>
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -317,23 +320,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="styleLabel">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="styleBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0">
<property name="sizeConstraint"> <property name="sizeConstraint">
@ -391,6 +377,23 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="styleLabel">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="styleBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="themeColorLabel"> <widget class="QLabel" name="themeColorLabel">
<property name="text"> <property name="text">
@ -462,7 +465,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item alignment="Qt::AlignTop"> <item>
<widget class="QGroupBox" name="connectionGroup"> <widget class="QGroupBox" name="connectionGroup">
<property name="title"> <property name="title">
<string>Connection Settings</string> <string>Connection Settings</string>
@ -492,11 +495,40 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="cbUseProxy"> <layout class="QHBoxLayout" name="proxyLayout_2">
<property name="text"> <item>
<string>Use proxy (SOCKS5)</string> <widget class="QLabel" name="label">
</property> <property name="text">
</widget> <string>Proxy type</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="proxyType">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>SOCKS5</string>
</property>
</item>
<item>
<property name="text">
<string>HTTP</string>
</property>
</item>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="proxyLayout"> <layout class="QHBoxLayout" name="proxyLayout">