Move collection retrieval in RetroFE class to helper method.

This commit is contained in:
emb 2015-01-01 16:38:44 -06:00
parent df3fe6f314
commit 7f0e4e4a38
2 changed files with 28 additions and 27 deletions

View File

@ -445,43 +445,43 @@ Page *RetroFE::LoadPage(std::string collectionName)
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Creating page for collection " + collectionName); Logger::Write(Logger::ZONE_INFO, "RetroFE", "Creating page for collection " + collectionName);
Page *page = NULL; Page *page = NULL;
std::vector<Item *> *collection = GetCollection(collectionName);
std::string layoutName = GetLayout(collectionName);
if(PageChain.size() > 0)
{
Page *oldPage = PageChain.back();
oldPage->FreeGraphicsMemory();
}
PageBuilder pb(layoutName, collectionName, Config, &FC);
page = pb.BuildPage();
page->SetItems(collection);
page->Start();
if(page)
{
PageChain.push_back(page);
}
return page;
}
std::vector<Item *> *RetroFE::GetCollection(std::string collectionName)
{
std::vector<Item *> *collection = new std::vector<Item *>(); // the page will deallocate this once its done std::vector<Item *> *collection = new std::vector<Item *>(); // the page will deallocate this once its done
MenuParser mp; MenuParser mp;
mp.GetMenuItems(&CollectionDB, collectionName, *collection); mp.GetMenuItems(&CollectionDB, collectionName, *collection);
CollectionDB.GetCollection(collectionName, *collection); CollectionDB.GetCollection(collectionName, *collection);
//todo: handle this in a more esthetically pleasing way instead of crashing
if(collection->size() == 0) if(collection->size() == 0)
{ {
Logger::Write(Logger::ZONE_WARNING, "RetroFE", "No list items found for collection " + collectionName); Logger::Write(Logger::ZONE_WARNING, "RetroFE", "No list items found for collection " + collectionName);
} }
else
{
std::string layoutName = GetLayout(collectionName);
if(PageChain.size() > 0) return collection;
{
Page *oldPage = PageChain.back();
if(oldPage)
{
oldPage->FreeGraphicsMemory();
}
}
PageBuilder pb(layoutName, collectionName, Config, &FC);
page = pb.BuildPage();
page->SetItems(collection);
page->Start();
if(page)
{
PageChain.push_back(page);
}
}
return page;
} }
std::string RetroFE::GetLayout(std::string collectionName) std::string RetroFE::GetLayout(std::string collectionName)

View File

@ -9,6 +9,7 @@
#include "Video/IVideo.h" #include "Video/IVideo.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <list> #include <list>
#include <vector>
class CollectionDatabase; class CollectionDatabase;
class Configuration; class Configuration;
@ -48,7 +49,7 @@ private:
RETROFE_STATE ProcessUserInput(); RETROFE_STATE ProcessUserInput();
void Update(float dt, bool scrollActive); void Update(float dt, bool scrollActive);
std::string GetLayout(std::string collectionName); std::string GetLayout(std::string collectionName);
std::vector<Item *> *GetCollection(std::string collectionName);
Configuration &Config; Configuration &Config;
CollectionDatabase &CollectionDB; CollectionDatabase &CollectionDB;
UserInput Input; UserInput Input;