Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy comment functionality to the torrent list's context menu #19846

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/gui/transferlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment can span multiple lines and even contain empty lines. Is something like this acceptable or even desirable to differentiate comments from each other?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use it until someone has a better idea.

}

void TransferListWidget::hideQueuePosColumn(bool hide)
{
setColumnHidden(TransferListModel::TR_QUEUE_POSITION, hide);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/gui/transferlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/webui/api/serialize/serialize_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Chocobo1 marked this conversation as resolved.
Show resolved Hide resolved

{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
};
Expand Down
1 change: 1 addition & 0 deletions src/webui/api/serialize/serialize_torrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Chocobo1 marked this conversation as resolved.
Show resolved Hide resolved

QVariantMap serialize(const BitTorrent::Torrent &torrent);
2 changes: 1 addition & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"

inline const Utils::Version<3, 2> API_VERSION {2, 10, 0};
inline const Utils::Version<3, 2> API_VERSION {2, 10, 1};

class APIController;
class AuthController;
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version
<li><a href="#" id="copyInfohash2" class="copyToClipboard"><img src="images/hash.svg" alt="QBT_TR(Info hash v2)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Info hash v2)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyMagnetLink" class="copyToClipboard"><img src="images/torrent-magnet.svg" alt="QBT_TR(Magnet link)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Magnet link)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyID" class="copyToClipboard"><img src="images/help-about.svg" alt="QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyComment" class="copyToClipboard"><img src="images/edit-copy.svg" alt="QBT_TR(Comment)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Comment)QBT_TR[CONTEXT=TransferListWidget]</a></li>
</ul>
</li>
<li>
Expand Down
2 changes: 2 additions & 0 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,8 @@ function setupCopyEventHandler() {
return copyMagnetLinkFN();
case "copyID":
return copyIdFN();
case "copyComment":
return copyCommentFN();
default:
return "";
}
Expand Down
16 changes: 16 additions & 0 deletions src/webui/www/private/scripts/mocha-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};

Expand Down Expand Up @@ -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) {
Expand Down