mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 17:37:36 +03:00
Settings: Auto download bandwidth limit #1485
This commit is contained in:
parent
389faa4bcb
commit
ef1e6add4f
5 changed files with 73 additions and 68 deletions
|
@ -63,6 +63,7 @@ NetworkSettings::NetworkSettings(QWidget *parent) :
|
||||||
connect(_ui->autoUploadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
|
connect(_ui->autoUploadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
|
||||||
connect(_ui->downloadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
|
connect(_ui->downloadLimitRadioButton, SIGNAL(clicked()), SLOT(saveBWLimitSettings()));
|
||||||
connect(_ui->noDownloadLimitRadioButton, 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->downloadSpinBox, SIGNAL(valueChanged(int)), SLOT(saveBWLimitSettings()));
|
||||||
connect(_ui->uploadSpinBox, SIGNAL(valueChanged(int)), SLOT(saveBWLimitSettings()));
|
connect(_ui->uploadSpinBox, SIGNAL(valueChanged(int)), SLOT(saveBWLimitSettings()));
|
||||||
}
|
}
|
||||||
|
@ -109,16 +110,25 @@ void NetworkSettings::loadProxySettings()
|
||||||
void NetworkSettings::loadBWLimitSettings()
|
void NetworkSettings::loadBWLimitSettings()
|
||||||
{
|
{
|
||||||
ConfigFile cfgFile;
|
ConfigFile cfgFile;
|
||||||
_ui->downloadLimitRadioButton->setChecked(cfgFile.useDownloadLimit());
|
|
||||||
int uploadLimit = cfgFile.useUploadLimit();
|
int useDownloadLimit = cfgFile.useDownloadLimit();
|
||||||
if ( uploadLimit >= 1 ) {
|
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);
|
_ui->uploadLimitRadioButton->setChecked(true);
|
||||||
} else if (uploadLimit == 0){
|
} else if (useUploadLimit == 0){
|
||||||
_ui->noUploadLimitRadioButton->setChecked(true);
|
_ui->noUploadLimitRadioButton->setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
_ui->autoUploadLimitRadioButton->setChecked(true);
|
_ui->autoUploadLimitRadioButton->setChecked(true);
|
||||||
}
|
}
|
||||||
_ui->downloadSpinBox->setValue(cfgFile.downloadLimit());
|
|
||||||
_ui->uploadSpinBox->setValue(cfgFile.uploadLimit());
|
_ui->uploadSpinBox->setValue(cfgFile.uploadLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +161,14 @@ void NetworkSettings::saveProxySettings()
|
||||||
void NetworkSettings::saveBWLimitSettings()
|
void NetworkSettings::saveBWLimitSettings()
|
||||||
{
|
{
|
||||||
ConfigFile cfgFile;
|
ConfigFile cfgFile;
|
||||||
cfgFile.setUseDownloadLimit(_ui->downloadLimitRadioButton->isChecked());
|
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()) {
|
if (_ui->uploadLimitRadioButton->isChecked()) {
|
||||||
cfgFile.setUseUploadLimit(1);
|
cfgFile.setUseUploadLimit(1);
|
||||||
|
@ -160,8 +177,6 @@ void NetworkSettings::saveBWLimitSettings()
|
||||||
} else if (_ui->autoUploadLimitRadioButton->isChecked()) {
|
} else if (_ui->autoUploadLimitRadioButton->isChecked()) {
|
||||||
cfgFile.setUseUploadLimit(-1);
|
cfgFile.setUseUploadLimit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgFile.setDownloadLimit(_ui->downloadSpinBox->value());
|
|
||||||
cfgFile.setUploadLimit(_ui->uploadSpinBox->value());
|
cfgFile.setUploadLimit(_ui->uploadSpinBox->value());
|
||||||
|
|
||||||
FolderMan::instance()->setDirtyNetworkLimits();
|
FolderMan::instance()->setDirtyNetworkLimits();
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>518</width>
|
<width>542</width>
|
||||||
<height>384</height>
|
<height>391</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="portSpinBox">
|
<widget class="QSpinBox" name="portSpinBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
@ -141,13 +141,22 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="margin">
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="userLineEdit">
|
<widget class="QLineEdit" name="userLineEdit">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
|
@ -157,7 +166,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="passwordLineEdit">
|
<widget class="QLineEdit" name="passwordLineEdit">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
|
@ -190,14 +199,37 @@
|
||||||
<string>Download Bandwidth</string>
|
<string>Download Bandwidth</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="2" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QRadioButton" name="downloadLimitRadioButton">
|
<widget class="QRadioButton" name="downloadLimitRadioButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Limit to</string>
|
<string>Limit to</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QRadioButton" name="noDownloadLimitRadioButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>No limit</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>147</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="downloadSpinBox">
|
<widget class="QSpinBox" name="downloadSpinBox">
|
||||||
|
@ -221,42 +253,13 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
<widget class="QRadioButton" name="noDownloadLimitRadioButton">
|
<widget class="QRadioButton" name="autoDownloadLimitRadioButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>No limit</string>
|
<string>Limit automatically</string>
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" colspan="2">
|
|
||||||
<spacer name="verticalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>147</width>
|
|
||||||
<height>25</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -323,19 +326,6 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
<zorder>autoUploadLimitRadioButton</zorder>
|
<zorder>autoUploadLimitRadioButton</zorder>
|
||||||
<zorder>uploadLimitRadioButton</zorder>
|
<zorder>uploadLimitRadioButton</zorder>
|
||||||
|
|
|
@ -514,9 +514,9 @@ int ConfigFile::useUploadLimit() const
|
||||||
return getValue(useUploadLimitC, QString::null, 0).toInt();
|
return getValue(useUploadLimitC, QString::null, 0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigFile::useDownloadLimit() const
|
int ConfigFile::useDownloadLimit() const
|
||||||
{
|
{
|
||||||
return getValue(useDownloadLimitC, QString::null, false).toBool();
|
return getValue(useDownloadLimitC, QString::null, 0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::setUseUploadLimit(int val)
|
void ConfigFile::setUseUploadLimit(int val)
|
||||||
|
@ -524,9 +524,9 @@ void ConfigFile::setUseUploadLimit(int val)
|
||||||
setValue(useUploadLimitC, val);
|
setValue(useUploadLimitC, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::setUseDownloadLimit(bool enable)
|
void ConfigFile::setUseDownloadLimit(int val)
|
||||||
{
|
{
|
||||||
setValue(useDownloadLimitC, enable);
|
setValue(useDownloadLimitC, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigFile::uploadLimit() const
|
int ConfigFile::uploadLimit() const
|
||||||
|
|
|
@ -87,9 +87,9 @@ public:
|
||||||
|
|
||||||
/** 0: no limit, 1: manual, >0: automatic */
|
/** 0: no limit, 1: manual, >0: automatic */
|
||||||
int useUploadLimit() const;
|
int useUploadLimit() const;
|
||||||
bool useDownloadLimit() const;
|
int useDownloadLimit() const;
|
||||||
void setUseUploadLimit(int);
|
void setUseUploadLimit(int);
|
||||||
void setUseDownloadLimit(bool);
|
void setUseDownloadLimit(int);
|
||||||
/** in kbyte/s */
|
/** in kbyte/s */
|
||||||
int uploadLimit() const;
|
int uploadLimit() const;
|
||||||
int downloadLimit() const;
|
int downloadLimit() const;
|
||||||
|
|
|
@ -242,7 +242,7 @@ void GETFileJob::slotReadyRead()
|
||||||
if (_bandwidthLimited) {
|
if (_bandwidthLimited) {
|
||||||
toRead = qMin(qint64(bufferSize), _bandwidthQuota);
|
toRead = qMin(qint64(bufferSize), _bandwidthQuota);
|
||||||
if (toRead == 0) {
|
if (toRead == 0) {
|
||||||
qDebug() << Q_FUNC_INFO << "Out of quota";
|
//qDebug() << Q_FUNC_INFO << "Out of quota";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_bandwidthQuota -= toRead;
|
_bandwidthQuota -= toRead;
|
||||||
|
|
Loading…
Reference in a new issue