2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2009 Christophe Dumez <chris@qbittorrent.org>
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.PropTrackers ??= (() => {
33 const exports = () => {
35 updateData: updateData
39 let current_hash = "";
41 const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable();
42 let loadTrackersDataTimer = -1;
44 const loadTrackersData = function() {
45 if ($("propTrackers").hasClass("invisible")
46 || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
47 // Tab changed, don't do anything
50 const new_hash = torrentsTable.getCurrentTorrentID();
51 if (new_hash === "") {
52 torrentTrackersTable.clear();
53 clearTimeout(loadTrackersDataTimer);
54 loadTrackersDataTimer = loadTrackersData.delay(10000);
57 if (new_hash !== current_hash) {
58 torrentTrackersTable.clear();
59 current_hash = new_hash;
61 const url = new URI("api/v2/torrents/trackers?hash=" + current_hash);
66 onComplete: function() {
67 clearTimeout(loadTrackersDataTimer);
68 loadTrackersDataTimer = loadTrackersData.delay(10000);
70 onSuccess: function(trackers) {
71 const selectedTrackers = torrentTrackersTable.selectedRowsIds();
72 torrentTrackersTable.clear();
75 trackers.each((tracker) => {
77 switch (tracker.status) {
79 status = "QBT_TR(Disabled)QBT_TR[CONTEXT=TrackerListWidget]";
82 status = "QBT_TR(Not contacted yet)QBT_TR[CONTEXT=TrackerListWidget]";
85 status = "QBT_TR(Working)QBT_TR[CONTEXT=TrackerListWidget]";
88 status = "QBT_TR(Updating...)QBT_TR[CONTEXT=TrackerListWidget]";
91 status = "QBT_TR(Not working)QBT_TR[CONTEXT=TrackerListWidget]";
97 tier: (tracker.tier >= 0) ? tracker.tier : "",
100 peers: (tracker.num_peers >= 0) ? tracker.num_peers : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
101 seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
102 leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
103 downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
107 torrentTrackersTable.updateRowData(row);
110 torrentTrackersTable.updateTable(false);
112 if (selectedTrackers.length > 0)
113 torrentTrackersTable.reselectRows(selectedTrackers);
119 const updateData = function() {
120 clearTimeout(loadTrackersDataTimer);
121 loadTrackersDataTimer = -1;
125 const torrentTrackersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
126 targets: "#torrentTrackersTableDiv",
127 menu: "torrentTrackersMenu",
129 AddTracker: function(element, ref) {
132 EditTracker: function(element, ref) {
133 // only allow editing of one row
134 element.firstChild.click();
135 editTrackerFN(element);
137 RemoveTracker: function(element, ref) {
138 removeTrackerFN(element);
146 const selectedTrackers = torrentTrackersTable.selectedRowsIds();
147 const containsStaticTracker = selectedTrackers.some((tracker) => {
148 return (tracker.indexOf("** [") === 0);
151 if (containsStaticTracker || (selectedTrackers.length === 0)) {
152 this.hideItem("EditTracker");
153 this.hideItem("RemoveTracker");
154 this.hideItem("CopyTrackerUrl");
157 this.showItem("EditTracker");
158 this.showItem("RemoveTracker");
159 this.showItem("CopyTrackerUrl");
164 const addTrackerFN = function() {
165 if (current_hash.length === 0)
169 icon: "images/qbittorrent-tray.svg",
170 title: "QBT_TR(Add trackers)QBT_TR[CONTEXT=TrackersAdditionDialog]",
171 loadMethod: "iframe",
172 contentURL: "addtrackers.html?hash=" + current_hash,
178 paddingHorizontal: 0,
181 onCloseComplete: function() {
187 const editTrackerFN = function(element) {
188 if (current_hash.length === 0)
191 const trackerUrl = encodeURIComponent(element.childNodes[1].textContent);
194 icon: "images/qbittorrent-tray.svg",
195 title: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]",
196 loadMethod: "iframe",
197 contentURL: "edittracker.html?hash=" + current_hash + "&url=" + trackerUrl,
203 paddingHorizontal: 0,
206 onCloseComplete: function() {
212 const removeTrackerFN = function(element) {
213 if (current_hash.length === 0)
216 const selectedTrackers = torrentTrackersTable.selectedRowsIds();
218 url: "api/v2/torrents/removeTrackers",
222 urls: selectedTrackers.join("|")
224 onSuccess: function() {
230 new ClipboardJS("#CopyTrackerUrl", {
231 text: function(trigger) {
232 return torrentTrackersTable.selectedRowsIds().join("\n");
236 torrentTrackersTable.setup("torrentTrackersTableDiv", "torrentTrackersTableFixedHeaderDiv", torrentTrackersContextMenu);
240 Object.freeze(window.qBittorrent.PropTrackers);