mirror of
				https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
				synced 2023-10-19 15:58:31 +00:00 
			
		
		
		
	added support for custom tokens in dislaychannel
This commit is contained in:
		
							
								
								
									
										1
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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 | ||||
|   | ||||
							
								
								
									
										31
									
								
								designer.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								designer.c
									
									
									
									
									
								
							| @@ -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 | ||||
|   | ||||
| @@ -163,6 +163,10 @@ void cSDDisplayChannel::Flush(void) { | ||||
|     if (!doOutput) | ||||
|         return; | ||||
|  | ||||
|     if (initial) { | ||||
|         channelView->DrawCustomTokens(); | ||||
|     } | ||||
|  | ||||
|     if (initial || channelChange) { | ||||
|         channelView->DrawDate(); | ||||
|     } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -24,6 +24,7 @@ enum eViewElement { | ||||
|     veBackground, | ||||
|     veDateTime, | ||||
|     veMessage, | ||||
|     veCustomTokens, | ||||
|     //DisplayChannel ViewElements | ||||
|     veChannelInfo, | ||||
|     veChannelGroup, | ||||
|   | ||||
| @@ -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! | ||||
|   | ||||
| @@ -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> | ||||
|   | ||||
| @@ -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> | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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(); }; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user