Browse Source

Add copy options to webui context menu (addresses #6815) (#7036)

* Add copy options to webui context menu
Add Copy Hash to gui (closes #6964)

* Use switch statement

* Use camel case, switch from signal to qaction.

* Rename variable

* Change variable name
adaptive-webui-19844
Tom Piccirello 7 years ago committed by Mike Tzou
parent
commit
145641ac41
  1. 12
      src/gui/transferlistwidget.cpp
  2. 1
      src/gui/transferlistwidget.h
  3. 2
      src/webui/btjson.cpp
  4. 1
      src/webui/webui.qrc
  5. 4
      src/webui/www/private/index.html
  6. 33
      src/webui/www/public/scripts/client.js
  7. 7
      src/webui/www/public/scripts/clipboard.min.js
  8. 30
      src/webui/www/public/scripts/mocha-init.js

12
src/gui/transferlistwidget.cpp

@ -527,6 +527,15 @@ void TransferListWidget::copySelectedNames() const @@ -527,6 +527,15 @@ void TransferListWidget::copySelectedNames() const
qApp->clipboard()->setText(torrent_names.join("\n"));
}
void TransferListWidget::copySelectedHashes() const
{
QStringList torrentHashes;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
torrentHashes << torrent->hash();
qApp->clipboard()->setText(torrentHashes.join('\n'));
}
void TransferListWidget::hidePriorityColumn(bool hide)
{
qDebug("hidePriorityColumn(%d)", hide);
@ -870,6 +879,8 @@ void TransferListWidget::displayListMenu(const QPoint&) @@ -870,6 +879,8 @@ void TransferListWidget::displayListMenu(const QPoint&)
connect(&actionCopy_magnet_link, SIGNAL(triggered()), this, SLOT(copySelectedMagnetURIs()));
QAction actionCopy_name(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy name"), 0);
connect(&actionCopy_name, SIGNAL(triggered()), this, SLOT(copySelectedNames()));
QAction actionCopyHash(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy hash"), 0);
connect(&actionCopyHash, &QAction::triggered, this, &TransferListWidget::copySelectedHashes);
QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0);
actionSuper_seeding_mode.setCheckable(true);
connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding()));
@ -1081,6 +1092,7 @@ void TransferListWidget::displayListMenu(const QPoint&) @@ -1081,6 +1092,7 @@ void TransferListWidget::displayListMenu(const QPoint&)
listMenu.addSeparator();
listMenu.addAction(&actionCopy_name);
listMenu.addAction(&actionCopy_magnet_link);
listMenu.addAction(&actionCopyHash);
// Call menu
QAction *act = 0;
act = listMenu.exec(QCursor::pos());

1
src/gui/transferlistwidget.h

@ -82,6 +82,7 @@ public slots: @@ -82,6 +82,7 @@ public slots:
void bottomPrioSelectedTorrents();
void copySelectedMagnetURIs() const;
void copySelectedNames() const;
void copySelectedHashes() const;
void openSelectedTorrentsFolder() const;
void recheckSelectedTorrents();
void setDlLimitSelectedTorrents();

2
src/webui/btjson.cpp

@ -76,6 +76,7 @@ static const int CACHE_DURATION_MS = 1500; // 1500ms @@ -76,6 +76,7 @@ static const int CACHE_DURATION_MS = 1500; // 1500ms
// Torrent keys
static const char KEY_TORRENT_HASH[] = "hash";
static const char KEY_TORRENT_NAME[] = "name";
static const char KEY_TORRENT_MAGNET_URI[] = "magnet_uri";
static const char KEY_TORRENT_SIZE[] = "size";
static const char KEY_TORRENT_PROGRESS[] = "progress";
static const char KEY_TORRENT_DLSPEED[] = "dlspeed";
@ -789,6 +790,7 @@ QVariantMap toMap(BitTorrent::TorrentHandle *const torrent) @@ -789,6 +790,7 @@ QVariantMap toMap(BitTorrent::TorrentHandle *const torrent)
QVariantMap ret;
ret[KEY_TORRENT_HASH] = QString(torrent->hash());
ret[KEY_TORRENT_NAME] = torrent->name();
ret[KEY_TORRENT_MAGNET_URI] = torrent->toMagnetUri();
ret[KEY_TORRENT_SIZE] = torrent->wantedSize();
ret[KEY_TORRENT_PROGRESS] = torrent->progress();
ret[KEY_TORRENT_DLSPEED] = torrent->downloadPayloadRate();

1
src/webui/webui.qrc

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
<file>www/public/css/Tabs.css</file>
<file>www/public/css/Window.css</file>
<file>www/public/scripts/client.js</file>
<file>www/public/scripts/clipboard.min.js</file>
<file>www/public/scripts/contextmenu.js</file>
<file>www/public/scripts/download.js</file>
<file>www/public/scripts/dynamicTable.js</file>

4
src/webui/www/private/index.html

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
<![endif]-->
<script type="text/javascript" src="scripts/mocha-yc.js"></script>
<script type="text/javascript" src="scripts/mocha-init.js"></script>
<script type="text/javascript" src="scripts/clipboard.min.js"></script>
<script type="text/javascript" src="scripts/misc.js"></script>
<script type="text/javascript" src="scripts/progressbar.js"></script>
<script type="text/javascript" src="scripts/dynamicTable.js" charset="utf-8"></script>
@ -125,6 +126,9 @@ @@ -125,6 +126,9 @@
<li class="separator"><a href="#SequentialDownload"><img src="theme/checked" alt="QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#FirstLastPiecePrio"><img src="theme/checked" alt="QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li class="separator"><a href="#ForceRecheck"><img src="theme/document-edit-verify" alt="QBT_TR(Force recheck)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Force recheck)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li class="separator"><a href="#" id="CopyName" class="copyToClipboard"><img src="theme/edit-copy" alt="QBT_TR(Copy name)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Copy name)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="CopyMagnetLink" class="copyToClipboard"><img src="theme/kt-magnet" alt="QBT_TR(Copy magnet link)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Copy magnet link)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="CopyHash" class="copyToClipboard"><img src="theme/kt-magnet" alt="QBT_TR(Copy hash)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Copy hash)QBT_TR[CONTEXT=TransferListWidget]</a></li>
</ul>
<ul id="categoriesFilterMenu" class="contextMenu">
<li><a href="#CreateCategory"><img src="theme/list-add" alt="QBT_TR(Add category...)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Add category...)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>

33
src/webui/www/public/scripts/client.js

@ -38,6 +38,8 @@ var alternativeSpeedLimits = false; @@ -38,6 +38,8 @@ var alternativeSpeedLimits = false;
var queueing_enabled = true;
var syncMainDataTimerPeriod = 1500;
var clipboardEvent;
var CATEGORIES_ALL = 1;
var CATEGORIES_UNCATEGORIZED = 2;
@ -309,6 +311,7 @@ window.addEvent('load', function () { @@ -309,6 +311,7 @@ window.addEvent('load', function () {
update_categories = true;
}
if (response['torrents']) {
var updateTorrentList = false;
for (var key in response['torrents']) {
response['torrents'][key]['hash'] = key;
response['torrents'][key]['rowId'] = key;
@ -317,7 +320,12 @@ window.addEvent('load', function () { @@ -317,7 +320,12 @@ window.addEvent('load', function () {
torrentsTable.updateRowData(response['torrents'][key]);
if (addTorrentToCategoryList(response['torrents'][key]))
update_categories = true;
if (response['torrents'][key]['name'])
updateTorrentList = true;
}
if (updateTorrentList)
setupCopyEventHandler();
}
if (response['torrents_removed'])
response['torrents_removed'].each(function (hash) {
@ -590,6 +598,31 @@ function closeWindows() { @@ -590,6 +598,31 @@ function closeWindows() {
MochaUI.closeAll();
}
function setupCopyEventHandler() {
if (clipboardEvent)
clipboardEvent.destroy();
clipboardEvent = new Clipboard('.copyToClipboard', {
text: function(trigger) {
var textToCopy;
switch (trigger.id) {
case "CopyName":
textToCopy = copyNameFN();
break;
case "CopyMagnetLink":
textToCopy = copyMagnetLinkFN();
break;
case "CopyHash":
textToCopy = copyHashFN();
break;
}
return textToCopy;
}
});
}
var keyboardEvents = new Keyboard({
defaultEventType: 'keydown',
events: {

7
src/webui/www/public/scripts/clipboard.min.js vendored

File diff suppressed because one or more lines are too long

30
src/webui/www/public/scripts/mocha-init.js

@ -451,6 +451,36 @@ initializeWindows = function() { @@ -451,6 +451,36 @@ initializeWindows = function() {
}
};
copyNameFN = function() {
var selectedRows = torrentsTable.selectedRowsIds();
var names = [];
if (selectedRows.length) {
var rows = torrentsTable.getFilteredAndSortedRows();
for (var i = 0; i < selectedRows.length; i++) {
var hash = selectedRows[i];
names.push(rows[hash].full_data.name);
}
}
return names.join("\n");
};
copyMagnetLinkFN = function() {
var selectedRows = torrentsTable.selectedRowsIds();
var magnets = [];
if (selectedRows.length) {
var rows = torrentsTable.getFilteredAndSortedRows();
for (var i = 0; i < selectedRows.length; i++) {
var hash = selectedRows[i];
magnets.push(rows[hash].full_data.magnet_uri);
}
}
return magnets.join("\n");
};
copyHashFN = function() {
return torrentsTable.selectedRowsIds().join("\n");
};
['pauseAll', 'resumeAll'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();

Loading…
Cancel
Save