diff options
author | louis <louis.braun@gmx.de> | 2015-07-07 17:58:10 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-07-07 17:58:10 +0200 |
commit | 5a6fb850b35bc63325cac482daaa70b00b0e8e8b (patch) | |
tree | c46bea143641a4a0f4461b971ae2cd03e10ac76b /libtemplate | |
parent | 50fe393724a265341b1745dd401db9d93f46f354 (diff) | |
download | vdr-plugin-skindesigner-5a6fb850b35bc63325cac482daaa70b00b0e8e8b.tar.gz vdr-plugin-skindesigner-5a6fb850b35bc63325cac482daaa70b00b0e8e8b.tar.bz2 |
immplemented areacontainers to group areas
Diffstat (limited to 'libtemplate')
-rw-r--r-- | libtemplate/globals.c | 4 | ||||
-rw-r--r-- | libtemplate/template.c | 24 | ||||
-rw-r--r-- | libtemplate/templatefunction.c | 3 | ||||
-rw-r--r-- | libtemplate/templatefunction.h | 1 | ||||
-rw-r--r-- | libtemplate/templatepixmap.c | 253 | ||||
-rw-r--r-- | libtemplate/templatepixmap.h | 70 | ||||
-rw-r--r-- | libtemplate/templateview.c | 51 | ||||
-rw-r--r-- | libtemplate/templateview.h | 21 | ||||
-rw-r--r-- | libtemplate/templateviewelement.c | 96 | ||||
-rw-r--r-- | libtemplate/templateviewelement.h | 18 | ||||
-rw-r--r-- | libtemplate/templateviewgrid.c | 2 | ||||
-rw-r--r-- | libtemplate/xmlparser.c | 1243 | ||||
-rw-r--r-- | libtemplate/xmlparser.h | 59 |
13 files changed, 907 insertions, 938 deletions
diff --git a/libtemplate/globals.c b/libtemplate/globals.c index 702bf8e..822b993 100644 --- a/libtemplate/globals.c +++ b/libtemplate/globals.c @@ -18,13 +18,13 @@ bool cGlobals::ReadFromXML(void) { //globals.xml is mandatory string xmlFile = "globals.xml"; cXmlParser parser; - if (!parser.ReadGlobals(this, xmlFile, true)) + if (!parser.ReadGlobals(this, xmlFile)) return false; if (!parser.ParseGlobals()) return false; //theme.xml is optional xmlFile = "theme.xml"; - if (parser.ReadGlobals(this, xmlFile, false)) { + if (parser.ReadGlobals(this, xmlFile)) { parser.ParseGlobals(); } return true; diff --git a/libtemplate/template.c b/libtemplate/template.c index b9698c2..43fd3da 100644 --- a/libtemplate/template.c +++ b/libtemplate/template.c @@ -190,10 +190,10 @@ void cTemplate::GetUsedFonts(cTemplateView *view, vector< pair<string, int> > &u view->InitViewElementIterator(); cTemplateViewElement *viewElement = NULL; while(viewElement = view->GetNextViewElement()) { - viewElement->InitIterator(); + viewElement->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewElement->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText) { @@ -206,10 +206,10 @@ void cTemplate::GetUsedFonts(cTemplateView *view, vector< pair<string, int> > &u view->InitViewListIterator(); cTemplateViewList *viewList = NULL; while(viewList = view->GetNextViewList()) { - viewList->InitIterator(); + viewList->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewList->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText) { @@ -218,9 +218,9 @@ void cTemplate::GetUsedFonts(cTemplateView *view, vector< pair<string, int> > &u } } cTemplateViewElement *listElement = viewList->GetListElement(); - listElement->InitIterator(); + listElement->InitPixmapIterator(); while(pix = listElement->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText) { @@ -233,7 +233,7 @@ void cTemplate::GetUsedFonts(cTemplateView *view, vector< pair<string, int> > &u view->InitViewTabIterator(); cTemplateViewTab *viewTab = NULL; while(viewTab = view->GetNextViewTab()) { - viewTab->InitIterator(); + viewTab->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = viewTab->GetNextFunction()) { if (func->GetType() == ftDrawText) { @@ -248,7 +248,7 @@ void cTemplate::CacheImages(cTemplateView *view) { view->InitViewElementIterator(); cTemplateViewElement *viewElement = NULL; while(viewElement = view->GetNextViewElement()) { - viewElement->InitIterator(); + viewElement->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewElement->GetNextPixmap()) { CachePixmapImages(pix); @@ -258,13 +258,13 @@ void cTemplate::CacheImages(cTemplateView *view) { view->InitViewListIterator(); cTemplateViewList *viewList = NULL; while(viewList = view->GetNextViewList()) { - viewList->InitIterator(); + viewList->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewList->GetNextPixmap()) { CachePixmapImages(pix); } cTemplateViewElement *listElement = viewList->GetListElement(); - listElement->InitIterator(); + listElement->InitPixmapIterator(); while(pix = listElement->GetNextPixmap()) { CachePixmapImages(pix); } @@ -272,7 +272,7 @@ void cTemplate::CacheImages(cTemplateView *view) { if (!currentElement) { continue; } - currentElement->InitIterator(); + currentElement->InitPixmapIterator(); while(pix = currentElement->GetNextPixmap()) { CachePixmapImages(pix); } @@ -286,7 +286,7 @@ void cTemplate::CacheImages(cTemplateView *view) { } void cTemplate::CachePixmapImages(cTemplatePixmap *pix) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawImage) { diff --git a/libtemplate/templatefunction.c b/libtemplate/templatefunction.c index 6c6ae5c..0adc754 100644 --- a/libtemplate/templatefunction.c +++ b/libtemplate/templatefunction.c @@ -1568,6 +1568,9 @@ string cTemplateFunction::GetFuncName(void) { case ftViewElement:
name = "View Element Parameters";
break;
+ case ftPixmapContainer:
+ name = "Pixmap Container Parameters";
+ break;
case ftPixmap:
name = "Pixmap Parameters";
break;
diff --git a/libtemplate/templatefunction.h b/libtemplate/templatefunction.h index a000110..d800c5f 100644 --- a/libtemplate/templatefunction.h +++ b/libtemplate/templatefunction.h @@ -23,6 +23,7 @@ enum eFuncType { ftView, ftViewElement, ftViewList, + ftPixmapContainer, ftPixmap, ftPixmapScroll, ftLoop, diff --git a/libtemplate/templatepixmap.c b/libtemplate/templatepixmap.c index d6866b5..117ab25 100644 --- a/libtemplate/templatepixmap.c +++ b/libtemplate/templatepixmap.c @@ -1,41 +1,50 @@ #include "templatepixmap.h"
using namespace std;
+// --- cTemplatePixmapNode -------------------------------------------------------------
-// --- cTemplatePixmap -------------------------------------------------------------
-
-cTemplatePixmap::cTemplatePixmap(void) {
+cTemplatePixmapNode::cTemplatePixmapNode(void) {
parameters = NULL;
+ globals = NULL;
containerX = 0;
containerY = 0;
containerWidth = 0;
containerHeight = 0;
- globals = NULL;
- scrolling = false;
- background = false;
}
-cTemplatePixmap::~cTemplatePixmap() {
- for (vector<cTemplateFunction*>::iterator it = functions.begin(); it != functions.end(); it++) {
- delete (*it);
- }
+cTemplatePixmapNode::~cTemplatePixmapNode() {
if (parameters)
delete parameters;
}
-void cTemplatePixmap::SetParameters(vector<pair<string, string> > ¶ms) {
- parameters = new cTemplateFunction(ftPixmap);
+void cTemplatePixmapNode::SetParameters(vector<stringpair> ¶ms) {
+ parameters = new cTemplateFunction(isContainer?ftPixmapContainer:ftPixmap);
parameters->SetGlobals(globals);
parameters->SetParameters(params);
}
-void cTemplatePixmap::SetContainer(int x, int y, int w, int h) {
+void cTemplatePixmapNode::SetContainer(int x, int y, int w, int h) {
containerX = x;
containerY = y;
containerWidth = w;
containerHeight = h;
}
+// --- cTemplatePixmap -------------------------------------------------------------
+
+cTemplatePixmap::cTemplatePixmap(void) {
+ pixContainer = NULL;
+ isContainer = false;
+ scrolling = false;
+ background = false;
+}
+
+cTemplatePixmap::~cTemplatePixmap() {
+ for (vector<cTemplateFunction*>::iterator it = functions.begin(); it != functions.end(); it++) {
+ delete (*it);
+ }
+}
+
void cTemplatePixmap::SetWidth(int width) {
cString pWidth = cString::sprintf("%d", width);
parameters->SetWidthManually(*pWidth);
@@ -76,6 +85,11 @@ void cTemplatePixmap::SetYPercent(double y) { parameters->SetYManually(absY);
}
+void cTemplatePixmap::SetParameter(eParamType type, string value) {
+ parameters->SetParameter(type, value);
+}
+
+
void cTemplatePixmap::ClearDynamicParameters(void) {
parameters->ClearDynamicParameters();
}
@@ -180,7 +194,7 @@ bool cTemplatePixmap::CalculateParameters(void) { }
void cTemplatePixmap::ClearDynamicFunctionParameters(void) {
- InitIterator();
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
func->ClearDynamicParameters();
@@ -188,7 +202,7 @@ void cTemplatePixmap::ClearDynamicFunctionParameters(void) { }
void cTemplatePixmap::ParseDynamicFunctionParameters(map <string,string> *stringTokens, map <string,int> *intTokens, map < string, vector< map< string, string > > > *loopTokens) {
- InitIterator();
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
bool completelyParsed = true;
while(func = GetNextFunction()) {
@@ -215,7 +229,7 @@ void cTemplatePixmap::ParseDynamicFunctionParameters(map <string,string> *string if (!replacedWidth && !replacedHeight && !replacedPosX && !replacedPosY)
return;
- InitIterator();
+ InitFunctionIterator();
func = NULL;
while(func = GetNextFunction()) {
if (func->ParsedCompletely())
@@ -249,7 +263,7 @@ bool cTemplatePixmap::CalculateDrawPortSize(cSize &size, map < string, vector< m }
} else if (orientation == orVertical) {
//check "last" element height
- InitIterator();
+ InitFunctionIterator();
cTemplateFunction *f = NULL;
int drawportHeight = 1;
while (f = GetNextFunction()) {
@@ -324,7 +338,7 @@ void cTemplatePixmap::SetScrollingTextWidth(void) { if (orientation != orHorizontal)
return;
int pixWidth = parameters->GetNumericParameter(ptWidth);
- InitIterator();
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
if (func->GetType() == ftDrawText) {
@@ -339,7 +353,7 @@ cTemplateFunction *cTemplatePixmap::GetScrollFunction(void) { string scrollElement = parameters->GetParameter(ptScrollElement);
if (scrollElement.size() == 0)
return NULL;
- InitIterator();
+ InitFunctionIterator();
cTemplateFunction *f = NULL;
while (f = GetNextFunction()) {
string funcName = f->GetParameter(ptName);
@@ -365,7 +379,7 @@ int cTemplatePixmap::GetNumericParameter(eParamType type) { return parameters->GetNumericParameter(type);
}
-void cTemplatePixmap::InitIterator(void) {
+void cTemplatePixmap::InitFunctionIterator(void) {
funcIt = functions.begin();
}
@@ -393,9 +407,26 @@ bool cTemplatePixmap::Ready(void) { return true;
}
+bool cTemplatePixmap::ParameterSet(eParamType type) {
+ string value = parameters->GetParameter(type);
+ if (value.size() > 0)
+ return true;
+ return false;
+}
+
+cTemplateFunction *cTemplatePixmap::GetFunction(string name) {
+ for (vector<cTemplateFunction*>::iterator it = functions.begin(); it != functions.end(); it++) {
+ string funcName = (*it)->GetParameter(ptName);
+ if (!name.compare(funcName))
+ return *it;
+ }
+ return NULL;
+}
+
bool cTemplatePixmap::ReplaceWidthFunctions(void) {
bool replaced = false;
- InitIterator();
+ bool found = false;
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
if (func->ParsedCompletely()) {
@@ -411,6 +442,20 @@ bool cTemplatePixmap::ReplaceWidthFunctions(void) { cTemplateFunction *myFunc = *it;
string myFuncName = myFunc->GetParameter(ptName);
if (!myFuncName.compare(label)) {
+ found = true;
+ funcWidth = myFunc->GetWidth();
+ func->SetWidth(type, label, funcWidth);
+ if (func->Updated()) {
+ func->CompleteParameters();
+ } else {
+ replaced = true;
+ }
+ break;
+ }
+ }
+ if (!found && pixContainer) {
+ cTemplateFunction *myFunc = pixContainer->GetFunction(label);
+ if (myFunc) {
funcWidth = myFunc->GetWidth();
func->SetWidth(type, label, funcWidth);
if (func->Updated()) {
@@ -418,6 +463,7 @@ bool cTemplatePixmap::ReplaceWidthFunctions(void) { } else {
replaced = true;
}
+ break;
}
}
}
@@ -427,7 +473,8 @@ bool cTemplatePixmap::ReplaceWidthFunctions(void) { bool cTemplatePixmap::ReplaceHeightFunctions(map < string, vector< map< string, string > > > *loopTokens) {
bool replaced = false;
- InitIterator();
+ bool found = false;
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
if (func->ParsedCompletely()) {
@@ -443,6 +490,20 @@ bool cTemplatePixmap::ReplaceHeightFunctions(map < string, vector< map< string, cTemplateFunction *myFunc = *it;
string myFuncName = myFunc->GetParameter(ptName);
if (!myFuncName.compare(label)) {
+ found = true;
+ funcHeight = myFunc->GetHeight(loopTokens);
+ func->SetHeight(type, label, funcHeight);
+ if (func->Updated()) {
+ func->CompleteParameters();
+ } else {
+ replaced = true;
+ }
+ break;
+ }
+ }
+ if (!found && pixContainer) {
+ cTemplateFunction *myFunc = pixContainer->GetFunction(label);
+ if (myFunc) {
funcHeight = myFunc->GetHeight(loopTokens);
func->SetHeight(type, label, funcHeight);
if (func->Updated()) {
@@ -450,6 +511,7 @@ bool cTemplatePixmap::ReplaceHeightFunctions(map < string, vector< map< string, } else {
replaced = true;
}
+ break;
}
}
}
@@ -459,7 +521,8 @@ bool cTemplatePixmap::ReplaceHeightFunctions(map < string, vector< map< string, bool cTemplatePixmap::ReplacePosXFunctions(void) {
bool replaced = false;
- InitIterator();
+ bool found = false;
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
if (func->ParsedCompletely()) {
@@ -475,6 +538,22 @@ bool cTemplatePixmap::ReplacePosXFunctions(void) { cTemplateFunction *myFunc = *it;
string myFuncName = myFunc->GetParameter(ptName);
if (!myFuncName.compare(label)) {
+ found = true;
+ funcX = myFunc->GetNumericParameter(ptX);
+ if (funcX > -1) {
+ func->SetX(type, label, funcX);
+ if (func->Updated()) {
+ func->CompleteParameters();
+ } else {
+ replaced = true;
+ }
+ }
+ break;
+ }
+ }
+ if (!found && pixContainer) {
+ cTemplateFunction *myFunc = pixContainer->GetFunction(label);
+ if (myFunc) {
funcX = myFunc->GetNumericParameter(ptX);
if (funcX > -1) {
func->SetX(type, label, funcX);
@@ -484,6 +563,7 @@ bool cTemplatePixmap::ReplacePosXFunctions(void) { replaced = true;
}
}
+ break;
}
}
}
@@ -493,7 +573,8 @@ bool cTemplatePixmap::ReplacePosXFunctions(void) { bool cTemplatePixmap::ReplacePosYFunctions(void) {
bool replaced = false;
- InitIterator();
+ bool found = false;
+ InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = GetNextFunction()) {
if (func->ParsedCompletely()) {
@@ -509,6 +590,7 @@ bool cTemplatePixmap::ReplacePosYFunctions(void) { cTemplateFunction *myFunc = *it;
string myFuncName = myFunc->GetParameter(ptName);
if (!myFuncName.compare(label)) {
+ found = true;
funcY = myFunc->GetNumericParameter(ptY);
if (funcY > -1) {
func->SetY(type, label, funcY);
@@ -518,6 +600,22 @@ bool cTemplatePixmap::ReplacePosYFunctions(void) { replaced = true;
}
}
+ break;
+ }
+ }
+ if (!found && pixContainer) {
+ cTemplateFunction *myFunc = pixContainer->GetFunction(label);
+ if (myFunc) {
+ funcY = myFunc->GetNumericParameter(ptY);
+ if (funcY > -1) {
+ func->SetY(type, label, funcY);
+ if (func->Updated()) {
+ func->CompleteParameters();
+ } else {
+ replaced = true;
+ }
+ }
+ break;
}
}
}
@@ -532,3 +630,110 @@ void cTemplatePixmap::Debug(void) { (*it)->Debug();
}
}
+
+// --- cTemplatePixmapContainer -------------------------------------------------------------
+
+cTemplatePixmapContainer::cTemplatePixmapContainer(void) {
+ isContainer = true;
+}
+
+cTemplatePixmapContainer::~cTemplatePixmapContainer() {
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ delete (*it);
+ }
+}
+
+void cTemplatePixmapContainer::SetGlobals(cGlobals *globals) {
+ this->globals = globals;
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ (*it)->SetGlobals(globals);
+ }
+}
+
+void cTemplatePixmapContainer::SetWidth(int width) {
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ (*it)->SetWidth(width);
+ }
+}
+
+void cTemplatePixmapContainer::SetHeight(int height) {
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ (*it)->SetHeight(height);
+ }
+}
+
+void cTemplatePixmapContainer::AddPixmap(cTemplatePixmap *pix) {
+ //setting default parameters of container if parameter is not set in area
+ string containerDefaultX = parameters->GetParameter(ptX);
+ string containerDefaultY = parameters->GetParameter(ptY);
+ string containerDefaultWidth = parameters->GetParameter(ptWidth);
+ string containerDefaultHeight = parameters->GetParameter(ptHeight);
+ if (containerDefaultX.size() > 0 && !pix->ParameterSet(ptX))
+ pix->SetParameter(ptX, containerDefaultX);
+ if (containerDefaultY.size() > 0 && !pix->ParameterSet(ptY))
+ pix->SetParameter(ptY, containerDefaultY);
+ if (containerDefaultWidth.size() > 0 && !pix->ParameterSet(ptWidth))
+ pix->SetParameter(ptWidth, containerDefaultWidth);
+ if (containerDefaultHeight.size() > 0 && !pix->ParameterSet(ptHeight))
+ pix->SetParameter(ptHeight, containerDefaultHeight);
+
+ pix->SetPixmapContainer(this);
+ pixmaps.push_back(pix);
+}
+
+bool cTemplatePixmapContainer::CalculateParameters(void) {
+ bool paramsValid = true;
+ //Calculate Pixmap Size
+ parameters->SetContainer(containerX, containerY, containerWidth, containerHeight);
+ parameters->SetGlobals(globals);
+ paramsValid = parameters->CalculateParameters();
+
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ (*it)->SetContainer(containerX, containerY, containerWidth, containerHeight);
+ (*it)->SetGlobals(globals);
+ paramsValid = (*it)->CalculateParameters() && paramsValid;
+ }
+
+ return paramsValid;
+}
+
+void cTemplatePixmapContainer::ParseDynamicParameters(map <string,string> *stringTokens, map <string,int> *intTokens) {
+ parameters->ClearDynamicParameters();
+ parameters->SetIntTokens(intTokens);
+ parameters->SetStringTokens(stringTokens);
+ parameters->ParseParameters();
+ parameters->UnsetIntTokens();
+ parameters->UnsetStringTokens();
+}
+
+void cTemplatePixmapContainer::InitIterator(void) {
+ pixmapIterator = pixmaps.begin();
+}
+
+cTemplatePixmap *cTemplatePixmapContainer::GetNextPixmap(void) {
+ if (pixmapIterator == pixmaps.end())
+ return NULL;
+ cTemplatePixmap *pix = *pixmapIterator;
+ pixmapIterator++;
+ return pix;
+}
+
+cTemplateFunction *cTemplatePixmapContainer::GetFunction(string name) {
+ cTemplateFunction *hit = NULL;
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ hit = (*it)->GetFunction(name);
+ if (hit)
+ return hit;
+ }
+ return NULL;
+}
+
+
+void cTemplatePixmapContainer::Debug(void) {
+ esyslog("skindesigner: pixmapcontainer");
+ parameters->Debug();
+ for (vector<cTemplatePixmap*>::iterator it = pixmaps.begin(); it != pixmaps.end(); it++) {
+ (*it)->Debug();
+ }
+}
+
diff --git a/libtemplate/templatepixmap.h b/libtemplate/templatepixmap.h index 5f16f21..f9c2f6f 100644 --- a/libtemplate/templatepixmap.h +++ b/libtemplate/templatepixmap.h @@ -13,23 +13,46 @@ #include "globals.h" #include "templateloopfunction.h" +#include "../views/viewhelpers.h" using namespace std; +// --- cTemplatePixmapNode ------------------------------------------------------------- +class cTemplatePixmapNode { +protected: + bool isContainer; + cGlobals *globals; + cTemplateFunction *parameters; + int containerX; + int containerY; + int containerWidth; + int containerHeight; +public: + cTemplatePixmapNode(void); + virtual ~cTemplatePixmapNode(void); + void SetParameters(vector<stringpair> ¶ms); + void SetContainer(int x, int y, int w, int h); + bool IsContainer(void) { return isContainer; }; + bool DoExecute(void) { return parameters->DoExecute(); }; + bool DoDebug(void) { return parameters->DoDebug(); }; + virtual void SetGlobals(cGlobals *globals) { this->globals = globals; }; + virtual bool CalculateParameters(void) { return false; }; + virtual void SetWidth(int width) {}; + virtual void SetHeight(int height) {}; + virtual int NumPixmaps(void) { return 0; }; + virtual void Debug(void) {}; +}; + // --- cTemplatePixmap ------------------------------------------------------------- +class cTemplatePixmapContainer; -class cTemplatePixmap { +class cTemplatePixmap : public cTemplatePixmapNode { protected: + cTemplatePixmapContainer *pixContainer; bool scrolling; bool background; - cTemplateFunction *parameters; vector<cTemplateFunction*> functions; vector<cTemplateFunction*>::iterator funcIt; - int containerX; - int containerY; - int containerWidth; - int containerHeight; - cGlobals *globals; //functions replacing {width(label)} and {height(label)} tokens bool ReplaceWidthFunctions(void); bool ReplaceHeightFunctions(map < string, vector< map< string, string > > > *loopTokens); @@ -42,8 +65,8 @@ public: cTemplatePixmap(void); virtual ~cTemplatePixmap(void); //Setter Functions + void SetPixmapContainer(cTemplatePixmapContainer *pixContainer) { this->pixContainer = pixContainer; }; void SetScrolling(void) { scrolling = true; }; - void SetParameters(vector<pair<string, string> > ¶ms); void SetWidth(int width); void SetHeight(int height); void SetX(int x); @@ -52,8 +75,7 @@ public: void SetHeightPercent(double height); void SetXPercent(double x); void SetYPercent(double y); - void SetContainer(int x, int y, int w, int h); - void SetGlobals(cGlobals *globals) { this->globals = globals; }; + void SetParameter(eParamType type, string value); void AddFunction(string name, vector<pair<string, string> > ¶ms); void AddLoopFunction(cTemplateLoopFunction *lf); //PreCache Parameters @@ -71,18 +93,40 @@ public: //Set max width for text in scrollarea void SetScrollingTextWidth(void); //Getter Functions + int NumPixmaps(void) { return 1; }; cRect GetPixmapSize(void); int GetNumericParameter(eParamType type); bool Scrolling(void) { return scrolling; }; - bool DoExecute(void) { return parameters->DoExecute(); }; - bool DoDebug(void) { return parameters->DoDebug(); }; bool Ready(void); bool BackgroundArea(void) { return background; }; + bool ParameterSet(eParamType type); + cTemplateFunction *GetFunction(string name); //Traverse Functions - void InitIterator(void); + void InitFunctionIterator(void); cTemplateFunction *GetNextFunction(void); //Debug void Debug(void); }; +class cTemplatePixmapContainer : public cTemplatePixmapNode { +private: + vector<cTemplatePixmap*> pixmaps; + vector<cTemplatePixmap*>::iterator pixmapIterator; +public: + cTemplatePixmapContainer(void); + virtual ~cTemplatePixmapContainer(void); + void SetGlobals(cGlobals *globals); + void SetWidth(int width); + void SetHeight(int height); + void AddPixmap(cTemplatePixmap *pix); + //PreCache Parameters + bool CalculateParameters(void); + void ParseDynamicParameters(map <string,string> *stringTokens, map <string,int> *intTokens); + int NumPixmaps(void) { return pixmaps.size(); }; + void InitIterator(void); + cTemplatePixmap *GetNextPixmap(void); + cTemplateFunction *GetFunction(string name); + void Debug(void); +}; + #endif //__TEMPLATEPIXMAP_H
\ No newline at end of file diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c index 91e28c4..363c37a 100644 --- a/libtemplate/templateview.c +++ b/libtemplate/templateview.c @@ -349,10 +349,10 @@ void cTemplateView::Translate(void) { InitViewElementIterator(); cTemplateViewElement *viewElement = NULL; while(viewElement = GetNextViewElement()) { - viewElement->InitIterator(); + viewElement->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewElement->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -385,10 +385,10 @@ void cTemplateView::Translate(void) { InitViewListIterator(); cTemplateViewList *viewList = NULL; while(viewList = GetNextViewList()) { - viewList->InitIterator(); + viewList->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewList->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -402,9 +402,9 @@ void cTemplateView::Translate(void) { } } cTemplateViewElement *listElement = viewList->GetListElement(); - listElement->InitIterator(); + listElement->InitPixmapIterator(); while(pix = listElement->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -420,9 +420,9 @@ void cTemplateView::Translate(void) { cTemplateViewElement *listElementCurrent = viewList->GetListElementCurrent(); if (listElementCurrent) { - listElementCurrent->InitIterator(); + listElementCurrent->InitPixmapIterator(); while(pix = listElementCurrent->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -463,7 +463,7 @@ void cTemplateView::Translate(void) { if (translated) { viewTab->SetName(tabTrans); } - viewTab->InitIterator(); + viewTab->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = viewTab->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -496,10 +496,10 @@ void cTemplateView::Translate(void) { InitViewGridIterator(); cTemplateViewGrid *viewGrid = NULL; while(viewGrid = GetNextViewGrid()) { - viewGrid->InitIterator(); + viewGrid->InitPixmapIterator(); cTemplatePixmap *pix = NULL; while(pix = viewGrid->GetNextPixmap()) { - pix->InitIterator(); + pix->InitFunctionIterator(); cTemplateFunction *func = NULL; while(func = pix->GetNextFunction()) { if (func->GetType() == ftDrawText || func->GetType() == ftDrawTextBox || func->GetType() == ftDrawTextVertical) { @@ -696,6 +696,16 @@ void cTemplateView::SetFunctionDefinitions(void) { attributes.insert("debug"); funcsAllowed.insert(pair< string, set<string> >(name, attributes)); + name = "areacontainer"; + attributes.clear(); + attributes.insert("x"); + attributes.insert("y"); + attributes.insert("width"); + attributes.insert("height"); + attributes.insert("debug"); + attributes.insert("condition"); + funcsAllowed.insert(pair< string, set<string> >(name, attributes)); + name = "area"; attributes.clear(); attributes.insert("debug"); @@ -998,9 +1008,9 @@ string cTemplateViewChannel::GetViewElementName(eViewElement ve) { return name; } -void cTemplateViewChannel::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewChannel::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<stringpair> &viewElementattributes) { eViewElement ve = veUndefined; - + if (!sViewElement.compare("background")) { ve = veBackground; } else if (!sViewElement.compare("channelinfo")) { @@ -1040,7 +1050,6 @@ void cTemplateViewChannel::AddPixmap(string sViewElement, cTemplatePixmap *pix, } else if (!sViewElement.compare("customtokens")) { ve = veCustomTokens; } - if (ve == veUndefined) { esyslog("skindesigner: unknown ViewElement in displaychannel: %s", sViewElement.c_str()); return; @@ -1507,7 +1516,7 @@ void cTemplateViewMenu::AddPluginView(string plugName, int templNo, cTemplateVie } } -void cTemplateViewMenu::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewMenu::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; if (!sViewElement.compare("background")) { @@ -1648,7 +1657,7 @@ string cTemplateViewMessage::GetViewElementName(eViewElement ve) { return name; } -void cTemplateViewMessage::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewMessage::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; if (!sViewElement.compare("background")) { @@ -1801,7 +1810,7 @@ string cTemplateViewReplay::GetViewElementName(eViewElement ve) { return name; } -void cTemplateViewReplay::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewReplay::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; if (!sViewElement.compare("background")) { @@ -1916,7 +1925,7 @@ string cTemplateViewVolume::GetViewElementName(eViewElement ve) { return name; } -void cTemplateViewVolume::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewVolume::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; if (!sViewElement.compare("background")) { @@ -2026,7 +2035,7 @@ string cTemplateViewAudioTracks::GetViewListName(eViewList vl) { return name; } -void cTemplateViewAudioTracks::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewAudioTracks::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; if (!sViewElement.compare("background")) { @@ -2133,7 +2142,7 @@ void cTemplateViewPlugin::AddSubView(string sSubView, cTemplateView *subView) { subViews.insert(pair< eSubView, cTemplateView* >((eSubView)subViewId, subView)); } -void cTemplateViewPlugin::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) { +void cTemplateViewPlugin::AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes) { eViewElement ve = veUndefined; string viewElementName = ""; int viewElementID = -1; @@ -2177,7 +2186,7 @@ void cTemplateViewPlugin::AddPixmap(string sViewElement, cTemplatePixmap *pix, v } } -void cTemplateViewPlugin::AddPixmapGrid(cTemplatePixmap *pix, vector<pair<string, string> > &gridAttributes) { +void cTemplateViewPlugin::AddPixmapGrid(cTemplatePixmapNode *pix, vector<pair<string, string> > &gridAttributes) { string gridName = ""; bool found = false; for (vector<pair<string, string> >::iterator it = gridAttributes.begin(); it != gridAttributes.end(); it++) { diff --git a/libtemplate/templateview.h b/libtemplate/templateview.h index d592b22..726ce68 100644 --- a/libtemplate/templateview.h +++ b/libtemplate/templateview.h @@ -76,8 +76,8 @@ public: virtual string GetViewListName(eViewList vl) { return ""; }; virtual void AddSubView(string sSubView, cTemplateView *subView) {}; virtual void AddPluginView(string plugName, int templNo, cTemplateView *plugView) {}; - virtual void AddPixmap(string sViewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes) {}; - virtual void AddPixmapGrid(cTemplatePixmap *pix, vector<pair<string, string> > &gridAttributes) {}; + virtual void AddPixmap(string sViewElement, cTemplatePixmapNode *pix, vector<stringpair> &viewElementattributes) {}; + virtual void AddPixmapGrid(cTemplatePixmapNode *pix, vector<pair<string, string> > &gridAttributes) {}; virtual void AddViewList(string sViewList, cTemplateViewList *viewList) {}; virtual void AddViewTab(cTemplateViewTab *viewTab) {}; //Setter Functions @@ -146,11 +146,12 @@ class cTemplateViewChannel : public cTemplateView { private: void SetViewElements(void); void SetViewLists(void); + eViewElement GetViewElementID(string sViewElement); public: cTemplateViewChannel(void); virtual ~cTemplateViewChannel(void); string GetViewElementName(eViewElement ve); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<stringpair> &viewElementattributes); }; // --- cTemplateViewMenu ------------------------------------------------------------- @@ -168,7 +169,7 @@ public: string GetViewListName(eViewList vl); void AddSubView(string sSubView, cTemplateView *subView); void AddPluginView(string plugName, int templNo, cTemplateView *plugView); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); void AddViewList(string sViewList, cTemplateViewList *viewList); void AddViewTab(cTemplateViewTab *viewTab); }; @@ -182,7 +183,7 @@ public: cTemplateViewMessage(void); virtual ~cTemplateViewMessage(void); string GetViewElementName(eViewElement ve); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); }; // --- cTemplateViewReplay ------------------------------------------------------------- @@ -194,7 +195,7 @@ public: cTemplateViewReplay(void); virtual ~cTemplateViewReplay(void); string GetViewElementName(eViewElement ve); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); }; // --- cTemplateViewVolume ------------------------------------------------------------- @@ -206,7 +207,7 @@ public: cTemplateViewVolume(void); virtual ~cTemplateViewVolume(void); string GetViewElementName(eViewElement ve); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); }; // --- cTemplateViewAudioTracks ------------------------------------------------------------- @@ -220,7 +221,7 @@ public: virtual ~cTemplateViewAudioTracks(void); string GetViewElementName(eViewElement ve); string GetViewListName(eViewList vl); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); void AddViewList(string sViewList, cTemplateViewList *viewList); }; @@ -234,8 +235,8 @@ public: cTemplateViewPlugin(string pluginName, int viewID); virtual ~cTemplateViewPlugin(void); void AddSubView(string sSubView, cTemplateView *subView); - void AddPixmap(string viewElement, cTemplatePixmap *pix, vector<pair<string, string> > &viewElementattributes); - void AddPixmapGrid(cTemplatePixmap *pix, vector<pair<string, string> > &gridAttributes); + void AddPixmap(string viewElement, cTemplatePixmapNode *pix, vector<pair<string, string> > &viewElementattributes); + void AddPixmapGrid(cTemplatePixmapNode *pix, vector<pair<string, string> > &gridAttributes); void AddViewTab(cTemplateViewTab *viewTab); }; diff --git a/libtemplate/templateviewelement.c b/libtemplate/templateviewelement.c index 5b18de2..0171bdb 100644 --- a/libtemplate/templateviewelement.c +++ b/libtemplate/templateviewelement.c @@ -9,12 +9,14 @@ cTemplateViewElement::cTemplateViewElement(void) { containerWidth = 0;
containerHeight = 0;
pixOffset = -1;
+ pixmapIterator = NULL;
+ currentNode = NULL;
}
cTemplateViewElement::~cTemplateViewElement(void) {
if (parameters)
delete parameters;
- for (vector<cTemplatePixmap*>::iterator it = viewPixmaps.begin(); it != viewPixmaps.end(); it++) {
+ for (vector<cTemplatePixmapNode*>::iterator it = viewPixmapNodes.begin(); it != viewPixmapNodes.end(); it++) {
delete (*it);
}
}
@@ -28,7 +30,7 @@ void cTemplateViewElement::SetContainer(int x, int y, int width, int height) { void cTemplateViewElement::SetGlobals(cGlobals *globals) {
this->globals = globals;
- for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
+ for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetGlobals(globals);
}
}
@@ -52,7 +54,7 @@ bool cTemplateViewElement::CalculateParameters(void) { bool cTemplateViewElement::CalculatePixmapParameters(void) {
bool paramsValid = true;
- for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
+ for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
(*pix)->SetGlobals(globals);
paramsValid = paramsValid && (*pix)->CalculateParameters();
@@ -62,7 +64,7 @@ bool cTemplateViewElement::CalculatePixmapParameters(void) { bool cTemplateViewElement::CalculatePixmapParametersList(int orientation, int numElements) {
bool paramsValid = true;
- for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
+ for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
(*pix)->SetGlobals(globals);
if (orientation == orHorizontal) {
@@ -87,23 +89,91 @@ int cTemplateViewElement::GetNumericParameter(eParamType type) { return parameters->GetNumericParameter(type);
}
-void cTemplateViewElement::InitIterator(void) {
- pixIterator = viewPixmaps.begin();
+int cTemplateViewElement::GetNumPixmaps(void) {
+ int numPixmaps = 0;
+ for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
+ numPixmaps += (*pix)->NumPixmaps();
+ }
+ return numPixmaps;
+};
+
+void cTemplateViewElement::InitPixmapNodeIterator(void) {
+ pixmapNodeIterator = viewPixmapNodes.begin();
+}
+
+cTemplatePixmapNode *cTemplateViewElement::GetNextPixmapNode(void) {
+ if (pixmapNodeIterator == viewPixmapNodes.end())
+ return NULL;
+ cTemplatePixmapNode *pix = *pixmapNodeIterator;
+ pixmapNodeIterator++;
+ return pix;
+}
+
+void cTemplateViewElement::InitPixmapIterator(void) {
+ pixmapNodeIterator = viewPixmapNodes.begin();
+ if (pixmapNodeIterator == viewPixmapNodes.end())
+ return;
+ if (!(*pixmapNodeIterator)->IsContainer()) {
+ //first node is a pixmap, use this
+ pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
+ return;
+ }
+ //first node is a container, so fetch first pixmap of this container
+ currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
+ currentNode->InitIterator();
+ pixmapIterator = currentNode->GetNextPixmap();
}
cTemplatePixmap *cTemplateViewElement::GetNextPixmap(void) {
- if (pixIterator == viewPixmaps.end())
+ if (!pixmapIterator)
return NULL;
- cTemplatePixmap *pix = *pixIterator;
- pixIterator++;
- return pix;
+ cTemplatePixmap *current = pixmapIterator;
+ //set next pixmap
+ if (!currentNode) {
+ //last node was a pixmap
+ pixmapNodeIterator++;
+ if (pixmapNodeIterator == viewPixmapNodes.end()) {
+ pixmapIterator = NULL;
+ return current;
+ }
+ if (!(*pixmapNodeIterator)->IsContainer()) {
+ //node is a pixmap, use this
+ pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
+ return current;
+ }
+ //node is a container, so fetch first pixmap of this container
+ currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
+ currentNode->InitIterator();
+ pixmapIterator = currentNode->GetNextPixmap();
+ } else {
+ pixmapIterator = currentNode->GetNextPixmap();
+ if (pixmapIterator) {
+ return current;
+ }
+ currentNode = NULL;
+ pixmapNodeIterator++;
+ if (pixmapNodeIterator == viewPixmapNodes.end()) {
+ pixmapIterator = NULL;
+ return current;
+ }
+ if (!(*pixmapNodeIterator)->IsContainer()) {
+ //node is a pixmap, use this
+ pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
+ return current;
+ }
+ //node is a container, so fetch first pixmap of this container
+ currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
+ currentNode->InitIterator();
+ pixmapIterator = currentNode->GetNextPixmap();
+ }
+ return current;
}
cTemplateFunction *cTemplateViewElement::GetFunction(string name) {
- InitIterator();
+ InitPixmapIterator();
cTemplatePixmap *pix = NULL;
while (pix = GetNextPixmap()) {
- pix->InitIterator();
+ pix->InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
@@ -151,7 +221,7 @@ void cTemplateViewElement::Debug(void) { if (parameters)
parameters->Debug();
return;
- for (vector<cTemplatePixmap*>::iterator it = viewPixmaps.begin(); it != viewPixmaps.end(); it++) {
+ for (vector<cTemplatePixmapNode*>::iterator it = viewPixmapNodes.begin(); it != viewPixmapNodes.end(); it++) {
(*it)->Debug();
}
}
\ No newline at end of file diff --git a/libtemplate/templateviewelement.h b/libtemplate/templateviewelement.h index 20c0906..cbc2911 100644 --- a/libtemplate/templateviewelement.h +++ b/libtemplate/templateviewelement.h @@ -91,24 +91,28 @@ protected: int containerY;
int containerWidth;
int containerHeight;
- vector<cTemplatePixmap*> viewPixmaps;
- vector<cTemplatePixmap*>::iterator pixIterator;
+ vector<cTemplatePixmapNode*> viewPixmapNodes;
+ vector<cTemplatePixmapNode*>::iterator pixmapNodeIterator;
+ cTemplatePixmap *pixmapIterator;
+ cTemplatePixmapContainer *currentNode;
int pixOffset;
public:
cTemplateViewElement(void);
virtual ~cTemplateViewElement(void);
+ void SetContainer(int x, int y, int width, int height);
+ virtual void SetGlobals(cGlobals *globals);
void SetParameters(vector<pair<string, string> > ¶ms);
bool CalculateParameters(void);
virtual bool CalculatePixmapParameters(void);
bool CalculatePixmapParametersList(int orientation, int numElements);
+ void AddPixmap(cTemplatePixmapNode *pix) { viewPixmapNodes.push_back(pix); };
int GetNumericParameter(eParamType type);
- void AddPixmap(cTemplatePixmap *pix) { viewPixmaps.push_back(pix); };
- virtual void SetGlobals(cGlobals *globals);
- void SetContainer(int x, int y, int width, int height);
void SetPixOffset(int offset) { pixOffset = offset; };
int GetPixOffset(void) { return pixOffset; };
- virtual int GetNumPixmaps(void) { return viewPixmaps.size(); };
- void InitIterator(void);
+ virtual int GetNumPixmaps(void);
+ void InitPixmapNodeIterator(void);
+ cTemplatePixmapNode *GetNextPixmapNode(void);
+ void InitPixmapIterator(void);
cTemplatePixmap *GetNextPixmap(void);
cTemplateFunction *GetFunction(string name);
bool Execute(void);
diff --git a/libtemplate/templateviewgrid.c b/libtemplate/templateviewgrid.c index dc4af63..bd73d84 100644 --- a/libtemplate/templateviewgrid.c +++ b/libtemplate/templateviewgrid.c @@ -15,7 +15,7 @@ bool cTemplateViewGrid::CalculatePixmapParameters(void) { int gridWidth = parameters->GetNumericParameter(ptWidth);
int gridHeight = parameters->GetNumericParameter(ptHeight);
- for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
+ for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetContainer(gridX, gridY, gridWidth, gridHeight);
(*pix)->SetGlobals(globals);
paramsValid = paramsValid && (*pix)->CalculateParameters();
diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index 4db7ce5..3df65f3 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -4,459 +4,432 @@ using namespace std; -void SkinDesignerXMLErrorHandler (void * userData, xmlErrorPtr error) { - esyslog("skindesigner: Error in XML: %s", error->message); -} - cXmlParser::cXmlParser(void) { view = NULL; - doc = NULL; - root = NULL; - ctxt = NULL; globals = NULL; skinSetup = NULL; - - initGenericErrorDefaultFunc(NULL); - xmlSetStructuredErrorFunc(NULL, SkinDesignerXMLErrorHandler); - ctxt = xmlNewParserCtxt(); } cXmlParser::~cXmlParser() { - DeleteDocument(); - xmlFreeParserCtxt(ctxt); } /********************************************************************* * PUBLIC Functions *********************************************************************/ bool cXmlParser::ReadView(cTemplateView *view, string xmlFile) { + if (!view) + return false; this->view = view; - string xmlPath = GetPath(xmlFile); - - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { - esyslog("skindesigner: ERROR: TemplateView %s not parsed successfully.", xmlPath.c_str()); + if (! Validate() ) return false; - } - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + if (! SetDocument() ) return false; - } - - root = xmlDocGetRootElement(doc); + if (! CheckNodeName(view->GetViewName()) ) + return false; + return true; +} - if (root == NULL) { - esyslog("skindesigner: ERROR: TemplateView %s is empty", xmlPath.c_str()); +bool cXmlParser::ParseView(void) { + if (!view) return false; - } - if (xmlStrcmp(root->name, (const xmlChar *) view->GetViewName())) { + vector<stringpair> rootAttribs = ParseAttributes(); + ValidateAttributes(NodeName(), rootAttribs); + view->SetParameters(rootAttribs); + + if (!LevelDown()) return false; - } + + 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()); + return true; + } bool cXmlParser::ReadPluginView(string plugName, int templateNumber, string templateName) { - string xmlPath = GetPath(templateName); - - if (!FileExists(xmlPath) || ctxt == NULL) { - return false; - } DeleteDocument(); - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); + if (! Validate() ) return false; - } + if (! SetDocument() ) + return false; + return true; +} - root = xmlDocGetRootElement(doc); +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); - if (root == NULL) { + if (!LevelDown()) return false; - } + 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()); return true; } -bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile, bool mandatory) { +bool cXmlParser::ReadGlobals(cGlobals *globals, string xmlFile) { this->globals = globals; - string xmlPath = GetPath(xmlFile); - - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); + DeleteDocument(); + if (! ReadXMLFile(xmlPath.c_str()) ) return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlPath.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL) { - if (mandatory) { - esyslog("skindesigner: ERROR: Globals %s not parsed successfully.", xmlPath.c_str()); - } else { - dsyslog("skindesigner: Globals %s not parsed successfully.", xmlPath.c_str()); - } + if (! Validate() ) return false; - } - - root = xmlDocGetRootElement(doc); - - if (ctxt->valid == 0) { - if (mandatory) { - esyslog("skindesigner: ERROR: Failed to validate %s", xmlPath.c_str()); - } else { - dsyslog("skindesigner: Failed to validate %s", xmlPath.c_str()); - } + if (! SetDocument() ) return false; - } - - if (root == NULL) { - if (mandatory) { - esyslog("skindesigner: ERROR: Globals %s is empty", xmlPath.c_str()); - } + if (! CheckNodeName("globals") ) return false; - } + return true; +} - if (xmlStrcmp(root->name, (const xmlChar *) "globals")) { +bool cXmlParser::ParseGlobals(void) { + if (!LevelDown()) return false; - } + do { + if (CheckNodeName("colors")) { + ParseGlobalColors(); + } else if (CheckNodeName("variables")) { + ParseGlobalVariables(); + } else if (CheckNodeName("fonts")) { + ParseGlobalFonts(); + } else if (CheckNodeName("translations")) { + ParseTranslations(); + } + } while (NextNode()); return true; } bool cXmlParser::ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile) { this->skinSetup = skinSetup; - - if (!FileExists(xmlFile)) - return false; - if (ctxt == NULL) { - esyslog("skindesigner: Failed to allocate parser context"); - return false; - } - - doc = xmlCtxtReadFile(ctxt, xmlFile.c_str(), NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID); - - if (doc == NULL ) { - esyslog("skindesigner: ERROR: skin setup %s not parsed successfully.", xmlFile.c_str()); + if (! ReadXMLFile(xmlFile.c_str()) ) return false; - } - - root = xmlDocGetRootElement(doc); - - if (ctxt->valid == 0) { - esyslog("skindesigner: Failed to validate %s", xmlFile.c_str()); + if (! Validate() ) return false; - } - if (root == NULL) { + if (! SetDocument() ) return false; - } - if (xmlStrcmp(root->name, (const xmlChar *) "setup")) { + if (! CheckNodeName("setup") ) return false; - } - return true; } +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 +*********************************************************************/ -bool cXmlParser::ParseView(void) { - vector<pair<string, string> > rootAttribs; - ParseAttributes(root->properties, root, rootAttribs); - +bool cXmlParser::ParseSubView(void) { if (!view) return false; - view->SetParameters(rootAttribs); - - xmlNodePtr node = root->xmlChildrenNode; + cTemplateView *subView = new cTemplateViewMenu(); + view->AddSubView(NodeName(), subView); - while (node != NULL) { + vector<pair<string, string> > subViewAttribs = ParseAttributes(); + ValidateAttributes(NodeName(), subViewAttribs); + subView->SetParameters(subViewAttribs); - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (view->ValidSubView((const char*)node->name)) { - ParseSubView(node); - } else if (view->ValidViewElement((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs, true); - ParseViewElement(node->name, node->xmlChildrenNode, attribs); - } else if (view->ValidViewList((const char*)node->name)) { - ParseViewList(node); - } else if (view->ValidViewGrid((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - ParseGrid(node->xmlChildrenNode, attribs); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "tab")) { - ParseViewTab(node, view); + if (!LevelDown()) + return false; + do { + + if (subView->ValidViewElement(NodeName())) { + ParseViewElement(subView); + } else if (subView->ValidViewList(NodeName())) { + ParseViewList(subView); + } else if (CheckNodeName("tab")) { + ParseViewTab(subView); } else { return false; } - node = node->next; - } - + } while (NextNode()); + LevelUp(); return true; - -} -bool cXmlParser::ParsePluginView(string plugName, int templateNumber) { +} +void cXmlParser::ParseViewElement(cTemplateView *subView) { + if (!view) + return; + + const char *viewElement = NodeName(); + vector<stringpair> attributes = ParseAttributes(); + ValidateAttributes("viewelement", attributes); - cTemplateView *plugView = new cTemplateViewMenu(); - view->AddPluginView(plugName, templateNumber, plugView); + 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(); + } + if (subView) + subView->AddPixmap(viewElement, pix, attributes); + else + view->AddPixmap(viewElement, pix, attributes); + } while (NextNode()); + LevelUp(); +} - vector<pair<string, string> > attribs; - ParseAttributes(root->properties, root, attribs); +void cXmlParser::ParseViewList(cTemplateView *subView) { + if (!view) + return; + + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); - plugView->SetParameters(attribs); + cTemplateViewList *viewList = new cTemplateViewList(); + viewList->SetGlobals(globals); + viewList->SetParameters(attribs); - xmlNodePtr childNode = root->xmlChildrenNode; + if (!LevelDown()) + return; - while (childNode != NULL) { + do { + if (CheckNodeName("currentelement")) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } + cTemplateViewElement *currentElement = new cTemplateViewElement(); + vector<stringpair> attribsCur = ParseAttributes(); + ValidateAttributes(NodeName(), attribsCur); + currentElement->SetGlobals(globals); + currentElement->SetParameters(attribsCur); + 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(); + } + currentElement->AddPixmap(pix); + } while (NextNode()); + LevelUp(); + viewList->AddCurrentElement(currentElement); - if (plugView->ValidViewElement((const char*)childNode->name)) { - vector<pair<string, string> > attribs; - ParseViewElement(childNode->name, childNode->xmlChildrenNode, attribs, plugView); - } else if (plugView->ValidViewList((const char*)childNode->name)) { - ParseViewList(childNode, plugView); - } else if (!xmlStrcmp(childNode->name, (const xmlChar *) "tab")) { - ParseViewTab(childNode, plugView); - } else { - return false; + } 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); } - childNode = childNode->next; - } + } while (NextNode()); + LevelUp(); - return true; + if (subView) + subView->AddViewList(NodeName(), viewList); + else + view->AddViewList(NodeName(), viewList); } -bool cXmlParser::ParseGlobals(void) { - xmlNodePtr node = root->xmlChildrenNode; - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (!xmlStrcmp(node->name, (const xmlChar *) "colors")) { - ParseGlobalColors(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "variables")) { - ParseGlobalVariables(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "fonts")) { - ParseGlobalFonts(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "translations")) { - ParseTranslations(node->xmlChildrenNode); - node = node->next; - continue; - } - node = node->next; - } +void cXmlParser::ParseViewTab(cTemplateView *subView) { + if (!view || !subView) + return; - return true; + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + cTemplateViewTab *viewTab = new cTemplateViewTab(); + viewTab->SetGlobals(globals); + viewTab->SetParameters(attribs); + viewTab->SetScrolling(); + ParseFunctionCalls(viewTab); + subView->AddViewTab(viewTab); } -bool cXmlParser::ParseSkinSetup(string skin) { - xmlNodePtr node = root->xmlChildrenNode; +void cXmlParser::ParseGrid(void) { + if (!view) + return; + + vector<stringpair> attributes = ParseAttributes(); + ValidateAttributes(NodeName(), attributes); + + if (!LevelDown()) + return; + do { - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + if (!CheckNodeName("areacontainer") && !CheckNodeName("area") && !CheckNodeName("areascroll")) { + esyslog("skindesigner: invalid tag \"%s\" in grid", NodeName()); continue; } - if (!xmlStrcmp(node->name, (const xmlChar *) "menu")) { - ParseSetupMenu(node->xmlChildrenNode); - node = node->next; - continue; - } else if (!xmlStrcmp(node->name, (const xmlChar *) "translations")) { - ParseTranslations(node->xmlChildrenNode); - node = node->next; - continue; + cTemplatePixmapNode *pix = NULL; + if (CheckNodeName("area") || CheckNodeName("areascroll")) { + pix = ParseArea(); + } else { + pix = ParseAreaContainer(); } - node = node->next; - } - - return true; - + view->AddPixmapGrid(pix, attributes); + } while (NextNode()); + LevelUp(); } -void cXmlParser::DeleteDocument(void) { - if (doc) { - xmlFreeDoc(doc); - doc = NULL; +cTemplatePixmap *cXmlParser::ParseArea(void) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + + cTemplatePixmap *pix = new cTemplatePixmap(); + if (CheckNodeName("areascroll")) { + pix->SetScrolling(); } + pix->SetParameters(attribs); + ParseFunctionCalls(pix); + return pix; } -/********************************************************************* -* PRIVATE Functions -*********************************************************************/ +cTemplatePixmapContainer *cXmlParser::ParseAreaContainer(void) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); -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; + 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; } -void cXmlParser::ParseSetupMenu(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseFunctionCalls(cTemplatePixmap *pix) { + if (!view) return; - if (!skinSetup) + if (!LevelDown()) return; - - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; + 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); } - if (!xmlStrcmp(node->name, (const xmlChar *) "parameter")) { - ParseSetupParameter(node); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "submenu")) { - xmlAttrPtr attr = node->properties; - xmlChar *subMenuName = NULL; - xmlChar *subDisplayText = NULL; - while (NULL != attr) { - if (!xmlStrcmp(attr->name, (const xmlChar *) "name")) { - subMenuName = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "displaytext")) { - subDisplayText = xmlGetProp(node, attr->name); - } - attr = attr->next; - } - skinSetup->SetSubMenu(subMenuName, subDisplayText); - ParseSetupMenu(node->xmlChildrenNode); - if (subMenuName) - xmlFree(subMenuName); - if (subDisplayText) - xmlFree(subDisplayText); - } - node = node->next; - } - skinSetup->SubMenuDone(); + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseSetupParameter(xmlNodePtr node) { - if (!node) - return; - if (!skinSetup) +void cXmlParser::ParseLoopFunctionCalls(cTemplateLoopFunction *loopFunc) { + if (!view) return; - - xmlAttrPtr attr = node->properties; - if (attr == NULL) { + if (!LevelDown()) return; - } - 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); + do { + if (view->ValidFunction(NodeName())) { + vector<stringpair> attribs = ParseAttributes(); + ValidateAttributes(NodeName(), attribs); + loopFunc->AddFunction(NodeName(), attribs); + } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseGlobalColors(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalColors(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "color")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; + do { + if (!CheckNodeName("color")) { continue; } - xmlChar *colName = NULL; - xmlChar *colValue = NULL; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - colName = xmlGetProp(node, attr->name); - attr = attr->next; - } + string attributeName = "name"; + string colorName = ""; + string colorValue = ""; + bool ok = GetAttribute(attributeName, colorName); if (ok) { - colValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (colName && colValue) - InsertColor((const char*)colName, (const char*)colValue); + ok = GetNodeValue(colorValue); + if (ok) + InsertColor(colorName, colorValue); } - if (colName) - xmlFree(colName); - if (colValue) - xmlFree(colValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } void cXmlParser::InsertColor(string name, string value) { @@ -469,50 +442,29 @@ void cXmlParser::InsertColor(string name, string value) { globals->AddColor(name, colVal); } -void cXmlParser::ParseGlobalVariables(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalVariables(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + do { + if (!CheckNodeName("var")) { continue; } - if (xmlStrcmp(node->name, (const xmlChar *) "var")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; - continue; - } - xmlChar *varName = NULL; - xmlChar *varType = NULL; - xmlChar *varValue = NULL; - while (NULL != attr) { - if (!xmlStrcmp(attr->name, (const xmlChar *) "name")) { - varName = xmlGetProp(node, attr->name); - } else if (!xmlStrcmp(attr->name, (const xmlChar *) "type")) { - varType = xmlGetProp(node, attr->name); - } else { - attr = attr->next; - continue; - } - attr = attr->next; + 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); } - varValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (varName && varType && varValue) - InsertVariable((const char*)varName, (const char*)varType, (const char*)varValue); - if (varName) - xmlFree(varName); - if (varType) - xmlFree(varType); - if (varValue) - xmlFree(varValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } void cXmlParser::InsertVariable(string name, string type, string value) { @@ -526,467 +478,146 @@ void cXmlParser::InsertVariable(string name, string type, string value) { } } -void cXmlParser::ParseGlobalFonts(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseGlobalFonts(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "font")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; + do { + if (!CheckNodeName("font")) { continue; } - xmlChar *fontName = NULL; - xmlChar *fontValue = NULL; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - fontName = xmlGetProp(node, attr->name); - attr = attr->next; - } + string attributeName = "name"; + string fontName = ""; + string fontValue = ""; + + bool ok = GetAttribute(attributeName, fontName); if (ok) { - fontValue = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (fontName && fontValue) { - string fN = (const char*)fontName; - string fV = (const char*)fontValue; - globals->AddFont(fN, fV); + ok = GetNodeValue(fontValue); + if (ok) { + globals->AddFont(fontName, fontValue); } } - if (fontName) - xmlFree(fontName); - if (fontValue) - xmlFree(fontValue); - node = node->next; - } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseTranslations(xmlNodePtr node) { - if (!node) +void cXmlParser::ParseTranslations(void) { + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "token")) { - node = node->next; - continue; - } - xmlAttrPtr attr = node->properties; - if (attr == NULL) { - node = node->next; - continue; - } - xmlChar *tokenName; - bool ok = false; - while (NULL != attr) { - if (xmlStrcmp(attr->name, (const xmlChar *) "name")) { - attr = attr->next; - continue; - } - ok = true; - tokenName = xmlGetProp(node, attr->name); - attr = attr->next; - } - if (!ok) - continue; - map < string, string > tokenTranslations; - xmlNodePtr nodeTrans = node->xmlChildrenNode; - while (nodeTrans != NULL) { - if (nodeTrans->type != XML_ELEMENT_NODE) { - nodeTrans = nodeTrans->next; - continue; - } - xmlChar *language = NULL; - if (xmlStrcmp(nodeTrans->name, (const xmlChar *) "trans")) { - nodeTrans = nodeTrans->next; - continue; - } - xmlAttrPtr attrTrans = nodeTrans->properties; - if (attrTrans == NULL) { - nodeTrans = nodeTrans->next; - continue; - } - ok = false; - - while (NULL != attrTrans) { - if (!ok && xmlStrcmp(attrTrans->name, (const xmlChar *) "lang")) { - attrTrans = attrTrans->next; - continue; - } - ok = true; - language = xmlGetProp(nodeTrans, attrTrans->name); - attrTrans = attrTrans->next; - } - if (!ok) - continue; - xmlChar *value = NULL; - value = xmlNodeListGetString(doc, nodeTrans->xmlChildrenNode, 1); - if (language && value) - tokenTranslations.insert(pair<string, string>((const char*)language, (const char*)value)); - if (language) - xmlFree(language); - if (value) - xmlFree(value); - nodeTrans = nodeTrans->next; - } - if (globals) { - globals->AddTranslation((const char*)tokenName, tokenTranslations); - } else if (skinSetup) { - skinSetup->SetTranslation((const char*)tokenName, tokenTranslations); - } - xmlFree(tokenName); - node = node->next; - } -} - -bool cXmlParser::ParseSubView(xmlNodePtr node) { - if (!node) - return false; - - if (!view) - return false; - - cTemplateView *subView = new cTemplateViewMenu(); - view->AddSubView((const char*)node->name, subView); - - vector<pair<string, string> > subViewAttribs; - ParseAttributes(node->properties, node, subViewAttribs); - - subView->SetParameters(subViewAttribs); - - xmlNodePtr childNode = node->xmlChildrenNode; - - while (childNode != NULL) { - - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; + do { + if (!CheckNodeName("token")) { continue; } + string attributeName = "name"; + string tokenName = ""; - if (subView->ValidViewElement((const char*)childNode->name)) { - xmlAttrPtr attr = childNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, childNode, attribs, true); - ParseViewElement(childNode->name, childNode->xmlChildrenNode, attribs, subView); - } else if (subView->ValidViewList((const char*)childNode->name)) { - ParseViewList(childNode, subView); - } else if (!xmlStrcmp(childNode->name, (const xmlChar *) "tab")) { - ParseViewTab(childNode, subView); - } else { - return false; - } - - childNode = childNode->next; - } - - - - return true; - -} - -void cXmlParser::ParseViewElement(const xmlChar * viewElement, xmlNodePtr node, vector<pair<string, string> > &attributes, cTemplateView *subView) { - if (!node) - return; - - if (!view) - return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + if (!GetAttribute(attributeName, tokenName)) continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "area") && xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - esyslog("skindesigner: invalid tag \"%s\"", node->name); - node = node->next; + if (!LevelDown()) continue; - } - - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - - cTemplatePixmap *pix = new cTemplatePixmap(); - if (!xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - pix->SetParameters(attribs); - ParseFunctionCalls(node->xmlChildrenNode, pix); - if (subView) - subView->AddPixmap((const char*)viewElement, pix, attributes); - else - view->AddPixmap((const char*)viewElement, pix, attributes); - - node = node->next; - } -} - -void cXmlParser::ParseViewList(xmlNodePtr parentNode, cTemplateView *subView) { - if (!parentNode || !view) - return; - - xmlAttrPtr attr = parentNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, parentNode, attribs); - - cTemplateViewList *viewList = new cTemplateViewList(); - viewList->SetGlobals(globals); - viewList->SetParameters(attribs); - xmlNodePtr node = parentNode->xmlChildrenNode; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - - if (!xmlStrcmp(node->name, (const xmlChar *) "currentelement")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) + stringmap tokenTranslations; + do { + if (!CheckNodeName("trans")) { continue; - cTemplateViewElement *currentElement = new cTemplateViewElement(); - xmlAttrPtr attrCur = node->properties; - vector<pair<string, string> > attribsCur; - ParseAttributes(attrCur, node, attribsCur); - currentElement->SetGlobals(globals); - currentElement->SetParameters(attribsCur); - while (childNode != NULL) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } - if ((!xmlStrcmp(childNode->name, (const xmlChar *) "area")) || (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll"))) { - xmlAttrPtr attrPix = childNode->properties; - vector<pair<string, string> > attribsPix; - ParseAttributes(attrPix, childNode, attribsPix); - cTemplatePixmap *pix = new cTemplatePixmap(); - pix->SetParameters(attribsPix); - ParseFunctionCalls(childNode->xmlChildrenNode, pix); - if (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - currentElement->AddPixmap(pix); - } - childNode = childNode->next; } - viewList->AddCurrentElement(currentElement); - } else if (!xmlStrcmp(node->name, (const xmlChar *) "listelement")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) + string attributeName = "lang"; + string language = ""; + if (!GetAttribute(attributeName, language)) continue; - cTemplateViewElement *listElement = new cTemplateViewElement(); - xmlAttrPtr attrList = node->properties; - vector<pair<string, string> > attribsList; - ParseAttributes(attrList, node, attribsList); - listElement->SetGlobals(globals); - listElement->SetParameters(attribsList); - while (childNode != NULL) { - if (childNode->type != XML_ELEMENT_NODE) { - childNode = childNode->next; - continue; - } - if ((!xmlStrcmp(childNode->name, (const xmlChar *) "area")) || (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll"))) { - xmlAttrPtr attrPix = childNode->properties; - vector<pair<string, string> > attribsPix; - ParseAttributes(attrPix, childNode, attribsPix); - cTemplatePixmap *pix = new cTemplatePixmap(); - pix->SetParameters(attribsPix); - ParseFunctionCalls(childNode->xmlChildrenNode, pix); - if (!xmlStrcmp(childNode->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - listElement->AddPixmap(pix); - } - childNode = childNode->next; - } - viewList->AddListElement(listElement); - } else { - node = node->next; - continue; - } - node = node->next; - } - if (subView) - subView->AddViewList((const char*)parentNode->name, viewList); - else - view->AddViewList((const char*)parentNode->name, viewList); -} - -void cXmlParser::ParseViewTab(xmlNodePtr parentNode, cTemplateView *subView) { - if (!parentNode || !view || !subView) - return; - - xmlAttrPtr attr = parentNode->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, parentNode, attribs); - - cTemplateViewTab *viewTab = new cTemplateViewTab(); - viewTab->SetGlobals(globals); - viewTab->SetParameters(attribs); - viewTab->SetScrolling(); - xmlNodePtr node = parentNode->xmlChildrenNode; - ParseFunctionCalls(node, viewTab); - - subView->AddViewTab(viewTab); -} - -void cXmlParser::ParseGrid(xmlNodePtr node, vector<pair<string, string> > &attributes) { - if (!node) - return; - - if (!view) - return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } + string translation = ""; + if (!GetNodeValue(translation)) + continue; + tokenTranslations.insert(stringpair(language, translation)); + } while (NextNode()); + LevelUp(); - if (xmlStrcmp(node->name, (const xmlChar *) "area") && xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - esyslog("skindesigner: invalid tag \"%s\"", node->name); - node = node->next; - continue; + if (globals) { + globals->AddTranslation(tokenName, tokenTranslations); + } else if (skinSetup) { + skinSetup->SetTranslation(tokenName, tokenTranslations); } - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - - cTemplatePixmap *pix = new cTemplatePixmap(); - if (!xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { - pix->SetScrolling(); - } - pix->SetParameters(attribs); - ParseFunctionCalls(node->xmlChildrenNode, pix); - view->AddPixmapGrid(pix, attributes); - - node = node->next; - } + } while (NextNode()); + LevelUp(); } -void cXmlParser::ParseFunctionCalls(xmlNodePtr node, cTemplatePixmap *pix) { - if (!node) +void cXmlParser::ParseSetupMenu(void) { + if (!skinSetup) return; - - if (!view) + if (!LevelDown()) return; - - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - - if (!xmlStrcmp(node->name, (const xmlChar *) "loop")) { - xmlNodePtr childNode = node->xmlChildrenNode; - if (!childNode) - continue; - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - cTemplateLoopFunction *loopFunc = new cTemplateLoopFunction(); - loopFunc->SetParameters(attribs); - ParseLoopFunctionCalls(childNode, loopFunc); - pix->AddLoopFunction(loopFunc); - node = node->next; - } else if (view->ValidFunction((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - pix->AddFunction((const char*)node->name, attribs); - node = node->next; - } else { - node = node->next; - continue; + 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(); } - - } + } while (NextNode()); + skinSetup->SubMenuDone(); + LevelUp(); } -void cXmlParser::ParseLoopFunctionCalls(xmlNodePtr node, cTemplateLoopFunction *loopFunc) { - if (!node) - return; - - if (!view) +void cXmlParser::ParseSetupParameter(void) { + if (!skinSetup) return; + 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 = ""; + + GetAttribute(attributeType, paramType); + GetAttribute(attributeName, paramName); + GetAttribute(attributeDisplayText, paramDisplayText); + GetAttribute(attributeMin, paramMin); + GetAttribute(attributeMax, paramMax); + GetNodeValue(paramValue); - while (node != NULL) { - - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - if (view->ValidFunction((const char*)node->name)) { - xmlAttrPtr attr = node->properties; - vector<pair<string, string> > attribs; - ParseAttributes(attr, node, attribs); - loopFunc->AddFunction((const char*)node->name, attribs); - node = node->next; - } else { - node = node->next; - continue; - } - - } + skinSetup->SetParameter(paramType, paramName, paramDisplayText, paramMin, paramMax, paramValue); } -bool cXmlParser::ParseAttributes(xmlAttrPtr attr, xmlNodePtr node, vector<pair<string, string> > &attribs, bool isViewElement) { - if (attr == NULL) { - return false; - } - - if (!view) - return false; - - while (NULL != attr) { - - string name = (const char*)attr->name; - xmlChar *value = NULL; - value = xmlGetProp(node, attr->name); - if (!view->ValidAttribute(isViewElement ? "viewelement" : (const char*)node->name, (const char*)attr->name)) { - esyslog("skindesigner: unknown attribute %s in %s", (const char*)attr->name, (const char*)node->name); - attr = attr->next; - if (value) - xmlFree(value); - continue; +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; + } } - if (value) - attribs.push_back(pair<string, string>((const char*)attr->name, (const char*)value)); - attr = attr->next; - if (value) - xmlFree(value); } - return true; } -void cXmlParser::InitLibXML() { - xmlInitParser(); +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; } -void cXmlParser::CleanupLibXML() { - xmlCleanupParser(); -} diff --git a/libtemplate/xmlparser.h b/libtemplate/xmlparser.h index 58d4e91..3dd0705 100644 --- a/libtemplate/xmlparser.h +++ b/libtemplate/xmlparser.h @@ -8,11 +8,8 @@ #include <vector> #include <map> #include <set> -#include <libxml/parser.h> -#include <libxml/tree.h> -#include <libxml/xmlerror.h> #include <vdr/plugin.h> - +#include "../libcore/libxmlwrapper.h" #include "templateview.h" #include "templateviewlist.h" #include "templateviewgrid.h" @@ -23,45 +20,49 @@ using namespace std; // --- cXmlParser ------------------------------------------------------------- -class cXmlParser { +class cXmlParser : public cLibXMLWrapper { private: cTemplateView *view; cGlobals *globals; cSkinSetup *skinSetup; - xmlParserCtxtPtr ctxt; - xmlDocPtr doc; - xmlNodePtr root; - string GetPath(string xmlFile); - void ParseSetupMenu(xmlNodePtr node); - void ParseSetupParameter(xmlNodePtr node); - void ParseGlobalColors(xmlNodePtr node); + //parsing views + bool ParseSubView(void); + void ParseViewElement(cTemplateView *subView = NULL); + void ParseViewList(cTemplateView *subView = NULL); + void ParseViewTab(cTemplateView *subView); + void ParseGrid(void); + cTemplatePixmap *ParseArea(void); + cTemplatePixmapContainer *ParseAreaContainer(void); + void ParseFunctionCalls(cTemplatePixmap *pix); + void ParseLoopFunctionCalls(cTemplateLoopFunction *loopFunc); + //parsing globals + void ParseGlobalColors(void); void InsertColor(string name, string value); - void ParseGlobalVariables(xmlNodePtr node); + void ParseGlobalVariables(void); void InsertVariable(string name, string type, string value); - void ParseGlobalFonts(xmlNodePtr node); - void ParseTranslations(xmlNodePtr node); - bool ParseSubView(xmlNodePtr node); - void ParseViewElement(const xmlChar * viewElement, xmlNodePtr node, vector<pair<string, string> > &attributes, cTemplateView *subView = NULL); - void ParseViewList(xmlNodePtr parentNode, cTemplateView *subView = NULL); - void ParseViewTab(xmlNodePtr parentNode, cTemplateView *subView); - void ParseGrid(xmlNodePtr node, vector<pair<string, string> > &attributes); - void ParseFunctionCalls(xmlNodePtr node, cTemplatePixmap *pix); - void ParseLoopFunctionCalls(xmlNodePtr node, cTemplateLoopFunction *loopFunc); - bool ParseAttributes(xmlAttrPtr attr, xmlNodePtr node, vector<pair<string, string> > &attribs, bool isViewElement = false); + void ParseGlobalFonts(void); + void ParseTranslations(void); + //parsing skin setup + void ParseSetupMenu(void); + void ParseSetupParameter(void); + //helpers + void ValidateAttributes(const char *nodeName, vector<stringpair> &attributes); + string GetPath(string xmlFile); public: cXmlParser(void); virtual ~cXmlParser(void); + //reading views bool ReadView(cTemplateView *view, string xmlFile); - bool ReadPluginView(string plugName, int templateNumber, string templateName); - bool ReadGlobals(cGlobals *globals, string xmlFile, bool mandatory); - bool ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile); bool ParseView(void); + //reading plugin views + bool ReadPluginView(string plugName, int templateNumber, string templateName); bool ParsePluginView(string plugName, int templateNumber); + //reading globals + bool ReadGlobals(cGlobals *globals, string xmlFile); bool ParseGlobals(void); + //reading skin setups + bool ReadSkinSetup(cSkinSetup *skinSetup, string xmlFile); bool ParseSkinSetup(string skin); - void DeleteDocument(void); - static void InitLibXML(); - static void CleanupLibXML(); }; #endif //__XMLPARSER_H |