From 3f0fbc08102520d225f4e96c7070f7d71e5a057c Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 14 Mar 2018 00:37:48 -0400 Subject: [PATCH 1/3] WebUI rename property to match its definition --- src/webui/api/serialize/serialize_torrent.cpp | 2 +- src/webui/api/serialize/serialize_torrent.h | 2 +- src/webui/api/synccontroller.cpp | 2 +- src/webui/www/private/scripts/dynamicTable.js | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index d28b20a55..82e2a18a4 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -120,7 +120,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent) ret[KEY_TORRENT_AMOUNT_UPLOADED_SESSION] = torrent.totalPayloadUpload(); ret[KEY_TORRENT_AMOUNT_LEFT] = torrent.incompletedSize(); ret[KEY_TORRENT_AMOUNT_COMPLETED] = torrent.completedSize(); - ret[KEY_TORRENT_RATIO_LIMIT] = torrent.maxRatio(); + ret[KEY_TORRENT_MAX_RATIO] = torrent.maxRatio(); ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent.lastSeenComplete().toTime_t(); ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent.isAutoTMMEnabled(); ret[KEY_TORRENT_TIME_ACTIVE] = torrent.activeTime(); diff --git a/src/webui/api/serialize/serialize_torrent.h b/src/webui/api/serialize/serialize_torrent.h index 8f861637a..cbc9a2af2 100644 --- a/src/webui/api/serialize/serialize_torrent.h +++ b/src/webui/api/serialize/serialize_torrent.h @@ -69,7 +69,7 @@ const char KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION[] = "downloaded_session"; const char KEY_TORRENT_AMOUNT_UPLOADED_SESSION[] = "uploaded_session"; const char KEY_TORRENT_AMOUNT_LEFT[] = "amount_left"; const char KEY_TORRENT_AMOUNT_COMPLETED[] = "completed"; -const char KEY_TORRENT_RATIO_LIMIT[] = "ratio_limit"; +const char KEY_TORRENT_MAX_RATIO[] = "max_ratio"; const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[] = "seen_complete"; const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity"; const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index f88fbd51a..19533fdbb 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -351,7 +351,7 @@ namespace // - "amount_left": Amount of data left to download // - "save_path": Torrent save path // - "completed": Amount of data completed -// - "ratio_limit": Upload share ratio limit +// - "max_ratio": Upload max share ratio // - "seen_complete": Indicates the time when the torrent was last seen complete/whole // - "last_activity": Last time when a chunk was downloaded/uploaded // - "total_size": Size including unwanted data diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index ebae00c21..00b6d1c5d 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -769,7 +769,7 @@ var TorrentsTable = new Class({ this.newColumn('time_active', '', 'QBT_TR(Time Active)QBT_TR[CONTEXT=TorrentModel]', 100, false); this.newColumn('save_path', '', 'QBT_TR(Save path)QBT_TR[CONTEXT=TorrentModel]', 100, false); this.newColumn('completed', '', 'QBT_TR(Completed)QBT_TR[CONTEXT=TorrentModel]', 100, false); - this.newColumn('ratio_limit', '', 'QBT_TR(Ratio Limit)QBT_TR[CONTEXT=TorrentModel]', 100, false); + this.newColumn('max_ratio', '', 'QBT_TR(Ratio Limit)QBT_TR[CONTEXT=TorrentModel]', 100, false); this.newColumn('seen_complete', '', 'QBT_TR(Last Seen Complete)QBT_TR[CONTEXT=TorrentModel]', 100, false); this.newColumn('last_activity', '', 'QBT_TR(Last Activity)QBT_TR[CONTEXT=TorrentModel]', 100, false); @@ -1076,8 +1076,8 @@ var TorrentsTable = new Class({ this.columns['save_path'].updateTd = this.columns['name'].updateTd; this.columns['tracker'].updateTd = this.columns['name'].updateTd; - // ratio_limit - this.columns['ratio_limit'].updateTd = this.columns['ratio'].updateTd; + // max_ratio + this.columns['max_ratio'].updateTd = this.columns['ratio'].updateTd; // last_activity this.columns['last_activity'].updateTd = function(td, row) { From 1f42ab8c4f29e91852605b6717e0ccfb9e5d1ba2 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 14 Mar 2018 00:56:57 -0400 Subject: [PATCH 2/3] Remove unused/superfluous variables --- src/webui/www/private/scripts/mocha-init.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 0ea4f16af..5faa6d3c8 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -146,7 +146,6 @@ initializeWindows = function() { uploadLimitFN = function() { var hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { - var hash = hashes[0]; new MochaUI.Window({ id: 'uploadLimitPage', title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]", @@ -257,7 +256,6 @@ initializeWindows = function() { downloadLimitFN = function() { var hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { - var hash = hashes[0]; new MochaUI.Window({ id: 'downloadLimitPage', title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]", @@ -388,12 +386,11 @@ initializeWindows = function() { var hash = hashes[0]; var row = torrentsTable.rows[hash]; if (row) { - var name = row.full_data.name; new MochaUI.Window({ id: 'renamePage', title: "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]", loadMethod: 'iframe', - contentURL: 'rename.html?hash=' + hashes[0] + '&name=' + name, + contentURL: 'rename.html?hash=' + hashes[0] + '&name=' + row.full_data.name, scrollbars: false, resizable: false, maximizable: false, From 9f36b54b04458065bb6721a0f0c0a496a143c03f Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 14 Mar 2018 00:41:16 -0400 Subject: [PATCH 3/3] WebUI Add Limit Share Ratio context menu option Closes #6815, #7602. --- src/webui/api/serialize/serialize_torrent.cpp | 3 + src/webui/api/serialize/serialize_torrent.h | 3 + src/webui/api/synccontroller.cpp | 3 + src/webui/api/torrentscontroller.cpp | 15 ++ src/webui/api/torrentscontroller.h | 1 + src/webui/webui.qrc | 1 + src/webui/www/private/index.html | 1 + src/webui/www/private/scripts/misc.js | 4 + src/webui/www/private/scripts/mocha-init.js | 39 ++++ src/webui/www/private/shareratio.html | 167 ++++++++++++++++++ src/webui/www/private/transferlist.html | 3 + 11 files changed, 240 insertions(+) create mode 100644 src/webui/www/private/shareratio.html diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 82e2a18a4..124d9e1f4 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -121,6 +121,9 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent) ret[KEY_TORRENT_AMOUNT_LEFT] = torrent.incompletedSize(); ret[KEY_TORRENT_AMOUNT_COMPLETED] = torrent.completedSize(); ret[KEY_TORRENT_MAX_RATIO] = torrent.maxRatio(); + ret[KEY_TORRENT_MAX_SEEDING_TIME] = torrent.maxSeedingTime(); + ret[KEY_TORRENT_RATIO_LIMIT] = torrent.ratioLimit(); + ret[KEY_TORRENT_SEEDING_TIME_LIMIT] = torrent.seedingTimeLimit(); ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent.lastSeenComplete().toTime_t(); ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent.isAutoTMMEnabled(); ret[KEY_TORRENT_TIME_ACTIVE] = torrent.activeTime(); diff --git a/src/webui/api/serialize/serialize_torrent.h b/src/webui/api/serialize/serialize_torrent.h index cbc9a2af2..832e9e252 100644 --- a/src/webui/api/serialize/serialize_torrent.h +++ b/src/webui/api/serialize/serialize_torrent.h @@ -70,6 +70,9 @@ const char KEY_TORRENT_AMOUNT_UPLOADED_SESSION[] = "uploaded_session"; const char KEY_TORRENT_AMOUNT_LEFT[] = "amount_left"; const char KEY_TORRENT_AMOUNT_COMPLETED[] = "completed"; const char KEY_TORRENT_MAX_RATIO[] = "max_ratio"; +const char KEY_TORRENT_MAX_SEEDING_TIME[] = "max_seeding_time"; +const char KEY_TORRENT_RATIO_LIMIT[] = "ratio_limit"; +const char KEY_TORRENT_SEEDING_TIME_LIMIT[] = "seeding_time_limit"; const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[] = "seen_complete"; const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity"; const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 19533fdbb..1c2126fd2 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -352,6 +352,9 @@ namespace // - "save_path": Torrent save path // - "completed": Amount of data completed // - "max_ratio": Upload max share ratio +// - "max_seeding_time": Upload max seeding time +// - "ratio_limit": Upload share ratio limit +// - "seeding_time_limit": Upload seeding time limit // - "seen_complete": Indicates the time when the torrent was last seen complete/whole // - "last_activity": Last time when a chunk was downloaded/uploaded // - "total_size": Size including unwanted data diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 8b6f25e76..c8b6813d3 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -623,6 +623,21 @@ void TorrentsController::setDownloadLimitAction() applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *torrent) { torrent->setDownloadLimit(limit); }); } +void TorrentsController::setShareLimitsAction() +{ + checkParams({"hashes", "ratioLimit", "seedingTimeLimit"}); + + const qreal ratioLimit = params()["ratioLimit"].toDouble(); + const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong(); + const QStringList hashes = params()["hashes"].split('|'); + + applyToTorrents(hashes, [ratioLimit, seedingTimeLimit](BitTorrent::TorrentHandle *torrent) + { + torrent->setRatioLimit(ratioLimit); + torrent->setSeedingTimeLimit(seedingTimeLimit); + }); +} + void TorrentsController::toggleSequentialDownloadAction() { checkParams({"hashes"}); diff --git a/src/webui/api/torrentscontroller.h b/src/webui/api/torrentscontroller.h index 0b1814ef2..03d870f93 100644 --- a/src/webui/api/torrentscontroller.h +++ b/src/webui/api/torrentscontroller.h @@ -61,6 +61,7 @@ private slots: void downloadLimitAction(); void setUploadLimitAction(); void setDownloadLimitAction(); + void setShareLimitsAction(); void increasePrioAction(); void decreasePrioAction(); void topPrioAction(); diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc index b889c9264..686aea1db 100644 --- a/src/webui/webui.qrc +++ b/src/webui/webui.qrc @@ -37,6 +37,7 @@ www/private/scripts/prop-trackers.js www/private/scripts/prop-webseeds.js www/private/setlocation.html + www/private/shareratio.html www/private/statistics.html www/private/transferlist.html www/private/upload.html diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index d28ef3daa..d6b4aea08 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -122,6 +122,7 @@
  • QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Limit download rate...)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Limit upload rate...)QBT_TR[CONTEXT=TransferListWidget]
  • +
  • QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Limit share ratio...)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Super seeding mode)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Super seeding mode)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]
  • QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]
  • diff --git a/src/webui/www/private/scripts/misc.js b/src/webui/www/private/scripts/misc.js index b1d14b1b9..fb6f4341d 100644 --- a/src/webui/www/private/scripts/misc.js +++ b/src/webui/www/private/scripts/misc.js @@ -76,6 +76,10 @@ function friendlyPercentage(value) { return percentage.toFixed(1) + "%"; } +function friendlyFloat(value, precision) { + return parseFloat(value).toFixed(precision); +} + /* * From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString */ diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 5faa6d3c8..ff316caff 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -162,6 +162,45 @@ initializeWindows = function() { } }; + shareRatioFN = function() { + var hashes = torrentsTable.selectedRowsIds(); + if (hashes.length) { + var shareRatio = null; + var torrentsHaveSameShareRatio = true; + + // check if all selected torrents have same share ratio + for (var i = 0; i < hashes.length; i++) { + var hash = hashes[i]; + var row = torrentsTable.rows[hash].full_data; + var origValues = row.ratio_limit + "|" + row.seeding_time_limit + "|" + row.max_ratio + "|" + row.max_seeding_time; + + // initialize value + if (shareRatio === null) + shareRatio = origValues; + + if (origValues !== shareRatio) { + torrentsHaveSameShareRatio = false; + break; + } + } + + // if all torrents have same share ratio, display that share ratio. else use the default + var orig = torrentsHaveSameShareRatio ? shareRatio : ""; + new MochaUI.Window({ + id: 'shareRatioPage', + title: "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg]", + loadMethod: 'iframe', + contentURL: 'shareratio.html?hashes=' + hashes.join("|") + '&orig=' + orig, + scrollbars: false, + maximizable: false, + paddingVertical: 0, + paddingHorizontal: 0, + width: 424, + height: 175 + }); + } + }; + toggleSequentialDownloadFN = function() { var hashes = torrentsTable.selectedRowsIds(); if (hashes.length) { diff --git a/src/webui/www/private/shareratio.html b/src/webui/www/private/shareratio.html new file mode 100644 index 000000000..1913c65f3 --- /dev/null +++ b/src/webui/www/private/shareratio.html @@ -0,0 +1,167 @@ + + + + + + QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDlg] + + + + + + + + +
    + QBT_TR(Use global share limit)QBT_TR[CONTEXT=UpDownRatioDlg]
    + QBT_TR(Set no share limit)QBT_TR[CONTEXT=UpDownRatioDlg]
    + QBT_TR(Set share limit to)QBT_TR[CONTEXT=UpDownRatioDlg]
    + +
    + + + +
    +
    + + + +
    +
    + +
    +
    + + + diff --git a/src/webui/www/private/transferlist.html b/src/webui/www/private/transferlist.html index 779e61019..5e2fb089c 100644 --- a/src/webui/www/private/transferlist.html +++ b/src/webui/www/private/transferlist.html @@ -61,6 +61,9 @@ UploadLimit: function(element, ref) { uploadLimitFN(); }, + ShareRatio : function (element, ref) { + shareRatioFN(); + }, SequentialDownload: function(element, ref) { toggleSequentialDownloadFN();