Skip to content

Commit 9877cc0

Browse files
committed
Qt: Move list background config logic to GameListWidget
1 parent 4d5b047 commit 9877cc0

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/duckstation-qt/gamelistwidget.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,22 @@ void GameListWidget::reloadThemeSpecificImages()
14821482
m_model->reloadThemeSpecificImages();
14831483
}
14841484

1485+
void GameListWidget::setBackgroundPath(const std::string_view path)
1486+
{
1487+
if (!path.empty())
1488+
{
1489+
Host::SetBaseStringSettingValue("UI", "GameListBackgroundPath",
1490+
Path::MakeRelative(path, EmuFolders::DataRoot).c_str());
1491+
}
1492+
else
1493+
{
1494+
Host::DeleteBaseSettingValue("UI", "GameListBackgroundPath");
1495+
}
1496+
1497+
Host::CommitBaseSettingChanges();
1498+
updateBackground(true);
1499+
}
1500+
14851501
void GameListWidget::updateBackground(bool reload_image)
14861502
{
14871503
const bool had_image = !m_background_image.isNull();
@@ -1529,6 +1545,11 @@ void GameListWidget::updateBackground(bool reload_image)
15291545
});
15301546
}
15311547

1548+
bool GameListWidget::hasBackground() const
1549+
{
1550+
return !m_background_image.isNull();
1551+
}
1552+
15321553
void GameListWidget::onRefreshProgress(const QString& status, int current, int total, int entry_count, float time)
15331554
{
15341555
// Avoid spamming the UI on very short refresh (e.g. game exit).

src/duckstation-qt/gamelistwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ class GameListWidget final : public QWidget
242242
void refresh(bool invalidate_cache);
243243
void cancelRefresh();
244244
void reloadThemeSpecificImages();
245-
void updateBackground(bool reload_image);
245+
void setBackgroundPath(const std::string_view path);
246+
bool hasBackground() const;
246247

247248
bool isShowingGameList() const;
248249
bool isShowingGameGrid() const;
@@ -293,6 +294,7 @@ public Q_SLOTS:
293294

294295
private:
295296
void setViewMode(int stack_index);
297+
void updateBackground(bool reload_image);
296298

297299
Ui::GameListWidget m_ui;
298300

src/duckstation-qt/mainwindow.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ void MainWindow::updateGameListRelatedActions()
539539

540540
const bool game_grid = m_game_list_widget->isShowingGameGrid();
541541
const bool game_list = m_game_list_widget->isShowingGameList();
542-
const bool has_background = Host::GetBaseStringSettingValue("UI", "GameListBackgroundPath") != "";
542+
const bool has_background = m_game_list_widget->hasBackground();
543543

544544
m_ui.menuSortBy->setDisabled(disable);
545545
m_ui.actionMergeDiscSets->setDisabled(disable);
@@ -2741,18 +2741,13 @@ void MainWindow::onViewChangeGameListBackgroundTriggered()
27412741
if (path.isEmpty())
27422742
return;
27432743

2744-
std::string relative_path = Path::MakeRelative(QDir::toNativeSeparators(path).toStdString(), EmuFolders::DataRoot);
2745-
Host::SetBaseStringSettingValue("UI", "GameListBackgroundPath", relative_path.c_str());
2746-
Host::CommitBaseSettingChanges();
2747-
m_game_list_widget->updateBackground(true);
2744+
m_game_list_widget->setBackgroundPath(QDir::toNativeSeparators(path).toStdString());
27482745
m_ui.actionClearGameListBackground->setEnabled(true);
27492746
}
27502747

27512748
void MainWindow::onViewClearGameListBackgroundTriggered()
27522749
{
2753-
Host::DeleteBaseSettingValue("UI", "GameListBackgroundPath");
2754-
Host::CommitBaseSettingChanges();
2755-
m_game_list_widget->updateBackground(true);
2750+
m_game_list_widget->setBackgroundPath({});
27562751
m_ui.actionClearGameListBackground->setEnabled(false);
27572752
}
27582753

0 commit comments

Comments
 (0)