From 9cb3a6d29e43dbaac4cff4a1685d31640917d081 Mon Sep 17 00:00:00 2001 From: Christoph Rackwitz Date: Fri, 26 Mar 2021 00:07:09 +0100 Subject: [PATCH 1/6] Fix tabChangesFocus attribute in "Edit trackers" dialog --- src/gui/trackerentriesdialog.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/trackerentriesdialog.ui b/src/gui/trackerentriesdialog.ui index 823c4d333..adee9c8ff 100644 --- a/src/gui/trackerentriesdialog.ui +++ b/src/gui/trackerentriesdialog.ui @@ -28,9 +28,9 @@ - + true - + From 7006afc6113635d7f77efba1a58a9f8aa76d5698 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 28 Mar 2021 13:15:47 +0800 Subject: [PATCH 2/6] Remove unnecessary URL encoding Fix #14635. --- src/webui/www/private/views/search.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui/www/private/views/search.html b/src/webui/www/private/views/search.html index e28e83264..0d19032b6 100644 --- a/src/webui/www/private/views/search.html +++ b/src/webui/www/private/views/search.html @@ -386,7 +386,7 @@ const downloadSearchTorrent = function() { const urls = []; searchResultsTable.selectedRowsIds().each(function(rowId) { - urls.push(encodeURIComponent(searchResultsTable.rows.get(rowId).full_data.fileUrl)); + urls.push(searchResultsTable.rows.get(rowId).full_data.fileUrl); }); // only proceed if at least 1 row was selected From 5c05bdaa27f7279e9e4328c7a329596fc5af2844 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 31 Mar 2021 00:10:52 +0800 Subject: [PATCH 3/6] Clean up code --- src/base/filesystemwatcher.cpp | 6 +++- src/base/filesystemwatcher.h | 6 ++-- src/webui/api/appcontroller.cpp | 33 +++++++------------- src/webui/www/private/views/preferences.html | 16 +++++----- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/base/filesystemwatcher.cpp b/src/base/filesystemwatcher.cpp index fd1b19fff..ccc6bd1d9 100644 --- a/src/base/filesystemwatcher.cpp +++ b/src/base/filesystemwatcher.cpp @@ -30,6 +30,8 @@ #include +#include + #if defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) #include #include @@ -42,9 +44,11 @@ #include "base/logger.h" #include "base/utils/fs.h" +using namespace std::chrono_literals; + namespace { - const int WATCH_INTERVAL = 10000; // 10 sec + const std::chrono::duration WATCH_INTERVAL = 10s; const int MAX_PARTIAL_RETRIES = 5; } diff --git a/src/base/filesystemwatcher.h b/src/base/filesystemwatcher.h index 56d5f6dd6..2f946e0a8 100644 --- a/src/base/filesystemwatcher.h +++ b/src/base/filesystemwatcher.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -39,9 +38,10 @@ * Subclassing QFileSystemWatcher in order to support Network File * System watching (NFS, CIFS) on Linux and Mac OS. */ -class FileSystemWatcher : public QFileSystemWatcher +class FileSystemWatcher final : public QFileSystemWatcher { Q_OBJECT + Q_DISABLE_COPY(FileSystemWatcher) public: explicit FileSystemWatcher(QObject *parent = nullptr); @@ -53,7 +53,7 @@ public: signals: void torrentsAdded(const QStringList &pathList); -protected slots: +private slots: void scanLocalFolder(const QString &path); void processPartialTorrents(); void scanNetworkFolders(); diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 0f82313c9..3a3c01b04 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -394,15 +394,14 @@ void AppController::setPreferencesAction() if (hasKey("scan_dirs")) { const QVariantHash nativeDirs = it.value().toHash(); - QVariantHash oldScanDirs = pref->getScanDirs(); + const QVariantHash oldScanDirs = pref->getScanDirs(); QVariantHash scanDirs; ScanFoldersModel *model = ScanFoldersModel::instance(); + for (auto i = nativeDirs.cbegin(); i != nativeDirs.cend(); ++i) { - QString folder = Utils::Fs::toUniformPath(i.key()); - int downloadType; + int downloadType = 0; QString downloadPath; - ScanFoldersModel::PathStatus ec; if (i.value().type() == QVariant::String) { downloadType = ScanFoldersModel::CUSTOM_LOCATION; @@ -411,23 +410,17 @@ void AppController::setPreferencesAction() else { downloadType = i.value().toInt(); - downloadPath = (downloadType == ScanFoldersModel::DEFAULT_LOCATION) ? "Default folder" : "Watch folder"; + downloadPath = (downloadType == ScanFoldersModel::DEFAULT_LOCATION) + ? QLatin1String("Default folder") + : QLatin1String("Watch folder"); } - if (!oldScanDirs.contains(folder)) - ec = model->addPath(folder, static_cast(downloadType), downloadPath); - else - ec = model->updatePath(folder, static_cast(downloadType), downloadPath); - + const QString folder = Utils::Fs::toUniformPath(i.key()); + const ScanFoldersModel::PathStatus ec = !oldScanDirs.contains(folder) + ? model->addPath(folder, static_cast(downloadType), downloadPath) + : model->updatePath(folder, static_cast(downloadType), downloadPath); if (ec == ScanFoldersModel::Ok) - { - scanDirs.insert(folder, (downloadType == ScanFoldersModel::CUSTOM_LOCATION) ? QVariant(downloadPath) : QVariant(downloadType)); - qDebug("New watched folder: %s to %s", qUtf8Printable(folder), qUtf8Printable(downloadPath)); - } - else - { - qDebug("Watched folder %s failed with error %d", qUtf8Printable(folder), ec); - } + scanDirs.insert(folder, ((downloadType == ScanFoldersModel::CUSTOM_LOCATION) ? QVariant(downloadPath) : QVariant(downloadType))); } // Update deleted folders @@ -435,11 +428,9 @@ void AppController::setPreferencesAction() { const QString &folder = i.key(); if (!scanDirs.contains(folder)) - { model->removePath(folder); - qDebug("Removed watched folder %s", qUtf8Printable(folder)); - } } + pref->setScanDirs(scanDirs); } // Email notification upon download completion diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 8d690dd1d..d2b28f90f 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1283,7 +1283,7 @@ }; // Downloads tab - const WatchedFoldersTable = new HtmlTable($("watched_folders_tab")); + const watchedFoldersTable = new HtmlTable($("watched_folders_tab")); const updateTempDirEnabled = function() { const isTempDirEnabled = $('temppath_checkbox').getProperty('checked'); @@ -1334,7 +1334,7 @@ + "" + ""; - WatchedFoldersTable.push([myinput, mycb]); + watchedFoldersTable.push([myinput, mycb]); $('cb_watch_' + pos).setProperty('value', sel); if (disableInput) { const elt = $('cb_watch_' + pos); @@ -1349,14 +1349,14 @@ for (let i = 0; i < nb_folders; ++i) { const fpath = $('text_watch_' + i).getProperty('value').trim(); if (fpath.length > 0) { - let other; const sel = $('cb_watch_' + i).getProperty('value').trim(); - if (sel == "other") { + + let other; + if (sel == "other") other = $('cb_watch_txt_' + i).getProperty('value').trim(); - } - else { - other = (sel == "watch_folder") ? 0 : 1; - } + else + other = (sel === "watch_folder") ? 0 : 1; + folders.set(fpath, other); } } From 89a8e07217d24d1c51f674c8e68c052560c8d896 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 31 Mar 2021 01:23:05 +0800 Subject: [PATCH 4/6] Revise folder monitoring functions in WebUI Closes #14241. --- src/webui/www/private/views/preferences.html | 77 ++++++-------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index d2b28f90f..77e9f6b1b 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -127,22 +127,6 @@ - - - - -
- - - Add -
- - - @@ -1290,30 +1274,10 @@ $('temppath_text').setProperty('disabled', !isTempDirEnabled); }; - const addWatchFolder = function() { - const new_folder = $('new_watch_folder_txt').getProperty('value').trim(); - if (new_folder.length <= 0) return; - - const new_other = $('new_watch_folder_other_txt').getProperty('value').trim(); - if (new_other.length <= 0) return; - - const new_select = $('new_watch_folder_select').getProperty('value').trim(); - - const i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length; - pushWatchFolder(i, new_folder, new_select, new_other); - - // Clear fields - $('new_watch_folder_txt').setProperty('value', ''); - const elt = $('new_watch_folder_select'); - elt.setProperty('value', 'watch_folder'); - const text = elt.options[elt.selectedIndex].innerHTML; - $('new_watch_folder_other_txt').setProperty('value', text); - }; - - const changeWatchFolderSelect = function(item) { - if (item.value == "other") { + const changeWatchFolderSelect = (item) => { + if (item.value === "other") { item.nextElementSibling.hidden = false; - item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR[CONTEXT=HttpServer]'; + item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR[CONTEXT=ScanFoldersModel]'; item.nextElementSibling.select(); } else { @@ -1323,16 +1287,19 @@ } }; - const pushWatchFolder = function(pos, folder, sel, other) { + const addWatchFolder = (folder = "", sel = "default_folder", other = "") => { + const pos = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length; const myinput = ""; - const disableInput = (sel != "other"); + const disableInput = (sel !== "other"); const mycb = "
" + "" - + "
"; + + "" + + "Add" + + ""; watchedFoldersTable.push([myinput, mycb]); $('cb_watch_' + pos).setProperty('value', sel); @@ -1341,9 +1308,13 @@ other = elt.options[elt.selectedIndex].innerHTML; } $('cb_watch_txt_' + pos).setProperty('value', other); + + // hide previous img + if (pos > 0) + $('addFolderImg_' + (pos - 1)).style.display = "none"; }; - const getWatchedFolders = function() { + const getWatchedFolders = () => { const nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length; const folders = new Hash(); for (let i = 0; i < nb_folders; ++i) { @@ -1352,7 +1323,7 @@ const sel = $('cb_watch_' + i).getProperty('value').trim(); let other; - if (sel == "other") + if (sel === "other") other = $('cb_watch_txt_' + i).getProperty('value').trim(); else other = (sel === "watch_folder") ? 0 : 1; @@ -1663,19 +1634,19 @@ updateExportDirFinEnabled(); // Automatically add torrents from - let i = 0; - for (const folder in pref.scan_dirs) { - let sel; + for (const [folder, folderType] of Object.entries(pref.scan_dirs)) { + let sel = ""; let other = ""; - if (typeof pref.scan_dirs[folder] == "string") { - other = pref.scan_dirs[folder]; - sel = "other"; + if (typeof folderType === "number") { + sel = (folderType === 0) ? "watch_folder" : "default_folder"; } else { - sel = (pref.scan_dirs[folder] == 0) ? "watch_folder" : "default_folder"; + sel = "other"; + other = folderType; } - pushWatchFolder(i++, folder, sel, other); + addWatchFolder(folder, sel, other); } + addWatchFolder(); // Email notification upon download completion $('mail_notification_checkbox').setProperty('checked', pref.mail_notification_enabled); From a590e7139bbf168292581ceaafa43760861489da Mon Sep 17 00:00:00 2001 From: brvphoenix Date: Sat, 3 Apr 2021 19:23:27 +0800 Subject: [PATCH 5/6] WebUI: Fix magnet url from the browser --- src/webui/www/private/scripts/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 5ee928af4..4a58f0021 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1177,7 +1177,7 @@ function handleDownloadParam() { if (location.hash.indexOf(downloadHash) !== 0) return; - const url = location.hash.substring(downloadHash.length); + const url = decodeURIComponent(location.hash.substring(downloadHash.length)); // Remove the processed hash from the URL history.replaceState('', document.title, (location.pathname + location.search)); showDownloadPage([url]); From 5c819ee384e39d6d4b42d3e2323755047ccca4dd Mon Sep 17 00:00:00 2001 From: skvenders <79187944+skvenders@users.noreply.github.com> Date: Wed, 31 Mar 2021 03:07:01 +0000 Subject: [PATCH 6/6] Remove contributor Remove contributor as requested: https://github.com/qbittorrent/qBittorrent/pull/14637#issuecomment-808894421 --- src/gui/translators.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/translators.html b/src/gui/translators.html index a7b688832..88693e285 100644 --- a/src/gui/translators.html +++ b/src/gui/translators.html @@ -44,7 +44,7 @@
  • Serbian: Anaximandar Milet (anaximandar@operamail.com)
  • Slovak: helix84
  • Spanish: Alfredo Monclús (alfrix), Francisco Luque Contreras (frannoe@ya.com), José Antonio Moray moray33(Transifex) and Diego de las Heras(Transifex)
  • -
  • Swedish: Daniel Nylander (po@danielnylander.se), Emil Hammarberg Ooglogput(Transifex) and Jonatan Nyberg jony08(Transifex)
  • +
  • Swedish: Daniel Nylander (po@danielnylander.se) and Emil Hammarberg Ooglogput(Transifex)
  • Turkish: Hasan YILMAZ (iletisim@hedefturkce.com), Erdem Bingöl (erdem84@gmail.com) and Burak Yavuz (BouRock)
  • Ukrainian: Oleh Prypin (blaxpirit@gmail.com)
  • Vietnamese: Anh Phan ppanhh(Transifex)