introducing skin setups

This commit is contained in:
louis
2015-01-19 09:23:15 +01:00
parent cb9044e5f6
commit ac89503027
14 changed files with 325 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();