playlist support - crashes

This commit is contained in:
Don Honerbrink
2015-07-28 16:37:45 -05:00
parent 2cc15babf9
commit 8bd246818c
10 changed files with 52 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ pageUp = A
pageDown = B pageDown = B
letterUp = N letterUp = N
letterDown = M letterDown = M
nextPlaylist = P
select = Space select = Space
back = Escape back = Escape
quit = Q quit = Q

View File

@@ -37,11 +37,17 @@ CollectionInfo::~CollectionInfo()
{ {
// remove items from the subcollections so their destructors do not // remove items from the subcollections so their destructors do not
// delete the items since the parent collection will delete them. // delete the items since the parent collection will delete them.
std::vector<CollectionInfo *>::iterator subit; std::vector<CollectionInfo *>::iterator subit = subcollections_.begin();
for (subit != subcollections_.begin(); subit != subcollections_.end(); subit++) while (subit != subcollections_.end())
{ {
CollectionInfo *info = *subit; CollectionInfo *info = *subit;
info->items.clear(); subcollections_.erase(subit);
if(info != this)
{
delete info;
}
subit = subcollections_.begin();
} }

View File

@@ -17,6 +17,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
class Item; class Item;
@@ -36,6 +37,9 @@ public:
std::string launcher; std::string launcher;
std::vector<Item *> items; std::vector<Item *> items;
typedef std::map<std::string, std::vector <Item *> > Playlists_T;
Playlists_T playlists;
private: private:
std::vector<CollectionInfo *> subcollections_; std::vector<CollectionInfo *> subcollections_;
std::string metadataPath_; std::string metadataPath_;

View File

@@ -242,8 +242,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
struct dirent *dirp; struct dirent *dirp;
std::string path = info->listpath; std::string path = info->listpath;
std::map<std::string, Item *> includeFilter; std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> favoritesFilter;
std::map<std::string, Item *> excludeFilter; std::map<std::string, Item *> excludeFilter;
std::string includeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "include.txt"); std::string includeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "include.txt");
std::string favoritesFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "favorites.txt");
std::string excludeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "exclude.txt"); std::string excludeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "exclude.txt");
std::string launcher; std::string launcher;
@@ -269,6 +271,7 @@ 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);
} }
@@ -297,6 +300,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
} }
} }
} }
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((dirp = readdir(dp)) != NULL)
{ {
@@ -327,6 +334,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
i->collectionInfo = info; i->collectionInfo = info;
info->items.push_back(i); info->items.push_back(i);
info->playlists["include"].push_back(i);
} }
} }
} }

View File

@@ -67,6 +67,7 @@ bool UserInput::initialize()
retVal = MapKey("select", KeyCodeSelect) && retVal; retVal = MapKey("select", KeyCodeSelect) && retVal;
retVal = MapKey("back", KeyCodeBack) && retVal; retVal = MapKey("back", KeyCodeBack) && retVal;
retVal = MapKey("quit", KeyCodeQuit) && retVal; retVal = MapKey("quit", KeyCodeQuit) && retVal;
MapKey("nextPlaylist", KeyCodeNextPlaylist);
// these features will need to be implemented at a later time // these features will need to be implemented at a later time
// retVal = MapKey("admin", KeyCodeAdminMode) && retVal; // retVal = MapKey("admin", KeyCodeAdminMode) && retVal;
// retVal = MapKey("remove", KeyCodeHideItem) && retVal; // retVal = MapKey("remove", KeyCodeHideItem) && retVal;

View File

@@ -38,6 +38,7 @@ public:
KeyCodePageUp, KeyCodePageUp,
KeyCodeLetterDown, KeyCodeLetterDown,
KeyCodeLetterUp, KeyCodeLetterUp,
KeyCodeNextPlaylist,
KeyCodeAdminMode, KeyCodeAdminMode,
KeyCodeHideItem, KeyCodeHideItem,
KeyCodeQuit, KeyCodeQuit,

View File

@@ -125,6 +125,7 @@ ScrollingList::~ScrollingList()
destroyItems(); destroyItems();
} }
void ScrollingList::setItems(std::vector<ComponentItemBinding *> *spriteList) void ScrollingList::setItems(std::vector<ComponentItemBinding *> *spriteList)
{ {
notifyAllRequested_ = true; notifyAllRequested_ = true;
@@ -227,6 +228,7 @@ void ScrollingList::destroyItems()
{ {
return; return;
} }
std::vector<ComponentItemBinding *>::iterator it = spriteList_->begin(); std::vector<ComponentItemBinding *>::iterator it = spriteList_->begin();
while(it != spriteList_->end()) while(it != spriteList_->end())
@@ -235,11 +237,7 @@ void ScrollingList::destroyItems()
{ {
deallocateTexture(*it); deallocateTexture(*it);
if((*it)->item) // items are destroyed when collections are destroyed
{
delete (*it)->item;
}
delete *it; delete *it;
} }

View File

@@ -438,6 +438,7 @@ bool Page::pushCollection(CollectionInfo *collection)
activeMenu_->destroyItems(); activeMenu_->destroyItems();
activeMenu_->setItems(sprites); activeMenu_->setItems(sprites);
activeMenu_->triggerMenuEnterEvent(); activeMenu_->triggerMenuEnterEvent();
playlist_ = collection->playlists.begin();
if(menuDepth_ < menus_.size()) if(menuDepth_ < menus_.size())
{ {
@@ -514,9 +515,26 @@ bool Page::popCollection()
} }
} }
if(collection)
{
delete collection;
}
return true; return true;
} }
void Page::nextPlaylist()
{
CollectionInfo *collection = collections_.back();
playlist_++;
if(playlist_ == collection->playlists.end()) playlist_ = collection->playlists.begin();
std::vector<ComponentItemBinding *> *sprites = ComponentItemBindingBuilder::buildCollectionItems(&playlist_->second);
activeMenu_->destroyItems();
activeMenu_->setItems(sprites);
activeMenu_->triggerMenuEnterEvent();
}
void Page::update(float dt) void Page::update(float dt)
{ {

View File

@@ -16,13 +16,13 @@
#pragma once #pragma once
#include "MenuNotifierInterface.h" #include "MenuNotifierInterface.h"
#include "../Collection/CollectionInfo.h"
#include <map> #include <map>
#include <string> #include <string>
#include <list> #include <list>
#include <vector> #include <vector>
class CollectionInfo;
class Component; class Component;
class Configuration; class Configuration;
class ScrollingList; class ScrollingList;
@@ -46,6 +46,7 @@ public:
virtual void onNewItemSelected(Item *); virtual void onNewItemSelected(Item *);
bool pushCollection(CollectionInfo *collection); bool pushCollection(CollectionInfo *collection);
bool popCollection(); bool popCollection();
void nextPlaylist();
void pushMenu(ScrollingList *s); void pushMenu(ScrollingList *s);
bool isMenusFull(); bool isMenusFull();
void setLoadSound(Sound *chunk); void setLoadSound(Sound *chunk);
@@ -105,6 +106,7 @@ private:
Sound *selectSoundChunk_; Sound *selectSoundChunk_;
float minShowTime_; float minShowTime_;
float elapsedTime_; float elapsedTime_;
CollectionInfo::Playlists_T::iterator playlist_;
}; };

View File

@@ -489,7 +489,10 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page)
} }
} }
} }
if(input_.keystate(UserInput::KeyCodeNextPlaylist) && page->isMenuIdle())
{
page->nextPlaylist();
}
if (input_.keystate(UserInput::KeyCodeBack) && page->isMenuIdle()) if (input_.keystate(UserInput::KeyCodeBack) && page->isMenuIdle())
{ {
if(back(exit) || exit) if(back(exit) || exit)