From ac89503027f048d0fa34234ed5ac62725f3f68e4 Mon Sep 17 00:00:00 2001 From: louis Date: Mon, 19 Jan 2015 09:23:15 +0100 Subject: [PATCH] introducing skin setups --- Makefile | 2 + config.c | 7 ++ config.h | 2 + designer.c | 8 +++ dtd/setup.dtd | 14 ++++ libcore/skinsetup.c | 55 +++++++++++++++ libcore/skinsetup.h | 29 ++++++++ libcore/skinsetupparameter.c | 24 +++++++ libcore/skinsetupparameter.h | 31 +++++++++ libtemplate/globals.c | 2 +- libtemplate/xmlparser.c | 127 +++++++++++++++++++++++++++++++++++ libtemplate/xmlparser.h | 5 ++ skindesigner.c | 1 + skins/blackhole/setup.xml | 19 ++++++ 14 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 dtd/setup.dtd create mode 100644 libcore/skinsetup.c create mode 100644 libcore/skinsetup.h create mode 100644 libcore/skinsetupparameter.c create mode 100644 libcore/skinsetupparameter.h create mode 100644 skins/blackhole/setup.xml diff --git a/Makefile b/Makefile index f77edb1..a43351a 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,8 @@ OBJS = $(PLUGIN).o \ libcore/helpers.o \ libcore/imageloader.o \ libcore/recfolderinfo.o \ + libcore/skinsetupparameter.o \ + libcore/skinsetup.o \ libcore/extrecinfo.o \ libcore/timers.o \ libtemplate/globals.o \ diff --git a/config.c b/config.c index 5f8e55a..4ddb618 100644 --- a/config.c +++ b/config.c @@ -27,6 +27,7 @@ cDesignerConfig::cDesignerConfig() { } cDesignerConfig::~cDesignerConfig() { + esyslog("skindesigner: config destruktor"); } void cDesignerConfig::SetPathes(void) { @@ -75,6 +76,12 @@ void cDesignerConfig::ReadSkins(void) { dsyslog("skindesigner %ld skins found in %s", skins.size(), *skinPath); } +void cDesignerConfig::ReadSkinSetup(string skin) { + cSkinSetup *skinSetup = new cSkinSetup(skin); + skinSetup->ReadFromXML(); + skinSetup->Debug(); +} + bool cDesignerConfig::GetSkin(string &skin) { if (skinIterator == skins.end()) { return false; diff --git a/config.h b/config.h index b4e5020..1e1b2e9 100644 --- a/config.h +++ b/config.h @@ -10,6 +10,7 @@ #include "libcore/fontmanager.h" #include "libcore/imagecache.h" #include "libcore/recfolderinfo.h" +#include "libcore/skinsetup.h" #define SCRIPTOUTPUTPATH "/tmp/skindesigner" @@ -37,6 +38,7 @@ public: void SetLogoPath(cString path); void SetEpgImagePath(cString path); void ReadSkins(void); + void ReadSkinSetup(string skin); void InitSkinIterator(void) { skinIterator = skins.begin(); }; bool GetSkin(string &skin); void CheckDecimalPoint(void); diff --git a/designer.c b/designer.c index 68112ec..7630d79 100644 --- a/designer.c +++ b/designer.c @@ -263,6 +263,14 @@ bool cSkinDesigner::LoadTemplates(void) { return false; } +/* + cSkinSetup *skinSetups = new cSkinSetup(); + config.InitSkinIterator(); + string skin = ""; + while (config.GetSkin(skin)) { + skinSetups->ReadFromXML(skin); + } +*/ DeleteTemplates(); channelTemplate = new cTemplate(vtDisplayChannel); diff --git a/dtd/setup.dtd b/dtd/setup.dtd new file mode 100644 index 0000000..81a801b --- /dev/null +++ b/dtd/setup.dtd @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/libcore/skinsetup.c b/libcore/skinsetup.c new file mode 100644 index 0000000..c01f2d7 --- /dev/null +++ b/libcore/skinsetup.c @@ -0,0 +1,55 @@ +#include "skinsetup.h" +#include "../libtemplate/xmlparser.h" + +cSkinSetup::cSkinSetup(string skin) { + this->skin = skin; +} + +void cSkinSetup::ReadFromXML(void) { + esyslog("skindesigner: reading setup for skin %s", skin.c_str()); + string xmlFile = "setup.xml"; + cXmlParser parser; + if (!parser.ReadSkinSetup(this, skin, xmlFile)) { + esyslog("skindesigner: no setup file for skin %s found", skin.c_str()); + return; + } + parser.ParseSkinSetup(skin); +} + +void cSkinSetup::SetParameter(xmlChar *type, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value) { + if (!type || !name || !displayText || !value) { + esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); + return; + } + eSetupParameterType paramType = sptUnknown; + if (!xmlStrcmp(type, (const xmlChar *) "int")) { + paramType = sptInt; + } else if (!xmlStrcmp(type, (const xmlChar *) "bool")) { + paramType = sptBool; + } + if (paramType == sptUnknown) { + esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); + return; + } + cSkinSetupParameter param; + param.type = paramType; + param.name = (const char*)name; + param.displayText = (const char*)displayText; + + if (min && paramType == sptInt) { + param.min = atoi((const char*)min); + } + if (max && paramType == sptInt) { + param.max = atoi((const char*)max); + } + param.value = atoi((const char*)value); + + parameters.push_back(param); +} + + +void cSkinSetup::Debug(void) { + dsyslog("skindesigner: Skin \"%s\" Setup Parameters", skin.c_str()); + for (vector::iterator p = parameters.begin(); p != parameters.end(); p++) + p->Debug(); +} diff --git a/libcore/skinsetup.h b/libcore/skinsetup.h new file mode 100644 index 0000000..4f8a93c --- /dev/null +++ b/libcore/skinsetup.h @@ -0,0 +1,29 @@ +#ifndef __SKINSETUP_H +#define __SKINSETUP_H + +#include +#include +#include +#include +#include +#include +#include +#include "skinsetupparameter.h" + +using namespace std; + +// --- cSkinSetup ----------------------------------------------------------- + +class cSkinSetup { +private: + string skin; + vector parameters; +public: + cSkinSetup(string skin); + virtual ~cSkinSetup(void) {}; + void ReadFromXML(void); + void SetParameter(xmlChar *type, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value); + void Debug(void); +}; + +#endif //__SKINSETUP_H \ No newline at end of file diff --git a/libcore/skinsetupparameter.c b/libcore/skinsetupparameter.c new file mode 100644 index 0000000..6f142f6 --- /dev/null +++ b/libcore/skinsetupparameter.c @@ -0,0 +1,24 @@ +#include "skinsetupparameter.h" + +cSkinSetupParameter::cSkinSetupParameter(void) { + type = sptUnknown; + name = ""; + displayText = ""; + min = 0; + max = 1000; + value = 0; +} + +void cSkinSetupParameter::Debug(void) { + if (type == sptBool) + dsyslog("skindesigner: type bool"); + else if (type == sptInt) + dsyslog("skindesigner: type integer"); + else + dsyslog("skindesigner: type UNKNOWN"); + dsyslog("skindesigner: name %s", name.c_str()); + dsyslog("skindesigner: displayText %s", displayText.c_str()); + if (type == sptInt) + dsyslog("skindesigner: min %d, max %d", min, max); + dsyslog("skindesigner: Value %d", value); +} \ No newline at end of file diff --git a/libcore/skinsetupparameter.h b/libcore/skinsetupparameter.h new file mode 100644 index 0000000..d038159 --- /dev/null +++ b/libcore/skinsetupparameter.h @@ -0,0 +1,31 @@ +#ifndef __SKINSETUPPARAMETER_H +#define __SKINSETUPPARAMETER_H + +#include +#include + +using namespace std; + +enum eSetupParameterType { + sptInt, + sptBool, + sptUnknown +}; + +// --- cSkinSetupParameter ----------------------------------------------------------- + +class cSkinSetupParameter { +private: +public: + cSkinSetupParameter(void); + virtual ~cSkinSetupParameter(void) {}; + eSetupParameterType type; + string name; + string displayText; + int min; + int max; + int value; + void Debug(void); +}; + +#endif //__SKINSETUPPARAMETER_H \ No newline at end of file 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 > 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(); diff --git a/skindesigner.c b/skindesigner.c index 3b10108..b416a87 100644 --- a/skindesigner.c +++ b/skindesigner.c @@ -108,6 +108,7 @@ bool cPluginSkinDesigner::Start(void) { config.InitSkinIterator(); string skin = ""; while (config.GetSkin(skin)) { + config.ReadSkinSetup(skin); cSkinDesigner *newSkin = new cSkinDesigner(skin); skins.push_back(newSkin); if (!trueColorAvailable) { diff --git a/skins/blackhole/setup.xml b/skins/blackhole/setup.xml new file mode 100644 index 0000000..c75e183 --- /dev/null +++ b/skins/blackhole/setup.xml @@ -0,0 +1,19 @@ + + + + + + + 0 + 1 + 300 + +