mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Add proxy support
This commit is contained in:
parent
a85372a5c0
commit
d093679d03
57
core.cpp
57
core.cpp
|
@ -121,6 +121,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();
|
||||
if (enableIPv6)
|
||||
qDebug() << "Core starting with IPv6 enabled";
|
||||
else
|
||||
|
@ -128,10 +131,28 @@ void Core::start()
|
|||
|
||||
Tox_Options toxOptions;
|
||||
toxOptions.ipv6enabled = enableIPv6;
|
||||
toxOptions.udp_disabled = 0;
|
||||
toxOptions.proxy_enabled = false;
|
||||
toxOptions.proxy_address[0] = 0;
|
||||
toxOptions.proxy_port = 0;
|
||||
toxOptions.udp_disabled = forceTCP;
|
||||
if (proxyAddr.length() > 255)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
tox = tox_new(&toxOptions);
|
||||
if (tox == nullptr)
|
||||
|
@ -142,13 +163,29 @@ void Core::start()
|
|||
tox = tox_new(&toxOptions);
|
||||
if (tox == nullptr)
|
||||
{
|
||||
qCritical() << "Tox core failed to start";
|
||||
emit failedToStart();
|
||||
if (toxOptions.proxy_enabled)
|
||||
{
|
||||
//QMessageBox::critical(Widget::getInstance(), tr("Proxy failure", "popup title"),
|
||||
//tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your "
|
||||
//"settings and restart.", "popup text"));
|
||||
qCritical() << "Core: bad proxy! no toxcore!";
|
||||
emit badProxy();
|
||||
}
|
||||
else
|
||||
{
|
||||
qCritical() << "Tox core failed to start";
|
||||
emit failedToStart();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly.";
|
||||
}
|
||||
else if (toxOptions.proxy_enabled)
|
||||
{
|
||||
emit badProxy();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
qCritical() << "Tox core failed to start";
|
||||
|
@ -919,8 +956,6 @@ void Core::setAvatar(uint8_t format, const QByteArray& data)
|
|||
qWarning() << "Core: Failed to set self avatar";
|
||||
return;
|
||||
}
|
||||
else
|
||||
qDebug() << "Core: Set avatar, format:"<<format<<", size:"<<data.size();
|
||||
|
||||
QPixmap pic;
|
||||
pic.loadFromData(data);
|
||||
|
@ -1053,6 +1088,8 @@ bool Core::loadConfiguration()
|
|||
|
||||
void Core::saveConfiguration()
|
||||
{
|
||||
Settings::getInstance().save();
|
||||
|
||||
if (!tox)
|
||||
{
|
||||
qWarning() << "Core::saveConfiguration: Tox not started, aborting!";
|
||||
|
@ -1085,8 +1122,6 @@ void Core::saveConfiguration()
|
|||
configurationFile.commit();
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
Settings::getInstance().save();
|
||||
}
|
||||
|
||||
void Core::loadFriends()
|
||||
|
|
1
core.h
1
core.h
|
@ -138,6 +138,7 @@ signals:
|
|||
void failedToSetTyping(bool typing);
|
||||
|
||||
void failedToStart();
|
||||
void badProxy();
|
||||
|
||||
void fileSendStarted(ToxFile file);
|
||||
void fileReceiveRequested(ToxFile file);
|
||||
|
|
|
@ -34,13 +34,12 @@ public:
|
|||
uint16_t size();
|
||||
|
||||
static QString toString(const uint8_t* cMessage, const uint16_t cMessageSize);
|
||||
static uint16_t fromString(const QString& message, uint8_t* cMessage);
|
||||
|
||||
private:
|
||||
const static int MAX_SIZE_OF_UTF8_ENCODED_CHARACTER = 4;
|
||||
|
||||
uint8_t* cString;
|
||||
uint16_t cStringSize;
|
||||
|
||||
static uint16_t fromString(const QString& message, uint8_t* cMessage);
|
||||
};
|
||||
#endif // CSTRING_H
|
||||
|
|
|
@ -140,6 +140,9 @@ 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
|
||||
|
@ -239,6 +242,9 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -351,6 +357,36 @@ void Settings::setUseTranslations(bool newValue)
|
|||
useTranslations = newValue;
|
||||
}
|
||||
|
||||
bool Settings::getForceTCP() const
|
||||
{
|
||||
return forceTCP;
|
||||
}
|
||||
|
||||
void Settings::setForceTCP(bool newValue)
|
||||
{
|
||||
forceTCP = newValue;
|
||||
}
|
||||
|
||||
QString Settings::getProxyAddr() const
|
||||
{
|
||||
return proxyAddr;
|
||||
}
|
||||
|
||||
void Settings::setProxyAddr(const QString& newValue)
|
||||
{
|
||||
proxyAddr = newValue;
|
||||
}
|
||||
|
||||
int Settings::getProxyPort() const
|
||||
{
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
void Settings::setProxyPort(int newValue)
|
||||
{
|
||||
proxyPort = newValue;
|
||||
}
|
||||
|
||||
bool Settings::getEnableLogging() const
|
||||
{
|
||||
return enableLogging;
|
||||
|
|
|
@ -52,6 +52,15 @@ public:
|
|||
bool getUseTranslations() const;
|
||||
void setUseTranslations(bool newValue);
|
||||
|
||||
bool getForceTCP() const;
|
||||
void setForceTCP(bool newValue);
|
||||
|
||||
QString getProxyAddr() const;
|
||||
void setProxyAddr(const QString& newValue);
|
||||
|
||||
int getProxyPort() const;
|
||||
void setProxyPort(int newValue);
|
||||
|
||||
bool getEnableLogging() const;
|
||||
void setEnableLogging(bool newValue);
|
||||
|
||||
|
@ -153,6 +162,10 @@ private:
|
|||
bool enableIPv6;
|
||||
bool useTranslations;
|
||||
static bool makeToxPortable;
|
||||
|
||||
bool forceTCP;
|
||||
QString proxyAddr;
|
||||
int proxyPort;
|
||||
|
||||
bool enableLogging;
|
||||
bool encryptLogs;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "widget/widget.h"
|
||||
#include "misc/settings.h"
|
||||
#include "misc/smileypack.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
GeneralForm::GeneralForm() :
|
||||
GenericForm(tr("General Settings"), QPixmap(":/img/settings/general.png"))
|
||||
|
@ -37,10 +38,20 @@ GeneralForm::GeneralForm() :
|
|||
}
|
||||
bodyUI->smileyPackBrowser->setCurrentIndex(bodyUI->smileyPackBrowser->findData(Settings::getInstance().getSmileyPack()));
|
||||
|
||||
connect(bodyUI->cbEnableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated()));
|
||||
connect(bodyUI->cbUseTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated()));
|
||||
connect(bodyUI->cbMakeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated()));
|
||||
bodyUI->cbUDPDisabled->setChecked(Settings::getInstance().getForceTCP());
|
||||
bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr());
|
||||
int port = Settings::getInstance().getProxyPort();
|
||||
if (port != -1)
|
||||
bodyUI->proxyPort->setText(QString::number(port));
|
||||
|
||||
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
|
||||
connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated);
|
||||
connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated);
|
||||
connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int)));
|
||||
// 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);
|
||||
}
|
||||
|
||||
GeneralForm::~GeneralForm()
|
||||
|
@ -68,3 +79,28 @@ void GeneralForm::onSmileyBrowserIndexChanged(int index)
|
|||
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();
|
||||
Settings::getInstance().setSmileyPack(filename);
|
||||
}
|
||||
|
||||
void GeneralForm::onUDPUpdated()
|
||||
{
|
||||
Settings::getInstance().setForceTCP(bodyUI->cbUDPDisabled->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::onProxyAddrEdited()
|
||||
{
|
||||
Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
|
||||
}
|
||||
|
||||
void GeneralForm::onProxyPortEdited()
|
||||
{
|
||||
QString text = bodyUI->proxyPort->text();
|
||||
if (text != "")
|
||||
{
|
||||
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(-1);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ private slots:
|
|||
void onUseTranslationUpdated();
|
||||
void onMakeToxPortableUpdated();
|
||||
void onSmileyBrowserIndexChanged(int index);
|
||||
void onUDPUpdated();
|
||||
void onProxyAddrEdited();
|
||||
void onProxyPortEdited();
|
||||
|
||||
private:
|
||||
Ui::GeneralSettings *bodyUI;
|
||||
|
|
|
@ -75,6 +75,52 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="proxyGroup">
|
||||
<property name="title">
|
||||
<string>Proxy settings</string>
|
||||
</property>
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayoutProxyLabel">
|
||||
<item>
|
||||
<widget class="QLabel" name="proxyAddrLabel">
|
||||
<property name="text">
|
||||
<string extracomment="Text on proxy addr label">Proxy address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="proxyPortLabel">
|
||||
<property name="text">
|
||||
<string extracomment="Text on proxy port label">Proxy 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>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
|
@ -66,7 +66,7 @@ SettingsWidget::SettingsWidget(Camera* cam, QWidget* parent)
|
|||
tabBar->setIconSize(QSize(20, 20));
|
||||
tabBar->setShape(QTabBar::RoundedSouth);
|
||||
|
||||
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(onTabChanged(int)));
|
||||
connect(tabBar, &QTabBar::currentChanged, this, &SettingsWidget::onTabChanged);
|
||||
}
|
||||
|
||||
SettingsWidget::~SettingsWidget()
|
||||
|
|
|
@ -124,6 +124,7 @@ Widget::Widget(QWidget *parent)
|
|||
connect(core, &Core::connected, this, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, this, &Widget::onDisconnected);
|
||||
connect(core, &Core::failedToStart, this, &Widget::onFailedToStartCore);
|
||||
connect(core, &Core::badProxy, this, &Widget::onBadProxyCore);
|
||||
connect(core, &Core::statusSet, this, &Widget::onStatusSet);
|
||||
connect(core, &Core::usernameSet, this, &Widget::setUsername);
|
||||
connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage);
|
||||
|
@ -283,12 +284,22 @@ void Widget::onDisconnected()
|
|||
void Widget::onFailedToStartCore()
|
||||
{
|
||||
QMessageBox critical(this);
|
||||
critical.setText("Toxcore failed to start, the application will terminate after you close this message.");
|
||||
critical.setText(tr("Toxcore failed to start, the application will terminate after you close this message."));
|
||||
critical.setIcon(QMessageBox::Critical);
|
||||
critical.exec();
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void Widget::onBadProxyCore()
|
||||
{
|
||||
QMessageBox critical(this);
|
||||
critical.setText(tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your "
|
||||
"settings and restart.", "popup text"));
|
||||
critical.setIcon(QMessageBox::Critical);
|
||||
critical.exec();
|
||||
onSettingsClicked();
|
||||
}
|
||||
|
||||
void Widget::onStatusSet(Status status)
|
||||
{
|
||||
//We have to use stylesheets here, there's no way to
|
||||
|
|
|
@ -77,6 +77,7 @@ private slots:
|
|||
void onTransferClicked();
|
||||
void onSettingsClicked();
|
||||
void onFailedToStartCore();
|
||||
void onBadProxyCore();
|
||||
void onAvatarClicked();
|
||||
void onSelfAvatarLoaded(const QPixmap &pic);
|
||||
void onUsernameChanged(const QString& newUsername, const QString& oldUsername);
|
||||
|
|
Loading…
Reference in New Issue
Block a user