Split up the Publisher/Developer filter into two separate filters.

This commit is contained in:
Leon Styhre 2021-09-25 19:30:44 +02:00
parent 3d6628f084
commit 5f3abed826
2 changed files with 71 additions and 70 deletions

View file

@ -26,7 +26,8 @@ FileFilterIndex::FileFilterIndex()
, mFilterByFavorites(false) , mFilterByFavorites(false)
, mFilterByGenre(false) , mFilterByGenre(false)
, mFilterByPlayers(false) , mFilterByPlayers(false)
, mFilterByPubDev(false) , mFilterByDeveloper(false)
, mFilterByPublisher(false)
, mFilterByRatings(false) , mFilterByRatings(false)
, mFilterByKidGame(false) , mFilterByKidGame(false)
, mFilterByCompleted(false) , mFilterByCompleted(false)
@ -42,7 +43,8 @@ FileFilterIndex::FileFilterIndex()
{FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES"}, {FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES"},
{GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE"}, {GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE"},
{PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS"}, {PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS"},
{PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER"}, {DEVELOPER_FILTER, &mDeveloperIndexAllKeys, &mFilterByDeveloper, &mDeveloperIndexFilteredKeys, "developer", false, "", "DEVELOPER"},
{PUBLISHER_FILTER, &mPublisherIndexAllKeys, &mFilterByPublisher, &mPublisherIndexFilteredKeys, "publisher", false, "", "PUBLISHER"},
{RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING"}, {RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING"},
{KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME"}, {KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME"},
{COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED"}, {COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED"},
@ -73,7 +75,8 @@ void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
{&mFavoritesIndexAllKeys, &(indexToImport->mFavoritesIndexAllKeys)}, {&mFavoritesIndexAllKeys, &(indexToImport->mFavoritesIndexAllKeys)},
{&mGenreIndexAllKeys, &(indexToImport->mGenreIndexAllKeys)}, {&mGenreIndexAllKeys, &(indexToImport->mGenreIndexAllKeys)},
{&mPlayersIndexAllKeys, &(indexToImport->mPlayersIndexAllKeys)}, {&mPlayersIndexAllKeys, &(indexToImport->mPlayersIndexAllKeys)},
{&mPubDevIndexAllKeys, &(indexToImport->mPubDevIndexAllKeys)}, {&mDeveloperIndexAllKeys, &(indexToImport->mDeveloperIndexAllKeys)},
{&mPublisherIndexAllKeys, &(indexToImport->mPublisherIndexAllKeys)},
{&mRatingsIndexAllKeys, &(indexToImport->mRatingsIndexAllKeys)}, {&mRatingsIndexAllKeys, &(indexToImport->mRatingsIndexAllKeys)},
{&mKidGameIndexAllKeys, &(indexToImport->mKidGameIndexAllKeys)}, {&mKidGameIndexAllKeys, &(indexToImport->mKidGameIndexAllKeys)},
{&mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys)}, {&mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys)},
@ -109,7 +112,8 @@ void FileFilterIndex::resetIndex()
clearIndex(mFavoritesIndexAllKeys); clearIndex(mFavoritesIndexAllKeys);
clearIndex(mGenreIndexAllKeys); clearIndex(mGenreIndexAllKeys);
clearIndex(mPlayersIndexAllKeys); clearIndex(mPlayersIndexAllKeys);
clearIndex(mPubDevIndexAllKeys); clearIndex(mDeveloperIndexAllKeys);
clearIndex(mPublisherIndexAllKeys);
clearIndex(mRatingsIndexAllKeys); clearIndex(mRatingsIndexAllKeys);
clearIndex(mKidGameIndexAllKeys); clearIndex(mKidGameIndexAllKeys);
clearIndex(mCompletedIndexAllKeys); clearIndex(mCompletedIndexAllKeys);
@ -132,7 +136,6 @@ std::string FileFilterIndex::getIndexableKey(FileData* game,
} }
case GENRE_FILTER: { case GENRE_FILTER: {
key = Utils::String::toUpper(game->metadata.get("genre")); key = Utils::String::toUpper(game->metadata.get("genre"));
key = Utils::String::trim(key);
if (getSecondary && !key.empty()) { if (getSecondary && !key.empty()) {
std::istringstream f(key); std::istringstream f(key);
std::string newKey; std::string newKey;
@ -150,13 +153,12 @@ std::string FileFilterIndex::getIndexableKey(FileData* game,
key = Utils::String::toUpper(game->metadata.get("players")); key = Utils::String::toUpper(game->metadata.get("players"));
break; break;
} }
case PUBDEV_FILTER: { case DEVELOPER_FILTER: {
key = Utils::String::toUpper(game->metadata.get("developer"));
break;
}
case PUBLISHER_FILTER: {
key = Utils::String::toUpper(game->metadata.get("publisher")); key = Utils::String::toUpper(game->metadata.get("publisher"));
key = Utils::String::trim(key);
if ((getSecondary && !key.empty()) || (!getSecondary && key.empty()))
key = Utils::String::toUpper(game->metadata.get("developer"));
else
key = Utils::String::toUpper(game->metadata.get("publisher"));
break; break;
} }
case RATINGS_FILTER: { case RATINGS_FILTER: {
@ -225,7 +227,8 @@ std::string FileFilterIndex::getIndexableKey(FileData* game,
key = Utils::String::trim(key); key = Utils::String::trim(key);
// Add a dummy value in case there is no metadata defined so we can filter based on this. // Add a dummy value in case there is no metadata defined so we can filter based on this.
if ((type == GENRE_FILTER || type == PLAYER_FILTER || type == PUBDEV_FILTER) && if ((type == GENRE_FILTER || type == PLAYER_FILTER || type == DEVELOPER_FILTER ||
type == PUBLISHER_FILTER) &&
Utils::String::toUpper(key) == UNKNOWN_LABEL) Utils::String::toUpper(key) == UNKNOWN_LABEL)
key = ViewController::CROSSEDCIRCLE_CHAR + " UNKNOWN"; key = ViewController::CROSSEDCIRCLE_CHAR + " UNKNOWN";
else if (type == ALTEMULATOR_FILTER && key.empty()) else if (type == ALTEMULATOR_FILTER && key.empty())
@ -241,7 +244,8 @@ void FileFilterIndex::addToIndex(FileData* game)
manageFavoritesEntryInIndex(game); manageFavoritesEntryInIndex(game);
manageGenreEntryInIndex(game); manageGenreEntryInIndex(game);
managePlayerEntryInIndex(game); managePlayerEntryInIndex(game);
managePubDevEntryInIndex(game); manageDeveloperEntryInIndex(game);
managePublisherEntryInIndex(game);
manageRatingsEntryInIndex(game); manageRatingsEntryInIndex(game);
manageKidGameEntryInIndex(game); manageKidGameEntryInIndex(game);
manageCompletedEntryInIndex(game); manageCompletedEntryInIndex(game);
@ -255,7 +259,8 @@ void FileFilterIndex::removeFromIndex(FileData* game)
manageFavoritesEntryInIndex(game, true); manageFavoritesEntryInIndex(game, true);
manageGenreEntryInIndex(game, true); manageGenreEntryInIndex(game, true);
managePlayerEntryInIndex(game, true); managePlayerEntryInIndex(game, true);
managePubDevEntryInIndex(game, true); manageDeveloperEntryInIndex(game, true);
managePublisherEntryInIndex(game, true);
manageRatingsEntryInIndex(game, true); manageRatingsEntryInIndex(game, true);
manageKidGameEntryInIndex(game, true); manageKidGameEntryInIndex(game, true);
manageCompletedEntryInIndex(game, true); manageCompletedEntryInIndex(game, true);
@ -339,7 +344,10 @@ void FileFilterIndex::debugPrintIndexes()
for (auto x : mPlayersIndexAllKeys) { for (auto x : mPlayersIndexAllKeys) {
LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second; LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second;
} }
for (auto x : mPubDevIndexAllKeys) { for (auto x : mDeveloperIndexAllKeys) {
LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second;
}
for (auto x : mPublisherIndexAllKeys) {
LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second; LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second;
} }
for (auto x : mRatingsIndexAllKeys) { for (auto x : mRatingsIndexAllKeys) {
@ -435,28 +443,29 @@ bool FileFilterIndex::isFiltered()
{ {
if (UIModeController::getInstance()->isUIModeKid()) { if (UIModeController::getInstance()->isUIModeKid()) {
return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers || return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers ||
mFilterByPubDev || mFilterByRatings || mFilterByCompleted || mFilterByBroken || mFilterByDeveloper || mFilterByPublisher || mFilterByRatings ||
mFilterByHidden || mFilterByAltemulator); mFilterByCompleted || mFilterByBroken || mFilterByHidden || mFilterByAltemulator);
} }
else { else {
return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers || return (mFilterByText || mFilterByFavorites || mFilterByGenre || mFilterByPlayers ||
mFilterByPubDev || mFilterByRatings || mFilterByKidGame || mFilterByCompleted || mFilterByDeveloper || mFilterByPublisher || mFilterByRatings || mFilterByKidGame ||
mFilterByBroken || mFilterByHidden | mFilterByAltemulator); mFilterByCompleted || mFilterByBroken || mFilterByHidden | mFilterByAltemulator);
} }
} }
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type) bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
{ {
const FilterIndexType filterTypes[10] = { const FilterIndexType filterTypes[11] = {FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER,
FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER, DEVELOPER_FILTER, PUBLISHER_FILTER, RATINGS_FILTER,
KIDGAME_FILTER, COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER, ALTEMULATOR_FILTER}; KIDGAME_FILTER, COMPLETED_FILTER, BROKEN_FILTER,
std::vector<std::string> filterKeysList[10] = { HIDDEN_FILTER, ALTEMULATOR_FILTER};
mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys, std::vector<std::string> filterKeysList[11] = {
mPubDevIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys, mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys,
mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys, mDeveloperIndexFilteredKeys, mPublisherIndexFilteredKeys, mRatingsIndexFilteredKeys,
mAltemulatorIndexFilteredKeys}; mKidGameIndexFilteredKeys, mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys,
mHiddenIndexFilteredKeys, mAltemulatorIndexFilteredKeys};
for (int i = 0; i < 10; i++) { for (int i = 0; i < 11; i++) {
if (filterTypes[i] == type) { if (filterTypes[i] == type) {
for (std::vector<std::string>::const_iterator it = filterKeysList[i].cbegin(); for (std::vector<std::string>::const_iterator it = filterKeysList[i].cbegin();
it != filterKeysList[i].cend(); it++) { it != filterKeysList[i].cend(); it++) {
@ -471,12 +480,10 @@ bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type
void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove)
{ {
// Flag for including unknowns.
bool includeUnknown = INCLUDE_UNKNOWN; bool includeUnknown = INCLUDE_UNKNOWN;
std::string key = getIndexableKey(game, FAVORITES_FILTER, false); std::string key = getIndexableKey(game, FAVORITES_FILTER, false);
if (!includeUnknown && key == UNKNOWN_LABEL) if (!includeUnknown && key == UNKNOWN_LABEL)
// No valid favorites info found.
return; return;
manageIndexEntry(&mFavoritesIndexAllKeys, key, remove); manageIndexEntry(&mFavoritesIndexAllKeys, key, remove);
@ -484,13 +491,10 @@ void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove)
void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
{ {
bool includeUnknown = INCLUDE_UNKNOWN;
std::string key = getIndexableKey(game, GENRE_FILTER, false); std::string key = getIndexableKey(game, GENRE_FILTER, false);
// Flag for including unknowns.
bool includeUnknown = INCLUDE_UNKNOWN;
if (!includeUnknown && (key == UNKNOWN_LABEL || key == "BIOS")) if (!includeUnknown && (key == UNKNOWN_LABEL || key == "BIOS"))
// No valid genre info found.
return; return;
manageIndexEntry(&mGenreIndexAllKeys, key, remove); manageIndexEntry(&mGenreIndexAllKeys, key, remove);
@ -502,51 +506,43 @@ void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove) void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove)
{ {
// Flag for including unknowns.
bool includeUnknown = INCLUDE_UNKNOWN; bool includeUnknown = INCLUDE_UNKNOWN;
std::string key = getIndexableKey(game, PLAYER_FILTER, false); std::string key = getIndexableKey(game, PLAYER_FILTER, false);
if (!includeUnknown && key == UNKNOWN_LABEL) if (!includeUnknown && key == UNKNOWN_LABEL)
// No valid player info found.
return; return;
manageIndexEntry(&mPlayersIndexAllKeys, key, remove); manageIndexEntry(&mPlayersIndexAllKeys, key, remove);
} }
void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageDeveloperEntryInIndex(FileData* game, bool remove)
{ {
std::string pub = getIndexableKey(game, PUBDEV_FILTER, false);
std::string dev = getIndexableKey(game, PUBDEV_FILTER, true);
// Flag for including unknowns.
bool includeUnknown = INCLUDE_UNKNOWN; bool includeUnknown = INCLUDE_UNKNOWN;
bool unknownPub = false; std::string key = getIndexableKey(game, DEVELOPER_FILTER, false);
bool unknownDev = false;
if (pub == UNKNOWN_LABEL) if (!includeUnknown && key == UNKNOWN_LABEL)
unknownPub = true;
if (dev == UNKNOWN_LABEL)
unknownDev = true;
if (!includeUnknown && unknownDev && unknownPub)
// No valid rating info found.
return; return;
if (unknownDev && unknownPub) { manageIndexEntry(&mDeveloperIndexAllKeys, key, remove);
// If no info at all.
manageIndexEntry(&mPubDevIndexAllKeys, pub, remove); key = getIndexableKey(game, DEVELOPER_FILTER, true);
} if (!includeUnknown && key == UNKNOWN_LABEL)
else { manageIndexEntry(&mDeveloperIndexAllKeys, key, remove);
if (!unknownDev) { }
// If no info at all.
manageIndexEntry(&mPubDevIndexAllKeys, dev, remove); void FileFilterIndex::managePublisherEntryInIndex(FileData* game, bool remove)
} {
if (!unknownPub) { bool includeUnknown = INCLUDE_UNKNOWN;
// If no info at all. std::string key = getIndexableKey(game, PUBLISHER_FILTER, false);
manageIndexEntry(&mPubDevIndexAllKeys, pub, remove);
} if (!includeUnknown && key == UNKNOWN_LABEL)
} return;
manageIndexEntry(&mPublisherIndexAllKeys, key, remove);
key = getIndexableKey(game, PUBLISHER_FILTER, true);
if (!includeUnknown && key == UNKNOWN_LABEL)
manageIndexEntry(&mPublisherIndexAllKeys, key, remove);
} }
void FileFilterIndex::manageRatingsEntryInIndex(FileData* game, bool remove) void FileFilterIndex::manageRatingsEntryInIndex(FileData* game, bool remove)

View file

@ -24,7 +24,8 @@ enum FilterIndexType {
FAVORITES_FILTER, FAVORITES_FILTER,
GENRE_FILTER, GENRE_FILTER,
PLAYER_FILTER, PLAYER_FILTER,
PUBDEV_FILTER, DEVELOPER_FILTER,
PUBLISHER_FILTER,
RATINGS_FILTER, RATINGS_FILTER,
KIDGAME_FILTER, KIDGAME_FILTER,
COMPLETED_FILTER, COMPLETED_FILTER,
@ -74,7 +75,8 @@ private:
void manageFavoritesEntryInIndex(FileData* game, bool remove = false); void manageFavoritesEntryInIndex(FileData* game, bool remove = false);
void manageGenreEntryInIndex(FileData* game, bool remove = false); void manageGenreEntryInIndex(FileData* game, bool remove = false);
void managePlayerEntryInIndex(FileData* game, bool remove = false); void managePlayerEntryInIndex(FileData* game, bool remove = false);
void managePubDevEntryInIndex(FileData* game, bool remove = false); void manageDeveloperEntryInIndex(FileData* game, bool remove = false);
void managePublisherEntryInIndex(FileData* game, bool remove = false);
void manageRatingsEntryInIndex(FileData* game, bool remove = false); void manageRatingsEntryInIndex(FileData* game, bool remove = false);
void manageKidGameEntryInIndex(FileData* game, bool remove = false); void manageKidGameEntryInIndex(FileData* game, bool remove = false);
void manageCompletedEntryInIndex(FileData* game, bool remove = false); void manageCompletedEntryInIndex(FileData* game, bool remove = false);
@ -93,7 +95,8 @@ private:
bool mFilterByFavorites; bool mFilterByFavorites;
bool mFilterByGenre; bool mFilterByGenre;
bool mFilterByPlayers; bool mFilterByPlayers;
bool mFilterByPubDev; bool mFilterByDeveloper;
bool mFilterByPublisher;
bool mFilterByRatings; bool mFilterByRatings;
bool mFilterByKidGame; bool mFilterByKidGame;
bool mFilterByCompleted; bool mFilterByCompleted;
@ -104,7 +107,8 @@ private:
std::map<std::string, int> mFavoritesIndexAllKeys; std::map<std::string, int> mFavoritesIndexAllKeys;
std::map<std::string, int> mGenreIndexAllKeys; std::map<std::string, int> mGenreIndexAllKeys;
std::map<std::string, int> mPlayersIndexAllKeys; std::map<std::string, int> mPlayersIndexAllKeys;
std::map<std::string, int> mPubDevIndexAllKeys; std::map<std::string, int> mDeveloperIndexAllKeys;
std::map<std::string, int> mPublisherIndexAllKeys;
std::map<std::string, int> mRatingsIndexAllKeys; std::map<std::string, int> mRatingsIndexAllKeys;
std::map<std::string, int> mKidGameIndexAllKeys; std::map<std::string, int> mKidGameIndexAllKeys;
std::map<std::string, int> mCompletedIndexAllKeys; std::map<std::string, int> mCompletedIndexAllKeys;
@ -115,7 +119,8 @@ private:
std::vector<std::string> mFavoritesIndexFilteredKeys; std::vector<std::string> mFavoritesIndexFilteredKeys;
std::vector<std::string> mGenreIndexFilteredKeys; std::vector<std::string> mGenreIndexFilteredKeys;
std::vector<std::string> mPlayersIndexFilteredKeys; std::vector<std::string> mPlayersIndexFilteredKeys;
std::vector<std::string> mPubDevIndexFilteredKeys; std::vector<std::string> mDeveloperIndexFilteredKeys;
std::vector<std::string> mPublisherIndexFilteredKeys;
std::vector<std::string> mRatingsIndexFilteredKeys; std::vector<std::string> mRatingsIndexFilteredKeys;
std::vector<std::string> mKidGameIndexFilteredKeys; std::vector<std::string> mKidGameIndexFilteredKeys;
std::vector<std::string> mCompletedIndexFilteredKeys; std::vector<std::string> mCompletedIndexFilteredKeys;