Provide v1 and v2 infohashes in UI (#15097)

This commit is contained in:
Vladimir Golovnev
2021-06-25 20:44:23 +03:00
committed by GitHub
parent f6eb29d800
commit 37f227ae74
24 changed files with 285 additions and 106 deletions

View File

@@ -96,8 +96,9 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
};
return {
// TODO: Add fields for real SHA1 and SHA256 hashes
{KEY_TORRENT_ID, QString(torrent.id().toString())},
{KEY_TORRENT_ID, torrent.id().toString()},
{KEY_TORRENT_INFOHASHV1, torrent.infoHash().v1().toString()},
{KEY_TORRENT_INFOHASHV2, torrent.infoHash().v2().toString()},
{KEY_TORRENT_NAME, torrent.name()},
{KEY_TORRENT_MAGNET_URI, torrent.createMagnetURI()},
{KEY_TORRENT_SIZE, torrent.wantedSize()},

View File

@@ -36,7 +36,10 @@ namespace BitTorrent
}
// Torrent keys
// TODO: Rename it to `id`.
inline const char KEY_TORRENT_ID[] = "hash";
inline const char KEY_TORRENT_INFOHASHV1[] = "infohash_v1";
inline const char KEY_TORRENT_INFOHASHV2[] = "infohash_v2";
inline const char KEY_TORRENT_NAME[] = "name";
inline const char KEY_TORRENT_MAGNET_URI[] = "magnet_uri";
inline const char KEY_TORRENT_SIZE[] = "size";

View File

@@ -382,6 +382,8 @@ void TorrentsController::propertiesAction()
QJsonObject dataDict;
dataDict[KEY_TORRENT_INFOHASHV1] = torrent->infoHash().v1().toString();
dataDict[KEY_TORRENT_INFOHASHV2] = torrent->infoHash().v2().toString();
dataDict[KEY_PROP_TIME_ELAPSED] = torrent->activeTime();
dataDict[KEY_PROP_SEEDING_TIME] = torrent->seedingTime();
dataDict[KEY_PROP_ETA] = static_cast<double>(torrent->eta());

View File

@@ -166,8 +166,10 @@
<a href="#" class="arrow-right"><img src="icons/edit-copy.svg" alt="QBT_TR(Copy)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Copy)QBT_TR[CONTEXT=TransferListWidget]</a>
<ul>
<li><a href="#" id="copyName" class="copyToClipboard"><img src="icons/edit-copy.svg" alt="QBT_TR(Name)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Name)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyHash" class="copyToClipboard"><img src="icons/edit-copy.svg" alt="QBT_TR(Hash)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Hash)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyInfohash1" class="copyToClipboard"><img src="icons/edit-copy.svg" alt="QBT_TR(Info hash v1)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Info hash v1)QBT_TR[CONTEXT=TransferListWidget]</a></li>
<li><a href="#" id="copyInfohash2" class="copyToClipboard"><img src="icons/edit-copy.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="icons/kt-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="icons/edit-copy.svg" alt="QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget]" /> QBT_TR(Torrent ID)QBT_TR[CONTEXT=TransferListWidget]</a></li>
</ul>
</li>
</ul>

View File

@@ -1201,10 +1201,14 @@ function setupCopyEventHandler() {
switch (trigger.id) {
case "copyName":
return copyNameFN();
case "copyInfohash1":
return copyInfohashFN(1);
case "copyInfohash2":
return copyInfohashFN(2);
case "copyMagnetLink":
return copyMagnetLinkFN();
case "copyHash":
return copyHashFN();
case "copyID":
return copyIdFN();
default:
return "";
}

View File

@@ -1383,7 +1383,7 @@ window.qBittorrent.DynamicTable = (function() {
tr.addClass("torrentsTableContextMenuTarget");
},
getCurrentTorrentHash: function() {
getCurrentTorrentID: function() {
return this.getSelectedRowId();
},

View File

@@ -84,8 +84,9 @@ let resumeTorrentsByTrackerFN = function() {};
let pauseTorrentsByTrackerFN = function() {};
let deleteTorrentsByTrackerFN = function() {};
let copyNameFN = function() {};
let copyInfohashFN = function(policy) {};
let copyMagnetLinkFN = function() {};
let copyHashFN = function() {};
let copyIdFN = function() {};
let setQueuePositionFN = function() {};
const initializeWindows = function() {
@@ -905,7 +906,7 @@ const initializeWindows = function() {
copyNameFN = function() {
const selectedRows = torrentsTable.selectedRowsIds();
const names = [];
if (selectedRows.length) {
if (selectedRows.length > 0) {
const rows = torrentsTable.getFilteredAndSortedRows();
for (let i = 0; i < selectedRows.length; ++i) {
const hash = selectedRows[i];
@@ -915,10 +916,35 @@ const initializeWindows = function() {
return names.join("\n");
};
copyInfohashFN = function(policy) {
const selectedRows = torrentsTable.selectedRowsIds();
const infohashes = [];
if (selectedRows.length > 0) {
const rows = torrentsTable.getFilteredAndSortedRows();
switch (policy) {
case 1:
for (const id of selectedRows) {
const infohash = rows[id].full_data.infohash_v1;
if (infohash !== "")
infohashes.push(infohash);
}
break;
case 2:
for (const id of selectedRows) {
const infohash = rows[id].full_data.infohash_v2;
if (infohash !== "")
infohashes.push(infohash);
}
break;
}
}
return infohashes.join("\n");
};
copyMagnetLinkFN = function() {
const selectedRows = torrentsTable.selectedRowsIds();
const magnets = [];
if (selectedRows.length) {
if (selectedRows.length > 0) {
const rows = torrentsTable.getFilteredAndSortedRows();
for (let i = 0; i < selectedRows.length; ++i) {
const hash = selectedRows[i];
@@ -928,7 +954,7 @@ const initializeWindows = function() {
return magnets.join("\n");
};
copyHashFN = function() {
copyIdFN = function() {
return torrentsTable.selectedRowsIds().join("\n");
};

View File

@@ -343,7 +343,7 @@ window.qBittorrent.PropFiles = (function() {
// Tab changed, don't do anything
return;
}
const new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentID();
if (new_hash === "") {
torrentFilesTable.clear();
clearTimeout(loadTorrentFilesDataTimer);
@@ -527,7 +527,7 @@ window.qBittorrent.PropFiles = (function() {
menu: 'torrentFilesMenu',
actions: {
Rename: function(element, ref) {
const hash = torrentsTable.getCurrentTorrentHash();
const hash = torrentsTable.getCurrentTorrentID();
if (!hash) return;
const rowId = torrentFilesTable.selectedRowsIds()[0];
if (rowId === undefined) return;

View File

@@ -61,7 +61,8 @@ window.qBittorrent.PropGeneral = (function() {
$('addition_date').set('html', '');
$('completion_date').set('html', '');
$('creation_date').set('html', '');
$('torrent_hash').set('html', '');
$('torrent_hash_v1').set('html', '');
$('torrent_hash_v2').set('html', '');
$('save_path').set('html', '');
$('comment').set('html', '');
};
@@ -73,16 +74,14 @@ window.qBittorrent.PropGeneral = (function() {
// Tab changed, don't do anything
return;
}
const current_hash = torrentsTable.getCurrentTorrentHash();
if (current_hash === "") {
const current_id = torrentsTable.getCurrentTorrentID();
if (current_id === "") {
clearData();
clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000);
return;
}
// Display hash
$('torrent_hash').set('html', current_hash);
const url = new URI('api/v2/torrents/properties?hash=' + current_hash);
const url = new URI('api/v2/torrents/properties?hash=' + current_id);
new Request.JSON({
url: url,
noCache: true,
@@ -191,6 +190,18 @@ window.qBittorrent.PropGeneral = (function() {
temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
$('creation_date').set('html', temp);
if (data.infohash_v1 === "")
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
else
temp = data.infohash_v1;
$('torrent_hash_v1').set('html', temp);
if (data.infohash_v2 === "")
temp = "QBT_TR(N/A)QBT_TR[CONTEXT=PropertiesWidget]";
else
temp = data.infohash_v2;
$('torrent_hash_v2').set('html', temp);
$('save_path').set('html', data.save_path);
$('comment').set('html', window.qBittorrent.Misc.parseHtmlLinks(window.qBittorrent.Misc.escapeHtml(data.comment)));

View File

@@ -51,7 +51,7 @@ window.qBittorrent.PropPeers = (function() {
torrentPeersTable.clear();
return;
}
const current_hash = torrentsTable.getCurrentTorrentHash();
const current_hash = torrentsTable.getCurrentTorrentID();
if (current_hash === "") {
syncTorrentPeersLastResponseId = 0;
torrentPeersTable.clear();
@@ -118,7 +118,7 @@ window.qBittorrent.PropPeers = (function() {
menu: 'torrentPeersMenu',
actions: {
addPeer: function(element, ref) {
const hash = torrentsTable.getCurrentTorrentHash();
const hash = torrentsTable.getCurrentTorrentID();
if (!hash)
return;
@@ -147,7 +147,7 @@ window.qBittorrent.PropPeers = (function() {
noCache: true,
method: 'post',
data: {
hash: torrentsTable.getCurrentTorrentHash(),
hash: torrentsTable.getCurrentTorrentID(),
peers: selectedPeers.join('|')
}
}).send();

View File

@@ -50,7 +50,7 @@ window.qBittorrent.PropTrackers = (function() {
// Tab changed, don't do anything
return;
}
const new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentID();
if (new_hash === "") {
torrentTrackersTable.clear();
clearTimeout(loadTrackersDataTimer);

View File

@@ -100,7 +100,7 @@ window.qBittorrent.PropWebseeds = (function() {
// Tab changed, don't do anything
return;
}
const new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentID();
if (new_hash === "") {
wsTable.removeAllRows();
clearTimeout(loadWebSeedsDataTimer);

View File

@@ -209,7 +209,9 @@
<li>QBT_TR(%C: Number of files)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%Z: Torrent size (bytes))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%T: Current tracker)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%I: Info hash)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%I: Info hash v1)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%J: Info hash v2)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%K: Torrent ID)QBT_TR[CONTEXT=OptionsDialog]</li>
</ul>
QBT_TR(Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., "%N"))QBT_TR[CONTEXT=OptionsDialog]
</div>

View File

@@ -64,8 +64,12 @@
<td id="creation_date"></td>
</tr>
<tr>
<td class="generalLabel">QBT_TR(Torrent Hash:)QBT_TR[CONTEXT=PropertiesWidget]</td>
<td colspan="5" id="torrent_hash"></td>
<td class="generalLabel">QBT_TR(Info Hash v1:)QBT_TR[CONTEXT=PropertiesWidget]</td>
<td colspan="5" id="torrent_hash_v1"></td>
</tr>
<tr>
<td class="generalLabel">QBT_TR(Info Hash v2:)QBT_TR[CONTEXT=PropertiesWidget]</td>
<td colspan="5" id="torrent_hash_v2"></td>
</tr>
<tr>
<td class="generalLabel">QBT_TR(Save Path:)QBT_TR[CONTEXT=PropertiesWidget]</td>