Some code cleanup for FileFilterIndex.

This commit is contained in:
Leon Styhre 2020-11-08 16:47:51 +01:00
parent cfad51fdb4
commit 56ae90cc67
2 changed files with 94 additions and 94 deletions

View file

@ -20,29 +20,29 @@
FileFilterIndex::FileFilterIndex() FileFilterIndex::FileFilterIndex()
: mFilterByText(false), : mFilterByText(false),
filterByFavorites(false), mFilterByFavorites(false),
filterByGenre(false), mFilterByGenre(false),
filterByPlayers(false), mFilterByPlayers(false),
filterByPubDev(false), mFilterByPubDev(false),
filterByRatings(false), mFilterByRatings(false),
filterByKidGame(false), mFilterByKidGame(false),
filterByCompleted(false), mFilterByCompleted(false),
filterByBroken(false), mFilterByBroken(false),
filterByHidden(false) mFilterByHidden(false)
{ {
clearAllFilters(); clearAllFilters();
FilterDataDecl filterDecls[] = { FilterDataDecl filterDecls[] = {
//type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel //type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel
{ FAVORITES_FILTER, &favoritesIndexAllKeys, &filterByFavorites, &favoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES" }, { FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES" },
{ GENRE_FILTER, &genreIndexAllKeys, &filterByGenre, &genreIndexFilteredKeys, "genre", true, "genre", "GENRE" }, { GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE" },
{ PLAYER_FILTER, &playersIndexAllKeys, &filterByPlayers, &playersIndexFilteredKeys, "players", false, "", "PLAYERS" }, { PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS" },
{ PUBDEV_FILTER, &pubDevIndexAllKeys, &filterByPubDev, &pubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER" }, { PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER" },
{ RATINGS_FILTER, &ratingsIndexAllKeys, &filterByRatings, &ratingsIndexFilteredKeys, "rating", false, "", "RATING" }, { RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING" },
{ KIDGAME_FILTER, &kidGameIndexAllKeys, &filterByKidGame, &kidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME" }, { KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME" },
{ COMPLETED_FILTER, &completedIndexAllKeys, &filterByCompleted, &completedIndexFilteredKeys, "completed", false, "", "COMPLETED" }, { COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED" },
{ BROKEN_FILTER, &brokenIndexAllKeys, &filterByBroken, &brokenIndexFilteredKeys, "broken", false, "", "BROKEN" }, { BROKEN_FILTER, &mBrokenIndexAllKeys, &mFilterByBroken, &mBrokenIndexFilteredKeys, "broken", false, "", "BROKEN" },
{ HIDDEN_FILTER, &hiddenIndexAllKeys, &filterByHidden, &hiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN" } { HIDDEN_FILTER, &mHiddenIndexAllKeys, &mFilterByHidden, &mHiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN" }
}; };
filterDataDecl = std::vector<FilterDataDecl>(filterDecls, filterDecls + filterDataDecl = std::vector<FilterDataDecl>(filterDecls, filterDecls +
@ -67,15 +67,15 @@ void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
}; };
IndexImportStructure indexStructDecls[] = { IndexImportStructure indexStructDecls[] = {
{ &favoritesIndexAllKeys, &(indexToImport->favoritesIndexAllKeys) }, { &mFavoritesIndexAllKeys, &(indexToImport->mFavoritesIndexAllKeys) },
{ &genreIndexAllKeys, &(indexToImport->genreIndexAllKeys) }, { &mGenreIndexAllKeys, &(indexToImport->mGenreIndexAllKeys) },
{ &playersIndexAllKeys, &(indexToImport->playersIndexAllKeys) }, { &mPlayersIndexAllKeys, &(indexToImport->mPlayersIndexAllKeys) },
{ &pubDevIndexAllKeys, &(indexToImport->pubDevIndexAllKeys) }, { &mPubDevIndexAllKeys, &(indexToImport->mPubDevIndexAllKeys) },
{ &ratingsIndexAllKeys, &(indexToImport->ratingsIndexAllKeys) }, { &mRatingsIndexAllKeys, &(indexToImport->mRatingsIndexAllKeys) },
{ &kidGameIndexAllKeys, &(indexToImport->kidGameIndexAllKeys) }, { &mKidGameIndexAllKeys, &(indexToImport->mKidGameIndexAllKeys) },
{ &completedIndexAllKeys, &(indexToImport->completedIndexAllKeys) }, { &mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys) },
{ &brokenIndexAllKeys, &(indexToImport->brokenIndexAllKeys) }, { &mBrokenIndexAllKeys, &(indexToImport->mBrokenIndexAllKeys) },
{ &hiddenIndexAllKeys, &(indexToImport->hiddenIndexAllKeys) }, { &mHiddenIndexAllKeys, &(indexToImport->mHiddenIndexAllKeys) },
}; };
std::vector<IndexImportStructure> indexImportDecl = std::vector<IndexImportStructure> indexImportDecl =
@ -101,15 +101,15 @@ void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
void FileFilterIndex::resetIndex() void FileFilterIndex::resetIndex()
{ {
clearAllFilters(); clearAllFilters();
clearIndex(favoritesIndexAllKeys); clearIndex(mFavoritesIndexAllKeys);
clearIndex(genreIndexAllKeys); clearIndex(mGenreIndexAllKeys);
clearIndex(playersIndexAllKeys); clearIndex(mPlayersIndexAllKeys);
clearIndex(pubDevIndexAllKeys); clearIndex(mPubDevIndexAllKeys);
clearIndex(ratingsIndexAllKeys); clearIndex(mRatingsIndexAllKeys);
clearIndex(kidGameIndexAllKeys); clearIndex(mKidGameIndexAllKeys);
clearIndex(completedIndexAllKeys); clearIndex(mCompletedIndexAllKeys);
clearIndex(brokenIndexAllKeys); clearIndex(mBrokenIndexAllKeys);
clearIndex(hiddenIndexAllKeys); clearIndex(mHiddenIndexAllKeys);
} }
std::string FileFilterIndex::getIndexableKey(FileData* game, std::string FileFilterIndex::getIndexableKey(FileData* game,
@ -301,12 +301,12 @@ void FileFilterIndex::setUIModeFilters()
{ {
if (Settings::getInstance()->getBool("GamelistFilters")){ if (Settings::getInstance()->getBool("GamelistFilters")){
if (UIModeController::getInstance()->isUIModeKiosk()) { if (UIModeController::getInstance()->isUIModeKiosk()) {
filterByHidden = true; mFilterByHidden = true;
std::vector<std::string> val = { "FALSE" }; std::vector<std::string> val = { "FALSE" };
setFilter(HIDDEN_FILTER, &val); setFilter(HIDDEN_FILTER, &val);
} }
if (UIModeController::getInstance()->isUIModeKid()) { if (UIModeController::getInstance()->isUIModeKid()) {
filterByKidGame = true; mFilterByKidGame = true;
std::vector<std::string> val = { "TRUE" }; std::vector<std::string> val = { "TRUE" };
setFilter(KIDGAME_FILTER, &val); setFilter(KIDGAME_FILTER, &val);
} }
@ -316,31 +316,31 @@ void FileFilterIndex::setUIModeFilters()
void FileFilterIndex::debugPrintIndexes() void FileFilterIndex::debugPrintIndexes()
{ {
LOG(LogInfo) << "Printing Indexes..."; LOG(LogInfo) << "Printing Indexes...";
for (auto x: favoritesIndexAllKeys) { for (auto x: mFavoritesIndexAllKeys) {
LOG(LogInfo) << "Favorites Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Favorites Index: " << x.first << ": " << x.second;
} }
for (auto x: genreIndexAllKeys) { for (auto x: mGenreIndexAllKeys) {
LOG(LogInfo) << "Genre Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Genre Index: " << x.first << ": " << x.second;
} }
for (auto x: playersIndexAllKeys) { for (auto x: mPlayersIndexAllKeys) {
LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second;
} }
for (auto x: pubDevIndexAllKeys) { for (auto x: mPubDevIndexAllKeys) {
LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second; LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second;
} }
for (auto x: ratingsIndexAllKeys) { for (auto x: mRatingsIndexAllKeys) {
LOG(LogInfo) << "Ratings Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Ratings Index: " << x.first << ": " << x.second;
} }
for (auto x : kidGameIndexAllKeys) { for (auto x : mKidGameIndexAllKeys) {
LOG(LogInfo) << "KidGames Index: " << x.first << ": " << x.second; LOG(LogInfo) << "KidGames Index: " << x.first << ": " << x.second;
} }
for (auto x : completedIndexAllKeys) { for (auto x : mCompletedIndexAllKeys) {
LOG(LogInfo) << "Completed Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Completed Index: " << x.first << ": " << x.second;
} }
for (auto x : brokenIndexAllKeys) { for (auto x : mBrokenIndexAllKeys) {
LOG(LogInfo) << "Broken Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Broken Index: " << x.first << ": " << x.second;
} }
for (auto x : hiddenIndexAllKeys) { for (auto x : mHiddenIndexAllKeys) {
LOG(LogInfo) << "Hidden Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Hidden Index: " << x.first << ": " << x.second;
} }
} }
@ -413,10 +413,10 @@ bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type
const FilterIndexType filterTypes[9] = { FAVORITES_FILTER, GENRE_FILTER, const FilterIndexType filterTypes[9] = { FAVORITES_FILTER, GENRE_FILTER,
PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER, PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER,
COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER }; COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER };
std::vector<std::string> filterKeysList[9] = { favoritesIndexFilteredKeys, std::vector<std::string> filterKeysList[9] = { mFavoritesIndexFilteredKeys,
genreIndexFilteredKeys, playersIndexFilteredKeys, pubDevIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys, mPubDevIndexFilteredKeys,
ratingsIndexFilteredKeys, kidGameIndexFilteredKeys, completedIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys, mCompletedIndexFilteredKeys,
brokenIndexFilteredKeys, hiddenIndexFilteredKeys }; mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys };
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
if (filterTypes[i] == type) { if (filterTypes[i] == type) {
@ -441,7 +441,7 @@ void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove)
// No valid favorites info found. // No valid favorites info found.
return; return;
manageIndexEntry(&favoritesIndexAllKeys, key, remove); manageIndexEntry(&mFavoritesIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
@ -456,11 +456,11 @@ void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
// No valid genre info found. // No valid genre info found.
return; return;
manageIndexEntry(&genreIndexAllKeys, key, remove); manageIndexEntry(&mGenreIndexAllKeys, key, remove);
key = getIndexableKey(game, GENRE_FILTER, true); key = getIndexableKey(game, GENRE_FILTER, true);
if (!includeUnknown && key == UNKNOWN_LABEL) if (!includeUnknown && key == UNKNOWN_LABEL)
manageIndexEntry(&genreIndexAllKeys, key, remove); manageIndexEntry(&mGenreIndexAllKeys, key, remove);
} }
void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove) void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove)
@ -474,7 +474,7 @@ void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove)
// No valid player info found. // No valid player info found.
return; return;
manageIndexEntry(&playersIndexAllKeys, key, remove); manageIndexEntry(&mPlayersIndexAllKeys, key, remove);
} }
void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove) void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove)
@ -499,16 +499,16 @@ void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove)
if (unknownDev && unknownPub) { if (unknownDev && unknownPub) {
// If no info at all. // If no info at all.
manageIndexEntry(&pubDevIndexAllKeys, pub, remove); manageIndexEntry(&mPubDevIndexAllKeys, pub, remove);
} }
else { else {
if (!unknownDev) { if (!unknownDev) {
// If no info at all. // If no info at all.
manageIndexEntry(&pubDevIndexAllKeys, dev, remove); manageIndexEntry(&mPubDevIndexAllKeys, dev, remove);
} }
if (!unknownPub) { if (!unknownPub) {
// If no info at all. // If no info at all.
manageIndexEntry(&pubDevIndexAllKeys, pub, remove); manageIndexEntry(&mPubDevIndexAllKeys, pub, remove);
} }
} }
} }
@ -524,7 +524,7 @@ void FileFilterIndex::manageRatingsEntryInIndex(FileData* game, bool remove)
// No valid rating info found. // No valid rating info found.
return; return;
manageIndexEntry(&ratingsIndexAllKeys, key, remove); manageIndexEntry(&mRatingsIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageKidGameEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageKidGameEntryInIndex(FileData* game, bool remove)
@ -537,7 +537,7 @@ void FileFilterIndex::manageKidGameEntryInIndex(FileData* game, bool remove)
// No valid kidgame info found. // No valid kidgame info found.
return; return;
manageIndexEntry(&kidGameIndexAllKeys, key, remove); manageIndexEntry(&mKidGameIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageCompletedEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageCompletedEntryInIndex(FileData* game, bool remove)
@ -550,7 +550,7 @@ void FileFilterIndex::manageCompletedEntryInIndex(FileData* game, bool remove)
// No valid completed info found. // No valid completed info found.
return; return;
manageIndexEntry(&completedIndexAllKeys, key, remove); manageIndexEntry(&mCompletedIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageBrokenEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageBrokenEntryInIndex(FileData* game, bool remove)
@ -563,7 +563,7 @@ void FileFilterIndex::manageBrokenEntryInIndex(FileData* game, bool remove)
// No valid broken info found. // No valid broken info found.
return; return;
manageIndexEntry(&brokenIndexAllKeys, key, remove); manageIndexEntry(&mBrokenIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageHiddenEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageHiddenEntryInIndex(FileData* game, bool remove)
@ -576,7 +576,7 @@ void FileFilterIndex::manageHiddenEntryInIndex(FileData* game, bool remove)
// No valid hidden info found. // No valid hidden info found.
return; return;
manageIndexEntry(&hiddenIndexAllKeys, key, remove); manageIndexEntry(&mHiddenIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageIndexEntry(std::map<std::string, int>* index, void FileFilterIndex::manageIndexEntry(std::map<std::string, int>* index,

View file

@ -55,9 +55,9 @@ public:
void clearAllFilters(); void clearAllFilters();
void debugPrintIndexes(); void debugPrintIndexes();
bool showFile(FileData* game); bool showFile(FileData* game);
bool isFiltered() { return (mFilterByText || filterByFavorites || filterByGenre || bool isFiltered() { return (mFilterByText || mFilterByFavorites || mFilterByGenre ||
filterByPlayers || filterByPubDev || filterByRatings || filterByKidGame || mFilterByPlayers || mFilterByPubDev || mFilterByRatings || mFilterByKidGame ||
filterByCompleted || filterByBroken || filterByHidden ); }; mFilterByCompleted || mFilterByBroken || mFilterByHidden ); };
bool isKeyBeingFilteredBy(std::string key, FilterIndexType type); bool isKeyBeingFilteredBy(std::string key, FilterIndexType type);
std::vector<FilterDataDecl>& getFilterDataDecls(); std::vector<FilterDataDecl>& getFilterDataDecls();
@ -87,35 +87,35 @@ private:
std::string mTextFilter; std::string mTextFilter;
bool mFilterByText; bool mFilterByText;
bool filterByFavorites; bool mFilterByFavorites;
bool filterByGenre; bool mFilterByGenre;
bool filterByPlayers; bool mFilterByPlayers;
bool filterByPubDev; bool mFilterByPubDev;
bool filterByRatings; bool mFilterByRatings;
bool filterByKidGame; bool mFilterByKidGame;
bool filterByCompleted; bool mFilterByCompleted;
bool filterByBroken; bool mFilterByBroken;
bool filterByHidden; bool mFilterByHidden;
std::map<std::string, int> favoritesIndexAllKeys; std::map<std::string, int> mFavoritesIndexAllKeys;
std::map<std::string, int> genreIndexAllKeys; std::map<std::string, int> mGenreIndexAllKeys;
std::map<std::string, int> playersIndexAllKeys; std::map<std::string, int> mPlayersIndexAllKeys;
std::map<std::string, int> pubDevIndexAllKeys; std::map<std::string, int> mPubDevIndexAllKeys;
std::map<std::string, int> ratingsIndexAllKeys; std::map<std::string, int> mRatingsIndexAllKeys;
std::map<std::string, int> kidGameIndexAllKeys; std::map<std::string, int> mKidGameIndexAllKeys;
std::map<std::string, int> completedIndexAllKeys; std::map<std::string, int> mCompletedIndexAllKeys;
std::map<std::string, int> brokenIndexAllKeys; std::map<std::string, int> mBrokenIndexAllKeys;
std::map<std::string, int> hiddenIndexAllKeys; std::map<std::string, int> mHiddenIndexAllKeys;
std::vector<std::string> favoritesIndexFilteredKeys; std::vector<std::string> mFavoritesIndexFilteredKeys;
std::vector<std::string> genreIndexFilteredKeys; std::vector<std::string> mGenreIndexFilteredKeys;
std::vector<std::string> playersIndexFilteredKeys; std::vector<std::string> mPlayersIndexFilteredKeys;
std::vector<std::string> pubDevIndexFilteredKeys; std::vector<std::string> mPubDevIndexFilteredKeys;
std::vector<std::string> ratingsIndexFilteredKeys; std::vector<std::string> mRatingsIndexFilteredKeys;
std::vector<std::string> kidGameIndexFilteredKeys; std::vector<std::string> mKidGameIndexFilteredKeys;
std::vector<std::string> completedIndexFilteredKeys; std::vector<std::string> mCompletedIndexFilteredKeys;
std::vector<std::string> brokenIndexFilteredKeys; std::vector<std::string> mBrokenIndexFilteredKeys;
std::vector<std::string> hiddenIndexFilteredKeys; std::vector<std::string> mHiddenIndexFilteredKeys;
FileData* mRootFolder; FileData* mRootFolder;