diff options
| author | louis <louis.braun@gmx.de> | 2015-07-07 17:58:10 +0200 |
|---|---|---|
| committer | louis <louis.braun@gmx.de> | 2015-07-07 17:58:10 +0200 |
| commit | 5a6fb850b35bc63325cac482daaa70b00b0e8e8b (patch) | |
| tree | c46bea143641a4a0f4461b971ae2cd03e10ac76b /libtemplate/xmlparser.c | |
| parent | 50fe393724a265341b1745dd401db9d93f46f354 (diff) | |
| download | vdr-plugin-skindesigner-5a6fb850b35bc63325cac482daaa70b00b0e8e8b.tar.gz vdr-plugin-skindesigner-5a6fb850b35bc63325cac482daaa70b00b0e8e8b.tar.bz2 | |
immplemented areacontainers to group areas
Diffstat (limited to 'libtemplate/xmlparser.c')
| -rw-r--r-- | libtemplate/xmlparser.c | 1243 |
1 files changed, 437 insertions, 806 deletions
diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index 4db7ce5..3df65f3 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -4,459 +4,432 @@ using namespace std; -void SkinDesignerXMLErrorHandler (void * userData, xmlErrorPtr error) { - esyslog("skindesigner: Error in XML: %s", error->message); -} - cXmlParser::cXmlParser(void) { view = NULL; - doc = NULL; - root = NULL; - ctxt = NULL; globals = NULL; skinSetup = NULL; - - initGenericErrorDefaultFunc(NULL); - xmlSetStructuredErrorFunc(NULL, SkinDesignerXMLErrorHandler); - ctxt = xmlNewParserCtxt(); } cXmlParser::~cXmlParser() { - DeleteDocument(); - xmlFreeParserCtxt(ctxt); } /********************************************************************* * PUBLIC Functions *********************************************************************/ bool cXmlParser::ReadView(cTemplateView *view, string xmlFile) { + if (!view) + return false; this->view = view; - string xmlPath = GetPath(xmlFile); - - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { - esyslog("skindesigner: ERROR: TemplateView %s not parsed successfully.", xmlPath.c_str()); + if (! Validate() ) return false; - } - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + if (! SetDocument() ) return false; - } - - root = xmlDocGetRootElement(doc); + if (! CheckNodeName(view->GetViewName()) ) + return false; + return true; +} - if (root == NULL) { - esyslog("skindesigner: ERROR: TemplateView %s is empty", xmlPath.c_str()); +bool cXmlParser::ParseView(void) { + if (!view) return false; - } - if (xmlStrcmp(root->name, (const xmlChar *) view->GetViewName())) { + vector<stringpair> rootAttribs = ParseAttributes(); + ValidateAttributes(NodeName(), rootAttribs); + view->SetParameters(rootAttribs); + + if (!LevelDown()) return false; - } + + do { + + if (view->ValidSubView(NodeName())) { + ParseSubView(); + } else if (view->ValidViewElement(NodeName())) { + ParseViewElement(); + } else if (view->ValidViewList(NodeName())) { + ParseViewList(); + } else if (view->ValidViewGrid(NodeName())) { + ParseGrid(); + } else if (CheckNodeName("tab")) { + ParseViewTab(view); + } else { + return false; + } + + } while (NextNode()); + return true; + } bool cXmlParser::ReadPluginView(string plugName, int templateNumber, string templateName) { - string xmlPath = GetPath(templateName); - - if (!FileExists(xmlPath) || ctxt == NULL) { - return false; - } DeleteDocument(); - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + if (! Validate() ) return false; - } + if (! SetDocument() ) + return false; + return true; +} - root = xmlDocGetRootElement(doc); +bool cXmlParser::ParsePluginView(string plugName, int templateNumber) { + cTemplateView *plugView = new cTemplateViewMenu(); + view->AddPluginView(plugName, templateNumber, plugView); + + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + plugView->SetParameters(attribs); - if (root == NULL) { + if (!LevelDown()) return false; - } + do { + + if (plugView->ValidViewElement(NodeName())) { + ParseViewElement(plugView); + } else if (plugView->ValidViewList(NodeName())) { + ParseViewList(plugView); + } else if (CheckNodeName("tab")) { + ParseViewTab(plugView); + } else { + return false; + } + + } while (NextNode()); return true; } -bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile, bool mandatory) { +bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile) { this->globals = globals; - string xmlPath = GetPath(xmlFile); - - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); + DeleteDocument(); + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { - if (mandatory) { - esyslog("skindesigner: ERROR: Globals %s not parsed successfully.", xmlPath.c_str()); - } else { - dsyslog("skindesigner: Globals %s not parsed successfully.", xmlPath.c_str()); - } + if (! Validate() ) return false; - } - - root = xmlDocGetRootElement(doc); - - if (ctxt->valid == 0) { - if (mandatory) { - esyslog("skindesigner: ERROR: Failed to validate %s", xmlPath.c_str()); - } else { - dsyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); - } + if (! SetDocument() ) return false; - } - - if (root == NULL) { - if (mandatory) { - esyslog("skindesigner: ERROR: Globals %s is empty", xmlPath.c_str()); - } + if (! CheckNodeName("globals") ) return false; - } + return true; +} - if (xmlStrcmp(root->name, (const xmlChar *) "globals")) { +bool cXmlParser::ParseGlobals(void) { + if (!LevelDown()) return false; - } + do { + if (CheckNodeName("colors")) { + ParseGlobalColors(); + } else if (CheckNodeName("variables")) { + ParseGlobalVariables(); + } else if (CheckNodeName("fonts")) { + ParseGlobalFonts(); + } else if (CheckNodeName("translations")) { + ParseTranslations(); + } + } while (NextNode()); return true; } bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile) { this->skinSetup = skinSetup; - - if (!FileExists(xmlFile)) - return false; - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); - return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlFile.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL ) { - esyslog("skindesigner: ERROR: skin setup %s not parsed successfully.", xmlFile.c_str()); + if (! ReadXMLFile(xmlFile.c_str()) ) return false; - } - - root = xmlDocGetRootElement(doc); - - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlFile.c_str()); + if (! Validate() ) return false; - } - if (root == NULL) { + if (! SetDocument() ) return false; - } - if (xmlStrcmp(root->name, (const xmlChar *) "setup")) { + if (! CheckNodeName("setup") ) return false; - } - return true; } +bool cXmlParser::ParseSkinSetup(string skin) { + if (!LevelDown()) + return false; + do { + if (CheckNodeName("menu")) { + ParseSetupMenu(); + } else if (CheckNodeName("translations")) { + ParseTranslations(); + } + } while (NextNode()); + return true; +} +/********************************************************************* +* PRIVATE Functions +*********************************************************************/ -bool cXmlParser::ParseView(void) { - vector<pair<string, string> > rootAttribs; - ParseAttributes(root->properties, root, rootAttribs); - +bool cXmlParser::ParseSubView(void) { if (!view) return false; - view->SetParameters(rootAttribs); - - xmlNodePtr node = root->xmlChildrenNode; + cTemplateView *subView = new cTemplateViewMenu(); + view->AddSubView(NodeName(), subView); - while (node != NULL) { + vector<pair<string, string> > subViewAttribs = ParseAttributes(); + ValidateAttributes(NodeName(), subViewAttribs); + subView->SetParameters(subViewAttribs); - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (view->ValidSubView((const char*)node->name)) { - ParseSubView(node); - } else if (view->ValidViewElement((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs, true); - ParseViewElement(node->name, node->xmlChildrenNode, attribs); - } else if (view->ValidViewList((const char*)node->name)) { - ParseViewList(node); - } else if (view->ValidViewGrid((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - ParseGrid(node->xmlChildrenNode, attribs); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "tab")) { - ParseViewTab(node, view); + if (!LevelDown()) + return false; + do { + + if (subView->ValidViewElement(NodeName())) { + ParseViewElement(subView); + } else if (subView->ValidViewList(NodeName())) { + ParseViewList(subView); + } else if (CheckNodeName("tab")) { + ParseViewTab(subView); } else { return false; } - node = node->next; - } - + } while (NextNode()); + LevelUp(); return true; - -} -bool cXmlParser::ParsePluginView(string plugName, int templateNumber) { +} +void cXmlParser::ParseViewElement(cTemplateView *subView) { + if (!view) + return; + + const char *viewElement = NodeName(); + vector<stringpair> attributes = ParseAttributes(); + ValidateAttributes("viewelement", attributes); - cTemplateView *plugView = new cTemplateViewMenu(); - view->AddPluginView(plugName, templateNumber, plugView); + if (!LevelDown()) + return; + do { + if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName()); + continue; + } + cTemplatePixmapNode *pix = NULL; + if (CheckNodeName("area") || CheckNodeName("areascroll")) { + pix = ParseArea(); + } else { + pix = ParseAreaContainer(); + } + if (subView) + subView->AddPixmap(viewElement, pix, attributes); + else + view->AddPixmap(viewElement, pix, attributes); + } while (NextNode()); + LevelUp(); +} - vector<pair<string, string> > attribs; - ParseAttributes(root->properties, root, attribs); +void cXmlParser::ParseViewList(cTemplateView *subView) { + if (!view) + return; + + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); - plugView->SetParameters(attribs); + cTemplateViewList *viewList = new cTemplateViewList(); + viewList->SetGlobals(globals); + viewList->SetParameters(attribs); - xmlNodePtr childNode = root->xmlChildrenNode; + if (!LevelDown()) + return; - while (childNode != NULL) { + do { + if (CheckNodeName("currentelement")) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } + cTemplateViewElement *currentElement = new cTemplateViewElement(); + vector<stringpair> attribsCur = ParseAttributes(); + ValidateAttributes(NodeName(), attribsCur); + currentElement->SetGlobals(globals); + currentElement->SetParameters(attribsCur); + if (!LevelDown()) + return; + do { + if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName()); + continue; + } + cTemplatePixmapNode *pix = NULL; + if (CheckNodeName("area") || CheckNodeName("areascroll")) { + pix = ParseArea(); + } else { + pix = ParseAreaContainer(); + } + currentElement->AddPixmap(pix); + } while (NextNode()); + LevelUp(); + viewList->AddCurrentElement(currentElement); - if (plugView->ValidViewElement((const char*)childNode->name)) { - vector<pair<string, string> > attribs; - ParseViewElement(childNode->name, childNode->xmlChildrenNode, attribs, plugView); - } else if (plugView->ValidViewList((const char*)childNode->name)) { - ParseViewList(childNode, plugView); - } else if (!xmlStrcmp(childNode->name, (const xmlChar *) "tab")) { - ParseViewTab(childNode, plugView); - } else { - return false; + } else if (CheckNodeName("listelement")) { + + cTemplateViewElement *listElement = new cTemplateViewElement(); + vector<stringpair> attribsList = ParseAttributes(); + ValidateAttributes(NodeName(), attribsList); + listElement->SetGlobals(globals); + listElement->SetParameters(attribsList); + if (!LevelDown()) + return; + do { + if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName()); + continue; + } + cTemplatePixmapNode *pix = NULL; + if (CheckNodeName("area") || CheckNodeName("areascroll")) { + pix = ParseArea(); + } else { + pix = ParseAreaContainer(); + } + listElement->AddPixmap(pix); + } while (NextNode()); + LevelUp(); + viewList->AddListElement(listElement); } - childNode = childNode->next; - } + } while (NextNode()); + LevelUp(); - return true; + if (subView) + subView->AddViewList(NodeName(), viewList); + else + view->AddViewList(NodeName(), viewList); } -bool cXmlParser::ParseGlobals(void) { - xmlNodePtr node = root->xmlChildrenNode; - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (!xmlStrcmp(node->name, (const xmlChar *) "colors")) { - ParseGlobalColors(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "variables")) { - ParseGlobalVariables(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "fonts")) { - ParseGlobalFonts(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "translations")) { - ParseTranslations(node->xmlChildrenNode); - node = node->next; - continue; - } - node = node->next; - } +void cXmlParser::ParseViewTab(cTemplateView *subView) { + if (!view || !subView) + return; - return true; + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + cTemplateViewTab *viewTab = new cTemplateViewTab(); + viewTab->SetGlobals(globals); + viewTab->SetParameters(attribs); + viewTab->SetScrolling(); + ParseFunctionCalls(viewTab); + subView->AddViewTab(viewTab); } -bool cXmlParser::ParseSkinSetup(string skin) { - xmlNodePtr node = root->xmlChildrenNode; +void cXmlParser::ParseGrid(void) { + if (!view) + return; + + vector<stringpair> attributes = ParseAttributes(); + ValidateAttributes(NodeName(), attributes); + + if (!LevelDown()) + return; + do { - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in grid", NodeName()); continue; } - if (!xmlStrcmp(node->name, (const xmlChar *) "menu")) { - ParseSetupMenu(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "translations")) { - ParseTranslations(node->xmlChildrenNode); - node = node->next; - continue; + cTemplatePixmapNode *pix = NULL; + if (CheckNodeName("area") || CheckNodeName("areascroll")) { + pix = ParseArea(); + } else { + pix = ParseAreaContainer(); } - node = node->next; - } - - return true; - + view->AddPixmapGrid(pix, attributes); + } while (NextNode()); + LevelUp(); } -void cXmlParser::DeleteDocument(void) { - if (doc) { - xmlFreeDoc(doc); - doc = NULL; +cTemplatePixmap *cXmlParser::ParseArea(void) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + + cTemplatePixmap *pix = new cTemplatePixmap(); + if (CheckNodeName("areascroll")) { + pix->SetScrolling(); } + pix->SetParameters(attribs); + ParseFunctionCalls(pix); + return pix; } -/********************************************************************* -* PRIVATE Functions -*********************************************************************/ +cTemplatePixmapContainer *cXmlParser::ParseAreaContainer(void) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); -string cXmlParser::GetPath(string xmlFile) { - string activeSkin = Setup.OSDSkin; - string activeTheme = Setup.OSDTheme; - string path = ""; - if (!xmlFile.compare("globals.xml")) { - path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); - } else if (!xmlFile.compare("theme.xml")) { - path = *cString::sprintf("%s%s/themes/%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), activeTheme.c_str(), xmlFile.c_str()); - } else if (!xmlFile.compare("setup.xml")) { - path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); - } else { - path = *cString::sprintf("%s%s/xmlfiles/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); - } - return path; + cTemplatePixmapContainer *pixContainer = new cTemplatePixmapContainer(); + pixContainer->SetParameters(attribs); + + if (!LevelDown()) + return pixContainer; + do { + if (!CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in areacontainer", NodeName()); + continue; + } + cTemplatePixmap *pix = ParseArea(); + pixContainer->AddPixmap(pix); + } while (NextNode()); + LevelUp(); + return pixContainer; } -void cXmlParser::ParseSetupMenu(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseFunctionCalls(cTemplatePixmap *pix) { + if (!view) return; - if (!skinSetup) + if (!LevelDown()) return; - - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; + do { + if (CheckNodeName("loop")) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + cTemplateLoopFunction *loopFunc = new cTemplateLoopFunction(); + loopFunc->SetParameters(attribs); + ParseLoopFunctionCalls(loopFunc); + pix->AddLoopFunction(loopFunc); + } else if (view->ValidFunction(NodeName())) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + pix->AddFunction(NodeName(), attribs); } - if (!xmlStrcmp(node->name, (const xmlChar *) "parameter")) { - ParseSetupParameter(node); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "submenu")) { - xmlAttrPtr attr = node->properties; - xmlChar *subMenuName = NULL; - xmlChar *subDisplayText = NULL; - while (NULL != attr) { - if (!xmlStrcmp(attr->name, (const xmlChar *) "name")) { - subMenuName = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "displaytext")) { - subDisplayText = xmlGetProp(node, attr->name); - } - attr = attr->next; - } - skinSetup->SetSubMenu(subMenuName, subDisplayText); - ParseSetupMenu(node->xmlChildrenNode); - if (subMenuName) - xmlFree(subMenuName); - if (subDisplayText) - xmlFree(subDisplayText); - } - node = node->next; - } - skinSetup->SubMenuDone(); + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseSetupParameter(xmlNodePtr node) { - if (!node) - return; - if (!skinSetup) +void cXmlParser::ParseLoopFunctionCalls(cTemplateLoopFunction *loopFunc) { + if (!view) return; - - xmlAttrPtr attr = node->properties; - if (attr == NULL) { + if (!LevelDown()) return; - } - xmlChar *paramType = NULL; - xmlChar *paramName = NULL; - xmlChar *paramDisplayText = NULL; - xmlChar *paramMin = NULL; - xmlChar *paramMax = NULL; - xmlChar *paramValue = NULL; - while (NULL != attr) { - if (!xmlStrcmp(attr->name, (const xmlChar *) "type")) { - paramType = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "name")) { - paramName = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "displaytext")) { - paramDisplayText = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "min")) { - paramMin = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "max")) { - paramMax = xmlGetProp(node, attr->name); - } - attr = attr->next; - } - paramValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - skinSetup->SetParameter(paramType, paramName, paramDisplayText, paramMin, paramMax, paramValue); - if (paramType) - xmlFree(paramType); - if (paramName) - xmlFree(paramName); - if (paramDisplayText) - xmlFree(paramDisplayText); - if (paramMin) - xmlFree(paramMin); - if (paramMax) - xmlFree(paramMax); - if (paramValue) - xmlFree(paramValue); + do { + if (view->ValidFunction(NodeName())) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + loopFunc->AddFunction(NodeName(), attribs); + } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseGlobalColors(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalColors(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "color")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; + do { + if (!CheckNodeName("color")) { continue; } - xmlChar *colName = NULL; - xmlChar *colValue = NULL; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - colName = xmlGetProp(node, attr->name); - attr = attr->next; - } + string attributeName = "name"; + string colorName = ""; + string colorValue = ""; + bool ok = GetAttribute(attributeName, colorName); if (ok) { - colValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (colName && colValue) - InsertColor((const char*)colName, (const char*)colValue); + ok = GetNodeValue(colorValue); + if (ok) + InsertColor(colorName, colorValue); } - if (colName) - xmlFree(colName); - if (colValue) - xmlFree(colValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } void cXmlParser::InsertColor(string name, string value) { @@ -469,50 +442,29 @@ void cXmlParser::InsertColor(string name, string value) { globals->AddColor(name, colVal); } -void cXmlParser::ParseGlobalVariables(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalVariables(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + do { + if (!CheckNodeName("var")) { continue; } - if (xmlStrcmp(node->name, (const xmlChar *) "var")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; - continue; - } - xmlChar *varName = NULL; - xmlChar *varType = NULL; - xmlChar *varValue = NULL; - while (NULL != attr) { - if (!xmlStrcmp(attr->name, (const xmlChar *) "name")) { - varName = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "type")) { - varType = xmlGetProp(node, attr->name); - } else { - attr = attr->next; - continue; - } - attr = attr->next; + string attributeName = "name"; + string attributeType = "type"; + string varName = ""; + string varType = ""; + string varValue = ""; + + bool ok1 = GetAttribute(attributeName, varName); + bool ok2 = GetAttribute(attributeType, varType); + + if (ok1 && ok2) { + bool ok = GetNodeValue(varValue); + if (ok) + InsertVariable(varName, varType, varValue); } - varValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (varName && varType && varValue) - InsertVariable((const char*)varName, (const char*)varType, (const char*)varValue); - if (varName) - xmlFree(varName); - if (varType) - xmlFree(varType); - if (varValue) - xmlFree(varValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } void cXmlParser::InsertVariable(string name, string type, string value) { @@ -526,467 +478,146 @@ void cXmlParser::InsertVariable(string name, string type, string value) { } } -void cXmlParser::ParseGlobalFonts(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalFonts(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "font")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; + do { + if (!CheckNodeName("font")) { continue; } - xmlChar *fontName = NULL; - xmlChar *fontValue = NULL; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - fontName = xmlGetProp(node, attr->name); - attr = attr->next; - } + string attributeName = "name"; + string fontName = ""; + string fontValue = ""; + + bool ok = GetAttribute(attributeName, fontName); if (ok) { - fontValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (fontName && fontValue) { - string fN = (const char*)fontName; - string fV = (const char*)fontValue; - globals->AddFont(fN, fV); + ok = GetNodeValue(fontValue); + if (ok) { + globals->AddFont(fontName, fontValue); } } - if (fontName) - xmlFree(fontName); - if (fontValue) - xmlFree(fontValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseTranslations(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseTranslations(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "token")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; - continue; - } - xmlChar *tokenName; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - tokenName = xmlGetProp(node, attr->name); - attr = attr->next; - } - if (!ok) - continue; - map < string, string > tokenTranslations; - xmlNodePtr nodeTrans = node->xmlChildrenNode; - while (nodeTrans != NULL) { - if (nodeTrans->type != XML_ELEMENT_NODE) { - nodeTrans = nodeTrans->next; - continue; - } - xmlChar *language = NULL; - if (xmlStrcmp(nodeTrans->name, (const xmlChar *) "trans")) { - nodeTrans = nodeTrans->next; - continue; - } - xmlAttrPtr attrTrans = nodeTrans->properties; - if (attrTrans == NULL) { - nodeTrans = nodeTrans->next; - continue; - } - ok = false; - - while (NULL != attrTrans) { - if (!ok && xmlStrcmp(attrTrans->name, (const xmlChar *) "lang")) { - attrTrans = attrTrans->next; - continue; - } - ok = true; - language = xmlGetProp(nodeTrans, attrTrans->name); - attrTrans = attrTrans->next; - } - if (!ok) - continue; - xmlChar *value = NULL; - value = xmlNodeListGetString(doc, nodeTrans->xmlChildrenNode, 1); - if (language && value) - tokenTranslations.insert(pair<string, string>((const char*)language, (const char*)value)); - if (language) - xmlFree(language); - if (value) - xmlFree(value); - nodeTrans = nodeTrans->next; - } - if (globals) { - globals->AddTranslation((const char*)tokenName, tokenTranslations); - } else if (skinSetup) { - skinSetup->SetTranslation((const char*)tokenName, tokenTranslations); - } - xmlFree(tokenName); - node = node->next; - } -} - -bool cXmlParser::ParseSubView(xmlNodePtr node) { - if (!node) - return false; - - if (!view) - return false; - - cTemplateView *subView = new cTemplateViewMenu(); - view->AddSubView((const char*)node->name, subView); - - vector<pair<string, string> > subViewAttribs; - ParseAttributes(node->properties, node, subViewAttribs); - - subView->SetParameters(subViewAttribs); - - xmlNodePtr childNode = node->xmlChildrenNode; - - while (childNode != NULL) { - - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; + do { + if (!CheckNodeName("token")) { continue; } + string attributeName = "name"; + string tokenName = ""; - if (subView->ValidViewElement((const char*)childNode->name)) { - xmlAttrPtr attr = childNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, childNode, attribs, true); - ParseViewElement(childNode->name, childNode->xmlChildrenNode, attribs, subView); - } else if (subView->ValidViewList((const char*)childNode->name)) { - ParseViewList(childNode, subView); - } else if (!xmlStrcmp(childNode->name, (const xmlChar *) "tab")) { - ParseViewTab(childNode, subView); - } else { - return false; - } - - childNode = childNode->next; - } - - - - return true; - -} - -void cXmlParser::ParseViewElement(const xmlChar * viewElement, xmlNodePtr node, vector<pair<string, string> > &attributes, cTemplateView *subView) { - if (!node) - return; - - if (!view) - return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + if (!GetAttribute(attributeName, tokenName)) continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "area") && xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - esyslog("skindesigner: invalid tag \"%s\"", node->name); - node = node->next; + if (!LevelDown()) continue; - } - - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - - cTemplatePixmap *pix = new cTemplatePixmap(); - if (!xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - pix->SetParameters(attribs); - ParseFunctionCalls(node->xmlChildrenNode, pix); - if (subView) - subView->AddPixmap((const char*)viewElement, pix, attributes); - else - view->AddPixmap((const char*)viewElement, pix, attributes); - - node = node->next; - } -} - -void cXmlParser::ParseViewList(xmlNodePtr parentNode, cTemplateView *subView) { - if (!parentNode || !view) - return; - - xmlAttrPtr attr = parentNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, parentNode, attribs); - - cTemplateViewList *viewList = new cTemplateViewList(); - viewList->SetGlobals(globals); - viewList->SetParameters(attribs); - xmlNodePtr node = parentNode->xmlChildrenNode; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - - if (!xmlStrcmp(node->name, (const xmlChar *) "currentelement")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) + stringmap tokenTranslations; + do { + if (!CheckNodeName("trans")) { continue; - cTemplateViewElement *currentElement = new cTemplateViewElement(); - xmlAttrPtr attrCur = node->properties; - vector<pair<string, string> > attribsCur; - ParseAttributes(attrCur, node, attribsCur); - currentElement->SetGlobals(globals); - currentElement->SetParameters(attribsCur); - while (childNode != NULL) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } - if ((!xmlStrcmp(childNode->name, (const xmlChar *) "area")) || (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll"))) { - xmlAttrPtr attrPix = childNode->properties; - vector<pair<string, string> > attribsPix; - ParseAttributes(attrPix, childNode, attribsPix); - cTemplatePixmap *pix = new cTemplatePixmap(); - pix->SetParameters(attribsPix); - ParseFunctionCalls(childNode->xmlChildrenNode, pix); - if (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - currentElement->AddPixmap(pix); - } - childNode = childNode->next; } - viewList->AddCurrentElement(currentElement); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "listelement")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) + string attributeName = "lang"; + string language = ""; + if (!GetAttribute(attributeName, language)) continue; - cTemplateViewElement *listElement = new cTemplateViewElement(); - xmlAttrPtr attrList = node->properties; - vector<pair<string, string> > attribsList; - ParseAttributes(attrList, node, attribsList); - listElement->SetGlobals(globals); - listElement->SetParameters(attribsList); - while (childNode != NULL) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } - if ((!xmlStrcmp(childNode->name, (const xmlChar *) "area")) || (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll"))) { - xmlAttrPtr attrPix = childNode->properties; - vector<pair<string, string> > attribsPix; - ParseAttributes(attrPix, childNode, attribsPix); - cTemplatePixmap *pix = new cTemplatePixmap(); - pix->SetParameters(attribsPix); - ParseFunctionCalls(childNode->xmlChildrenNode, pix); - if (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - listElement->AddPixmap(pix); - } - childNode = childNode->next; - } - viewList->AddListElement(listElement); - } else { - node = node->next; - continue; - } - node = node->next; - } - if (subView) - subView->AddViewList((const char*)parentNode->name, viewList); - else - view->AddViewList((const char*)parentNode->name, viewList); -} - -void cXmlParser::ParseViewTab(xmlNodePtr parentNode, cTemplateView *subView) { - if (!parentNode || !view || !subView) - return; - - xmlAttrPtr attr = parentNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, parentNode, attribs); - - cTemplateViewTab *viewTab = new cTemplateViewTab(); - viewTab->SetGlobals(globals); - viewTab->SetParameters(attribs); - viewTab->SetScrolling(); - xmlNodePtr node = parentNode->xmlChildrenNode; - ParseFunctionCalls(node, viewTab); - - subView->AddViewTab(viewTab); -} - -void cXmlParser::ParseGrid(xmlNodePtr node, vector<pair<string, string> > &attributes) { - if (!node) - return; - - if (!view) - return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } + string translation = ""; + if (!GetNodeValue(translation)) + continue; + tokenTranslations.insert(stringpair(language, translation)); + } while (NextNode()); + LevelUp(); - if (xmlStrcmp(node->name, (const xmlChar *) "area") && xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - esyslog("skindesigner: invalid tag \"%s\"", node->name); - node = node->next; - continue; + if (globals) { + globals->AddTranslation(tokenName, tokenTranslations); + } else if (skinSetup) { + skinSetup->SetTranslation(tokenName, tokenTranslations); } - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - - cTemplatePixmap *pix = new cTemplatePixmap(); - if (!xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - pix->SetParameters(attribs); - ParseFunctionCalls(node->xmlChildrenNode, pix); - view->AddPixmapGrid(pix, attributes); - - node = node->next; - } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseFunctionCalls(xmlNodePtr node, cTemplatePixmap *pix) { - if (!node) +void cXmlParser::ParseSetupMenu(void) { + if (!skinSetup) return; - - if (!view) + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - - if (!xmlStrcmp(node->name, (const xmlChar *) "loop")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) - continue; - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - cTemplateLoopFunction *loopFunc = new cTemplateLoopFunction(); - loopFunc->SetParameters(attribs); - ParseLoopFunctionCalls(childNode, loopFunc); - pix->AddLoopFunction(loopFunc); - node = node->next; - } else if (view->ValidFunction((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - pix->AddFunction((const char*)node->name, attribs); - node = node->next; - } else { - node = node->next; - continue; + do { + if (CheckNodeName("parameter")) { + ParseSetupParameter(); + } else if (CheckNodeName("submenu")) { + string attributeName = "name"; + string subMenuName = ""; + string attributeDisplayText = "displaytext"; + string subDisplayText = ""; + GetAttribute(attributeName, subMenuName); + GetAttribute(attributeDisplayText, subDisplayText); + skinSetup->SetSubMenu(subMenuName, subDisplayText); + ParseSetupMenu(); } - - } + } while (NextNode()); + skinSetup->SubMenuDone(); + LevelUp(); } -void cXmlParser::ParseLoopFunctionCalls(xmlNodePtr node, cTemplateLoopFunction *loopFunc) { - if (!node) - return; - - if (!view) +void cXmlParser::ParseSetupParameter(void) { + if (!skinSetup) return; + string attributeType = "type"; + string paramType = ""; + string attributeName = "name"; + string paramName = ""; + string attributeDisplayText = "displaytext"; + string paramDisplayText = ""; + string attributeMin = "min"; + string paramMin = ""; + string attributeMax = "max"; + string paramMax = ""; + string paramValue = ""; + + GetAttribute(attributeType, paramType); + GetAttribute(attributeName, paramName); + GetAttribute(attributeDisplayText, paramDisplayText); + GetAttribute(attributeMin, paramMin); + GetAttribute(attributeMax, paramMax); + GetNodeValue(paramValue); - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (view->ValidFunction((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - loopFunc->AddFunction((const char*)node->name, attribs); - node = node->next; - } else { - node = node->next; - continue; - } - - } + skinSetup->SetParameter(paramType, paramName, paramDisplayText, paramMin, paramMax, paramValue); } -bool cXmlParser::ParseAttributes(xmlAttrPtr attr, xmlNodePtr node, vector<pair<string, string> > &attribs, bool isViewElement) { - if (attr == NULL) { - return false; - } - - if (!view) - return false; - - while (NULL != attr) { - - string name = (const char*)attr->name; - xmlChar *value = NULL; - value = xmlGetProp(node, attr->name); - if (!view->ValidAttribute(isViewElement ? "viewelement" : (const char*)node->name, (const char*)attr->name)) { - esyslog("skindesigner: unknown attribute %s in %s", (const char*)attr->name, (const char*)node->name); - attr = attr->next; - if (value) - xmlFree(value); - continue; +void cXmlParser::ValidateAttributes(const char *nodeName, vector<stringpair> &attributes) { + bool repeat = true; + while (repeat) { + repeat = false; + for (vector<stringpair>::iterator it = attributes.begin(); it != attributes.end(); it++) { + string attributeName = (*it).first; + if (!view->ValidAttribute(nodeName, attributeName.c_str())) { + attributes.erase(it); + repeat = true; + break; + } } - if (value) - attribs.push_back(pair<string, string>((const char*)attr->name, (const char*)value)); - attr = attr->next; - if (value) - xmlFree(value); } - return true; } -void cXmlParser::InitLibXML() { - xmlInitParser(); +string cXmlParser::GetPath(string xmlFile) { + string activeSkin = Setup.OSDSkin; + string activeTheme = Setup.OSDTheme; + string path = ""; + if (!xmlFile.compare("globals.xml")) { + path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); + } else if (!xmlFile.compare("theme.xml")) { + path = *cString::sprintf("%s%s/themes/%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), activeTheme.c_str(), xmlFile.c_str()); + } else if (!xmlFile.compare("setup.xml")) { + path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); + } else { + path = *cString::sprintf("%s%s/xmlfiles/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str()); + } + return path; } -void cXmlParser::CleanupLibXML() { - xmlCleanupParser(); -} |
