Skip to content

Commit

Permalink
WebUI: Support managing web seeds
Browse files Browse the repository at this point in the history
Closes #8475.
PR #21055.
  • Loading branch information
Piccirello authored Sep 28, 2024
1 parent a23f45c commit 81def39
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 87 deletions.
20 changes: 10 additions & 10 deletions src/gui/properties/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ void PropertiesWidget::loadUrlSeeds()
return;

m_ui->listWebSeeds->clear();
qDebug("Loading URL seeds");
qDebug("Loading web seeds");
// Add url seeds
for (const QUrl &urlSeed : urlSeeds)
{
qDebug("Loading URL seed: %s", qUtf8Printable(urlSeed.toString()));
qDebug("Loading web seed: %s", qUtf8Printable(urlSeed.toString()));
new QListWidgetItem(urlSeed.toString(), m_ui->listWebSeeds);
}
});
Expand All @@ -550,16 +550,16 @@ void PropertiesWidget::displayWebSeedListMenu()
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);

menu->addAction(UIThemeManager::instance()->getIcon(u"list-add"_s), tr("New Web seed"), this, &PropertiesWidget::askWebSeed);
menu->addAction(UIThemeManager::instance()->getIcon(u"list-add"_s), tr("Add web seed..."), this, &PropertiesWidget::askWebSeed);

if (!rows.isEmpty())
{
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-clear"_s, u"list-remove"_s), tr("Remove Web seed")
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-clear"_s, u"list-remove"_s), tr("Remove web seed")
, this, &PropertiesWidget::deleteSelectedUrlSeeds);
menu->addSeparator();
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-copy"_s), tr("Copy Web seed URL")
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-copy"_s), tr("Copy web seed URL")
, this, &PropertiesWidget::copySelectedWebSeedsToClipboard);
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-rename"_s), tr("Edit Web seed URL")
menu->addAction(UIThemeManager::instance()->getIcon(u"edit-rename"_s), tr("Edit web seed URL...")
, this, &PropertiesWidget::editWebSeed);
}

Expand Down Expand Up @@ -607,14 +607,14 @@ void PropertiesWidget::askWebSeed()
{
bool ok = false;
// Ask user for a new url seed
const QString urlSeed = AutoExpandableDialog::getText(this, tr("New URL seed", "New HTTP source"),
tr("New URL seed:"), QLineEdit::Normal,
const QString urlSeed = AutoExpandableDialog::getText(this, tr("Add web seed", "Add HTTP source"),
tr("Add web seed:"), QLineEdit::Normal,
u"http://www."_s, &ok);
if (!ok) return;
qDebug("Adding %s web seed", qUtf8Printable(urlSeed));
if (!m_ui->listWebSeeds->findItems(urlSeed, Qt::MatchFixedString).empty())
{
QMessageBox::warning(this, u"qBittorrent"_s, tr("This URL seed is already in the list."), QMessageBox::Ok);
QMessageBox::warning(this, u"qBittorrent"_s, tr("This web seed is already in the list."), QMessageBox::Ok);
return;
}
if (m_torrent)
Expand Down Expand Up @@ -667,7 +667,7 @@ void PropertiesWidget::editWebSeed()
if (!m_ui->listWebSeeds->findItems(newSeed, Qt::MatchFixedString).empty())
{
QMessageBox::warning(this, u"qBittorrent"_s,
tr("This URL seed is already in the list."),
tr("This web seed is already in the list."),
QMessageBox::Ok);
return;
}
Expand Down
58 changes: 58 additions & 0 deletions src/webui/www/private/addwebseeds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="${LANG}">

<head>
<meta charset="UTF-8">
<title>QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script>
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Escape": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
}
}
}).activate();

$("urls").focus();
$("addWebSeedsButton").addEvent("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/addWebSeeds",
method: "post",
data: {
hash: hash,
urls: $("urls").value.split("\n").map(w => encodeURIComponent(w.trim())).filter(w => (w.length > 0)).join("|")
},
onComplete: function() {
window.parent.qBittorrent.Client.closeWindows();
}
}).send();
});
});
</script>
</head>

<body>
<div style="text-align: center;">
<br>
<label for="urls">QBT_TR(List of web seeds to add (one per line):)QBT_TR[CONTEXT=HttpServer]</label>
<textarea name="list" id="urls" rows="10" cols="1"></textarea>
<br>
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="addWebSeedsButton">
</div>
</body>

</html>
68 changes: 68 additions & 0 deletions src/webui/www/private/editwebseed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="${LANG}">

<head>
<meta charset="UTF-8">
<title>QBT_TR(Edit web seed)QBT_TR[CONTEXT=HttpServer]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script>
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("editWebSeedButton").click();
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeWindows();
event.preventDefault();
}
}
}).activate();

const origUrl = new URI().getData("url");
$("url").value = decodeURIComponent(origUrl);
$("url").focus();

$("editWebSeedButton").addEvent("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
url: "api/v2/torrents/editWebSeed",
method: "post",
data: {
hash: hash,
origUrl: origUrl,
newUrl: encodeURIComponent($("url").value.trim()),
},
onComplete: function() {
window.parent.qBittorrent.Client.closeWindows();
}
}).send();
});
});
</script>
</head>

<body>
<div style="text-align: center;">
<br>
<label for="url">QBT_TR(Web seed URL:)QBT_TR[CONTEXT=PropertiesWidget]</label>
<div style="text-align: center; padding-top: 10px;">
<input type="text" id="url" style="width: 90%;">
</div>
<br>
<input type="button" value="QBT_TR(Edit)QBT_TR[CONTEXT=HttpServer]" id="editWebSeedButton">
</div>
</body>

</html>
6 changes: 6 additions & 0 deletions src/webui/www/private/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version
<li><a href="#copyPeer" id="CopyPeerInfo"><img src="images/edit-copy.svg" alt="QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget]"> QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget]</a></li>
<li class="separator"><a href="#banPeer"><img src="images/peers-remove.svg" alt="QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]"> QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]</a></li>
</ul>
<ul id="torrentWebseedsMenu" class="contextMenu">
<li><a href="#AddWebSeeds"><img src="images/list-add.svg" alt="QBT_TR(Add web seeds...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Add web seeds...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li><a href="#RemoveWebSeed"><img src="images/list-remove.svg" alt="QBT_TR(Remove web seed)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Remove web seed)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li class="separator"><a href="#CopyWebseedUrl" id="CopyWebseedUrl"><img src="images/edit-copy.svg" alt="QBT_TR(Copy web seed URL)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Copy web seed URL)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li><a href="#EditWebSeed"><img src="images/edit-rename.svg" alt="QBT_TR(Edit web seed URL...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Edit web seed URL...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
</ul>
<ul id="torrentFilesMenu" class="contextMenu">
<li><a href="#Rename"><img src="images/edit-rename.svg" alt="QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]"> QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li class="separator">
Expand Down
11 changes: 10 additions & 1 deletion src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ window.qBittorrent.DynamicTable ??= (() => {
RssArticleTable: RssArticleTable,
RssDownloaderRulesTable: RssDownloaderRulesTable,
RssDownloaderFeedSelectionTable: RssDownloaderFeedSelectionTable,
RssDownloaderArticlesTable: RssDownloaderArticlesTable
RssDownloaderArticlesTable: RssDownloaderArticlesTable,
TorrentWebseedsTable: TorrentWebseedsTable
};
};

Expand Down Expand Up @@ -3251,6 +3252,14 @@ window.qBittorrent.DynamicTable ??= (() => {
}
});

const TorrentWebseedsTable = new Class({
Extends: DynamicTable,

initColumns: function() {
this.newColumn("url", "", "QBT_TR(URL)QBT_TR[CONTEXT=HttpServer]", 500, true);
},
});

return exports();
})();
Object.freeze(window.qBittorrent.DynamicTable);
Expand Down
Loading

0 comments on commit 81def39

Please sign in to comment.