2013-07-24 21:53:05 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-07-24 21:53:05 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "networksettings.h"
|
|
|
|
#include "ui_networksettings.h"
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "theme.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "application.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderman.h"
|
2017-11-05 21:50:09 +03:00
|
|
|
#include "accountmanager.h"
|
2013-07-24 21:53:05 +04:00
|
|
|
|
|
|
|
#include <QNetworkProxy>
|
2017-11-05 21:50:09 +03:00
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
2013-07-24 21:53:05 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-24 21:53:05 +04:00
|
|
|
|
|
|
|
NetworkSettings::NetworkSettings(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, _ui(new Ui::NetworkSettings)
|
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
|
|
|
|
_ui->hostLineEdit->setPlaceholderText(tr("Hostname of proxy server"));
|
|
|
|
_ui->userLineEdit->setPlaceholderText(tr("Username for proxy server"));
|
|
|
|
_ui->passwordLineEdit->setPlaceholderText(tr("Password for proxy server"));
|
|
|
|
|
|
|
|
_ui->typeComboBox->addItem(tr("HTTP(S) proxy"), QNetworkProxy::HttpProxy);
|
|
|
|
_ui->typeComboBox->addItem(tr("SOCKS5 proxy"), QNetworkProxy::Socks5Proxy);
|
|
|
|
|
|
|
|
_ui->authRequiredcheckBox->setEnabled(true);
|
|
|
|
|
2015-07-16 11:27:15 +03:00
|
|
|
// Explicitly set up the enabled status of the proxy auth widgets to ensure
|
|
|
|
// toggling the parent enables/disables the children
|
|
|
|
_ui->userLineEdit->setEnabled(true);
|
|
|
|
_ui->passwordLineEdit->setEnabled(true);
|
|
|
|
_ui->authWidgets->setEnabled(_ui->authRequiredcheckBox->isChecked());
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->authRequiredcheckBox, &QAbstractButton::toggled,
|
|
|
|
_ui->authWidgets, &QWidget::setEnabled);
|
2015-07-16 11:27:15 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->manualProxyRadioButton, &QAbstractButton::toggled,
|
|
|
|
_ui->manualSettings, &QWidget::setEnabled);
|
|
|
|
connect(_ui->manualProxyRadioButton, &QAbstractButton::toggled,
|
|
|
|
_ui->typeComboBox, &QWidget::setEnabled);
|
2013-07-24 21:53:05 +04:00
|
|
|
|
|
|
|
loadProxySettings();
|
|
|
|
loadBWLimitSettings();
|
|
|
|
|
|
|
|
// proxy
|
2017-09-20 12:48:13 +03:00
|
|
|
connect(_ui->typeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &NetworkSettings::saveProxySettings);
|
|
|
|
connect(_ui->proxyButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &NetworkSettings::saveProxySettings);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->hostLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings);
|
|
|
|
connect(_ui->userLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings);
|
|
|
|
connect(_ui->passwordLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings);
|
|
|
|
connect(_ui->portSpinBox, &QAbstractSpinBox::editingFinished, this, &NetworkSettings::saveProxySettings);
|
|
|
|
connect(_ui->authRequiredcheckBox, &QAbstractButton::toggled, this, &NetworkSettings::saveProxySettings);
|
2013-07-24 21:53:05 +04:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->uploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->noUploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->autoUploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->downloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->noDownloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->autoDownloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings);
|
2017-09-20 12:48:13 +03:00
|
|
|
connect(_ui->downloadSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &NetworkSettings::saveBWLimitSettings);
|
|
|
|
connect(_ui->uploadSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &NetworkSettings::saveBWLimitSettings);
|
2017-11-05 21:50:09 +03:00
|
|
|
|
|
|
|
// Warn about empty proxy host
|
|
|
|
connect(_ui->hostLineEdit, &QLineEdit::textChanged, this, &NetworkSettings::checkEmptyProxyHost);
|
|
|
|
checkEmptyProxyHost();
|
2013-07-24 21:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NetworkSettings::~NetworkSettings()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:15:45 +03:00
|
|
|
QSize NetworkSettings::sizeHint() const
|
|
|
|
{
|
2020-05-27 15:36:07 +03:00
|
|
|
return {
|
|
|
|
ownCloudGui::settingsDialogSize().width(),
|
|
|
|
QWidget::sizeHint().height()
|
|
|
|
};
|
2015-07-20 19:15:45 +03:00
|
|
|
}
|
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
void NetworkSettings::loadProxySettings()
|
|
|
|
{
|
2016-03-11 18:21:40 +03:00
|
|
|
if (Theme::instance()->forceSystemNetworkProxy()) {
|
|
|
|
_ui->systemProxyRadioButton->setChecked(true);
|
|
|
|
_ui->proxyGroupBox->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-24 21:53:05 +04:00
|
|
|
// load current proxy settings
|
2014-11-10 00:34:07 +03:00
|
|
|
OCC::ConfigFile cfgFile;
|
2013-07-24 21:53:05 +04:00
|
|
|
int type = cfgFile.proxyType();
|
|
|
|
switch (type) {
|
|
|
|
case QNetworkProxy::NoProxy:
|
|
|
|
_ui->noProxyRadioButton->setChecked(true);
|
|
|
|
break;
|
|
|
|
case QNetworkProxy::DefaultProxy:
|
|
|
|
_ui->systemProxyRadioButton->setChecked(true);
|
|
|
|
break;
|
|
|
|
case QNetworkProxy::Socks5Proxy:
|
|
|
|
case QNetworkProxy::HttpProxy:
|
|
|
|
_ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(type));
|
|
|
|
_ui->manualProxyRadioButton->setChecked(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ui->hostLineEdit->setText(cfgFile.proxyHostName());
|
|
|
|
int port = cfgFile.proxyPort();
|
|
|
|
if (port == 0)
|
|
|
|
port = 8080;
|
|
|
|
_ui->portSpinBox->setValue(port);
|
2015-07-16 15:21:51 +03:00
|
|
|
_ui->authRequiredcheckBox->setChecked(cfgFile.proxyNeedsAuth());
|
|
|
|
_ui->userLineEdit->setText(cfgFile.proxyUser());
|
|
|
|
_ui->passwordLineEdit->setText(cfgFile.proxyPassword());
|
2013-07-24 21:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkSettings::loadBWLimitSettings()
|
|
|
|
{
|
2015-10-22 18:57:34 +03:00
|
|
|
ConfigFile cfgFile;
|
|
|
|
|
2015-06-29 18:43:25 +03:00
|
|
|
int useDownloadLimit = cfgFile.useDownloadLimit();
|
|
|
|
if (useDownloadLimit >= 1) {
|
|
|
|
_ui->downloadLimitRadioButton->setChecked(true);
|
|
|
|
} else if (useDownloadLimit == 0) {
|
|
|
|
_ui->noDownloadLimitRadioButton->setChecked(true);
|
|
|
|
} else {
|
|
|
|
_ui->autoDownloadLimitRadioButton->setChecked(true);
|
|
|
|
}
|
|
|
|
_ui->downloadSpinBox->setValue(cfgFile.downloadLimit());
|
|
|
|
|
|
|
|
int useUploadLimit = cfgFile.useUploadLimit();
|
|
|
|
if (useUploadLimit >= 1) {
|
2013-07-25 13:20:03 +04:00
|
|
|
_ui->uploadLimitRadioButton->setChecked(true);
|
2015-06-29 18:43:25 +03:00
|
|
|
} else if (useUploadLimit == 0) {
|
2013-08-17 18:11:45 +04:00
|
|
|
_ui->noUploadLimitRadioButton->setChecked(true);
|
2013-07-24 21:53:05 +04:00
|
|
|
} else {
|
|
|
|
_ui->autoUploadLimitRadioButton->setChecked(true);
|
|
|
|
}
|
|
|
|
_ui->uploadSpinBox->setValue(cfgFile.uploadLimit());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkSettings::saveProxySettings()
|
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfgFile;
|
2013-07-24 21:53:05 +04:00
|
|
|
|
2017-11-05 21:50:09 +03:00
|
|
|
checkEmptyProxyHost();
|
2013-07-24 21:53:05 +04:00
|
|
|
if (_ui->noProxyRadioButton->isChecked()) {
|
|
|
|
cfgFile.setProxyType(QNetworkProxy::NoProxy);
|
|
|
|
} else if (_ui->systemProxyRadioButton->isChecked()) {
|
|
|
|
cfgFile.setProxyType(QNetworkProxy::DefaultProxy);
|
|
|
|
} else if (_ui->manualProxyRadioButton->isChecked()) {
|
|
|
|
int type = _ui->typeComboBox->itemData(_ui->typeComboBox->currentIndex()).toInt();
|
2018-04-25 15:22:35 +03:00
|
|
|
QString host = _ui->hostLineEdit->text();
|
|
|
|
if (host.isEmpty())
|
|
|
|
type = QNetworkProxy::NoProxy;
|
2013-07-24 21:53:05 +04:00
|
|
|
bool needsAuth = _ui->authRequiredcheckBox->isChecked();
|
|
|
|
QString user = _ui->userLineEdit->text();
|
|
|
|
QString pass = _ui->passwordLineEdit->text();
|
|
|
|
cfgFile.setProxyType(type, _ui->hostLineEdit->text(),
|
|
|
|
_ui->portSpinBox->value(), needsAuth, user, pass);
|
|
|
|
}
|
|
|
|
|
2014-01-16 15:07:58 +04:00
|
|
|
ClientProxy proxy;
|
|
|
|
proxy.setupQtProxyFromConfig(); // Refresh the Qt proxy settings as the
|
|
|
|
// quota check can happen all the time.
|
|
|
|
|
|
|
|
// ...and set the folders dirty, they refresh their proxy next time they
|
|
|
|
// start the sync.
|
2018-01-05 11:44:20 +03:00
|
|
|
FolderMan::instance()->setDirtyProxy();
|
2017-11-05 21:50:09 +03:00
|
|
|
|
2020-03-21 03:24:06 +03:00
|
|
|
const auto accounts = AccountManager::instance()->accounts();
|
|
|
|
for (auto account : accounts) {
|
2017-11-05 21:50:09 +03:00
|
|
|
account->freshConnectionAttempt();
|
|
|
|
}
|
2013-07-24 21:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkSettings::saveBWLimitSettings()
|
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfgFile;
|
2015-06-29 18:43:25 +03:00
|
|
|
if (_ui->downloadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseDownloadLimit(1);
|
|
|
|
} else if (_ui->noDownloadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseDownloadLimit(0);
|
|
|
|
} else if (_ui->autoDownloadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseDownloadLimit(-1);
|
|
|
|
}
|
|
|
|
cfgFile.setDownloadLimit(_ui->downloadSpinBox->value());
|
2013-07-24 21:53:05 +04:00
|
|
|
|
|
|
|
if (_ui->uploadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseUploadLimit(1);
|
|
|
|
} else if (_ui->noUploadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseUploadLimit(0);
|
|
|
|
} else if (_ui->autoUploadLimitRadioButton->isChecked()) {
|
|
|
|
cfgFile.setUseUploadLimit(-1);
|
|
|
|
}
|
|
|
|
cfgFile.setUploadLimit(_ui->uploadSpinBox->value());
|
2014-01-31 20:29:50 +04:00
|
|
|
|
|
|
|
FolderMan::instance()->setDirtyNetworkLimits();
|
2013-07-24 21:53:05 +04:00
|
|
|
}
|
|
|
|
|
2017-11-05 21:50:09 +03:00
|
|
|
void NetworkSettings::checkEmptyProxyHost()
|
|
|
|
{
|
|
|
|
if (_ui->hostLineEdit->isEnabled() && _ui->hostLineEdit->text().isEmpty()) {
|
|
|
|
_ui->hostLineEdit->setStyleSheet("border: 1px solid red");
|
|
|
|
} else {
|
|
|
|
_ui->hostLineEdit->setStyleSheet(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 16:37:28 +03:00
|
|
|
void NetworkSettings::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
if (!event->spontaneous()
|
|
|
|
&& _ui->manualProxyRadioButton->isChecked()
|
|
|
|
&& _ui->hostLineEdit->text().isEmpty()) {
|
|
|
|
_ui->noProxyRadioButton->setChecked(true);
|
|
|
|
checkEmptyProxyHost();
|
2018-04-25 15:22:35 +03:00
|
|
|
saveProxySettings();
|
2018-04-16 16:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|