From 560ecbc6c37a5950114a322c87fcd1e8f744c972 Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 11 Mar 2021 16:47:59 +0200 Subject: [PATCH 1/3] Add seeding time to the active time column in WebUI Closes #14526 --- src/webui/api/serialize/serialize_torrent.cpp | 1 + src/webui/api/serialize/serialize_torrent.h | 1 + src/webui/www/private/scripts/dynamicTable.js | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index d39115091..7f64d37c8 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -147,6 +147,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) {KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, torrent.lastSeenComplete().toSecsSinceEpoch()}, {KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()}, {KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()}, + {KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()}, {KEY_TORRENT_LAST_ACTIVITY_TIME, adjustLastActivity(torrent.timeSinceActivity())}, {KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()}, diff --git a/src/webui/api/serialize/serialize_torrent.h b/src/webui/api/serialize/serialize_torrent.h index 1db455af1..84c53c2ae 100644 --- a/src/webui/api/serialize/serialize_torrent.h +++ b/src/webui/api/serialize/serialize_torrent.h @@ -80,6 +80,7 @@ const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity"; const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm"; const char KEY_TORRENT_TIME_ACTIVE[] = "time_active"; +const char KEY_TORRENT_SEEDING_TIME[] = "seeding_time"; const char KEY_TORRENT_AVAILABILITY[] = "availability"; QVariantMap serialize(const BitTorrent::Torrent &torrent); diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 368eb6efd..e868708c9 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -856,6 +856,7 @@ window.qBittorrent.DynamicTable = (function() { this.columns['num_seeds'].dataProperties.push('num_complete'); this.columns['num_leechs'].dataProperties.push('num_incomplete'); + this.columns['time_active'].dataProperties.push('seeding_time'); this.initColumnsFunctions(); }, @@ -1161,7 +1162,13 @@ window.qBittorrent.DynamicTable = (function() { // time active this.columns['time_active'].updateTd = function(td, row) { - const time = window.qBittorrent.Misc.friendlyDuration(this.getRowValue(row)); + const activeTime = this.getRowValue(row, 0); + const seedingTime = this.getRowValue(row, 1); + const time = (seedingTime > 0) + ? ('QBT_TR(%1 (seeded for %2))QBT_TR[CONTEXT=TransferListDelegate]' + .replace('%1', window.qBittorrent.Misc.friendlyDuration(activeTime)) + .replace('%2', window.qBittorrent.Misc.friendlyDuration(seedingTime))) + : window.qBittorrent.Misc.friendlyDuration(activeTime); td.set('text', time); td.set('title', time); }; From 9f30aba2b3018dc0d5f032599a6620a0dbf786c5 Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 11 Mar 2021 16:48:51 +0200 Subject: [PATCH 2/3] Fix incorrect seeding time string in WebUI General tab --- src/webui/www/private/scripts/prop-general.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index 07a93c6e8..f820e553a 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -98,7 +98,7 @@ window.qBittorrent.PropGeneral = (function() { let temp; // Update Torrent data if (data.seeding_time > 0) - temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" + temp = "QBT_TR(%1 (seeded for %2))QBT_TR[CONTEXT=PropertiesWidget]" .replace("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed)) .replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time)); else From d1240417263bffd0349b8e7f5ca15609b1cdc9f5 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 12 Mar 2021 18:28:07 +0200 Subject: [PATCH 3/3] Allow >100 days in WebUI function "friendlyDuration" Because it's not only used for ETA. --- src/webui/www/private/scripts/dynamicTable.js | 2 +- src/webui/www/private/scripts/misc.js | 18 +++++++++++------- src/webui/www/private/scripts/prop-general.js | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index e868708c9..42c016881 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -1103,7 +1103,7 @@ window.qBittorrent.DynamicTable = (function() { // eta this.columns['eta'].updateTd = function(td, row) { - const eta = window.qBittorrent.Misc.friendlyDuration(this.getRowValue(row)); + const eta = window.qBittorrent.Misc.friendlyDuration(this.getRowValue(row), window.qBittorrent.Misc.MAX_ETA)); td.set('text', eta); td.set('title', eta); }; diff --git a/src/webui/www/private/scripts/misc.js b/src/webui/www/private/scripts/misc.js index 1671f1525..f9fd8f9f8 100644 --- a/src/webui/www/private/scripts/misc.js +++ b/src/webui/www/private/scripts/misc.js @@ -43,7 +43,8 @@ window.qBittorrent.Misc = (function() { escapeHtml: escapeHtml, safeTrim: safeTrim, toFixedPointString: toFixedPointString, - containsAllTerms: containsAllTerms + containsAllTerms: containsAllTerms, + MAX_ETA: 8640000 }; }; @@ -94,9 +95,8 @@ window.qBittorrent.Misc = (function() { /* * JS counterpart of the function in src/misc.cpp */ - const friendlyDuration = function(seconds) { - const MAX_ETA = 8640000; - if (seconds < 0 || seconds >= MAX_ETA) + const friendlyDuration = function(seconds, maxCap = -1) { + if (seconds < 0 || ((seconds >= maxCap) && (maxCap >= 0))) return "∞"; if (seconds === 0) return "0"; @@ -109,11 +109,13 @@ window.qBittorrent.Misc = (function() { minutes = minutes % 60; if (hours < 24) return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes)); - const days = hours / 24; + let days = hours / 24; hours = hours % 24; - if (days < 100) + if (days < 365) return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours)); - return "∞"; + const years = days / 365; + days = days % 365; + return "QBT_TR(%1y %2d)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(years)).replace("%2", parseInt(days)); } const friendlyPercentage = function(value) { @@ -213,3 +215,5 @@ window.qBittorrent.Misc = (function() { return exports(); })(); + +Object.freeze(window.qBittorrent.Misc); diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index f820e553a..69285d0d9 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -105,7 +105,7 @@ window.qBittorrent.PropGeneral = (function() { temp = window.qBittorrent.Misc.friendlyDuration(data.time_elapsed); $('time_elapsed').set('html', temp); - $('eta').set('html', window.qBittorrent.Misc.friendlyDuration(data.eta)); + $('eta').set('html', window.qBittorrent.Misc.friendlyDuration(data.eta, window.qBittorrent.Misc.MAX_ETA)); temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]" .replace("%1", data.nb_connections)