1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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"
#include "theme.h"
#include "configfile.h"
#include "application.h"
#include "configfile.h"
#include "folderman.h"
#include <QNetworkProxy>
namespace OCC {
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);
// 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());
connect(_ui->authRequiredcheckBox, SIGNAL(toggled(bool)),
_ui->authWidgets, SLOT(setEnabled(bool)));
connect(_ui->manualProxyRadioButton, SIGNAL(toggled(bool)),
_ui->manualSettings, SLOT(setEnabled(bool)));
connect(_ui->manualProxyRadioButton, SIGNAL(toggled(bool)),
_ui->typeComboBox, SLOT(setEnabled(bool)));
loadProxySettings();
loadBWLimitSettings();
// proxy
connect(_ui->typeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(saveProxySettings()));
connect(_ui->proxyButtonGroup, SIGNAL(buttonClicked(int)), SLOT(saveProxySettings()));
connect(_ui->hostLineEdit, SIGNAL(editingFinished()), SLOT(saveProxySettings()));
connect(_ui->userLineEdit, SIGNAL(editingFinished()), SLOT(saveProxySettings()));
connect(_ui->passwordLineEdit, SIGNAL(editingFinished()), SLOT(saveProxySettings()));
connect(_ui->portSpinBox, SIGNAL(editingFinished()), SLOT(saveProxySettings()));
connect(_ui->authRequiredcheckBox, SIGNAL(toggled(bool)), SLOT(saveProxySettings()));
connect(_ui->uploadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->noUploadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->autoUploadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->downloadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->noDownloadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->autoDownloadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
connect(_ui->downloadSpinBox, SIGNAL(valueChanged(int)), SLOT(saveBWLimitSettings()));
connect(_ui->uploadSpinBox, SIGNAL(valueChanged(int)), SLOT(saveBWLimitSettings()));
}
NetworkSettings::~NetworkSettings()
{
delete _ui;
}
QSize NetworkSettings::sizeHint() const
{
return QSize(ownCloudGui::settingsDialogSize().width(), QWidget::sizeHint().height());
}
void NetworkSettings::loadProxySettings()
{
if (Theme::instance()->forceSystemNetworkProxy()) {
_ui->systemProxyRadioButton->setChecked(true);
_ui->proxyGroupBox->setEnabled(false);
return;
}
// load current proxy settings
OCC::ConfigFile cfgFile;
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);
_ui->authRequiredcheckBox->setChecked(cfgFile.proxyNeedsAuth());
_ui->userLineEdit->setText(cfgFile.proxyUser());
_ui->passwordLineEdit->setText(cfgFile.proxyPassword());
}
void NetworkSettings::loadBWLimitSettings()
{
ConfigFile cfgFile;
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 3)
// QNAM bandwidth limiting only works with versions of Qt greater or equal to 5.3.3
// (It needs Qt commits 097b641 and b99fa32)
const char *v = qVersion(); // "x.y.z";
if (QLatin1String(v) < QLatin1String("5.3.3")) {
QString tooltip = tr("Qt >= 5.4 is required in order to use the bandwidth limit");
_ui->downloadBox->setEnabled(false);
_ui->uploadBox->setEnabled(false);
_ui->downloadBox->setToolTip(tooltip);
_ui->uploadBox->setToolTip(tooltip);
_ui->noDownloadLimitRadioButton->setChecked(true);
_ui->noUploadLimitRadioButton->setChecked(true);
if (cfgFile.useUploadLimit() != 0 || cfgFile.useDownloadLimit() != 0) {
// Update from old mirall that was using neon propagator jobs.
saveBWLimitSettings();
}
return;
}
#endif
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) {
_ui->uploadLimitRadioButton->setChecked(true);
} else if (useUploadLimit == 0) {
_ui->noUploadLimitRadioButton->setChecked(true);
} else {
_ui->autoUploadLimitRadioButton->setChecked(true);
}
_ui->uploadSpinBox->setValue(cfgFile.uploadLimit());
}
void NetworkSettings::saveProxySettings()
{
ConfigFile cfgFile;
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();
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);
}
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.
FolderMan::instance()->setDirtyProxy(true);
}
void NetworkSettings::saveBWLimitSettings()
{
ConfigFile cfgFile;
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());
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());
FolderMan::instance()->setDirtyNetworkLimits();
}
} // namespace OCC
|