From b0509b5182b6e0d04f05e6b3d5676b0d21f51966 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 27 Sep 2014 09:25:14 +0200 Subject: initial commit version 0.0.1 --- views/displaymenuitemcurrentview.c | 561 +++++++++++++++++++++++++++++++++++++ 1 file changed, 561 insertions(+) create mode 100644 views/displaymenuitemcurrentview.c (limited to 'views/displaymenuitemcurrentview.c') diff --git a/views/displaymenuitemcurrentview.c b/views/displaymenuitemcurrentview.c new file mode 100644 index 0000000..a615794 --- /dev/null +++ b/views/displaymenuitemcurrentview.c @@ -0,0 +1,561 @@ +#include "../services/scraper2vdr.h" +#include "../libcore/helpers.h" +#include "displaymenuitemcurrentview.h" + + +cDisplayMenuItemCurrentView::cDisplayMenuItemCurrentView(cTemplateViewElement *tmplCurrent) : cView(tmplCurrent) { + delay = tmplItem->GetNumericParameter(ptDelay); + SetFadeTime(tmplItem->GetNumericParameter(ptFadeTime)); +} + +cDisplayMenuItemCurrentView::~cDisplayMenuItemCurrentView() { + CancelSave(); +} + +void cDisplayMenuItemCurrentView::SetPosMenuItem(cRect &pos) { + posMenuItem.SetX(pos.X()); + posMenuItem.SetY(pos.Y()); + posMenuItem.SetWidth(pos.Width()); + posMenuItem.SetHeight(pos.Height()); +} + +void cDisplayMenuItemCurrentView::SetTokensPosMenuItem(void) { + intTokens.insert(pair("menuitemx", posMenuItem.X())); + intTokens.insert(pair("menuitemy", posMenuItem.Y())); + intTokens.insert(pair("menuitemwidth", posMenuItem.Width())); + intTokens.insert(pair("menuitemheight", posMenuItem.Height())); +} + +void cDisplayMenuItemCurrentView::SetScraperPoster(const cEvent *event, const cRecording *recording) { + static cPlugin *pScraper = GetScraperPlugin(); + if (!pScraper || (!event && !recording)) { + intTokens.insert(pair("hasposter", false)); + intTokens.insert(pair("posterwidth", -1)); + intTokens.insert(pair("posterheight", -1)); + stringTokens.insert(pair("posterpath", "")); + return; + } + + ScraperGetPoster call; + call.event = event; + call.recording = recording; + if (pScraper->Service("GetPoster", &call)) { + intTokens.insert(pair("hasposter", true)); + intTokens.insert(pair("posterwidth", call.poster.width)); + intTokens.insert(pair("posterheight", call.poster.height)); + stringTokens.insert(pair("posterpath", call.poster.path)); + } else { + intTokens.insert(pair("hasposter", false)); + intTokens.insert(pair("posterwidth", -1)); + intTokens.insert(pair("posterheight", -1)); + stringTokens.insert(pair("posterpath", "")); + } +} + +/************************************************************* +* cDisplayMenuItemCurrentMainView +*************************************************************/ + +cDisplayMenuItemCurrentMainView::cDisplayMenuItemCurrentMainView(cTemplateViewElement *tmplCurrent, string number, string label, string icon) + : cDisplayMenuItemCurrentView(tmplCurrent) { + this->number = number; + this->label = label; + this->icon = icon; +} + +cDisplayMenuItemCurrentMainView::~cDisplayMenuItemCurrentMainView() { +} + +void cDisplayMenuItemCurrentMainView::Prepare(void) { +} + + +void cDisplayMenuItemCurrentMainView::Render(void) { + stringTokens.insert(pair("number", number)); + stringTokens.insert(pair("label", label)); + stringTokens.insert(pair("icon", icon)); + SetTokensPosMenuItem(); + DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens); +} + +void cDisplayMenuItemCurrentMainView::Clear(void) { + +} + +void cDisplayMenuItemCurrentMainView::Action(void) { + SetInitFinished(); + DoSleep(delay); + Render(); + FadeIn(); + DoFlush(); + if (scrolling) { + DoSleep(scrollDelay); + if (scrollOrientation == orHorizontal) { + ScrollHorizontal(scrollingPix, scrollDelay, scrollSpeed, scrollMode); + } else { + ScrollVertical(scrollingPix, scrollDelay, scrollSpeed); + } + } +} + +/************************************************************* +* cDisplayMenuItemCurrentSchedulesView +*************************************************************/ + +cDisplayMenuItemCurrentSchedulesView::cDisplayMenuItemCurrentSchedulesView(cTemplateViewElement *tmplCurrent, const cEvent *event, const cChannel *channel, eTimerMatch timerMatch, eMenuCategory cat) + : cDisplayMenuItemCurrentView(tmplCurrent) { + this->event = event; + this->channel = channel; + this->timerMatch = timerMatch; + this->cat = cat; +} + +cDisplayMenuItemCurrentSchedulesView::~cDisplayMenuItemCurrentSchedulesView() { +} + +void cDisplayMenuItemCurrentSchedulesView::Prepare(void) { +} + + +void cDisplayMenuItemCurrentSchedulesView::Render(void) { + intTokens.insert(pair("whatson", (cat == mcSchedule) ? true: false)); + intTokens.insert(pair("whatsonnow", (cat == mcScheduleNow) ? true: false)); + intTokens.insert(pair("whatsonnext", (cat == mcScheduleNext) ? true: false)); + if (timerMatch == tmFull) { + intTokens.insert(pair("timerpartitial", false)); + intTokens.insert(pair("timerfull", true)); + } else if (timerMatch == tmPartial) { + intTokens.insert(pair("timerpartitial", true)); + intTokens.insert(pair("timerfull", false)); + } else { + intTokens.insert(pair("timerpartitial", false)); + intTokens.insert(pair("timerfull", false)); + } + + if (event) { + stringTokens.insert(pair("title", event->Title() ? event->Title() : "")); + stringTokens.insert(pair("shorttext", event->ShortText() ? event->ShortText() : "")); + stringTokens.insert(pair("description", event->Description() ? event->Description() : "")); + stringTokens.insert(pair("start", *(event->GetTimeString()))); + stringTokens.insert(pair("stop", *(event->GetEndTimeString()))); + stringTokens.insert(pair("day", *WeekDayName(event->StartTime()))); + stringTokens.insert(pair("date", *ShortDateString(event->StartTime()))); + bool isRunning = false; + time_t now = time(NULL); + if ((now >= event->StartTime()) && (now <= event->EndTime())) + isRunning = true; + intTokens.insert(pair("running", isRunning)); + if (isRunning) { + intTokens.insert(pair("elapsed", (now - event->StartTime())/60)); + } else { + intTokens.insert(pair("elapsed", 0)); + } + intTokens.insert(pair("duration", event->Duration() / 60)); + SetScraperPoster(event); + } + if (channel) { + stringTokens.insert(pair("channelid", *(channel->GetChannelID().ToString()))); + } + + vector< map > schedulesTokens; + if (cat == mcScheduleNow || cat == mcScheduleNext) { + ReadSchedules(&schedulesTokens); + } + map < string, vector< map< string, string > > > loopTokens; + loopTokens.insert(pair > >("schedule", schedulesTokens)); + SetTokensPosMenuItem(); + DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); +} + +void cDisplayMenuItemCurrentSchedulesView::Clear(void) { + +} + +void cDisplayMenuItemCurrentSchedulesView::Action(void) { + SetInitFinished(); + DoSleep(delay); + Render(); + FadeIn(); + DoFlush(); + if (scrolling) { + DoSleep(scrollDelay); + if (scrollOrientation == orHorizontal) { + ScrollHorizontal(scrollingPix, scrollDelay, scrollSpeed, scrollMode); + } else { + ScrollVertical(scrollingPix, scrollDelay, scrollSpeed); + } + } +} + +void cDisplayMenuItemCurrentSchedulesView::ReadSchedules(vector< map > *schedulesTokens) { + if (!event) + return; + const cSchedule *schedule = event->Schedule(); + const cEvent *curEvent = event; + int num = 0; + for (; curEvent; curEvent = schedule->Events()->Next(curEvent)) { + if (num == 0) { + num++; + continue; + } + map element; + element.insert(pair("schedule[start]", *(curEvent->GetTimeString()))); + element.insert(pair("schedule[stop]", *(curEvent->GetEndTimeString()))); + element.insert(pair("schedule[title]", curEvent->Title() ? curEvent->Title() : "")); + element.insert(pair("schedule[shorttext]", curEvent->ShortText() ? curEvent->ShortText() : "")); + schedulesTokens->push_back(element); + num++; + if (num > 10) + break; + } +} + +/************************************************************* +* cDisplayMenuItemCurrentChannelView +*************************************************************/ + +cDisplayMenuItemCurrentChannelView::cDisplayMenuItemCurrentChannelView(cTemplateViewElement *tmplCurrent, const cChannel *channel) + : cDisplayMenuItemCurrentView(tmplCurrent) { + this->channel = channel; +} + +cDisplayMenuItemCurrentChannelView::~cDisplayMenuItemCurrentChannelView() { +} + +void cDisplayMenuItemCurrentChannelView::Prepare(void) { +} + + +void cDisplayMenuItemCurrentChannelView::Render(void) { + if (!channel) + return; + //general channel information + intTokens.insert(pair("number", channel->Number())); + intTokens.insert(pair("transponder", channel->Transponder())); + intTokens.insert(pair("frequency", channel->Frequency())); + + stringTokens.insert(pair("name", channel->Name() ? channel->Name() : "")); + stringTokens.insert(pair("channelid", *(channel->GetChannelID().ToString()))); + + //Channel Source Information + const cSource *source = Sources.Get(channel->Source()); + if (source) { + stringTokens.insert(pair("source", *cSource::ToString(source->Code()))); + stringTokens.insert(pair("sourcedescription", source->Description() ? source->Description() : "")); + stringTokens.insert(pair("source", *cSource::ToString(source->Code()))); + intTokens.insert(pair("isAtsc", source->IsAtsc(source->Code()))); + intTokens.insert(pair("isCable", source->IsCable(source->Code()))); + intTokens.insert(pair("isSat", source->IsSat(source->Code()))); + intTokens.insert(pair("isTerr", source->IsTerr(source->Code()))); + } + + //current schedule + cSchedulesLock schedulesLock; + const cSchedules *schedules = cSchedules::Schedules(schedulesLock); + const cSchedule *schedule = NULL; + schedule = schedules->GetSchedule(channel); + if (schedule) { + const cEvent *presentEvent = schedule->GetPresentEvent(); + if (presentEvent) { + stringTokens.insert(pair("presenteventtitle", presentEvent->Title() ? presentEvent->Title() : "")); + stringTokens.insert(pair("presenteventshorttext", presentEvent->ShortText() ? presentEvent->ShortText() : "")); + stringTokens.insert(pair("presenteventdescription", presentEvent->Description() ? presentEvent->Description() : "")); + stringTokens.insert(pair("presenteventstart", *presentEvent->GetTimeString())); + stringTokens.insert(pair("presenteventstop", *presentEvent->GetEndTimeString())); + stringTokens.insert(pair("presenteventday", *WeekDayName(presentEvent->StartTime()))); + stringTokens.insert(pair("presenteventdate", *ShortDateString(presentEvent->StartTime()))); + intTokens.insert(pair("presenteventelapsed", (time(0) - presentEvent->StartTime())/60)); + intTokens.insert(pair("presenteventduration", presentEvent->Duration() / 60)); + SetScraperPoster(presentEvent); + } else { + stringTokens.insert(pair("presenteventtitle", "")); + stringTokens.insert(pair("presenteventshorttext", "")); + stringTokens.insert(pair("presenteventdescription", "")); + stringTokens.insert(pair("presenteventstart", "")); + stringTokens.insert(pair("presenteventstop", "")); + stringTokens.insert(pair("presenteventday", "")); + stringTokens.insert(pair("presenteventdate", "")); + intTokens.insert(pair("presenteventelapsed", 0)); + intTokens.insert(pair("presenteventduration", 0)); + } + const cList *events = schedule->Events(); + bool inserted = false; + if (events && presentEvent) { + const cEvent *nextEvent = events->Next(presentEvent); + if (nextEvent) { + stringTokens.insert(pair("nexteventtitle", nextEvent->Title() ? nextEvent->Title() : "")); + stringTokens.insert(pair("nexteventshorttext", nextEvent->ShortText() ? nextEvent->ShortText() : "")); + stringTokens.insert(pair("nexteventdescription", nextEvent->Description() ? nextEvent->Description() : "")); + stringTokens.insert(pair("nexteventstart", *nextEvent->GetTimeString())); + stringTokens.insert(pair("nexteventstop", *nextEvent->GetEndTimeString())); + stringTokens.insert(pair("nexteventday", *WeekDayName(nextEvent->StartTime()))); + stringTokens.insert(pair("nexteventdate", *ShortDateString(nextEvent->StartTime()))); + intTokens.insert(pair("nexteventduration", nextEvent->Duration() / 60)); + inserted = true; + } + } + if (!inserted) { + stringTokens.insert(pair("nexteventtitle", "")); + stringTokens.insert(pair("nexteventshorttext", "")); + stringTokens.insert(pair("nexteventdescription", "")); + stringTokens.insert(pair("nexteventstart", "")); + stringTokens.insert(pair("nexteventstop", "")); + stringTokens.insert(pair("nexteventday", "")); + stringTokens.insert(pair("nexteventdate", "")); + intTokens.insert(pair("nexteventduration", 0)); + } + } + + vector< map > schedulesTokens; + ReadSchedules(&schedulesTokens); + + map < string, vector< map< string, string > > > loopTokens; + loopTokens.insert(pair > >("schedule", schedulesTokens)); + SetTokensPosMenuItem(); + DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens, &loopTokens); +} + +void cDisplayMenuItemCurrentChannelView::Clear(void) { + +} + +void cDisplayMenuItemCurrentChannelView::Action(void) { + SetInitFinished(); + DoSleep(delay); + Render(); + FadeIn(); + DoFlush(); + if (scrolling) { + DoSleep(scrollDelay); + if (scrollOrientation == orHorizontal) { + ScrollHorizontal(scrollingPix, scrollDelay, scrollSpeed, scrollMode); + } else { + ScrollVertical(scrollingPix, scrollDelay, scrollSpeed); + } + } +} + +void cDisplayMenuItemCurrentChannelView::ReadSchedules(vector< map > *schedulesTokens) { + cSchedulesLock schedulesLock; + const cSchedules *schedules = cSchedules::Schedules(schedulesLock); + const cSchedule *schedule = NULL; + schedule = schedules->GetSchedule(channel); + if (!schedule) { + return; + } + const cEvent *curEvent = schedule->GetPresentEvent(); + int num = 0; + for (; curEvent; curEvent = schedule->Events()->Next(curEvent)) { + if (num < 2) { + num++; + continue; + } + map element; + element.insert(pair("schedule[start]", *(curEvent->GetTimeString()))); + element.insert(pair("schedule[stop]", *(curEvent->GetEndTimeString()))); + element.insert(pair("schedule[title]", curEvent->Title() ? curEvent->Title() : "")); + element.insert(pair("schedule[shorttext]", curEvent->ShortText() ? curEvent->ShortText() : "")); + schedulesTokens->push_back(element); + num++; + if (num > 11) + break; + } +} + +/************************************************************* +* cDisplayMenuItemCurrentTimerView +*************************************************************/ + +cDisplayMenuItemCurrentTimerView::cDisplayMenuItemCurrentTimerView(cTemplateViewElement *tmplCurrent, const cTimer *timer) + : cDisplayMenuItemCurrentView(tmplCurrent) { + this->timer = timer; +} + +cDisplayMenuItemCurrentTimerView::~cDisplayMenuItemCurrentTimerView() { +} + +void cDisplayMenuItemCurrentTimerView::Prepare(void) { +} + + +void cDisplayMenuItemCurrentTimerView::Render(void) { + if (!timer) + return; + intTokens.insert(pair("flagactive", timer->HasFlags(tfActive))); + intTokens.insert(pair("flaginstant", timer->HasFlags(tfInstant))); + intTokens.insert(pair("flagvps", timer->HasFlags(tfVps))); + intTokens.insert(pair("flagrecording", timer->Recording())); + intTokens.insert(pair("flagpending", timer->Pending())); + + 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(); + stringTokens.insert(pair("title", file)); + stringTokens.insert(pair("timerstart", *cString::sprintf("%02d:%02d", timer->Start() / 100, timer->Start() % 100))); + stringTokens.insert(pair("timerstop", *cString::sprintf("%02d:%02d", timer->Stop() / 100, timer->Stop() % 100))); + + string day = ""; + string dayName = ""; + if (timer->WeekDays()) + day = timer->PrintDay(0, timer->WeekDays(), false); + else if (timer->Day() - time(NULL) < 28 * SECSINDAY) { + day = itoa(timer->GetMDay(timer->Day())); + dayName = WeekDayName(timer->Day()); + } else { + struct tm tm_r; + time_t Day = timer->Day(); + localtime_r(&Day, &tm_r); + char buffer[16]; + strftime(buffer, sizeof(buffer), "%Y%m%d", &tm_r); + day = buffer; + } + stringTokens.insert(pair("day", day)); + stringTokens.insert(pair("dayname", dayName)); + + const cChannel *channel = timer->Channel(); + if (channel) { + stringTokens.insert(pair("channelname", channel->Name() ? channel->Name() : "")); + stringTokens.insert(pair("channelid", *(channel->GetChannelID().ToString()))); + intTokens.insert(pair("channelnumber", channel->Number())); + } else { + stringTokens.insert(pair("channelname", "")); + stringTokens.insert(pair("channelid", "")); + intTokens.insert(pair("channelnumber", 0)); + } + + const cEvent *event = timer->Event(); + if (event) { + stringTokens.insert(pair("eventtitle", event->Title() ? event->Title() : "")); + stringTokens.insert(pair("eventstart", *event->GetTimeString())); + stringTokens.insert(pair("eventstop", *event->GetEndTimeString())); + stringTokens.insert(pair("eventshorttext", event->ShortText() ? event->ShortText() : "")); + stringTokens.insert(pair("eventdescription", event->Description() ? event->Description() : "")); + SetScraperPoster(event); + } else { + stringTokens.insert(pair("eventtitle", "")); + stringTokens.insert(pair("eventtitle", "")); + stringTokens.insert(pair("eventstop", "")); + stringTokens.insert(pair("eventshorttext", "")); + stringTokens.insert(pair("eventdescription", "")); + } + SetTokensPosMenuItem(); + DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens); +} + +void cDisplayMenuItemCurrentTimerView::Clear(void) { + +} + +void cDisplayMenuItemCurrentTimerView::Action(void) { + SetInitFinished(); + DoSleep(delay); + Render(); + FadeIn(); + DoFlush(); + if (scrolling) { + DoSleep(scrollDelay); + if (scrollOrientation == orHorizontal) { + ScrollHorizontal(scrollingPix, scrollDelay, scrollSpeed, scrollMode); + } else { + ScrollVertical(scrollingPix, scrollDelay, scrollSpeed); + } + } +} + +/************************************************************* +* cDisplayMenuItemCurrentRecordingView +*************************************************************/ + +cDisplayMenuItemCurrentRecordingView::cDisplayMenuItemCurrentRecordingView(cTemplateViewElement *tmplCurrent, const cRecording *recording, int level, int total, int newRecs) + : cDisplayMenuItemCurrentView(tmplCurrent) { + this->recording = recording; + this->level = level; + this->total = total; + this->newRecs = newRecs; +} + +cDisplayMenuItemCurrentRecordingView::~cDisplayMenuItemCurrentRecordingView() { +} + +void cDisplayMenuItemCurrentRecordingView::Prepare(void) { +} + + +void cDisplayMenuItemCurrentRecordingView::Render(void) { + if (!recording) + return; + bool isFolder = (total > 0) ? true : false; + intTokens.insert(pair("folder", isFolder)); + + string name = recording->Name() ? recording->Name() : ""; + string buffer = ""; + try { + vector tokens; + istringstream f(name.c_str()); + string s; + while (getline(f, s, FOLDERDELIMCHAR)) { + tokens.push_back(s); + } + buffer = tokens.at(level); + if (!isFolder && recording->IsEdited()) { + buffer = buffer.substr(1); + } + } catch (...) { + buffer = name.c_str(); + } + stringTokens.insert(pair("name", buffer.c_str())); + intTokens.insert(pair("new", recording->IsNew())); + intTokens.insert(pair("newrecordingsfolder", newRecs)); + intTokens.insert(pair("numrecordingsfolder", total)); + intTokens.insert(pair("cutted", recording->IsEdited())); + + SetScraperPoster(NULL, recording); + + const cRecordingInfo *info = recording->Info(); + if (!info) return; + + stringTokens.insert(pair("shorttext", info->ShortText() ? info->ShortText() : "")); + stringTokens.insert(pair("description", info->Description() ? info->Description() : "")); + + const cEvent *event = info->GetEvent(); + if (!event) return; + + string recDate = *(event->GetDateString()); + string recTime = *(event->GetTimeString()); + if (recDate.find("1970") != string::npos) { + time_t start = recording->Start(); + recDate = *DateString(start); + recTime = *TimeString(start); + } + int duration = event->Duration() / 60; + int recDuration = recording->LengthInSeconds(); + recDuration = (recDuration>0)?(recDuration / 60):0; + stringTokens.insert(pair("date", recDate.c_str())); + stringTokens.insert(pair("time", recTime.c_str())); + intTokens.insert(pair("duration", recDuration)); + intTokens.insert(pair("durationevent", duration)); + SetTokensPosMenuItem(); + DrawViewElement(veMenuCurrentItemDetail, &stringTokens, &intTokens); +} + +void cDisplayMenuItemCurrentRecordingView::Clear(void) { + +} + +void cDisplayMenuItemCurrentRecordingView::Action(void) { + SetInitFinished(); + DoSleep(delay); + Render(); + FadeIn(); + DoFlush(); + if (scrolling) { + DoSleep(scrollDelay); + if (scrollOrientation == orHorizontal) { + ScrollHorizontal(scrollingPix, scrollDelay, scrollSpeed, scrollMode); + } else { + ScrollVertical(scrollingPix, scrollDelay, scrollSpeed); + } + } +} -- cgit v1.2.3