2014-09-27 09:25:14 +02:00
|
|
|
#include "xmlparser.h"
|
|
|
|
#include "../config.h"
|
2014-11-15 09:47:22 +01:00
|
|
|
#include "../libcore/helpers.h"
|
2014-09-27 09:25:14 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
cXmlParser::cXmlParser(void) {
|
2015-01-27 17:30:24 +01:00
|
|
|
view = NULL;
|
2015-01-19 09:23:15 +01:00
|
|
|
globals = NULL;
|
|
|
|
skinSetup = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cXmlParser::~cXmlParser() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* PUBLIC Functions
|
|
|
|
*********************************************************************/
|
|
|
|
bool cXmlParser::ReadView(cTemplateView *view, string xmlFile) {
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
2014-09-27 09:25:14 +02:00
|
|
|
this->view = view;
|
|
|
|
string xmlPath = GetPath(xmlFile);
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! ReadXMLFile(xmlPath.c_str()) )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! Validate() )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! SetDocument() )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! CheckNodeName(view->GetViewName()) )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ParseView(void) {
|
|
|
|
if (!view)
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
vector<stringpair> rootAttribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), rootAttribs);
|
|
|
|
view->SetParameters(rootAttribs);
|
|
|
|
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
if (view->ValidSubView(NodeName())) {
|
|
|
|
ParseSubView();
|
|
|
|
} else if (view->ValidViewElement(NodeName())) {
|
|
|
|
ParseViewElement();
|
|
|
|
} else if (view->ValidViewList(NodeName())) {
|
|
|
|
ParseViewList();
|
|
|
|
} else if (view->ValidViewGrid(NodeName())) {
|
|
|
|
ParseGrid();
|
|
|
|
} else if (CheckNodeName("tab")) {
|
|
|
|
ParseViewTab(view);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (NextNode());
|
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
return true;
|
2015-07-07 17:58:10 +02:00
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2014-11-15 09:47:22 +01:00
|
|
|
bool cXmlParser::ReadPluginView(string plugName, int templateNumber, string templateName) {
|
|
|
|
string xmlPath = GetPath(templateName);
|
|
|
|
DeleteDocument();
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! ReadXMLFile(xmlPath.c_str()) )
|
2014-11-15 09:47:22 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! Validate() )
|
2014-11-15 09:47:22 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! SetDocument() )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ParsePluginView(string plugName, int templateNumber) {
|
|
|
|
cTemplateView *plugView = new cTemplateViewMenu();
|
|
|
|
view->AddPluginView(plugName, templateNumber, plugView);
|
|
|
|
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
|
|
|
plugView->SetParameters(attribs);
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
2014-11-15 09:47:22 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
|
|
|
|
if (plugView->ValidViewElement(NodeName())) {
|
|
|
|
ParseViewElement(plugView);
|
|
|
|
} else if (plugView->ValidViewList(NodeName())) {
|
|
|
|
ParseViewList(plugView);
|
|
|
|
} else if (CheckNodeName("tab")) {
|
|
|
|
ParseViewTab(plugView);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (NextNode());
|
2014-11-15 09:47:22 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile) {
|
2014-09-27 09:25:14 +02:00
|
|
|
this->globals = globals;
|
|
|
|
string xmlPath = GetPath(xmlFile);
|
2015-07-07 17:58:10 +02:00
|
|
|
DeleteDocument();
|
|
|
|
if (! ReadXMLFile(xmlPath.c_str()) )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! Validate() )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! SetDocument() )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! CheckNodeName("globals") )
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ParseGlobals(void) {
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (CheckNodeName("colors")) {
|
|
|
|
ParseGlobalColors();
|
|
|
|
} else if (CheckNodeName("variables")) {
|
|
|
|
ParseGlobalVariables();
|
|
|
|
} else if (CheckNodeName("fonts")) {
|
|
|
|
ParseGlobalFonts();
|
|
|
|
} else if (CheckNodeName("translations")) {
|
|
|
|
ParseTranslations();
|
|
|
|
}
|
|
|
|
} while (NextNode());
|
2014-09-27 09:25:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-31 11:46:06 +01:00
|
|
|
bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile) {
|
2015-01-19 09:23:15 +01:00
|
|
|
this->skinSetup = skinSetup;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! ReadXMLFile(xmlFile.c_str()) )
|
2015-01-19 09:23:15 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! Validate() )
|
2015-01-19 09:23:15 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! SetDocument() )
|
2015-01-19 09:23:15 +01:00
|
|
|
return false;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (! CheckNodeName("setup") )
|
2015-01-19 09:23:15 +01:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ParseSkinSetup(string skin) {
|
|
|
|
if (!LevelDown())
|
|
|
|
return false;
|
|
|
|
do {
|
|
|
|
if (CheckNodeName("menu")) {
|
|
|
|
ParseSetupMenu();
|
|
|
|
} else if (CheckNodeName("translations")) {
|
|
|
|
ParseTranslations();
|
|
|
|
}
|
|
|
|
} while (NextNode());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/*********************************************************************
|
|
|
|
* PRIVATE Functions
|
|
|
|
*********************************************************************/
|
2015-01-19 09:23:15 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
bool cXmlParser::ParseSubView(void) {
|
2014-09-27 09:25:14 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplateView *subView = new cTemplateViewMenu();
|
|
|
|
view->AddSubView(NodeName(), subView);
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
vector<pair<string, string> > subViewAttribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), subViewAttribs);
|
|
|
|
subView->SetParameters(subViewAttribs);
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
|
|
|
return false;
|
|
|
|
do {
|
|
|
|
|
|
|
|
if (subView->ValidViewElement(NodeName())) {
|
|
|
|
ParseViewElement(subView);
|
|
|
|
} else if (subView->ValidViewList(NodeName())) {
|
|
|
|
ParseViewList(subView);
|
|
|
|
} else if (CheckNodeName("tab")) {
|
|
|
|
ParseViewTab(subView);
|
2014-09-27 09:25:14 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2014-09-27 09:25:14 +02:00
|
|
|
return true;
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
}
|
|
|
|
void cXmlParser::ParseViewElement(cTemplateView *subView) {
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
2015-08-08 11:04:15 +02:00
|
|
|
const char *viewElementName = NodeName();
|
2015-07-07 17:58:10 +02:00
|
|
|
vector<stringpair> attributes = ParseAttributes();
|
|
|
|
ValidateAttributes("viewelement", attributes);
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
|
|
|
return;
|
2015-08-08 11:04:15 +02:00
|
|
|
|
|
|
|
cTemplateViewElement *viewElement = new cTemplateViewElement();
|
|
|
|
viewElement->SetParameters(attributes);
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) {
|
|
|
|
esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cTemplatePixmapNode *pix = NULL;
|
|
|
|
if (CheckNodeName("area") || CheckNodeName("areascroll")) {
|
|
|
|
pix = ParseArea();
|
|
|
|
} else {
|
|
|
|
pix = ParseAreaContainer();
|
|
|
|
}
|
2015-08-08 11:04:15 +02:00
|
|
|
pix->SetGlobals(globals);
|
|
|
|
viewElement->AddPixmap(pix);
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-08-08 11:04:15 +02:00
|
|
|
|
|
|
|
if (subView)
|
|
|
|
subView->AddViewElement(viewElementName, viewElement);
|
|
|
|
else
|
|
|
|
view->AddViewElement(viewElementName, viewElement);
|
2015-07-07 17:58:10 +02:00
|
|
|
}
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseViewList(cTemplateView *subView) {
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplateViewList *viewList = new cTemplateViewList();
|
|
|
|
viewList->SetGlobals(globals);
|
|
|
|
viewList->SetParameters(attribs);
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
|
|
|
return;
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (CheckNodeName("currentelement")) {
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplateViewElement *currentElement = new cTemplateViewElement();
|
|
|
|
vector<stringpair> attribsCur = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribsCur);
|
|
|
|
currentElement->SetGlobals(globals);
|
|
|
|
currentElement->SetParameters(attribsCur);
|
|
|
|
if (!LevelDown())
|
2015-07-10 15:55:49 +02:00
|
|
|
continue;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) {
|
|
|
|
esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cTemplatePixmapNode *pix = NULL;
|
|
|
|
if (CheckNodeName("area") || CheckNodeName("areascroll")) {
|
|
|
|
pix = ParseArea();
|
|
|
|
} else {
|
|
|
|
pix = ParseAreaContainer();
|
|
|
|
}
|
|
|
|
currentElement->AddPixmap(pix);
|
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
|
|
|
viewList->AddCurrentElement(currentElement);
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
} else if (CheckNodeName("listelement")) {
|
|
|
|
|
|
|
|
cTemplateViewElement *listElement = new cTemplateViewElement();
|
|
|
|
vector<stringpair> attribsList = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribsList);
|
|
|
|
listElement->SetGlobals(globals);
|
|
|
|
listElement->SetParameters(attribsList);
|
|
|
|
if (!LevelDown())
|
|
|
|
return;
|
|
|
|
do {
|
|
|
|
if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) {
|
|
|
|
esyslog("skindesigner: invalid tag \"%s\" in viewelement", NodeName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cTemplatePixmapNode *pix = NULL;
|
|
|
|
if (CheckNodeName("area") || CheckNodeName("areascroll")) {
|
|
|
|
pix = ParseArea();
|
|
|
|
} else {
|
|
|
|
pix = ParseAreaContainer();
|
|
|
|
}
|
|
|
|
listElement->AddPixmap(pix);
|
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
|
|
|
viewList->AddListElement(listElement);
|
2014-11-15 09:47:22 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2014-11-15 09:47:22 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (subView)
|
|
|
|
subView->AddViewList(NodeName(), viewList);
|
|
|
|
else
|
|
|
|
view->AddViewList(NodeName(), viewList);
|
2014-11-15 09:47:22 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseViewTab(cTemplateView *subView) {
|
|
|
|
if (!view || !subView)
|
|
|
|
return;
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplateViewTab *viewTab = new cTemplateViewTab();
|
|
|
|
viewTab->SetGlobals(globals);
|
|
|
|
viewTab->SetParameters(attribs);
|
|
|
|
viewTab->SetScrolling();
|
|
|
|
ParseFunctionCalls(viewTab);
|
|
|
|
subView->AddViewTab(viewTab);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseGrid(void) {
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vector<stringpair> attributes = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attributes);
|
|
|
|
|
|
|
|
if (!LevelDown())
|
|
|
|
return;
|
2015-08-08 11:04:15 +02:00
|
|
|
|
|
|
|
cTemplateViewGrid *viewGrid = new cTemplateViewGrid();
|
|
|
|
viewGrid->SetParameters(attributes);
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
2015-01-19 09:23:15 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) {
|
|
|
|
esyslog("skindesigner: invalid tag \"%s\" in grid", NodeName());
|
2015-01-19 09:23:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplatePixmapNode *pix = NULL;
|
|
|
|
if (CheckNodeName("area") || CheckNodeName("areascroll")) {
|
|
|
|
pix = ParseArea();
|
|
|
|
} else {
|
|
|
|
pix = ParseAreaContainer();
|
2015-01-19 09:23:15 +01:00
|
|
|
}
|
2015-08-08 11:04:15 +02:00
|
|
|
pix->SetGlobals(globals);
|
|
|
|
viewGrid->AddPixmap(pix);
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-08-08 11:04:15 +02:00
|
|
|
|
|
|
|
view->AddGrid(viewGrid);
|
2015-01-19 09:23:15 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplatePixmap *cXmlParser::ParseArea(void) {
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
|
|
|
|
|
|
|
cTemplatePixmap *pix = new cTemplatePixmap();
|
|
|
|
if (CheckNodeName("areascroll")) {
|
|
|
|
pix->SetScrolling();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
pix->SetParameters(attribs);
|
|
|
|
ParseFunctionCalls(pix);
|
|
|
|
return pix;
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplatePixmapContainer *cXmlParser::ParseAreaContainer(void) {
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
cTemplatePixmapContainer *pixContainer = new cTemplatePixmapContainer();
|
|
|
|
pixContainer->SetParameters(attribs);
|
|
|
|
|
|
|
|
if (!LevelDown())
|
|
|
|
return pixContainer;
|
|
|
|
do {
|
|
|
|
if (!CheckNodeName("area") && !CheckNodeName("areascroll")) {
|
|
|
|
esyslog("skindesigner: invalid tag \"%s\" in areacontainer", NodeName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cTemplatePixmap *pix = ParseArea();
|
|
|
|
pixContainer->AddPixmap(pix);
|
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
|
|
|
return pixContainer;
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseFunctionCalls(cTemplatePixmap *pix) {
|
|
|
|
if (!view)
|
2015-01-19 09:23:15 +01:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
2015-01-19 09:23:15 +01:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (CheckNodeName("loop")) {
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
|
|
|
cTemplateLoopFunction *loopFunc = new cTemplateLoopFunction();
|
|
|
|
loopFunc->SetParameters(attribs);
|
|
|
|
ParseLoopFunctionCalls(loopFunc);
|
|
|
|
pix->AddLoopFunction(loopFunc);
|
|
|
|
} else if (view->ValidFunction(NodeName())) {
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
|
|
|
pix->AddFunction(NodeName(), attribs);
|
2015-01-19 09:23:15 +01:00
|
|
|
}
|
2015-01-31 11:46:06 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-01-31 11:46:06 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseLoopFunctionCalls(cTemplateLoopFunction *loopFunc) {
|
|
|
|
if (!view)
|
2015-01-31 11:46:06 +01:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
2015-01-31 11:46:06 +01:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (view->ValidFunction(NodeName())) {
|
|
|
|
vector<stringpair> attribs = ParseAttributes();
|
|
|
|
ValidateAttributes(NodeName(), attribs);
|
|
|
|
loopFunc->AddFunction(NodeName(), attribs);
|
|
|
|
}
|
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-01-19 09:23:15 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseGlobalColors(void) {
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("color")) {
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeName = "name";
|
|
|
|
string colorName = "";
|
|
|
|
string colorValue = "";
|
|
|
|
bool ok = GetAttribute(attributeName, colorName);
|
2014-09-27 09:25:14 +02:00
|
|
|
if (ok) {
|
2015-07-07 17:58:10 +02:00
|
|
|
ok = GetNodeValue(colorValue);
|
|
|
|
if (ok)
|
|
|
|
InsertColor(colorName, colorValue);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cXmlParser::InsertColor(string name, string value) {
|
|
|
|
if (value.size() != 8)
|
|
|
|
return;
|
|
|
|
std::stringstream str;
|
|
|
|
str << value;
|
|
|
|
tColor colVal;
|
|
|
|
str >> std::hex >> colVal;
|
2015-01-24 10:47:47 +01:00
|
|
|
globals->AddColor(name, colVal);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseGlobalVariables(void) {
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("var")) {
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeName = "name";
|
|
|
|
string attributeType = "type";
|
|
|
|
string varName = "";
|
|
|
|
string varType = "";
|
|
|
|
string varValue = "";
|
|
|
|
|
|
|
|
bool ok1 = GetAttribute(attributeName, varName);
|
|
|
|
bool ok2 = GetAttribute(attributeType, varType);
|
|
|
|
|
|
|
|
if (ok1 && ok2) {
|
|
|
|
bool ok = GetNodeValue(varValue);
|
|
|
|
if (ok)
|
|
|
|
InsertVariable(varName, varType, varValue);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cXmlParser::InsertVariable(string name, string type, string value) {
|
|
|
|
if (!type.compare("int")) {
|
|
|
|
int val = atoi(value.c_str());
|
2015-01-24 10:47:47 +01:00
|
|
|
globals->AddInt(name, val);
|
2014-10-10 15:32:38 +02:00
|
|
|
} else if (!type.compare("double")) {
|
2015-01-24 10:47:47 +01:00
|
|
|
globals->AddDouble(name, value);
|
2014-09-27 09:25:14 +02:00
|
|
|
} else if (!type.compare("string")) {
|
2015-01-24 10:47:47 +01:00
|
|
|
globals->AddString(name, value);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseGlobalFonts(void) {
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("font")) {
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeName = "name";
|
|
|
|
string fontName = "";
|
|
|
|
string fontValue = "";
|
|
|
|
|
|
|
|
bool ok = GetAttribute(attributeName, fontName);
|
2014-09-27 09:25:14 +02:00
|
|
|
if (ok) {
|
2015-07-07 17:58:10 +02:00
|
|
|
ok = GetNodeValue(fontValue);
|
|
|
|
if (ok) {
|
|
|
|
globals->AddFont(fontName, fontValue);
|
2015-01-24 10:47:47 +01:00
|
|
|
}
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseTranslations(void) {
|
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (!CheckNodeName("token")) {
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeName = "name";
|
|
|
|
string tokenName = "";
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!GetAttribute(attributeName, tokenName))
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
stringmap tokenTranslations;
|
|
|
|
do {
|
|
|
|
if (!CheckNodeName("trans")) {
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeName = "lang";
|
|
|
|
string language = "";
|
|
|
|
if (!GetAttribute(attributeName, language))
|
2014-09-27 09:25:14 +02:00
|
|
|
continue;
|
2015-07-07 17:58:10 +02:00
|
|
|
string translation = "";
|
|
|
|
if (!GetNodeValue(translation))
|
|
|
|
continue;
|
|
|
|
tokenTranslations.insert(stringpair(language, translation));
|
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-02-12 18:50:58 +01:00
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
if (globals) {
|
|
|
|
globals->AddTranslation(tokenName, tokenTranslations);
|
|
|
|
} else if (skinSetup) {
|
|
|
|
skinSetup->SetTranslation(tokenName, tokenTranslations);
|
2015-02-12 18:50:58 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
LevelUp();
|
2015-02-12 18:50:58 +01:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseSetupMenu(void) {
|
|
|
|
if (!skinSetup)
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
if (!LevelDown())
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
do {
|
|
|
|
if (CheckNodeName("parameter")) {
|
|
|
|
ParseSetupParameter();
|
|
|
|
} else if (CheckNodeName("submenu")) {
|
|
|
|
string attributeName = "name";
|
|
|
|
string subMenuName = "";
|
|
|
|
string attributeDisplayText = "displaytext";
|
|
|
|
string subDisplayText = "";
|
|
|
|
GetAttribute(attributeName, subMenuName);
|
|
|
|
GetAttribute(attributeDisplayText, subDisplayText);
|
|
|
|
skinSetup->SetSubMenu(subMenuName, subDisplayText);
|
|
|
|
ParseSetupMenu();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
2015-07-07 17:58:10 +02:00
|
|
|
} while (NextNode());
|
|
|
|
skinSetup->SubMenuDone();
|
|
|
|
LevelUp();
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ParseSetupParameter(void) {
|
|
|
|
if (!skinSetup)
|
2014-09-27 09:25:14 +02:00
|
|
|
return;
|
2015-07-07 17:58:10 +02:00
|
|
|
string attributeType = "type";
|
|
|
|
string paramType = "";
|
|
|
|
string attributeName = "name";
|
|
|
|
string paramName = "";
|
|
|
|
string attributeDisplayText = "displaytext";
|
|
|
|
string paramDisplayText = "";
|
|
|
|
string attributeMin = "min";
|
|
|
|
string paramMin = "";
|
|
|
|
string attributeMax = "max";
|
|
|
|
string paramMax = "";
|
|
|
|
string paramValue = "";
|
2015-08-08 11:04:15 +02:00
|
|
|
string attributeOptions = "options";
|
|
|
|
string paramOptions="";
|
2015-07-07 17:58:10 +02:00
|
|
|
|
|
|
|
GetAttribute(attributeType, paramType);
|
|
|
|
GetAttribute(attributeName, paramName);
|
|
|
|
GetAttribute(attributeDisplayText, paramDisplayText);
|
|
|
|
GetAttribute(attributeMin, paramMin);
|
2015-08-08 11:04:15 +02:00
|
|
|
GetAttribute(attributeOptions, paramOptions);
|
2015-07-07 17:58:10 +02:00
|
|
|
GetNodeValue(paramValue);
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-08-08 11:04:15 +02:00
|
|
|
skinSetup->SetParameter(paramType, paramName, paramDisplayText, paramMin, paramMax, paramValue, paramOptions);
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
void cXmlParser::ValidateAttributes(const char *nodeName, vector<stringpair> &attributes) {
|
|
|
|
bool repeat = true;
|
|
|
|
while (repeat) {
|
|
|
|
repeat = false;
|
|
|
|
for (vector<stringpair>::iterator it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
string attributeName = (*it).first;
|
|
|
|
if (!view->ValidAttribute(nodeName, attributeName.c_str())) {
|
|
|
|
attributes.erase(it);
|
|
|
|
repeat = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:58:10 +02:00
|
|
|
string cXmlParser::GetPath(string xmlFile) {
|
|
|
|
string activeSkin = Setup.OSDSkin;
|
|
|
|
string activeTheme = Setup.OSDTheme;
|
|
|
|
string path = "";
|
|
|
|
if (!xmlFile.compare("globals.xml")) {
|
|
|
|
path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str());
|
|
|
|
} else if (!xmlFile.compare("theme.xml")) {
|
|
|
|
path = *cString::sprintf("%s%s/themes/%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), activeTheme.c_str(), xmlFile.c_str());
|
|
|
|
} else if (!xmlFile.compare("setup.xml")) {
|
|
|
|
path = *cString::sprintf("%s%s/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str());
|
|
|
|
} else {
|
|
|
|
path = *cString::sprintf("%s%s/xmlfiles/%s", *config.GetSkinPath(activeSkin), activeSkin.c_str(), xmlFile.c_str());
|
|
|
|
}
|
|
|
|
return path;
|
2014-11-12 16:58:01 +01:00
|
|
|
}
|
|
|
|
|