2014-09-27 09:25:14 +02:00
|
|
|
#include "designer.h"
|
|
|
|
#include "libcore/helpers.h"
|
|
|
|
|
2014-10-03 15:54:23 +02:00
|
|
|
cSkinDesigner::cSkinDesigner(string skin) : cSkin(skin.c_str(), &::Theme) {
|
|
|
|
init = true;
|
|
|
|
this->skin = skin;
|
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
backupSkin = NULL;
|
|
|
|
useBackupSkin = false;
|
2014-10-18 10:05:32 +02:00
|
|
|
|
2014-10-03 15:54:23 +02:00
|
|
|
globals = NULL;
|
|
|
|
channelTemplate = NULL;
|
|
|
|
menuTemplate = NULL;
|
|
|
|
messageTemplate = NULL;
|
|
|
|
replayTemplate = NULL;
|
|
|
|
volumeTemplate = NULL;
|
|
|
|
audiotracksTemplate = NULL;
|
2014-10-18 10:05:32 +02:00
|
|
|
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
|
|
|
|
2014-10-03 15:54:23 +02:00
|
|
|
dsyslog("skindesigner: skin %s started", skin.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDesigner::~cSkinDesigner(void) {
|
|
|
|
if (globals)
|
|
|
|
delete globals;
|
|
|
|
DeleteTemplates();
|
|
|
|
if (backupSkin)
|
|
|
|
delete backupSkin;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *cSkinDesigner::Description(void) {
|
|
|
|
return skin.c_str();
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayChannel *cSkinDesigner::DisplayChannel(bool WithInfo) {
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayChannel *displayChannel = NULL;
|
|
|
|
if (!useBackupSkin) {
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-27 09:25:14 +02:00
|
|
|
displayChannel = new cSDDisplayChannel(channelTemplate, WithInfo);
|
|
|
|
} else {
|
|
|
|
displayChannel = backupSkin->DisplayChannel(WithInfo);
|
|
|
|
}
|
|
|
|
return displayChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDisplayMenu *cSkinDesigner::DisplayMenu(void) {
|
|
|
|
if (!useBackupSkin) {
|
2014-11-15 09:47:22 +01:00
|
|
|
cSDDisplayMenu *displayMenu = NULL;
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-28 10:47:54 +02:00
|
|
|
firstDisplay = false;
|
2014-09-27 09:25:14 +02:00
|
|
|
displayMenu = new cSDDisplayMenu(menuTemplate);
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = displayMenu;
|
|
|
|
return displayMenu;
|
2014-09-27 09:25:14 +02:00
|
|
|
} else {
|
2014-11-15 09:47:22 +01:00
|
|
|
cSkinDisplayMenu *displayMenu = backupSkin->DisplayMenu();
|
|
|
|
currentMenu = NULL;
|
|
|
|
return displayMenu;
|
2014-09-27 09:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDisplayReplay *cSkinDesigner::DisplayReplay(bool ModeOnly) {
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayReplay *displayReplay = NULL;
|
|
|
|
if (!useBackupSkin) {
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-27 09:25:14 +02:00
|
|
|
displayReplay = new cSDDisplayReplay(replayTemplate, ModeOnly);
|
|
|
|
} else {
|
|
|
|
displayReplay = backupSkin->DisplayReplay(ModeOnly);
|
|
|
|
}
|
|
|
|
return displayReplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDisplayVolume *cSkinDesigner::DisplayVolume(void) {
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayVolume *displayVolume = NULL;
|
|
|
|
if (!useBackupSkin) {
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-27 09:25:14 +02:00
|
|
|
displayVolume = new cSDDisplayVolume(volumeTemplate);
|
|
|
|
} else {
|
|
|
|
displayVolume = backupSkin->DisplayVolume();
|
|
|
|
}
|
|
|
|
return displayVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDisplayTracks *cSkinDesigner::DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks) {
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayTracks *displayTracks = NULL;
|
|
|
|
if (!useBackupSkin) {
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-27 09:25:14 +02:00
|
|
|
displayTracks = new cSDDisplayTracks(audiotracksTemplate, Title, NumTracks, Tracks);
|
|
|
|
} else {
|
|
|
|
displayTracks = backupSkin->DisplayTracks(Title, NumTracks, Tracks);
|
|
|
|
}
|
|
|
|
return displayTracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
cSkinDisplayMessage *cSkinDesigner::DisplayMessage(void) {
|
2014-11-15 09:47:22 +01:00
|
|
|
currentMenu = NULL;
|
2014-09-27 09:25:14 +02:00
|
|
|
cSkinDisplayMessage *displayMessage = NULL;
|
|
|
|
if (!useBackupSkin) {
|
2014-10-18 10:05:32 +02:00
|
|
|
Init();
|
2014-09-27 09:25:14 +02:00
|
|
|
displayMessage = new cSDDisplayMessage(messageTemplate);
|
|
|
|
} else {
|
|
|
|
displayMessage = backupSkin->DisplayMessage();
|
|
|
|
}
|
|
|
|
return displayMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSkinDesigner::Reload(void) {
|
|
|
|
dsyslog("skindesigner: forcing full reload of templates");
|
|
|
|
if (cOsd::IsOpen()) {
|
|
|
|
esyslog("skindesigner: OSD is open, close first!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeleteTemplates();
|
|
|
|
cStopWatch watch;
|
|
|
|
bool ok = LoadTemplates();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error during loading of templates - using LCARS as backup");
|
|
|
|
if (!backupSkin)
|
|
|
|
backupSkin = new cSkinLCARS();
|
|
|
|
useBackupSkin = true;
|
|
|
|
} else {
|
|
|
|
CacheTemplates();
|
|
|
|
useBackupSkin = false;
|
|
|
|
watch.Stop("templates reloaded and cache created");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSkinDesigner::ListAvailableFonts(void) {
|
|
|
|
fontManager->ListAvailableFonts();
|
|
|
|
}
|
|
|
|
|
2014-10-11 16:31:39 +02:00
|
|
|
bool cSkinDesigner::SetCustomToken(string option) {
|
|
|
|
splitstring s(option.c_str());
|
|
|
|
vector<string> flds = s.split('=', 0);
|
|
|
|
|
|
|
|
if (flds.size() != 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string key = trim(flds[0]);
|
|
|
|
string val = trim(flds[1]);
|
|
|
|
|
|
|
|
if (!globals)
|
|
|
|
return true;
|
|
|
|
|
2014-12-19 15:39:21 +01:00
|
|
|
if (isNumber(val)) {
|
|
|
|
map<string, int>::iterator hit = globals->customIntTokens.find(key);
|
|
|
|
if (hit != globals->customIntTokens.end()) {
|
|
|
|
globals->customIntTokens.erase(key);
|
|
|
|
}
|
|
|
|
globals->customIntTokens.insert(pair<string,int>(key, atoi(val.c_str())));
|
|
|
|
} else {
|
|
|
|
map<string, string>::iterator hit = globals->customStringTokens.find(key);
|
|
|
|
if (hit != globals->customStringTokens.end()) {
|
|
|
|
globals->customStringTokens.erase(key);
|
|
|
|
}
|
|
|
|
globals->customStringTokens.insert(pair<string,string>(key, val));
|
2014-10-11 16:31:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSkinDesigner::ListCustomTokens(void) {
|
|
|
|
if (!globals)
|
|
|
|
return;
|
|
|
|
|
2014-12-19 15:39:21 +01:00
|
|
|
for (map<string, string>::iterator it = globals->customStringTokens.begin(); it != globals->customStringTokens.end(); it++) {
|
|
|
|
dsyslog("skindesigner: custom string token \"%s\" = \"%s\"", (it->first).c_str(), (it->second).c_str());
|
|
|
|
}
|
|
|
|
for (map<string, int>::iterator it = globals->customIntTokens.begin(); it != globals->customIntTokens.end(); it++) {
|
|
|
|
dsyslog("skindesigner: custom int token \"%s\" = \"%d\"", (it->first).c_str(), it->second);
|
2014-10-11 16:31:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
/*********************************************************************************
|
|
|
|
* PRIVATE FUNCTIONS
|
|
|
|
*********************************************************************************/
|
2014-10-18 10:05:32 +02:00
|
|
|
void cSkinDesigner::Init(void) {
|
2014-11-22 12:19:13 +01:00
|
|
|
if (init || config.OsdSizeChanged() || config.SkinChanged() || config.OsdLanguageChanged()) {
|
2014-10-18 10:05:32 +02:00
|
|
|
|
|
|
|
if (init) {
|
|
|
|
config.SetSkin();
|
|
|
|
config.SetOSDSize();
|
2014-10-18 10:28:38 +02:00
|
|
|
config.SetOSDFonts();
|
2014-10-18 10:05:32 +02:00
|
|
|
}
|
|
|
|
dsyslog("skindesigner: initializing skin %s", skin.c_str());
|
|
|
|
|
|
|
|
config.CheckDecimalPoint();
|
|
|
|
|
|
|
|
if (fontManager)
|
|
|
|
delete fontManager;
|
|
|
|
fontManager = new cFontManager();
|
|
|
|
if (imgCache)
|
|
|
|
delete imgCache;
|
|
|
|
imgCache = new cImageCache();
|
|
|
|
imgCache->SetPathes();
|
|
|
|
|
|
|
|
cStopWatch watch;
|
|
|
|
bool ok = LoadTemplates();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error during loading of templates - using LCARS as backup");
|
|
|
|
backupSkin = new cSkinLCARS();
|
|
|
|
useBackupSkin = true;
|
|
|
|
} else {
|
|
|
|
CacheTemplates();
|
|
|
|
watch.Stop("templates loaded and cache created");
|
|
|
|
}
|
|
|
|
init = false;
|
2014-10-18 10:28:38 +02:00
|
|
|
} else if (config.OsdFontsChanged()) {
|
|
|
|
dsyslog("skindesigner: reloading fonts");
|
|
|
|
if (fontManager)
|
|
|
|
delete fontManager;
|
|
|
|
fontManager = new cFontManager();
|
|
|
|
cStopWatch watch;
|
|
|
|
bool ok = LoadTemplates();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error during loading of templates - using LCARS as backup");
|
|
|
|
backupSkin = new cSkinLCARS();
|
|
|
|
useBackupSkin = true;
|
|
|
|
} else {
|
|
|
|
CacheTemplates();
|
|
|
|
watch.Stop("templates loaded and cache created");
|
|
|
|
}
|
2014-10-18 10:05:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:25:14 +02:00
|
|
|
void cSkinDesigner::DeleteTemplates(void) {
|
|
|
|
if (channelTemplate) {
|
|
|
|
delete channelTemplate;
|
|
|
|
channelTemplate = NULL;
|
|
|
|
}
|
|
|
|
if (menuTemplate) {
|
|
|
|
delete menuTemplate;
|
|
|
|
menuTemplate = NULL;
|
|
|
|
}
|
|
|
|
if (messageTemplate) {
|
|
|
|
delete messageTemplate;
|
|
|
|
messageTemplate = NULL;
|
|
|
|
}
|
|
|
|
if (replayTemplate) {
|
|
|
|
delete replayTemplate;
|
|
|
|
replayTemplate = NULL;
|
|
|
|
}
|
|
|
|
if (volumeTemplate) {
|
|
|
|
delete volumeTemplate;
|
|
|
|
volumeTemplate = NULL;
|
|
|
|
}
|
|
|
|
if (audiotracksTemplate) {
|
|
|
|
delete audiotracksTemplate;
|
|
|
|
audiotracksTemplate = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSkinDesigner::LoadTemplates(void) {
|
2014-10-18 10:05:32 +02:00
|
|
|
if (globals)
|
|
|
|
delete globals;
|
2014-09-27 09:25:14 +02:00
|
|
|
globals = new cGlobals();
|
|
|
|
bool ok = globals->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error parsing globals, aborting");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTemplates();
|
|
|
|
|
|
|
|
channelTemplate = new cTemplate(vtDisplayChannel);
|
|
|
|
channelTemplate->SetGlobals(globals);
|
|
|
|
ok = channelTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displaychannel template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
channelTemplate->Translate();
|
|
|
|
|
|
|
|
menuTemplate = new cTemplate(vtDisplayMenu);
|
|
|
|
menuTemplate->SetGlobals(globals);
|
|
|
|
ok = menuTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displaymenu template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
menuTemplate->Translate();
|
|
|
|
|
|
|
|
messageTemplate = new cTemplate(vtDisplayMessage);
|
|
|
|
messageTemplate->SetGlobals(globals);
|
|
|
|
ok = messageTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displaymessage template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
messageTemplate->Translate();
|
|
|
|
|
|
|
|
replayTemplate = new cTemplate(vtDisplayReplay);
|
|
|
|
replayTemplate->SetGlobals(globals);
|
|
|
|
ok = replayTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displayreplay template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
replayTemplate->Translate();
|
|
|
|
|
|
|
|
volumeTemplate = new cTemplate(vtDisplayVolume);
|
|
|
|
volumeTemplate->SetGlobals(globals);
|
|
|
|
ok = volumeTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displayvolume template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
volumeTemplate->Translate();
|
|
|
|
|
|
|
|
audiotracksTemplate = new cTemplate(vtDisplayAudioTracks);
|
|
|
|
audiotracksTemplate->SetGlobals(globals);
|
|
|
|
ok = audiotracksTemplate->ReadFromXML();
|
|
|
|
if (!ok) {
|
|
|
|
esyslog("skindesigner: error reading displayaudiotracks template, aborting");
|
|
|
|
DeleteTemplates();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
audiotracksTemplate->Translate();
|
|
|
|
|
|
|
|
dsyslog("skindesigner: templates successfully validated and parsed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSkinDesigner::CacheTemplates(void) {
|
|
|
|
channelTemplate->PreCache();
|
|
|
|
menuTemplate->PreCache();
|
|
|
|
messageTemplate->PreCache();
|
|
|
|
replayTemplate->PreCache();
|
|
|
|
volumeTemplate->PreCache();
|
|
|
|
audiotracksTemplate->PreCache();
|
|
|
|
dsyslog("skindesigner: templates cached");
|
|
|
|
fontManager->CacheFonts(channelTemplate);
|
|
|
|
fontManager->CacheFonts(menuTemplate);
|
|
|
|
fontManager->CacheFonts(messageTemplate);
|
|
|
|
fontManager->CacheFonts(replayTemplate);
|
|
|
|
fontManager->CacheFonts(volumeTemplate);
|
|
|
|
fontManager->CacheFonts(audiotracksTemplate);
|
|
|
|
dsyslog("skindesigner: fonts cached");
|
|
|
|
dsyslog("skindesigner: caching images...");
|
|
|
|
imgCache->Clear();
|
2014-10-03 15:54:23 +02:00
|
|
|
imgCache->SetPathes();
|
2014-09-27 09:25:14 +02:00
|
|
|
channelTemplate->CacheImages();
|
|
|
|
menuTemplate->CacheImages();
|
|
|
|
messageTemplate->CacheImages();
|
|
|
|
replayTemplate->CacheImages();
|
|
|
|
volumeTemplate->CacheImages();
|
|
|
|
audiotracksTemplate->CacheImages();
|
|
|
|
imgCache->Debug(false);
|
|
|
|
}
|
|
|
|
|