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
,
40 let current_hash
= "";
42 const torrentTrackersTable
= new window
.qBittorrent
.DynamicTable
.TorrentTrackersTable();
43 let loadTrackersDataTimer
= -1;
45 const loadTrackersData
= () => {
46 if ($("propTrackers").classList
.contains("invisible")
47 || $("propertiesPanel_collapseToggle").classList
.contains("panel-expand")) {
48 // Tab changed, don't do anything
51 const new_hash
= torrentsTable
.getCurrentTorrentID();
52 if (new_hash
=== "") {
53 torrentTrackersTable
.clear();
54 clearTimeout(loadTrackersDataTimer
);
57 if (new_hash
!== current_hash
) {
58 torrentTrackersTable
.clear();
59 current_hash
= new_hash
;
62 const url
= new URL("api/v2/torrents/trackers", window
.location
);
63 url
.search
= new URLSearchParams({
70 .then(async (response
) => {
74 const selectedTrackers
= torrentTrackersTable
.selectedRowsIds();
75 torrentTrackersTable
.clear();
77 const trackers
= await response
.json();
79 trackers
.each((tracker
) => {
81 switch (tracker
.status
) {
83 status
= "QBT_TR(Disabled)QBT_TR[CONTEXT=TrackerListWidget]";
86 status
= "QBT_TR(Not contacted yet)QBT_TR[CONTEXT=TrackerListWidget]";
89 status
= "QBT_TR(Working)QBT_TR[CONTEXT=TrackerListWidget]";
92 status
= "QBT_TR(Updating...)QBT_TR[CONTEXT=TrackerListWidget]";
95 status
= "QBT_TR(Not working)QBT_TR[CONTEXT=TrackerListWidget]";
101 tier
: (tracker
.tier
>= 0) ? tracker
.tier
: "",
104 peers
: (tracker
.num_peers
>= 0) ? tracker
.num_peers
: "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
105 seeds
: (tracker
.num_seeds
>= 0) ? tracker
.num_seeds
: "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
106 leeches
: (tracker
.num_leeches
>= 0) ? tracker
.num_leeches
: "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
107 downloaded
: (tracker
.num_downloaded
>= 0) ? tracker
.num_downloaded
: "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
108 message
: tracker
.msg
,
109 _sortable
: !tracker
.url
.startsWith("** [")
112 torrentTrackersTable
.updateRowData(row
);
115 torrentTrackersTable
.updateTable(false);
117 if (selectedTrackers
.length
> 0)
118 torrentTrackersTable
.reselectRows(selectedTrackers
);
122 clearTimeout(loadTrackersDataTimer
);
123 loadTrackersDataTimer
= loadTrackersData
.delay(10000);
127 const updateData
= () => {
128 clearTimeout(loadTrackersDataTimer
);
129 loadTrackersDataTimer
= -1;
133 const torrentTrackersContextMenu
= new window
.qBittorrent
.ContextMenu
.ContextMenu({
134 targets
: "#torrentTrackersTableDiv",
135 menu
: "torrentTrackersMenu",
137 AddTracker
: (element
, ref
) => {
140 EditTracker
: (element
, ref
) => {
141 // only allow editing of one row
142 element
.firstElementChild
.click();
143 editTrackerFN(element
);
145 RemoveTracker
: (element
, ref
) => {
146 removeTrackerFN(element
);
154 const selectedTrackers
= torrentTrackersTable
.selectedRowsIds();
155 const containsStaticTracker
= selectedTrackers
.some((tracker
) => {
156 return tracker
.startsWith("** [");
159 if (containsStaticTracker
|| (selectedTrackers
.length
=== 0)) {
160 this.hideItem("EditTracker");
161 this.hideItem("RemoveTracker");
162 this.hideItem("CopyTrackerUrl");
165 this.showItem("EditTracker");
166 this.showItem("RemoveTracker");
167 this.showItem("CopyTrackerUrl");
172 const addTrackerFN
= () => {
173 if (current_hash
.length
=== 0)
177 icon
: "images/qbittorrent-tray.svg",
178 title
: "QBT_TR(Add trackers)QBT_TR[CONTEXT=TrackersAdditionDialog]",
179 loadMethod
: "iframe",
180 contentURL
: "addtrackers.html?hash=" + current_hash
,
186 paddingHorizontal
: 0,
189 onCloseComplete
: () => {
195 const editTrackerFN
= (element
) => {
196 if (current_hash
.length
=== 0)
199 const trackerUrl
= encodeURIComponent(element
.childNodes
[1].textContent
);
202 icon
: "images/qbittorrent-tray.svg",
203 title
: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]",
204 loadMethod
: "iframe",
205 contentURL
: "edittracker.html?hash=" + current_hash
+ "&url=" + trackerUrl
,
211 paddingHorizontal
: 0,
214 onCloseComplete
: () => {
220 const removeTrackerFN
= (element
) => {
221 if (current_hash
.length
=== 0)
224 fetch("api/v2/torrents/removeTrackers", {
226 body
: new URLSearchParams({
228 urls
: torrentTrackersTable
.selectedRowsIds().map(encodeURIComponent
).join("|")
231 .then((response
) => {
239 const clear
= () => {
240 torrentTrackersTable
.clear();
243 new ClipboardJS("#CopyTrackerUrl", {
245 return torrentTrackersTable
.selectedRowsIds().join("\n");
249 torrentTrackersTable
.setup("torrentTrackersTableDiv", "torrentTrackersTableFixedHeaderDiv", torrentTrackersContextMenu
);
253 Object
.freeze(window
.qBittorrent
.PropTrackers
);