2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2015 Diego de las Heras <ngosang@hotmail.es>
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
.PropWebseeds
??= (() => {
33 const exports
= () => {
35 updateData
: updateData
,
40 const torrentWebseedsTable
= new window
.qBittorrent
.DynamicTable
.TorrentWebseedsTable();
42 let current_hash
= "";
44 let loadWebSeedsDataTimer
= -1;
45 const loadWebSeedsData
= () => {
46 if ($("propWebSeeds").hasClass("invisible")
47 || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
48 // Tab changed, don't do anything
51 const new_hash
= torrentsTable
.getCurrentTorrentID();
52 if (new_hash
=== "") {
53 torrentWebseedsTable
.clear();
54 clearTimeout(loadWebSeedsDataTimer
);
57 if (new_hash
!== current_hash
) {
58 torrentWebseedsTable
.clear();
59 current_hash
= new_hash
;
62 url
: new URI("api/v2/torrents/webseeds").setData("hash", current_hash
),
66 clearTimeout(loadWebSeedsDataTimer
);
67 loadWebSeedsDataTimer
= loadWebSeedsData
.delay(10000);
69 onSuccess
: (webseeds
) => {
70 const selectedWebseeds
= torrentWebseedsTable
.selectedRowsIds();
71 torrentWebseedsTable
.clear();
74 // Update WebSeeds data
75 webseeds
.each((webseed
) => {
76 torrentWebseedsTable
.updateRowData({
83 torrentWebseedsTable
.updateTable(false);
85 if (selectedWebseeds
.length
> 0)
86 torrentWebseedsTable
.reselectRows(selectedWebseeds
);
91 const updateData
= () => {
92 clearTimeout(loadWebSeedsDataTimer
);
93 loadWebSeedsDataTimer
= -1;
97 const torrentWebseedsContextMenu
= new window
.qBittorrent
.ContextMenu
.ContextMenu({
98 targets
: "#torrentWebseedsTableDiv",
99 menu
: "torrentWebseedsMenu",
101 AddWebSeeds
: (element
, ref
) => {
104 EditWebSeed
: (element
, ref
) => {
105 // only allow editing of one row
106 element
.firstChild
.click();
107 editWebSeedFN(element
);
109 RemoveWebSeed
: (element
, ref
) => {
110 removeWebSeedFN(element
);
118 const selectedWebseeds
= torrentWebseedsTable
.selectedRowsIds();
120 if (selectedWebseeds
.length
=== 0) {
121 this.hideItem("EditWebSeed");
122 this.hideItem("RemoveWebSeed");
123 this.hideItem("CopyWebseedUrl");
126 if (selectedWebseeds
.length
=== 1)
127 this.showItem("EditWebSeed");
129 this.hideItem("EditWebSeed");
131 this.showItem("RemoveWebSeed");
132 this.showItem("CopyWebseedUrl");
137 const addWebseedFN
= () => {
138 if (current_hash
.length
=== 0)
143 title
: "QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer]",
144 loadMethod
: "iframe",
145 contentURL
: "addwebseeds.html?hash=" + current_hash
,
151 paddingHorizontal
: 0,
154 onCloseComplete
: () => {
160 const editWebSeedFN
= (element
) => {
161 if (current_hash
.length
=== 0)
164 const selectedWebseeds
= torrentWebseedsTable
.selectedRowsIds();
165 if (selectedWebseeds
.length
> 1)
168 const webseedUrl
= selectedWebseeds
[0];
172 title
: "QBT_TR(Web seed editing)QBT_TR[CONTEXT=PropertiesWidget]",
173 loadMethod
: "iframe",
174 contentURL
: "editwebseed.html?hash=" + current_hash
+ "&url=" + encodeURIComponent(webseedUrl
),
180 paddingHorizontal
: 0,
183 onCloseComplete
: () => {
189 const removeWebSeedFN
= (element
) => {
190 if (current_hash
.length
=== 0)
193 const selectedWebseeds
= torrentWebseedsTable
.selectedRowsIds();
195 url
: "api/v2/torrents/removeWebSeeds",
199 urls
: selectedWebseeds
.map(webseed
=> encodeURIComponent(webseed
)).join("|")
207 const clear
= () => {
208 torrentWebseedsTable
.clear();
211 new ClipboardJS("#CopyWebseedUrl", {
213 return torrentWebseedsTable
.selectedRowsIds().join("\n");
217 torrentWebseedsTable
.setup("torrentWebseedsTableDiv", "torrentWebseedsTableFixedHeaderDiv", torrentWebseedsContextMenu
);
221 Object
.freeze(window
.qBittorrent
.PropWebseeds
);