vdr-plugin-skindesigner/libtemplate/template.c

323 lines
11 KiB
C
Raw Permalink Normal View History

2014-09-27 09:25:14 +02:00
#include "template.h"
#include "xmlparser.h"
#include "../config.h"
// --- cTemplate -------------------------------------------------------------
2015-02-12 18:50:58 +01:00
cTemplate::cTemplate(eViewType viewType, string pluginName, int viewID) {
2014-09-27 09:25:14 +02:00
globals = NULL;
rootView = NULL;
this->viewType = viewType;
2015-02-12 18:50:58 +01:00
CreateView(pluginName, viewID);
2014-09-27 09:25:14 +02:00
}
cTemplate::~cTemplate() {
2015-06-18 10:21:43 +02:00
if (rootView)
delete rootView;
2014-09-27 09:25:14 +02:00
}
/*******************************************************************
* Public Functions
*******************************************************************/
2015-02-12 18:50:58 +01:00
bool cTemplate::ReadFromXML(string xmlfile) {
string xmlFile;
2014-09-27 09:25:14 +02:00
switch (viewType) {
case vtDisplayChannel:
xmlFile = "displaychannel.xml";
break;
case vtDisplayMenu:
xmlFile = "displaymenu.xml";
break;
case vtDisplayMessage:
xmlFile = "displaymessage.xml";
break;
case vtDisplayReplay:
xmlFile = "displayreplay.xml";
break;
case vtDisplayVolume:
xmlFile = "displayvolume.xml";
break;
case vtDisplayAudioTracks:
xmlFile = "displayaudiotracks.xml";
break;
2015-02-12 18:50:58 +01:00
case vtDisplayPlugin:
xmlFile = xmlfile;
break;
2014-09-27 09:25:14 +02:00
default:
return false;
}
cXmlParser parser;
if (!parser.ReadView(rootView, xmlFile)) {
return false;
}
if (!parser.ParseView()) {
return false;
}
2015-03-12 17:28:35 +01:00
//read additional plugin menu templates
2014-11-15 09:47:22 +01:00
bool ok = true;
if (viewType == vtDisplayMenu) {
2015-02-12 18:50:58 +01:00
config.InitPluginMenuIterator();
2014-11-15 09:47:22 +01:00
map <int,string> *plugTemplates = NULL;
string plugName;
while ( plugTemplates = config.GetPluginTemplates(plugName) ) {
for (map <int,string>::iterator it = plugTemplates->begin(); it != plugTemplates->end(); it++) {
int templateNumber = it->first;
stringstream templateName;
templateName << "plug-" << plugName << "-" << it->second.c_str();
if (parser.ReadPluginView(plugName, templateNumber, templateName.str())) {
ok = parser.ParsePluginView(plugName, templateNumber);
2015-05-30 16:43:59 +02:00
} else {
dsyslog("skindesigner: template %s for plugin %s not available", templateName.str().c_str(), plugName.c_str());
2014-11-15 09:47:22 +01:00
}
}
}
}
return ok;
2014-09-27 09:25:14 +02:00
}
void cTemplate::SetGlobals(cGlobals *globals) {
this->globals = globals;
rootView->SetGlobals(globals);
}
void cTemplate::Translate(void) {
rootView->Translate();
}
void cTemplate::PreCache(void) {
rootView->PreCache(false);
}
vector< pair<string, int> > cTemplate::GetUsedFonts(void) {
vector< pair<string, int> > usedFonts;
GetUsedFonts(rootView, usedFonts);
rootView->InitSubViewIterator();
cTemplateView *subView = NULL;
while(subView = rootView->GetNextSubView()) {
GetUsedFonts(subView, usedFonts);
}
return usedFonts;
}
void cTemplate::CacheImages(void) {
CacheImages(rootView);
rootView->InitSubViewIterator();
cTemplateView *subView = NULL;
while(subView = rootView->GetNextSubView()) {
CacheImages(subView);
}
}
2015-03-12 17:28:35 +01:00
bool cTemplate::SetSubViews(string plugName, int viewID) {
map <int,string> subViews = config.GetPluginSubViews(plugName, viewID);
if (subViews.size() == 0) {
return true;
}
for (map<int,string>::iterator it = subViews.begin(); it != subViews.end(); it ++) {
int subViewID = it->first;
stringstream templateName;
templateName << "plug-" << plugName << "-" << it->second;
string subViewTemplate = templateName.str();
cTemplateView *plgTemplateView = new cTemplateViewPlugin(plugName, subViewID);
plgTemplateView->SetGlobals(globals);
cXmlParser parser;
if (!parser.ReadView(plgTemplateView, subViewTemplate)) {
esyslog("skindesigner: error reading plugin %s template", plugName.c_str());
delete plgTemplateView;
return false;
}
if (!parser.ParseView()) {
esyslog("skindesigner: error reading plugin %s template", plugName.c_str());
delete plgTemplateView;
return false;
}
stringstream svid;
svid << subViewID;
rootView->AddSubView(svid.str(), plgTemplateView);
}
return true;
}
2014-09-27 09:25:14 +02:00
void cTemplate::Debug(void) {
rootView->Debug();
}
/*******************************************************************
* Private Functions
*******************************************************************/
2015-02-12 18:50:58 +01:00
void cTemplate::CreateView(string pluginName, int viewID) {
2014-09-27 09:25:14 +02:00
switch (viewType) {
case vtDisplayChannel:
rootView = new cTemplateViewChannel();
break;
case vtDisplayMenu:
rootView = new cTemplateViewMenu();
break;
case vtDisplayReplay:
rootView = new cTemplateViewReplay();
break;
case vtDisplayVolume:
rootView = new cTemplateViewVolume();
break;
case vtDisplayAudioTracks:
rootView = new cTemplateViewAudioTracks();
break;
case vtDisplayMessage:
rootView = new cTemplateViewMessage();
2015-02-12 18:50:58 +01:00
break;
case vtDisplayPlugin:
rootView = new cTemplateViewPlugin(pluginName, viewID);
break;
2014-09-27 09:25:14 +02:00
default:
esyslog("skindesigner: unknown view %d", viewType);
}
}
void cTemplate::GetUsedFonts(cTemplateView *view, vector< pair<string, int> > &usedFonts) {
//used fonts in viewElements
view->InitViewElementIterator();
cTemplateViewElement *viewElement = NULL;
while(viewElement = view->GetNextViewElement()) {
viewElement->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
cTemplatePixmap *pix = NULL;
while(pix = viewElement->GetNextPixmap()) {
pix->InitFunctionIterator();
2014-09-27 09:25:14 +02:00
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
usedFonts.push_back(pair<string,int>(func->GetFontName(), func->GetNumericParameter(ptFontSize)));
}
}
}
}
//used fonts in viewLists pixmaps
view->InitViewListIterator();
cTemplateViewList *viewList = NULL;
while(viewList = view->GetNextViewList()) {
viewList->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
cTemplatePixmap *pix = NULL;
while(pix = viewList->GetNextPixmap()) {
pix->InitFunctionIterator();
2014-09-27 09:25:14 +02:00
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
usedFonts.push_back(pair<string,int>(func->GetFontName(), func->GetNumericParameter(ptFontSize)));
}
}
}
cTemplateViewElement *listElement = viewList->GetListElement();
listElement->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
while(pix = listElement->GetNextPixmap()) {
pix->InitFunctionIterator();
2014-09-27 09:25:14 +02:00
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
usedFonts.push_back(pair<string,int>(func->GetFontName(), func->GetNumericParameter(ptFontSize)));
}
}
}
}
//used fonts in viewTabs
view->InitViewTabIterator();
cTemplateViewTab *viewTab = NULL;
while(viewTab = view->GetNextViewTab()) {
viewTab->InitFunctionIterator();
2014-09-27 09:25:14 +02:00
cTemplateFunction *func = NULL;
while(func = viewTab->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
usedFonts.push_back(pair<string,int>(func->GetFontName(), func->GetNumericParameter(ptFontSize)));
}
}
}
}
void cTemplate::CacheImages(cTemplateView *view) {
//used images in viewElements
view->InitViewElementIterator();
cTemplateViewElement *viewElement = NULL;
while(viewElement = view->GetNextViewElement()) {
viewElement->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
cTemplatePixmap *pix = NULL;
while(pix = viewElement->GetNextPixmap()) {
2014-11-25 14:33:59 +01:00
CachePixmapImages(pix);
2014-09-27 09:25:14 +02:00
}
}
//used images in viewLists pixmaps
view->InitViewListIterator();
cTemplateViewList *viewList = NULL;
while(viewList = view->GetNextViewList()) {
viewList->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
cTemplatePixmap *pix = NULL;
while(pix = viewList->GetNextPixmap()) {
2014-11-25 14:33:59 +01:00
CachePixmapImages(pix);
2014-09-27 09:25:14 +02:00
}
cTemplateViewElement *listElement = viewList->GetListElement();
listElement->InitPixmapIterator();
2014-09-27 09:25:14 +02:00
while(pix = listElement->GetNextPixmap()) {
2014-11-25 14:33:59 +01:00
CachePixmapImages(pix);
}
cTemplateViewElement *currentElement = viewList->GetListElementCurrent();
if (!currentElement) {
continue;
}
currentElement->InitPixmapIterator();
2014-11-25 14:33:59 +01:00
while(pix = currentElement->GetNextPixmap()) {
CachePixmapImages(pix);
2014-09-27 09:25:14 +02:00
}
}
2014-11-25 14:33:59 +01:00
//used images in viewTabs
2014-09-27 09:25:14 +02:00
view->InitViewTabIterator();
cTemplateViewTab *viewTab = NULL;
while(viewTab = view->GetNextViewTab()) {
2014-11-25 14:33:59 +01:00
CachePixmapImages(viewTab);
2014-09-27 09:25:14 +02:00
}
}
2014-11-25 14:33:59 +01:00
void cTemplate::CachePixmapImages(cTemplatePixmap *pix) {
pix->InitFunctionIterator();
2014-11-25 14:33:59 +01:00
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawImage) {
CacheImage(func);
}
}
}
2014-09-27 09:25:14 +02:00
void cTemplate::CacheImage(cTemplateFunction *func) {
eImageType imgType = (eImageType)func->GetNumericParameter(ptImageType);
int width = func->GetNumericParameter(ptWidth);
int height = func->GetNumericParameter(ptHeight);
switch (imgType) {
case itIcon:
case itMenuIcon: {
string path = func->GetParameter(ptPath);
imgCache->CacheIcon(imgType, path, width, height);
break; }
case itChannelLogo: {
string doCache = func->GetParameter(ptCache);
if (!doCache.compare("true")) {
imgCache->CacheLogo(width, height);
}
break; }
case itSkinPart: {
string path = func->GetParameter(ptPath);
imgCache->CacheSkinpart(path, width, height);
break; }
default:
break;
}
}