From 2425a1ff94391ce4bad01fb1ff5d929f60bbae92 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Dec 2023 14:39:15 -0900 Subject: [PATCH 1/6] Expose torrent file deletion setting to WebUI This setting was used in the Qt GUI but not in WebUI; I named it delete_torrent_files_as_default to match other WebUI setting names. --- src/webui/api/appcontroller.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 4f917409af36..62d95fdab911 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -167,6 +167,9 @@ void AppController::preferencesAction() data[u"excluded_file_names_enabled"_s] = session->isExcludedFileNamesEnabled(); data[u"excluded_file_names"_s] = session->excludedFileNames().join(u'\n'); + // Default setting for torrent file deletion on torrent removal + data[u"delete_torrent_files_as_default"_s] = pref->deleteTorrentFilesAsDefault(); + // Email notification upon download completion data[u"mail_notification_enabled"_s] = pref->isMailNotificationEnabled(); data[u"mail_notification_sender"_s] = pref->getMailNotificationSender(); @@ -597,6 +600,10 @@ void AppController::setPreferencesAction() if (hasKey(u"excluded_file_names"_s)) session->setExcludedFileNames(it.value().toString().split(u'\n')); + // Default setting for torrent file deletion on torrent removal + if (hasKey(u"delete_torrent_files_as_default"_s)) + pref->setDeleteTorrentFilesAsDefault(it.value().toBool()); + // Email notification upon download completion if (hasKey(u"mail_notification_enabled"_s)) pref->setMailNotificationEnabled(it.value().toBool()); From 50598eaa5df8959632e087f862736f7783ed8a3a Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Dec 2023 14:44:03 -0900 Subject: [PATCH 2/6] Add Lock icon SVG to WebUI --- src/webui/www/private/images/object-locked.svg | 1 + src/webui/www/webui.qrc | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/webui/www/private/images/object-locked.svg diff --git a/src/webui/www/private/images/object-locked.svg b/src/webui/www/private/images/object-locked.svg new file mode 100644 index 000000000000..e1244412229d --- /dev/null +++ b/src/webui/www/private/images/object-locked.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/webui/www/webui.qrc b/src/webui/www/webui.qrc index b9f9bcb79d60..bc8eecbcdba5 100644 --- a/src/webui/www/webui.qrc +++ b/src/webui/www/webui.qrc @@ -332,6 +332,7 @@ private/images/mail-inbox.svg private/images/mascot.png private/images/name.svg + private/images/object-locked.svg private/images/peers-add.svg private/images/peers-remove.svg private/images/queued.svg From 0f5876c0d1e595af01331c13f3d08c929558a9ea Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Dec 2023 14:51:50 -0900 Subject: [PATCH 3/6] Add button to set delete files default in WebUI Qt UI has a 'Remember choice' button in the confirm torrent deletion dialog; this adds a button to the WebUI that matches the Qt dialog in looks and functionality. - Button's title text (not visible, but needed for accessibility) matches Qt UI, so existing translations for 'Remember choice' can be used. Do I just need to update all the .ts files and use the QBT_TR() helper? - The button's script GETs api/v2/app/preferences each time the confirm deletion dialog opens; should we cache the deletion setting locally? Closes #20073. --- src/webui/www/private/confirmdeletion.html | 63 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/webui/www/private/confirmdeletion.html b/src/webui/www/private/confirmdeletion.html index 6ce0174e882c..8d03cccbc580 100644 --- a/src/webui/www/private/confirmdeletion.html +++ b/src/webui/www/private/confirmdeletion.html @@ -14,6 +14,53 @@ const isDeletingFiles = (new URI().getData('deleteFiles') === "true"); $('deleteFromDiskCB').checked = isDeletingFiles; + // Add SVG lock icon to rememberBtn with JS so we can change the fill color + new Request({ + url: '/images/object-locked.svg', + method: 'get', + onSuccess: function(text, xml) { + // The SVG's height is 32px, which is too big for our dialog + xml.childNodes[0].style.height = '24px'; + xml.childNodes[0].style.width = '24px'; + $('rememberBtn').appendChild(xml.childNodes[0]); + // Disable button until delete-files checkbox is clicked + disableRememberBtn(); + } + }).send(); + + new Request.JSON({ + url: 'api/v2/app/preferences', + method: 'get', + noCache: true, + onSuccess: function(pref) { + if (pref) { + $('deleteFromDiskCB').checked = pref.delete_torrent_files_as_default; + } + } + }).send(); + + $('rememberBtn').addEvent('click', function(e) { + const cmd = 'api/v2/app/setPreferences'; + const deleteTorrentFilesAsDefault = $('deleteFromDiskCB').checked; + new Request({ + url: cmd, + method: 'post', + data: { + 'json': JSON.encode({ + 'delete_torrent_files_as_default': deleteTorrentFilesAsDefault + }) + }, + onComplete: function() { + disableRememberBtn(); + } + }).send(); + }); + + // Undisable rememberBtn if checkbox is clicked + $('deleteFromDiskCB').addEvent('click', function(e) { + enableRememberBtn(); + }); + const hashes = new URI().getData('hashes').split('|'); $('cancelBtn').focus(); $('cancelBtn').addEvent('click', function(e) { @@ -38,6 +85,18 @@ }).send(); }); }); + + function enableRememberBtn() { + let btn = $('rememberBtn'); + btn.disabled = false; + btn.getElementsByTagName('path')[0].style.fill = ""; + } + + function disableRememberBtn() { + let btn = $('rememberBtn'); + btn.disabled = true; + btn.getElementsByTagName('path')[0].style.fill = "lightgray"; + } @@ -45,7 +104,9 @@

  QBT_TR(Are you sure you want to remove the selected torrents from the transfer list?)QBT_TR[CONTEXT=HttpServer]

-     

+      +

    
From ad6593d542f2895493da9414dc7377d40399897c Mon Sep 17 00:00:00 2001 From: David Date: Sat, 30 Dec 2023 18:41:06 -0900 Subject: [PATCH 4/6] Declare lock icon and its height and width in html --- src/webui/www/private/confirmdeletion.html | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/webui/www/private/confirmdeletion.html b/src/webui/www/private/confirmdeletion.html index 8d03cccbc580..46d28a0791f1 100644 --- a/src/webui/www/private/confirmdeletion.html +++ b/src/webui/www/private/confirmdeletion.html @@ -14,20 +14,6 @@ const isDeletingFiles = (new URI().getData('deleteFiles') === "true"); $('deleteFromDiskCB').checked = isDeletingFiles; - // Add SVG lock icon to rememberBtn with JS so we can change the fill color - new Request({ - url: '/images/object-locked.svg', - method: 'get', - onSuccess: function(text, xml) { - // The SVG's height is 32px, which is too big for our dialog - xml.childNodes[0].style.height = '24px'; - xml.childNodes[0].style.width = '24px'; - $('rememberBtn').appendChild(xml.childNodes[0]); - // Disable button until delete-files checkbox is clicked - disableRememberBtn(); - } - }).send(); - new Request.JSON({ url: 'api/v2/app/preferences', method: 'get', @@ -105,6 +91,10 @@

  QBT_TR(Are you sure you want to remove the selected torrents from the transfer list?)QBT_TR[CONTEXT=HttpServer]

    

From 1b80df8a0fcc01e759e5abe9c5ada89a102fd970 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 30 Dec 2023 18:56:25 -0900 Subject: [PATCH 5/6] Update for dark mode, implement review suggestions Also reordered things for better clarity and rewrote/added comments. --- src/webui/www/private/confirmdeletion.html | 41 +++++++++++----------- src/webui/www/private/css/style.css | 4 +++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/webui/www/private/confirmdeletion.html b/src/webui/www/private/confirmdeletion.html index 46d28a0791f1..4f726deed2b2 100644 --- a/src/webui/www/private/confirmdeletion.html +++ b/src/webui/www/private/confirmdeletion.html @@ -25,15 +25,20 @@ } }).send(); + // Disable 'Remember choice' button until 'Delete files' checkbox is clicked + disableRememberBtn(); + $('deleteFromDiskCB').addEvent('click', function(e) { + enableRememberBtn(); + }); + + // Set current "Delete files" choice as the default $('rememberBtn').addEvent('click', function(e) { - const cmd = 'api/v2/app/setPreferences'; - const deleteTorrentFilesAsDefault = $('deleteFromDiskCB').checked; new Request({ - url: cmd, + url: 'api/v2/app/setPreferences', method: 'post', data: { 'json': JSON.encode({ - 'delete_torrent_files_as_default': deleteTorrentFilesAsDefault + 'delete_torrent_files_as_default': $('deleteFromDiskCB').checked }) }, onComplete: function() { @@ -42,11 +47,17 @@ }).send(); }); - // Undisable rememberBtn if checkbox is clicked - $('deleteFromDiskCB').addEvent('click', function(e) { - enableRememberBtn(); - }); + function enableRememberBtn() { + const btn = $('rememberBtn'); + btn.disabled = false; + btn.getElementsByTagName('path')[0].style.fill = ""; + } + function disableRememberBtn() { + const btn = $('rememberBtn'); + btn.disabled = true; + btn.getElementsByTagName('path')[0].style.fill = "var(--color-border-default)"; + } const hashes = new URI().getData('hashes').split('|'); $('cancelBtn').focus(); $('cancelBtn').addEvent('click', function(e) { @@ -71,18 +82,6 @@ }).send(); }); }); - - function enableRememberBtn() { - let btn = $('rememberBtn'); - btn.disabled = false; - btn.getElementsByTagName('path')[0].style.fill = ""; - } - - function disableRememberBtn() { - let btn = $('rememberBtn'); - btn.disabled = true; - btn.getElementsByTagName('path')[0].style.fill = "lightgray"; - } @@ -90,7 +89,7 @@

  QBT_TR(Are you sure you want to remove the selected torrents from the transfer list?)QBT_TR[CONTEXT=HttpServer]

-     

diff --git a/src/webui/www/private/css/style.css b/src/webui/www/private/css/style.css index bc77f1634c39..f05ae3e78b87 100644 --- a/src/webui/www/private/css/style.css +++ b/src/webui/www/private/css/style.css @@ -34,8 +34,8 @@ button { padding: 4px 16px; } -button[disabled] { - cursor: auto; +button:disabled { + cursor: initial; } /*table { border-collapse: collapse; border-spacing: 0; }*/ diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index cfda9444b061..3801bc78a89d 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -390,11 +390,11 @@ const initializeWindows = function() { loadMethod: 'iframe', contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).setData("deleteFiles", deleteFiles).toString(), scrollbars: false, - resizable: false, + resizable: true, maximizable: false, padding: 10, width: 424, - height: 140 + height: 160 }); updateMainData(); } @@ -711,11 +711,11 @@ const initializeWindows = function() { loadMethod: 'iframe', contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(), scrollbars: false, - resizable: false, + resizable: true, maximizable: false, padding: 10, width: 424, - height: 140 + height: 160 }); updateMainData(); } @@ -852,11 +852,11 @@ const initializeWindows = function() { loadMethod: 'iframe', contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(), scrollbars: false, - resizable: false, + resizable: true, maximizable: false, padding: 10, width: 424, - height: 140 + height: 160 }); updateMainData(); } @@ -938,11 +938,11 @@ const initializeWindows = function() { loadMethod: 'iframe', contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(), scrollbars: false, - resizable: false, + resizable: true, maximizable: false, padding: 10, width: 424, - height: 140, + height: 160, onCloseComplete: function() { updateMainData(); setTrackerFilter(TRACKERS_ALL);