diff --git a/core.cpp b/core.cpp index f6b7a2a5c..fdc91616a 100644 --- a/core.cpp +++ b/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:"< 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); +} diff --git a/widget/form/settings/generalform.h b/widget/form/settings/generalform.h index 5d5fd6efe..2af8f4bb6 100644 --- a/widget/form/settings/generalform.h +++ b/widget/form/settings/generalform.h @@ -37,6 +37,9 @@ private slots: void onUseTranslationUpdated(); void onMakeToxPortableUpdated(); void onSmileyBrowserIndexChanged(int index); + void onUDPUpdated(); + void onProxyAddrEdited(); + void onProxyPortEdited(); private: Ui::GeneralSettings *bodyUI; diff --git a/widget/form/settings/generalsettings.ui b/widget/form/settings/generalsettings.ui index 902d41039..0015d1787 100644 --- a/widget/form/settings/generalsettings.ui +++ b/widget/form/settings/generalsettings.ui @@ -75,6 +75,52 @@ + + + + Proxy settings + + + + + + Disable UDP (not recommended) + + + + + + + + + Proxy address + + + + + + + Proxy port + + + + + + + + + + + + + + + + + + + + diff --git a/widget/form/settingswidget.cpp b/widget/form/settingswidget.cpp index 434513004..b7539a4c5 100644 --- a/widget/form/settingswidget.cpp +++ b/widget/form/settingswidget.cpp @@ -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() diff --git a/widget/widget.cpp b/widget/widget.cpp index 283900fdc..ad08389bf 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -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 diff --git a/widget/widget.h b/widget/widget.h index fa371a9b2..aae819adc 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -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);