Simplified the detection of grouped custom collections.

This commit is contained in:
Leon Styhre 2020-10-30 10:12:15 +01:00
parent b9301f08da
commit 07efcd19d0
5 changed files with 14 additions and 30 deletions

View file

@ -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<std::string, CollectionSystemData, stringComparator>::const_iterator
it = mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend() ; it++) {
if (it->second.system == system)
return true;
}
return false;
}

View file

@ -103,8 +103,6 @@ public:
SystemData* getSystemToView(SystemData* sys);
FileData* updateCollectionFolderMetadata(SystemData* sys);
bool getIsCustomCollection(SystemData* system);
private:
static CollectionSystemManager* sInstance;
SystemEnvironmentData* mCollectionEnvData;

View file

@ -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");

View file

@ -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;

View file

@ -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();