diff options
author | louis <louis.braun@gmx.de> | 2014-10-11 16:31:39 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2014-10-11 16:31:39 +0200 |
commit | 0e0f05cfcb72e9d679a6681b9fcabd732856f942 (patch) | |
tree | e79b1772dbdd7fcb116f2298f4ac2f190aefff2d | |
parent | 04340d11c9c0efb908cce138edde535bc07636d7 (diff) | |
download | vdr-plugin-skindesigner-0e0f05cfcb72e9d679a6681b9fcabd732856f942.tar.gz vdr-plugin-skindesigner-0e0f05cfcb72e9d679a6681b9fcabd732856f942.tar.bz2 |
added support for custom tokens in dislaychannel
-rw-r--r-- | HISTORY | 1 | ||||
-rw-r--r-- | designer.c | 31 | ||||
-rw-r--r-- | designer.h | 2 | ||||
-rw-r--r-- | displaychannel.c | 4 | ||||
-rw-r--r-- | dtd/displaychannel.dtd | 7 | ||||
-rw-r--r-- | libcore/helpers.c | 18 | ||||
-rw-r--r-- | libcore/helpers.h | 4 | ||||
-rw-r--r-- | libtemplate/globals.h | 1 | ||||
-rw-r--r-- | libtemplate/templateview.c | 6 | ||||
-rw-r--r-- | libtemplate/templateview.h | 1 | ||||
-rw-r--r-- | libtemplate/templateviewelement.h | 1 | ||||
-rw-r--r-- | skindesigner.c | 32 | ||||
-rw-r--r-- | skins/metrixhd/xmlfiles/displaychannel.xml | 8 | ||||
-rw-r--r-- | skinskeleton/xmlfiles/displaychannel.xml | 8 | ||||
-rw-r--r-- | views/displaychannelview.c | 11 | ||||
-rw-r--r-- | views/displaychannelview.h | 1 |
16 files changed, 132 insertions, 4 deletions
@@ -19,3 +19,4 @@ Version 0.0.2 - support for global variables type "double" - added setup options to configure rerun display behaviour - changed display of menu lists, do flush first after complete rendering +- added support for custom tokens in dislaychannel @@ -170,6 +170,37 @@ void cSkinDesigner::ListAvailableFonts(void) { fontManager->ListAvailableFonts(); } +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; + + map<string, string>::iterator hit = globals->customTokens.find(key); + if (hit != globals->customTokens.end()) { + globals->customTokens.erase(key); + } + globals->customTokens.insert(pair<string,string>(key, val)); + + return true; +} + +void cSkinDesigner::ListCustomTokens(void) { + if (!globals) + return; + + for (map<string, string>::iterator it = globals->customTokens.begin(); it != globals->customTokens.end(); it++) { + dsyslog("skindesigner: custom token \"%s\" = \"%s\"", (it->first).c_str(), (it->second).c_str()); + } +} + /********************************************************************************* * PRIVATE FUNCTIONS *********************************************************************************/ @@ -49,6 +49,8 @@ public: void ActivateBackupSkin(void) { useBackupSkin = true; }; void Reload(void); void ListAvailableFonts(void); + bool SetCustomToken(string option); + void ListCustomTokens(void); }; #endif //__SKINDESIGNER_H diff --git a/displaychannel.c b/displaychannel.c index 4e99002..7442b87 100644 --- a/displaychannel.c +++ b/displaychannel.c @@ -163,6 +163,10 @@ void cSDDisplayChannel::Flush(void) { if (!doOutput) return; + if (initial) { + channelView->DrawCustomTokens(); + } + if (initial || channelChange) { channelView->DrawDate(); } diff --git a/dtd/displaychannel.dtd b/dtd/displaychannel.dtd index 538540b..be0f22e 100644 --- a/dtd/displaychannel.dtd +++ b/dtd/displaychannel.dtd @@ -5,7 +5,7 @@ <!ELEMENT displaychannel (background | channelinfo | epginfo | progressbar | progressbarback |
statusinfo | screenresolution | channelgroup |
signalquality | signalqualityback | scrapercontent |
- datetime | message)* >
+ datetime | message | customtokens)* >
<!ATTLIST displaychannel
x CDATA #REQUIRED
y CDATA #REQUIRED
@@ -83,4 +83,9 @@ debug CDATA #IMPLIED
>
+<!ELEMENT customtokens (area|areascroll)*>
+<!ATTLIST customtokens
+ debug CDATA #IMPLIED
+>
+
%functions;
diff --git a/libcore/helpers.c b/libcore/helpers.c index b4b507a..f24f6e7 100644 --- a/libcore/helpers.c +++ b/libcore/helpers.c @@ -121,6 +121,24 @@ bool FirstFileInFolder(string &path, string &extension, string &fileName) { return false; } +// trim from start +string <rim(string &s) { + s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))); + return s; +} + +// trim from end +string &rtrim(string &s) { + s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end()); + return s; +} + +// trim from both ends +string &trim(string &s) { + return ltrim(rtrim(s)); +} + + // split: receives a char delimiter; returns a vector of strings // By default ignores repeated delimiters, unless argument rep == 1. vector<string>& splitstring::split(char delim, int rep) { diff --git a/libcore/helpers.h b/libcore/helpers.h index 74ddf94..884738d 100644 --- a/libcore/helpers.h +++ b/libcore/helpers.h @@ -16,6 +16,10 @@ bool FileExists(const string &path, const string &name, const string &ext); bool FolderExists(const string &path); bool FirstFileInFolder(string &path, string &extension, string &fileName); +string <rim(string &s); +string &rtrim(string &s); +string &trim(string &s); + class splitstring : public std::string { std::vector<std::string> flds; public: diff --git a/libtemplate/globals.h b/libtemplate/globals.h index eda9ec9..09c9756 100644 --- a/libtemplate/globals.h +++ b/libtemplate/globals.h @@ -31,6 +31,7 @@ public: map <string, string> stringVars; map <string, string> fonts; map <string, map< string, string > > translations; + map <string, string> customTokens; bool ReadFromXML(void); bool Translate(string text, string &translation); void Debug(void); diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c index abaedc8..f1704f8 100644 --- a/libtemplate/templateview.c +++ b/libtemplate/templateview.c @@ -593,6 +593,7 @@ void cTemplateViewChannel::SetViewElements(void) { viewElementsAllowed.insert("scrapercontent"); viewElementsAllowed.insert("datetime"); viewElementsAllowed.insert("message"); + viewElementsAllowed.insert("customtokens"); } string cTemplateViewChannel::GetViewElementName(eViewElement ve) { @@ -637,6 +638,9 @@ string cTemplateViewChannel::GetViewElementName(eViewElement ve) { case veMessage: name = "Message"; break; + case veCustomTokens: + name = "Custom Tokens"; + break; default: name = "Unknown"; break; @@ -673,6 +677,8 @@ void cTemplateViewChannel::AddPixmap(string sViewElement, cTemplatePixmap *pix, ve = veDateTime; } else if (!sViewElement.compare("message")) { ve = veMessage; + } else if (!sViewElement.compare("customtokens")) { + ve = veCustomTokens; } if (ve == veUndefined) { diff --git a/libtemplate/templateview.h b/libtemplate/templateview.h index 414deaa..6603275 100644 --- a/libtemplate/templateview.h +++ b/libtemplate/templateview.h @@ -99,6 +99,7 @@ public: int GetNumPixmapsViewElement(eViewElement ve); int GetNumListViewMenuItems(void); bool GetScalingWindow(cRect &scalingWindow); + map<string,string> GetCustomTokens(void) { return globals->customTokens; }; //Checks for parsing template XML files bool ValidSubView(const char *subView); bool ValidViewElement(const char *viewElement); diff --git a/libtemplate/templateviewelement.h b/libtemplate/templateviewelement.h index 84db627..9c32a4c 100644 --- a/libtemplate/templateviewelement.h +++ b/libtemplate/templateviewelement.h @@ -24,6 +24,7 @@ enum eViewElement { veBackground,
veDateTime,
veMessage,
+ veCustomTokens,
//DisplayChannel ViewElements
veChannelInfo,
veChannelGroup,
diff --git a/skindesigner.c b/skindesigner.c index 131a23b..9001d97 100644 --- a/skindesigner.c +++ b/skindesigner.c @@ -157,6 +157,10 @@ const char **cPluginSkinDesigner::SVDRPHelpPages(void) { static const char *HelpPages[] = { "RELD\n" " force reload of templates and caches", + "SCTK\n" + " Set custom Token name = value", + "LCTK\n" + " List custom Tokens", "LSTF\n" " List available Fonts", 0 @@ -176,17 +180,39 @@ cString cPluginSkinDesigner::SVDRPCommand(const char *Command, const char *Optio } } - if (!activeSkin) - return NULL; + if (!activeSkin) { + ReplyCode = 550; + return ""; + } if (strcasecmp(Command, "RELD") == 0) { activeSkin->Reload(); + ReplyCode = 250; return "SKINDESIGNER reload of templates and caches forced."; } else if (strcasecmp(Command, "LSTF") == 0) { activeSkin->ListAvailableFonts(); + ReplyCode = 250; return "SKINDESIGNER available fonts listed in syslog."; + } else if (strcasecmp(Command, "SCTK") == 0) { + if (!Option) { + ReplyCode = 501; + return "SKINDESIGNER SCTK Error: no Token name = value set"; + } + bool optionOk = activeSkin->SetCustomToken(Option); + if (optionOk) { + ReplyCode = 250; + return cString::sprintf("SKINDESIGNER Set custom Token %s", Option); + } else { + ReplyCode = 501; + return cString::sprintf("SKINDESIGNER Invalid custom Token %s", Option); + } + } else if (strcasecmp(Command, "LCTK") == 0) { + activeSkin->ListCustomTokens(); + ReplyCode = 250; + return "SKINDESIGNER Custom Tokens listed in Log"; } - return NULL; + ReplyCode = 502; + return ""; } VDRPLUGINCREATOR(cPluginSkinDesigner); // Don't touch this! diff --git a/skins/metrixhd/xmlfiles/displaychannel.xml b/skins/metrixhd/xmlfiles/displaychannel.xml index ba8c347..22ff0b2 100644 --- a/skins/metrixhd/xmlfiles/displaychannel.xml +++ b/skins/metrixhd/xmlfiles/displaychannel.xml @@ -219,4 +219,12 @@ <drawtext align="center" valign="center" width="{areawidth} - 80" font="{light}" fontsize="40%" color="{clrWhite}" text="{text}" /> </area> </message> + + <!-- Available Variables customtokens: + all custom tokens set by the svdrp command SCTK are available in this viewelement + For instance, use an appropriate script which runs periodically as cronjob and + sets these custom tokens with svdrpsend or dbus2vdr + --> + <customtokens> + </customtokens> </displaychannel> diff --git a/skinskeleton/xmlfiles/displaychannel.xml b/skinskeleton/xmlfiles/displaychannel.xml index d9ce5eb..efa41dd 100644 --- a/skinskeleton/xmlfiles/displaychannel.xml +++ b/skinskeleton/xmlfiles/displaychannel.xml @@ -132,4 +132,12 @@ <message> </message> + <!-- Available Variables customtokens: + all custom tokens set by the svdrp command SCTK are available in this viewelement + For instance, use an appropriate script which runs periodically as cronjob and + sets these custom tokens with svdrpsend or dbus2vdr + --> + <customtokens> + </customtokens> + </displaychannel> diff --git a/views/displaychannelview.c b/views/displaychannelview.c index da24a5a..d55164a 100644 --- a/views/displaychannelview.c +++ b/views/displaychannelview.c @@ -479,6 +479,17 @@ void cDisplayChannelView::DisplayMessage(eMessageType Type, const char *Text) { DrawViewElement(veMessage, &stringTokens, &intTokens); } +void cDisplayChannelView::DrawCustomTokens(void) { + if (!ViewElementImplemented(veCustomTokens)) { + return; + } + if (!tmplView) + return; + map < string, string > stringTokens = tmplView->GetCustomTokens(); + map < string, int > intTokens; + DrawViewElement(veCustomTokens, &stringTokens, &intTokens); +} + void cDisplayChannelView::Action(void) { SetInitFinished(); FadeIn(); diff --git a/views/displaychannelview.h b/views/displaychannelview.h index 599ac5f..9d16e25 100644 --- a/views/displaychannelview.h +++ b/views/displaychannelview.h @@ -43,6 +43,7 @@ public: void DrawChannelGroups(const cChannel *Channel, cString ChannelName); void ClearChannelGroups(void); void DisplayMessage(eMessageType Type, const char *Text); + void DrawCustomTokens(void); void DoStart(void) { Start(); }; void Flush(void) { DoFlush(); }; }; |