summaryrefslogtreecommitdiff
path: root/libtemplate
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2015-01-19 09:23:15 +0100
committerlouis <louis.braun@gmx.de>2015-01-19 09:23:15 +0100
commitac89503027f048d0fa34234ed5ac62725f3f68e4 (patch)
tree949b4bfa1af33571b746d86e636d3994fed5261a /libtemplate
parentcb9044e5f6613d69db26bd0e81575db9c0ff5a25 (diff)
downloadvdr-plugin-skindesigner-ac89503027f048d0fa34234ed5ac62725f3f68e4.tar.gz
vdr-plugin-skindesigner-ac89503027f048d0fa34234ed5ac62725f3f68e4.tar.bz2
introducing skin setups
Diffstat (limited to 'libtemplate')
-rw-r--r--libtemplate/globals.c2
-rw-r--r--libtemplate/xmlparser.c127
-rw-r--r--libtemplate/xmlparser.h5
3 files changed, 133 insertions, 1 deletions
diff --git a/libtemplate/globals.c b/libtemplate/globals.c
index 1896e7c..4faa710 100644
--- a/libtemplate/globals.c
+++ b/libtemplate/globals.c
@@ -11,7 +11,7 @@ cGlobals::cGlobals(void) {
}
bool cGlobals::ReadFromXML(void) {
- std::string xmlFile = "globals.xml";
+ string xmlFile = "globals.xml";
cXmlParser parser;
if (!parser.ReadGlobals(this, xmlFile))
return false;
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;
diff --git a/libtemplate/xmlparser.h b/libtemplate/xmlparser.h
index 5ff829f..0369622 100644
--- a/libtemplate/xmlparser.h
+++ b/libtemplate/xmlparser.h
@@ -16,6 +16,7 @@
#include "templateview.h"
#include "templateviewlist.h"
#include "templateviewtab.h"
+#include "../libcore/skinsetup.h"
using namespace std;
@@ -25,10 +26,12 @@ class cXmlParser {
private:
cTemplateView *view;
cGlobals *globals;
+ cSkinSetup *skinSetup;
xmlParserCtxtPtr ctxt;
xmlDocPtr doc;
xmlNodePtr root;
string GetPath(string xmlFile);
+ void ParseSetupParameter(xmlNodePtr node);
void ParseGlobalColors(xmlNodePtr node);
void InsertColor(string name, string value);
void ParseGlobalVariables(xmlNodePtr node);
@@ -48,9 +51,11 @@ public:
bool ReadView(cTemplateView *view, string xmlFile);
bool ReadPluginView(string plugName, int templateNumber, string templateName);
bool ReadGlobals(cGlobals *globals, string xmlFile);
+ bool ReadSkinSetup(cSkinSetup *skinSetup, string skin, string xmlFile);
bool ParseView(void);
bool ParsePluginView(string plugName, int templateNumber);
bool ParseGlobals(void);
+ bool ParseSkinSetup(string skin);
void DeleteDocument(void);
static void InitLibXML();
static void CleanupLibXML();