From 71f83cf9ba3a4d9ac38598c4f70fd5b3ce968de9 Mon Sep 17 00:00:00 2001 From: skomerko <168652295+skomerko@users.noreply.github.com> Date: Sat, 9 Nov 2024 09:03:20 +0100 Subject: [PATCH] WebUI: Display torrent progress percentage in General tab This PR adds torrent progress percentage next to pieces bar in General tab, as in the GUI. PR #21756. --- src/webui/api/torrentscontroller.cpp | 4 +++- src/webui/www/private/css/style.css | 16 ++++++++++++++++ src/webui/www/private/scripts/prop-general.js | 3 +++ src/webui/www/private/views/properties.html | 13 +++++-------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 15407cf00..a34971da0 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -116,6 +116,7 @@ const QString KEY_PROP_SSL_CERTIFICATE = u"ssl_certificate"_s; const QString KEY_PROP_SSL_PRIVATEKEY = u"ssl_private_key"_s; const QString KEY_PROP_SSL_DHPARAMS = u"ssl_dh_params"_s; const QString KEY_PROP_HAS_METADATA = u"has_metadata"_s; +const QString KEY_PROP_PROGRESS = u"progress"_s; // File keys @@ -503,7 +504,8 @@ void TorrentsController::propertiesAction() {KEY_PROP_SAVE_PATH, torrent->savePath().toString()}, {KEY_PROP_DOWNLOAD_PATH, torrent->downloadPath().toString()}, {KEY_PROP_COMMENT, torrent->comment()}, - {KEY_PROP_HAS_METADATA, torrent->hasMetadata()} + {KEY_PROP_HAS_METADATA, torrent->hasMetadata()}, + {KEY_PROP_PROGRESS, torrent->progress()} }; setResult(ret); diff --git a/src/webui/www/private/css/style.css b/src/webui/www/private/css/style.css index 6872d6766..18904a3d8 100644 --- a/src/webui/www/private/css/style.css +++ b/src/webui/www/private/css/style.css @@ -700,6 +700,22 @@ td.generalLabel { padding: 2px; } +#propProgressWrapper { + align-items: center; + display: flex; + height: auto; + margin: 5px 2px; + + & > span:not(:first-child, :empty) { + margin-left: 6px; + min-width: 3.5em; + } + + & #progress { + flex: 1; + } +} + .piecesbarWrapper { position: relative; width: 100%; diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index 5d0e0a324..c0c407e06 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -43,6 +43,7 @@ window.qBittorrent.PropGeneral ??= (() => { $("progress").appendChild(piecesBar); const clearData = () => { + document.getElementById("progressPercentage").textContent = ""; $("time_elapsed").textContent = ""; $("eta").textContent = ""; $("nb_connections").textContent = ""; @@ -101,6 +102,8 @@ window.qBittorrent.PropGeneral ??= (() => { if (data) { // Update Torrent data + document.getElementById("progressPercentage").textContent = window.qBittorrent.Misc.friendlyPercentage(data.progress); + const timeElapsed = (data.seeding_time > 0) ? "QBT_TR(%1 (seeded for %2))QBT_TR[CONTEXT=PropertiesWidget]" .replace("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed)) diff --git a/src/webui/www/private/views/properties.html b/src/webui/www/private/views/properties.html index f3f9a232d..e3cb42b1b 100644 --- a/src/webui/www/private/views/properties.html +++ b/src/webui/www/private/views/properties.html @@ -1,12 +1,9 @@