summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/submenuprovider.cc9
-rw-r--r--src/submenuprovider.h4
-rw-r--r--src/xmlmenu.cpp231
-rw-r--r--src/xmlmenu.h19
4 files changed, 258 insertions, 5 deletions
diff --git a/src/submenuprovider.cc b/src/submenuprovider.cc
index beeb736..a731b60 100644
--- a/src/submenuprovider.cc
+++ b/src/submenuprovider.cc
@@ -6,10 +6,11 @@
SubMenuProvider::SubMenuProvider()
{
- CreateTestMenus();
- _currentMenu = &_rootMenuNode;
+ //CreateTestMenus();
+ _oXmlMenu.loadXmlMenu();
+ _currentMenu = &_rootMenuNode;
}
-
+/*
void SubMenuProvider::CreateTestMenus()
{
MenuNode* subMenu1 =_rootMenuNode.AddChild(new SubMenuItem("Custom menu 1"));
@@ -33,7 +34,7 @@ void SubMenuProvider::CreateTestMenus()
if (Commands.Count())
_rootMenuNode.AddChild(new VdrMenuItem(tr("Commands"), osCommands));
}
-
+*/
MainMenuItemsList* SubMenuProvider::MainMenuItems()
{
ResetMainMenuItemsList();
diff --git a/src/submenuprovider.h b/src/submenuprovider.h
index 095482b..7f3ac68 100644
--- a/src/submenuprovider.h
+++ b/src/submenuprovider.h
@@ -3,13 +3,15 @@
#include <vdr/submenupatch.h>
#include "menunode.h"
+#include "xmlmenu.h"
using namespace SubMenuPatch;
class SubMenuProvider: public ISubMenuProvider
{
private:
- MenuNode _rootMenuNode;
+ XmlMenu _oXmlMenu;
+ //MenuNode _rootMenuNode;
MenuNode* _currentMenu;
MainMenuItemsList _currentMainMenuItems;
diff --git a/src/xmlmenu.cpp b/src/xmlmenu.cpp
new file mode 100644
index 0000000..2bba503
--- /dev/null
+++ b/src/xmlmenu.cpp
@@ -0,0 +1,231 @@
+#include <libxml++/libxml++.h>
+#include <iostream>
+
+//#include <vdr/submenupatch.h>
+using namespace xmlpp;
+using namespace std;
+
+XmlMenu::XmlMenu(void)
+{
+ //MenuNr = 0;
+}
+
+void XmlMenu::loadXmlMenu()
+{
+ // TODO: show how vdr handels the path vars (developer doc)
+ // and change code for dynamic path vars
+ const char *File = "/var/lib/vdr/plugins/vdr-menu.xml";
+
+ try
+ {
+ DomParser parser;
+
+ //TODO: patch the xmlfile with the xsd definition for validate
+ //parser.set_validate();
+ parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
+ parser.parse_file(File);
+ if(parser)
+ {
+ //Walk the tree:
+ const Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
+ parseNode(pNode,0);
+ }
+ }
+ catch(const std::exception& ex)
+ {
+ //TODO: print output to syslog (isyslog or dsyslog?)
+ cout << "Exception caught: " << ex.what() << endl;
+
+ //TODO: display message on osd
+ }
+}
+
+void XmlMenu::parseNode(const Node* a_node, unsigned int Parent, MenuNode *parentNode)
+{
+ const ContentNode* nodeContent = dynamic_cast<const ContentNode*>(a_node);
+ const TextNode* nodeText = dynamic_cast<const TextNode*>(a_node);
+ const CommentNode* nodeComment = dynamic_cast<const CommentNode*>(a_node);
+
+/****
+ MenuNode* subMenu1 =_rootMenuNode.AddChild(new SubMenuItem("Custom menu 1"));
+ subMenu1->AddChild(new VdrMenuItem(tr("Schedule"), osSchedule));
+ subMenu1->AddChild(new VdrMenuItem(tr("Channels"), osChannels));
+ MenuNode* subMenu1_1 = subMenu1->AddChild(new SubMenuItem("Custom menu 1.1"));
+ subMenu1_1->AddChild(new VdrMenuItem(tr("Timers"), osTimers));
+ subMenu1_1->AddChild(new VdrMenuItem(tr("Recordings"), osRecordings));
+ MenuNode* subMenu2 =_rootMenuNode.AddChild(new SubMenuItem("Custom menu 2"));
+ subMenu2->AddChild(new PluginMenuItem(item, i));
+****/
+
+ Glib::ustring nodename = a_node->get_name();
+
+ if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
+ {
+ for(int i=0;i<=Parent;i++)
+ {
+ printf(" ");
+ }
+ if (nodename == "menus")
+ {
+ //cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-ROOT" << endl;
+
+ }
+ else if (nodename == "system")
+ {
+ if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
+ {
+ const Element::AttributeList& attributes = nodeElement->get_attributes();
+ for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
+ {
+ const Attribute* attribute = *iter;
+ //cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-SystemItem=" << attribute->get_value() << endl;
+ if (parentNode == NULL)
+ newparentNode =_rootMenuNode.AddChild(new VdrMenuItem(tr(attribute->get_value()), geteOSState(attribute->get_value())));
+ else
+ newparentNode = parentNode->AddChild(new VdrMenuItem(tr(attribute->get_value()), geteOSState(attribute->get_value())));
+ }
+ }
+ }
+ else if (nodename == "menu")
+ {
+ if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
+ {
+ const Element::AttributeList& attributes = nodeElement->get_attributes();
+ for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
+ {
+ const Attribute* attribute = *iter;
+ //cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-MenuItem=" << attribute->get_value() << endl;
+ if (parentNode == NULL)
+ newparentNode =_rootMenuNode.AddChild(new SubMenuItem(attribute->get_value()));
+ else
+ newparentNode = parentNode->AddChild(new SubMenuItem(attribute->get_value()));
+ }
+ }
+ }
+ else if (nodename == "plugin")
+ {
+ if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
+ {
+ const Element::AttributeList& attributes = nodeElement->get_attributes();
+ for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
+ {
+ const Attribute* attribute = *iter;
+ //cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-PluginItem=" << attribute->get_value() << endl;
+ if (getPluginIndex(attribute->get_value()) != NULL)
+ {
+ if (parentNode == NULL)
+ newparentNode =_rootMenuNode.AddChild(new PluginMenuItem(item, getPluginIndex(attribute->get_value())));
+ else
+ newparentNode = parentNode->AddChild(new PluginMenuItem(item, getPluginIndex(attribute->get_value())));
+ }
+ }
+ }
+ }
+ }
+ if(!nodeContent)
+ {
+ //Recurse through child nodes:
+ Node::NodeList list = a_node->get_children();
+ for(Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
+ {
+ parseNode(*iter, Parent+1, newparentNode); //recursive
+ }
+ }
+}
+/*
+enum eOSState { osUnknown,
+ osContinue,
+ osSchedule,
+ osChannels,
+ osTimers,
+ osRecordings,
+ osPlugin,
+ osSetup,
+ osCommands,
+ osPause,
+ osRecord,
+ osReplay,
+ osStopRecord,
+ osStopReplay,
+ osCancelEdit,
+ osSwitchDvb,
+ osBack,
+ osEnd,
+ os_User, // the following values can be used locally
+ osUser1,
+ osUser2,
+ osUser3,
+ osUser4,
+ osUser5,
+ osUser6,
+ osUser7,
+ osUser8,
+ osUser9,
+ osUser10,
+ };
+*/
+eOSState XmlMenu::geteOSState(char* name)
+{
+ if(name == "Continue")
+ {
+ return osContinue;
+ }
+ else if (name == "Schedule")
+ {
+ return osSchedule;
+ }
+ else if (name == "Channels")
+ {
+ return osChannels;
+ }
+ else if (name == "Timers")
+ {
+ return osTimers;
+ }
+ else if (name == "Recordings")
+ {
+ return osRecordings;
+ }
+ else if (name == "Plugin")
+ {
+ return osPlugin;
+ }
+ else if (name == "Setup")
+ {
+ return osSetup;
+ }
+ else if (name == "Pause")
+ {
+ return osPause;
+ }
+ else if (name == "Record")
+ {
+ return osRecord;
+ }
+ else if (name == "Replay")
+ {
+ return osReplay;
+ }
+ else if (name == "CancelEdit")
+ {
+ return osCancelEdit;
+ }
+ else if (name == "SwitchDvb")
+ {
+ return osSwitchDvb;
+ }
+ else if (name == "Back")
+ {
+ return osBack;
+ }
+ else if (name == "End")
+ {
+ return osEnd;
+ }
+ else if (name == "User")
+ {
+ return os_User;
+ }
+ else
+ return osContinue;
+} \ No newline at end of file
diff --git a/src/xmlmenu.h b/src/xmlmenu.h
new file mode 100644
index 0000000..eb9dd77
--- /dev/null
+++ b/src/xmlmenu.h
@@ -0,0 +1,19 @@
+#ifndef ___XMLMENU_H
+#define ___XMLMENU_H
+
+#include "menunode.h"
+
+class XmlMenu
+{
+ private:
+ //void createMenu(); // create the Menu Node
+ void parseNode(const Node *a_node, unsigned int Parent);
+ eOSState geteOSState(char* name); // gets the eOSState for the given string
+ int getPluginIndex(char* name); // gets the plugin index for the given string
+ public:
+ MenuNode _rootMenuNode; // hold the Menue Node
+ XmlMenu (void);
+ void loadXmlMenu(); // load the xmlfile
+};
+
+#endif