From 2d9582980adaa3108a3be4e75569afb3c4bbe9e9 Mon Sep 17 00:00:00 2001 From: svntobi Date: Sun, 19 Aug 2007 14:47:57 +0000 Subject: renamed XmlMenu to MenuConfiguration git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/submenu/trunk@5825 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f --- src/mainmenuitemsprovider.h | 1 - src/menuconfiguration.cpp | 179 ++++++++++++++++++++++++++++++++++++++++++++ src/menuconfiguration.h | 49 ++++++++++++ src/menuorg.cpp | 5 +- src/xmlmenu.cpp | 179 -------------------------------------------- src/xmlmenu.h | 49 ------------ 6 files changed, 231 insertions(+), 231 deletions(-) create mode 100644 src/menuconfiguration.cpp create mode 100644 src/menuconfiguration.h delete mode 100644 src/xmlmenu.cpp delete mode 100644 src/xmlmenu.h (limited to 'src') diff --git a/src/mainmenuitemsprovider.h b/src/mainmenuitemsprovider.h index 013f76e..951f600 100644 --- a/src/mainmenuitemsprovider.h +++ b/src/mainmenuitemsprovider.h @@ -25,7 +25,6 @@ #include #include "menunode.h" -#include "xmlmenu.h" using namespace MenuOrgPatch; 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 +#include +#include +#include "systemmenuitem.h" +#include "submenuitem.h" +#include "pluginmenuitem.h" + +using namespace xmlpp; +using namespace std; + +const string MenuConfiguration::_dtd = + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\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(*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; +} diff --git a/src/menuconfiguration.h b/src/menuconfiguration.h new file mode 100644 index 0000000..65ac1d3 --- /dev/null +++ b/src/menuconfiguration.h @@ -0,0 +1,49 @@ +/* + * 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$ + * + */ + +#ifndef ___MENUCONFIGURARION_H +#define ___MENUCONFIGURATION_H + +#include +#include +#include "menunode.h" + +namespace xmlpp { class Element; } + +class MenuConfiguration +{ + private: + static const std::string _dtd; + + public: + MenuNode* LoadMenu(std::string menuFileName, std::string schemaFileName); + + 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 diff --git a/src/menuorg.cpp b/src/menuorg.cpp index 1ef6738..ce15527 100644 --- a/src/menuorg.cpp +++ b/src/menuorg.cpp @@ -30,6 +30,7 @@ #include #include "version.h" #include "menuorg.h" +#include "menuconfiguration.h" #include "i18n.h" using namespace std; @@ -107,7 +108,7 @@ bool MenuOrgPlugin::ProcessArgs(int argc, char *argv[]) bool MenuOrgPlugin::Initialize(void) { - XmlMenu xmlMenu; + MenuConfiguration menuConfiguration; if(configFile.empty()) configFile = (string) ConfigDirectory() + "/menuorg.xml"; @@ -115,7 +116,7 @@ bool MenuOrgPlugin::Initialize(void) if(schemaFile.empty()) schemaFile = (string) ConfigDirectory() + "/menuorg.dtd"; - MenuNode* menu = xmlMenu.LoadXmlMenu(configFile, schemaFile); + MenuNode* menu = menuConfiguration.LoadMenu(configFile, schemaFile); if (menu) { _subMenuProvider = new MainMenuItemsProvider(menu); diff --git a/src/xmlmenu.cpp b/src/xmlmenu.cpp deleted file mode 100644 index b050dbd..0000000 --- a/src/xmlmenu.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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 "xmlmenu.h" -#include -#include -#include -#include "systemmenuitem.h" -#include "submenuitem.h" -#include "pluginmenuitem.h" - -using namespace xmlpp; -using namespace std; - -const string XmlMenu::_dtd = - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n"; - -MenuNode* XmlMenu::LoadXmlMenu(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 XmlMenu::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(*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* XmlMenu::AddSubMenuItem(string name, MenuNode* menu) -{ - return menu->AddChild(new SubMenuItem(name)); -} - -void XmlMenu::AddSystemMenuItem(string name, MenuNode* menu) -{ - menu->AddChild(new SystemMenuItem(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 (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 XmlMenu::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; -} diff --git a/src/xmlmenu.h b/src/xmlmenu.h deleted file mode 100644 index 4bf8160..0000000 --- a/src/xmlmenu.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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$ - * - */ - -#ifndef ___XMLMENU_H -#define ___XMLMENU_H - -#include -#include -#include "menunode.h" - -namespace xmlpp { class Element; } - -class XmlMenu -{ - private: - static const std::string _dtd; - - public: - MenuNode* LoadXmlMenu(std::string menuFileName, std::string schemaFileName); - - 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 -- cgit v1.2.3