2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2019 Thomas Piccirello <thomas.piccirello@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
32 addUpLimitSlider: (hashes) => {
33 if ($("uplimitSliderarea")) {
34 // Get global upload limit
35 fetch("api/v2/transfer/uploadLimit", {
39 .then(async (response) => {
43 const data = await response.text();
46 const tmp = Number(data);
48 maximum = tmp / 1024.0;
51 if (hashes[0] === "global")
57 // Get torrents upload limit
59 if (hashes[0] === "global") {
60 let up_limit = maximum;
64 new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), {
67 initialStep: up_limit.round(),
70 $("uplimitUpdatevalue").value = pos;
71 $("upLimitUnit").style.visibility = "visible";
74 $("uplimitUpdatevalue").value = "∞";
75 $("upLimitUnit").style.visibility = "hidden";
81 $("uplimitUpdatevalue").value = "∞";
82 $("upLimitUnit").style.visibility = "hidden";
85 $("uplimitUpdatevalue").value = up_limit.round();
86 $("upLimitUnit").style.visibility = "visible";
90 fetch("api/v2/torrents/uploadLimit", {
92 body: new URLSearchParams({
93 "hashes": hashes.join("|")
96 .then(async (response) => {
100 const data = await response.json();
102 let up_limit = data[hashes[0]];
103 for (const key in data) {
104 if (up_limit !== data[key]) {
111 new Slider($("uplimitSliderarea"), $("uplimitSliderknob"), {
114 initialStep: (up_limit / 1024.0).round(),
117 $("uplimitUpdatevalue").value = pos;
118 $("upLimitUnit").style.visibility = "visible";
121 $("uplimitUpdatevalue").value = "∞";
122 $("upLimitUnit").style.visibility = "hidden";
127 if (up_limit === 0) {
128 $("uplimitUpdatevalue").value = "∞";
129 $("upLimitUnit").style.visibility = "hidden";
132 $("uplimitUpdatevalue").value = (up_limit / 1024.0).round();
133 $("upLimitUnit").style.visibility = "visible";
141 addDlLimitSlider: (hashes) => {
142 if ($("dllimitSliderarea")) {
143 // Get global upload limit
144 fetch("api/v2/transfer/downloadLimit", {
148 .then(async (response) => {
152 const data = await response.text();
155 const tmp = Number(data);
157 maximum = tmp / 1024.0;
160 if (hashes[0] === "global")
166 // Get torrents download limit
168 if (hashes[0] === "global") {
169 let dl_limit = maximum;
173 new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), {
176 initialStep: dl_limit.round(),
179 $("dllimitUpdatevalue").value = pos;
180 $("dlLimitUnit").style.visibility = "visible";
183 $("dllimitUpdatevalue").value = "∞";
184 $("dlLimitUnit").style.visibility = "hidden";
189 if (dl_limit === 0) {
190 $("dllimitUpdatevalue").value = "∞";
191 $("dlLimitUnit").style.visibility = "hidden";
194 $("dllimitUpdatevalue").value = dl_limit.round();
195 $("dlLimitUnit").style.visibility = "visible";
199 fetch("api/v2/torrents/downloadLimit", {
201 body: new URLSearchParams({
202 "hashes": hashes.join("|")
205 .then(async (response) => {
209 const data = await response.json();
211 let dl_limit = data[hashes[0]];
212 for (const key in data) {
213 if (dl_limit !== data[key]) {
220 new Slider($("dllimitSliderarea"), $("dllimitSliderknob"), {
223 initialStep: (dl_limit / 1024.0).round(),
226 $("dllimitUpdatevalue").value = pos;
227 $("dlLimitUnit").style.visibility = "visible";
230 $("dllimitUpdatevalue").value = "∞";
231 $("dlLimitUnit").style.visibility = "hidden";
236 if (dl_limit === 0) {
237 $("dllimitUpdatevalue").value = "∞";
238 $("dlLimitUnit").style.visibility = "hidden";
241 $("dllimitUpdatevalue").value = (dl_limit / 1024.0).round();
242 $("dlLimitUnit").style.visibility = "visible";