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

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

View File

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

View File

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

View File

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

14
dtd/setup.dtd Normal file
View File

@ -0,0 +1,14 @@
<?xml encoding="UTF-8"?>
<!ELEMENT setup (parameters)>
<!ELEMENT parameters (parameter)*>
<!ELEMENT parameter (#PCDATA)>
<!ATTLIST parameter
name NMTOKEN #REQUIRED
type (int|bool) #REQUIRED
min NMTOKEN #IMPLIED
max NMTOKEN #IMPLIED
displaytext CDATA #REQUIRED
>

55
libcore/skinsetup.c Normal file
View File

@ -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<cSkinSetupParameter>::iterator p = parameters.begin(); p != parameters.end(); p++)
p->Debug();
}

29
libcore/skinsetup.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef __SKINSETUP_H
#define __SKINSETUP_H
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <vdr/plugin.h>
#include <libxml/xmlstring.h>
#include "skinsetupparameter.h"
using namespace std;
// --- cSkinSetup -----------------------------------------------------------
class cSkinSetup {
private:
string skin;
vector<cSkinSetupParameter> 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

View File

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

View File

@ -0,0 +1,31 @@
#ifndef __SKINSETUPPARAMETER_H
#define __SKINSETUPPARAMETER_H
#include <string>
#include <vdr/plugin.h>
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

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

View File

@ -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) {

19
skins/blackhole/setup.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE setup SYSTEM "../../dtd/setup.dtd">
<setup>
<!--
define all your parameters here which should be configurable via
OSD and the skindesigner setup menu.
Parameters must have type "bool" or "integer". For "bool" Parameters
a choice yes/no is shown in the setup menu, a "integer" parameter
can be configured to a value between "min" and "max". If "min" is not
set, "0" is the minimum, if "max" is not set, "1000" is maximum.
"displayname" is used to display the option in the setup menu.
-->
<parameters>
<parameter type="bool" name="showsignal" displaytext="Show Signalstrength and -quality when switching channel">0</parameter>
<parameter type="bool" name="showposter" displaytext="Show Poster when switching channel">1</parameter>
<parameter type="int" name="fadetime" min="0" max="1000" displaytext="Fade In and Out time in ms">300</parameter>
</parameters>
</setup>