diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index e6b11e8d8..0f1904dcb 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -1482,6 +1482,22 @@ void GameListWidget::reloadThemeSpecificImages() m_model->reloadThemeSpecificImages(); } +void GameListWidget::setBackgroundPath(const std::string_view path) +{ + if (!path.empty()) + { + Host::SetBaseStringSettingValue("UI", "GameListBackgroundPath", + Path::MakeRelative(path, EmuFolders::DataRoot).c_str()); + } + else + { + Host::DeleteBaseSettingValue("UI", "GameListBackgroundPath"); + } + + Host::CommitBaseSettingChanges(); + updateBackground(true); +} + void GameListWidget::updateBackground(bool reload_image) { const bool had_image = !m_background_image.isNull(); @@ -1529,6 +1545,11 @@ void GameListWidget::updateBackground(bool reload_image) }); } +bool GameListWidget::hasBackground() const +{ + return !m_background_image.isNull(); +} + void GameListWidget::onRefreshProgress(const QString& status, int current, int total, int entry_count, float time) { // Avoid spamming the UI on very short refresh (e.g. game exit). diff --git a/src/duckstation-qt/gamelistwidget.h b/src/duckstation-qt/gamelistwidget.h index 9255ce6d8..0a815f819 100644 --- a/src/duckstation-qt/gamelistwidget.h +++ b/src/duckstation-qt/gamelistwidget.h @@ -242,7 +242,8 @@ public: void refresh(bool invalidate_cache); void cancelRefresh(); void reloadThemeSpecificImages(); - void updateBackground(bool reload_image); + void setBackgroundPath(const std::string_view path); + bool hasBackground() const; bool isShowingGameList() const; bool isShowingGameGrid() const; @@ -293,6 +294,7 @@ protected: private: void setViewMode(int stack_index); + void updateBackground(bool reload_image); Ui::GameListWidget m_ui; diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 218039ae4..db7bca7c3 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -539,7 +539,7 @@ void MainWindow::updateGameListRelatedActions() const bool game_grid = m_game_list_widget->isShowingGameGrid(); const bool game_list = m_game_list_widget->isShowingGameList(); - const bool has_background = Host::GetBaseStringSettingValue("UI", "GameListBackgroundPath") != ""; + const bool has_background = m_game_list_widget->hasBackground(); m_ui.menuSortBy->setDisabled(disable); m_ui.actionMergeDiscSets->setDisabled(disable); @@ -2741,18 +2741,13 @@ void MainWindow::onViewChangeGameListBackgroundTriggered() if (path.isEmpty()) return; - std::string relative_path = Path::MakeRelative(QDir::toNativeSeparators(path).toStdString(), EmuFolders::DataRoot); - Host::SetBaseStringSettingValue("UI", "GameListBackgroundPath", relative_path.c_str()); - Host::CommitBaseSettingChanges(); - m_game_list_widget->updateBackground(true); + m_game_list_widget->setBackgroundPath(QDir::toNativeSeparators(path).toStdString()); m_ui.actionClearGameListBackground->setEnabled(true); } void MainWindow::onViewClearGameListBackgroundTriggered() { - Host::DeleteBaseSettingValue("UI", "GameListBackgroundPath"); - Host::CommitBaseSettingChanges(); - m_game_list_widget->updateBackground(true); + m_game_list_widget->setBackgroundPath({}); m_ui.actionClearGameListBackground->setEnabled(false); }