2 Copyright 2004-2007 Chris Tallon, 2014 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
20 #include "vepglistadvanced.h"
30 #include "messagequeue.h"
32 #include "movieinfo.h"
33 #include "seriesinfo.h"
36 #include "vepgsummary.h"
37 #include "vepgsettimer.h"
39 #include "staticartwork.h"
44 VEpgListAdvanced::VEpgListAdvanced(VVideoLiveTV *tvideolive, ChannelList* tchanList,ULONG initialChannelNumber)
46 channelNumber = initialChannelNumber;
48 videolive = tvideolive;
49 boxstack = BoxStack::getInstance();
53 setSize(640+40, 500+40); //old setSize(570, 420);
59 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
60 TVMediaInfo *info= new TVMediaInfo();
61 info->setChannelLogo(channelNumber);
62 info->setStaticFallback(sa_tv);
63 setTitleBarIcon(info);
65 sl.setPosition(10, 30 + 5);
66 sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30);
67 sl.setLinesPerOption(2.4f);
70 Region slarea=sl.getRegionR();
72 epg.setParaMode(true);
73 epg.setPosition(slarea.x +slarea.w+10 ,30+5);
74 epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30);
77 epg.setVideoBackground();
78 epg.setBackgroundColour(DrawStyle::VIEWTRANSPARENTBACKGROUND);
80 epgTVmedia.setPosition(epg.getRegionR().w-100-10,10);
81 epgTVmedia.setSize(100,(UINT)(150/Osd::getInstance()->getPixelAspect()));
84 boxRed.setBackgroundColour(DrawStyle::RED);
85 boxRed.setPosition(165 /*54*/, sl.getY2()+8);
86 boxRed.setSize(18, 16);
89 textRed.setPosition(boxRed.getX2(), sl.getY2()+4);
90 textRed.setSize(116, 30);
94 boxGreen.setBackgroundColour(DrawStyle::GREEN);
95 boxGreen.setPosition(165 +1*110, sl.getY2()+8);
96 boxGreen.setSize(18, 16);
99 textGreen.setPosition(boxGreen.getX2(), sl.getY2()+4);
100 textGreen.setSize(116, 30);
103 boxYellow.setBackgroundColour(DrawStyle::YELLOW);
104 boxYellow.setPosition(165 +2*110, sl.getY2()+8);
105 boxYellow.setSize(18, 16);
108 textYellow.setPosition(boxYellow.getX2(), sl.getY2()+4);
109 textYellow.setSize(116, 30);
112 boxBlue.setBackgroundColour(DrawStyle::BLUE);
113 boxBlue.setPosition(165 +3*110, sl.getY2()+8);
114 boxBlue.setSize(18, 16);
117 textBlue.setPosition(boxBlue.getX2(), sl.getY2()+4);
118 textBlue.setSize(116, 30);
124 updateEpgDataChannel();
127 VEpgListAdvanced::~VEpgListAdvanced()
133 void VEpgListAdvanced::setButtonText()
138 textRed.setText(tr("Record"));
139 textGreen.setText(tr("Now"));
140 textYellow.setText(tr("Next"));
141 textBlue.setText(tr("Guide"));
145 textRed.setText(tr("Record"));
146 textGreen.setText(tr("Next"));
147 textYellow.setText(tr("Schedule"));
148 textBlue.setText(tr("Switch"));
151 textRed.setText(tr("Record"));
152 textGreen.setText(tr("Now"));
153 textYellow.setText(tr("Schedule"));
154 textBlue.setText(tr("Switch"));
160 void VEpgListAdvanced::doRed()
165 void VEpgListAdvanced::doGreen()
179 void VEpgListAdvanced::doYellow()
193 void VEpgListAdvanced::doBlue()
207 void VEpgListAdvanced::doNext()
209 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doNext");
210 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
211 if (mode!=OneChannel) {
212 Channel * chan=(*chanList)[slCurrentOption];
213 channelNumber = chan->number;
216 updateEpgDataNowNext(true);
218 TVMediaInfo *info= new TVMediaInfo();
219 info->setStaticArtwork(sa_tv);
220 setTitleBarIcon(info);
222 boxstack->update(this);
224 void VEpgListAdvanced::doNow()
226 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doNow");
227 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
228 if (mode!=OneChannel) {
229 Channel * chan=(*chanList)[slCurrentOption];
230 channelNumber = chan->number;
233 updateEpgDataNowNext(true);
235 TVMediaInfo *info= new TVMediaInfo();
236 info->setStaticArtwork(sa_tv);
237 setTitleBarIcon(info);
239 boxstack->update(this);
242 void VEpgListAdvanced::doProgramm()
244 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doProgram");
246 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
247 Channel * chan=(*chanList)[slCurrentOption];
248 channelNumber = chan->number;
249 updateEpgDataChannel();
251 TVMediaInfo *info= new TVMediaInfo();
252 info->setChannelLogo(channelNumber);
253 info->setStaticFallback(sa_tv);
254 setTitleBarIcon(info);
256 boxstack->update(this);
259 void VEpgListAdvanced::doSwitch()
264 if (mode!=OneChannel) {
265 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
266 Channel * chan=(*chanList)[slCurrentOption];
267 channelNumber = chan->number;
269 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doSwitch %d", channelNumber);
270 Message* m = new Message(); // Must be done after this view deleted
273 m->message = Message::CHANNEL_CHANGE;
274 m->parameter = channelNumber;
276 MessageQueue::getInstance()->postMessage(m);
282 #pragma warning(disable : 4703)
285 void VEpgListAdvanced::doRecord()
288 Event* current = getCurrentOptionEvent(channel);
291 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Found the option you pointed at. %s %d", current->title, current->id);
292 unsigned int chanlistsize=chanList->size();
295 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
297 chan = (*chanList)[listIndex];
298 if ((int)chan->number == channel) break;
301 Log::getInstance()->log("VEpgSummary", Log::DEBUG, "ID %lu TIME %lu DURATION %lu TITLE %s", current->id, current->time,
302 current->duration, current->title);
303 VEpgSetTimer* vs = new VEpgSetTimer(current, chan);
306 boxstack->update(vs);
311 void VEpgListAdvanced::doGrid()
314 if (mode!=OneChannel) {
315 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
316 Channel * chan=(*chanList)[slCurrentOption];
317 channelNumber = chan->number;
320 unsigned int chanlistsize=chanList->size();
322 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
324 chan = (*chanList)[listIndex];
325 if (chan->number == channelNumber) break;
328 VEpg* vepg = new VEpg(videolive, listIndex, chanList);
331 boxstack->update(vepg);
335 void VEpgListAdvanced::clearEventList()
337 std::vector<EventList*>::iterator itty = eventLista.begin();
338 while (itty!= eventLista.end()) {
352 * if (!chanList) return;
354 for(UINT listIndex = 0; listIndex < gridRows; listIndex++)
356 if(listTop + listIndex >= UINT(chanListbox.getBottomOption()))
358 chan = (*chanList)[listTop + listIndex];
359 eventLista[listIndex] = VDR::getInstance()->getChannelSchedule(chan->number, ltime - 1, window_width * 60 + 2); // ltime - 1 to get prog before window (allows cursor left past ltime). + 2 to get prog after window
364 void VEpgListAdvanced::updateEpgData()
369 //updateEpgDataChannel();
373 updateEpgDataNowNext(false);
379 void VEpgListAdvanced::updateEpgDataNowNext(bool changeState)
384 unsigned int chanlistsize=chanList->size();
387 eventLista.resize(chanList->size());
389 for(UINT listIndex = 0; listIndex < chanlistsize; listIndex++)
391 if (listIndex < 0) continue;
392 if (listIndex >= chanlistsize) continue;
393 chan = (*chanList)[listIndex];
394 if (chan->number == channelNumber) {
395 startupdate = listIndex-sl.getNumOptionsDisplayable()-2;
396 endupdate = listIndex+sl.getNumOptionsDisplayable()+2;
401 startupdate=sl.getTopOption()-2;
402 endupdate=sl.getBottomOption()+1;
409 for(int listIndex = startupdate; listIndex < endupdate; listIndex++)
411 if (listIndex < 0) continue;
412 if (listIndex >= (int)chanlistsize) continue;
414 chan = (*chanList)[listIndex];
415 if (!eventLista[listIndex]) eventLista[listIndex] = VDR::getInstance()->getChannelSchedule(chan->number, now, 4 * 60 *60);
421 void VEpgListAdvanced::updateEpgDataChannel()
424 eventLista.resize(1);
427 eventLista[0] = VDR::getInstance()->getChannelSchedule(channelNumber, now, 24 * 60 *60 *30); // one month
428 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Eventlist %x %d", eventLista[0],channelNumber);
432 void VEpgListAdvanced::drawData(bool doIndexPop)
437 drawDataChannel(doIndexPop);
440 drawDataNowNext(true, doIndexPop);
443 drawDataNowNext(false, doIndexPop);
449 void VEpgListAdvanced::drawDataChannel(bool doIndexPop)
451 int saveIndex = sl.getCurrentOption();
452 int saveTop = sl.getTopOption();
456 sl.addColumn(25 + 7);
457 sl.addColumn(25 + 7+ 7);
462 char tempA[300]; // FIXME this is guesswork!
463 char tempB[300]; // FIXME
464 char tempC[300]; // FIXME
470 Event* currentEvent = NULL;
471 EventList::iterator j;
472 EventList* eventList = eventLista[0];
474 for (j = eventList->begin(); j != eventList->end(); j++)
477 time_t eventStartTime = (time_t)currentEvent->time;
478 time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
480 LOCALTIME_R(&eventStartTime, &btime);
481 strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
482 LOCALTIME_R(&eventEndTime, &btime);
483 strftime(tempB, 299, "- %H:%M ", &btime);
485 sprintf(tempC, "\t %s\n \t \t%s%s", currentEvent->title,tempA,tempB);
487 TVMediaInfo *info= new TVMediaInfo();
488 info->setPosterThumb(channelNumber, currentEvent->id);
489 info->setStaticFallback(sa_defposter);
490 currentEvent->index = sl.addOption(tempC, reinterpret_cast<void*>(currentEvent->id), first, info);
497 sl.hintSetCurrent(0);
501 sl.hintSetCurrent(saveIndex);
502 sl.hintSetTop(saveTop);
508 void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop)
510 int saveIndex = sl.getCurrentOption();
511 int saveTop = sl.getTopOption();
519 char tempA[300]; // FIXME this is guesswork!
520 char tempB[300]; // FIXME
521 char tempC[300]; // FIXME
527 Event* currentEvent = NULL;
528 EventList::iterator j;
530 if (next) minevents++;
531 int setcurrenthelper =0;
533 unsigned int chanlistsize=chanList->size();
534 for(UINT listIndex = 0; listIndex < chanlistsize; listIndex++)
537 chan = (*chanList)[listIndex];
539 EventList* eventList = eventLista[listIndex];
540 if (eventList && ((int)eventList->size() >= minevents)) {
541 j = eventList->begin();
543 currentEvent = j[minevents-1];
544 time_t eventStartTime = (time_t)currentEvent->time;
545 time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
547 LOCALTIME_R(&eventStartTime, &btime);
548 strftime(tempA, 299, "%H:%M ", &btime);
549 LOCALTIME_R(&eventEndTime, &btime);
550 strftime(tempB, 299, "- %H:%M ", &btime);
552 sprintf(tempC, "%s\n%s\t %s%s", currentEvent->title, chan->name,tempA,tempB);
555 sprintf(tempC, "\n%s", chan->name);
558 TVMediaInfo *info= new TVMediaInfo();
559 if ((*chanList)[listIndex]->number == channelNumber) {
561 setcurrenthelper = listIndex;
563 info->setChannelLogo((*chanList)[listIndex]->number);
564 info->setStaticFallback(sa_tv);
565 int index = sl.addOption(tempC, reinterpret_cast<void*>(listIndex), first, info);
566 if (currentEvent) currentEvent->index = index;
572 sl.hintSetCurrent(setcurrenthelper);
576 sl.hintSetCurrent(saveIndex);
577 sl.hintSetTop(saveTop);
582 void VEpgListAdvanced::draw(bool doIndexPop)
585 // Single channel mode
589 unsigned int chanlistsize=chanList->size();
592 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
594 chan = (*chanList)[listIndex];
595 if (chan->number == channelNumber) break;
597 sprintf(tempA, tr("Schedule - %s"), (*chanList)[listIndex]->name);
601 setTitleText(tr("Now"));
604 setTitleText(tr("Next"));
610 drawData(doIndexPop);
624 LOCALTIME_R(&now, &btime);
625 strftime(freeSpace, 299, "%d/%m/%y", &btime);
627 drawTextRJ(freeSpace, getWidth(), 5, DrawStyle::LIGHTTEXT);
633 w.nextSymbol = WSymbol::UP;
634 w.setPosition(20, area.h-35);
636 w.nextSymbol = WSymbol::DOWN;
637 w.setPosition(50, area.h-35);
639 w.nextSymbol = WSymbol::SKIPBACK;
640 w.setPosition(85, area.h-35);
642 w.nextSymbol = WSymbol::SKIPFORWARD;
643 w.setPosition(115, area.h-35);
646 drawTextRJ(tr("[ok] = info"), 560+70, sl.getY2()+4, DrawStyle::LIGHTTEXT);
648 // All static stuff done
653 Event* VEpgListAdvanced::getCurrentOptionEvent(int& channel)
655 // version for channel
656 Event* currentEvent = NULL;
657 EventList::iterator j;
658 EventList* eventList = NULL;
659 ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
664 eventList = eventLista[0];
666 channel = channelNumber;
667 for (j = eventList->begin(); j != eventList->end(); j++)
670 if (currentEvent->index == slCurrentOption) return currentEvent;
676 eventList = eventLista[slCurrentOption];
677 channel = (*chanList)[slCurrentOption]->number;
680 if (eventList && eventList->size()>1) {
681 j = eventList->begin();
688 eventList = eventLista[slCurrentOption];
689 channel = (*chanList)[slCurrentOption]->number;
691 if (eventList && eventList->size()>0) {
692 j = eventList->begin();
707 void VEpgListAdvanced::updateSelection()
710 if (mode==OneChannel) {
711 TVMediaInfo *info= new TVMediaInfo();
712 info->setChannelLogo(channelNumber);
713 info->setStaticFallback(sa_tv);
714 setTitleBarIcon(info);
716 Event* toShow = getCurrentOptionEvent(channel);
719 toShow->loadinfos(channel);
720 std::stringstream description;
722 description << "\n"<< toShow->title << "\n\n";
723 description << toShow->subtitle <<"\n";
724 description << toShow->description;
728 if (toShow->movieInfo) {
729 poster=toShow->movieInfo->poster;
731 if (toShow->seriesInfo) {
732 if (toShow->seriesInfo->seasonposter.height) {
733 poster=toShow->seriesInfo->seasonposter;
735 else if (toShow->seriesInfo->posters.size()) {
736 poster=toShow->seriesInfo->posters[0];
740 epgTVmedia.setTVMedia(poster.info, WTVMedia::ZoomHorizontal);
741 epgTVmedia.setVisible(true);
743 if (toShow->epgImage)
746 info.setPosterThumb(channel,toShow->id);
747 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
748 epgTVmedia.setVisible(true);
749 }else if (mode!=OneChannel) {
751 info.setChannelLogo(channel);
752 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
753 epgTVmedia.setVisible(true);
755 epgTVmedia.setVisible(false);
759 epg.setText(description.str().c_str());
762 if (mode!=OneChannel) {
764 info.setChannelLogo(channel);
765 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
766 epgTVmedia.setVisible(true);
768 epgTVmedia.setVisible(false);
774 int VEpgListAdvanced::handleCommand(int command)
783 boxstack->update(this);
791 boxstack->update(this);
794 case Input::SKIPBACK:
799 boxstack->update(this);
802 case Input::SKIPFORWARD:
807 boxstack->update(this);
832 if (sl.getNumOptions() == 0) return 2;
836 Event* current = getCurrentOptionEvent(channel);
839 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Found the option you pointed at. %s %d", current->title, current->id);
840 unsigned int chanlistsize=chanList->size();
843 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
845 chan = (*chanList)[listIndex];
846 if ((int)chan->number == channel) break;
849 VEpgSummary* vr = new VEpgSummary(current, (*chanList)[listIndex]);
852 boxstack->update(vr);
856 // should not get to here
864 // stop command getting to any more views
868 void VEpgListAdvanced::processMessage(Message* m)
870 Log::getInstance()->log("VEpgListAdvanced", Log::DEBUG, "Got message value %lu", m->message);
872 if (m->message == Message::MOUSE_MOVE)
874 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
877 boxstack->update(this);
880 else if (m->message == Message::MOUSE_LBDOWN)
882 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
884 boxstack->handleCommand(Input::OK); //simulate OK press
886 else if (boxRed.mouseLBDOWN((m->parameter >> 16) - getScreenX(), (m->parameter & 0xFFFF) - getScreenY()))
888 boxstack->handleCommand(Input::RED);
890 else if (boxGreen.mouseLBDOWN((m->parameter >> 16) - getScreenX(), (m->parameter & 0xFFFF) - getScreenY()))
892 boxstack->handleCommand(Input::GREEN);
894 else if (boxYellow.mouseLBDOWN((m->parameter >> 16) - getScreenX(), (m->parameter & 0xFFFF) - getScreenY()))
896 boxstack->handleCommand(Input::GREEN);
898 else if (boxBlue.mouseLBDOWN((m->parameter >> 16) - getScreenX(), (m->parameter & 0xFFFF) - getScreenY()))
900 boxstack->handleCommand(Input::GREEN);
904 if (coordsOutsideBox(m))
906 boxstack->handleCommand(Input::BACK); //simulate cancel press
914 void VEpgListAdvanced::quickUpdate() { //only quick for plattform that need it!
917 #ifdef GRADIENT_DRAWING