diff options
author | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-07-28 09:08:10 +0000 |
---|---|---|
committer | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-07-28 09:08:10 +0000 |
commit | 68e0fa1bf7d1c311b632b7409ff62e3769ed2a8e (patch) | |
tree | 6150936710989aa19e1dd63f9df2c904dccd4c17 | |
parent | 5add845c880a421d3f8c4624476c6941c2b5e551 (diff) | |
download | vdr-plugin-menuorg-68e0fa1bf7d1c311b632b7409ff62e3769ed2a8e.tar.gz vdr-plugin-menuorg-68e0fa1bf7d1c311b632b7409ff62e3769ed2a8e.tar.bz2 |
cleaned up the mess I left yesterday
git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/submenu/trunk@5663 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f
-rw-r--r-- | src/submenuprovider.cpp | 4 | ||||
-rw-r--r-- | src/xmlmenu.cpp | 82 | ||||
-rw-r--r-- | src/xmlmenu.h | 23 |
3 files changed, 69 insertions, 40 deletions
diff --git a/src/submenuprovider.cpp b/src/submenuprovider.cpp index 872927c..114fc04 100644 --- a/src/submenuprovider.cpp +++ b/src/submenuprovider.cpp @@ -7,8 +7,8 @@ SubMenuProvider::SubMenuProvider() { //CreateTestMenus(); - _oXmlMenu.loadXmlMenu(); - _currentMenu = &_oXmlMenu._rootMenuNode; + _oXmlMenu.LoadXmlMenu(); + _currentMenu = _oXmlMenu.GetMenuTree(); } /* void SubMenuProvider::CreateTestMenus() diff --git a/src/xmlmenu.cpp b/src/xmlmenu.cpp index be24c95..2f57335 100644 --- a/src/xmlmenu.cpp +++ b/src/xmlmenu.cpp @@ -1,16 +1,16 @@ +#include "xmlmenu.h" +#include <iostream> #include <libxml++/libxml++.h> +#include <exception> #include <vdr/plugin.h> -#include "menunode.h" #include "vdrmenuitem.h" #include "submenuitem.h" #include "pluginmenuitem.h" -#include "xmlmenu.h" -#include <iostream> using namespace xmlpp; using namespace std; -void XmlMenu::loadXmlMenu() +void XmlMenu::LoadXmlMenu() { // TODO: show how vdr handels the path vars (developer doc) // and change code for dynamic path vars @@ -41,6 +41,11 @@ void XmlMenu::loadXmlMenu() } } +MenuNode* XmlMenu::GetMenuTree() +{ + return &_rootMenuNode; +} + void XmlMenu::ParseElement(const Element* element, MenuNode* menuNode) { Node::NodeList children = element->get_children(); @@ -51,56 +56,74 @@ void XmlMenu::ParseElement(const Element* element, MenuNode* menuNode) if (childElement) { const xmlpp::Attribute* nameAttribute = childElement->get_attribute("name"); + if (nameAttribute) { - if (childElement->get_name() == "menu") + string type = childElement->get_name(); + string name = nameAttribute->get_value(); + + if ( type == "menu") { - MenuNode* subMenu = menuNode->AddChild(new SubMenuItem(nameAttribute->get_value())); + MenuNode* subMenu = AddSubMenuItem(name, menuNode); ParseElement(childElement, subMenu); } - else if (childElement->get_name() == "system") + else if (type == "system") { - std::string systemMenuItemText = nameAttribute->get_value(); - menuNode->AddChild(new VdrMenuItem(systemMenuItemText, geteOSState(systemMenuItemText))); + AddSystemMenuItem(name, menuNode); } - else if (childElement->get_name() == "plugin") + else if (type == "plugin") { - const char* pluginMainMenuEntry; - int pluginIndex; - - if (FindPluginByName(nameAttribute->get_value(), &pluginMainMenuEntry, pluginIndex)) - { - menuNode->AddChild(new PluginMenuItem(pluginMainMenuEntry, pluginIndex)); - } + AddPluginMenuItem(name, menuNode); } } } } } -eOSState XmlMenu::geteOSState(std::string name) +MenuNode* XmlMenu::AddSubMenuItem(string name, MenuNode* menu) +{ + return menu->AddChild(new SubMenuItem(name)); +} + +void XmlMenu::AddSystemMenuItem(string name, MenuNode* menu) +{ + menu->AddChild(new VdrMenuItem(name, MenuTextToVdrState(name))); +} + +void XmlMenu::AddPluginMenuItem(string pluginName, MenuNode* menu) +{ + const char* pluginMainMenuEntry; + int pluginIndex; + + if (FindPluginByName(pluginName, &pluginMainMenuEntry, pluginIndex)) + { + menu->AddChild(new PluginMenuItem(pluginMainMenuEntry, pluginIndex)); + } +} + +eOSState XmlMenu::MenuTextToVdrState(string menuText) { - if (name == "Schedule") + if (menuText == "Schedule") { return osSchedule; } - else if (name == "Channels") + else if (menuText == "Channels") { return osChannels; } - else if (name == "Timers") + else if (menuText == "Timers") { return osTimers; } - else if (name == "Recordings") + else if (menuText == "Recordings") { return osRecordings; } - else if (name == "Setup") + else if (menuText == "Setup") { return osSetup; } - else if (name == "Commands") + else if (menuText == "Commands") { return osCommands; } @@ -108,14 +131,15 @@ eOSState XmlMenu::geteOSState(std::string name) return osContinue; } -bool XmlMenu::FindPluginByName(std::string name, const char** mainMenuEntry, int& pluginIndex) +bool XmlMenu::FindPluginByName(string name, const char** mainMenuEntry, int& pluginIndex) { - int i=0; - while (cPlugin *p = cPluginManager::GetPlugin(i)) + int i = 0; + + while (cPlugin *plugin = cPluginManager::GetPlugin(i)) { - if (name == p->Name()) + if (name == plugin->Name()) { - if (const char *item = p->MainMenuEntry()) + if (const char *item = plugin->MainMenuEntry()) { pluginIndex = i; *mainMenuEntry = item; diff --git a/src/xmlmenu.h b/src/xmlmenu.h index 4c7dbb1..f3cf372 100644 --- a/src/xmlmenu.h +++ b/src/xmlmenu.h @@ -1,24 +1,29 @@ #ifndef ___XMLMENU_H #define ___XMLMENU_H -#include <libxml++/libxml++.h> +#include <string> +#include <vdr/osdbase.h> #include "menunode.h" -using namespace xmlpp; +namespace xmlpp { class Element; } class XmlMenu { private: - //void createMenu(); // create the Menu Node - void ParseElement(const Element* a_node, MenuNode* menuNode); - eOSState geteOSState(std::string name); // gets the eOSState for the given string - bool FindPluginByName(std::string name, const char** mainMenuEntry, int& pluginIndex); // gets the plugin for the given string - MenuNode* _subMenu[30]; // holds the submenus int MenuCount; + MenuNode _rootMenuNode; public: - MenuNode _rootMenuNode; // hold the Menue Nodes - void loadXmlMenu(); // load the xmlfile + MenuNode* GetMenuTree(); + void LoadXmlMenu(); + + private: + void ParseElement(const xmlpp::Element* a_node, MenuNode* menuNode); + eOSState MenuTextToVdrState(std::string menuText); + bool FindPluginByName(std::string name, const char** mainMenuEntry, int& pluginIndex); + MenuNode* AddSubMenuItem(std::string name, MenuNode* menu); + void AddSystemMenuItem(std::string name, MenuNode* menu); + void AddPluginMenuItem(std::string pluginName, MenuNode* menu); }; #endif |