2019-02-04 13:45:22 +08:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
|
|
|
* Copyright (C) 2015 Diego de las Heras <ngosang@hotmail.es>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-11-30 18:30:26 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-05-30 09:05:16 +03:00
|
|
|
const webseedsDynTable = new Class({
|
2015-06-12 17:52:01 +02:00
|
|
|
|
|
|
|
initialize: function() {},
|
|
|
|
|
|
|
|
setup: function(table) {
|
|
|
|
this.table = $(table);
|
|
|
|
this.rows = new Hash();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRow: function(url) {
|
|
|
|
if (this.rows.has(url)) {
|
2019-05-30 09:05:16 +03:00
|
|
|
const tr = this.rows.get(url);
|
2015-06-12 17:52:01 +02:00
|
|
|
tr.dispose();
|
|
|
|
this.rows.erase(url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeAllRows: function() {
|
|
|
|
this.rows.each(function(tr, url) {
|
|
|
|
this.removeRow(url);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRow: function(tr, row) {
|
2019-05-30 09:05:16 +03:00
|
|
|
const tds = tr.getElements('td');
|
|
|
|
for (let i = 0; i < row.length; ++i) {
|
2015-06-12 17:52:01 +02:00
|
|
|
tds[i].set('html', row[i]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
insertRow: function(row) {
|
2019-05-30 09:05:16 +03:00
|
|
|
const url = row[0];
|
2015-06-12 17:52:01 +02:00
|
|
|
if (this.rows.has(url)) {
|
2019-05-30 09:05:16 +03:00
|
|
|
const tableRow = this.rows.get(url);
|
2017-07-01 00:42:20 -04:00
|
|
|
this.updateRow(tableRow, row);
|
2015-06-12 17:52:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//this.removeRow(id);
|
2019-05-30 09:05:16 +03:00
|
|
|
const tr = new Element('tr');
|
2015-06-12 17:52:01 +02:00
|
|
|
this.rows.set(url, tr);
|
2019-05-30 09:05:16 +03:00
|
|
|
for (let i = 0; i < row.length; ++i) {
|
|
|
|
const td = new Element('td');
|
2015-06-12 17:52:01 +02:00
|
|
|
td.set('html', row[i]);
|
|
|
|
td.injectInside(tr);
|
|
|
|
}
|
|
|
|
tr.injectInside(this.table);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-05-30 09:05:16 +03:00
|
|
|
this.current_hash = "";
|
2015-06-12 17:52:01 +02:00
|
|
|
|
2019-05-30 09:05:16 +03:00
|
|
|
let loadWebSeedsDataTimer;
|
|
|
|
const loadWebSeedsData = function() {
|
2018-04-05 11:59:31 +08:00
|
|
|
if ($('prop_webseeds').hasClass('invisible')
|
|
|
|
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
|
2015-06-12 17:52:01 +02:00
|
|
|
// Tab changed, don't do anything
|
|
|
|
return;
|
|
|
|
}
|
2019-05-30 09:05:16 +03:00
|
|
|
const new_hash = torrentsTable.getCurrentTorrentHash();
|
2017-07-01 00:42:20 -04:00
|
|
|
if (new_hash === "") {
|
2015-06-12 17:52:01 +02:00
|
|
|
wsTable.removeAllRows();
|
|
|
|
clearTimeout(loadWebSeedsDataTimer);
|
|
|
|
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (new_hash != current_hash) {
|
|
|
|
wsTable.removeAllRows();
|
|
|
|
current_hash = new_hash;
|
|
|
|
}
|
2019-05-30 09:05:16 +03:00
|
|
|
const url = new URI('api/v2/torrents/webseeds?hash=' + current_hash);
|
2018-09-26 23:10:51 -04:00
|
|
|
new Request.JSON({
|
2015-06-12 17:52:01 +02:00
|
|
|
url: url,
|
|
|
|
noCache: true,
|
|
|
|
method: 'get',
|
|
|
|
onFailure: function() {
|
2017-05-01 01:45:02 +03:00
|
|
|
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
2015-06-12 17:52:01 +02:00
|
|
|
clearTimeout(loadWebSeedsDataTimer);
|
|
|
|
loadWebSeedsDataTimer = loadWebSeedsData.delay(20000);
|
|
|
|
},
|
|
|
|
onSuccess: function(webseeds) {
|
|
|
|
$('error_div').set('html', '');
|
|
|
|
if (webseeds) {
|
|
|
|
// Update WebSeeds data
|
|
|
|
webseeds.each(function(webseed) {
|
2019-05-30 09:05:16 +03:00
|
|
|
const row = [];
|
2015-06-12 17:52:01 +02:00
|
|
|
row.length = 1;
|
|
|
|
row[0] = webseed.url;
|
|
|
|
wsTable.insertRow(row);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wsTable.removeAllRows();
|
|
|
|
}
|
|
|
|
clearTimeout(loadWebSeedsDataTimer);
|
|
|
|
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
|
|
|
|
}
|
|
|
|
}).send();
|
2017-07-01 00:42:20 -04:00
|
|
|
};
|
2015-06-12 17:52:01 +02:00
|
|
|
|
2019-05-30 09:05:16 +03:00
|
|
|
updateWebSeedsData = function() {
|
2015-06-12 17:52:01 +02:00
|
|
|
clearTimeout(loadWebSeedsDataTimer);
|
|
|
|
loadWebSeedsData();
|
2017-07-01 00:42:20 -04:00
|
|
|
};
|
2015-06-12 17:52:01 +02:00
|
|
|
|
2019-05-30 09:05:16 +03:00
|
|
|
const wsTable = new webseedsDynTable();
|
2015-06-12 17:52:01 +02:00
|
|
|
wsTable.setup($('webseedsTable'));
|