mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-13 18:28:52 +01:00
Corrected switching to favorites list by adding a separate function for that purpose.
Restricted playlist add/remove to games for now. Fixed not writing playlist if the playlists directory does not exist; directory is now created.
This commit is contained in:
parent
84d301dd5a
commit
9c47adc9cc
@ -23,6 +23,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
#ifdef __linux
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <cstring>
|
||||||
|
#endif
|
||||||
|
|
||||||
CollectionInfo::CollectionInfo(std::string name,
|
CollectionInfo::CollectionInfo(std::string name,
|
||||||
std::string listPath,
|
std::string listPath,
|
||||||
std::string extensions,
|
std::string extensions,
|
||||||
@ -76,12 +83,38 @@ bool CollectionInfo::Save()
|
|||||||
bool retval = true;
|
bool retval = true;
|
||||||
if(saveRequest)
|
if(saveRequest)
|
||||||
{
|
{
|
||||||
|
std::string dir = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists");
|
||||||
std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists/favorites.txt");
|
std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists/favorites.txt");
|
||||||
Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file);
|
Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file);
|
||||||
|
|
||||||
std::ofstream filestream;
|
std::ofstream filestream;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Create playlists directory if it does not exist yet.
|
||||||
|
struct stat info;
|
||||||
|
if ( stat( dir.c_str(), &info ) != 0 && (info.st_mode & S_IFDIR) )
|
||||||
|
{
|
||||||
|
#if defined(_WIN32) && !defined(__GNUC__)
|
||||||
|
if(!CreateDirectory(dir, NULL))
|
||||||
|
{
|
||||||
|
if(ERROR_ALREADY_EXISTS != GetLastError())
|
||||||
|
{
|
||||||
|
std::cout << "Could not create folder \"" << *it << "\"" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
if(mkdir(dir.c_str()) == -1)
|
||||||
|
#else
|
||||||
|
if(mkdir(dir.c_str(), 0755) == -1)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
std::cout << "Could not create folder \"" << dir << "\":" << errno << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
filestream.open(file.c_str());
|
filestream.open(file.c_str());
|
||||||
std::vector<Item *> *saveitems = playlists["favorites"];
|
std::vector<Item *> *saveitems = playlists["favorites"];
|
||||||
for(std::vector<Item *>::iterator it = saveitems->begin(); it != saveitems->end(); it++)
|
for(std::vector<Item *>::iterator it = saveitems->begin(); it != saveitems->end(); it++)
|
||||||
|
|||||||
@ -606,6 +606,34 @@ void Page::nextPlaylist()
|
|||||||
playlistChanged_ = true;
|
playlistChanged_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Page::favPlaylist()
|
||||||
|
{
|
||||||
|
MenuInfo_S &info = collections_.back();
|
||||||
|
info.collection->Save();
|
||||||
|
unsigned int numlists = info.collection->playlists.size();
|
||||||
|
|
||||||
|
// Store current playlist
|
||||||
|
CollectionInfo::Playlists_T::iterator playlist_store = playlist_;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i <= numlists; ++i)
|
||||||
|
{
|
||||||
|
playlist_++;
|
||||||
|
// wrap
|
||||||
|
if(playlist_ == info.collection->playlists.end()) playlist_ = info.collection->playlists.begin();
|
||||||
|
|
||||||
|
// find the first playlist
|
||||||
|
if(playlist_->second->size() != 0 && playlist_->first == "favorites") break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not change playlist if favorites does not exist
|
||||||
|
if ( playlist_->first != "favorites" )
|
||||||
|
playlist_ = playlist_store;
|
||||||
|
|
||||||
|
activeMenu_->setItems(playlist_->second);
|
||||||
|
activeMenu_->triggerMenuEnterEvent();
|
||||||
|
playlistChanged_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Page::update(float dt)
|
void Page::update(float dt)
|
||||||
{
|
{
|
||||||
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
|
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
|
||||||
@ -690,6 +718,7 @@ void Page::draw()
|
|||||||
void Page::removePlaylist()
|
void Page::removePlaylist()
|
||||||
{
|
{
|
||||||
if(!selectedItem_) return;
|
if(!selectedItem_) return;
|
||||||
|
if(!selectedItem_->leaf) return;
|
||||||
|
|
||||||
MenuInfo_S &info = collections_.back();
|
MenuInfo_S &info = collections_.back();
|
||||||
CollectionInfo *collection = info.collection;
|
CollectionInfo *collection = info.collection;
|
||||||
@ -713,6 +742,7 @@ void Page::removePlaylist()
|
|||||||
void Page::addPlaylist()
|
void Page::addPlaylist()
|
||||||
{
|
{
|
||||||
if(!selectedItem_) return;
|
if(!selectedItem_) return;
|
||||||
|
if(!selectedItem_->leaf) return;
|
||||||
|
|
||||||
MenuInfo_S &info = collections_.back();
|
MenuInfo_S &info = collections_.back();
|
||||||
CollectionInfo *collection = info.collection;
|
CollectionInfo *collection = info.collection;
|
||||||
|
|||||||
@ -48,6 +48,7 @@ public:
|
|||||||
bool pushCollection(CollectionInfo *collection);
|
bool pushCollection(CollectionInfo *collection);
|
||||||
bool popCollection();
|
bool popCollection();
|
||||||
void nextPlaylist();
|
void nextPlaylist();
|
||||||
|
void favPlaylist();
|
||||||
void pushMenu(ScrollingList *s);
|
void pushMenu(ScrollingList *s);
|
||||||
bool isMenusFull();
|
bool isMenusFull();
|
||||||
void setLoadSound(Sound *chunk);
|
void setLoadSound(Sound *chunk);
|
||||||
|
|||||||
@ -533,7 +533,7 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page)
|
|||||||
config_.getProperty("autoFavorites", autoFavorites);
|
config_.getProperty("autoFavorites", autoFavorites);
|
||||||
|
|
||||||
if (autoFavorites)
|
if (autoFavorites)
|
||||||
page->nextPlaylist(); // Switch to favorites if it exists
|
page->favPlaylist(); // Switch to favorites if it exists
|
||||||
|
|
||||||
state = RETROFE_NEXT_PAGE_REQUEST;
|
state = RETROFE_NEXT_PAGE_REQUEST;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user