From ac41837ae9aacec0394d4ba5b51db644da2ebc49 Mon Sep 17 00:00:00 2001 From: Dinesh Manajipet Date: Mon, 11 Oct 2021 08:49:36 +0530 Subject: [PATCH] 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 --- qt/DetailsDialog.cc | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index 929cf0f08..9ccbfb16e 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1289,37 +1290,42 @@ void DetailsDialog::onTrackerSelectionChanged() void DetailsDialog::onAddTrackerClicked() { bool ok = false; - QString const - url = QInputDialog::getText(this, tr("Add URL "), tr("Add tracker announce URL:"), QLineEdit::Normal, QString(), &ok); - if (!ok) - { - // user pressed "cancel" -- noop - } - else if (!QUrl(url).isValid()) - { - QMessageBox::warning(this, tr("Error"), tr("Invalid URL \"%1\"").arg(url)); - } - else + QString const text = QInputDialog::getMultiLineText( + this, + tr("Add URL(s) "), + tr("Add tracker announce URLs, one per line:"), + {}, + &ok); + + if (ok) { + QSet urls; 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 { - auto const urls = QStringList{ url }; - torrentSet(ids, TR_KEY_trackerAdd, urls); + torrentSet(ids, TR_KEY_trackerAdd, urls.values()); } } }