From 14e2ede448dad59675dd413a16fb7a0246576869 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 17 Sep 2020 22:18:13 +0200 Subject: [PATCH] Moved a sorting function to the proper location inside the correct class. --- es-app/src/CollectionSystemManager.cpp | 28 ++++++++++--------- es-app/src/FileData.cpp | 25 ++++++++--------- es-app/src/FileData.h | 4 +-- es-app/src/SystemData.cpp | 2 +- es-app/src/guis/GuiMenu.cpp | 6 ++-- es-app/src/guis/GuiMetaDataEd.cpp | 2 +- .../views/gamelist/ISimpleGameListView.cpp | 2 +- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index 11096e909..dc7a55693 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -217,11 +217,11 @@ void CollectionSystemManager::updateSystemsList() // Don't sort bundled collections unless at least one collection is enabled. if (!mIsEditingCustom && mHasEnabledCustomCollection) { + FileData* rootFolder = mCustomCollectionsBundle->getRootFolder(); // Sort the bundled custom collections. - if (mCustomCollectionsBundle->getRootFolder()->getChildren().size() > 0) { - mCustomCollectionsBundle->getRootFolder()->sort(getSortTypeFromString( - mCustomCollectionsBundle->getRootFolder()->getSortTypeString()), - Settings::getInstance()->getBool("FavFirstCustom")); + if (rootFolder->getChildren().size() > 0) { + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder-> + getSortTypeString()), Settings::getInstance()->getBool("FavFirstCustom")); SystemData::sSystemVector.push_back(mCustomCollectionsBundle); } } @@ -348,22 +348,22 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS } if (name == "recent") { - rootFolder->sort(getSortTypeFromString("last played, descending")); + rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending")); } else if (sysData.decl.isCustom && !Settings::getInstance()->getBool("UseCustomCollectionsSystem")) { - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), mFavoritesSorting); } // If the game doesn't exist in the current system and it's a custom // collection, then skip the sorting. else if (sysData.decl.isCustom && children.find(file->getFullPath()) != children.cend()) { - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), mFavoritesSorting); } else if (!sysData.decl.isCustom) { - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), mFavoritesSorting); } @@ -600,9 +600,10 @@ bool CollectionSystemManager::toggleGameInCollection(FileData* file) ViewController::get()->getGameListView(systemViewToUpdate)-> onFileChanged(newGame, FILE_METADATA_CHANGED); if (name == "recent") - rootFolder->sort(getSortTypeFromString("last played, descending")); + rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending")); else - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString( + rootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavFirstCustom")); ViewController::get()->onFileChanged(systemViewToUpdate-> @@ -850,9 +851,9 @@ void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysDa } } if (rootFolder->getName() == "recent") - rootFolder->sort(getSortTypeFromString("last played, descending")); + rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending")); else - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); if (sysDecl.type == AUTO_LAST_PLAYED) @@ -966,7 +967,8 @@ void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems( // If this is a non-bundled custom collection, then sort it. if (it->second.decl.isCustom == true) { FileData* rootFolder = it->second.system->getRootFolder(); - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString( + rootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavFirstCustom")); // Jump to the first row of the game list, assuming it's not empty. IGameListView* gameList = ViewController::get()-> diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 5588e6fb2..fe90306c8 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -621,6 +621,18 @@ void FileData::sort(const SortType& type, bool mFavoritesOnTop) sort(*type.comparisonFunction, type.ascending); } +FileData::SortType FileData::getSortTypeFromString(std::string desc) { + std::vector SortTypes = FileSorts::SortTypes; + + for (unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) { + const FileData::SortType& sort = FileSorts::SortTypes.at(i); + if (sort.description == desc) + return sort; + } + // If no type was found then default to "filename, ascending". + return FileSorts::SortTypes.at(0); +} + void FileData::launchGame(Window* window) { LOG(LogInfo) << "Attempting to launch game..."; @@ -831,16 +843,3 @@ const std::string& CollectionFileData::getName() return mSourceFileData->metadata.get("name"); } - -// Return sort type based on a string description. -FileData::SortType getSortTypeFromString(std::string desc) { - std::vector SortTypes = FileSorts::SortTypes; - // Find it - for (unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) { - const FileData::SortType& sort = FileSorts::SortTypes.at(i); - if (sort.description == desc) - return sort; - } - // If no type found then default to "filename, ascending". - return FileSorts::SortTypes.at(0); -} diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index 5a9da003c..84ded8fe1 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -129,6 +129,8 @@ public: inline void setSortTypeString(std::string typestring) { mSortTypeString = typestring; } inline std::string getSortTypeString() { return mSortTypeString; } + // Return sort type based on a string description. + FileData::SortType getSortTypeFromString(std::string desc); protected: FileData* mSourceFileData; @@ -167,6 +169,4 @@ private: bool mDirty; }; -FileData::SortType getSortTypeFromString(std::string desc); - #endif // ES_APP_FILE_DATA_H diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index a6561d07f..f4ab91ad0 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -60,7 +60,7 @@ SystemData::SystemData( setupSystemSortType(mRootFolder); - mRootFolder->sort(getSortTypeFromString(mRootFolder->getSortTypeString()), + mRootFolder->sort(mRootFolder->getSortTypeFromString(mRootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); indexAllGameFilters(mRootFolder); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index d9a9e12e5..f0f30710a 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -385,7 +385,7 @@ void GuiMenu::openUISettings() FileData* rootFolder = (*it)->getRootFolder(); rootFolder->getSystem()->setupSystemSortType(rootFolder); - rootFolder->sort(getSortTypeFromString( + rootFolder->sort(rootFolder->getSortTypeFromString( rootFolder->getSortTypeString()), favoritesSorting); ViewController::get()->reloadGameListView(*it); @@ -458,7 +458,7 @@ void GuiMenu::openUISettings() continue; FileData* rootFolder = (*it)->getRootFolder(); - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); ViewController::get()->reloadGameListView(*it); @@ -486,7 +486,7 @@ void GuiMenu::openUISettings() continue; FileData* rootFolder = (*it)->getRootFolder(); - rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), + rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); ViewController::get()->reloadGameListView(*it); diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 531caefe0..cf4c33944 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -380,7 +380,7 @@ void GuiMetaDataEd::save() // and reload the gamelist as CollectionSystemManager ignores folders. if (hideGameWhileHidden && mScraperParams.game->getType() == FOLDER) { FileData* systemRoot = mScraperParams.system->getRootFolder(); - systemRoot->sort(getSortTypeFromString(systemRoot->getSortTypeString()), + systemRoot->sort(systemRoot->getSortTypeFromString(systemRoot->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); ViewController::get()->reloadGameListView(mScraperParams.system); } diff --git a/es-app/src/views/gamelist/ISimpleGameListView.cpp b/es-app/src/views/gamelist/ISimpleGameListView.cpp index b08dd07ee..b01dd0541 100644 --- a/es-app/src/views/gamelist/ISimpleGameListView.cpp +++ b/es-app/src/views/gamelist/ISimpleGameListView.cpp @@ -205,7 +205,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) getCursor()->getSourceFileData()->getSystem()->onMetaDataSavePoint(); if (!Settings::getInstance()->getBool("FoldersOnTop")) - mRoot->sort(getSortTypeFromString(mRoot->getSortTypeString()), + mRoot->sort(mRoot->getSortTypeFromString(mRoot->getSortTypeString()), Settings::getInstance()->getBool("FavoritesFirst")); ViewController::get()->onFileChanged(getCursor(), FILE_METADATA_CHANGED);