Add option to enable previous Add new torrent dialog behavior

PR #19874.
Closes #19774.
This commit is contained in:
Vladimir Golovnev 2023-11-08 08:31:29 +03:00 committed by GitHub
parent 488c022d89
commit 6b3da26af8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 4 deletions

View file

@ -69,6 +69,7 @@ namespace
#define SETTINGS_KEY(name) u"AddNewTorrentDialog/" name #define SETTINGS_KEY(name) u"AddNewTorrentDialog/" name
const QString KEY_ENABLED = SETTINGS_KEY(u"Enabled"_s); const QString KEY_ENABLED = SETTINGS_KEY(u"Enabled"_s);
const QString KEY_TOPLEVEL = SETTINGS_KEY(u"TopLevel"_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_SAVEPATHHISTORY = SETTINGS_KEY(u"SavePathHistory"_s);
const QString KEY_DOWNLOADPATHHISTORY = SETTINGS_KEY(u"DownloadPathHistory"_s); const QString KEY_DOWNLOADPATHHISTORY = SETTINGS_KEY(u"DownloadPathHistory"_s);
const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY(u"SavePathHistoryLength"_s); const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY(u"SavePathHistoryLength"_s);
@ -471,6 +472,18 @@ void AddNewTorrentDialog::setSavePathHistoryLength(const int value)
, QStringList(settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY).mid(0, clampedValue))); , QStringList(settings()->loadValue<QStringList>(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() void AddNewTorrentDialog::loadState()
{ {
if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) 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) 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 // By not setting a parent to the "AddNewTorrentDialog", all those dialogs
// will be displayed on top and will not overlap with the main window. // 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). // Qt::Window is required to avoid showing only two dialog on top (see #12852).
// Also improves the general convenience of adding multiple torrents. // Also improves the general convenience of adding multiple torrents.
dlg->setWindowFlags(Qt::Window); if (!attached)
dlg->setWindowFlags(Qt::Window);
dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->setAttribute(Qt::WA_DeleteOnClose);
if (Net::DownloadManager::hasSupportedScheme(source)) if (Net::DownloadManager::hasSupportedScheme(source))
{ {
const auto *pref = Preferences::instance();
// Launch downloader // Launch downloader
Net::DownloadManager::instance()->download( Net::DownloadManager::instance()->download(
Net::DownloadRequest(source).limit(pref->getTorrentFileSizeLimit()) Net::DownloadRequest(source).limit(pref->getTorrentFileSizeLimit())

View file

@ -74,6 +74,10 @@ public:
static void setTopLevel(bool value); static void setTopLevel(bool value);
static int savePathHistoryLength(); static int savePathHistoryLength();
static void setSavePathHistoryLength(int value); 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, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
static void show(const QString &source, QWidget *parent); static void show(const QString &source, QWidget *parent);

View file

@ -94,6 +94,7 @@ namespace
ENABLE_SPEED_WIDGET, ENABLE_SPEED_WIDGET,
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
ENABLE_ICONS_IN_MENUS, ENABLE_ICONS_IN_MENUS,
USE_ATTACHED_ADD_NEW_TORRENT_DIALOG,
#endif #endif
// embedded tracker // embedded tracker
TRACKER_STATUS, TRACKER_STATUS,
@ -310,6 +311,7 @@ void AdvancedSettings::saveAdvancedSettings() const
pref->setSpeedWidgetEnabled(m_checkBoxSpeedWidgetEnabled.isChecked()); pref->setSpeedWidgetEnabled(m_checkBoxSpeedWidgetEnabled.isChecked());
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
pref->setIconsInMenusEnabled(m_checkBoxIconsInMenusEnabled.isChecked()); pref->setIconsInMenusEnabled(m_checkBoxIconsInMenusEnabled.isChecked());
AddNewTorrentDialog::setAttached(m_checkBoxAttachedAddNewTorrentDialog.isChecked());
#endif #endif
// Tracker // Tracker
@ -796,6 +798,9 @@ void AdvancedSettings::loadAdvancedSettings()
// Enable icons in menus // Enable icons in menus
m_checkBoxIconsInMenusEnabled.setChecked(pref->iconsInMenusEnabled()); m_checkBoxIconsInMenusEnabled.setChecked(pref->iconsInMenusEnabled());
addRow(ENABLE_ICONS_IN_MENUS, tr("Enable icons in menus"), &m_checkBoxIconsInMenusEnabled); 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 #endif
// Tracker State // Tracker State
m_checkBoxTrackerStatus.setChecked(session->isTrackerEnabled()); m_checkBoxTrackerStatus.setChecked(session->isTrackerEnabled());

View file

@ -102,6 +102,7 @@ private:
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
QCheckBox m_checkBoxIconsInMenusEnabled; QCheckBox m_checkBoxIconsInMenusEnabled;
QCheckBox m_checkBoxAttachedAddNewTorrentDialog;
#endif #endif
#ifdef QBT_USES_DBUS #ifdef QBT_USES_DBUS