diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index e59290f74..a3d62cde1 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #ifdef Q_OS_WIN @@ -1371,34 +1370,6 @@ void Preferences::setPropTrackerListState(const QByteArray &state) #endif } -QSize Preferences::getRssGeometrySize() const -{ - return value(u"RssFeedDownloader/geometrySize"_qs); -} - -void Preferences::setRssGeometrySize(const QSize &geometry) -{ - setValue(u"RssFeedDownloader/geometrySize"_qs, geometry); -} - -QByteArray Preferences::getRssHSplitterSizes() const -{ -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - return value(u"GUI/Qt6/RSSFeedDownloader/HSplitterSizes"_qs); -#else - return value(u"RssFeedDownloader/qt5/hsplitterSizes"_qs); -#endif -} - -void Preferences::setRssHSplitterSizes(const QByteArray &sizes) -{ -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - setValue(u"GUI/Qt6/RSSFeedDownloader/HSplitterSizes"_qs, sizes); -#else - setValue(u"RssFeedDownloader/qt5/hsplitterSizes"_qs, sizes); -#endif -} - QStringList Preferences::getRssOpenFolders() const { return value(u"GUI/RSSWidget/OpenedFolders"_qs); diff --git a/src/base/preferences.h b/src/base/preferences.h index 068d1168e..0d976b75f 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -38,7 +38,6 @@ class QDateTime; class QNetworkCookie; -class QSize; class QTime; namespace Scheduler @@ -353,10 +352,6 @@ public: void setPropVisible(bool visible); QByteArray getPropTrackerListState() const; void setPropTrackerListState(const QByteArray &state); - QSize getRssGeometrySize() const; - void setRssGeometrySize(const QSize &geometry); - QByteArray getRssHSplitterSizes() const; - void setRssHSplitterSizes(const QByteArray &sizes); QStringList getRssOpenFolders() const; void setRssOpenFolders(const QStringList &folders); QByteArray getRssSideSplitterState() const; diff --git a/src/gui/aboutdialog.cpp b/src/gui/aboutdialog.cpp index 682dadc3d..9e9959209 100644 --- a/src/gui/aboutdialog.cpp +++ b/src/gui/aboutdialog.cpp @@ -112,7 +112,8 @@ AboutDialog::AboutDialog(QWidget *parent) "The database is licensed under the Creative Commons Attribution 4.0 International License")); m_ui->labelDBIP->setText(DBIPText); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } AboutDialog::~AboutDialog() diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index f29c2e0d7..1d4c7a430 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -336,7 +336,9 @@ void AddNewTorrentDialog::setSavePathHistoryLength(const int value) void AddNewTorrentDialog::loadState() { - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); + m_ui->splitter->restoreState(m_storeSplitterState);; } diff --git a/src/gui/banlistoptionsdialog.cpp b/src/gui/banlistoptionsdialog.cpp index 595a32836..4350dd929 100644 --- a/src/gui/banlistoptionsdialog.cpp +++ b/src/gui/banlistoptionsdialog.cpp @@ -56,7 +56,8 @@ BanListOptionsDialog::BanListOptionsDialog(QWidget *parent) m_ui->bannedIPList->sortByColumn(0, Qt::AscendingOrder); m_ui->buttonBanIP->setEnabled(false); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } BanListOptionsDialog::~BanListOptionsDialog() diff --git a/src/gui/cookiesdialog.cpp b/src/gui/cookiesdialog.cpp index 7a829613d..9f3b16045 100644 --- a/src/gui/cookiesdialog.cpp +++ b/src/gui/cookiesdialog.cpp @@ -64,7 +64,9 @@ CookiesDialog::CookiesDialog(QWidget *parent) m_cookiesModel->index(0, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); + m_ui->treeView->header()->restoreState(m_storeViewState); } diff --git a/src/gui/downloadfromurldialog.cpp b/src/gui/downloadfromurldialog.cpp index 34ba6bd06..af3026fbc 100644 --- a/src/gui/downloadfromurldialog.cpp +++ b/src/gui/downloadfromurldialog.cpp @@ -92,7 +92,8 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent) m_ui->textUrls->setText(text); m_ui->textUrls->moveCursor(QTextCursor::End); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } DownloadFromURLDialog::~DownloadFromURLDialog() diff --git a/src/gui/ipsubnetwhitelistoptionsdialog.cpp b/src/gui/ipsubnetwhitelistoptionsdialog.cpp index 6be57b8a7..96da8fcbc 100644 --- a/src/gui/ipsubnetwhitelistoptionsdialog.cpp +++ b/src/gui/ipsubnetwhitelistoptionsdialog.cpp @@ -60,7 +60,8 @@ IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent) m_ui->whitelistedIPSubnetList->sortByColumn(0, Qt::AscendingOrder); m_ui->buttonWhitelistIPSubnet->setEnabled(false); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } IPSubnetWhitelistOptionsDialog::~IPSubnetWhitelistOptionsDialog() diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 323ba6163..9b79240b8 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -572,10 +572,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) m_ui->tabSelection->setCurrentRow(m_storeLastViewedPage); - resize(m_storeDialogSize); - - // Have to be called after show(), because splitter width needed - loadSplitterState(); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } void OptionsDialog::initializeLanguageCombo() @@ -646,6 +644,13 @@ void OptionsDialog::loadSplitterState() m_ui->hsplitter->setSizes(splitterSizes); } +void OptionsDialog::showEvent(QShowEvent *e) +{ + QDialog::showEvent(e); + + loadSplitterState(); +} + void OptionsDialog::saveOptions() { auto *pref = Preferences::instance(); diff --git a/src/gui/optionsdialog.h b/src/gui/optionsdialog.h index 5454f0cf5..c15b0a3dd 100644 --- a/src/gui/optionsdialog.h +++ b/src/gui/optionsdialog.h @@ -115,6 +115,8 @@ private slots: void webUIHttpsKeyChanged(const Path &path, ShowError showError); private: + void showEvent(QShowEvent *e) override; + // Methods void saveOptions(); void loadOptions(); diff --git a/src/gui/previewselectdialog.cpp b/src/gui/previewselectdialog.cpp index 6c7427a09..b7c05f16e 100644 --- a/src/gui/previewselectdialog.cpp +++ b/src/gui/previewselectdialog.cpp @@ -173,13 +173,12 @@ void PreviewSelectDialog::saveWindowState() void PreviewSelectDialog::loadWindowState() { // Restore dialog size - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); // Restore TreeView Header state - if (!m_storeTreeHeaderState.get().isEmpty()) - { - m_headerStateInitialized = m_ui->previewList->header()->restoreState(m_storeTreeHeaderState); - } + if (const QByteArray treeHeaderState = m_storeTreeHeaderState; !treeHeaderState.isEmpty()) + m_headerStateInitialized = m_ui->previewList->header()->restoreState(treeHeaderState); } void PreviewSelectDialog::showEvent(QShowEvent *event) diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index f5f80ff2b..2159199c5 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -29,6 +29,7 @@ #include "automatedrssdownloader.h" +#include #include #include #include @@ -41,7 +42,6 @@ #include "base/bittorrent/session.h" #include "base/global.h" #include "base/path.h" -#include "base/preferences.h" #include "base/rss/rss_article.h" #include "base/rss/rss_autodownloader.h" #include "base/rss/rss_feed.h" @@ -65,6 +65,13 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) , m_formatFilterLegacy(u"%1 (*%2)"_qs.arg(tr("Rules (legacy)"), EXT_LEGACY)) , m_ui(new Ui::AutomatedRssDownloader) , m_currentRuleItem(nullptr) + , m_storeDialogSize {u"RssFeedDownloader/geometrySize"_qs} +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + , m_storeHSplitterSize {u"GUI/Qt6/RSSFeedDownloader/HSplitterSizes"_qs} +#else + , m_storeHSplitterSize {u"RssFeedDownloader/qt5/hsplitterSizes"_qs} +#endif + { m_ui->setupUi(this); // Icons @@ -160,16 +167,17 @@ AutomatedRssDownloader::~AutomatedRssDownloader() void AutomatedRssDownloader::loadSettings() { - const auto *pref = Preferences::instance(); - resize(pref->getRssGeometrySize()); - m_ui->hsplitter->restoreState(pref->getRssHSplitterSizes()); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); + + if (const QByteArray hSplitterSize = m_storeHSplitterSize; !hSplitterSize.isEmpty()) + m_ui->hsplitter->restoreState(hSplitterSize); } void AutomatedRssDownloader::saveSettings() { - Preferences *const pref = Preferences::instance(); - pref->setRssGeometrySize(size()); - pref->setRssHSplitterSizes(m_ui->hsplitter->saveState()); + m_storeDialogSize = size(); + m_storeHSplitterSize = m_ui->hsplitter->saveState(); } void AutomatedRssDownloader::createRuleItem(const RSS::AutoDownloadRule &rule) diff --git a/src/gui/rss/automatedrssdownloader.h b/src/gui/rss/automatedrssdownloader.h index 3a5eadce0..304f33b8b 100644 --- a/src/gui/rss/automatedrssdownloader.h +++ b/src/gui/rss/automatedrssdownloader.h @@ -36,6 +36,7 @@ #include #include "base/rss/rss_autodownloadrule.h" +#include "base/settingvalue.h" class QListWidgetItem; class QRegularExpression; @@ -106,4 +107,7 @@ private: RSS::AutoDownloadRule m_currentRule; QHash m_itemsByRuleName; QRegularExpression *m_episodeRegex; + + SettingValue m_storeDialogSize; + SettingValue m_storeHSplitterSize; }; diff --git a/src/gui/search/pluginselectdialog.cpp b/src/gui/search/pluginselectdialog.cpp index d90819f98..33fb63703 100644 --- a/src/gui/search/pluginselectdialog.cpp +++ b/src/gui/search/pluginselectdialog.cpp @@ -87,7 +87,8 @@ PluginSelectDialog::PluginSelectDialog(SearchPluginManager *pluginManager, QWidg connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFinished, this, &PluginSelectDialog::checkForUpdatesFinished); connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFailed, this, &PluginSelectDialog::checkForUpdatesFailed); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } PluginSelectDialog::~PluginSelectDialog() diff --git a/src/gui/search/pluginsourcedialog.cpp b/src/gui/search/pluginsourcedialog.cpp index 65694c21c..12f631756 100644 --- a/src/gui/search/pluginsourcedialog.cpp +++ b/src/gui/search/pluginsourcedialog.cpp @@ -40,7 +40,8 @@ PluginSourceDialog::PluginSourceDialog(QWidget *parent) { m_ui->setupUi(this); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } PluginSourceDialog::~PluginSourceDialog() diff --git a/src/gui/speedlimitdialog.cpp b/src/gui/speedlimitdialog.cpp index 3a95bc95f..165ece724 100644 --- a/src/gui/speedlimitdialog.cpp +++ b/src/gui/speedlimitdialog.cpp @@ -108,7 +108,8 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) connect(m_ui->spinAltDownloadLimit, qOverload(&QSpinBox::valueChanged) , this, [this](const int value) { updateSliderValue(m_ui->sliderAltDownloadLimit, value); }); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } SpeedLimitDialog::~SpeedLimitDialog() diff --git a/src/gui/statsdialog.cpp b/src/gui/statsdialog.cpp index 3849240ad..d0fcc9aab 100644 --- a/src/gui/statsdialog.cpp +++ b/src/gui/statsdialog.cpp @@ -60,7 +60,8 @@ StatsDialog::StatsDialog(QWidget *parent) m_ui->labelCacheHits->hide(); #endif - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } StatsDialog::~StatsDialog() diff --git a/src/gui/torrentcreatordialog.cpp b/src/gui/torrentcreatordialog.cpp index eed17ffdc..86e941344 100644 --- a/src/gui/torrentcreatordialog.cpp +++ b/src/gui/torrentcreatordialog.cpp @@ -340,5 +340,6 @@ void TorrentCreatorDialog::loadSettings() m_ui->txtComment->setPlainText(m_storeComments); m_ui->lineEditSource->setText(m_storeSource); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index ea5968865..f9f7fab33 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -390,7 +390,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectorbuttonGroup, &QButtonGroup::idClicked, this, &TorrentOptionsDialog::handleRatioTypeChanged); - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } TorrentOptionsDialog::~TorrentOptionsDialog() diff --git a/src/gui/trackerentriesdialog.cpp b/src/gui/trackerentriesdialog.cpp index 76ae8c965..62e82904d 100644 --- a/src/gui/trackerentriesdialog.cpp +++ b/src/gui/trackerentriesdialog.cpp @@ -110,5 +110,6 @@ void TrackerEntriesDialog::saveSettings() void TrackerEntriesDialog::loadSettings() { - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } diff --git a/src/gui/watchedfolderoptionsdialog.cpp b/src/gui/watchedfolderoptionsdialog.cpp index 2054f5efe..480352b8e 100644 --- a/src/gui/watchedfolderoptionsdialog.cpp +++ b/src/gui/watchedfolderoptionsdialog.cpp @@ -125,7 +125,8 @@ TorrentFilesWatcher::WatchedFolderOptions WatchedFolderOptionsDialog::watchedFol void WatchedFolderOptionsDialog::loadState() { - resize(m_storeDialogSize); + if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid()) + resize(dialogSize); } void WatchedFolderOptionsDialog::saveState()