From 0e0f05cfcb72e9d679a6681b9fcabd732856f942 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 11 Oct 2014 16:31:39 +0200 Subject: [PATCH] added support for custom tokens in dislaychannel --- HISTORY | 1 + designer.c | 31 +++++++++++++++++++++ designer.h | 2 ++ displaychannel.c | 4 +++ dtd/displaychannel.dtd | 7 ++++- libcore/helpers.c | 18 ++++++++++++ libcore/helpers.h | 4 +++ libtemplate/globals.h | 1 + libtemplate/templateview.c | 6 ++++ libtemplate/templateview.h | 1 + libtemplate/templateviewelement.h | 1 + skindesigner.c | 32 ++++++++++++++++++++-- skins/metrixhd/xmlfiles/displaychannel.xml | 8 ++++++ skinskeleton/xmlfiles/displaychannel.xml | 8 ++++++ views/displaychannelview.c | 11 ++++++++ views/displaychannelview.h | 1 + 16 files changed, 132 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index a85d835..697c5ea 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/designer.c b/designer.c index 75cf0d7..0d4669d 100644 --- a/designer.c +++ b/designer.c @@ -170,6 +170,37 @@ void cSkinDesigner::ListAvailableFonts(void) { fontManager->ListAvailableFonts(); } +bool cSkinDesigner::SetCustomToken(string option) { + splitstring s(option.c_str()); + vector 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::iterator hit = globals->customTokens.find(key); + if (hit != globals->customTokens.end()) { + globals->customTokens.erase(key); + } + globals->customTokens.insert(pair(key, val)); + + return true; +} + +void cSkinDesigner::ListCustomTokens(void) { + if (!globals) + return; + + for (map::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 *********************************************************************************/ diff --git a/designer.h b/designer.h index f3edf7b..3f0989e 100644 --- a/designer.h +++ b/designer.h @@ -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 @@ + datetime | message | customtokens)* > + + + %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(isspace)))); + return s; +} + +// trim from end +string &rtrim(string &s) { + s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun(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& 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 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 stringVars; map fonts; map > translations; + map 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 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 @@ + + + + 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 @@ + + + + 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(); }; };