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.
This commit is contained in:
Jake Merdich 2017-03-28 04:32:21 -04:00
parent 36aaaafc26
commit abf54effe0
3 changed files with 20 additions and 5 deletions

View File

@ -37,6 +37,10 @@ GameList::GameList(QWidget* parent) : QWidget{parent} {
item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, "File type"); item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, "File type");
item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, "Size"); 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::activated, this, &GameList::ValidateEntry);
connect(tree_view, &QTreeView::customContextMenuRequested, this, &GameList::PopupContextMenu); connect(tree_view, &QTreeView::customContextMenuRequested, this, &GameList::PopupContextMenu);
connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory); connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory);
@ -151,9 +155,18 @@ static bool HasSupportedFileExtension(const std::string& file_name) {
} }
void GameList::RefreshGameDirectory() { 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."); 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();
} }
} }

View File

@ -33,6 +33,7 @@ public:
void SaveInterfaceLayout(); void SaveInterfaceLayout();
void LoadInterfaceLayout(); void LoadInterfaceLayout();
void OnSettingsUpdated();
static const QStringList supported_file_extensions; static const QStringList supported_file_extensions;
@ -54,4 +55,6 @@ private:
QStandardItemModel* item_model = nullptr; QStandardItemModel* item_model = nullptr;
GameListWorker* current_worker = nullptr; GameListWorker* current_worker = nullptr;
QFileSystemWatcher watcher; QFileSystemWatcher watcher;
QString game_directory;
bool recursive;
}; };

View File

@ -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)); .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc));
show(); show();
game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
QStringList args = QApplication::arguments(); QStringList args = QApplication::arguments();
if (args.length() >= 2) { if (args.length() >= 2) {
BootGame(args[1]); BootGame(args[1]);
@ -538,7 +536,7 @@ void GMainWindow::OnMenuSelectGameListRoot() {
QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
if (!dir_path.isEmpty()) { if (!dir_path.isEmpty()) {
UISettings::values.gamedir = dir_path; 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(); auto result = configureDialog.exec();
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
configureDialog.applyConfiguration(); configureDialog.applyConfiguration();
game_list->OnSettingsUpdated();
config->Save(); config->Save();
} }
} }