Support for checking for new keypresses. Fix playlist updating bug.

This commit is contained in:
emb 2015-10-27 22:42:15 -05:00
parent 6ff4acbd30
commit 2d188fd2b2
4 changed files with 44 additions and 18 deletions

View File

@ -231,6 +231,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
DIR *dp; DIR *dp;
struct dirent *dirp; struct dirent *dirp;
std::string path = info->listpath; std::string path = info->listpath;
std::map<std::string, Item *> allMap;
std::map<std::string, Item *> includeFilter; std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> favoritesFilter; std::map<std::string, Item *> favoritesFilter;
std::map<std::string, Item *> excludeFilter; std::map<std::string, Item *> excludeFilter;
@ -261,7 +262,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
{ {
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + includeFile + "\""); Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + includeFile + "\"");
ImportBasicList(info, includeFile, includeFilter); ImportBasicList(info, includeFile, includeFilter);
ImportBasicList(info, favoritesFile, favoritesFilter);
ImportBasicList(info, excludeFile, excludeFilter); ImportBasicList(info, excludeFile, excludeFilter);
} }
@ -269,9 +269,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
std::vector<std::string>::iterator extensionsIt; std::vector<std::string>::iterator extensionsIt;
info->extensionList(extensions); info->extensionList(extensions);
info->playlists["all"] = &info->items;
info->playlists["favorites"] = new std::vector<Item *>();
dp = opendir(path.c_str()); dp = opendir(path.c_str());
@ -279,7 +276,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
if(dp == NULL) if(dp == NULL)
{ {
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu."); Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu.");
return false;
} }
if(showMissing) if(showMissing)
@ -292,13 +288,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
} }
} }
} }
// add the favorites list
for(std::map<std::string, Item *>::iterator it = favoritesFilter.begin(); it != favoritesFilter.end(); it++)
{
info->playlists["favorites"]->push_back(it->second);
}
while((dirp = readdir(dp)) != NULL) while(dp != NULL && (dirp = readdir(dp)) != NULL)
{ {
std::string file = dirp->d_name; std::string file = dirp->d_name;
@ -333,7 +324,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
} }
} }
closedir(dp); if(dp != NULL)
{
closedir(dp);
}
while(includeFilter.size() > 0) while(includeFilter.size() > 0)
{ {
@ -352,6 +346,27 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
excludeFilter.erase(it); excludeFilter.erase(it);
} }
for(std::vector<Item *>::iterator it = info->items.begin(); it != info->items.end(); it++) {
allMap[(*it)->fullTitle] = *it;
}
ImportBasicList(info, favoritesFile, favoritesFilter);
info->playlists["all"] = &info->items;
info->playlists["favorites"] = new std::vector<Item *>();
// add the favorites list
for(std::map<std::string, Item *>::iterator it = favoritesFilter.begin(); it != favoritesFilter.end(); it++)
{
std::map<std::string, Item *>::iterator itemit = allMap.find(it->first);
if(itemit != allMap.end())
{
info->playlists["favorites"]->push_back(itemit->second);
}
}
metaDB_.injectMetadata(info); metaDB_.injectMetadata(info);
return true; return true;

View File

@ -30,6 +30,7 @@ UserInput::UserInput(Configuration &c)
for(unsigned int i = 0; i < KeyCodeMax; ++i) for(unsigned int i = 0; i < KeyCodeMax; ++i)
{ {
keyHandlers_[i] = NULL; keyHandlers_[i] = NULL;
currentKeyState_[i] = false;
lastKeyState_[i] = false; lastKeyState_[i] = false;
} }
} }
@ -234,6 +235,9 @@ void UserInput::resetStates()
bool UserInput::update(SDL_Event &e) bool UserInput::update(SDL_Event &e)
{ {
bool updated = false; bool updated = false;
memcpy(lastKeyState_, currentKeyState_, sizeof(lastKeyState_));
for(unsigned int i = 0; i < KeyCodeMax; ++i) for(unsigned int i = 0; i < KeyCodeMax; ++i)
{ {
InputHandler *h = keyHandlers_[i]; InputHandler *h = keyHandlers_[i];
@ -241,7 +245,7 @@ bool UserInput::update(SDL_Event &e)
{ {
if(h->update(e)) updated = true; if(h->update(e)) updated = true;
lastKeyState_[i] = h->pressed(); currentKeyState_[i] = h->pressed();
} }
} }
@ -250,5 +254,11 @@ bool UserInput::update(SDL_Event &e)
bool UserInput::keystate(KeyCode_E code) bool UserInput::keystate(KeyCode_E code)
{ {
return lastKeyState_[code]; return currentKeyState_[code];
} }
bool UserInput::newKeyPressed(KeyCode_E code)
{
return currentKeyState_[code] && !lastKeyState_[code];
}

View File

@ -55,6 +55,7 @@ public:
void resetStates(); void resetStates();
bool update(SDL_Event &e); bool update(SDL_Event &e);
bool keystate(KeyCode_E); bool keystate(KeyCode_E);
bool newKeyPressed(KeyCode_E code);
private: private:
bool MapKey(std::string keyDescription, KeyCode_E key); bool MapKey(std::string keyDescription, KeyCode_E key);
@ -63,5 +64,5 @@ private:
std::vector<SDL_Joystick *> joysticks_; std::vector<SDL_Joystick *> joysticks_;
InputHandler *keyHandlers_[KeyCodeMax]; InputHandler *keyHandlers_[KeyCodeMax];
bool lastKeyState_[KeyCodeMax]; bool lastKeyState_[KeyCodeMax];
bool currentKeyState_[KeyCodeMax];
}; };

View File

@ -480,15 +480,15 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page)
{ {
page->letterScroll(Page::ScrollDirectionForward); page->letterScroll(Page::ScrollDirectionForward);
} }
if(input_.keystate(UserInput::KeyCodeNextPlaylist)) if(input_.newKeyPressed(UserInput::KeyCodeNextPlaylist))
{ {
page->nextPlaylist(); page->nextPlaylist();
} }
if(input_.keystate(UserInput::KeyCodeRemovePlaylist)) if(input_.newKeyPressed(UserInput::KeyCodeRemovePlaylist))
{ {
page->removePlaylist(); page->removePlaylist();
} }
if(input_.keystate(UserInput::KeyCodeAddPlaylist)) if(input_.newKeyPressed(UserInput::KeyCodeAddPlaylist))
{ {
page->addPlaylist(); page->addPlaylist();
} }