240 lines
11 KiB
JavaScript
Raw Normal View History

2022-10-18 22:39:32 -04:00
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2019 Thomas Piccirello <thomas.piccirello@gmail.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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
"use strict";
2022-10-18 22:39:32 -04:00
MochaUI.extend({
addUpLimitSlider: function(hashes) {
if ($("uplimitSliderarea")) {
2022-10-18 22:39:32 -04:00
// Get global upload limit
let maximum = 500;
new Request({
url: "api/v2/transfer/uploadLimit",
method: "get",
2022-10-18 22:39:32 -04:00
data: {},
onSuccess: function(data) {
if (data) {
const tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.0;
}
else {
if (hashes[0] === "global")
2022-10-18 22:39:32 -04:00
maximum = 10000;
else
maximum = 1000;
}
}
// Get torrents upload limit
// And create slider
if (hashes[0] === "global") {
2022-10-18 22:39:32 -04:00
let up_limit = maximum;
if (up_limit < 0)
up_limit = 0;
maximum = 10000;
new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), {
2022-10-18 22:39:32 -04:00
steps: maximum,
offset: 0,
initialStep: up_limit.round(),
onChange: function(pos) {
if (pos > 0) {
$("uplimitUpdatevalue").value = pos;
$("upLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
else {
$("uplimitUpdatevalue").value = "∞";
$("upLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
}.bind(this)
});
// Set default value
if (up_limit === 0) {
$("uplimitUpdatevalue").value = "∞";
$("upLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
else {
$("uplimitUpdatevalue").value = up_limit.round();
$("upLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
}
else {
new Request.JSON({
url: "api/v2/torrents/uploadLimit",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
hashes: hashes.join("|")
2022-10-18 22:39:32 -04:00
},
onSuccess: function(data) {
if (data) {
let up_limit = data[hashes[0]];
for (const key in data) {
if (up_limit !== data[key]) {
2022-10-18 22:39:32 -04:00
up_limit = 0;
break;
}
}
2022-10-18 22:39:32 -04:00
if (up_limit < 0)
up_limit = 0;
new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), {
2022-10-18 22:39:32 -04:00
steps: maximum,
offset: 0,
initialStep: (up_limit / 1024.0).round(),
onChange: function(pos) {
if (pos > 0) {
$("uplimitUpdatevalue").value = pos;
$("upLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
else {
$("uplimitUpdatevalue").value = "∞";
$("upLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
}.bind(this)
});
// Set default value
if (up_limit === 0) {
$("uplimitUpdatevalue").value = "∞";
$("upLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
else {
$("uplimitUpdatevalue").value = (up_limit / 1024.0).round();
$("upLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
}
}
}).send();
}
}
}).send();
}
},
addDlLimitSlider: function(hashes) {
if ($("dllimitSliderarea")) {
2022-10-18 22:39:32 -04:00
// Get global upload limit
let maximum = 500;
new Request({
url: "api/v2/transfer/downloadLimit",
method: "get",
2022-10-18 22:39:32 -04:00
data: {},
onSuccess: function(data) {
if (data) {
const tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.0;
}
else {
if (hashes[0] === "global")
2022-10-18 22:39:32 -04:00
maximum = 10000;
else
maximum = 1000;
}
}
// Get torrents download limit
// And create slider
if (hashes[0] === "global") {
2022-10-18 22:39:32 -04:00
let dl_limit = maximum;
if (dl_limit < 0)
dl_limit = 0;
maximum = 10000;
new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), {
2022-10-18 22:39:32 -04:00
steps: maximum,
offset: 0,
initialStep: dl_limit.round(),
onChange: function(pos) {
if (pos > 0) {
$("dllimitUpdatevalue").value = pos;
$("dlLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
else {
$("dllimitUpdatevalue").value = "∞";
$("dlLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
}.bind(this)
});
// Set default value
if (dl_limit === 0) {
$("dllimitUpdatevalue").value = "∞";
$("dlLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
else {
$("dllimitUpdatevalue").value = dl_limit.round();
$("dlLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
}
else {
new Request.JSON({
url: "api/v2/torrents/downloadLimit",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
hashes: hashes.join("|")
2022-10-18 22:39:32 -04:00
},
onSuccess: function(data) {
if (data) {
let dl_limit = data[hashes[0]];
for (const key in data) {
if (dl_limit !== data[key]) {
2022-10-18 22:39:32 -04:00
dl_limit = 0;
break;
}
}
2022-10-18 22:39:32 -04:00
if (dl_limit < 0)
dl_limit = 0;
new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), {
2022-10-18 22:39:32 -04:00
steps: maximum,
offset: 0,
initialStep: (dl_limit / 1024.0).round(),
onChange: function(pos) {
if (pos > 0) {
$("dllimitUpdatevalue").value = pos;
$("dlLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
else {
$("dllimitUpdatevalue").value = "∞";
$("dlLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
}.bind(this)
});
// Set default value
if (dl_limit === 0) {
$("dllimitUpdatevalue").value = "∞";
$("dlLimitUnit").style.visibility = "hidden";
2022-10-18 22:39:32 -04:00
}
else {
$("dllimitUpdatevalue").value = (dl_limit / 1024.0).round();
$("dlLimitUnit").style.visibility = "visible";
2022-10-18 22:39:32 -04:00
}
}
}
}).send();
}
}
}).send();
}
}
});