diff options
| author | louis <louis.braun@gmx.de> | 2015-01-19 09:23:15 +0100 |
|---|---|---|
| committer | louis <louis.braun@gmx.de> | 2015-01-19 09:23:15 +0100 |
| commit | ac89503027f048d0fa34234ed5ac62725f3f68e4 (patch) | |
| tree | 949b4bfa1af33571b746d86e636d3994fed5261a /libtemplate/xmlparser.c | |
| parent | cb9044e5f6613d69db26bd0e81575db9c0ff5a25 (diff) | |
| download | vdr-plugin-skindesigner-ac89503027f048d0fa34234ed5ac62725f3f68e4.tar.gz vdr-plugin-skindesigner-ac89503027f048d0fa34234ed5ac62725f3f68e4.tar.bz2 | |
introducing skin setups
Diffstat (limited to 'libtemplate/xmlparser.c')
| -rw-r--r-- | libtemplate/xmlparser.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index ce39dcc..dd93a0d 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -12,6 +12,8 @@ cXmlParser::cXmlParser(void) { doc = NULL; root = NULL; ctxt = NULL; + globals = NULL; + skinSetup = NULL; initGenericErrorDefaultFunc(NULL); xmlSetStructuredErrorFunc(NULL, SkinDesignerXMLErrorHandler); @@ -122,6 +124,47 @@ bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile) { return true; } +bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string skin, string xmlFile) { + this->skinSetup = skinSetup; + string xmlPath = *cString::sprintf("%s%s/%s", *config.skinPath, skin.c_str(), xmlFile.c_str()); + + esyslog("skindesigner: reading skin setup %s", xmlPath.c_str()); + + if (!FileExists(xmlPath)) + 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); + + if (doc == NULL ) { + esyslog("skindesigner: ERROR: skin setup %s not parsed successfully.", xmlPath.c_str()); + return false; + } + + root = xmlDocGetRootElement(doc); + + if (ctxt->valid == 0) { + esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + return false; + } + + if (root == NULL) { + esyslog("skindesigner: ERROR: Skin Setup %s is empty", xmlPath.c_str()); + return false; + } + + if (xmlStrcmp(root->name, (const xmlChar *) "setup")) { + return false; + } + + return true; +} + + bool cXmlParser::ParseView(void) { vector<pair<string, string> > rootAttribs; ParseAttributes(root->properties, root, rootAttribs); @@ -227,6 +270,28 @@ bool cXmlParser::ParseGlobals(void) { } +bool cXmlParser::ParseSkinSetup(string skin) { + esyslog("skindesigner: parsing skinsetup from %s", skin.c_str()); + + xmlNodePtr node = root->xmlChildrenNode; + + while (node != NULL) { + if (node->type != XML_ELEMENT_NODE) { + node = node->next; + continue; + } + if (!xmlStrcmp(node->name, (const xmlChar *) "parameters")) { + ParseSetupParameter(node->xmlChildrenNode); + node = node->next; + continue; + } + node = node->next; + } + + return true; + +} + void cXmlParser::DeleteDocument(void) { if (doc) { xmlFreeDoc(doc); @@ -244,12 +309,74 @@ string cXmlParser::GetPath(string xmlFile) { string path = ""; if (!xmlFile.compare("globals.xml")) { path = *cString::sprintf("%s%s/themes/%s/%s", *config.skinPath, activeSkin.c_str(), activeTheme.c_str(), xmlFile.c_str()); + } else if (!xmlFile.compare("setup.xml")) { + path = *cString::sprintf("%s%s/%s", *config.skinPath, activeSkin.c_str(), xmlFile.c_str()); } else { path = *cString::sprintf("%s%s/xmlfiles/%s", *config.skinPath, activeSkin.c_str(), xmlFile.c_str()); } return path; } +void cXmlParser::ParseSetupParameter(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); + } + 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); + node = node->next; + } +} + void cXmlParser::ParseGlobalColors(xmlNodePtr node) { if (!node) return; |
