From ddd8fbd34eddd807fdca6e78f1a307e6b1f2ef23 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Mon, 31 Mar 2025 09:18:16 +0300 Subject: [PATCH] Add option to enable previous Add new torrent dialog behavior Some people are still unhappy with "standalone window mode" of "Add new torrent dialog" so just provide them with an option to use old "modal dialog mode" in all the current qBittorrent branches. PR #22492 (based on original PR #19874). --- src/base/preferences.cpp | 13 +++++++++++++ src/base/preferences.h | 2 ++ src/gui/advancedsettings.cpp | 5 +++++ src/gui/advancedsettings.h | 1 + src/gui/guiaddtorrentmanager.cpp | 11 +++++++++-- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 5b3fcb94e..fc9c5a5e5 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -2000,6 +2000,19 @@ void Preferences::setAddNewTorrentDialogSavePathHistoryLength(const int value) setValue(u"AddNewTorrentDialog/SavePathHistoryLength"_s, clampedValue); } +bool Preferences::isAddNewTorrentDialogAttached() const +{ + return value(u"AddNewTorrentDialog/Attached"_s, false); +} + +void Preferences::setAddNewTorrentDialogAttached(const bool attached) +{ + if (attached == isAddNewTorrentDialogAttached()) + return; + + setValue(u"AddNewTorrentDialog/Attached"_s, attached); +} + void Preferences::apply() { if (SettingsStorage::instance()->save()) diff --git a/src/base/preferences.h b/src/base/preferences.h index a106ac7cf..70f5cedcf 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -423,6 +423,8 @@ public: void setAddNewTorrentDialogTopLevel(bool value); int addNewTorrentDialogSavePathHistoryLength() const; void setAddNewTorrentDialogSavePathHistoryLength(int value); + bool isAddNewTorrentDialogAttached() const; + void setAddNewTorrentDialogAttached(bool attached); public slots: void setStatusFilterState(bool checked); diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 53d50f468..7af38add3 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -97,6 +97,7 @@ namespace ENABLE_SPEED_WIDGET, #ifndef Q_OS_MACOS ENABLE_ICONS_IN_MENUS, + USE_ATTACHED_ADD_NEW_TORRENT_DIALOG, #endif // embedded tracker TRACKER_STATUS, @@ -323,6 +324,7 @@ void AdvancedSettings::saveAdvancedSettings() const pref->setSpeedWidgetEnabled(m_checkBoxSpeedWidgetEnabled.isChecked()); #ifndef Q_OS_MACOS pref->setIconsInMenusEnabled(m_checkBoxIconsInMenusEnabled.isChecked()); + pref->setAddNewTorrentDialogAttached(m_checkBoxAttachedAddNewTorrentDialog.isChecked()); #endif // Tracker @@ -835,6 +837,9 @@ void AdvancedSettings::loadAdvancedSettings() // Enable icons in menus m_checkBoxIconsInMenusEnabled.setChecked(pref->iconsInMenusEnabled()); addRow(ENABLE_ICONS_IN_MENUS, tr("Enable icons in menus"), &m_checkBoxIconsInMenusEnabled); + + m_checkBoxAttachedAddNewTorrentDialog.setChecked(pref->isAddNewTorrentDialogAttached()); + addRow(USE_ATTACHED_ADD_NEW_TORRENT_DIALOG, tr("Attach \"Add new torrent\" dialog to main window"), &m_checkBoxAttachedAddNewTorrentDialog); #endif // Tracker State m_checkBoxTrackerStatus.setChecked(session->isTrackerEnabled()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 74914b293..6c9db2055 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -108,6 +108,7 @@ private: #ifndef Q_OS_MACOS QCheckBox m_checkBoxIconsInMenusEnabled; + QCheckBox m_checkBoxAttachedAddNewTorrentDialog; #endif #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) diff --git a/src/gui/guiaddtorrentmanager.cpp b/src/gui/guiaddtorrentmanager.cpp index d600a4e17..90ca669ab 100644 --- a/src/gui/guiaddtorrentmanager.cpp +++ b/src/gui/guiaddtorrentmanager.cpp @@ -225,12 +225,19 @@ bool GUIAddTorrentManager::processTorrent(const QString &source if (!hasMetadata) btSession()->downloadMetadata(torrentDescr); +#ifdef Q_OS_MACOS + const bool attached = false; +#else + const bool attached = Preferences::instance()->isAddNewTorrentDialogAttached(); +#endif + // By not setting a parent to the "AddNewTorrentDialog", all those dialogs // will be displayed on top and will not overlap with the main window. - auto *dlg = new AddNewTorrentDialog(torrentDescr, params, nullptr); + auto *dlg = new AddNewTorrentDialog(torrentDescr, params, (attached ? app()->mainWindow() : nullptr)); // Qt::Window is required to avoid showing only two dialog on top (see #12852). // Also improves the general convenience of adding multiple torrents. - dlg->setWindowFlags(Qt::Window); + if (!attached) + dlg->setWindowFlags(Qt::Window); dlg->setAttribute(Qt::WA_DeleteOnClose); m_dialogs[infoHash] = dlg;