Feature: Support Batch Adding Tracker Urls in Qt UI (#1161)

Adding tracker urls one at a time is very tedious.
This lEts you add multiple tracker urls at oNce, 1 trAcker url per line.
As a bonus, this also takes care of trailing spaces when pasting urls.

Fixes #1148
And this seems to be a requested feature:
https://forum.transmissionbt.com/viewtopic.php?t=18958

Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
Dinesh Manajipet 2021-10-11 08:49:36 +05:30 committed by GitHub
parent 1fb5a79813
commit ac41837ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 18 deletions

View File

@ -24,6 +24,7 @@
#include <QMap> #include <QMap>
#include <QMessageBox> #include <QMessageBox>
#include <QResizeEvent> #include <QResizeEvent>
#include <QRegExp>
#include <QStringList> #include <QStringList>
#include <QStyle> #include <QStyle>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
@ -1289,37 +1290,42 @@ void DetailsDialog::onTrackerSelectionChanged()
void DetailsDialog::onAddTrackerClicked() void DetailsDialog::onAddTrackerClicked()
{ {
bool ok = false; bool ok = false;
QString const
url = QInputDialog::getText(this, tr("Add URL "), tr("Add tracker announce URL:"), QLineEdit::Normal, QString(), &ok);
if (!ok) QString const text = QInputDialog::getMultiLineText(
{ this,
// user pressed "cancel" -- noop tr("Add URL(s) "),
} tr("Add tracker announce URLs, one per line:"),
else if (!QUrl(url).isValid()) {},
{ &ok);
QMessageBox::warning(this, tr("Error"), tr("Invalid URL \"%1\"").arg(url));
} if (ok)
else
{ {
QSet<QString> urls;
torrent_ids_t ids; torrent_ids_t ids;
for (int const id : ids_) for (auto const& line : text.split(QRegExp(QStringLiteral("[\r\n]+"))))
{ {
if (tracker_model_->find(id, url) == -1) QString const url = line.trimmed();
if (!line.isEmpty() && QUrl(url).isValid())
{ {
ids.insert(id); for (auto const& id : ids_)
{
if (tracker_model_->find(id, url) == -1 && !urls.contains(url))
{
ids.insert(id);
urls.insert(url);
}
}
} }
} }
if (ids.empty()) // all the torrents already have this tracker if (urls.isEmpty())
{ {
QMessageBox::warning(this, tr("Error"), tr("Tracker already exists.")); QMessageBox::warning(this, tr("Error"), tr("No new URLs found."));
} }
else else
{ {
auto const urls = QStringList{ url }; torrentSet(ids, TR_KEY_trackerAdd, urls.values());
torrentSet(ids, TR_KEY_trackerAdd, urls);
} }
} }
} }