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->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()));
|
||||
}
|
||||
|
@ -109,16 +110,25 @@ void NetworkSettings::loadProxySettings()
|
|||
void NetworkSettings::loadBWLimitSettings()
|
||||
{
|
||||
ConfigFile cfgFile;
|
||||
_ui->downloadLimitRadioButton->setChecked(cfgFile.useDownloadLimit());
|
||||
int uploadLimit = cfgFile.useUploadLimit();
|
||||
if ( uploadLimit >= 1 ) {
|
||||
|
||||
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 (uploadLimit == 0){
|
||||
} else if (useUploadLimit == 0){
|
||||
_ui->noUploadLimitRadioButton->setChecked(true);
|
||||
} else {
|
||||
_ui->autoUploadLimitRadioButton->setChecked(true);
|
||||
}
|
||||
_ui->downloadSpinBox->setValue(cfgFile.downloadLimit());
|
||||
_ui->uploadSpinBox->setValue(cfgFile.uploadLimit());
|
||||
}
|
||||
|
||||
|
@ -151,7 +161,14 @@ void NetworkSettings::saveProxySettings()
|
|||
void NetworkSettings::saveBWLimitSettings()
|
||||
{
|
||||
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()) {
|
||||
cfgFile.setUseUploadLimit(1);
|
||||
|
@ -160,8 +177,6 @@ void NetworkSettings::saveBWLimitSettings()
|
|||
} else if (_ui->autoUploadLimitRadioButton->isChecked()) {
|
||||
cfgFile.setUseUploadLimit(-1);
|
||||
}
|
||||
|
||||
cfgFile.setDownloadLimit(_ui->downloadSpinBox->value());
|
||||
cfgFile.setUploadLimit(_ui->uploadSpinBox->value());
|
||||
|
||||
FolderMan::instance()->setDirtyNetworkLimits();
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>518</width>
|
||||
<height>384</height>
|
||||
<width>542</width>
|
||||
<height>391</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -104,7 +104,7 @@
|
|||
<item>
|
||||
<widget class="QSpinBox" name="portSpinBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
|
@ -141,13 +141,22 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<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>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="userLineEdit">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
|
@ -157,7 +166,7 @@
|
|||
<item>
|
||||
<widget class="QLineEdit" name="passwordLineEdit">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
|
@ -190,14 +199,37 @@
|
|||
<string>Download Bandwidth</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QRadioButton" name="downloadLimitRadioButton">
|
||||
<property name="text">
|
||||
<string>Limit to</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="downloadSpinBox">
|
||||
|
@ -221,42 +253,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="noDownloadLimitRadioButton">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="autoDownloadLimitRadioButton">
|
||||
<property name="text">
|
||||
<string>No limit</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<string>Limit automatically</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -323,19 +326,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<zorder>autoUploadLimitRadioButton</zorder>
|
||||
<zorder>uploadLimitRadioButton</zorder>
|
||||
|
|
|
@ -514,9 +514,9 @@ int ConfigFile::useUploadLimit() const
|
|||
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)
|
||||
|
@ -524,9 +524,9 @@ void ConfigFile::setUseUploadLimit(int val)
|
|||
setValue(useUploadLimitC, val);
|
||||
}
|
||||
|
||||
void ConfigFile::setUseDownloadLimit(bool enable)
|
||||
void ConfigFile::setUseDownloadLimit(int val)
|
||||
{
|
||||
setValue(useDownloadLimitC, enable);
|
||||
setValue(useDownloadLimitC, val);
|
||||
}
|
||||
|
||||
int ConfigFile::uploadLimit() const
|
||||
|
|
|
@ -87,9 +87,9 @@ public:
|
|||
|
||||
/** 0: no limit, 1: manual, >0: automatic */
|
||||
int useUploadLimit() const;
|
||||
bool useDownloadLimit() const;
|
||||
int useDownloadLimit() const;
|
||||
void setUseUploadLimit(int);
|
||||
void setUseDownloadLimit(bool);
|
||||
void setUseDownloadLimit(int);
|
||||
/** in kbyte/s */
|
||||
int uploadLimit() const;
|
||||
int downloadLimit() const;
|
||||
|
|
|
@ -242,7 +242,7 @@ void GETFileJob::slotReadyRead()
|
|||
if (_bandwidthLimited) {
|
||||
toRead = qMin(qint64(bufferSize), _bandwidthQuota);
|
||||
if (toRead == 0) {
|
||||
qDebug() << Q_FUNC_INFO << "Out of quota";
|
||||
//qDebug() << Q_FUNC_INFO << "Out of quota";
|
||||
break;
|
||||
}
|
||||
_bandwidthQuota -= toRead;
|
||||
|
|
Loading…
Reference in a new issue