vdr-plugin-skindesigner/config.c

526 lines
17 KiB
C
Raw Permalink Normal View History

2014-09-27 09:25:14 +02:00
#include "config.h"
2016-01-26 18:32:38 +01:00
#include "extensions/helpers.h"
#include "extensions/imageloader.h"
2014-09-27 09:25:14 +02:00
cDesignerConfig::cDesignerConfig() {
tmplGlobals = NULL;
2014-09-27 09:25:14 +02:00
epgImagePathSet = false;
skinPathSet = false;
2015-05-22 13:34:23 +02:00
installerSkinPathSet = false;
logoPathSet = false;
2014-09-27 09:25:14 +02:00
//Common
2016-01-26 18:32:38 +01:00
cacheImagesInitial = 1;
2014-09-27 09:25:14 +02:00
numLogosPerSizeInitial = 30;
limitLogoCache = 1;
numLogosMax = 200;
debugImageLoading = 0;
replaceDecPoint = false;
//settings for rerun display
rerunAmount = 10;
rerunDistance = 2;
rerunMaxChannel = 0;
2016-01-26 18:32:38 +01:00
//max number of custom int and string tokens
numCustomTokens = 10;
2016-07-22 15:21:09 +02:00
//Frames per Second to display animations
FPS = 50;
//remember current skin and theme, osd size and osd fonts
SetSkin();
SetOSDSize();
SetOSDFonts();
2015-01-21 18:33:19 +01:00
osdLanguage = "";
setupCloseDoReload = false;
2014-09-27 09:25:14 +02:00
}
cDesignerConfig::~cDesignerConfig() {
ClearSkinSetups();
2016-02-14 15:06:30 +01:00
for (vector<cTheme*>::iterator it = themes.begin(); it != themes.end(); it++) {
delete *it;
}
2014-09-27 09:25:14 +02:00
}
void cDesignerConfig::SetPathes(void) {
if (!skinPathSet)
skinPath = cString::sprintf("%s/skins/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
2015-05-22 13:34:23 +02:00
if (!installerSkinPathSet)
installerSkinPath = cString::sprintf("%s/installerskins/", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N));
if (!logoPathSet)
logoPath = cString::sprintf("%s/logos/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
2014-09-27 09:25:14 +02:00
if (!epgImagePathSet)
epgImagePath = cString::sprintf("%s/epgimages/", cPlugin::CacheDirectory(PLUGIN_NAME_I18N));
dsyslog("skindesigner: using Skin Directory %s", *skinPath);
2016-04-16 10:01:29 +02:00
#ifndef DO_NOT_USE_SKININSTALLER
2015-05-22 13:34:23 +02:00
dsyslog("skindesigner: using Installer Skin Directory %s", *installerSkinPath);
2016-04-16 10:01:29 +02:00
#endif
dsyslog("skindesigner: using common ChannelLogo Directory %s", *logoPath);
2014-09-27 09:25:14 +02:00
dsyslog("skindesigner: using EPG Images Directory %s", *epgImagePath);
2015-05-30 16:43:59 +02:00
vdrThemesPath = cPlugin::ConfigDirectory(PLUGIN_NAME_I18N);
size_t found = vdrThemesPath.find("/plugins");
if (found != string::npos)
vdrThemesPath = vdrThemesPath.substr(0, found);
vdrThemesPath += "/themes/";
2014-09-27 09:25:14 +02:00
}
void cDesignerConfig::SetSkinPath(cString path) {
skinPath = CheckSlashAtEnd(*path);
skinPathSet = true;
}
2015-05-22 13:34:23 +02:00
void cDesignerConfig::SetInstallerSkinPath(cString path) {
installerSkinPath = CheckSlashAtEnd(*path);
installerSkinPathSet = true;
}
void cDesignerConfig::SetLogoPath(cString path) {
logoPath = CheckSlashAtEnd(*path);
logoPathSet = true;
}
2014-09-27 09:25:14 +02:00
void cDesignerConfig::SetEpgImagePath(cString path) {
epgImagePath = CheckSlashAtEnd(*path);
epgImagePathSet = true;
}
2015-06-13 10:46:11 +02:00
bool cDesignerConfig::GetThemeColor(string &name, tColor &col) {
if (!tmplGlobals)
return false;
return tmplGlobals->GetColor(name, col);
}
2016-02-14 15:06:30 +01:00
void cDesignerConfig::StoreTheme(cTheme *theme) {
themes.push_back(theme);
}
2015-05-30 16:43:59 +02:00
void cDesignerConfig::ReadSkinFolder(cString &skinFolder, vector<string> *container) {
DIR *folder = NULL;
struct dirent *dirEntry;
2015-05-30 16:43:59 +02:00
folder = opendir(skinFolder);
if (!folder) {
2015-05-30 16:43:59 +02:00
esyslog("skindesigner: no skins found in %s", *skinFolder);
return;
}
while (dirEntry = readdir(folder)) {
string dirEntryName = dirEntry->d_name;
int dirEntryType = dirEntry->d_type;
cString subfolder = cString::sprintf("%s%s", *skinFolder, dirEntryName.c_str());
if (!dirEntryName.compare(".") || !dirEntryName.compare("..") || !dirEntryName.compare("skinrepositories"))
continue;
if (dirEntryType != DT_DIR && dirEntryType != DT_LNK && !DirectoryOk(*subfolder, false))
continue;
2015-05-30 16:43:59 +02:00
container->push_back(dirEntryName);
}
dsyslog("skindesigner %ld skins found in %s", container->size(), *skinFolder);
}
void cDesignerConfig::ReadSkins(void) {
ReadSkinFolder(skinPath, &deliveredSkins);
2016-04-16 10:01:29 +02:00
#ifndef DO_NOT_USE_SKININSTALLER
2015-05-30 16:43:59 +02:00
ReadSkinFolder(installerSkinPath, &installerSkins);
2016-04-16 10:01:29 +02:00
#endif
2015-05-30 16:43:59 +02:00
for (vector<string>::iterator it = deliveredSkins.begin(); it != deliveredSkins.end(); it++) {
skins.push_back(*it);
}
2016-04-16 10:01:29 +02:00
#ifndef DO_NOT_USE_SKININSTALLER
2015-05-30 16:43:59 +02:00
for (vector<string>::iterator it = installerSkins.begin(); it != installerSkins.end(); it++) {
string instSkin = *it;
bool found = false;
for (vector<string>::iterator it2 = deliveredSkins.begin(); it2 != deliveredSkins.end(); it2++) {
if (!instSkin.compare(*it2)) {
found = true;
break;
}
}
if (!found)
skins.push_back(instSkin);
}
2016-04-16 10:01:29 +02:00
#endif
}
void cDesignerConfig::ClearSkinSetups(void) {
for (map < string, cSkinSetup* >::iterator it = skinSetups.begin(); it != skinSetups.end(); it++) {
delete it->second;
}
skinSetups.clear();
}
void cDesignerConfig::DebugSkinSetups(void) {
dsyslog("skindesigner: skin setups:");
InitSetupIterator();
cSkinSetup *skinSetup = NULL;
while (skinSetup = GetNextSkinSetup()) {
skinSetup->Debug();
}
}
void cDesignerConfig::DebugSkinSetupParameters(void) {
dsyslog("skindesigner: skin setup parameters:");
for (vector<pair<string, int> >::iterator it = skinSetupParameters.begin(); it != skinSetupParameters.end(); it++) {
dsyslog("skindesigner: parameter %s value %d", (*it).first.c_str(), (*it).second);
}
}
2015-01-19 09:23:15 +01:00
void cDesignerConfig::ReadSkinSetup(string skin) {
cSkinSetup *skinSetup = new cSkinSetup(skin);
2015-01-19 10:50:22 +01:00
if (skinSetup->ReadFromXML()) {
//skinSetup->Debug();
skinSetups.insert(pair<string, cSkinSetup* >(skin, skinSetup));
}
2015-01-19 09:23:15 +01:00
}
bool cDesignerConfig::GetSkin(string &skin) {
if (skinIterator == skins.end()) {
return false;
}
skin = *skinIterator;
skinIterator++;
return true;
}
2015-05-30 16:43:59 +02:00
cString cDesignerConfig::GetSkinPath(string skin) {
for (vector<string>::iterator it = deliveredSkins.begin(); it != deliveredSkins.end(); it++) {
if (!skin.compare(*it)) {
return skinPath;
}
}
return installerSkinPath;
}
void cDesignerConfig::AddNewSkinRef(string skin) {
2016-02-14 15:06:30 +01:00
cTheme *theme = new cTheme();
StoreTheme(theme);
cSkinDesigner *newSkin = new cSkinDesigner(skin, theme);
2015-05-30 16:43:59 +02:00
AddSkin(newSkin);
skins.push_back(skin);
installerSkins.push_back(skin);
ReadSkinSetup(skin);
map < string, cSkinSetup* >::iterator hit = skinSetups.find(skin);
if (hit != skinSetups.end())
(hit->second)->TranslateSetup();
}
bool cDesignerConfig::SkinActive(string skin) {
cSkin *activeSkin = Skins.Current();
if (activeSkin && !skin.compare(activeSkin->Name()))
return true;
return false;
}
void cDesignerConfig::DeleteSkin(string skin) {
dsyslog("skindesigner: deleting skin %s", skin.c_str());
cSkin *deleteSkin = NULL;
bool found = false;
for (deleteSkin = Skins.First(); deleteSkin; deleteSkin = Skins.Next(deleteSkin)) {
if (!skin.compare(deleteSkin->Name())) {
found = true;
break;
}
}
if (!found || !deleteSkin) {
esyslog("skindesigner: skin %s to delete not found", skin.c_str());
return;
}
vector<cSkinDesigner*>::iterator delIt;
for (delIt = skinRefs.begin(); delIt != skinRefs.end(); delIt++) {
if (*delIt == deleteSkin)
break;
}
if (delIt != skinRefs.end())
skinRefs.erase(delIt);
vector<string>::iterator delIt2;
for (delIt2 = installerSkins.begin(); delIt2 != installerSkins.end(); delIt2++) {
if (!skin.compare(*delIt2))
break;
}
if (delIt2 != installerSkins.end())
installerSkins.erase(delIt2);
vector<string>::iterator delIt3;
for (delIt3 = skins.begin(); delIt3 != skins.end(); delIt3++) {
if (!skin.compare(*delIt3))
break;
}
if (delIt3 != skins.end())
skins.erase(delIt3);
Skins.Del(deleteSkin);
stringstream deletePath;
deletePath << *installerSkinPath << skin;
string delPath = deletePath.str();
if (FolderExists(delPath)) {
dsyslog("skindesigner: deleting skin %s", delPath.c_str());
cString command = cString::sprintf("rm -rf %s", delPath.c_str());
int ok = system(*command);
if (!ok) {
esyslog("skindesigner: error deleting skin %s", delPath.c_str());
}
}
}
2015-05-30 16:43:59 +02:00
cSkinDesigner* cDesignerConfig::GetNextSkinRef(void) {
if (skinRefsIterator == skinRefs.end()) {
return NULL;
}
cSkinDesigner *skin = *skinRefsIterator;
skinRefsIterator++;
return skin;
}
2015-01-19 10:50:22 +01:00
cSkinSetup* cDesignerConfig::GetSkinSetup(string &skin) {
map< string, cSkinSetup* >::iterator hit = skinSetups.find(skin);
if (hit != skinSetups.end()) {
return hit->second;
}
return NULL;
}
cSkinSetup* cDesignerConfig::GetNextSkinSetup(void) {
if (setupIt == skinSetups.end()) {
return NULL;
}
cSkinSetup* skinSetup = setupIt->second;
setupIt++;
return skinSetup;
}
cSkinSetupMenu* cDesignerConfig::GetSkinSetupMenu(string &skin, string &menu) {
cSkinSetup *skinSetup = GetSkinSetup(skin);
if (!skinSetup)
return NULL;
return skinSetup->GetMenu(menu);
}
void cDesignerConfig::TranslateSetup(void) {
for (map< string, cSkinSetup* >::iterator it = skinSetups.begin(); it != skinSetups.end(); it++) {
(it->second)->TranslateSetup();
}
}
void cDesignerConfig::UpdateSkinSetupParameter(string name, int value) {
vector<pair<string,int> >::iterator hit;
for (hit = skinSetupParameters.begin(); hit != skinSetupParameters.end(); hit++) {
if (!name.compare((*hit).first)) {
skinSetupParameters.erase(hit);
break;
}
}
skinSetupParameters.push_back(pair<string,int>(name, value));
}
void cDesignerConfig::SetSkinSetupParameters(void) {
for (vector < pair <string, int> >::iterator it = skinSetupParameters.begin(); it != skinSetupParameters.end(); it++) {
string name = (*it).first;
int value = (*it).second;
InitSkinIterator();
string activeSkin = "";
bool skinFound = false;
while (GetSkin(activeSkin)) {
stringstream checkString;
checkString << activeSkin << ".";
size_t hit = name.find(checkString.str());
if (hit != 0)
continue;
skinFound = true;
break;
}
if (skinFound) {
cSkinSetup* skinSetup = GetSkinSetup(activeSkin);
if (skinSetup != NULL) {
string paramName = name.substr(activeSkin.size()+1);
cSkinSetupParameter *skinSetupParam = skinSetup->GetParameter(paramName);
if (skinSetupParam) {
skinSetupParam->value = value;
continue;
}
}
}
esyslog("skindesigner: ERROR Unknown Setup Parameter %s", name.c_str());
}
}
2015-05-22 13:34:23 +02:00
void cDesignerConfig::ReadSkinRepos(void) {
2016-04-16 10:01:29 +02:00
#ifndef DO_NOT_USE_SKININSTALLER
skinRepos.Init(*installerSkinPath);
skinRepos.Read(*installerSkinPath);
dsyslog("skindesigner: read %d skinrepositories from %s", skinRepos.Count(), *installerSkinPath);
2016-04-16 10:01:29 +02:00
#endif
}
bool cDesignerConfig::CheckVersion(string name, string &neededVersion) {
cSkinRepo *repo = skinRepos.GetRepo(name);
if (!repo)
return false;
neededVersion = repo->MinSDVersion();
splitstring minVer(neededVersion.c_str());
vector<string> tokensMinVer = minVer.split('.', 1);
if (tokensMinVer.size() != 3) {
esyslog("skindesigner: incorrect minimumskindesignerversion definition: %s", neededVersion.c_str());
return false;
}
splitstring ver(version.c_str());
vector<string> tokensVer = ver.split('.', 1);
if (tokensVer.size() != 3) {
esyslog("skindesigner: incorrect version definition: %s", version.c_str());
return false;
}
int minVerMajor = atoi(tokensMinVer[0].c_str());
int minVerMinor = atoi(tokensMinVer[1].c_str());
int minVerMikro = atoi(tokensMinVer[2].c_str());
int verMajor = atoi(tokensVer[0].c_str());
int verMinor = atoi(tokensVer[1].c_str());
int verMikro = atoi(tokensVer[2].c_str());
2015-07-29 18:32:03 +02:00
if (minVerMajor < verMajor)
return true;
if (minVerMajor > verMajor)
return false;
2015-07-29 18:32:03 +02:00
if (minVerMinor < verMinor)
return true;
if (minVerMinor > verMinor)
return false;
2015-07-29 18:32:03 +02:00
if (minVerMikro <= verMikro)
return true;
return false;
2015-05-22 13:34:23 +02:00
}
2015-05-30 16:43:59 +02:00
bool cDesignerConfig::SkinInstalled(string name) {
for (vector<string>::iterator it = installerSkins.begin(); it != installerSkins.end(); it++) {
if (!name.compare(*it))
return true;
}
return false;
}
2015-05-22 13:34:23 +02:00
void cDesignerConfig::UpdateGlobals(void) {
string activeSkin = Setup.OSDSkin;
cSkinSetup *skinSetupActiveSkin = GetSkinSetup(activeSkin);
if (skinSetupActiveSkin && tmplGlobals) {
dsyslog("skindesigner: globals for skin %s adapted to skin setup", activeSkin.c_str());
skinSetupActiveSkin->AddToGlobals(tmplGlobals);
}
}
2015-01-19 10:50:22 +01:00
2014-09-27 09:25:14 +02:00
void cDesignerConfig::CheckDecimalPoint(void) {
struct lconv *pLocInfo;
pLocInfo = localeconv();
string decimalPoint = pLocInfo->decimal_point;
if (decimalPoint.compare(".")) {
dsyslog("skindesigner: using decimal point %s", decimalPoint.c_str());
replaceDecPoint = true;
decPoint = decimalPoint[0];
}
}
void cDesignerConfig::SetSkin(void) {
osdSkin = Setup.OSDSkin;
osdTheme = Setup.OSDTheme;
}
bool cDesignerConfig::SkinChanged(void) {
bool changed = false;
if (osdSkin.compare(Setup.OSDSkin) != 0) {
dsyslog("skindesigner: skin changed from %s to %s", osdSkin.c_str(), Setup.OSDSkin);
changed = true;
}
if (osdTheme.compare(Setup.OSDTheme) != 0) {
dsyslog("skindesigner: theme changed from %s to %s", osdTheme.c_str(), Setup.OSDTheme);
changed = true;
}
if (changed)
SetSkin();
return changed;
}
void cDesignerConfig::SetOSDSize(void) {
osdSize.SetWidth(cOsd::OsdWidth());
osdSize.SetHeight(cOsd::OsdHeight());
osdSize.SetX(cOsd::OsdLeft());
osdSize.SetY(cOsd::OsdTop());
}
bool cDesignerConfig::OsdSizeChanged(void) {
if ((osdSize.Width() != cOsd::OsdWidth()) ||
(osdSize.Height() != cOsd::OsdHeight()) ||
(osdSize.X() != cOsd::OsdLeft()) ||
(osdSize.Y() != cOsd::OsdTop())) {
dsyslog("skindesigner: osd size changed");
dsyslog("skindesigner: old osd size: top %d left %d size %d * %d", osdSize.X(), osdSize.Y(), osdSize.Width(), osdSize.Height());
SetOSDSize();
dsyslog("skindesigner: new osd size: top %d left %d size %d * %d", osdSize.X(), osdSize.Y(), osdSize.Width(), osdSize.Height());
return true;
}
return false;
}
void cDesignerConfig::SetOSDFonts(void) {
fontFix = Setup.FontFix;
fontOsd = Setup.FontOsd;
fontSml = Setup.FontSml;
}
bool cDesignerConfig::OsdFontsChanged(void) {
bool changed = false;
if (fontFix.compare(Setup.FontFix) != 0) {
changed = true;
}
if (fontOsd.compare(Setup.FontOsd) != 0) {
changed = true;
}
if (fontSml.compare(Setup.FontSml) != 0) {
changed = true;
}
if (changed)
SetOSDFonts();
return changed;
}
bool cDesignerConfig::OsdLanguageChanged(void) {
if (osdLanguage.compare(Setup.OSDLanguage)) {
osdLanguage = Setup.OSDLanguage;
return true;
}
return false;
}
cString cDesignerConfig::GetSkinRessourcePath(void) {
return cString::sprintf("%s%s", *skinPath, osdSkin.c_str());
}
2014-09-27 09:25:14 +02:00
cString cDesignerConfig::CheckSlashAtEnd(std::string path) {
try {
if (!(path.at(path.size()-1) == '/'))
return cString::sprintf("%s/", path.c_str());
} catch (...) {return path.c_str();}
return path.c_str();
}
bool cDesignerConfig::SetupParse(const char *Name, const char *Value) {
bool pluginSetupParam = true;
2014-09-27 09:25:14 +02:00
if (!strcasecmp(Name, "DebugImageLoading")) debugImageLoading = atoi(Value);
2016-01-26 18:32:38 +01:00
else if (!strcasecmp(Name, "CacheImagesInitial")) cacheImagesInitial = atoi(Value);
2014-09-27 09:25:14 +02:00
else if (!strcasecmp(Name, "LimitChannelLogoCache")) limitLogoCache = atoi(Value);
else if (!strcasecmp(Name, "NumberLogosInitially")) numLogosPerSizeInitial = atoi(Value);
else if (!strcasecmp(Name, "NumberLogosMax")) numLogosMax = atoi(Value);
else if (!strcasecmp(Name, "RerunAmount")) rerunAmount = atoi(Value);
else if (!strcasecmp(Name, "RerunDistance")) rerunDistance = atoi(Value);
else if (!strcasecmp(Name, "RerunMaxChannel")) rerunMaxChannel = atoi(Value);
2016-01-26 18:32:38 +01:00
else if (!strcasecmp(Name, "NumCustomTokens")) numCustomTokens = atoi(Value);
2016-07-22 15:21:09 +02:00
else if (!strcasecmp(Name, "FPS")) FPS = atoi(Value);
else pluginSetupParam = false;
if (!pluginSetupParam) {
skinSetupParameters.push_back(pair <string, int>(Name, atoi(Value)));
}
2014-09-27 09:25:14 +02:00
return true;
}