From 32099095f796e057ca6f2965bbb494c193a1490d Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 17 Jun 2025 17:35:48 +0300 Subject: [PATCH] feat: Introduce 'By Shown File Order' priority in WebUI --- src/webui/www/private/index.html | 1 + src/webui/www/private/scripts/file-tree.js | 3 +- src/webui/www/private/scripts/prop-files.js | 52 ++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index e10762d5f..8a823c397 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -269,6 +269,7 @@
  • QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]
  • QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]
  • QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]
  • +
  • QBT_TR(By shown file order)QBT_TR[CONTEXT=PropListDelegate]
  • diff --git a/src/webui/www/private/scripts/file-tree.js b/src/webui/www/private/scripts/file-tree.js index c56ddeaef..234f2b1a0 100644 --- a/src/webui/www/private/scripts/file-tree.js +++ b/src/webui/www/private/scripts/file-tree.js @@ -45,7 +45,8 @@ window.qBittorrent.FileTree ??= (() => { Normal: 1, High: 6, Maximum: 7, - Mixed: -1 + Mixed: -1, + ByShownOrder: -2 }; Object.freeze(FilePriority); diff --git a/src/webui/www/private/scripts/prop-files.js b/src/webui/www/private/scripts/prop-files.js index b0242a9aa..e4ee789eb 100644 --- a/src/webui/www/private/scripts/prop-files.js +++ b/src/webui/www/private/scripts/prop-files.js @@ -478,7 +478,54 @@ window.qBittorrent.PropFiles ??= (() => { }); } - setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority); + // Will be used both in general case and ByShownOrder case + const filesLen = Object.keys(uniqueFileIds).length; + const priorityList = {}; + Object.values(FilePriority).forEach((p) => { + priorityList[p] = []; + }); + const priorityGroupSize = Math.max(Math.floor(filesLen / 3), 1); + const uniqueFileKeys = Object.keys(uniqueFileIds); + const uniqueRowKeys = Object.keys(uniqueRowIds); + + // Will be altered only if we select ByShownOrder, use whatever is passed otherwise + let priorityGroup = priority; + let fileId = 0; + let rowId = 0; + for (let i = 0; i < filesLen; ++i) { + fileId = uniqueFileKeys[i]; + rowId = uniqueRowKeys[i]; + // Calculate priority based on order + if (priority === FilePriority.ByShownOrder) { + switch (Math.floor(i / priorityGroupSize)) { + case 0: + priorityGroup = FilePriority.Maximum; + break; + case 1: + priorityGroup = FilePriority.High; + break; + default: + case 2: + priorityGroup = FilePriority.Normal; + break; + } + } + // Or if we use one of the simpler priorities, just push in the same group + priorityList[priorityGroup].push({ + fileId: fileId, + rowId: rowId + }); + } + + Object.entries(priorityList).forEach(([groupPriority, groupedFileRowPair]) => { + if (groupedFileRowPair.length === 0) + return; + setFilePriority( + groupedFileRowPair.map(pair => pair.rowId), + groupedFileRowPair.map(pair => pair.fileId), + groupPriority + ); + }); }; const singleFileRename = (hash) => { @@ -553,6 +600,9 @@ window.qBittorrent.PropFiles ??= (() => { }, FilePrioMaximum: (element, ref) => { filesPriorityMenuClicked(FilePriority.Maximum); + }, + FilePrioByShownOrder: (element, ref) => { + filesPriorityMenuClicked(FilePriority.ByShownOrder); } }, offsets: {