#include #include #include #include "config.h" #include "helpers.h" #include cNopacityConfig config; cTheme Theme; cNopacityConfig::cNopacityConfig() { logoPathSet = false; epgImagePathSet = false; iconPathSet = false; //Common mainMenuEntry = false; fontName = NULL; fontDefaultName = "VDRSymbols Sans:Book"; logoExtension = "png"; LoadDefaults(); } cNopacityConfig::~cNopacityConfig() { } void cNopacityConfig::Init(void) { LoadDefaults(); LoadThemeSpecificConfigs(); SetThemeSpecificDefaults(); SetThemeSetup(); SetPathes(); SetFontName(); } int cNopacityConfig::GetValue(std::string name) { std::map::iterator hit = conf.find(name); if (hit != conf.end()) { return (int)hit->second; } else { dsyslog("nopacity: ERROR: access to unknown config value %s", name.c_str()); } return 0; } int *cNopacityConfig::GetValueRef(std::string name) { int *ref = NULL; std::map::iterator hit = conf.find(name); if (hit != conf.end()) { ref = &hit->second; } else { dsyslog("nopacity: ERROR: access to unknown config value %s", name.c_str()); } return ref; } void cNopacityConfig::LoadDefaults(void) { conf.clear(); //Common Values conf.insert(std::pair("displayType", dtBlending)); conf.insert(std::pair("fontIndex", 0)); conf.insert(std::pair("debugImageLoading", 0)); //DisplayMenu conf.insert(std::pair("scrollMode", 0)); conf.insert(std::pair("spaceMenu", 5)); conf.insert(std::pair("widthScrollbar", 20)); conf.insert(std::pair("menuAdjustLeft", 1)); conf.insert(std::pair("scalePicture", 1)); conf.insert(std::pair("roundedCorners", 1)); conf.insert(std::pair("cornerRadius", 12)); conf.insert(std::pair("useMenuIcons", 1)); conf.insert(std::pair("mainMenuTitleStyle", 0)); conf.insert(std::pair("narrowMainMenu", 1)); conf.insert(std::pair("narrowScheduleMenu", 1)); conf.insert(std::pair("narrowChannelMenu", 1)); conf.insert(std::pair("narrowTimerMenu", 1)); conf.insert(std::pair("narrowRecordingMenu", 1)); conf.insert(std::pair("narrowSetupMenu", 1)); conf.insert(std::pair("numReruns", 5)); conf.insert(std::pair("useSubtitleRerun", 1)); conf.insert(std::pair("menuChannelDisplayMode", 0)); conf.insert(std::pair("menuChannelDisplayTime", 1)); conf.insert(std::pair("numEPGEntriesChannelsMenu", 15)); conf.insert(std::pair("menuFadeTime", 0)); conf.insert(std::pair("menuEPGWindowFadeTime", 300)); conf.insert(std::pair("menuWidthMain", 30)); conf.insert(std::pair("menuWidthSchedules", 30)); conf.insert(std::pair("menuWidthChannels", 30)); conf.insert(std::pair("menuWidthTimers", 30)); conf.insert(std::pair("menuWidthRecordings", 30)); conf.insert(std::pair("menuWidthSetup", 30)); conf.insert(std::pair("menuHeightInfoWindow", 20)); conf.insert(std::pair("menuScrollDelay", 1)); conf.insert(std::pair("menuScrollSpeed", 2)); conf.insert(std::pair("menuInfoTextDelay", 2)); conf.insert(std::pair("menuInfoScrollDelay", 5)); conf.insert(std::pair("menuInfoScrollSpeed", 2)); conf.insert(std::pair("menuWidthRightItems", 12)); conf.insert(std::pair("menuSizeDiskUsage", 12)); conf.insert(std::pair("showDiscUsage", 1)); conf.insert(std::pair("discUsageStyle", 0)); conf.insert(std::pair("showTimers", 1)); conf.insert(std::pair("numberTimers", 10)); conf.insert(std::pair("timersLogoWidth", 60)); conf.insert(std::pair("checkTimerConflict", 1)); conf.insert(std::pair("headerHeight", 7)); conf.insert(std::pair("footerHeight", 7)); conf.insert(std::pair("numDefaultMenuItems", 16)); conf.insert(std::pair("numMainMenuItems", 10)); conf.insert(std::pair("numSchedulesMenuItems", 10)); conf.insert(std::pair("numRecordingsMenuItems", 10)); conf.insert(std::pair("menuHeaderLogoWidth", 160)); conf.insert(std::pair("menuHeaderLogoHeight", 70)); conf.insert(std::pair("epgImageWidth", 210)); conf.insert(std::pair("epgImageHeight", 160)); conf.insert(std::pair("epgImageWidthLarge", 525)); conf.insert(std::pair("epgImageHeightLarge", 400)); conf.insert(std::pair("posterWidth", 500)); conf.insert(std::pair("posterHeight", 750)); conf.insert(std::pair("useFolderPoster", 1)); conf.insert(std::pair("menuChannelLogoBackground", 1)); conf.insert(std::pair("borderDetailedEPG", 30)); conf.insert(std::pair("borderDetailedRecordings", 30)); conf.insert(std::pair("headerDetailedEPG", 20)); conf.insert(std::pair("headerDetailedRecordings", 20)); conf.insert(std::pair("detailedViewScrollStep", 1)); conf.insert(std::pair("menuSchedulesWindowMode", 1)); conf.insert(std::pair("menuRecordingsWindowMode", 1)); conf.insert(std::pair("menuTimersWindowMode", 1)); conf.insert(std::pair("fontHeader", 0)); conf.insert(std::pair("fontDate", 0)); conf.insert(std::pair("fontMenuitemLarge", 0)); conf.insert(std::pair("fontMenuitemSchedule", 0)); conf.insert(std::pair("fontMenuitemScheduleSmall", 0)); conf.insert(std::pair("fontMenuitemChannel", 0)); conf.insert(std::pair("fontMenuitemChannelSmall", 0)); conf.insert(std::pair("fontMenuitemRecordings", 0)); conf.insert(std::pair("fontMenuitemRecordingsSmall", 0)); conf.insert(std::pair("fontMenuitemTimers", 0)); conf.insert(std::pair("fontMenuitemTimersSmall", 0)); conf.insert(std::pair("fontMenuitemDefault", 0)); conf.insert(std::pair("fontDiskUsage", 0)); conf.insert(std::pair("fontDiskUsagePercent", 0)); conf.insert(std::pair("fontTimers", 0)); conf.insert(std::pair("fontTimersHead", 0)); conf.insert(std::pair("fontButtons", 0)); conf.insert(std::pair("fontMessageMenu", 0)); conf.insert(std::pair("fontDetailView", 0)); conf.insert(std::pair("fontDetailViewSmall", 0)); conf.insert(std::pair("fontDetailViewHeader", 0)); conf.insert(std::pair("fontDetailViewHeaderLarge", 0)); conf.insert(std::pair("fontEPGInfoWindow", 0)); conf.insert(std::pair("fontEPGInfoWindowLarge", 0)); //DisplayChannel conf.insert(std::pair("channelHeight", 25)); conf.insert(std::pair("channelBorderVertical", 15)); conf.insert(std::pair("channelBorderBottom", 15)); conf.insert(std::pair("channelFadeTime", 300)); conf.insert(std::pair("channelBackgroundTransparency", 0)); conf.insert(std::pair("channelUseLogoBackground", 1)); conf.insert(std::pair("logoPosition", 1)); conf.insert(std::pair("logoVerticalAlignment", 1)); conf.insert(std::pair("logoWidth", 260)); conf.insert(std::pair("logoHeight", 200)); conf.insert(std::pair("logoWidthOriginal", 260)); conf.insert(std::pair("logoHeightOriginal", 200)); conf.insert(std::pair("backgroundStyle", 0)); conf.insert(std::pair("roundedCornersChannel", 1)); conf.insert(std::pair("displaySignalStrength", 1)); conf.insert(std::pair("displaySourceInfo", 1)); conf.insert(std::pair("displayPrevNextChannelGroup", 1)); conf.insert(std::pair("fontChannelHeaderSize", 0)); conf.insert(std::pair("fontChannelDateSize", 0)); conf.insert(std::pair("fontEPGSize", 0)); conf.insert(std::pair("fontEPGSmallSize", 0)); conf.insert(std::pair("fontChannelSourceInfoSize", 0)); conf.insert(std::pair("fontChannelGroupSize", 0)); conf.insert(std::pair("fontChannelGroupSmallSize", 0)); conf.insert(std::pair("progressCurrentSchedule", 0)); conf.insert(std::pair("displayPoster", 1)); conf.insert(std::pair("channelPosterBorder", 10)); //Display Replay conf.insert(std::pair("replayHeight", 25)); conf.insert(std::pair("replayBorderVertical", 15)); conf.insert(std::pair("replayBorderBottom", 15)); conf.insert(std::pair("replayFadeTime", 300)); conf.insert(std::pair("fontReplayHeader", 0)); conf.insert(std::pair("fontReplay", 0)); //DisplayMessage conf.insert(std::pair("messageFadeTime", 300)); conf.insert(std::pair("messageWidth", 90)); conf.insert(std::pair("messageHeight", 10)); conf.insert(std::pair("messageBorderBottom", 10)); conf.insert(std::pair("fontMessage", 0)); //DisplayTracks conf.insert(std::pair("tracksFadeTime", 300)); conf.insert(std::pair("tracksWidth", 25)); conf.insert(std::pair("tracksItemHeight", 80)); conf.insert(std::pair("tracksPosition", 0)); conf.insert(std::pair("tracksBorderHorizontal", 10)); conf.insert(std::pair("tracksBorderVertical", 10)); conf.insert(std::pair("fontTracksHeader", 0)); conf.insert(std::pair("fontTracks", 0)); //DisplayVolume conf.insert(std::pair("volumeFadeTime", 300)); conf.insert(std::pair("volumeWidth", 40)); conf.insert(std::pair("volumeHeight", 10)); conf.insert(std::pair("volumeBorderBottom", 10)); conf.insert(std::pair("fontVolume", 0)); //Channel Logo Caching conf.insert(std::pair("limitLogoCache", 1)); conf.insert(std::pair("numLogosInitial", 30)); conf.insert(std::pair("numLogosMax", 50)); } void cNopacityConfig::SetFontName() { if (fontName) free(fontName); if (GetValue("fontIndex") == 0) { fontName = strdup(fontDefaultName); } else { cStringList availableFonts; cFont::GetAvailableFontNames(&availableFonts); if (availableFonts[GetValue("fontIndex")-1]) { fontName = strdup(availableFonts[GetValue("fontIndex")-1]); } else fontName = strdup(fontDefaultName); } } void cNopacityConfig::SetPathes(void) { logoPathDefault = cString::sprintf("%s/logos/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N)); iconPathDefault = cString::sprintf("%s/icons/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N)); epgImagePathDefault = cString::sprintf("%s/epgimages/", cPlugin::CacheDirectory(PLUGIN_NAME_I18N)); dsyslog("nopacity: using Logo Directory %s", (logoPathSet)?(*logoPath):(*logoPathDefault)); dsyslog("nopacity: using Icon Directory %s", (iconPathSet)?(*iconPath):(*iconPathDefault)); dsyslog("nopacity: using EPG Images Directory %s", (epgImagePathSet)?(*epgImagePath):(*epgImagePathDefault)); } void cNopacityConfig::SetLogoPath(cString path) { logoPath = checkSlashAtEnd(*path); logoPathSet = true; } void cNopacityConfig::SetIconPath(cString path) { iconPath = checkSlashAtEnd(*path); iconPathSet = true; } void cNopacityConfig::SetEpgImagePath(cString path) { epgImagePath = checkSlashAtEnd(*path); epgImagePathSet = true; } cString cNopacityConfig::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(); } void cNopacityConfig::LoadThemeSpecificConfigs(void) { cThemes themes; themes.Load("nOpacity"); int numThemes = themes.NumThemes(); dsyslog("nopacity: %d themes available", numThemes); for (int theme = 0; theme < numThemes; theme++) { cString confFile = cString::sprintf("%s/themeconfigs/theme-%s.conf", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N), themes.Name(theme)); dsyslog("nopacity: trying to load theme config %s", *confFile); LoadThemeConfig(confFile, themes.Name(theme)); } } void cNopacityConfig::LoadThemeConfig(cString confFile, cString theme) { FILE *f = fopen(*confFile, "r"); if (f) { dsyslog("nopacity: %s successfully loaded", *confFile); std::map themeConf; char *line; cReadLine ReadLine; bool insertConf = false; while ((line = ReadLine.Read(f)) != NULL) { std::pair themeConfLine = ReadThemeConfigLine(line); std::string name = (std::string)themeConfLine.first; if (name.compare("undefined") != 0) { themeConf.insert(themeConfLine); insertConf = true; } } if (insertConf) themeConfigDefaults.insert(std::pair >(*theme, themeConf)); } } std::pair cNopacityConfig::ReadThemeConfigLine(const char *line) { std::pair themeConf; try { splitstring s(line); std::vector flds = s.split('=', 0); if (flds.size() == 2) { std::string name = flds[0]; name.erase(name.find_last_not_of(" ")+1); name.erase(0, name.find_first_not_of(" ")); int value = atoi(flds[1].c_str()); themeConf = std::make_pair (name,value); } else { themeConf = std::make_pair ("undefined",0); } } catch (...) { themeConf = std::make_pair ("undefined",0); } return themeConf; } void cNopacityConfig::SetThemeSpecificDefaults(void) { std::map >::iterator themeConfHit = themeConfigDefaults.find(Setup.OSDTheme); if (themeConfHit != themeConfigDefaults.end()) { std::map themeConf = (std::map)themeConfHit->second; for(std::map::const_iterator it = themeConf.begin(); it != themeConf.end(); it++) { std::string name = (std::string)it->first; int value = (int)it->second; std::map::iterator origVal = conf.find(name); if (origVal != conf.end()) { conf.erase(origVal); conf.insert(std::pair(name, value)); } else { dsyslog("nopacity: ERROR: unknown config parameter %s in default config for theme %s", name.c_str(), Setup.OSDTheme); } } } } void cNopacityConfig::SetThemeSetup(void) { std::map >::iterator themeSetupHit = themeConfigSetup.find(Setup.OSDTheme); if (themeSetupHit != themeConfigSetup.end()) { std::map themeSetup = (std::map)themeSetupHit->second; for(std::map::const_iterator it = themeSetup.begin(); it != themeSetup.end(); it++) { std::string name = (std::string)it->first; int value = (int)it->second; std::map::iterator origVal = conf.find(name); if (origVal != conf.end()) { conf.erase(origVal); conf.insert(std::pair(name, value)); } } } } bool cNopacityConfig::SetupParse(const char *Name, const char *Value) { splitstring s(Name); std::vector flds = s.split('.', 0); if (flds.size() == 2) { std::string theme = flds[0]; std::string name = flds[1]; //check if valid value std::map::iterator hit = conf.find(name); if (hit == conf.end()) return false; SetThemeConfigSetupValue(theme, name, atoi(Value)); } else { return false; } return true; } void cNopacityConfig::SetThemeConfigSetupValue(std::string themeName, std::string key, int value) { //check if theme already in map std::map >::iterator hit = themeConfigSetup.find(themeName); if (hit != themeConfigSetup.end()) { std::map existingValues = (std::map)hit->second; existingValues.erase(key); existingValues.insert(std::pair(key, value)); themeConfigSetup.erase(themeName); themeConfigSetup.insert(std::pair >(themeName, existingValues)); } else { std::map themeConf; themeConf.insert(std::pair(key, value)); themeConfigSetup.insert(std::pair >(themeName, themeConf)); } } void cNopacityConfig::DumpConfig(void) { esyslog("nopacity: current config -----------------"); for(std::map::const_iterator it = conf.begin(); it != conf.end(); it++) { esyslog("nopacity: %s: %d", (std::string(it->first)).c_str(), (int)it->second); } esyslog("nopacity: --------------------------------"); } void cNopacityConfig::DumpThemeConfig(void) { for (std::map >::const_iterator it = themeConfigDefaults.begin(); it != themeConfigDefaults.end(); it++) { esyslog("nopacity: Default Config for theme %s -----------------", (std::string(it->first)).c_str()); std::map themeValues = (std::map)it->second; for (std::map::const_iterator it2 = themeValues.begin(); it2 != themeValues.end(); it2++) { esyslog("nopacity: %s: %d", (std::string(it2->first)).c_str(), (int)it2->second); } } esyslog("nopacity: --------------------------------"); for (std::map >::const_iterator it3 = themeConfigSetup.begin(); it3 != themeConfigSetup.end(); it3++) { esyslog("nopacity: Setup for theme %s -----------------", (std::string(it3->first)).c_str()); std::map themeValues = (std::map)it3->second; for (std::map::const_iterator it4 = themeValues.begin(); it4 != themeValues.end(); it4++) { esyslog("nopacity: %s: %d", (std::string(it4->first)).c_str(), (int)it4->second); } } esyslog("nopacity: --------------------------------"); }