diff options
author | louis <louis.braun@gmx.de> | 2015-01-31 11:59:36 +0100 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-01-31 11:59:36 +0100 |
commit | 0341add15e210d2a2da18753bda07b92430fcbf9 (patch) | |
tree | a0dc85fee2c22e4f7e64d5020d249cd2316fcf43 /libtemplate/xmlparser.c | |
parent | 796ce8e5873f3bb55bec8db2b1ee6b5a857e304d (diff) | |
parent | d446ce0d0faa56aea7ef50c4762c2e532494adcb (diff) | |
download | vdr-plugin-skindesigner-0341add15e210d2a2da18753bda07b92430fcbf9.tar.gz vdr-plugin-skindesigner-0341add15e210d2a2da18753bda07b92430fcbf9.tar.bz2 |
Merge branch 'master' into plugininterface
Diffstat (limited to 'libtemplate/xmlparser.c')
-rw-r--r-- | libtemplate/xmlparser.c | 127 |
1 files changed, 75 insertions, 52 deletions
diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index 8df22e8..0162780 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -135,28 +135,27 @@ bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile, bool mandatory) return true; } -bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string skin, string xmlFile) { +bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile) { this->skinSetup = skinSetup; - string xmlPath = *cString::sprintf("%s%s/%s", *config.skinPath, skin.c_str(), xmlFile.c_str()); - if (!FileExists(xmlPath)) + if (!FileExists(xmlFile)) return false; if (ctxt == NULL) { esyslog("skindesigner: Failed to allocate parser context"); return false; } - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); + 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.", xmlPath.c_str()); + esyslog("skindesigner: ERROR: skin setup %s not parsed successfully.", xmlFile.c_str()); return false; } root = xmlDocGetRootElement(doc); if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + esyslog("skindesigner: Failed to validate %s", xmlFile.c_str()); return false; } if (root == NULL) { @@ -282,8 +281,8 @@ bool cXmlParser::ParseSkinSetup(string skin) { node = node->next; continue; } - if (!xmlStrcmp(node->name, (const xmlChar *) "parameters")) { - ParseSetupParameter(node->xmlChildrenNode); + if (!xmlStrcmp(node->name, (const xmlChar *) "menu")) { + ParseSetupMenu(node->xmlChildrenNode); node = node->next; continue; } else if (!xmlStrcmp(node->name, (const xmlChar *) "translations")) { @@ -325,64 +324,88 @@ string cXmlParser::GetPath(string xmlFile) { return path; } -void cXmlParser::ParseSetupParameter(xmlNodePtr node) { +void cXmlParser::ParseSetupMenu(xmlNodePtr node) { if (!node) return; if (!skinSetup) return; while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { node = node->next; continue; } - if (xmlStrcmp(node->name, (const xmlChar *) "parameter")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; - continue; - } - 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); + + 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; } - attr = attr->next; + skinSetup->SetSubMenu(subMenuName, subDisplayText); + ParseSetupMenu(node->xmlChildrenNode); + if (subMenuName) + xmlFree(subMenuName); + if (subDisplayText) + xmlFree(subDisplayText); } - 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); node = node->next; } + skinSetup->SubMenuDone(); +} + +void cXmlParser::ParseSetupParameter(xmlNodePtr node) { + if (!node) + return; + if (!skinSetup) + return; + + xmlAttrPtr attr = node->properties; + if (attr == NULL) { + 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); } void cXmlParser::ParseGlobalColors(xmlNodePtr node) { |