diff --git a/src/webui/www/private/download.html b/src/webui/www/private/download.html index 45186abe6..c7bc12f37 100644 --- a/src/webui/www/private/download.html +++ b/src/webui/www/private/download.html @@ -10,6 +10,7 @@ + @@ -38,7 +39,7 @@ - + @@ -191,6 +192,8 @@ if (submitted) window.parent.qBittorrent.Client.closeWindows(); }); + + window.qBittorrent.pathAutofill.attachPathAutofill(); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 388a509fd..224c92e7f 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -39,6 +39,7 @@ + diff --git a/src/webui/www/private/newcategory.html b/src/webui/www/private/newcategory.html index 37f52d827..b17ad6f0f 100644 --- a/src/webui/www/private/newcategory.html +++ b/src/webui/www/private/newcategory.html @@ -8,6 +8,7 @@ + @@ -139,7 +142,7 @@

QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]:

QBT_TR(Save path)QBT_TR[CONTEXT=TransferListWidget]:

- +
diff --git a/src/webui/www/private/newfolder.html b/src/webui/www/private/newfolder.html index edcef4a80..a3cbbb326 100644 --- a/src/webui/www/private/newfolder.html +++ b/src/webui/www/private/newfolder.html @@ -8,6 +8,7 @@ +

QBT_TR(Folder name:)QBT_TR[CONTEXT=RSSWidget]

- +
diff --git a/src/webui/www/private/scripts/pathAutofill.js b/src/webui/www/private/scripts/pathAutofill.js new file mode 100644 index 000000000..3a7021dbf --- /dev/null +++ b/src/webui/www/private/scripts/pathAutofill.js @@ -0,0 +1,93 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2024 Paweł Kotiuk + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project"s "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +"use strict"; + +/* +File implementing auto-fill for the path input field in the path dialogs. +*/ +if (window.qBittorrent === undefined) + window.qBittorrent = {}; + +if (window.qBittorrent.pathAutofill === undefined) { + window.qBittorrent.pathAutofill = (() => { + const exports = () => { + return { + attachPathAutofill: attachPathAutofill + }; + }; + + function showInputSuggestions(inputElement, names) { + const datalist = document.createElement("datalist"); + datalist.id = inputElement.id + "Suggestions"; + for (const name of names) { + const option = document.createElement("option"); + option.value = name; + datalist.appendChild(option); + } + + const oldDatalist = document.getElementById(`${inputElement.id}Suggestions`); + if (oldDatalist !== null) { + oldDatalist.replaceWith(datalist); + } + else { + inputElement.appendChild(datalist); + inputElement.setAttribute("list", datalist.id); + } + } + + function showPathSuggestions(element, mode) { + const partialPath = element.value; + if (partialPath === "") + return; + + fetch(`api/v2/app/getDirectoryContent?dirPath=${partialPath}&mode=${mode}`) + .then(response => response.json()) + .then(filesList => { showInputSuggestions(element, filesList); }) + .catch(error => {}); + } + + function attachPathAutofill() { + const directoryInputs = document.querySelectorAll(".pathDirectory:not(.pathAutoFillInitialized)"); + for (const input of directoryInputs) { + input.addEventListener("input", function() { showPathSuggestions(this, "dirs"); }); + input.classList.add("pathAutoFillInitialized"); + } + + const fileInputs = document.querySelectorAll(".pathFile:not(.pathAutoFillInitialized)"); + for (const input of fileInputs) { + input.addEventListener("input", function() { showPathSuggestions(this, "all"); }); + input.classList.add("pathAutoFillInitialized"); + } + }; + + return exports(); + })(); + + Object.freeze(window.qBittorrent.pathAutofill); +}; diff --git a/src/webui/www/private/upload.html b/src/webui/www/private/upload.html index 3d2ee024b..2be87ba9e 100644 --- a/src/webui/www/private/upload.html +++ b/src/webui/www/private/upload.html @@ -8,6 +8,7 @@ + @@ -34,7 +35,7 @@ - + @@ -171,6 +172,8 @@ if ((Browser.platform === "ios") || ((Browser.platform === "mac") && (navigator.maxTouchPoints > 1))) $("fileselect").accept = ".torrent"; + + window.qBittorrent.pathAutofill.attachPathAutofill(); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 966ab579b..78ec25d9f 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -14,7 +14,7 @@
- +
@@ -151,7 +151,7 @@ @@ -160,7 +160,7 @@ @@ -169,7 +169,7 @@ @@ -178,7 +178,7 @@
- +
- +
- +
- +
@@ -810,7 +810,7 @@ - + @@ -818,7 +818,7 @@ - + @@ -880,7 +880,7 @@
- +
@@ -1126,7 +1126,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD - + @@ -2896,4 +2896,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD })(); Object.freeze(window.qBittorrent.Preferences); + + window.qBittorrent.pathAutofill.attachPathAutofill(); diff --git a/src/webui/www/webui.qrc b/src/webui/www/webui.qrc index 7b9e7fd5d..31a8632ae 100644 --- a/src/webui/www/webui.qrc +++ b/src/webui/www/webui.qrc @@ -392,6 +392,7 @@ private/scripts/localpreferences.js private/scripts/misc.js private/scripts/mocha-init.js + private/scripts/pathAutofill.js private/scripts/piecesbar.js private/scripts/progressbar.js private/scripts/prop-files.js