diff options
author | Thomas Maass <mase@mase1.setho.org> | 2011-06-16 17:55:50 +0200 |
---|---|---|
committer | Thomas Maass <mase@mase1.setho.org> | 2011-06-16 17:55:50 +0200 |
commit | dfbd81c8c111d8df351dcf221c6a1d08bcaa13a2 (patch) | |
tree | 5dcaff5a80994aaab1d3e31a7a3322f48cb86122 /mainmenu.cpp | |
download | vdr-plugin-mame-master.tar.gz vdr-plugin-mame-master.tar.bz2 |
Diffstat (limited to 'mainmenu.cpp')
-rwxr-xr-x | mainmenu.cpp | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/mainmenu.cpp b/mainmenu.cpp new file mode 100755 index 0000000..fd8eb8f --- /dev/null +++ b/mainmenu.cpp @@ -0,0 +1,191 @@ +#include "mainmenu.h" + + + +using namespace std; + + + +cFolderList::cFolderList() : cOsdMenu("MAME") +{ + createFolders(); +} + + + +cFolderList::~cFolderList() +{} + + + +void cFolderList::createFolders() +{ + //Create first folder "#", and "A - Z" with ASCII-Code + cOsdItem* Folder = new cOsdItem("#"); + Add(Folder); + + for (int i = 65; i < 91; i++) + { + char FolderName[1]; + sprintf(FolderName, "%c", i); + cOsdItem* Folder = new cOsdItem(FolderName); + Add(Folder); + } + SetHelp(tr("Open")); +} + + + +eOSState cFolderList::ProcessKey(eKeys Key) +{ + cOsdItem* Item = (cOsdItem*)Get(Current()); + eOSState state = cOsdMenu::ProcessKey(Key); + if (!HasSubMenu()) + { + switch (Key) + { + case kOk: + AddSubMenu(new cGameList(Item->Text())); + break; + case kRed: + AddSubMenu(new cGameList(Item->Text())); + break; + default: + break; + } + } + return state; +} + + + + + + +cGameList::cGameList(const char* Base) : cOsdMenu(Base), FolderName(Base) +{ + Actions = new cActions; + createGameList(); + FillFolders(); +} + + + +cGameList::~cGameList() +{ + delete Actions; +} + + + +bool cGameList::createGameList() +{ + string TempLine; + string GameName; + string RomName; + int GameName_Begin; + int GameName_End; + int RomName_Begin; + int RomName_End; + + //Let mame write it's gamelist to /tmp/vdr-mamelist and try to open it + system("export DISPLAY=:0.0 && sdlmame -listfull > /tmp/vdr-mamelist"); + fstream File; + File.open("/tmp/vdr-mamelist", ios_base::in); + m_GameMap.clear(); + + if (!File) + { + return false; + } + + while (!File.eof()) + { + getline(File, TempLine); + + //skip empty lines + if (TempLine.empty()) + { + continue; + } + + //Find entry positions in the line + RomName_Begin = 0; + RomName_End = TempLine.find_first_of(" ", RomName_Begin); + GameName_Begin = TempLine.find_first_not_of(" ", RomName_End + 1) + 1; + GameName_End = TempLine.size() - 1; + + //Get the game and romname from the line + RomName = TempLine.substr(RomName_Begin, RomName_End); + GameName = TempLine.substr(GameName_Begin, GameName_End - GameName_Begin); + + //Skip comments + if (RomName == "Name:" || RomName == "Description:") + { + continue; + } + + //Create a new entry in the gamemap + m_GameMap[GameName] = RomName; + } + + return true; +} + + + +eOSState cGameList::ProcessKey(eKeys Key) +{ + eOSState state=cOsdMenu::ProcessKey(Key); + switch (Key) + { + case kOk: + Open(); + state = osEnd; + break; + case kRed: + Open(); + state = osEnd; + break; + default: + break; + } + return state; +} + + + +void cGameList::FillFolders() +{ + //Walk through m_GameMap, and compare the foldername with the first letter of the + //game, converted to uppercase + //If the foldername is "#", check the first character is a digit + for (m_MapIter = m_GameMap.begin(); m_MapIter != m_GameMap.end(); ++m_MapIter) + { + if (FolderName[0] == '#' && isdigit(m_MapIter->first[0])) + { + cOsdItem* GameName = new cOsdItem((m_MapIter->first).c_str()); + Add(GameName); + } + + if (toupper(m_MapIter->first[0]) == FolderName[0]) + { + cOsdItem* GameName = new cOsdItem((m_MapIter->first).c_str()); + Add(GameName); + } + } + + SetHelp(tr("Play")); +} + + + +void cGameList::Open() +{ + cOsdItem* Item = (cOsdItem*)Get(Current()); + stringstream SelectedGame; + SelectedGame << Item->Text(); + + Actions->Play(m_GameMap[SelectedGame.str()]); +} + |