diff --git a/HISTORY b/HISTORY index 0192557..c635020 100644 --- a/HISTORY +++ b/HISTORY @@ -229,4 +229,8 @@ Version 0.3.1 Version 0.3.2 - fixed crash if number of dvb devices changes +- added possibility to detach dedicated viewelements in displaychannel + and displaymenumain that they start in an own thread +- introduced background="true" attribute in viewelements. These areas + will only be drawn once. diff --git a/Makefile b/Makefile index 66a89d4..837608c 100644 --- a/Makefile +++ b/Makefile @@ -91,8 +91,8 @@ OBJS = $(PLUGIN).o \ views/view.o \ views/viewgrid.o \ views/viewhelpers.o \ + views/displayviewelements.o \ views/displaychannelview.o \ - views/displaychannelviewelements.o \ views/displaymenurootview.o \ views/displaymenuview.o \ views/displaymenulistview.o \ diff --git a/displaychannel.c b/displaychannel.c index bb447d3..711f05a 100644 --- a/displaychannel.c +++ b/displaychannel.c @@ -22,13 +22,11 @@ cSDDisplayChannel::cSDDisplayChannel(cTemplate *channelTemplate, bool WithInfo) doOutput = false; return; } - esyslog("skindesigner: displaychannel opened"); } cSDDisplayChannel::~cSDDisplayChannel() { if (channelView) delete channelView; - esyslog("skindesigner: displaychannel closed"); } void cSDDisplayChannel::SetChannel(const cChannel *Channel, int Number) { diff --git a/dtd/displaychannel.dtd b/dtd/displaychannel.dtd index cb86725..bb440a6 100644 --- a/dtd/displaychannel.dtd +++ b/dtd/displaychannel.dtd @@ -95,24 +95,36 @@ @@ -125,6 +137,9 @@ diff --git a/dtd/displaymenu.dtd b/dtd/displaymenu.dtd index 63baaae..4b6d248 100644 --- a/dtd/displaymenu.dtd +++ b/dtd/displaymenu.dtd @@ -53,54 +53,81 @@ diff --git a/dtd/functions.dtd b/dtd/functions.dtd index 5d6e782..ce80a54 100644 --- a/dtd/functions.dtd +++ b/dtd/functions.dtd @@ -7,6 +7,7 @@ layer CDATA #REQUIRED transparency CDATA #IMPLIED condition CDATA #IMPLIED + background (true|false) #IMPLIED debug (true|false) #IMPLIED > diff --git a/libtemplate/templatefunction.c b/libtemplate/templatefunction.c index 8ea8917..5e72948 100644 --- a/libtemplate/templatefunction.c +++ b/libtemplate/templatefunction.c @@ -83,6 +83,8 @@ void cTemplateFunction::SetParameters(vector > params) { p.first = ptLayer; } else if (!name.compare("transparency")) { p.first = ptTransparency; + } else if (!name.compare("background")) { + p.first = ptBackground; } else if (!name.compare("quadrant")) { p.first = ptQuadrant; } else if (!name.compare("type")) { @@ -271,6 +273,9 @@ bool cTemplateFunction::CalculateParameters(void) { case ptDetached: paramValid = SetDetached(value); break; + case ptBackground: + paramValid = SetBackground(value); + break; default: paramValid = true; break; @@ -413,6 +418,8 @@ int cTemplateFunction::GetNumericParameter(eParamType type) { return 0; else if (type == ptDetached) return 0; + else if (type == ptBackground) + return 0; return -1; } return hit->second; @@ -1077,6 +1084,14 @@ bool cTemplateFunction::SetDetached(string value) { return true; } +bool cTemplateFunction::SetBackground(string value) { + int back = 0; + if (!value.compare("true")) + back = 1; + numericParameters.insert(pair(ptBackground, back)); + return true; +} + void cTemplateFunction::ParseStringParameters(void) { //first replace stringtokens in Text (drawText) stringstream text; diff --git a/libtemplate/templatefunction.h b/libtemplate/templatefunction.h index e53dbda..a862aa7 100644 --- a/libtemplate/templatefunction.h +++ b/libtemplate/templatefunction.h @@ -56,6 +56,7 @@ enum eParamType { ptText, ptLayer, ptTransparency, + ptBackground, ptQuadrant, ptType, ptAlign, @@ -154,6 +155,7 @@ protected: bool SetOverflow(string value); bool SetHideRoot(string value); bool SetDetached(string value); + bool SetBackground(string value); void ParseStringParameters(void); void ParseNumericalParameters(void); void CalculateAlign(int elementWidth, int elementHeight); diff --git a/libtemplate/templatepixmap.c b/libtemplate/templatepixmap.c index 52ae63f..1490236 100644 --- a/libtemplate/templatepixmap.c +++ b/libtemplate/templatepixmap.c @@ -12,6 +12,7 @@ cTemplatePixmap::cTemplatePixmap(void) { containerHeight = 0; globals = NULL; scrolling = false; + background = false; } cTemplatePixmap::~cTemplatePixmap() { @@ -171,6 +172,8 @@ bool cTemplatePixmap::CalculateParameters(void) { } } + background = parameters->GetNumericParameter(ptBackground); + return paramsValid; } diff --git a/libtemplate/templatepixmap.h b/libtemplate/templatepixmap.h index 17bf7d3..a5d8f83 100644 --- a/libtemplate/templatepixmap.h +++ b/libtemplate/templatepixmap.h @@ -21,6 +21,7 @@ using namespace std; class cTemplatePixmap { protected: bool scrolling; + bool background; cTemplateFunction *parameters; vector functions; vector::iterator funcIt; @@ -76,6 +77,7 @@ public: bool DoExecute(void) { return parameters->DoExecute(); }; bool DoDebug(void) { return parameters->DoDebug(); }; bool Ready(void); + bool BackgroundArea(void) { return background; }; //Traverse Functions void InitIterator(void); cTemplateFunction *GetNextFunction(void); diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c index 5677a31..1383ed2 100644 --- a/libtemplate/templateview.c +++ b/libtemplate/templateview.c @@ -638,6 +638,7 @@ void cTemplateView::SetFunctionDefinitions(void) { attributes.insert("height"); attributes.insert("layer"); attributes.insert("transparency"); + attributes.insert("background"); funcsAllowed.insert(pair< string, set >(name, attributes)); name = "areascroll"; diff --git a/skins/blackhole/xmlfiles/displaymenumain.xml b/skins/blackhole/xmlfiles/displaymenumain.xml index abf6bcc..c82faf9 100644 --- a/skins/blackhole/xmlfiles/displaymenumain.xml +++ b/skins/blackhole/xmlfiles/displaymenumain.xml @@ -52,7 +52,7 @@ - + @@ -75,7 +75,7 @@ {timers[channelid]} ChannelID of channel {timers[channellogoexists]} true if channel logo exists --> - + @@ -97,7 +97,7 @@ {discalert} true if disc usage is > 95% {vdrusagestring} localized VDR internal usage string --> - + @@ -131,7 +131,7 @@ {load} current system load {loadhand} system load for tacho hand (between 0 and 2.5 in 0.025 steps multiplied by 1000, >2.5 is always 2525) --> - + @@ -144,7 +144,7 @@ {cputemp} current cpu temperature in °C {gputemp} current gpu temperature in °C --> - + diff --git a/skins/metrixhd/xmlfiles/displaychannel.xml b/skins/metrixhd/xmlfiles/displaychannel.xml index d6c201b..6851c6c 100644 --- a/skins/metrixhd/xmlfiles/displaychannel.xml +++ b/skins/metrixhd/xmlfiles/displaychannel.xml @@ -7,16 +7,6 @@ - - - - - - - - - - @@ -196,11 +186,11 @@ {devices[channelid]} ID of the currently tuned channel {devices[source]} source of the currently tuned channel --> - - + + - + @@ -235,6 +225,10 @@ {ozone} ozone value in DU --> + + + + @@ -284,6 +278,10 @@ {year} year in yyyy --> + + + + diff --git a/skins/metrixhd/xmlfiles/displaymenumain.xml b/skins/metrixhd/xmlfiles/displaymenumain.xml index ef588a6..d755f71 100644 --- a/skins/metrixhd/xmlfiles/displaymenumain.xml +++ b/skins/metrixhd/xmlfiles/displaymenumain.xml @@ -120,7 +120,7 @@ {timers[channelid]} ChannelID of channel {timers[channellogoexists]} true if channel logo exists --> - + @@ -174,8 +174,8 @@ {discalert} true if disc usage is > 95% {vdrusagestring} localized VDR internal usage string --> - - + + @@ -206,7 +206,7 @@ {pressure} pressure in HPo {ozone} ozone value in DU --> - + @@ -240,8 +240,8 @@ {devices[channelid]} ID of the currently tuned channel {devices[source]} source of the currently tuned channel --> - - + + @@ -261,8 +261,8 @@ - - + + diff --git a/skins/nopacity/xmlfiles/displaymenumain.xml b/skins/nopacity/xmlfiles/displaymenumain.xml index 5af1bc9..cfcc631 100644 --- a/skins/nopacity/xmlfiles/displaymenumain.xml +++ b/skins/nopacity/xmlfiles/displaymenumain.xml @@ -28,7 +28,7 @@ {timers[channelid]} ChannelID of channel {timers[channellogoexists]} true if channel logo exists --> - + @@ -61,8 +61,8 @@ {discalert} true if disc usage is > 95% {vdrusagestring} localized VDR internal usage string --> - - + + @@ -75,8 +75,8 @@ - - + + diff --git a/views/displaychannelview.c b/views/displaychannelview.c index 314cfba..51bfa6b 100644 --- a/views/displaychannelview.c +++ b/views/displaychannelview.c @@ -2,16 +2,13 @@ #include #include "../services/scraper2vdr.h" #include "displaychannelview.h" -#include "displaychannelviewelements.h" +#include "displayviewelements.h" #include "../libcore/timers.h" #include "../libcore/helpers.h" cDisplayChannelView::cDisplayChannelView(cTemplateView *tmplView) : cView(tmplView) { lastScreenWidth = 0; lastScreenHeight = 0; - lastSignalDisplay = 0; - lastSignalStrength = 0; - lastSignalQuality = 0; lastNumAudioTracks = 0; lastAudioChannel = -1; lastTracDesc = ""; @@ -65,15 +62,27 @@ void cDisplayChannelView::DrawDate(void) { return; } - map < string, string > stringTokens; - map < string, int > intTokens; - - if (!SetDate(stringTokens, intTokens)) { - return; - } + if (DetachViewElement(veDateTime)) { + cViewElement *viewElement = GetViewElement(veDateTime); + if (!viewElement) { + viewElement = new cViewElementDate(tmplView->GetViewElement(veDateTime)); + AddViewElement(veDateTime, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + + if (!SetDate(stringTokens, intTokens)) { + return; + } - ClearViewElement(veDateTime); - DrawViewElement(veDateTime, &stringTokens, &intTokens); + ClearViewElement(veDateTime); + DrawViewElement(veDateTime, &stringTokens, &intTokens); + } } void cDisplayChannelView::DrawTime(void) { @@ -81,14 +90,26 @@ void cDisplayChannelView::DrawTime(void) { return; } - map < string, string > stringTokens; - map < string, int > intTokens; + if (DetachViewElement(veTime)) { + cViewElement *viewElement = GetViewElement(veTime); + if (!viewElement) { + viewElement = new cViewElementTime(tmplView->GetViewElement(veTime)); + AddViewElement(veTime, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; - if (!SetTime(stringTokens, intTokens)) { - return; - } - ClearViewElement(veTime); - DrawViewElement(veTime, &stringTokens, &intTokens); + if (!SetTime(stringTokens, intTokens)) { + return; + } + ClearViewElement(veTime); + DrawViewElement(veTime, &stringTokens, &intTokens); + } } void cDisplayChannelView::DrawProgressBar(cString &start, cString &stop, int Current, int Total) { @@ -316,72 +337,22 @@ void cDisplayChannelView::DrawScraperContent(const cEvent *event) { return; } - static cPlugin *pScraper = GetScraperPlugin(); - if (!pScraper) { - return; - } - - ScraperGetPosterBanner call; - call.event = event; - if (pScraper->Service("GetPosterBanner", &call)) { - int mediaWidth = 0; - int mediaHeight = 0; - string mediaPath = ""; - bool isBanner = false; - int posterWidth = 0; - int posterHeight = 0; - string posterPath = ""; - bool hasPoster = false; - int bannerWidth = 0; - int bannerHeight = 0; - string bannerPath = ""; - bool hasBanner = false; - - if ((call.type == tSeries) && call.banner.path.size() > 0) { - mediaWidth = call.banner.width; - mediaHeight = call.banner.height; - mediaPath = call.banner.path; - isBanner = true; - bannerWidth = mediaWidth; - bannerHeight = mediaHeight; - bannerPath = mediaPath; - hasBanner = true; - - ScraperGetPoster callPoster; - callPoster.event = event; - callPoster.recording = NULL; - if (pScraper->Service("GetPoster", &callPoster)) { - posterWidth = callPoster.poster.width; - posterHeight = callPoster.poster.height; - posterPath = callPoster.poster.path; - hasPoster = true; - } - } else if (call.type == tMovie && call.poster.path.size() > 0 && call.poster.height > 0) { - mediaWidth = call.poster.width; - mediaHeight = call.poster.height; - mediaPath = call.poster.path; - posterWidth = call.poster.width; - posterHeight = call.poster.height; - posterPath = call.poster.path; - hasPoster = true; - } else - return; - - map < string, int > intTokens; + if (DetachViewElement(veScraperContent)) { + cViewElement *viewElement = GetViewElement(veScraperContent); + if (!viewElement) { + viewElement = new cViewElementScraperContent(event, ctPosterBanner, tmplView->GetViewElement(veScraperContent)); + AddViewElement(veScraperContent, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { map < string, string > stringTokens; - intTokens.insert(pair("mediawidth", mediaWidth)); - intTokens.insert(pair("mediaheight", mediaHeight)); - intTokens.insert(pair("isbanner", isBanner)); - stringTokens.insert(pair("mediapath", mediaPath)); - intTokens.insert(pair("posterwidth", posterWidth)); - intTokens.insert(pair("posterheight", posterHeight)); - stringTokens.insert(pair("posterpath", posterPath)); - intTokens.insert(pair("hasposter", hasPoster)); - intTokens.insert(pair("bannerwidth", bannerWidth)); - intTokens.insert(pair("bannerheight", bannerHeight)); - stringTokens.insert(pair("bannerpath", bannerPath)); - intTokens.insert(pair("hasbanner", hasBanner)); - ClearViewElement(veScraperContent); + map < string, int > intTokens; + + SetPosterBanner(event, stringTokens, intTokens); + ClearScraperContent(); DrawViewElement(veScraperContent, &stringTokens, &intTokens); } } @@ -395,25 +366,26 @@ void cDisplayChannelView::DrawSignal(void) { return; } - time_t Now = time(NULL); - if (Now != lastSignalDisplay) { - int SignalStrength = cDevice::ActualDevice()->SignalStrength(); - int SignalQuality = cDevice::ActualDevice()->SignalQuality(); - if (SignalStrength < 0) SignalStrength = 0; - if (SignalQuality < 0) SignalQuality = 0; - if ((SignalStrength == 0)&&(SignalQuality==0)) - return; - if ((lastSignalStrength != SignalStrength) || (lastSignalQuality != SignalQuality)) { - map < string, int > intTokens; - map < string, string > stringTokens; - intTokens.insert(pair("signalstrength", SignalStrength)); - intTokens.insert(pair("signalquality", SignalQuality)); - ClearViewElement(veSignalQuality); - DrawViewElement(veSignalQuality, &stringTokens, &intTokens); + if (DetachViewElement(veSignalQuality)) { + cViewElement *viewElement = GetViewElement(veSignalQuality); + if (!viewElement) { + viewElement = new cViewElementSignal(tmplView->GetViewElement(veSignalQuality)); + AddViewElement(veSignalQuality, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); } - lastSignalStrength = SignalStrength; - lastSignalQuality = SignalQuality; - lastSignalDisplay = Now; + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + + bool changed = SetSignal(intTokens); + if (!changed) + return; + + ClearSignal(); + DrawViewElement(veSignalQuality, &stringTokens, &intTokens); } } @@ -445,7 +417,8 @@ void cDisplayChannelView::DrawDevices(bool initial) { AddViewElement(veDevices, viewElement); viewElement->Start(); } else { - viewElement->Render(); + if (!viewElement->Starting()) + viewElement->Render(); } } else { map < string, string > stringTokens; @@ -459,10 +432,9 @@ void cDisplayChannelView::DrawDevices(bool initial) { deviceLoopTokens.insert(pair< string, vector< map< string, string > > >("devices", devices)); - ClearViewElement(veDevices); + ClearDevices(); DrawViewElement(veDevices, &stringTokens, &intTokens, &deviceLoopTokens); } - } void cDisplayChannelView::ClearDevices(void) { @@ -477,8 +449,8 @@ void cDisplayChannelView::DrawChannelGroups(const cChannel *Channel, cString Cha bool separatorExists = imgCache->SeparatorLogoExists(*ChannelName); string separatorPath = separatorExists ? *ChannelName : ""; - std::string prevChannelSep = GetChannelSep(Channel, true); - std::string nextChannelSep = GetChannelSep(Channel, false); + string prevChannelSep = GetChannelSep(Channel, true); + string nextChannelSep = GetChannelSep(Channel, false); bool prevAvailable = (prevChannelSep.size() > 0)?true:false; bool nextAvailable = (nextChannelSep.size() > 0)?true:false; @@ -502,7 +474,7 @@ void cDisplayChannelView::ClearChannelGroups(void) { } string cDisplayChannelView::GetChannelSep(const cChannel *channel, bool prev) { - std::string sepName = ""; + string sepName = ""; const cChannel *sep = prev ? Channels.Prev(channel) : Channels.Next(channel); for (; sep; (prev)?(sep = Channels.Prev(sep)):(sep = Channels.Next(sep))) { @@ -540,24 +512,49 @@ void cDisplayChannelView::DrawCustomTokens(void) { } if (!tmplView) return; - map < string, string > stringTokens = tmplView->GetCustomStringTokens(); - map < string, int > intTokens = tmplView->GetCustomIntTokens(); - DrawViewElement(veCustomTokens, &stringTokens, &intTokens); + + if (DetachViewElement(veCustomTokens)) { + cViewElement *viewElement = GetViewElement(veCustomTokens); + if (!viewElement) { + viewElement = new cViewElementCustomTokens(tmplView->GetViewElement(veCustomTokens), tmplView); + AddViewElement(veCustomTokens, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens = tmplView->GetCustomStringTokens(); + map < string, int > intTokens = tmplView->GetCustomIntTokens(); + DrawViewElement(veCustomTokens, &stringTokens, &intTokens); + } } void cDisplayChannelView::DrawCurrentWeather(void) { if (!ExecuteViewElement(veCurrentWeather)) { return; } - map < string, string > stringTokens; - map < string, int > intTokens; - if (!SetCurrentWeatherTokens(stringTokens, intTokens)){ + + if (DetachViewElement(veCurrentWeather)) { + cViewElement *viewElement = GetViewElement(veCurrentWeather); + if (!viewElement) { + viewElement = new cViewElementWeather(tmplView->GetViewElement(veCurrentWeather)); + AddViewElement(veCurrentWeather, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + if (!SetCurrentWeatherTokens(stringTokens, intTokens)){ + ClearViewElement(veCurrentWeather); + return; + } ClearViewElement(veCurrentWeather); - return; + DrawViewElement(veCurrentWeather, &stringTokens, &intTokens); } - - ClearViewElement(veCurrentWeather); - DrawViewElement(veCurrentWeather, &stringTokens, &intTokens); } diff --git a/views/displaychannelview.h b/views/displaychannelview.h index 5990232..e3f33c3 100644 --- a/views/displaychannelview.h +++ b/views/displaychannelview.h @@ -9,9 +9,6 @@ class cDisplayChannelView : public cView, public cViewHelpers { private: int lastScreenWidth; int lastScreenHeight; - int lastSignalDisplay; - int lastSignalStrength; - int lastSignalQuality; int lastNumAudioTracks; int lastAudioChannel; string lastTracDesc; diff --git a/views/displaychannelviewelements.c b/views/displaychannelviewelements.c deleted file mode 100644 index 7709b94..0000000 --- a/views/displaychannelviewelements.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "displaychannelviewelements.h" - -cViewElementDevices::cViewElementDevices(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { - init = true; -} - -void cViewElementDevices::Render(void) { - map < string, vector< map< string, string > > > deviceLoopTokens; - vector< map< string, string > > devices; - - if (init) - InitDevices(); - bool changed = SetDevices(init, &intTokens, &devices); - init = false; - - if (!changed) - return; - - deviceLoopTokens.insert(pair< string, vector< map< string, string > > >("devices", devices)); - - Clear(); - Draw(&deviceLoopTokens); -} \ No newline at end of file diff --git a/views/displaychannelviewelements.h b/views/displaychannelviewelements.h deleted file mode 100644 index 87d45c9..0000000 --- a/views/displaychannelviewelements.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __DISPLAYCHANNELVIEWELEMENTS_H -#define __DISPLAYCHANNELVIEWELEMENTS_H - -#include "../libtemplate/template.h" -#include "view.h" -#include "viewhelpers.h" - -class cViewElementDevices : public cViewElement, public cViewHelpers { -private: - bool init; -public: - cViewElementDevices(cTemplateViewElement *tmplViewElement); - virtual ~cViewElementDevices() {}; - void Render(void); -}; - -#endif //__DISPLAYCHANNELVIEWELEMENTS_H \ No newline at end of file diff --git a/views/displaymenuitemcurrentview.c b/views/displaymenuitemcurrentview.c index 48f1459..6a88067 100644 --- a/views/displaymenuitemcurrentview.c +++ b/views/displaymenuitemcurrentview.c @@ -62,12 +62,13 @@ cDisplayMenuItemCurrentMainView::cDisplayMenuItemCurrentMainView(cTemplateViewEl this->icon = icon; } -void cDisplayMenuItemCurrentMainView::Render(void) { +bool cDisplayMenuItemCurrentMainView::Render(void) { stringTokens.insert(pair("number", number)); stringTokens.insert(pair("label", label)); stringTokens.insert(pair("icon", icon)); SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens); + return true; } /************************************************************* @@ -83,7 +84,7 @@ cDisplayMenuItemCurrentSchedulesView::cDisplayMenuItemCurrentSchedulesView(cTemp this->isEpgSearchFav = isEpgSearchFav; } -void cDisplayMenuItemCurrentSchedulesView::Render(void) { +bool cDisplayMenuItemCurrentSchedulesView::Render(void) { intTokens.insert(pair("whatson", (cat == mcSchedule)&&(!isEpgSearchFav) ? true: false)); intTokens.insert(pair("whatsonnow", (cat == mcScheduleNow) ? true: false)); intTokens.insert(pair("whatsonnext", (cat == mcScheduleNext) ? true: false)); @@ -145,6 +146,7 @@ void cDisplayMenuItemCurrentSchedulesView::Render(void) { loopTokens.insert(pair > >("schedule", schedulesTokens)); SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); + return true; } void cDisplayMenuItemCurrentSchedulesView::ReadSchedules(vector< map > *schedulesTokens) { @@ -179,9 +181,9 @@ cDisplayMenuItemCurrentChannelView::cDisplayMenuItemCurrentChannelView(cTemplate this->channel = channel; } -void cDisplayMenuItemCurrentChannelView::Render(void) { +bool cDisplayMenuItemCurrentChannelView::Render(void) { if (!channel) - return; + return false; //general channel information intTokens.insert(pair("number", channel->Number())); intTokens.insert(pair("transponder", channel->Transponder())); @@ -276,6 +278,7 @@ void cDisplayMenuItemCurrentChannelView::Render(void) { loopTokens.insert(pair > >("schedule", schedulesTokens)); SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); + return true; } void cDisplayMenuItemCurrentChannelView::ReadSchedules(vector< map > *schedulesTokens) { @@ -314,9 +317,9 @@ cDisplayMenuItemCurrentTimerView::cDisplayMenuItemCurrentTimerView(cTemplateView this->timer = timer; } -void cDisplayMenuItemCurrentTimerView::Render(void) { +bool cDisplayMenuItemCurrentTimerView::Render(void) { if (!timer) - return; + return false; intTokens.insert(pair("flagactive", timer->HasFlags(tfActive))); intTokens.insert(pair("flaginstant", timer->HasFlags(tfInstant))); intTokens.insert(pair("flagvps", timer->HasFlags(tfVps))); @@ -398,6 +401,7 @@ void cDisplayMenuItemCurrentTimerView::Render(void) { } SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens); + return true; } /************************************************************* @@ -412,9 +416,9 @@ cDisplayMenuItemCurrentRecordingView::cDisplayMenuItemCurrentRecordingView(cTemp this->newRecs = newRecs; } -void cDisplayMenuItemCurrentRecordingView::Render(void) { +bool cDisplayMenuItemCurrentRecordingView::Render(void) { if (!recording) - return; + return false; map < string, vector< map< string, string > > > loopTokens; bool isFolder = (total > 0) ? true : false; @@ -468,7 +472,7 @@ void cDisplayMenuItemCurrentRecordingView::Render(void) { const cRecordingInfo *info = usedRecording->Info(); - if (!info) return; + if (!info) return true; bool extRecinfoAvailable = false; if (info->Aux()) { @@ -509,7 +513,7 @@ void cDisplayMenuItemCurrentRecordingView::Render(void) { stringTokens.insert(pair("description", info->Description() ? info->Description() : "")); const cEvent *event = info->GetEvent(); - if (!event) return; + if (!event) return true; string recDate = *(event->GetDateString()); string recTime = *(event->GetTimeString()); @@ -538,6 +542,7 @@ void cDisplayMenuItemCurrentRecordingView::Render(void) { stringTokens.insert(pair("durationeventminutes", *cString::sprintf("%.2d", duration%60))); SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); + return true; } /************************************************************* @@ -553,7 +558,8 @@ cDisplayMenuItemCurrentPluginView::cDisplayMenuItemCurrentPluginView(cTemplateVi loopTokens = pluginLoopTokens; } -void cDisplayMenuItemCurrentPluginView::Render(void) { +bool cDisplayMenuItemCurrentPluginView::Render(void) { SetTokensPosMenuItem(); DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); + return true; } diff --git a/views/displaymenuitemcurrentview.h b/views/displaymenuitemcurrentview.h index c925ffa..810355d 100644 --- a/views/displaymenuitemcurrentview.h +++ b/views/displaymenuitemcurrentview.h @@ -24,7 +24,7 @@ private: public: cDisplayMenuItemCurrentMainView(cTemplateViewElement *tmplCurrent, string number, string label, string icon); virtual ~cDisplayMenuItemCurrentMainView() {}; - void Render(void); + bool Render(void); }; class cDisplayMenuItemCurrentSchedulesView: public cDisplayMenuItemCurrentView { @@ -38,7 +38,7 @@ private: public: cDisplayMenuItemCurrentSchedulesView(cTemplateViewElement *tmplCurrent, const cEvent *event, const cChannel *channel, eTimerMatch timerMatch, eMenuCategory cat, bool isEpgSearchFav); virtual ~cDisplayMenuItemCurrentSchedulesView() {}; - void Render(void); + bool Render(void); }; class cDisplayMenuItemCurrentChannelView: public cDisplayMenuItemCurrentView { @@ -48,7 +48,7 @@ private: public: cDisplayMenuItemCurrentChannelView(cTemplateViewElement *tmplCurrent, const cChannel *channel); virtual ~cDisplayMenuItemCurrentChannelView() {}; - void Render(void); + bool Render(void); }; class cDisplayMenuItemCurrentTimerView: public cDisplayMenuItemCurrentView { @@ -57,7 +57,7 @@ private: public: cDisplayMenuItemCurrentTimerView(cTemplateViewElement *tmplCurrent, const cTimer *timer); virtual ~cDisplayMenuItemCurrentTimerView() {}; - void Render(void); + bool Render(void); }; class cDisplayMenuItemCurrentRecordingView: public cDisplayMenuItemCurrentView { @@ -69,7 +69,7 @@ private: public: cDisplayMenuItemCurrentRecordingView(cTemplateViewElement *tmplCurrent, const cRecording *recording, int level, int total, int newRecs); virtual ~cDisplayMenuItemCurrentRecordingView() {}; - void Render(void); + bool Render(void); }; class cDisplayMenuItemCurrentPluginView: public cDisplayMenuItemCurrentView { @@ -78,7 +78,7 @@ private: public: cDisplayMenuItemCurrentPluginView(cTemplateViewElement *tmplCurrent, map &plugStringTokens, map &plugIntTokens, map > > &pluginLoopTokens); virtual ~cDisplayMenuItemCurrentPluginView() {}; - void Render(void); + bool Render(void); }; #endif //__DISPLAYMENUITEMCURRENTVIEW_H diff --git a/views/displaymenurootview.c b/views/displaymenurootview.c index aaef353..efe7816 100644 --- a/views/displaymenurootview.c +++ b/views/displaymenurootview.c @@ -1,12 +1,13 @@ #define __STL_CONFIG_H #include -#include #include "displaymenurootview.h" +#include "displayviewelements.h" #include "../config.h" #include "../libcore/helpers.h" cDisplayMenuRootView::cDisplayMenuRootView(cTemplateView *rootView) : cView(rootView) { cat = mcUndefined; + menuTitle = ""; viewType = svUndefined; subView = NULL; subViewAvailable = false; @@ -479,37 +480,9 @@ void cDisplayMenuRootView::DrawHeader(void) { if (!ExecuteViewElement(veHeader)) { return; } - map < string, string > stringTokens; map < string, int > intTokens; - - stringTokens.insert(pair("title", menuTitle)); - stringTokens.insert(pair("vdrversion", VDRVERSION)); - - //check for standard menu entries - bool hasIcon = false; - - string icon = imgCache->GetIconName(menuTitle, cat); - if (imgCache->MenuIconExists(icon)) - hasIcon = true; - - stringTokens.insert(pair("icon", icon)); - intTokens.insert(pair("hasicon", hasIcon)); - - //Disc Usage - string vdrUsageString = *cVideoDiskUsage::String(); - int discUsage = cVideoDiskUsage::UsedPercent(); - bool discAlert = (discUsage > 95) ? true : false; - string freeTime = *cString::sprintf("%02d:%02d", cVideoDiskUsage::FreeMinutes() / 60, cVideoDiskUsage::FreeMinutes() % 60); - int freeGB = cVideoDiskUsage::FreeMB() / 1024; - - intTokens.insert(pair("usedpercent", discUsage)); - intTokens.insert(pair("freepercent", 100-discUsage)); - intTokens.insert(pair("discalert", discAlert)); - intTokens.insert(pair("freegb", freeGB)); - stringTokens.insert(pair("freetime", freeTime)); - stringTokens.insert(pair("vdrusagestring", vdrUsageString)); - + SetMenuHeader(cat, menuTitle, stringTokens, intTokens); ClearViewElement(veHeader); DrawViewElement(veHeader, &stringTokens, &intTokens); } diff --git a/views/displaymenuview.c b/views/displaymenuview.c index 22b6084..4e7b0d5 100644 --- a/views/displaymenuview.c +++ b/views/displaymenuview.c @@ -1,13 +1,10 @@ #define __STL_CONFIG_H -#include -#include -#include #include #include #include "displaymenuview.h" +#include "displayviewelements.h" #include "../config.h" #include "../libcore/helpers.h" -#include "../libcore/timers.h" #include "../services/scraper2vdr.h" cDisplayMenuView::cDisplayMenuView(cTemplateView *tmplView, bool menuInit) : cView(tmplView) { @@ -39,35 +36,9 @@ bool cDisplayMenuView::DrawHeader(void) { if (!ExecuteViewElement(veHeader)) { return false; } - map < string, string > stringTokens; map < string, int > intTokens; - - stringTokens.insert(pair("title", menuTitle)); - stringTokens.insert(pair("vdrversion", VDRVERSION)); - - //check for standard menu entries - bool hasIcon = false; - string icon = imgCache->GetIconName(menuTitle, cat); - if (imgCache->MenuIconExists(icon)) - hasIcon = true; - stringTokens.insert(pair("icon", icon)); - intTokens.insert(pair("hasicon", hasIcon)); - - //Disc Usage - string vdrUsageString = *cVideoDiskUsage::String(); - int discUsage = cVideoDiskUsage::UsedPercent(); - bool discAlert = (discUsage > 95) ? true : false; - string freeTime = *cString::sprintf("%02d:%02d", cVideoDiskUsage::FreeMinutes() / 60, cVideoDiskUsage::FreeMinutes() % 60); - int freeGB = cVideoDiskUsage::FreeMB() / 1024; - - intTokens.insert(pair("usedpercent", discUsage)); - intTokens.insert(pair("freepercent", 100-discUsage)); - intTokens.insert(pair("discalert", discAlert)); - intTokens.insert(pair("freegb", freeGB)); - stringTokens.insert(pair("freetime", freeTime)); - stringTokens.insert(pair("vdrusagestring", vdrUsageString)); - + SetMenuHeader(cat, menuTitle, stringTokens, intTokens); ClearViewElement(veHeader); DrawViewElement(veHeader, &stringTokens, &intTokens); return true; @@ -224,8 +195,6 @@ void cDisplayMenuView::Action(void) { cDisplayMenuMainView::cDisplayMenuMainView(cTemplateView *tmplView, bool menuInit) : cDisplayMenuView(tmplView, menuInit) { initial = true; - lastSystemLoad = 0.0; - lastMemUsage = -1; InitDevices(); } @@ -256,382 +225,215 @@ void cDisplayMenuMainView::DrawTimers(void) { if (!ExecuteViewElement(veTimers)) { return; } - - map < string, string > stringTokens; - map < string, int > intTokens; - - map < string, vector< map< string, string > > > timerLoopTokens; - vector< map< string, string > > timers; - - cGlobalSortedTimers SortedTimers;// local and remote timers - int numTimers = SortedTimers.Size(); - - intTokens.insert(pair("numtimers", numTimers)); - - int numTimerConflicts = SortedTimers.NumTimerConfilicts(); - intTokens.insert(pair("numtimerconflicts", numTimerConflicts)); - - for (int i=0; i<15; i++) { - stringstream name; - name << "timer" << i+1 << "exists"; - if (i < numTimers) { - intTokens.insert(pair(name.str(), true)); + if (DetachViewElement(veTimers)) { + cViewElement *viewElement = GetViewElement(veTimers); + if (!viewElement) { + viewElement = new cViewElementTimers(tmplView->GetViewElement(veTimers)); + AddViewElement(veTimers, viewElement); + viewElement->Start(); } else { - intTokens.insert(pair(name.str(), false)); + if (!viewElement->Starting()) + viewElement->Render(); } - } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + map < string, vector< map< string, string > > > timerLoopTokens; + vector< map< string, string > > timers; - for (int i = 0; i < numTimers; i++) { - if (i >=15) - break; - map< string, string > timerVals; - const cTimer *Timer = SortedTimers[i]; - const cEvent *event = Timer->Event(); - if (event) { - timerVals.insert(pair< string, string >("timers[title]", event->Title())); - } else { - const char *File = Setup.FoldersInTimerMenu ? NULL : strrchr(Timer->File(), FOLDERDELIMCHAR); - if (File && strcmp(File + 1, TIMERMACRO_TITLE) && strcmp(File + 1, TIMERMACRO_EPISODE)) - File++; - else - File = Timer->File(); - timerVals.insert(pair< string, string >("timers[title]", File)); - } - const cChannel *channel = Timer->Channel(); - if (channel) { - timerVals.insert(pair< string, string >("timers[channelname]", channel->Name())); - stringstream chanNum; - chanNum << channel->Number(); - timerVals.insert(pair< string, string >("timers[channelnumber]", chanNum.str())); - string channelID = *(channel->GetChannelID().ToString()); - timerVals.insert(pair< string, string >("timers[channelid]", channelID)); - bool logoExists = imgCache->LogoExists(channelID); - timerVals.insert(pair< string, string >("timers[channellogoexists]", logoExists ? "1" : "0")); - } else { - timerVals.insert(pair< string, string >("timers[channelname]", "")); - timerVals.insert(pair< string, string >("timers[channelnumber]", "0")); - timerVals.insert(pair< string, string >("timers[channelid]", "")); - timerVals.insert(pair< string, string >("timers[channellogoexists]", "0")); - } - - timerVals.insert(pair< string, string >("timers[recording]", Timer->Recording() ? "1" : "0")); + SetTimers(&intTokens, &stringTokens, &timers); - cString timerDate(""); - if (Timer->Recording()) { - timerDate = cString::sprintf("-%s", *TimeString(Timer->StopTime())); - } else { - time_t Now = time(NULL); - cString Today = WeekDayName(Now); - cString Time = TimeString(Timer->StartTime()); - cString Day = WeekDayName(Timer->StartTime()); - if (Timer->StartTime() > Now + 6 * SECSINDAY) { - time_t ttm = Timer->StartTime(); - struct tm * timerTime = localtime(&ttm); - timerDate = cString::sprintf("%02d.%02d %s", timerTime->tm_mday, timerTime->tm_mon + 1, *Time); - } else if (strcmp(Day, Today) != 0) - timerDate = cString::sprintf("%s %s", *Day, *Time); - else - timerDate = Time; - if (Timer->Flags() & tfVps) - timerDate = cString::sprintf("VPS %s", *timerDate); - } - timerVals.insert(pair< string, string >("timers[datetime]", *timerDate)); + timerLoopTokens.insert(pair< string, vector< map< string, string > > >("timers", timers)); - timers.push_back(timerVals); - } - - timerLoopTokens.insert(pair< string, vector< map< string, string > > >("timers", timers)); - - ClearViewElement(veTimers); - DrawViewElement(veTimers, &stringTokens, &intTokens, &timerLoopTokens); + ClearViewElement(veTimers); + DrawViewElement(veTimers, &stringTokens, &intTokens, &timerLoopTokens); + } } void cDisplayMenuMainView::DrawDiscUsage(void) { if (!ExecuteViewElement(veDiscUsage)) { return; } - - map < string, string > stringTokens; - map < string, int > intTokens; - - string vdrUsageString = *cVideoDiskUsage::String(); - int discUsage = cVideoDiskUsage::UsedPercent(); - bool discAlert = (discUsage > 95) ? true : false; - string freeTime = *cString::sprintf("%02d:%02d", cVideoDiskUsage::FreeMinutes() / 60, cVideoDiskUsage::FreeMinutes() % 60); - int freeGB = cVideoDiskUsage::FreeMB() / 1024; - - intTokens.insert(pair("usedpercent", discUsage)); - intTokens.insert(pair("freepercent", 100-discUsage)); - intTokens.insert(pair("discalert", discAlert)); - intTokens.insert(pair("freegb", freeGB)); - stringTokens.insert(pair("freetime", freeTime)); - stringTokens.insert(pair("vdrusagestring", vdrUsageString)); - - ClearViewElement(veDiscUsage); - DrawViewElement(veDiscUsage, &stringTokens, &intTokens); + if (DetachViewElement(veDiscUsage)) { + cViewElement *viewElement = GetViewElement(veDiscUsage); + if (!viewElement) { + viewElement = new cViewElementDiscUsage(tmplView->GetViewElement(veDiscUsage)); + AddViewElement(veDiscUsage, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + SetDiscUsage(stringTokens, intTokens); + ClearViewElement(veDiscUsage); + DrawViewElement(veDiscUsage, &stringTokens, &intTokens); + } } bool cDisplayMenuMainView::DrawLoad(void) { if (!ExecuteViewElement(veSystemLoad)) { return false; } - - map < string, string > stringTokens; - map < string, int > intTokens; - - double systemLoad; - if (getloadavg(&systemLoad, 1) > 0) { - if (lastSystemLoad == systemLoad) { - return false; + bool changed = false; + if (DetachViewElement(veSystemLoad)) { + cViewElement *viewElement = GetViewElement(veSystemLoad); + if (!viewElement) { + viewElement = new cViewElementSystemLoad(tmplView->GetViewElement(veSystemLoad)); + AddViewElement(veSystemLoad, viewElement); + viewElement->Start(); + changed = true; + } else { + if (!viewElement->Starting()) + changed = viewElement->Render(); } - string load = *cString::sprintf("%.2f", systemLoad); - int loadHand = systemLoad * 1000; - int loadHandValue = 0; - if (loadHand > 2500) - loadHandValue = 2525; - else { - - int loadHandDec = loadHand - (loadHand / 100) * 100; - - if (loadHandDec <= 12) - loadHandDec = 0; - else if (loadHandDec <= 37) - loadHandDec = 25; - else if (loadHandDec <= 62) - loadHandDec = 50; - else if (loadHandDec <= 87) - loadHandDec = 75; - else - loadHandDec = 0; - - loadHandValue = loadHand / 100 * 100 + loadHandDec; + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + changed = SetSystemLoad(stringTokens, intTokens); + if (changed) { + ClearViewElement(veSystemLoad); + DrawViewElement(veSystemLoad, &stringTokens, &intTokens); } - - stringTokens.insert(pair("load", load)); - intTokens.insert(pair("loadhand", loadHandValue)); - lastSystemLoad = systemLoad; } - - ClearViewElement(veSystemLoad); - DrawViewElement(veSystemLoad, &stringTokens, &intTokens); - - return true; + return changed; } bool cDisplayMenuMainView::DrawMemory(void) { if (!ExecuteViewElement(veSystemMemory)) { return false; } - struct sysinfo memInfo; - sysinfo (&memInfo); - - long long totalMem = memInfo.totalram; - totalMem += memInfo.totalswap; - totalMem *= memInfo.mem_unit; - int totalMemMB = totalMem / 1024 / 1024; - - long long usedMem = memInfo.totalram - memInfo.freeram; - usedMem += memInfo.totalswap - memInfo.freeswap; - usedMem *= memInfo.mem_unit; - int usedMemMB = usedMem / 1024 / 1024; - - if (lastMemUsage == usedMemMB) { - return false; + bool changed = false; + if (DetachViewElement(veSystemMemory)) { + cViewElement *viewElement = GetViewElement(veSystemMemory); + if (!viewElement) { + viewElement = new cViewElementSystemMemory(tmplView->GetViewElement(veSystemMemory)); + AddViewElement(veSystemMemory, viewElement); + viewElement->Start(); + changed = true; + } else { + if (!viewElement->Starting()) + changed = viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + changed = SetSystemMemory(stringTokens, intTokens); + if (changed) { + ClearViewElement(veSystemMemory); + DrawViewElement(veSystemMemory, &stringTokens, &intTokens); + } } - lastMemUsage = usedMemMB; - - map < string, string > stringTokens; - map < string, int > intTokens; - intTokens.insert(pair("totalmem", totalMemMB)); - intTokens.insert(pair("usedmem", usedMemMB)); - if (totalMemMB > 0) - intTokens.insert(pair("usedmempercent", usedMemMB * 100 / totalMemMB)); - - ClearViewElement(veSystemMemory); - DrawViewElement(veSystemMemory, &stringTokens, &intTokens); - - return true; + return changed; } void cDisplayMenuMainView::DrawTemperatures(void) { if (!ExecuteViewElement(veTemperatures)) { return; } - cString execCommand = cString::sprintf("cd \"%s/\"; \"%s/temperatures\"", SCRIPTFOLDER, SCRIPTFOLDER); - system(*execCommand); - - string tempCPU, tempGPU; - int cpu, gpu; - - cString itemFilename = cString::sprintf("%s/cpu", SCRIPTOUTPUTPATH ); - ifstream file(*itemFilename, ifstream::in); - if( file.is_open() ) { - std::getline(file, tempCPU); - if (tempCPU.size() > 2) { - cpu = atoi(tempCPU.substr(0,2).c_str()); - } else - cpu = 0; - file.close(); + if (DetachViewElement(veTemperatures)) { + cViewElement *viewElement = GetViewElement(veTemperatures); + if (!viewElement) { + viewElement = new cViewElementTemperature(tmplView->GetViewElement(veTemperatures)); + AddViewElement(veTemperatures, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } } else { - tempCPU = "0°C"; - cpu = 0; + map < string, string > stringTokens; + map < string, int > intTokens; + bool changed = SetSystemTemperatures(stringTokens, intTokens); + if (changed) { + ClearViewElement(veTemperatures); + DrawViewElement(veTemperatures, &stringTokens, &intTokens); + } } - - itemFilename = cString::sprintf("%s/gpu", SCRIPTOUTPUTPATH ); - ifstream file2(*itemFilename, ifstream::in); - if( file2.is_open() ) { - std::getline(file2, tempGPU); - if (tempGPU.size() > 2) { - gpu = atoi(tempGPU.substr(0,2).c_str()); - } else - gpu = 0; - file2.close(); - } else { - tempGPU = "0°C"; - gpu = 0; - } - - map < string, string > stringTokens; - map < string, int > intTokens; - - intTokens.insert(pair("cputemp", cpu)); - intTokens.insert(pair("gputemp", gpu)); - - ClearViewElement(veTemperatures); - DrawViewElement(veTemperatures, &stringTokens, &intTokens); } bool cDisplayMenuMainView::DrawDevices(void) { if (!ExecuteViewElement(veDevices)) { return false; } + bool changed = false; + if (DetachViewElement(veDevices)) { + cViewElement *viewElement = GetViewElement(veDevices); + if (!viewElement) { + viewElement = new cViewElementDevices(tmplView->GetViewElement(veDevices)); + AddViewElement(veDevices, viewElement); + viewElement->Start(); + changed = true; + } else { + if (!viewElement->Starting()) + changed = viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + map < string, vector< map< string, string > > > deviceLoopTokens; + vector< map< string, string > > devices; - map < string, string > stringTokens; - map < string, int > intTokens; - map < string, vector< map< string, string > > > deviceLoopTokens; - vector< map< string, string > > devices; + changed = SetDevices(initial, &intTokens, &devices); + if (!changed) + return false; - bool changed = SetDevices(initial, &intTokens, &devices); - if (!changed) - return false; - - deviceLoopTokens.insert(pair< string, vector< map< string, string > > >("devices", devices)); - - ClearViewElement(veDevices); - DrawViewElement(veDevices, &stringTokens, &intTokens, &deviceLoopTokens); - return true; + deviceLoopTokens.insert(pair< string, vector< map< string, string > > >("devices", devices)); + ClearViewElement(veDevices); + DrawViewElement(veDevices, &stringTokens, &intTokens, &deviceLoopTokens); + } + return changed; } void cDisplayMenuMainView::DrawCurrentSchedule(void) { if (!ExecuteViewElement(veCurrentSchedule)) { return; } - - cDevice *device = cDevice::PrimaryDevice(); - const cChannel *channel = NULL; - if (!device->Replaying() || device->Transferring()) { - channel = Channels.GetByNumber(device->CurrentChannel()); - } - if (!channel) - return; - - const cEvent *event = NULL; - cSchedulesLock SchedulesLock; - if (const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock)) - if (const cSchedule *Schedule = Schedules->GetSchedule(channel)) - event = Schedule->GetPresentEvent(); - if (!event) - return; - - map < string, string > stringTokens; - map < string, int > intTokens; - - stringTokens.insert(pair("title", (event->Title())?event->Title():"")); - stringTokens.insert(pair("subtitle", (event->ShortText())?event->ShortText():"")); - stringTokens.insert(pair("start", *event->GetTimeString())); - stringTokens.insert(pair("stop", *event->GetEndTimeString())); - intTokens.insert(pair("duration", event->Duration() / 60)); - intTokens.insert(pair("durationhours", event->Duration() / 3600)); - stringTokens.insert(pair("durationminutes", *cString::sprintf("%.2d", (event->Duration() / 60)%60))); - intTokens.insert(pair("elapsed", (int)round((time(NULL) - event->StartTime())/60))); - intTokens.insert(pair("remaining", (int)round((event->EndTime() - time(NULL))/60))); - - int mediaWidth = 0; - int mediaHeight = 0; - string mediaPath = ""; - bool isBanner = false; - int posterWidth = 0; - int posterHeight = 0; - string posterPath = ""; - bool hasPoster = false; - int bannerWidth = 0; - int bannerHeight = 0; - string bannerPath = ""; - bool hasBanner = false; - static cPlugin *pScraper = GetScraperPlugin(); - if (pScraper) { - ScraperGetPosterBanner call; - call.event = event; - if (pScraper->Service("GetPosterBanner", &call)) { - if ((call.type == tSeries) && call.banner.path.size() > 0) { - mediaWidth = call.banner.width; - mediaHeight = call.banner.height; - mediaPath = call.banner.path; - isBanner = true; - bannerWidth = mediaWidth; - bannerHeight = mediaHeight; - bannerPath = mediaPath; - hasBanner = true; - ScraperGetPoster callPoster; - callPoster.event = event; - callPoster.recording = NULL; - if (pScraper->Service("GetPoster", &callPoster)) { - posterWidth = callPoster.poster.width; - posterHeight = callPoster.poster.height; - posterPath = callPoster.poster.path; - hasPoster = true; - } - } else if (call.type == tMovie && call.poster.path.size() > 0 && call.poster.height > 0) { - mediaWidth = call.poster.width; - mediaHeight = call.poster.height; - mediaPath = call.poster.path; - posterWidth = call.poster.width; - posterHeight = call.poster.height; - posterPath = call.poster.path; - hasPoster = true; - } + if (DetachViewElement(veCurrentSchedule)) { + cViewElement *viewElement = GetViewElement(veCurrentSchedule); + if (!viewElement) { + viewElement = new cViewElementCurrentSchedule(tmplView->GetViewElement(veCurrentSchedule)); + AddViewElement(veCurrentSchedule, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + SetCurrentSchedule(stringTokens, intTokens); + ClearViewElement(veCurrentSchedule); + DrawViewElement(veCurrentSchedule, &stringTokens, &intTokens); } - intTokens.insert(pair("mediawidth", mediaWidth)); - intTokens.insert(pair("mediaheight", mediaHeight)); - intTokens.insert(pair("isbanner", isBanner)); - stringTokens.insert(pair("mediapath", mediaPath)); - intTokens.insert(pair("posterwidth", posterWidth)); - intTokens.insert(pair("posterheight", posterHeight)); - stringTokens.insert(pair("posterpath", posterPath)); - intTokens.insert(pair("hasposter", hasPoster)); - intTokens.insert(pair("bannerwidth", bannerWidth)); - intTokens.insert(pair("bannerheight", bannerHeight)); - stringTokens.insert(pair("bannerpath", bannerPath)); - intTokens.insert(pair("hasbanner", hasBanner)); - - ClearViewElement(veCurrentSchedule); - DrawViewElement(veCurrentSchedule, &stringTokens, &intTokens); } void cDisplayMenuMainView::DrawCurrentWeather(void) { if (!ExecuteViewElement(veCurrentWeather)) { return; } - map < string, string > stringTokens; - map < string, int > intTokens; - if (!SetCurrentWeatherTokens(stringTokens, intTokens)){ + if (DetachViewElement(veCurrentWeather)) { + cViewElement *viewElement = GetViewElement(veCurrentWeather); + if (!viewElement) { + viewElement = new cViewElementWeather(tmplView->GetViewElement(veCurrentWeather)); + AddViewElement(veCurrentWeather, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + if (!SetCurrentWeatherTokens(stringTokens, intTokens)){ + ClearViewElement(veCurrentWeather); + return; + } ClearViewElement(veCurrentWeather); - return; + DrawViewElement(veCurrentWeather, &stringTokens, &intTokens); } - - ClearViewElement(veCurrentWeather); - DrawViewElement(veCurrentWeather, &stringTokens, &intTokens); } void cDisplayMenuMainView::DrawCustomTokens(void) { @@ -640,9 +442,22 @@ void cDisplayMenuMainView::DrawCustomTokens(void) { } if (!tmplView) return; - map < string, string > stringTokens = tmplView->GetCustomStringTokens(); - map < string, int > intTokens = tmplView->GetCustomIntTokens(); - DrawViewElement(veCustomTokens, &stringTokens, &intTokens); + + if (DetachViewElement(veCustomTokens)) { + cViewElement *viewElement = GetViewElement(veCustomTokens); + if (!viewElement) { + viewElement = new cViewElementCustomTokens(tmplView->GetViewElement(veCustomTokens), tmplView); + AddViewElement(veCustomTokens, viewElement); + viewElement->Start(); + } else { + if (!viewElement->Starting()) + viewElement->Render(); + } + } else { + map < string, string > stringTokens = tmplView->GetCustomStringTokens(); + map < string, int > intTokens = tmplView->GetCustomIntTokens(); + DrawViewElement(veCustomTokens, &stringTokens, &intTokens); + } } /************************************************************************ diff --git a/views/displaymenuview.h b/views/displaymenuview.h index 3bc64b8..dbf8acf 100644 --- a/views/displaymenuview.h +++ b/views/displaymenuview.h @@ -37,8 +37,6 @@ public: class cDisplayMenuMainView : public cDisplayMenuView { private: bool initial; - double lastSystemLoad; - int lastMemUsage; void DrawTimers(void); void DrawDiscUsage(void); bool DrawLoad(void); diff --git a/views/displayviewelements.c b/views/displayviewelements.c new file mode 100644 index 0000000..61760df --- /dev/null +++ b/views/displayviewelements.c @@ -0,0 +1,207 @@ +#include "displayviewelements.h" + +cViewElementDevices::cViewElementDevices(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { + init = true; +} + +bool cViewElementDevices::Render(void) { + ClearTokens(); + map < string, vector< map< string, string > > > deviceLoopTokens; + vector< map< string, string > > devices; + + if (init) + InitDevices(); + bool changed = SetDevices(init, &intTokens, &devices); + init = false; + + if (!changed) + return false; + + deviceLoopTokens.insert(pair< string, vector< map< string, string > > >("devices", devices)); + + ClearViewElement(veDevices); + DrawViewElement(veDevices, &stringTokens, &intTokens, &deviceLoopTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementSignal::cViewElementSignal(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementSignal::Render(void) { + ClearTokens(); + bool changed = SetSignal(intTokens); + if (!changed) + return false; + ClearViewElement(veSignalQuality); + DrawViewElement(veSignalQuality, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementWeather::cViewElementWeather(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementWeather::Render(void) { + ClearTokens(); + if (!SetCurrentWeatherTokens(stringTokens, intTokens)){ + ClearViewElement(veCurrentWeather); + return false; + } + ClearViewElement(veCurrentWeather); + DrawViewElement(veCurrentWeather, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementDate::cViewElementDate(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementDate::Render(void) { + ClearTokens(); + if (!SetDate(stringTokens, intTokens)) { + return false; + } + ClearViewElement(veDateTime); + DrawViewElement(veDateTime, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementTime::cViewElementTime(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementTime::Render(void) { + ClearTokens(); + if (!SetTime(stringTokens, intTokens)) { + return false; + } + ClearViewElement(veTime); + DrawViewElement(veTime, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementScraperContent::cViewElementScraperContent(const cEvent *event, ScraperContentType type, cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { + this->event = event; + this->type = type; +} + +bool cViewElementScraperContent::Render(void) { + ClearTokens(); + SetPosterBanner(event, stringTokens, intTokens); + ClearViewElement(veScraperContent); + DrawViewElement(veScraperContent, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementCustomTokens::cViewElementCustomTokens(cTemplateViewElement *tmplViewElement, cTemplateView *tmplView) : cViewElement(tmplViewElement) { + this->tmplView = tmplView; +} + +bool cViewElementCustomTokens::Render(void) { + ClearTokens(); + if (!tmplView) + return false; + stringTokens = tmplView->GetCustomStringTokens(); + intTokens = tmplView->GetCustomIntTokens(); + + ClearViewElement(veCustomTokens); + DrawViewElement(veCustomTokens, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementTimers::cViewElementTimers(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementTimers::Render(void) { + ClearTokens(); + map < string, vector< map< string, string > > > timerLoopTokens; + vector< map< string, string > > timers; + + SetTimers(&intTokens, &stringTokens, &timers); + + timerLoopTokens.insert(pair< string, vector< map< string, string > > >("timers", timers)); + + ClearViewElement(veTimers); + DrawViewElement(veTimers, &stringTokens, &intTokens, &timerLoopTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementDiscUsage::cViewElementDiscUsage(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementDiscUsage::Render(void) { + ClearTokens(); + SetDiscUsage(stringTokens, intTokens); + + ClearViewElement(veDiscUsage); + DrawViewElement(veDiscUsage, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementSystemLoad::cViewElementSystemLoad(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementSystemLoad::Render(void) { + ClearTokens(); + if (!SetSystemLoad(stringTokens, intTokens)) + return false; + ClearViewElement(veSystemLoad); + DrawViewElement(veSystemLoad, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementSystemMemory::cViewElementSystemMemory(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementSystemMemory::Render(void) { + ClearTokens(); + if (!SetSystemMemory(stringTokens, intTokens)) + return false; + ClearViewElement(veSystemMemory); + DrawViewElement(veSystemMemory, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementTemperature::cViewElementTemperature(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementTemperature::Render(void) { + ClearTokens(); + if (!SetSystemTemperatures(stringTokens, intTokens)) + return false; + ClearViewElement(veTemperatures); + DrawViewElement(veTemperatures, &stringTokens, &intTokens); + return true; +} + +/********************************************************************************************************************/ + +cViewElementCurrentSchedule::cViewElementCurrentSchedule(cTemplateViewElement *tmplViewElement) : cViewElement(tmplViewElement) { +} + +bool cViewElementCurrentSchedule::Render(void) { + ClearTokens(); + SetCurrentSchedule(stringTokens, intTokens); + ClearViewElement(veCurrentSchedule); + DrawViewElement(veCurrentSchedule, &stringTokens, &intTokens); + return true; +} diff --git a/views/displayviewelements.h b/views/displayviewelements.h new file mode 100644 index 0000000..46492f4 --- /dev/null +++ b/views/displayviewelements.h @@ -0,0 +1,121 @@ +#ifndef __DISPLAYCHANNELVIEWELEMENTS_H +#define __DISPLAYCHANNELVIEWELEMENTS_H + +#include "../libtemplate/template.h" +#include "view.h" +#include "viewhelpers.h" + +class cViewElementDevices : public cViewElement, public cViewHelpers { +private: + bool init; +public: + cViewElementDevices(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementDevices() {}; + bool Render(void); +}; + +class cViewElementSignal : public cViewElement, public cViewHelpers { +private: +public: + cViewElementSignal(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementSignal() {}; + bool Render(void); +}; + +class cViewElementWeather : public cViewElement, public cViewHelpers { +private: +public: + cViewElementWeather(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementWeather() {}; + bool Render(void); +}; + +class cViewElementDate : public cViewElement, public cViewHelpers { +private: +public: + cViewElementDate(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementDate() {}; + bool Render(void); +}; + +class cViewElementTime : public cViewElement, public cViewHelpers { +private: +public: + cViewElementTime(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementTime() {}; + bool Render(void); +}; + +enum ScraperContentType { + ctPosterBanner, + ctFull +}; + +class cViewElementScraperContent : public cViewElement, public cViewHelpers { +private: + ScraperContentType type; + const cEvent *event; +public: + cViewElementScraperContent(const cEvent *event, ScraperContentType type, cTemplateViewElement *tmplViewElement); + virtual ~cViewElementScraperContent() {}; + bool Render(void); +}; + +class cViewElementCustomTokens : public cViewElement, public cViewHelpers { +private: + cTemplateView *tmplView; +public: + cViewElementCustomTokens(cTemplateViewElement *tmplViewElement, cTemplateView *tmplView); + virtual ~cViewElementCustomTokens() {}; + bool Render(void); +}; + +class cViewElementTimers : public cViewElement, public cViewHelpers { +private: +public: + cViewElementTimers(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementTimers() {}; + bool Render(void); +}; + +class cViewElementDiscUsage : public cViewElement, public cViewHelpers { +private: +public: + cViewElementDiscUsage(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementDiscUsage() {}; + bool Render(void); +}; + +class cViewElementSystemLoad : public cViewElement, public cViewHelpers { +private: +public: + cViewElementSystemLoad(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementSystemLoad() {}; + bool Render(void); +}; + +class cViewElementSystemMemory : public cViewElement, public cViewHelpers { +private: +public: + cViewElementSystemMemory(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementSystemMemory() {}; + bool Render(void); +}; + +class cViewElementTemperature : public cViewElement, public cViewHelpers { +private: +public: + cViewElementTemperature(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementTemperature() {}; + bool Render(void); +}; + +class cViewElementCurrentSchedule : public cViewElement, public cViewHelpers { +private: +public: + cViewElementCurrentSchedule(cTemplateViewElement *tmplViewElement); + virtual ~cViewElementCurrentSchedule() {}; + bool Render(void); +}; + +#endif //__DISPLAYCHANNELVIEWELEMENTS_H \ No newline at end of file diff --git a/views/view.c b/views/view.c index 3bebde7..a76c48a 100644 --- a/views/view.c +++ b/views/view.c @@ -37,7 +37,8 @@ cView::~cView() { cDevice::PrimaryDevice()->ScaleVideo(cRect::Null); } for (map::iterator dVeIt = detachedViewElements.begin(); dVeIt != detachedViewElements.end(); dVeIt++) { - delete dVeIt->second; + cViewElement *ve = dVeIt->second; + delete ve; } } @@ -94,6 +95,11 @@ void cView::DrawViewElement(eViewElement ve, map *stringTokens, viewElement->InitIterator(); cTemplatePixmap *pix = NULL; while(pix = viewElement->GetNextPixmap()) { + //check if already drawn background area, this can be skipped + if (PixmapExists(pixCurrent) && pix->BackgroundArea()) { + pixCurrent++; + continue; + } //reset Template pix->ClearDynamicParameters(); //create Pixmap if already fully parsed @@ -151,9 +157,12 @@ void cView::DrawViewElement(eViewElement ve, map *stringTokens, } void cView::ClearViewElement(eViewElement ve) { - if (!tmplView) - return; - cTemplateViewElement *viewElement = tmplView->GetViewElement(ve); + cTemplateViewElement *viewElement = NULL; + if (tmplViewElement) { + viewElement = tmplViewElement; + } else if (tmplView) { + viewElement = tmplView->GetViewElement(ve); + } if (!viewElement) return; int pixCurrent = viewElement->GetPixOffset(); @@ -162,7 +171,9 @@ void cView::ClearViewElement(eViewElement ve) { cTemplatePixmap *pix = NULL; viewElement->InitIterator(); while(pix = viewElement->GetNextPixmap()) { - Fill(pixCurrent, clrTransparent); + if (!pix->BackgroundArea()) { + Fill(pixCurrent, clrTransparent); + } pixCurrent++; } } @@ -834,6 +845,7 @@ void cView::DoDrawImage(int num, cTemplateFunction *func, int x0, int y0) { ************************************************************************/ cViewElement::cViewElement(cTemplateViewElement *tmplViewElement) : cView(tmplViewElement) { + tmplViewElement->SetPixOffset(0); delay = tmplViewElement->GetNumericParameter(ptDelay); SetFadeTime(tmplViewElement->GetNumericParameter(ptFadeTime)); } @@ -858,82 +870,11 @@ void cViewElement::Action(void) { } } -void cViewElement::Draw(map < string, vector< map< string, string > > > *loopTokens) { - if (!tmplViewElement) - return; - - if (tmplViewElement->DebugTokens()) { - DebugTokens("viewelement", &stringTokens, &intTokens, loopTokens); - } - //iterate through pixmaps of viewelement - int pixCurrent = 0; - tmplViewElement->InitIterator(); - cTemplatePixmap *pix = NULL; - while(pix = tmplViewElement->GetNextPixmap()) { - //reset Template - pix->ClearDynamicParameters(); - //create Pixmap if already fully parsed - if (!PixmapExists(pixCurrent) && pix->Ready() && pix->DoExecute() && !pix->Scrolling()) { - CreateViewPixmap(pixCurrent, pix); - } - //check if pixmap needs dynamic parameters - if ((!pix->Ready() || !pix->DoExecute()) && !pix->Scrolling()) { - //parse dynamic parameters and initiate functions - pix->ParseDynamicParameters(&intTokens, true); - if (pix->Ready() && pix->DoExecute()) { - CreateViewPixmap(pixCurrent, pix); - } - } else { - //parse dynamic parameters but not initiate functions - pix->ParseDynamicParameters(&intTokens, false); - } - //if pixmap still not valid, skip - if (!pix->Ready() && !pix->Scrolling()) { - pixCurrent++; - continue; - } - //if condition for pixmap set, check if cond is true - if (!pix->DoExecute()) { - pixCurrent++; - continue; - } - //parse dynamic tokens of pixmap functions - pix->ClearDynamicFunctionParameters(); - pix->ParseDynamicFunctionParameters(&stringTokens, &intTokens); - - if (!PixmapExists(pixCurrent) && pix->Scrolling()) { - cSize drawportSize; - scrolling = pix->CalculateDrawPortSize(drawportSize, loopTokens); - if (scrolling) { - /* - CreateScrollingPixmap(pixCurrent, pix, drawportSize); - pix->SetScrollingTextWidth(); - veScroll = ve; - scrollingPix = pixCurrent; - scrollOrientation = pix->GetNumericParameter(ptOrientation); - scrollMode = pix->GetNumericParameter(ptScrollMode); - scrollDelay = pix->GetNumericParameter(ptDelay); - scrollSpeed = pix->GetNumericParameter(ptScrollSpeed); - */ - } else { - CreateViewPixmap(pixCurrent, pix); - } - } - if (pix->DoDebug()) { - pix->Debug(); - } - - DrawPixmap(pixCurrent, pix, loopTokens); - pixCurrent++; - } +void cViewElement::ClearTokens(void) { + stringTokens.clear(); + intTokens.clear(); } -void cViewElement::Clear(void) { - int pixMax = NumPixmaps(); - for (int pixCurrent = 0; pixCurrent < pixMax; pixCurrent++) { - Fill(pixCurrent, clrTransparent); - } -} /*********************************************************************** * cViewListItem diff --git a/views/view.h b/views/view.h index ab11717..f81885f 100644 --- a/views/view.h +++ b/views/view.h @@ -72,12 +72,12 @@ protected: map < string, string > stringTokens; map < string, int > intTokens; void Action(void); - void Draw(map < string, vector< map< string, string > > > *loopTokens = NULL); + void ClearTokens(void); public: cViewElement(cTemplateViewElement *tmplViewElement); virtual ~cViewElement(); - virtual void Render(void) {}; - void Clear(void); + virtual bool Render(void) { return false; }; + bool Starting(void) { return Running(); }; }; class cViewListItem : public cView { diff --git a/views/viewhelpers.c b/views/viewhelpers.c index 3ec8847..5c6d4ed 100644 --- a/views/viewhelpers.c +++ b/views/viewhelpers.c @@ -1,15 +1,25 @@ +#include +#include #include +#include +#include #include "../services/scraper2vdr.h" #include "../services/weatherforecast.h" #include "../config.h" +#include "../libcore/timers.h" #include "../libcore/helpers.h" #include "viewhelpers.h" cViewHelpers::cViewHelpers(void) { numDevices = 0; devicesInit = false; + lSignalDisplay = 0; + lSignalStrength = 0; + lSignalQuality = 0; lastSecond = -1; lastMinute = -1; + lastSystemLoad = 0.0; + lastMemUsage = -1; } cViewHelpers::~cViewHelpers() { @@ -141,6 +151,28 @@ bool cViewHelpers::SetDevices(bool initial, map *intTokens, vector &intTokens) { + bool done = false; + time_t Now = time(NULL); + if (Now != lSignalDisplay) { + int SignalStrength = cDevice::ActualDevice()->SignalStrength(); + int SignalQuality = cDevice::ActualDevice()->SignalQuality(); + if (SignalStrength < 0) SignalStrength = 0; + if (SignalQuality < 0) SignalQuality = 0; + if ((SignalStrength == 0)&&(SignalQuality==0)) + return done; + if ((lSignalStrength != SignalStrength) || (lSignalQuality != SignalQuality)) { + intTokens.insert(pair("signalstrength", SignalStrength)); + intTokens.insert(pair("signalquality", SignalQuality)); + lSignalStrength = SignalStrength; + lSignalQuality = SignalQuality; + done = true; + } + lSignalDisplay = Now; + } + return done; +} + bool cViewHelpers::CheckNewMails(void) { static cPlugin *pMailbox = cPluginManager::GetPlugin("mailbox"); if (!pMailbox) { @@ -359,13 +391,80 @@ void cViewHelpers::SetScraperTokens(const cEvent *event, const cRecording *recor } +void cViewHelpers::SetPosterBanner(const cEvent *event, map < string, string > &stringTokens, map < string, int > &intTokens) { + static cPlugin *pScraper = GetScraperPlugin(); + if (!pScraper) { + return; + } + + ScraperGetPosterBanner call; + call.event = event; + if (pScraper->Service("GetPosterBanner", &call)) { + int mediaWidth = 0; + int mediaHeight = 0; + string mediaPath = ""; + bool isBanner = false; + int posterWidth = 0; + int posterHeight = 0; + string posterPath = ""; + bool hasPoster = false; + int bannerWidth = 0; + int bannerHeight = 0; + string bannerPath = ""; + bool hasBanner = false; + + if ((call.type == tSeries) && call.banner.path.size() > 0) { + mediaWidth = call.banner.width; + mediaHeight = call.banner.height; + mediaPath = call.banner.path; + isBanner = true; + bannerWidth = mediaWidth; + bannerHeight = mediaHeight; + bannerPath = mediaPath; + hasBanner = true; + + ScraperGetPoster callPoster; + callPoster.event = event; + callPoster.recording = NULL; + if (pScraper->Service("GetPoster", &callPoster)) { + posterWidth = callPoster.poster.width; + posterHeight = callPoster.poster.height; + posterPath = callPoster.poster.path; + hasPoster = true; + } + } else if (call.type == tMovie && call.poster.path.size() > 0 && call.poster.height > 0) { + mediaWidth = call.poster.width; + mediaHeight = call.poster.height; + mediaPath = call.poster.path; + posterWidth = call.poster.width; + posterHeight = call.poster.height; + posterPath = call.poster.path; + hasPoster = true; + } else + return; + + intTokens.insert(pair("mediawidth", mediaWidth)); + intTokens.insert(pair("mediaheight", mediaHeight)); + intTokens.insert(pair("isbanner", isBanner)); + stringTokens.insert(pair("mediapath", mediaPath)); + intTokens.insert(pair("posterwidth", posterWidth)); + intTokens.insert(pair("posterheight", posterHeight)); + stringTokens.insert(pair("posterpath", posterPath)); + intTokens.insert(pair("hasposter", hasPoster)); + intTokens.insert(pair("bannerwidth", bannerWidth)); + intTokens.insert(pair("bannerheight", bannerHeight)); + stringTokens.insert(pair("bannerpath", bannerPath)); + intTokens.insert(pair("hasbanner", hasBanner)); + } +} + bool cViewHelpers::SetTime(map < string, string > &stringTokens, map < string, int > &intTokens) { time_t t = time(0); // get time now struct tm * now = localtime(&t); int sec = now->tm_sec; - if (sec == lastSecond) + if (sec == lastSecond) { return false; - + } int min = now->tm_min; int hour = now->tm_hour; int hourMinutes = hour%12 * 5 + min / 12; @@ -433,3 +532,316 @@ bool cViewHelpers::SetCurrentWeatherTokens(map < string, string > &stringTokens, stringTokens.insert(pair("ozone", currentWeather.ozone)); return true; } + +void cViewHelpers::SetTimers(map *intTokens, map *stringTokens, vector > *timers) { + cGlobalSortedTimers SortedTimers;// local and remote timers + int numTimers = SortedTimers.Size(); + + intTokens->insert(pair("numtimers", numTimers)); + + int numTimerConflicts = SortedTimers.NumTimerConfilicts(); + intTokens->insert(pair("numtimerconflicts", numTimerConflicts)); + + for (int i=0; i<15; i++) { + stringstream name; + name << "timer" << i+1 << "exists"; + if (i < numTimers) { + intTokens->insert(pair(name.str(), true)); + } else { + intTokens->insert(pair(name.str(), false)); + } + } + + for (int i = 0; i < numTimers; i++) { + if (i >=15) + break; + map< string, string > timerVals; + const cTimer *Timer = SortedTimers[i]; + const cEvent *event = Timer->Event(); + if (event) { + timerVals.insert(pair< string, string >("timers[title]", event->Title())); + } else { + const char *File = Setup.FoldersInTimerMenu ? NULL : strrchr(Timer->File(), FOLDERDELIMCHAR); + if (File && strcmp(File + 1, TIMERMACRO_TITLE) && strcmp(File + 1, TIMERMACRO_EPISODE)) + File++; + else + File = Timer->File(); + timerVals.insert(pair< string, string >("timers[title]", File)); + } + const cChannel *channel = Timer->Channel(); + if (channel) { + timerVals.insert(pair< string, string >("timers[channelname]", channel->Name())); + stringstream chanNum; + chanNum << channel->Number(); + timerVals.insert(pair< string, string >("timers[channelnumber]", chanNum.str())); + string channelID = *(channel->GetChannelID().ToString()); + timerVals.insert(pair< string, string >("timers[channelid]", channelID)); + bool logoExists = imgCache->LogoExists(channelID); + timerVals.insert(pair< string, string >("timers[channellogoexists]", logoExists ? "1" : "0")); + } else { + timerVals.insert(pair< string, string >("timers[channelname]", "")); + timerVals.insert(pair< string, string >("timers[channelnumber]", "0")); + timerVals.insert(pair< string, string >("timers[channelid]", "")); + timerVals.insert(pair< string, string >("timers[channellogoexists]", "0")); + } + + timerVals.insert(pair< string, string >("timers[recording]", Timer->Recording() ? "1" : "0")); + + cString timerDate(""); + if (Timer->Recording()) { + timerDate = cString::sprintf("-%s", *TimeString(Timer->StopTime())); + } else { + time_t Now = time(NULL); + cString Today = WeekDayName(Now); + cString Time = TimeString(Timer->StartTime()); + cString Day = WeekDayName(Timer->StartTime()); + if (Timer->StartTime() > Now + 6 * SECSINDAY) { + time_t ttm = Timer->StartTime(); + struct tm * timerTime = localtime(&ttm); + timerDate = cString::sprintf("%02d.%02d %s", timerTime->tm_mday, timerTime->tm_mon + 1, *Time); + } else if (strcmp(Day, Today) != 0) + timerDate = cString::sprintf("%s %s", *Day, *Time); + else + timerDate = Time; + if (Timer->Flags() & tfVps) + timerDate = cString::sprintf("VPS %s", *timerDate); + } + timerVals.insert(pair< string, string >("timers[datetime]", *timerDate)); + + timers->push_back(timerVals); + } +} + +void cViewHelpers::SetMenuHeader(eMenuCategory cat, string menuTitle, map < string, string > &stringTokens, map < string, int > &intTokens) { + stringTokens.insert(pair("title", menuTitle)); + stringTokens.insert(pair("vdrversion", VDRVERSION)); + + //check for standard menu entries + bool hasIcon = false; + + string icon = imgCache->GetIconName(menuTitle, cat); + if (imgCache->MenuIconExists(icon)) + hasIcon = true; + + stringTokens.insert(pair("icon", icon)); + intTokens.insert(pair("hasicon", hasIcon)); + + //Disc Usage + string vdrUsageString = *cVideoDiskUsage::String(); + int discUsage = cVideoDiskUsage::UsedPercent(); + bool discAlert = (discUsage > 95) ? true : false; + string freeTime = *cString::sprintf("%02d:%02d", cVideoDiskUsage::FreeMinutes() / 60, cVideoDiskUsage::FreeMinutes() % 60); + int freeGB = cVideoDiskUsage::FreeMB() / 1024; + + intTokens.insert(pair("usedpercent", discUsage)); + intTokens.insert(pair("freepercent", 100-discUsage)); + intTokens.insert(pair("discalert", discAlert)); + intTokens.insert(pair("freegb", freeGB)); + stringTokens.insert(pair("freetime", freeTime)); + stringTokens.insert(pair("vdrusagestring", vdrUsageString)); +} + +void cViewHelpers::SetDiscUsage(map < string, string > &stringTokens, map < string, int > &intTokens) { + string vdrUsageString = *cVideoDiskUsage::String(); + int discUsage = cVideoDiskUsage::UsedPercent(); + bool discAlert = (discUsage > 95) ? true : false; + string freeTime = *cString::sprintf("%02d:%02d", cVideoDiskUsage::FreeMinutes() / 60, cVideoDiskUsage::FreeMinutes() % 60); + int freeGB = cVideoDiskUsage::FreeMB() / 1024; + + intTokens.insert(pair("usedpercent", discUsage)); + intTokens.insert(pair("freepercent", 100-discUsage)); + intTokens.insert(pair("discalert", discAlert)); + intTokens.insert(pair("freegb", freeGB)); + stringTokens.insert(pair("freetime", freeTime)); + stringTokens.insert(pair("vdrusagestring", vdrUsageString)); +} + +bool cViewHelpers::SetSystemLoad(map < string, string > &stringTokens, map < string, int > &intTokens) { + double systemLoad; + if (getloadavg(&systemLoad, 1) > 0) { + if (lastSystemLoad == systemLoad) { + return false; + } + string load = *cString::sprintf("%.2f", systemLoad); + int loadHand = systemLoad * 1000; + int loadHandValue = 0; + if (loadHand > 2500) + loadHandValue = 2525; + else { + + int loadHandDec = loadHand - (loadHand / 100) * 100; + + if (loadHandDec <= 12) + loadHandDec = 0; + else if (loadHandDec <= 37) + loadHandDec = 25; + else if (loadHandDec <= 62) + loadHandDec = 50; + else if (loadHandDec <= 87) + loadHandDec = 75; + else + loadHandDec = 0; + + loadHandValue = loadHand / 100 * 100 + loadHandDec; + } + stringTokens.insert(pair("load", load)); + intTokens.insert(pair("loadhand", loadHandValue)); + lastSystemLoad = systemLoad; + } else { + return false; + } + return true; +} + +bool cViewHelpers::SetSystemMemory(map < string, string > &stringTokens, map < string, int > &intTokens) { + struct sysinfo memInfo; + sysinfo (&memInfo); + + long long totalMem = memInfo.totalram; + totalMem += memInfo.totalswap; + totalMem *= memInfo.mem_unit; + int totalMemMB = totalMem / 1024 / 1024; + + long long usedMem = memInfo.totalram - memInfo.freeram; + usedMem += memInfo.totalswap - memInfo.freeswap; + usedMem *= memInfo.mem_unit; + int usedMemMB = usedMem / 1024 / 1024; + + if (lastMemUsage == usedMemMB) { + return false; + } + lastMemUsage = usedMemMB; + + intTokens.insert(pair("totalmem", totalMemMB)); + intTokens.insert(pair("usedmem", usedMemMB)); + if (totalMemMB > 0) + intTokens.insert(pair("usedmempercent", usedMemMB * 100 / totalMemMB)); + return true; +} + +bool cViewHelpers::SetSystemTemperatures(map < string, string > &stringTokens, map < string, int > &intTokens) { + cString execCommand = cString::sprintf("cd \"%s/\"; \"%s/temperatures\"", SCRIPTFOLDER, SCRIPTFOLDER); + system(*execCommand); + + string tempCPU, tempGPU; + int cpu, gpu; + + cString itemFilename = cString::sprintf("%s/cpu", SCRIPTOUTPUTPATH ); + ifstream file(*itemFilename, ifstream::in); + if( file.is_open() ) { + std::getline(file, tempCPU); + if (tempCPU.size() > 2) { + cpu = atoi(tempCPU.substr(0,2).c_str()); + } else + cpu = 0; + file.close(); + } else { + tempCPU = "0°C"; + cpu = 0; + } + + itemFilename = cString::sprintf("%s/gpu", SCRIPTOUTPUTPATH ); + ifstream file2(*itemFilename, ifstream::in); + if( file2.is_open() ) { + std::getline(file2, tempGPU); + if (tempGPU.size() > 2) { + gpu = atoi(tempGPU.substr(0,2).c_str()); + } else + gpu = 0; + file2.close(); + } else { + tempGPU = "0°C"; + gpu = 0; + } + + intTokens.insert(pair("cputemp", cpu)); + intTokens.insert(pair("gputemp", gpu)); + return true; +} + +void cViewHelpers::SetCurrentSchedule(map < string, string > &stringTokens, map < string, int > &intTokens) { + cDevice *device = cDevice::PrimaryDevice(); + const cChannel *channel = NULL; + if (!device->Replaying() || device->Transferring()) { + channel = Channels.GetByNumber(device->CurrentChannel()); + } + if (!channel) + return; + + const cEvent *event = NULL; + cSchedulesLock SchedulesLock; + if (const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock)) + if (const cSchedule *Schedule = Schedules->GetSchedule(channel)) + event = Schedule->GetPresentEvent(); + if (!event) + return; + + stringTokens.insert(pair("title", (event->Title())?event->Title():"")); + stringTokens.insert(pair("subtitle", (event->ShortText())?event->ShortText():"")); + stringTokens.insert(pair("start", *event->GetTimeString())); + stringTokens.insert(pair("stop", *event->GetEndTimeString())); + intTokens.insert(pair("duration", event->Duration() / 60)); + intTokens.insert(pair("durationhours", event->Duration() / 3600)); + stringTokens.insert(pair("durationminutes", *cString::sprintf("%.2d", (event->Duration() / 60)%60))); + intTokens.insert(pair("elapsed", (int)round((time(NULL) - event->StartTime())/60))); + intTokens.insert(pair("remaining", (int)round((event->EndTime() - time(NULL))/60))); + + int mediaWidth = 0; + int mediaHeight = 0; + string mediaPath = ""; + bool isBanner = false; + int posterWidth = 0; + int posterHeight = 0; + string posterPath = ""; + bool hasPoster = false; + int bannerWidth = 0; + int bannerHeight = 0; + string bannerPath = ""; + bool hasBanner = false; + static cPlugin *pScraper = GetScraperPlugin(); + if (pScraper) { + ScraperGetPosterBanner call; + call.event = event; + if (pScraper->Service("GetPosterBanner", &call)) { + if ((call.type == tSeries) && call.banner.path.size() > 0) { + mediaWidth = call.banner.width; + mediaHeight = call.banner.height; + mediaPath = call.banner.path; + isBanner = true; + bannerWidth = mediaWidth; + bannerHeight = mediaHeight; + bannerPath = mediaPath; + hasBanner = true; + ScraperGetPoster callPoster; + callPoster.event = event; + callPoster.recording = NULL; + if (pScraper->Service("GetPoster", &callPoster)) { + posterWidth = callPoster.poster.width; + posterHeight = callPoster.poster.height; + posterPath = callPoster.poster.path; + hasPoster = true; + } + } else if (call.type == tMovie && call.poster.path.size() > 0 && call.poster.height > 0) { + mediaWidth = call.poster.width; + mediaHeight = call.poster.height; + mediaPath = call.poster.path; + posterWidth = call.poster.width; + posterHeight = call.poster.height; + posterPath = call.poster.path; + hasPoster = true; + } + } + } + intTokens.insert(pair("mediawidth", mediaWidth)); + intTokens.insert(pair("mediaheight", mediaHeight)); + intTokens.insert(pair("isbanner", isBanner)); + stringTokens.insert(pair("mediapath", mediaPath)); + intTokens.insert(pair("posterwidth", posterWidth)); + intTokens.insert(pair("posterheight", posterHeight)); + stringTokens.insert(pair("posterpath", posterPath)); + intTokens.insert(pair("hasposter", hasPoster)); + intTokens.insert(pair("bannerwidth", bannerWidth)); + intTokens.insert(pair("bannerheight", bannerHeight)); + stringTokens.insert(pair("bannerpath", bannerPath)); + intTokens.insert(pair("hasbanner", hasBanner)); +} \ No newline at end of file diff --git a/views/viewhelpers.h b/views/viewhelpers.h index 53209b4..4d54677 100644 --- a/views/viewhelpers.h +++ b/views/viewhelpers.h @@ -8,16 +8,30 @@ private: int* lastSignalStrength; int* lastSignalQuality; bool* recDevices; + int lSignalDisplay; + int lSignalStrength; + int lSignalQuality; int lastSecond; int lastMinute; + double lastSystemLoad; + int lastMemUsage; protected: void InitDevices(void); bool SetDevices(bool initial, map *intTokens, vector > *devices); + bool SetSignal(map < string, int > &intTokens); bool CheckNewMails(void); void SetScraperTokens(const cEvent *event, const cRecording *recording, map < string, string > &stringTokens, map < string, int > &intTokens, map < string, vector< map< string, string > > > &loopTokens); + void SetPosterBanner(const cEvent *event, map < string, string > &stringTokens, map < string, int > &intTokens); bool SetTime(map < string, string > &stringTokens, map < string, int > &intTokens); bool SetDate(map < string, string > &stringTokens, map < string, int > &intTokens); bool SetCurrentWeatherTokens(map < string, string > &stringTokens, map < string, int > &intTokens); + void SetTimers(map *intTokens, map *stringTokens, vector > *timers); + void SetMenuHeader(eMenuCategory cat, string menuTitle, map < string, string > &stringTokens, map < string, int > &intTokens); + void SetDiscUsage(map < string, string > &stringTokens, map < string, int > &intTokens); + bool SetSystemLoad(map < string, string > &stringTokens, map < string, int > &intTokens); + bool SetSystemMemory(map < string, string > &stringTokens, map < string, int > &intTokens); + bool SetSystemTemperatures(map < string, string > &stringTokens, map < string, int > &intTokens); + void SetCurrentSchedule(map < string, string > &stringTokens, map < string, int > &intTokens); public: cViewHelpers(void); virtual ~cViewHelpers(void);