diff options
author | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-08-19 14:47:57 +0000 |
---|---|---|
committer | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-08-19 14:47:57 +0000 |
commit | 2d9582980adaa3108a3be4e75569afb3c4bbe9e9 (patch) | |
tree | 9c1a3b3599c3b1391bd80913d7ea911fb848b085 /src/menuconfiguration.cpp | |
parent | 9ceabe93656984d2a6bb63bcd7e80379f2623ff6 (diff) | |
download | vdr-plugin-menuorg-2d9582980adaa3108a3be4e75569afb3c4bbe9e9.tar.gz vdr-plugin-menuorg-2d9582980adaa3108a3be4e75569afb3c4bbe9e9.tar.bz2 |
renamed XmlMenu to MenuConfiguration
git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/submenu/trunk@5825 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f
Diffstat (limited to 'src/menuconfiguration.cpp')
-rw-r--r-- | src/menuconfiguration.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/src/menuconfiguration.cpp b/src/menuconfiguration.cpp new file mode 100644 index 0000000..a25c56c --- /dev/null +++ b/src/menuconfiguration.cpp @@ -0,0 +1,179 @@ +/* + * vdr-menuorg - A plugin for the Linux Video Disk Recorder + * Copyright (C) 2007 Thomas Creutz, Tobias Grimm + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + * + */ + +#include "menuconfiguration.h" +#include <libxml++/libxml++.h> +#include <exception> +#include <vdr/plugin.h> +#include "systemmenuitem.h" +#include "submenuitem.h" +#include "pluginmenuitem.h" + +using namespace xmlpp; +using namespace std; + +const string MenuConfiguration::_dtd = + "<!ELEMENT menus ((menu | system | plugin)+)>\n" + "<!ELEMENT menu ((menu | system | plugin)+)>\n" + "<!ATTLIST menu name CDATA #REQUIRED>\n" + "<!ELEMENT system EMPTY>\n" + "<!ATTLIST system name CDATA #REQUIRED>\n" + "<!ELEMENT plugin EMPTY>\n" + "<!ATTLIST plugin name CDATA #REQUIRED>\n"; + +MenuNode* MenuConfiguration::LoadMenu(string menuFileName, string schemaFileName) +{ + MenuNode* menuRoot = new MenuNode(); + + try + { + dsyslog("loading menuorg config file from %s and schema from %s", menuFileName.c_str(), schemaFileName.c_str()); + + DomParser parser; + parser.set_substitute_entities(); + parser.parse_file(menuFileName); + + DtdValidator validator; + validator.parse_memory(_dtd); + + Document *pDoc = parser.get_document(); + validator.validate( pDoc ); + + const Element* rootElement = parser.get_document()->get_root_node(); + ParseElement(rootElement, menuRoot); + } + catch(const std::exception& ex) + { + delete menuRoot; + menuRoot = NULL; + + esyslog("Exception caught when parsing xml configuration: %s", ex.what()); + } + + return menuRoot; +} + +void MenuConfiguration::ParseElement(const Element* element, MenuNode* menuNode) +{ + Node::NodeList children = element->get_children(); + for (Node::NodeList::iterator i = children.begin(); i != children.end(); i++) + { + const xmlpp::Element* childElement = dynamic_cast<const xmlpp::Element*>(*i); + + if (childElement) + { + const xmlpp::Attribute* nameAttribute = childElement->get_attribute("name"); + + if (nameAttribute) + { + string type = childElement->get_name(); + string name = nameAttribute->get_value(); + + if ( type == "menu") + { + MenuNode* subMenu = AddSubMenuItem(name, menuNode); + ParseElement(childElement, subMenu); + } + else if (type == "system") + { + AddSystemMenuItem(name, menuNode); + } + else if (type == "plugin") + { + AddPluginMenuItem(name, menuNode); + } + } + } + } +} + +MenuNode* MenuConfiguration::AddSubMenuItem(string name, MenuNode* menu) +{ + return menu->AddChild(new SubMenuItem(name)); +} + +void MenuConfiguration::AddSystemMenuItem(string name, MenuNode* menu) +{ + menu->AddChild(new SystemMenuItem(name, MenuTextToVdrState(name))); +} + +void MenuConfiguration::AddPluginMenuItem(string pluginName, MenuNode* menu) +{ + const char* pluginMainMenuEntry; + int pluginIndex; + + if (FindPluginByName(pluginName, &pluginMainMenuEntry, pluginIndex)) + { + menu->AddChild(new PluginMenuItem(pluginMainMenuEntry, pluginIndex)); + } +} + +eOSState MenuConfiguration::MenuTextToVdrState(string menuText) +{ + if (menuText == "Schedule") + { + return osSchedule; + } + else if (menuText == "Channels") + { + return osChannels; + } + else if (menuText == "Timers") + { + return osTimers; + } + else if (menuText == "Recordings") + { + return osRecordings; + } + else if (menuText == "Setup") + { + return osSetup; + } + else if (menuText == "Commands") + { + return osCommands; + } + else + return osContinue; +} + +bool MenuConfiguration::FindPluginByName(string name, const char** mainMenuEntry, int& pluginIndex) +{ + int i = 0; + + while (cPlugin *plugin = cPluginManager::GetPlugin(i)) + { + if (name == plugin->Name()) + { + if (const char *item = plugin->MainMenuEntry()) + { + pluginIndex = i; + *mainMenuEntry = item; + return true; + } + } + i++; + } + + return false; +} |