2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2018 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.
31 window.qBittorrent ??= {};
32 window.qBittorrent.PropPeers ??= (() => {
33 const exports = () => {
35 updateData: updateData,
40 const torrentPeersTable = new window.qBittorrent.DynamicTable.TorrentPeersTable();
41 let loadTorrentPeersTimer = -1;
42 let syncTorrentPeersLastResponseId = 0;
43 let show_flags = true;
45 const loadTorrentPeersData = () => {
46 if ($("propPeers").hasClass("invisible")
47 || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
48 syncTorrentPeersLastResponseId = 0;
49 torrentPeersTable.clear();
52 const current_hash = torrentsTable.getCurrentTorrentID();
53 if (current_hash === "") {
54 syncTorrentPeersLastResponseId = 0;
55 torrentPeersTable.clear();
56 clearTimeout(loadTorrentPeersTimer);
59 const url = new URI("api/v2/sync/torrentPeers");
60 url.setData("rid", syncTorrentPeersLastResponseId);
61 url.setData("hash", current_hash);
67 clearTimeout(loadTorrentPeersTimer);
68 loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval());
70 onSuccess: (response) => {
71 $("error_div").textContent = "";
73 const full_update = (response["full_update"] === true);
75 torrentPeersTable.clear();
77 syncTorrentPeersLastResponseId = response["rid"];
78 if (response["peers"]) {
79 for (const key in response["peers"]) {
80 if (!Object.hasOwn(response["peers"], key))
83 response["peers"][key]["rowId"] = key;
84 torrentPeersTable.updateRowData(response["peers"][key]);
87 if (response["peers_removed"]) {
88 response["peers_removed"].each((hash) => {
89 torrentPeersTable.removeRow(hash);
92 torrentPeersTable.updateTable(full_update);
94 if (response["show_flags"]) {
95 if (show_flags !== response["show_flags"]) {
96 show_flags = response["show_flags"];
97 torrentPeersTable.columns["country"].force_hide = !show_flags;
98 torrentPeersTable.updateColumn("country");
103 torrentPeersTable.clear();
109 const updateData = () => {
110 clearTimeout(loadTorrentPeersTimer);
111 loadTorrentPeersTimer = -1;
112 loadTorrentPeersData();
115 const clear = () => {
116 torrentPeersTable.clear();
119 const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
120 targets: "#torrentPeersTableDiv",
121 menu: "torrentPeersMenu",
123 addPeer: (element, ref) => {
124 const hash = torrentsTable.getCurrentTorrentID();
130 icon: "images/qbittorrent-tray.svg",
131 title: "QBT_TR(Add Peers)QBT_TR[CONTEXT=PeersAdditionDialog]",
132 loadMethod: "iframe",
133 contentURL: "addpeers.html?hash=" + hash,
138 paddingHorizontal: 0,
143 banPeer: (element, ref) => {
144 const selectedPeers = torrentPeersTable.selectedRowsIds();
145 if (selectedPeers.length === 0)
148 if (confirm("QBT_TR(Are you sure you want to permanently ban the selected peers?)QBT_TR[CONTEXT=PeerListWidget]")) {
150 url: "api/v2/transfer/banPeers",
153 hash: torrentsTable.getCurrentTorrentID(),
154 peers: selectedPeers.join("|")
165 const selectedPeers = torrentPeersTable.selectedRowsIds();
167 if (selectedPeers.length >= 1) {
168 this.showItem("copyPeer");
169 this.showItem("banPeer");
172 this.hideItem("copyPeer");
173 this.hideItem("banPeer");
178 new ClipboardJS("#CopyPeerInfo", {
180 return torrentPeersTable.selectedRowsIds().join("\n");
184 torrentPeersTable.setup("torrentPeersTableDiv", "torrentPeersTableFixedHeaderDiv", torrentPeersContextMenu);
188 Object.freeze(window.qBittorrent.PropPeers);