diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 58bbfb216..b77b930b4 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -69,6 +69,7 @@ namespace #define SETTINGS_KEY(name) u"AddNewTorrentDialog/" name const QString KEY_ENABLED = SETTINGS_KEY(u"Enabled"_s); const QString KEY_TOPLEVEL = SETTINGS_KEY(u"TopLevel"_s); + const QString KEY_ATTACHED = SETTINGS_KEY(u"Attached"_s); const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY(u"SavePathHistory"_s); const QString KEY_DOWNLOADPATHHISTORY = SETTINGS_KEY(u"DownloadPathHistory"_s); const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY(u"SavePathHistoryLength"_s); @@ -471,6 +472,18 @@ void AddNewTorrentDialog::setSavePathHistoryLength(const int value) , QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).mid(0, clampedValue))); } +#ifndef Q_OS_MACOS +void AddNewTorrentDialog::setAttached(const bool value) +{ + settings()->storeValue(KEY_ATTACHED, value); +} + +bool AddNewTorrentDialog::isAttached() +{ + return settings()->loadValue(KEY_ATTACHED, false); +} +#endif + void AddNewTorrentDialog::loadState() { if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) @@ -489,19 +502,24 @@ void AddNewTorrentDialog::saveState() void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent) { - Q_UNUSED(parent); + const auto *pref = Preferences::instance(); +#ifdef Q_OS_MACOS + const bool attached = false; +#else + const bool attached = isAttached(); +#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(inParams, nullptr); + auto *dlg = new AddNewTorrentDialog(inParams, (attached ? parent : 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); if (Net::DownloadManager::hasSupportedScheme(source)) { - const auto *pref = Preferences::instance(); // Launch downloader Net::DownloadManager::instance()->download( Net::DownloadRequest(source).limit(pref->getTorrentFileSizeLimit()) diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index 2a830e14b..3e2891037 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -74,6 +74,10 @@ public: static void setTopLevel(bool value); static int savePathHistoryLength(); static void setSavePathHistoryLength(int value); +#ifndef Q_OS_MACOS + static bool isAttached(); + static void setAttached(bool value); +#endif static void show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent); static void show(const QString &source, QWidget *parent); diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 0d0ce6642..af665fdae 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -94,6 +94,7 @@ namespace ENABLE_SPEED_WIDGET, #ifndef Q_OS_MACOS ENABLE_ICONS_IN_MENUS, + USE_ATTACHED_ADD_NEW_TORRENT_DIALOG, #endif // embedded tracker TRACKER_STATUS, @@ -310,6 +311,7 @@ void AdvancedSettings::saveAdvancedSettings() const pref->setSpeedWidgetEnabled(m_checkBoxSpeedWidgetEnabled.isChecked()); #ifndef Q_OS_MACOS pref->setIconsInMenusEnabled(m_checkBoxIconsInMenusEnabled.isChecked()); + AddNewTorrentDialog::setAttached(m_checkBoxAttachedAddNewTorrentDialog.isChecked()); #endif // Tracker @@ -796,6 +798,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(AddNewTorrentDialog::isAttached()); + 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 1cb869e9e..652cd88ac 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -102,6 +102,7 @@ private: #ifndef Q_OS_MACOS QCheckBox m_checkBoxIconsInMenusEnabled; + QCheckBox m_checkBoxAttachedAddNewTorrentDialog; #endif #ifdef QBT_USES_DBUS