From 07efcd19d05ff7020096245143d4a49f853e63f8 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 30 Oct 2020 10:12:15 +0100 Subject: [PATCH] Simplified the detection of grouped custom collections. --- es-app/src/CollectionSystemManager.cpp | 33 ++++++-------------------- es-app/src/CollectionSystemManager.h | 2 -- es-app/src/SystemData.cpp | 3 ++- es-app/src/SystemData.h | 4 ++++ es-app/src/guis/GuiMenu.cpp | 2 +- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index 174516ae3..ad379d294 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -442,19 +442,13 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS } else { ViewController::get()->onFileChanged(rootFolder, false); - // If it's a custom collection and the setting to group the collections is - // enabled, we may have to update the parent instead. - // However it may not necessarily be so if some collections are themed and - // some are not, so we always need to check whether a parent exists. - if (sysData.decl.isCustom && - Settings::getInstance()->getBool("UseCustomCollectionsSystem")) { - // In case of a returned null pointer, we know there is no parent. - if (rootFolder->getParent() == nullptr) { - ViewController::get()->onFileChanged(rootFolder, false); - } - else { + // For custom collections, update either the actual system or its parent depending + // on whether the collection is grouped or not. + if (sysData.decl.isCustom) { + if (rootFolder->getSystem()->isGroupedCustomCollection()) ViewController::get()->onFileChanged(rootFolder->getParent(), false); - } + else + ViewController::get()->onFileChanged(rootFolder, false); } } } @@ -1063,6 +1057,7 @@ void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems( FileData* newSysRootFolder = it->second.system->getRootFolder(); mCustomCollectionsBundle->getRootFolder()->addChild(newSysRootFolder); mCustomCollectionsBundle->getIndex()->importIndex(it->second.system->getIndex()); + it->second.system->setIsGroupedCustomCollection(true); } } } @@ -1251,17 +1246,3 @@ std::string CollectionSystemManager::getCollectionsFolder() return Utils::FileSystem::getGenericPath(Utils::FileSystem::getHomePath() + "/.emulationstation/collections"); } - -// Return whether the system is a custom collection. -bool CollectionSystemManager::getIsCustomCollection(SystemData* system) -{ - // Iterate the map. - for (std::map::const_iterator - it = mCustomCollectionSystemsData.cbegin(); - it != mCustomCollectionSystemsData.cend() ; it++) { - if (it->second.system == system) - return true; - } - - return false; -} diff --git a/es-app/src/CollectionSystemManager.h b/es-app/src/CollectionSystemManager.h index 6f1ad9ec2..e141e8a8c 100644 --- a/es-app/src/CollectionSystemManager.h +++ b/es-app/src/CollectionSystemManager.h @@ -103,8 +103,6 @@ public: SystemData* getSystemToView(SystemData* sys); FileData* updateCollectionFolderMetadata(SystemData* sys); - bool getIsCustomCollection(SystemData* system); - private: static CollectionSystemManager* sInstance; SystemEnvironmentData* mCollectionEnvData; diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index b7f667f8f..235afba23 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -44,6 +44,7 @@ SystemData::SystemData( mThemeFolder(themeFolder), mIsCollectionSystem(CollectionSystem), mIsCustomCollectionSystem(CustomCollectionSystem), + mIsGroupedCustomCollectionSystem(false), mIsGameSystem(true), mScrapeFlag(false) { @@ -629,7 +630,7 @@ void SystemData::sortSystem(bool reloadGamelist) bool favoritesSorting; - if (CollectionSystemManager::get()->getIsCustomCollection(this)) + if (this->isCustomCollection()) favoritesSorting = Settings::getInstance()->getBool("FavFirstCustom"); else favoritesSorting = Settings::getInstance()->getBool("FavoritesFirst"); diff --git a/es-app/src/SystemData.h b/es-app/src/SystemData.h index a2250c1a2..a6a5d4c4e 100644 --- a/es-app/src/SystemData.h +++ b/es-app/src/SystemData.h @@ -83,6 +83,9 @@ public: { return std::find(sSystemVector.crbegin(), sSystemVector.crend(), this); }; inline bool isCollection() { return mIsCollectionSystem; }; inline bool isCustomCollection() { return mIsCustomCollectionSystem; }; + inline bool isGroupedCustomCollection() { return mIsGroupedCustomCollectionSystem; }; + void setIsGroupedCustomCollection(bool isGroupedCustom) + { mIsGroupedCustomCollectionSystem = isGroupedCustom; }; inline bool isGameSystem() { return mIsGameSystem; }; bool isVisible(); @@ -106,6 +109,7 @@ public: private: bool mIsCollectionSystem; bool mIsCustomCollectionSystem; + bool mIsGroupedCustomCollectionSystem; bool mIsGameSystem; bool mScrapeFlag; // Only used by scraper GUI to remember which systems to scrape. std::string mName; diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index e75634c3e..e02da4d0e 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -468,7 +468,7 @@ void GuiMenu::openUISettings() continue; // Don't re-sort custom collections as they have their own option // for whether to sort favorites on top or not (FavFirstCustom). - if (CollectionSystemManager::get()->getIsCustomCollection((*it))) + if ((*it)->isCustomCollection()) continue; FileData* rootFolder = (*it)->getRootFolder();