diff options
Diffstat (limited to 'views/displaymenuview.c')
| -rw-r--r-- | views/displaymenuview.c | 521 |
1 files changed, 168 insertions, 353 deletions
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 <fstream> -#include <iostream> -#include <sys/sysinfo.h> #include <vdr/menu.h> #include <vdr/videodir.h> #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<string,string>("title", menuTitle)); - stringTokens.insert(pair<string,string>("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<string,string>("icon", icon)); - intTokens.insert(pair<string,int>("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<string, int>("usedpercent", discUsage)); - intTokens.insert(pair<string, int>("freepercent", 100-discUsage)); - intTokens.insert(pair<string, int>("discalert", discAlert)); - intTokens.insert(pair<string, int>("freegb", freeGB)); - stringTokens.insert(pair<string,string>("freetime", freeTime)); - stringTokens.insert(pair<string,string>("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<string, int>("numtimers", numTimers)); - - int numTimerConflicts = SortedTimers.NumTimerConfilicts(); - intTokens.insert(pair<string, int>("numtimerconflicts", numTimerConflicts)); - - for (int i=0; i<15; i++) { - stringstream name; - name << "timer" << i+1 << "exists"; - if (i < numTimers) { - intTokens.insert(pair<string, int>(name.str(), true)); - } else { - intTokens.insert(pair<string, int>(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())); + if (DetachViewElement(veTimers)) { + cViewElement *viewElement = GetViewElement(veTimers); + if (!viewElement) { + viewElement = new cViewElementTimers(tmplView->GetViewElement(veTimers)); + AddViewElement(veTimers, viewElement); + viewElement->Start(); } 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); + if (!viewElement->Starting()) + viewElement->Render(); } - timerVals.insert(pair< string, string >("timers[datetime]", *timerDate)); + } else { + map < string, string > stringTokens; + map < string, int > intTokens; + map < string, vector< map< string, string > > > timerLoopTokens; + vector< map< string, string > > timers; - timers.push_back(timerVals); - } + SetTimers(&intTokens, &stringTokens, &timers); - timerLoopTokens.insert(pair< string, vector< map< string, string > > >("timers", timers)); + 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<string, int>("usedpercent", discUsage)); - intTokens.insert(pair<string, int>("freepercent", 100-discUsage)); - intTokens.insert(pair<string, int>("discalert", discAlert)); - intTokens.insert(pair<string, int>("freegb", freeGB)); - stringTokens.insert(pair<string,string>("freetime", freeTime)); - stringTokens.insert(pair<string,string>("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<string,string>("load", load)); - intTokens.insert(pair<string,int>("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<string,int>("totalmem", totalMemMB)); - intTokens.insert(pair<string,int>("usedmem", usedMemMB)); - if (totalMemMB > 0) - intTokens.insert(pair<string,int>("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(); - } 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(); + 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 { - tempGPU = "0°C"; - gpu = 0; + map < string, string > stringTokens; + map < string, int > intTokens; + bool changed = SetSystemTemperatures(stringTokens, intTokens); + if (changed) { + ClearViewElement(veTemperatures); + DrawViewElement(veTemperatures, &stringTokens, &intTokens); + } } - - map < string, string > stringTokens; - map < string, int > intTokens; - - intTokens.insert(pair<string,int>("cputemp", cpu)); - intTokens.insert(pair<string,int>("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; - - bool changed = SetDevices(initial, &intTokens, &devices); - if (!changed) - return false; + 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<string,string>("title", (event->Title())?event->Title():"")); - stringTokens.insert(pair<string,string>("subtitle", (event->ShortText())?event->ShortText():"")); - stringTokens.insert(pair<string,string>("start", *event->GetTimeString())); - stringTokens.insert(pair<string,string>("stop", *event->GetEndTimeString())); - intTokens.insert(pair<string,int>("duration", event->Duration() / 60)); - intTokens.insert(pair<string,int>("durationhours", event->Duration() / 3600)); - stringTokens.insert(pair<string,string>("durationminutes", *cString::sprintf("%.2d", (event->Duration() / 60)%60))); - intTokens.insert(pair<string,int>("elapsed", (int)round((time(NULL) - event->StartTime())/60))); - intTokens.insert(pair<string,int>("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<string,int>("mediawidth", mediaWidth)); - intTokens.insert(pair<string,int>("mediaheight", mediaHeight)); - intTokens.insert(pair<string,int>("isbanner", isBanner)); - stringTokens.insert(pair<string,string>("mediapath", mediaPath)); - intTokens.insert(pair<string,int>("posterwidth", posterWidth)); - intTokens.insert(pair<string,int>("posterheight", posterHeight)); - stringTokens.insert(pair<string,string>("posterpath", posterPath)); - intTokens.insert(pair<string,int>("hasposter", hasPoster)); - intTokens.insert(pair<string,int>("bannerwidth", bannerWidth)); - intTokens.insert(pair<string,int>("bannerheight", bannerHeight)); - stringTokens.insert(pair<string,string>("bannerpath", bannerPath)); - intTokens.insert(pair<string,int>("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); + } } /************************************************************************ |
