From 6cfbc02d8ffc6b56a49b319e41f274b81b2aee29 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Oct 2023 22:54:05 +0800 Subject: [PATCH] Expose Mark-of-the-Web setting in Options --- src/base/bittorrent/torrentimpl.cpp | 2 +- src/base/net/downloadhandlerimpl.cpp | 7 +++++-- src/base/preferences.cpp | 13 +++++++++++++ src/base/preferences.h | 2 ++ src/gui/advancedsettings.cpp | 17 +++++++++++++++++ src/gui/advancedsettings.h | 6 +++++- src/webui/api/appcontroller.cpp | 5 +++++ src/webui/webapplication.h | 2 +- src/webui/www/private/views/preferences.html | 10 ++++++++++ 9 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 58c7a92d2..10160e1a0 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -2245,7 +2245,7 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p) #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) // only apply Mark-of-the-Web to new download files - if (isDownloading()) + if (Preferences::instance()->isMarkOfTheWebEnabled() && isDownloading()) { const Path fullpath = actualStorageLocation() / actualPath; Utils::OS::applyMarkOfTheWeb(fullpath); diff --git a/src/base/net/downloadhandlerimpl.cpp b/src/base/net/downloadhandlerimpl.cpp index 32294bb5f..932214d8f 100644 --- a/src/base/net/downloadhandlerimpl.cpp +++ b/src/base/net/downloadhandlerimpl.cpp @@ -43,6 +43,7 @@ #endif #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) +#include "base/preferences.h" #include "base/utils/os.h" #endif // Q_OS_MACOS || Q_OS_WIN @@ -155,7 +156,8 @@ void Net::DownloadHandlerImpl::processFinishedDownload() m_result.filePath = result.value(); #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) - Utils::OS::applyMarkOfTheWeb(m_result.filePath, m_result.url); + if (Preferences::instance()->isMarkOfTheWebEnabled()) + Utils::OS::applyMarkOfTheWeb(m_result.filePath, m_result.url); #endif // Q_OS_MACOS || Q_OS_WIN } else @@ -171,7 +173,8 @@ void Net::DownloadHandlerImpl::processFinishedDownload() m_result.filePath = destinationPath; #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) - Utils::OS::applyMarkOfTheWeb(m_result.filePath, m_result.url); + if (Preferences::instance()->isMarkOfTheWebEnabled()) + Utils::OS::applyMarkOfTheWeb(m_result.filePath, m_result.url); #endif // Q_OS_MACOS || Q_OS_WIN } else diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 31598b5be..559a4e245 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1319,6 +1319,19 @@ void Preferences::setTrackerPortForwardingEnabled(const bool enabled) setValue(u"Preferences/Advanced/trackerPortForwarding"_s, enabled); } +bool Preferences::isMarkOfTheWebEnabled() const +{ + return value(u"Preferences/Advanced/markOfTheWeb"_s, true); +} + +void Preferences::setMarkOfTheWebEnabled(const bool enabled) +{ + if (enabled == isMarkOfTheWebEnabled()) + return; + + setValue(u"Preferences/Advanced/markOfTheWeb"_s, enabled); +} + Path Preferences::getPythonExecutablePath() const { return value(u"Preferences/Search/pythonExecutablePath"_s, Path()); diff --git a/src/base/preferences.h b/src/base/preferences.h index 3c2cab599..ac92f55e2 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -291,6 +291,8 @@ public: void setTrackerPort(int port); bool isTrackerPortForwardingEnabled() const; void setTrackerPortForwardingEnabled(bool enabled); + bool isMarkOfTheWebEnabled() const; + void setMarkOfTheWebEnabled(bool enabled); Path getPythonExecutablePath() const; void setPythonExecutablePath(const Path &path); #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index dfb3f8f69..6b269574b 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -100,6 +100,9 @@ namespace TRACKER_STATUS, TRACKER_PORT, TRACKER_PORT_FORWARDING, +#if defined(Q_OS_MACOS) || defined(Q_OS_WIN) + ENABLE_MARK_OF_THE_WEB, +#endif // Q_OS_MACOS || Q_OS_WIN PYTHON_EXECUTABLE_PATH, // libtorrent section @@ -319,6 +322,10 @@ void AdvancedSettings::saveAdvancedSettings() const pref->setTrackerPort(m_spinBoxTrackerPort.value()); pref->setTrackerPortForwardingEnabled(m_checkBoxTrackerPortForwarding.isChecked()); session->setTrackerEnabled(m_checkBoxTrackerStatus.isChecked()); +#if defined(Q_OS_MACOS) || defined(Q_OS_WIN) + // Mark-of-the-Web + pref->setMarkOfTheWebEnabled(m_checkBoxMarkOfTheWeb.isChecked()); +#endif // Q_OS_MACOS || Q_OS_WIN // Python executable path pref->setPythonExecutablePath(Path(m_pythonExecutablePath.text().trimmed())); // Choking algorithm @@ -815,6 +822,16 @@ void AdvancedSettings::loadAdvancedSettings() // Tracker port forwarding m_checkBoxTrackerPortForwarding.setChecked(pref->isTrackerPortForwardingEnabled()); addRow(TRACKER_PORT_FORWARDING, tr("Enable port forwarding for embedded tracker"), &m_checkBoxTrackerPortForwarding); +#if defined(Q_OS_MACOS) || defined(Q_OS_WIN) + // Mark-of-the-Web +#ifdef Q_OS_MACOS + const QString motwLabel = tr("Enable quarantine for downloaded files"); +#elif defined(Q_OS_WIN) + const QString motwLabel = tr("Enable Mark-of-the-Web (MOTW) for downloaded files"); +#endif + m_checkBoxMarkOfTheWeb.setChecked(pref->isMarkOfTheWebEnabled()); + addRow(ENABLE_MARK_OF_THE_WEB, motwLabel, &m_checkBoxMarkOfTheWeb); +#endif // Q_OS_MACOS || Q_OS_WIN // Python executable path m_pythonExecutablePath.setPlaceholderText(tr("(Auto detect if empty)")); m_pythonExecutablePath.setText(pref->getPythonExecutablePath().toString()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index aa83f1636..8dbc39fd7 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -101,7 +101,7 @@ private: #endif // OS dependent settings -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN QComboBox m_comboBoxOSMemoryPriority; #endif @@ -109,6 +109,10 @@ private: QCheckBox m_checkBoxIconsInMenusEnabled; #endif +#if defined(Q_OS_MACOS) || defined(Q_OS_WIN) + QCheckBox m_checkBoxMarkOfTheWeb; +#endif // Q_OS_MACOS || Q_OS_WIN + #ifdef QBT_USES_DBUS QSpinBox m_spinBoxNotificationTimeout; #endif diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 395afde3f..bdd4c65f0 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -414,6 +414,8 @@ void AppController::preferencesAction() data[u"enable_embedded_tracker"_s] = session->isTrackerEnabled(); data[u"embedded_tracker_port"_s] = pref->getTrackerPort(); data[u"embedded_tracker_port_forwarding"_s] = pref->isTrackerPortForwardingEnabled(); + // Mark-of-the-Web + data[u"mark_of_the_web"_s] = pref->isMarkOfTheWebEnabled(); // Python executable path data[u"python_executable_path"_s] = pref->getPythonExecutablePath().toString(); // Choking algorithm @@ -1020,6 +1022,9 @@ void AppController::setPreferencesAction() pref->setTrackerPortForwardingEnabled(it.value().toBool()); if (hasKey(u"enable_embedded_tracker"_s)) session->setTrackerEnabled(it.value().toBool()); + // Mark-of-the-Web + if (hasKey(u"mark_of_the_web"_s)) + pref->setMarkOfTheWebEnabled(it.value().toBool()); // Python executable path if (hasKey(u"python_executable_path"_s)) pref->setPythonExecutablePath(Path(it.value().toString())); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 30bd3b80c..320506694 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -52,7 +52,7 @@ #include "base/utils/version.h" #include "api/isessionmanager.h" -inline const Utils::Version<3, 2> API_VERSION {2, 10, 0}; +inline const Utils::Version<3, 2> API_VERSION {2, 10, 1}; class APIController; class AuthController; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 002866531..aa4a9e411 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1077,6 +1077,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD + + + + + + + + @@ -2320,6 +2328,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('enableEmbeddedTracker').setProperty('checked', pref.enable_embedded_tracker); $('embeddedTrackerPort').setProperty('value', pref.embedded_tracker_port); $('embeddedTrackerPortForwarding').setProperty('checked', pref.embedded_tracker_port_forwarding); + $('markOfTheWeb').setProperty('checked', pref.mark_of_the_web); $('pythonExecutablePath').setProperty('value', pref.python_executable_path); $('uploadSlotsBehavior').setProperty('value', pref.upload_slots_behavior); $('uploadChokingAlgorithm').setProperty('value', pref.upload_choking_algorithm); @@ -2764,6 +2773,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD settings.set('enable_embedded_tracker', $('enableEmbeddedTracker').getProperty('checked')); settings.set('embedded_tracker_port', $('embeddedTrackerPort').getProperty('value')); settings.set('embedded_tracker_port_forwarding', $('embeddedTrackerPortForwarding').getProperty('checked')); + settings.set('mark_of_the_web', $('markOfTheWeb').getProperty('checked')); settings.set('python_executable_path', $('pythonExecutablePath').getProperty('value')); settings.set('upload_slots_behavior', $('uploadSlotsBehavior').getProperty('value')); settings.set('upload_choking_algorithm', $('uploadChokingAlgorithm').getProperty('value'));