From 30d9978c97a582b396c53441c938b05b124ba8c9 Mon Sep 17 00:00:00 2001 From: thalieht Date: Tue, 7 Nov 2023 11:42:31 +0200 Subject: [PATCH] Add copy comment functionality to the torrent list's context menu PR #19846. Closes #18890. --- src/gui/transferlistwidget.cpp | 15 +++++++++++++++ src/gui/transferlistwidget.h | 1 + src/webui/api/serialize/serialize_torrent.cpp | 1 + src/webui/api/serialize/serialize_torrent.h | 1 + src/webui/www/private/index.html | 1 + src/webui/www/private/scripts/client.js | 2 ++ src/webui/www/private/scripts/mocha-init.js | 16 ++++++++++++++++ 7 files changed, 37 insertions(+) diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index c677c8e94..c731775db 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -574,6 +574,18 @@ void TransferListWidget::copySelectedIDs() const qApp->clipboard()->setText(torrentIDs.join(u'\n')); } +void TransferListWidget::copySelectedComments() const +{ + QStringList torrentComments; + for (const BitTorrent::Torrent *torrent : asConst(getSelectedTorrents())) + { + if (!torrent->comment().isEmpty()) + torrentComments << torrent->comment(); + } + + qApp->clipboard()->setText(torrentComments.join(u"\n---------\n"_s)); +} + void TransferListWidget::hideQueuePosColumn(bool hide) { setColumnHidden(TransferListModel::TR_QUEUE_POSITION, hide); @@ -986,6 +998,8 @@ void TransferListWidget::displayListMenu() connect(actionCopyMagnetLink, &QAction::triggered, this, &TransferListWidget::copySelectedMagnetURIs); auto *actionCopyID = new QAction(UIThemeManager::instance()->getIcon(u"help-about"_s, u"edit-copy"_s), tr("Torrent &ID"), listMenu); connect(actionCopyID, &QAction::triggered, this, &TransferListWidget::copySelectedIDs); + auto *actionCopyComment = new QAction(UIThemeManager::instance()->getIcon(u"edit-copy"_s), tr("&Comment"), listMenu); + connect(actionCopyComment, &QAction::triggered, this, &TransferListWidget::copySelectedComments); auto *actionCopyName = new QAction(UIThemeManager::instance()->getIcon(u"name"_s, u"edit-copy"_s), tr("&Name"), listMenu); connect(actionCopyName, &QAction::triggered, this, &TransferListWidget::copySelectedNames); auto *actionCopyHash1 = new QAction(UIThemeManager::instance()->getIcon(u"hash"_s, u"edit-copy"_s), tr("Info &hash v1"), listMenu); @@ -1277,6 +1291,7 @@ void TransferListWidget::displayListMenu() actionCopyHash2->setEnabled(hasInfohashV2); copySubMenu->addAction(actionCopyMagnetLink); copySubMenu->addAction(actionCopyID); + copySubMenu->addAction(actionCopyComment); actionExportTorrent->setToolTip(tr("Exported torrent is not necessarily the same as the imported")); listMenu->addAction(actionExportTorrent); diff --git a/src/gui/transferlistwidget.h b/src/gui/transferlistwidget.h index ad9b0f37b..88a00662b 100644 --- a/src/gui/transferlistwidget.h +++ b/src/gui/transferlistwidget.h @@ -86,6 +86,7 @@ public slots: void copySelectedNames() const; void copySelectedInfohashes(CopyInfohashPolicy policy) const; void copySelectedIDs() const; + void copySelectedComments() const; void openSelectedTorrentsFolder() const; void recheckSelectedTorrents(); void reannounceSelectedTorrents(); diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 604b301b5..15c4007af 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -160,6 +160,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) {KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()}, {KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()}, {KEY_TORRENT_REANNOUNCE, torrent.nextAnnounce()}, + {KEY_TORRENT_COMMENT, torrent.comment()}, {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()} }; diff --git a/src/webui/api/serialize/serialize_torrent.h b/src/webui/api/serialize/serialize_torrent.h index d5ac92999..3a67551a9 100644 --- a/src/webui/api/serialize/serialize_torrent.h +++ b/src/webui/api/serialize/serialize_torrent.h @@ -91,5 +91,6 @@ inline const QString KEY_TORRENT_TIME_ACTIVE = u"time_active"_s; inline const QString KEY_TORRENT_SEEDING_TIME = u"seeding_time"_s; inline const QString KEY_TORRENT_AVAILABILITY = u"availability"_s; inline const QString KEY_TORRENT_REANNOUNCE = u"reannounce"_s; +inline const QString KEY_TORRENT_COMMENT = u"comment"_s; QVariantMap serialize(const BitTorrent::Torrent &torrent); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 9aa01c063..768ffac2f 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -180,6 +180,7 @@
  • QBT_TR(Info hash v2)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Info hash v2)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Magnet link)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Magnet link)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget]
  • +
  • QBT_TR(Comment)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Comment)QBT_TR[CONTEXT=TransferListWidget]
  • diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 0f07d8aba..c4b8bebe8 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1528,6 +1528,8 @@ function setupCopyEventHandler() { return copyMagnetLinkFN(); case "copyID": return copyIdFN(); + case "copyComment": + return copyCommentFN(); default: return ""; } diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 217a3bb91..cfda9444b 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -89,6 +89,7 @@ let copyNameFN = function() {}; let copyInfohashFN = function(policy) {}; let copyMagnetLinkFN = function() {}; let copyIdFN = function() {}; +let copyCommentFN = function() {}; let setQueuePositionFN = function() {}; let exportTorrentFN = function() {}; @@ -1005,6 +1006,21 @@ const initializeWindows = function() { return torrentsTable.selectedRowsIds().join("\n"); }; + copyCommentFN = function() { + const selectedRows = torrentsTable.selectedRowsIds(); + const comments = []; + if (selectedRows.length > 0) { + const rows = torrentsTable.getFilteredAndSortedRows(); + for (let i = 0; i < selectedRows.length; ++i) { + const hash = selectedRows[i]; + const comment = rows[hash].full_data.comment; + if (comment && (comment !== "")) + comments.push(comment); + } + } + return comments.join("\n---------\n"); + }; + exportTorrentFN = async function() { const hashes = torrentsTable.selectedRowsIds(); for (const hash of hashes) {