diff options
author | louis <louis.braun@gmx.de> | 2015-01-31 11:46:06 +0100 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-01-31 11:46:06 +0100 |
commit | 1883ac1691f1e6cbe035819c07bbae72bc7748a9 (patch) | |
tree | ef3ee83a82ee65d96f1640414e940921936cae9c /libcore | |
parent | 304f5920045b1d55f093b2a7bb19162de1d2d4db (diff) | |
download | vdr-plugin-skindesigner-1883ac1691f1e6cbe035819c07bbae72bc7748a9.tar.gz vdr-plugin-skindesigner-1883ac1691f1e6cbe035819c07bbae72bc7748a9.tar.bz2 |
added possibiliy to use submenus in the skin setup menus
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/skinsetup.c | 238 | ||||
-rw-r--r-- | libcore/skinsetup.h | 49 |
2 files changed, 226 insertions, 61 deletions
diff --git a/libcore/skinsetup.c b/libcore/skinsetup.c index d678243..88901c8 100644 --- a/libcore/skinsetup.c +++ b/libcore/skinsetup.c @@ -1,4 +1,5 @@ #include "skinsetup.h" +#include "../config.h" #include "../libtemplate/xmlparser.h" // --- cSkinSetupParameter ----------------------------------------------------------- @@ -23,75 +24,191 @@ void cSkinSetupParameter::Debug(void) { dsyslog("skindesigner: min %d, max %d", min, max); } +// --- cSkinSetupMenu ----------------------------------------------------------- +cSkinSetupMenu::cSkinSetupMenu(void) { + name = ""; + displayText = ""; + parent = NULL; +} + +cSkinSetupMenu::~cSkinSetupMenu(void) { + for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) { + delete p->second; + } + for (vector < cSkinSetupMenu* >::iterator s = subMenus.begin(); s != subMenus.end(); s++) { + delete (*s); + } +} + +cSkinSetupParameter *cSkinSetupMenu::GetNextParameter(bool deep) { + cSkinSetupParameter *param = NULL; + if (paramIt != parameters.end()) { + param = paramIt->second; + paramIt++; + return param; + } + if (!deep) + return NULL; + + if (subMenuIt != subMenus.end()) { + param = (*subMenuIt)->GetNextParameter(); + if (!param) { + subMenuIt++; + if (subMenuIt != subMenus.end()) { + (*subMenuIt)->InitIterators(); + param = (*subMenuIt)->GetNextParameter(); + } + } + } + return param; +} + +cSkinSetupParameter *cSkinSetupMenu::GetParameter(string name) { + map < string, cSkinSetupParameter* >::iterator hit = parameters.find(name); + if (hit != parameters.end()) + return hit->second; + + cSkinSetupParameter *paramHit = NULL; + for (vector < cSkinSetupMenu* >::iterator subMenu = subMenus.begin(); subMenu != subMenus.end(); subMenu++) { + paramHit = (*subMenu)->GetParameter(name); + if (paramHit) + return paramHit; + } + return NULL; +} + +void cSkinSetupMenu::InitIterators(void) { + paramIt = parameters.begin(); + subMenuIt = subMenus.begin(); + while (subMenuIt != subMenus.end()) { + (*subMenuIt)->InitIterators(); + subMenuIt++; + } + subMenuIt = subMenus.begin(); +} + +void cSkinSetupMenu::SetParameter(eSetupParameterType paramType, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value) { + cSkinSetupParameter *param = new cSkinSetupParameter(); + param->type = paramType; + param->name = (const char*)name; + param->displayText = (const char*)displayText; + + if (min && paramType == sptInt) { + param->min = atoi((const char*)min); + } + if (max && paramType == sptInt) { + param->max = atoi((const char*)max); + } + param->value = atoi((const char*)value); + + parameters.insert(pair< string, cSkinSetupParameter* >(param->name, param)); +} + +cSkinSetupMenu *cSkinSetupMenu::GetMenu(string &name) { + for (vector<cSkinSetupMenu*>::iterator m = subMenus.begin(); m != subMenus.end(); m++) { + cSkinSetupMenu *menu = (*m); + if (!name.compare(menu->GetName())) + return menu; + menu = menu->GetMenu(name); + if (menu) + return menu; + } + return NULL; +} + +cSkinSetupMenu *cSkinSetupMenu::GetNextSubMenu(bool deep) { + cSkinSetupMenu *menu = NULL; + if (subMenuIt != subMenus.end()) { + if (deep) { + menu = (*subMenuIt)->GetNextSubMenu(deep); + if (menu) + return menu; + } + menu = *subMenuIt; + subMenuIt++; + return menu; + } + return NULL; +} + + +void cSkinSetupMenu::Debug(bool deep) { + dsyslog("skindesigner: Menu %s Setup Parameters", name.c_str()); + for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) { + (p->second)->Debug(); + } + if (subMenus.empty()) + return; + for (vector < cSkinSetupMenu* >::iterator s = subMenus.begin(); s != subMenus.end(); s++) { + dsyslog("skindesigner: SubMenu %s, Parent %s", ((*s)->GetName()).c_str(), ((*s)->GetParent()->GetName()).c_str()); + if (deep) + (*s)->Debug(); + } +} // --- cSkinSetup ----------------------------------------------------------- cSkinSetup::cSkinSetup(string skin) { this->skin = skin; + rootMenu = new cSkinSetupMenu(); + rootMenu->SetName("root"); + currentMenu = rootMenu; } cSkinSetup::~cSkinSetup() { - for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) { - delete p->second; - } + delete rootMenu; } bool cSkinSetup::ReadFromXML(void) { - string xmlFile = "setup.xml"; + string xmlPath = *cString::sprintf("%s%s/setup.xml", *config.skinPath, skin.c_str()); cXmlParser parser; - if (!parser.ReadSkinSetup(this, skin, xmlFile)) { + if (!parser.ReadSkinSetup(this, xmlPath)) { return false; } parser.ParseSkinSetup(skin); return true; } -void cSkinSetup::SetParameter(xmlChar *type, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value) { - if (!type || !name || !displayText || !value) { - esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); - return; - } - eSetupParameterType paramType = sptUnknown; - if (!xmlStrcmp(type, (const xmlChar *) "int")) { - paramType = sptInt; - } else if (!xmlStrcmp(type, (const xmlChar *) "bool")) { - paramType = sptBool; - } - if (paramType == sptUnknown) { - esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); - return; - } - - cSkinSetupParameter *param = new cSkinSetupParameter(); - param->type = paramType; - param->name = (const char*)name; - param->displayText = (const char*)displayText; - - if (min && paramType == sptInt) { - param->min = atoi((const char*)min); - } - if (max && paramType == sptInt) { - param->max = atoi((const char*)max); - } - param->value = atoi((const char*)value); +void cSkinSetup::SetSubMenu(xmlChar *name, xmlChar *displayText) { + cSkinSetupMenu *subMenu = new cSkinSetupMenu(); + subMenu->SetName((const char*)name); + subMenu->SetDisplayText((const char*)displayText); + subMenu->SetParent(currentMenu); + currentMenu->AddSubMenu(subMenu); + currentMenu = subMenu; +} - parameters.insert(pair< string, cSkinSetupParameter* >(param->name, param)); +void cSkinSetup::SubMenuDone(void) { + cSkinSetupMenu *parent = currentMenu->GetParent(); + if (parent) { + currentMenu = parent; + } } -cSkinSetupParameter *cSkinSetup::GetParameter(void) { - if (paramIt == parameters.end()) - return NULL; - cSkinSetupParameter *param = paramIt->second; - paramIt++; - return param; +void cSkinSetup::SetParameter(xmlChar *type, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value) { + if (!type || !name || !displayText || !value) { + esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); + return; + } + eSetupParameterType paramType = sptUnknown; + if (!xmlStrcmp(type, (const xmlChar *) "int")) { + paramType = sptInt; + } else if (!xmlStrcmp(type, (const xmlChar *) "bool")) { + paramType = sptBool; + } + if (paramType == sptUnknown) { + esyslog("skindesigner: invalid setup parameter for skin %s", skin.c_str()); + return; + } + currentMenu->SetParameter(paramType, name, displayText, min, max, value); } -cSkinSetupParameter *cSkinSetup::GetParameter(string name) { - map < string, cSkinSetupParameter* >::iterator hit = parameters.find(name); - if (hit != parameters.end()) - return hit->second; - return NULL; +cSkinSetupParameter *cSkinSetup::GetNextParameter(void) { + return rootMenu->GetNextParameter(); } +cSkinSetupParameter *cSkinSetup::GetParameter(string name) { + return rootMenu->GetParameter(name); +} void cSkinSetup::SetTranslation(string translationToken, map < string, string > transl) { translations.insert(pair<string, map < string, string > >(translationToken, transl)); @@ -100,21 +217,37 @@ void cSkinSetup::SetTranslation(string translationToken, map < string, string > void cSkinSetup::AddToGlobals(cGlobals *globals) { if (!globals) return; - for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) { - cSkinSetupParameter *param = p->second; + rootMenu->InitIterators(); + cSkinSetupParameter *param = NULL; + while (param = rootMenu->GetNextParameter()) { globals->AddInt(param->name, param->value); } } void cSkinSetup::TranslateSetup(void) { - InitParameterIterator(); + rootMenu->InitIterators(); cSkinSetupParameter *param = NULL; - while (param = GetParameter()) { + while (param = rootMenu->GetNextParameter()) { string transl = ""; if (Translate(param->displayText, transl)) { param->displayText = transl; } } + + rootMenu->InitIterators(); + cSkinSetupMenu *subMenu = NULL; + while (subMenu = rootMenu->GetNextSubMenu()) { + string transl = ""; + if (Translate(subMenu->GetDisplayText(), transl)) { + subMenu->SetDisplayText(transl); + } + } +} + +cSkinSetupMenu *cSkinSetup::GetMenu(string &name) { + if (name.size() == 0) + return rootMenu; + return rootMenu->GetMenu(name); } bool cSkinSetup::Translate(string text, string &translation) { @@ -161,11 +294,8 @@ string cSkinSetup::DoTranslate(string token) { } void cSkinSetup::Debug(void) { - dsyslog("skindesigner: Skin \"%s\" Setup Parameters", skin.c_str()); - for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) { - (p->second)->Debug(); - } - + rootMenu->Debug(); + return; dsyslog("skindesigner: Skin \"%s\" Setup Parameter Translations", skin.c_str()); for (map<string, map<string,string> >::iterator trans = translations.begin(); trans != translations.end(); trans++) { dsyslog("skindesigner: translation token %s", (trans->first).c_str()); diff --git a/libcore/skinsetup.h b/libcore/skinsetup.h index 4b0082d..6e99799 100644 --- a/libcore/skinsetup.h +++ b/libcore/skinsetup.h @@ -34,28 +34,63 @@ public: void Debug(void); }; +// --- cSkinSetupMenu ----------------------------------------------------------- + +class cSkinSetupMenu { +private: + string name; + string displayText; + cSkinSetupMenu *parent; + vector < cSkinSetupMenu* > subMenus; + vector < cSkinSetupMenu* >::iterator subMenuIt; + map < string, cSkinSetupParameter* > parameters; + map < string, cSkinSetupParameter* >::iterator paramIt; +public: + cSkinSetupMenu(void); + virtual ~cSkinSetupMenu(void); + void SetName(string name) { this->name = name; }; + void SetDisplayText(string displayText) { this->displayText = displayText; }; + string GetName(void) { return name; }; + string GetDisplayText(void) { return displayText; }; + void SetParent(cSkinSetupMenu *p) { parent = p; }; + cSkinSetupMenu *GetParent(void) { return parent; }; + void AddSubMenu(cSkinSetupMenu *sub) { subMenus.push_back(sub); }; + void SetParameter(eSetupParameterType paramType, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value); + void InitIterators(void); + void InitParameterIterator(void) { paramIt = parameters.begin(); }; + cSkinSetupParameter *GetNextParameter(bool deep = true); + cSkinSetupParameter *GetParameter(string name); + void InitSubmenuIterator(void) { subMenuIt = subMenus.begin(); }; + cSkinSetupMenu *GetNextSubMenu(bool deep = true); + cSkinSetupMenu *GetMenu(string &name); + void Debug(bool deep = true); +}; + // --- cSkinSetup ----------------------------------------------------------- class cSkinSetup { private: - string skin; - map < string, cSkinSetupParameter* > parameters; - map < string, cSkinSetupParameter* >::iterator paramIt; - map < string, map< string, string > > translations; + string skin; + cSkinSetupMenu *rootMenu; + cSkinSetupMenu *currentMenu; + map < string, map< string, string > > translations; string DoTranslate(string token); bool Translate(string text, string &translation); public: cSkinSetup(string skin); virtual ~cSkinSetup(void); bool ReadFromXML(void); + void SetSubMenu(xmlChar *name, xmlChar *displayText); + void SubMenuDone(void); void SetParameter(xmlChar *type, xmlChar *name, xmlChar* displayText, xmlChar *min, xmlChar *max, xmlChar *value); + void InitParameterIterator(void) { rootMenu->InitIterators(); }; + cSkinSetupParameter *GetNextParameter(void); + cSkinSetupParameter *GetParameter(string name); void SetTranslation(string translationToken, map < string, string > transl); void AddToGlobals(cGlobals *globals); void TranslateSetup(void); - void InitParameterIterator(void) { paramIt = parameters.begin(); }; - cSkinSetupParameter *GetParameter(void); - cSkinSetupParameter *GetParameter(string name); string GetSkin(void) { return skin; }; + cSkinSetupMenu *GetMenu(string &name); void Debug(void); }; |