From abf54effe07fbd0dde17ba5763ac30fc006cab98 Mon Sep 17 00:00:00 2001 From: Jake Merdich Date: Tue, 28 Mar 2017 04:32:21 -0400 Subject: [PATCH] Refresh game list if recursion setting changed This version cleans out all the signals/slots boilerplate, and only actually refreshes the list if that checkbox is modified. It also makes it so that changing to the same directory is a nop. --- src/citra_qt/game_list.cpp | 17 +++++++++++++++-- src/citra_qt/game_list.h | 3 +++ src/citra_qt/main.cpp | 5 ++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index f630a1ec2..4d1f9ab67 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -37,6 +37,10 @@ GameList::GameList(QWidget* parent) : QWidget{parent} { item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, "File type"); item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, "Size"); + recursive = UISettings::values.gamedir_deepscan; + game_directory = UISettings::values.gamedir; + PopulateAsync(game_directory, recursive); + connect(tree_view, &QTreeView::activated, this, &GameList::ValidateEntry); connect(tree_view, &QTreeView::customContextMenuRequested, this, &GameList::PopupContextMenu); connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory); @@ -151,9 +155,18 @@ static bool HasSupportedFileExtension(const std::string& file_name) { } void GameList::RefreshGameDirectory() { - if (!UISettings::values.gamedir.isEmpty() && current_worker != nullptr) { + if (!game_directory.isEmpty() && current_worker != nullptr) { LOG_INFO(Frontend, "Change detected in the games directory. Reloading game list."); - PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan); + PopulateAsync(game_directory, recursive); + } +} + +void GameList::OnSettingsUpdated() { + if (UISettings::values.gamedir_deepscan != recursive || + UISettings::values.gamedir != game_directory) { + game_directory = UISettings::values.gamedir; + recursive = UISettings::values.gamedir_deepscan; + RefreshGameDirectory(); } } diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h index b141fa3a5..d0b9d44bc 100644 --- a/src/citra_qt/game_list.h +++ b/src/citra_qt/game_list.h @@ -33,6 +33,7 @@ public: void SaveInterfaceLayout(); void LoadInterfaceLayout(); + void OnSettingsUpdated(); static const QStringList supported_file_extensions; @@ -54,4 +55,6 @@ private: QStandardItemModel* item_model = nullptr; GameListWorker* current_worker = nullptr; QFileSystemWatcher watcher; + QString game_directory; + bool recursive; }; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 2723a0217..7e0e630d2 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -73,8 +73,6 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc)); show(); - game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan); - QStringList args = QApplication::arguments(); if (args.length() >= 2) { BootGame(args[1]); @@ -538,7 +536,7 @@ void GMainWindow::OnMenuSelectGameListRoot() { QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); if (!dir_path.isEmpty()) { UISettings::values.gamedir = dir_path; - game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan); + game_list->OnSettingsUpdated(); } } @@ -612,6 +610,7 @@ void GMainWindow::OnConfigure() { auto result = configureDialog.exec(); if (result == QDialog::Accepted) { configureDialog.applyConfiguration(); + game_list->OnSettingsUpdated(); config->Save(); } }